summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/irdaapplet/irda.cpp76
-rw-r--r--core/applets/irdaapplet/irda.h17
2 files changed, 65 insertions, 28 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp
index c3ddff2..84c656f 100644
--- a/core/applets/irdaapplet/irda.cpp
+++ b/core/applets/irdaapplet/irda.cpp
@@ -3,4 +3,5 @@
** Max Reiss <harlekin@handhelds.org> [trivial stuff]
** Robert Griebl <sandman@handhelds.org>
+** Holger Freyther <zecke@handhelds.org> QCOP Interface
**
** This file may be distributed and/or modified under the terms of the
@@ -14,4 +15,6 @@
**********************************************************************/
+#include <qcopchannel_qws.h>
+
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
@@ -42,12 +45,12 @@ IrdaApplet::IrdaApplet ( QWidget *parent, const char *name )
setFixedHeight ( 18 );
setFixedWidth ( 14 );
-
+
m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP );
-
+
m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" );
m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" );
m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" );
m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" );
-
+
m_irda_active = false;
m_irda_discovery_active = false;
@@ -55,4 +58,9 @@ IrdaApplet::IrdaApplet ( QWidget *parent, const char *name )
m_receive_state_changed = false;
m_popup = 0;
+ m_wasOn = false;
+
+ QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this );
+ connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
+ this, SLOT(slotMessage(const QCString&, const QByteArray& ) ) );
}
@@ -71,12 +79,12 @@ IrdaApplet::~IrdaApplet()
void IrdaApplet::popup ( QString message, QString icon )
{
- if ( !m_popup )
+ if ( !m_popup )
m_popup = new QPopupMenu ( this );
m_popup-> clear ( );
-
- if ( icon. isEmpty ( ))
+
+ if ( icon. isEmpty ( ))
m_popup-> insertItem ( message, 0 );
- else
+ else
m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 );
@@ -148,5 +156,5 @@ bool IrdaApplet::setIrdaDiscoveryStatus ( bool d )
if ( discovery. open ( IO_WriteOnly | IO_Raw )) {
- discovery.putch ( d ? '1' : '0' );
+ discovery.putch ( d ? '1' : '0' );
return true;
}
@@ -159,8 +167,8 @@ bool IrdaApplet::setIrdaReceiveStatus ( bool d )
QCopEnvelope e ( "QPE/Obex", "receive(int)" );
e << ( d ? 1 : 0 );
-
+
m_receive_active = d;
m_receive_state_changed = true;
-
+
return true;
}
@@ -179,5 +187,5 @@ void IrdaApplet::showDiscovered ( )
QString discoveredDevice;
QString deviceAddr;
-
+
// since it is /proc we _must_ use QTextStream
QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( ));
@@ -190,5 +198,5 @@ void IrdaApplet::showDiscovered ( )
for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) {
const QString &line = *lit;
-
+
if ( line. startsWith ( "nickname:" )) {
discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 );
@@ -208,14 +216,14 @@ void IrdaApplet::showDiscovered ( )
for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) {
// qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?");
-
+
if ( it. data ( ). left ( 3 ) == "+++" ) {
popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 ));
snd_lost. play ( );
-
+
QMap <QString, QString>::Iterator tmp = it;
tmp++;
m_devices. remove ( it ); // in contrast to QValueListIterator this remove doesn't return the next Iterator
it = tmp;
-
+
qcopsend = true;
}
@@ -226,5 +234,5 @@ void IrdaApplet::showDiscovered ( )
QCopEnvelope e ( "QPE/Network", "irdaSend(bool)" );
e << ( m_devices. count ( ) > 0 );
- // }
+ // }
}
}
@@ -260,5 +268,5 @@ void IrdaApplet::mousePressEvent ( QMouseEvent * )
p = QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ));
-
+
switch ( menu-> exec ( p )) {
case 0:
@@ -275,5 +283,5 @@ void IrdaApplet::mousePressEvent ( QMouseEvent * )
break;
}
-
+
delete menu;
}
@@ -293,8 +301,8 @@ void IrdaApplet::timerEvent ( QTimerEvent * )
m_irda_discovery_active = checkIrdaDiscoveryStatus ( );
- if ( m_irda_discovery_active )
+ if ( m_irda_discovery_active )
showDiscovered ( );
- if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate )
+ if (( m_irda_active != oldactive ) || ( m_irda_discovery_active != olddiscovery ) || receiveUpdate )
update ( );
}
@@ -309,5 +317,31 @@ void IrdaApplet::paintEvent ( QPaintEvent * )
p. drawPixmap( 0, 1, m_irdaDiscoveryOnPixmap );
- if ( m_receive_active )
+ if ( m_receive_active )
p. drawPixmap( 0, 1, m_receiveActivePixmap );
}
+/*
+ * We know 3 calls
+ * a) enable
+ * b) disable
+ * a and b will temp enable the IrDa device and disable will disable it again if it wasn't on
+ * c) listDevices: We will return a list of known devices
+ */
+void IrdaApplet::slotMessage( const QCString& str, const QByteArray& ar ) {
+ if ( str == "enableIrda()") {
+ m_wasOn = checkIrdaStatus();
+ if (!m_wasOn)
+ setIrdaStatus( true );
+ }else if ( str == "disableIrda()") {
+ if (!m_wasOn)
+ setIrdaStatus( false );
+ }else if ( str == "listDevices()") {
+ QCopEnvelope e("QPE/IrDaAppletBack", "devices(QStringList)");
+
+ QStringList list;
+ QMap<QString, QString>::Iterator it;
+ for (it = m_devices.begin(); it != m_devices.end(); ++it )
+ list << (*it);
+
+ e << list;
+ }
+}
diff --git a/core/applets/irdaapplet/irda.h b/core/applets/irdaapplet/irda.h
index 1b5faa6..675f874 100644
--- a/core/applets/irdaapplet/irda.h
+++ b/core/applets/irdaapplet/irda.h
@@ -25,5 +25,5 @@ class IrdaApplet : public QWidget
{
Q_OBJECT
-
+
public:
IrdaApplet( QWidget *parent = 0, const char *name = 0 );
@@ -36,7 +36,8 @@ protected:
virtual void mousePressEvent ( QMouseEvent * );
virtual void paintEvent ( QPaintEvent* );
-
+
private slots:
void popupTimeout ( );
+ void slotMessage( const QCString& , const QByteArray& );
private:
@@ -50,5 +51,5 @@ private:
void showDiscovered();
-
+
private:
QPixmap m_irdaOnPixmap;
@@ -56,15 +57,17 @@ private:
QPixmap m_irdaDiscoveryOnPixmap;
QPixmap m_receiveActivePixmap;
-
- bool m_irda_active;
+
+ bool m_irda_active;
bool m_irda_discovery_active;
bool m_receive_active;
bool m_receive_state_changed;
-
+
QPopupMenu *m_popup;
int m_sockfd;
-
+
QMap <QString, QString> m_devices;
+
+ bool m_wasOn; // if IrDa was enabled
};