summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2002-10-12 15:37:56 (UTC)
committer mickeyl <mickeyl>2002-10-12 15:37:56 (UTC)
commit83aed438ec060307bf5562d91bd8b61fe60f860b (patch) (unidiff)
treeb5156e2be374491e0dbf587b48272c1ae121660d
parentfe2f3c3b72dfcffe0b6ab02cea37f6dcb300b218 (diff)
downloadopie-83aed438ec060307bf5562d91bd8b61fe60f860b.zip
opie-83aed438ec060307bf5562d91bd8b61fe60f860b.tar.gz
opie-83aed438ec060307bf5562d91bd8b61fe60f860b.tar.bz2
- dhcp renew now really functions
- added dhcp renew support for udhcp
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp62
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
@@ -31,116 +31,116 @@
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
58WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) 58WirelessControl::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
146void WirelessControl::advancedConfigClicked() 146void WirelessControl::advancedConfigClicked()
@@ -212,77 +212,103 @@ WirelessApplet::WirelessApplet( QWidget *parent, const char *name )
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
221void WirelessApplet::checkInterface() 221void 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
239void WirelessApplet::renewDHCP() 239void 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
266void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) 292void 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
274void WirelessApplet::updateDelayChange( int delay ) 300void 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
284void WirelessApplet::displayStyleChange( int style ) 310void WirelessApplet::displayStyleChange( int style )
285{ 311{
286 visualStyle = style; 312 visualStyle = style;
287 repaint(); 313 repaint();
288} 314}