author | harlekin <harlekin> | 2003-03-26 18:23:57 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2003-03-26 18:23:57 (UTC) |
commit | 8c1acc27882a79ea9f1ee9b9be708b9bbab052ba (patch) (unidiff) | |
tree | b906f762e28da948eaaa3ea0df5c81fdd9d41755 | |
parent | 88a93db37e001dc02f9edddf81919266fde0173c (diff) | |
download | opie-8c1acc27882a79ea9f1ee9b9be708b9bbab052ba.zip opie-8c1acc27882a79ea9f1ee9b9be708b9bbab052ba.tar.gz opie-8c1acc27882a79ea9f1ee9b9be708b9bbab052ba.tar.bz2 |
also activate discovery if not allready running - makes beaming with s45 easier
-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 28 | ||||
-rw-r--r-- | core/applets/irdaapplet/irda.h | 3 |
2 files changed, 21 insertions, 10 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp index a5b4bfc..51c2ebf 100644 --- a/core/applets/irdaapplet/irda.cpp +++ b/core/applets/irdaapplet/irda.cpp | |||
@@ -1,347 +1,357 @@ | |||
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 <qcopchannel_qws.h> | 17 | #include <qcopchannel_qws.h> |
18 | 18 | ||
19 | #include <qpe/qpeapplication.h> | 19 | #include <qpe/qpeapplication.h> |
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | #include <qpe/ir.h> | 21 | #include <qpe/ir.h> |
22 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
23 | #include <qpe/sound.h> | 23 | #include <qpe/sound.h> |
24 | 24 | ||
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 | #include <qpopupmenu.h> | 29 | #include <qpopupmenu.h> |
30 | 30 | ||
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 | #include "irda.h" | 38 | #include "irda.h" |
39 | 39 | ||
40 | //=========================================================================== | 40 | //=========================================================================== |
41 | 41 | ||
42 | IrdaApplet::IrdaApplet ( QWidget *parent, const char *name ) | 42 | IrdaApplet::IrdaApplet ( QWidget *parent, const char *name ) |
43 | : QWidget ( parent, name ) | 43 | : QWidget ( parent, name ) |
44 | { | 44 | { |
45 | setFixedHeight ( 18 ); | 45 | setFixedHeight ( 18 ); |
46 | setFixedWidth ( 14 ); | 46 | setFixedWidth ( 14 ); |
47 | 47 | ||
48 | m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP ); | 48 | m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP ); |
49 | 49 | ||
50 | m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); | 50 | m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); |
51 | m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); | 51 | m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); |
52 | m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); | 52 | m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); |
53 | m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" ); | 53 | m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" ); |
54 | 54 | ||
55 | m_irda_active = false; | 55 | m_irda_active = false; |
56 | m_irda_discovery_active = false; | 56 | m_irda_discovery_active = false; |
57 | m_receive_active = false; | 57 | m_receive_active = false; |
58 | m_receive_state_changed = false; | 58 | m_receive_state_changed = false; |
59 | m_popup = 0; | 59 | m_popup = 0; |
60 | m_wasOn = false; | 60 | m_wasOn = false; |
61 | m_wasDiscover = false; | ||
61 | 62 | ||
62 | QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this ); | 63 | QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this ); |
63 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 64 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
64 | this, SLOT(slotMessage(const QCString&, const QByteArray& ) ) ); | 65 | this, SLOT(slotMessage(const QCString&, const QByteArray& ) ) ); |
65 | } | 66 | } |
66 | 67 | ||
67 | void IrdaApplet::show() | 68 | void IrdaApplet::show() |
68 | { | 69 | { |
69 | QWidget::show ( ); | 70 | QWidget::show ( ); |
70 | startTimer ( 2000 ); | 71 | startTimer ( 2000 ); |
71 | } | 72 | } |
72 | 73 | ||
73 | IrdaApplet::~IrdaApplet() | 74 | IrdaApplet::~IrdaApplet() |
74 | { | 75 | { |
75 | if ( m_sockfd >= 0 ) | 76 | if ( m_sockfd >= 0 ) |
76 | ::close ( m_sockfd ); | 77 | ::close ( m_sockfd ); |
77 | } | 78 | } |
78 | 79 | ||
79 | void IrdaApplet::popup ( QString message, QString icon ) | 80 | void IrdaApplet::popup ( QString message, QString icon ) |
80 | { | 81 | { |
81 | if ( !m_popup ) | 82 | if ( !m_popup ) |
82 | m_popup = new QPopupMenu ( this ); | 83 | m_popup = new QPopupMenu ( this ); |
83 | 84 | ||
84 | m_popup-> clear ( ); | 85 | m_popup-> clear ( ); |
85 | 86 | ||
86 | if ( icon. isEmpty ( )) | 87 | if ( icon. isEmpty ( )) |
87 | m_popup-> insertItem ( message, 0 ); | 88 | m_popup-> insertItem ( message, 0 ); |
88 | else | 89 | else |
89 | m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 ); | 90 | m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 ); |
90 | 91 | ||
91 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); | 92 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); |
92 | QSize s = m_popup-> sizeHint ( ); | 93 | QSize s = m_popup-> sizeHint ( ); |
93 | m_popup-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), | 94 | m_popup-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), |
94 | p. y ( ) - s. height ( ))); | 95 | p. y ( ) - s. height ( ))); |
95 | 96 | ||
96 | QTimer::singleShot ( 2000, this, SLOT( popupTimeout ( ))); | 97 | QTimer::singleShot ( 2000, this, SLOT( popupTimeout ( ))); |
97 | } | 98 | } |
98 | 99 | ||
99 | void IrdaApplet::popupTimeout ( ) | 100 | void IrdaApplet::popupTimeout ( ) |
100 | { | 101 | { |
101 | m_popup-> hide ( ); | 102 | m_popup-> hide ( ); |
102 | } | 103 | } |
103 | 104 | ||
104 | bool IrdaApplet::checkIrdaStatus ( ) | 105 | bool IrdaApplet::checkIrdaStatus ( ) |
105 | { | 106 | { |
106 | struct ifreq ifr; | 107 | struct ifreq ifr; |
107 | strcpy ( ifr. ifr_name, "irda0" ); | 108 | strcpy ( ifr. ifr_name, "irda0" ); |
108 | 109 | ||
109 | if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) | 110 | if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) |
110 | return false; | 111 | return false; |
111 | 112 | ||
112 | return ( ifr. ifr_flags & IFF_UP ); | 113 | return ( ifr. ifr_flags & IFF_UP ); |
113 | } | 114 | } |
114 | 115 | ||
115 | bool IrdaApplet::setIrdaStatus ( bool b ) | 116 | bool IrdaApplet::setIrdaStatus ( bool b ) |
116 | { | 117 | { |
117 | struct ifreq ifr; | 118 | struct ifreq ifr; |
118 | strcpy ( ifr. ifr_name, "irda0" ); | 119 | strcpy ( ifr. ifr_name, "irda0" ); |
119 | 120 | ||
120 | if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) | 121 | if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) |
121 | return false; | 122 | return false; |
122 | 123 | ||
123 | if ( b ) { | 124 | if ( b ) { |
124 | ifr. ifr_flags |= IFF_UP; | 125 | ifr. ifr_flags |= IFF_UP; |
125 | } | 126 | } |
126 | else { | 127 | else { |
127 | setIrdaDiscoveryStatus ( 0 ); | 128 | setIrdaDiscoveryStatus ( 0 ); |
128 | setIrdaReceiveStatus ( 0 ); | 129 | setIrdaReceiveStatus ( 0 ); |
129 | ifr. ifr_flags &= ~IFF_UP; | 130 | ifr. ifr_flags &= ~IFF_UP; |
130 | } | 131 | } |
131 | 132 | ||
132 | if ( ::ioctl ( m_sockfd, SIOCSIFFLAGS, &ifr ) < 0 ) | 133 | if ( ::ioctl ( m_sockfd, SIOCSIFFLAGS, &ifr ) < 0 ) |
133 | return false; | 134 | return false; |
134 | 135 | ||
135 | return true; | 136 | return true; |
136 | } | 137 | } |
137 | 138 | ||
138 | bool IrdaApplet::checkIrdaDiscoveryStatus ( ) | 139 | bool IrdaApplet::checkIrdaDiscoveryStatus ( ) |
139 | { | 140 | { |
140 | QFile discovery ( "/proc/sys/net/irda/discovery" ); | 141 | QFile discovery ( "/proc/sys/net/irda/discovery" ); |
141 | 142 | ||
142 | QString streamIn = "0"; | 143 | QString streamIn = "0"; |
143 | 144 | ||
144 | if ( discovery. open ( IO_ReadOnly )) { | 145 | if ( discovery. open ( IO_ReadOnly )) { |
145 | QTextStream stream ( &discovery ); | 146 | QTextStream stream ( &discovery ); |
146 | streamIn = stream. read ( ); | 147 | streamIn = stream. read ( ); |
147 | } | 148 | } |
148 | 149 | ||
149 | return streamIn. toInt ( ) > 0; | 150 | return streamIn. toInt ( ) > 0; |
150 | } | 151 | } |
151 | 152 | ||
152 | 153 | ||
153 | bool IrdaApplet::setIrdaDiscoveryStatus ( bool d ) | 154 | bool IrdaApplet::setIrdaDiscoveryStatus ( bool d ) |
154 | { | 155 | { |
155 | QFile discovery ( "/proc/sys/net/irda/discovery" ); | 156 | QFile discovery ( "/proc/sys/net/irda/discovery" ); |
156 | 157 | ||
157 | if ( discovery. open ( IO_WriteOnly | IO_Raw )) { | 158 | if ( discovery. open ( IO_WriteOnly | IO_Raw )) { |
158 | discovery.putch ( d ? '1' : '0' ); | 159 | discovery.putch ( d ? '1' : '0' ); |
159 | return true; | 160 | return true; |
160 | } | 161 | } |
161 | return false; | 162 | return false; |
162 | } | 163 | } |
163 | 164 | ||
164 | 165 | ||
165 | bool IrdaApplet::setIrdaReceiveStatus ( bool d ) | 166 | bool IrdaApplet::setIrdaReceiveStatus ( bool d ) |
166 | { | 167 | { |
167 | QCopEnvelope e ( "QPE/Obex", "receive(int)" ); | 168 | QCopEnvelope e ( "QPE/Obex", "receive(int)" ); |
168 | e << ( d ? 1 : 0 ); | 169 | e << ( d ? 1 : 0 ); |
169 | 170 | ||
170 | m_receive_active = d; | 171 | m_receive_active = d; |
171 | m_receive_state_changed = true; | 172 | m_receive_state_changed = true; |
172 | 173 | ||
173 | return true; | 174 | return true; |
174 | } | 175 | } |
175 | 176 | ||
176 | 177 | ||
177 | void IrdaApplet::showDiscovered ( ) | 178 | void IrdaApplet::showDiscovered ( ) |
178 | { | 179 | { |
179 | //static Sound snd_found ( "irdaapplet/irdaon" ); | 180 | //static Sound snd_found ( "irdaapplet/irdaon" ); |
180 | //static Sound snd_lost ( "irdaapplet/irdaoff" ); | 181 | //static Sound snd_lost ( "irdaapplet/irdaoff" ); |
181 | 182 | ||
182 | QFile discovery ( "/proc/net/irda/discovery" ); | 183 | QFile discovery ( "/proc/net/irda/discovery" ); |
183 | 184 | ||
184 | if ( discovery. open ( IO_ReadOnly )) { | 185 | if ( discovery. open ( IO_ReadOnly )) { |
185 | bool qcopsend = false; | 186 | bool qcopsend = false; |
186 | 187 | ||
187 | QString discoveredDevice; | 188 | QString discoveredDevice; |
188 | QString deviceAddr; | 189 | QString deviceAddr; |
189 | 190 | ||
190 | // since it is /proc we _must_ use QTextStream | 191 | // since it is /proc we _must_ use QTextStream |
191 | QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( )); | 192 | QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( )); |
192 | 193 | ||
193 | QMap <QString, QString>::Iterator it; | 194 | QMap <QString, QString>::Iterator it; |
194 | 195 | ||
195 | for ( it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) | 196 | for ( it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) |
196 | it. data ( ). prepend ( "+++" ); | 197 | it. data ( ). prepend ( "+++" ); |
197 | 198 | ||
198 | for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) { | 199 | for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) { |
199 | const QString &line = *lit; | 200 | const QString &line = *lit; |
200 | 201 | ||
201 | if ( line. startsWith ( "nickname:" )) { | 202 | if ( line. startsWith ( "nickname:" )) { |
202 | discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 ); | 203 | discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 ); |
203 | deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 ); | 204 | deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 ); |
204 | 205 | ||
205 | // qDebug(discoveredDevice + "(" + deviceAddr + ")"); | 206 | // qDebug(discoveredDevice + "(" + deviceAddr + ")"); |
206 | 207 | ||
207 | if ( !m_devices. contains ( deviceAddr )) { | 208 | if ( !m_devices. contains ( deviceAddr )) { |
208 | popup ( tr( "Found:" ) + " " + discoveredDevice ); | 209 | popup ( tr( "Found:" ) + " " + discoveredDevice ); |
209 | //snd_found. play ( ); | 210 | //snd_found. play ( ); |
210 | qcopsend = true; | 211 | qcopsend = true; |
211 | } | 212 | } |
212 | m_devices. replace ( deviceAddr, discoveredDevice ); | 213 | m_devices. replace ( deviceAddr, discoveredDevice ); |
213 | } | 214 | } |
214 | } | 215 | } |
215 | 216 | ||
216 | for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) { | 217 | for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) { |
217 | // qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?"); | 218 | // qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?"); |
218 | 219 | ||
219 | if ( it. data ( ). left ( 3 ) == "+++" ) { | 220 | if ( it. data ( ). left ( 3 ) == "+++" ) { |
220 | popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 )); | 221 | popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 )); |
221 | //snd_lost. play ( ); | 222 | //snd_lost. play ( ); |
222 | 223 | ||
223 | QMap <QString, QString>::Iterator tmp = it; | 224 | QMap <QString, QString>::Iterator tmp = it; |
224 | tmp++; | 225 | tmp++; |
225 | m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator | 226 | m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator |
226 | it = tmp; | 227 | it = tmp; |
227 | 228 | ||
228 | qcopsend = true; | 229 | qcopsend = true; |
229 | } | 230 | } |
230 | else | 231 | else |
231 | it++; | 232 | it++; |
232 | } | 233 | } |
233 | // XXX if( qcopsend ) { | 234 | // XXX if( qcopsend ) { |
234 | QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" ); | 235 | QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" ); |
235 | e << ( m_devices. count ( ) > 0 ); | 236 | e << ( m_devices. count ( ) > 0 ); |
236 | // } | 237 | // } |
237 | } | 238 | } |
238 | } | 239 | } |
239 | 240 | ||
240 | void IrdaApplet::mousePressEvent ( QMouseEvent * ) | 241 | void IrdaApplet::mousePressEvent ( QMouseEvent * ) |
241 | { | 242 | { |
242 | QPopupMenu *menu = new QPopupMenu ( this ); | 243 | QPopupMenu *menu = new QPopupMenu ( this ); |
243 | QString cmd; | 244 | QString cmd; |
244 | 245 | ||
245 | /* Refresh active state */ | 246 | /* Refresh active state */ |
246 | timerEvent ( 0 ); | 247 | timerEvent ( 0 ); |
247 | 248 | ||
248 | //menu->insertItem( tr("More..."), 4 ); | 249 | //menu->insertItem( tr("More..."), 4 ); |
249 | 250 | ||
250 | if ( m_irda_active && !m_devices. isEmpty ( )) { | 251 | if ( m_irda_active && !m_devices. isEmpty ( )) { |
251 | menu-> insertItem ( tr( "Discovered Device:" ), 9 ); | 252 | menu-> insertItem ( tr( "Discovered Device:" ), 9 ); |
252 | 253 | ||
253 | for ( QMap<QString, QString>::Iterator it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) | 254 | for ( QMap<QString, QString>::Iterator it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) |
254 | menu-> insertItem ( *it ); | 255 | menu-> insertItem ( *it ); |
255 | 256 | ||
256 | menu-> insertSeparator ( ); | 257 | menu-> insertSeparator ( ); |
257 | } | 258 | } |
258 | 259 | ||
259 | menu-> insertItem ( m_irda_active ? tr( "Disable IrDA" ) : tr( "Enable IrDA" ), 0 ); | 260 | menu-> insertItem ( m_irda_active ? tr( "Disable IrDA" ) : tr( "Enable IrDA" ), 0 ); |
260 | 261 | ||
261 | if ( m_irda_active ) { | 262 | if ( m_irda_active ) { |
262 | menu-> insertItem ( m_irda_discovery_active ? tr( "Disable Discovery" ) : tr( "Enable Discovery" ), 1 ); | 263 | menu-> insertItem ( m_irda_discovery_active ? tr( "Disable Discovery" ) : tr( "Enable Discovery" ), 1 ); |
263 | menu-> insertItem ( m_receive_active ? tr( "Disable Receive" ) : tr( "Enable Receive" ), 2 ); | 264 | menu-> insertItem ( m_receive_active ? tr( "Disable Receive" ) : tr( "Enable Receive" ), 2 ); |
264 | } | 265 | } |
265 | 266 | ||
266 | QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); | 267 | QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); |
267 | QSize s = menu-> sizeHint ( ); | 268 | QSize s = menu-> sizeHint ( ); |
268 | 269 | ||
269 | p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( )); | 270 | p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( )); |
270 | 271 | ||
271 | switch ( menu-> exec ( p )) { | 272 | switch ( menu-> exec ( p )) { |
272 | case 0: | 273 | case 0: |
273 | setIrdaStatus ( !m_irda_active ); | 274 | setIrdaStatus ( !m_irda_active ); |
274 | timerEvent ( 0 ); | 275 | timerEvent ( 0 ); |
275 | break; | 276 | break; |
276 | case 1: | 277 | case 1: |
277 | setIrdaDiscoveryStatus ( !m_irda_discovery_active ); | 278 | setIrdaDiscoveryStatus ( !m_irda_discovery_active ); |
278 | timerEvent ( 0 ); | 279 | timerEvent ( 0 ); |
279 | break; | 280 | break; |
280 | case 2: | 281 | case 2: |
281 | setIrdaReceiveStatus ( !m_receive_active ); | 282 | setIrdaReceiveStatus ( !m_receive_active ); |
282 | timerEvent( 0 ); | 283 | timerEvent( 0 ); |
283 | break; | 284 | break; |
284 | } | 285 | } |
285 | 286 | ||
286 | delete menu; | 287 | delete menu; |
287 | } | 288 | } |
288 | 289 | ||
289 | void IrdaApplet::timerEvent ( QTimerEvent * ) | 290 | void IrdaApplet::timerEvent ( QTimerEvent * ) |
290 | { | 291 | { |
291 | bool oldactive = m_irda_active; | 292 | bool oldactive = m_irda_active; |
292 | bool olddiscovery = m_irda_discovery_active; | 293 | bool olddiscovery = m_irda_discovery_active; |
293 | bool receiveUpdate = false; | 294 | bool receiveUpdate = false; |
294 | 295 | ||
295 | if ( m_receive_state_changed ) { | 296 | if ( m_receive_state_changed ) { |
296 | receiveUpdate = true; | 297 | receiveUpdate = true; |
297 | m_receive_state_changed = false; | 298 | m_receive_state_changed = false; |
298 | } | 299 | } |
299 | 300 | ||
300 | m_irda_active = checkIrdaStatus ( ); | 301 | m_irda_active = checkIrdaStatus ( ); |
301 | m_irda_discovery_active = checkIrdaDiscoveryStatus ( ); | 302 | m_irda_discovery_active = checkIrdaDiscoveryStatus ( ); |
302 | 303 | ||
303 | if ( m_irda_discovery_active ) | 304 | if ( m_irda_discovery_active ) |
304 | showDiscovered ( ); | 305 | showDiscovered ( ); |
305 | 306 | ||
306 | if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate ) | 307 | if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate ) |
307 | update ( ); | 308 | update ( ); |
308 | } | 309 | } |
309 | 310 | ||
310 | void IrdaApplet::paintEvent ( QPaintEvent * ) | 311 | void IrdaApplet::paintEvent ( QPaintEvent * ) |
311 | { | 312 | { |
312 | QPainter p ( this ); | 313 | QPainter p ( this ); |
313 | 314 | ||
314 | p. drawPixmap ( 0, 1, m_irda_active ? m_irdaOnPixmap : m_irdaOffPixmap ); | 315 | p. drawPixmap ( 0, 1, m_irda_active ? m_irdaOnPixmap : m_irdaOffPixmap ); |
315 | 316 | ||
316 | if ( m_irda_discovery_active ) | 317 | if ( m_irda_discovery_active ) |
317 | p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap ); | 318 | p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap ); |
318 | 319 | ||
319 | if ( m_receive_active ) | 320 | if ( m_receive_active ) |
320 | p. drawPixmap( 0, 1, m_receiveActivePixmap ); | 321 | p. drawPixmap( 0, 1, m_receiveActivePixmap ); |
321 | } | 322 | } |
322 | /* | 323 | /* |
323 | * We know 3 calls | 324 | * We know 3 calls |
324 | * a) enable | 325 | * a) enable |
325 | * b) disable | 326 | * b) disable |
326 | * a and b will temp enable the IrDa device and disable will disable it again if it wasn't on | 327 | * 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 | * c) listDevices: We will return a list of known devices |
328 | */ | 329 | */ |
329 | void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ar ) { | 330 | void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ar ) { |
330 | if ( str == "enableIrda()") { | 331 | if ( str == "enableIrda()") { |
331 | m_wasOn = checkIrdaStatus(); | 332 | m_wasOn = checkIrdaStatus(); |
332 | if (!m_wasOn) | 333 | m_wasDiscover = checkIrdaDiscoveryStatus(); |
334 | if (!m_wasOn) { | ||
333 | setIrdaStatus( true ); | 335 | setIrdaStatus( true ); |
334 | }else if ( str == "disableIrda()") { | 336 | } |
335 | if (!m_wasOn) | 337 | if ( !m_wasDiscover ) { |
338 | setIrdaDiscoveryStatus ( true ); | ||
339 | } | ||
340 | } else if ( str == "disableIrda()") { | ||
341 | if (!m_wasOn) { | ||
336 | setIrdaStatus( false ); | 342 | setIrdaStatus( false ); |
337 | }else if ( str == "listDevices()") { | 343 | } |
344 | if ( !m_wasDiscover ) { | ||
345 | setIrdaDiscoveryStatus ( false ); | ||
346 | } | ||
347 | } else if ( str == "listDevices()") { | ||
338 | QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)"); | 348 | QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)"); |
339 | 349 | ||
340 | QStringList list; | 350 | QStringList list; |
341 | QMap<QString, QString>::Iterator it; | 351 | QMap<QString, QString>::Iterator it; |
342 | for (it = m_devices.begin(); it != m_devices.end(); ++it ) | 352 | for (it = m_devices.begin(); it != m_devices.end(); ++it ) |
343 | list << (*it); | 353 | list << (*it); |
344 | 354 | ||
345 | e << list; | 355 | e << list; |
346 | } | 356 | } |
347 | } | 357 | } |
diff --git a/core/applets/irdaapplet/irda.h b/core/applets/irdaapplet/irda.h index 675f874..ec1d32c 100644 --- a/core/applets/irdaapplet/irda.h +++ b/core/applets/irdaapplet/irda.h | |||
@@ -1,75 +1,76 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com, | 2 | ** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com, |
3 | ** Robert Griebl sandman@handhelds.org | 3 | ** Robert Griebl sandman@handhelds.org |
4 | ** All rights reserved. | 4 | ** All rights reserved. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** 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 | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #ifndef __OPIE_IRDA_APPLET_H__ | 16 | #ifndef __OPIE_IRDA_APPLET_H__ |
17 | #define __OPIE_IRDA_APPLET_H__ | 17 | #define __OPIE_IRDA_APPLET_H__ |
18 | 18 | ||
19 | #include <qwidget.h> | 19 | #include <qwidget.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | #include <qpopupmenu.h> | 21 | #include <qpopupmenu.h> |
22 | #include <qmap.h> | 22 | #include <qmap.h> |
23 | 23 | ||
24 | class IrdaApplet : public QWidget | 24 | class IrdaApplet : public QWidget |
25 | { | 25 | { |
26 | Q_OBJECT | 26 | Q_OBJECT |
27 | 27 | ||
28 | public: | 28 | public: |
29 | IrdaApplet( QWidget *parent = 0, const char *name = 0 ); | 29 | IrdaApplet( QWidget *parent = 0, const char *name = 0 ); |
30 | ~IrdaApplet(); | 30 | ~IrdaApplet(); |
31 | 31 | ||
32 | virtual void show ( ); | 32 | virtual void show ( ); |
33 | 33 | ||
34 | protected: | 34 | protected: |
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 | ||
39 | private slots: | 39 | private slots: |
40 | void popupTimeout ( ); | 40 | void popupTimeout ( ); |
41 | void slotMessage( const QCString& , const QByteArray& ); | 41 | void slotMessage( const QCString& , const QByteArray& ); |
42 | 42 | ||
43 | private: | 43 | private: |
44 | void popup( QString message, QString icon = QString::null ); | 44 | void popup( QString message, QString icon = QString::null ); |
45 | 45 | ||
46 | bool checkIrdaStatus ( ); | 46 | bool checkIrdaStatus ( ); |
47 | bool setIrdaStatus ( bool ); | 47 | bool setIrdaStatus ( bool ); |
48 | bool checkIrdaDiscoveryStatus (); | 48 | bool checkIrdaDiscoveryStatus (); |
49 | bool setIrdaDiscoveryStatus ( bool ); | 49 | bool setIrdaDiscoveryStatus ( bool ); |
50 | bool setIrdaReceiveStatus ( bool ); | 50 | bool setIrdaReceiveStatus ( bool ); |
51 | 51 | ||
52 | void showDiscovered(); | 52 | void showDiscovered(); |
53 | 53 | ||
54 | private: | 54 | private: |
55 | QPixmap m_irdaOnPixmap; | 55 | QPixmap m_irdaOnPixmap; |
56 | QPixmap m_irdaOffPixmap; | 56 | QPixmap m_irdaOffPixmap; |
57 | QPixmap m_irdaDiscoveryOnPixmap; | 57 | QPixmap m_irdaDiscoveryOnPixmap; |
58 | QPixmap m_receiveActivePixmap; | 58 | QPixmap m_receiveActivePixmap; |
59 | 59 | ||
60 | bool m_irda_active; | 60 | bool m_irda_active; |
61 | bool m_irda_discovery_active; | 61 | bool m_irda_discovery_active; |
62 | bool m_receive_active; | 62 | bool m_receive_active; |
63 | bool m_receive_state_changed; | 63 | bool m_receive_state_changed; |
64 | 64 | ||
65 | QPopupMenu *m_popup; | 65 | QPopupMenu *m_popup; |
66 | 66 | ||
67 | int m_sockfd; | 67 | int m_sockfd; |
68 | 68 | ||
69 | QMap <QString, QString> m_devices; | 69 | QMap <QString, QString> m_devices; |
70 | 70 | ||
71 | bool m_wasOn; // if IrDa was enabled | 71 | bool m_wasOn; // if IrDa was enabled |
72 | bool m_wasDiscover; | ||
72 | }; | 73 | }; |
73 | 74 | ||
74 | 75 | ||
75 | #endif // __OPIE_IRDA_APPLET_H__ | 76 | #endif // __OPIE_IRDA_APPLET_H__ |