From 87e94122774bc53e728a8cfd7c77ed79d842071a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mikko=20Kein=C3=A4nen?= Date: Sun, 7 Nov 2010 02:56:32 +0200 Subject: [PATCH] Added configuration of temporary directory. --- src/dataobjects/filepathobject.cpp | 6 ++-- src/dataobjects/filepathobject.h | 9 ++++- src/db/dbconfig.cpp | 33 ++++++++++++++++++ src/db/dbconfig.h | 18 ++++++++++ src/db/dbcreator.cpp | 4 +++ src/db/dbfilepath.cpp | 7 ++-- src/db/dbfilepath.h | 4 ++- src/dialogs/browsefilepathdialog.cpp | 54 ++++++++++++++++++++++++++++++ src/dialogs/browsefilepathdialog.h | 48 ++++++++++++++++++++++++++ src/dialogs/mediaimagepathdialog.cpp | 15 +++++---- src/dialogs/mediaimagepathdialog.h | 18 +++++----- src/dialogs/mediaimagepathmaindialog.cpp | 2 +- src/emufront.pro | 10 +++--- src/emulauncher.cpp | 11 ++++-- src/emulauncher.h | 4 ++- src/mainwindow.cpp | 31 +++++++++++++++-- src/mainwindow.h | 5 +++ src/utils/emuhelper.cpp | 15 +++++---- src/utils/emuhelper.h | 2 +- 19 files changed, 251 insertions(+), 45 deletions(-) create mode 100644 src/db/dbconfig.cpp create mode 100644 src/db/dbconfig.h create mode 100644 src/dialogs/browsefilepathdialog.cpp create mode 100644 src/dialogs/browsefilepathdialog.h diff --git a/src/dataobjects/filepathobject.cpp b/src/dataobjects/filepathobject.cpp index 93f3da8..6619ddc 100644 --- a/src/dataobjects/filepathobject.cpp +++ b/src/dataobjects/filepathobject.cpp @@ -21,7 +21,8 @@ #include "filepathobject.h" #include "setup.h" -FilePathObject::FilePathObject() : EmuFrontObject(), setup(0) +FilePathObject::FilePathObject(int type) + : EmuFrontObject(), type(type), setup(0) { } FilePathObject::FilePathObject(int id, QString name, int filetype) @@ -38,10 +39,7 @@ FilePathObject::~FilePathObject() FilePathObject::FilePathObject(const FilePathObject &fpobj) : EmuFrontObject(fpobj), type(fpobj.type) { - qDebug() << "FilePathObject copy constructor."; Setup *s = fpobj.setup; - qDebug() << "Setup name " << s->getName(); - qDebug() << "Setup id " << s->getId(); setup = new Setup(*s); } diff --git a/src/dataobjects/filepathobject.h b/src/dataobjects/filepathobject.h index 53d82bd..d0bb80f 100644 --- a/src/dataobjects/filepathobject.h +++ b/src/dataobjects/filepathobject.h @@ -27,7 +27,7 @@ class Setup; class FilePathObject : public EmuFrontObject { public: - FilePathObject(); + FilePathObject(int type); ~FilePathObject(); FilePathObject(int id, QString name, int filetype); FilePathObject(int id, QString name, int filetype, Setup*); @@ -39,6 +39,13 @@ public: int getType() const; void setType(int); + enum { + FilePathType_MediaImageDir = 1, + FilePathType_TmpDir, + FilePathType_PlatformIconsDir, + FilePathType_MediaIconsDir + }; + private: int type; Setup *setup; diff --git a/src/db/dbconfig.cpp b/src/db/dbconfig.cpp new file mode 100644 index 0000000..1ae9f52 --- /dev/null +++ b/src/db/dbconfig.cpp @@ -0,0 +1,33 @@ +#include "dbconfig.h" +#include +#include +#include + +DbConfig::DbConfig(QObject *parent) : + QObject(parent) +{ +} + +QString DbConfig::getTmpDir() +{ + QString r = ""; + QSqlQuery q("SELECT tmpdirpath FROM config"); + if (q.first()) + r = q.value(DbConfig::DbConfig_TmpDirPath).toString(); + return r; +} + +bool DbConfig::setTmpDir(QString path) +{ + QSqlQuery q("SELECT COUNT(*) FROM config"); + int rows = 0; + if (q.first()) + rows = q.value(0).toInt(); + if (rows == 0) + q.prepare("INSERT INTO config (tmpdirpath) " + "VALUES (:path)"); + else + q.prepare("UPDATE CONFIG SET tmpdirpath=:path"); + q.bindValue(":path", path); + return q.exec(); +} diff --git a/src/db/dbconfig.h b/src/db/dbconfig.h new file mode 100644 index 0000000..6246407 --- /dev/null +++ b/src/db/dbconfig.h @@ -0,0 +1,18 @@ +#ifndef DBCONFIG_H +#define DBCONFIG_H + +#include + +class DbConfig : public QObject +{ + Q_OBJECT +public: + DbConfig(QObject *parent = 0); + static QString getTmpDir(); + static bool setTmpDir(QString); + enum { + DbConfig_TmpDirPath = 0 + }; +}; + +#endif // DBCONFIG_H diff --git a/src/db/dbcreator.cpp b/src/db/dbcreator.cpp index 5fd76b6..5b686af 100644 --- a/src/db/dbcreator.cpp +++ b/src/db/dbcreator.cpp @@ -53,6 +53,10 @@ bool DbCreator::createDB() qDebug() << "Creating TABLE file"; + ret = query.exec("CREATE TABLE IF NOT EXISTS config" + "(tmpdirpath TEXT)" + ); + ret = query.exec("CREATE TABLE IF NOT EXISTS file" "(id INTEGER PRIMARY KEY, " "name TEXT, " diff --git a/src/db/dbfilepath.cpp b/src/db/dbfilepath.cpp index 13b5778..cc37e94 100644 --- a/src/db/dbfilepath.cpp +++ b/src/db/dbfilepath.cpp @@ -36,11 +36,11 @@ EmuFrontObject* DbFilePath::recordToDataObject(const QSqlRecord *rec) int id = rec->value(FilePath_Id).toInt(); QString fpath = rec->value(FilePath_Name).toString(); int setupId = rec->value(FilePath_SetupId).toInt(); - //int fileType = rec->value(FilePath_FileTypeId).toInt(); + int fileType = rec->value(FilePath_FileTypeId).toInt(); Setup *sup = dynamic_cast(dbSetup->getDataObject(setupId)); // TODO //int lastScanned = 0; - return new FilePathObject(id, fpath, /* TODO */ 0, sup); + return new FilePathObject(id, fpath, fileType, sup); } bool DbFilePath::updateDataObjectToModel(const EmuFrontObject *ob) @@ -103,7 +103,8 @@ QString DbFilePath::constructSelect(QString where) const "filepath.name AS Name, " "filepath.lastscanned AS LastScanned, " "setup.id AS SetupId, " - "platform.name || ' ' || mediatype.name AS SetupName " + "platform.name || ' ' || mediatype.name AS SetupName, " + "filepath.filetypeid " "FROM filepath " "INNER JOIN setup ON filepath.setupid=setup.id " "INNER JOIN platform ON setup.platformid=platform.id " diff --git a/src/db/dbfilepath.h b/src/db/dbfilepath.h index 682d393..4d0f9d4 100644 --- a/src/db/dbfilepath.h +++ b/src/db/dbfilepath.h @@ -35,7 +35,9 @@ public: FilePath_Name, FilePath_LastScanned, FilePath_SetupId, - FilePath_SetupName }; + FilePath_SetupName, + FilePath_FileTypeId + }; protected: virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ); diff --git a/src/dialogs/browsefilepathdialog.cpp b/src/dialogs/browsefilepathdialog.cpp new file mode 100644 index 0000000..525a83c --- /dev/null +++ b/src/dialogs/browsefilepathdialog.cpp @@ -0,0 +1,54 @@ +// 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 . + +#include +#include "browsefilepathdialog.h" + +BrowseFilePathDialog::BrowseFilePathDialog(QWidget *parent, EmuFrontObject *efo, Qt::Orientation orientation) : + DataObjectEditDialog(parent, efo, orientation) +{ +} + +void BrowseFilePathDialog::connectSignals() +{ + DataObjectEditDialog::connectSignals(); + connect(filePathButton, SIGNAL(clicked()), this, SLOT(browseFilePath())); +} + +void BrowseFilePathDialog::initWidgets() +{ + filePathLabel = new QLabel; + filePathButton = new QPushButton(tr("&Browse filepath")); +} + +void BrowseFilePathDialog::browseFilePath() +{ + QString startPath = (efObject && !efObject->getName().isEmpty()) + ? efObject->getName() + : QDir::homePath(); + + QString fpath = QFileDialog::getExistingDirectory(this, + tr("Select a directory"), startPath, + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + QDir d(fpath); + if (d.exists() && d.isReadable()) { + filePathLabel->setText(d.path()); + if (d.path() != startPath) emit filePathUpdated(); + } +} diff --git a/src/dialogs/browsefilepathdialog.h b/src/dialogs/browsefilepathdialog.h new file mode 100644 index 0000000..ffdab6e --- /dev/null +++ b/src/dialogs/browsefilepathdialog.h @@ -0,0 +1,48 @@ +// 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 . + +#ifndef BROWSEFILEPATHDIALOG_H +#define BROWSEFILEPATHDIALOG_H + +#include "dataobjecteditdialog.h" + +class QLabel; +class QPushButton; + +class BrowseFilePathDialog : public DataObjectEditDialog +{ + Q_OBJECT +public: + BrowseFilePathDialog(QWidget *parent, EmuFrontObject*, + Qt::Orientation orientation = Qt::Horizontal); + +signals: + void filePathUpdated(); + +protected slots: + void browseFilePath(); + +protected: + void connectSignals(); + void initWidgets(); + QLabel *filePathLabel; + QPushButton *filePathButton; +}; + +#endif // BROWSEFILEPATHDIALOG_H diff --git a/src/dialogs/mediaimagepathdialog.cpp b/src/dialogs/mediaimagepathdialog.cpp index 62673e6..3838657 100644 --- a/src/dialogs/mediaimagepathdialog.cpp +++ b/src/dialogs/mediaimagepathdialog.cpp @@ -26,7 +26,7 @@ #include "../widgets/setupcombobox.h" MediaImagePathDialog::MediaImagePathDialog(QWidget *parent, EmuFrontObject *efObject) - : DataObjectEditDialog(parent, efObject, Qt::Horizontal) + : BrowseFilePathDialog(parent, efObject, Qt::Horizontal) { initWidgets(); dbPlatform = 0; @@ -40,13 +40,13 @@ MediaImagePathDialog::~MediaImagePathDialog() { } -void MediaImagePathDialog::connectSignals() +/*void MediaImagePathDialog::connectSignals() { DataObjectEditDialog::connectSignals(); connect(filePathButton, SIGNAL(clicked()), this, SLOT(browseFilePath())); -} +}*/ -void MediaImagePathDialog::browseFilePath() +/*void MediaImagePathDialog::browseFilePath() { QString fpath = QFileDialog::getExistingDirectory(this, tr("Select a directory"), ".", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); @@ -55,13 +55,14 @@ void MediaImagePathDialog::browseFilePath() { filePathLabel->setText(d.path()); } -} +}*/ void MediaImagePathDialog::initWidgets() { + BrowseFilePathDialog::initWidgets(); // these widgets will be automatically parented using layout components - filePathLabel = new QLabel; - filePathButton = new QPushButton(tr("&Browse filepath")); + //filePathLabel = new QLabel; + //filePathButton = new QPushButton(tr("&Browse filepath")); dbSetup = new DbSetup(this); setupComBox = new SetupComboBox(dbSetup, this); } diff --git a/src/dialogs/mediaimagepathdialog.h b/src/dialogs/mediaimagepathdialog.h index 1ec5413..b1f3692 100644 --- a/src/dialogs/mediaimagepathdialog.h +++ b/src/dialogs/mediaimagepathdialog.h @@ -20,19 +20,19 @@ #ifndef MEDIAIMAGEPATHDIALOG_H #define MEDIAIMAGEPATHDIALOG_H -#include "dataobjecteditdialog.h" +#include "browsefilepathdialog.h" -class QDialogButtonBox; -class QLabel; -class QPushButton; -class QSqlTableModel; +//class QDialogButtonBox; +//class QLabel; +//class QPushButton; +//class QSqlTableModel; class DbSetup; class Setup; class DbMediaType; class DbPlatform; class SetupComboBox; -class MediaImagePathDialog : public DataObjectEditDialog +class MediaImagePathDialog : public BrowseFilePathDialog { Q_OBJECT @@ -44,19 +44,17 @@ public: protected slots: virtual void acceptChanges(); - void browseFilePath(); + //void browseFilePath(); private: SetupComboBox *setupComBox; - QLabel *filePathLabel; - QPushButton *filePathButton; DbSetup *dbSetup; DbMediaType *dbMediaType; DbPlatform *dbPlatform; void initWidgets(); void layout(); - void connectSignals(); + //void connectSignals(); void populateSetupComBox(); void setSelectedSetup(const Setup *); Setup* getSelectedSetup(); diff --git a/src/dialogs/mediaimagepathmaindialog.cpp b/src/dialogs/mediaimagepathmaindialog.cpp index 2ec1f60..ff31fc6 100644 --- a/src/dialogs/mediaimagepathmaindialog.cpp +++ b/src/dialogs/mediaimagepathmaindialog.cpp @@ -93,7 +93,7 @@ void MediaImagePathMainDialog::beginScanFilePath() EmuFrontObject* MediaImagePathMainDialog::createObject() { - return new FilePathObject; + return new FilePathObject(FilePathObject::FilePathType_MediaImageDir); } MediaImagePathMainDialog::~MediaImagePathMainDialog() diff --git a/src/emufront.pro b/src/emufront.pro index 1c6e173..a11a3a5 100644 --- a/src/emufront.pro +++ b/src/emufront.pro @@ -65,7 +65,9 @@ HEADERS += mainwindow.h \ utils/emuhelper.h \ dialogs/listdialog.h \ dialogs/emufrontinputdialog.h \ - dialogs/emufrontfileobjectdialog.h + dialogs/emufrontfileobjectdialog.h \ + dialogs/browsefilepathdialog.h \ + db/dbconfig.h SOURCES += main.cpp \ mainwindow.cpp \ db/databasemanager.cpp \ @@ -119,11 +121,11 @@ SOURCES += main.cpp \ utils/emuhelper.cpp \ dialogs/listdialog.cpp \ dialogs/emufrontinputdialog.cpp \ - dialogs/emufrontfileobjectdialog.cpp + dialogs/emufrontfileobjectdialog.cpp \ + dialogs/browsefilepathdialog.cpp \ + db/dbconfig.cpp OTHER_FILES += CONFIG += mobility MOBILITY = - - diff --git a/src/emulauncher.cpp b/src/emulauncher.cpp index d2aca49..11418a6 100644 --- a/src/emulauncher.cpp +++ b/src/emulauncher.cpp @@ -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); @@ -224,7 +224,7 @@ void EmuLauncher::launchEmu() 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; @@ -261,3 +261,8 @@ void EmuLauncher::cleanTmp() { // TODO } + +void EmuLauncher::setTmpDirPath(QString tmp) +{ + tmpDirPath = tmp; +} diff --git a/src/emulauncher.h b/src/emulauncher.h index 6921f9a..1e88136 100644 --- a/src/emulauncher.h +++ b/src/emulauncher.h @@ -39,9 +39,10 @@ class EmuLauncher : public QWidget { Q_OBJECT public: - explicit EmuLauncher(QWidget *parent = 0); + EmuLauncher(QWidget *parent = 0, QString tmp = "."); ~EmuLauncher(); void updateData(); + void setTmpDirPath(QString); signals: @@ -70,6 +71,7 @@ private: void populateMediaTypeSelectBox(); void launch(const Executable*, const MediaImageContainer*); void cleanTmp(); + QString tmpDirPath; }; #endif // EMULAUNCHER_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f5bbfb1..7d474d8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,12 +25,17 @@ #include "dialogs/mediaimagepathmaindialog.h" #include "dialogs/setupmaindialog.h" #include "dialogs/executablemaindialog.h" +#include "dialogs/tmpfoldereditdialog.h" #include "db/databasemanager.h" +#include "db/dbconfig.h" MainWindow::MainWindow() { setWindowTitle("EmuFront"); - launcher = new EmuLauncher(this); + tmpDirFilePath = DbConfig::getTmpDir(); + if (tmpDirFilePath.isEmpty()) + tmpDirFilePath = QDir::tempPath(); + launcher = new EmuLauncher(this, tmpDirFilePath); setCentralWidget(launcher); createActions(); createMenus(); @@ -41,7 +46,6 @@ MainWindow::MainWindow() mediaImagePathDialog = 0; setupMainDialog = 0; executableMainDialog = 0; - connectSignals(); } void MainWindow::connectSignals() @@ -72,6 +76,10 @@ void MainWindow::createActions() configEmulatorAction->setStatusTip(tr("Configure emulators")); connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators())); + configTmpDirAction = new QAction(tr("&Temp dir"), this); + configTmpDirAction->setStatusTip(tr("Configure directory for temporary files.")); + connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir())); + exitAction = new QAction(tr("&Exit"), this); exitAction->setShortcut(tr("Ctrl+Q")); exitAction->setStatusTip(tr("Exit EmuFront")); @@ -132,6 +140,24 @@ void MainWindow::configureEmulators() executableMainDialog->refreshDataModel(); } +void MainWindow::configureTmpDir() +{ + /*if (!tmpFolderDialog) { + tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath); + } + activateDialog(tmpFolderDialog);*/ + + QString fpath = QFileDialog::getExistingDirectory(this, + tr("Select a directory"), tmpDirFilePath, + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + QDir d(fpath); + if (d.exists() && d.isReadable()) { + tmpDirFilePath = fpath; + DbConfig::setTmpDir(tmpDirFilePath); + launcher->setTmpDirPath(tmpDirFilePath); + } +} + void MainWindow::activateDialog(EmuFrontDialog* dia) const { dia->show(); @@ -150,6 +176,7 @@ void MainWindow::createMenus() configMenu->addAction(configMediaImagePathAction); configMenu->addAction(configSetupAction); configMenu->addAction(configEmulatorAction); + configMenu->addAction(configTmpDirAction); helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(aboutAction); diff --git a/src/mainwindow.h b/src/mainwindow.h index 7f8ba29..eca5089 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,6 +28,7 @@ class MediaTypeDialog; class MediaImagePathMainDialog; class SetupMainDialog; class ExecutableMainDialog; +//class TmpFolderEditDialog; class QLabel; class DatabaseManager; class EmuFrontDialog; @@ -50,6 +51,7 @@ private slots: void configureMediaImagePaths(); void configureSetups(); void configureEmulators(); + void configureTmpDir(); void updateData(); void about(); @@ -67,6 +69,7 @@ private: MediaImagePathMainDialog *mediaImagePathDialog; SetupMainDialog *setupMainDialog; ExecutableMainDialog *executableMainDialog; + //TmpFolderEditDialog *tmpFolderDialog; QMenu *configMenu; QMenu *fileMenu; QMenu *helpMenu; @@ -77,9 +80,11 @@ private: QAction *configEmulatorAction; QAction *exitAction; QAction *aboutAction; + QAction *configTmpDirAction; QLabel *messageLabel; DatabaseManager *dbManager; EmuLauncher *launcher; + QString tmpDirFilePath; }; #endif diff --git a/src/utils/emuhelper.cpp b/src/utils/emuhelper.cpp index e98a888..03f84a4 100644 --- a/src/utils/emuhelper.cpp +++ b/src/utils/emuhelper.cpp @@ -33,7 +33,7 @@ EmuHelper::EmuHelper(QObject *parent) : } void EmuHelper::launch(const Executable * ex, QList micList, - QList miList, int mediaCount) + QList miList, int mediaCount, QString tmp) { if (miList.count() < 1) { throw EmuFrontException(tr("No media images available!")); @@ -42,10 +42,9 @@ void EmuHelper::launch(const Executable * ex, QList micLi throw EmuFrontException(tr("No media image containers available!")); } - QString tmp = "/tmp/"; // TODO: do this configurable! + if (!tmp.endsWith('/')) tmp.append("/"); // extract the media image container to tmp folder - // (TODO: tmp folder configuration) foreach(MediaImageContainer *mic, micList) { QString fp; fp.append(mic->getFilePath()->getName()); @@ -60,7 +59,8 @@ void EmuHelper::launch(const Executable * ex, QList micLi // fill in the media image slots in the command line options ($1, $2, ...) QString opts = ex->getOptions(); for(int i = 0; i < mediaCount && i < miList.size(); i++) { - QString tmpfp = " \"/tmp/"; + QString tmpfp = " \""; + tmpfp.append(tmp); tmpfp.append (miList.at(i)->getName()); tmpfp.append("\""); opts.replace(QString("$%1").arg(i+1), tmpfp); @@ -78,10 +78,11 @@ void EmuHelper::launch(const Executable * ex, QList micLi // clean the temp dir foreach(EmuFrontObject *ob, miList) { - QString fp = tmp; + QString fp = " \""; + fp.append(tmp); fp.append(ob->getName()); - QFile f(fp); - if (!f.remove()) + fp.append("\""); + if (!QFile::remove(fp)) qDebug() << "Removing " << fp << " failed."; } delete ex; diff --git a/src/utils/emuhelper.h b/src/utils/emuhelper.h index de80679..dfdc81c 100644 --- a/src/utils/emuhelper.h +++ b/src/utils/emuhelper.h @@ -33,7 +33,7 @@ class EmuHelper : public ProcessHelper Q_OBJECT public: explicit EmuHelper(QObject *parent = 0); - void launch(const Executable * ex, QList micList, QList miList, int mediaCount = 1); + void launch(const Executable * ex, QList micList, QList miList, int mediaCount = 1, QString tmp = "."); private slots: void processError(QProcess::ProcessError); void processFinished(int); -- 1.7.9.5