#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)
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);
}
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*);
int getType() const;
void setType(int);
+ enum {
+ FilePathType_MediaImageDir = 1,
+ FilePathType_TmpDir,
+ FilePathType_PlatformIconsDir,
+ FilePathType_MediaIconsDir
+ };
+
private:
int type;
Setup *setup;
--- /dev/null
+#include "dbconfig.h"
+#include <QSqlRelationalTableModel>
+#include <QSqlQuery>
+#include <QSqlRecord>
+
+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();
+}
--- /dev/null
+#ifndef DBCONFIG_H
+#define DBCONFIG_H
+
+#include <QObject>
+
+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
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, "
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<Setup*>(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)
"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 "
FilePath_Name,
FilePath_LastScanned,
FilePath_SetupId,
- FilePath_SetupName };
+ FilePath_SetupName,
+ FilePath_FileTypeId
+ };
protected:
virtual EmuFrontObject* recordToDataObject(const QSqlRecord* );
--- /dev/null
+// 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 <QtGui>
+#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();
+ }
+}
--- /dev/null
+// 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 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
#include "../widgets/setupcombobox.h"
MediaImagePathDialog::MediaImagePathDialog(QWidget *parent, EmuFrontObject *efObject)
- : DataObjectEditDialog(parent, efObject, Qt::Horizontal)
+ : BrowseFilePathDialog(parent, efObject, Qt::Horizontal)
{
initWidgets();
dbPlatform = 0;
{
}
-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);
{
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);
}
#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
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();
EmuFrontObject* MediaImagePathMainDialog::createObject()
{
- return new FilePathObject;
+ return new FilePathObject(FilePathObject::FilePathType_MediaImageDir);
}
MediaImagePathMainDialog::~MediaImagePathMainDialog()
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 \
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 =
-
-
#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);
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;
{
// TODO
}
+
+void EmuLauncher::setTmpDirPath(QString tmp)
+{
+ tmpDirPath = tmp;
+}
{
Q_OBJECT
public:
- explicit EmuLauncher(QWidget *parent = 0);
+ EmuLauncher(QWidget *parent = 0, QString tmp = ".");
~EmuLauncher();
void updateData();
+ void setTmpDirPath(QString);
signals:
void populateMediaTypeSelectBox();
void launch(const Executable*, const MediaImageContainer*);
void cleanTmp();
+ QString tmpDirPath;
};
#endif // EMULAUNCHER_H
#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();
mediaImagePathDialog = 0;
setupMainDialog = 0;
executableMainDialog = 0;
- connectSignals();
}
void MainWindow::connectSignals()
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"));
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();
configMenu->addAction(configMediaImagePathAction);
configMenu->addAction(configSetupAction);
configMenu->addAction(configEmulatorAction);
+ configMenu->addAction(configTmpDirAction);
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAction);
class MediaImagePathMainDialog;
class SetupMainDialog;
class ExecutableMainDialog;
+//class TmpFolderEditDialog;
class QLabel;
class DatabaseManager;
class EmuFrontDialog;
void configureMediaImagePaths();
void configureSetups();
void configureEmulators();
+ void configureTmpDir();
void updateData();
void about();
MediaImagePathMainDialog *mediaImagePathDialog;
SetupMainDialog *setupMainDialog;
ExecutableMainDialog *executableMainDialog;
+ //TmpFolderEditDialog *tmpFolderDialog;
QMenu *configMenu;
QMenu *fileMenu;
QMenu *helpMenu;
QAction *configEmulatorAction;
QAction *exitAction;
QAction *aboutAction;
+ QAction *configTmpDirAction;
QLabel *messageLabel;
DatabaseManager *dbManager;
EmuLauncher *launcher;
+ QString tmpDirFilePath;
};
#endif
}
void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micList,
- QList<EmuFrontObject *> miList, int mediaCount)
+ QList<EmuFrontObject *> miList, int mediaCount, QString tmp)
{
if (miList.count() < 1) {
throw EmuFrontException(tr("No media images available!"));
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());
// 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);
// 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;
Q_OBJECT
public:
explicit EmuHelper(QObject *parent = 0);
- void launch(const Executable * ex, QList<MediaImageContainer *> micList, QList<EmuFrontObject*> miList, int mediaCount = 1);
+ void launch(const Executable * ex, QList<MediaImageContainer *> micList, QList<EmuFrontObject*> miList, int mediaCount = 1, QString tmp = ".");
private slots:
void processError(QProcess::ProcessError);
void processFinished(int);