00001
00002 #include <unistd.h>
00003
00004
00005 #include <QApplication>
00006 #include <QDir>
00007
00008
00009 #include <lcddevice.h>
00010 #include <mythcontext.h>
00011 #include <mythplugin.h>
00012 #include <mythpluginapi.h>
00013 #include <mythversion.h>
00014 #include <myththemedmenu.h>
00015 #include <mythmainwindow.h>
00016 #include <mythuihelper.h>
00017
00018
00019 #include "weather.h"
00020 #include "weatherSetup.h"
00021 #include "sourceManager.h"
00022 #include "dbcheck.h"
00023
00024 SourceManager *srcMan = 0;
00025
00026 static int RunWeather()
00027 {
00028 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00029
00030 Weather *weather = new Weather(mainStack, "mythweather", srcMan);
00031
00032 if (weather->Create())
00033 {
00034 if( weather->SetupScreens() )
00035 mainStack->AddScreen(weather);
00036
00037 return 0;
00038 }
00039
00040 delete weather;
00041 return -1;
00042 }
00043
00044 static void runWeather()
00045 {
00046 RunWeather();
00047 }
00048
00049 static void setupKeys()
00050 {
00051 REG_JUMP("MythWeather", QT_TRANSLATE_NOOP("MythControls",
00052 "Weather forecasts"), "", runWeather);
00053 REG_KEY("Weather", "PAUSE", QT_TRANSLATE_NOOP("MythControls",
00054 "Pause current page"), "P");
00055 REG_KEY("Weather", "SEARCH", QT_TRANSLATE_NOOP("MythControls",
00056 "Search List"), "/");
00057 REG_KEY("Weather", "NEXTSEARCH", QT_TRANSLATE_NOOP("MythControls",
00058 "Search List"), "n");
00059 REG_KEY("Weather", "UPDATE", QT_TRANSLATE_NOOP("MythControls",
00060 "Search List"), "u");
00061 }
00062
00063 int mythplugin_init(const char *libversion)
00064 {
00065 if (!gContext->TestPopupVersion("mythweather", libversion,
00066 MYTH_BINARY_VERSION))
00067 return -1;
00068
00069 gCoreContext->ActivateSettingsCache(false);
00070 InitializeDatabase();
00071 gCoreContext->ActivateSettingsCache(true);
00072
00073 setupKeys();
00074
00075 if (gCoreContext->GetNumSetting("weatherbackgroundfetch", 0))
00076 {
00077 srcMan = new SourceManager();
00078 srcMan->startTimers();
00079 srcMan->doUpdate();
00080 }
00081
00082 return 0;
00083 }
00084
00085 int mythplugin_run()
00086 {
00087 return RunWeather();
00088 }
00089
00090 static void WeatherCallback(void *data, QString &selection)
00091 {
00092 (void) data;
00093
00094 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00095
00096 if (selection == "SETTINGS_GENERAL")
00097 {
00098 GlobalSetup *gsetup = new GlobalSetup(mainStack, "weatherglobalsetup");
00099
00100 if (gsetup->Create())
00101 mainStack->AddScreen(gsetup);
00102 else
00103 delete gsetup;
00104 }
00105 else if (selection == "SETTINGS_SCREEN")
00106 {
00107 ScreenSetup *ssetup = new ScreenSetup(mainStack, "weatherscreensetup", srcMan);
00108
00109 if (ssetup->Create())
00110 mainStack->AddScreen(ssetup);
00111 else
00112 delete ssetup;
00113 }
00114 else if (selection == "SETTINGS_SOURCE")
00115 {
00116 SourceSetup *srcsetup = new SourceSetup(mainStack, "weathersourcesetup");
00117
00118 if (srcsetup->Create())
00119 mainStack->AddScreen(srcsetup);
00120 else
00121 delete srcsetup;
00122 }
00123 }
00124
00125 int mythplugin_config()
00126 {
00127 QString menuname = "weather_settings.xml";
00128 QString themedir = GetMythUI()->GetThemeDir();
00129
00130 MythThemedMenu *menu = new MythThemedMenu(
00131 themedir, menuname,
00132 GetMythMainWindow()->GetMainStack(), "weather menu");
00133
00134 menu->setCallback(WeatherCallback, 0);
00135 menu->setKillable();
00136 if (menu->foundTheme())
00137 {
00138 if (LCD *lcd = LCD::Get()) {
00139 lcd->setFunctionLEDs(FUNC_NEWS, false);
00140 lcd->switchToTime();
00141 }
00142
00143 GetMythMainWindow()->GetMainStack()->AddScreen(menu);
00144 return 0;
00145 }
00146 else
00147 {
00148 LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
00149 .arg(menuname).arg(themedir));
00150 delete menu;
00151 return -1;
00152 }
00153 }
00154
00155 void mythplugin_destroy()
00156 {
00157 if (srcMan)
00158 {
00159 delete srcMan;
00160 srcMan = 0;
00161 }
00162 }
00163
00164
00165
00166