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

menusettings.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 "menusettings.h"
00030 
00031 #include <qpe/config.h>
00032 #include <qpe/qlibrary.h>
00033 #include <qpe/qpeapplication.h>
00034 #include <qpe/menuappletinterface.h>
00035 #include <qpe/qcopenvelope_qws.h>
00036 
00037 #include <qdir.h>
00038 #include <qlistview.h>
00039 #include <qcheckbox.h>
00040 #include <qheader.h>
00041 #include <qlayout.h>
00042 #include <qlabel.h>
00043 #include <qwhatsthis.h>
00044 
00045 #include <stdlib.h>
00046 
00047 
00048 MenuSettings::MenuSettings ( QWidget *parent, const char *name )
00049         : QWidget ( parent, name )
00050 {
00051         m_applets_changed = false;
00052 
00053         QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 );
00054 
00055         QLabel *l = new QLabel ( tr( "Load applets in O-Menu:" ), this );
00056         lay-> addWidget ( l );
00057 
00058         m_list = new QListView ( this );
00059         m_list-> addColumn ( "foobar" );
00060         m_list-> header ( )-> hide ( );
00061 
00062         lay-> addWidget ( m_list );
00063 
00064         m_menutabs = new QCheckBox ( tr( "Show Launcher tabs in O-Menu" ), this );
00065         lay-> addWidget ( m_menutabs );
00066 
00067         m_menusubpopup = new QCheckBox ( tr( "Show Applications in Subpopups" ), this );
00068         lay-> addWidget ( m_menusubpopup );
00069 
00070         QWhatsThis::add ( m_list, tr( "Check the applets that you want to have included in the O-Menu." ));
00071         QWhatsThis::add ( m_menutabs, tr( "Adds the contents of the Launcher Tabs as menus in the O-Menu." ));
00072 
00073         connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged()));
00074 
00075         init ( );
00076 }
00077 
00078 void MenuSettings::init ( )
00079 {
00080         Config cfg ( "StartMenu" );
00081         cfg. setGroup ( "Applets" );
00082         QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' );
00083 
00084         QString path = QPEApplication::qpeDir ( ) + "plugins/applets";
00085 #ifdef Q_OS_MACX
00086         QStringList list = QDir ( path, "lib*.dylib" ). entryList ( );
00087 #else
00088         QStringList list = QDir ( path, "lib*.so" ). entryList ( );
00089 #endif /* Q_OS_MACX */
00090 
00091         for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) {
00092                 QString name;
00093                 QPixmap icon;
00094                 MenuAppletInterface *iface = 0;
00095 
00096                 QLibrary *lib = new QLibrary ( path + "/" + *it );
00097                 lib-> queryInterface ( IID_MenuApplet, (QUnknownInterface**) &iface );
00098         if ( iface ) {
00099                         QString lang = getenv( "LANG" );
00100                         QTranslator *trans = new QTranslator ( qApp );
00101                         QString type = (*it). left ((*it). find ("."));
00102                         QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm";
00103                         if ( trans-> load ( tfn ))
00104                                 qApp-> installTranslator ( trans );
00105                         else
00106                                 delete trans;
00107                         name = iface-> name ( );
00108                         icon = iface-> icon ( ). pixmap ();
00109                         iface-> release ( );
00110                         lib-> unload ( );
00111 
00112                         QCheckListItem *item;
00113                         item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox );
00114                         if ( !icon. isNull ( ))
00115                                 item-> setPixmap ( 0, icon );
00116                         item-> setOn ( exclude. find ( *it ) == exclude. end ( ));
00117                         m_applets [*it] = item;
00118                 } else {
00119                         delete lib;
00120                 }
00121         }
00122 
00123         cfg. setGroup ( "Menu" );
00124         m_menutabs->setChecked( cfg.readBoolEntry( "LauncherTabs", true ) );
00125         m_menusubpopup->setChecked( cfg.readBoolEntry( "LauncherSubPopup", true ) );
00126         m_menusubpopup->setEnabled( m_menutabs->isChecked() );
00127         connect( m_menutabs, SIGNAL( stateChanged(int) ), m_menusubpopup, SLOT( setEnabled(bool) ) );
00128 
00129 }
00130 
00131 void MenuSettings::appletChanged()
00132 {
00133         m_applets_changed = true;
00134 }
00135 
00136 void MenuSettings::accept ( )
00137 {
00138         bool apps_changed = false;
00139 
00140         Config cfg ( "StartMenu" );
00141         cfg. setGroup ( "Applets" );
00142         if ( m_applets_changed ) {
00143                 QStringList exclude;
00144                 QMap <QString, QCheckListItem *>::Iterator it;
00145                 for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) {
00146                         if ( !(*it)-> isOn ( ))
00147                                 exclude << it. key ( );
00148                 }
00149                 cfg. writeEntry ( "ExcludeApplets", exclude, ',' );
00150         }
00151         cfg. writeEntry ( "SafeMode", false );
00152 
00153         cfg. setGroup ( "Menu" );
00154 
00155         if ( m_menutabs-> isChecked ( ) != cfg. readBoolEntry ( "LauncherTabs", true )) {
00156                 apps_changed = true;
00157                 cfg. writeEntry ( "LauncherTabs", m_menutabs-> isChecked ( ));
00158         }
00159 
00160                 if ( m_menusubpopup-> isChecked ( ) != cfg. readBoolEntry ( "LauncherSubPopup", true )) {
00161                  apps_changed = true;
00162                 cfg. writeEntry ( "LauncherSubPopup", m_menusubpopup-> isChecked ( ));
00163         }
00164 
00165         cfg. write ( );
00166 
00167         if ( m_applets_changed ) {
00168                 QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" );
00169                 m_applets_changed = false;
00170         }
00171         if ( apps_changed ) {
00172                                  // currently use reloadApplets() since reloadApps is now used exclusive for server
00173                                  // to refresh the tabs. But what we want here is also a refresh of the startmenu entries
00174                 QCopEnvelope ( "QPE/TaskBar", "reloadApps()" );
00175                                 QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" );
00176         }
00177 }
00178 

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