summaryrefslogtreecommitdiff
path: root/core/settings/launcher/taskbarsettings.cpp
Unidiff
Diffstat (limited to 'core/settings/launcher/taskbarsettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/launcher/taskbarsettings.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/core/settings/launcher/taskbarsettings.cpp b/core/settings/launcher/taskbarsettings.cpp
new file mode 100644
index 0000000..8f16951
--- a/dev/null
+++ b/core/settings/launcher/taskbarsettings.cpp
@@ -0,0 +1,169 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "taskbarsettings.h"
22
23#include <qpe/config.h>
24#include <qpe/qlibrary.h>
25#include <qpe/qpeapplication.h>
26#include <qpe/taskbarappletinterface.h>
27#include <qpe/qcopenvelope_qws.h>
28
29#include <qdir.h>
30#include <qlistview.h>
31#include <qcheckbox.h>
32#include <qheader.h>
33#include <qlayout.h>
34#include <qlabel.h>
35#include <qwhatsthis.h>
36
37#include <stdlib.h>
38
39
40TaskbarSettings::TaskbarSettings ( QWidget *parent, const char *name )
41 : QWidget ( parent, name )
42{
43 m_applets_changed = false;
44
45 QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 );
46
47 QLabel *l = new QLabel ( tr( "Load applets:" ), this );
48 lay-> addWidget ( l );
49
50 m_list = new QListView ( this );
51 m_list-> addColumn ( "foobar" );
52 m_list-> header ( )-> hide ( );
53
54 lay-> addWidget ( m_list );
55
56 m_omenu = new QCheckBox ( tr( "Show O-Menu" ), this );
57 lay-> addWidget ( m_omenu );
58
59 m_omenu_tabs = new QCheckBox ( tr( "Show Launcher tabs in O-Menu" ), this );
60 lay-> addWidget ( m_omenu_tabs );
61
62 QWhatsThis::add ( m_list, tr( "Check the applets that you want displayed in the Taskbar." ));
63 QWhatsThis::add( m_omenu_tabs, tr( "Adds the contents of the Launcher as menus in the O-Menu." ));
64 QWhatsThis::add( m_omenu, tr( "Check if you want the O-Menu in the taskbar." ));
65
66 connect ( m_list, SIGNAL( clicked ( QListViewItem * )), this, SLOT( appletChanged ( )));
67 connect ( m_omenu, SIGNAL( toggled ( bool )), m_omenu_tabs, SLOT( setEnabled ( bool )));
68
69 // This option does not make sense ! (sandman)
70 m_omenu_tabs-> hide ( );
71
72 init ( );
73}
74
75void TaskbarSettings::init ( )
76{
77 Config cfg ( "Taskbar" );
78 cfg. setGroup ( "Applets" );
79 QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' );
80
81 QString path = QPEApplication::qpeDir ( ) + "/plugins/applets";
82 QStringList list = QDir ( path, "lib*.so" ). entryList ( );
83
84 for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) {
85 QString name;
86 QPixmap icon;
87 TaskbarNamedAppletInterface *iface = 0;
88
89 QLibrary *lib = new QLibrary ( path + "/" + *it );
90 lib-> queryInterface ( IID_TaskbarNamedApplet, (QUnknownInterface**) &iface );
91 if ( iface ) {
92 QString lang = getenv( "LANG" );
93 QTranslator *trans = new QTranslator ( qApp );
94 QString type = (*it). left ((*it). find ("."));
95 QString tfn = QPEApplication::qpeDir ( ) + "/i18n/" + lang + "/" + type + ".qm";
96 if ( trans-> load ( tfn ))
97 qApp-> installTranslator ( trans );
98 else
99 delete trans;
100 name = iface-> name ( );
101 icon = iface-> icon ( );
102 iface-> release ( );
103 lib-> unload ( );
104 } else {
105 delete lib;
106 name = (*it). mid ( 3 );
107 int sep = name. find( ".so" );
108 if ( sep > 0 )
109 name. truncate ( sep );
110 sep = name. find ( "applet" );
111 if ( sep == (int) name.length ( ) - 6 )
112 name. truncate ( sep );
113 name[0] = name[0]. upper ( );
114 }
115 QCheckListItem *item;
116 item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox );
117 if ( !icon. isNull ( ))
118 item-> setPixmap ( 0, icon );
119 item-> setOn ( exclude. find ( *it ) == exclude. end ( ));
120 m_applets [*it] = item;
121 }
122
123 cfg. setGroup ( "Menu" );
124
125 m_omenu_tabs-> setChecked ( cfg. readBoolEntry ( "LauncherTabs", true ));
126 m_omenu-> setChecked ( cfg. readBoolEntry ( "ShowMenu", true ));
127
128 m_omenu_tabs-> setEnabled ( m_omenu-> isChecked ( ));
129}
130
131void TaskbarSettings::appletChanged()
132{
133 m_applets_changed = true;
134}
135
136void TaskbarSettings::accept ( )
137{
138 Config cfg ( "Taskbar" );
139 cfg. setGroup ( "Applets" );
140 if ( m_applets_changed ) {
141 QStringList exclude;
142 QMap <QString, QCheckListItem *>::Iterator it;
143 for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) {
144 if ( !(*it)-> isOn ( ))
145 exclude << it. key ( );
146 }
147 cfg. writeEntry ( "ExcludeApplets", exclude, ',' );
148 }
149 cfg. writeEntry ( "SafeMode", false );
150
151 cfg. setGroup ( "Menu" );
152
153 if ( m_omenu_tabs-> isChecked ( ) != cfg. readBoolEntry ( "LauncherTabs", true )) {
154 m_applets_changed = true;
155 cfg. writeEntry ( "LauncherTabs", m_omenu_tabs-> isChecked ( ));
156 }
157
158 if ( m_omenu-> isChecked ( ) != cfg. readBoolEntry ( "ShowMenu", true )) {
159 m_applets_changed = true;
160 cfg. writeEntry ( "ShowMenu", m_omenu-> isChecked ( ));
161 }
162 cfg. write ( );
163
164 if ( m_applets_changed ) {
165 QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" );
166 m_applets_changed = false;
167 }
168}
169