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