bea2327f5e33af9e1cbb84da31b5c76c05c3b04d
[emufront] / src / models / externalexecutablemodel.cpp
1 /*
2 ** EmuFront
3 ** Copyright 2010 Mikko Keinänen
4 **
5 ** This file is part of EmuFront.
6 **
7 **
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
12 **
13 ** EmuFront is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "externalexecutablemodel.h"
23
24 ExternalExecutableModel::ExternalExecutableModel(QObject *parent) :
25     EmuFrontQueryModel(parent)
26 {
27     refresh();
28 }
29
30 void ExternalExecutableModel::refresh()
31 {
32     setQuery(constructSelect());
33     setHeaderData(Executable_Id, Qt::Horizontal, tr("Id"));
34     setHeaderData(Executable_Name, Qt::Horizontal, tr("Name"));
35     setHeaderData(Executable_Executable, Qt::Horizontal, tr("Executable"));
36     setHeaderData(Executable_Options, Qt::Horizontal, tr("Options"));
37     setHeaderData(Executable_TypeId, Qt::Horizontal, tr("Type"));
38     setHeaderData(Executable_SetupId, Qt::Horizontal, tr("Setup id"));
39     setHeaderData(Executable_SetupName, Qt::Horizontal, tr("Setup"));
40 }
41
42 QString ExternalExecutableModel::constructSelect(QString where) const
43 {
44     return QString("SELECT "
45                    "executable.id AS ExecutableId, "
46                    "executable.name AS ExecutableName, "
47                    "executable.executable AS Executable, "
48                    "executable.options AS ExecutableOptions, "
49                    "executable.type AS ExecutableType, "
50                    "setup.id As ExecutableSetupId, "
51                    "platform.name || ' ' || mediatype.name AS SetupName "
52                    "FROM executable "
53                    "INNER JOIN setup ON executable.setupid = setup.id "
54                    "INNER JOIN platform ON setup.platformid=platform.id "
55                    "INNER JOIN mediatype ON setup.mediatypeid=mediatype.id "
56                    "%1 "
57                    "ORDER BY executable.name").arg(where);
58 }
59
60 Qt::ItemFlags ExternalExecutableModel::flags(const QModelIndex &index) const
61 {
62     Qt::ItemFlags flags = QSqlQueryModel::flags(index);
63     int col = index.column();
64     if (col == Executable_Name ||
65         col == Executable_Options ||
66         col == Executable_Executable ||
67         col == Executable_SetupId) {
68        flags  |= Qt::ItemIsEditable;
69     }
70     return flags;
71 }
72
73 bool ExternalExecutableModel::setData(const QModelIndex &index, const QVariant &value, int role)
74 {
75     // TODO
76     return false;
77 }
78
79 bool ExternalExecutableModel::insertRows(int row, int count, const QModelIndex &parent)
80 {
81     // TODO
82     return false;
83 }
84
85 bool ExternalExecutableModel::removeRows(int row, int count, const QModelIndex &parent)
86 {
87     // TODO
88     return false;
89 }
90
91 bool ExternalExecutableModel::setSetup(int isd, int setupId)
92 {
93     // TODO
94     return false;
95 }