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
21{
22};
23
24static 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",
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
64static 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
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
92static 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
106static void runGames(void)
107{
108 RunGames();
109}
110
111static 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
126int 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
147{
148 return RunGames();
149}
150
152{
153 return runMenu("game_settings.xml");
154}
155
static void processAllGames(void)
Definition: gameui.h:26
Definition: lcddevice.h:170
static LCD * Get(void)
Definition: lcddevice.cpp:69
void ActivateSettingsCache(bool activate=true)
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
MythScreenStack * GetMainStack()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Themed menu class, used for main menus in MythTV frontend.
void setCallback(void(*lcallback)(void *, QString &), void *data)
Set the themed menus callback function and data for that function.
bool foundTheme(void) const
Returns true iff a theme has been found by a previous call to SetMenuTheme().
void setKillable(void)
bool UpgradeGameDatabaseSchema(void)
Definition: gamedbcheck.cpp:87
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static QString themedir
Definition: mythdirs.cpp:23
static void GameCallback(void *data, QString &selection)
Definition: mythgame.cpp:24
int mythplugin_config(void)
Definition: mythgame.cpp:151
static void runGames(void)
Definition: mythgame.cpp:106
static int RunGames(void)
Definition: mythgame.cpp:92
static void setupKeys(void)
Definition: mythgame.cpp:111
static int runMenu(const QString &which_menu)
Definition: mythgame.cpp:64
int mythplugin_run(void)
Definition: mythgame.cpp:146
int mythplugin_init(const char *libversion)
Definition: mythgame.cpp:126
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
static void REG_KEY(const QString &Context, const QString &Action, const QString &Description, const QString &Key)
static MythThemedMenu * menu
MythUIHelper * GetMythUI()