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

runningappbar.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 ***********************************************************************/
00020 
00021 #define QTOPIA_INTERNAL_PRELOADACCESS
00022 
00023 #include "runningappbar.h"
00024 #include "serverinterface.h"
00025 
00026 /* OPIE */
00027 #include <opie2/odebug.h>
00028 #include <qtopia/qcopenvelope_qws.h>
00029 using namespace Opie::Core;
00030 
00031 /* QT */
00032 #include <qpainter.h>
00033 
00034 /* STD */
00035 #include <stdlib.h>
00036 
00037 RunningAppBar::RunningAppBar(QWidget* parent)
00038   : QFrame(parent), selectedAppIndex(-1)
00039 {
00040     QCopChannel* channel = new QCopChannel( "QPE/System", this );
00041     connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
00042              this, SLOT(received(const QCString&,const QByteArray&)) );
00043 
00044     spacing = AppLnk::smallIconSize()+3;
00045 }
00046 
00047 RunningAppBar::~RunningAppBar()
00048 {
00049 }
00050 
00051 void RunningAppBar::received(const QCString& msg, const QByteArray& data) {
00052     // Since fast apps appear and disappear without disconnecting from their
00053     // channel we need to watch for the showing/hiding events and update according.
00054     QDataStream stream( data, IO_ReadOnly );
00055     if ( msg == "fastAppShowing(QString)") {
00056         QString appName;
00057         stream >> appName;
00058     //    odebug << "fastAppShowing " << appName.data() << "" << oendl;
00059         const AppLnk* f = ServerInterface::appLnks().findExec(appName);
00060         if ( f ) addTask(*f);
00061     } else if ( msg == "fastAppHiding(QString)") {
00062         QString appName;
00063         stream >> appName;
00064         const AppLnk* f = ServerInterface::appLnks().findExec(appName);
00065         if ( f ) removeTask(*f);
00066     }
00067 }
00068 
00069 void RunningAppBar::addTask(const AppLnk& appLnk) {
00070     odebug << "Added " << appLnk.name() << " to app list." << oendl;
00071     AppLnk* newApp = new AppLnk(appLnk);
00072     newApp->setExec(appLnk.exec());
00073     appList.prepend(newApp);
00074     update();
00075 }
00076 
00077 void RunningAppBar::removeTask(const AppLnk& appLnk) {
00078   unsigned int i = 0;
00079   for (; i < appList.count() ; i++) {
00080     AppLnk* target = appList.at(i);
00081     if (target->exec() == appLnk.exec()) {
00082        odebug << "Removing " << appLnk.name() << " from app list." << oendl;
00083       appList.remove();
00084       delete target;
00085     }
00086   }
00087   update();
00088 }
00089 
00090 void RunningAppBar::mousePressEvent(QMouseEvent *e)
00091 {
00092   // Find out if the user is clicking on an app icon...
00093   // If so, snag the index so when we repaint we show it
00094   // as highlighed.
00095   selectedAppIndex = 0;
00096   int x=0;
00097   QListIterator<AppLnk> it( appList );
00098   for ( ; it.current(); ++it,++selectedAppIndex,x+=spacing ) {
00099     if ( x + spacing <= width() ) {
00100       if ( e->x() >= x && e->x() < x+spacing ) {
00101         if ( selectedAppIndex < (int)appList.count() ) {
00102           repaint(FALSE);
00103           return;
00104         }
00105       }
00106     } else {
00107       break;
00108     }
00109   }
00110   selectedAppIndex = -1;
00111   repaint( FALSE );
00112 }
00113 
00114 void RunningAppBar::mouseReleaseEvent(QMouseEvent *e)
00115 {
00116     if (e->button() == QMouseEvent::RightButton)
00117         return;
00118     if ( selectedAppIndex >= 0 ) {
00119         QString app = appList.at(selectedAppIndex)->exec();
00120         QCopEnvelope e("QPE/System", "raise(QString)");
00121         e << app;
00122         selectedAppIndex = -1;
00123         update();
00124     }
00125 }
00126 
00127 void RunningAppBar::paintEvent( QPaintEvent * )
00128 {
00129     QPainter p( this );
00130     AppLnk *curApp;
00131     int x = 0;
00132     int y = (height() - AppLnk::smallIconSize()) / 2;
00133     int i = 0;
00134 
00135     p.fillRect( 0, 0, width(), height(), colorGroup().background() );
00136 
00137     QListIterator<AppLnk> it(appList);
00138 
00139     for (; it.current(); i++, ++it ) {
00140       if ( x + spacing <= width() ) {
00141         curApp = it.current();
00142         owarn << "Drawing " << curApp->name() << "" << oendl;
00143         if ( (int)i == selectedAppIndex )
00144           p.fillRect( x, y, spacing, curApp->pixmap().height()+1, colorGroup().highlight() );
00145         else
00146           p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 );
00147         p.drawPixmap( x, y, curApp->pixmap() );
00148         x += spacing;
00149       }
00150     }
00151 }
00152 
00153 QSize RunningAppBar::sizeHint() const
00154 {
00155     return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 );
00156 }
00157 
00158 void RunningAppBar::applicationLaunched(const QString &appName)
00159 {
00160     odebug << "desktop:: app: " << appName.data() << " launched with pid " << oendl;
00161     const AppLnk* newGuy = ServerInterface::appLnks().findExec(appName);
00162     if ( newGuy && !newGuy->isPreloaded() ) {
00163         addTask( *newGuy );
00164     }
00165 }
00166 
00167 void RunningAppBar::applicationTerminated(const QString &app)
00168 {
00169     const AppLnk* gone = ServerInterface::appLnks().findExec(app);
00170     if ( gone ) {
00171         removeTask(*gone);
00172     }
00173 }
00174 
00175 
00176 

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