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