MythTV  0.26-pre
main.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 using namespace std;
00003 
00004 #include <unistd.h>
00005 
00006 #include <QDir>
00007 #include <QApplication>
00008 
00009 #include "gameui.h"
00010 #include "gamehandler.h"
00011 #include "rominfo.h"
00012 #include "gamesettings.h"
00013 #include "dbcheck.h"
00014 
00015 #include <mythcontext.h>
00016 #include <mythdbcon.h>
00017 #include <mythversion.h>
00018 #include <lcddevice.h>
00019 #include <myththemedmenu.h>
00020 #include <mythpluginapi.h>
00021 #include <mythuihelper.h>
00022 
00023 #define LOC_ERR QString("MythGame:MAIN Error: ")
00024 #define LOC QString("MythGame:MAIN: ")
00025 
00026 struct GameData
00027 {
00028 };
00029 
00030 static void GameCallback(void *data, QString &selection)
00031 {
00032     GameData *ddata = (GameData *)data;
00033     QString sel = selection.toLower();
00034 
00035     (void)ddata;
00036 
00037     if (sel == "game_settings")
00038     {
00039         MythGameGeneralSettings settings;
00040         settings.exec();
00041     }
00042 
00043     if (sel == "game_players")
00044     {
00045         MythGamePlayerEditor mgpe;
00046         mgpe.exec();
00047     }
00048     else if (sel == "search_for_games")
00049     {
00050         GameHandler::processAllGames();
00051     }
00052     if (sel == "clear_game_data")
00053     {
00054         GameHandler *handler = new GameHandler();
00055         handler->clearAllGameData();
00056     }
00057 
00058 }
00059 
00060 static int runMenu(QString which_menu)
00061 {
00062     QString themedir = GetMythUI()->GetThemeDir();
00063 
00064     MythThemedMenu *menu = new MythThemedMenu(
00065         themedir, which_menu, GetMythMainWindow()->GetMainStack(), "game menu");
00066 
00067     GameData data;
00068 
00069     menu->setCallback(GameCallback, &data);
00070     menu->setKillable();
00071 
00072     if (menu->foundTheme())
00073     {
00074         if (LCD *lcd = LCD::Get())
00075             lcd->switchToTime();
00076 
00077         GetMythMainWindow()->GetMainStack()->AddScreen(menu);
00078         return 0;
00079     }
00080     else
00081     {
00082         LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
00083                               .arg(which_menu).arg(themedir));
00084         delete menu;
00085         return -1;
00086     }
00087 }
00088 
00089 static int RunGames(void)
00090 {
00091     MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00092     GameUI *game = new GameUI(mainStack);
00093 
00094     if (game->Create())
00095     {
00096         mainStack->AddScreen(game);
00097         return 0;
00098     }
00099     else
00100     {
00101         delete game;
00102         return -1;
00103     }
00104 }
00105 
00106 static void runGames(void)
00107 {
00108     RunGames();
00109 }
00110 
00111 static void setupKeys(void)
00112 {
00113     REG_JUMP("MythGame", QT_TRANSLATE_NOOP("MythControls",
00114         "Game frontend"), "", runGames);
00115 
00116     REG_KEY("Game", "TOGGLEFAV", QT_TRANSLATE_NOOP("MythControls",
00117         "Toggle the current game as a favorite"), "?,/");
00118     REG_KEY("Game", "INCSEARCH", QT_TRANSLATE_NOOP("MythControls",
00119         "Show incremental search dialog"), "Ctrl+S");
00120     REG_KEY("Game", "INCSEARCHNEXT", QT_TRANSLATE_NOOP("MythControls",
00121         "Incremental search find next match"), "Ctrl+N");
00122     REG_KEY("Game","DOWNLOADDATA", QT_TRANSLATE_NOOP("MythControls",
00123         "Download metadata for current item"), "W");
00124 }
00125 
00126 int mythplugin_init(const char *libversion)
00127 {
00128     if (!gContext->TestPopupVersion("mythgame", libversion,
00129                                     MYTH_BINARY_VERSION))
00130         return -1;
00131 
00132     gCoreContext->ActivateSettingsCache(false);
00133     if (!UpgradeGameDatabaseSchema())
00134     {
00135         LOG(VB_GENERAL, LOG_ERR,
00136             "Couldn't upgrade database to new schema, exiting.");
00137         return -1;
00138     }
00139     gCoreContext->ActivateSettingsCache(true);
00140 
00141     MythGamePlayerSettings settings;
00142 #if 0
00143     settings.Load();
00144     settings.Save();
00145 #endif
00146 
00147     setupKeys();
00148 
00149     return 0;
00150 }
00151 
00152 int mythplugin_run(void)
00153 {
00154     return RunGames();
00155 }
00156 
00157 int mythplugin_config(void)
00158 {
00159     return runMenu("game_settings.xml");
00160 }
00161 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends