1/***************************************************************************
2 koptionsdlg.cpp - description
3 -------------------
4 begin : Tue Dec 28 1999
5 copyright : (C) 1999 by François Dupoux
6 (C) 2004 Emiliano Gulmini <emi_barbarossa@yahoo.it>
7 email : dupoux@dupoux.com
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19// QT
20#include <qcheckbox.h>
21#include <qspinbox.h>
22
23#include <qpushbutton.h>
24#include <qlabel.h>
25#include <qlineedit.h>
26
27// KDE
28#include <kcharsets.h>
29#include <kcombobox.h>
30#include <kconfig.h>
31#include <kglobal.h>
32#include <kstandarddirs.h>
33#include <kapplication.h>
34//#include <kdebug.h>
35
36// local
37#include "whatthis.h"
38#include "koptionsdlg.h"
39
40
41using namespace whatthisNameSpace;
42
43
44KOptionsDlg::KOptionsDlg(RCOptions* info, QWidget *parent, const char *name) : KOptionsDlgS(parent,name,true)
45{
46 m_config = new KConfig("kfilereplacerc");
47 m_option = info;
48
49 initGUI();
50
51 connect(m_pbOK, SIGNAL(clicked()), this, SLOT(slotOK()));
52 connect(m_pbDefault, SIGNAL(clicked()),this,SLOT(slotDefaults()));
53 connect(m_chbBackup, SIGNAL(toggled(bool)), this, SLOT(slotChbBackup(bool)));
54 connect(m_pbHelp, SIGNAL(clicked()), this, SLOT(slotHelp()));
55 connect(m_chbConfirmStrings, SIGNAL(toggled(bool)), this, SLOT(slotChbConfirmStrings(bool)));
56 connect(m_chbShowConfirmDialog, SIGNAL(toggled(bool)), this, SLOT(slotChbShowConfirmDialog(bool)));
57
58 whatsThis();
59}
60
61KOptionsDlg::~KOptionsDlg()
62{
63}
64
65//PRIVATE SLOTS
66void KOptionsDlg::slotOK()
67{
68 saveRCOptions();
69 accept();
70}
71
72/** Set defaults values for all options of the dialog */
73void KOptionsDlg::slotDefaults()
74{
75 m_chbCaseSensitive->setChecked(CaseSensitiveOption);
76 m_chbRecursive->setChecked(RecursiveOption);
77 m_chbHaltOnFirstOccurrence->setChecked(StopWhenFirstOccurenceOption);
78
79 m_chbFollowSymLinks->setChecked(FollowSymbolicLinksOption);
80 m_chbIgnoreHidden->setChecked(IgnoreHiddenOption);
81 m_chbRegularExpressions->setChecked(RegularExpressionsOption);
82 m_chbIgnoreFiles->setChecked(IgnoreFilesOption);
83 m_chbConfirmStrings->setChecked(AskConfirmReplaceOption);
84
85 QStringList bkList = BackupExtensionOption.split(",",QString::KeepEmptyParts);
86
87 bool enableBackup = (bkList[0] == "true" ? true : false);
88
89 m_chbBackup->setChecked(enableBackup);
90 m_leBackup->setEnabled(enableBackup);
91 m_tlBackup->setEnabled(enableBackup);
92
93 m_leBackup->setText(bkList[1]);
94
95 m_chbVariables->setChecked(VariablesOption);
96
97 m_chbNotifyOnErrors->setChecked(NotifyOnErrorsOption);
98}
99
100void KOptionsDlg::slotChbBackup(bool b)
101{
102 m_leBackup->setEnabled(b);
103 m_tlBackup->setEnabled(b);
104}
105
106void KOptionsDlg::slotChbConfirmStrings(bool b)
107{
108 KConfigGroup grp(m_config, "Notification Messages");
109 if(b)
110 {
111 m_chbShowConfirmDialog->setEnabled(true);
112 m_chbShowConfirmDialog->setChecked(true);
113 grp.writeEntry(rcDontAskAgain,"no");
114 }
115 else
116 {
117 m_chbShowConfirmDialog->setEnabled(false);
118 m_chbShowConfirmDialog->setChecked(false);
119 grp.writeEntry(rcDontAskAgain,"yes");
120 }
121}
122
123void KOptionsDlg::slotChbShowConfirmDialog(bool b)
124{
125 KConfigGroup grp(m_config, "Notification Messages");
126 if(b)
127 {
128 grp.writeEntry(rcDontAskAgain,"no");
129 }
130 else
131 {
132 grp.writeEntry(rcDontAskAgain,"yes");
133 }
134}
135
136//PRIVATE
137void KOptionsDlg::initGUI()
138{
139 m_config->sync();
140 KConfigGroup grp(m_config, "Notification Messages");
141 m_option->m_notifyOnErrors = grp.readEntry(rcNotifyOnErrors, true);
142
143 QString dontAskAgain = grp.readEntry(rcDontAskAgain, QString("no"));
144
145 m_chbConfirmStrings->setChecked(m_option->m_askConfirmReplace);
146
147 if(m_chbConfirmStrings->isChecked())
148 {
149 if(dontAskAgain == "yes")
150 m_chbShowConfirmDialog->setChecked(false);
151 else
152 m_chbShowConfirmDialog->setChecked(true);
153 }
154
155 QStringList availableEncodingNames(KGlobal::charsets()->availableEncodingNames());
156 m_cbEncoding->addItems( availableEncodingNames );
157 int idx = -1;
158 int utf8Idx = -1;
159 for (int i = 0; i < availableEncodingNames.count(); i++)
160 {
161 if (availableEncodingNames[i] == m_option->m_encoding)
162 {
163 idx = i;
164 break;
165 }
166 if (availableEncodingNames[i] == "utf8")
167 {
168 utf8Idx = i;
169 }
170 }
171 if (idx != -1)
172 m_cbEncoding->setCurrentIndex(idx);
173 else
174 m_cbEncoding->setCurrentIndex(utf8Idx);
175
176 m_chbCaseSensitive->setChecked(m_option->m_caseSensitive);
177 m_chbRecursive->setChecked(m_option->m_recursive);
178
179 bool enableBackup = m_option->m_backup;
180
181 m_chbBackup->setChecked(enableBackup);
182 m_leBackup->setEnabled(enableBackup);
183 m_tlBackup->setEnabled(enableBackup);
184
185 m_leBackup->setText(m_option->m_backupExtension);
186
187 m_chbVariables->setChecked(m_option->m_variables);
188 m_chbRegularExpressions->setChecked(m_option->m_regularExpressions);
189 m_chbHaltOnFirstOccurrence->setChecked(m_option->m_haltOnFirstOccur);
190 m_chbFollowSymLinks->setChecked(m_option->m_followSymLinks);
191 m_chbIgnoreHidden->setChecked(m_option->m_ignoreHidden);
192 m_chbIgnoreFiles->setChecked(m_option->m_ignoreFiles);
193
194 m_chbNotifyOnErrors->setChecked(m_option->m_notifyOnErrors);
195}
196
197void KOptionsDlg::saveRCOptions()
198{
199 m_option->m_encoding = m_cbEncoding->currentText();
200 m_option->m_caseSensitive = m_chbCaseSensitive->isChecked();
201 m_option->m_recursive = m_chbRecursive->isChecked();
202 QString backupExt = m_leBackup->text();
203 m_option->m_backup = (m_chbBackup->isChecked() && !backupExt.isEmpty());
204 m_option->m_backupExtension = backupExt;
205 m_option->m_variables = m_chbVariables->isChecked();
206 m_option->m_regularExpressions = m_chbRegularExpressions->isChecked();
207 m_option->m_haltOnFirstOccur = m_chbHaltOnFirstOccurrence->isChecked();
208 m_option->m_followSymLinks = m_chbFollowSymLinks->isChecked();
209 m_option->m_ignoreHidden = m_chbIgnoreHidden->isChecked();
210 m_option->m_ignoreFiles = m_chbIgnoreFiles->isChecked();
211 m_option->m_askConfirmReplace = m_chbConfirmStrings->isChecked();
212 m_option->m_notifyOnErrors = m_chbNotifyOnErrors->isChecked();
213
214 KConfigGroup grp(m_config, "Notification Messages");
215 grp.writeEntry(rcNotifyOnErrors, m_option->m_notifyOnErrors);
216
217 m_config->sync();
218}
219
220void KOptionsDlg::whatsThis()
221{
222 // Create help QWhatsThis
223 m_chbCaseSensitive->setWhatsThis( chbCaseSensitiveWhatthis);
224 m_chbRecursive->setWhatsThis( chbRecursiveWhatthis);
225 m_chbHaltOnFirstOccurrence->setWhatsThis( chbHaltOnFirstOccurrenceWhatthis);
226 m_chbFollowSymLinks->setWhatsThis( chbFollowSymLinksWhatthis);
227 m_chbIgnoreHidden->setWhatsThis( chbIgnoreHiddenWhatthis);
228 m_chbIgnoreFiles->setWhatsThis( chbIgnoreFilesWhatthis);
229 m_chbRegularExpressions->setWhatsThis( chbRegularExpressionsWhatthis);
230 m_chbVariables->setWhatsThis( chbVariablesWhatthis);
231 m_chbBackup->setWhatsThis( chbBackupWhatthis);
232 m_chbConfirmStrings->setWhatsThis( chbConfirmStringsWhatthis);
233}
234
235#include "koptionsdlg.moc"
236