Removed debug message.
[emufront] / src / emulauncher.cpp
index 6e0af93..c6403e9 100644 (file)
@@ -32,8 +32,8 @@
 #include "utils/emuhelper.h"
 #include "dialogs/emufrontinputdialog.h"
 
-EmuLauncher::EmuLauncher(QWidget *parent) :
-    QWidget(parent)
+EmuLauncher::EmuLauncher(QWidget *parent, QString tmp) :
+    QWidget(parent), tmpDirPath(tmp)
 {
     dbPlatform = new DbPlatform(this);
     dbMediaType = new DbMediaType(this);
@@ -59,13 +59,17 @@ void EmuLauncher::updateData()
 {
     platformSelectBox->updateDataModel();
     mediaTypeSelectBox->updateDataModel();
-    execSelectBox->updateDataModel();
+    //execSelectBox->updateDataModel();
 }
 
 void EmuLauncher::initWidgets()
 {
     micTable = new QTableView(this);
-    micTable->setSelectionMode(QAbstractItemView::MultiSelection);
+    micTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
+    micTable->setCornerButtonEnabled(false);
+    micTable->verticalHeader()->setVisible(false);
+    //micTable->horizontalHeader()->setDisabled(true);
+    micTable->horizontalHeader()->setClickable(false);
     mediaTypeSelectBox = new EFFileObjectComboBox(dbMediaType, this);
     platformSelectBox = new EFFileObjectComboBox(dbPlatform, this);
     execSelectBox = new ExecutableComboBox(dbExec, this);
@@ -77,11 +81,13 @@ void EmuLauncher::layout()
 {
     QGridLayout *grid = new QGridLayout;
     grid->addWidget(platformSelectBox, 0, 0);
-    grid->addWidget(mediaTypeSelectBox, 1, 0);
-    grid->addWidget(selectButton, 1, 1);
-    grid->addWidget(micTable, 2, 0, 1, 2);
-    grid->addWidget(execSelectBox, 3, 0);
-    grid->addWidget(launchButton, 3, 1);
+    grid->addWidget(mediaTypeSelectBox, 0, 1);
+    grid->addWidget(selectButton, 0, 2);
+    grid->setColumnStretch(3, 1);
+
+    grid->addWidget(micTable, 1, 0, 1, 4);
+    grid->addWidget(execSelectBox, 2, 0);
+    grid->addWidget(launchButton, 2, 1);
     // grid will be implicitily parented to this
     setLayout(grid);
 }
@@ -120,10 +126,13 @@ void EmuLauncher::updateMediaImageContainers()
     micTable->resizeColumnsToContents();
     platformSelectBox->updateDataModel();
     mediaTypeSelectBox->updateDataModel();
+    execSelectBox->updateToSetup(plfid, mtid);
 }
 
 void EmuLauncher::launchEmu()
 {
+    // if selected emulator has no extensions configured, it's assumed to be a M.A.M.E. or similar and
+    // map of media images will be no be used
     QMap<QString, EmuFrontObject*> mediaImages;
     QList<MediaImageContainer*> mediaImageContainers;
     Executable *exe = 0;
@@ -150,6 +159,24 @@ void EmuLauncher::launchEmu()
             throw EmuFrontException(tr("Failed creating Emulator object!"));
         }
 
+
+        qDebug() << "File types; " << exe->getSetup()->getSupportedFileTypeExtensions().count();
+
+        bool mame = exe->getSetup()->getSupportedFileTypeExtensions().isEmpty();
+
+
+
+        if (mame && listMIndex.count() > 1) {
+            throw new EmuFrontException(tr("No supported file types configured for this emulator configuration. "
+                "Assuming emulator support container files as is. "
+                "Only one container can be selected without configuring supported file types."
+            ));
+        }
+
+
+        // Now we have one or more media image containers and an emulator selected,
+        // let's fetch the media image container data.
+
         foreach(QModelIndex mind, listMIndex) {
             if (!mind.isValid()) continue;
             EmuFrontObject *obImg = dbMic->getDataObjectFromModel(&mind);
@@ -168,6 +195,16 @@ void EmuLauncher::launchEmu()
             mediaImages.unite(contained);
         }
 
+        if (mame) {
+            emuHelper->launch(exe, mediaImageContainers);
+            return;
+        }
+
+        // mediaImageContainers list contains all the selected media image containers and
+        // mediaImages list contains all the media images inside all the selected containers
+
+
+        QList<EmuFrontObject*> selectedImages;
         if (mediaImages.count() < 1) {
             throw EmuFrontException("No media images available!");
         }
@@ -181,14 +218,15 @@ void EmuLauncher::launchEmu()
             list << rx.cap(1);
             pos += rx.matchedLength();
         }
