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>
13 #include <libmythui/mythuihelper.h>
14 
15 // MythWeather headers
16 #include "sourceManager.h"
17 #include "weather.h"
18 #include "weatherSetup.h"
19 #include "weatherdbcheck.h"
20 
21 SourceManager *srcMan = nullptr;
22 
23 static 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 
41 static void runWeather()
42 {
43  RunWeather();
44 }
45 
46 static 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 
60 int 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();
76  srcMan->doUpdate();
77  }
78 
79  return 0;
80 }
81 
83 {
84  return RunWeather();
85 }
86 
87 static 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 
129  menu->setCallback(WeatherCallback, nullptr);
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  */
themedir
static QString themedir
Definition: mythdirs.cpp:23
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:317
RunWeather
static int RunWeather()
Definition: mythweather.cpp:23
FUNC_NEWS
@ FUNC_NEWS
Definition: lcddevice.h:166
sourceManager.h
REG_KEY
static void REG_KEY(const QString &Context, const QString &Action, const QString &Description, const QString &Key)
Definition: mythmainwindow.h:175
weatherdbcheck.h
mythplugin_init
int mythplugin_init(const char *libversion)
Definition: mythweather.cpp:60
setupKeys
static void setupKeys()
Definition: mythweather.cpp:46
InitializeDatabase
static bool InitializeDatabase(void)
Definition: gamedbcheck.cpp:21
mythplugin.h
runWeather
static void runWeather()
Definition: mythweather.cpp:41
MythScreenStack
Definition: mythscreenstack.h:16
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythThemedMenu::foundTheme
bool foundTheme(void) const
Returns true iff a theme has been found by a previous call to SetMenuTheme().
Definition: myththemedmenu.cpp:145
MythCoreContext::TestPluginVersion
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
Definition: mythcorecontext.cpp:2089
weather.h
SourceManager::startTimers
void startTimers()
Definition: sourceManager.cpp:261
LCD::Get
static LCD * Get(void)
Definition: lcddevice.cpp:69
mythplugin_destroy
void mythplugin_destroy()
Definition: mythweather.cpp:147
ScreenSetup
Definition: weatherSetup.h:63
weatherSetup.h
mythlogging.h
menu
static MythThemedMenu * menu
Definition: mythtv-setup.cpp:58
MythUIThemeHelper::GetThemeDir
QString GetThemeDir()
Definition: mythuithemehelper.cpp:141
GlobalSetup
Screen for mythweather global settings.
Definition: weatherSetup.h:39
SourceManager::doUpdate
void doUpdate(bool forceUpdate=false)
Definition: sourceManager.cpp:273
mythplugin_config
int mythplugin_config()
Definition: mythweather.cpp:120
Weather
Definition: weather.h:20
WeatherCallback
static void WeatherCallback([[maybe_unused]] void *data, QString &selection)
Definition: mythweather.cpp:87
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
SourceSetup
Definition: weatherSetup.h:97
mythpluginapi.h
MythThemedMenu::setKillable
void setKillable(void)
Definition: myththemedmenu.cpp:166
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:912
mythuihelper.h
mythcorecontext.h
REG_JUMP
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
Definition: mythmainwindow.h:188
MythThemedMenu::setCallback
void setCallback(void(*lcallback)(void *, QString &), void *data)
Set the themed menus callback function and data for that function.
Definition: myththemedmenu.cpp:159
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythCoreContext::ActivateSettingsCache
void ActivateSettingsCache(bool activate=true)
Definition: mythcorecontext.cpp:839
mythplugin_run
int mythplugin_run()
Definition: mythweather.cpp:82
MythThemedMenu
Themed menu class, used for main menus in MythTV frontend.
Definition: myththemedmenu.h:57
myththemedmenu.h
srcMan
SourceManager * srcMan
Definition: mythweather.cpp:21
lcddevice.h
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:64
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
LCD
Definition: lcddevice.h:169
SourceManager
Definition: sourceManager.h:18