FileModel. Also a MediaImageContainerModel.
**
** You should have received a copy of the GNU General Public License
** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
-*/#ifndef MEDIAIMAGECONTAINER_H
+*/
+
+#ifndef MEDIAIMAGECONTAINER_H
#define MEDIAIMAGECONTAINER_H
#include "emufrontfileobject.h"
#include "mediaimage.h"
#include "setup.h"
#include "filepathobject.h"
+#include <QMap>
class MediaImageContainer : public EmuFrontFile
{
**
** You should have received a copy of the GNU General Public License
** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
-*/#ifndef DBFILE_H
+*/
+
+#ifndef DBFILE_H
#define DBFILE_H
#include "dbquerymodelmanager.h"
delegates/filesystembrowsedelegate.h \
widgets/filepathselectorwidget.h \
models/externalexecutablemodel.h \
- views/externalexecutableeditview.h
+ views/externalexecutableeditview.h \
+ models/mediaimagecontainermodel.h \
+ models/mediaimagemodel.h \
+ models/filemodel.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
delegates/filesystembrowsedelegate.cpp \
widgets/filepathselectorwidget.cpp \
models/externalexecutablemodel.cpp \
- views/externalexecutableeditview.cpp
+ views/externalexecutableeditview.cpp \
+ models/mediaimagecontainermodel.cpp \
+ models/mediaimagemodel.cpp \
+ models/filemodel.cpp
OTHER_FILES +=
CONFIG += mobility
** 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 <QProcess>
#include <QSqlTableModel>
#include <QItemSelectionModel>
#include "emulauncher.h"
+#include "setup.h"
#include "setupmodel.h"
#include "externalexecutablemodel.h"
-#include "dbmediaimagecontainer.h"
+//#include "dbmediaimagecontainer.h"
+#include "mediaimagecontainer.h"
+#include "mediaimagecontainermodel.h"
#include "effileobjectcombobox.h"
#include "executablecombobox.h"
#include "executable.h"
EmuLauncher::EmuLauncher(QErrorMessage *errorMessage, QWidget *parent, QString tmp) :
QWidget(parent), tmpDirPath(tmp), errorMessage(errorMessage)
{
- dbMic = 0;
emuHelper = new EmuHelper(this);
initWidgets();
layout();
micTable->verticalHeader()->setVisible(false);
micTable->horizontalHeader()->setClickable(false);
+ MediaImageContainerModel *micModel = new MediaImageContainerModel(this);
+ micTable->setModel(micModel);
+
SetupModel *supModel = new SetupModel(this);
setupSelectBox = new QComboBox(this);
setupSelectBox->setModel(supModel);
QAbstractItemModel *setupAbsModel = setupSelectBox->model();
SetupModel *supModel = qobject_cast<SetupModel *>(setupAbsModel);
if (!supModel) return;
- QModelIndex plfInd =
- supModel->index(setupSelectBox->currentIndex(), SetupModel::Setup_PlatformId);
- int plfid = supModel->data(plfInd).toInt();
- QModelIndex mtInd =
- supModel->index(setupSelectBox->currentIndex(), SetupModel::Setup_MediaTypeId);
- int mtid = supModel->data(mtInd).toInt();
- if (mtid < 0 || plfid < 0) return;
+ QModelIndex supInd =
+ supModel->index(setupSelectBox->currentIndex(), SetupModel::Setup_Id);
+ int supId = supModel->data(supInd).toInt();
+ if (supId < 0) return;
// 2. fetch available media image containers
- if (!dbMic) dbMic = new DbMediaImageContainer(this);
- dbMic->filter(mtid, plfid);
- micTable->setModel(dbMic->getDataModel());
- micTable->hideColumn(DbMediaImageContainer::MIC_FileId);
- micTable->hideColumn(DbMediaImageContainer::MIC_FileSize);
- micTable->hideColumn(DbMediaImageContainer::MIC_FileCheckSum);
- micTable->hideColumn(DbMediaImageContainer::MIC_FilePathId);
- micTable->hideColumn(DbMediaImageContainer::MIC_FilePathName);
- micTable->hideColumn(DbMediaImageContainer::MIC_SetupId);
- micTable->hideColumn(DbMediaImageContainer::MIC_PlatformName);
- micTable->hideColumn(DbMediaImageContainer::MIC_PlatformId);
- micTable->hideColumn(DbMediaImageContainer::MIC_MediaTypeName);
- micTable->hideColumn(DbMediaImageContainer::MIC_MediaTypeId);
+
+ QAbstractItemModel *absModel = micTable->model();
+ MediaImageContainerModel *micModel = qobject_cast<MediaImageContainerModel*>(absModel);
+ micModel->filterBySetup(supId);
+
+ micTable->hideColumn(MediaImageContainerModel::MIC_FileId);
+ micTable->hideColumn(MediaImageContainerModel::MIC_FileSize);
+ micTable->hideColumn(MediaImageContainerModel::MIC_FileCheckSum);
+ micTable->hideColumn(MediaImageContainerModel::MIC_FilePathId);
+ micTable->hideColumn(MediaImageContainerModel::MIC_FilePathName);
+ micTable->hideColumn(MediaImageContainerModel::MIC_SetupId);
+ micTable->hideColumn(MediaImageContainerModel::MIC_PlatformName);
+ micTable->hideColumn(MediaImageContainerModel::MIC_PlatformId);
+ micTable->hideColumn(MediaImageContainerModel::MIC_MediaTypeName);
+ micTable->hideColumn(MediaImageContainerModel::MIC_MediaTypeId);
micTable->resizeColumnsToContents();
// 3. filter available emulators
- QModelIndex supInd =
- supModel->index(setupSelectBox->currentIndex(), SetupModel::Setup_Id);
- int supid = supModel->data(supInd).toInt();
QAbstractItemModel *execAbsModel = execSelectBox->model();
ExternalExecutableModel *execModel = qobject_cast<ExternalExecutableModel*>(execAbsModel);
if (!execModel) return;
- execModel->filterBySetup(supid);
+ execModel->filterBySetup(supId);
}
void EmuLauncher::launchEmu()
// Now we have one or more media image containers and an emulator selected,
// let's fetch the media image container data.
+ QAbstractItemModel *micAbsModel = micTable->model();
+ MediaImageContainerModel *micModel = qobject_cast<MediaImageContainerModel *>(micAbsModel);
+ if (!micModel) {
+ throw new EmuFrontException(tr("Failed creating data model for media image containers."));
+ }
+
foreach(QModelIndex mind, listMIndex) {
if (!mind.isValid()) continue;
- EmuFrontObject *obImg = dbMic->getDataObjectFromModel(&mind); // throws EmuFrontException
+
+ EmuFrontObject *obImg = micModel->getDataObject(mind);
+
if (!obImg) {
qDebug() << "Failed creating media image container at row " << mind.row();
continue;
**
** You should have received a copy of the GNU General Public License
** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
-*/#ifndef EMULAUNCHER_H
+*/
+
+#ifndef EMULAUNCHER_H
#define EMULAUNCHER_H
#include <QWidget>
class QPushButton;
class QComboBox;
class QErrorMessage;
-class DbMediaImageContainer;
+//class DbMediaImageContainer;
class Executable;
class MediaImageContainer;
class EmuHelper;
QComboBox *execSelectBox;
QPushButton *selectButton;
QPushButton *launchButton;
- DbMediaImageContainer *dbMic;
+ //DbMediaImageContainer *dbMic;
EmuHelper *emuHelper;
void initWidgets();
void layout();
**
** You should have received a copy of the GNU General Public License
** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
-*/#ifndef EMUFRONTQUERYMODEL_H
+*/
+
+#ifndef EMUFRONTQUERYMODEL_H
#define EMUFRONTQUERYMODEL_H
#include <QSqlQueryModel>
--- /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 "emufrontfile.h"
+#include "filemodel.h"
+#include <QtSql>
+
+FileModel::FileModel(QObject *parent) :
+ EmuFrontQueryModel(parent)
+{
+}
+
+QString FileModel::constructSelect(QString where) const
+{
+ return QString(
+ "SELECT file.id AS FileId, "
+ "file.name AS Name, "
+ "file.type AS FileType, "
+ "file.checksum AS Checksum, "
+ "file.size AS FileSize, "
+ "file.updatetime AS UpdateTime "
+ "FROM file "
+ "%1 "
+ "ORDER BY Name"
+ ).arg(where);
+}
+
+QString FileModel::constructFilterById(int id) const
+{
+ return QString("file.id = %1").arg(id);
+}
+
+EmuFrontObject* FileModel::recordToDataObject(const QSqlRecord *record)
+{
+ int id = record->value(File_Id).toInt();
+ QString name = record->value(File_Name).toString();
+ QString checksum = record->value(File_CheckSum).toString();
+ int size = record->value(File_FileSize).toInt();
+ int type = record->value(File_FileType).toInt();
+ return new EmuFrontFile(id, name, checksum, size, type);
+}
--- /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 FILEMODEL_H
+#define FILEMODEL_H
+
+#include "emufrontquerymodel.h"
+
+class FileModel : public EmuFrontQueryModel
+{
+ Q_OBJECT
+public:
+ FileModel(QObject *parent = 0);
+
+ enum {
+ File_Id,
+ File_Name,
+ File_FileType,
+ File_CheckSum,
+ File_FileSize,
+ File_UpdateTime
+ };
+protected:
+ virtual QString constructSelect(QString where = "") const;
+ // Implemented for EmuFrontQueryModel:
+ virtual EmuFrontObject* recordToDataObject(const QSqlRecord* );
+ virtual QString constructFilterById(int id) const;
+};
+
+#endif // FILEMODEL_H
--- /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 "mediaimagecontainer.h"
+#include "mediaimagecontainermodel.h"
+#include "filepathmodel.h"
+#include "mediaimagemodel.h"
+#include <QtSql>
+
+MediaImageContainerModel::MediaImageContainerModel(QObject *parent) :
+ EmuFrontQueryModel(parent)
+{
+}
+
+QString MediaImageContainerModel::constructSelect(QString where) const
+{
+ // TODO, for a usual search need a "light" version of this select
+ // and MediaImageContainer (only id, name)
+ return QString(
+ "SELECT file.id, file.name, file.checksum, file.size, "
+ " filepath.id, filepath.name, "
+ " setup.id, "
+ " platform.id, platform.name, "
+ " mediatype.id, mediatype.name "
+ "FROM file "
+ "INNER JOIN mediaimagecontainer_filepath ON mediaimagecontainer_filepath.fileid = file.id "
+ "INNER JOIN filepath ON mediaimagecontainer_filepath.filepathid = filepath.id "
+ "INNER JOIN setup ON filepath.setupid = setup.id "
+ "INNER JOIN platform ON setup.platformid = platform.id "
+ "INNER JOIN mediatype ON setup.mediatypeid = mediatype.id "
+ "%1 "
+ "ORDER BY file.name"
+ ).arg(where);
+}
+
+QString MediaImageContainerModel::constructFilterById(int id) const
+{
+ return QString("file.id = %1").arg(id);
+}
+
+void MediaImageContainerModel::refresh()
+{
+ //setQuery(constructSelect());
+ setHeaderData(MIC_FileId, Qt::Horizontal, tr("File id"));
+ setHeaderData(MIC_FileName, Qt::Horizontal, tr("File Name"));
+ setHeaderData(MIC_FileCheckSum, Qt::Horizontal, tr("File checksum"));
+ setHeaderData(MIC_FileSize, Qt::Horizontal, tr("File Size"));
+ setHeaderData(MIC_FilePathId, Qt::Horizontal, tr("File path id"));
+ setHeaderData(MIC_FilePathName, Qt::Horizontal, tr("File path name"));
+ setHeaderData(MIC_SetupId, Qt::Horizontal, tr("Setup id"));
+ setHeaderData(MIC_PlatformId, Qt::Horizontal, tr("Platform id"));
+ setHeaderData(MIC_PlatformName, Qt::Horizontal, tr("Platform name"));
+ setHeaderData(MIC_MediaTypeId, Qt::Horizontal, tr("Media type id"));
+ setHeaderData(MIC_MediaTypeName, Qt::Horizontal, tr("Media type name"));
+}
+
+EmuFrontObject* MediaImageContainerModel::recordToDataObject(const QSqlRecord *rec)
+{
+ // TODO: checks!
+ MediaImageContainer *mic = 0;
+ if (!rec) return mic;
+ int id = rec->value(MIC_FileId).toInt();
+ QString name = rec->value(MIC_FileName).toString();
+ QString checksum = rec->value(MIC_FileCheckSum).toString();
+ int size = rec->value(MIC_FileSize).toInt();
+ int fpId = rec->value(MIC_FilePathId).toInt();
+ FilePathModel fpModel;
+ EmuFrontObject *efo = fpModel.getDataObject(fpId);
+ FilePathObject *fpo = dynamic_cast<FilePathObject*>(efo);
+ if (!fpo) return 0;
+ //int supId = rec->value(MIC_SetupId).toInt();
+ //Setup *sup = dbSetup->getDataObject(supId)
+ MediaImageModel miModel;
+ QMap<QString, EmuFrontObject*> images = miModel.getMediaImages(id);
+ mic = new MediaImageContainer(
+ id, name, checksum, size, images, fpo
+ );
+ return mic;
+}
+
+void MediaImageContainerModel::filterBySetup(int setupId)
+{
+ QList<QString> filters;
+ filters.append(QString("setup.id = %1").arg(setupId));
+ filterDataObjects(filters);
+}
--- /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 MEDIAIMAGECONTAINERMODEL_H
+#define MEDIAIMAGECONTAINERMODEL_H
+
+#include "emufrontquerymodel.h"
+
+class MediaImageContainerModel : public EmuFrontQueryModel
+{
+ Q_OBJECT
+public:
+ MediaImageContainerModel(QObject *parent = 0);
+ void filterBySetup(int setupId);
+ enum {
+ MIC_FileId,
+ MIC_FileName,
+ MIC_FileCheckSum,
+ MIC_FileSize,
+ MIC_FilePathId,
+ MIC_FilePathName,
+ MIC_SetupId,
+ MIC_PlatformId,
+ MIC_PlatformName,
+ MIC_MediaTypeId,
+ MIC_MediaTypeName
+ };
+
+protected:
+ virtual void refresh();
+ virtual QString constructSelect(QString where = "") const;
+ // Implemented for EmuFrontQueryModel:
+ virtual EmuFrontObject* recordToDataObject(const QSqlRecord* );
+ virtual QString constructFilterById(int id) const;
+};
+
+#endif // MEDIAIMAGECONTAINERMODEL_H
--- /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 "mediaimage.h"
+#include "mediaimagemodel.h"
+#include <QtSql>
+
+MediaImageModel::MediaImageModel(QObject *parent) :
+ FileModel(parent)
+{
+}
+
+/* Fetches a list of media images inside a media image container
+ with a given id */
+QMap<QString, EmuFrontObject*> MediaImageModel::getMediaImages(int micId)
+{
+ QMap<QString, EmuFrontObject*> list;
+ QSqlQuery q;
+ 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 ");
+ q.bindValue(":micid", micId);
+ q.exec();
+ QSqlRecord rec;
+ int id, size;
+ QString name, checksum;
+ MediaImage *mi = 0;
+ while(q.next()) {
+ // TODO: checks?
+ rec = q.record();
+ id = rec.value(MediaImageModel::File_Id).toInt();
+ name = rec.value(MediaImageModel::File_Name).toString();
+ checksum = rec.value(MediaImageModel::File_CheckSum).toString();
+ size = rec.value(MediaImageModel::File_FileSize).toInt();
+ list[checksum] = new MediaImage(id, name, checksum, size);
+ }
+ return list;
+}
--- /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 MEDIAIMAGEMODEL_H
+#define MEDIAIMAGEMODEL_H
+
+#include "filemodel.h"
+#include <QMap>
+
+class MediaImageModel : public FileModel
+{
+ Q_OBJECT
+public:
+ MediaImageModel(QObject *parent = 0);
+ QMap<QString, EmuFrontObject*> getMediaImages(int id);
+
+protected:
+ //virtual void refresh();
+ //virtual QString constructSelect(QString where = "") const;
+ // Implemented for EmuFrontQueryModel:
+ //virtual EmuFrontObject* recordToDataObject(const QSqlRecord* );
+ //virtual QString constructFilterById(int id) const;
+};
+
+#endif // MEDIAIMAGEMODEL_H
**
** You should have received a copy of the GNU General Public License
** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
-*/#ifndef SETUPMODEL_H
+*/
+
+#ifndef SETUPMODEL_H
#define SETUPMODEL_H
#include "emufrontquerymodel.h"
-class SetupLt;
-
class SetupModel : public EmuFrontQueryModel
{
Q_OBJECT
virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
virtual bool insertRows(int row, int count, const QModelIndex &parent);
virtual bool removeRows(int row, int count, const QModelIndex &parent);
- //virtual EmuFrontObject* getObject(int row) const;
enum { Setup_Id = 0,
Setup_PlatformId,
Setup_MediaTypeId,
Setup_FileTypeExtensions,
Setup_Name };
static const QString FILE_TYPE_EXTENSION_SEPARATOR;
- SetupLt* getCurrentItem();
protected:
virtual void refresh();