New dialog for selecting from multiple emu front objects derived from
authorMikko Keinänen <mikko.keinanen@gmail.com>
Mon, 18 Oct 2010 15:57:34 +0000 (18:57 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Mon, 18 Oct 2010 15:57:34 +0000 (18:57 +0300)
QInputDialog.

src/dialogs/emufrontinputdialog.cpp [new file with mode: 0644]
src/dialogs/emufrontinputdialog.h [new file with mode: 0644]
src/dialogs/listdialog.cpp [new file with mode: 0644]
src/dialogs/listdialog.h [new file with mode: 0644]
src/emufront.pro
src/emulauncher.cpp
src/utils/emuhelper.cpp
src/utils/emuhelper.h

diff --git a/src/dialogs/emufrontinputdialog.cpp b/src/dialogs/emufrontinputdialog.cpp
new file mode 100644 (file)
index 0000000..8408ffb
--- /dev/null
@@ -0,0 +1,22 @@
+#include "emufrontinputdialog.h"
+#include <QMap>
+#include "../dataobjects/emufrontobject.h"
+
+EmuFrontInputDialog::EmuFrontInputDialog(QWidget *parent, Qt::WindowFlags flags)
+        : QInputDialog(parent, flags)
+{
+}
+
+EmuFrontObject* EmuFrontInputDialog::getItem(QWidget *parent, const QString &title, const QString &label,
+                               const QList<EmuFrontObject*> &items, int current, bool editable,
+                               bool *ok, Qt::WindowFlags flags)
+{
+    QStringList l;
+    QMap<QString, EmuFrontObject*> map;
+    foreach(EmuFrontObject *efo, items){
+        l << efo->getName();
+        map[efo->getName()] = efo;
+    }
+    QString sel = QInputDialog::getItem(parent, title, label, l, current, editable, ok, flags);
+    return map.value(sel, 0);
+}
diff --git a/src/dialogs/emufrontinputdialog.h b/src/dialogs/emufrontinputdialog.h
new file mode 100644 (file)
index 0000000..fcb445b
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef EMUFRONTINPUTDIALOG_H
+#define EMUFRONTINPUTDIALOG_H
+
+#include <QInputDialog>
+
+class EmuFrontObject;
+class EmuFrontInputDialog : public QInputDialog
+{
+public:
+    EmuFrontInputDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0);
+    static EmuFrontObject* getItem(QWidget *parent, const QString &title, const QString &label,
+                           const QList<EmuFrontObject*> &items, int current = 0, bool editable = true,
+                           bool *ok = 0, Qt::WindowFlags flags = 0);
+};
+
+#endif // EMUFRONTINPUTDIALOG_H
diff --git a/src/dialogs/listdialog.cpp b/src/dialogs/listdialog.cpp
new file mode 100644 (file)
index 0000000..56fbbdb
--- /dev/null
@@ -0,0 +1,45 @@
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "listdialog.h"
+#include <QtGui>
+#include "../dataobjects/emufrontobject.h"
+
+ListDialog::ListDialog(QWidget *parent)
+    : QDialog(parent)
+{
+    listView = new QListWidget(this);
+    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Vertical);
+
+}
+
+void ListDialog::setData(QList<EmuFrontObject *> list)
+{
+    foreach(EmuFrontObject *efo, list) {
+        listView->addItem(efo->getName());
+    }
+}
+
+void ListDialog::layout()
+{
+    QHBoxLayout *mainLayout = new QHBoxLayout;
+    mainLayout->addWidget(listView);
+    mainLayout->addWidget(buttonBox);
+    setLayout(mainLayout);
+}
diff --git a/src/dialogs/listdialog.h b/src/dialogs/listdialog.h
new file mode 100644 (file)
index 0000000..3414cb0
--- /dev/null
@@ -0,0 +1,42 @@
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef LISTDIALOG_H
+#define LISTDIALOG_H
+
+#include <QDialog>
+
+class QListWidget;
+class QDialogButtonBox;
+class EmuFrontObject;
+
+class ListDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    ListDialog(QWidget *parent = 0);
+    void setData(QList<EmuFrontObject*>);
+private:
+    QListWidget *listView;
+    QDialogButtonBox *buttonBox;
+    void layout();
+};
+
+#endif // LISTDIALOG_H
index 8550420..53879e5 100644 (file)
@@ -61,7 +61,9 @@ HEADERS += mainwindow.h \
     widgets/executablecombobox.h \
     utils/processhelper.h \
     utils/unziphelper.h \
-    utils/emuhelper.h
+    utils/emuhelper.h \
+    dialogs/listdialog.h \
+    dialogs/emufrontinputdialog.h
 SOURCES += main.cpp \
     mainwindow.cpp \
     db/databasemanager.cpp \
@@ -112,5 +114,7 @@ SOURCES += main.cpp \
     widgets/executablecombobox.cpp \
     utils/processhelper.cpp \
     utils/unziphelper.cpp \
