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

systray.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 #include "systray.h"
00022 
00023 /* OPIE */
00024 #include <opie2/odebug.h>
00025 #include <qtopia/qpeapplication.h>
00026 #include <qtopia/qlibrary.h>
00027 #include <qtopia/config.h>
00028 using namespace Opie::Core;
00029 
00030 /* QT */
00031 #include <qlayout.h>
00032 #include <qdir.h>
00033 
00034 /* STD */
00035 #include <stdlib.h>
00036 
00037 SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0)
00038 {
00039     //setFrameStyle( QFrame::Panel | QFrame::Sunken );
00040     loadApplets();
00041 }
00042 
00043 SysTray::~SysTray()
00044 {
00045     clearApplets();
00046 }
00047 
00048 static int compareAppletPositions(const void *a, const void *b)
00049 {
00050     const TaskbarApplet* aa = *(const TaskbarApplet**)a;
00051     const TaskbarApplet* ab = *(const TaskbarApplet**)b;
00052     int d = ab->iface->position() - aa->iface->position();
00053     if ( d ) return d;
00054     return QString::compare(ab->name,aa->name);
00055 }
00056 
00057 void SysTray::loadApplets()
00058 {
00059     hide();
00060     clearApplets();
00061     addApplets();
00062 }
00063 
00064 void SysTray::clearApplets()
00065 {
00066 #ifndef QT_NO_COMPONENTS
00067 
00068     /*
00069      * Note on clearing. SOme applets delete their
00070      * applets themselves some don't do it
00071      * and on restart this can crash. If we delete it
00072      * here we might end up in a double deletion. We could
00073      * use QGuardedPtr but that would be one QOBject
00074      * for every applet more but only useful for restart
00075      */
00076     QValueList<TaskbarApplet>::Iterator mit;
00077     for ( mit = appletList.begin(); mit != appletList.end(); ++mit ) {
00078         (*mit).iface->release();
00079         (*mit).library->unload();
00080         delete (*mit).library;
00081     }
00082 
00083 #endif
00084     appletList.clear();
00085     if ( layout )
00086         delete layout;
00087     layout = new QHBoxLayout( this, 0, 1 );
00088     layout->setAutoAdd(TRUE);
00089 }
00090 
00091 void SysTray::addApplets()
00092 {
00093     hide();
00094 #ifndef QT_NO_COMPONENTS
00095     Config cfg( "Taskbar" );
00096     cfg.setGroup( "Applets" );
00097     QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
00098 
00099     QString lang = getenv( "LANG" );
00100     QString path = QPEApplication::qpeDir() + "plugins/applets";
00101 #ifdef Q_OS_MACX
00102     QDir dir( path, "lib*.dylib" );
00103 #else
00104     QDir dir( path, "lib*.so" );
00105 #endif /* Q_OS_MACX */
00106     QStringList list = dir.entryList();
00107     QStringList::Iterator it;
00108     int napplets=0;
00109     TaskbarApplet* *applets = new TaskbarApplet*[list.count()];
00110     for ( it = list.begin(); it != list.end(); ++it ) {
00111         if ( exclude.find( *it ) != exclude.end() )
00112             continue;
00113     owarn << "Found Applet: " << (*it) << "" << oendl;
00114         TaskbarAppletInterface *iface = 0;
00115         QLibrary *lib = new QLibrary( path + "/" + *it );
00116         if (( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) {
00117             TaskbarApplet *applet = new TaskbarApplet;
00118             applets[napplets++] = applet;
00119             applet->library = lib;
00120             applet->iface = iface;
00121 
00122             QTranslator *trans = new QTranslator(qApp);
00123             QString type = (*it).left( (*it).find(".") );
00124             QString tfn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+type+".qm";
00125             if ( trans->load( tfn ))
00126                 qApp->installTranslator( trans );
00127             else
00128                 delete trans;
00129         } else {
00130             exclude += *it;
00131             delete lib;
00132         }
00133     }
00134     cfg.writeEntry( "ExcludeApplets", exclude, ',' );
00135     qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions);
00136     while (napplets--) {
00137         TaskbarApplet *applet = applets[napplets];
00138         applet->applet = applet->iface->applet( this );
00139         appletList.append(*applet);
00140     }
00141     delete [] applets;
00142 #else /* ## FIXME single app */
00143     TaskbarApplet * const applet = new TaskbarApplet();
00144     applet->iface = new ClockAppletImpl();
00145     applet->applet = applet->iface->applet( this );
00146     appletList.append( applet );
00147 #endif
00148     show();
00149 }
00150 

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