libtdepim

tdeconfigwizard.cpp
1 /*
2  This file is part of libtdepim.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 
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.
10 
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.
15 
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.
20 */
21 
22 #include "tdeconfigwizard.h"
23 
24 #include <tdelocale.h>
25 #include <kdebug.h>
26 #include <tdeconfigskeleton.h>
27 #include <tdemessagebox.h>
28 #include <tdeapplication.h>
29 
30 #include <tqlistview.h>
31 #include <tqlayout.h>
32 #include <tqtimer.h>
33 
35  char *name, bool modal )
36  : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent,
37  name, modal ),
38  mPropagator( 0 ), mChangesPage( 0 )
39 {
40  init();
41 }
42 
43 TDEConfigWizard::TDEConfigWizard( TDEConfigPropagator *propagator, TQWidget *parent,
44  char *name, bool modal )
45  : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent,
46  name, modal ),
47  mPropagator( propagator ), mChangesPage( 0 )
48 {
49  init();
50 }
51 
53 {
54  delete mPropagator;
55 }
56 
57 void TDEConfigWizard::init()
58 {
59  connect( this, TQ_SIGNAL( aboutToShowPage( TQWidget * ) ),
60  TQ_SLOT( slotAboutToShowPage( TQWidget * ) ) );
61 
62  TQTimer::singleShot( 0, this, TQ_SLOT( readConfig() ) );
63 }
64 
65 void TDEConfigWizard::setPropagator( TDEConfigPropagator *p )
66 {
67  mPropagator = p;
68 }
69 
70 void TDEConfigWizard::slotAboutToShowPage( TQWidget *page )
71 {
72  if ( page == mChangesPage ) {
73  updateChanges();
74  }
75 }
76 
77 TQFrame *TDEConfigWizard::createWizardPage( const TQString &title )
78 {
79  return addPage( title );
80 }
81 
82 void TDEConfigWizard::setupRulesPage()
83 {
84  TQFrame *topFrame = addPage( i18n("Rules") );
85  TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame );
86 
87  mRuleView = new TQListView( topFrame );
88  topLayout->addWidget( mRuleView );
89 
90  mRuleView->addColumn( i18n("Source") );
91  mRuleView->addColumn( i18n("Target") );
92  mRuleView->addColumn( i18n("Condition") );
93 
94  updateRules();
95 }
96 
97 void TDEConfigWizard::updateRules()
98 {
99  if ( !mPropagator ) {
100  kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl;
101  return;
102  }
103 
104  mRuleView->clear();
105 
106  TDEConfigPropagator::Rule::List rules = mPropagator->rules();
107  TDEConfigPropagator::Rule::List::ConstIterator it;
108  for( it = rules.begin(); it != rules.end(); ++it ) {
109  TDEConfigPropagator::Rule r = *it;
110  TQString source = r.sourceFile + "/" + r.sourceGroup + "/" +
111  r.sourceEntry;
112  TQString target = r.targetFile + "/" + r.targetGroup + "/" +
113  r.targetEntry;
114  TQString condition;
115  TDEConfigPropagator::Condition c = r.condition;
116  if ( c.isValid ) {
117  condition = c.file + "/" + c.group + "/" + c.key + " = " + c.value;
118  }
119  new TQListViewItem( mRuleView, source, target, condition );
120  }
121 }
122 
123 void TDEConfigWizard::setupChangesPage()
124 {
125  TQFrame *topFrame = addPage( i18n("Changes") );
126  TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame );
127 
128  mChangeView = new TQListView( topFrame );
129  topLayout->addWidget( mChangeView );
130 
131  mChangeView->addColumn( i18n("Action") );
132  mChangeView->addColumn( i18n("Option") );
133  mChangeView->addColumn( i18n("Value") );
134  mChangeView->setSorting( -1 );
135 
136  mChangesPage = topFrame;
137 }
138 
139 void TDEConfigWizard::updateChanges()
140 {
141  kdDebug() << "TDEConfigWizard::updateChanges()" << endl;
142 
143  if ( !mPropagator ) {
144  kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl;
145  return;
146  }
147 
148  usrWriteConfig();
149 
150  mPropagator->updateChanges();
151 
152  mChangeView->clear();
153 
154  TDEConfigPropagator::Change::List changes = mPropagator->changes();
155  TDEConfigPropagator::Change *c;
156  for( c = changes.first(); c; c = changes.next() ) {
157  new TQListViewItem( mChangeView, mChangeView->lastItem(), c->title(), c->arg1(), c->arg2() );
158  }
159 }
160 
161 void TDEConfigWizard::readConfig()
162 {
163  kdDebug() << "TDEConfigWizard::readConfig()" << endl;
164 
165  int result = KMessageBox::warningContinueCancel( this,
166  i18n("Please make sure that the programs which are "
167  "configured by the wizard do not run in parallel to the wizard; "
168  "otherwise, changes done by the wizard could be lost."),
169  i18n("Warning"), i18n("Run Wizard Now"), "warning_running_instances" );
170  if ( result != KMessageBox::Continue ) kapp->quit();
171 
172  usrReadConfig();
173 }
174 
175 void TDEConfigWizard::slotOk()
176 {
177  TQString error = validate();
178  if ( error.isNull() ) {
179  usrWriteConfig();
180 
181  if ( !mPropagator ) {
182  kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl;
183  return;
184  } else {
185  if ( mPropagator->skeleton() ) {
186  mPropagator->skeleton()->writeConfig();
187  }
188  mPropagator->commit();
189  }
190 
191  accept();
192  } else {
193  KMessageBox::sorry( this, error );
194  }
195 }
196 
197 #include "tdeconfigwizard.moc"
virtual TQString validate()
Validates the supplied data.
virtual ~TDEConfigWizard()
Destructor.
TDEConfigWizard(TQWidget *parent=0, char *name=0, bool modal=false)
Create wizard.
virtual void usrReadConfig()=0
Use this function to read the configuration from the TDEConfigSkeleton object to the GUI.
void setPropagator(TDEConfigPropagator *)
Set propagator the wizard operates on.
virtual void usrWriteConfig()=0
This function is called when the wizard is finished.
TQFrame * createWizardPage(const TQString &title)
Create wizard page with given title.