MythTV  master
mythgame.cpp
Go to the documentation of this file.
1 // MythTV
2 #include <libmyth/mythcontext.h>
6 #include <libmythbase/mythversion.h>
9 
10 // MythGame
11 #include "gamedbcheck.h"
12 #include "gamehandler.h"
13 #include "gamesettings.h"
14 #include "gameui.h"
15 
16 #define LOC_ERR QString("MythGame:MAIN Error: ")
17 #define LOC QString("MythGame:MAIN: ")
18 
19 struct GameData
20 {
21 };
22 
23 static void GameCallback(void *data, QString &selection)
24 {
25  [[maybe_unused]] auto *ddata = static_cast<GameData *>(data);
26  QString sel = selection.toLower();
27 
28  if (sel == "game_settings")
29  {
31  auto *ssd = new StandardSettingDialog(mainStack, "gamesettings",
32  new GameGeneralSettings());
33 
34  if (ssd->Create())
35  mainStack->AddScreen(ssd);
36  else
37  delete ssd;
38  }
39 
40  if (sel == "game_players")
41  {
43  auto *ssd = new StandardSettingDialog(mainStack, "gamesettings",
44  new GamePlayersList());
45 
46  if (ssd->Create())
47  mainStack->AddScreen(ssd);
48  else
49  delete ssd;
50  }
51  else if (sel == "search_for_games")
52  {
54  }
55  if (sel == "clear_game_data")
56  {
57  auto *handler = new GameHandler();
58  handler->clearAllGameData();
59  }
60 
61 }
62 
63 static int runMenu(const QString& which_menu)
64 {
65  QString themedir = GetMythUI()->GetThemeDir();
66 
67  auto *menu = new MythThemedMenu(themedir, which_menu,
68  GetMythMainWindow()->GetMainStack(),
69  "game menu");
70 
71  GameData data;
72 
73  menu->setCallback(GameCallback, &data);
74  menu->setKillable();
75 
76  if (menu->foundTheme())
77  {
78  if (LCD *lcd = LCD::Get())
79  lcd->switchToTime();
80 
82  return 0;
83  }
84 
85  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
86  .arg(which_menu, themedir));
87  delete menu;
88  return -1;
89 }
90 
91 static int RunGames(void)
92 {
94  auto *game = new GameUI(mainStack);
95 
96  if (game->Create())
97  {
98  mainStack->AddScreen(game);
99  return 0;
100  }
101  delete game;
102  return -1;
103 }
104 
105 static void runGames(void)
106 {
107  RunGames();
108 }
109 
110 static void setupKeys(void)
111 {
112  REG_JUMP("MythGame", QT_TRANSLATE_NOOP("MythControls",
113  "Game frontend"), "", runGames);
114 
115  REG_KEY("Game", "TOGGLEFAV", QT_TRANSLATE_NOOP("MythControls",
116  "Toggle the current game as a favorite"), "?,/");
117  REG_KEY("Game", "INCSEARCH", QT_TRANSLATE_NOOP("MythControls",
118  "Show incremental search dialog"), "Ctrl+S");
119  REG_KEY("Game", "INCSEARCHNEXT", QT_TRANSLATE_NOOP("MythControls",
120  "Incremental search find next match"), "Ctrl+N");
121  REG_KEY("Game","DOWNLOADDATA", QT_TRANSLATE_NOOP("MythControls",
122  "Download metadata for current item"), "W");
123 }
124 
125 int mythplugin_init(const char *libversion)
126 {
127  if (!MythCoreContext::TestPluginVersion("mythgame", libversion,
128  MYTH_BINARY_VERSION))
129  return -1;
130 
133  {
134  LOG(VB_GENERAL, LOG_ERR,
135  "Couldn't upgrade database to new schema, exiting.");
136  return -1;
137  }
139 
140  setupKeys();
141 
142  return 0;
143 }
144 
145 int mythplugin_run(void)
146 {
147  return RunGames();
148 }
149 
151 {
152  return runMenu("game_settings.xml");
153 }
154 
mythplugin_init
int mythplugin_init(const char *libversion)
Definition: mythgame.cpp:125
themedir
static QString themedir
Definition: mythdirs.cpp:23
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:318
runGames
static void runGames(void)
Definition: mythgame.cpp:105
REG_KEY
static void REG_KEY(const QString &Context, const QString &Action, const QString &Description, const QString &Key)
Definition: mythmainwindow.h:175
GameUI
Definition: gameui.h:25
gamedbcheck.h
UpgradeGameDatabaseSchema
bool UpgradeGameDatabaseSchema(void)
Definition: gamedbcheck.cpp:86
GameHandler
Definition: gamehandler.h:64
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythThemedMenu::foundTheme
bool foundTheme(void) const
Returns true iff a theme has been found by a previous call to SetMenuTheme().
Definition: myththemedmenu.cpp:142
MythCoreContext::TestPluginVersion
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
Definition: mythcorecontext.cpp:2079
LCD::Get
static LCD * Get(void)
Definition: lcddevice.cpp:69
GameCallback
static void GameCallback(void *data, QString &selection)
Definition: mythgame.cpp:23
runMenu
static int runMenu(const QString &which_menu)
Definition: mythgame.cpp:63
StandardSettingDialog
Definition: standardsettings.h:468
GameGeneralSettings
Definition: gamesettings.h:11
GameData
Definition: mythgame.cpp:19
menu
static MythThemedMenu * menu
Definition: mythtv-setup.cpp:58
MythUIThemeHelper::GetThemeDir
QString GetThemeDir()
Definition: mythuithemehelper.cpp:141
GamePlayersList
Definition: gamesettings.h:40
GameHandler::processAllGames
static void processAllGames(void)
Definition: gamehandler.cpp:759
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
mythpluginapi.h
MythThemedMenu::setKillable
void setKillable(void)
Definition: myththemedmenu.cpp:163
gamesettings.h
mythplugin_config
int mythplugin_config(void)
Definition: mythgame.cpp:150
mythuihelper.h
RunGames
static int RunGames(void)
Definition: mythgame.cpp:91
REG_JUMP
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
Definition: mythmainwindow.h:188
mythcontext.h
MythThemedMenu::setCallback
void setCallback(void(*lcallback)(void *, QString &), void *data)
Set the themed menus callback function and data for that function.
Definition: myththemedmenu.cpp:156
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythCoreContext::ActivateSettingsCache
void ActivateSettingsCache(bool activate=true)
Definition: mythcorecontext.cpp:833
setupKeys
static void setupKeys(void)
Definition: mythgame.cpp:110
MythThemedMenu
Themed menu class, used for main menus in MythTV frontend.
Definition: myththemedmenu.h:57
myththemedmenu.h
gameui.h
lcddevice.h
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:66
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
gamehandler.h
mythplugin_run
int mythplugin_run(void)
Definition: mythgame.cpp:145
LCD
Definition: lcddevice.h:169