Diffstat (limited to 'core/applets/irdaapplet/irda.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp index c0f11c0..42bed5e 100644 --- a/core/applets/irdaapplet/irda.cpp +++ b/core/applets/irdaapplet/irda.cpp | |||
@@ -35,50 +35,54 @@ | |||
35 | #include <qpainter.h> | 35 | #include <qpainter.h> |
36 | #include <qcombobox.h> | 36 | #include <qcombobox.h> |
37 | #include <qspinbox.h> | 37 | #include <qspinbox.h> |
38 | #include <qslider.h> | 38 | #include <qslider.h> |
39 | #include <qlayout.h> | 39 | #include <qlayout.h> |
40 | #include <qframe.h> | 40 | #include <qframe.h> |
41 | #include <qpixmap.h> | 41 | #include <qpixmap.h> |
42 | #include <qstring.h> | 42 | #include <qstring.h> |
43 | #include <qfile.h> | 43 | #include <qfile.h> |
44 | #include <qtimer.h> | 44 | #include <qtimer.h> |
45 | #include <qtextstream.h> | 45 | #include <qtextstream.h> |
46 | #include <qpopupmenu.h> | 46 | #include <qpopupmenu.h> |
47 | #include <qsound.h> | ||
47 | 48 | ||
48 | #include <net/if.h> | 49 | #include <net/if.h> |
49 | #include <netinet/in.h> | 50 | #include <netinet/in.h> |
50 | #include <sys/types.h> | 51 | #include <sys/types.h> |
51 | #include <sys/socket.h> | 52 | #include <sys/socket.h> |
52 | #include <sys/ioctl.h> | 53 | #include <sys/ioctl.h> |
53 | 54 | ||
54 | 55 | ||
55 | //=========================================================================== | 56 | //=========================================================================== |
56 | 57 | ||
57 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | 58 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) |
58 | : QWidget( parent, name ) { | 59 | : QWidget( parent, name ) { |
59 | setFixedHeight( 14 ); | 60 | setFixedHeight( 14 ); |
60 | setFixedWidth( 14 ); | 61 | setFixedWidth( 14 ); |
61 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | 62 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
62 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); | 63 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); |
63 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); | 64 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); |
64 | irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); | 65 | irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); |
65 | receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive"); | 66 | receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive"); |
66 | receiveActive = false; | 67 | receiveActive = false; |
67 | startTimer(5000); | ||
68 | timerEvent(NULL); | ||
69 | popupMenu = 0; | 68 | popupMenu = 0; |
70 | devicesAvailable.setAutoDelete(TRUE); | 69 | devicesAvailable.setAutoDelete(TRUE); |
71 | } | 70 | } |
72 | 71 | ||
72 | void IrdaApplet::show() { | ||
73 | QWidget::show(); | ||
74 | startTimer(2000); | ||
75 | } | ||
76 | |||
73 | IrdaApplet::~IrdaApplet() { | 77 | IrdaApplet::~IrdaApplet() { |
74 | close(sockfd); | 78 | close(sockfd); |
75 | if( popupMenu ) { delete popupMenu; } | 79 | if( popupMenu ) { delete popupMenu; } |
76 | } | 80 | } |
77 | 81 | ||
78 | void IrdaApplet::popup(QString message, QString icon="") { | 82 | void IrdaApplet::popup(QString message, QString icon="") { |
79 | if ( ! popupMenu ) { | 83 | if ( ! popupMenu ) { |
80 | popupMenu = new QPopupMenu(); | 84 | popupMenu = new QPopupMenu(); |
81 | } | 85 | } |
82 | popupMenu->clear(); | 86 | popupMenu->clear(); |
83 | if( icon == "" ) { | 87 | if( icon == "" ) { |
84 | popupMenu->insertItem( message, 0 ); | 88 | popupMenu->insertItem( message, 0 ); |
@@ -197,71 +201,72 @@ void IrdaApplet::showDiscovered() { | |||
197 | streamIn = stream.read(); | 201 | streamIn = stream.read(); |
198 | list = QStringList::split("\n", streamIn); | 202 | list = QStringList::split("\n", streamIn); |
199 | 203 | ||
200 | QDictIterator<QString> it( devicesAvailable ); | 204 | QDictIterator<QString> it( devicesAvailable ); |
201 | while ( it.current() ) { | 205 | while ( it.current() ) { |
202 | devicesAvailable.replace( it.currentKey(), new QString("+++" + *devicesAvailable[it.currentKey()]) ); | 206 | devicesAvailable.replace( it.currentKey(), new QString("+++" + *devicesAvailable[it.currentKey()]) ); |
203 | //qDebug("IrdaMon: " + it.currentKey()); | 207 | //qDebug("IrdaMon: " + it.currentKey()); |
204 | //qDebug(" =" + *devicesAvailable[it.currentKey()] ); | 208 | //qDebug(" =" + *devicesAvailable[it.currentKey()] ); |
205 | ++it; | 209 | ++it; |
206 | } | 210 | } |
207 | 211 | ||
208 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { | 212 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { |
209 | qDebug( (*line) ); | 213 | // qDebug( (*line) ); |
210 | if( (*line).startsWith("nickname:") ){ | 214 | if( (*line).startsWith("nickname:") ){ |
211 | discoveredDevice = (*line).mid(((*line).find(':'))+2,(*line).find(',')-(*line).find(':')-2); | 215 | discoveredDevice = (*line).mid(((*line).find(':'))+2,(*line).find(',')-(*line).find(':')-2); |
212 | deviceAddr = (*line).mid( (*line).find( "daddr:" )+9, 8 ); | 216 | deviceAddr = (*line).mid( (*line).find( "daddr:" )+9, 8 ); |
213 | 217 | ||
214 | qDebug(discoveredDevice + "(" + deviceAddr + ")"); | 218 | // qDebug(discoveredDevice + "(" + deviceAddr + ")"); |
215 | 219 | ||
216 | if( ! devicesAvailable.find(deviceAddr) ) { | 220 | if( ! devicesAvailable.find(deviceAddr) ) { |
217 | popup( tr("Found:") + " " + discoveredDevice ); | 221 | popup( tr("Found:") + " " + discoveredDevice ); |
222 | QSound::play(Resource::findSound("irdaapplet/irdaon")); | ||
218 | qcopsend = TRUE; | 223 | qcopsend = TRUE; |
219 | } | 224 | } |
220 | devicesAvailable.replace( deviceAddr, new QString(discoveredDevice) ); | 225 | devicesAvailable.replace( deviceAddr, new QString(discoveredDevice) ); |
221 | //qDebug("IrdaMon: " + deviceAddr + "=" + *devicesAvailable[deviceAddr] ); | 226 | // qDebug("IrdaMon: " + deviceAddr + "=" + *devicesAvailable[deviceAddr] ); |
222 | } | 227 | } |
223 | } | 228 | } |
224 | 229 | ||
225 | it.toFirst(); | 230 | it.toFirst(); |
226 | while ( it.current() ) { | 231 | while ( it.current() ) { |
227 | qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?"); | 232 | // qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?"); |
228 | if ( (*it.current()).left(3) == "+++" ) { | 233 | if ( (*it.current()).left(3) == "+++" ) { |
229 | popup( tr("Lost:") + " " + (*devicesAvailable[it.currentKey()]).mid(3) ); | 234 | popup( tr("Lost:") + " " + (*devicesAvailable[it.currentKey()]).mid(3) ); |
235 | QSound::play(Resource::findSound("irdaapplet/irdaoff")); | ||
230 | devicesAvailable.remove( it.currentKey() ); | 236 | devicesAvailable.remove( it.currentKey() ); |
231 | qDebug("IrdaMon: delete " + it.currentKey() + "!"); | 237 | // qDebug("IrdaMon: delete " + it.currentKey() + "!"); |
232 | qcopsend = TRUE; | 238 | qcopsend = TRUE; |
233 | } | 239 | } |
234 | ++it; | 240 | ++it; |
235 | } | 241 | } |
236 | /* XXX if( qcopsend ) { | 242 | /* XXX if( qcopsend ) { |
237 | QCopEnvelope e("QPE/Network", "irdaSend(bool)" ); | 243 | QCopEnvelope e("QPE/Network", "irdaSend(bool)" ); |
238 | e << (devicesAvailable.count() > 0) ; | 244 | e << (devicesAvailable.count() > 0) ; |
239 | } */ | 245 | } */ |
240 | } | 246 | } |
241 | } | 247 | } |
242 | 248 | ||
243 | void IrdaApplet::mousePressEvent( QMouseEvent *) { | 249 | void IrdaApplet::mousePressEvent( QMouseEvent *) { |
244 | QPopupMenu *menu = new QPopupMenu(); | 250 | QPopupMenu *menu = new QPopupMenu(); |
245 | QString cmd; | 251 | QString cmd; |
246 | int ret=0; | 252 | int ret=0; |
247 | 253 | ||
248 | /* Refresh active state */ | 254 | /* Refresh active state */ |
249 | timerEvent(NULL); | 255 | timerEvent(NULL); |
250 | 256 | ||
251 | //menu->insertItem( tr("More..."), 4 ); | 257 | //menu->insertItem( tr("More..."), 4 ); |
252 | 258 | ||
253 | if (irdaactive && devicesAvailable.count() > 0) { | 259 | if (irdaactive && devicesAvailable.count() > 0) { |
254 | menu->insertItem( tr("Discovered Device:"), 9); | 260 | menu->insertItem( tr("Discovered Device:"), 9); |
255 | |||
256 | QDictIterator<QString> it( devicesAvailable ); | 261 | QDictIterator<QString> it( devicesAvailable ); |
257 | while ( it.current() ) { | 262 | while ( it.current() ) { |
258 | menu->insertItem( *devicesAvailable[it.currentKey()]); | 263 | menu->insertItem( *devicesAvailable[it.currentKey()]); |
259 | ++it; | 264 | ++it; |
260 | } | 265 | } |
261 | menu->insertSeparator(); | 266 | menu->insertSeparator(); |
262 | } | 267 | } |
263 | 268 | ||
264 | if (irdaactive) { | 269 | if (irdaactive) { |
265 | menu->insertItem( tr("Disable IrDA"), 0 ); | 270 | menu->insertItem( tr("Disable IrDA"), 0 ); |
266 | } else { | 271 | } else { |
267 | menu->insertItem( tr("Enable IrDA"), 1 ); | 272 | menu->insertItem( tr("Enable IrDA"), 1 ); |
@@ -307,27 +312,24 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { | |||
307 | timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l | 312 | timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l |
308 | break; | 313 | break; |
309 | case 4: { // enable receive | 314 | case 4: { // enable receive |
310 | setIrdaReceiveStatus(0); | 315 | setIrdaReceiveStatus(0); |
311 | timerEvent(NULL); | 316 | timerEvent(NULL); |
312 | break; | 317 | break; |
313 | } | 318 | } |
314 | case 5: { // disable receive | 319 | case 5: { // disable receive |
315 | setIrdaReceiveStatus(1); | 320 | setIrdaReceiveStatus(1); |
316 | timerEvent(NULL); | 321 | timerEvent(NULL); |
317 | break; | 322 | break; |
318 | } | 323 | } |
319 | case 6: | ||
320 | qDebug("FIXME: Bring up pretty menu...\n"); | ||
321 | // With table of currently-detected devices. | ||
322 | } | 324 | } |
323 | delete menu; // Can somebody explain why use a QPopupMenu* and not QPopupMenu nor QAction. with out delete we will leak cause QPopupMenu doesn't have a parent in this case | 325 | delete menu; // Can somebody explain why use a QPopupMenu* and not QPopupMenu nor QAction. with out delete we will leak cause QPopupMenu doesn't have a parent in this case |
324 | } | 326 | } |
325 | 327 | ||
326 | void IrdaApplet::timerEvent( QTimerEvent * ) { | 328 | void IrdaApplet::timerEvent( QTimerEvent * ) { |
327 | int oldactive = irdaactive; | 329 | int oldactive = irdaactive; |
328 | int olddiscovery = irdaDiscoveryActive; | 330 | int olddiscovery = irdaDiscoveryActive; |
329 | bool receiveUpdate = false; | 331 | bool receiveUpdate = false; |
330 | 332 | ||
331 | if (receiveStateChanged) { | 333 | if (receiveStateChanged) { |
332 | receiveUpdate = true; | 334 | receiveUpdate = true; |
333 | receiveStateChanged = false; | 335 | receiveStateChanged = false; |
@@ -340,25 +342,25 @@ void IrdaApplet::timerEvent( QTimerEvent * ) { | |||
340 | if (irdaDiscoveryActive) { | 342 | if (irdaDiscoveryActive) { |
341 | showDiscovered(); | 343 | showDiscovered(); |
342 | } | 344 | } |
343 | 345 | ||
344 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { | 346 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { |
345 | paintEvent(NULL); | 347 | paintEvent(NULL); |
346 | } | 348 | } |
347 | 349 | ||
348 | } | 350 | } |
349 | 351 | ||
350 | void IrdaApplet::paintEvent( QPaintEvent* ) { | 352 | void IrdaApplet::paintEvent( QPaintEvent* ) { |
351 | QPainter p(this); | 353 | QPainter p(this); |
352 | qDebug("paint irda pixmap"); | 354 | // qDebug("paint irda pixmap"); |
353 | 355 | ||
354 | p.eraseRect ( 0, 0, this->width(), this->height() ); | 356 | p.eraseRect ( 0, 0, this->width(), this->height() ); |
355 | if (irdaactive > 0) { | 357 | if (irdaactive > 0) { |
356 | p.drawPixmap( 0, 0, irdaOnPixmap ); | 358 | p.drawPixmap( 0, 0, irdaOnPixmap ); |
357 | } else { | 359 | } else { |
358 | p.drawPixmap( 0, 0, irdaOffPixmap ); | 360 | p.drawPixmap( 0, 0, irdaOffPixmap ); |
359 | } | 361 | } |
360 | 362 | ||
361 | if (irdaDiscoveryActive > 0) { | 363 | if (irdaDiscoveryActive > 0) { |
362 | p.drawPixmap( 0, 0, irdaDiscoveryOnPixmap ); | 364 | p.drawPixmap( 0, 0, irdaDiscoveryOnPixmap ); |
363 | } | 365 | } |
364 | if (receiveActive) { | 366 | if (receiveActive) { |