MythTV  master
gamesettings.cpp
Go to the documentation of this file.
1 #include <QCoreApplication>
2 
3 #include <mythdb.h>
4 #include <mythdirs.h>
5 
6 #include "gamesettings.h"
7 
8 struct GameTypes {
9  QString m_nameStr;
10  QString m_idStr;
11  QString m_extensions;
12 };
13 
14 const std::array<GameTypes,12> GameTypeList
15 {{
16  { QT_TRANSLATE_NOOP("(GameTypes)", "OTHER"), "OTHER", "" },
17  { QT_TRANSLATE_NOOP("(GameTypes)", "AMIGA"), "AMIGA", "adf,ipf" },
18  { QT_TRANSLATE_NOOP("(GameTypes)", "ATARI"), "ATARI", "bin,a26" },
19  { QT_TRANSLATE_NOOP("(GameTypes)", "GAMEGEAR"), "GAMEGEAR", "gg" },
20  { QT_TRANSLATE_NOOP("(GameTypes)", "GENESIS/MEGADRIVE"), "GENESIS", "smd,bin,md" },
21  { QT_TRANSLATE_NOOP("(GameTypes)", "MAME"), "MAME", "" },
22  { QT_TRANSLATE_NOOP("(GameTypes)", "N64"), "N64", "v64,n64" },
23  { QT_TRANSLATE_NOOP("(GameTypes)", "NES"), "NES", "zip,nes" },
24  { QT_TRANSLATE_NOOP("(GameTypes)", "PC GAME"), "PC", "" },
25  { QT_TRANSLATE_NOOP("(GameTypes)", "PCE/TG16"),"PCE", "pce" },
26  { QT_TRANSLATE_NOOP("(GameTypes)", "SEGA/MASTER SYSTEM"), "SEGA", "sms" },
27  { QT_TRANSLATE_NOOP("(GameTypes)", "SNES"), "SNES", "zip,smc,sfc,fig,swc" }
28 }};
29 
30 QString GetGameTypeName(const QString &GameType)
31 {
32  auto sametype = [GameType](const auto & console)
33  { return console.m_idStr == GameType; };
34  const auto *const con = std::find_if(GameTypeList.cbegin(), GameTypeList.cend(), sametype);
35  return (con != GameTypeList.cend())
36  ? QCoreApplication::translate("(GameTypes)", con->m_nameStr.toUtf8())
37  : "";
38 }
39 
40 QString GetGameTypeExtensions(const QString &GameType)
41 {
42  auto sametype = [GameType](const auto & console)
43  { return console.m_idStr == GameType; };
44  const auto *const con = std::find_if(GameTypeList.cbegin(), GameTypeList.cend(), sametype);
45  return (con != GameTypeList.cend()) ? con->m_extensions : "";
46 }
47 
48 // -----------------------------------------------------------------------
49 
50 // General Settings
51 #undef TR
52 #define TR GameGeneralSettings::tr
53 
55 {
56  auto *gc = new HostTextEditSetting("GameAllTreeLevels");
57  gc->setLabel(TR("Game display order"));
58  gc->setValue("system gamename");
59  gc->setHelpText(TR("Order in which to sort the "
60  "games - this is for all "
61  "systems. Available choices: "
62  "system, year, genre and "
63  "gamename"));
64  return gc;
65 }
66 
68 {
69  auto *gc = new HostTextEditSetting("GameFavTreeLevels");
70  gc->setLabel(TR("Favorite display order"));
71  gc->setValue("gamename");
72  gc->setHelpText(TR("Order in which to sort the "
73  "games marked as favorites "
74  "- this is for all systems. "
75  "Available choices: system, "
76  "year, genre and gamename"));
77  return gc;
78 }
79 
81 {
82  auto *gc = new HostCheckBoxSetting("GameDeepScan");
83  gc->setLabel(TR("Indepth Game Scan"));
84  gc->setHelpText(
85  TR("Enabling this causes a game scan to "
86  "gather CRC values and attempt to find out "
87  "more detailed information about the game: "
88  "NOTE this can greatly increase the time a "
89  "game scan takes based on the amount of "
90  "games scanned."));
91  return gc;
92 }
93 
95 {
96  auto *gc = new HostCheckBoxSetting("GameRemovalPrompt");
97  gc->setLabel(TR("Prompt for removal of deleted ROM(s)"));
98  gc->setHelpText(TR("This enables a prompt for "
99  "removing deleted ROMs from "
100  "the database during a game "
101  "scan"));
102 
103  return gc;
104 }
105 
107 {
108  auto *gc = new HostCheckBoxSetting("GameShowFileNames");
109  gc->setLabel(TR("Display Files Names in Game "
110  "Tree"));
111  gc->setHelpText(TR("Enabling this causes the "
112  "filenames to be displayed in "
113  "the game tree rather than the "
114  "trimmed/looked up game name"));
115  return gc;
116 }
117 
119 {
120  auto *gc = new HostCheckBoxSetting("GameTreeView");
121  gc->setLabel(TR("Hash filenames in display"));
122  gc->setValue(0);
123  gc->setHelpText(TR("Enable hashing of names in "
124  "the display tree. This can "
125  "make navigating long lists "
126  "a little faster"));
127  return gc;
128 }
129 
131 {
132  auto *gc = new HostTextEditSetting("mythgame.screenshotdir");
133  gc->setLabel(TR("Directory where Game Screenshots "
134  "are stored"));
135  gc->setValue(GetConfDir() + "/MythGame/Screenshots");
136  gc->setHelpText(TR("This directory will be the "
137  "default browse location when "
138  "assigning screenshots."));
139  return gc;
140 }
141 
143 {
144  auto *gc = new HostTextEditSetting("mythgame.fanartdir");
145  gc->setLabel(TR("Directory where Game Fanart is "
146  "stored"));
147  gc->setValue(GetConfDir() + "/MythGame/Fanart");
148  gc->setHelpText(TR("This directory will be the "
149  "default browse location when "
150  "assigning fanart."));
151  return gc;
152 }
153 
155 {
156  auto *gc = new HostTextEditSetting("mythgame.boxartdir");
157  gc->setLabel(TR("Directory where Game Boxart is "
158  "stored"));
159  gc->setValue(GetConfDir() + "/MythGame/Boxart");
160  gc->setHelpText(TR("This directory will be the "
161  "default browse location when "
162  "assigning boxart."));
163  return gc;
164 }
165 
167 {
168  setLabel(tr("MythGame Settings -- General"));
178 }
179 
180 // -----------------------------------------------------------------------
181 
182 // Player Settings
183 #undef TR
184 #define TR GamePlayerSetting::tr
185 
188 {
189  GameDBStorage(StorageUser *user, const PlayerId &id, const QString &name)
190  : SimpleDBStorage(user, "gameplayers", name), m_id(id) {}
191 protected:
192  const PlayerId &m_id;
193 
194  QString GetWhereClause(MSqlBindings &bindings) const override // SimpleStorage
195  {
196  bindings.insert(":PLAYERID", m_id.Value());
197  return "gameplayerid = :PLAYERID";
198  }
199 
200  QString GetSetClause(MSqlBindings &bindings) const override // SimpleStorage
201  {
202  bindings.insert(":SETPLAYERID", m_id.Value());
203  bindings.insert(":SETCOLUMN", m_user->GetDBValue());
204  return QString("gameplayerid = :SETPLAYERID, "
205  "%2 = :SETCOLUMN").arg(GetColumnName());
206  }
207 };
208 
211 {
212  explicit TextEdit(const PlayerId &parent, const QString& column) :
213  MythUITextEditSetting(new GameDBStorage(this, parent, column))
214  {}
215 };
216 
217 struct Name : public TextEdit
218 {
219  explicit Name(const PlayerId &parent)
220  : TextEdit(parent, "playername")
221  {
222  setLabel(TR("Player Name"));
223  setHelpText(TR("Name of this Game and or Emulator"));
224  }
225 };
226 
227 struct Command : public TextEdit
228 {
229  explicit Command(const PlayerId &parent)
230  : TextEdit(parent, "commandline")
231  {
232  setLabel(TR("Command"));
233  setHelpText(TR("Binary and optional parameters. Multiple commands "
234  "separated with \';\' . Use \%s for the ROM name. "
235  "\%d1, \%d2, \%d3 and \%d4 represent disks in a "
236  "multidisk/game. %s auto appended if not specified"));
237  }
238 };
239 
241 {
242  explicit GameType(const PlayerId &parent) :
243  MythUIComboBoxSetting(new GameDBStorage(this, parent, "gametype"))
244  {
245  //: Game type
246  setLabel(TR("Type"));
247  for (const auto & console : GameTypeList)
248  {
249  addSelection(QCoreApplication::translate("(GameTypes)",
250  console.m_nameStr.toUtf8()),
251  console.m_idStr);
252  }
253  setValue(0);
254  setHelpText(TR("Type of Game/Emulator. Mostly for informational "
255  "purposes and has little effect on the "
256  "function of your system."));
257  }
258 };
259 
260 struct RomPath : public TextEdit
261 {
262  explicit RomPath(const PlayerId &parent)
263  : TextEdit(parent, "rompath")
264  {
265  setLabel(TR("ROM Path"));
266  setHelpText(TR("Location of the ROM files for this emulator"));
267  }
268 };
269 
270 struct WorkingDirPath : public TextEdit
271 {
272  explicit WorkingDirPath(const PlayerId &parent)
273  : TextEdit(parent, "workingpath")
274  {
275  setLabel(TR("Working Directory"));
276  setHelpText(TR("Directory to change to before launching emulator. "
277  "Blank is usually fine"));
278  }
279 };
280 
281 struct Extensions : public TextEdit
282 {
283  explicit Extensions(const PlayerId &parent)
284  : TextEdit(parent, "extensions")
285  {
286  setLabel(TR("File Extensions"));
287  setHelpText(TR("A comma separated list of all file extensions for this "
288  "emulator. Blank means any file under ROM PATH is "
289  "considered to be used with this emulator"));
290  }
291 };
292 
294 {
295  explicit AllowMultipleRoms(const PlayerId &parent) :
296  MythUICheckBoxSetting(new GameDBStorage(this, parent, "spandisks"))
297  {
298  setLabel(TR("Allow games to span multiple ROMs/disks"));
299  setHelpText(TR("This setting means that we will look for items like "
300  "game.1.rom, game.2.rom and consider them a single game."));
301  }
302 };
303 
306  : m_id(id)
307 {
308  setName(name);
309 
310  // Pre-set name for new players
311  auto *nameChild = new Name(m_id);
312  nameChild->setValue(name);
313 
314  addChild(nameChild);
315  addChild(new GameType(m_id));
316  addChild(new Command(m_id));
317  addChild(new RomPath(m_id));
319  addChild(new Extensions(m_id));
321 }
322 
324 {
325  // Allocate id for new player
326  m_id.Save();
328 }
329 
331 {
333  query.prepare("DELETE FROM gameplayers "
334  "WHERE gameplayerid = :PLAYERID");
335 
336  query.bindValue(":PLAYERID", m_id.Value());
337 
338  if (!query.exec() || !query.isActive())
339  MythDB::DBError("Deleting MythGamePlayerSettings:", query);
340 }
341 
342 // -----------------------------------------------------------------------
343 
345 {
346  setLabel(tr("Game Players"));
347 }
348 
350 {
351  clearSettings();
352 
353  auto *newPlayer = new ButtonStandardSetting(tr("(New Game Player)"));
354  addChild(newPlayer);
355  connect(newPlayer, &ButtonStandardSetting::clicked,
357 
358  //: %1 is the player/emulator name, %2 is the type of player/emulator
359  QString playerDisp = tr("%1 (%2)", "Game player/emulator display");
360 
362  query.prepare("SELECT gameplayerid, playername, gametype "
363  "FROM gameplayers "
364  "WHERE playername <> '' "
365  "ORDER BY playername;");
366 
367  if (!query.exec() || !query.isActive())
368  {
369  MythDB::DBError("GamePlayersSetting::Load", query);
370  }
371  else
372  {
373  while (query.next())
374  {
375  int id = query.value(0).toInt();
376  QString name = query.value(1).toString();
377  QString type = query.value(2).toString();
378 
379  auto *child = new GamePlayerSetting(name, id);
380  addChild(child);
381  child->setLabel(playerDisp.arg(name, GetGameTypeName(type)));
382  }
383  }
384 
386 }
387 
389 {
390  MythScreenStack *stack = GetMythMainWindow()->GetStack("popup stack");
391  auto *nameDialog = new MythTextInputDialog(stack, tr("Player Name"));
392 
393  if (nameDialog->Create())
394  {
395  stack->AddScreen(nameDialog);
396  connect(nameDialog, &MythTextInputDialog::haveResult,
398  }
399  else
400  delete nameDialog;
401 }
402 
403 void GamePlayersList::CreateNewPlayer(const QString& name)
404 {
405  if (name.isEmpty())
406  return;
407 
408  // Database name must be unique
409  for (StandardSetting* child : qAsConst(*getSubSettings()))
410  {
411  if (child->getName() == name)
412  {
413  LOG(VB_GENERAL, LOG_ERR,
414  QString("Player name %1 is already used").arg(name));
415  return;
416  }
417  }
418 
419  addChild(new GamePlayerSetting(name));
420 
421  // Redraw list
422  setVisible(true);
423 }
Extensions::Extensions
Extensions(const PlayerId &parent)
Definition: gamesettings.cpp:283
MSqlBindings
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:98
MSqlQuery::isActive
bool isActive(void) const
Definition: mythdbcon.h:204
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:126
GetGameTypeName
QString GetGameTypeName(const QString &GameType)
Definition: gamesettings.cpp:30
StandardSetting::setName
virtual void setName(const QString &name)
Definition: standardsettings.cpp:247
mythdb.h
DBStorage::m_user
StorageUser * m_user
Definition: mythstorage.h:50
GameDBStorage::GetSetClause
QString GetSetClause(MSqlBindings &bindings) const override
Definition: gamesettings.cpp:200
GamePlayersList::GamePlayersList
GamePlayersList()
Definition: gamesettings.cpp:344
RomPath
Definition: gamesettings.cpp:261
ButtonStandardSetting
Definition: standardsettings.h:448
GameDBStorage
Game player database table reader/writer.
Definition: gamesettings.cpp:188
GamePlayerSetting::m_id
PlayerId m_id
Definition: gamesettings.h:36
HostTextEditSetting
Definition: standardsettings.h:166
RomPath::RomPath
RomPath(const PlayerId &parent)
Definition: gamesettings.cpp:262
GamePlayersList::NewPlayerDialog
void NewPlayerDialog() const
Definition: gamesettings.cpp:388
musicbrainzngs.musicbrainz.user
string user
Definition: musicbrainz.py:287
AllowMultipleRoms::AllowMultipleRoms
AllowMultipleRoms(const PlayerId &parent)
Definition: gamesettings.cpp:295
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:198
MythScreenStack
Definition: mythscreenstack.h:16
arg
arg(title).arg(filename).arg(doDelete))
Extensions
Definition: gamesettings.cpp:282
DBStorage::GetColumnName
QString GetColumnName(void) const
Definition: mythstorage.h:47
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
GameType::GameType
GameType(const PlayerId &parent)
Definition: gamesettings.cpp:242
StandardSetting::clearSettings
virtual void clearSettings()
Definition: standardsettings.cpp:153
StorageUser::GetDBValue
virtual QString GetDBValue(void) const =0
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
GameTypes
Definition: gamesettings.cpp:8
mythdirs.h
GameTypes::m_extensions
QString m_extensions
Definition: gamesettings.cpp:11
SimpleDBStorage
Definition: mythstorage.h:56
GameTypes::m_nameStr
QString m_nameStr
Definition: gamesettings.cpp:9
MythTextInputDialog::haveResult
void haveResult(QString)
HostCheckBoxSetting
Definition: standardsettings.h:415
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:326
AllowMultipleRoms
Definition: gamesettings.cpp:294
GameFavTreeLevels
static HostTextEditSetting * GameFavTreeLevels()
Definition: gamesettings.cpp:67
GamePlayersList::CreateNewPlayer
void CreateNewPlayer(const QString &name)
Definition: gamesettings.cpp:403
GameTypes::m_idStr
QString m_idStr
Definition: gamesettings.cpp:10
ButtonStandardSetting::clicked
void clicked()
GameShowFileNames
static HostCheckBoxSetting * GameShowFileNames()
Definition: gamesettings.cpp:106
GetBoxartDir
static HostTextEditSetting * GetBoxartDir()
Definition: gamesettings.cpp:154
StandardSetting::addChild
virtual void addChild(StandardSetting *child)
Definition: standardsettings.cpp:64
Command
Definition: gamesettings.cpp:228
GamePlayerSetting::Save
void Save() override
Definition: gamesettings.cpp:323
GetConfDir
QString GetConfDir(void)
Definition: mythdirs.cpp:224
StandardSetting::getSubSettings
virtual QList< StandardSetting * > * getSubSettings()
Definition: standardsettings.cpp:139
MythUIComboBoxSetting
Definition: standardsettings.h:216
AutoIncrementSetting::Save
void Save(void) override
Definition: standardsettings.cpp:316
GameDBStorage::GetWhereClause
QString GetWhereClause(MSqlBindings &bindings) const override
Definition: gamesettings.cpp:194
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:178
StandardSetting::Load
virtual void Load(void)
Definition: standardsettings.cpp:208
StandardSetting::setHelpText
virtual void setHelpText(const QString &str)
Definition: standardsettings.h:37
GamePlayerSetting::deleteEntry
void deleteEntry() override
Definition: gamesettings.cpp:330
StandardSetting::Save
virtual void Save(void)
Definition: standardsettings.cpp:227
GameRemovalPrompt
static HostCheckBoxSetting * GameRemovalPrompt()
Definition: gamesettings.cpp:94
GamePlayersList::Load
void Load() override
Definition: gamesettings.cpp:349
WorkingDirPath
Definition: gamesettings.cpp:271
uint
unsigned int uint
Definition: compat.h:140
GamePlayerSetting
Definition: gamesettings.h:26
StandardSetting::setLabel
virtual void setLabel(QString str)
Definition: standardsettings.h:34
gamesettings.h
PlayerId::Value
int Value() const
Definition: gamesettings.h:22
GetFanartDir
static HostTextEditSetting * GetFanartDir()
Definition: gamesettings.cpp:142
MythUIComboBoxSetting::addSelection
void addSelection(const QString &label, QString value=QString(), bool select=false)
Definition: standardsettings.cpp:479
GameDeepScan
static HostCheckBoxSetting * GameDeepScan()
Definition: gamesettings.cpp:80
GameDBStorage::m_id
const PlayerId & m_id
Definition: gamesettings.cpp:192
MythUITextEditSetting
Definition: standardsettings.h:144
TextEdit
Base for Game textual settings.
Definition: gamesettings.cpp:211
Name
Definition: channelsettings.cpp:47
Command::Command
Command(const PlayerId &parent)
Definition: gamesettings.cpp:229
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
GameAllTreeLevels
static HostTextEditSetting * GameAllTreeLevels()
Definition: gamesettings.cpp:54
GameGeneralSettings::GameGeneralSettings
GameGeneralSettings()
Definition: gamesettings.cpp:166
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:105
StandardSetting::setVisible
void setVisible(bool visible)
Definition: standardsettings.cpp:53
StandardSetting
Definition: standardsettings.h:30
GameTypeList
const std::array< GameTypes, 12 > GameTypeList
Definition: gamesettings.cpp:15
PlayerId
Definition: gamesettings.h:18
TextEdit::TextEdit
TextEdit(const PlayerId &parent, const QString &column)
Definition: gamesettings.cpp:212
GameType
Definition: gamesettings.cpp:241
MythUICheckBoxSetting
Definition: standardsettings.h:388
GameTreeView
static HostCheckBoxSetting * GameTreeView()
Definition: gamesettings.cpp:118
MythTextInputDialog
Dialog prompting the user to enter a text string.
Definition: mythdialogbox.h:264
GamePlayerSetting::GamePlayerSetting
GamePlayerSetting(const QString &name, uint id=0)
Settings for a game player.
Definition: gamesettings.cpp:305
GameDBStorage::GameDBStorage
GameDBStorage(StorageUser *user, const PlayerId &id, const QString &name)
Definition: gamesettings.cpp:189
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
Name::Name
Name(const PlayerId &parent)
Definition: gamesettings.cpp:219
query
MSqlQuery query(MSqlQuery::InitCon())
GetScreenshotDir
static HostTextEditSetting * GetScreenshotDir()
Definition: gamesettings.cpp:130
WorkingDirPath::WorkingDirPath
WorkingDirPath(const PlayerId &parent)
Definition: gamesettings.cpp:272
MythUIComboBoxSetting::setValue
void setValue(int value) override
Definition: standardsettings.cpp:459
TR
#define TR
Definition: gamesettings.cpp:184
GetGameTypeExtensions
QString GetGameTypeExtensions(const QString &GameType)
Definition: gamesettings.cpp:40
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808
StorageUser
Definition: mythstorage.h:16