author | drw <drw> | 2002-11-11 01:18:50 (UTC) |
---|---|---|
committer | drw <drw> | 2002-11-11 01:18:50 (UTC) |
commit | cbafca79e0a7993f55c085ead8aaa30604cc646b (patch) (unidiff) | |
tree | bf6ace5e20f33cfb3a43cafa64a8702ed045dcc6 | |
parent | f1e191f9cbfb4031fa4b5125306428b083b2cc04 (diff) | |
download | opie-cbafca79e0a7993f55c085ead8aaa30604cc646b.zip opie-cbafca79e0a7993f55c085ead8aaa30604cc646b.tar.gz opie-cbafca79e0a7993f55c085ead8aaa30604cc646b.tar.bz2 |
New Today weather plugin
-rw-r--r-- | noncore/todayplugins/weather/.cvsignore | 3 | ||||
-rw-r--r-- | noncore/todayplugins/weather/config.in | 5 | ||||
-rw-r--r-- | noncore/todayplugins/weather/opie-today-weatherplugin.control | 8 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weather.pro | 23 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherconfig.cpp | 127 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherconfig.h | 59 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherplugin.cpp | 78 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherplugin.h | 54 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginimpl.cpp | 61 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginimpl.h | 52 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.cpp | 321 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.h | 69 |
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 @@ | |||
1 | Makefile* | ||
2 | moc_* | ||
3 | *.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 @@ | |||
1 | config TODAY_WEATHER | ||
2 | boolean "weather" | ||
3 | default "y" | ||
4 | depends TODAY | ||
5 | |||
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 @@ | |||
1 | Files: plugins/today/libtodayweatherplugin.so* pics/todayweatherplugin | ||
2 | Priority: optional | ||
3 | Section: opie/applications | ||
4 | Maintainer: Dan Williams <williamsdr@acm.org> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-$SUB_VERSION | ||
7 | Depends: qt-embedded (>=$QTE_VERSION), opie-today | ||
8 | 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 @@ | |||
1 | TEMPLATE = lib | ||
2 | #CONFIG -= moc | ||
3 | CONFIG += qt debug | ||
4 | |||
5 | HEADERS = weatherplugin.h \ | ||
6 | weatherpluginimpl.h \ | ||
7 | weatherpluginwidget.h \ | ||
8 | weatherconfig.h | ||
9 | |||
10 | SOURCES = weatherplugin.cpp \ | ||
11 | weatherpluginimpl.cpp \ | ||
12 | weatherpluginwidget.cpp \ | ||
13 | weatherconfig.cpp | ||
14 | |||
15 | INCLUDEPATH += $(OPIEDIR)/include \ | ||
16 | ../ ../library | ||
17 | DEPENDPATH += $(OPIEDIR)/include \ | ||
18 | ../ ../library | ||
19 | |||
20 | LIBS+= -lqpe -lopie | ||
21 | |||
22 | DESTDIR = $(OPIEDIR)/plugins/today | ||
23 | 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 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include <stdlib.h> | ||
30 | |||
31 | #include <qcheckbox.h> | ||
32 | #include <qclipboard.h> | ||
33 | #include <qfontmetrics.h> | ||
34 | #include <qlabel.h> | ||
35 | #include <qlayout.h> | ||
36 | #include <qlineedit.h> | ||
37 | #include <qlayout.h> | ||
38 | #include <qpushbutton.h> | ||
39 | #include <qspinbox.h> | ||
40 | #include <qwhatsthis.h> | ||
41 | |||
42 | #include <qpe/config.h> | ||
43 | #include <qpe/qpeapplication.h> | ||
44 | #include <qpe/resource.h> | ||
45 | #include <opie/todayconfigwidget.h> | ||
46 | |||
47 | #include "weatherconfig.h" | ||
48 | |||
49 | WeatherPluginConfig::WeatherPluginConfig( QWidget *parent, const char* name) | ||
50 | : TodayConfigWidget(parent, name ) | ||
51 | { | ||
52 | Config config( "todayweatherplugin"); | ||
53 | config.setGroup( "Config" ); | ||
54 | |||
55 | QFontMetrics fm = fontMetrics(); | ||
56 | int fh = fm.height(); | ||
57 | |||
58 | QGridLayout *layout = new QGridLayout( this ); | ||
59 | layout->setSpacing( 4 ); | ||
60 | layout->setMargin( 4 ); | ||
61 | |||
62 | QLabel *label = new QLabel( tr( "Enter ICAO location identifier:" ), this ); | ||
63 | label->setMaximumHeight( fh + 3 ); | ||
64 | layout->addMultiCellWidget( label, 0, 0, 0, 1 ); | ||
65 | |||
66 | locationEdit = new QLineEdit( config.readEntry( "Location", "" ), this ); | ||
67 | locationEdit->setMaximumHeight( fh + 5 ); | ||
68 | locationEdit->setFocus(); | ||
69 | layout->addMultiCellWidget( locationEdit, 1, 1, 0, 1 ); | ||
70 | |||
71 | label = new QLabel( tr( "Visit http://www.nws.noaa.gov/tg/siteloc.shtml to find the nearest location." ), this ); | ||
72 | label->setAlignment( AlignHCenter | WordBreak ); | ||
73 | label->setMaximumHeight( label->height() ); | ||
74 | layout->addMultiCellWidget( label, 2, 2, 0, 1 ); | ||
75 | //layout->addWidget( label, 2, 0 ); | ||
76 | |||
77 | //QPushButton *pb = new QPushButton( Resource::loadPixmap( "copy" ), | ||
78 | //tr( "Copy link" ), this ); | ||
79 | //connect( pb, SIGNAL( clicked() ), this, SLOT( slotCopyLink() ) ); | ||
80 | //layout->addWidget( pb, 2, 1 ); | ||
81 | |||
82 | metricCB = new QCheckBox( tr( "Use metric units" ), this ); | ||
83 | metricCB->setMaximumHeight( fh + 5 ); | ||
84 | metricCB->setChecked( config.readBoolEntry( "Metric", TRUE ) ); | ||
85 | layout->addMultiCellWidget( metricCB, 3, 3, 0, 1 ); | ||
86 | |||
87 | label = new QLabel( tr( "Update frequency (in minutes):" ), this ); | ||
88 | label->setMaximumHeight( fh + 3 ); | ||
89 | layout->addWidget( label, 4, 0 ); | ||
90 | |||
91 | timerDelaySB = new QSpinBox( 1, 60, 1, this ); | ||
92 | timerDelaySB->setMaximumHeight( fh + 5 ); | ||
93 | timerDelaySB->setValue( config.readNumEntry( "Frequency", 5 ) ); | ||
94 | layout->addWidget( timerDelaySB, 4, 1 ); | ||
95 | } | ||
96 | |||
97 | |||
98 | void WeatherPluginConfig::writeConfig() | ||
99 | { | ||
100 | Config config( "todayweatherplugin"); | ||
101 | config.setGroup( "Config" ); | ||
102 | |||
103 | config.writeEntry( "Location", locationEdit->text().upper().stripWhiteSpace() ); | ||
104 | config.writeEntry( "Metric", metricCB->isChecked() ); | ||
105 | config.writeEntry( "Frequency", timerDelaySB->value() ); | ||
106 | |||
107 | config.write(); | ||
108 | } | ||
109 | |||
110 | WeatherPluginConfig::~WeatherPluginConfig() | ||
111 | { | ||
112 | } | ||
113 | |||
114 | void WeatherPluginConfig::doLookup() | ||
115 | { | ||
116 | system( "weather" ); | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | |||
121 | Doesn't seem to like QPEApplication::clipboard()... | ||
122 | |||
123 | void WeatherPluginConfig::slotCopyLink() | ||
124 | { | ||
125 | QPEApplication::clipboard()->setText( "http://www.nws.noaa.gov/tg/siteloc.shtml" ); | ||
126 | } | ||
127 | */ \ 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 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef WEATHER_PLUGIN_CONFIG_H | ||
30 | #define WEATHER_PLUGIN_CONFIG_H | ||
31 | |||
32 | #include <qstring.h> | ||
33 | #include <qwidget.h> | ||
34 | |||
35 | #include <opie/todayconfigwidget.h> | ||
36 | |||
37 | class QCheckBox; | ||
38 | class QLineEdit; | ||
39 | class QPushButton; | ||
40 | class QSpinBox; | ||
41 | |||
42 | class WeatherPluginConfig : public TodayConfigWidget | ||
43 | { | ||
44 | public: | ||
45 | WeatherPluginConfig( QWidget *parent, const char *name ); | ||
46 | ~WeatherPluginConfig(); | ||
47 | void writeConfig(); | ||
48 | |||
49 | private: | ||
50 | QLineEdit *locationEdit; | ||
51 | QCheckBox *metricCB; | ||
52 | QSpinBox *timerDelaySB; | ||
53 | |||
54 | private slots: | ||
55 | void doLookup(); | ||
56 | //void slotCopyLink(); | ||
57 | }; | ||
58 | |||
59 | #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 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include "weatherplugin.h" | ||
30 | #include "weatherpluginwidget.h" | ||
31 | #include "weatherconfig.h" | ||
32 | |||
33 | WeatherPlugin::WeatherPlugin() { | ||
34 | } | ||
35 | |||
36 | WeatherPlugin::~WeatherPlugin() { | ||
37 | } | ||
38 | |||
39 | QString WeatherPlugin::pluginName() const | ||
40 | { | ||
41 | return QObject::tr( "Weather plugin" ); | ||
42 | } | ||
43 | |||
44 | double WeatherPlugin::versionNumber() const | ||
45 | { | ||
46 | return 0.1; | ||
47 | } | ||
48 | |||
49 | QString WeatherPlugin::pixmapNameWidget() const | ||
50 | { | ||
51 | return "todayweatherplugin/weather"; | ||
52 | } | ||
53 | |||
54 | QWidget* WeatherPlugin::widget( QWidget * wid ) | ||
55 | { | ||
56 | return new WeatherPluginWidget( wid, "Weather" ); | ||
57 | } | ||
58 | |||
59 | QString WeatherPlugin::pixmapNameConfig() const | ||
60 | { | ||
61 | return "todayweatherplugin/weather"; | ||
62 | } | ||
63 | |||
64 | TodayConfigWidget* WeatherPlugin::configWidget( QWidget* wid ) | ||
65 | { | ||
66 | return new WeatherPluginConfig( wid, "Weather" ); | ||
67 | } | ||
68 | |||
69 | QString WeatherPlugin::appName() const | ||
70 | { | ||
71 | return "Weather"; | ||
72 | } | ||
73 | |||
74 | bool WeatherPlugin::excludeFromRefresh() const { | ||
75 | |||
76 | return true; | ||
77 | } | ||
78 | |||
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 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef WEATHER_PLUGIN_H | ||
30 | #define WEATHER_PLUGIN_H | ||
31 | |||
32 | #include <qstring.h> | ||
33 | #include <qwidget.h> | ||
34 | |||
35 | #include <opie/todayplugininterface.h> | ||
36 | #include <opie/todayconfigwidget.h> | ||
37 | |||
38 | class WeatherPlugin : public TodayPluginObject | ||
39 | { | ||
40 | public: | ||
41 | WeatherPlugin(); | ||
42 | ~WeatherPlugin(); | ||
43 | |||
44 | QString pluginName() const; | ||
45 | double versionNumber() const; | ||
46 | QString pixmapNameWidget() const; | ||
47 | QWidget *widget(QWidget *); | ||
48 | QString pixmapNameConfig() const; | ||
49 | QString appName() const; | ||
50 | bool excludeFromRefresh() const; | ||
51 | TodayConfigWidget *configWidget(QWidget *); | ||
52 | }; | ||
53 | |||
54 | #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 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include "weatherplugin.h" | ||
30 | #include "weatherpluginimpl.h" | ||
31 | |||
32 | WeatherPluginImpl::WeatherPluginImpl() | ||
33 | { | ||
34 | weatherPlugin = new WeatherPlugin(); | ||
35 | } | ||
36 | |||
37 | WeatherPluginImpl::~WeatherPluginImpl() | ||
38 | { | ||
39 | } | ||
40 | |||
41 | |||
42 | TodayPluginObject* WeatherPluginImpl::guiPart() | ||
43 | { | ||
44 | return weatherPlugin; | ||
45 | } | ||
46 | |||
47 | QRESULT WeatherPluginImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) | ||
48 | { | ||
49 | *iface = 0; | ||
50 | if ( ( uuid == IID_QUnknown ) || ( uuid == IID_TodayPluginInterface ) ) | ||
51 | { | ||
52 | *iface = this, (*iface)->addRef(); | ||
53 | } | ||
54 | |||
55 | return QS_OK; | ||
56 | } | ||
57 | |||
58 | Q_EXPORT_INTERFACE() | ||
59 | { | ||
60 | Q_CREATE_INSTANCE( WeatherPluginImpl ); | ||
61 | } | ||
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 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef WEATHER_PLUGIN_IMPL_H | ||
30 | #define WEATHER_PLUGIN_IMPL_H | ||
31 | |||
32 | #include <opie/todayplugininterface.h> | ||
33 | |||
34 | class WeatherPlugin; | ||
35 | |||
36 | class WeatherPluginImpl : public TodayPluginInterface | ||
37 | { | ||
38 | public: | ||
39 | WeatherPluginImpl(); | ||
40 | virtual ~WeatherPluginImpl(); | ||
41 | |||
42 | QRESULT queryInterface( const QUuid &, QUnknownInterface ** ); | ||
43 | Q_REFCOUNT | ||
44 | |||
45 | virtual TodayPluginObject *guiPart(); | ||
46 | |||
47 | private: | ||
48 | WeatherPlugin *weatherPlugin; | ||
49 | ulong ref; | ||
50 | }; | ||
51 | |||
52 | #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 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | #include <stdio.h> | ||
29 | |||
30 | #include <qfile.h> | ||
31 | #include <qimage.h> | ||
32 | #include <qlabel.h> | ||
33 | #include <qlayout.h> | ||
34 | #include <qpixmap.h> | ||
35 | #include <qtextstream.h> | ||
36 | |||
37 | #include <qpe/config.h> | ||
38 | #include <qpe/resource.h> | ||
39 | |||
40 | #include "weatherpluginwidget.h" | ||
41 | |||
42 | WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) | ||
43 | : QWidget( parent, name ) | ||
44 | { | ||
45 | Config config( "todayweatherplugin"); | ||
46 | config.setGroup( "Config" ); | ||
47 | |||
48 | location = config.readEntry( "Location", "" ); | ||
49 | useMetric = config.readBoolEntry( "Metric", TRUE ); | ||
50 | frequency = config.readNumEntry( "Frequency", 5 ); | ||
51 | |||
52 | localFile = "/tmp/"; | ||
53 | localFile.append( location ); | ||
54 | localFile.append( ".TXT" ); | ||
55 | |||
56 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; | ||
57 | remoteFile.append( location ); | ||
58 | remoteFile.append( ".TXT" ); | ||
59 | |||
60 | QHBoxLayout *layout = new QHBoxLayout( this ); | ||
61 | layout->setAutoAdd( TRUE ); | ||
62 | layout->setSpacing( 2 ); | ||
63 | |||
64 | weatherIcon = new QLabel( this ); | ||
65 | weatherIcon->setMaximumWidth( 32 ); | ||
66 | QImage logo1 = Resource::loadImage( "todayweatherplugin/wait" ); | ||
67 | QPixmap pic; | ||
68 | pic.convertFromImage( logo1 ); | ||
69 | weatherIcon->setPixmap( pic ); | ||
70 | |||
71 | weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this ); | ||
72 | weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); | ||
73 | |||
74 | startTimer(1000); | ||
75 | //retreiveData(); | ||
76 | } | ||
77 | |||
78 | WeatherPluginWidget::~WeatherPluginWidget() | ||
79 | { | ||
80 | QFile file( localFile ); | ||
81 | if ( file.exists() ) | ||
82 | { | ||
83 | file.remove(); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void WeatherPluginWidget::timerEvent( QTimerEvent *e ) | ||
88 | { | ||
89 | killTimer( e->timerId() ); | ||
90 | retreiveData(); | ||
91 | } | ||
92 | |||
93 | |||
94 | |||
95 | void WeatherPluginWidget::retreiveData() | ||
96 | { | ||
97 | startTimer( frequency * 60000 ); | ||
98 | |||
99 | QFile file( localFile ); | ||
100 | if ( file.exists() ) | ||
101 | { | ||
102 | file.remove(); | ||
103 | } | ||
104 | |||
105 | QString command = "wget -q "; | ||
106 | command.append( remoteFile ); | ||
107 | command.append( " -O " ); | ||
108 | command.append( localFile ); | ||
109 | FILE *get = popen( command.latin1(), "r" ); | ||
110 | if ( get ) | ||
111 | { | ||
112 | pclose( get ); | ||
113 | displayWeather(); | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) ); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | void WeatherPluginWidget::displayWeather() | ||
122 | { | ||
123 | weatherData = QString::null; | ||
124 | |||
125 | QFile file( localFile ); | ||
126 | if ( file.open( IO_ReadOnly ) ) | ||
127 | { | ||
128 | QTextStream data( &file ); | ||
129 | while ( !data.eof() ) | ||
130 | { | ||
131 | weatherData.append( data.readLine() ); | ||
132 | } | ||
133 | file.close(); | ||
134 | weatherData = weatherData.simplifyWhiteSpace(); | ||
135 | |||
136 | QString tmpstr; | ||
137 | |||
138 | tmpstr.append( tr( "Temp: " ) ); | ||
139 | getTemp( weatherData ); | ||
140 | tmpstr.append( dataStr ); | ||
141 | |||
142 | tmpstr.append( tr( " Wind: " ) ); | ||
143 | getWind( weatherData ); | ||
144 | tmpstr.append( dataStr ); | ||
145 | |||
146 | tmpstr.append( tr( "\nPres: " ) ); | ||
147 | getPressure( weatherData ); | ||
148 | tmpstr.append( dataStr ); | ||
149 | |||
150 | weatherLabel->setText( tmpstr ); | ||
151 | |||
152 | tmpstr = "todayweatherplugin/"; | ||
153 | getIcon( weatherData ); | ||
154 | tmpstr.append( dataStr ); | ||
155 | QImage logo1 = Resource::loadImage( tmpstr ); | ||
156 | QPixmap pic; | ||
157 | pic.convertFromImage( logo1 ); | ||
158 | weatherIcon->setPixmap( pic ); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) ); | ||
163 | } | ||
164 | } | ||
165 | |||
166 | void WeatherPluginWidget::getTemp( const QString &data ) | ||
167 | { | ||
168 | int value; | ||
169 | bool ok; | ||
170 | |||
171 | int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); | ||
172 | if ( pos > -1 ) | ||
173 | { | ||
174 | if ( data.at( pos ) == 'M' ) | ||
175 | { | ||
176 | value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | value = data.mid( pos, 2 ).toInt( &ok ); | ||
181 | } | ||
182 | if ( useMetric ) | ||
183 | { | ||
184 | dataStr = QString::number( value ); | ||
185 | dataStr.append( 'C' ); | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | dataStr = QString::number( ( value * 9 / 5 ) + 32 ); | ||
190 | dataStr.append( 'F' ); | ||
191 | } | ||
192 | } | ||
193 | else | ||
194 | { | ||
195 | dataStr = tr( "n/a" ); | ||
196 | } | ||
197 | } | ||
198 | |||
199 | void WeatherPluginWidget::getWind( const QString &data ) | ||
200 | { | ||
201 | int value; | ||
202 | bool ok; | ||
203 | |||
204 | int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 ); | ||
205 | if ( pos > -1 ) | ||
206 | { | ||
207 | if ( data.mid( pos, 3 ) != "VRB" ) | ||
208 | { | ||
209 | value = data.mid( pos, 3 ).toInt( &ok ); | ||
210 | if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) ) | ||
211 | dataStr = tr("E " ); | ||
212 | else if ( value >= 23 && value < 69 ) | ||
213 | dataStr = tr( "NE " ); | ||
214 | else if ( value >= 69 && value < 113 ) | ||
215 | dataStr = tr( "N " ); | ||
216 | else if ( value >= 113 && value < 157 ) | ||
217 | dataStr = tr( "NW " ); | ||
218 | else if ( value >= 157 && value < 203 ) | ||
219 | dataStr = tr( "W " ); | ||
220 | else if ( value >= 203 && value < 248 ) | ||
221 | dataStr = tr( "SW " ); | ||
222 | else if ( value >= 248 && value < 294 ) | ||
223 | dataStr = tr( "S " ); | ||
224 | else if ( value >= 294 && value < 238 ) | ||
225 | dataStr = tr( "SE " ); | ||
226 | } | ||
227 | if ( data.mid( pos + 5, 1) == "G" || | ||
228 | data.mid( pos + 5, 1) == "K" ) | ||
229 | { | ||
230 | value = data.mid( pos + 3, 2 ).toInt( &ok ); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | value = data.mid( pos + 3, 3 ).toInt( &ok ); | ||
235 | } | ||
236 | if ( useMetric ) | ||
237 | { | ||
238 | value = value * 3.6 / 1.94; | ||
239 | dataStr.append( QString::number( value ) ); | ||
240 | dataStr.append( tr( " KPH" ) ); | ||
241 | } | ||
242 | else | ||
243 | { | ||
244 | value = value * 2.24 / 1.94; | ||
245 | dataStr.append( QString::number( value ) ); | ||
246 | dataStr.append( tr( " MPH" ) ); | ||
247 | } | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | dataStr = tr( "n/a" ); | ||
252 | } | ||
253 | } | ||
254 | |||
255 | void WeatherPluginWidget::getPressure( const QString &data ) | ||
256 | { | ||
257 | float value; | ||
258 | bool ok; | ||
259 | |||
260 | int pos = data.find( QRegExp( "[AQ][0-9]+" ), 20 ); | ||
261 | if ( pos > -1 ) | ||
262 | { | ||
263 | value = data.mid( pos + 1, 4 ).toFloat( &ok ); | ||
264 | if ( useMetric ) | ||
265 | { | ||
266 | if ( data.mid( pos, 1 ) == "A" ) | ||
267 | value *= 33.8639 / 100; | ||
268 | dataStr = QString::number( value, 'f', 2 ); | ||
269 | dataStr.append( tr( " hPa" ) ); | ||
270 | } | ||
271 | else | ||
272 | { | ||
273 | if ( data.mid( pos, 1 ) == "Q" ) | ||
274 | value /= 33.8639; | ||
275 | else | ||
276 | value /= 100; | ||
277 | dataStr = QString::number( value, 'f', 2 ); | ||
278 | dataStr.append( tr( " Hg" ) ); | ||
279 | } | ||
280 | } | ||
281 | else | ||
282 | { | ||
283 | dataStr = tr( "n/a" ); | ||
284 | } | ||
285 | } | ||
286 | |||
287 | void WeatherPluginWidget::getIcon(const QString &data ) | ||
288 | { | ||
289 | dataStr = "psunny"; | ||
290 | if ( data.find( "CLR ", 20 ) > -1 || | ||
291 | data.find( "SKC ", 20 ) > -1 || | ||
292 | data.find( "CAVOK ", 20 ) > -1 ) | ||
293 | { | ||
294 | dataStr = "sunny"; | ||
295 | } | ||
296 | else if ( data.find( "SH ", 20 ) > -1 || | ||
297 | data.find( "DZ ", 20 ) > -1 || | ||
298 | data.find( "RA ", 20 ) > -1 || | ||
299 | data.find( "UP ", 20 ) > -1 || | ||
300 | data.find( "BR ", 20 ) > -1 ) | ||
301 | { | ||
302 | dataStr = "shower"; | ||
303 | } | ||
304 | else if ( data.find( "TS ", 20 ) > -1 ) | ||
305 | { | ||
306 | dataStr = "tstorm"; | ||
307 | } | ||
308 | else if ( data.find( "SN ", 20 ) > -1 || | ||
309 | data.find( "SG ", 20 ) > -1 ) | ||
310 | { | ||
311 | dataStr = "snow"; | ||
312 | } | ||
313 | else if ( data.find( "FZ ", 20 ) > -1 || | ||
314 | data.find( "GR ", 20 ) > -1 || | ||
315 | data.find( "GS ", 20 ) > -1 || | ||
316 | data.find( "PE ", 20 ) > -1 || | ||
317 | data.find( "IC ", 20 ) > -1 ) | ||
318 | { | ||
319 | dataStr = "sleet"; | ||
320 | } | ||
321 | } | ||
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 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef WEATHER_PLUGIN_WIDGET_H | ||
30 | #define WEATHER_PLUGIN_WIDGET_H | ||
31 | |||
32 | #include <qstring.h> | ||
33 | #include <qwidget.h> | ||
34 | |||
35 | #include <unistd.h> | ||
36 | |||
37 | class QLabel; | ||
38 | class QTimer; | ||
39 | |||
40 | class WeatherPluginWidget : public QWidget { | ||
41 | |||
42 | Q_OBJECT | ||
43 | |||
44 | public: | ||
45 | WeatherPluginWidget( QWidget *parent, const char *name ); | ||
46 | ~WeatherPluginWidget(); | ||
47 | |||
48 | private: | ||
49 | QString location; | ||
50 | QString remoteFile; | ||
51 | QString localFile; | ||
52 | QString weatherData; | ||
53 | QString dataStr; | ||
54 | bool useMetric; | ||
55 | int frequency; | ||
56 | |||
57 | QLabel *weatherLabel; | ||
58 | QLabel *weatherIcon; | ||
59 | |||
60 | void timerEvent( QTimerEvent * ); | ||
61 | void retreiveData(); | ||
62 | void displayWeather(); | ||
63 | void getTemp( const QString & ); | ||
64 | void getWind( const QString & ); | ||
65 | void getPressure( const QString & ); | ||
66 | void getIcon( const QString & ); | ||
67 | }; | ||
68 | |||
69 | #endif | ||