summaryrefslogtreecommitdiff
Unidiff
Diffstat (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
@@ -1,8 +1,9 @@
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** 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
7** 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
8** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
@@ -12,8 +13,10 @@
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 14**
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>
18#include <qpe/ir.h> 21#include <qpe/ir.h>
19#include <qpe/qcopenvelope_qws.h> 22#include <qpe/qcopenvelope_qws.h>
@@ -40,21 +43,26 @@ IrdaApplet::IrdaApplet ( QWidget *parent, const char *name )
40 : QWidget ( parent, name ) 43 : QWidget ( parent, name )
41{ 44{
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;
54 m_receive_active = false; 57 m_receive_active = false;
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
59void IrdaApplet::show() 67void IrdaApplet::show()
60{ 68{
@@ -69,16 +77,16 @@ IrdaApplet::~IrdaApplet()
69} 77}
70 78
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
83 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 91 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
84 QSize s = m_popup-> sizeHint ( ); 92 QSize s = m_popup-> sizeHint ( );
@@ -146,9 +154,9 @@ bool IrdaApplet::setIrdaDiscoveryStatus ( bool d )
146{ 154{
147 QFile discovery ( "/proc/sys/net/irda/discovery" ); 155 QFile discovery ( "/proc/sys/net/irda/discovery" );
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 }
153 return false; 161 return false;
154} 162}
@@ -157,12 +165,12 @@ bool IrdaApplet::setIrdaDiscoveryStatus ( bool d )
157bool IrdaApplet::setIrdaReceiveStatus ( bool d ) 165bool IrdaApplet::setIrdaReceiveStatus ( bool d )
158{ 166{
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}
167 175
168 176
@@ -177,9 +185,9 @@ void IrdaApplet::showDiscovered ( )
177 bool qcopsend = false; 185 bool qcopsend = false;
178 186
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 ( ));
184 192
185 QMap <QString, QString>::Iterator it; 193 QMap <QString, QString>::Iterator it;
@@ -188,9 +196,9 @@ void IrdaApplet::showDiscovered ( )
188 it. data ( ). prepend ( "+++" ); 196 it. data ( ). prepend ( "+++" );
189 197
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 );
195 deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 ); 203 deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 );
196 204
@@ -206,27 +214,27 @@ void IrdaApplet::showDiscovered ( )
206 } 214 }
207 215
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 }
222 else 230 else
223 it++; 231 it++;
224 } 232 }
225 // XXX if( qcopsend ) { 233 // XXX if( qcopsend ) {
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}
231 239
232void IrdaApplet::mousePressEvent ( QMouseEvent * ) 240void IrdaApplet::mousePressEvent ( QMouseEvent * )
@@ -258,9 +266,9 @@ void IrdaApplet::mousePressEvent ( QMouseEvent * )
258 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); 266 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) );
259 QSize s = menu-> sizeHint ( ); 267 QSize s = menu-> sizeHint ( );
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:
265 setIrdaStatus ( !m_irda_active ); 273 setIrdaStatus ( !m_irda_active );
266 timerEvent ( 0 ); 274 timerEvent ( 0 );
@@ -273,9 +281,9 @@ void IrdaApplet::mousePressEvent ( QMouseEvent * )
273 setIrdaReceiveStatus ( !m_receive_active ); 281 setIrdaReceiveStatus ( !m_receive_active );
274 timerEvent( 0 ); 282 timerEvent( 0 );
275 break; 283 break;
276 } 284 }
277 285
278 delete menu; 286 delete menu;
279} 287}
280 288
281void IrdaApplet::timerEvent ( QTimerEvent * ) 289void IrdaApplet::timerEvent ( QTimerEvent * )
@@ -291,12 +299,12 @@ void IrdaApplet::timerEvent ( QTimerEvent * )
291 299
292 m_irda_active = checkIrdaStatus ( ); 300 m_irda_active = checkIrdaStatus ( );
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}
301 309
302void IrdaApplet::paintEvent ( QPaintEvent * ) 310void IrdaApplet::paintEvent ( QPaintEvent * )
@@ -307,7 +315,33 @@ void IrdaApplet::paintEvent ( QPaintEvent * )
307 315
308 if ( m_irda_discovery_active ) 316 if ( m_irda_discovery_active )
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
@@ -23,9 +23,9 @@
23 23
24class IrdaApplet : public QWidget 24class 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 );
30 ~IrdaApplet(); 30 ~IrdaApplet();
31 31
@@ -34,11 +34,12 @@ public:
34protected: 34protected:
35 virtual void timerEvent ( QTimerEvent * ); 35 virtual void timerEvent ( QTimerEvent * );
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:
43 void popup( QString message, QString icon = QString::null ); 44 void popup( QString message, QString icon = QString::null );
44 45
@@ -48,25 +49,27 @@ private:
48 bool setIrdaDiscoveryStatus ( bool ); 49 bool setIrdaDiscoveryStatus ( bool );
49 bool setIrdaReceiveStatus ( bool ); 50 bool setIrdaReceiveStatus ( bool );
50 51
51 void showDiscovered(); 52 void showDiscovered();
52 53
53private: 54private:
54 QPixmap m_irdaOnPixmap; 55 QPixmap m_irdaOnPixmap;
55 QPixmap m_irdaOffPixmap; 56 QPixmap m_irdaOffPixmap;
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
71 74
72#endif // __OPIE_IRDA_APPLET_H__ 75#endif // __OPIE_IRDA_APPLET_H__