00001 #include <qdir.h>
00002 #include <iostream>
00003 using namespace std;
00004
00005 #include <qapplication.h>
00006 #include <unistd.h>
00007
00008 #include "gamehandler.h"
00009 #include "rominfo.h"
00010 #include "gamesettings.h"
00011 #include "gametree.h"
00012 #include "dbcheck.h"
00013
00014 #include <mythtv/mythcontext.h>
00015 #include <mythtv/mythdbcon.h>
00016 #include <mythtv/lcddevice.h>
00017 #include <mythtv/libmythui/myththemedmenu.h>
00018 #include <mythtv/mythpluginapi.h>
00019
00020 #define LOC_ERR QString("MythGame:MAIN Error: ")
00021 #define LOC QString("MythGame:MAIN: ")
00022
00023 struct GameData
00024 {
00025 };
00026
00027 void GameCallback(void *data, QString &selection)
00028 {
00029 GameData *ddata = (GameData *)data;
00030 QString sel = selection.lower();
00031
00032 (void)ddata;
00033
00034 if (sel == "game_settings")
00035 {
00036 MythGameGeneralSettings settings;
00037 settings.exec();
00038 }
00039
00040 if (sel == "game_players")
00041 {
00042 MythGamePlayerEditor mgpe;
00043 mgpe.exec();
00044 }
00045 else if (sel == "search_for_games")
00046 {
00047 GameHandler::processAllGames();
00048 }
00049 if (sel == "clear_game_data")
00050 {
00051 GameHandler::clearAllGameData();
00052 }
00053
00054 }
00055
00056 void runMenu(QString which_menu)
00057 {
00058 QString themedir = gContext->GetThemeDir();
00059
00060 MythThemedMenu *diag = new MythThemedMenu(themedir.ascii(), which_menu,
00061 GetMythMainWindow()->GetMainStack(),
00062 "game menu");
00063
00064 GameData data;
00065
00066 diag->setCallback(GameCallback, &data);
00067 diag->setKillable();
00068
00069 if (diag->foundTheme())
00070 {
00071 if (class LCD * lcd = LCD::Get())
00072 {
00073 lcd->switchToTime();
00074 }
00075 GetMythMainWindow()->GetMainStack()->AddScreen(diag);
00076 }
00077 else
00078 {
00079 VERBOSE(VB_GENERAL, LOC_ERR + QString("Couldn't find theme %1")
00080 .arg(themedir));
00081 delete diag;
00082 }
00083 }
00084
00085 void runGames(void);
00086
00087 void setupKeys(void)
00088 {
00089 REG_JUMP("MythGame", "Game frontend", "", runGames);
00090
00091 REG_KEY("Game", "TOGGLEFAV", "Toggle the current game as a favorite",
00092 "?,/");
00093 REG_KEY("Game", "INCSEARCH", "Show incremental search dialog", "Ctrl+S");
00094 REG_KEY("Game", "INCSEARCHNEXT", "Incremental search find next match", "Ctrl+N");
00095
00096 }
00097
00098 int mythplugin_init(const char *libversion)
00099 {
00100 if (!gContext->TestPopupVersion("mythgame", libversion,
00101 MYTH_BINARY_VERSION))
00102 return -1;
00103
00104
00105 gContext->ActivateSettingsCache(false);
00106 if (!UpgradeGameDatabaseSchema())
00107 {
00108 VERBOSE(VB_IMPORTANT,
00109 "Couldn't upgrade database to new schema, exiting.");
00110 return -1;
00111 }
00112 gContext->ActivateSettingsCache(true);
00113
00114 MythGamePlayerSettings settings;
00115
00116
00117
00118 setupKeys();
00119
00120 return 0;
00121 }
00122
00123 void runGames(void)
00124 {
00125 gContext->addCurrentLocation("mythgame");
00126 GameTree gametree(gContext->GetMainWindow(), "gametree", "game-");
00127 gametree.exec();
00128 gContext->removeCurrentLocation();
00129 }
00130
00131 int mythplugin_run(void)
00132 {
00133 runGames();
00134 return 0;
00135 }
00136
00137 int mythplugin_config(void)
00138 {
00139 runMenu("game_settings.xml");
00140 return 0;
00141 }
00142