Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / konqueror / settings / konqhtml / domainlistview.cpp
blob2f45afe72c8837f812a3dcdc6a65522597b7cef7
1 /*
2 Copyright (c) 2002 Leo Savernik <l.savernik@aon.at>
3 Derived from jsopts.cpp and javaopts.cpp, code copied from there is
4 copyrighted to its respective owners.
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.
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.
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 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 // Own
23 #include "domainlistview.h"
25 // Qt
26 #include <QtGui/QLayout>
27 #include <QtGui/QPushButton>
28 #include <QtGui/QGridLayout>
30 // KDE
31 #include <kconfig.h>
32 #include <k3listview.h>
33 #include <klocale.h>
34 #include <kmessagebox.h>
36 // Local
37 #include "policies.h"
38 #include "policydlg.h"
40 DomainListView::DomainListView(KSharedConfig::Ptr config,const QString &title,
41 QWidget *parent) :
42 QGroupBox(title, parent), config(config) {
43 QGridLayout* thisLayout = new QGridLayout();
44 setLayout( thisLayout );
45 thisLayout->setAlignment(Qt::AlignTop);
46 thisLayout->setSpacing(KDialog::spacingHint());
47 thisLayout->setMargin(KDialog::marginHint());
49 domainSpecificLV = new K3ListView(this);
50 domainSpecificLV->addColumn(i18n("Host/Domain"));
51 domainSpecificLV->addColumn(i18n("Policy"), 100);
52 connect(domainSpecificLV,SIGNAL(doubleClicked(Q3ListViewItem *)), SLOT(changePressed()));
53 connect(domainSpecificLV,SIGNAL(returnPressed(Q3ListViewItem *)), SLOT(changePressed()));
54 connect(domainSpecificLV, SIGNAL( executed( Q3ListViewItem *)), SLOT( updateButton()));
55 connect(domainSpecificLV, SIGNAL(selectionChanged()), SLOT(updateButton()));
56 thisLayout->addWidget(domainSpecificLV, 0, 0, 6, 1);
58 addDomainPB = new QPushButton(i18n("&New..."), this);
59 thisLayout->addWidget(addDomainPB, 0, 1);
60 connect(addDomainPB, SIGNAL(clicked()), SLOT(addPressed()));
62 changeDomainPB = new QPushButton( i18n("Chan&ge..."), this);
63 thisLayout->addWidget(changeDomainPB, 1, 1);
64 connect(changeDomainPB, SIGNAL(clicked()), this, SLOT(changePressed()));
66 deleteDomainPB = new QPushButton(i18n("De&lete"), this);
67 thisLayout->addWidget(deleteDomainPB, 2, 1);
68 connect(deleteDomainPB, SIGNAL(clicked()), this, SLOT(deletePressed()));
70 importDomainPB = new QPushButton(i18n("&Import..."), this);
71 thisLayout->addWidget(importDomainPB, 3, 1);
72 connect(importDomainPB, SIGNAL(clicked()), this, SLOT(importPressed()));
73 importDomainPB->setEnabled(false);
74 importDomainPB->hide();
76 exportDomainPB = new QPushButton(i18n("&Export..."), this);
77 thisLayout->addWidget(exportDomainPB, 4, 1);
78 connect(exportDomainPB, SIGNAL(clicked()), this, SLOT(exportPressed()));
79 exportDomainPB->setEnabled(false);
80 exportDomainPB->hide();
82 QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
83 thisLayout->addItem(spacer, 5, 1);
85 addDomainPB->setWhatsThis( i18n("Click on this button to manually add a host or domain "
86 "specific policy.") );
87 changeDomainPB->setWhatsThis( i18n("Click on this button to change the policy for the "
88 "host or domain selected in the list box.") );
89 deleteDomainPB->setWhatsThis( i18n("Click on this button to delete the policy for the "
90 "host or domain selected in the list box.") );
91 updateButton();
94 DomainListView::~DomainListView() {
95 // free all policies
96 DomainPolicyMap::Iterator it = domainPolicies.begin();
97 for (; it != domainPolicies.end(); ++it) {
98 delete it.value();
99 }/*next it*/
102 void DomainListView::updateButton()
104 Q3ListViewItem *index = domainSpecificLV->currentItem();
105 bool enable = ( index != 0 );
106 changeDomainPB->setEnabled( enable );
107 deleteDomainPB->setEnabled( enable );
111 void DomainListView::addPressed()
113 // JavaPolicies pol_copy(m_pConfig,m_groupname,false);
114 Policies *pol = createPolicies();
115 pol->defaults();
116 PolicyDialog pDlg(pol, this);
117 setupPolicyDlg(AddButton,pDlg,pol);
118 if( pDlg.exec() ) {
119 Q3ListViewItem* index = new Q3ListViewItem( domainSpecificLV, pDlg.domain(),
120 pDlg.featureEnabledPolicyText() );
121 pol->setDomain(pDlg.domain());
122 domainPolicies.insert(index, pol);
123 domainSpecificLV->setCurrentItem( index );
124 emit changed(true);
125 } else {
126 delete pol;
128 updateButton();
131 void DomainListView::changePressed()
133 Q3ListViewItem *index = domainSpecificLV->currentItem();
134 if ( index == 0 )
136 KMessageBox::information( 0, i18n("You must first select a policy to be changed." ) );
137 return;
140 Policies *pol = domainPolicies[index];
141 // This must be copied because the policy dialog is allowed to change
142 // the data even if the changes are rejected in the end.
143 Policies *pol_copy = copyPolicies(pol);
145 PolicyDialog pDlg( pol_copy, this );
146 pDlg.setDisableEdit( true, index->text(0) );
147 setupPolicyDlg(ChangeButton,pDlg,pol_copy);
148 if( pDlg.exec() )
150 pol_copy->setDomain(pDlg.domain());
151 domainPolicies[index] = pol_copy;
152 pol_copy = pol;
153 index->setText(0, pDlg.domain() );
154 index->setText(1, pDlg.featureEnabledPolicyText());
155 emit changed(true);
157 delete pol_copy;
160 void DomainListView::deletePressed()
162 Q3ListViewItem *index = domainSpecificLV->currentItem();
163 if ( index == 0 )
165 KMessageBox::information( 0, i18n("You must first select a policy to delete." ) );
166 return;
169 DomainPolicyMap::Iterator it = domainPolicies.find(index);
170 if (it != domainPolicies.end()) {
171 delete it.value();
172 domainPolicies.erase(it);
173 delete index;
174 emit changed(true);
176 updateButton();
179 void DomainListView::importPressed()
181 // PENDING(kalle) Implement this.
184 void DomainListView::exportPressed()
186 // PENDING(kalle) Implement this.
189 void DomainListView::initialize(const QStringList &domainList)
191 domainSpecificLV->clear();
192 domainPolicies.clear();
193 // JavaPolicies pol(m_pConfig,m_groupname,false);
194 for (QStringList::ConstIterator it = domainList.begin();
195 it != domainList.end(); ++it) {
196 QString domain = *it;
197 Policies *pol = createPolicies();
198 pol->setDomain(domain);
199 pol->load();
201 QString policy;
202 if (pol->isFeatureEnabledPolicyInherited())
203 policy = i18n("Use Global");
204 else if (pol->isFeatureEnabled())
205 policy = i18n("Accept");
206 else
207 policy = i18n("Reject");
208 Q3ListViewItem *index =
209 new Q3ListViewItem( domainSpecificLV, domain, policy );
211 domainPolicies[index] = pol;
215 void DomainListView::save(const QString &group, const QString &domainListKey) {
216 QStringList domainList;
217 DomainPolicyMap::Iterator it = domainPolicies.begin();
218 for (; it != domainPolicies.end(); ++it) {
219 Q3ListViewItem *current = it.key();
220 Policies *pol = it.value();
221 pol->save();
222 domainList.append(current->text(0));
224 config->group(group).writeEntry(domainListKey, domainList);
227 void DomainListView::setupPolicyDlg(PushButton /*trigger*/,
228 PolicyDialog &/*pDlg*/,Policies */*copy*/) {
229 // do nothing
232 #include "domainlistview.moc"