summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-05-28 14:08:23 (UTC)
committer mickeyl <mickeyl>2004-05-28 14:08:23 (UTC)
commit130d8d2699232848ff2a89a1ab563f924ca39f4f (patch) (unidiff)
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) (ignore 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 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@vanille.de> 2** Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@vanille.de>
3** All rights reserved. 3** All rights reserved.
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13**********************************************************************/ 13**********************************************************************/
14 14
15#include "pyquicklaunch.h" 15#include "pyquicklaunch.h"
16 16
17/* OPIE */ 17/* OPIE */
18#include <opie2/odebug.h> 18#include <opie2/odebug.h>
19#include <opie2/otaskbarapplet.h> 19#include <opie2/otaskbarapplet.h>
20#include <qpe/qpeapplication.h>
21#include <qpe/config.h> 20#include <qpe/config.h>
21#include <qpe/qpeapplication.h>
22#include <qpe/resource.h>
22using namespace Opie::Core; 23using namespace Opie::Core;
23 24
24/* QT */ 25/* QT */
26#include <qcopchannel_qws.h>
25#include <qpainter.h> 27#include <qpainter.h>
26#include <qframe.h> 28#include <qframe.h>
29#include <qfile.h>
30#include <qtimer.h>
31
32/* STD */
33#include <pwd.h>
34#include <sys/types.h>
35#include <unistd.h>
27 36
28PyQuicklaunchControl::PyQuicklaunchControl( PyQuicklaunchApplet *applet, QWidget *parent, const char *name ) 37PyQuicklaunchControl::PyQuicklaunchControl( PyQuicklaunchApplet *applet, QWidget *parent, const char *name )
29 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) 38 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
30{ 39{
31 40
32 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 41 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
33 setFixedSize( sizeHint() ); 42 setFixedSize( sizeHint() );
34 setFocusPolicy( QWidget::NoFocus ); 43 setFocusPolicy( QWidget::NoFocus );
35} 44}
36 45
37 46
38void PyQuicklaunchControl::show( bool ) 47void PyQuicklaunchControl::show( bool )
39{ 48{
40 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); 49 QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) );
41 50
42 int w = sizeHint().width(); 51 int w = sizeHint().width();
43 int x = curPos.x() - ( w / 2 ); 52 int x = curPos.x() - ( w / 2 );
44 53
45 if ( ( x + w ) > QPEApplication::desktop() ->width() ) 54 if ( ( x + w ) > QPEApplication::desktop() ->width() )
46 x = QPEApplication::desktop ( ) -> width ( ) - w; 55 x = QPEApplication::desktop ( ) -> width ( ) - w;
47 56
48 move( x, curPos.y () - sizeHint().height () ); 57 move( x, curPos.y () - sizeHint().height () );
49 QFrame::show(); 58 QFrame::show();
50} 59}
51 60
52void PyQuicklaunchControl::readConfig() 61void PyQuicklaunchControl::readConfig()
53{ 62{
54 Config cfg( "qpe" ); 63 Config cfg( "qpe" );
55 cfg.setGroup( "PyQuicklaunch" ); 64 cfg.setGroup( "PyQuicklaunch" );
56 65
57 // ... 66 // ...
58} 67}
59 68
60void PyQuicklaunchControl::writeConfigEntry( const char *entry, int val ) 69void PyQuicklaunchControl::writeConfigEntry( const char *entry, int val )
61{ 70{
62 Config cfg( "qpe" ); 71 Config cfg( "qpe" );
63 cfg.setGroup( "PyQuicklaunch" ); 72 cfg.setGroup( "PyQuicklaunch" );
64 cfg.writeEntry( entry, val ); 73 cfg.writeEntry( entry, val );
65} 74}
66 75
67//=========================================================================== 76//===========================================================================
68 77
69PyQuicklaunchApplet::PyQuicklaunchApplet( QWidget *parent, const char *name ) 78PyQuicklaunchApplet::PyQuicklaunchApplet( QWidget *parent, const char *name )
70 : QWidget( parent, name ) 79 : QWidget( parent, name ), online( false )
71{ 80{
72 setFixedHeight( 18 ); 81 setFixedHeight( 18 );
73 setFixedWidth( 14 ); 82 setFixedWidth( 14 );
74 status = new PyQuicklaunchControl( this, this, "Python Quicklaunch Status" ); 83 status = new PyQuicklaunchControl( this, this, "Python Quicklaunch Status" );
84
85 _online = Resource::loadPixmap( "pyquicklaunch/online" );
86 _offline = Resource::loadPixmap( "pyquicklaunch/offline" );
87
88 _fifoName = QString().sprintf( "/tmp/mickeys-quicklauncher-%s", ::getpwuid( ::getuid() )->pw_name );
89 odebug << "PyQuicklaunchApplet fifo name = '" << _fifoName << "'" << oendl;
90 _fifo.setName( _fifoName );
91
92 _control = new QCopChannel( "QPE/PyLauncher", parent, "PyLauncher QCop Control Channel" );
93 connect( _control, SIGNAL(received(const QCString&,const QByteArray&)),
94 this, SLOT(receivedMessage(const QCString&,const QByteArray&) ) );
95
75} 96}
76 97
77 98
78PyQuicklaunchApplet::~PyQuicklaunchApplet() 99PyQuicklaunchApplet::~PyQuicklaunchApplet()
79{} 100{
101}
102
103
104void PyQuicklaunchApplet::receivedMessage( const QCString& msg, const QByteArray& data )
105{
106 odebug << "receivedMessage = '" << msg << "' " << oendl;
107
108 if ( msg == "setOnline()" )
109 {
110 online = true;
111 repaint( true );
112 }
113 else if ( msg == "setOffline()" )
114 {
115 online = false;
116 repaint( true );
117 }
118 else
119 {
120 odebug << "unknown command." << oendl;
121 }
122}
80 123
81 124
82void PyQuicklaunchApplet::timerEvent( QTimerEvent* ) 125void PyQuicklaunchApplet::timerEvent( QTimerEvent* )
83{ 126{
84 // FIXME 127 bool nowOnline = _fifo.exists();
128 if ( nowOnline != online )
129 {
130 online = nowOnline;
131 repaint( true );
132 }
85} 133}
86 134
135
87void PyQuicklaunchApplet::mousePressEvent( QMouseEvent * ) 136void PyQuicklaunchApplet::mousePressEvent( QMouseEvent * )
88{ 137{
89 status->isVisible() ? status->hide() : status->show( true ); 138 status->isVisible() ? status->hide() : status->show( true );
90} 139}
91 140
141
92void PyQuicklaunchApplet::paintEvent( QPaintEvent* ) 142void PyQuicklaunchApplet::paintEvent( QPaintEvent* )
93{ 143{
94 QPainter p( this ); 144 QPainter p( this );
95 int h = height(); 145 p.drawPixmap( 0, 2, online ? _online : _offline );
96 int w = width();
97
98 // FIXME
99
100} 146}
101 147
102 148
103int PyQuicklaunchApplet::position() 149int PyQuicklaunchApplet::position()
104{ 150{
105 return 6; 151 return 6;
106} 152}
107 153
108EXPORT_OPIE_APPLET_v1( PyQuicklaunchApplet ) 154EXPORT_OPIE_APPLET_v1( PyQuicklaunchApplet )
109 155
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 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 2** Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
3** All rights reserved. 3** All rights reserved.
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13**********************************************************************/ 13**********************************************************************/
14 14
15#ifndef PYQUICKLAUNCHAPPLET_H 15#ifndef PYQUICKLAUNCHAPPLET_H
16#define PYQUICKLAUNCHAPPLET_H 16#define PYQUICKLAUNCHAPPLET_H
17 17
18#include <qwidget.h> 18#include <qwidget.h>
19#include <qfile.h>
19#include <qframe.h> 20#include <qframe.h>
20#include <qpixmap.h> 21#include <qpixmap.h>
21 22
22class PyQuicklaunchApplet; 23class PyQuicklaunchApplet;
24class QCopChannel;
23 25
24class PyQuicklaunchControl : public QFrame 26class PyQuicklaunchControl : public QFrame
25{ 27{
26 Q_OBJECT 28 Q_OBJECT
27 public: 29 public:
28 PyQuicklaunchControl( PyQuicklaunchApplet* icon, QWidget *parent=0, const char *name=0 ); 30 PyQuicklaunchControl( PyQuicklaunchApplet* icon, QWidget *parent=0, const char *name=0 );
29 void show( bool ); 31 void show( bool );
30 32
31 void readConfig(); 33 void readConfig();
32 void writeConfigEntry( const char* entry, int val ); 34 void writeConfigEntry( const char* entry, int val );
33 35
34 public slots:
35
36 private: 36 private:
37 PyQuicklaunchApplet* applet; 37 PyQuicklaunchApplet* applet;
38}; 38};
39 39
40class PyQuicklaunchApplet : public QWidget 40class PyQuicklaunchApplet : public QWidget
41{ 41{
42 Q_OBJECT 42 Q_OBJECT
43 public: 43 public:
44 PyQuicklaunchApplet( QWidget *parent = 0, const char *name=0 ); 44 PyQuicklaunchApplet( QWidget *parent = 0, const char *name=0 );
45 ~PyQuicklaunchApplet(); 45 ~PyQuicklaunchApplet();
46 static int position(); 46 static int position();
47 PyQuicklaunchControl* status; 47 PyQuicklaunchControl* status;
48 48
49 virtual void timerEvent( QTimerEvent* ); 49 virtual void timerEvent( QTimerEvent* );
50 bool online;
51
52 public slots:
53 void receivedMessage( const QCString & msg, const QByteArray & data );
50 54
51 protected: 55 protected:
52 virtual void mousePressEvent( QMouseEvent * ); 56 virtual void mousePressEvent( QMouseEvent * );
53 virtual void paintEvent( QPaintEvent* ); 57 virtual void paintEvent( QPaintEvent* );
58
59 private:
60 QCopChannel* _control;
61 QFile _fifo;
62 QString _fifoName;
63 QPixmap _online;
64 QPixmap _offline;
54}; 65};
55 66
56#endif // PYQUICKLAUNCHAPPLET_H 67#endif // PYQUICKLAUNCHAPPLET_H
57 68