summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-06-23 22:05:53 (UTC)
committer harlekin <harlekin>2002-06-23 22:05:53 (UTC)
commit5762bcc7430739798ed9e7869066255cb1998f1a (patch) (side-by-side diff)
treee55409db7b3519684087918066129f9a5dd6741f
parent64f2b33735d6df230820af5aa0f47d8db29e6e35 (diff)
downloadopie-5762bcc7430739798ed9e7869066255cb1998f1a.zip
opie-5762bcc7430739798ed9e7869066255cb1998f1a.tar.gz
opie-5762bcc7430739798ed9e7869066255cb1998f1a.tar.bz2
changes by Bruno David Rodrigues <bruno.rodrigues@litux.org>, like multiple device detection
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/irdaapplet/irda.cpp161
-rw-r--r--core/applets/irdaapplet/irda.h15
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 )
: QWidget( parent, name ) {
- setFixedHeight( 18 );
+ setFixedHeight( 14 );
setFixedWidth( 14 );
@@ -68,2 +68,4 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name )
timerEvent(NULL);
+ popupMenu = 0;
+ devicesAvailable.setAutoDelete(TRUE);
}
@@ -72,2 +74,28 @@ IrdaApplet::~IrdaApplet() {
close(sockfd);
+ if( popupMenu ) { delete popupMenu; }
+}
+
+void IrdaApplet::popup(QString message, QString icon="") {
+ if ( ! popupMenu ) {
+ popupMenu = new QPopupMenu();
+ }
+ popupMenu->clear();
+ if( icon == "" ) {
+ popupMenu->insertItem( message, 0 );
+ } else {
+ popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon )),
+ message, 0 );
+ }
+
+ QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
+ QSize s = popupMenu->sizeHint ( );
+ popupMenu->popup( QPoint (
+ p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
+ p. y ( ) - s. height ( ) ), 0);
+
+ QTimer::singleShot( 2000, this, SLOT(popupTimeout()) );
+}
+
+void IrdaApplet::popupTimeout() {
+ popupMenu->hide();
}
@@ -93,6 +121,9 @@ int IrdaApplet::setIrdaStatus(int c) {
- if (c)
+ if (c) {
ifr.ifr_flags |= IFF_UP;
- else
+ } else {
+ setIrdaDiscoveryStatus(0);
+ setIrdaReceiveStatus(0);
ifr.ifr_flags &= ~IFF_UP;
+ }
@@ -136,2 +167,18 @@ int IrdaApplet::setIrdaDiscoveryStatus(int d) {
+int IrdaApplet::setIrdaReceiveStatus(int d) {
+ if(d) {
+ qWarning("Enable receive" );
+ QCopEnvelope e("QPE/Obex", "receive(int)" );
+ e << 1;
+ receiveActive = true;
+ receiveStateChanged = true;
+ } else {
+ qWarning("Disable receive" );
+ QCopEnvelope e("QPE/Obex", "receive(int)" );
+ e << 0;
+ receiveActive = false;
+ receiveStateChanged = true;
+ }
+ return 0;
+}
@@ -141,2 +188,6 @@ void IrdaApplet::showDiscovered() {
if (discovery.open(IO_ReadOnly) ) {
+ int qcopsend = FALSE;
+
+ QString discoveredDevice;
+ QString deviceAddr;
QStringList list;
@@ -148,10 +199,43 @@ void IrdaApplet::showDiscovered() {
+ QDictIterator<QString> it( devicesAvailable );
+ while ( it.current() ) {
+ devicesAvailable.replace( it.currentKey(), new QString("+++" + *devicesAvailable[it.currentKey()]) );
+ //qDebug("IrdaMon: " + it.currentKey());
+ //qDebug(" =" + *devicesAvailable[it.currentKey()] );
+ ++it;
+ }
+
for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
+ qDebug( (*line) );
if( (*line).startsWith("nickname:") ){
- discoveredDevice = (*line).mid(((*line).find(':'))+1,(*line).find(',')-(*line).find(':')-1);
- qDebug(discoveredDevice);
+ discoveredDevice = (*line).mid(((*line).find(':'))+2,(*line).find(',')-(*line).find(':')-2);
+ deviceAddr = (*line).mid( (*line).find( "daddr:" )+9, 8 );
+
+ qDebug(discoveredDevice + "(" + deviceAddr + ")");
+
+ if( ! devicesAvailable.find(deviceAddr) ) {
+ popup( tr("Found:") + " " + discoveredDevice );
+ qcopsend = TRUE;
+ }
+ devicesAvailable.replace( deviceAddr, new QString(discoveredDevice) );
+ //qDebug("IrdaMon: " + deviceAddr + "=" + *devicesAvailable[deviceAddr] );
}
}
- }
+ it.toFirst();
+ while ( it.current() ) {
+ qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?");
+ if ( (*it.current()).left(3) == "+++" ) {
+ popup( tr("Lost:") + " " + (*devicesAvailable[it.currentKey()]).mid(3) );
+ devicesAvailable.remove( it.currentKey() );
+ qDebug("IrdaMon: delete " + it.currentKey() + "!");
+ qcopsend = TRUE;
+ }
+ ++it;
+ }
+ /* XXX if( qcopsend ) {
+ QCopEnvelope e("QPE/Network", "irdaSend(bool)" );
+ e << (devicesAvailable.count() > 0) ;
+ } */
+ }
}
@@ -162,3 +246,2 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) {
int ret=0;
- showDiscovered();
@@ -169,12 +252,13 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) {
- menu->insertItem( tr("Discovered Device:"), 9);
+ if (irdaactive && devicesAvailable.count() > 0) {
+ menu->insertItem( tr("Discovered Device:"), 9);
- if ( !discoveredDevice.isEmpty() ) {
- menu->insertItem( discoveredDevice ,7 );
- } else {
- menu->insertItem( tr("None"), 8);
+ QDictIterator<QString> it( devicesAvailable );
+ while ( it.current() ) {
+ menu->insertItem( *devicesAvailable[it.currentKey()]);
+ ++it;
+ }
+ menu->insertSeparator();
}
- menu->insertSeparator();
-
if (irdaactive) {
@@ -185,12 +269,14 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) {
- if (irdaDiscoveryActive) {
- menu->insertItem( tr("Disable Discovery"), 2 );
- } else {
- menu->insertItem( tr("Enable Discovery"), 3 );
- }
-
- if( receiveActive ){
- menu->insertItem( tr("Disable Receive"), 5 );
- } else {
- menu->insertItem( tr("Enable Receive"), 4 );
+ if (irdaactive) {
+ if (irdaDiscoveryActive) {
+ menu->insertItem( tr("Disable Discovery"), 2 );
+ } else {
+ menu->insertItem( tr("Enable Discovery"), 3 );
+ }
+
+ if( receiveActive ){
+ menu->insertItem( tr("Disable Receive"), 4 );
+ } else {
+ menu->insertItem( tr("Enable Receive"), 5 );
+ }
}
@@ -203,3 +289,3 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) {
- qDebug("ret was %d\n", ret);
+ // qDebug("ret was %d\n", ret);
@@ -223,7 +309,3 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) {
case 4: { // enable receive
- qWarning("Enable receive" );
- QCopEnvelope e("QPE/Obex", "receive(int)" );
- e << 1;
- receiveActive = true;
- receiveStateChanged = true;
+ setIrdaReceiveStatus(0);
timerEvent(NULL);
@@ -232,7 +314,3 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) {
case 5: { // disable receive
- qWarning("Disable receive" );
- QCopEnvelope e("QPE/Obex", "receive(int)" );
- e << 0;
- receiveActive = false;
- receiveStateChanged = true;
+ setIrdaReceiveStatus(1);
timerEvent(NULL);
@@ -260,2 +338,7 @@ void IrdaApplet::timerEvent( QTimerEvent * ) {
+
+ if (irdaDiscoveryActive) {
+ showDiscovered();
+ }
+
if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) {
@@ -272,5 +355,5 @@ void IrdaApplet::paintEvent( QPaintEvent* ) {
if (irdaactive > 0) {
- p.drawPixmap( 0, 1, irdaOnPixmap );
+ p.drawPixmap( 0, 0, irdaOnPixmap );
} else {
- p.drawPixmap( 0, 1, irdaOffPixmap );
+ p.drawPixmap( 0, 0, irdaOffPixmap );
}
@@ -278,6 +361,6 @@ void IrdaApplet::paintEvent( QPaintEvent* ) {
if (irdaDiscoveryActive > 0) {
- p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap );
+ p.drawPixmap( 0, 0, irdaDiscoveryOnPixmap );
}
if (receiveActive) {
- p.drawPixmap( 0, 1, receiveActivePixmap);
+ p.drawPixmap( 0, 0, receiveActivePixmap);
}
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 @@
#include <qfile.h>
-
+#include <qpopupmenu.h>
+#include <qdict.h>
@@ -44,2 +45,3 @@ private:
int setIrdaDiscoveryStatus(int);
+ int setIrdaReceiveStatus(int);
void showDiscovered();
@@ -47,2 +49,5 @@ private:
+private slots:
+ void popupTimeout();
+
private:
@@ -52,3 +57,2 @@ private:
QPixmap receiveActivePixmap;
- QString discoveredDevice;
int irdaactive; // bool and bitfields later bool irdaactive :1 ;
@@ -57,5 +61,5 @@ private:
bool receiveStateChanged;
-private slots:
-
-
+ QPopupMenu *popupMenu;
+ void popup(QString message, QString icon="");
+ QDict<QString> devicesAvailable;
};
@@ -64,2 +68 @@ private slots:
#endif // __SCREENSHOT_APPLET_H__
-