summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-05-28 14:08:23 (UTC)
committer mickeyl <mickeyl>2004-05-28 14:08:23 (UTC)
commit130d8d2699232848ff2a89a1ab563f924ca39f4f (patch) (side-by-side diff)
treeb9570735c275c1fa30e93195289e813d97fc24b0
parent8555ba060b1cdfcbfae939b753afc333253c99a0 (diff)
downloadopie-130d8d2699232848ff2a89a1ab563f924ca39f4f.zip
opie-130d8d2699232848ff2a89a1ab563f924ca39f4f.tar.gz
opie-130d8d2699232848ff2a89a1ab563f924ca39f4f.tar.bz2
open communication channel and listen for messages
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/applets/pyquicklaunch/pyquicklaunch.cpp64
-rw-r--r--noncore/applets/pyquicklaunch/pyquicklaunch.h15
2 files changed, 68 insertions, 11 deletions
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
@@ -1,109 +1,155 @@
/**********************************************************************
** Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@vanille.de>
** All rights reserved.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#include "pyquicklaunch.h"
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/otaskbarapplet.h>
-#include <qpe/qpeapplication.h>
#include <qpe/config.h>
+#include <qpe/qpeapplication.h>
+#include <qpe/resource.h>
using namespace Opie::Core;
/* QT */
+#include <qcopchannel_qws.h>
#include <qpainter.h>
#include <qframe.h>
+#include <qfile.h>
+#include <qtimer.h>
+
+/* STD */
+#include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
PyQuicklaunchControl::PyQuicklaunchControl( PyQuicklaunchApplet *applet, QWidget *parent, const char *name )
: QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
{
setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
setFixedSize( sizeHint() );
setFocusPolicy( QWidget::NoFocus );
}
void PyQuicklaunchControl::show( bool )
{
QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) );
int w = sizeHint().width();
int x = curPos.x() - ( w / 2 );
if ( ( x + w ) > QPEApplication::desktop() ->width() )
x = QPEApplication::desktop ( ) -> width ( ) - w;
move( x, curPos.y () - sizeHint().height () );
QFrame::show();
}
void PyQuicklaunchControl::readConfig()
{
Config cfg( "qpe" );
cfg.setGroup( "PyQuicklaunch" );
// ...
}
void PyQuicklaunchControl::writeConfigEntry( const char *entry, int val )
{
Config cfg( "qpe" );
cfg.setGroup( "PyQuicklaunch" );
cfg.writeEntry( entry, 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 );
}
int PyQuicklaunchApplet::position()
{
return 6;
}
EXPORT_OPIE_APPLET_v1( PyQuicklaunchApplet )
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
@@ -1,57 +1,68 @@
/**********************************************************************
** Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
** All rights reserved.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#ifndef PYQUICKLAUNCHAPPLET_H
#define PYQUICKLAUNCHAPPLET_H
#include <qwidget.h>
+#include <qfile.h>
#include <qframe.h>
#include <qpixmap.h>
class PyQuicklaunchApplet;
+class QCopChannel;
class PyQuicklaunchControl : public QFrame
{
Q_OBJECT
public:
PyQuicklaunchControl( PyQuicklaunchApplet* icon, QWidget *parent=0, const char *name=0 );
void show( bool );
void readConfig();
void writeConfigEntry( const char* entry, int val );
- public slots:
-
private:
PyQuicklaunchApplet* applet;
};
class PyQuicklaunchApplet : public QWidget
{
Q_OBJECT
public:
PyQuicklaunchApplet( QWidget *parent = 0, const char *name=0 );
~PyQuicklaunchApplet();
static int position();
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