00001 #include <mythtv/mythcontext.h>
00002 #include <mythtv/mythdbcon.h>
00003
00004 #include "gamesettings.h"
00005 #include <qfile.h>
00006 #include <qdialog.h>
00007 #include <qcursor.h>
00008 #include <qdir.h>
00009 #include <qimage.h>
00010
00011
00012 const QString GetGameExtensions(const QString GameType)
00013 {
00014 QString result = "";
00015
00016 for (int i = 0; i < MAX_GAME_TYPES; i++)
00017 {
00018 if (GameTypeList[i].idStr == GameType) {
00019 result = GameTypeList[i].extensions;
00020 break;
00021 }
00022 }
00023 return result;
00024 }
00025
00026
00027 static HostLineEdit *GameAllTreeLevels()
00028 {
00029 HostLineEdit *gc = new HostLineEdit("GameAllTreeLevels");
00030 gc->setLabel(QObject::tr("Game display order"));
00031 gc->setValue("system gamename");
00032 gc->setHelpText(QObject::tr("Order in which to sort the games "
00033 "- this is for all systems. Available choices: "
00034 "system, year, genre and gamename"));
00035 return gc;
00036 }
00037
00038 static HostLineEdit *GameFavTreeLevels()
00039 {
00040 HostLineEdit *gc = new HostLineEdit("GameFavTreeLevels");
00041 gc->setLabel(QObject::tr("Favourite display order"));
00042 gc->setValue("gamename");
00043 gc->setHelpText(QObject::tr("Order in which to sort the games "
00044 "marked as favourites "
00045 "- this is for all systems. Available choices: "
00046 "system, year, genre and gamename"));
00047 return gc;
00048 }
00049
00050 static HostCheckBox *GameDeepScan()
00051 {
00052 HostCheckBox *gc = new HostCheckBox("GameDeepScan");
00053 gc->setLabel(QObject::tr("Indepth Game Scan"));
00054 gc->setHelpText(QObject::tr("Enabling this causes a game scan to gather crc values and attempt to find out more"
00055 " detailed information about the game: NOTE this can greatly increase the time a gamescan takes"
00056 " based on the amount of games scanned."));
00057 return gc;
00058 }
00059
00060 static HostCheckBox *GameRemovalPrompt()
00061 {
00062 HostCheckBox *gc = new HostCheckBox("GameRemovalPrompt");
00063 gc->setLabel(QObject::tr("Prompt for removal of deleted rom(s)"));
00064 gc->setHelpText(QObject::tr("This enables a prompt for removing"
00065 " deleted roms from the database during a "
00066 " gamescan"));
00067
00068 return gc;
00069 }
00070
00071 static HostCheckBox *GameShowFileNames()
00072 {
00073 HostCheckBox *gc = new HostCheckBox("GameShowFileNames");
00074 gc->setLabel(QObject::tr("Display Files Names in Game Tree"));
00075 gc->setHelpText(QObject::tr("Enabling this causes the filenames to be displayed in the game tree rather than the trimmed/looked up gamename"));
00076 return gc;
00077 }
00078
00079 static HostCheckBox *GameTreeView()
00080 {
00081 HostCheckBox *gc = new HostCheckBox("GameTreeView");
00082 gc->setLabel(QObject::tr("Hash filenames in display"));
00083 gc->setValue(0);
00084 gc->setHelpText(QObject::tr("Enable hashing of names in the display tree. This can make navigating long lists a little faster"));
00085 return gc;
00086 }
00087
00088 MythGameGeneralSettings::MythGameGeneralSettings()
00089 {
00090 VerticalConfigurationGroup *general = new VerticalConfigurationGroup(false);
00091 general->setLabel(QObject::tr("MythGame Settings -- General"));
00092 general->addChild(GameAllTreeLevels());
00093 general->addChild(GameFavTreeLevels());
00094 general->addChild(GameDeepScan());
00095 general->addChild(GameRemovalPrompt());
00096 general->addChild(GameShowFileNames());
00097 general->addChild(GameTreeView());
00098 addChild(general);
00099 }
00100
00101
00102 QString GameDBStorage::whereClause(MSqlBindings &bindings)
00103 {
00104 QString playerId(":PLAYERID");
00105 QString query("gameplayerid = " + playerId);
00106
00107 bindings.insert(playerId, parent.getGamePlayerID());
00108
00109 return query;
00110 }
00111
00112 QString GameDBStorage::setClause(MSqlBindings &bindings)
00113 {
00114 QString playerID(":SETPLAYERID");
00115 QString colTag(":SET" + getColumn().upper());
00116
00117 QString query("gameplayerid = " + playerID + ", " +
00118 getColumn() + " = " + colTag);
00119
00120 bindings.insert(playerID, parent.getGamePlayerID());
00121 bindings.insert(colTag, setting->getValue());
00122
00123 return query;
00124 }
00125
00126 class AllowMultipleRoms : public CheckBoxSetting, public GameDBStorage
00127 {
00128 public:
00129 AllowMultipleRoms(const MythGamePlayerSettings &parent) :
00130 CheckBoxSetting(this), GameDBStorage(this, parent, "spandisks")
00131 {
00132 setLabel(QObject::tr("Allow games to span multiple roms/disks"));
00133 setHelpText(QObject::tr("This setting means that we will look for items like game.1.rom, game.2.rom and consider them a single game."));
00134 };
00135 };
00136
00137 class Command : public LineEditSetting, public GameDBStorage
00138 {
00139 public:
00140 Command(const MythGamePlayerSettings &parent) :
00141 LineEditSetting(this), GameDBStorage(this, parent, "commandline")
00142 {
00143 setLabel(QObject::tr("Command"));
00144 setHelpText(QObject::tr("Binary and optional parameters. Multiple commands seperated with \';\' . Use \%s for the rom name. \%d1, \%d2, \%d3 and \%d4 represent disks in a multidisk/game. %s auto appended if not specified"));
00145 };
00146 };
00147
00148 class GameType : public ComboBoxSetting, public GameDBStorage
00149 {
00150 public:
00151 GameType(const MythGamePlayerSettings &parent) :
00152 ComboBoxSetting(this), GameDBStorage(this, parent, "gametype")
00153 {
00154 setLabel(QObject::tr("Type"));
00155 for (int i = 0; i < MAX_GAME_TYPES; i++)
00156 {
00157 addSelection(GameTypeList[i].nameStr, GameTypeList[i].idStr);
00158 }
00159 setValue(0);
00160 setHelpText(QObject::tr("Type of Game/Emulator. Mostly for informational purposes and has little effect on the function of your system."));
00161 };
00162 };
00163
00164 class RomPath : public LineEditSetting, public GameDBStorage
00165 {
00166 public:
00167 RomPath(const MythGamePlayerSettings &parent) :
00168 LineEditSetting(this), GameDBStorage(this, parent, "rompath")
00169 {
00170 setLabel(QObject::tr("Rom Path"));
00171 setHelpText(QObject::tr("Location of the ROM files for this emulator"));
00172 };
00173 };
00174
00175 class WorkingDirPath : public LineEditSetting, public GameDBStorage
00176 {
00177 public:
00178 WorkingDirPath(const MythGamePlayerSettings &parent) :
00179 LineEditSetting(this), GameDBStorage(this, parent, "workingpath")
00180 {
00181 setLabel(QObject::tr("Working Directory"));
00182 setHelpText(QObject::tr("Directory to change to before launching emulator. Blank is usually fine"));
00183 };
00184 };
00185
00186 class Extensions : public LineEditSetting, public GameDBStorage
00187 {
00188 public:
00189 Extensions(const MythGamePlayerSettings &parent) :
00190 LineEditSetting(this), GameDBStorage(this, parent, "extensions")
00191 {
00192 setLabel(QObject::tr("File Extensions"));
00193 setHelpText(QObject::tr("A Comma seperated list of all file extensions for this emulator. Blank means any file under ROM PATH is considered to be used with this emulator"));
00194 };
00195 };
00196
00197
00198 class ScreenPath : public LineEditSetting, public GameDBStorage
00199 {
00200 public:
00201 ScreenPath(const MythGamePlayerSettings &parent) :
00202 LineEditSetting(this), GameDBStorage(this, parent, "screenshots")
00203 {
00204 setLabel(QObject::tr("ScreenShots"));
00205 setHelpText(QObject::tr("Path to any screenshots for this player"));
00206 };
00207 };
00208
00209 MythGamePlayerSettings::MythGamePlayerSettings()
00210 {
00211
00212 addChild(id = new ID());
00213
00214 ConfigurationGroup *group = new VerticalConfigurationGroup(false, false);
00215 group->setLabel(QObject::tr("Game Player Setup"));
00216 group->addChild(name = new Name(*this));
00217 group->addChild(new GameType(*this));
00218 group->addChild(new Command(*this));
00219 group->addChild(new RomPath(*this));
00220 group->addChild(new ScreenPath(*this));
00221 group->addChild(new WorkingDirPath(*this));
00222 group->addChild(new Extensions(*this));
00223 group->addChild(new AllowMultipleRoms(*this));
00224 addChild(group);
00225 };
00226
00227 void MythGamePlayerSettings::fillSelections(SelectSetting* setting)
00228 {
00229 MSqlQuery result(MSqlQuery::InitCon());
00230 result.prepare("SELECT playername, gameplayerid, gametype FROM gameplayers WHERE playername <> '' ORDER BY playername;");
00231
00232 if (result.exec() && result.isActive() && result.size() > 0)
00233 {
00234 while (result.next())
00235 {
00236 setting->addSelection(result.value(0).toString() + " (" + result.value(2).toString() + ")",
00237 result.value(1).toString());
00238 }
00239 }
00240 }
00241
00242 void MythGamePlayerSettings::loadByID(int sourceid)
00243 {
00244 id->setValue(sourceid);
00245 load();
00246 }
00247
00248 MythGamePlayerEditor::MythGamePlayerEditor() : listbox(new ListBoxSetting(this))
00249 {
00250 listbox->setLabel(tr("Game Players"));
00251 addChild(listbox);
00252 }
00253
00254 DialogCode MythGamePlayerEditor::exec(void)
00255 {
00256 while (ConfigurationDialog::exec() == kDialogCodeAccepted)
00257 edit();
00258
00259 return kDialogCodeRejected;
00260 }
00261
00262 void MythGamePlayerEditor::load(void)
00263 {
00264 listbox->clearSelections();
00265 listbox->addSelection(QObject::tr("(New Game Player)"), "0");
00266 MythGamePlayerSettings::fillSelections(listbox);
00267 }
00268
00269 MythDialog *MythGamePlayerEditor::dialogWidget(MythMainWindow *parent,
00270 const char *widgetName)
00271 {
00272 dialog = ConfigurationDialog::dialogWidget(parent, widgetName);
00273 connect(dialog, SIGNAL(menuButtonPressed()), this, SLOT(menu()));
00274 connect(dialog, SIGNAL(editButtonPressed()), this, SLOT(edit()));
00275 connect(dialog, SIGNAL(deleteButtonPressed()), this, SLOT(del()));
00276 return dialog;
00277 }
00278
00279 void MythGamePlayerEditor::menu(void)
00280 {
00281 if (!listbox->getValue().toUInt())
00282 {
00283 MythGamePlayerSettings gp;
00284 gp.exec();
00285 }
00286 else
00287 {
00288 DialogCode val = MythPopupBox::Show2ButtonPopup(
00289 gContext->GetMainWindow(),
00290 "", tr("Game Player Menu"),
00291 tr("Edit.."), tr("Delete.."), kDialogCodeButton1);
00292
00293 if (kDialogCodeButton0 == val)
00294 edit();
00295 else if (kDialogCodeButton1 == val)
00296 del();
00297 }
00298 }
00299
00300 void MythGamePlayerEditor::edit(void)
00301 {
00302 MythGamePlayerSettings gp;
00303
00304 uint sourceid = listbox->getValue().toUInt();
00305 if (sourceid)
00306 gp.loadByID(sourceid);
00307
00308 gp.exec();
00309 }
00310
00311 void MythGamePlayerEditor::del(void)
00312 {
00313 DialogCode val = MythPopupBox::Show2ButtonPopup(
00314 gContext->GetMainWindow(), "",
00315 tr("Are you sure you want to delete "
00316 "this item?"),
00317 tr("Yes, delete It"),
00318 tr("No, don't"), kDialogCodeButton1);
00319
00320 if (kDialogCodeButton0 == val)
00321 {
00322 MSqlQuery query(MSqlQuery::InitCon());
00323 query.prepare("DELETE FROM gameplayers "
00324 "WHERE gameplayerid = :SOURCEID");
00325 query.bindValue(":SOURCEID", listbox->getValue());
00326
00327 if (!query.exec() || !query.isActive())
00328 MythContext::DBError("Deleting MythGamePlayerSettings:", query);
00329
00330 load();
00331 }
00332 }
00333