2015-12-01 16:24:51 +00:00
|
|
|
#include "catalogwidget.h"
|
|
|
|
#include "ui_catalogwidget.h"
|
|
|
|
#include "filedescriptiveentry.h"
|
2016-02-10 16:10:37 +00:00
|
|
|
#include "binaryfile.h"
|
|
|
|
#include "applesoftfile.h"
|
|
|
|
#include "genericfile.h"
|
2015-12-01 16:24:51 +00:00
|
|
|
#include <QUrl>
|
2016-02-10 16:10:37 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QAction>
|
2015-12-01 16:24:51 +00:00
|
|
|
|
|
|
|
CatalogWidget::CatalogWidget(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::CatalogWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->catalog_list->setFont(QFont("monospace"));
|
|
|
|
|
2015-12-02 21:04:41 +00:00
|
|
|
connect(ui->catalog_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
|
|
|
SLOT(itemClicked(QListWidgetItem*)));
|
2015-12-01 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CatalogWidget::~CatalogWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CatalogWidget::prepForNewDisk(QString filename, DiskFile *disk)
|
|
|
|
{
|
|
|
|
m_disk = disk;
|
|
|
|
m_diskname = filename;
|
|
|
|
}
|
|
|
|
|
2016-02-10 16:10:37 +00:00
|
|
|
QString CatalogWidget::createToolTip(FileDescriptiveEntry &fde) {
|
|
|
|
QString retval;
|
2016-10-15 15:13:53 +00:00
|
|
|
//qDebug() << AppleString(fde.filename).printable().trimmed();
|
2016-02-10 16:10:37 +00:00
|
|
|
retval += AppleString(fde.filename).printable().trimmed() + "\n";
|
|
|
|
retval += QString("Type: %1\n").arg(fde.fileType());
|
|
|
|
retval += QString("Sectors: %1 (%2 bytes)\n").arg(fde.lengthInSectors).arg(fde.lengthInSectors*256);
|
|
|
|
retval += QString("%1\n").arg(fde.isLocked()?"Locked":"Unlocked");
|
|
|
|
|
|
|
|
GenericFile *file = m_disk->getFile(fde);
|
2016-02-11 23:46:10 +00:00
|
|
|
quint16 address = file->address();
|
|
|
|
retval += QString("Address: $%1 (%2)\n").arg((quint16) (address),4,16,QChar('0'))
|
|
|
|
.arg(address);
|
2016-02-10 16:10:37 +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'))
|
|
|
|
.arg(length);
|
|
|
|
} 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'))
|
|
|
|
.arg(length);
|
|
|
|
quint16 uabytes = asfile->extraData().length();
|
|
|
|
if (uabytes) {
|
|
|
|
retval += QString("Unaccounted Bytes: $%1 (%2)\n").arg((quint16) (uabytes),4,16,QChar('0'))
|
|
|
|
.arg(uabytes);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
retval += QString("Data Length: $%1 (%2)\n").arg((quint16) (file->data().length()),4,16,QChar('0'))
|
|
|
|
.arg(file->data().length());
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-12-01 16:24:51 +00:00
|
|
|
void CatalogWidget::processNewlyLoadedDisk(QString diskfilename, DiskFile *disk)
|
|
|
|
{
|
|
|
|
if (m_disk == disk) {
|
|
|
|
QUrl url = QUrl::fromLocalFile(diskfilename);
|
|
|
|
QString shortfilename = url.fileName();
|
2016-10-14 18:12:13 +00:00
|
|
|
QFontMetrics fm(ui->catalog_list->font());
|
2015-12-01 16:24:51 +00:00
|
|
|
QRect maxrect;
|
|
|
|
ui->volume_label->setText(shortfilename);
|
2015-12-02 21:04:41 +00:00
|
|
|
int idx = 0;
|
2015-12-01 16:24:51 +00:00
|
|
|
foreach(FileDescriptiveEntry fde, m_disk->getAllFDEs()) {
|
|
|
|
QString filetype = fde.fileType();
|
2015-12-02 21:04:41 +00:00
|
|
|
QString filename = AppleString(fde.filename).printable().trimmed();
|
2015-12-01 16:24:51 +00:00
|
|
|
int 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);
|
2015-12-02 21:04:41 +00:00
|
|
|
QListWidgetItem *item = new QListWidgetItem(text);
|
2016-02-10 16:10:37 +00:00
|
|
|
item->setToolTip(createToolTip(fde));
|
2015-12-02 21:04:41 +00:00
|
|
|
item->setData(0x0100,idx);
|
|
|
|
ui->catalog_list->addItem(item);
|
2016-10-14 18:12:13 +00:00
|
|
|
QRect rect = fm.boundingRect(text);
|
2015-12-01 16:24:51 +00:00
|
|
|
if (rect.width() > maxrect.width()) {
|
|
|
|
maxrect = rect;
|
|
|
|
}
|
2015-12-02 21:04:41 +00:00
|
|
|
idx++;
|
2015-12-01 16:24:51 +00:00
|
|
|
}
|
|
|
|
ui->catalog_list->resize(maxrect.width(),ui->catalog_list->size().height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CatalogWidget::unloadDisk(DiskFile *disk)
|
|
|
|
{
|
|
|
|
if (m_disk == disk) {
|
|
|
|
m_disk = 0;
|
|
|
|
}
|
|
|
|
ui->catalog_list->clear();
|
|
|
|
ui->volume_label->clear();
|
|
|
|
}
|
|
|
|
|
2015-12-02 21:04:41 +00:00
|
|
|
void CatalogWidget::itemClicked(QListWidgetItem *item)
|
|
|
|
{
|
|
|
|
int idx = item->data(0x0100).toInt();
|
|
|
|
FileDescriptiveEntry fde = m_disk->getAllFDEs()[idx];
|
2016-10-15 15:13:53 +00:00
|
|
|
// qDebug() << "Default File " << AppleString(fde.filename).printable().trimmed();
|
2016-02-11 23:46:10 +00:00
|
|
|
emit openWithDefaultViewer(m_disk,fde);
|
|
|
|
}
|