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.
23 #include "domainlistview.h"
26 #include <QtGui/QLayout>
27 #include <QtGui/QPushButton>
28 #include <QtGui/QGridLayout>
32 #include <k3listview.h>
34 #include <kmessagebox.h>
38 #include "policydlg.h"
40 DomainListView::DomainListView(KSharedConfig::Ptr config
,const QString
&title
,
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.") );
94 DomainListView::~DomainListView() {
96 DomainPolicyMap::Iterator it
= domainPolicies
.begin();
97 for (; it
!= domainPolicies
.end(); ++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();
116 PolicyDialog
pDlg(pol
, this);
117 setupPolicyDlg(AddButton
,pDlg
,pol
);
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
);
131 void DomainListView::changePressed()
133 Q3ListViewItem
*index
= domainSpecificLV
->currentItem();
136 KMessageBox::information( 0, i18n("You must first select a policy to be changed." ) );
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
);
150 pol_copy
->setDomain(pDlg
.domain());
151 domainPolicies
[index
] = pol_copy
;
153 index
->setText(0, pDlg
.domain() );
154 index
->setText(1, pDlg
.featureEnabledPolicyText());
160 void DomainListView::deletePressed()
162 Q3ListViewItem
*index
= domainSpecificLV
->currentItem();
165 KMessageBox::information( 0, i18n("You must first select a policy to delete." ) );
169 DomainPolicyMap::Iterator it
= domainPolicies
.find(index
);
170 if (it
!= domainPolicies
.end()) {
172 domainPolicies
.erase(it
);
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
);
202 if (pol
->isFeatureEnabledPolicyInherited())
203 policy
= i18n("Use Global");
204 else if (pol
->isFeatureEnabled())
205 policy
= i18n("Accept");
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();
222 domainList
.append(current
->text(0));
224 config
->group(group
).writeEntry(domainListKey
, domainList
);
227 void DomainListView::setupPolicyDlg(PushButton
/*trigger*/,
228 PolicyDialog
&/*pDlg*/,Policies */
*copy*/
) {
232 #include "domainlistview.moc"