00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "systray.h"
00022
00023
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
00031 #include <qlayout.h>
00032 #include <qdir.h>
00033
00034
00035 #include <stdlib.h>
00036
00037 SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0)
00038 {
00039
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
00070
00071
00072
00073
00074
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
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
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