Ticket #5903: mythweather.2.diff

File mythweather.2.diff, 10.1 KB (added by wstewart@…, 15 years ago)

Updated, see comment for changes

  • mythweather/mythweather/weatherScreen.cpp

    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; 
    1212WeatherScreen *WeatherScreen::loadScreen(MythScreenStack *parent,
    1313                                         ScreenListInfo *screenDefn, int id)
    1414{
    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   
    2219    if (key == "Severe Weather Alerts")
    2320        return new SevereWeatherScreen(parent, "Severe Weather Alerts", screenDefn, id);
    2421    if (key == "Static Map")
    WeatherScreen *WeatherScreen::loadScreen 
    2623    if (key == "Animated Map")
    2724        return new AnimatedImageScreen(parent, "Animated Map", screenDefn, id);
    2825
    29     return new WeatherScreen(parent, "Unknown Screen", screenDefn, id);
     26    return new WeatherScreen(parent, screen_name, screenDefn, id);
    3027}
    3128
    3229WeatherScreen::WeatherScreen(MythScreenStack *parent, const char *name,
    void WeatherScreen::prepareWidget(MythUI 
    161158    }
    162159}
    163160
    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)
     161QString WeatherScreen::formatDataItem(const QString &key, const QString &value)
    186162{
    187163    if (key == "relative_humidity")
    188164        return value + " %";
    QString CurrCondScreen::prepareDataItem( 
    193169    if (key == "visibility")
    194170        return value + (m_units == ENG_UNITS ? " mi" : " km");
    195171
    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))
    200174    {
    201175       if ( (value == "NA") || (value == "N/A") )
    202176          return value;
    QString CurrCondScreen::prepareDataItem( 
    207181    if (key == "wind_gust" || key == "wind_spdgst" || key == "wind_speed")
    208182        return value + (m_units == ENG_UNITS ? " mph" : " kph");
    209183
    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 
    232184    /*The days of the week will be translated if the script sends elements from
    233185     the enum DaysOfWeek.*/
    234186    if (key.startsWith("date-"))
    QString ThreeDayForecastScreen::prepareD 
    270222    return value;
    271223}
    272224
    273 SixDayForecastScreen::SixDayForecastScreen(MythScreenStack *parent,
    274                                             const char *name,
    275                                             ScreenListInfo *screenDefn, int id)
    276     : WeatherScreen(parent, name, screenDefn, id)
     225QString WeatherScreen::prepareDataItem(const QString &key, const QString &value)
    277226{
     227//    (void) key;
     228//    return value;
     229    return formatDataItem(key, value);
    278230}
    279231
    280 QString SixDayForecastScreen::prepareDataItem(const QString &key,
    281                                         const QString &value)
     232bool WeatherScreen::keyPressEvent(QKeyEvent *event)
    282233{
    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;
    291236
    292     return value;
     237    return false;
    293238}
    294239
    295240SevereWeatherScreen::SevereWeatherScreen(MythScreenStack *parent, const char *name,
  • mythweather/mythweather/weatherScreen.h

    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 
    6565    virtual void prepareWidget(MythUIType *widget);
    6666    virtual void prepareScreen();
    6767    virtual QString getTemperatureUnit();
     68    QString formatDataItem(const QString &key, const QString &value);
    6869
    6970  private:
    7071    QMap<QString, QString> m_dataValueMap;
    class WeatherScreen : public MythScreenT 
    7475    int m_id;
    7576};
    7677
    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 
    11578class SevereWeatherScreen : public WeatherScreen
    11679{
    11780    Q_OBJECT
  • mythweather/mythweather/weatherUtils.cpp

    diff -Naurp -x Makefile -x '*.log' -x '*.pro' -x '*.mak' mythplugins-orig/mythweather/mythweather/weatherUtils.cpp mythplugins-tmp/mythweather/mythweather/weatherUtils.cpp
    old new  
    33#include <QStringList>
    44
    55#include <mythdirs.h>
     6#include "mythmainwindow.h"
     7#include "mythuihelper.h"
    68
    79// MythWeather headers
    810#include "weatherUtils.h"
    911
    1012ScreenListMap loadScreens()
    1113{
    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    }
    1429
    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    }
    1639
     40    return screens;
     41}
     42
     43bool doLoadScreens(const QString &filename, ScreenListMap &screens)
     44{
     45    QFile f(filename);
     46    QDomDocument doc;
     47       
    1748    if (!f.open(QIODevice::ReadOnly))
    1849    {
    19         VERBOSE(VB_FILE, QString("Unable to open weather-screens.xml"));
    20         return screens;
     50        return false;
    2151    }
    2252
    23     if ( !doc.setContent( &f ) ) {
    24         VERBOSE(VB_IMPORTANT, QString("Unable to parse weather-screens.xml"));
     53    if ( !doc.setContent( &f ) )
     54    {
    2555        f.close();
    26         return screens;
     56        return false;
    2757    }
    2858    f.close();
    2959
    ScreenListMap loadScreens() 
    3565        QDomElement e = n.toElement();
    3666        if (!e.isNull())
    3767        {
    38             if (e.tagName() == "screen")
     68            if ( (e.tagName() == "screen") && !screens.contains(e.attribute("name")) )
    3969            {
    4070                ScreenListInfo *screendef = new ScreenListInfo();
    4171                screendef->name = e.attribute("name");
    ScreenListMap loadScreens() 
    4979            }
    5080        }
    5181    }
    52 
    53     return screens;
     82    return true;
    5483}
    5584
    5685QStringList loadScreen(QDomElement ScreenListInfo)
  • mythweather/mythweather/weatherUtils.h

    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 *>  
    7070
    7171ScreenListMap loadScreens();
    7272QStringList loadScreen(QDomElement ScreenListInfo);
     73bool doLoadScreens(const QString &filename, ScreenListMap &screens);
    7374
    7475#endif