Emulators can be now configured with multiple media image slots ($1, $2,
authorMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 19 Oct 2010 19:27:33 +0000 (22:27 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 19 Oct 2010 19:27:33 +0000 (22:27 +0300)
...).

src/db/dbmediaimage.cpp
src/emulauncher.cpp
src/utils/emuhelper.cpp
src/utils/emuhelper.h

index 376d578..44fb8cf 100644 (file)
@@ -142,7 +142,7 @@ QMap<QString, EmuFrontObject*> DbMediaImage::getMediaImages(int micId) const
 {
     QMap<QString, EmuFrontObject*> list;
     QSqlQuery  q;
-    q.prepare("SELECT file.id, file.name, file.checksum, file.size "
+    q.prepare("SELECT file.id, file.name, file.size, file.checksum "
         "FROM file INNER JOIN mediaimagecontainer_mediaimage "
         "ON mediaimagecontainer_mediaimage.mediaimageid = file.id "
         "WHERE mediaimagecontainer_mediaimage.mediaimagecontainerid = :micid ");
index 063cccd..f0e8e4f 100644 (file)
@@ -185,10 +185,11 @@ void EmuLauncher::launchEmu()
                 }
                 selectedImages << efo;
                 MediaImage *mi = dynamic_cast<MediaImage*>(efo);
-                mediaImages.remove(mi->getCheckSum());
+                QString key = mi->getCheckSum();
+                mediaImages.remove(key);
             }
-            if (list.count() == mediaImages.count() && mediaImages.count() == 1) {
-                // there should be only one media image left in mediaImages map
+            if (mediaImages.count() == 1) {
+                // there should be at least one media image left in mediaImages map
                 selectedImages << mediaImages.values().first();
             }
         }
@@ -208,7 +209,7 @@ void EmuLauncher::launchEmu()
         if (selectedImages.count() < 1)
             throw EmuFrontException(tr("No media images selected"));
 
-        emuHelper->launch(exe, mediaImageContainers, selectedImages);
+        emuHelper->launch(exe, mediaImageContainers, selectedImages, list.count());
     } catch (EmuFrontException efe) {
         delete exe;
         qDeleteAll(mediaImageContainers);
index 33fae17..ee92899 100644 (file)
@@ -32,7 +32,7 @@ EmuHelper::EmuHelper(QObject *parent) :
 }
 
 void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micList,
-    QList<EmuFrontObject *> miList)
+    QList<EmuFrontObject *> miList, int mediaCount)
 {
     if (miList.count() < 1) {
         throw EmuFrontException(tr("No media images available!"));
@@ -40,9 +40,9 @@ void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micLi
     if (micList.count() < 1) {
         throw EmuFrontException(tr("No media image containers available!"));
     }
+
     // extract the media image container to tmp folder
     // (TODO: tmp folder configuration)
-
     foreach(MediaImageContainer *mic, micList) {
         QString fp;
         fp.append(mic->getFilePath()->getName());
@@ -51,25 +51,22 @@ void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micLi
         int ret = unzipHelper->extractAll(fp, "/tmp/");
         if (ret) {
             qDebug() << "Failed unzipping " << fp << ".";
-            //throw EmuFrontException(tr("Unzip failed with %1.").arg(ret));
         }
     }
 
-    // TODO: launch the 1st media image in the media image list of ex
-    // or if emulator command options has a place for more than one
-    // media image assign the media images in the list order
-    // to emulator command line.
-
+    // fill in the media image slots in the command line options ($1, $2, ...)
     QString opts = ex->getOptions();
-    QString tmpfp = " \"/tmp/";
-    // if only one media image placeholder -> TODO: if more placeholders e.g. $1 $2 ...
-    tmpfp.append(miList.first()->getName()).append("\"");
-    opts.replace("$1", tmpfp);
+    for(int i = 0; i < mediaCount && i < miList.size(); i++) {
+        QString tmpfp = " \"/tmp/";
+        tmpfp.append (miList.at(i)->getName());
+        tmpfp.append("\"");
+        opts.replace(QString("$%1").arg(i+1), tmpfp);
+    }
+
     QString cmdWithParams;
     cmdWithParams.append(ex->getExecutable());
     cmdWithParams.append(" ").append(opts);
-    // TODO: tmp will be set dynamically
-    // TODO: assigning multiple media images
+
     qDebug() << "Command with params " << cmdWithParams;
     // Executable and MediaImageContainer / MediaImage objects are no more needed:
     delete ex;
index d7ab9b4..de80679 100644 (file)
@@ -33,7 +33,7 @@ class EmuHelper : public ProcessHelper
     Q_OBJECT
 public:
     explicit EmuHelper(QObject *parent = 0);
-    void launch(const Executable * ex, QList<MediaImageContainer *> micList, QList<EmuFrontObject*> miList);
+    void launch(const Executable * ex, QList<MediaImageContainer *> micList, QList<EmuFrontObject*> miList, int mediaCount = 1);
 private slots:
     void processError(QProcess::ProcessError);
     void processFinished(int);