~ubuntu-branches/ubuntu/warty/kdebase/warty

« back to all changes in this revision

Viewing changes to kcontrol/kicker/applettab_impl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-09-16 04:51:45 UTC
  • Revision ID: james.westby@ubuntu.com-20040916045145-9vr63kith3k1cpza
Tags: upstream-3.2.2
ImportĀ upstreamĀ versionĀ 3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  applettab.cpp
 
3
 *
 
4
 *  Copyright (c) 2000 Matthias Elter <elter@kde.org>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 */
 
19
 
 
20
#include <qlayout.h>
 
21
#include <qgroupbox.h>
 
22
#include <qvbuttongroup.h>
 
23
#include <qwhatsthis.h>
 
24
#include <qradiobutton.h>
 
25
#include <qpushbutton.h>
 
26
#include <qtoolbutton.h>
 
27
#include <qvbox.h>
 
28
#include <qfileinfo.h>
 
29
 
 
30
#include <kconfig.h>
 
31
#include <kglobal.h>
 
32
#include <klocale.h>
 
33
#include <kdialog.h>
 
34
#include <kstandarddirs.h>
 
35
#include <klistview.h>
 
36
#include <kdebug.h>
 
37
 
 
38
#include "applettab_impl.h"
 
39
#include "applettab_impl.moc"
 
40
 
 
41
AppletTab::AppletTab( QWidget *parent, const char* name )
 
42
  : AppletTabBase (parent, name)
 
43
{
 
44
 
 
45
  connect(level_group, SIGNAL(clicked(int)), SLOT(level_changed(int)));
 
46
 
 
47
  connect(lb_trusted, SIGNAL(selectionChanged(QListViewItem*)),
 
48
          SLOT(trusted_selection_changed(QListViewItem*)));
 
49
 
 
50
  connect(pb_add, SIGNAL(clicked()), SLOT(add_clicked()));
 
51
  connect(pb_remove, SIGNAL(clicked()), SLOT(remove_clicked()));
 
52
 
 
53
  connect(lb_available, SIGNAL(selectionChanged(QListViewItem*)),
 
54
          SLOT(available_selection_changed(QListViewItem*)));
 
55
 
 
56
  pb_add->setEnabled(false);
 
57
  pb_remove->setEnabled(false);
 
58
 
 
59
  QWhatsThis::add( level_group, i18n("Panel applets can be started in two different ways:"
 
60
    " internally or externally. While 'internally' is the preferred way to load applets, this can"
 
61
    " raise stability or security problems when you are using poorly programmed third-party applets."
 
62
    " To address these problems, applets can be marked 'trusted'. You might want to configure"
 
63
    " Kicker to treat trusted applets different from untrusted ones. Your options are:"
 
64
    " <ul><li><em>Load only trusted applets internally:</em> All applets but the ones marked 'trusted'"
 
65
    " will be loaded using an external wrapper application.</li>"
 
66
    " <li><em>Load startup config applets internally:</em> The applets shown on KDE startup"
 
67
    " will be loaded internally, others will be loaded using an external wrapper application.</li>"
 
68
    " <li><em>Load all applets internally</em></li></ul>") );
 
69
 
 
70
  QWhatsThis::add( lb_trusted, i18n("Here you can see a list of applets that are marked"
 
71
    " 'trusted', i.e. will be loaded internally by Kicker in any case. To move an applet"
 
72
    " from the list of available applets to the trusted ones or vice versa, select it and"
 
73
    " press the left or right buttons.") );
 
74
 
 
75
  QWhatsThis::add( pb_add, i18n("Click here to add the selected applet from the list of available,"
 
76
    " untrusted applets to the list of trusted applets.") );
 
77
 
 
78
  QWhatsThis::add( pb_remove, i18n("Click here to remove the selected applet from the list of trusted"
 
79
    " applets to the list of available, untrusted applets.") );
 
80
 
 
81
  QWhatsThis::add( lb_available, i18n("Here you can see a list of available applets that you"
 
82
    " currently don't trust. This doesn't mean you can't use those applets, but rather that"
 
83
    " the panel's policy using them depends on your applet security level. To move an applet"
 
84
    " from the list of available applets to the trusted ones or vice versa, select it and"
 
85
    " press the left or right buttons.") );
 
86
 
 
87
  load();
 
88
}
 
89
 
 
90
void AppletTab::load()
 
