Initial support for multiple selection.
[emufront] / src / emulauncher.cpp
index 8b3690e..e188e2c 100644 (file)
@@ -5,9 +5,9 @@
 //
 //
 // EmuFront is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
 //
 // EmuFront is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,6 +20,7 @@
 #include <QtGui>
 #include <QProcess>
 #include <QSqlTableModel>
+#include <QItemSelectionModel>
 #include "utils/OSDaB-Zip/unzip.h"
 #include "emulauncher.h"
 #include "db/dbmediatype.h"
@@ -61,7 +62,7 @@ void EmuLauncher::updateData()
 void EmuLauncher::initWidgets()
 {
     micTable = new QTableView(this);
-    micTable->setSelectionMode(QAbstractItemView::SingleSelection);
+    micTable->setSelectionMode(QAbstractItemView::MultiSelection);
     mediaTypeSelectBox = new EFFileObjectComboBox(dbMediaType, this);
     platformSelectBox = new EFFileObjectComboBox(dbPlatform, this);
     execSelectBox = new ExecutableComboBox(dbExec, this);
@@ -114,11 +115,18 @@ void EmuLauncher::launchEmu()
         if (!execSelectBox || execSelectBox->currentIndex() == -1) {
             throw EmuFrontException(tr("Emulator not selected!"));
         }
-        // TODO: multiple media image container selection
-        QModelIndex mindex = micTable->currentIndex();
-        if (!mindex.isValid()) {
+        //QModelIndex mindex = micTable->currentIndex();
+        QItemSelectionModel *selModel = micTable->selectionModel();
+        QModelIndexList listMIndex =  selModel->selectedIndexes();
+        /*if (!mindex.isValid()) {
+            throw EmuFrontException(tr("Media image container not selected!"));
+        }*/
+        if (listMIndex.count() < 1) {
             throw EmuFrontException(tr("Media image container not selected!"));
         }
+        qDebug() << listMIndex.count() << " items selected.";
+        // TODO: multiple media image container selection
+        QModelIndex mindex = listMIndex.first();
         EmuFrontObject *obImg = dbMic->getDataObjectFromModel(&mindex);
         if (!obImg) {
             throw EmuFrontException(tr("Failed fetching selected media image container."));
@@ -139,8 +147,8 @@ void EmuLauncher::launchEmu()
                 << mic->getName() << " and emulator "
                 << obExe->getName() << ".";
         if (mic->getMediaImages().count() > 0) {
-            // TODO
             // 1. Launch media image
+            // TODO
             // 2. If 2 or more media images in container
             //    show a diaglog for choosing the boot image
             // 3. If 2 or more media image containers selected
@@ -194,6 +202,28 @@ void EmuLauncher::launch(const Executable * ex, const MediaImageContainer * mic)
     // Executable and MediaImageContainer objects are no more needed:
     delete ex;
     delete mic;
-    if (!proc) proc = new QProcess(this); // This has to be done in the heap
+    if (!proc) {
+        proc = new QProcess(this); // This has to be done in the heap
+        connect(proc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
+        connect(proc, SIGNAL(finished(int)), this, SLOT(processFinished(int)));
+    }
     proc->start(cmdWithParams, QIODevice::ReadOnly);
 }
+
+void EmuLauncher::processError(QProcess::ProcessError e)
+{
+    QString stdErr = proc->readAllStandardError();
+    QMessageBox::warning(this, tr("Emulator"),
+        tr("Launching emulator failed with: %1.\n").arg(e)
+        .append(";\n").append(proc->errorString().append(";\n")
+        .append(stdErr)), QMessageBox::Ok );
+}
+
+void EmuLauncher::processFinished(int a)
+{
+    QString stdErr = proc->readAllStandardError();
+    QString stdMsg = proc->readAllStandardOutput();
+    QString msg = tr("Emulator has finished with: %1.\n").arg(a).append(stdMsg);
+    if (a) msg.append("; ").append(proc->errorString()).append(";\n").append(stdErr);
+    QMessageBox::information(this, tr("Emulator finished"), msg, QMessageBox::Ok);
+}