AppleSAWS/src/catalogwidget.cxx

62 lines
1.7 KiB
C++
Raw Normal View History

2015-12-01 16:24:51 +00:00
#include "catalogwidget.h"
#include "ui_catalogwidget.h"
#include "filedescriptiveentry.h"
#include <QUrl>
CatalogWidget::CatalogWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CatalogWidget)
{
ui->setupUi(this);
ui->catalog_list->setFont(QFont("monospace"));
}
CatalogWidget::~CatalogWidget()
{
delete ui;
}
void CatalogWidget::prepForNewDisk(QString filename, DiskFile *disk)
{
m_disk = disk;
m_diskname = filename;
}
void CatalogWidget::processNewlyLoadedDisk(QString diskfilename, DiskFile *disk)
{
if (m_disk == disk) {
QUrl url = QUrl::fromLocalFile(diskfilename);
QString shortfilename = url.fileName();
QFontMetrics *fm = new QFontMetrics(ui->catalog_list->font());
QRect maxrect;
ui->volume_label->setText(shortfilename);
foreach(FileDescriptiveEntry fde, m_disk->getAllFDEs()) {
QString filetype = fde.fileType();
QString filename = AppleString(fde.filename).printable().simplified();
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);
ui->catalog_list->addItem(new QListWidgetItem(text));
QRect rect = fm->boundingRect(text);
if (rect.width() > maxrect.width()) {
maxrect = rect;
}
}
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();
}