MythTV  master
weatherUtils.cpp
Go to the documentation of this file.
1 // QT headers
2 #include <QCoreApplication>
3 #include <QString>
4 #include <QStringList>
5 
6 // MythTV
7 #include <libmythbase/mythdirs.h>
10 #include <libmythui/mythuihelper.h>
11 
12 // MythWeather headers
13 #include "weatherUtils.h"
14 
15 static QString getScreenTitle(const QString &screenName)
16 {
17  if (screenName == "Current Conditions")
18  return QCoreApplication::translate("(Weather Screens)",
19  "Current Conditions");
20  if (screenName == "Three Day Forecast")
21  return QCoreApplication::translate("(Weather Screens)",
22  "Three Day Forecast");
23  if (screenName == "18 Hour Forecast")
24  return QCoreApplication::translate("(Weather Screens)",
25  "18 Hour Forecast");
26  if (screenName == "Severe Weather Alerts")
27  return QCoreApplication::translate("(Weather Screens)",
28  "Severe Weather Alerts");
29  if (screenName == "Six Day Forecast")
30  return QCoreApplication::translate("(Weather Screens)",
31  "Six Day Forecast");
32  if (screenName == "Static Map")
33  return QCoreApplication::translate("(Weather Screens)",
34  "Static Map");
35  if (screenName == "Animated Map")
36  return QCoreApplication::translate("(Weather Screens)",
37  "Animated Map");
38 
39  return screenName;
40 }
41 
43 {
44  ScreenListMap screens;
45  QStringList searchpath = GetMythUI()->GetThemeSearchPath();
46 
47  // Check the theme first if it has its own weather-screens.xml
48 
49  QStringList::iterator it;
50  for (it = searchpath.begin(); it != searchpath.end(); ++it)
51  {
52  QString filename = (*it) + "weather-screens.xml";
53  if (doLoadScreens(filename, screens))
54  {
55  LOG(VB_GENERAL, LOG_INFO,
56  QString("Loading from: %1").arg(filename));
57  break;
58  }
59  }
60 
61  // Also load from the default file in case the theme file doesn't
62  // exist or the theme file doesn't define all the screens
63 
64  QString filename = GetShareDir() + "mythweather/weather-screens.xml";
65 
66  if (!doLoadScreens(filename, screens))
67  {
68  LOG(VB_GENERAL, LOG_ERR,
69  QString("Unable to parse weather-screens.xml"));
70  }
71 
72  return screens;
73 }
74 
75 bool doLoadScreens(const QString &filename, ScreenListMap &screens)
76 {
77  QFile f(filename);
78  QDomDocument doc;
79 
80  if (!f.open(QIODevice::ReadOnly))
81  {
82  return false;
83  }
84 
85  if ( !doc.setContent( &f ) )
86  {
87  f.close();
88  return false;
89  }
90  f.close();
91 
92  QDomElement docElem = doc.documentElement();
93 
94  for (QDomNode n = docElem.firstChild(); !n.isNull();
95  n = n.nextSibling())
96  {
97  QDomElement e = n.toElement();
98  if (!e.isNull())
99  {
100  if ( (e.tagName() == "screen") && !screens.contains(e.attribute("name")) )
101  {
102  screens[e.attribute("name")].m_multiLoc = false;
103  screens[e.attribute("name")].m_name = e.attribute("name");
104  screens[e.attribute("name")].m_title =
105  getScreenTitle(e.attribute("name"));
106  QString hasUnits = e.attribute("hasunits");
107  screens[e.attribute("name")].m_hasUnits =
108  hasUnits.toLower() != "no";
109  screens[e.attribute("name")].m_dataTypes = loadScreen(e);
110  }
111  }
112  }
113  return true;
114 }
115 
116 QStringList loadScreen(const QDomElement& ScreenListInfo)
117 {
118 
119  QStringList typesList;
120 
121  for (QDomNode n = ScreenListInfo.firstChild(); !n.isNull();
122  n = n.nextSibling())
123  {
124  QDomElement e = n.toElement();
125  if (!e.isNull())
126  {
127  if (e.tagName() == "datum")
128  {
129  QString name = e.attribute("name");
130  typesList << name;
131  }
132  }
133  }
134 
135  return typesList;
136 }
doLoadScreens
bool doLoadScreens(const QString &filename, ScreenListMap &screens)
Definition: weatherUtils.cpp:75
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
mythdirs.h
loadScreen
QStringList loadScreen(const QDomElement &ScreenListInfo)
Definition: weatherUtils.cpp:116
loadScreens
ScreenListMap loadScreens()
Definition: weatherUtils.cpp:42
mythlogging.h
GetShareDir
QString GetShareDir(void)
Definition: mythdirs.cpp:261
ScreenListInfo
Definition: weatherUtils.h:48
MythUIThemeHelper::GetThemeSearchPath
QStringList GetThemeSearchPath()
Definition: mythuithemehelper.cpp:151
ScreenListMap
QMap< QString, ScreenListInfo > ScreenListMap
Definition: weatherUtils.h:68
mythuihelper.h
getScreenTitle
static QString getScreenTitle(const QString &screenName)
Definition: weatherUtils.cpp:15
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:64
build_compdb.filename
filename
Definition: build_compdb.py:21
mythmainwindow.h
weatherUtils.h