-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp index 6444ebf..f4ea0f2 100644 --- a/noncore/todayplugins/weather/weatherpluginwidget.cpp +++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp | |||
@@ -34,104 +34,104 @@ | |||
34 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
35 | 35 | ||
36 | #include <opie/oprocess.h> | 36 | #include <opie/oprocess.h> |
37 | 37 | ||
38 | #include <qpe/config.h> | 38 | #include <qpe/config.h> |
39 | #include <qpe/resource.h> | 39 | #include <qpe/resource.h> |
40 | 40 | ||
41 | #include "weatherpluginwidget.h" | 41 | #include "weatherpluginwidget.h" |
42 | 42 | ||
43 | WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) | 43 | WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) |
44 | : QWidget( parent, name ) | 44 | : QWidget( parent, name ) |
45 | { | 45 | { |
46 | QHBoxLayout *layout = new QHBoxLayout( this ); | 46 | QHBoxLayout *layout = new QHBoxLayout( this ); |
47 | layout->setAutoAdd( TRUE ); | 47 | layout->setAutoAdd( TRUE ); |
48 | layout->setSpacing( 2 ); | 48 | layout->setSpacing( 2 ); |
49 | 49 | ||
50 | weatherIcon = new QLabel( this ); | 50 | weatherIcon = new QLabel( this ); |
51 | weatherIcon->setMaximumWidth( 32 ); | 51 | weatherIcon->setMaximumWidth( 32 ); |
52 | QImage logo1 = Resource::loadImage( "todayweatherplugin/wait" ); | 52 | QImage logo1 = Resource::loadImage( "todayweatherplugin/wait" ); |
53 | QPixmap pic; | 53 | QPixmap pic; |
54 | pic.convertFromImage( logo1 ); | 54 | pic.convertFromImage( logo1 ); |
55 | weatherIcon->setPixmap( pic ); | 55 | weatherIcon->setPixmap( pic ); |
56 | 56 | ||
57 | weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this ); | 57 | weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this ); |
58 | weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); | 58 | weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); |
59 | 59 | ||
60 | startTimer(1000); | 60 | startTimer(1000); |
61 | } | 61 | } |
62 | 62 | ||
63 | WeatherPluginWidget::~WeatherPluginWidget() | 63 | WeatherPluginWidget::~WeatherPluginWidget() |
64 | { | 64 | { |
65 | QFile file( localFile ); | 65 | QFile file( localFile ); |
66 | if ( file.exists() ) | 66 | if ( file.exists() ) |
67 | { | 67 | { |
68 | file.remove(); | 68 | file.remove(); |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | void WeatherPluginWidget::timerEvent( QTimerEvent *e ) | 72 | void WeatherPluginWidget::timerEvent( QTimerEvent *e ) |
73 | { | 73 | { |
74 | killTimer( e->timerId() ); | 74 | killTimer( e->timerId() ); |
75 | retreiveData(); | 75 | retreiveData(); |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | 79 | ||
80 | void WeatherPluginWidget::retreiveData() | 80 | void WeatherPluginWidget::retreiveData() |
81 | { | 81 | { |
82 | startTimer( frequency * 60000 ); | ||
83 | |||
84 | Config config( "todayweatherplugin"); | 82 | Config config( "todayweatherplugin"); |
85 | config.setGroup( "Config" ); | 83 | config.setGroup( "Config" ); |
86 | 84 | ||
87 | location = config.readEntry( "Location", "" ); | 85 | location = config.readEntry( "Location", "" ); |
88 | useMetric = config.readBoolEntry( "Metric", TRUE ); | 86 | useMetric = config.readBoolEntry( "Metric", TRUE ); |
89 | frequency = config.readNumEntry( "Frequency", 5 ); | 87 | frequency = config.readNumEntry( "Frequency", 5 ); |
88 | |||
89 | startTimer( frequency * 60000 ); | ||
90 | 90 | ||
91 | localFile = "/tmp/"; | 91 | localFile = "/tmp/"; |
92 | localFile.append( location ); | 92 | localFile.append( location ); |
93 | localFile.append( ".TXT" ); | 93 | localFile.append( ".TXT" ); |
94 | 94 | ||
95 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; | 95 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; |
96 | remoteFile.append( location ); | 96 | remoteFile.append( location ); |
97 | remoteFile.append( ".TXT" ); | 97 | remoteFile.append( ".TXT" ); |
98 | 98 | ||
99 | QFile file( localFile ); | 99 | QFile file( localFile ); |
100 | if ( file.exists() ) | 100 | if ( file.exists() ) |
101 | { | 101 | { |
102 | file.remove(); | 102 | file.remove(); |
103 | } | 103 | } |
104 | 104 | ||
105 | OProcess *proc = new OProcess; | 105 | OProcess *proc = new OProcess; |
106 | 106 | ||
107 | *proc << "wget" << "-q" << remoteFile << "-O" << localFile; | 107 | *proc << "wget" << "-q" << remoteFile << "-O" << localFile; |
108 | connect( proc, SIGNAL( processExited( OProcess * ) ), this, SLOT( dataRetrieved( OProcess * ) ) ); | 108 | connect( proc, SIGNAL( processExited( OProcess * ) ), this, SLOT( dataRetrieved( OProcess * ) ) ); |
109 | proc->start(); | 109 | proc->start(); |
110 | } | 110 | } |
111 | 111 | ||
112 | void WeatherPluginWidget::displayWeather() | 112 | void WeatherPluginWidget::displayWeather() |
113 | { | 113 | { |
114 | weatherData = QString::null; | 114 | weatherData = QString::null; |
115 | 115 | ||
116 | QFile file( localFile ); | 116 | QFile file( localFile ); |
117 | if ( file.open( IO_ReadOnly ) ) | 117 | if ( file.open( IO_ReadOnly ) ) |
118 | { | 118 | { |
119 | QTextStream data( &file ); | 119 | QTextStream data( &file ); |
120 | while ( !data.eof() ) | 120 | while ( !data.eof() ) |
121 | { | 121 | { |
122 | weatherData.append( data.readLine() ); | 122 | weatherData.append( data.readLine() ); |
123 | } | 123 | } |
124 | file.close(); | 124 | file.close(); |
125 | weatherData = weatherData.simplifyWhiteSpace(); | 125 | weatherData = weatherData.simplifyWhiteSpace(); |
126 | 126 | ||
127 | QString tmpstr; | 127 | QString tmpstr; |
128 | 128 | ||
129 | tmpstr.append( tr( "Temp: " ) ); | 129 | tmpstr.append( tr( "Temp: " ) ); |
130 | getTemp( weatherData ); | 130 | getTemp( weatherData ); |
131 | tmpstr.append( dataStr ); | 131 | tmpstr.append( dataStr ); |
132 | 132 | ||
133 | tmpstr.append( tr( " Wind: " ) ); | 133 | tmpstr.append( tr( " Wind: " ) ); |
134 | getWind( weatherData ); | 134 | getWind( weatherData ); |
135 | tmpstr.append( dataStr ); | 135 | tmpstr.append( dataStr ); |
136 | 136 | ||
137 | tmpstr.append( tr( "\nPres: " ) ); | 137 | tmpstr.append( tr( "\nPres: " ) ); |