-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 @@ -57,5 +57,5 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { - setFixedHeight( 18 ); + setFixedHeight( 14 ); setFixedWidth( 14 ); sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); @@ -67,8 +67,36 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) 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(); } @@ -92,8 +120,11 @@ int IrdaApplet::setIrdaStatus(int c) { 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)) @@ -135,4 +166,20 @@ 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; +} void IrdaApplet::showDiscovered() { @@ -140,4 +187,8 @@ void IrdaApplet::showDiscovered() { if (discovery.open(IO_ReadOnly) ) { + int qcopsend = FALSE; + + QString discoveredDevice; + QString deviceAddr; QStringList list; // since it is /proc we _must_ use QTextStream @@ -147,12 +198,45 @@ void IrdaApplet::showDiscovered() { 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) ; + } */ + } } @@ -161,5 +245,4 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { QString cmd; int ret=0; - showDiscovered(); /* Refresh active state */ @@ -168,14 +251,15 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { // menu->insertItem( tr("More..."), 4 ); - 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) { menu->insertItem( tr("Disable IrDA"), 0 ); @@ -184,14 +268,16 @@ 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 ); + } } @@ -202,5 +288,5 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { p. y ( ) - s. height ( ) ), 0); - qDebug("ret was %d\n", ret); + // qDebug("ret was %d\n", ret); switch(ret) { @@ -222,18 +308,10 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) { 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; @@ -259,4 +337,9 @@ void IrdaApplet::timerEvent( QTimerEvent * ) { irdaDiscoveryActive = checkIrdaDiscoveryStatus(); + + if (irdaDiscoveryActive) { + showDiscovered(); + } + if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { paintEvent(NULL); @@ -271,14 +354,14 @@ void IrdaApplet::paintEvent( QPaintEvent* ) { 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 @@ -24,5 +24,6 @@ #include <qtimer.h> #include <qfile.h> - +#include <qpopupmenu.h> +#include <qdict.h> class IrdaApplet : public QWidget @@ -43,7 +44,11 @@ private: int checkIrdaDiscoveryStatus(); int setIrdaDiscoveryStatus(int); + int setIrdaReceiveStatus(int); void showDiscovered(); int sockfd; +private slots: + void popupTimeout(); + private: QPixmap irdaOnPixmap; @@ -51,15 +56,13 @@ private: 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__ - |