2 // filepicker.cpp - A ROM chooser
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -------------------------------------------------------------
11 // JLH 01/22/2010 Created this file
12 // JLH 02/06/2010 Modified to use Qt model/view framework
15 #include "filepicker.h"
18 #include "filelistmodel.h"
19 #include "filethread.h"
20 #include "imagedelegate.h"
21 //#include "settings.h"
25 Our strategy here is like so:
26 Look at the files in the directory pointed to by ROMPath.
27 For each file in the directory, take the CRC32 of it and compare it to the CRC
28 in the romList[]. If there's a match, put it in a list and note it's index value
29 in romList for future reference.
31 When constructing the list, use the index to pull up an image of the cart and
32 put that in the list. User picks from a graphical image of the cart.
34 Ideally, the label will go into the archive along with the ROM image, but that's
36 Maybe box art, screenshots will go as well...
38 I'm thinking compatibility info should be displayed as well... Just to stop the
39 inevitable stupid questions from people too lazy to do basic research for themselves.
42 //could use Window as well...
43 //FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)
44 FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
46 setWindowTitle("Insert Cartridge...");
48 //is there any reason why this must be cast as a QAbstractListModel? No
49 //Also, need to think about data structure for the model...
50 model = new FileListModel;
51 fileList = new QListView;
52 fileList->setModel(model);
53 // fileList->setItemDelegate(new ImageDelegate(this));
54 fileList->setItemDelegate(new ImageDelegate());
56 // QVBoxLayout * layout = new QVBoxLayout;
57 QHBoxLayout * layout = new QHBoxLayout;
59 layout->addWidget(fileList);
61 // Weird note: This layout has to be added *before* putting anything into it...
62 QVBoxLayout * vLayout = new QVBoxLayout;
63 layout->addLayout(vLayout);
65 QLabel * image = new QLabel;
66 // image->setAlignment(Qt::AlignRight);
67 // image->setPixmap(QPixmap(":/res/cart-blank.png"));
68 QImage cartImg(":/res/cart-blank.png");
69 QPainter painter(&cartImg);
70 painter.drawPixmap(23, 87, 373, 172, QPixmap(":/res/label-blank.png"));
72 image->setPixmap(QPixmap::fromImage(cartImg));
74 vLayout->addWidget(image);
76 QLabel * text1 = new QLabel(QString(tr(
77 "<h2>Attack of the Mutant Penguins (World)</h2>"
80 text1->setAlignment(Qt::AlignCenter);
81 vLayout->addWidget(text1);
83 QLabel * text2 = new QLabel(QString(tr(
85 "<tr><td align='right'><b>Type: </b></td><td>4MB Cartridge</td></tr>"
86 "<tr><td align='right'><b>CRC32: </b></td><td>FEDCBA98</td></tr>"
87 "<tr><td align='right'><b>Compatibility: </b></td><td>DOES NOT WORK</td></tr>"
88 "<tr><td align='right'><b>Notes: </b></td><td>Universal Header detected; Requires DSP</td></tr>"
91 vLayout->addWidget(text2);
93 fileThread = new FileThread(this);
94 // connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long)));
95 connect(fileThread, SIGNAL(FoundAFile2(unsigned long, QString, QImage *)), this, SLOT(AddFileToList2(unsigned long, QString, QImage *)));
98 New sizes: 373x172 (label), 420x340 (cart)
103 // This slot gets called by the FileThread's run() function when it finds a
104 // match in the filesystem to a ROM on our CRC list.
106 void FilePickerWindow::AddFileToList(unsigned long index)
108 printf("FilePickerWindow: Found match [%s]...\n", romList[index].name);
109 // NOTE: The model *ignores* what you send it, so this is crap. !!! FIX !!! [DONE, somewhat]
110 // model->AddData(QIcon(":/res/generic.png"));
111 model->AddData(index);
114 void FilePickerWindow::AddFileToList2(unsigned long index, QString str, QImage * img)
116 printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name);
118 model->AddData(index, str, *img);
120 model->AddData(index, str, QImage());
124 Super Duper Awesome Guy (World)
128 Compatibility: DOES NOT WORK
129 Notes: Universal Header detected; Requires DSP
132 Stupid Homebrew Game That Sux
134 Type: ABS/COF Executable (43853 bytes)
136 Compatibility: Unknown
137 Notes: $4000 Load, $4000 Run
140 Action Hopscotch Plus (Prototype)
144 Compatibility: 80% (or ****)
145 Notes: EEPROM available