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>
41 KConfigWizard::KConfigWizard( QWidget
*parent
, bool modal
)
42 : KPageDialog( parent
), mPropagator( 0 ), mChangesPage( 0 )
48 KConfigWizard::KConfigWizard( KConfigPropagator
*propagator
, QWidget
*parent
,
50 : KPageDialog( parent
), mPropagator( propagator
), mChangesPage( 0 )
56 KConfigWizard::~KConfigWizard()
61 void KConfigWizard::init()
63 setFaceType( KPageDialog::Tree
);
65 KGlobal::mainComponent().aboutData()->programName().isEmpty()
66 ? i18nc( "@title:window", "Configuration Wizard" )
67 : KGlobal::mainComponent().aboutData()->programName() );
68 setWindowIcon( KIcon("tools-wizard") );
69 setButtons( Ok
|Cancel
);
70 setDefaultButton( Ok
);
72 connect( this, SIGNAL( currentPageChanged(KPageWidgetItem
*, KPageWidgetItem
* )),
73 SLOT( slotAboutToShowPage(KPageWidgetItem
*, KPageWidgetItem
*) ) );
74 connect( this, SIGNAL(okClicked()),
76 QTimer::singleShot( 0, this, SLOT( readConfig() ) );
79 void KConfigWizard::setPropagator( KConfigPropagator
*p
)
84 void KConfigWizard::slotAboutToShowPage( KPageWidgetItem
*page
, KPageWidgetItem
* )
86 if ( page
== mChangesPage
) {
91 QWidget
*KConfigWizard::createWizardPage( const QString
&title
)
93 QFrame
*page
= new QFrame(this);
94 addPage( page
, title
);
98 void KConfigWizard::setupRulesPage()
100 QFrame
*page
= new QFrame(this);
101 KPageWidgetItem
*item
= addPage( page
, i18nc( "@title:tab", "Rules" ) );
102 item
->setHeader( i18nc( "@title:window", "Set Up Rules" ) );
103 //TODO: set item icon
104 //rame *topFrame = new QFrame( this );
105 QVBoxLayout
*topLayout
= new QVBoxLayout
;
106 page
->setLayout(topLayout
);
107 mRuleView
= new Q3ListView
;
108 topLayout
->addWidget( mRuleView
);
110 mRuleView
->addColumn( i18nc( "@title:column source file,group,entry", "Source" ) );
111 mRuleView
->addColumn( i18nc( "@title:column target file,group,entry", "Target" ) );
112 mRuleView
->addColumn( i18nc( "@title:column file,group,key,value", "Condition" ) );
117 void KConfigWizard::updateRules()
119 if ( !mPropagator
) {
120 kError() << "KConfigWizard: No KConfigPropagator set.";
126 const KConfigPropagator::Rule::List rules
= mPropagator
->rules();
127 KConfigPropagator::Rule::List::ConstIterator it
;
128 for ( it
= rules
.constBegin(); it
!= rules
.constEnd(); ++it
) {
129 KConfigPropagator::Rule r
= *it
;
130 QString source
= r
.sourceFile
+ '/' + r
.sourceGroup
+ '/' +
132 QString target
= r
.targetFile
+ '/' + r
.targetGroup
+ '/' +
135 KConfigPropagator::Condition c
= r
.condition
;
137 condition
= c
.file
+ '/' + c
.group
+ '/' + c
.key
+ " = " + c
.value
;
139 new Q3ListViewItem( mRuleView
, source
, target
, condition
);
143 void KConfigWizard::setupChangesPage()
145 QFrame
*page
= new QFrame( this );
146 KPageWidgetItem
*item
= addPage( page
, i18nc( "@title:tab", "Changes" ) );
147 item
->setHeader( i18nc( "@title:window", "Set Up Changes" ) );
148 //TODO: set item icon
149 QVBoxLayout
*topLayout
= new QVBoxLayout
;
150 page
->setLayout(topLayout
);
151 mChangeView
= new Q3ListView
;
152 topLayout
->addWidget( mChangeView
);
154 mChangeView
->addColumn( i18nc( "@title:column change action", "Action" ) );
155 mChangeView
->addColumn( i18nc( "@title:column option to change", "Option" ) );
156 mChangeView
->addColumn( i18nc( "@title:column value for option", "Value" ) );
157 mChangeView
->setSorting( -1 );
162 void KConfigWizard::updateChanges()
164 kDebug() << "KConfigWizard::updateChanges()";
166 if ( !mPropagator
) {
167 kError() << "KConfigWizard: No KConfigPropagator set.";
173 mPropagator
->updateChanges();
175 mChangeView
->clear();
177 KConfigPropagator::Change::List changes
= mPropagator
->changes();
178 KConfigPropagator::Change
*c
;
179 for ( c
= changes
.first(); c
; c
= changes
.next() ) {
180 new Q3ListViewItem( mChangeView
, mChangeView
->lastItem(), c
->title(), c
->arg1(), c
->arg2() );
184 void KConfigWizard::readConfig()
186 kDebug() << "KConfigWizard::readConfig()";
189 int result
= KMessageBox::warningContinueCancel(
191 i18nc( "@info", "Please make sure that the programs which are "
192 "configured by the wizard do not run in parallel to the wizard; "
193 "otherwise, changes done by the wizard could be lost." ),
194 i18nc( "@title:window warn about running instances", "Warning" ),
195 KGuiItem( i18nc( "@action:button", "Run Wizard Now" ) ),
196 KStandardGuiItem::cancel(), "warning_running_instances" );
197 if ( result
!= KMessageBox::Continue
) {
205 void KConfigWizard::slotOk()
207 QString error
= validate();
208 if ( error
.isNull() ) {
211 if ( !mPropagator
) {
212 kError() << "KConfigWizard: No KConfigPropagator set.";
215 if ( mPropagator
->skeleton() ) {
216 mPropagator
->skeleton()->writeConfig();
218 mPropagator
->commit();
223 KMessageBox::sorry( this, error
);
227 #include "kconfigwizard.moc"