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  auto *ddata = (GameData *)data;
24  QString sel = selection.toLower();
25 
26  (void)ddata;
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).arg(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,
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)
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)
static 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)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
Themed menu class, used for main menus in MythTV frontend.
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