1/***************************************************************************
2 knewprojectdlg.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
20//QT
21
22#include <qcheckbox.h>
23#include <qspinbox.h>
24#include <qlabel.h>
25#include <qradiobutton.h>
26#include <q3listview.h>
27//Added by qt3to4:
28#include <QPixmap>
29
30//KDE
31#include <kseparator.h>
32#include <kmessagebox.h>
33#include <kcharsets.h>
34#include <kcombobox.h>
35#include <kconfig.h>
36#include <kfiledialog.h>
37#include <klineedit.h>
38#include <kglobal.h>
39#include <klocale.h>
40#include <kpushbutton.h>
41#include <kstandarddirs.h>
42#include <kdeversion.h>
43#include <kiconloader.h>
44#include <kdebug.h>
45#include <kapplication.h>
46
47// local
48#include "knewprojectdlg.h"
49#include "whatthis.h"
50
51using namespace whatthisNameSpace;
52
53
54KNewProjectDlg::KNewProjectDlg(RCOptions* info, QWidget *parent, const char *name) : KNewProjectDlgS(parent, name)
55{
56 m_searchNowFlag = "";
57 m_option = info;
58
59 initGUI();
60
61 connect(m_pbLocation, SIGNAL(clicked()), this, SLOT(slotDir()));
62 connect(m_pbCancel, SIGNAL(clicked()), this, SLOT(slotReject()));
63 connect(m_pbSearchNow, SIGNAL(clicked()), this, SLOT(slotSearchNow()));
64 connect(m_pbSearchLater, SIGNAL(clicked()), this, SLOT(slotSearchLater()));
65 connect(m_leSearch, SIGNAL(textChanged(const QString&)), this, SLOT(slotSearchLineEdit(const QString&)));
66 connect(m_chbSizeMin, SIGNAL(toggled(bool)), this, SLOT(slotEnableSpinboxSizeMin(bool)));
67 connect(m_chbSizeMax, SIGNAL(toggled(bool)), this, SLOT(slotEnableSpinboxSizeMax(bool)));
68 connect(m_chbDateMin, SIGNAL(toggled(bool)), m_dedDateMin, SLOT(setEnabled(bool)));
69 connect(m_chbDateMax, SIGNAL(toggled(bool)), m_dedDateMax, SLOT(setEnabled(bool)));
70 connect(m_chbDateMin,SIGNAL(toggled(bool)),this, SLOT(slotEnableCbValidDate(bool)));
71 connect(m_chbDateMax,SIGNAL(toggled(bool)),this, SLOT(slotEnableCbValidDate(bool)));
72 connect(m_chbOwnerUser, SIGNAL(toggled(bool)), this, SLOT(slotEnableChbUser(bool)));
73 connect(m_chbOwnerGroup, SIGNAL(toggled(bool)), this, SLOT(slotEnableChbGroup(bool)));
74 connect(m_chbBackup, SIGNAL(toggled(bool)), this, SLOT(slotEnableChbBackup(bool)));
75 connect(m_pbHelp, SIGNAL(clicked()), this, SLOT(slotHelp()));
76
77 whatsThis();
78}
79
80KNewProjectDlg::~KNewProjectDlg()
81{
82}
83
84void KNewProjectDlg::saveRCOptions()
85{
86 saveOptions();
87 saveFileSizeOptions();
88 saveDateAccessOptions();
89 saveOwnerOptions();
90 saveLocationsList();
91 saveFiltersList();
92 saveBackupExtensionOptions();
93}
94
95void KNewProjectDlg::slotDir()
96{
97 QString directoryString = KFileDialog::getExistingDirectory(KUrl(), this, i18n("Project Directory"));
98 if(!directoryString.isEmpty())
99 m_cbLocation->setEditText(directoryString);
100}
101
102void KNewProjectDlg::slotOK()
103{
104 // Check that Search text and Filter are not empty
105 m_option->m_directories = m_cbLocation->currentText();
106 m_option->m_filters = m_cbFilter->currentText();
107 if(!m_leSearch->text().isEmpty())
108 {
109 if(m_leReplace->text().isEmpty())
110 m_option->m_searchingOnlyMode = true;
111 else
112 m_option->m_searchingOnlyMode = false;
113 }
114 m_option->m_quickSearchString = m_searchNowFlag + m_leSearch->text();
115 m_option->m_quickReplaceString = m_searchNowFlag + m_leReplace->text();
116
117 if (m_option->m_directories.isEmpty() || m_option->m_filters.isEmpty())
118 {
119 KMessageBox::error(this, i18n("You must fill the combo boxes (location and filter) before continuing."));
120 return;
121 }
122
123 // OWNER OPTIONS
124 if ((m_chbOwnerUser->isChecked() && m_edOwnerUser->text().isEmpty()) ||
125 (m_chbOwnerGroup->isChecked() && m_edOwnerGroup->text().isEmpty()))
126 {
127 KMessageBox::error(this, i18n("Some edit boxes are empty in the <b>Owner</b> page."));
128 return ;
129 }
130
131 // Check option "Size Min/Max": check MinSize is not greater than MaxSize
132 int minSize = m_spbSizeMin->value(),
133 maxSize = m_spbSizeMax->value();
134 if ((minSize != FileSizeOption) && (maxSize != FileSizeOption))
135 if (minSize > maxSize)
136 {
137 KMessageBox::error(this, i18n("The minimum size is greater than the maximum size."));
138 return ;
139 }
140
141 accept();
142}
143
144void KNewProjectDlg::slotReject()
145{
146 m_option->m_quickSearchString = m_searchNowFlag;
147 m_option->m_quickReplaceString = m_searchNowFlag;
148
149 reject();
150}
151
152void KNewProjectDlg::slotSearchNow()
153{ //Add a 'N' to represent the status search-now
154 m_searchNowFlag = "N";
155 slotOK();
156}
157
158void KNewProjectDlg::slotSearchLater()
159{ //Add a 'L' to represent the status search-later
160 m_searchNowFlag = "L";
161 slotOK();
162}
163
164void KNewProjectDlg::slotSearchLineEdit(const QString& t)
165{
166 m_pbSearchNow->setEnabled(!t.isEmpty());
167}
168
169void KNewProjectDlg::slotEnableSpinboxSizeMin(bool b)
170{
171 m_spbSizeMin->setEnabled(b);
172}
173
174void KNewProjectDlg::slotEnableSpinboxSizeMax(bool b)
175{
176 m_spbSizeMax->setEnabled(b);
177}
178
179void KNewProjectDlg::slotEnableCbValidDate(bool b)
180{
181 Q_UNUSED(b);
182 m_cbDateValid->setEnabled(m_chbDateMax->isChecked() || m_chbDateMin->isChecked());
183}
184
185void KNewProjectDlg::slotEnableChbUser(bool b)
186{
187 m_cbOwnerUserType->setEnabled(b);
188 m_cbOwnerUserBool->setEnabled(b);
189 m_edOwnerUser->setEnabled(b);
190}
191
192void KNewProjectDlg::slotEnableChbGroup(bool b)
193{
194 m_cbOwnerGroupType->setEnabled(b);
195 m_cbOwnerGroupBool->setEnabled(b);
196 m_edOwnerGroup->setEnabled(b);
197}
198
199void KNewProjectDlg::slotEnableChbBackup(bool b)
200{
201 m_leBackup->setEnabled(b);
202 m_tlBackup->setEnabled(b);
203}
204
205//PRIVATE
206void KNewProjectDlg::initGUI()
207{
208 QIcon iconSet = SmallIconSet("document-open");
209 QPixmap pixMap = iconSet.pixmap( QIcon::Small, QIcon::Normal );
210
211 m_pbLocation->setIconSet(iconSet);
212 m_pbLocation->setFixedSize(pixMap.width() + 8, pixMap.height() + 8);
213
214 m_pbSearchNow->setEnabled(false);
215
216 loadOptions();
217 loadFileSizeOptions();
218 loadDateAccessOptions();
219 loadOwnerOptions();
220 loadBackupExtensionOptions();
221 loadLocationsList();
222 loadFiltersList();
223}
224
225void KNewProjectDlg::loadOptions()
226{
227 QStringList availableEncodingNames(KGlobal::charsets()->availableEncodingNames());
228 m_cbEncoding->addItems(availableEncodingNames);
229 int idx = -1;
230 int utf8Idx = -1;
231 for (int i = 0; i < availableEncodingNames.count(); i++)
232 {
233 if (availableEncodingNames[i] == m_option->m_encoding)
234 {
235 idx = i;
236 break;
237 }
238 if (availableEncodingNames[i] == "UTF-8")
239 {
240 utf8Idx = i;
241 }
242 }
243 if (idx != -1)
244 m_cbEncoding->setCurrentIndex(idx);
245 else
246 m_cbEncoding->setCurrentIndex(utf8Idx);
247
248 m_chbIncludeSubfolders->setChecked(m_option->m_recursive);
249 m_chbCaseSensitive->setChecked(m_option->m_caseSensitive);
250 m_chbEnableVariables->setChecked(m_option->m_variables);
251 m_chbRegularExpressions->setChecked(m_option->m_regularExpressions);
252}
253
254void KNewProjectDlg::loadFileSizeOptions()
255{
256 int size = m_option->m_minSize;
257 if(size == FileSizeOption)
258 {
259 m_chbSizeMin->setChecked(false);
260 m_spbSizeMin->setEnabled(false);
261 m_spbSizeMin->setValue(0);
262 }
263 else
264 {
265 m_chbSizeMin->setChecked(true);
266 m_spbSizeMin->setEnabled(true);
267 m_spbSizeMin->setValue(size);
268 }
269
270 size = m_option->m_maxSize;
271 if(size == FileSizeOption)
272 {
273 m_chbSizeMax->setChecked(false);
274 m_spbSizeMax->setEnabled(false);
275 m_spbSizeMax->setValue(0);
276 }
277 else
278 {
279 m_chbSizeMax->setChecked(true);
280 m_spbSizeMax->setEnabled(true);
281 m_spbSizeMax->setValue(size);
282 }
283}
284
285void KNewProjectDlg::loadDateAccessOptions()
286{
287 // ================== DATE OPTIONS ========================
288
289 QString date = m_option->m_minDate;
290 if(date == AccessDateOption)
291 {
292 m_chbDateMin->setChecked(false);
293 m_dedDateMin->setDate(m_dedDateMin->minValue());
294 m_dedDateMin->setEnabled(false);
295 }
296 else
297 {
298 m_chbDateMin->setChecked(true);
299 m_dedDateMin->setDate(QDate::fromString(date,Qt::ISODate));
300 m_dedDateMin->setEnabled(true);
301 }
302
303 date = m_option->m_maxDate;
304 if(date == AccessDateOption)
305 {
306 m_chbDateMax->setChecked(false);
307 m_dedDateMax->setDate(m_dedDateMax->maxValue());
308 m_dedDateMax->setEnabled(false);
309 }
310 else
311 {
312 m_chbDateMax->setChecked(true);
313 m_dedDateMax->setDate(QDate::fromString(date,Qt::ISODate));
314 m_dedDateMax->setEnabled(true);
315 }
316
317 m_cbDateValid->setEnabled(m_chbDateMax->isChecked() || m_chbDateMin->isChecked());
318
319}
320
321void KNewProjectDlg::loadOwnerOptions()
322{
323 bool enableOwner = m_option->m_ownerUserIsChecked;
324
325 m_chbOwnerUser->setChecked(enableOwner);
326 m_cbOwnerUserType->setEnabled(enableOwner);
327 m_cbOwnerUserBool->setEnabled(enableOwner);
328 m_edOwnerUser->setEnabled(enableOwner);
329
330 m_cbOwnerUserType->setCurrentText(m_option->m_ownerUserType);
331 m_cbOwnerUserBool->setCurrentText(m_option->m_ownerUserBool);
332
333 m_edOwnerUser->setText(m_option->m_ownerUserValue);
334
335 enableOwner = m_option->m_ownerGroupIsChecked;
336
337 m_chbOwnerGroup->setChecked(enableOwner);
338 m_cbOwnerGroupType->setEnabled(enableOwner);
339 m_cbOwnerGroupBool->setEnabled(enableOwner);
340 m_edOwnerGroup->setEnabled(enableOwner);
341
342 m_cbOwnerGroupType->setCurrentText(m_option->m_ownerGroupType);
343 m_cbOwnerGroupBool->setCurrentText(m_option->m_ownerGroupBool);
344 m_edOwnerGroup->setText(m_option->m_ownerGroupValue);
345}
346
347void KNewProjectDlg::loadLocationsList()
348{
349 m_cbLocation->addItems(m_option->m_directories.split(","));
350}
351
352void KNewProjectDlg::loadFiltersList()
353{
354 m_cbFilter->addItems(m_option->m_filters.split(","));
355}
356
357void KNewProjectDlg::loadBackupExtensionOptions()
358{
359 bool enableBackup = m_option->m_backup;
360
361 m_chbBackup->setChecked(enableBackup);
362 m_leBackup->setEnabled(enableBackup);
363 m_tlBackup->setEnabled(enableBackup);
364 m_leBackup->setText(m_option->m_backupExtension);
365}
366
367void KNewProjectDlg::saveOptions()
368{
369 m_option->m_encoding = m_cbEncoding->currentText();
370 m_option->m_recursive = m_chbIncludeSubfolders->isChecked();
371 m_option->m_caseSensitive = m_chbCaseSensitive->isChecked();
372 m_option->m_variables = m_chbEnableVariables->isChecked();
373 m_option->m_regularExpressions = m_chbRegularExpressions->isChecked();
374}
375
376void KNewProjectDlg::saveFileSizeOptions()
377{
378 if(m_chbSizeMax->isChecked())
379 m_option->m_maxSize = m_spbSizeMax->value();
380 else
381 m_option->m_maxSize = FileSizeOption;
382
383 if(m_chbSizeMin->isChecked())
384 m_option->m_minSize = m_spbSizeMin->value();
385 else
386 m_option->m_minSize = FileSizeOption;
387}
388
389void KNewProjectDlg::saveDateAccessOptions()
390{
391 if(m_chbDateMin->isChecked() || m_chbDateMax->isChecked())
392 m_option->m_dateAccess = m_cbDateValid->currentText();
393 else
394 m_option->m_dateAccess = ValidAccessDateOption;
395
396 if(m_chbDateMin->isChecked())
397 {
398 QString date = m_dedDateMin->date().toString(Qt::ISODate);
399 m_option->m_minDate = date;
400 }
401 else
402 m_option->m_minDate = AccessDateOption;
403
404 if(m_chbDateMax->isChecked())
405 {
406 QString date = m_dedDateMax->date().toString(Qt::ISODate);
407 m_option->m_maxDate = date;
408 }
409 else
410 m_option->m_maxDate = AccessDateOption;
411}
412
413void KNewProjectDlg::saveOwnerOptions()
414{
415 bool isChecked = m_chbOwnerUser->isChecked();
416 if(isChecked)
417 {
418 m_option->m_ownerUserIsChecked = true;
419 m_option->m_ownerUserType = m_cbOwnerUserType->currentText();
420 m_option->m_ownerUserBool = m_cbOwnerUserBool->currentText();
421 m_option->m_ownerUserValue = m_edOwnerUser->text();
422 }
423 else
424 {
425 m_option->m_ownerUserIsChecked = false;
426 m_option->m_ownerUserType = "Name";
427 m_option->m_ownerUserBool = "Equals To";
428 m_option->m_ownerUserValue = "";
429 }
430
431 isChecked = m_chbOwnerGroup->isChecked();
432 if(isChecked)
433 {
434 m_option->m_ownerGroupIsChecked = true;
435 m_option->m_ownerGroupType = m_cbOwnerGroupType->currentText();
436 m_option->m_ownerGroupBool = m_cbOwnerGroupBool->currentText();
437 m_option->m_ownerGroupValue = m_edOwnerGroup->text();
438 }
439 else
440 {
441 m_option->m_ownerGroupIsChecked = false;
442 m_option->m_ownerGroupType = "Name";
443 m_option->m_ownerGroupBool = "Equals To";
444 m_option->m_ownerGroupValue = "";
445 }
446}
447
448void KNewProjectDlg::saveLocationsList()
449{
450 QString current = m_cbLocation->currentText(), list = current;
451
452 int count = m_cbLocation->count(),
453 i;
454 for(i = 0; i < count; i++)
455 {
456 QString text = m_cbLocation->itemText(i);
457 if(text != current)
458 list += ','+text;
459 }
460 m_option->m_directories = list;
461}
462
463void KNewProjectDlg::saveFiltersList()
464{
465 QString current = m_cbFilter->currentText(), list = current;
466
467 int count = m_cbFilter->count(),
468 i;
469 for(i = 0; i < count; i++)
470 {
471 QString text = m_cbFilter->itemText(i);
472 if(text != current)
473 list += ','+text;
474 }
475 m_option->m_filters = list;
476}
477
478void KNewProjectDlg::saveBackupExtensionOptions()
479{
480 QString backupExt = m_leBackup->text();
481 m_option->m_backup = (m_chbBackup->isChecked() && !backupExt.isEmpty());
482 m_option->m_backupExtension = backupExt;
483}
484
485void KNewProjectDlg::setDatas(const QString& directoryString, const QString& filterString)
486{
487 if (!directoryString.isEmpty())
488 m_cbLocation->setEditText(directoryString);
489
490 if (!filterString.isEmpty())
491 m_cbFilter->setEditText(filterString);
492}
493
494bool KNewProjectDlg::contains(Q3ListView* lv,const QString& s, int column)
495{
496 Q3ListViewItem* i = lv->firstChild();
497 while (i != 0)
498 {
499 if(i->text(column) == s)
500 return true;
501 i = i->nextSibling();
502 }
503 return false;
504}
505
506void KNewProjectDlg::whatsThis()
507{
508 m_cbLocation->setWhatsThis( cbLocationWhatthis);
509 m_cbFilter->setWhatsThis( cbFilterWhatthis);
510
511 m_spbSizeMin->setWhatsThis( edSizeMinWhatthis);
512 m_spbSizeMax->setWhatsThis( edSizeMaxWhatthis);
513
514 m_cbDateValid->setWhatsThis( cbDateValidWhatthis);
515 m_chbDateMin->setWhatsThis( chbDateMinWhatthis);
516 m_chbDateMax->setWhatsThis( chbDateMaxWhatthis);
517
518 m_chbIncludeSubfolders->setWhatsThis( chbRecursiveWhatthis);
519 m_chbRegularExpressions->setWhatsThis( chbRegularExpressionsWhatthis);
520 m_chbEnableVariables->setWhatsThis( chbVariablesWhatthis);
521 m_chbCaseSensitive->setWhatsThis( chbCaseSensitiveWhatthis);
522 m_chbBackup->setWhatsThis( chbBackupWhatthis);
523 m_leBackup->setWhatsThis( chbBackupWhatthis);
524 m_leSearch->setWhatsThis( leSearchWhatthis);
525 m_leReplace->setWhatsThis( leReplaceWhatthis);
526}
527
528#include "knewprojectdlg.moc"
529
530