91
{
 
92
  KConfig c(KickerConfig::configName(), false, false);
 
93
  c.setGroup("General");
 
94
 
 
95
  available.clear();
 
96
  l_available.clear();
 
97
  l_trusted.clear();
 
98
 
 
99
  int level = c.readNumEntry("SecurityLevel", 1);
 
100
 
 
101
  switch(level)
 
102
    {
 
103
    case 0:
 
104
    default:
 
105
      trusted_rb->setChecked(true);
 
106
      break;
 
107
    case 1:
 
108
      new_rb->setChecked(true);
 
109
      break;
 
110
    case 2:
 
111
      all_rb->setChecked(true);
 
112
      break;
 
113
    }
 
114
 
 
115
  list_group->setEnabled(trusted_rb->isChecked());
 
116
 
 
117
  QStringList list = KGlobal::dirs()->findAllResources("applets", "*.desktop");
 
118
  for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
 
119
    {
 
120
      QFileInfo fi(*it);
 
121
      available << fi.baseName();
 
122
    }
 
123
 
 
124
  if(c.hasKey("TrustedApplets"))
 
125
    {
 
126
      QStringList list = c.readListEntry("TrustedApplets");
 
127
      for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
 
128
        {
 
129
          if(available.contains(*it))
 
130
            l_trusted << (*it);
 
131
        }
 
132
    }
 
133
  else
 
134
      l_trusted << "clockapplet" << "ksystemtrayapplet" << "krunapplet" << "quicklauncher"
 
135
                << "kminipagerapplet" << "ktaskbarapplet" << "eyesapplet" << "kmixapplet";
 
136
 
 
137
  for ( QStringList::Iterator it = available.begin(); it != available.end(); ++it )
 
138
    {
 
139
      if(!l_trusted.contains(*it))
 
140
        l_available << (*it);
 
141
    }
 
142
 
 
143
  updateTrusted();
 
144
  updateAvailable();
 
145
}
 
146
 
 
147
void AppletTab::save()
 
148
{
 
149
  KConfig c(KickerConfig::configName(), false, false);
 
150
  c.setGroup("General");
 
151
 
 
152
  int level = 0;
 
153
  if(new_rb->isChecked()) level = 1;
 
154
  else if (all_rb->isChecked()) level = 2;
 
155
 
 
156
  c.writeEntry("SecurityLevel", level);
 
157
  c.writeEntry("TrustedApplets", l_trusted);
 
158
  c.sync();
 
159
}
 
160
 
 
161
void AppletTab::defaults()
 
162
{
 
163
  new_rb->setChecked(true);
 
164
  list_group->setEnabled(false);
 
165
}
 
166
 
 
167
QString AppletTab::quickHelp() const
 
168
{
 
169
  return i18n("");
 
170
}
 
171
 
 
172
void AppletTab::level_changed(int)
 
173
{
 
174
  list_group->setEnabled(trusted_rb->isChecked());
 
175
  setChanged();
 
176
}
 
177
 
 
178
void AppletTab::updateTrusted()
 
179
{
 
180
  lb_trusted->clear();
 
181
  for ( QStringList::Iterator it = l_trusted.begin(); it != l_trusted.end(); ++it )
 
182
    (void) new QListViewItem(lb_trusted, (*it));
 
183
}
 
184
 
 
185
void AppletTab::updateAvailable()
 
186
{
 
187
  lb_available->clear();
 
188
  for ( QStringList::Iterator it = l_available.begin(); it != l_available.end(); ++it )
 
189
    (void) new QListViewItem(lb_available, (*it));
 
190
}
 
191
 
 
192
void AppletTab::trusted_selection_changed(QListViewItem * item)
 
193
{
 
194
  pb_remove->setEnabled(item != 0);
 
195
  setChanged();
 
196
}
 
197
 
 
198
void AppletTab::available_selection_changed(QListViewItem * item)
 
199
{
 
200
  pb_add->setEnabled(item != 0);
 
201
  setChanged();
 
202
}
 
203
 
 
204
void AppletTab::add_clicked()
 
205
{
 
206
  QListViewItem *item = lb_available->selectedItem();
 
207
  if (!item) return;
 
208
  l_available.remove(item->text(0));
 
209
  l_trusted.append(item->text(0));
 
210
 
 
211
  updateTrusted();
 
212
  updateAvailable();
 
213
  updateAddRemoveButton();
 
214
}
 
215
 
 
216
void AppletTab::remove_clicked()
 
217
{
 
218
  QListViewItem *item = lb_trusted->selectedItem();
 
219
  if (!item) return;
 
220
  l_trusted.remove(item->text(0));
 
221
  l_available.append(item->text(0));
 
222
 
 
223
  updateTrusted();
 
224
  updateAvailable();
 
225
  updateAddRemoveButton();
 
226
}
 
227
 
 
228
 
 
229
void AppletTab::updateAddRemoveButton()
 
230
{
 
231
    pb_remove->setEnabled(l_trusted.count ()>0);
 
232
    pb_add->setEnabled(l_available.count()>0);
 
233
}