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