]> Shamusworld >> Repos - virtualjaguar/commitdiff
Moving towards a better file picker... :-)
authorShamus Hammons <jlhamm@acm.org>
Fri, 12 Feb 2010 22:18:49 +0000 (22:18 +0000)
committerShamus Hammons <jlhamm@acm.org>
Fri, 12 Feb 2010 22:18:49 +0000 (22:18 +0000)
src/gui/filelistmodel.cpp
src/gui/filelistmodel.h
src/gui/filepicker.cpp
src/gui/filepicker.h
src/gui/filethread.cpp
src/gui/filethread.h
src/gui/imagedelegate.cpp
src/gui/vj.qrc

index 2730a4509ad82e07c8eb0b0ce69ab586e12f0199..a975b82cc2e66f860ef7bdf37082086648869bd0 100644 (file)
@@ -26,13 +26,15 @@ FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent
 
 int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const
 {
-       return pixList.size();
+//     return pixList.size();
+       return dbIndex.size();
 }
 
 QVariant FileListModel::data(const QModelIndex & index, int role) const
 {
 //     return QVariant();
-       return pixList.at(index.row());
+//     return pixList.at(index.row());
+       return (uint)dbIndex.at(index.row());
 }
 
 QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role/*= Qt::DisplayRole*/) const
@@ -62,6 +64,12 @@ void FileListModel::AddData(QIcon pix)
        reset();
 }
 
+void FileListModel::AddData(unsigned long index)
+{
+       dbIndex.push_back(index);
+       reset();
+}
+
 
 #if 0
 
index 4828d383a10a3a83f400afb4e944ddf9b0d14b1a..1599ca5fdddec0d5bfd6cb03b5bf943f0865c565 100644 (file)
@@ -21,9 +21,11 @@ class FileListModel: public QAbstractListModel
                QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 
                void AddData(QIcon pix);
+               void AddData(unsigned long);
 
        private:
                std::vector<QIcon> pixList;
+               std::vector<unsigned long> dbIndex;
 };
 
 #endif // __FILELISTMODEL_H__
index 52117362d37b98184392f298864bab397efeda1f..a841d885866ae305b992ef2c77bfc6f184de0f35 100644 (file)
 
 #include "filepicker.h"
 
-#include "crc32.h"
 #include "filelistmodel.h"
 #include "filethread.h"
 #include "imagedelegate.h"
 #include "settings.h"
 #include "types.h"
 
