From 130d8d2699232848ff2a89a1ab563f924ca39f4f Mon Sep 17 00:00:00 2001 From: mickeyl Date: Fri, 28 May 2004 14:08:23 +0000 Subject: open communication channel and listen for messages --- (limited to 'noncore') diff --git a/noncore/applets/pyquicklaunch/pyquicklaunch.cpp b/noncore/applets/pyquicklaunch/pyquicklaunch.cpp index 2ee8e17..bcd2f0d 100644 --- a/noncore/applets/pyquicklaunch/pyquicklaunch.cpp +++ b/noncore/applets/pyquicklaunch/pyquicklaunch.cpp @@ -17,13 +17,22 @@ /* OPIE */ #include #include -#include #include +#include +#include using namespace Opie::Core; /* QT */ +#include #include #include +#include +#include + +/* STD */ +#include +#include +#include PyQuicklaunchControl::PyQuicklaunchControl( PyQuicklaunchApplet *applet, QWidget *parent, const char *name ) : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) @@ -67,36 +76,73 @@ void PyQuicklaunchControl::writeConfigEntry( const char *entry, int val ) //=========================================================================== PyQuicklaunchApplet::PyQuicklaunchApplet( QWidget *parent, const char *name ) - : QWidget( parent, name ) + : QWidget( parent, name ), online( false ) { setFixedHeight( 18 ); setFixedWidth( 14 ); status = new PyQuicklaunchControl( this, this, "Python Quicklaunch Status" ); + + _online = Resource::loadPixmap( "pyquicklaunch/online" ); + _offline = Resource::loadPixmap( "pyquicklaunch/offline" ); + + _fifoName = QString().sprintf( "/tmp/mickeys-quicklauncher-%s", ::getpwuid( ::getuid() )->pw_name ); + odebug << "PyQuicklaunchApplet fifo name = '" << _fifoName << "'" << oendl; + _fifo.setName( _fifoName ); + + _control = new QCopChannel( "QPE/PyLauncher", parent, "PyLauncher QCop Control Channel" ); + connect( _control, SIGNAL(received(const QCString&,const QByteArray&)), + this, SLOT(receivedMessage(const QCString&,const QByteArray&) ) ); + } PyQuicklaunchApplet::~PyQuicklaunchApplet() -{} +{ +} + + +void PyQuicklaunchApplet::receivedMessage( const QCString& msg, const QByteArray& data ) +{ + odebug << "receivedMessage = '" << msg << "' " << oendl; + + if ( msg == "setOnline()" ) + { + online = true; + repaint( true ); + } + else if ( msg == "setOffline()" ) + { + online = false; + repaint( true ); + } + else + { + odebug << "unknown command." << oendl; + } +} void PyQuicklaunchApplet::timerEvent( QTimerEvent* ) { - // FIXME + bool nowOnline = _fifo.exists(); + if ( nowOnline != online ) + { + online = nowOnline; + repaint( true ); + } } + void PyQuicklaunchApplet::mousePressEvent( QMouseEvent * ) { status->isVisible() ? status->hide() : status->show( true ); } + void PyQuicklaunchApplet::paintEvent( QPaintEvent* ) { QPainter p( this ); - int h = height(); - int w = width(); - - // FIXME - + p.drawPixmap( 0, 2, online ? _online : _offline ); } diff --git a/noncore/applets/pyquicklaunch/pyquicklaunch.h b/noncore/applets/pyquicklaunch/pyquicklaunch.h index e99f780..f108b43 100644 --- a/noncore/applets/pyquicklaunch/pyquicklaunch.h +++ b/noncore/applets/pyquicklaunch/pyquicklaunch.h @@ -16,10 +16,12 @@ #define PYQUICKLAUNCHAPPLET_H #include +#include #include #include class PyQuicklaunchApplet; +class QCopChannel; class PyQuicklaunchControl : public QFrame { @@ -31,8 +33,6 @@ class PyQuicklaunchControl : public QFrame void readConfig(); void writeConfigEntry( const char* entry, int val ); - public slots: - private: PyQuicklaunchApplet* applet; }; @@ -47,10 +47,21 @@ class PyQuicklaunchApplet : public QWidget PyQuicklaunchControl* status; virtual void timerEvent( QTimerEvent* ); + bool online; + + public slots: + void receivedMessage( const QCString & msg, const QByteArray & data ); protected: virtual void mousePressEvent( QMouseEvent * ); virtual void paintEvent( QPaintEvent* ); + + private: + QCopChannel* _control; + QFile _fifo; + QString _fifoName; + QPixmap _online; + QPixmap _offline; }; #endif // PYQUICKLAUNCHAPPLET_H -- cgit v0.9.0.2