Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pyquicklaunch.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@vanille.de>
00003 ** All rights reserved.
00004 **
00005 ** This file may be distributed and/or modified under the terms of the
00006 ** GNU General Public License version 2 as published by the Free Software
00007 ** Foundation and appearing in the file LICENSE.GPL included in the
00008 ** packaging of this file.
00009 **
00010 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 **
00013 **********************************************************************/
00014 
00015 #include "pyquicklaunch.h"
00016 
00017 /* OPIE */
00018 #include <opie2/odebug.h>
00019 #include <opie2/oresource.h>
00020 #include <opie2/otaskbarapplet.h>
00021 #include <qpe/config.h>
00022 #include <qpe/qpeapplication.h>
00023 using namespace Opie::Core;
00024 
00025 /* QT */
00026 #include <qcopchannel_qws.h>
00027 #include <qpainter.h>
00028 #include <qframe.h>
00029 #include <qfile.h>
00030 #include <qtimer.h>
00031 
00032 /* STD */
00033 #include <pwd.h>
00034 #include <sys/types.h>
00035 #include <unistd.h>
00036 
00037 PyQuicklaunchControl::PyQuicklaunchControl( PyQuicklaunchApplet *applet, QWidget *parent, const char *name )
00038         : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
00039 {
00040 
00041     setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
00042     setFixedSize( sizeHint() );
00043     setFocusPolicy( QWidget::NoFocus );
00044 }
00045 
00046 
00047 void PyQuicklaunchControl::show( bool )
00048 {
00049     QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) );
00050 
00051     int w = sizeHint().width();
00052     int x = curPos.x() - ( w / 2 );
00053 
00054     if ( ( x + w ) > QPEApplication::desktop() ->width() )
00055         x = QPEApplication::desktop ( ) -> width ( ) - w;
00056 
00057     move( x, curPos.y () - sizeHint().height () );
00058     QFrame::show();
00059 }
00060 
00061 void PyQuicklaunchControl::readConfig()
00062 {
00063     Config cfg( "qpe" );
00064     cfg.setGroup( "PyQuicklaunch" );
00065 
00066     // ...
00067 }
00068 
00069 void PyQuicklaunchControl::writeConfigEntry( const char *entry, int val )
00070 {
00071     Config cfg( "qpe" );
00072     cfg.setGroup( "PyQuicklaunch" );
00073     cfg.writeEntry( entry, val );
00074 }
00075 
00076 //===========================================================================
00077 
00078 PyQuicklaunchApplet::PyQuicklaunchApplet( QWidget *parent, const char *name )
00079         : QWidget( parent, name ), online( false )
00080 {
00081     setFixedHeight( 18 );
00082     setFixedWidth( 14 );
00083     status = new PyQuicklaunchControl( this, this, "Python Quicklaunch Status" );
00084 
00085     _online = Opie::Core::OResource::loadPixmap( "pyquicklaunch/online", Opie::Core::OResource::SmallIcon );
00086     _offline = Opie::Core::OResource::loadPixmap( "pyquicklaunch/offline", Opie::Core::OResource::SmallIcon );
00087 
00088     _fifoName = QString().sprintf( "/tmp/mickeys-quicklauncher-%s", ::getpwuid( ::getuid() )->pw_name );
00089     odebug << "PyQuicklaunchApplet fifo name = '" << _fifoName << "'" << oendl;
00090     _fifo.setName( _fifoName );
00091 
00092     _control = new QCopChannel( "QPE/PyLauncher", parent, "PyLauncher QCop Control Channel" );
00093     connect( _control, SIGNAL(received(const QCString&,const QByteArray&)),
00094              this, SLOT(receivedMessage(const QCString&,const QByteArray&) ) );
00095 
00096 }
00097 
00098 
00099 PyQuicklaunchApplet::~PyQuicklaunchApplet()
00100 {
00101 }
00102 
00103 
00104 void PyQuicklaunchApplet::receivedMessage( const QCString& msg, const QByteArray& data )
00105 {
00106     odebug << "receivedMessage = '" << msg << "' " << oendl;
00107 
00108     if ( msg == "setOnline()" )
00109     {
00110         online = true;
00111         repaint( true );
00112     }
00113     else if ( msg == "setOffline()" )
00114     {
00115         online = false;
00116         repaint( true );
00117     }
00118     else
00119     {
00120         odebug << "unknown command." << oendl;
00121     }
00122 }
00123 
00124 
00125 void PyQuicklaunchApplet::timerEvent( QTimerEvent* )
00126 {
00127     bool nowOnline = _fifo.exists();
00128     if ( nowOnline != online )
00129     {
00130         online = nowOnline;
00131         repaint( true );
00132     }
00133 }
00134 
00135 
00136 void PyQuicklaunchApplet::mousePressEvent( QMouseEvent * )
00137 {
00138      status->isVisible() ? status->hide() : status->show( true );
00139 }
00140 
00141 
00142 void PyQuicklaunchApplet::paintEvent( QPaintEvent* )
00143 {
00144     QPainter p( this );
00145     p.drawPixmap( 0, 2, online ? _online : _offline );
00146 }
00147 
00148 
00149 int PyQuicklaunchApplet::position()
00150 {
00151     return 6;
00152 }
00153 
00154 EXPORT_OPIE_APPLET_v1( PyQuicklaunchApplet )
00155 

Generated on Sat Nov 5 16:16:45 2005 for OPIE by  doxygen 1.4.2