]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/filepicker.cpp
More incremental improvements to the "Insert Cart" dialog...
[virtualjaguar] / src / gui / filepicker.cpp
1 //
2 // filepicker.cpp - A ROM chooser
3 //
4 // by James L. Hammons
5 // (C) 2010 Underground Software
6 //
7 // JLH = James L. Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  01/22/2010  Created this file
12 // JLH  02/06/2010  Modified to use Qt model/view framework
13 //
14
15 #include "filepicker.h"
16
17 #include "filedb.h"
18 #include "filelistmodel.h"
19 #include "filethread.h"
20 #include "imagedelegate.h"
21 //#include "settings.h"
22 //#include "types.h"
23
24 /*
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.
30
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.
33
34 Ideally, the label will go into the archive along with the ROM image, but that's
35 for the future...
36 Maybe box art, screenshots will go as well...
37
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.
40 */
41
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)
45 {
46         setWindowTitle("Insert Cartridge...");
47
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());
55
56 //      QVBoxLayout * layout = new QVBoxLayout;
57         QHBoxLayout * layout = new QHBoxLayout;
58         setLayout(layout);
59         layout->addWidget(fileList);
60
61         // Weird note: This layout has to be added *before* putting anything into it...
62         QVBoxLayout * vLayout = new QVBoxLayout;
63         layout->addLayout(vLayout);
64
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"));
71         painter.end();
72         image->setPixmap(QPixmap::fromImage(cartImg));
73         image->setMargin(4);
74         vLayout->addWidget(image);
75
76         QLabel * text1 = new QLabel(QString(tr(
77                 "<h2>Attack of the Mutant Penguins (World)</h2>"
78         )));
79         text1->setMargin(6);
80         text1->setAlignment(Qt::AlignCenter);
81         vLayout->addWidget(text1);
82
83         QLabel * text2 = new QLabel(QString(tr(
84                 "<table>"
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>"
89                 "</table>"
90         )));
91         vLayout->addWidget(text2);
92
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 *)));
96         fileThread->Go();
97 /*
98 New sizes: 373x172 (label), 420x340 (cart)
99 */
100 }
101
102 //
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.
105 //
106 void FilePickerWindow::AddFileToList(unsigned long index)
107 {
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);
112 }
113
114 void FilePickerWindow::AddFileToList2(unsigned long index, QString str, QImage * img)
115 {
116 printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name);
117         if (img)
118                 model->AddData(index, str, *img);
119         else
120                 model->AddData(index, str, QImage());
121 }
122
123 /*
124     Super Duper Awesome Guy (World)
125
126          Type: 4MB Cartridge
127         CRC32: FEDCBA98
128 Compatibility: DOES NOT WORK
129         Notes: Universal Header detected; Requires DSP
130
131
132     Stupid Homebrew Game That Sux
133
134          Type: ABS/COF Executable (43853 bytes)
135         CRC32: 76543210
136 Compatibility: Unknown
137         Notes: $4000 Load, $4000 Run
138
139
140     Action Hopscotch Plus (Prototype)
141
142          Type: 2MB Alpine ROM
143         CRC32: 44889921
144 Compatibility: 80% (or ****)
145         Notes: EEPROM available
146
147
148 */
149
150