-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 161 | ||||
-rw-r--r-- | core/applets/irdaapplet/irda.h | 15 |
2 files changed, 131 insertions, 45 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 | |||
@@ -58,3 +58,3 @@ 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 ); |
@@ -68,2 +68,4 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | |||
68 | timerEvent(NULL); | 68 | timerEvent(NULL); |
69 | popupMenu = 0; | ||
70 | devicesAvailable.setAutoDelete(TRUE); | ||
69 | } | 71 | } |
@@ -72,2 +74,28 @@ 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 | } |
@@ -93,6 +121,9 @@ int IrdaApplet::setIrdaStatus(int c) { | |||
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 | ||
@@ -136,2 +167,18 @@ int IrdaApplet::setIrdaDiscoveryStatus(int d) { | |||
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 | ||
@@ -141,2 +188,6 @@ void IrdaApplet::showDiscovered() { | |||
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; |
@@ -148,10 +199,43 @@ void IrdaApplet::showDiscovered() { | |||
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; | ||
219 | } | ||
220 | devicesAvailable.replace( deviceAddr, new QString(discoveredDevice) ); | ||
221 | //qDebug("IrdaMon: " + deviceAddr + "=" + *devicesAvailable[deviceAddr] ); | ||
153 | } | 222 | } |
154 | } | 223 | } |
155 | } | ||
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 | } |
@@ -162,3 +246,2 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { | |||
162 | int ret=0; | 246 | int ret=0; |
163 | showDiscovered(); | ||
164 | 247 | ||
@@ -169,12 +252,13 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { | |||
169 | 252 | ||
170 | menu->insertItem( tr("Discovered Device:"), 9); | 253 | if (irdaactive && devicesAvailable.count() > 0) { |
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; |
260 | } | ||
261 | menu->insertSeparator(); | ||
176 | } | 262 | } |
177 | 263 | ||
178 | menu->insertSeparator(); | ||
179 | |||
180 | if (irdaactive) { | 264 | if (irdaactive) { |
@@ -185,12 +269,14 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { | |||
185 | 269 | ||
186 | if (irdaDiscoveryActive) { | 270 | if (irdaactive) { |
187 | menu->insertItem( tr("Disable Discovery"), 2 ); | 271 | if (irdaDiscoveryActive) { |
188 | } else { | 272 | menu->insertItem( tr("Disable Discovery"), 2 ); |
189 | menu->insertItem( tr("Enable Discovery"), 3 ); | 273 | } else { |
190 | } | 274 | menu->insertItem( tr("Enable Discovery"), 3 ); |
191 | 275 | } | |
192 | if( receiveActive ){ | 276 | |
193 | menu->insertItem( tr("Disable Receive"), 5 ); | 277 | if( receiveActive ){ |
194 | } else { | 278 | menu->insertItem( tr("Disable Receive"), 4 ); |
195 | menu->insertItem( tr("Enable Receive"), 4 ); | 279 | } else { |
280 | menu->insertItem( tr("Enable Receive"), 5 ); | ||
281 | } | ||
196 | } | 282 | } |
@@ -203,3 +289,3 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { | |||
203 | 289 | ||
204 | qDebug("ret was %d\n", ret); | 290 | // qDebug("ret was %d\n", ret); |
205 | 291 | ||
@@ -223,7 +309,3 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { | |||
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); |
@@ -232,7 +314,3 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { | |||
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); |
@@ -260,2 +338,7 @@ void IrdaApplet::timerEvent( QTimerEvent * ) { | |||
260 | 338 | ||
339 | |||
340 | if (irdaDiscoveryActive) { | ||
341 | showDiscovered(); | ||
342 | } | ||
343 | |||
261 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { | 344 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { |
@@ -272,5 +355,5 @@ void IrdaApplet::paintEvent( QPaintEvent* ) { | |||
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 | } |
@@ -278,6 +361,6 @@ void IrdaApplet::paintEvent( QPaintEvent* ) { | |||
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 | } |
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 | |||
@@ -25,3 +25,4 @@ | |||
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | 26 | #include <qpopupmenu.h> | |
27 | #include <qdict.h> | ||
27 | 28 | ||
@@ -44,2 +45,3 @@ private: | |||
44 | int setIrdaDiscoveryStatus(int); | 45 | int setIrdaDiscoveryStatus(int); |
46 | int setIrdaReceiveStatus(int); | ||
45 | void showDiscovered(); | 47 | void showDiscovered(); |
@@ -47,2 +49,5 @@ private: | |||
47 | 49 | ||
50 | private slots: | ||
51 | void popupTimeout(); | ||
52 | |||
48 | private: | 53 | private: |
@@ -52,3 +57,2 @@ private: | |||
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 ; |
@@ -57,5 +61,5 @@ private: | |||
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 | }; |
@@ -64,2 +68 @@ private slots: | |||
64 | #endif // __SCREENSHOT_APPLET_H__ | #endif // __SCREENSHOT_APPLET_H__ | |
65 | |||