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