00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qapplication.h>
00013
00014 #include <unistd.h>
00015
00016 #include <mythtv/lcddevice.h>
00017 #include <mythtv/mythcontext.h>
00018 #include <mythtv/mythdialogs.h>
00019 #include <mythtv/mythplugin.h>
00020 #include <mythtv/libmythui/myththemedmenu.h>
00021 #include <mythtv/mythpluginapi.h>
00022
00023 #include "weather.h"
00024 #include "weatherSetup.h"
00025 #include "sourceManager.h"
00026 #include "dbcheck.h"
00027
00028 SourceManager *srcMan = 0;
00029 XMLParse *theme = 0;
00030
00031 void runWeather();
00032 void loadTheme();
00033
00034 void setupKeys()
00035 {
00036 REG_JUMP("MythWeather", "Weather forecasts", "", runWeather);
00037 REG_KEY("Weather", "PAUSE", "Pause current page", "P");
00038 REG_KEY("Weather", "SEARCH", "Search List", "/");
00039 REG_KEY("Weather", "NEXTSEARCH", "Search List", "n");
00040 REG_KEY("Weather", "UPDATE", "Search List", "u");
00041 REG_KEY("Weather", "DELETE", "Delete screen from list", "D");
00042 }
00043
00044 int mythplugin_init(const char *libversion)
00045 {
00046 if (!gContext->TestPopupVersion("mythweather", libversion,
00047 MYTH_BINARY_VERSION))
00048 return -1;
00049
00050 gContext->ActivateSettingsCache(false);
00051 InitializeDatabase();
00052 gContext->ActivateSettingsCache(true);
00053
00054 setupKeys();
00055
00056 if (gContext->GetNumSetting("weatherbackgroundfetch", 0))
00057 {
00058 srcMan = new SourceManager();
00059 srcMan->startTimers();
00060 srcMan->doUpdate();
00061 }
00062
00063 return 0;
00064 }
00065
00066 void runWeather()
00067 {
00068 gContext->addCurrentLocation("mythweather");
00069 if (!srcMan)
00070 {
00071 srcMan = new SourceManager();
00072 srcMan->startTimers();
00073 srcMan->doUpdate();
00074 }
00075 Weather *weatherDat = new Weather(gContext->GetMainWindow(), srcMan,
00076 "weather");
00077 weatherDat->exec();
00078 delete weatherDat;
00079 gContext->removeCurrentLocation();
00080 if (!gContext->GetNumSetting("weatherbackgroundfetch", 0))
00081 {
00082 delete srcMan;
00083 srcMan = 0;
00084 }
00085 }
00086
00087 int mythplugin_run()
00088 {
00089 runWeather();
00090 return 0;
00091 }
00092
00093 void WeatherCallback(void *data, QString &selection)
00094 {
00095 (void) data;
00096 if (selection == "SETTINGS_GENERAL")
00097 {
00098 GlobalSetup gsetup(gContext->GetMainWindow());
00099 gsetup.exec();
00100 }
00101 else if (selection == "SETTINGS_SCREEN")
00102 {
00103 if (!srcMan)
00104 {
00105 srcMan = new SourceManager();
00106 }
00107 srcMan->clearSources();
00108 srcMan->findScripts();
00109 ScreenSetup ssetup(gContext->GetMainWindow(), srcMan);
00110 ssetup.exec();
00111 if (gContext->GetNumSetting("weatherbackgroundfetch", 0))
00112 {
00113 if (!srcMan)
00114 srcMan = new SourceManager();
00115 else
00116 {
00117 srcMan->clearSources();
00118 srcMan->findScriptsDB();
00119 srcMan->setupSources();
00120 }
00121
00122 srcMan->startTimers();
00123 srcMan->doUpdate();
00124 }
00125 else
00126 {
00127 if (srcMan)
00128 {
00129 delete srcMan;
00130 srcMan = 0;
00131 }
00132 }
00133 }
00134 else if (selection == "SETTINGS_SOURCE")
00135 {
00136 SourceSetup srcsetup(gContext->GetMainWindow());
00137 if (srcsetup.loadData())
00138 {
00139 srcsetup.exec();
00140 }
00141 else
00142 {
00143 MythPopupBox::showOkPopup(gContext->GetMainWindow(), "no sources",
00144 QObject::tr("No Sources defined, Sources are defined by"
00145 " adding screens in Screen Setup."));
00146 }
00147 }
00148 }
00149
00150 int mythplugin_config()
00151 {
00152 MythThemedMenu *menu =
00153 new MythThemedMenu(gContext->GetThemeDir().ascii(),
00154 "weather_settings.xml",
00155 gContext->GetMainWindow()->GetMainStack(),
00156 "weather menu");
00157 menu->setCallback(WeatherCallback, 0);
00158 menu->setKillable();
00159 if (menu->foundTheme())
00160 {
00161 if (LCD *lcd = LCD::Get())
00162 lcd->switchToTime();
00163
00164 GetMythMainWindow()->GetMainStack()->AddScreen(menu);
00165 }
00166 else
00167 cerr << "Couldn't find theme weather_settings.xml" << endl;
00168
00169 return 0;
00170 }
00171
00172 void mythplugin_destroy()
00173 {
00174 if (srcMan)
00175 {
00176 delete srcMan;
00177 srcMan = 0;
00178 }
00179 }