MythTV  master
mythplugins/mythgame/mythgame/main.cpp
Go to the documentation of this file.
1 #include "gameui.h"
2 #include "gamehandler.h"
3 #include "gamesettings.h"
4 #include "dbcheck.h"
5 
6 #include <mythcontext.h>
7 #include <mythdbcon.h>
8 #include <mythversion.h>
9 #include <lcddevice.h>
10 #include <myththemedmenu.h>
11 #include <mythpluginapi.h>
12 #include <mythuihelper.h>
13 
14 #define LOC_ERR QString("MythGame:MAIN Error: ")
15 #define LOC QString("MythGame:MAIN: ")
16 
17 struct GameData
18 {
19 };
20 
21 static void GameCallback(void *data, QString &selection)
22 {
23  GameData *ddata = (GameData *)data;
24  QString sel = selection.toLower();
25 
26  (void)ddata;
27 
28  if (sel == "game_settings")
29  {
32  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  GameHandler *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 
69  themedir, which_menu, GetMythMainWindow()->GetMainStack(), "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).arg(themedir));
87  delete menu;
88  return -1;
89 }
90 
91 static int RunGames(void)
92 {
94  GameUI *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 (!gCoreContext->TestPluginVersion("mythgame", libversion,
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 
#define REG_JUMP(a, b, c, d)
void clearAllGameData(void)
int mythplugin_init(const char *libversion)
static QString themedir
Definition: mythdirs.cpp:21
bool UpgradeGameDatabaseSchema(void)
static int runMenu(const QString &which_menu)
void setCallback(void(*lcallback)(void *, QString &), void *data)
Set the themed menus callback function and data for that function.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
#define REG_KEY(a, b, c, d)
static MythThemedMenu * menu
QString GetThemeDir(void)
bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
static LCD * Get(void)
Definition: lcddevice.cpp:65
void setKillable(void)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
static void GameCallback(void *data, QString &selection)
static void processAllGames(void)
static int RunGames(void)
MythUIHelper * GetMythUI()
MythMainWindow * GetMythMainWindow(void)
bool Create() override
Definition: gameui.cpp:55
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
Themed menu class, used for main menus in MythTV frontend.
bool Create(void) override
static void runGames(void)
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
bool foundTheme(void)
Returns true iff a theme has been found by a previous call to SetMenuTheme().
Definition: lcddevice.h:165
static void setupKeys(void)
void ActivateSettingsCache(bool activate=true)
Definition: gameui.h:24