1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
|
/***************************************************************************
knewprojectdlg.cpp - description
-------------------
begin : Tue Dec 28 1999
copyright : (C) 1999 by Fran�is Dupoux
(C) 2004 Emiliano Gulmini <emi_barbarossa@yahoo.it>
email : dupoux@dupoux.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "knewprojectdlg.h"
#include "resource.h"
//QT
#include <qwhatsthis.h>
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qspinbox.h>
//KDE
#include <kseparator.h>
#include <kmessagebox.h>
#include <kcombobox.h>
#include <kconfig.h>
#include <kfiledialog.h>
#include <klineedit.h>
#include <klocale.h>
#include <kpushbutton.h>
#include <kstandarddirs.h>
#include <kdeversion.h>
#include <kdebug.h>
#include <kiconloader.h>
#include "whatthis.h"
using namespace whatthisNameSpace;
KNewProjectDlg::KNewProjectDlg(QWidget *parent, KConfig *config, const char *name/*=0*/) : KNewProjectDlgS(parent, name, true)
{
// copy data
m_config = config;
m_searchLater = false;
QIconSet iconSet = SmallIconSet(QString::fromLatin1("fileopen"));
QPixmap pixMap = iconSet.pixmap( QIconSet::Small, QIconSet::Normal );
pbLocation->setIconSet(iconSet);
pbLocation->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
spbSizeMin->setEnabled(chbSizeMin->isChecked());
spbSizeMax->setEnabled(chbSizeMax->isChecked());
setWhatsThis();
loadLocationsList();
loadFiltersList();
connect(pbLocation, SIGNAL(clicked()), this, SLOT(slotDir()));
connect(pbOK, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(pbLater, SIGNAL(clicked()), this, SLOT(slotLater()));
connect(pbCancel, SIGNAL(clicked()), this, SLOT(reject()));
connect(chbSizeMin, SIGNAL(toggled(bool)), this, SLOT(slotEnableSpinboxSizeMin(bool)));
connect(chbSizeMax, SIGNAL(toggled(bool)), this, SLOT(slotEnableSpinboxSizeMax(bool)));
}
KNewProjectDlg::~KNewProjectDlg()
{
m_config = 0L;
}
QString KNewProjectDlg::searchFor()
{
return lineSearch->text();
}
QString KNewProjectDlg::replaceWith()
{
return lineReplace->text();
}
bool KNewProjectDlg::includeSubfolders()
{
return chbIncludeSubfolders->isChecked();
}
bool KNewProjectDlg::caseSensitive()
{
return chbCaseSensitive->isChecked();
}
bool KNewProjectDlg::enableWildcards()
{
return chbEnableWildcards->isChecked();
}
bool KNewProjectDlg::enableVariables()
{
return chbEnableVariables->isChecked();
}
QString KNewProjectDlg::location()
{
return cbLocation->currentText();
}
QString KNewProjectDlg::filter()
{
return cbFilter->currentText();
}
void KNewProjectDlg::slotDir()
{
QString directoryString;
directoryString = KFileDialog::getExistingDirectory(QString::null, this, i18n("Project Directory"));
if (!directoryString.isEmpty())
cbLocation->setEditText(directoryString);
}
void KNewProjectDlg::slotOK()
{
bool minimumSize,
maximumSize,
minimumDate,
maximumDate;
// Check the Search text and the Filter are not empty
if (location().isEmpty() || filter().isEmpty())
{
KMessageBox::error(this, i18n("You must fill the combo boxes (directory and filter) before continuing."));
m_searchLater = false;
return;
}
// Copy text into variables
saveLocationsList();
saveFiltersList();
// ================== SIZE OPTIONS ========================
maxFilesSize(maximumSize, m_MaximumSizeNumber);
minFilesSize(minimumSize, m_MinimumSizeNumber);
// ================== DATE OPTIONS ========================
QString minimumDateString, maximumDateString;
minimumDate = chbDateMin->isChecked();
maximumDate = chbDateMax->isChecked();
minimumDateString = edDateMin->text();
maximumDateString = edDateMax->text();
// ================== OWNER OPTIONS ========================
bool OwnerUser, OwnerGroup;
OwnerUser = isOwnerUser();
OwnerGroup = isOwnerGroup();
if ((OwnerUser && edOwnerUser->text().isEmpty()) || (OwnerGroup && edOwnerGroup->text().isEmpty()))
{
KMessageBox::error(this, i18n("Some edit boxes are empty in the <b>Owner</b> page."));
m_searchLater = false;
return ;
}
// =========================================================
// Check all the fields are filled
if ( (minimumDate && edDateMin->text().isEmpty())
|| (maximumDate && edDateMax->text().isEmpty()) )
{
KMessageBox::error(this, i18n("Some edit boxes are empty"));
m_searchLater = false;
return ;
}
// Check option "Size Min/Max": check MinSize is not greater than MaxSize
if (maximumSize && minimumSize && (m_MaximumSizeNumber < m_MinimumSizeNumber))
{
KMessageBox::error(this, i18n("The minimum size is greater than the maximum size."));
m_searchLater = false;
return ;
}
// Check option "Date Min/Max": check date is valid
// Check 2 things: * QRegExp ==> valid text (2/2/4)
// * QDate::isValid()
// 1. Check the first Date: DateMin (After...)
if (minimumDate) // If "DateMin" option in checked
{
if ( !QDate::fromString(minimumDateString, Qt::ISODate).isValid())
{
KMessageBox::error(this, i18n("The dates must be in the YYYY-MM-DD format."));
m_searchLater = false;
return ;
}
}
// 2. Check the second Date: DateMax (Before...)
if (maximumDate) // If "DateMax" option in checked
{
if ( !QDate::fromString(maximumDateString, Qt::ISODate).isValid())
{
KMessageBox::error(this, i18n("The dates must be in the YYYY-MM-DD format."));
m_searchLater = false;
return ;
}
}
// 3. Convert Strings to QDate
if (minimumDate) // If "DateMin" option in checked
m_MinDate = QDate::fromString(minimumDateString, Qt::ISODate);
if (maximumDate) // If "DateMax" option in checked
m_MaxDate = QDate::fromString(maximumDateString, Qt::ISODate);
// 4. Check DateMax is not before DateMin
if (minimumDate && maximumDate && m_MinDate > m_MaxDate)
{
KMessageBox::error(this, i18n("<qt>The <i>accessed after</i> date is after the <i>accessed before</i> date."));
m_searchLater = false;
return ;
}
accept();
}
void KNewProjectDlg::slotLater()
{
m_searchLater = true;
slotOK();
}
void KNewProjectDlg::slotEnableSpinboxSizeMin(bool b)
{
spbSizeMin->setEnabled(b);
}
void KNewProjectDlg::slotEnableSpinboxSizeMax(bool b)
{
spbSizeMax->setEnabled(b);
}
void KNewProjectDlg::loadLocationsList()
{
m_config->setGroup("Directories");
#if KDE_IS_VERSION(3,1,3)
QString locationsEntry = m_config->readPathEntry("Directories list");
#else
QString locationsEntry = m_config->readEntry("Directories list");
#endif
QStringList locationsEntryList = QStringList::split(",",locationsEntry);
cbLocation->insertStringList(locationsEntryList);
if(cbLocation->count() == 0)
cbLocation->insertItem(QDir::current().path());
}
void KNewProjectDlg::loadFiltersList()
{
m_config->setGroup("Filters");
#if KDE_IS_VERSION(3,1,3)
QStringList filtersEntryList = m_config->readPathListEntry("Filters list");
#else
QStringList filtersEntryList = m_config->readListEntry("Filters list");
#endif
cbFilter->insertStringList(filtersEntryList);
if(cbFilter->count() == 0)
cbFilter->insertItem("*.htm;*.html;*.xml;*.xhtml;*.css;*.js;*.php");
}
void KNewProjectDlg::saveLocationsList()
{
m_config->setGroup("Directories");
#if KDE_IS_VERSION(3,1,3)
QStringList locationsEntryList = m_config->readPathListEntry("Directories list");
#else
QStringList locationsEntryList = m_config->readListEntry("Directories list");
#endif
QString lineText = cbLocation->lineEdit()->text();
if(locationsEntryList.contains(lineText) == 0)
locationsEntryList.append(lineText);
m_config->writeEntry("Directories list",locationsEntryList.join(","));
m_config->sync();
}
void KNewProjectDlg::saveFiltersList()
{
m_config->setGroup("Filters");
#if KDE_IS_VERSION(3,1,3)
QStringList filtersEntryList = m_config->readPathListEntry("Filters list");
#else
QStringList filtersEntryList = m_config->readListEntry("Filters list");
#endif
QString lineText = cbFilter->lineEdit()->text();
if(filtersEntryList.contains(lineText) == 0)
filtersEntryList.append(lineText);
m_config->writeEntry("Filters list",filtersEntryList.join(","));
m_config->sync();
}
void KNewProjectDlg::setWhatsThis()
{
QWhatsThis::add(cbLocation, i18n(cbLocationWhatthis));
QWhatsThis::add(cbFilter, i18n(cbFilterWhatthis));
QWhatsThis::add(spbSizeMin, i18n(edSizeMinWhatthis));
QWhatsThis::add(spbSizeMax, i18n(edSizeMaxWhatthis));
QWhatsThis::add(edDateMin, i18n(edDateMinWhatthis));
QWhatsThis::add(edDateMax, i18n(edDateMaxWhatthis));
QWhatsThis::add(cbDateValid, i18n(cbDateValidWhatthis));
}
void KNewProjectDlg::maxFilesSize(bool & bChecked, long unsigned int & nMaxSize)
{
bChecked = chbSizeMax->isChecked();
if (bChecked) // If option activated
nMaxSize = spbSizeMax->value() * 1024; // KB --> Bytes
else
nMaxSize = 0;
}
void KNewProjectDlg::minFilesSize(bool & bChecked, long unsigned int & nMinSize)
{
bChecked = chbSizeMin->isChecked();
if (bChecked) // If option activated
nMinSize = spbSizeMin->value() * 1024; // KB --> Bytes
else
nMinSize = 0;
}
int KNewProjectDlg::accessType()
{
return cbDateValid->currentItem();
}
bool KNewProjectDlg::isMinDate()
{
return chbDateMin->isChecked();
}
bool KNewProjectDlg::isMaxDate()
{
return chbDateMax->isChecked();
}
bool KNewProjectDlg::isMinSize()
{
return chbSizeMin->isChecked();
}
bool KNewProjectDlg::isMaxSize()
{
return chbSizeMax->isChecked();
}
bool KNewProjectDlg::isOwnerUser()
{
return chbOwnerUser->isChecked();
}
bool KNewProjectDlg::isOwnerGroup()
{
return chbOwnerGroup->isChecked();
}
bool KNewProjectDlg::ownerUserMustBe()
{
return (cbOwnerUserBool->currentText() == i18n("must be"));
}
bool KNewProjectDlg::ownerGroupMustBe()
{
return (cbOwnerGroupBool->currentText() == i18n("must be"));
}
QString KNewProjectDlg::ownerUserValue()
{
return edOwnerUser->text();
}
QString KNewProjectDlg::ownerGroupValue()
{
return edOwnerGroup->text();
}
QString KNewProjectDlg::ownerUserType()
{
return cbOwnerUserType->currentText();
}
QString KNewProjectDlg::ownerGroupType()
{
return cbOwnerGroupType->currentText();
}
QDate KNewProjectDlg::minDate()
{
return m_MinDate;
}
QDate KNewProjectDlg::maxDate()
{
return m_MaxDate;
}
unsigned long int KNewProjectDlg::minSize()
{
return m_MinimumSizeNumber;
}
unsigned long int KNewProjectDlg::maxSize()
{
return m_MaximumSizeNumber;
}
void KNewProjectDlg::setDatas(const QString& directoryString, const QString& FilterString)
{
if (!directoryString.isEmpty())
cbLocation->setEditText(directoryString);
if (!FilterString.isEmpty())
cbFilter->setEditText(FilterString);
}
#include "knewprojectdlg.moc"
|