[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/marble/marble-gsoc-2009/src/plugins/render/weather
From: Bastian Holst <bastianholst () gmx ! de>
Date: 2009-06-30 21:08:05
Message-ID: 1246396085.828329.20005.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 989761 by bholst:
Changes to marbles weather plugin:
* date and time parsing in BBCParser.
* removed Kelvin from choosable temperature units
M +72 -1 BBCParser.cpp
M +2 -0 BBCParser.h
M +0 -5 WeatherConfigWidget.ui
M +1 -1 WeatherData.cpp
M +0 -3 WeatherPlugin.cpp
--- branches/marble/marble-gsoc-2009/src/plugins/render/weather/BBCParser.cpp \
#989760:989761 @@ -17,6 +17,7 @@
// Qt
#include <QtCore/QByteArray>
+#include <QtCore/QDateTime>
#include <QtCore/QDebug>
#include <QtCore/QRegExp>
@@ -32,6 +33,8 @@
= QHash<QString, WeatherData::PressureDevelopment>();
QHash<QString, WeatherData::Visibility> BBCParser::visibilityStates
= QHash<QString, WeatherData::Visibility>();
+QHash<QString, int> BBCParser::monthNames
+ = QHash<QString, int>();
BBCParser::BBCParser()
{
@@ -125,6 +128,8 @@
readDescription( &item );
else if( name() == "title" )
readTitle( &item );
+ else if( name() == "pubDate" )
+ readPubDate( &item );
else
readUnknownElement();
}
@@ -263,12 +268,65 @@
}
}
+void BBCParser::readPubDate( WeatherData *data ) {
+ Q_ASSERT( isStartElement()
+ && name() == "pubDate" );
+
+ while( !atEnd() ) {
+ readNext();
+
+ if( isEndElement() )
+ break;
+
+ if( isStartElement() ) {
+ readUnknownElement();
+ }
+
+ if( isCharacters() ) {
+ QString pubDate = text().toString();
+ QRegExp regExp;
+
+ regExp.setPattern( \
"([A-Za-z]+,\\s+)(\\d+)(\\s+)([A-Za-z]+)(\\s+)(\\d{4,4})(\\s+)(\\d+)(:)(\\d+)(:)(\\d+)(\\s+)([+-])(\\d{2,2})(\\d{2,2})" \
); + int pos = regExp.indexIn( pubDate );
+ if ( pos > -1 ) {
+ QDateTime dateTime;
+ QDate date;
+ QTime time;
+
+ dateTime.setTimeSpec( Qt::UTC );
+ date.setYMD( regExp.cap( 6 ).toInt(),
+ monthNames.value( regExp.cap( 4 ) ),
+ regExp.cap( 2 ).toInt() );
+ time.setHMS( regExp.cap( 8 ).toInt(),
+ regExp.cap( 10 ).toInt(),
+ regExp.cap( 12 ).toInt() );
+
+ dateTime.setDate( date );
+ dateTime.setTime( time );
+
+ // Timezone
+ if( regExp.cap( 14 ) == "-" ) {
+ dateTime = dateTime.addSecs( 60*60*regExp.cap( 15 ).toInt() );
+ dateTime = dateTime.addSecs( 60 *regExp.cap( 16 ).toInt() );
+ }
+ else {
+ dateTime = dateTime.addSecs( -60*60*regExp.cap( 15 ).toInt() );
+ dateTime = dateTime.addSecs( -60 *regExp.cap( 16 ).toInt() );
+ }
+
+ data->setDateTime( dateTime );
+ }
+ }
+ }
+}
+
void BBCParser::setupHashes() {
if( !( ( dayConditions.isEmpty() )
|| ( nightConditions.isEmpty() )
|| ( windDirections.isEmpty() )
|| ( pressureDevelopments.isEmpty() )
- || ( visibilityStates.isEmpty() ) ) )
+ || ( visibilityStates.isEmpty() )
+ || ( monthNames.isEmpty() ) ) )
{
return;
}
@@ -392,4 +450,17 @@
visibilityStates["Very Poor"] = WeatherData::VeryPoor;
visibilityStates["Fog"] = WeatherData::VeryPoor;
visibilityStates["N/A"] = WeatherData::VisibilityNotAvailable;
+
+ monthNames["Jan"] = 1;
+ monthNames["Feb"] = 2;
+ monthNames["Mar"] = 3;
+ monthNames["Apr"] = 4;
+ monthNames["May"] = 5;
+ monthNames["Jun"] = 6;
+ monthNames["Jul"] = 7;
+ monthNames["Aug"] = 8;
+ monthNames["Sep"] = 9;
+ monthNames["Oct"] = 10;
+ monthNames["Nov"] = 11;
+ monthNames["Dec"] = 12;
}
--- branches/marble/marble-gsoc-2009/src/plugins/render/weather/BBCParser.h \
#989760:989761 @@ -38,6 +38,7 @@
void readItem();
void readDescription( WeatherData *data );
void readTitle( WeatherData *data );
+ void readPubDate( WeatherData *data );
void setupHashes();
@@ -48,6 +49,7 @@
static QHash<QString, WeatherData::WindDirection> windDirections;
static QHash<QString, WeatherData::PressureDevelopment> pressureDevelopments;
static QHash<QString, WeatherData::Visibility> visibilityStates;
+ static QHash<QString, int> monthNames;
};
} // Marble namespace
--- branches/marble/marble-gsoc-2009/src/plugins/render/weather/WeatherConfigWidget.ui \
#989760:989761 @@ -41,11 +41,6 @@
<string>Fahrenheit</string>
</property>
</item>
- <item>
- <property name="text">
- <string>Kelvin</string>
- </property>
- </item>
</widget>
</item>
</layout>
--- branches/marble/marble-gsoc-2009/src/plugins/render/weather/WeatherData.cpp \
#989760:989761 @@ -292,7 +292,7 @@
void WeatherData::setDateTime( const QDateTime& dateTime ) {
detach();
- d->m_dateTime = dateTime;
+ d->m_dateTime = dateTime.toUTC();
}
bool WeatherData::hasValidDateTime() const {
--- branches/marble/marble-gsoc-2009/src/plugins/render/weather/WeatherPlugin.cpp \
#989760:989761 @@ -118,15 +118,12 @@
int temperatureUnit;
if ( m_settings.contains( "temperatureUnit" ) ) {
temperatureUnit = m_settings.value( "temperatureUnit" ).toInt();
- qDebug() << "Found unit" << temperatureUnit;
}
else {
temperatureUnit = WeatherData::Kelvin;
m_settings.insert( "temperatureUnit", temperatureUnit );
- qDebug() << "Didn't find unit" << temperatureUnit;
}
ui_configWidget.m_temperatureComboBox->setCurrentIndex( temperatureUnit );
- qDebug() << "Set unit " << temperatureUnit;
int windSpeedUnit;
if ( m_settings.contains( "windSpeedUnit" ) ) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic