+ model->AddData(index, str, QImage(), size, haveUniversalHeader, fileType, crc);
+}
+
+void FilePickerWindow::LoadButtonPressed(void)
+{
+ // TODO: Get the text of the current selection, call the MainWin slot for loading
+ emit(RequestLoad(currentFile));
+ hide();
+}
+
+//
+// This slot gets called when the QListView gets clicked on. Updates
+// the cart graphic and accompanying text.
+//
+void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModelIndex &/*previous*/)
+{
+#if 0
+ QString s = current.model()->data(current, Qt::EditRole).toString();
+ unsigned long i = current.model()->data(current, Qt::DisplayRole).toUInt();
+ QImage label = current.model()->data(current, Qt::DecorationRole).value<QImage>();
+// printf("FPW: %s\n", s.toAscii().data());
+ unsigned long fileSize = current.model()->data(current, Qt::WhatsThisRole).toUInt();
+#else
+// QString s = current.model()->data(current, FLM_FILENAME).toString();
+ currentFile = current.model()->data(current, FLM_FILENAME).toString();
+ unsigned long i = current.model()->data(current, FLM_INDEX).toUInt();
+ QImage label = current.model()->data(current, FLM_LABEL).value<QImage>();
+ unsigned long fileSize = current.model()->data(current, FLM_FILESIZE).toUInt();
+ bool haveUniversalHeader = current.model()->data(current, FLM_UNIVERSALHDR).toBool();
+ unsigned long fileType = current.model()->data(current, FLM_FILETYPE).toUInt();
+ uint32 crc = (uint32)current.model()->data(current, FLM_CRC).toUInt();
+// printf("FPW: %s\n", s.toAscii().data());
+ bool haveUnknown = (i == 0xFFFFFFFF ? true : false);
+#endif
+
+ // Disallow loading completely unknown files, but allow all others.
+ insertCart->setEnabled(haveUnknown && (fileType == JST_NONE) ? false : true);
+//hm.
+//currentFile = s;
+
+//373x172 is label size...
+//365x168 now...
+ if (!label.isNull())
+ {
+/*
+ QImage cartImg(":/res/cart-blank.png");
+ QPainter painter(&cartImg);
+ painter.drawPixmap(23, 87, QPixmap(":/res/label-blank.png"));
+ painter.end();
+ cartSmall = cartImg.scaled(488/4, 395/4, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+*/
+ QImage cart(":/res/cart-blank.png");
+ QPainter painter(&cart);
+//Though this should probably be done when this is loaded, instead of every time here...
+//QImage scaledImg = label.scaled(373, 172, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+//painter.drawPixmap(23, 87, QPixmap::fromImage(scaledImg));
+ // Now, looks like it is...
+// painter.drawPixmap(23, 87, QPixmap::fromImage(label));
+ painter.drawPixmap(27, 89, QPixmap::fromImage(label));
+// painter.drawPixmap(23, 87, 373, 172, QPixmap::fromImage(label));
+
+// Well, heck. This should be done to the label *before* we get here.
+ painter.drawPixmap(27, 89, QPixmap::fromImage(QImage(":/res/upper-left.png")));
+ painter.drawPixmap(27+355, 89, QPixmap::fromImage(QImage(":/res/upper-right.png")));
+
+ painter.end();
+ cartImage->setPixmap(QPixmap::fromImage(cart));
+ }
+ else
+ {
+ // We should try to be intelligent with our updates here, and only redraw when
+ // we're going from a selection with a label to a selection without. Now, we
+ // redraw regardless.
+ QImage cart;
+
+// We now have to sources of data for the passed in files:
+// - The file DB
+// - The file type detection
+// This means we have to be mindful of what's passed back by that stuff.
+// We can assume that if it wasn't found in the DB, then the fileType
+// should be valid.
+// The DB takes precedence over the fileType.
+ if ((!haveUnknown && (romList[i].flags & FF_ROM))
+ || (haveUnknown && (fileType == JST_ROM) && !haveUniversalHeader))
+ {
+ cart = QImage(":/res/cart-blank.png");
+ QPainter painter(&cart);
+ painter.drawPixmap(27, 89, QPixmap::fromImage(QImage(":/res/label-blank.png")));
+ painter.end();
+ }
+ else if ((!haveUnknown && (romList[i].flags & FF_ALPINE))
+ || (haveUnknown
+ && ((fileType == JST_ALPINE) || ((fileType == JST_ROM) && haveUniversalHeader))))
+ {
+ if (haveUniversalHeader)
+ cart = QImage(":/res/skunkboard-file.png");
+ else
+ cart = QImage(":/res/alpine-file.png");
+ }
+ else if (haveUnknown && (fileType == JST_ABS_TYPE1 || fileType == JST_ABS_TYPE2
+ || fileType == JST_JAGSERVER) || fileType == JST_WTFOMGBBQ)
+ {
+ cart = QImage(":/res/homebrew-file.png");
+ }
+ else
+ cart = QImage(":/res/unknown-file.png");
+
+ cartImage->setPixmap(QPixmap::fromImage(cart));
+ }
+
+//1048576
+//2097152
+//4194304
+ if (!haveUnknown)
+ prettyFilename = romList[i].name;
+ else
+ {
+ int lastSlashPos = currentFile.lastIndexOf('/');
+ prettyFilename = "\"" + currentFile.mid(lastSlashPos + 1) + "\"";
+ }
+
+ // Ensure that the title isn't longer than the width of the dialog...
+#if 1
+ title->setText(QString("<h2>%1</h2>").arg(prettyFilename));
+#else
+ // This doesn't work...
+ QFontMetrics metrics(title->font());
+ QString elidedText = metrics.elidedText(QString("<h2>%1</h2>").arg(prettyFilename), Qt::ElideRight, title->sizeHint().width());
+ title->setText(elidedText);
+#endif
+
+//Kludge for now, we'll have to fix this later...
+// So let's fix it now!
+ QString fileTypeString, crcString, notes, compatibility;
+
+#if 0
+ if (!haveUnknown)
+ {
+ if (romList[i].flags & FF_ROM)
+ fileTypeString = QString(tr("%1MB Cartridge")).arg(fileSize / 1048576);
+ else if (romList[i].flags & FF_ALPINE)
+ fileTypeString = QString(tr("%1MB Alpine ROM")).arg(fileSize / 1048576);
+ else
+ fileTypeString = QString(tr("*** UNKNOWN *** (%1 bytes)")).arg(fileSize);
+ }
+#else
+ if ((!haveUnknown && (romList[i].flags & FF_ROM))
+ || (haveUnknown && (fileType == JST_ROM) && !haveUniversalHeader))
+ fileTypeString = QString(tr("%1MB Cartridge")).arg(fileSize / 1048576);
+ else if ((!haveUnknown && (romList[i].flags & FF_ALPINE))
+ || (haveUnknown
+ && ((fileType == JST_ALPINE) || ((fileType == JST_ROM) && haveUniversalHeader))))
+ {
+ if (haveUniversalHeader)
+ fileTypeString = QString(tr("%1MB Alpine ROM w/Universal Header"));
+ else
+ fileTypeString = QString(tr("%1MB Alpine ROM"));
+
+ fileTypeString = fileTypeString.arg((fileSize + 8192) / 1048576);
+ }
+ else if (haveUnknown && (fileType == JST_ABS_TYPE1 || fileType == JST_ABS_TYPE2))
+ fileTypeString = QString(tr("ABS/COF Executable (%1 bytes)")).arg(fileSize);
+ else if (haveUnknown && (fileType == JST_JAGSERVER))
+ fileTypeString = QString(tr("Jaguar Server Executable (%1 bytes)")).arg(fileSize);
+ else
+ fileTypeString = QString(tr("*** UNKNOWN *** (%1 bytes)")).arg(fileSize);
+#endif
+
+// crcString = QString("%1").arg(romList[i].crc32, 8, 16, QChar('0')).toUpper();
+ crcString = QString("%1").arg(crc, 8, 16, QChar('0')).toUpper();
+
+ if (!haveUnknown && (romList[i].flags & FF_NON_WORKING))
+ compatibility = "DOES NOT WORK";
+ else
+ compatibility = "Unknown";
+
+ // This is going to need some formatting love before long...
+ if (!haveUnknown && (romList[i].flags & FF_BAD_DUMP))
+ notes = "<b>BAD DUMP</b>";
+
+// if (haveUniversalHeader)
+// notes += " Universal Header detected";
+
+ if (!haveUnknown && (romList[i].flags & FF_REQ_BIOS))
+ notes += " Requires BIOS";
+
+ if (!haveUnknown && (romList[i].flags & FF_REQ_DSP))
+ notes += " Requires DSP";
+
+ if (!haveUnknown && (romList[i].flags & FF_VERIFIED))
+ notes += " <i>(Verified)</i>";
+
+ data->setText(QString("%1<br>%2<br>%3<br>%4")
+ .arg(fileTypeString).arg(crcString).arg(compatibility).arg(notes));