-
         bool ok;
-        QList<EmuFrontObject*> selectedImages;
+
         if (list.count() > mediaImages.count()) {
             throw EmuFrontException(tr("Select %1 media images for this emulator configuration").arg(list.count()));
         }
         if (list.count() > 1) {
+            // more than one placeholder for media image in the command line ($1, $2, ...)
             int lim = list.count() == mediaImages.count() ? list.count() - 1 : list.count();
+            // user sets the order of media images
             for(int i = 0; i < lim; i++) {
                 EmuFrontObject *efo = EmuFrontInputDialog::getItem(
                         this, tr("Select image no. %1").arg(i+1), tr("Select"), mediaImages.values(), 0, false, &ok);
@@ -200,28 +238,41 @@ void EmuLauncher::launchEmu()
                 QString key = mi->getCheckSum();
                 mediaImages.remove(key);
             }
-            if (mediaImages.count() == 1) {
-                // there should be at least one media image left in mediaImages map
+            // there should be at least one media image left in mediaImages map...
+            /*if (mediaImages.count() == 1) {
                 selectedImages << mediaImages.values().first();
-            }
+            } ... this is added later-> */
         }
         else if (mediaImages.count() > 1) {
             // show select boot image dialog
             EmuFrontObject *efo = EmuFrontInputDialog::getItem(
-                this, tr("Select boot image"), tr("Select"), mediaImages.values(), 0, false, &ok);
+                    this, tr("Select boot image"), tr("Select"), mediaImages.values(), 0, false, &ok);
             if (!ok)  {
                 throw EmuFrontException(tr("Boot image selection was canceled, aborting."));
             }
             selectedImages << efo;
+            MediaImage *mi = dynamic_cast<MediaImage*>(efo);
+            QString key = mi->getCheckSum();
+            mediaImages.remove(key);
+        }
+        else if (mediaImages.count() == 1) {
+            EmuFrontObject *efo = mediaImages.values().first();
+            selectedImages << efo;
+            MediaImage *mi = dynamic_cast<MediaImage*>(efo);
+            QString key = mi->getCheckSum();
+            mediaImages.remove(key);
+        }
+        // in all the both cases the (ordered) list of media images will be passed to emuHelper
+
+        // wee also keep the rest of the mediaimages in the selected containers for reference!
+        foreach(EmuFrontObject *efo, mediaImages) {
+            selectedImages << efo;
         }
-        else if (mediaImages.count() == 1)
-            selectedImages << mediaImages.values().first();
-        // in the both cases the (ordered) list of media images will be passed to emuHelper
 
         if (selectedImages.count() < 1)
             throw EmuFrontException(tr("No media images selected"));
 
-        emuHelper->launch(exe, mediaImageContainers, selectedImages, list.count());
+        emuHelper->launch(exe, mediaImageContainers, selectedImages, list.count(), tmpDirPath);
         micTable->clearSelection();
     } catch (EmuFrontException efe) {
         if (exe) delete exe;
@@ -258,3 +309,8 @@ void EmuLauncher::cleanTmp()
 {
     // TODO
 }
+
+void EmuLauncher::setTmpDirPath(QString tmp)
+{
+    tmpDirPath = tmp;
+}