2 This file is part of libkdepim.
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library 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 GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include "kconfigwizard.h"
23 #include "kconfigpropagator.h"
26 #include <KComponentData>
27 #include <KConfigSkeleton>
30 #include <KMessageBox>
31 #include <KPageDialog>
33 #include <QApplication>
36 #include <QVBoxLayout>
37 #include <QTreeWidget>
39 KConfigWizard::KConfigWizard( QWidget
*parent
, bool modal
)
40 : KPageDialog( parent
), mPropagator( 0 ), mChangesPage( 0 )
46 KConfigWizard::KConfigWizard( KConfigPropagator
*propagator
, QWidget
*parent
,
48 : KPageDialog( parent
), mPropagator( propagator
), mChangesPage( 0 )
54 KConfigWizard::~KConfigWizard()
59 void KConfigWizard::init()
61 setFaceType( KPageDialog::Tree
);
63 KGlobal::mainComponent().aboutData()->programName().isEmpty()
64 ? i18nc( "@title:window", "Configuration Wizard" )
65 : KGlobal::mainComponent().aboutData()->programName() );
66 setWindowIcon( KIcon("tools-wizard") );
67 setButtons( Ok
|Cancel
);
68 setDefaultButton( Ok
);
70 connect( this, SIGNAL( currentPageChanged(KPageWidgetItem
*, KPageWidgetItem
* )),
71 SLOT( slotAboutToShowPage(KPageWidgetItem
*, KPageWidgetItem
*) ) );
72 connect( this, SIGNAL(okClicked()),
74 QTimer::singleShot( 0, this, SLOT( readConfig() ) );
77 void KConfigWizard::setPropagator( KConfigPropagator
*p
)
82 void KConfigWizard::slotAboutToShowPage( KPageWidgetItem
*page
, KPageWidgetItem
* )
84 if ( page
== mChangesPage
) {
89 QWidget
*KConfigWizard::createWizardPage( const QString
&title
)
91 QFrame
*page
= new QFrame(this);
92 addPage( page
, title
);
96 void KConfigWizard::setupRulesPage()
98 QFrame
*page
= new QFrame(this);
99 KPageWidgetItem
*item
= addPage( page
, i18nc( "@title:tab", "Rules" ) );
100 item
->setHeader( i18nc( "@title:window", "Set Up Rules" ) );
101 //TODO: set item icon
102 //rame *topFrame = new QFrame( this );
103 QVBoxLayout
*topLayout
= new QVBoxLayout
;
104 page
->setLayout(topLayout
);
105 mRuleView
= new QTreeWidget
;
106 topLayout
->addWidget( mRuleView
);
108 mRuleView
->setHeaderLabels( QStringList()
109 << i18nc( "@title:column source file,group,entry", "Source" )
110 << i18nc( "@title:column target file,group,entry", "Target" )
111 << i18nc( "@title:column file,group,key,value", "Condition" ) );
116 void KConfigWizard::updateRules()
118 if ( !mPropagator
) {
119 kError() << "KConfigWizard: No KConfigPropagator set.";
125 const KConfigPropagator::Rule::List rules
= mPropagator
->rules();
126 KConfigPropagator::Rule::List::ConstIterator it
;
127 for ( it
= rules
.constBegin(); it
!= rules
.constEnd(); ++it
) {
128 KConfigPropagator::Rule r
= *it
;
129 QString source
= r
.sourceFile
+ '/' + r
.sourceGroup
+ '/' +
131 QString target
= r
.targetFile
+ '/' + r
.targetGroup
+ '/' +
134 KConfigPropagator::Condition c
= r
.condition
;
136 condition
= c
.file
+ '/' + c
.group
+ '/' + c
.key
+ " = " + c
.value
;
138 QTreeWidgetItem
*item
= new QTreeWidgetItem( mRuleView
);
139 item
->setText( 0, source
);
140 item
->setText( 1, target
);
141 item
->setText( 2, condition
);
145 void KConfigWizard::setupChangesPage()
147 QFrame
*page
= new QFrame( this );
148 KPageWidgetItem
*item
= addPage( page
, i18nc( "@title:tab", "Changes" ) );
149 item
->setHeader( i18nc( "@title:window", "Set Up Changes" ) );
150 //TODO: set item icon
151 QVBoxLayout
*topLayout
= new QVBoxLayout
;
152 page
->setLayout(topLayout
);
153 mChangeView
= new QTreeWidget
;
154 topLayout
->addWidget( mChangeView
);
156 mChangeView
->setHeaderLabels( QStringList()
157 << i18nc( "@title:column change action", "Action" )
158 << i18nc( "@title:column option to change", "Option" )
159 << i18nc( "@title:column value for option", "Value" ) );
160 mChangeView
->setSortingEnabled( false );
165 void KConfigWizard::updateChanges()
167 kDebug() << "KConfigWizard::updateChanges()";
169 if ( !mPropagator
) {
170 kError() << "KConfigWizard: No KConfigPropagator set.";
176 mPropagator
->updateChanges();
178 mChangeView
->clear();
180 foreach( KConfigPropagator::Change
*c
, mPropagator
->changes() ) {
181 QTreeWidgetItem
*item
= new QTreeWidgetItem( mChangeView
);
182 item
->setText( 0, c
->title() );
183 item
->setText( 1, c
->arg1() );
184 item
->setText( 2, c
->arg2() );
188 void KConfigWizard::readConfig()
190 kDebug() << "KConfigWizard::readConfig()";
193 int result
= KMessageBox::warningContinueCancel(
195 i18nc( "@info", "Please make sure that the programs which are "
196 "configured by the wizard do not run in parallel to the wizard; "
197 "otherwise, changes done by the wizard could be lost." ),
198 i18nc( "@title:window warn about running instances", "Warning" ),
199 KGuiItem( i18nc( "@action:button", "Run Wizard Now" ) ),
200 KStandardGuiItem::cancel(), "warning_running_instances" );
201 if ( result
!= KMessageBox::Continue
) {
209 void KConfigWizard::slotOk()
211 QString error
= validate();
212 if ( error
.isNull() ) {
215 if ( !mPropagator
) {
216 kError() << "KConfigWizard: No KConfigPropagator set.";
219 if ( mPropagator
->skeleton() ) {
220 mPropagator
->skeleton()->writeConfig();
222 mPropagator
->commit();
227 KMessageBox::sorry( this, error
);
231 #include "kconfigwizard.moc"