summaryrefslogtreecommitdiff
path: root/noncore/todayplugins/weather
authordrw <drw>2002-11-11 01:18:50 (UTC)
committer drw <drw>2002-11-11 01:18:50 (UTC)
commitcbafca79e0a7993f55c085ead8aaa30604cc646b (patch) (side-by-side diff)
treebf6ace5e20f33cfb3a43cafa64a8702ed045dcc6 /noncore/todayplugins/weather
parentf1e191f9cbfb4031fa4b5125306428b083b2cc04 (diff)
downloadopie-cbafca79e0a7993f55c085ead8aaa30604cc646b.zip
opie-cbafca79e0a7993f55c085ead8aaa30604cc646b.tar.gz
opie-cbafca79e0a7993f55c085ead8aaa30604cc646b.tar.bz2
New Today weather plugin
Diffstat (limited to 'noncore/todayplugins/weather') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/weather/.cvsignore3
-rw-r--r--noncore/todayplugins/weather/config.in5
-rw-r--r--noncore/todayplugins/weather/opie-today-weatherplugin.control8
-rw-r--r--noncore/todayplugins/weather/weather.pro23
-rw-r--r--noncore/todayplugins/weather/weatherconfig.cpp127
-rw-r--r--noncore/todayplugins/weather/weatherconfig.h59
-rw-r--r--noncore/todayplugins/weather/weatherplugin.cpp78
-rw-r--r--noncore/todayplugins/weather/weatherplugin.h54
-rw-r--r--noncore/todayplugins/weather/weatherpluginimpl.cpp61
-rw-r--r--noncore/todayplugins/weather/weatherpluginimpl.h52
-rw-r--r--noncore/todayplugins/weather/weatherpluginwidget.cpp321
-rw-r--r--noncore/todayplugins/weather/weatherpluginwidget.h69
12 files changed, 860 insertions, 0 deletions
diff --git a/noncore/todayplugins/weather/.cvsignore b/noncore/todayplugins/weather/.cvsignore
new file mode 100644
index 0000000..c9bb88e
--- a/dev/null
+++ b/noncore/todayplugins/weather/.cvsignore
@@ -0,0 +1,3 @@
+Makefile*
+moc_*
+*.moc \ No newline at end of file
diff --git a/noncore/todayplugins/weather/config.in b/noncore/todayplugins/weather/config.in
new file mode 100644
index 0000000..8677bc4
--- a/dev/null
+++ b/noncore/todayplugins/weather/config.in
@@ -0,0 +1,5 @@
+ config TODAY_WEATHER
+ boolean "weather"
+ default "y"
+ depends TODAY
+
diff --git a/noncore/todayplugins/weather/opie-today-weatherplugin.control b/noncore/todayplugins/weather/opie-today-weatherplugin.control
new file mode 100644
index 0000000..34a57c5
--- a/dev/null
+++ b/noncore/todayplugins/weather/opie-today-weatherplugin.control
@@ -0,0 +1,8 @@
+Files: plugins/today/libtodayweatherplugin.so* pics/todayweatherplugin
+Priority: optional
+Section: opie/applications
+Maintainer: Dan Williams <williamsdr@acm.org>
+Architecture: arm
+Version: $QPE_VERSION-$SUB_VERSION
+Depends: qt-embedded (>=$QTE_VERSION), opie-today
+Description: Current weather plugin for today.
diff --git a/noncore/todayplugins/weather/weather.pro b/noncore/todayplugins/weather/weather.pro
new file mode 100644
index 0000000..2c7d865
--- a/dev/null
+++ b/noncore/todayplugins/weather/weather.pro
@@ -0,0 +1,23 @@
+TEMPLATE = lib
+#CONFIG -= moc
+CONFIG += qt debug
+
+HEADERS = weatherplugin.h \
+ weatherpluginimpl.h \
+ weatherpluginwidget.h \
+ weatherconfig.h
+
+SOURCES = weatherplugin.cpp \
+ weatherpluginimpl.cpp \
+ weatherpluginwidget.cpp \
+ weatherconfig.cpp
+
+INCLUDEPATH += $(OPIEDIR)/include \
+ ../ ../library
+DEPENDPATH += $(OPIEDIR)/include \
+ ../ ../library
+
+LIBS+= -lqpe -lopie
+
+DESTDIR = $(OPIEDIR)/plugins/today
+TARGET = todayweatherplugin
diff --git a/noncore/todayplugins/weather/weatherconfig.cpp b/noncore/todayplugins/weather/weatherconfig.cpp
new file mode 100644
index 0000000..fe10883
--- a/dev/null
+++ b/noncore/todayplugins/weather/weatherconfig.cpp
@@ -0,0 +1,127 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include <stdlib.h>
+
+#include <qcheckbox.h>
+#include <qclipboard.h>
+#include <qfontmetrics.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qspinbox.h>
+#include <qwhatsthis.h>
+
+#include <qpe/config.h>
+#include <qpe/qpeapplication.h>
+#include <qpe/resource.h>
+#include <opie/todayconfigwidget.h>
+
+#include "weatherconfig.h"
+
+WeatherPluginConfig::WeatherPluginConfig( QWidget *parent, const char* name)
+ : TodayConfigWidget(parent, name )
+{
+ Config config( "todayweatherplugin");
+ config.setGroup( "Config" );
+
+ QFontMetrics fm = fontMetrics();
+ int fh = fm.height();
+
+ QGridLayout *layout = new QGridLayout( this );
+ layout->setSpacing( 4 );
+ layout->setMargin( 4 );
+
+ QLabel *label = new QLabel( tr( "Enter ICAO location identifier:" ), this );
+ label->setMaximumHeight( fh + 3 );
+ layout->addMultiCellWidget( label, 0, 0, 0, 1 );
+
+ locationEdit = new QLineEdit( config.readEntry( "Location", "" ), this );
+ locationEdit->setMaximumHeight( fh + 5 );
+ locationEdit->setFocus();
+ layout->addMultiCellWidget( locationEdit, 1, 1, 0, 1 );
+
+ label = new QLabel( tr( "Visit http://www.nws.noaa.gov/tg/siteloc.shtml to find the nearest location." ), this );
+ label->setAlignment( AlignHCenter | WordBreak );
+ label->setMaximumHeight( label->height() );
+ layout->addMultiCellWidget( label, 2, 2, 0, 1 );
+ //layout->addWidget( label, 2, 0 );
+
+ //QPushButton *pb = new QPushButton( Resource::loadPixmap( "copy" ),
+ // tr( "Copy link" ), this );
+ //connect( pb, SIGNAL( clicked() ), this, SLOT( slotCopyLink() ) );
+ //layout->addWidget( pb, 2, 1 );
+
+ metricCB = new QCheckBox( tr( "Use metric units" ), this );
+ metricCB->setMaximumHeight( fh + 5 );
+ metricCB->setChecked( config.readBoolEntry( "Metric", TRUE ) );
+ layout->addMultiCellWidget( metricCB, 3, 3, 0, 1 );
+
+ label = new QLabel( tr( "Update frequency (in minutes):" ), this );
+ label->setMaximumHeight( fh + 3 );
+ layout->addWidget( label, 4, 0 );
+
+ timerDelaySB = new QSpinBox( 1, 60, 1, this );
+ timerDelaySB->setMaximumHeight( fh + 5 );
+ timerDelaySB->setValue( config.readNumEntry( "Frequency", 5 ) );
+ layout->addWidget( timerDelaySB, 4, 1 );
+}
+
+
+void WeatherPluginConfig::writeConfig()
+{
+ Config config( "todayweatherplugin");
+ config.setGroup( "Config" );
+
+ config.writeEntry( "Location", locationEdit->text().upper().stripWhiteSpace() );
+ config.writeEntry( "Metric", metricCB->isChecked() );
+ config.writeEntry( "Frequency", timerDelaySB->value() );
+
+ config.write();
+}
+
+WeatherPluginConfig::~WeatherPluginConfig()
+{
+}
+
+void WeatherPluginConfig::doLookup()
+{
+ system( "weather" );
+}
+
+/*
+
+Doesn't seem to like QPEApplication::clipboard()...
+
+void WeatherPluginConfig::slotCopyLink()
+{
+ QPEApplication::clipboard()->setText( "http://www.nws.noaa.gov/tg/siteloc.shtml" );
+}
+*/ \ No newline at end of file
diff --git a/noncore/todayplugins/weather/weatherconfig.h b/noncore/todayplugins/weather/weatherconfig.h
new file mode 100644
index 0000000..3877818
--- a/dev/null
+++ b/noncore/todayplugins/weather/weatherconfig.h
@@ -0,0 +1,59 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef WEATHER_PLUGIN_CONFIG_H
+#define WEATHER_PLUGIN_CONFIG_H
+
+#include <qstring.h>
+#include <qwidget.h>
+
+#include <opie/todayconfigwidget.h>
+
+class QCheckBox;
+class QLineEdit;
+class QPushButton;
+class QSpinBox;
+
+class WeatherPluginConfig : public TodayConfigWidget
+{
+ public:
+ WeatherPluginConfig( QWidget *parent, const char *name );
+ ~WeatherPluginConfig();
+ void writeConfig();
+
+ private:
+ QLineEdit *locationEdit;
+ QCheckBox *metricCB;
+ QSpinBox *timerDelaySB;
+
+ private slots:
+ void doLookup();
+ //void slotCopyLink();
+};
+
+#endif
diff --git a/noncore/todayplugins/weather/weatherplugin.cpp b/noncore/todayplugins/weather/weatherplugin.cpp
new file mode 100644
index 0000000..80e1cc6
--- a/dev/null
+++ b/noncore/todayplugins/weather/weatherplugin.cpp
@@ -0,0 +1,78 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "weatherplugin.h"
+#include "weatherpluginwidget.h"
+#include "weatherconfig.h"
+
+WeatherPlugin::WeatherPlugin() {
+}
+
+WeatherPlugin::~WeatherPlugin() {
+}
+
+QString WeatherPlugin::pluginName() const
+{
+ return QObject::tr( "Weather plugin" );
+}
+
+double WeatherPlugin::versionNumber() const
+{
+ return 0.1;
+}
+
+QString WeatherPlugin::pixmapNameWidget() const
+{
+ return "todayweatherplugin/weather";
+}
+
+QWidget* WeatherPlugin::widget( QWidget * wid )
+{
+ return new WeatherPluginWidget( wid, "Weather" );
+}
+
+QString WeatherPlugin::pixmapNameConfig() const
+{
+ return "todayweatherplugin/weather";
+}
+
+TodayConfigWidget* WeatherPlugin::configWidget( QWidget* wid )
+{
+ return new WeatherPluginConfig( wid, "Weather" );
+}
+
+QString WeatherPlugin::appName() const
+{
+ return "Weather";
+}
+
+bool WeatherPlugin::excludeFromRefresh() const {
+
+return true;
+}
+
diff --git a/noncore/todayplugins/weather/weatherplugin.h b/noncore/todayplugins/weather/weatherplugin.h
new file mode 100644
index 0000000..480d220
--- a/dev/null
+++ b/noncore/todayplugins/weather/weatherplugin.h
@@ -0,0 +1,54 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef WEATHER_PLUGIN_H
+#define WEATHER_PLUGIN_H
+
+#include <qstring.h>
+#include <qwidget.h>
+
+#include <opie/todayplugininterface.h>
+#include <opie/todayconfigwidget.h>
+
+class WeatherPlugin : public TodayPluginObject
+{
+ public:
+ WeatherPlugin();
+ ~WeatherPlugin();
+
+ QString pluginName() const;
+ double versionNumber() const;
+ QString pixmapNameWidget() const;
+ QWidget *widget(QWidget *);
+ QString pixmapNameConfig() const;
+ QString appName() const;
+ bool excludeFromRefresh() const;
+ TodayConfigWidget *configWidget(QWidget *);
+};
+
+#endif
diff --git a/noncore/todayplugins/weather/weatherpluginimpl.cpp b/noncore/todayplugins/weather/weatherpluginimpl.cpp
new file mode 100644
index 0000000..b5c7d0a
--- a/dev/null
+++ b/noncore/todayplugins/weather/weatherpluginimpl.cpp
@@ -0,0 +1,61 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "weatherplugin.h"
+#include "weatherpluginimpl.h"
+
+WeatherPluginImpl::WeatherPluginImpl()
+{
+ weatherPlugin = new WeatherPlugin();
+}
+
+WeatherPluginImpl::~WeatherPluginImpl()
+{
+}
+
+
+TodayPluginObject* WeatherPluginImpl::guiPart()
+{
+ return weatherPlugin;
+}
+
+QRESULT WeatherPluginImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
+{
+ *iface = 0;
+ if ( ( uuid == IID_QUnknown ) || ( uuid == IID_TodayPluginInterface ) )
+ {
+ *iface = this, (*iface)->addRef();
+ }
+
+ return QS_OK;
+}
+
+Q_EXPORT_INTERFACE()
+{
+ Q_CREATE_INSTANCE( WeatherPluginImpl );
+}
diff --git a/noncore/todayplugins/weather/weatherpluginimpl.h b/noncore/todayplugins/weather/weatherpluginimpl.h
new file mode 100644
index 0000000..aad8958
--- a/dev/null
+++ b/noncore/todayplugins/weather/weatherpluginimpl.h
@@ -0,0 +1,52 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef WEATHER_PLUGIN_IMPL_H
+#define WEATHER_PLUGIN_IMPL_H
+
+#include <opie/todayplugininterface.h>
+
+class WeatherPlugin;
+
+class WeatherPluginImpl : public TodayPluginInterface
+{
+ public:
+ WeatherPluginImpl();
+ virtual ~WeatherPluginImpl();
+
+ QRESULT queryInterface( const QUuid &, QUnknownInterface ** );
+ Q_REFCOUNT
+
+ virtual TodayPluginObject *guiPart();
+
+ private:
+ WeatherPlugin *weatherPlugin;
+ ulong ref;
+};
+
+#endif
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp
new file mode 100644
index 0000000..0fd8e57
--- a/dev/null
+++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp
@@ -0,0 +1,321 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+#include <stdio.h>
+
+#include <qfile.h>
+#include <qimage.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpixmap.h>
+#include <qtextstream.h>
+
+#include <qpe/config.h>
+#include <qpe/resource.h>
+
+#include "weatherpluginwidget.h"
+
+WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name )
+ : QWidget( parent, name )
+{
+ Config config( "todayweatherplugin");
+ config.setGroup( "Config" );
+
+ location = config.readEntry( "Location", "" );
+ useMetric = config.readBoolEntry( "Metric", TRUE );
+ frequency = config.readNumEntry( "Frequency", 5 );
+
+ localFile = "/tmp/";
+ localFile.append( location );
+ localFile.append( ".TXT" );
+
+ remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/";
+ remoteFile.append( location );
+ remoteFile.append( ".TXT" );
+
+ QHBoxLayout *layout = new QHBoxLayout( this );
+ layout->setAutoAdd( TRUE );
+ layout->setSpacing( 2 );
+
+ weatherIcon = new QLabel( this );
+ weatherIcon->setMaximumWidth( 32 );
+ QImage logo1 = Resource::loadImage( "todayweatherplugin/wait" );
+ QPixmap pic;
+ pic.convertFromImage( logo1 );
+ weatherIcon->setPixmap( pic );
+
+ weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this );
+ weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
+
+ startTimer(1000);
+ //retreiveData();
+}
+
+WeatherPluginWidget::~WeatherPluginWidget()
+{
+ QFile file( localFile );
+ if ( file.exists() )
+ {
+ file.remove();
+ }
+}
+
+void WeatherPluginWidget::timerEvent( QTimerEvent *e )
+{
+ killTimer( e->timerId() );
+ retreiveData();
+}
+
+
+
+void WeatherPluginWidget::retreiveData()
+{
+ startTimer( frequency * 60000 );
+
+ QFile file( localFile );
+ if ( file.exists() )
+ {
+ file.remove();
+ }
+
+ QString command = "wget -q ";
+ command.append( remoteFile );
+ command.append( " -O " );
+ command.append( localFile );
+ FILE *get = popen( command.latin1(), "r" );
+ if ( get )
+ {
+ pclose( get );
+ displayWeather();
+ }
+ else
+ {
+ weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) );
+ }
+}
+
+void WeatherPluginWidget::displayWeather()
+{
+ weatherData = QString::null;
+
+ QFile file( localFile );
+ if ( file.open( IO_ReadOnly ) )
+ {
+ QTextStream data( &file );
+ while ( !data.eof() )
+ {
+ weatherData.append( data.readLine() );
+ }
+ file.close();
+ weatherData = weatherData.simplifyWhiteSpace();
+
+ QString tmpstr;
+
+ tmpstr.append( tr( "Temp: " ) );
+ getTemp( weatherData );
+ tmpstr.append( dataStr );
+
+ tmpstr.append( tr( " Wind: " ) );
+ getWind( weatherData );
+ tmpstr.append( dataStr );
+
+ tmpstr.append( tr( "\nPres: " ) );
+ getPressure( weatherData );
+ tmpstr.append( dataStr );
+
+ weatherLabel->setText( tmpstr );
+
+ tmpstr = "todayweatherplugin/";
+ getIcon( weatherData );
+ tmpstr.append( dataStr );
+ QImage logo1 = Resource::loadImage( tmpstr );
+ QPixmap pic;
+ pic.convertFromImage( logo1 );
+ weatherIcon->setPixmap( pic );
+ }
+ else
+ {
+ weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) );
+ }
+}
+
+void WeatherPluginWidget::getTemp( const QString &data )
+{
+ int value;
+ bool ok;
+
+ int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 );
+ if ( pos > -1 )
+ {
+ if ( data.at( pos ) == 'M' )
+ {
+ value = -1 * data.mid( pos + 1, 2 ).toInt( &ok );
+ }
+ else
+ {
+ value = data.mid( pos, 2 ).toInt( &ok );
+ }
+ if ( useMetric )
+ {
+ dataStr = QString::number( value );
+ dataStr.append( 'C' );
+ }
+ else
+ {
+ dataStr = QString::number( ( value * 9 / 5 ) + 32 );
+ dataStr.append( 'F' );
+ }
+ }
+ else
+ {
+ dataStr = tr( "n/a" );
+ }
+}
+
+void WeatherPluginWidget::getWind( const QString &data )
+{
+ int value;
+ bool ok;
+
+ int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 );
+ if ( pos > -1 )
+ {
+ if ( data.mid( pos, 3 ) != "VRB" )
+ {
+ value = data.mid( pos, 3 ).toInt( &ok );
+ if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) )
+ dataStr = tr("E " );
+ else if ( value >= 23 && value < 69 )
+ dataStr = tr( "NE " );
+ else if ( value >= 69 && value < 113 )
+ dataStr = tr( "N " );
+ else if ( value >= 113 && value < 157 )
+ dataStr = tr( "NW " );
+ else if ( value >= 157 && value < 203 )
+ dataStr = tr( "W " );
+ else if ( value >= 203 && value < 248 )
+ dataStr = tr( "SW " );
+ else if ( value >= 248 && value < 294 )
+ dataStr = tr( "S " );
+ else if ( value >= 294 && value < 238 )
+ dataStr = tr( "SE " );
+ }
+ if ( data.mid( pos + 5, 1) == "G" ||
+ data.mid( pos + 5, 1) == "K" )
+ {
+ value = data.mid( pos + 3, 2 ).toInt( &ok );
+ }
+ else
+ {
+ value = data.mid( pos + 3, 3 ).toInt( &ok );
+ }
+ if ( useMetric )
+ {
+ value = value * 3.6 / 1.94;
+ dataStr.append( QString::number( value ) );
+ dataStr.append( tr( " KPH" ) );
+ }
+ else
+ {
+ value = value * 2.24 / 1.94;
+ dataStr.append( QString::number( value ) );
+ dataStr.append( tr( " MPH" ) );
+ }
+ }
+ else
+ {
+ dataStr = tr( "n/a" );
+ }
+}
+
+void WeatherPluginWidget::getPressure( const QString &data )
+{
+ float value;
+ bool ok;
+
+ int pos = data.find( QRegExp( "[AQ][0-9]+" ), 20 );
+ if ( pos > -1 )
+ {
+ value = data.mid( pos + 1, 4 ).toFloat( &ok );
+ if ( useMetric )
+ {
+ if ( data.mid( pos, 1 ) == "A" )
+ value *= 33.8639 / 100;
+ dataStr = QString::number( value, 'f', 2 );
+ dataStr.append( tr( " hPa" ) );
+ }
+ else
+ {
+ if ( data.mid( pos, 1 ) == "Q" )
+ value /= 33.8639;
+ else
+ value /= 100;
+ dataStr = QString::number( value, 'f', 2 );
+ dataStr.append( tr( " Hg" ) );
+ }
+ }
+ else
+ {
+ dataStr = tr( "n/a" );
+ }
+}
+
+void WeatherPluginWidget::getIcon(const QString &data )
+{
+ dataStr = "psunny";
+ if ( data.find( "CLR ", 20 ) > -1 ||
+ data.find( "SKC ", 20 ) > -1 ||
+ data.find( "CAVOK ", 20 ) > -1 )
+ {
+ dataStr = "sunny";
+ }
+ else if ( data.find( "SH ", 20 ) > -1 ||
+ data.find( "DZ ", 20 ) > -1 ||
+ data.find( "RA ", 20 ) > -1 ||
+ data.find( "UP ", 20 ) > -1 ||
+ data.find( "BR ", 20 ) > -1 )
+ {
+ dataStr = "shower";
+ }
+ else if ( data.find( "TS ", 20 ) > -1 )
+ {
+ dataStr = "tstorm";
+ }
+ else if ( data.find( "SN ", 20 ) > -1 ||
+ data.find( "SG ", 20 ) > -1 )
+ {
+ dataStr = "snow";
+ }
+ else if ( data.find( "FZ ", 20 ) > -1 ||
+ data.find( "GR ", 20 ) > -1 ||
+ data.find( "GS ", 20 ) > -1 ||
+ data.find( "PE ", 20 ) > -1 ||
+ data.find( "IC ", 20 ) > -1 )
+ {
+ dataStr = "sleet";
+ }
+}
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.h b/noncore/todayplugins/weather/weatherpluginwidget.h
new file mode 100644
index 0000000..2c0238d
--- a/dev/null
+++ b/noncore/todayplugins/weather/weatherpluginwidget.h
@@ -0,0 +1,69 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef WEATHER_PLUGIN_WIDGET_H
+#define WEATHER_PLUGIN_WIDGET_H
+
+#include <qstring.h>
+#include <qwidget.h>
+
+#include <unistd.h>
+
+class QLabel;
+class QTimer;
+
+class WeatherPluginWidget : public QWidget {
+
+ Q_OBJECT
+
+ public:
+ WeatherPluginWidget( QWidget *parent, const char *name );
+ ~WeatherPluginWidget();
+
+ private:
+ QString location;
+ QString remoteFile;
+ QString localFile;
+ QString weatherData;
+ QString dataStr;
+ bool useMetric;
+ int frequency;
+
+ QLabel *weatherLabel;
+ QLabel *weatherIcon;
+
+ void timerEvent( QTimerEvent * );
+ void retreiveData();
+ void displayWeather();
+ void getTemp( const QString & );
+ void getWind( const QString & );
+ void getPressure( const QString & );
+ void getIcon( const QString & );
+};
+
+#endif