-struct RomIdentifier
-{
-       const uint32 crc32;
-       const char name[128];
-       const char file[128];
-};
-
-RomIdentifier romList2[] = {
-       { 0x0509C85E, "Raiden (World)", "" },
-       { 0x08F15576, "Iron Soldier (World) (v1.04)", "" },
-       { 0x0957A072, "Kasumi Ninja (World)", "" },
-       { 0x0AC83D77, "NBA Jam T.E. (World)", "" },
-       { 0x0EC5369D, "Evolution - Dino Dudes (World)", "" },
-       { 0x0F6A1C2C, "Ultra Vortek (World)", "" },
-       { 0x14915F20, "White Men Can't Jump (World)", "" },
-       { 0x1660F070, "Power Drive Rally (World)", "" },
-       { 0x1E451446, "Trevor McFur in the Crescent Galaxy (World)", "" },
-       { 0x27594C6A, "Defender 2000 (World)", "" },
-       { 0x2E17D5DA, "Bubsy in Fractured Furry Tales (World)", "" },
-       { 0x348E6449, "Double Dragon V - The Shadow Falls (World)", "" },
-       { 0x3615AF6A, "Fever Pitch Soccer (World) (En,Fr,De,Es,It)", "" },
-       { 0x38A130ED, "Troy Aikman NFL Football (World)", "" },
-       { 0x3C044941, "Skyhammer (World)", "" },
-       { 0x42A13EC5, "Soccer Kid (World)", "" },
-       { 0x47EBC158, "Theme Park (World)", "" },
-       { 0x4899628F, "Hover Strike (World)", "" },
-       { 0x53DF6440, "Space War 2000 (World)", "" },
-       { 0x55A0669C, "[BIOS] Atari Jaguar Developer CD (World)", "" },
-       { 0x58272540, "Syndicate (World)", "" },
-       { 0x5A101212, "Sensible Soccer - International Edition (World)", "" },
-       { 0x5B6BB205, "Ruiner Pinball (World)", "" },
-       { 0x5CFF14AB, "Pinball Fantasies (World)", "" },
-       { 0x5E2CDBC0, "Doom (World)", "" },
-       { 0x61C7EEC0, "Zero 5 (World)", "" },
-       { 0x67F9AB3A, "Battle Sphere Gold (World)", "" },
-       { 0x687068D5, "[BIOS] Atari Jaguar CD (World)", "" },
-       { 0x6B2B95AD, "Tempest 2000 (World)", "" },
-       { 0x6EB774EB, "Worms (World)", "" },
-       { 0x6F8B2547, "Super Burnout (World)", "" },
-       { 0x817A2273, "Pitfall - The Mayan Adventure (World)", "" },
-       { 0x8975F48B, "Zool 2 (World)", "" },
-       { 0x8D15DBC6, "[BIOS] Atari Jaguar Stubulator '94 (World)", "" },
-       { 0x8FEA5AB0, "Dragon - The Bruce Lee Story (World)", "" },
-       { 0x97EB4651, "I-War (World)", "" },
-       { 0xA27823D8, "Ultra Vortek (World) (v0.94) (Beta)", "" },
-       { 0xA56D0798, "Protector - Special Edition (World)", "" },
-       { 0xA9F8A00E, "Rayman (World)", "" },
-       { 0xB14C4753, "Fight for Life (World)", "" },
-       { 0xBCB1A4BF, "Brutal Sports Football (World)", "" },
-       { 0xBDA405C6, "Cannon Fodder (World)", "" },
-       { 0xBDE67498, "Cybermorph (World) (Rev 1)", "" },
-       { 0xC5562581, "Zoop! (World)", "" },
-       { 0xC654681B, "Total Carnage (World)", "" },
-       { 0xC6C7BA62, "Fight for Life (World) (Alt)", "" },
-       { 0xC9608717, "Val d'Isere Skiing and Snowboarding (World)", "" },
-       { 0xCBFD822A, "Air Cars (World)", "" },
-       { 0xCD5BF827, "Attack of the Mutant Penguins (World)", "" },
-       { 0xD6C19E34, "Iron Soldier 2 (World)", "" },
-       { 0xDA9C4162, "Missile Command 3D (World)", "" },
-       { 0xDC187F82, "Alien vs Predator (World)", "" },
-       { 0xDE55DCC7, "Flashback - The Quest for Identity (World) (En,Fr)", "" },
-       { 0xE28756DE, "Atari Karts (World)", "" },
-       { 0xE60277BB, "[BIOS] Atari Jaguar Stubulator '93 (World)", "" },
-       { 0xE91BD644, "Wolfenstein 3D (World)", "" },
-       { 0xEC22F572, "SuperCross 3D (World)", "" },
-       { 0xECF854E7, "Cybermorph (World) (Rev 2)", "" },
-       { 0xEEE8D61D, "Club Drive (World)", "" },
-       { 0xF0360DB3, "Hyper Force (World)", "" },
-       { 0xFA7775AE, "Checkered Flag (World)", "" },
-       { 0xFAE31DD0, "Flip Out! (World)", "" },
-       { 0xFB731AAA, "[BIOS] Atari Jaguar (World)", "" },
-       { 0xFFFFFFFF, "***END***", "" }
-};
-
 /*
 Our strategy here is like so:
 Look at the files in the directory pointed to by ROMPath.
@@ -108,90 +33,42 @@ put that in the list. User picks from a graphical image of the cart.
 Ideally, the label will go into the archive along with the ROM image, but that's
 for the future...
 Maybe box art, screenshots will go as well...
+
+I'm thinking compatibility info should be displayed as well... Just to stop the
+inevitable stupid questions from people too lazy to do basic research for themselves.
 */
 
-//FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)//could use Window as well...
+//could use Window as well...
+//FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)
 FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
 {
        setWindowTitle("Insert Cartridge...");
 
-#if 0
-       fileList2 = new QListWidget(this);
-//     addWidget(fileList);
-
-       QVBoxLayout * layout = new QVBoxLayout();
-//     layout->setSizeConstraint(QLayout::SetFixedSize);
-       setLayout(layout);
-
-       layout->addWidget(fileList2);
-
-//     PopulateList();
-       fileThread = new FileThread(this);
-
-       /*bool b =*/ connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long)));
-//printf("FilePickerWindow: Connection to FileThread %s...\n", (b ? "succeeded" : "failed"));
-
-       fileThread->Go(fileList2);
-#else
-//is there any reason why this must be cast as a QAbstractListModel?
+//is there any reason why this must be cast as a QAbstractListModel? No
 //Also, need to think about data structure for the model...
