removed the content from template.docbook, which is completly unrelated to kmobiletools
[kdepim.git] / korn / korncfgimpl.cpp
blobf2fb71d42abc630219cc4d28a9575db72cddcfd0
1 /*
2 * Copyright (C) 2004, Mart Kelder (mart.kde@hccnet.nl)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "korncfgimpl.h"
21 #include "kornboxcfgimpl.h"
22 #include "password.h"
23 #include "settings.h"
25 #include <kconfig.h>
26 #include <kdebug.h>
27 #include <kdialog.h>
28 #include <klocale.h>
29 #include <kmenu.h>
31 #include <QCheckBox>
32 #include <QString>
36 * parent should be of type KDialog
38 KornCfgImpl::KornCfgImpl( QWidget * parent )
39 : QWidget( parent ),
40 Ui_KornCfgWidget(),
41 m_settings( Settings::self() ),
42 m_base( 0 )
44 setupUi( this );
46 connect( parent, SIGNAL( okClicked() ), this, SLOT( slotOK() ) );
47 connect( parent, SIGNAL( cancelClicked() ), this, SLOT( slotCancel() ) );
48 connect( parent, SIGNAL( applyClicked() ), this, SLOT( slotApply() ) );
50 connect( pbAdd, SIGNAL(clicked()), this, SLOT(slotAdd()) );
51 connect( pbRemove, SIGNAL(clicked()), this, SLOT(slotRemove()) );
52 connect( pbMoveUp, SIGNAL(clicked()), this, SLOT(slotMoveUp()) );
53 connect( pbMoveDown, SIGNAL(clicked()), this, SLOT(slotMoveDown()) );
54 connect( pbEdit, SIGNAL(clicked()), this, SLOT(slotEditBox()) );
55 connect( lsBoxes, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(slotEditBox()) );
57 lsBoxes->setSelectionMode( QAbstractItemView::SingleSelection );
59 readConfig();
62 KornCfgImpl::~KornCfgImpl()
66 void KornCfgImpl::slotEditBox()
68 if( m_base )
69 return; //Already a dialog open
70 if( lsBoxes->currentRow() < 0 ) //TODO: test if it works
71 return; //No item selected
72 lsBoxes->setEnabled( false );
73 pbAdd->setEnabled( false );
74 pbRemove->setEnabled( false );
75 pbMoveUp->setEnabled( false );
76 pbMoveDown->setEnabled( false );
78 m_base = new KDialog( this );
79 m_base->setCaption( i18n("Box Configuration") );
80 m_base->setButtons( KDialog::Ok | KDialog::Cancel );
81 m_base->setModal( false );
82 m_base->showButtonSeparator( true );
83 KornBoxCfgImpl *widget = new KornBoxCfgImpl( m_base, m_settings, m_settings->getBox( lsBoxes->currentRow() ) );
85 connect( m_base, SIGNAL( finished() ), this, SLOT( slotDialogDestroyed() ) );
87 m_base->setMainWidget( widget );
89 m_base->show();
92 void KornCfgImpl::slotDialogDestroyed()
94 m_base->deleteLater(); m_base = 0;
95 lsBoxes->setEnabled( true );
96 pbAdd->setEnabled( true );
97 pbRemove->setEnabled( true );
98 pbMoveUp->setEnabled( true );
99 pbMoveDown->setEnabled( true );
100 if( m_settings->getBox( lsBoxes->currentRow() ) )
101 lsBoxes->currentItem()->setText( m_settings->getBox( lsBoxes->currentRow() )->boxName() );
104 void KornCfgImpl::slotActivated( const QModelIndex& )
106 slotEditBox();
109 void KornCfgImpl::slotOK()
111 writeConfig();
114 void KornCfgImpl::slotCancel()
116 //m_config->rollback();
119 void KornCfgImpl::slotApply()
121 writeConfig();
124 void KornCfgImpl::readConfig()
126 int xx = 0;
127 BoxSettings *setting;
129 m_settings->readConfig();
131 switch( m_settings->layout() )
133 case Settings::Horizontal:
134 rbHorizontal->setChecked( true );
135 break;
136 case Settings::Vertical:
137 rbVertical->setChecked( true );
138 break;
139 case Settings::Docked:
140 rbDocked->setChecked( true );
141 break;
143 chUseWallet->setChecked( m_settings->useWallet() );
145 while( ( setting = m_settings->getBox( xx ) ) )
147 lsBoxes->addItem( m_settings->getBox( xx )->boxName() );
148 ++xx;
152 void KornCfgImpl::writeConfig()
154 if( rbHorizontal->isChecked() )
155 m_settings->setLayout( Settings::Horizontal );
156 if( rbVertical->isChecked() )
157 m_settings->setLayout( Settings::Vertical );
158 if( rbDocked->isChecked() )
159 m_settings->setLayout( Settings::Docked );
161 //Default is 'false' here, because if no option is set, KWallet isn't used.
162 //if( m_settings->useWallet() != chUseWallet->isChecked() )
163 //Configuration box changed => setting over configuration
164 //rewritePasswords();
166 m_settings->setUseWallet( chUseWallet->isChecked() );
167 m_settings->writeConfig();
170 void KornCfgImpl::slotAdd()
172 m_settings->addBox();
173 lsBoxes->addItem( "new box" );
174 lsBoxes->setCurrentRow( lsBoxes->count() - 1 );
175 slotEditBox();
178 void KornCfgImpl::slotRemove()
180 if( lsBoxes->currentRow() < 0 )
181 return; // No item selected
183 //Move item to behind
184 while( lsBoxes->currentRow() != lsBoxes->count() - 1 )
185 slotMoveDown();
187 //Delete box and remove from list
188 m_settings->deleteBox( lsBoxes->count() - 1 );
189 lsBoxes->takeItem( lsBoxes->count() - 1 );
192 void KornCfgImpl::slotMoveUp()
194 if( lsBoxes->currentRow() < 1 )
195 return; //Already first, or there is no item selected
196 m_settings->swapBox( lsBoxes->currentRow() - 1, lsBoxes->currentRow() );
197 if( !m_settings->getBox( lsBoxes->currentRow() ) )
198 kWarning() <<"The settings do not match with the list widget";
199 else
200 lsBoxes->currentItem()->setText( m_settings->getBox( lsBoxes->currentRow() )->boxName() );
201 lsBoxes->setCurrentRow( lsBoxes->currentRow() - 1 );
202 if( !m_settings->getBox( lsBoxes->currentRow() ) )
203 kWarning() <<"The settings do not match with the list widget";
204 else
205 lsBoxes->currentItem()->setText( m_settings->getBox( lsBoxes->currentRow() )->boxName() );
208 void KornCfgImpl::slotMoveDown()
210 if( lsBoxes->currentRow() < 0 || lsBoxes->currentRow() + 1 >= lsBoxes->count() )
211 return; //Already last, or there is no item selected
212 m_settings->swapBox( lsBoxes->currentRow(), lsBoxes->currentRow() + 1 );
213 if( !m_settings->getBox( lsBoxes->currentRow() ) )
214 kWarning() <<"The settings do not match with the list widget";
215 else
216 lsBoxes->currentItem()->setText( m_settings->getBox( lsBoxes->currentRow() )->boxName() );
217 lsBoxes->setCurrentRow( lsBoxes->currentRow() + 1 );
218 if( !m_settings->getBox( lsBoxes->currentRow() ) )
219 kWarning() <<"The settings do not match with the list widget";
220 else
221 lsBoxes->currentItem()->setText( m_settings->getBox( lsBoxes->currentRow() )->boxName() );
224 /*void KornCfgImpl::rewritePasswords()
226 int box = 0 - 1;
227 int account = 0 - 1;
228 KConfigGroup *group;
230 while( m_config->hasGroup( QString( "korn-%1" ).arg( ++box ) ) )
232 account = 0 - 1;
233 while( m_config->hasGroup( QString( "korn-%1-%2" ).arg( box ).arg( ++account ) ) )
235 group = new KConfigGroup( m_config, QString( "korn-%1-%2" ).arg( box ).arg( account ) );
236 KOrnPassword::rewritePassword( box, account, *group, chUseWallet->isChecked() );
237 delete group;
241 m_config->setGroup( "korn" );
244 #include "korncfgimpl.moc"