author | harlekin <harlekin> | 2002-06-23 22:05:53 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-06-23 22:05:53 (UTC) |
commit | 5762bcc7430739798ed9e7869066255cb1998f1a (patch) (unidiff) | |
tree | e55409db7b3519684087918066129f9a5dd6741f | |
parent | 64f2b33735d6df230820af5aa0f47d8db29e6e35 (diff) | |
download | opie-5762bcc7430739798ed9e7869066255cb1998f1a.zip opie-5762bcc7430739798ed9e7869066255cb1998f1a.tar.gz opie-5762bcc7430739798ed9e7869066255cb1998f1a.tar.bz2 |
changes by Bruno David Rodrigues <bruno.rodrigues@litux.org>, like multiple device detection
-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 139 | ||||
-rw-r--r-- | core/applets/irdaapplet/irda.h | 15 |
2 files changed, 120 insertions, 34 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp index d986df4..c0f11c0 100644 --- a/core/applets/irdaapplet/irda.cpp +++ b/core/applets/irdaapplet/irda.cpp | |||
@@ -55,9 +55,9 @@ | |||
55 | //=========================================================================== | 55 | //=========================================================================== |
56 | 56 | ||
57 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | 57 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) |
58 | : QWidget( parent, name ) { | 58 | : QWidget( parent, name ) { |
59 | setFixedHeight( 18 ); | 59 | setFixedHeight( 14 ); |
60 | setFixedWidth( 14 ); | 60 | setFixedWidth( 14 ); |
61 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | 61 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
62 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); | 62 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); |
63 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); | 63 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); |
@@ -65,12 +65,40 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | |||
65 | receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive"); | 65 | receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive"); |
66 | receiveActive = false; | 66 | receiveActive = false; |
67 | startTimer(5000); | 67 | startTimer(5000); |
68 | timerEvent(NULL); | 68 | timerEvent(NULL); |
69 | popupMenu = 0; | ||
70 | devicesAvailable.setAutoDelete(TRUE); | ||
69 | } | 71 | } |
70 | 72 | ||
71 | IrdaApplet::~IrdaApplet() { | 73 | IrdaApplet::~IrdaApplet() { |
72 | close(sockfd); | 74 | close(sockfd); |
75 | if( popupMenu ) { delete popupMenu; } | ||
76 | } | ||
77 | |||
78 | void IrdaApplet::popup(QString message, QString icon="") { | ||
79 | if ( ! popupMenu ) { | ||
80 | popupMenu = new QPopupMenu(); | ||
81 | } | ||
82 | popupMenu->clear(); | ||
83 | if( icon == "" ) { | ||
84 | popupMenu->insertItem( message, 0 ); | ||
85 | } else { | ||
86 | popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon )), | ||
87 | message, 0 ); | ||
88 | } | ||
89 | |||
90 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); | ||
91 | QSize s = popupMenu->sizeHint ( ); | ||
92 | popupMenu->popup( QPoint ( | ||
93 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), | ||
94 | p. y ( ) - s. height ( ) ), 0); | ||
95 | |||
96 | QTimer::singleShot( 2000, this, SLOT(popupTimeout()) ); | ||
97 | } | ||
98 | |||
99 | void IrdaApplet::popupTimeout() { | ||
100 | popupMenu->hide(); | ||
73 | } | 101 | } |
74 | 102 | ||
75 | int IrdaApplet::checkIrdaStatus() { | 103 | int IrdaApplet::checkIrdaStatus() { |
76 | struct ifreq ifr; | 104 | struct ifreq ifr; |
@@ -90,12 +118,15 @@ int IrdaApplet::setIrdaStatus(int c) { | |||
90 | 118 | ||
91 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 119 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
92 | return -1; | 120 | return -1; |
93 | 121 | ||
94 | if (c) | 122 | if (c) { |
95 | ifr.ifr_flags |= IFF_UP; | 123 | ifr.ifr_flags |= IFF_UP; |
96 | else | 124 | } else { |
125 | setIrdaDiscoveryStatus(0); | ||
126 | setIrdaReceiveStatus(0); | ||
97 | ifr.ifr_flags &= ~IFF_UP; | 127 | ifr.ifr_flags &= ~IFF_UP; |
128 | } | ||
98 | 129 | ||
99 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) | 130 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) |
100 | return -1; | 131 | return -1; |
101 | 132 | ||
@@ -133,76 +164,131 @@ int IrdaApplet::setIrdaDiscoveryStatus(int d) { | |||
133 | 164 | ||
134 | return 0; | 165 | return 0; |
135 | } | 166 | } |
136 | 167 | ||
168 | int IrdaApplet::setIrdaReceiveStatus(int d) { | ||
169 | if(d) { | ||
170 | qWarning("Enable receive" ); | ||
171 | QCopEnvelope e("QPE/Obex", "receive(int)" ); | ||
172 | e << 1; | ||
173 | receiveActive = true; | ||
174 | receiveStateChanged = true; | ||
175 | } else { | ||
176 | qWarning("Disable receive" ); | ||
177 | QCopEnvelope e("QPE/Obex", "receive(int)" ); | ||
178 | e << 0; | ||
179 | receiveActive = false; | ||
180 | receiveStateChanged = true; | ||
181 | } | ||
182 | return 0; | ||
183 | } | ||
137 | 184 | ||
138 | void IrdaApplet::showDiscovered() { | 185 | void IrdaApplet::showDiscovered() { |
139 | QFile discovery("/proc/net/irda/discovery"); | 186 | QFile discovery("/proc/net/irda/discovery"); |
140 | 187 | ||
141 | if (discovery.open(IO_ReadOnly) ) { | 188 | if (discovery.open(IO_ReadOnly) ) { |
189 | int qcopsend = FALSE; | ||
190 | |||
191 | QString discoveredDevice; | ||
192 | QString deviceAddr; | ||
142 | QStringList list; | 193 | QStringList list; |
143 | // since it is /proc we _must_ use QTextStream | 194 | // since it is /proc we _must_ use QTextStream |
144 | QTextStream stream ( &discovery); | 195 | QTextStream stream ( &discovery); |
145 | QString streamIn; | 196 | QString streamIn; |
146 | streamIn = stream.read(); | 197 | streamIn = stream.read(); |
147 | list = QStringList::split("\n", streamIn); | 198 | list = QStringList::split("\n", streamIn); |
148 | 199 | ||
200 | QDictIterator<QString> it( devicesAvailable ); | ||
201 | while ( it.current() ) { | ||
202 | devicesAvailable.replace( it.currentKey(), new QString("+++" + *devicesAvailable[it.currentKey()]) ); | ||
203 | //qDebug("IrdaMon: " + it.currentKey()); | ||
204 | //qDebug(" =" + *devicesAvailable[it.currentKey()] ); | ||
205 | ++it; | ||
206 | } | ||
207 | |||
149 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { | 208 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { |
209 | qDebug( (*line) ); | ||
150 | if( (*line).startsWith("nickname:") ){ | 210 | if( (*line).startsWith("nickname:") ){ |
151 | discoveredDevice = (*line).mid(((*line).find(':'))+1,(*line).find(',')-(*line).find(':')-1); | 211 | discoveredDevice = (*line).mid(((*line).find(':'))+2,(*line).find(',')-(*line).find(':')-2); |
152 | qDebug(discoveredDevice); | 212 | deviceAddr = (*line).mid( (*line).find( "daddr:" )+9, 8 ); |
213 | |||
214 | qDebug(discoveredDevice + "(" + deviceAddr + ")"); | ||
215 | |||
216 | if( ! devicesAvailable.find(deviceAddr) ) { | ||
217 | popup( tr("Found:") + " " + discoveredDevice ); | ||
218 | qcopsend = TRUE; | ||
153 | } | 219 | } |
220 | devicesAvailable.replace( deviceAddr, new QString(discoveredDevice) ); | ||
221 | //qDebug("IrdaMon: " + deviceAddr + "=" + *devicesAvailable[deviceAddr] ); | ||
154 | } | 222 | } |
155 | } | 223 | } |
156 | 224 | ||
225 | it.toFirst(); | ||
226 | while ( it.current() ) { | ||
227 | qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?"); | ||
228 | if ( (*it.current()).left(3) == "+++" ) { | ||
229 | popup( tr("Lost:") + " " + (*devicesAvailable[it.currentKey()]).mid(3) ); | ||
230 | devicesAvailable.remove( it.currentKey() ); | ||
231 | qDebug("IrdaMon: delete " + it.currentKey() + "!"); | ||
232 | qcopsend = TRUE; | ||
233 | } | ||
234 | ++it; | ||
235 | } | ||
236 | /* XXX if( qcopsend ) { | ||
237 | QCopEnvelope e("QPE/Network", "irdaSend(bool)" ); | ||
238 | e << (devicesAvailable.count() > 0) ; | ||
239 | } */ | ||
240 | } | ||
157 | } | 241 | } |
158 | 242 | ||
159 | void IrdaApplet::mousePressEvent( QMouseEvent *) { | 243 | void IrdaApplet::mousePressEvent( QMouseEvent *) { |
160 | QPopupMenu *menu = new QPopupMenu(); | 244 | QPopupMenu *menu = new QPopupMenu(); |
161 | QString cmd; | 245 | QString cmd; |
162 | int ret=0; | 246 | int ret=0; |
163 | showDiscovered(); | ||
164 | 247 | ||
165 | /* Refresh active state */ | 248 | /* Refresh active state */ |
166 | timerEvent(NULL); | 249 | timerEvent(NULL); |
167 | 250 | ||
168 | //menu->insertItem( tr("More..."), 4 ); | 251 | //menu->insertItem( tr("More..."), 4 ); |
169 | 252 | ||
253 | if (irdaactive && devicesAvailable.count() > 0) { | ||
170 | menu->insertItem( tr("Discovered Device:"), 9); | 254 | menu->insertItem( tr("Discovered Device:"), 9); |
171 | 255 | ||
172 | if ( !discoveredDevice.isEmpty() ) { | 256 | QDictIterator<QString> it( devicesAvailable ); |
173 | menu->insertItem( discoveredDevice ,7 ); | 257 | while ( it.current() ) { |
174 | } else { | 258 | menu->insertItem( *devicesAvailable[it.currentKey()]); |
175 | menu->insertItem( tr("None"), 8); | 259 | ++it; |
176 | } | 260 | } |
177 | |||
178 | menu->insertSeparator(); | 261 | menu->insertSeparator(); |
262 | } | ||
179 | 263 | ||
180 | if (irdaactive) { | 264 | if (irdaactive) { |
181 | menu->insertItem( tr("Disable IrDA"), 0 ); | 265 | menu->insertItem( tr("Disable IrDA"), 0 ); |
182 | } else { | 266 | } else { |
183 | menu->insertItem( tr("Enable IrDA"), 1 ); | 267 | menu->insertItem( tr("Enable IrDA"), 1 ); |
184 | } | 268 | } |
185 | 269 | ||
270 | if (irdaactive) { | ||
186 | if (irdaDiscoveryActive) { | 271 | if (irdaDiscoveryActive) { |
187 | menu->insertItem( tr("Disable Discovery"), 2 ); | 272 | menu->insertItem( tr("Disable Discovery"), 2 ); |
188 | } else { | 273 | } else { |
189 | menu->insertItem( tr("Enable Discovery"), 3 ); | 274 | menu->insertItem( tr("Enable Discovery"), 3 ); |
190 | } | 275 | } |
191 | 276 | ||
192 | if( receiveActive ){ | 277 | if( receiveActive ){ |
193 | menu->insertItem( tr("Disable Receive"), 5 ); | 278 | menu->insertItem( tr("Disable Receive"), 4 ); |
194 | } else { | 279 | } else { |
195 | menu->insertItem( tr("Enable Receive"), 4 ); | 280 | menu->insertItem( tr("Enable Receive"), 5 ); |
281 | } | ||
196 | } | 282 | } |
197 | 283 | ||
198 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); | 284 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); |
199 | QSize s = menu-> sizeHint ( ); | 285 | QSize s = menu-> sizeHint ( ); |
200 | ret = menu->exec( QPoint ( | 286 | ret = menu->exec( QPoint ( |
201 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), | 287 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), |
202 | p. y ( ) - s. height ( ) ), 0); | 288 | p. y ( ) - s. height ( ) ), 0); |
203 | 289 | ||
204 | qDebug("ret was %d\n", ret); | 290 | // qDebug("ret was %d\n", ret); |
205 | 291 | ||
206 | switch(ret) { | 292 | switch(ret) { |
207 | case 0: | 293 | case 0: |
208 | setIrdaStatus(0); | 294 | setIrdaStatus(0); |
@@ -220,22 +306,14 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { | |||
220 | setIrdaDiscoveryStatus(1); | 306 | setIrdaDiscoveryStatus(1); |
221 | timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l | 307 | timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l |
222 | break; | 308 | break; |
223 | case 4: { // enable receive | 309 | case 4: { // enable receive |
224 | qWarning("Enable receive" ); | 310 | setIrdaReceiveStatus(0); |
225 | QCopEnvelope e("QPE/Obex", "receive(int)" ); | ||
226 | e << 1; | ||
227 | receiveActive = true; | ||
228 | receiveStateChanged = true; | ||
229 | timerEvent(NULL); | 311 | timerEvent(NULL); |
230 | break; | 312 | break; |
231 | } | 313 | } |
232 | case 5: { // disable receive | 314 | case 5: { // disable receive |
233 | qWarning("Disable receive" ); | 315 | setIrdaReceiveStatus(1); |
234 | QCopEnvelope e("QPE/Obex", "receive(int)" ); | ||
235 | e << 0; | ||
236 | receiveActive = false; | ||
237 | receiveStateChanged = true; | ||
238 | timerEvent(NULL); | 316 | timerEvent(NULL); |
239 | break; | 317 | break; |
240 | } | 318 | } |
241 | case 6: | 319 | case 6: |
@@ -257,8 +335,13 @@ void IrdaApplet::timerEvent( QTimerEvent * ) { | |||
257 | 335 | ||
258 | irdaactive = checkIrdaStatus(); | 336 | irdaactive = checkIrdaStatus(); |
259 | irdaDiscoveryActive = checkIrdaDiscoveryStatus(); | 337 | irdaDiscoveryActive = checkIrdaDiscoveryStatus(); |
260 | 338 | ||
339 | |||
340 | if (irdaDiscoveryActive) { | ||
341 | showDiscovered(); | ||
342 | } | ||
343 | |||
261 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { | 344 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { |
262 | paintEvent(NULL); | 345 | paintEvent(NULL); |
263 | } | 346 | } |
264 | 347 | ||
@@ -269,16 +352,16 @@ void IrdaApplet::paintEvent( QPaintEvent* ) { | |||
269 | qDebug("paint irda pixmap"); | 352 | qDebug("paint irda pixmap"); |
270 | 353 | ||
271 | p.eraseRect ( 0, 0, this->width(), this->height() ); | 354 | p.eraseRect ( 0, 0, this->width(), this->height() ); |
272 | if (irdaactive > 0) { | 355 | if (irdaactive > 0) { |
273 | p.drawPixmap( 0, 1, irdaOnPixmap ); | 356 | p.drawPixmap( 0, 0, irdaOnPixmap ); |
274 | } else { | 357 | } else { |
275 | p.drawPixmap( 0, 1, irdaOffPixmap ); | 358 | p.drawPixmap( 0, 0, irdaOffPixmap ); |
276 | } | 359 | } |
277 | 360 | ||
278 | if (irdaDiscoveryActive > 0) { | 361 | if (irdaDiscoveryActive > 0) { |
279 | p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap ); | 362 | p.drawPixmap( 0, 0, irdaDiscoveryOnPixmap ); |
280 | } | 363 | } |
281 | if (receiveActive) { | 364 | if (receiveActive) { |
282 | p.drawPixmap( 0, 1, receiveActivePixmap); | 365 | p.drawPixmap( 0, 0, receiveActivePixmap); |
283 | } | 366 | } |
284 | } | 367 | } |
diff --git a/core/applets/irdaapplet/irda.h b/core/applets/irdaapplet/irda.h index 5822afe..7b37847 100644 --- a/core/applets/irdaapplet/irda.h +++ b/core/applets/irdaapplet/irda.h | |||
@@ -22,9 +22,10 @@ | |||
22 | #include <qpixmap.h> | 22 | #include <qpixmap.h> |
23 | #include <qguardedptr.h> | 23 | #include <qguardedptr.h> |
24 | #include <qtimer.h> | 24 | #include <qtimer.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | 26 | #include <qpopupmenu.h> | |
27 | #include <qdict.h> | ||
27 | 28 | ||
28 | class IrdaApplet : public QWidget | 29 | class IrdaApplet : public QWidget |
29 | { | 30 | { |
30 | Q_OBJECT | 31 | Q_OBJECT |
@@ -41,25 +42,27 @@ private: | |||
41 | int checkIrdaStatus(); | 42 | int checkIrdaStatus(); |
42 | int setIrdaStatus(int); | 43 | int setIrdaStatus(int); |
43 | int checkIrdaDiscoveryStatus(); | 44 | int checkIrdaDiscoveryStatus(); |
44 | int setIrdaDiscoveryStatus(int); | 45 | int setIrdaDiscoveryStatus(int); |
46 | int setIrdaReceiveStatus(int); | ||
45 | void showDiscovered(); | 47 | void showDiscovered(); |
46 | int sockfd; | 48 | int sockfd; |
47 | 49 | ||
50 | private slots: | ||
51 | void popupTimeout(); | ||
52 | |||
48 | private: | 53 | private: |
49 | QPixmap irdaOnPixmap; | 54 | QPixmap irdaOnPixmap; |
50 | QPixmap irdaOffPixmap; | 55 | QPixmap irdaOffPixmap; |
51 | QPixmap irdaDiscoveryOnPixmap; | 56 | QPixmap irdaDiscoveryOnPixmap; |
52 | QPixmap receiveActivePixmap; | 57 | QPixmap receiveActivePixmap; |
53 | QString discoveredDevice; | ||
54 | int irdaactive; // bool and bitfields later bool irdaactive :1 ; | 58 | int irdaactive; // bool and bitfields later bool irdaactive :1 ; |
55 | int irdaDiscoveryActive; | 59 | int irdaDiscoveryActive; |
56 | bool receiveActive : 1; | 60 | bool receiveActive : 1; |
57 | bool receiveStateChanged; | 61 | bool receiveStateChanged; |
58 | private slots: | 62 | QPopupMenu *popupMenu; |
59 | 63 | void popup(QString message, QString icon=""); | |
60 | 64 | QDict<QString> devicesAvailable; | |
61 | }; | 65 | }; |
62 | 66 | ||
63 | 67 | ||
64 | #endif // __SCREENSHOT_APPLET_H__ | 68 | #endif // __SCREENSHOT_APPLET_H__ |
65 | |||