From 40c9e361197c09007e0493025913d79f380dc620 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mikko=20Kein=C3=A4nen?= Date: Sun, 17 Oct 2010 12:24:46 +0300 Subject: [PATCH] Expanded support for multiple media images. --- src/emulauncher.cpp | 80 +++++++++++++++++++++++++++------------------ src/utils/emuhelper.cpp | 5 ++- src/utils/emuhelper.h | 3 +- src/utils/unziphelper.cpp | 2 ++ src/utils/unziphelper.h | 1 + 5 files changed, 57 insertions(+), 34 deletions(-) diff --git a/src/emulauncher.cpp b/src/emulauncher.cpp index ce6f731..01cd325 100644 --- a/src/emulauncher.cpp +++ b/src/emulauncher.cpp @@ -129,18 +129,6 @@ void EmuLauncher::launchEmu() } qDebug() << listMIndex.count() << " items selected."; - // TODO: multiple media image container selection - // - build a list of selected media image objects - // - check that the platform and media type (setup) matches - QModelIndex mindex = listMIndex.first(); - EmuFrontObject *obImg = dbMic->getDataObjectFromModel(&mindex); - if (!obImg) { - throw EmuFrontException(tr("Failed fetching selected media image container.")); - } - MediaImageContainer *mic = dynamic_cast(obImg); - if (!mic) { - throw EmuFrontException(tr("Failed creating media image container object!")); - } EmuFrontObject *obExe = execSelectBox->getSelected(); if (!obExe) { throw EmuFrontException(tr("Failed fetching selected emulator!")); @@ -149,28 +137,56 @@ void EmuLauncher::launchEmu() if (!exe) { throw EmuFrontException(tr("Failed creating Emulator object!")); } - qDebug() << "Selected media image container " - << mic->getName() << " and emulator " - << obExe->getName() << "."; - if (mic->getMediaImages().count() > 0) { - // 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 - // from a list show a dialog listing all the media - // images in those container for choosing the - // boot image - // 4. If selected emulator command line containes more - // than one media image placeholder ($1, $2, ...) - // show a dialog for ordering the media images to - // right order. - QList ls = mic->getMediaImages(); - foreach(MediaImage *mi, ls) { - qDebug() << "Media image " << mi->getName(); + + // TODO: multiple media image container selection + // - build a list of selected media image objects + // - check that the platform and media type (setup) matches + QList mediaImages; + QList mediaImageContainers; + foreach(QModelIndex mind, listMIndex) { + EmuFrontObject *obImg = dbMic->getDataObjectFromModel(&mind); + if (!obImg) { + qDebug() << "Failed creating media image container at row " << mind.row(); + continue; + } + MediaImageContainer *mic = dynamic_cast(obImg); + if (!mic) { + qDebug() << "Failed to create media image container for " << obImg->getName(); + delete obImg; + continue; } - emuHelper->launch(exe, mic); + mediaImageContainers << mic; + QList contained = mic->getMediaImages(); + mediaImages << contained; + } + + if (mediaImages.count() < 1) { + delete exe; + throw new EmuFrontException("No media images available!"); + } + + // check if command options have slots for nr media images > 1 e.g. "-diska $1 -diskb $2 ..." + QString opts = exe->getOptions(); + QRegExp rx("(\\s\\$\\d+\\s)"); + QStringList list; + int pos = 0; + while ((pos = rx.indexIn(opts, pos)) != -1) { + list << rx.cap(1); + pos += rx.matchedLength(); + } + + if (list.count() > 1) { + // 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 + } + // in the both cases the (ordered) list of media images will be passed to emuHelper + + foreach(MediaImage *mi, mediaImages) { + qDebug() << "Media image " << mi->getName(); } + emuHelper->launch(exe, mediaImageContainers, mediaImages); } catch (EmuFrontException efe) { QMessageBox::information(this, tr("Launching emulator"), efe.what(), QMessageBox::Ok); diff --git a/src/utils/emuhelper.cpp b/src/utils/emuhelper.cpp index f190c05..63dab2a 100644 --- a/src/utils/emuhelper.cpp +++ b/src/utils/emuhelper.cpp @@ -31,11 +31,14 @@ EmuHelper::EmuHelper(QObject *parent) : unzipHelper = new UnzipHelper(this); } -void EmuHelper::launch(const Executable * ex, const MediaImageContainer * mic) +void EmuHelper::launch(const Executable * ex, QList micList, QList miList) { // extract the media image container to tmp folder // (TODO: tmp folder configuration) + // TODO: support multiple media images + MediaImageContainer *mic = micList.first(); + QString fp; fp.append(mic->getFilePath()->getName()); if (!fp.endsWith('/')) fp.append("/"); diff --git a/src/utils/emuhelper.h b/src/utils/emuhelper.h index c11e40d..891f772 100644 --- a/src/utils/emuhelper.h +++ b/src/utils/emuhelper.h @@ -24,6 +24,7 @@ class Executable; class MediaImageContainer; +class MediaImage; class UnzipHelper; class EmuHelper : public ProcessHelper @@ -31,7 +32,7 @@ class EmuHelper : public ProcessHelper Q_OBJECT public: explicit EmuHelper(QObject *parent = 0); - void launch(const Executable * ex, const MediaImageContainer * mic); + void launch(const Executable * ex, QList micList, QList miList); private slots: void processError(QProcess::ProcessError); void processFinished(int); diff --git a/src/utils/unziphelper.cpp b/src/utils/unziphelper.cpp index 9a20b69..48434d5 100644 --- a/src/utils/unziphelper.cpp +++ b/src/utils/unziphelper.cpp @@ -26,6 +26,7 @@ const QString UnzipHelper::UNZIP_COMMAND = "unzip "; const QString UnzipHelper::UNZIP_LIST_ARGS = "-lv "; +const QString UnzipHelper::UNZIP_EXTRACT_ARGS= "-qqo "; UnzipHelper::UnzipHelper(QObject *parent) : ProcessHelper(parent) @@ -139,6 +140,7 @@ int UnzipHelper::extractAll(QString filePath, QString targetPath) // unzip filepath -d targetpath QString command; command.append(UNZIP_COMMAND); + command.append(UNZIP_EXTRACT_ARGS); command.append("\""); command.append(filePath); command.append("\""); diff --git a/src/utils/unziphelper.h b/src/utils/unziphelper.h index 6f92d5f..f4dbe4c 100644 --- a/src/utils/unziphelper.h +++ b/src/utils/unziphelper.h @@ -34,6 +34,7 @@ public: private: static const QString UNZIP_COMMAND; static const QString UNZIP_LIST_ARGS; + static const QString UNZIP_EXTRACT_ARGS; }; -- 1.7.9.5