author | harlekin <harlekin> | 2002-06-23 22:05:53 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-06-23 22:05:53 (UTC) |
commit | 5762bcc7430739798ed9e7869066255cb1998f1a (patch) (side-by-side diff) | |
tree | e55409db7b3519684087918066129f9a5dd6741f /core/applets/irdaapplet | |
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 @@ //=========================================================================== IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { - setFixedHeight( 18 ); + setFixedHeight( 14 ); setFixedWidth( 14 ); sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); @@ -65,12 +65,40 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive"); receiveActive = false; startTimer(5000); timerEvent(NULL); + popupMenu = 0; + devicesAvailable.setAutoDelete(TRUE); } 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(); } int IrdaApplet::checkIrdaStatus() { struct ifreq ifr; @@ -90,12 +118,15 @@ int IrdaApplet::setIrdaStatus(int c) { if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) return -1; - if (c) + if (c) { ifr.ifr_flags |= IFF_UP; - else + } else { + setIrdaDiscoveryStatus(0); + setIrdaReceiveStatus(0); ifr.ifr_flags &= ~IFF_UP; + } if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) return -1; @@ -133,76 +164,131 @@ int IrdaApplet::setIrdaDiscoveryStatus(int d) { return 0; } +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; +} void IrdaApplet::showDiscovered() { QFile discovery("/proc/net/irda/discovery"); if (discovery.open(IO_ReadOnly) ) { + int qcopsend = FALSE; + + QString discoveredDevice; + QString deviceAddr; QStringList list; // since it is /proc we _must_ use QTextStream QTextStream stream ( &discovery); QString streamIn; streamIn = stream.read(); list = QStringList::split("\n", streamIn); + 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) ; + } */ + } } void IrdaApplet::mousePressEvent( QMouseEvent *) { QPopupMenu *menu = new QPopupMenu(); QString cmd; int ret=0; - showDiscovered(); /* Refresh active state */ timerEvent(NULL); // menu->insertItem( tr("More..."), 4 ); + 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(); + } if (irdaactive) { menu->insertItem( tr("Disable IrDA"), 0 ); } else { menu->insertItem( tr("Enable IrDA"), 1 ); } + if (irdaactive) { if (irdaDiscoveryActive) { menu->insertItem( tr("Disable Discovery"), 2 ); } else { menu->insertItem( tr("Enable Discovery"), 3 ); } if( receiveActive ){ - menu->insertItem( tr("Disable Receive"), 5 ); + menu->insertItem( tr("Disable Receive"), 4 ); } else { - menu->insertItem( tr("Enable Receive"), 4 ); + menu->insertItem( tr("Enable Receive"), 5 ); + } } QPoint p = mapToGlobal ( QPoint ( 0, 0 )); QSize s = menu-> sizeHint ( ); ret = menu->exec( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ) ), 0); - qDebug("ret was %d\n", ret); + // qDebug("ret was %d\n", ret); switch(ret) { case 0: setIrdaStatus(0); @@ -220,22 +306,14 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { setIrdaDiscoveryStatus(1); timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l break; case 4: { // enable receive - qWarning("Enable receive" ); - QCopEnvelope e("QPE/Obex", "receive(int)" ); - e << 1; - receiveActive = true; - receiveStateChanged = true; + setIrdaReceiveStatus(0); timerEvent(NULL); break; } case 5: { // disable receive - qWarning("Disable receive" ); - QCopEnvelope e("QPE/Obex", "receive(int)" ); - e << 0; - receiveActive = false; - receiveStateChanged = true; + setIrdaReceiveStatus(1); timerEvent(NULL); break; } case 6: @@ -257,8 +335,13 @@ void IrdaApplet::timerEvent( QTimerEvent * ) { irdaactive = checkIrdaStatus(); irdaDiscoveryActive = checkIrdaDiscoveryStatus(); + + if (irdaDiscoveryActive) { + showDiscovered(); + } + if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { paintEvent(NULL); } @@ -269,16 +352,16 @@ void IrdaApplet::paintEvent( QPaintEvent* ) { qDebug("paint irda pixmap"); p.eraseRect ( 0, 0, this->width(), this->height() ); if (irdaactive > 0) { - p.drawPixmap( 0, 1, irdaOnPixmap ); + p.drawPixmap( 0, 0, irdaOnPixmap ); } else { - p.drawPixmap( 0, 1, irdaOffPixmap ); + p.drawPixmap( 0, 0, irdaOffPixmap ); } 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 @@ -22,9 +22,10 @@ #include <qpixmap.h> #include <qguardedptr.h> #include <qtimer.h> #include <qfile.h> - +#include <qpopupmenu.h> +#include <qdict.h> class IrdaApplet : public QWidget { Q_OBJECT @@ -41,25 +42,27 @@ private: int checkIrdaStatus(); int setIrdaStatus(int); int checkIrdaDiscoveryStatus(); int setIrdaDiscoveryStatus(int); + int setIrdaReceiveStatus(int); void showDiscovered(); int sockfd; +private slots: + void popupTimeout(); + private: QPixmap irdaOnPixmap; QPixmap irdaOffPixmap; QPixmap irdaDiscoveryOnPixmap; QPixmap receiveActivePixmap; - QString discoveredDevice; int irdaactive; // bool and bitfields later bool irdaactive :1 ; int irdaDiscoveryActive; bool receiveActive : 1; bool receiveStateChanged; -private slots: - - + QPopupMenu *popupMenu; + void popup(QString message, QString icon=""); + QDict<QString> devicesAvailable; }; #endif // __SCREENSHOT_APPLET_H__ - |