2021-01-22 21:45:10 +00:00
|
|
|
#include "catalogwidget.h"
|
|
|
|
#include "ui_catalogwidget.h"
|
|
|
|
#include "filedescriptiveentry.h"
|
|
|
|
#include "binaryfile.h"
|
|
|
|
#include "applesoftfile.h"
|
|
|
|
#include "genericfile.h"
|
|
|
|
#include "IntBasicFile.h"
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QPalette>
|
|
|
|
|
|
|
|
CatalogWidget::CatalogWidget(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::CatalogWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-02-03 19:11:56 +00:00
|
|
|
QFont catalogFont("PR Number 3",12);
|
|
|
|
//catalogFont.setStyleHint(QFont::Monospace);
|
|
|
|
|
2021-01-22 21:45:10 +00:00
|
|
|
ui->catalog_list->setFont(catalogFont);
|
|
|
|
ui->noteButton->setText(QChar(0x270d));
|
|
|
|
ui->noteButton->setFont(QFont("sans",16,QFont::Bold));
|
|
|
|
|
|
|
|
connect(ui->catalog_list, &QListWidget::itemDoubleClicked,
|
|
|
|
this, &CatalogWidget::itemDoubleClicked);
|
|
|
|
}
|
|
|
|
|
|
|
|
CatalogWidget::~CatalogWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CatalogWidget::prepForNewDisk(QString filename, DiskFile *disk)
|
|
|
|
{
|
|
|
|
m_disk = disk;
|
|
|
|
m_diskname = filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CatalogWidget::createToolTip(FileDescriptiveEntry &fde) {
|
|
|
|
QString retval;
|
2021-02-03 18:32:07 +00:00
|
|
|
retval += AppleString(fde.filename).printable().trimmed() +
|
|
|
|
(fde.deleted?"(Deleted)":"") + "\n";
|
2021-01-22 21:45:10 +00:00
|
|
|
retval += QString("Type: %1\n").arg(fde.fileType());
|
|
|
|
retval += QString("Sectors: %1 (%2 bytes)\n")
|
2021-02-03 18:32:07 +00:00
|
|
|
.arg(fde.lengthInSectors)
|
|
|
|
.arg(fde.lengthInSectors*256);
|
2021-01-22 21:45:10 +00:00
|
|
|
retval += QString("%1\n").arg(fde.isLocked()?"Locked":"Unlocked");
|
|
|
|
GenericFile *file = m_disk->getFile(fde);
|
2021-02-03 18:32:07 +00:00
|
|
|
if (!file) { return ""; }
|
2021-01-22 21:45:10 +00:00
|
|
|
quint16 address = file->address();
|
|
|
|
retval += QString("Address: $%1 (%2)\n").arg((quint16) (address),4,16,QChar('0'))
|
2021-02-03 18:32:07 +00:00
|
|
|
.arg(address);
|
2021-01-22 21:45:10 +00:00
|
|
|
if (dynamic_cast<BinaryFile*>(file)) {
|
|
|
|
BinaryFile *binfile = dynamic_cast<BinaryFile*>(file);
|
|
|
|
quint16 length = binfile->length();
|
|
|
|
retval += QString("Length: $%1 (%2)\n").arg((quint16) (length),4,16,QChar('0'))
|
2021-02-03 18:32:07 +00:00
|
|
|
.arg(length);
|
2021-01-22 21:45:10 +00:00
|
|
|
} else if (dynamic_cast<ApplesoftFile*>(file)) {
|
|
|
|
ApplesoftFile *asfile = dynamic_cast<ApplesoftFile*>(file);
|
|
|
|
quint16 length = asfile->length();
|
|
|
|
retval += QString("Length: $%1 (%2)\n").arg((quint16) (length),4,16,QChar('0'))
|
2021-02-03 18:32:07 +00:00
|
|
|
.arg(length);
|
2021-01-22 21:45:10 +00:00
|
|
|
quint16 uabytes = asfile->extraData().length();
|
|
|
|
if (uabytes) {
|
2021-02-03 18:32:07 +00:00
|
|
|
retval += QString("Unaccounted Bytes: $%1 (%2)\n").arg((quint16) (uabytes),4,16,QChar('0'))
|
|
|
|
.arg(uabytes);
|
2021-01-22 21:45:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
retval += QString("Data Length: $%1 (%2)\n").arg((quint16) (file->data().length()),4,16,QChar('0'))
|
|
|
|
.arg(file->data().length());
|
|
|
|
}
|
2021-02-03 18:32:07 +00:00
|
|
|
// delete file;
|
2021-01-22 21:45:10 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CatalogWidget::processNewlyLoadedDisk(QString diskfilename, DiskFile *disk)
|
|
|
|
{
|
2021-02-03 18:32:07 +00:00
|
|
|
qDebug() << "### Start processNewlyLoadedDisk";
|
2021-01-22 21:45:10 +00:00
|
|
|
if (m_disk == disk) {
|
|
|
|
QUrl url = QUrl::fromLocalFile(diskfilename);
|
|
|
|
QString shortfilename = url.fileName();
|
|
|
|
QFontMetrics fm(ui->catalog_list->font());
|
|
|
|
QRect maxrect;
|
|
|
|
ui->volume_label->setText(shortfilename);
|
|
|
|
int idx = 0;
|
|
|
|
foreach(FileDescriptiveEntry fde, m_disk->getAllFDEs()) {
|
2021-02-03 18:32:07 +00:00
|
|
|
qDebug() << " Processing FDE# " << idx;
|
2021-01-22 21:45:10 +00:00
|
|
|
QString filetype = fde.fileType();
|
|
|
|
QString filename = AppleString(fde.filename).printable().trimmed();
|
|
|
|
quint16 size = fde.lengthInSectors;
|
|
|
|
bool locked = fde.isLocked();
|
|
|
|
QString sizeStr = QString("%1").arg(size,5,10,QChar(' ')).toUpper();
|
|
|
|
QString text = QString("%1 %2 %3 %4").arg(locked?"*":" ").arg(sizeStr).arg(filetype).arg(filename);
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(text);
|
|
|
|
if (filetype == "A") { item->setForeground(Qt::blue); }
|
|
|
|
else if (filetype == "I") { item->setForeground(Qt::darkYellow); }
|
|
|
|
else if (filetype == "B") { item->setForeground(Qt::darkGreen); }
|
|
|
|
else if (filetype == "T") { item->setForeground(Qt::red); }
|
|
|
|
else if (filetype == "R") { item->setForeground(Qt::darkRed); }
|
|
|
|
else if (filetype == "S") { item->setForeground(Qt::magenta); }
|
|
|
|
else if (filetype == "a") { item->setForeground(Qt::darkBlue); }
|
|
|
|
else if (filetype == "b") { item->setForeground(Qt::darkMagenta); }
|
|
|
|
else { item->setForeground(Qt::black); }
|
|
|
|
item->setToolTip(createToolTip(fde));
|
|
|
|
item->setData(0x0100,idx);
|
2021-02-03 18:32:07 +00:00
|
|
|
|
|
|
|
if (!fde.deleted) ui->catalog_list->addItem(item);
|
|
|
|
|
2021-01-22 21:45:10 +00:00
|
|
|
QRect rect = fm.boundingRect(text);
|
|
|
|
if (rect.width() > maxrect.width()) {
|
|
|
|
maxrect = rect;
|
|
|
|
}
|
|
|
|
idx++;
|
2021-02-03 18:32:07 +00:00
|
|
|
qDebug() << " Done Processing FDE# " << idx-1;
|
2021-01-22 21:45:10 +00:00
|
|
|
}
|
2021-02-03 18:32:07 +00:00
|
|
|
// QFont italfont = ui->catalog_list->font();
|
|
|
|
// italfont.setItalic(true);
|
|
|
|
// QListWidgetItem *item = new QListWidgetItem("Boot Sector");
|
|
|
|
// item->setForeground(Qt::black);
|
|
|
|
// item->setFont(italfont);
|
|
|
|
// item->setData(0x0100,-1);
|
|
|
|
// ui->catalog_list->addItem(item);
|
|
|
|
|
|
|
|
// item = new QListWidgetItem("DOS Image");
|
|
|
|
// item->setForeground(Qt::black);
|
|
|
|
// item->setFont(italfont);
|
|
|
|
// item->setData(0x0100,-2);
|
|
|
|
// ui->catalog_list->addItem(item);
|
2021-01-22 21:45:10 +00:00
|
|
|
|
|
|
|
ui->catalog_list->resize(maxrect.width(),ui->catalog_list->size().height());
|
|
|
|
}
|
2021-02-03 18:32:07 +00:00
|
|
|
qDebug() << "### End processNewlyLoadedDisk";
|
2021-01-22 21:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CatalogWidget::unloadDisk(DiskFile *disk)
|
|
|
|
{
|
|
|
|
if (m_disk == disk) {
|
|
|
|
m_disk = 0;
|
|
|
|
}
|
|
|
|
ui->catalog_list->clear();
|
|
|
|
ui->volume_label->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CatalogWidget::itemDoubleClicked(QListWidgetItem *item)
|
|
|
|
{
|
|
|
|
int idx = item->data(0x0100).toInt();
|
|
|
|
if (idx >= 0)
|
|
|
|
{
|
|
|
|
FileDescriptiveEntry fde = m_disk->getAllFDEs()[idx];
|
2021-02-03 18:32:07 +00:00
|
|
|
// qDebug() << "Default File " << AppleString(fde.filename).printable().trimmed();
|
2021-01-22 21:45:10 +00:00
|
|
|
emit openWithDefaultViewer(m_disk,fde);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (idx == -1) // Boot Sector
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (idx == -2) // DOS Image
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CatalogWidget::itemClicked(QListWidgetItem *item)
|
|
|
|
{
|
|
|
|
int idx = item->data(0x0100).toInt();
|
|
|
|
FileDescriptiveEntry fde = m_disk->getAllFDEs()[idx];
|
2021-02-03 18:32:07 +00:00
|
|
|
// qDebug() << "Default File " << AppleString(fde.filename).printable().trimmed();
|
2021-01-22 21:45:10 +00:00
|
|
|
emit newFileSelected(m_disk,fde);
|
|
|
|
}
|