author | drw <drw> | 2005-05-24 20:53:08 (UTC) |
---|---|---|
committer | drw <drw> | 2005-05-24 20:53:08 (UTC) |
commit | 22cda9f7212641869c3abe210c66bf54a03f9579 (patch) (unidiff) | |
tree | 446175ae7d2d2790bf52732a66a930648f0a195c | |
parent | 2848aca68964a46fb2f786cc01a9b2583d599511 (diff) | |
download | opie-22cda9f7212641869c3abe210c66bf54a03f9579.zip opie-22cda9f7212641869c3abe210c66bf54a03f9579.tar.gz opie-22cda9f7212641869c3abe210c66bf54a03f9579.tar.bz2 |
Resource -> OResource and remove unnecessary include
-rw-r--r-- | noncore/todayplugins/weather/weatherconfig.cpp | 49 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.cpp | 13 |
2 files changed, 25 insertions, 37 deletions
diff --git a/noncore/todayplugins/weather/weatherconfig.cpp b/noncore/todayplugins/weather/weatherconfig.cpp index 4663549..d3ff3c9 100644 --- a/noncore/todayplugins/weather/weatherconfig.cpp +++ b/noncore/todayplugins/weather/weatherconfig.cpp | |||
@@ -1,131 +1,124 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | 4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "weatherconfig.h" | 29 | #include "weatherconfig.h" |
30 | 30 | ||
31 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
32 | #include <qpe/qpeapplication.h> | 32 | #include <qpe/qpeapplication.h> |
33 | #include <qpe/resource.h> | ||
34 | 33 | ||
35 | #include <qcheckbox.h> | 34 | #include <qcheckbox.h> |
36 | #include <qclipboard.h> | 35 | #include <qclipboard.h> |
37 | #include <qfontmetrics.h> | 36 | #include <qfontmetrics.h> |
38 | #include <qlabel.h> | 37 | #include <qlabel.h> |
39 | #include <qlayout.h> | 38 | #include <qlayout.h> |
40 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
41 | #include <qlayout.h> | 40 | #include <qlayout.h> |
42 | #include <qpushbutton.h> | 41 | #include <qpushbutton.h> |
43 | #include <qspinbox.h> | 42 | #include <qspinbox.h> |
44 | #include <qwhatsthis.h> | 43 | #include <qwhatsthis.h> |
45 | 44 | ||
46 | #include <stdlib.h> | 45 | #include <stdlib.h> |
47 | 46 | ||
48 | WeatherPluginConfig::WeatherPluginConfig( QWidget *parent, const char* name) | 47 | WeatherPluginConfig::WeatherPluginConfig( QWidget *parent, const char* name) |
49 | : TodayConfigWidget(parent, name ) | 48 | : TodayConfigWidget(parent, name ) |
50 | { | 49 | { |
51 | Config config( "todayweatherplugin"); | 50 | Config config( "todayweatherplugin"); |
52 | config.setGroup( "Config" ); | 51 | config.setGroup( "Config" ); |
53 | 52 | ||
54 | QFontMetrics fm = fontMetrics(); | 53 | QFontMetrics fm = fontMetrics(); |
55 | int fh = fm.height(); | 54 | int fh = fm.height(); |
56 | 55 | ||
57 | QGridLayout *layout = new QGridLayout( this ); | 56 | QGridLayout *layout = new QGridLayout( this ); |
58 | layout->setSpacing( 4 ); | 57 | layout->setSpacing( 4 ); |
59 | layout->setMargin( 4 ); | 58 | layout->setMargin( 4 ); |
60 | 59 | ||
61 | QLabel *label = new QLabel( tr( "Enter ICAO location identifier:" ), this ); | 60 | QLabel *label = new QLabel( tr( "Enter ICAO location identifier:" ), this ); |
62 | label->setMaximumHeight( fh + 3 ); | 61 | label->setMaximumHeight( fh + 3 ); |
63 | layout->addMultiCellWidget( label, 0, 0, 0, 1 ); | 62 | layout->addMultiCellWidget( label, 0, 0, 0, 1 ); |
64 | QWhatsThis::add( label, tr( "Enter the 4 letter code for the desired location here. See http://www.nws.noaa.gov/tg/siteloc.shtml to find a location near you." ) ); | 63 | QWhatsThis::add( label, tr( "Enter the 4 letter code for the desired location here. See http://www.nws.noaa.gov/tg/siteloc.shtml to find a location near you." ) ); |
65 | 64 | ||
66 | locationEdit = new QLineEdit( config.readEntry( "Location", "" ), this ); | 65 | locationEdit = new QLineEdit( config.readEntry( "Location", "" ), this ); |
67 | locationEdit->setMaximumHeight( fh + 5 ); | 66 | locationEdit->setMaximumHeight( fh + 5 ); |
68 | locationEdit->setFocus(); | 67 | locationEdit->setFocus(); |
69 | layout->addMultiCellWidget( locationEdit, 1, 1, 0, 1 ); | 68 | layout->addMultiCellWidget( locationEdit, 1, 1, 0, 1 ); |
70 | QWhatsThis::add( locationEdit, tr( "Enter the 4 letter code for the desired location here. See http://www.nws.noaa.gov/tg/siteloc.shtml to find a location near you." ) ); | 69 | QWhatsThis::add( locationEdit, tr( "Enter the 4 letter code for the desired location here. See http://www.nws.noaa.gov/tg/siteloc.shtml to find a location near you." ) ); |
71 | 70 | ||
72 | label = new QLabel( tr( "Visit http://www.nws.noaa.gov/tg/siteloc.shtml to find the nearest location." ), this ); | 71 | label = new QLabel( tr( "Visit http://www.nws.noaa.gov/tg/siteloc.shtml to find the nearest location." ), this ); |
73 | label->setAlignment( AlignHCenter | WordBreak ); | 72 | label->setAlignment( AlignHCenter | WordBreak ); |
74 | label->setMaximumHeight( label->height() ); | 73 | label->setMaximumHeight( label->height() ); |
75 | layout->addMultiCellWidget( label, 2, 2, 0, 1 ); | 74 | layout->addMultiCellWidget( label, 2, 2, 0, 1 ); |
76 | //layout->addWidget( label, 2, 0 ); | ||
77 | |||
78 | //QPushButton *pb = new QPushButton( Resource::loadPixmap( "copy" ), | ||
79 | //tr( "Copy link" ), this ); | ||
80 | //connect( pb, SIGNAL( clicked() ), this, SLOT( slotCopyLink() ) ); | ||
81 | //layout->addWidget( pb, 2, 1 ); | ||
82 | 75 | ||
83 | metricCB = new QCheckBox( tr( "Use metric units" ), this ); | 76 | metricCB = new QCheckBox( tr( "Use metric units" ), this ); |
84 | metricCB->setMaximumHeight( fh + 5 ); | 77 | metricCB->setMaximumHeight( fh + 5 ); |
85 | metricCB->setChecked( config.readBoolEntry( "Metric", TRUE ) ); | 78 | metricCB->setChecked( config.readBoolEntry( "Metric", TRUE ) ); |
86 | layout->addMultiCellWidget( metricCB, 3, 3, 0, 1 ); | 79 | layout->addMultiCellWidget( metricCB, 3, 3, 0, 1 ); |
87 | QWhatsThis::add( metricCB, tr( "Click here to select type of units displayed." ) ); | 80 | QWhatsThis::add( metricCB, tr( "Click here to select type of units displayed." ) ); |
88 | 81 | ||
89 | label = new QLabel( tr( "Update frequency (in minutes):" ), this ); | 82 | label = new QLabel( tr( "Update frequency (in minutes):" ), this ); |
90 | label->setMaximumHeight( fh + 3 ); | 83 | label->setMaximumHeight( fh + 3 ); |
91 | layout->addWidget( label, 4, 0 ); | 84 | layout->addWidget( label, 4, 0 ); |
92 | QWhatsThis::add( label, tr( "Select how often (in minutes) you want the weather to be updated." ) ); | 85 | QWhatsThis::add( label, tr( "Select how often (in minutes) you want the weather to be updated." ) ); |
93 | 86 | ||
94 | timerDelaySB = new QSpinBox( 1, 60, 1, this ); | 87 | timerDelaySB = new QSpinBox( 1, 60, 1, this ); |
95 | timerDelaySB->setMaximumHeight( fh + 5 ); | 88 | timerDelaySB->setMaximumHeight( fh + 5 ); |
96 | timerDelaySB->setValue( config.readNumEntry( "Frequency", 5 ) ); | 89 | timerDelaySB->setValue( config.readNumEntry( "Frequency", 5 ) ); |
97 | layout->addWidget( timerDelaySB, 4, 1 ); | 90 | layout->addWidget( timerDelaySB, 4, 1 ); |
98 | QWhatsThis::add( timerDelaySB, tr( "Select how often (in minutes) you want the weather to be updated." ) ); | 91 | QWhatsThis::add( timerDelaySB, tr( "Select how often (in minutes) you want the weather to be updated." ) ); |
99 | } | 92 | } |
100 | 93 | ||
101 | 94 | ||
102 | void WeatherPluginConfig::writeConfig() | 95 | void WeatherPluginConfig::writeConfig() |
103 | { | 96 | { |
104 | Config config( "todayweatherplugin"); | 97 | Config config( "todayweatherplugin"); |
105 | config.setGroup( "Config" ); | 98 | config.setGroup( "Config" ); |
106 | 99 | ||
107 | config.writeEntry( "Location", locationEdit->text().upper().stripWhiteSpace() ); | 100 | config.writeEntry( "Location", locationEdit->text().upper().stripWhiteSpace() ); |
108 | config.writeEntry( "Metric", metricCB->isChecked() ); | 101 | config.writeEntry( "Metric", metricCB->isChecked() ); |
109 | config.writeEntry( "Frequency", timerDelaySB->value() ); | 102 | config.writeEntry( "Frequency", timerDelaySB->value() ); |
110 | 103 | ||
111 | config.write(); | 104 | config.write(); |
112 | } | 105 | } |
113 | 106 | ||
114 | WeatherPluginConfig::~WeatherPluginConfig() | 107 | WeatherPluginConfig::~WeatherPluginConfig() |
115 | { | 108 | { |
116 | } | 109 | } |
117 | 110 | ||
118 | void WeatherPluginConfig::doLookup() | 111 | void WeatherPluginConfig::doLookup() |
119 | { | 112 | { |
120 | system( "weather" ); | 113 | system( "weather" ); |
121 | } | 114 | } |
122 | 115 | ||
123 | /* | 116 | /* |
124 | 117 | ||
125 | Doesn't seem to like QPEApplication::clipboard()... | 118 | Doesn't seem to like QPEApplication::clipboard()... |
126 | 119 | ||
127 | void WeatherPluginConfig::slotCopyLink() | 120 | void WeatherPluginConfig::slotCopyLink() |
128 | { | 121 | { |
129 | QPEApplication::clipboard()->setText( "http://www.nws.noaa.gov/tg/siteloc.shtml" ); | 122 | QPEApplication::clipboard()->setText( "http://www.nws.noaa.gov/tg/siteloc.shtml" ); |
130 | } | 123 | } |
131 | */ | 124 | */ |
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp index 8c41189..fe54051 100644 --- a/noncore/todayplugins/weather/weatherpluginwidget.cpp +++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp | |||
@@ -1,325 +1,320 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> | 4 | .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <opie2/oprocess.h> | 29 | #include <opie2/oprocess.h> |
30 | 30 | ||
31 | #include <qpe/applnk.h> | 31 | #include <opie2/oresource.h> |
32 | |||
32 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
33 | #include <qpe/resource.h> | ||
34 | 34 | ||
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qimage.h> | ||
37 | #include <qlabel.h> | 36 | #include <qlabel.h> |
38 | #include <qlayout.h> | 37 | #include <qlayout.h> |
39 | #include <qpixmap.h> | 38 | #include <qpixmap.h> |
40 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
41 | 40 | ||
42 | #include "weatherpluginwidget.h" | 41 | #include "weatherpluginwidget.h" |
43 | 42 | ||
44 | using namespace Opie::Core; | 43 | using namespace Opie::Core; |
45 | WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) | 44 | WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) |
46 | : QWidget( parent, name ) | 45 | : QWidget( parent, name ) |
47 | { | 46 | { |
48 | QHBoxLayout *layout = new QHBoxLayout( this, 1, 2 ); | 47 | QHBoxLayout *layout = new QHBoxLayout( this, 1, 2 ); |
49 | layout->setAutoAdd( true ); | 48 | layout->setAutoAdd( true ); |
50 | 49 | ||
51 | weatherIcon = new QLabel( this ); | 50 | weatherIcon = new QLabel( this ); |
52 | QPixmap pic; | 51 | weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( "Clock", Opie::Core::OResource::SmallIcon ) ); |
53 | pic.convertFromImage( Resource::loadImage( "Clock" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); | ||
54 | weatherIcon->setPixmap( pic ); | ||
55 | 52 | ||
56 | weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this ); | 53 | weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this ); |
57 | weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); | 54 | weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); |
58 | 55 | ||
59 | weatherIcon->setFixedSize( weatherLabel->height(), weatherLabel->height() ); | 56 | weatherIcon->setFixedSize( weatherLabel->height(), weatherLabel->height() ); |
60 | 57 | ||
61 | startTimer(1000); | 58 | startTimer(1000); |
62 | } | 59 | } |
63 | 60 | ||
64 | WeatherPluginWidget::~WeatherPluginWidget() | 61 | WeatherPluginWidget::~WeatherPluginWidget() |
65 | { | 62 | { |
66 | QFile file( localFile ); | 63 | QFile file( localFile ); |
67 | if ( file.exists() ) | 64 | if ( file.exists() ) |
68 | { | 65 | { |
69 | file.remove(); | 66 | file.remove(); |
70 | } | 67 | } |
71 | } | 68 | } |
72 | 69 | ||
73 | void WeatherPluginWidget::timerEvent( QTimerEvent *e ) | 70 | void WeatherPluginWidget::timerEvent( QTimerEvent *e ) |
74 | { | 71 | { |
75 | killTimer( e->timerId() ); | 72 | killTimer( e->timerId() ); |
76 | retreiveData(); | 73 | retreiveData(); |
77 | } | 74 | } |
78 | 75 | ||
79 | 76 | ||
80 | 77 | ||
81 | void WeatherPluginWidget::retreiveData() | 78 | void WeatherPluginWidget::retreiveData() |
82 | { | 79 | { |
83 | Config config( "todayweatherplugin"); | 80 | Config config( "todayweatherplugin"); |
84 | config.setGroup( "Config" ); | 81 | config.setGroup( "Config" ); |
85 | 82 | ||
86 | location = config.readEntry( "Location", "" ); | 83 | location = config.readEntry( "Location", "" ); |
87 | useMetric = config.readBoolEntry( "Metric", true ); | 84 | useMetric = config.readBoolEntry( "Metric", true ); |
88 | frequency = config.readNumEntry( "Frequency", 5 ); | 85 | frequency = config.readNumEntry( "Frequency", 5 ); |
89 | 86 | ||
90 | startTimer( frequency * 60000 ); | 87 | startTimer( frequency * 60000 ); |
91 | 88 | ||
92 | localFile = "/tmp/"; | 89 | localFile = "/tmp/"; |
93 | localFile.append( location ); | 90 | localFile.append( location ); |
94 | localFile.append( ".TXT" ); | 91 | localFile.append( ".TXT" ); |
95 | 92 | ||
96 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; | 93 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; |
97 | remoteFile.append( location ); | 94 | remoteFile.append( location ); |
98 | remoteFile.append( ".TXT" ); | 95 | remoteFile.append( ".TXT" ); |
99 | 96 | ||
100 | QFile file( localFile ); | 97 | QFile file( localFile ); |
101 | if ( file.exists() ) | 98 | if ( file.exists() ) |
102 | { | 99 | { |
103 | file.remove(); | 100 | file.remove(); |
104 | } | 101 | } |
105 | 102 | ||
106 | OProcess *proc = new OProcess; | 103 | OProcess *proc = new OProcess; |
107 | 104 | ||
108 | *proc << "wget" << "-q" << remoteFile << "-O" << localFile; | 105 | *proc << "wget" << "-q" << remoteFile << "-O" << localFile; |
109 | connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) ); | 106 | connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) ); |
110 | proc->start(); | 107 | proc->start(); |
111 | } | 108 | } |
112 | 109 | ||
113 | void WeatherPluginWidget::displayWeather() | 110 | void WeatherPluginWidget::displayWeather() |
114 | { | 111 | { |
115 | weatherData = QString::null; | 112 | weatherData = QString::null; |
116 | 113 | ||
117 | QFile file( localFile ); | 114 | QFile file( localFile ); |
118 | 115 | ||
119 | if ( file.size() > 0 && file.open( IO_ReadOnly ) ) | 116 | if ( file.size() > 0 && file.open( IO_ReadOnly ) ) |
120 | { | 117 | { |
121 | QTextStream data( &file ); | 118 | QTextStream data( &file ); |
122 | while ( !data.eof() ) | 119 | while ( !data.eof() ) |
123 | { | 120 | { |
124 | weatherData.append( data.readLine() ); | 121 | weatherData.append( data.readLine() ); |
125 | } | 122 | } |
126 | file.close(); | 123 | file.close(); |
127 | weatherData = weatherData.simplifyWhiteSpace(); | 124 | weatherData = weatherData.simplifyWhiteSpace(); |
128 | 125 | ||
129 | QString tmpstr; | 126 | QString tmpstr; |
130 | 127 | ||
131 | tmpstr.append( tr( "Temp: " ) ); | 128 | tmpstr.append( tr( "Temp: " ) ); |
132 | getTemp( weatherData ); | 129 | getTemp( weatherData ); |
133 | tmpstr.append( dataStr ); | 130 | tmpstr.append( dataStr ); |
134 | 131 | ||
135 | tmpstr.append( tr( " Wind: " ) ); | 132 | tmpstr.append( tr( " Wind: " ) ); |
136 | getWind( weatherData ); | 133 | getWind( weatherData ); |
137 | tmpstr.append( dataStr ); | 134 | tmpstr.append( dataStr ); |
138 | 135 | ||
139 | tmpstr.append( tr( "\nPres: " ) ); | 136 | tmpstr.append( tr( "\nPres: " ) ); |
140 | getPressure( weatherData ); | 137 | getPressure( weatherData ); |
141 | tmpstr.append( dataStr ); | 138 | tmpstr.append( dataStr ); |
142 | 139 | ||
143 | weatherLabel->setText( tmpstr ); | 140 | weatherLabel->setText( tmpstr ); |
144 | 141 | ||
145 | tmpstr = "todayweatherplugin/"; | 142 | tmpstr = "todayweatherplugin/"; |
146 | getIcon( weatherData ); | 143 | getIcon( weatherData ); |
147 | tmpstr.append( dataStr ); | 144 | tmpstr.append( dataStr ); |
148 | QPixmap pic; | 145 | weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) ); |
149 | pic.convertFromImage( Resource::loadImage( tmpstr ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); | ||
150 | weatherIcon->setPixmap( pic ); | ||
151 | } | 146 | } |
152 | else | 147 | else |
153 | { | 148 | { |
154 | weatherLabel->setText( tr( "Current weather data not available." ) ); | 149 | weatherLabel->setText( tr( "Current weather data not available." ) ); |
155 | } | 150 | } |
156 | } | 151 | } |
157 | 152 | ||
158 | void WeatherPluginWidget::getTemp( const QString &data ) | 153 | void WeatherPluginWidget::getTemp( const QString &data ) |
159 | { | 154 | { |
160 | int value; | 155 | int value; |
161 | bool ok; | 156 | bool ok; |
162 | 157 | ||
163 | int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); | 158 | int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); |
164 | if ( pos > -1 ) | 159 | if ( pos > -1 ) |
165 | { | 160 | { |
166 | if ( data.at( pos ) == 'M' ) | 161 | if ( data.at( pos ) == 'M' ) |
167 | { | 162 | { |
168 | value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); | 163 | value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); |
169 | } | 164 | } |
170 | else | 165 | else |
171 | { | 166 | { |
172 | value = data.mid( pos, 2 ).toInt( &ok ); | 167 | value = data.mid( pos, 2 ).toInt( &ok ); |
173 | } | 168 | } |
174 | if ( useMetric ) | 169 | if ( useMetric ) |
175 | { | 170 | { |
176 | dataStr = QString::number( value ); | 171 | dataStr = QString::number( value ); |
177 | dataStr.append( 'C' ); | 172 | dataStr.append( 'C' ); |
178 | } | 173 | } |
179 | else | 174 | else |
180 | { | 175 | { |
181 | dataStr = QString::number( ( value * 9 / 5 ) + 32 ); | 176 | dataStr = QString::number( ( value * 9 / 5 ) + 32 ); |
182 | dataStr.append( 'F' ); | 177 | dataStr.append( 'F' ); |
183 | } | 178 | } |
184 | } | 179 | } |
185 | else | 180 | else |
186 | { | 181 | { |
187 | dataStr = tr( "n/a" ); | 182 | dataStr = tr( "n/a" ); |
188 | } | 183 | } |
189 | } | 184 | } |
190 | 185 | ||
191 | void WeatherPluginWidget::getWind( const QString &data ) | 186 | void WeatherPluginWidget::getWind( const QString &data ) |
192 | { | 187 | { |
193 | int value; | 188 | int value; |
194 | bool ok; | 189 | bool ok; |
195 | 190 | ||
196 | int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 ); | 191 | int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 ); |
197 | if ( pos > -1 ) | 192 | if ( pos > -1 ) |
198 | { | 193 | { |
199 | if ( data.mid( pos, 3 ) != "VRB" ) | 194 | if ( data.mid( pos, 3 ) != "VRB" ) |
200 | { | 195 | { |
201 | value = data.mid( pos, 3 ).toInt( &ok ); | 196 | value = data.mid( pos, 3 ).toInt( &ok ); |
202 | if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) ) | 197 | if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) ) |
203 | dataStr = tr("E " ); | 198 | dataStr = tr("E " ); |
204 | else if ( value >= 23 && value < 69 ) | 199 | else if ( value >= 23 && value < 69 ) |
205 | dataStr = tr( "NE " ); | 200 | dataStr = tr( "NE " ); |
206 | else if ( value >= 69 && value < 113 ) | 201 | else if ( value >= 69 && value < 113 ) |
207 | dataStr = tr( "N " ); | 202 | dataStr = tr( "N " ); |
208 | else if ( value >= 113 && value < 157 ) | 203 | else if ( value >= 113 && value < 157 ) |
209 | dataStr = tr( "NW " ); | 204 | dataStr = tr( "NW " ); |
210 | else if ( value >= 157 && value < 203 ) | 205 | else if ( value >= 157 && value < 203 ) |
211 | dataStr = tr( "W " ); | 206 | dataStr = tr( "W " ); |
212 | else if ( value >= 203 && value < 248 ) | 207 | else if ( value >= 203 && value < 248 ) |
213 | dataStr = tr( "SW " ); | 208 | dataStr = tr( "SW " ); |
214 | else if ( value >= 248 && value < 294 ) | 209 | else if ( value >= 248 && value < 294 ) |
215 | dataStr = tr( "S " ); | 210 | dataStr = tr( "S " ); |
216 | else if ( value >= 294 && value < 238 ) | 211 | else if ( value >= 294 && value < 238 ) |
217 | dataStr = tr( "SE " ); | 212 | dataStr = tr( "SE " ); |
218 | } | 213 | } |
219 | if ( data.mid( pos + 5, 1) == "G" || | 214 | if ( data.mid( pos + 5, 1) == "G" || |
220 | data.mid( pos + 5, 1) == "K" ) | 215 | data.mid( pos + 5, 1) == "K" ) |
221 | { | 216 | { |
222 | value = data.mid( pos + 3, 2 ).toInt( &ok ); | 217 | value = data.mid( pos + 3, 2 ).toInt( &ok ); |
223 | } | 218 | } |
224 | else | 219 | else |
225 | { | 220 | { |
226 | value = data.mid( pos + 3, 3 ).toInt( &ok ); | 221 | value = data.mid( pos + 3, 3 ).toInt( &ok ); |
227 | } | 222 | } |
228 | if ( useMetric ) | 223 | if ( useMetric ) |
229 | { | 224 | { |
230 | value = value * 3.6 / 1.94; | 225 | value = value * 3.6 / 1.94; |
231 | dataStr.append( QString::number( value ) ); | 226 | dataStr.append( QString::number( value ) ); |
232 | dataStr.append( tr( " KPH" ) ); | 227 | dataStr.append( tr( " KPH" ) ); |
233 | } | 228 | } |
234 | else | 229 | else |
235 | { | 230 | { |
236 | value = value * 2.24 / 1.94; | 231 | value = value * 2.24 / 1.94; |
237 | dataStr.append( QString::number( value ) ); | 232 | dataStr.append( QString::number( value ) ); |
238 | dataStr.append( tr( " MPH" ) ); | 233 | dataStr.append( tr( " MPH" ) ); |
239 | } | 234 | } |
240 | } | 235 | } |
241 | else | 236 | else |
242 | { | 237 | { |
243 | dataStr = tr( "n/a" ); | 238 | dataStr = tr( "n/a" ); |
244 | } | 239 | } |
245 | } | 240 | } |
246 | 241 | ||
247 | void WeatherPluginWidget::getPressure( const QString &data ) | 242 | void WeatherPluginWidget::getPressure( const QString &data ) |
248 | { | 243 | { |
249 | float value; | 244 | float value; |
250 | bool ok; | 245 | bool ok; |
251 | 246 | ||
252 | int pos = data.find( QRegExp( "[AQ][0-9]+" ), 20 ); | 247 | int pos = data.find( QRegExp( "[AQ][0-9]+" ), 20 ); |
253 | if ( pos > -1 ) | 248 | if ( pos > -1 ) |
254 | { | 249 | { |
255 | value = data.mid( pos + 1, 4 ).toFloat( &ok ); | 250 | value = data.mid( pos + 1, 4 ).toFloat( &ok ); |
256 | if ( useMetric ) | 251 | if ( useMetric ) |
257 | { | 252 | { |
258 | if ( data.mid( pos, 1 ) == "A" ) | 253 | if ( data.mid( pos, 1 ) == "A" ) |
259 | value *= 33.8639 / 100; | 254 | value *= 33.8639 / 100; |
260 | dataStr = QString::number( value, 'f', 2 ); | 255 | dataStr = QString::number( value, 'f', 2 ); |
261 | dataStr.append( tr( " kPa" ) ); | 256 | dataStr.append( tr( " kPa" ) ); |
262 | } | 257 | } |
263 | else | 258 | else |
264 | { | 259 | { |
265 | if ( data.mid( pos, 1 ) == "Q" ) | 260 | if ( data.mid( pos, 1 ) == "Q" ) |
266 | value /= 33.8639; | 261 | value /= 33.8639; |
267 | else | 262 | else |
268 | value /= 100; | 263 | value /= 100; |
269 | dataStr = QString::number( value, 'f', 2 ); | 264 | dataStr = QString::number( value, 'f', 2 ); |
270 | dataStr.append( tr( " Hg" ) ); | 265 | dataStr.append( tr( " Hg" ) ); |
271 | } | 266 | } |
272 | } | 267 | } |
273 | else | 268 | else |
274 | { | 269 | { |
275 | dataStr = tr( "n/a" ); | 270 | dataStr = tr( "n/a" ); |
276 | } | 271 | } |
277 | } | 272 | } |
278 | 273 | ||
279 | void WeatherPluginWidget::getIcon(const QString &data ) | 274 | void WeatherPluginWidget::getIcon(const QString &data ) |
280 | { | 275 | { |
281 | dataStr = "psunny"; | 276 | dataStr = "psunny"; |
282 | if ( data.find( "CLR ", 20 ) > -1 || | 277 | if ( data.find( "CLR ", 20 ) > -1 || |
283 | data.find( "SKC ", 20 ) > -1 || | 278 | data.find( "SKC ", 20 ) > -1 || |
284 | data.find( "CAVOK ", 20 ) > -1 ) | 279 | data.find( "CAVOK ", 20 ) > -1 ) |
285 | { | 280 | { |
286 | dataStr = "sunny"; | 281 | dataStr = "sunny"; |
287 | } | 282 | } |
288 | else if ( data.find( "SH ", 20 ) > -1 || | 283 | else if ( data.find( "SH ", 20 ) > -1 || |
289 | data.find( "DZ ", 20 ) > -1 || | 284 | data.find( "DZ ", 20 ) > -1 || |
290 | data.find( "RA ", 20 ) > -1 || | 285 | data.find( "RA ", 20 ) > -1 || |
291 | data.find( "UP ", 20 ) > -1 || | 286 | data.find( "UP ", 20 ) > -1 || |
292 | data.find( "BR ", 20 ) > -1 ) | 287 | data.find( "BR ", 20 ) > -1 ) |
293 | { | 288 | { |
294 | dataStr = "shower"; | 289 | dataStr = "shower"; |
295 | } | 290 | } |
296 | else if ( data.find( "TS ", 20 ) > -1 ) | 291 | else if ( data.find( "TS ", 20 ) > -1 ) |
297 | { | 292 | { |
298 | dataStr = "tstorm"; | 293 | dataStr = "tstorm"; |
299 | } | 294 | } |
300 | else if ( data.find( "SN ", 20 ) > -1 || | 295 | else if ( data.find( "SN ", 20 ) > -1 || |
301 | data.find( "SG ", 20 ) > -1 ) | 296 | data.find( "SG ", 20 ) > -1 ) |
302 | { | 297 | { |
303 | dataStr = "snow"; | 298 | dataStr = "snow"; |
304 | } | 299 | } |
305 | else if ( data.find( "FZ ", 20 ) > -1 || | 300 | else if ( data.find( "FZ ", 20 ) > -1 || |
306 | data.find( "GR ", 20 ) > -1 || | 301 | data.find( "GR ", 20 ) > -1 || |
307 | data.find( "GS ", 20 ) > -1 || | 302 | data.find( "GS ", 20 ) > -1 || |
308 | data.find( "PE ", 20 ) > -1 || | 303 | data.find( "PE ", 20 ) > -1 || |
309 | data.find( "IC ", 20 ) > -1 ) | 304 | data.find( "IC ", 20 ) > -1 ) |
310 | { | 305 | { |
311 | dataStr = "sleet"; | 306 | dataStr = "sleet"; |
312 | } | 307 | } |
313 | } | 308 | } |
314 | 309 | ||
315 | void WeatherPluginWidget::dataRetrieved( OProcess *process ) | 310 | void WeatherPluginWidget::dataRetrieved( OProcess *process ) |
316 | { | 311 | { |
317 | if ( process->normalExit() ) | 312 | if ( process->normalExit() ) |
318 | { | 313 | { |
319 | displayWeather(); | 314 | displayWeather(); |
320 | } | 315 | } |
321 | else | 316 | else |
322 | { | 317 | { |
323 | weatherLabel->setText( tr( "Current weather data not available." ) ); | 318 | weatherLabel->setText( tr( "Current weather data not available." ) ); |
324 | } | 319 | } |
325 | } | 320 | } |