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  auto *ddata = static_cast<GameData *>(data);
26  QString sel = selection.toLower();
27 
28  (void)ddata;
29 
30  if (sel == "game_settings")
31  {
33  auto *ssd = new StandardSettingDialog(mainStack, "gamesettings",
34  new GameGeneralSettings());
35 
36  if (ssd->Create())
37  mainStack->AddScreen(ssd);
38  else
39  delete ssd;
40  }
41 
42  if (sel == "game_players")
43  {
45  auto *ssd = new StandardSettingDialog(mainStack, "gamesettings",
46  new GamePlayersList());
47 
48  if (ssd->Create())
49  mainStack->AddScreen(ssd);
50  else
51  delete ssd;
52  }
53  else if (sel == "search_for_games")
54  {
56  }
57  if (sel == "clear_game_data")
58  {
59  auto *handler = new GameHandler();
60  handler->clearAllGameData();
61  }
62 
63 }
64 
65 static int runMenu(const QString& which_menu)
66 {
67  QString themedir = GetMythUI()->GetThemeDir();
68 
69  auto *menu = new MythThemedMenu(themedir, which_menu,
70  GetMythMainWindow()->GetMainStack(),
71  "game menu");
72 
73  GameData data;
74 
75  menu->setCallback(GameCallback, &data);
76  menu->setKillable();
77 
78  if (menu->foundTheme())
79  {
80  if (LCD *lcd = LCD::Get())
81  lcd->switchToTime();
82 
84  return 0;
85  }
86 
87  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
88  .arg(which_menu, themedir));
89  delete menu;
90  return -1;
91 }
92 
93 static int RunGames(void)
94 {
96  auto *game = new GameUI(mainStack);
97 
98  if (game->Create())
99  {
100  mainStack->AddScreen(game);
101  return 0;
102  }
103  delete game;
104  return -1;
105 }
106 
107 static void runGames(void)
108 {
109  RunGames();
110 }
111 
112 static void setupKeys(void)
113 {
114  REG_JUMP("MythGame", QT_TRANSLATE_NOOP("MythControls",
115  "Game frontend"), "", runGames);
116 
117  REG_KEY("Game", "TOGGLEFAV", QT_TRANSLATE_NOOP("MythControls",
118  "Toggle the current game as a favorite"), "?,/");
119  REG_KEY("Game", "INCSEARCH", QT_TRANSLATE_NOOP("MythControls",
120  "Show incremental search dialog"), "Ctrl+S");
121  REG_KEY("Game", "INCSEARCHNEXT", QT_TRANSLATE_NOOP("MythControls",
122  "Incremental search find next match"), "Ctrl+N");
123  REG_KEY("Game","DOWNLOADDATA", QT_TRANSLATE_NOOP("MythControls",
124  "Download metadata for current item"), "W");
125 }
126 
127 int mythplugin_init(const char *libversion)
128 {
129  if (!MythCoreContext::TestPluginVersion("mythgame", libversion,
130  MYTH_BINARY_VERSION))
131  return -1;
132 
135  {
136  LOG(VB_GENERAL, LOG_ERR,
137  "Couldn't upgrade database to new schema, exiting.");
138  return -1;
139  }
141 
142  setupKeys();
143 
144  return 0;
145 }
146 
147 int mythplugin_run(void)
148 {
149  return RunGames();
150 }
151 
153 {
154  return runMenu("game_settings.xml");
155 }
156 
mythplugin_init
int mythplugin_init(const char *libversion)
Definition: mythgame.cpp:127
themedir
static QString themedir
Definition: mythdirs.cpp:21
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:315
runGames
static void runGames(void)
Definition: mythgame.cpp:107
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:2049
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:65
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:764
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:54
mythpluginapi.h
MythThemedMenu::setKillable
void setKillable(void)
Definition: myththemedmenu.cpp:163
gamesettings.h
mythplugin_config
int mythplugin_config(void)
Definition: mythgame.cpp:152
mythuihelper.h
RunGames
static int RunGames(void)
Definition: mythgame.cpp:93
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:102
MythCoreContext::ActivateSettingsCache
void ActivateSettingsCache(bool activate=true)
Definition: mythcorecontext.cpp:831
setupKeys
static void setupKeys(void)
Definition: mythgame.cpp:112
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:50
gamehandler.h
mythplugin_run
int mythplugin_run(void)
Definition: mythgame.cpp:147
LCD
Definition: lcddevice.h:173