summaryrefslogtreecommitdiffstats
path: root/kweather/stationdatabase.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitae2a03c2941bf92573f89b88ef73f8aa842bea0a (patch)
tree3566563f3fb6ac3cb3496669d8f233062d3091bc /kweather/stationdatabase.cpp
downloadtdetoys-ae2a03c2941bf92573f89b88ef73f8aa842bea0a.tar.gz
tdetoys-ae2a03c2941bf92573f89b88ef73f8aa842bea0a.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdetoys@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kweather/stationdatabase.cpp')
-rw-r--r--kweather/stationdatabase.cpp170
1 files changed, 170 insertions, 0 deletions
diff --git a/kweather/stationdatabase.cpp b/kweather/stationdatabase.cpp
new file mode 100644
index 0000000..00f13c1
--- /dev/null
+++ b/kweather/stationdatabase.cpp
@@ -0,0 +1,170 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: ian reinhart geiser <geiseri@yahoo.com>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include "stationdatabase.h"
+
+#include <qstringlist.h>
+#include <qfile.h>
+#include <kdebug.h>
+
+class StationInfo
+{
+ public:
+ QString cityName;
+ QString country;
+ QString longitude;
+ QString latitude;
+ StationInfo () {}
+};
+
+StationDatabase::StationDatabase(const QString path) : mPath(path)
+{
+}
+
+
+StationDatabase::~StationDatabase()
+{
+}
+
+bool StationDatabase::loadStation( const QString & stationID )
+{
+ QFile file( mPath );
+ bool found = FALSE;
+
+ if ( !file.open( IO_ReadOnly ) )
+ return false;
+
+ QTextStream stream( &file );
+ stream.setEncoding( QTextStream::UnicodeUTF8 );
+ QString line;
+ while ( !stream.eof() )
+ {
+ line = stream.readLine(); // line of text excluding '\n'
+ QStringList data = QStringList::split( ";", line, true );
+
+ if ( data[ 0 ].stripWhiteSpace() == stationID )
+ {
+ StationInfo station;
+ station.cityName = data[ 3 ].stripWhiteSpace();
+ station.country = data[ 5 ].stripWhiteSpace();
+ station.latitude = data[ 7 ].stripWhiteSpace();
+ station.longitude = data[ 8 ].stripWhiteSpace();
+
+ theDB.insert( data[ 0 ], station );
+ found = TRUE;
+ break;
+ }
+ }
+
+ file.close();
+ return found;
+}
+
+/*!
+ \fn StationDatabase::stationNameFromID(const QString& id)
+ */
+QString StationDatabase::stationNameFromID( const QString & stationID )
+{
+ QString result;
+
+ if ( theDB.find( stationID ) == theDB.end() )
+ {
+ if ( loadStation( stationID ) )
+ result = theDB[ stationID ].cityName;
+ else
+ result = i18n( "Unknown Station" );
+ }
+ else
+ {
+ result = theDB[ stationID ].cityName;
+ }
+
+ return result;
+}
+
+/*!
+ \fn StationDatabase::stationLongitudeFromID( const QString &stationID)
+ */
+QString StationDatabase::stationLongitudeFromID( const QString & stationID )
+{
+ QString result;
+
+ if ( theDB.find( stationID ) == theDB.end() )
+ {
+ if ( loadStation( stationID ) )
+ result = theDB[ stationID ].longitude;
+ else
+ result = i18n( "Unknown Station" );
+ }
+ else
+ {
+ result = theDB[ stationID ].longitude;
+ }
+
+ return result;
+}
+
+/*!
+ \fn StationDatabase::stationLatitudeFromID(const QString &stationID)
+ */
+QString StationDatabase::stationLatitudeFromID( const QString & stationID )
+{
+ QString result;
+
+ if ( theDB.find( stationID ) == theDB.end() )
+ {
+ if ( loadStation( stationID ) )
+ result = theDB[ stationID ].latitude;
+ else
+ result = i18n( "Unknown Station" );
+ }
+ else
+ {
+ result = theDB[ stationID ].latitude;
+ }
+
+ return result;
+}
+
+/*!
+ \fn StationDatabase::stationCountryFromID( const QString &stationID)
+ */
+QString StationDatabase::stationCountryFromID( const QString &stationID )
+{
+ QString result;
+
+ if ( theDB.find( stationID ) == theDB.end() )
+ {
+ if ( loadStation( stationID ) )
+ result = theDB[ stationID ].country;
+ else
+ result = i18n( "Unknown Station" );
+ }
+ else
+ {
+ result = theDB[ stationID ].country;
+ }
+
+ return result;
+}
+
+QString StationDatabase::stationIDfromName( const QString &name )
+{
+ QMap<QString,StationInfo>::Iterator itr = theDB.begin();
+ for( ; itr != theDB.end(); ++itr)
+ {
+ kdDebug() << "Checking " << itr.data().cityName << endl;
+ if( itr.data().cityName == name )
+ return itr.key();
+ }
+ return "0000";
+}