AppleSAWS/src/ui/catalogwidget.cxx

117 lines
4.1 KiB
C++
Raw Normal View History

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"));
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);
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);
int idx = 0;
2015-12-01 16:24:51 +00:00
foreach(FileDescriptiveEntry fde, m_disk->getAllFDEs()) {
QString filetype = fde.fileType();
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);
QListWidgetItem *item = new QListWidgetItem(text);
2016-02-10 16:10:37 +00:00
item->setToolTip(createToolTip(fde));
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;
}
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();
}
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();
emit openWithDefaultViewer(m_disk,fde);
}