-       model = new FileListModel();
-       fileList = new QListView();
+       model = new FileListModel;
+       fileList = new QListView;
        fileList->setModel(model);
-       ImageDelegate * delegate = new ImageDelegate(this);
-       fileList->setItemDelegate(delegate);
+       fileList->setItemDelegate(new ImageDelegate(this));
 
        QVBoxLayout * layout = new QVBoxLayout;
        setLayout(layout);
-
        layout->addWidget(fileList);
-       ((FileListModel *)model)->AddData(QIcon(":/res/generic.png"));
-       ((FileListModel *)model)->AddData(QIcon(":/res/generic.png"));
-#endif
-}
-
-// Need a slot here to pickup stuff from the thread...
 
-void FilePickerWindow::AddFileToList(unsigned long index)
-{
-       printf("--> Found CRC: %08X...\n", romList2[index].crc32);
+       fileThread = new FileThread(this);
+       connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long)));
+       fileThread->Go();
 }
 
-
-/*
-void FilePickerWindow::PopulateList(void)
+//
+// This slot gets called by the FileThread's run() function when it finds a
+// match in the filesystem to a ROM on our CRC list.
+//
+void FilePickerWindow::AddFileToList(unsigned long index)
 {
-       QDir romDir(vjs.ROMPath);
-       QFileInfoList list = romDir.entryInfoList();
-
-       for(int i=0; i<list.size(); i++)
-       {
-               QFileInfo fileInfo = list.at(i);
-//         std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
-//                                                 .arg(fileInfo.fileName()));
-//         std::cout << std::endl;
-               QFile file(romDir.filePath(fileInfo.fileName()));
-               uint8 * buffer = new uint8[fileInfo.size()];
-
-               if (file.open(QIODevice::ReadOnly))
-               {
-                       file.read((char *)buffer, fileInfo.size());
-                       uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size());
-                       file.close();
-//printf("FilePickerWindow: File crc == %08X...\n", crc);
-
-                       for(int j=0; romList2[j].crc32 != 0xFFFFFFFF; j++)
-                       {
-                               if (romList2[j].crc32 == crc)
-                               {
-printf("FilePickerWindow: Found match [%s]...\n", romList2[j].name);
-                                       new QListWidgetItem(QIcon(":/res/generic.png"), romList2[j].name, fileList);
-                                       break;
-                               }
-                       }
-               }
-
-               delete[] buffer;
-       }
+printf("FilePickerWindow: Found match [%s]...\n", romList[index].name);
+//printf("--> Found CRC: %08X...\n", romList2[index].crc32);
+       // NOTE: The model *ignores* what you send it, so this is crap. !!! FIX !!!
+//     model->AddData(QIcon(":/res/generic.png"));
+       model->AddData(index);
 }
-*/
index 543de0ebeba39c3a39039fd8c798275b3f4fd341..f0b5143babc52667575149808d9a2c5756fc8555 100644 (file)
@@ -8,7 +8,7 @@
 // Forward declarations
 class QListWidget;
 class FileThread;
-//class FileListModel;
+class FileListModel;
 class QListView;
 
 class FilePickerWindow: public QWidget
@@ -28,6 +28,7 @@ class FilePickerWindow: public QWidget
        private:
                QListWidget * fileList2;
                FileThread * fileThread;
-               QAbstractItemModel * model;
+//             QAbstractItemModel * model;
+               FileListModel * model;
                QListView * fileList;
 };
index 7ecb4532abc25e6d7c1d763511e423ddd3e50faa..a6ecd3fbd1dcbd3c435e058d3ee6f986286b52ef 100644 (file)
 #include "settings.h"
 //#include "types.h"
 
+#if 0
 struct RomIdentifier
 {
        const uint32 crc32;
        const char name[128];
        const char file[128];
 };
+#endif
 
 RomIdentifier romList[] = {
        { 0x0509C85E, "Raiden (World)", "" },
@@ -107,7 +109,7 @@ for the future...
 Maybe box art, screenshots will go as well...
 */
 
-FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), listWidget(NULL), abort(false)
+FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), /*listWidget(NULL),*/ abort(false)
 {
 }
 
