MythTV  master
mythplugins/mythweather/mythweather/main.cpp
Go to the documentation of this file.
1 
2 #include <unistd.h>
3 
4 // MythTV headers
5 #include <lcddevice.h>
6 #include <mythcontext.h>
7 #include <mythplugin.h>
8 #include <mythpluginapi.h>
9 #include <mythversion.h>
10 #include <myththemedmenu.h>
11 #include <mythmainwindow.h>
12 #include <mythuihelper.h>
13 
14 // MythWeather headers
15 #include "weather.h"
16 #include "weatherSetup.h"
17 #include "sourceManager.h"
18 #include "dbcheck.h"
19 
20 SourceManager *srcMan = nullptr;
21 
22 static int RunWeather()
23 {
25 
26  Weather *weather = new Weather(mainStack, "mythweather", srcMan);
27 
28  if (weather->Create())
29  {
30  if( weather->SetupScreens() )
31  mainStack->AddScreen(weather);
32 
33  return 0;
34  }
35 
36  delete weather;
37  return -1;
38 }
39 
40 static void runWeather()
41 {
42  RunWeather();
43 }
44 
45 static void setupKeys()
46 {
47  REG_JUMP("MythWeather", QT_TRANSLATE_NOOP("MythControls",
48  "Weather forecasts"), "", runWeather);
49  REG_KEY("Weather", "PAUSE", QT_TRANSLATE_NOOP("MythControls",
50  "Pause current page"), "P");
51  REG_KEY("Weather", "SEARCH", QT_TRANSLATE_NOOP("MythControls",
52  "Search List"), "/");
53  REG_KEY("Weather", "NEXTSEARCH", QT_TRANSLATE_NOOP("MythControls",
54  "Search List"), "n");
55  REG_KEY("Weather", "UPDATE", QT_TRANSLATE_NOOP("MythControls",
56  "Search List"), "u");
57 }
58 
59 int mythplugin_init(const char *libversion)
60 {
61  if (!gCoreContext->TestPluginVersion("mythweather", libversion,
63  return -1;
64 
68 
69  setupKeys();
70 
71  if (gCoreContext->GetBoolSetting("weatherbackgroundfetch", false))
72  {
73  srcMan = new SourceManager();
75  srcMan->doUpdate();
76  }
77 
78  return 0;
79 }
80 
82 {
83  return RunWeather();
84 }
85 
86 static void WeatherCallback(void *data, QString &selection)
87 {
88  (void) data;
89 
91 
92  if (selection == "SETTINGS_GENERAL")
93  {
94  GlobalSetup *gsetup = new GlobalSetup(mainStack, "weatherglobalsetup");
95 
96  if (gsetup->Create())
97  mainStack->AddScreen(gsetup);
98  else
99  delete gsetup;
100  }
101  else if (selection == "SETTINGS_SCREEN")
102  {
103  ScreenSetup *ssetup = new ScreenSetup(mainStack, "weatherscreensetup", srcMan);
104 
105  if (ssetup->Create())
106  mainStack->AddScreen(ssetup);
107  else
108  delete ssetup;
109  }
110  else if (selection == "SETTINGS_SOURCE")
111  {
112  SourceSetup *srcsetup = new SourceSetup(mainStack, "weathersourcesetup");
113 
114  if (srcsetup->Create())
115  mainStack->AddScreen(srcsetup);
116  else
117  delete srcsetup;
118  }
119 }
120 
122 {
123  QString menuname = "weather_settings.xml";
124  QString themedir = GetMythUI()->GetThemeDir();
125 
127  themedir, menuname,
128  GetMythMainWindow()->GetMainStack(), "weather menu");
129 
130  menu->setCallback(WeatherCallback, nullptr);
131  menu->setKillable();
132  if (menu->foundTheme())
133  {
134  if (LCD *lcd = LCD::Get()) {
135  lcd->setFunctionLEDs(FUNC_NEWS, false);
136  lcd->switchToTime();
137  }
138 
140  return 0;
141  }
142  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
143  .arg(menuname).arg(themedir));
144  delete menu;
145  return -1;
146 }
147 
149 {
150  if (srcMan)
151  {
152  delete srcMan;
153  srcMan = nullptr;
154  }
155 }
156 
157 /*
158  * vim:ts=4:sw=4:ai:et:si:sts=4
159  */
#define REG_JUMP(a, b, c, d)
static QString themedir
Definition: mythdirs.cpp:21
Screen for mythweather global settings.
Definition: weatherSetup.h:40
void setCallback(void(*lcallback)(void *, QString &), void *data)
Set the themed menus callback function and data for that function.
bool SetupScreens()
Definition: weather.cpp:112
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
#define REG_KEY(a, b, c, d)
static MythThemedMenu * menu
QString GetThemeDir(void)
bool Create(void) override
bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
static LCD * Get(void)
Definition: lcddevice.cpp:65
void setKillable(void)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
bool Create(void) override
Definition: weather.cpp:61
bool Create(void) override
bool Create(void) override
MythUIHelper * GetMythUI()
MythMainWindow * GetMythMainWindow(void)
static void WeatherCallback(void *data, QString &selection)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
Themed menu class, used for main menus in MythTV frontend.
static bool InitializeDatabase(void)
bool GetBoolSetting(const QString &key, bool defaultval=false)
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
bool foundTheme(void)
Returns true iff a theme has been found by a previous call to SetMenuTheme().
void doUpdate(bool forceUpdate=false)
Definition: lcddevice.h:165
int mythplugin_init(const char *libversion)
void ActivateSettingsCache(bool activate=true)