]> Shamusworld >> Repos - virtualjaguar/commitdiff
Successfully integrated ZIP file fishing of images & software
authorShamus Hammons <jlhamm@acm.org>
Thu, 4 Mar 2010 19:35:39 +0000 (19:35 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 4 Mar 2010 19:35:39 +0000 (19:35 +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

index a975b82cc2e66f860ef7bdf37082086648869bd0..c35bd35944ca84ac9a49c30ed0d95e54ff016a8d 100644 (file)
@@ -27,17 +27,26 @@ FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent
 int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const
 {
 //     return pixList.size();
-       return dbIndex.size();
+//     return dbIndex.size();
+       return list.size();
 }
 
 QVariant FileListModel::data(const QModelIndex & index, int role) const
 {
 //     return QVariant();
 //     return pixList.at(index.row());
-       return (uint)dbIndex.at(index.row());
+//     return (uint)dbIndex.at(index.row());
+       if (role == Qt::DecorationRole)
+               return list.at(index.row()).label;
+       else if (role == Qt::DisplayRole)
+               return (uint)list.at(index.row()).dbIndex;
+       else if (role == Qt::EditRole)
+               return list.at(index.row()).filename;
+       else
+               return QVariant();
 }
 
-QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role/*= Qt::DisplayRole*/) const
+QVariant FileListModel::headerData(int/* section*/, Qt::Orientation/* orientation*/, int role/*= Qt::DisplayRole*/) const
 {
 #if 0
        // Not sure that this is necessary for our purposes...
@@ -70,6 +79,23 @@ void FileListModel::AddData(unsigned long index)
        reset();
 }
 
+void FileListModel::AddData(unsigned long index, QString str, QImage img)
+{
+       // Assuming that both QString and QImage have copy constructors, this should work.
+       FileListData data;
+
+       data.dbIndex = index;
+       data.filename = str;
+       data.label = img;
+
+       list.push_back(data);
+       reset();
+}
+
+//FileListData FileListModel::GetData(const QModelIndex & index) const
+//{
+//     return list.at(index.row());
+//}
 
 #if 0
 
index 1599ca5fdddec0d5bfd6cb03b5bf943f0865c565..b2006a84b107f0aecec757162968af8a1139e810 100644 (file)
 #include <QtGui>
 #include <vector>
 
+struct FileListData
+{
+//     FileListData(unsigned long ul=0, QString str="", QImage img=QImage()): dbIndex(ul), filename(str), label(img) {}
+//     FileListData(unsigned long ul=0, QString str, QImage img): dbIndex(ul), filename(str), label(img) {}
+
+       unsigned long dbIndex;
+       QString filename;
+       QImage label;
+};
+
 class FileListModel: public QAbstractListModel
 {
        public:
@@ -22,10 +32,14 @@ class FileListModel: public QAbstractListModel
 
                void AddData(QIcon pix);
                void AddData(unsigned long);
+               void AddData(unsigned long, QString, QImage);
+
+//             FileListData GetData(const QModelIndex & index) const;
 
        private:
                std::vector<QIcon> pixList;
                std::vector<unsigned long> dbIndex;
+               std::vector<FileListData> list;
 };
 
 #endif // __FILELISTMODEL_H__
index 9f85885f6f9b96cdfc0c8b4c489ec6cebdd66253..f64257126750898659b6586cff9dbb04b1d1d76b 100644 (file)
@@ -57,7 +57,8 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt:
        layout->addWidget(fileList);
 
        fileThread = new FileThread(this);
-       connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long)));
+//     connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long)));
+       connect(fileThread, SIGNAL(FoundAFile2(unsigned long, QString, QImage *)), this, SLOT(AddFileToList2(unsigned long, QString, QImage *)));
        fileThread->Go();
 }
 
@@ -72,3 +73,13 @@ printf("FilePickerWindow: Found match [%s]...\n", romList[index].name);
 //     model->AddData(QIcon(":/res/generic.png"));
        model->AddData(index);
 }
+
+void FilePickerWindow::AddFileToList2(unsigned long index, QString str, QImage * img)
+{
+printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name);
+       if (img)
+               model->AddData(index, str, *img);
+       else
+               model->AddData(index, str, QImage());
+}
+
index f0b5143babc52667575149808d9a2c5756fc8555..447162efb7ccb56f491169c887f0cb2288e655e4 100644 (file)
@@ -21,6 +21,7 @@ class FilePickerWindow: public QWidget
 
        public slots:
                void AddFileToList(unsigned long index);
+               void AddFileToList2(unsigned long index, QString, QImage *);
 
        protected:
 //             void PopulateList(void);
