]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/filepicker.cpp
Moving towards a better file picker... :-)
[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 "filelistmodel.h"
18 #include "filethread.h"
19 #include "imagedelegate.h"
20 #include "settings.h"
21 #include "types.h"
22
23 /*
24 Our strategy here is like so:
25 Look at the files in the directory pointed to by ROMPath.
26 For each file in the directory, take the CRC32 of it and compare it to the CRC
27 in the romList[]. If there's a match, put it in a list and note it's index value
28 in romList for future reference.
29
30 When constructing the list, use the index to pull up an image of the cart and
31 put that in the list. User picks from a graphical image of the cart.
32
33 Ideally, the label will go into the archive along with the ROM image, but that's
34 for the future...
35 Maybe box art, screenshots will go as well...
36
37 I'm thinking compatibility info should be displayed as well... Just to stop the
38 inevitable stupid questions from people too lazy to do basic research for themselves.
39 */
40
41 //could use Window as well...
42 //FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)
43 FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
44 {
45         setWindowTitle("Insert Cartridge...");
46
47 //is there any reason why this must be cast as a QAbstractListModel? No
48 //Also, need to think about data structure for the model...
49         model = new FileListModel;
50         fileList = new QListView;
51         fileList->setModel(model);
52         fileList->setItemDelegate(new ImageDelegate(this));
53
54         QVBoxLayout * layout = new QVBoxLayout;
55         setLayout(layout);
56         layout->addWidget(fileList);
57
58         fileThread = new FileThread(this);
59         connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long)));
60         fileThread->Go();
61 }
62
63 //
64 // This slot gets called by the FileThread's run() function when it finds a
65 // match in the filesystem to a ROM on our CRC list.
66 //
67 void FilePickerWindow::AddFileToList(unsigned long index)
68 {
69 printf("FilePickerWindow: Found match [%s]...\n", romList[index].name);
70 //printf("--> Found CRC: %08X...\n", romList2[index].crc32);
71         // NOTE: The model *ignores* what you send it, so this is crap. !!! FIX !!!
72 //      model->AddData(QIcon(":/res/generic.png"));
73         model->AddData(index);
74 }