]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/filepicker.cpp
Incremental improvements to the file picker, introduction of ImageDelegate
[virtualjaguar] / src / gui / filepicker.cpp
index 9146bdf446722c949c11d54f755514945fbe0063..52117362d37b98184392f298864bab397efeda1f 100644 (file)
@@ -9,11 +9,15 @@
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
 // JLH  01/22/2010  Created this file
+// JLH  02/06/2010  Modified to use Qt model/view framework
 //
 
 #include "filepicker.h"
 
 #include "crc32.h"
+#include "filelistmodel.h"
+#include "filethread.h"
+#include "imagedelegate.h"
 #include "settings.h"
 #include "types.h"
 
@@ -24,7 +28,7 @@ struct RomIdentifier
        const char file[128];
 };
 
-RomIdentifier romList[] = {
+RomIdentifier romList2[] = {
        { 0x0509C85E, "Raiden (World)", "" },
        { 0x08F15576, "Iron Soldier (World) (v1.04)", "" },
        { 0x0957A072, "Kasumi Ninja (World)", "" },
@@ -111,18 +115,50 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt:
 {
        setWindowTitle("Insert Cartridge...");
 
-       fileList = new QListWidget(this);
+#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?
+//Also, need to think about data structure for the model...
+       model = new FileListModel();
+       fileList = new QListView();
+       fileList->setModel(model);
+       ImageDelegate * delegate = new ImageDelegate(this);
+       fileList->setItemDelegate(delegate);
+
+       QVBoxLayout * layout = new QVBoxLayout;
+       setLayout(layout);
+
        layout->addWidget(fileList);
+       ((FileListModel *)model)->AddData(QIcon(":/res/generic.png"));
+       ((FileListModel *)model)->AddData(QIcon(":/res/generic.png"));
+#endif
+}
 
-       PopulateList();
+// Need a slot here to pickup stuff from the thread...
+
+void FilePickerWindow::AddFileToList(unsigned long index)
+{
+       printf("--> Found CRC: %08X...\n", romList2[index].crc32);
 }
 
+
+/*
 void FilePickerWindow::PopulateList(void)
 {
        QDir romDir(vjs.ROMPath);
@@ -144,12 +180,12 @@ void FilePickerWindow::PopulateList(void)
                        file.close();
 //printf("FilePickerWindow: File crc == %08X...\n", crc);
 
-                       for(int j=0; romList[j].crc32 != 0xFFFFFFFF; j++)
+                       for(int j=0; romList2[j].crc32 != 0xFFFFFFFF; j++)
                        {
-                               if (romList[j].crc32 == crc)
+                               if (romList2[j].crc32 == crc)
                                {
-printf("FilePickerWindow: Found match [%s]...\n", romList[j].name);
-                                       new QListWidgetItem(QIcon(":/res/generic.png"), romList[j].name, fileList);
+printf("FilePickerWindow: Found match [%s]...\n", romList2[j].name);
+                                       new QListWidgetItem(QIcon(":/res/generic.png"), romList2[j].name, fileList);
                                        break;
                                }
                        }
@@ -158,4 +194,4 @@ printf("FilePickerWindow: Found match [%s]...\n", romList[j].name);
                delete[] buffer;
        }
 }
-
+*/