]> Shamusworld >> Repos - virtualjaguar/commitdiff
Added beginnings of ROM directory scanning functionality
authorShamus Hammons <jlhamm@acm.org>
Wed, 27 Jan 2010 18:07:17 +0000 (18:07 +0000)
committerShamus Hammons <jlhamm@acm.org>
Wed, 27 Jan 2010 18:07:17 +0000 (18:07 +0000)
src/gui/filepicker.cpp
src/gui/filepicker.h
src/gui/mainwin.cpp
src/gui/mainwin.h

index 2280f82202c10b55798cc9aaadec4af6c30a4127..daaae590288c19a57019b764bebce88eefe1d3d9 100644 (file)
@@ -13,6 +13,8 @@
 
 #include "filepicker.h"
 
+#include "crc32.h"
+#include "settings.h"
 #include "types.h"
 
 struct RomIdentifier
@@ -98,5 +100,63 @@ in romList for future reference.
 
 When constructing the list, use the index to pull up an image of the cart and
 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...
 */
 
+//FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)//could use Window as well...
+FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
+{
+       setWindowTitle("Insert Cartridge...");
+
+       fileList = new QListWidget(this);
+//     addWidget(fileList);
+
+       QVBoxLayout * layout = new QVBoxLayout();
+//     layout->setSizeConstraint(QLayout::SetFixedSize);
+       setLayout(layout);
+
+       layout->addWidget(fileList);
+
+       PopulateList();
+}
+
+void FilePickerWindow::PopulateList(void)
+{
+       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; romList[j].crc32 != 0xFFFFFFFF; j++)
+                       {
+                               if (romList[j].crc32 == crc)
+                               {
+printf("FilePickerWindow: Found match [%s]...\n", romList[j].name);
+                                       new QListWidgetItem(QIcon(":/res/generic.png"), romList[j].name, fileList);
+                                       break;
+                               }
+                       }
+               }
+
+               delete[] buffer;
+       }
+
+}
+
index ec02cba811a355f63350f9d37e9cd9257e5ea44f..e886e3b8a425d911518e1e2982b27b59cc019810 100644 (file)
@@ -3,3 +3,18 @@
 //
 
 #include <QtGui>
+
+// Forward declarations
+class QListWidget;
+
+class FilePickerWindow: public QWidget
+{
+       public:
+               FilePickerWindow(QWidget * parent = 0);
+
+       protected:
+               void PopulateList(void);
+
+       private:
+               QListWidget * fileList;
+};
index 69634f65338ed3f9b6f1ba56901ee0ceace7c4f5..5aae995359e54042e37fbbd32b7fa735dd0be80a 100644 (file)
@@ -30,6 +30,7 @@
 #include "glwidget.h"
 #include "about.h"
 #include "settings.h"
+#include "filepicker.h"
 
 // The way BSNES controls things is by setting a timer with a zero
 // timeout, sleeping if not emulating anything. Seems there has to be a
@@ -50,7 +51,11 @@ MainWin::MainWin()
        setWindowIcon(QIcon(":/res/vj.xpm"));
        setWindowTitle("Virtual Jaguar v2.0.0");
 
+       ReadSettings();
+       setUnifiedTitleAndToolBarOnMac(true);
+
        aboutWin = new AboutWindow(this);
+       filePickWin = new FilePickerWindow(this);
 
     videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -105,9 +110,14 @@ MainWin::MainWin()
        aboutAct->setStatusTip(tr("Blatant self-promotion"));
        connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
 
+       filePickAct = new QAction(QIcon(":/res/generic.png"), tr("Insert Cartridge..."), this);
+       filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
+       connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
+
        // Create menus & toolbars
 
        fileMenu = menuBar()->addMenu(tr("&File"));
+       fileMenu->addAction(filePickAct);
        fileMenu->addAction(powerAct);
        fileMenu->addAction(quitAppAct);
 
@@ -126,9 +136,6 @@ MainWin::MainWin()
        //      Create status bar
        statusBar()->showMessage(tr("Ready"));
 
-       ReadSettings();
-       setUnifiedTitleAndToolBarOnMac(true);
-
        // Set toolbar button based on setting read in (sync the UI)...
        blurAct->setChecked(vjs.glFilter);
        x1Act->setChecked(zoomLevel == 1);
@@ -230,6 +237,11 @@ void MainWin::ShowAboutWin(void)
        aboutWin->show();
 }
 
+void MainWin::InsertCart(void)
+{
+       filePickWin->show();
+}
+
 void MainWin::ResizeMainWindow(void)
 {
        videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
@@ -264,6 +276,9 @@ void MainWin::ReadSettings(void)
        vjs.useOpenGL        = settings.value("useOpenGL", true).toBool();
        vjs.glFilter         = settings.value("glFilterType", 0).toInt();
        vjs.renderType       = settings.value("renderType", 0).toInt();
+
+       // Hardcoded, !!! FIX !!!
+       strcpy(vjs.ROMPath, "./roms");
 }
 
 void MainWin::WriteSettings(void)
index a3a26cccf95b2ebb3624fa4d680a6f452dbc4476..fb07549119b5a447225d62a9596ffd32fcf31460 100644 (file)
 #include <QtGui>
 
 // Forward declarations
-
 class GLWidget;
 class AboutWindow;
-//class EditWindow;
-//class CharWindow;
+class FilePickerWindow;
 
 class MainWin: public QMainWindow
 {
@@ -40,6 +38,7 @@ class MainWin: public QMainWindow
                void SetPAL(void);
                void ToggleBlur(void);
                void ShowAboutWin(void);
+               void InsertCart(void);
 
        private:
                void ResizeMainWindow(void);
@@ -49,6 +48,7 @@ class MainWin: public QMainWindow
 //     public:
                GLWidget * videoWidget;
                AboutWindow * aboutWin;
+               FilePickerWindow * filePickWin;
                QTimer * timer;
                bool running;
                int zoomLevel;
@@ -68,6 +68,7 @@ class MainWin: public QMainWindow
                QAction * palAct;
                QAction * blurAct;
                QAction * aboutAct;
+               QAction * filePickAct;
 };
 
 #endif // __MAINWIN_H__