/
main.cpp
162 lines (133 loc) · 3.64 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <unistd.h>
// MythTV headers
#include <lcddevice.h>
#include <mythcontext.h>
#include <mythplugin.h>
#include <mythpluginapi.h>
#include <mythversion.h>
#include <myththemedmenu.h>
#include <mythmainwindow.h>
#include <mythuihelper.h>
// MythWeather headers
#include "weather.h"
#include "weatherSetup.h"
#include "sourceManager.h"
#include "dbcheck.h"
SourceManager *srcMan = 0;
static int RunWeather()
{
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
Weather *weather = new Weather(mainStack, "mythweather", srcMan);
if (weather->Create())
{
if( weather->SetupScreens() )
mainStack->AddScreen(weather);
return 0;
}
delete weather;
return -1;
}
static void runWeather()
{
RunWeather();
}
static void setupKeys()
{
REG_JUMP("MythWeather", QT_TRANSLATE_NOOP("MythControls",
"Weather forecasts"), "", runWeather);
REG_KEY("Weather", "PAUSE", QT_TRANSLATE_NOOP("MythControls",
"Pause current page"), "P");
REG_KEY("Weather", "SEARCH", QT_TRANSLATE_NOOP("MythControls",
"Search List"), "/");
REG_KEY("Weather", "NEXTSEARCH", QT_TRANSLATE_NOOP("MythControls",
"Search List"), "n");
REG_KEY("Weather", "UPDATE", QT_TRANSLATE_NOOP("MythControls",
"Search List"), "u");
}
int mythplugin_init(const char *libversion)
{
if (!gCoreContext->TestPluginVersion("mythweather", libversion,
MYTH_BINARY_VERSION))
return -1;
gCoreContext->ActivateSettingsCache(false);
InitializeDatabase();
gCoreContext->ActivateSettingsCache(true);
setupKeys();
if (gCoreContext->GetNumSetting("weatherbackgroundfetch", 0))
{
srcMan = new SourceManager();
srcMan->startTimers();
srcMan->doUpdate();
}
return 0;
}
int mythplugin_run()
{
return RunWeather();
}
static void WeatherCallback(void *data, QString &selection)
{
(void) data;
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
if (selection == "SETTINGS_GENERAL")
{
GlobalSetup *gsetup = new GlobalSetup(mainStack, "weatherglobalsetup");
if (gsetup->Create())
mainStack->AddScreen(gsetup);
else
delete gsetup;
}
else if (selection == "SETTINGS_SCREEN")
{
ScreenSetup *ssetup = new ScreenSetup(mainStack, "weatherscreensetup", srcMan);
if (ssetup->Create())
mainStack->AddScreen(ssetup);
else
delete ssetup;
}
else if (selection == "SETTINGS_SOURCE")
{
SourceSetup *srcsetup = new SourceSetup(mainStack, "weathersourcesetup");
if (srcsetup->Create())
mainStack->AddScreen(srcsetup);
else
delete srcsetup;
}
}
int mythplugin_config()
{
QString menuname = "weather_settings.xml";
QString themedir = GetMythUI()->GetThemeDir();
MythThemedMenu *menu = new MythThemedMenu(
themedir, menuname,
GetMythMainWindow()->GetMainStack(), "weather menu");
menu->setCallback(WeatherCallback, 0);
menu->setKillable();
if (menu->foundTheme())
{
if (LCD *lcd = LCD::Get()) {
lcd->setFunctionLEDs(FUNC_NEWS, false);
lcd->switchToTime();
}
GetMythMainWindow()->GetMainStack()->AddScreen(menu);
return 0;
}
else
{
LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
.arg(menuname).arg(themedir));
delete menu;
return -1;
}
}
void mythplugin_destroy()
{
if (srcMan)
{
delete srcMan;
srcMan = 0;
}
}
/*
* vim:ts=4:sw=4:ai:et:si:sts=4
*/