index dec070ffd4efcfeeb81207a06de89df66d0b2d62..22bf3b72f09afc258f0e8cc4671c640326daea2a 100644 (file)
@@ -10,6 +10,7 @@
 // ---  ----------  -------------------------------------------------------------
 // JLH  01/28/2010  Created this file
 // JLH  02/16/2010  Moved RomIdentifier stuff to its own file
+// JLH  03/02/2010  Added .ZIP file fishing
 //
 
 #include "filethread.h"
@@ -83,6 +84,9 @@ printf("FileThread: Aborting!!!\n");
 
                QFileInfo fileInfo = list.at(i);
 
+               // ZIP files are special: They contain more than just the software now... ;-)
+               // So now we fish around inside them to pull out the stuff we want.
+               // Probably also need more stringent error checking as well... :-O
                if (fileInfo.suffix().compare("zip", Qt::CaseInsensitive) == 0)
                {
                        uint8 * buffer = NULL;
@@ -96,6 +100,12 @@ printf("FileThread: Aborting!!!\n");
                                delete[] buffer;
 
 // Mebbe we should pass a index AND a QImage here???
+/*
+Let's think about this... What *do* we need to send out?
+we need the filename for sure. image file if it exists.
+do we need the index? I think we're only using it to pull the label from the subdir...
+we might need it if we want to pull ROM flags from the fileDB...
+*/
                                if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS))
                                {
                                        QImage img;
@@ -108,7 +118,8 @@ printf("FileThread: Aborting!!!\n");
                                        }
 //printf("FileThread: Attempted to load image. Size: %u x %u...\n", img.width(), img.height());
 
-                                       emit FoundAFile(index);
+//                                     emit FoundAFile(index);
+                                       emit FoundAFile2(index, fileInfo.canonicalFilePath(), &img);
                                }
                        }
                }
@@ -127,7 +138,8 @@ printf("FileThread: Aborting!!!\n");
 
 // Mebbe we should pass a index AND a QImage here???
                                if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS))
-                                       emit FoundAFile(index);
+//                                     emit FoundAFile(index);
+                                       emit FoundAFile2(index, fileInfo.canonicalFilePath(), 0);
                        }
                }
        }
index 0065f51fb6f542db026dee8d594d6824f4e78032..533ddfb14f9bb496bf89d94fd8577964403237da 100644 (file)
@@ -19,6 +19,7 @@ class FileThread: public QThread
 
        signals:
                void FoundAFile(unsigned long index);
+               void FoundAFile2(unsigned long index, QString filename, QImage * label);
 
        protected:
                void run(void);
index d148c2c12c76db30b006f13d8875c3f926fb6ae6..f7dfa9b1d5603fbb49a0ea8507ea25522845b2fe 100644 (file)
@@ -17,6 +17,7 @@
 #include "imagedelegate.h"
 
 #include "filedb.h"
+//#include "filelistmodel.h"
 
 
 ImageDelegate::ImageDelegate(QObject * parent): QAbstractItemDelegate(parent), pixelSize(12)
@@ -75,9 +76,22 @@ The foreground of the item (the circle representing a pixel) must be rendered us
 //     painter->drawPixmap(option.rect.x()+13, option.rect.y()+51, 433/2, 203/2, 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(), option.rect.y(), 488/4, 395/4, QPixmap(":/res/cart-blank.png"));
+//     unsigned long i = index.model()->data(index, Qt::DisplayRole).toUInt();
        unsigned long i = index.model()->data(index, Qt::DisplayRole).toUInt();
+       QString filename = index.model()->data(index, Qt::EditRole).toString();
+       QImage label = index.model()->data(index, Qt::DecorationRole).value<QImage>();
 
-       if (romList[i].file[0] == 0)
+#if 0
+       if (role == Qt::DecorationRole)
+               return list.at(index.row()).label;
+       else if (role == Qt::DisplayRole)
+               return (uint)list.at(index.row()).dbIndex;
+       else if (role == Qt::EditRole)
+               return list.at(index.row()).filename;
+#endif
+
+//     if (romList[i].file[0] == 0)
+       if (label.isNull())
        {
 //     painter->drawPixmap(option.rect.x()+14, option.rect.y()+50, 433/2, 203/2, QPixmap(":/res/label-blank.png"));
                painter->drawPixmap(option.rect.x()+7, option.rect.y()+25, 433/4, 203/4, QPixmap(":/res/label-blank.png"));
@@ -90,10 +104,14 @@ The foreground of the item (the circle representing a pixel) must be rendered us
        }
        else
        {
+#if 0
                QString filename(romList[i].file);
                filename.prepend("./label/");
                QImage img(filename);
                painter->drawImage(QRect(option.rect.x()+7, option.rect.y()+25, 433/4, 203/4), img);
+#else
+               painter->drawImage(QRect(option.rect.x()+7, option.rect.y()+25, 433/4, 203/4), label);
+#endif
        }
 //26x100
 #endif