MythTV  master
mythweather.cpp
Go to the documentation of this file.
1 
2 #include <unistd.h>
3 
4 // MythTV headers
5 #include <libmyth/mythcontext.h>
9 #include <libmythbase/mythversion.h>
12 #include <libmythui/mythuihelper.h>
13 
14 // MythWeather headers
15 #include "sourceManager.h"
16 #include "weather.h"
17 #include "weatherSetup.h"
18 #include "weatherdbcheck.h"
19 
20 SourceManager *srcMan = nullptr;
21 
22 static int RunWeather()
23 {
25 
26  auto *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 (!MythCoreContext::TestPluginVersion("mythweather", libversion,
62  MYTH_BINARY_VERSION))
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([[maybe_unused]] void *data, QString &selection)
87 {
89 
90  if (selection == "SETTINGS_GENERAL")
91  {
92  auto *gsetup = new GlobalSetup(mainStack, "weatherglobalsetup");
93 
94  if (gsetup->Create())
95  mainStack->AddScreen(gsetup);
96  else
97  delete gsetup;
98  }
99  else if (selection == "SETTINGS_SCREEN")
100  {
101  auto *ssetup = new ScreenSetup(mainStack, "weatherscreensetup", srcMan);
102 
103  if (ssetup->Create())
104  mainStack->AddScreen(ssetup);
105  else
106  delete ssetup;
107  }
108  else if (selection == "SETTINGS_SOURCE")
109  {
110  auto *srcsetup = new SourceSetup(mainStack, "weathersourcesetup");
111 
112  if (srcsetup->Create())
113  mainStack->AddScreen(srcsetup);
114  else
115  delete srcsetup;
116  }
117 }
118 
120 {
121  QString menuname = "weather_settings.xml";
122  QString themedir = GetMythUI()->GetThemeDir();
123 
124  auto *menu = new MythThemedMenu(themedir, menuname,
125  GetMythMainWindow()->GetMainStack(),
126  "weather menu");
127 
128  menu->setCallback(WeatherCallback, nullptr);
129  menu->setKillable();
130  if (menu->foundTheme())
131  {
132  if (LCD *lcd = LCD::Get()) {
133  lcd->setFunctionLEDs(FUNC_NEWS, false);
134  lcd->switchToTime();
135  }
136 
138  return 0;
139  }
140  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
141  .arg(menuname, themedir));
142  delete menu;
143  return -1;
144 }
145 
147 {
148  if (srcMan)
149  {
150  delete srcMan;
151  srcMan = nullptr;
152  }
153 }
154 
155 /*
156  * vim:ts=4:sw=4:ai:et:si:sts=4
157  */
themedir
static QString themedir
Definition: mythdirs.cpp:23
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:318
RunWeather
static int RunWeather()
Definition: mythweather.cpp:22
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:59
setupKeys
static void setupKeys()
Definition: mythweather.cpp:45
InitializeDatabase
static bool InitializeDatabase(void)
Definition: gamedbcheck.cpp:20
mythplugin.h
runWeather
static void runWeather()
Definition: mythweather.cpp:40
MythScreenStack
Definition: mythscreenstack.h:16
FUNC_NEWS
@ FUNC_NEWS
Definition: lcddevice.h:170
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:142
MythCoreContext::TestPluginVersion
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
Definition: mythcorecontext.cpp:2048
weather.h
SourceManager::startTimers
void startTimers()
Definition: sourceManager.cpp:260
LCD::Get
static LCD * Get(void)
Definition: lcddevice.cpp:69
mythplugin_destroy
void mythplugin_destroy()
Definition: mythweather.cpp:146
ScreenSetup
Definition: weatherSetup.h:64
weatherSetup.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:40
SourceManager::doUpdate
void doUpdate(bool forceUpdate=false)
Definition: sourceManager.cpp:272
mythplugin_config
int mythplugin_config()
Definition: mythweather.cpp:119
Weather
Definition: weather.h:20
WeatherCallback
static void WeatherCallback([[maybe_unused]] void *data, QString &selection)
Definition: mythweather.cpp:86
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
SourceSetup
Definition: weatherSetup.h:98
mythpluginapi.h
MythThemedMenu::setKillable
void setKillable(void)
Definition: myththemedmenu.cpp:163
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:905
mythuihelper.h
REG_JUMP
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
Definition: mythmainwindow.h:188
mythcontext.h
MythThemedMenu::setCallback
void setCallback(void(*lcallback)(void *, QString &), void *data)
Set the themed menus callback function and data for that function.
Definition: myththemedmenu.cpp:156
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythCoreContext::ActivateSettingsCache
void ActivateSettingsCache(bool activate=true)
Definition: mythcorecontext.cpp:832
mythplugin_run
int mythplugin_run()
Definition: mythweather.cpp:81
MythThemedMenu
Themed menu class, used for main menus in MythTV frontend.
Definition: myththemedmenu.h:57
myththemedmenu.h
srcMan
SourceManager * srcMan
Definition: mythweather.cpp:20
lcddevice.h
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:66
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
LCD
Definition: lcddevice.h:173
SourceManager
Definition: sourceManager.h:18