-    utils/emuhelper.cpp
+    utils/emuhelper.cpp \
+    dialogs/listdialog.cpp \
+    dialogs/emufrontinputdialog.cpp
 OTHER_FILES += 
index 01cd325..171b897 100644 (file)
@@ -30,6 +30,7 @@
 #include "widgets/executablecombobox.h"
 #include "dataobjects/executable.h"
 #include "utils/emuhelper.h"
+#include "dialogs/emufrontinputdialog.h"
 
 EmuLauncher::EmuLauncher(QWidget *parent) :
     QWidget(parent)
@@ -111,6 +112,9 @@ void EmuLauncher::updateMediaImageContainers()
 
 void EmuLauncher::launchEmu()
 {
+    QList<EmuFrontObject*> mediaImages;
+    QList<MediaImageContainer*> mediaImageContainers;
+    Executable *exe;
     try {
         if (!micTable || !micTable->model()) {
             throw EmuFrontException(tr("No search results available!"));
@@ -133,7 +137,7 @@ void EmuLauncher::launchEmu()
         if (!obExe) {
             throw EmuFrontException(tr("Failed fetching selected emulator!"));
         }
-        Executable *exe = dynamic_cast<Executable*>(obExe);
+        exe = dynamic_cast<Executable*>(obExe);
         if (!exe) {
             throw EmuFrontException(tr("Failed creating Emulator object!"));
         }
@@ -141,8 +145,6 @@ void EmuLauncher::launchEmu()
         // TODO: multiple media image container selection
         //          - build a list of selected media image objects
         //          - check that the platform and media type (setup) matches
-        QList<MediaImage*> mediaImages;
-        QList<MediaImageContainer*> mediaImageContainers;
         foreach(QModelIndex mind, listMIndex) {
             EmuFrontObject *obImg = dbMic->getDataObjectFromModel(&mind);
             if (!obImg) {
@@ -157,11 +159,11 @@ void EmuLauncher::launchEmu()
             }
             mediaImageContainers << mic;
             QList<MediaImage*> contained = mic->getMediaImages();
-            mediaImages << contained;
+            foreach(MediaImage *mi, contained)
+                mediaImages << mi;
         }
 
         if (mediaImages.count() < 1) {
-            delete exe;
             throw new EmuFrontException("No media images available!");
         }
 
@@ -175,19 +177,34 @@ void EmuLauncher::launchEmu()
             pos += rx.matchedLength();
         }
 
+        QList<MediaImage*> selectedImages;
         if (list.count() > 1) {
+            for(int i = 0; i < list.count(); i++) {
+                //QInputDialog::getItem();
+                // TODO: Use input dialog here
+                // Create a new input dialog class for emufrontobjects
+            }
             // TODO: show dialog to set the media order (the images will be assigned to slots in the order in respect to the image list)
         }
-        else {
-            // TODO: show select boot image dialog
+        else if (mediaImages.count() > 1) {
+            // show select boot image dialog
+            bool ok;
+            EmuFrontObject *efo = EmuFrontInputDialog::getItem(
+                this, tr("Select boot image"), tr("Select"), mediaImages, 0, false, &ok);
+            if (!ok)  {
+                throw new EmuFrontException(tr("Boot image selection was canceled, aborting."));
+            }
         }
         // in the both cases the (ordered) list of media images will be passed to emuHelper
 
-        foreach(MediaImage *mi, mediaImages) {
+        foreach(EmuFrontObject *mi, mediaImages) {
             qDebug() << "Media image " << mi->getName();
         }
         emuHelper->launch(exe, mediaImageContainers, mediaImages);
     } catch (EmuFrontException efe) {
+        delete exe;
+        qDeleteAll(mediaImageContainers);
+        qDeleteAll(mediaImages);
         QMessageBox::information(this, tr("Launching emulator"),
                                  efe.what(), QMessageBox::Ok);
         return;
index 63dab2a..d2fbd90 100644 (file)
@@ -31,7 +31,7 @@ EmuHelper::EmuHelper(QObject *parent) :
     unzipHelper = new UnzipHelper(this);
 }
 
-void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micList, QList<MediaImage *> miList)
+void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> &micList, QList<EmuFrontObject *> &miList)
 {
     // extract the media image container to tmp folder
     // (TODO: tmp folder configuration)
index 891f772..5dab145 100644 (file)
@@ -25,6 +25,7 @@
 class Executable;
 class MediaImageContainer;
 class MediaImage;
+class EmuFrontObject;
 class UnzipHelper;
 
 class EmuHelper : public ProcessHelper
@@ -32,7 +33,7 @@ class EmuHelper : public ProcessHelper
     Q_OBJECT
 public:
     explicit EmuHelper(QObject *parent = 0);
-    void launch(const Executable * ex, QList<MediaImageContainer *> micList, QList<MediaImage *> miList);
+    void launch(const Executable * ex, QList<MediaImageContainer *> &micList, QList<EmuFrontObject*> &miList);
 private slots:
     void processError(QProcess::ProcessError);
     void processFinished(int);