author | mickeyl <mickeyl> | 2002-10-12 15:37:56 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2002-10-12 15:37:56 (UTC) |
commit | 83aed438ec060307bf5562d91bd8b61fe60f860b (patch) (unidiff) | |
tree | b5156e2be374491e0dbf587b48272c1ae121660d | |
parent | fe2f3c3b72dfcffe0b6ab02cea37f6dcb300b218 (diff) | |
download | opie-83aed438ec060307bf5562d91bd8b61fe60f860b.zip opie-83aed438ec060307bf5562d91bd8b61fe60f860b.tar.gz opie-83aed438ec060307bf5562d91bd8b61fe60f860b.tar.bz2 |
- dhcp renew now really functions
- added dhcp renew support for udhcp
-rw-r--r-- | noncore/applets/wirelessapplet/wireless.cpp | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp index 649cf20..fb9522a 100644 --- a/noncore/applets/wirelessapplet/wireless.cpp +++ b/noncore/applets/wirelessapplet/wireless.cpp | |||
@@ -1,513 +1,539 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer | 2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer |
3 | ** <mickey@tm.informatik.uni-frankfurt.de> | 3 | ** <mickey@tm.informatik.uni-frankfurt.de> |
4 | ** http://www.Vanille.de | 4 | ** http://www.Vanille.de |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "wireless.h" | 16 | #include "wireless.h" |
17 | 17 | ||
18 | #include <qapplication.h> | 18 | #include <qapplication.h> |
19 | #include <qpe/qpeapplication.h> | 19 | #include <qpe/qpeapplication.h> |
20 | #include <qpe/config.h> | 20 | #include <qpe/config.h> |
21 | 21 | ||
22 | #include <qpoint.h> | 22 | #include <qpoint.h> |
23 | #include <qradiobutton.h> | 23 | #include <qradiobutton.h> |
24 | #include <qpushbutton.h> | 24 | #include <qpushbutton.h> |
25 | #include <qpainter.h> | 25 | #include <qpainter.h> |
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qslider.h> | 27 | #include <qslider.h> |
28 | #include <qbuttongroup.h> | 28 | #include <qbuttongroup.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qframe.h> | 30 | #include <qframe.h> |
31 | #include <qpixmap.h> | 31 | #include <qpixmap.h> |
32 | #include <qstring.h> | 32 | #include <qstring.h> |
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
35 | 35 | ||
36 | #include <sys/types.h> | 36 | #include <sys/types.h> |
37 | #include <signal.h> | 37 | #include <signal.h> |
38 | 38 | ||
39 | #include "networkinfo.h" | 39 | #include "networkinfo.h" |
40 | #include "mgraph.h" | 40 | #include "mgraph.h" |
41 | 41 | ||
42 | #include "advancedconfig.h" | 42 | #include "advancedconfig.h" |
43 | 43 | ||
44 | #include "connect0.xpm" | 44 | #include "connect0.xpm" |
45 | #include "connect1.xpm" | 45 | #include "connect1.xpm" |
46 | #include "connect2.xpm" | 46 | #include "connect2.xpm" |
47 | #include "connect3.xpm" | 47 | #include "connect3.xpm" |
48 | #include "connect4.xpm" | 48 | #include "connect4.xpm" |
49 | #include "connect5.xpm" | 49 | #include "connect5.xpm" |
50 | #include "nowireless.xpm" | 50 | #include "nowireless.xpm" |
51 | 51 | ||
52 | #define STYLE_BARS 0 | 52 | #define STYLE_BARS 0 |
53 | #define STYLE_ANTENNA 1 | 53 | #define STYLE_ANTENNA 1 |
54 | 54 | ||
55 | //#define MDEBUG 0 | 55 | //#define MDEBUG |
56 | #undef MDEBUG | 56 | #undef MDEBUG |
57 | 57 | ||
58 | WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) | 58 | WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) |
59 | : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) | 59 | : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) |
60 | { | 60 | { |
61 | 61 | ||
62 | readConfig(); | 62 | readConfig(); |
63 | writeConfigEntry( "UpdateFrequency", updateFrequency ); | 63 | writeConfigEntry( "UpdateFrequency", updateFrequency ); |
64 | writeConfigEntry( "DisplayStyle", displayStyle ); | 64 | writeConfigEntry( "DisplayStyle", displayStyle ); |
65 | 65 | ||
66 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 66 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
67 | QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); | 67 | QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); |
68 | 68 | ||
69 | /* status label */ | 69 | /* status label */ |
70 | 70 | ||
71 | statusLabel = new QLabel( this, "statuslabel" ); | 71 | statusLabel = new QLabel( this, "statuslabel" ); |
72 | QString text( "Wireless Status:<br>" | 72 | QString text( "Wireless Status:<br>" |
73 | "*** Unknown ***<br>" | 73 | "*** Unknown ***<br>" |
74 | "Card not inserted ?<br>" | 74 | "Card not inserted ?<br>" |
75 | "Or Sharp ROM ?<br>" | 75 | "Or Sharp ROM ?<br>" |
76 | "CELL: 00:00:00:00:00:00" ); | 76 | "CELL: 00:00:00:00:00:00" ); |
77 | /* QString text( "Station: Unknown<br>" | 77 | /* QString text( "Station: Unknown<br>" |
78 | "ESSID: Unknown<br>" | 78 | "ESSID: Unknown<br>" |
79 | "MODE: Unknown<br>" | 79 | "MODE: Unknown<br>" |
80 | "FREQ: Unknown<br>" | 80 | "FREQ: Unknown<br>" |
81 | "CELL: AA:BB:CC:DD:EE:FF" ); */ | 81 | "CELL: AA:BB:CC:DD:EE:FF" ); */ |
82 | statusLabel->setText( text ); | 82 | statusLabel->setText( text ); |
83 | statusLabel->setFixedSize( statusLabel->sizeHint() ); | 83 | statusLabel->setFixedSize( statusLabel->sizeHint() ); |
84 | grid->addWidget( statusLabel, 0, 0 ); | 84 | grid->addWidget( statusLabel, 0, 0 ); |
85 | 85 | ||
86 | /* visualization group box */ | 86 | /* visualization group box */ |
87 | 87 | ||
88 | QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); | 88 | QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); |
89 | QRadioButton* r1 = new QRadioButton( "Color Bars", group ); | 89 | QRadioButton* r1 = new QRadioButton( "Color Bars", group ); |
90 | QRadioButton* r2 = new QRadioButton( "Antenna", group ); | 90 | QRadioButton* r2 = new QRadioButton( "Antenna", group ); |
91 | r1->setFocusPolicy( QWidget::NoFocus ); | 91 | r1->setFocusPolicy( QWidget::NoFocus ); |
92 | r2->setFocusPolicy( QWidget::NoFocus ); | 92 | r2->setFocusPolicy( QWidget::NoFocus ); |
93 | group->setFocusPolicy( QWidget::NoFocus ); | 93 | group->setFocusPolicy( QWidget::NoFocus ); |
94 | group->setButton( displayStyle ); | 94 | group->setButton( displayStyle ); |
95 | grid->addWidget( group, 0, 1 ); | 95 | grid->addWidget( group, 0, 1 ); |
96 | 96 | ||
97 | /* quality graph */ | 97 | /* quality graph */ |
98 | 98 | ||
99 | mgraph = new MGraph( this ); | 99 | mgraph = new MGraph( this ); |
100 | mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 100 | mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
101 | mgraph->setMin( 0 ); | 101 | mgraph->setMin( 0 ); |
102 | mgraph->setMax( 92 ); | 102 | mgraph->setMax( 92 ); |
103 | grid->addWidget( mgraph, 1, 0 ); | 103 | grid->addWidget( mgraph, 1, 0 ); |
104 | mgraph->setFocusPolicy( QWidget::NoFocus ); | 104 | mgraph->setFocusPolicy( QWidget::NoFocus ); |
105 | 105 | ||
106 | /* advanced configuration Button */ | 106 | /* advanced configuration Button */ |
107 | 107 | ||
108 | QPushButton* advanced = new QPushButton( "Advanced...", this ); | 108 | QPushButton* advanced = new QPushButton( "Advanced...", this ); |
109 | advanced->setFocusPolicy( QWidget::NoFocus ); | 109 | advanced->setFocusPolicy( QWidget::NoFocus ); |
110 | grid->addWidget( advanced, 2, 0, Qt::AlignCenter ); | 110 | grid->addWidget( advanced, 2, 0, Qt::AlignCenter ); |
111 | connect( advanced, SIGNAL( clicked() ), | 111 | connect( advanced, SIGNAL( clicked() ), |
112 | this, SLOT( advancedConfigClicked() ) ); | 112 | this, SLOT( advancedConfigClicked() ) ); |
113 | 113 | ||
114 | /* update Frequency Label */ | 114 | /* update Frequency Label */ |
115 | 115 | ||
116 | updateLabel = new QLabel( this ); | 116 | updateLabel = new QLabel( this ); |
117 | text.sprintf( "Update every %d s", updateFrequency ); | 117 | text.sprintf( "Update every %d s", updateFrequency ); |
118 | updateLabel->setText( text ); | 118 | updateLabel->setText( text ); |
119 | grid->addWidget( updateLabel, 2, 1 ); | 119 | grid->addWidget( updateLabel, 2, 1 ); |
120 | 120 | ||
121 | /* update Frequency Slider */ | 121 | /* update Frequency Slider */ |
122 | 122 | ||
123 | QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); | 123 | QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); |
124 | updateSlider->setRange( 0, 9 ); | 124 | updateSlider->setRange( 0, 9 ); |
125 | updateSlider->setValue( updateFrequency ); | 125 | updateSlider->setValue( updateFrequency ); |
126 | updateSlider->setTickmarks( QSlider::Both ); | 126 | updateSlider->setTickmarks( QSlider::Both ); |
127 | updateSlider->setTickInterval( 1 ); | 127 | updateSlider->setTickInterval( 1 ); |
128 | updateSlider->setSteps( 1, 1 ); | 128 | updateSlider->setSteps( 1, 1 ); |
129 | updateSlider->setFocusPolicy( QWidget::NoFocus ); | 129 | updateSlider->setFocusPolicy( QWidget::NoFocus ); |
130 | grid->addWidget( updateSlider, 1, 1 ); | 130 | grid->addWidget( updateSlider, 1, 1 ); |
131 | connect( updateSlider, SIGNAL( valueChanged( int ) ), | 131 | connect( updateSlider, SIGNAL( valueChanged( int ) ), |
132 | this, SLOT( updateDelayChange( int ) ) ); | 132 | this, SLOT( updateDelayChange( int ) ) ); |
133 | 133 | ||
134 | setFixedSize( sizeHint() ); | 134 | setFixedSize( sizeHint() ); |
135 | setFocusPolicy( QWidget::NoFocus ); | 135 | setFocusPolicy( QWidget::NoFocus ); |
136 | 136 | ||
137 | applet->displayStyleChange( displayStyle ); | 137 | applet->displayStyleChange( displayStyle ); |
138 | applet->updateDelayChange( updateFrequency ); | 138 | applet->updateDelayChange( updateFrequency ); |
139 | 139 | ||
140 | connect( group, SIGNAL( clicked( int ) ), | 140 | connect( group, SIGNAL( clicked( int ) ), |
141 | this, SLOT( displayStyleChange( int ) ) ); | 141 | this, SLOT( displayStyleChange( int ) ) ); |
142 | 142 | ||
143 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); | 143 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); |
144 | } | 144 | } |
145 | 145 | ||
146 | void WirelessControl::advancedConfigClicked() | 146 | void WirelessControl::advancedConfigClicked() |
147 | { | 147 | { |
148 | AdvancedConfig* a = new AdvancedConfig( this, "dialog", TRUE ); | 148 | AdvancedConfig* a = new AdvancedConfig( this, "dialog", TRUE ); |
149 | int result = a->exec(); | 149 | int result = a->exec(); |
150 | a->hide(); | 150 | a->hide(); |
151 | delete a; | 151 | delete a; |
152 | if ( result == QDialog::Accepted ) | 152 | if ( result == QDialog::Accepted ) |
153 | { | 153 | { |
154 | readConfig(); | 154 | readConfig(); |
155 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); | 155 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); |
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | void WirelessControl::updateDelayChange( int delay ) | 159 | void WirelessControl::updateDelayChange( int delay ) |
160 | { | 160 | { |
161 | QString text; | 161 | QString text; |
162 | text.sprintf( "Update every %d s", delay ); | 162 | text.sprintf( "Update every %d s", delay ); |
163 | updateLabel->setText( text ); | 163 | updateLabel->setText( text ); |
164 | applet->updateDelayChange( delay ); | 164 | applet->updateDelayChange( delay ); |
165 | writeConfigEntry( "UpdateFrequency", delay ); | 165 | writeConfigEntry( "UpdateFrequency", delay ); |
166 | } | 166 | } |
167 | 167 | ||
168 | void WirelessControl::displayStyleChange( int style ) | 168 | void WirelessControl::displayStyleChange( int style ) |
169 | { | 169 | { |
170 | applet->displayStyleChange( style ); | 170 | applet->displayStyleChange( style ); |
171 | writeConfigEntry( "DisplayStyle", style ); | 171 | writeConfigEntry( "DisplayStyle", style ); |
172 | } | 172 | } |
173 | 173 | ||
174 | void WirelessControl::show ( bool ) | 174 | void WirelessControl::show ( bool ) |
175 | { | 175 | { |
176 | QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); | 176 | QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); |
177 | 177 | ||
178 | int w = sizeHint().width(); | 178 | int w = sizeHint().width(); |
179 | int x = curPos.x() - ( w / 2 ); | 179 | int x = curPos.x() - ( w / 2 ); |
180 | 180 | ||
181 | if ( ( x + w ) > QPEApplication::desktop()->width() ) | 181 | if ( ( x + w ) > QPEApplication::desktop()->width() ) |
182 | x = QPEApplication::desktop ( )-> width ( ) - w; | 182 | x = QPEApplication::desktop ( )-> width ( ) - w; |
183 | 183 | ||
184 | move( x, curPos.y () - sizeHint().height () ); | 184 | move( x, curPos.y () - sizeHint().height () ); |
185 | QFrame::show(); | 185 | QFrame::show(); |
186 | } | 186 | } |
187 | 187 | ||
188 | void WirelessControl::readConfig() | 188 | void WirelessControl::readConfig() |
189 | { | 189 | { |
190 | Config cfg( "qpe" ); | 190 | Config cfg( "qpe" ); |
191 | cfg.setGroup( "Wireless" ); | 191 | cfg.setGroup( "Wireless" ); |
192 | 192 | ||
193 | updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); | 193 | updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); |
194 | displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA ); | 194 | displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA ); |
195 | rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false ); | 195 | rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false ); |
196 | rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false ); | 196 | rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false ); |
197 | rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false ); | 197 | rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false ); |
198 | rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false ); | 198 | rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false ); |
199 | } | 199 | } |
200 | 200 | ||
201 | void WirelessControl::writeConfigEntry( const char *entry, int val ) | 201 | void WirelessControl::writeConfigEntry( const char *entry, int val ) |
202 | { | 202 | { |
203 | Config cfg( "qpe" ); | 203 | Config cfg( "qpe" ); |
204 | cfg.setGroup( "Wireless" ); | 204 | cfg.setGroup( "Wireless" ); |
205 | cfg.writeEntry( entry, val ); | 205 | cfg.writeEntry( entry, val ); |
206 | } | 206 | } |
207 | 207 | ||
208 | //=========================================================================== | 208 | //=========================================================================== |
209 | 209 | ||
210 | WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) | 210 | WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) |
211 | : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), | 211 | : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), |
212 | timer( 0 ), interface( 0 ), | 212 | timer( 0 ), interface( 0 ), |
213 | rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false ) | 213 | rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false ) |
214 | { | 214 | { |
215 | setFixedHeight( 18 ); | 215 | setFixedHeight( 18 ); |
216 | setFixedWidth( 14 ); | 216 | setFixedWidth( 14 ); |
217 | network = new MWirelessNetwork(); | 217 | network = new MWirelessNetwork(); |
218 | status = new WirelessControl( this, 0, "wireless status" ); | 218 | status = new WirelessControl( this, 0, "wireless status" ); |
219 | } | 219 | } |
220 | 220 | ||
221 | void WirelessApplet::checkInterface() | 221 | void WirelessApplet::checkInterface() |
222 | { | 222 | { |
223 | interface = network->getFirstInterface(); | 223 | interface = network->getFirstInterface(); |
224 | if ( interface ) | 224 | if ( interface ) |
225 | { | 225 | { |
226 | #ifdef MDEBUG | 226 | #ifdef MDEBUG |
227 | qDebug( "WIFIAPPLET: using interface '%s'", (const char*) interface->getName() ); | 227 | qDebug( "WIFIAPPLET: using interface '%s'", (const char*) interface->getName() ); |
228 | #endif | 228 | #endif |
229 | } | 229 | } |
230 | else | 230 | else |
231 | { | 231 | { |
232 | #ifdef MDEBUG | 232 | #ifdef MDEBUG |
233 | qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); | 233 | qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); |
234 | #endif | 234 | #endif |
235 | hide(); | 235 | hide(); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | 238 | ||
239 | void WirelessApplet::renewDHCP() | 239 | void WirelessApplet::renewDHCP() |
240 | { | 240 | { |
241 | #ifdef MDEBUG | 241 | #ifdef MDEBUG |
242 | qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." ); | 242 | qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." ); |
243 | #endif | 243 | #endif |
244 | 244 | ||
245 | QString pidfile; | 245 | QString pidfile; |
246 | if ( !interface ) | 246 | if ( !interface ) |
247 | return; | 247 | return; |
248 | QString ifacename( interface->getName() ); | 248 | QString ifacename( interface->getName() ); |
249 | |||
250 | // At first we are trying dhcpcd | ||
251 | |||
249 | pidfile.sprintf( "/var/run/dhcpcd-%s.pid", (const char* ) ifacename ); | 252 | pidfile.sprintf( "/var/run/dhcpcd-%s.pid", (const char* ) ifacename ); |
250 | #ifdef MDEBUG | 253 | #ifdef MDEBUG |
251 | qDebug( "WIFIAPPLET: pidfile is '%s'", (const char*) pidfile ); | 254 | qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", (const char*) pidfile ); |
252 | #endif | 255 | #endif |
253 | int pid; | 256 | int pid; |
254 | QFile pfile( pidfile ); | 257 | QFile pfile( pidfile ); |
255 | bool hasFile = pfile.open( IO_ReadOnly ); | 258 | bool hasFile = pfile.open( IO_ReadOnly ); |
256 | QTextStream s( &pfile ); | 259 | QTextStream s( &pfile ); |
257 | if ( hasFile ) | 260 | if ( hasFile ) |
261 | { | ||
258 | s >> pid; | 262 | s >> pid; |
259 | #ifdef MDEBUG | 263 | #ifdef MDEBUG |
260 | qDebug( "WIFIAPPLET: sent -14 to pid %d", pid ); | 264 | qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid ); |
261 | #endif | 265 | #endif |
262 | kill( pid, -14 ); | 266 | kill( pid, SIGALRM ); |
267 | return; | ||
268 | } | ||
263 | 269 | ||
264 | } | 270 | // No dhcpcd, so we are trying udhcpc |
271 | #ifdef MDEBUG | ||
272 | qDebug( "WIFIAPPLET: dhcpcd not available." ); | ||
273 | #endif | ||
274 | pidfile.sprintf( "/var/run/udhcpc.%s.pid", (const char*) ifacename ); | ||
275 | #ifdef MDEBUG | ||
276 | qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", (const char*) pidfile ); | ||
277 | #endif | ||
278 | QFile pfile2( pidfile ); | ||
279 | hasFile = pfile2.open( IO_ReadOnly ); | ||
280 | QTextStream s2( &pfile2 ); | ||
281 | if ( hasFile ) | ||
282 | { | ||
283 | s2 >> pid; | ||
284 | #ifdef MDEBUG | ||
285 | qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid ); | ||
286 | #endif | ||
287 | kill( pid, SIGUSR1 ); | ||
288 | return; | ||
289 | } | ||
290 | } | ||
265 | 291 | ||
266 | void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) | 292 | void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) |
267 | { | 293 | { |
268 | rocESSID = ESSID; | 294 | rocESSID = ESSID; |
269 | rocFREQ = FREQ; | 295 | rocFREQ = FREQ; |
270 | rocAP = AP; | 296 | rocAP = AP; |
271 | rocMODE = MODE; | 297 | rocMODE = MODE; |
272 | } | 298 | } |
273 | 299 | ||
274 | void WirelessApplet::updateDelayChange( int delay ) | 300 | void WirelessApplet::updateDelayChange( int delay ) |
275 | { | 301 | { |
276 | if ( timer ) | 302 | if ( timer ) |
277 | killTimer( timer ); | 303 | killTimer( timer ); |
278 | delay *= 1000; | 304 | delay *= 1000; |
279 | if ( delay == 0 ) | 305 | if ( delay == 0 ) |
280 | delay = 50; | 306 | delay = 50; |
281 | timer = startTimer( delay ); | 307 | timer = startTimer( delay ); |
282 | } | 308 | } |
283 | 309 | ||
284 | void WirelessApplet::displayStyleChange( int style ) | 310 | void WirelessApplet::displayStyleChange( int style ) |
285 | { | 311 | { |
286 | visualStyle = style; | 312 | visualStyle = style; |
287 | repaint(); | 313 | repaint(); |
288 | } | 314 | } |
289 | 315 | ||
290 | WirelessApplet::~WirelessApplet() | 316 | WirelessApplet::~WirelessApplet() |
291 | { | 317 | { |
292 | } | 318 | } |
293 | 319 | ||
294 | void WirelessApplet::timerEvent( QTimerEvent* ) | 320 | void WirelessApplet::timerEvent( QTimerEvent* ) |
295 | { | 321 | { |
296 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | 322 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; |
297 | 323 | ||
298 | if ( iface ) | 324 | if ( iface ) |
299 | { | 325 | { |
300 | bool statResult = iface->updateStatistics(); | 326 | bool statResult = iface->updateStatistics(); |
301 | if ( !statResult ) | 327 | if ( !statResult ) |
302 | { | 328 | { |
303 | interface = 0; | 329 | interface = 0; |
304 | mustRepaint(); | 330 | mustRepaint(); |
305 | return; | 331 | return; |
306 | } else | 332 | } else |
307 | if ( mustRepaint() ) | 333 | if ( mustRepaint() ) |
308 | { | 334 | { |
309 | //qDebug( "WIFIAPPLET: A value has changed -> repainting." ); | 335 | //qDebug( "WIFIAPPLET: A value has changed -> repainting." ); |
310 | repaint(); | 336 | repaint(); |
311 | } | 337 | } |
312 | 338 | ||
313 | if ( status->isVisible() ) | 339 | if ( status->isVisible() ) |
314 | updatePopupWindow(); | 340 | updatePopupWindow(); |
315 | } else checkInterface(); | 341 | } else checkInterface(); |
316 | } | 342 | } |
317 | 343 | ||
318 | void WirelessApplet::mousePressEvent( QMouseEvent *) | 344 | void WirelessApplet::mousePressEvent( QMouseEvent *) |
319 | { | 345 | { |
320 | if ( status->isVisible() ) | 346 | if ( status->isVisible() ) |
321 | status->hide(); | 347 | status->hide(); |
322 | else | 348 | else |
323 | status->show( true ); | 349 | status->show( true ); |
324 | } | 350 | } |
325 | 351 | ||
326 | bool WirelessApplet::mustRepaint() | 352 | bool WirelessApplet::mustRepaint() |
327 | { | 353 | { |
328 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | 354 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; |
329 | 355 | ||
330 | // check if there are enough changes to justify a (flickering) repaint | 356 | // check if there are enough changes to justify a (flickering) repaint |
331 | 357 | ||
332 | // has the interface changed? | 358 | // has the interface changed? |
333 | 359 | ||
334 | if ( iface != oldiface ) | 360 | if ( iface != oldiface ) |
335 | { | 361 | { |
336 | oldiface = iface; | 362 | oldiface = iface; |
337 | if ( iface ) | 363 | if ( iface ) |
338 | { | 364 | { |
339 | #ifdef MDEBUG | 365 | #ifdef MDEBUG |
340 | qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" ); | 366 | qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" ); |
341 | #endif | 367 | #endif |
342 | show(); | 368 | show(); |
343 | } | 369 | } |
344 | else | 370 | else |
345 | { | 371 | { |
346 | #ifdef MDEBUG | 372 | #ifdef MDEBUG |
347 | qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" ); | 373 | qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" ); |
348 | #endif | 374 | #endif |
349 | hide(); | 375 | hide(); |
350 | return true; | 376 | return true; |
351 | } | 377 | } |
352 | } | 378 | } |
353 | 379 | ||
354 | const char** pixmap = getQualityPixmap(); | 380 | const char** pixmap = getQualityPixmap(); |
355 | 381 | ||
356 | if ( pixmap && ( pixmap != oldpixmap ) ) | 382 | if ( pixmap && ( pixmap != oldpixmap ) ) |
357 | { | 383 | { |
358 | oldpixmap = pixmap; | 384 | oldpixmap = pixmap; |
359 | return true; | 385 | return true; |
360 | } | 386 | } |
361 | 387 | ||
362 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; | 388 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; |
363 | int signalH = iface->signalPercent() * ( height() - 3 ) / 100; | 389 | int signalH = iface->signalPercent() * ( height() - 3 ) / 100; |
364 | int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; | 390 | int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; |
365 | 391 | ||
366 | if ( ( noiseH != oldnoiseH ) | 392 | if ( ( noiseH != oldnoiseH ) |
367 | || ( signalH != oldsignalH ) | 393 | || ( signalH != oldsignalH ) |
368 | || ( qualityH != oldqualityH ) ) | 394 | || ( qualityH != oldqualityH ) ) |
369 | { | 395 | { |
370 | oldnoiseH = noiseH; | 396 | oldnoiseH = noiseH; |
371 | oldsignalH = signalH; | 397 | oldsignalH = signalH; |
372 | oldqualityH = qualityH; | 398 | oldqualityH = qualityH; |
373 | return true; | 399 | return true; |
374 | } | 400 | } |
375 | 401 | ||
376 | if ( rocESSID && ( oldESSID != iface->essid ) ) | 402 | if ( rocESSID && ( oldESSID != iface->essid ) ) |
377 | { | 403 | { |
378 | #ifdef MDEBUG | 404 | #ifdef MDEBUG |
379 | qDebug( "WIFIAPPLET: ESSID has changed."); | 405 | qDebug( "WIFIAPPLET: ESSID has changed."); |
380 | #endif | 406 | #endif |
381 | renewDHCP(); | 407 | renewDHCP(); |
382 | } | 408 | } |
383 | else if ( rocFREQ && ( oldFREQ != iface->freq ) ) | 409 | else if ( rocFREQ && ( oldFREQ != iface->freq ) ) |
384 | { | 410 | { |
385 | #ifdef MDEBUG | 411 | #ifdef MDEBUG |
386 | qDebug( "WIFIAPPLET: FREQ has changed."); | 412 | qDebug( "WIFIAPPLET: FREQ has changed."); |
387 | #endif | 413 | #endif |
388 | renewDHCP(); | 414 | renewDHCP(); |
389 | } | 415 | } |
390 | else if ( rocAP && ( oldAP != iface->APAddr ) ) | 416 | else if ( rocAP && ( oldAP != iface->APAddr ) ) |
391 | { | 417 | { |
392 | #ifdef MDEBUG | 418 | #ifdef MDEBUG |
393 | qDebug( "WIFIAPPLET: AP has changed."); | 419 | qDebug( "WIFIAPPLET: AP has changed."); |
394 | #endif | 420 | #endif |
395 | renewDHCP(); | 421 | renewDHCP(); |
396 | } | 422 | } |
397 | else if ( rocMODE && ( oldMODE != iface->mode ) ) | 423 | else if ( rocMODE && ( oldMODE != iface->mode ) ) |
398 | { | 424 | { |
399 | #ifdef MDEBUG | 425 | #ifdef MDEBUG |
400 | qDebug( "WIFIAPPLET: MODE has changed."); | 426 | qDebug( "WIFIAPPLET: MODE has changed."); |
401 | #endif | 427 | #endif |
402 | renewDHCP(); | 428 | renewDHCP(); |
403 | } | 429 | } |
404 | 430 | ||
405 | oldESSID = iface->essid; | 431 | oldESSID = iface->essid; |
406 | oldMODE = iface->mode; | 432 | oldMODE = iface->mode; |
407 | oldFREQ = iface->freq; | 433 | oldFREQ = iface->freq; |
408 | oldAP = iface->APAddr; | 434 | oldAP = iface->APAddr; |
409 | 435 | ||
410 | return false; | 436 | return false; |
411 | } | 437 | } |
412 | 438 | ||
413 | void WirelessApplet::updatePopupWindow() | 439 | void WirelessApplet::updatePopupWindow() |
414 | { | 440 | { |
415 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | 441 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; |
416 | int qualityH = iface->qualityPercent(); | 442 | int qualityH = iface->qualityPercent(); |
417 | 443 | ||
418 | if ( status->mgraph ) | 444 | if ( status->mgraph ) |
419 | status->mgraph->addValue( qualityH, false ); | 445 | status->mgraph->addValue( qualityH, false ); |
420 | 446 | ||
421 | QString freqString; | 447 | QString freqString; |
422 | QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: "; | 448 | QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: "; |
423 | freqString.sprintf( "%.3f GHz", iface->freq ); | 449 | freqString.sprintf( "%.3f GHz", iface->freq ); |
424 | status->statusLabel->setText( "Station: " + iface->nick + "<br>" + | 450 | status->statusLabel->setText( "Station: " + iface->nick + "<br>" + |
425 | "ESSID: " + iface->essid + "<br>" + | 451 | "ESSID: " + iface->essid + "<br>" + |
426 | "MODE: " + iface->mode + "<br>" + | 452 | "MODE: " + iface->mode + "<br>" + |
427 | "FREQ: " + freqString + "<br>" + | 453 | "FREQ: " + freqString + "<br>" + |
428 | cell + " " + iface->APAddr ); | 454 | cell + " " + iface->APAddr ); |
429 | } | 455 | } |
430 | 456 | ||
431 | const char** WirelessApplet::getQualityPixmap() | 457 | const char** WirelessApplet::getQualityPixmap() |
432 | { | 458 | { |
433 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | 459 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; |
434 | 460 | ||
435 | if ( !iface ) return ( const char** ) nowireless_xpm; | 461 | if ( !iface ) return ( const char** ) nowireless_xpm; |
436 | int qualityH = iface->qualityPercent(); | 462 | int qualityH = iface->qualityPercent(); |
437 | if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; | 463 | if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; |
438 | 464 | ||
439 | if ( visualStyle == STYLE_ANTENNA ) | 465 | if ( visualStyle == STYLE_ANTENNA ) |
440 | { | 466 | { |
441 | if ( qualityH < 1 ) return ( const char** ) connect0_xpm; | 467 | if ( qualityH < 1 ) return ( const char** ) connect0_xpm; |
442 | if ( qualityH < 17 ) return ( const char** ) connect1_xpm; | 468 | if ( qualityH < 17 ) return ( const char** ) connect1_xpm; |
443 | if ( qualityH < 34 ) return ( const char** ) connect2_xpm; | 469 | if ( qualityH < 34 ) return ( const char** ) connect2_xpm; |
444 | if ( qualityH < 50 ) return ( const char** ) connect3_xpm; | 470 | if ( qualityH < 50 ) return ( const char** ) connect3_xpm; |
445 | if ( qualityH < 65 ) return ( const char** ) connect4_xpm; | 471 | if ( qualityH < 65 ) return ( const char** ) connect4_xpm; |
446 | return ( const char** ) connect5_xpm; | 472 | return ( const char** ) connect5_xpm; |
447 | } | 473 | } |
448 | 474 | ||
449 | return 0; // please draw your bars | 475 | return 0; // please draw your bars |
450 | } | 476 | } |
451 | 477 | ||
452 | void WirelessApplet::paintEvent( QPaintEvent* ) | 478 | void WirelessApplet::paintEvent( QPaintEvent* ) |
453 | { | 479 | { |
454 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | 480 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; |
455 | 481 | ||
456 | QPainter p(this); | 482 | QPainter p(this); |
457 | QColor color; | 483 | QColor color; |
458 | 484 | ||
459 | const char** pixmap = getQualityPixmap(); | 485 | const char** pixmap = getQualityPixmap(); |
460 | 486 | ||
461 | if ( pixmap ) | 487 | if ( pixmap ) |
462 | p.drawPixmap( 0, 1, pixmap ); | 488 | p.drawPixmap( 0, 1, pixmap ); |
463 | else | 489 | else |
464 | { | 490 | { |
465 | 491 | ||
466 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; | 492 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; |
467 | int signalH = iface->signalPercent() * ( height() - 3 ) / 100; | 493 | int signalH = iface->signalPercent() * ( height() - 3 ) / 100; |
468 | int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; | 494 | int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; |
469 | 495 | ||
470 | double intensity; | 496 | double intensity; |
471 | int pixelHeight; | 497 | int pixelHeight; |
472 | int pixelWidth = 2; | 498 | int pixelWidth = 2; |
473 | int Hue; | 499 | int Hue; |
474 | int barSpace = 3; | 500 | int barSpace = 3; |
475 | int leftoffset = 0; | 501 | int leftoffset = 0; |
476 | int bottomoffset = 2; | 502 | int bottomoffset = 2; |
477 | 503 | ||
478 | // draw noise indicator | 504 | // draw noise indicator |
479 | pixelHeight = noiseH; | 505 | pixelHeight = noiseH; |
480 | Hue = 50; | 506 | Hue = 50; |
481 | for ( int i = 0; i < pixelHeight; ++i ) | 507 | for ( int i = 0; i < pixelHeight; ++i ) |
482 | { | 508 | { |
483 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; | 509 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; |
484 | color.setHsv( Hue, 255, intensity ); | 510 | color.setHsv( Hue, 255, intensity ); |
485 | p.setPen ( color ); | 511 | p.setPen ( color ); |
486 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); | 512 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); |
487 | } | 513 | } |
488 | 514 | ||
489 | // draw signal indicator | 515 | // draw signal indicator |
490 | pixelHeight = signalH; | 516 | pixelHeight = signalH; |
491 | Hue = 100; | 517 | Hue = 100; |
492 | leftoffset += pixelWidth + barSpace; | 518 | leftoffset += pixelWidth + barSpace; |
493 | for ( int i = 0; i < pixelHeight; ++i ) | 519 | for ( int i = 0; i < pixelHeight; ++i ) |
494 | { | 520 | { |
495 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; | 521 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; |
496 | color.setHsv( Hue, 255, intensity ); | 522 | color.setHsv( Hue, 255, intensity ); |
497 | p.setPen ( color ); | 523 | p.setPen ( color ); |
498 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); | 524 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); |
499 | } | 525 | } |
500 | 526 | ||
501 | // draw quality indicator | 527 | // draw quality indicator |
502 | pixelHeight = qualityH; | 528 | pixelHeight = qualityH; |
503 | Hue = 250; | 529 | Hue = 250; |
504 | leftoffset += pixelWidth + barSpace; | 530 | leftoffset += pixelWidth + barSpace; |
505 | for ( int i = 0; i < pixelHeight; ++i ) | 531 | for ( int i = 0; i < pixelHeight; ++i ) |
506 | { | 532 | { |
507 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; | 533 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; |
508 | color.setHsv( Hue, 255, intensity ); | 534 | color.setHsv( Hue, 255, intensity ); |
509 | p.setPen ( color ); | 535 | p.setPen ( color ); |
510 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); | 536 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); |
511 | } | 537 | } |
512 | } | 538 | } |
513 | } | 539 | } |