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

taskbarsettings.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the OPIE Project
00003                =.            Copyright (c)  2002 Trolltech AS <info@trolltech.com>
00004              .=l.            Copyright (c)  2002 Robert Griebl <sandman@handhelds.org>
00005            .>+-=
00006  _;:,     .>    :=|.         This file is free software; you can
00007 .> <`_,   >  .   <=          redistribute it and/or modify it under
00008 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00009 .="- .-=="i,     .._         License as published by the Free Software
00010  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00011      ._= =}       :          or (at your option) any later version.
00012     .%`+i>       _;_.
00013     .i_,=:_.      -<s.       This file is distributed in the hope that
00014      +  .  -:.       =       it will be useful, but WITHOUT ANY WARRANTY;
00015     : ..    .:,     . . .    without even the implied warranty of
00016     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00017   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU General
00018 ..}^=.=       =       ;      Public License for more details.
00019 ++=   -.     .`     .:
00020  :     =  ...= . :.=-        You should have received a copy of the GNU
00021  -.   .:....=;==+<;          General Public License along with this file;
00022   -_. . .   )=.  =           see the file COPYING. If not, write to the
00023     --        :-=`           Free Software Foundation, Inc.,
00024                              59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 #include "taskbarsettings.h"
00030 
00031 /* OPIE */
00032 #include <qpe/config.h>
00033 #include <qpe/qlibrary.h>
00034 #include <qpe/qpeapplication.h>
00035 #include <qpe/taskbarappletinterface.h>
00036 #include <qpe/qcopenvelope_qws.h>
00037 #include <opie2/odebug.h>
00038 
00039 /* QT */
00040 #include <qdir.h>
00041 #include <qlistview.h>
00042 #include <qheader.h>
00043 #include <qlayout.h>
00044 #include <qlabel.h>
00045 #include <qwhatsthis.h>
00046 
00047 /* STD */
00048 #include <stdlib.h>
00049 
00050 
00051 TaskbarSettings::TaskbarSettings ( QWidget *parent, const char *name )
00052     : QWidget ( parent, name )
00053 {
00054     m_applets_changed = false;
00055 
00056     QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 );
00057 
00058     QLabel *l = new QLabel ( tr( "Load applets in Taskbar:" ), this );
00059     lay-> addWidget ( l );
00060 
00061     m_list = new QListView ( this );
00062     m_list-> addColumn ( "foobar" );
00063     m_list-> header ( )-> hide ( );
00064 
00065     lay-> addWidget ( m_list );
00066 
00067     QWhatsThis::add ( m_list, tr( "Check the applets that you want displayed in the Taskbar." ));
00068 
00069     connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged()));
00070 
00071     init ( );
00072 }
00073 
00074 void TaskbarSettings::init ( )
00075 {
00076     Config cfg ( "Taskbar" );
00077     cfg. setGroup ( "Applets" );
00078     QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' );
00079 
00080     QString path = QPEApplication::qpeDir ( ) + "plugins/applets";
00081 #ifdef Q_OS_MACX
00082     QStringList list = QDir ( path, "lib*.dylib" ). entryList ( );
00083 #else
00084     QStringList list = QDir ( path, "lib*.so" ). entryList ( );
00085 #endif /* Q_OS_MACX */
00086 
00087     for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) {
00088         QString name;
00089         QPixmap icon;
00090         TaskbarNamedAppletInterface *iface = 0;
00091 
00092         owarn << "Load applet: " << (*it) << "" << oendl;
00093         QLibrary *lib = new QLibrary ( path + "/" + *it );
00094         lib-> queryInterface ( IID_TaskbarNamedApplet, (QUnknownInterface**) &iface );
00095         owarn << "<1>" << oendl;
00096         if ( iface ) {
00097             owarn << "<2>" << oendl;
00098             QString lang = getenv( "LANG" );
00099             QTranslator *trans = new QTranslator ( qApp );
00100             QString type = (*it). left ((*it). find ("."));
00101             QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm";
00102             if ( trans-> load ( tfn ))
00103                 qApp-> installTranslator ( trans );
00104             else
00105                 delete trans;
00106             name = iface-> name ( );
00107             icon = iface-> icon ( );
00108             iface-> release ( );
00109         }
00110         owarn << "<3>" << oendl;
00111         if ( !iface ) {
00112             owarn << "<4>" << oendl;
00113             lib-> queryInterface ( IID_TaskbarApplet, (QUnknownInterface**) &iface );
00114 
00115             if ( iface ) {
00116                 owarn << "<5>" << oendl;
00117                 name = (*it). mid ( 3 );
00118                 owarn << "Found applet: " << name << "" << oendl;
00119 #ifdef Q_OS_MACX
00120                 int sep = name. find( ".dylib" );
00121 #else
00122                 int sep = name. find( ".so" );
00123 #endif /* Q_OS_MACX */
00124                 if ( sep > 0 )
00125                     name. truncate ( sep );
00126                 sep = name. find ( "applet" );
00127                 if ( sep == (int) name.length ( ) - 6 )
00128                     name. truncate ( sep );
00129                 name[0] = name[0]. upper ( );
00130                 iface-> release ( );
00131             }
00132         }
00133         owarn << "<6>" << oendl;
00134 
00135         if ( iface ) {
00136             owarn << "<7>" << oendl;
00137             QCheckListItem *item;
00138             item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox );
00139             if ( !icon. isNull ( ))
00140                 item-> setPixmap ( 0, icon );
00141             item-> setOn ( exclude. find ( *it ) == exclude. end ( ));
00142             m_applets [*it] = item;
00143         }
00144         lib-> unload ( );
00145         delete lib;
00146     }
00147 }
00148 
00149 void TaskbarSettings::appletChanged()
00150 {
00151     m_applets_changed = true;
00152 }
00153 
00154 void TaskbarSettings::accept ( )
00155 {
00156     Config cfg ( "Taskbar" );
00157     cfg. setGroup ( "Applets" );
00158 
00159     if ( m_applets_changed ) {
00160         QStringList exclude;
00161         QMap <QString, QCheckListItem *>::Iterator it;
00162         for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) {
00163             if ( !(*it)-> isOn ( ))
00164                 exclude << it. key ( );
00165         }
00166         cfg. writeEntry ( "ExcludeApplets", exclude, ',' );
00167     }
00168     cfg. writeEntry ( "SafeMode", false );
00169     cfg. write ( );
00170 
00171     if ( m_applets_changed ) {
00172         QCopEnvelope e ( "QPE/TaskBar", "reloadApplets()" );
00173         m_applets_changed = false;
00174     }
00175 }
00176 

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