diff -Naurp -x Makefile -x '*.log' -x '*.pro' -x '*.mak' mythplugins-orig/mythweather/mythweather/weatherScreen.cpp mythplugins-tmp/mythweather/mythweather/weatherScreen.cpp
old
|
new
|
using namespace std; |
12 | 12 | WeatherScreen *WeatherScreen::loadScreen(MythScreenStack *parent, |
13 | 13 | ScreenListInfo *screenDefn, int id) |
14 | 14 | { |
15 | | QString key = screenDefn->name; |
16 | | if (key == "Current Conditions") |
17 | | return new CurrCondScreen(parent, "Current Conditions", screenDefn, id); |
18 | | if (key == "Three Day Forecast") |
19 | | return new ThreeDayForecastScreen(parent,"Three Day Forecast" , screenDefn, id); |
20 | | if (key == "Six Day Forecast") |
21 | | return new SixDayForecastScreen(parent, "Six Day Forecast", screenDefn, id); |
| 15 | QString key = screenDefn->name; |
| 16 | QByteArray ba = key.toLatin1(); |
| 17 | const char *screen_name = ba.data(); |
| 18 | |
22 | 19 | if (key == "Severe Weather Alerts") |
23 | 20 | return new SevereWeatherScreen(parent, "Severe Weather Alerts", screenDefn, id); |
24 | 21 | if (key == "Static Map") |
… |
… |
WeatherScreen *WeatherScreen::loadScreen |
26 | 23 | if (key == "Animated Map") |
27 | 24 | return new AnimatedImageScreen(parent, "Animated Map", screenDefn, id); |
28 | 25 | |
29 | | return new WeatherScreen(parent, "Unknown Screen", screenDefn, id); |
| 26 | return new WeatherScreen(parent, screen_name, screenDefn, id); |
30 | 27 | } |
31 | 28 | |
32 | 29 | WeatherScreen::WeatherScreen(MythScreenStack *parent, const char *name, |
… |
… |
void WeatherScreen::prepareWidget(MythUI |
161 | 158 | } |
162 | 159 | } |
163 | 160 | |
164 | | QString WeatherScreen::prepareDataItem(const QString &key, const QString &value) |
165 | | { |
166 | | (void) key; |
167 | | return value; |
168 | | } |
169 | | |
170 | | bool WeatherScreen::keyPressEvent(QKeyEvent *event) |
171 | | { |
172 | | if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event)) |
173 | | return true; |
174 | | |
175 | | return false; |
176 | | } |
177 | | |
178 | | CurrCondScreen::CurrCondScreen(MythScreenStack *parent, const char *name, |
179 | | ScreenListInfo *screenDefn, int id) |
180 | | : WeatherScreen(parent, name, screenDefn, id) |
181 | | { |
182 | | } |
183 | | |
184 | | QString CurrCondScreen::prepareDataItem(const QString &key, |
185 | | const QString &value) |
| 161 | QString WeatherScreen::formatDataItem(const QString &key, const QString &value) |
186 | 162 | { |
187 | 163 | if (key == "relative_humidity") |
188 | 164 | return value + " %"; |
… |
… |
QString CurrCondScreen::prepareDataItem( |
193 | 169 | if (key == "visibility") |
194 | 170 | return value + (m_units == ENG_UNITS ? " mi" : " km"); |
195 | 171 | |
196 | | if (key == "appt") |
197 | | return value == "NA" ? value : value + getTemperatureUnit(); |
198 | | |
199 | | if (key == "temp") |
| 172 | if (key == "temp" || key == "appt" || key.contains("low",Qt::CaseInsensitive) || |
| 173 | key.contains("high",Qt::CaseInsensitive)) |
200 | 174 | { |
201 | 175 | if ( (value == "NA") || (value == "N/A") ) |
202 | 176 | return value; |
… |
… |
QString CurrCondScreen::prepareDataItem( |
207 | 181 | if (key == "wind_gust" || key == "wind_spdgst" || key == "wind_speed") |
208 | 182 | return value + (m_units == ENG_UNITS ? " mph" : " kph"); |
209 | 183 | |
210 | | return value; |
211 | | } |
212 | | |
213 | | ThreeDayForecastScreen::ThreeDayForecastScreen(MythScreenStack *parent, |
214 | | const char *name, |
215 | | ScreenListInfo *screenDefn, int id) |
216 | | : WeatherScreen(parent, name, screenDefn, id) |
217 | | { |
218 | | } |
219 | | |
220 | | QString ThreeDayForecastScreen::prepareDataItem(const QString &key, |
221 | | const QString &value) |
222 | | { |
223 | | if (key.contains("low", Qt::CaseInsensitive) || |
224 | | key.contains("high", Qt::CaseInsensitive) ) |
225 | | { |
226 | | if ( (value == "NA") || (value == "N/A") ) |
227 | | return value; |
228 | | else |
229 | | return value + getTemperatureUnit(); |
230 | | } |
231 | | |
232 | 184 | /*The days of the week will be translated if the script sends elements from |
233 | 185 | the enum DaysOfWeek.*/ |
234 | 186 | if (key.startsWith("date-")) |
… |
… |
QString ThreeDayForecastScreen::prepareD |
270 | 222 | return value; |
271 | 223 | } |
272 | 224 | |
273 | | SixDayForecastScreen::SixDayForecastScreen(MythScreenStack *parent, |
274 | | const char *name, |
275 | | ScreenListInfo *screenDefn, int id) |
276 | | : WeatherScreen(parent, name, screenDefn, id) |
| 225 | QString WeatherScreen::prepareDataItem(const QString &key, const QString &value) |
277 | 226 | { |
| 227 | // (void) key; |
| 228 | // return value; |
| 229 | return formatDataItem(key, value); |
278 | 230 | } |
279 | 231 | |
280 | | QString SixDayForecastScreen::prepareDataItem(const QString &key, |
281 | | const QString &value) |
| 232 | bool WeatherScreen::keyPressEvent(QKeyEvent *event) |
282 | 233 | { |
283 | | if (key.contains("low", Qt::CaseInsensitive) || |
284 | | key.contains("high", Qt::CaseInsensitive) ) |
285 | | { |
286 | | if ( (value == "NA") || (value == "N/A") ) |
287 | | return value; |
288 | | else |
289 | | return value + getTemperatureUnit(); |
290 | | } |
| 234 | if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event)) |
| 235 | return true; |
291 | 236 | |
292 | | return value; |
| 237 | return false; |
293 | 238 | } |
294 | 239 | |
295 | 240 | SevereWeatherScreen::SevereWeatherScreen(MythScreenStack *parent, const char *name, |
diff -Naurp -x Makefile -x '*.log' -x '*.pro' -x '*.mak' mythplugins-orig/mythweather/mythweather/weatherScreen.h mythplugins-tmp/mythweather/mythweather/weatherScreen.h
old
|
new
|
class WeatherScreen : public MythScreenT |
65 | 65 | virtual void prepareWidget(MythUIType *widget); |
66 | 66 | virtual void prepareScreen(); |
67 | 67 | virtual QString getTemperatureUnit(); |
| 68 | QString formatDataItem(const QString &key, const QString &value); |
68 | 69 | |
69 | 70 | private: |
70 | 71 | QMap<QString, QString> m_dataValueMap; |
… |
… |
class WeatherScreen : public MythScreenT |
74 | 75 | int m_id; |
75 | 76 | }; |
76 | 77 | |
77 | | class CurrCondScreen : public WeatherScreen |
78 | | { |
79 | | Q_OBJECT |
80 | | |
81 | | public: |
82 | | CurrCondScreen(MythScreenStack *parent, const char *name, |
83 | | ScreenListInfo *screenDefn, int id); |
84 | | |
85 | | protected: |
86 | | virtual QString prepareDataItem(const QString &key, const QString &value); |
87 | | }; |
88 | | |
89 | | class ThreeDayForecastScreen : public WeatherScreen |
90 | | { |
91 | | Q_OBJECT |
92 | | |
93 | | public: |
94 | | ThreeDayForecastScreen(MythScreenStack *parent, const char *name, |
95 | | ScreenListInfo *screenDefn, int id); |
96 | | |
97 | | protected: |
98 | | virtual QString prepareDataItem(const QString &key, const QString &value); |
99 | | |
100 | | }; |
101 | | |
102 | | class SixDayForecastScreen : public WeatherScreen |
103 | | { |
104 | | Q_OBJECT |
105 | | |
106 | | public: |
107 | | SixDayForecastScreen(MythScreenStack *parent, const char *name, |
108 | | ScreenListInfo *screenDefn, int id); |
109 | | |
110 | | protected: |
111 | | virtual QString prepareDataItem(const QString &key, const QString &value); |
112 | | |
113 | | }; |
114 | | |
115 | 78 | class SevereWeatherScreen : public WeatherScreen |
116 | 79 | { |
117 | 80 | Q_OBJECT |
diff -Naurp -x Makefile -x '*.log' -x '*.pro' -x '*.mak' mythplugins-orig/mythweather/mythweather/weatherUtils.cpp mythplugins-tmp/mythweather/mythweather/weatherUtils.cpp
old
|
new
|
|
3 | 3 | #include <QStringList> |
4 | 4 | |
5 | 5 | #include <mythdirs.h> |
| 6 | #include "mythmainwindow.h" |
| 7 | #include "mythuihelper.h" |
6 | 8 | |
7 | 9 | // MythWeather headers |
8 | 10 | #include "weatherUtils.h" |
9 | 11 | |
10 | 12 | ScreenListMap loadScreens() |
11 | 13 | { |
12 | | ScreenListMap screens; |
13 | | QDomDocument doc; |
| 14 | ScreenListMap screens; |
| 15 | QList<QString> searchpath = GetMythUI()->GetThemeSearchPath(); |
| 16 | |
| 17 | // Check the theme first if it has its own weather-screens.xml |
| 18 | |
| 19 | QList<QString>::iterator i; |
| 20 | for (i = searchpath.begin(); i != searchpath.end(); i++) |
| 21 | { |
| 22 | QString filename = *i + "weather-screens.xml"; |
| 23 | if (doLoadScreens(filename, screens)) |
| 24 | { |
| 25 | VERBOSE(VB_GENERAL, QString("Loading from: %1").arg(filename)); |
| 26 | break; |
| 27 | } |
| 28 | } |
14 | 29 | |
15 | | QFile f(GetShareDir() + "mythweather/weather-screens.xml"); |
| 30 | // Also load from the default file in case the theme file doesn't |
| 31 | // exist or the theme file doesn't define all the screens |
| 32 | |
| 33 | QString filename = GetShareDir() + "mythweather/weather-screens.xml"; |
| 34 | |
| 35 | if (!doLoadScreens(filename, screens)) |
| 36 | { |
| 37 | VERBOSE(VB_IMPORTANT, QString("Unable to parse weather-screens.xml")); |
| 38 | } |
16 | 39 | |
| 40 | return screens; |
| 41 | } |
| 42 | |
| 43 | bool doLoadScreens(const QString &filename, ScreenListMap &screens) |
| 44 | { |
| 45 | QFile f(filename); |
| 46 | QDomDocument doc; |
| 47 | |
17 | 48 | if (!f.open(QIODevice::ReadOnly)) |
18 | 49 | { |
19 | | VERBOSE(VB_FILE, QString("Unable to open weather-screens.xml")); |
20 | | return screens; |
| 50 | return false; |
21 | 51 | } |
22 | 52 | |
23 | | if ( !doc.setContent( &f ) ) { |
24 | | VERBOSE(VB_IMPORTANT, QString("Unable to parse weather-screens.xml")); |
| 53 | if ( !doc.setContent( &f ) ) |
| 54 | { |
25 | 55 | f.close(); |
26 | | return screens; |
| 56 | return false; |
27 | 57 | } |
28 | 58 | f.close(); |
29 | 59 | |
… |
… |
ScreenListMap loadScreens() |
35 | 65 | QDomElement e = n.toElement(); |
36 | 66 | if (!e.isNull()) |
37 | 67 | { |
38 | | if (e.tagName() == "screen") |
| 68 | if ( (e.tagName() == "screen") && !screens.contains(e.attribute("name")) ) |
39 | 69 | { |
40 | 70 | ScreenListInfo *screendef = new ScreenListInfo(); |
41 | 71 | screendef->name = e.attribute("name"); |
… |
… |
ScreenListMap loadScreens() |
49 | 79 | } |
50 | 80 | } |
51 | 81 | } |
52 | | |
53 | | return screens; |
| 82 | return true; |
54 | 83 | } |
55 | 84 | |
56 | 85 | QStringList loadScreen(QDomElement ScreenListInfo) |
diff -Naurp -x Makefile -x '*.log' -x '*.pro' -x '*.mak' mythplugins-orig/mythweather/mythweather/weatherUtils.h mythplugins-tmp/mythweather/mythweather/weatherUtils.h
old
|
new
|
typedef QMap<QString, ScreenListInfo *> |
70 | 70 | |
71 | 71 | ScreenListMap loadScreens(); |
72 | 72 | QStringList loadScreen(QDomElement ScreenListInfo); |
| 73 | bool doLoadScreens(const QString &filename, ScreenListMap &screens); |
73 | 74 | |
74 | 75 | #endif |