summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp2
-rw-r--r--core/applets/irdaapplet/irda.cpp6
2 files changed, 4 insertions, 4 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index 3f07b41..48146ab 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -104,277 +104,277 @@ void CardMonitor::popUp( QString message, QString icon ) {
104 104
105void CardMonitor::popupTimeout() { 105void CardMonitor::popupTimeout() {
106 popupMenu->hide(); 106 popupMenu->hide();
107} 107}
108 108
109void CardMonitor::mousePressEvent( QMouseEvent * ) { 109void CardMonitor::mousePressEvent( QMouseEvent * ) {
110 QPopupMenu * menu = new QPopupMenu( this ); 110 QPopupMenu * menu = new QPopupMenu( this );
111 QString cmd; 111 QString cmd;
112 112
113 if ( cardInSd ) { 113 if ( cardInSd ) {
114 menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), 114 menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ),
115 tr( "Eject SD/MMC card" ), 0 ); 115 tr( "Eject SD/MMC card" ), 0 );
116 } 116 }
117 117
118 if ( cardInPcmcia0 ) { 118 if ( cardInPcmcia0 ) {
119 menu-> 119 menu->
120 insertItem( QIconSet 120 insertItem( QIconSet
121 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), 121 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ),
122 tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); 122 tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 );
123 } 123 }
124 124
125 if ( cardInPcmcia1 ) { 125 if ( cardInPcmcia1 ) {
126 menu-> 126 menu->
127 insertItem( QIconSet 127 insertItem( QIconSet
128 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), 128 ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ),
129 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); 129 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 );
130 } 130 }
131 131
132 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 132 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
133 QSize s = menu->sizeHint(); 133 QSize s = menu->sizeHint();
134 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 134 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
135 p.y() - s.height() ), 0 ); 135 p.y() - s.height() ), 0 );
136 136
137 if ( opt == 1 ) { 137 if ( opt == 1 ) {
138 m_commandOrig = 1; 138 m_commandOrig = 1;
139 execCommand("/sbin/cardctl eject 0"); 139 execCommand("/sbin/cardctl eject 0");
140 } else if ( opt == 0 ) { 140 } else if ( opt == 0 ) {
141 if ( ODevice::inst() ->system() == System_Familiar ) { 141 if ( ODevice::inst() ->system() == System_Familiar ) {
142 cmd = "umount /dev/mmc/part1"; 142 cmd = "umount /dev/mmc/part1";
143 } else { 143 } else {
144 cmd = "umount /dev/mmcda1"; 144 cmd = "umount /dev/mmcda1";
145 } 145 }
146 m_commandOrig = 2; 146 m_commandOrig = 2;
147 execCommand( cmd ); 147 execCommand( cmd );
148 } else if ( opt == 2 ) { 148 } else if ( opt == 2 ) {
149 m_commandOrig = 3; 149 m_commandOrig = 3;
150 execCommand( "/sbin/cardctl eject 1" ); 150 execCommand( "/sbin/cardctl eject 1" );
151 } 151 }
152 delete menu; 152 delete menu;
153} 153}
154 154
155 155
156void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) { 156void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) {
157 if ( msg == "stabChanged()" ) { 157 if ( msg == "stabChanged()" ) {
158 // odebug << "Pcmcia: stabchanged" << oendl; 158 // odebug << "Pcmcia: stabchanged" << oendl;
159 getStatusPcmcia(); 159 getStatusPcmcia();
160 } else if ( msg == "mtabChanged()" ) { 160 } else if ( msg == "mtabChanged()" ) {
161 // odebug << "CARDMONAPPLET: mtabchanged" << oendl; 161 // odebug << "CARDMONAPPLET: mtabchanged" << oendl;
162 getStatusSd(); 162 getStatusSd();
163 } 163 }
164} 164}
165 165
166bool CardMonitor::getStatusPcmcia( int showPopUp ) { 166bool CardMonitor::getStatusPcmcia( int showPopUp ) {
167 167
168 bool cardWas0 = cardInPcmcia0; // remember last state 168 bool cardWas0 = cardInPcmcia0; // remember last state
169 bool cardWas1 = cardInPcmcia1; 169 bool cardWas1 = cardInPcmcia1;
170 170
171 QString fileName; 171 QString fileName;
172 172
173 // one of these 3 files should exist 173 // one of these 3 files should exist
174 if ( QFile::exists( "/var/run/stab" ) ) { 174 if ( QFile::exists( "/var/run/stab" ) ) {
175 fileName = "/var/run/stab"; 175 fileName = "/var/run/stab";
176 } else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { 176 } else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) {
177 fileName = "/var/state/pcmcia/stab"; 177 fileName = "/var/state/pcmcia/stab";
178 } else { 178 } else {
179 fileName = "/var/lib/pcmcia/stab"; 179 fileName = "/var/lib/pcmcia/stab";
180 } 180 }
181 181
182 QFile f( fileName ); 182 QFile f( fileName );
183 183
184 if ( f.open( IO_ReadOnly ) ) { 184 if ( f.open( IO_ReadOnly ) ) {
185 QStringList list; 185 QStringList list;
186 QTextStream stream( &f ); 186 QTextStream stream( &f );
187 QString streamIn; 187 QString streamIn;
188 streamIn = stream.read(); 188 streamIn = stream.read();
189 list = QStringList::split( "\n", streamIn ); 189 list = QStringList::split( "\n", streamIn );
190 for ( QStringList::Iterator line = list.begin(); line != list.end(); 190 for ( QStringList::Iterator line = list.begin(); line != list.end();
191 line++ ) { 191 line++ ) {
192 if ( ( *line ).startsWith( "Socket 0:" ) ) { 192 if ( ( *line ).startsWith( "Socket 0:" ) ) {
193 if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) { 193 if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) {
194 cardInPcmcia0 = FALSE; 194 cardInPcmcia0 = FALSE;
195 } else if ( !( *line ).startsWith( "Socket 0: empty" ) 195 } else if ( !( *line ).startsWith( "Socket 0: empty" )
196 && !cardInPcmcia0 ) { 196 && !cardInPcmcia0 ) {
197 cardInPcmcia0Name = 197 cardInPcmcia0Name =
198 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), 198 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ),
199 ( *line ).length() - 9 ); 199 ( *line ).length() - 9 );
200 cardInPcmcia0Name.stripWhiteSpace(); 200 cardInPcmcia0Name.stripWhiteSpace();
201 cardInPcmcia0 = TRUE; 201 cardInPcmcia0 = TRUE;
202 show(); 202 show();
203 line++; 203 line++;
204 int pos = ( *line ).find( '\t' ) + 1; 204 int pos = ( *line ).find( '\t' ) + 1;
205 cardInPcmcia0Type = 205 cardInPcmcia0Type =
206 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); 206 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos );
207 } 207 }
208 } else if ( ( *line ).startsWith( "Socket 1:" ) ) { 208 } else if ( ( *line ).startsWith( "Socket 1:" ) ) {
209 if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) { 209 if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) {
210 cardInPcmcia1 = FALSE; 210 cardInPcmcia1 = FALSE;
211 } else if ( !( *line ).startsWith( "Socket 1: empty" ) 211 } else if ( !( *line ).startsWith( "Socket 1: empty" )
212 && !cardInPcmcia1 ) { 212 && !cardInPcmcia1 ) {
213 cardInPcmcia1Name = 213 cardInPcmcia1Name =
214 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), 214 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ),
215 ( *line ).length() - 9 ); 215 ( *line ).length() - 9 );
216 cardInPcmcia1Name.stripWhiteSpace(); 216 cardInPcmcia1Name.stripWhiteSpace();
217 cardInPcmcia1 = TRUE; 217 cardInPcmcia1 = TRUE;
218 show(); 218 show();
219 line++; 219 line++;
220 int pos = ( *line ).find( '\t' ) + 1; 220 int pos = ( *line ).find( '\t' ) + 1;
221 cardInPcmcia1Type = 221 cardInPcmcia1Type =
222 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); 222 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos );
223 } 223 }
224 } 224 }
225 } 225 }
226 f.close(); 226 f.close();
227 227
228 if ( !showPopUp 228 if ( !showPopUp
229 && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) { 229 && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) {
230 QString text = QString::null; 230 QString text = QString::null;
231 QString what = QString::null; 231 QString what = QString::null;
232 if ( cardWas0 != cardInPcmcia0 ) { 232 if ( cardWas0 != cardInPcmcia0 ) {
233 if ( cardInPcmcia0 ) { 233 if ( cardInPcmcia0 ) {
234 text += tr( "New card: " ); 234 text += tr( "New card: " );
235 what = "on"; 235 what = "on";
236 } else { 236 } else {
237 text += tr( "Ejected: " ); 237 text += tr( "Ejected: " );
238 what = "off"; 238 what = "off";
239 } 239 }
240 text += cardInPcmcia0Name; 240 text += cardInPcmcia0Name;
241 popUp( text, "cardmon/" + cardInPcmcia0Type ); 241 popUp( text, "cardmon/" + cardInPcmcia0Type );
242 } 242 }
243 243
244 if ( cardWas1 != cardInPcmcia1 ) { 244 if ( cardWas1 != cardInPcmcia1 ) {
245 if ( cardInPcmcia1 ) { 245 if ( cardInPcmcia1 ) {
246 text += tr( "New card: " ); 246 text += tr( "New card: " );
247 what = "on"; 247 what = "on";
248 } else { 248 } else {
249 text += tr( "Ejected: " ); 249 text += tr( "Ejected: " );
250 what = "off"; 250 what = "off";
251 } 251 }
252 text += cardInPcmcia1Name; 252 text += cardInPcmcia1Name;
253 popUp( text, "cardmon/" + cardInPcmcia1Type ); 253 popUp( text, "cardmon/" + cardInPcmcia1Type );
254 } 254 }
255 #ifndef QT_NO_SOUND 255 #ifndef QT_NO_SOUND
256 QSound::play( Resource::findSound( "cardmon/card" + what ) ); 256 QSound::play( Resource::findSound( "cardmon/card" + what ) );
257 #endif 257 #endif
258 258
259 } 259 }
260 } else { 260 } else {
261 // no file found 261 // no file found
262 odebug << "no file found" << oendl; 262 odebug << "no file found" << oendl;
263 cardInPcmcia0 = FALSE; 263 cardInPcmcia0 = FALSE;
264 cardInPcmcia1 = FALSE; 264 cardInPcmcia1 = FALSE;
265 } 265 }
266 repaint( FALSE ); 266 repaint( FALSE );
267 return ( ( cardWas0 == cardInPcmcia0 267 return ( ( cardWas0 == cardInPcmcia0
268 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); 268 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE );
269 269
270} 270}
271 271
272 272
273bool CardMonitor::getStatusSd( int showPopUp ) { 273bool CardMonitor::getStatusSd( int showPopUp ) {
274 274
275 bool cardWas = cardInSd; // remember last state 275 bool cardWas = cardInSd; // remember last state
276 cardInSd = FALSE; 276 cardInSd = FALSE;
277 277
278 #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 278 #if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
279 279
280 struct mntent *me; 280 struct mntent *me;
281 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 281 FILE *mntfp = setmntent( "/etc/mtab", "r" );
282 282
283 if ( mntfp ) { 283 if ( mntfp ) {
284 while ( ( me = getmntent( mntfp ) ) != 0 ) { 284 while ( ( me = getmntent( mntfp ) ) != 0 ) {
285 QString fs = me->mnt_fsname; 285 QString fs = me->mnt_fsname;
286 //odebug << fs << oendl; 286 //odebug << fs << oendl;
287 if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" 287 if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd"
288 || fs.left( 9 ) == "/dev/mmcd" ) { 288 || fs.left( 9 ) == "/dev/mmcd" ) {
289 cardInSd = TRUE; 289 cardInSd = TRUE;
290 show(); 290 show();
291 } 291 }
292 // else { 292 // else {
293 // cardInSd = FALSE; 293 // cardInSd = FALSE;
294 // } 294 // }
295 } 295 }
296 endmntent( mntfp ); 296 endmntent( mntfp );
297 } 297 }
298 298
299 if ( !showPopUp && cardWas != cardInSd ) { 299 if ( !showPopUp && cardWas != cardInSd ) {
300 QString text = QString::null; 300 QString text = QString::null;
301 QString what = QString::null; 301 QString what = QString::null;
302 if ( cardInSd ) { 302 if ( cardInSd ) {
303 text += "New card: SD/MMC"; 303 text += "New card: SD/MMC";
304 what = "on"; 304 what = "on";
305 } else { 305 } else {
306 text += "Ejected: SD/MMC"; 306 text += "Ejected: SD/MMC";
307 what = "off"; 307 what = "off";
308 } 308 }
309 //odebug << "TEXT: " + text << oendl; 309 //odebug << "TEXT: " + text << oendl;
310 #ifndef QT_NO_SOUND 310 #ifndef QT_NO_SOUND
311 QSound::play( Resource::findSound( "cardmon/card" + what ) ); 311 QSound::play( Resource::findSound( "cardmon/card" + what ) );
312 #endif 312 #endif
313 313
314 popUp( text, "cardmon/ide" ); // XX add SD pic 314 popUp( text, "cardmon/ide" ); // XX add SD pic
315 } 315 }
316 #else 316 #else
317 #error "Not on Linux" 317 #error "Not on Linux"
318 #endif 318 #endif
319 repaint( FALSE ); 319 repaint( FALSE );
320 return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); 320 return ( ( cardWas == cardInSd ) ? FALSE : TRUE );
321} 321}
322 322
323void CardMonitor::paintEvent( QPaintEvent * ) { 323void CardMonitor::paintEvent( QPaintEvent * ) {
324 324
325 QPainter p( this ); 325 QPainter p( this );
326 326
327 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { 327 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) {
328 p.drawPixmap( 0, 0, pm ); 328 p.drawPixmap( 0, 0, pm );
329 show(); 329 show();
330 } else { 330 } else {
331 //p.eraseRect(rect()); 331 //p.eraseRect(rect());
332 hide(); 332 hide();
333 } 333 }
334} 334}
335 335
336int CardMonitor::position() { 336int CardMonitor::position() {
337 return 7; 337 return 7;
338} 338}
339 339
340void CardMonitor::execCommand( const QString &command ) { 340void CardMonitor::execCommand( const QString &command ) {
341 341
342 if ( m_process == 0 ) { 342 if ( m_process == 0 ) {
343 m_process = new OProcess(); 343 m_process = new OProcess();
344 QStringList strList = QStringList::split( " ", command ); 344 QStringList strList = QStringList::split( " ", command );
345 345
346 for ( QStringList::Iterator it = strList.begin(); it != strList.end(); ++it ) { 346 for ( QStringList::Iterator it = strList.begin(); it != strList.end(); ++it ) {
347 *m_process << *it; 347 *m_process << *it;
348 } 348 }
349 349
350 connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), 350 connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ),
351 this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); 351 this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
352 352
353 if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ) { 353 if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ) {
354 delete m_process; 354 delete m_process;
355 m_process = 0; 355 m_process = 0;
356 } 356 }
357 } 357 }
358} 358}
359 359
360void CardMonitor::slotExited( OProcess* proc ) { 360void CardMonitor::slotExited( OProcess* ) {
361 361
362 if( m_process->normalExit() ) { 362 if( m_process->normalExit() ) {
363 int ret = m_process->exitStatus(); 363 int ret = m_process->exitStatus();
364 if( ret != 0 ) { 364 if( ret != 0 ) {
365 if ( m_commandOrig == 1 ) { 365 if ( m_commandOrig == 1 ) {
366 popUp( tr( "CF/PCMCIA card eject failed!" ) ); 366 popUp( tr( "CF/PCMCIA card eject failed!" ) );
367 } else if ( m_commandOrig == 2 ) { 367 } else if ( m_commandOrig == 2 ) {
368 popUp( tr( "SD/MMC card eject failed!" ) ); 368 popUp( tr( "SD/MMC card eject failed!" ) );
369 } else if ( m_commandOrig == 3 ) { 369 } else if ( m_commandOrig == 3 ) {
370 popUp( tr( "CF/PCMCIA card eject failed!" ) ); 370 popUp( tr( "CF/PCMCIA card eject failed!" ) );
371 } 371 }
372 } 372 }
373 } 373 }
374 374
375 delete m_process; 375 delete m_process;
376 m_process = 0; 376 m_process = 0;
377} 377}
378 378
379EXPORT_OPIE_APPLET_v1( CardMonitor ) 379EXPORT_OPIE_APPLET_v1( CardMonitor )
380 380
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp
index 7122b40..267714e 100644
--- a/core/applets/irdaapplet/irda.cpp
+++ b/core/applets/irdaapplet/irda.cpp
@@ -1,363 +1,363 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org> 2** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org>
3** Max Reiss <harlekin@handhelds.org> [trivial stuff] 3** Max Reiss <harlekin@handhelds.org> [trivial stuff]
4** Robert Griebl <sandman@handhelds.org> 4** Robert Griebl <sandman@handhelds.org>
5** Holger Freyther <zecke@handhelds.org> QCOP Interface 5** Holger Freyther <zecke@handhelds.org> QCOP Interface
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15**********************************************************************/ 15**********************************************************************/
16 16
17#include "irda.h" 17#include "irda.h"
18 18
19/* OPIE */ 19/* OPIE */
20#include <opie2/otaskbarapplet.h> 20#include <opie2/otaskbarapplet.h>
21#include <qpe/resource.h> 21#include <qpe/resource.h>
22#include <qpe/qcopenvelope_qws.h> 22#include <qpe/qcopenvelope_qws.h>
23 23
24/* QT */ 24/* QT */
25#include <qpainter.h> 25#include <qpainter.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29 29
30/* STD */ 30/* STD */
31#include <unistd.h> 31#include <unistd.h>
32#include <net/if.h> 32#include <net/if.h>
33#include <netinet/in.h> 33#include <netinet/in.h>
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/socket.h> 35#include <sys/socket.h>
36#include <sys/ioctl.h> 36#include <sys/ioctl.h>
37 37
38//=========================================================================== 38//===========================================================================
39 39
40using namespace Opie::Ui; 40using namespace Opie::Ui;
41IrdaApplet::IrdaApplet ( QWidget *parent, const char *name ) 41IrdaApplet::IrdaApplet ( QWidget *parent, const char *name )
42 : QWidget ( parent, name ) 42 : QWidget ( parent, name )
43{ 43{
44 setFixedHeight ( 18 ); 44 setFixedHeight ( 18 );
45 setFixedWidth ( 14 ); 45 setFixedWidth ( 14 );
46 46
47 m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP ); 47 m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP );
48 48
49 m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); 49 m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" );
50 m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); 50 m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" );
51 m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); 51 m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" );
52 m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" ); 52 m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" );
53 53
54 m_irda_active = false; 54 m_irda_active = false;
55 m_irda_discovery_active = false; 55 m_irda_discovery_active = false;
56 m_receive_active = false; 56 m_receive_active = false;
57 m_receive_state_changed = false; 57 m_receive_state_changed = false;
58 m_popup = 0; 58 m_popup = 0;
59 m_wasOn = false; 59 m_wasOn = false;
60 m_wasDiscover = false; 60 m_wasDiscover = false;
61 61
62 QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this ); 62 QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this );
63 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 63 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
64 this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); 64 this, SLOT(slotMessage(const QCString&,const QByteArray&) ) );
65} 65}
66 66
67int IrdaApplet::position() 67int IrdaApplet::position()
68{ 68{
69 return 6; 69 return 6;
70} 70}
71 71
72void IrdaApplet::show() 72void IrdaApplet::show()
73{ 73{
74 QWidget::show ( ); 74 QWidget::show ( );
75 startTimer ( 2000 ); 75 startTimer ( 2000 );
76} 76}
77 77
78IrdaApplet::~IrdaApplet() 78IrdaApplet::~IrdaApplet()
79{ 79{
80 if ( m_sockfd >= 0 ) 80 if ( m_sockfd >= 0 )
81 ::close ( m_sockfd ); 81 ::close ( m_sockfd );
82} 82}
83 83
84void IrdaApplet::popup ( QString message, QString icon ) 84void IrdaApplet::popup ( QString message, QString icon )
85{ 85{
86 if ( !m_popup ) 86 if ( !m_popup )
87 m_popup = new QPopupMenu ( this ); 87 m_popup = new QPopupMenu ( this );
88 88
89 m_popup-> clear ( ); 89 m_popup-> clear ( );
90 90
91 if ( icon. isEmpty ( )) 91 if ( icon. isEmpty ( ))
92 m_popup-> insertItem ( message, 0 ); 92 m_popup-> insertItem ( message, 0 );
93 else 93 else
94 m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 ); 94 m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 );
95 95
96 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 96 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
97 QSize s = m_popup-> sizeHint ( ); 97 QSize s = m_popup-> sizeHint ( );
98 m_popup-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 98 m_popup-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
99 p. y ( ) - s. height ( ))); 99 p. y ( ) - s. height ( )));
100 100
101 QTimer::singleShot ( 2000, this, SLOT( popupTimeout())); 101 QTimer::singleShot ( 2000, this, SLOT( popupTimeout()));
102} 102}
103 103
104void IrdaApplet::popupTimeout ( ) 104void IrdaApplet::popupTimeout ( )
105{ 105{
106 m_popup-> hide ( ); 106 m_popup-> hide ( );
107} 107}
108 108
109bool IrdaApplet::checkIrdaStatus ( ) 109bool IrdaApplet::checkIrdaStatus ( )
110{ 110{
111 struct ifreq ifr; 111 struct ifreq ifr;
112 strcpy ( ifr. ifr_name, "irda0" ); 112 strcpy ( ifr. ifr_name, "irda0" );
113 113
114 if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) 114 if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 )
115 return false; 115 return false;
116 116
117 return ( ifr. ifr_flags & IFF_UP ); 117 return ( ifr. ifr_flags & IFF_UP );
118} 118}
119 119
120bool IrdaApplet::setIrdaStatus ( bool b ) 120bool IrdaApplet::setIrdaStatus ( bool b )
121{ 121{
122 struct ifreq ifr; 122 struct ifreq ifr;
123 strcpy ( ifr. ifr_name, "irda0" ); 123 strcpy ( ifr. ifr_name, "irda0" );
124 124
125 if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) 125 if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 )
126 return false; 126 return false;
127 127
128 if ( b ) { 128 if ( b ) {
129 ifr. ifr_flags |= IFF_UP; 129 ifr. ifr_flags |= IFF_UP;
130 } 130 }
131 else { 131 else {
132 setIrdaDiscoveryStatus ( 0 ); 132 setIrdaDiscoveryStatus ( 0 );
133 setIrdaReceiveStatus ( 0 ); 133 setIrdaReceiveStatus ( 0 );
134 ifr. ifr_flags &= ~IFF_UP; 134 ifr. ifr_flags &= ~IFF_UP;
135 } 135 }
136 136
137 if ( ::ioctl ( m_sockfd, SIOCSIFFLAGS, &ifr ) < 0 ) 137 if ( ::ioctl ( m_sockfd, SIOCSIFFLAGS, &ifr ) < 0 )
138 return false; 138 return false;
139 139
140 return true; 140 return true;
141} 141}
142 142
143bool IrdaApplet::checkIrdaDiscoveryStatus ( ) 143bool IrdaApplet::checkIrdaDiscoveryStatus ( )
144{ 144{
145 QFile discovery ( "/proc/sys/net/irda/discovery" ); 145 QFile discovery ( "/proc/sys/net/irda/discovery" );
146 146
147 QString streamIn = "0"; 147 QString streamIn = "0";
148 148
149 if ( discovery. open ( IO_ReadOnly )) { 149 if ( discovery. open ( IO_ReadOnly )) {
150 QTextStream stream ( &discovery ); 150 QTextStream stream ( &discovery );
151 streamIn = stream. read ( ); 151 streamIn = stream. read ( );
152 } 152 }
153 153
154 return streamIn. toInt ( ) > 0; 154 return streamIn. toInt ( ) > 0;
155} 155}
156 156
157 157
158bool IrdaApplet::setIrdaDiscoveryStatus ( bool d ) 158bool IrdaApplet::setIrdaDiscoveryStatus ( bool d )
159{ 159{
160 QFile discovery ( "/proc/sys/net/irda/discovery" ); 160 QFile discovery ( "/proc/sys/net/irda/discovery" );
161 161
162 if ( discovery. open ( IO_WriteOnly | IO_Raw )) { 162 if ( discovery. open ( IO_WriteOnly | IO_Raw )) {
163 discovery.putch ( d ? '1' : '0' ); 163 discovery.putch ( d ? '1' : '0' );
164 return true; 164 return true;
165 } 165 }
166 return false; 166 return false;
167} 167}
168 168
169 169
170bool IrdaApplet::setIrdaReceiveStatus ( bool d ) 170bool IrdaApplet::setIrdaReceiveStatus ( bool d )
171{ 171{
172 QCopEnvelope e ( "QPE/Obex", "receive(int)" ); 172 QCopEnvelope e ( "QPE/Obex", "receive(int)" );
173 e << ( d ? 1 : 0 ); 173 e << ( d ? 1 : 0 );
174 174
175 m_receive_active = d; 175 m_receive_active = d;
176 m_receive_state_changed = true; 176 m_receive_state_changed = true;
177 177
178 return true; 178 return true;
179} 179}
180 180
181 181
182void IrdaApplet::showDiscovered ( ) 182void IrdaApplet::showDiscovered ( )
183{ 183{
184 //static Sound snd_found ( "irdaapplet/irdaon" ); 184 //static Sound snd_found ( "irdaapplet/irdaon" );
185 //static Sound snd_lost ( "irdaapplet/irdaoff" ); 185 //static Sound snd_lost ( "irdaapplet/irdaoff" );
186 186
187 QFile discovery ( "/proc/net/irda/discovery" ); 187 QFile discovery ( "/proc/net/irda/discovery" );
188 188
189 if ( discovery. open ( IO_ReadOnly )) { 189 if ( discovery. open ( IO_ReadOnly )) {
190 bool qcopsend = false; 190 bool qcopsend = false;
191 191
192 QString discoveredDevice; 192 QString discoveredDevice;
193 QString deviceAddr; 193 QString deviceAddr;
194 194
195 // since it is /proc we _must_ use QTextStream 195 // since it is /proc we _must_ use QTextStream
196 QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( )); 196 QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( ));
197 197
198 QMap <QString, QString>::Iterator it; 198 QMap <QString, QString>::Iterator it;
199 199
200 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) 200 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ++it )
201 it. data ( ). prepend ( "+++" ); 201 it. data ( ). prepend ( "+++" );
202 202
203 for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) { 203 for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) {
204 const QString &line = *lit; 204 const QString &line = *lit;
205 205
206 if ( line. startsWith ( "nickname:" )) { 206 if ( line. startsWith ( "nickname:" )) {
207 discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 ); 207 discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 );
208 deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 ); 208 deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 );
209 209
210 // odebug << discoveredDevice + "(" + deviceAddr + ")" << oendl; 210 // odebug << discoveredDevice + "(" + deviceAddr + ")" << oendl;
211 211
212 if ( !m_devices. contains ( deviceAddr )) { 212 if ( !m_devices. contains ( deviceAddr )) {
213 popup ( tr( "Found:" ) + " " + discoveredDevice ); 213 popup ( tr( "Found:" ) + " " + discoveredDevice );
214 //snd_found. play ( ); 214 //snd_found. play ( );
215 qcopsend = true; 215 qcopsend = true;
216 } 216 }
217 m_devices. replace ( deviceAddr, discoveredDevice ); 217 m_devices. replace ( deviceAddr, discoveredDevice );
218 } 218 }
219 } 219 }
220 220
221 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) { 221 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) {
222 // odebug << "IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?" << oendl; 222 // odebug << "IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?" << oendl;
223 223
224 if ( it. data ( ). left ( 3 ) == "+++" ) { 224 if ( it. data ( ). left ( 3 ) == "+++" ) {
225 popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 )); 225 popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 ));
226 //snd_lost. play ( ); 226 //snd_lost. play ( );
227 227
228 QMap <QString, QString>::Iterator tmp = it; 228 QMap <QString, QString>::Iterator tmp = it;
229 tmp++; 229 tmp++;
230 m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator 230 m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator
231 it = tmp; 231 it = tmp;
232 232
233 qcopsend = true; 233 qcopsend = true;
234 } 234 }
235 else 235 else
236 it++; 236 it++;
237 } 237 }
238 // XXX if( qcopsend ) { 238 // XXX if( qcopsend ) {
239 QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" ); 239 QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" );
240 e << ( m_devices. count ( ) > 0 ); 240 e << ( m_devices. count ( ) > 0 );
241 // } 241 // }
242 } 242 }
243} 243}
244 244
245void IrdaApplet::mousePressEvent ( QMouseEvent * ) 245void IrdaApplet::mousePressEvent ( QMouseEvent * )
246{ 246{
247 QPopupMenu *menu = new QPopupMenu ( this ); 247 QPopupMenu *menu = new QPopupMenu ( this );
248 QString cmd; 248 QString cmd;
249 249
250 /* Refresh active state */ 250 /* Refresh active state */
251 timerEvent ( 0 ); 251 timerEvent ( 0 );
252 252
253 //menu->insertItem( tr("More..."), 4 ); 253 //menu->insertItem( tr("More..."), 4 );
254 254
255 if ( m_irda_active && !m_devices. isEmpty ( )) { 255 if ( m_irda_active && !m_devices. isEmpty ( )) {
256 menu-> insertItem ( tr( "Discovered Device:" ), 9 ); 256 menu-> insertItem ( tr( "Discovered Device:" ), 9 );
257 257
258 for ( QMap<QString, QString>::Iterator it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) 258 for ( QMap<QString, QString>::Iterator it = m_devices. begin ( ); it != m_devices. end ( ); ++it )
259 menu-> insertItem ( *it ); 259 menu-> insertItem ( *it );
260 260
261 menu-> insertSeparator ( ); 261 menu-> insertSeparator ( );
262 } 262 }
263 263
264 menu-> insertItem ( m_irda_active ? tr( "Disable IrDA" ) : tr( "Enable IrDA" ), 0 ); 264 menu-> insertItem ( m_irda_active ? tr( "Disable IrDA" ) : tr( "Enable IrDA" ), 0 );
265 265
266 if ( m_irda_active ) { 266 if ( m_irda_active ) {
267 menu-> insertItem ( m_irda_discovery_active ? tr( "Disable Discovery" ) : tr( "Enable Discovery" ), 1 ); 267 menu-> insertItem ( m_irda_discovery_active ? tr( "Disable Discovery" ) : tr( "Enable Discovery" ), 1 );
268 menu-> insertItem ( m_receive_active ? tr( "Disable Receive" ) : tr( "Enable Receive" ), 2 ); 268 menu-> insertItem ( m_receive_active ? tr( "Disable Receive" ) : tr( "Enable Receive" ), 2 );
269 } 269 }
270 270
271 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); 271 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) );
272 QSize s = menu-> sizeHint ( ); 272 QSize s = menu-> sizeHint ( );
273 273
274 p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( )); 274 p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ));
275 275
276 switch ( menu-> exec ( p )) { 276 switch ( menu-> exec ( p )) {
277 case 0: 277 case 0:
278 setIrdaStatus ( !m_irda_active ); 278 setIrdaStatus ( !m_irda_active );
279 timerEvent ( 0 ); 279 timerEvent ( 0 );
280 break; 280 break;
281 case 1: 281 case 1:
282 setIrdaDiscoveryStatus ( !m_irda_discovery_active ); 282 setIrdaDiscoveryStatus ( !m_irda_discovery_active );
283 timerEvent ( 0 ); 283 timerEvent ( 0 );
284 break; 284 break;
285 case 2: 285 case 2:
286 setIrdaReceiveStatus ( !m_receive_active ); 286 setIrdaReceiveStatus ( !m_receive_active );
287 timerEvent( 0 ); 287 timerEvent( 0 );
288 break; 288 break;
289 } 289 }
290 290
291 delete menu; 291 delete menu;
292} 292}
293 293
294void IrdaApplet::timerEvent ( QTimerEvent * ) 294void IrdaApplet::timerEvent ( QTimerEvent * )
295{ 295{
296 bool oldactive = m_irda_active; 296 bool oldactive = m_irda_active;
297 bool olddiscovery = m_irda_discovery_active; 297 bool olddiscovery = m_irda_discovery_active;
298 bool receiveUpdate = false; 298 bool receiveUpdate = false;
299 299
300 if ( m_receive_state_changed ) { 300 if ( m_receive_state_changed ) {
301 receiveUpdate = true; 301 receiveUpdate = true;
302 m_receive_state_changed = false; 302 m_receive_state_changed = false;
303 } 303 }
304 304
305 m_irda_active = checkIrdaStatus ( ); 305 m_irda_active = checkIrdaStatus ( );
306 m_irda_discovery_active = checkIrdaDiscoveryStatus ( ); 306 m_irda_discovery_active = checkIrdaDiscoveryStatus ( );
307 307
308 if ( m_irda_discovery_active ) 308 if ( m_irda_discovery_active )
309 showDiscovered ( ); 309 showDiscovered ( );
310 310
311 if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate ) 311 if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate )
312 update ( ); 312 update ( );
313} 313}
314 314
315void IrdaApplet::paintEvent ( QPaintEvent * ) 315void IrdaApplet::paintEvent ( QPaintEvent * )
316{ 316{
317 QPainter p ( this ); 317 QPainter p ( this );
318 318
319 p. drawPixmap ( 0, 1, m_irda_active ? m_irdaOnPixmap : m_irdaOffPixmap ); 319 p. drawPixmap ( 0, 1, m_irda_active ? m_irdaOnPixmap : m_irdaOffPixmap );
320 320
321 if ( m_irda_discovery_active ) 321 if ( m_irda_discovery_active )
322 p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap ); 322 p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap );
323 323
324 if ( m_receive_active ) 324 if ( m_receive_active )
325 p. drawPixmap( 0, 1, m_receiveActivePixmap ); 325 p. drawPixmap( 0, 1, m_receiveActivePixmap );
326} 326}
327/* 327/*
328 * We know 3 calls 328 * We know 3 calls
329 * a) enable 329 * a) enable
330 * b) disable 330 * b) disable
331 * a and b will temp enable the IrDa device and disable will disable it again if it wasn't on 331 * a and b will temp enable the IrDa device and disable will disable it again if it wasn't on
332 * c) listDevices: We will return a list of known devices 332 * c) listDevices: We will return a list of known devices
333 */ 333 */
334void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ar ) { 334void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ) {
335 if ( str == "enableIrda()") { 335 if ( str == "enableIrda()") {
336 m_wasOn = checkIrdaStatus(); 336 m_wasOn = checkIrdaStatus();
337 m_wasDiscover = checkIrdaDiscoveryStatus(); 337 m_wasDiscover = checkIrdaDiscoveryStatus();
338 if (!m_wasOn) { 338 if (!m_wasOn) {
339 setIrdaStatus( true ); 339 setIrdaStatus( true );
340 } 340 }
341 if ( !m_wasDiscover ) { 341 if ( !m_wasDiscover ) {
342 setIrdaDiscoveryStatus ( true ); 342 setIrdaDiscoveryStatus ( true );
343 } 343 }
344 } else if ( str == "disableIrda()") { 344 } else if ( str == "disableIrda()") {
345 if (!m_wasOn) { 345 if (!m_wasOn) {
346 setIrdaStatus( false ); 346 setIrdaStatus( false );
347 } 347 }
348 if ( !m_wasDiscover ) { 348 if ( !m_wasDiscover ) {
349 setIrdaDiscoveryStatus ( false ); 349 setIrdaDiscoveryStatus ( false );
350 } 350 }
351 } else if ( str == "listDevices()") { 351 } else if ( str == "listDevices()") {
352 QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)"); 352 QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)");
353 353
354 QStringList list; 354 QStringList list;
355 QMap<QString, QString>::Iterator it; 355 QMap<QString, QString>::Iterator it;
356 for (it = m_devices.begin(); it != m_devices.end(); ++it ) 356 for (it = m_devices.begin(); it != m_devices.end(); ++it )
357 list << (*it); 357 list << (*it);
358 358
359 e << list; 359 e << list;
360 } 360 }
361} 361}
362 362
363EXPORT_OPIE_APPLET_v1( IrdaApplet ) 363EXPORT_OPIE_APPLET_v1( IrdaApplet )