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