@@ -121,13 +123,17 @@ FileThread::~FileThread()
        wait();
 }
 
-void FileThread::Go(QListWidget * lw)
+//void FileThread::Go(QListWidget * lw)
+void FileThread::Go(void)
 {
        QMutexLocker locker(&mutex);
-       this->listWidget = lw;
+//     this->listWidget = lw;
        start();
 }
 
+//
+// Here's the thread's actual execution path...
+//
 void FileThread::run(void)
 {
        QDir romDir(vjs.ROMPath);
@@ -165,8 +171,8 @@ printf("FileThread: Aborting!!!\n");
 
                        if (index != 0xFFFFFFFF)
                        {
-printf("FileThread: Found match [%s]...\n", romList[index].name);
-                               new QListWidgetItem(QIcon(":/res/generic.png"), romList[index].name, listWidget);
+//printf("FileThread: Found match [%s]...\n", romList[index].name);
+//                             new QListWidgetItem(QIcon(":/res/generic.png"), romList[index].name, listWidget);
 //                             emit FoundAFile(romList[index].crc32);
                                emit FoundAFile(index);
                        }
index 12c316fa52d2bfaa4427466b946190d44cd059de..6690dc6b0bf3fbb260e9b174b2588a919a4268b0 100644 (file)
@@ -9,7 +9,7 @@
 #include "types.h"
 
 // Forward declarations
-class QListWidget;
+//class QListWidget;
 
 class FileThread: public QThread
 {
@@ -18,7 +18,8 @@ class FileThread: public QThread
        public:
                FileThread(QObject * parent = 0);
                ~FileThread();
-               void Go(QListWidget * lw);
+//             void Go(QListWidget * lw);
+               void Go(void);
 
        signals:
                void FoundAFile(unsigned long index);
@@ -28,10 +29,19 @@ class FileThread: public QThread
                uint32 FindCRCIndexInFileList(uint32);
 
        private:
-               QListWidget * listWidget;
+//             QListWidget * listWidget;
                QMutex mutex;
                QWaitCondition condition;
                bool abort;
 };
 
+struct RomIdentifier
+{
+       const uint32 crc32;
+       const char name[128];
+       const char file[128];
+};
+
+extern RomIdentifier romList[];
+
 #endif // __FILETHREAD_H__
index 76e690b8be9ba7bee6c1662f4455e7a58a2338f0..70879151f081dc3d4f47a8cbdacf288fd94f63db 100644 (file)
@@ -15,6 +15,8 @@
 // class utilized in FilePicker.
 
 #include "imagedelegate.h"
+#warning "Move ROM database to its own file... !!! FIX !!!"
+#include "filethread.h"
 
 
 ImageDelegate::ImageDelegate(QObject * parent): QAbstractItemDelegate(parent), pixelSize(12)
@@ -71,7 +73,11 @@ The foreground of the item (the circle representing a pixel) must be rendered us
 #else
 //     painter->drawPixmap(option.rect.x()+8, option.rect.y()+8, 200, 94, QPixmap(":/res/labels/rayman.jpg"));
        painter->drawPixmap(option.rect.x(), option.rect.y(), 488/2, 395/2, QPixmap(":/res/cart-blank.png"));
-       painter->drawPixmap(option.rect.x()+13, option.rect.y()+51, 433/2, 203/2, QPixmap(":/res/labels/rayman.jpg"));
+//     painter->drawPixmap(option.rect.x()+13, option.rect.y()+51, 433/2, 203/2, QPixmap(":/res/labels/rayman.jpg"));
+       painter->drawPixmap(option.rect.x()+14, option.rect.y()+50, 433/2, 203/2, QPixmap(":/res/label-blank.png"));
+//Need to query the model for the data we're supposed to draw here...
+       unsigned long i = index.model()->data(index, Qt::DisplayRole).toUInt();
+       painter->drawText(17, 73, QString(romList[i].name));
 //26x100
 #endif
        painter->restore();
index f55a393b843828ce0e6f29ef5f16bc09d9a4633f..4f7e92ab9b0ae07c93333a0579919ad92c4773d4 100644 (file)
@@ -7,6 +7,7 @@
        <file>../../res/zoom300.png</file>
        <file>../../res/generic.png</file>
        <file>../../res/cart-blank.png</file>
+       <file>../../res/label-blank.png</file>
        <file>../../res/vj_title_small.png</file>
        <file>../../res/labels/rayman.jpg</file>
 </qresource>