summaryrefslogtreecommitdiff
path: root/core/applets
Unidiff
Diffstat (limited to 'core/applets') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/irdaapplet/irda.cpp76
-rw-r--r--core/applets/irdaapplet/irda.h17
2 files changed, 65 insertions, 28 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp
index c3ddff2..84c656f 100644
--- a/core/applets/irdaapplet/irda.cpp
+++ b/core/applets/irdaapplet/irda.cpp
@@ -3,4 +3,5 @@
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** 6**
6** 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
@@ -14,4 +15,6 @@
14**********************************************************************/ 15**********************************************************************/
15 16
17#include <qcopchannel_qws.h>
18
16#include <qpe/qpeapplication.h> 19#include <qpe/qpeapplication.h>
17#include <qpe/resource.h> 20#include <qpe/resource.h>
@@ -42,12 +45,12 @@ IrdaApplet::IrdaApplet ( QWidget *parent, const char *name )
42 setFixedHeight ( 18 ); 45 setFixedHeight ( 18 );
43 setFixedWidth ( 14 ); 46 setFixedWidth ( 14 );
44 47
45 m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP ); 48 m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP );
46 49
47 m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); 50 m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" );
48 m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); 51 m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" );
49 m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); 52 m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" );
50 m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" ); 53 m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" );
51 54
52 m_irda_active = false; 55 m_irda_active = false;
53 m_irda_discovery_active = false; 56 m_irda_discovery_active = false;
@@ -55,4 +58,9 @@ IrdaApplet::IrdaApplet ( QWidget *parent, const char *name )
55 m_receive_state_changed = false; 58 m_receive_state_changed = false;
56 m_popup = 0; 59 m_popup = 0;
60 m_wasOn = false;
61
62 QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this );
63 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
64 this, SLOT(slotMessage(const QCString&, const QByteArray& ) ) );
57} 65}
58 66
@@ -71,12 +79,12 @@ IrdaApplet::~IrdaApplet()
71void IrdaApplet::popup ( QString message, QString icon ) 79void IrdaApplet::popup ( QString message, QString icon )
72{ 80{
73 if ( !m_popup ) 81 if ( !m_popup )
74 m_popup = new QPopupMenu ( this ); 82 m_popup = new QPopupMenu ( this );
75 83
76 m_popup-> clear ( ); 84 m_popup-> clear ( );
77 85
78 if ( icon. isEmpty ( )) 86 if ( icon. isEmpty ( ))
79 m_popup-> insertItem ( message, 0 ); 87 m_popup-> insertItem ( message, 0 );
80 else 88 else
81 m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 ); 89 m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 );
82 90
@@ -148,5 +156,5 @@ bool IrdaApplet::setIrdaDiscoveryStatus ( bool d )
148 156
149 if ( discovery. open ( IO_WriteOnly | IO_Raw )) { 157 if ( discovery. open ( IO_WriteOnly | IO_Raw )) {
150 discovery.putch ( d ? '1' : '0' ); 158 discovery.putch ( d ? '1' : '0' );
151 return true; 159 return true;
152 } 160 }
@@ -159,8 +167,8 @@ bool IrdaApplet::setIrdaReceiveStatus ( bool d )
159 QCopEnvelope e ( "QPE/Obex", "receive(int)" ); 167 QCopEnvelope e ( "QPE/Obex", "receive(int)" );
160 e << ( d ? 1 : 0 ); 168 e << ( d ? 1 : 0 );
161 169
162 m_receive_active = d; 170 m_receive_active = d;
163 m_receive_state_changed = true; 171 m_receive_state_changed = true;
164 172
165 return true; 173 return true;
166} 174}
@@ -179,5 +187,5 @@ void IrdaApplet::showDiscovered ( )
179 QString discoveredDevice; 187 QString discoveredDevice;
180 QString deviceAddr; 188 QString deviceAddr;
181 189
182 // since it is /proc we _must_ use QTextStream 190 // since it is /proc we _must_ use QTextStream
183 QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( )); 191 QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( ));
@@ -190,5 +198,5 @@ void IrdaApplet::showDiscovered ( )
190 for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) { 198 for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) {
191 const QString &line = *lit; 199 const QString &line = *lit;
192 200
193 if ( line. startsWith ( "nickname:" )) { 201 if ( line. startsWith ( "nickname:" )) {
194 discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 ); 202 discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 );
@@ -208,14 +216,14 @@ void IrdaApplet::showDiscovered ( )
208 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) { 216 for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) {
209 // qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?"); 217 // qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?");
210 218
211 if ( it. data ( ). left ( 3 ) == "+++" ) { 219 if ( it. data ( ). left ( 3 ) == "+++" ) {
212 popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 )); 220 popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 ));
213 snd_lost. play ( ); 221 snd_lost. play ( );
214 222
215 QMap <QString, QString>::Iterator tmp = it; 223 QMap <QString, QString>::Iterator tmp = it;
216 tmp++; 224 tmp++;
217 m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator 225 m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator
218 it = tmp; 226 it = tmp;
219 227
220 qcopsend = true; 228 qcopsend = true;
221 } 229 }
@@ -226,5 +234,5 @@ void IrdaApplet::showDiscovered ( )
226 QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" ); 234 QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" );
227 e << ( m_devices. count ( ) > 0 ); 235 e << ( m_devices. count ( ) > 0 );
228 // } 236 // }
229 } 237 }
230} 238}
@@ -260,5 +268,5 @@ void IrdaApplet::mousePressEvent ( QMouseEvent * )
260 268
261 p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( )); 269 p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ));
262 270
263 switch ( menu-> exec ( p )) { 271 switch ( menu-> exec ( p )) {
264 case 0: 272 case 0:
@@ -275,5 +283,5 @@ void IrdaApplet::mousePressEvent ( QMouseEvent * )
275 break; 283 break;
276 } 284 }
277 285
278 delete menu; 286 delete menu;
279} 287}
@@ -293,8 +301,8 @@ void IrdaApplet::timerEvent ( QTimerEvent * )
293 m_irda_discovery_active = checkIrdaDiscoveryStatus ( ); 301 m_irda_discovery_active = checkIrdaDiscoveryStatus ( );
294 302
295 if ( m_irda_discovery_active ) 303 if ( m_irda_discovery_active )
296 showDiscovered ( ); 304 showDiscovered ( );
297 305
298 if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate ) 306 if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate )
299 update ( ); 307 update ( );
300} 308}
@@ -309,5 +317,31 @@ void IrdaApplet::paintEvent ( QPaintEvent * )
309 p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap ); 317 p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap );
310 318
311 if ( m_receive_active ) 319 if ( m_receive_active )
312 p. drawPixmap( 0, 1, m_receiveActivePixmap ); 320 p. drawPixmap( 0, 1, m_receiveActivePixmap );
313} 321}
322/*
323 * We know 3 calls
324 * a) enable
325 * b) disable
326 * a and b will temp enable the IrDa device and disable will disable it again if it wasn't on
327 * c) listDevices: We will return a list of known devices
328 */
329void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ar ) {
330 if ( str == "enableIrda()") {
331 m_wasOn = checkIrdaStatus();
332 if (!m_wasOn)
333 setIrdaStatus( true );
334 }else if ( str == "disableIrda()") {
335 if (!m_wasOn)
336 setIrdaStatus( false );
337 }else if ( str == "listDevices()") {
338 QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)");
339
340 QStringList list;
341 QMap<QString, QString>::Iterator it;
342 for (it = m_devices.begin(); it != m_devices.end(); ++it )
343 list << (*it);
344
345 e << list;
346 }
347}
diff --git a/core/applets/irdaapplet/irda.h b/core/applets/irdaapplet/irda.h
index 1b5faa6..675f874 100644
--- a/core/applets/irdaapplet/irda.h
+++ b/core/applets/irdaapplet/irda.h
@@ -25,5 +25,5 @@ class IrdaApplet : public QWidget
25{ 25{
26 Q_OBJECT 26 Q_OBJECT
27 27
28public: 28public:
29 IrdaApplet( QWidget *parent = 0, const char *name = 0 ); 29 IrdaApplet( QWidget *parent = 0, const char *name = 0 );
@@ -36,7 +36,8 @@ protected:
36 virtual void mousePressEvent ( QMouseEvent * ); 36 virtual void mousePressEvent ( QMouseEvent * );
37 virtual void paintEvent ( QPaintEvent* ); 37 virtual void paintEvent ( QPaintEvent* );
38 38
39private slots: 39private slots:
40 void popupTimeout ( ); 40 void popupTimeout ( );
41 void slotMessage( const QCString& , const QByteArray& );
41 42
42private: 43private:
@@ -50,5 +51,5 @@ private:
50 51
51 void showDiscovered(); 52 void showDiscovered();
52 53
53private: 54private:
54 QPixmap m_irdaOnPixmap; 55 QPixmap m_irdaOnPixmap;
@@ -56,15 +57,17 @@ private:
56 QPixmap m_irdaDiscoveryOnPixmap; 57 QPixmap m_irdaDiscoveryOnPixmap;
57 QPixmap m_receiveActivePixmap; 58 QPixmap m_receiveActivePixmap;
58 59
59 bool m_irda_active; 60 bool m_irda_active;
60 bool m_irda_discovery_active; 61 bool m_irda_discovery_active;
61 bool m_receive_active; 62 bool m_receive_active;
62 bool m_receive_state_changed; 63 bool m_receive_state_changed;
63 64
64 QPopupMenu *m_popup; 65 QPopupMenu *m_popup;
65 66
66 int m_sockfd; 67 int m_sockfd;
67 68
68 QMap <QString, QString> m_devices; 69 QMap <QString, QString> m_devices;
70
71 bool m_wasOn; // if IrDa was enabled
69}; 72};
70 73