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
13 // JLH 03/08/2010 Added large cart view and info text
16 #include "filepicker.h"
19 #include "filelistmodel.h"
20 #include "filethread.h"
21 #include "imagedelegate.h"
22 //#include "settings.h"
26 Our strategy here is like so:
27 Look at the files in the directory pointed to by ROMPath.
28 For each file in the directory, take the CRC32 of it and compare it to the CRC
29 in the romList[]. If there's a match, put it in a list and note it's index value
30 in romList for future reference.
32 When constructing the list, use the index to pull up an image of the cart and
33 put that in the list. User picks from a graphical image of the cart.
35 Ideally, the label will go into the archive along with the ROM image, but that's
37 Maybe box art, screenshots will go as well...
39 I'm thinking compatibility info should be displayed as well... Just to stop the
40 inevitable stupid questions from people too lazy to do basic research for themselves.
45 - Should keep a QImage of the blank cart with blank label
46 - Should keep a QImage of the blank cart? (For overpainting the ROMs label)
47 - Should we have a special Alpine image? Floppy image (for COF/ABS)?
49 - Need some way of keeping track of cart size and compatibility info
50 [compat info needs to be BAD DUMP or % of what works]
51 - Need to properly scale the thumbnails images in the list
54 //could use Window as well...
55 //FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)
56 FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
58 setWindowTitle(tr("Insert Cartridge..."));
60 //is there any reason why this must be cast as a QAbstractListModel? No
61 //Also, need to think about data structure for the model...
62 model = new FileListModel;
63 fileList = new QListView;
64 fileList->setModel(model);
65 // fileList->setItemDelegate(new ImageDelegate(this));
66 fileList->setItemDelegate(new ImageDelegate());
68 // QVBoxLayout * layout = new QVBoxLayout;
69 QHBoxLayout * layout = new QHBoxLayout;
71 layout->addWidget(fileList);
73 // Weird note: This layout has to be added *before* putting anything into it...
74 QVBoxLayout * vLayout = new QVBoxLayout;
75 layout->addLayout(vLayout);
77 cartImage = new QLabel;
78 QImage cartImg(":/res/cart-blank.png");
79 QPainter painter(&cartImg);
80 painter.drawPixmap(23, 87, QPixmap(":/res/label-blank.png"));
82 cartImage->setPixmap(QPixmap::fromImage(cartImg));
83 cartImage->setMargin(4);
84 vLayout->addWidget(cartImage);
86 title = new QLabel(QString(tr("<h2>...</h2>")));
88 title->setAlignment(Qt::AlignCenter);
89 vLayout->addWidget(title);
92 QHBoxLayout * dataLayout = new QHBoxLayout;
93 vLayout->addLayout(dataLayout);
95 QLabel * labels = new QLabel(QString(tr(
98 "<b>Compatibility: </b><br>"
101 labels->setAlignment(Qt::AlignRight);
102 labels->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
103 dataLayout->addWidget(labels);
104 data = new QLabel(QString(tr(
108 "Universal Header detected; Requires DSP"
110 data->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
111 dataLayout->addWidget(data);
113 QLabel * text2 = new QLabel(QString(tr(
115 "<tr><td align='right'><b>Type: </b></td><td>4MB Cartridge</td></tr>"
116 "<tr><td align='right'><b>CRC32: </b></td><td>FEDCBA98</td></tr>"
117 "<tr><td align='right'><b>Compatibility: </b></td><td>DOES NOT WORK</td></tr>"
118 "<tr><td align='right'><b>Notes: </b></td><td>Universal Header detected; Requires DSP</td></tr>"
121 vLayout->addWidget(text2);
124 fileThread = new FileThread(this);
125 // connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long)));
126 connect(fileThread, SIGNAL(FoundAFile2(unsigned long, QString, QImage *)), this, SLOT(AddFileToList2(unsigned long, QString, QImage *)));
129 New sizes: 373x172 (label), 420x340 (cart)
132 // QItemSelectionModel * ism = fileList->selectionModel();
133 // connect(ism, SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(UpdateSelection(const QModelIndex &, const QModelIndex &)));
134 connect(fileList->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(UpdateSelection(const QModelIndex &, const QModelIndex &)));
138 // This slot gets called by the FileThread's run() function when it finds a
139 // match in the filesystem to a ROM on our CRC list.
141 void FilePickerWindow::AddFileToList(unsigned long index)
143 printf("FilePickerWindow: Found match [%s]...\n", romList[index].name);
144 // NOTE: The model *ignores* what you send it, so this is crap. !!! FIX !!! [DONE, somewhat]
145 // model->AddData(QIcon(":/res/generic.png"));
146 model->AddData(index);
149 void FilePickerWindow::AddFileToList2(unsigned long index, QString str, QImage * img)
151 printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name);
153 model->AddData(index, str, *img);
155 model->AddData(index, str, QImage());
159 // This slot gets called when the QListView gets clicked on. Updates
160 // the cart graphic and accompanying text.
162 void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModelIndex &/*previous*/)
164 QString s = current.model()->data(current, Qt::EditRole).toString();
165 unsigned long i = current.model()->data(current, Qt::DisplayRole).toUInt();
166 QImage label = current.model()->data(current, Qt::DecorationRole).value<QImage>();
167 // printf("FPW: %s\n", s.toAscii().data());
171 QImage cart(":/res/cart-blank.png");
172 QPainter painter(&cart);
173 painter.drawPixmap(23, 87, QPixmap::fromImage(label));
175 cartImage->setPixmap(QPixmap::fromImage(cart));
178 title->setText(QString("<h2>%1</h2>").arg(romList[i].name));
179 QString crcString = QString("%1").arg(romList[i].crc32, 8, 16, QChar('0')).toUpper();
180 data->setText(QString("%1<br>%2<br>%3<br>%4").arg("Cart").arg(crcString).arg("100%").arg("Requires BIOS"));
184 Super Duper Awesome Guy (World)
188 Compatibility: DOES NOT WORK
189 Notes: Universal Header detected; Requires DSP
192 Stupid Homebrew Game That Sux
194 Type: ABS/COF Executable (43853 bytes)
196 Compatibility: Unknown
197 Notes: $4000 Load, $4000 Run
200 Action Hopscotch Plus (Prototype)
204 Compatibility: 80% (or ****)
205 Notes: EEPROM available