MythTV  0.26-pre
weatherUtils.cpp
Go to the documentation of this file.
00001 // QT headers
00002 #include <QString>
00003 #include <QStringList>
00004 
00005 #include <mythdirs.h>
00006 #include "mythmainwindow.h"
00007 #include "mythuihelper.h"
00008 
00009 // MythWeather headers
00010 #include "weatherUtils.h"
00011 
00012 static QString getScreenTitle(const QString &screenName)
00013 {
00014     if (screenName == "Current Conditions")
00015         return QObject::tr("Current Conditions");
00016     if (screenName == "Three Day Forecast")
00017         return QObject::tr("Three Day Forecast");
00018     if (screenName == "18 Hour Forecast")
00019         return QObject::tr("18 Hour Forecast");
00020     if (screenName == "Severe Weather Alerts")
00021         return QObject::tr("Severe Weather Alerts");
00022     if (screenName == "Six Day Forecast")
00023         return QObject::tr("Six Day Forecast");
00024     if (screenName == "Static Map")
00025         return QObject::tr("Static Map");
00026     if (screenName == "Animated Map")
00027         return QObject::tr("Animated Map");
00028 
00029     return screenName;
00030 }
00031 
00032 ScreenListMap loadScreens()
00033 {
00034     ScreenListMap screens;
00035     QStringList searchpath = GetMythUI()->GetThemeSearchPath();
00036 
00037     // Check the theme first if it has its own weather-screens.xml
00038 
00039     QStringList::iterator it;
00040     for (it = searchpath.begin(); it != searchpath.end(); ++it)
00041     {
00042         QString filename = (*it) + "weather-screens.xml";
00043         if (doLoadScreens(filename, screens))
00044         {
00045             LOG(VB_GENERAL, LOG_INFO,
00046                 QString("Loading from: %1").arg(filename));
00047             break;
00048         }
00049     }
00050 
00051     //  Also load from the default file in case the theme file doesn't
00052     //  exist or the theme file doesn't define all the screens
00053 
00054     QString filename = GetShareDir() + "mythweather/weather-screens.xml";
00055 
00056     if (!doLoadScreens(filename, screens))
00057     {
00058         LOG(VB_GENERAL, LOG_ERR,
00059             QString("Unable to parse weather-screens.xml"));
00060     }
00061 
00062     return screens;
00063 }
00064 
00065 bool doLoadScreens(const QString &filename, ScreenListMap &screens)
00066 {
00067     QFile f(filename);
00068     QDomDocument doc;
00069 
00070     if (!f.open(QIODevice::ReadOnly))
00071     {
00072         return false;
00073     }
00074 
00075     if ( !doc.setContent( &f ) )
00076     {
00077         f.close();
00078         return false;
00079     }
00080     f.close();
00081 
00082     QDomElement docElem = doc.documentElement();
00083 
00084     for (QDomNode n = docElem.firstChild(); !n.isNull();
00085             n = n.nextSibling())
00086     {
00087         QDomElement e = n.toElement();
00088         if (!e.isNull())
00089         {
00090             if ( (e.tagName() == "screen") && !screens.contains(e.attribute("name")) )
00091             {
00092                 screens[e.attribute("name")].multiLoc = false;
00093                 screens[e.attribute("name")].name = e.attribute("name");
00094                 screens[e.attribute("name")].title =
00095                                             getScreenTitle(e.attribute("name"));
00096                 QString hasUnits = e.attribute("hasunits");
00097                 if (hasUnits.toLower() == "no")
00098                     screens[e.attribute("name")].hasUnits = false;
00099                 else
00100                     screens[e.attribute("name")].hasUnits = true;
00101                 screens[e.attribute("name")].dataTypes = loadScreen(e);
00102             }
00103         }
00104     }
00105     return true;
00106 }
00107 
00108 QStringList loadScreen(QDomElement ScreenListInfo)
00109 {
00110 
00111     QStringList typesList;
00112 
00113     for (QDomNode n = ScreenListInfo.firstChild(); !n.isNull();
00114             n = n.nextSibling())
00115     {
00116         QDomElement e = n.toElement();
00117         if (!e.isNull())
00118         {
00119             if (e.tagName() == "datum")
00120             {
00121                 QString name = e.attribute("name");
00122                 typesList << name;
00123             }
00124         }
00125     }
00126 
00127     return typesList;
00128 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends