1
/***********************************************************************
5
**********************************************************************/
7
#include <qbuttongroup.h>
8
#include <qradiobutton.h>
11
#include <qcheckbox.h>
12
#include <qwhatsthis.h>
14
#include <qcombobox.h>
16
#include <qpushbutton.h>
17
#include <qapplication.h>
19
#include <kcalendarsystem.h>
21
#include <kcombobox.h>
22
#include <klineedit.h>
24
#include <kmessagebox.h>
25
#include <kfiledialog.h>
26
#include <kregexpeditorinterface.h>
27
#include <kparts/componentfactory.h>
28
#include <kstandarddirs.h>
33
// Static utility functions
34
static void save_pattern(QComboBox *, const QString &, const QString &);
36
#define SPECIAL_TYPES 7
38
class KSortedMimeTypeList : public QPtrList<KMimeType>
41
KSortedMimeTypeList() { };
42
int compareItems(QPtrCollection::Item s1, QPtrCollection::Item s2)
44
KMimeType *item1 = (KMimeType *) s1;
45
KMimeType *item2 = (KMimeType *) s2;
46
if (item1->comment() > item2->comment()) return 1;
47
if (item1->comment() == item2->comment()) return 0;
52
KfindTabWidget::KfindTabWidget(QWidget *parent, const char *name)
53
: QTabWidget( parent, name ), regExpDialog(0)
55
// This validator will be used for all numeric edit fields
56
//KDigitValidator *digitV = new KDigitValidator(this);
58
// ************ Page One ************
60
pages[0] = new QWidget( this, "page1" );
62
nameBox = new KComboBox(TRUE, pages[0], "combo1");
63
nameBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); // allow smaller than widest entry
64
QLabel * namedL = new QLabel(nameBox, i18n("&Named:"), pages[0], "named");
65
QToolTip::add( namedL, i18n("You can use wildcard matching and \";\" for separating multiple names") );
66
dirBox = new KComboBox(TRUE, pages[0], "combo2");
67
dirBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); // allow smaller than widest entry
68
QLabel * lookinL = new QLabel(dirBox, i18n("Look &in:"), pages[0], "named");
69
subdirsCb = new QCheckBox(i18n("Include &subfolders"), pages[0]);
70
caseSensCb = new QCheckBox(i18n("Case s&ensitive search"), pages[0]);
71
browseB = new QPushButton(i18n("&Browse..."), pages[0]);
72
useLocateCb = new QCheckBox(i18n("&Use files index"), pages[0]);
76
subdirsCb->setChecked(true);
77
caseSensCb->setChecked(false);
78
useLocateCb->setChecked(false);
79
if(KStandardDirs::findExe("locate")==NULL)
80
useLocateCb->setEnabled(false);
82
nameBox->setDuplicatesEnabled(FALSE);
84
dirBox->setDuplicatesEnabled(FALSE);
86
nameBox->setInsertionPolicy(QComboBox::AtTop);
87
dirBox->setInsertionPolicy(QComboBox::AtTop);
89
const QString nameWhatsThis
90
= i18n("<qt>Enter the filename you are looking for. <br>"
91
"Alternatives may be separated by a semicolon \";\".<br>"
93
"The filename may contain the following special characters:"
95
"<li><b>?</b> matches any single character</li>"
96
"<li><b>*</b> matches zero or more of any characters</li>"
97
"<li><b>[...]</b> matches any of the characters in braces</li>"
102
"<li><b>*.kwd;*.txt</b> finds all files ending with .kwd or .txt</li>"
103
"<li><b>go[dt]</b> finds god and got</li>"
104
"<li><b>Hel?o</b> finds all files that start with \"Hel\" and end with \"o\", "
105
"having one character in between</li>"
106
"<li><b>My Document.kwd</b> finds a file of exactly that name</li>"
108
QWhatsThis::add(nameBox,nameWhatsThis);
109
QWhatsThis::add(namedL,nameWhatsThis);
110
const QString whatsfileindex
111
= i18n("<qt>This lets you use the files' index created by the <i>slocate</i> "
112
"package to speed-up the search; remember to update the index from time to time "
113
"(using <i>updatedb</i>)."
115
QWhatsThis::add(useLocateCb,whatsfileindex);
119
QGridLayout *grid = new QGridLayout( pages[0], 3, 2,
120
KDialog::marginHint(),
121
KDialog::spacingHint() );
122
QBoxLayout *subgrid = new QVBoxLayout( -1 , "subgrid" );
123
grid->addWidget( namedL, 0, 0 );
124
grid->addMultiCellWidget( nameBox, 0, 0, 1, 2 );
125
grid->addWidget( lookinL, 1, 0 );
126
grid->addWidget( dirBox, 1, 1 );
127
grid->addWidget( browseB, 1, 2);
128
grid->setColStretch(1,1);
129
grid->addMultiCellLayout( subgrid, 2, 2, 1, 2 );
130
subgrid->addWidget( subdirsCb );
131
subgrid->addWidget( caseSensCb);
132
subgrid->addWidget( useLocateCb );
133
subgrid->addStretch(1);
137
connect( browseB, SIGNAL(clicked()),
138
this, SLOT(getDirectory()) );
140
connect( nameBox, SIGNAL(activated(int)),
141
this, SIGNAL(startSearch()));
143
// ************ Page Two
145
pages[1] = new QWidget( this, "page2" );
147
findCreated = new QCheckBox(i18n("Find all files created or &modified:"), pages[1]);
148
bg = new QButtonGroup();
149
rb[0] = new QRadioButton(i18n("&between"), pages[1] );
150
rb[1] = new QRadioButton(i18n("&during the previous"), pages[1] );
151
QLabel * andL = new QLabel(i18n("and"), pages[1], "and");
152
betweenType = new KComboBox(FALSE, pages[1], "comboBetweenType");
153
betweenType->insertItem(i18n("minute(s)"));
154
betweenType->insertItem(i18n("hour(s)"));
155
betweenType->insertItem(i18n("day(s)"));
156
betweenType->insertItem(i18n("month(s)"));
157
betweenType->insertItem(i18n("year(s)"));
158
betweenType->setCurrentItem(1);
161
QDate dt = KGlobal::locale()->calendar()->addYears(QDate::currentDate(), -1);
163
fromDate = new KDateCombo(dt, pages[1], "fromDate");
164
toDate = new KDateCombo(pages[1], "toDate");
165
timeBox = new QSpinBox(1, 60, 1, pages[1], "timeBox");
167
sizeBox =new KComboBox(FALSE, pages[1], "sizeBox");
168
QLabel * sizeL =new QLabel(sizeBox,i18n("File &size is:"), pages[1],"size");
169
sizeEdit=new QSpinBox(0, INT_MAX, 1, pages[1], "sizeEdit" );
170
sizeEdit->setValue(1);
171
sizeUnitBox =new KComboBox(FALSE, pages[1], "sizeUnitBox");
173
m_usernameBox = new KComboBox( true, pages[1], "m_combo1");
174
QLabel *usernameLabel= new QLabel(m_usernameBox,i18n("Files owned by &user:"),pages[1]);
175
m_groupBox = new KComboBox( true, pages[1], "m_combo2");
176
QLabel *groupLabel= new QLabel(m_groupBox,i18n("Owned by &group:"),pages[1]);
178
sizeBox ->insertItem( i18n("(none)") );
179
sizeBox ->insertItem( i18n("At Least") );
180
sizeBox ->insertItem( i18n("At Most") );
181
sizeBox ->insertItem( i18n("Equal To") );
183
sizeUnitBox ->insertItem( i18n("Bytes") );
184
sizeUnitBox ->insertItem( i18n("KB") );
185
sizeUnitBox ->insertItem( i18n("MB") );
186
sizeUnitBox ->insertItem( i18n("GB") );
187
sizeUnitBox ->setCurrentItem(1);
189
int tmp = sizeEdit->fontMetrics().width(" 000000000 ");
190
sizeEdit->setMinimumSize(tmp, sizeEdit->sizeHint().height());
192
m_usernameBox->setDuplicatesEnabled(FALSE);
193
m_groupBox->setDuplicatesEnabled(FALSE);
194
m_usernameBox->setInsertionPolicy(QComboBox::AtTop);
195
m_groupBox->setInsertionPolicy(QComboBox::AtTop);
199
timeBox->setButtonSymbols(QSpinBox::PlusMinus);
200
rb[0]->setChecked(true);
206
QGridLayout *grid1 = new QGridLayout( pages[1], 5, 6,
207
KDialog::marginHint(),
208
KDialog::spacingHint() );
210
grid1->addMultiCellWidget(findCreated, 0, 0, 0, 3 );
211
grid1->addColSpacing(0, KDialog::spacingHint());
213
grid1->addWidget(rb[0], 1, 1 );
214
grid1->addWidget(fromDate, 1, 2 );
215
grid1->addWidget(andL, 1, 3, AlignHCenter );
216
grid1->addWidget(toDate, 1, 4 );
218
grid1->addWidget(rb[1], 2, 1 );
219
grid1->addMultiCellWidget(timeBox, 2, 2, 2, 3);
220
grid1->addWidget(betweenType, 2, 4 );
222
grid1->addMultiCellWidget(sizeL,3,3,0,1);
223
grid1->addWidget(sizeBox,3,2);
224
grid1->addWidget(sizeEdit,3,3);
225
grid1->addWidget(sizeUnitBox,3,4);
227
grid1->addMultiCellWidget(usernameLabel,4,4,0,1);
228
grid1->addWidget(m_usernameBox,4,2);
229
grid1->addWidget(groupLabel,4,3);
230
grid1->addWidget(m_groupBox,4,4);
232
for (int c=1; c<=4; c++)
233
grid1->setColStretch(c,1);
235
grid1->setRowStretch(6,1);
238
connect( findCreated, SIGNAL(toggled(bool)), SLOT(fixLayout()) );
239
connect( bg, SIGNAL(clicked(int)), this, SLOT(fixLayout()) );
240
connect( sizeBox, SIGNAL(highlighted(int)), this, SLOT(slotSizeBoxChanged(int)));
243
// ************ Page Three
245
pages[2] = new QWidget( this, "page3" );
247
typeBox =new KComboBox(FALSE, pages[2], "typeBox");
248
typeBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); // allow smaller than widest entry
249
QLabel * typeL =new QLabel(typeBox, i18n("File &type:"), pages[2], "type");
250
textEdit=new KLineEdit(pages[2], "textEdit" );
251
QLabel * textL =new QLabel(textEdit, i18n("C&ontaining text:"), pages[2], "text");
253
connect( textEdit, SIGNAL(returnPressed(const QString &)), SIGNAL( startSearch()));
255
const QString containingtext
256
= i18n("<qt>If specified, only files that contain this text"
257
" are found. Note that not all file types from the list"
258
" above are supported. Please refer to the documentation"
259
" for a list of supported file types."
261
QToolTip::add(textEdit,containingtext);
262
QWhatsThis::add(textL,containingtext);
264
caseContextCb =new QCheckBox(i18n("Case s&ensitive"), pages[2]);
265
binaryContextCb =new QCheckBox(i18n("Include &binary files"), pages[2]);
266
regexpContentCb =new QCheckBox(i18n("Regular e&xpression"), pages[2]);
268
const QString binaryTooltip
269
= i18n("<qt>This lets you search in any type of file, "
270
"even those that usually do not contain text (for example "
271
"program files and images).</qt>");
272
QToolTip::add(binaryContextCb,binaryTooltip);
274
QPushButton* editRegExp = 0;
275
if ( !KTrader::self()->query("KRegExpEditor/KRegExpEditor").isEmpty() ) {
276
// The editor is available, so lets use it.
277
editRegExp = new QPushButton(i18n("&Edit..."), pages[2], "editRegExp");
280
metainfokeyEdit=new KLineEdit(pages[2], "textEdit" );
281
metainfoEdit=new KLineEdit(pages[2], "textEdit" );
282
QLabel * textMetaInfo = new QLabel(metainfoEdit, i18n("fo&r:"), pages[2], "text");
283
QLabel * textMetaKey = new QLabel(metainfokeyEdit, i18n("Search &metainfo sections:"), pages[2], "text");
286
typeBox->insertItem(i18n("All Files & Folders"));
287
typeBox->insertItem(i18n("Files"));
288
typeBox->insertItem(i18n("Folders"));
289
typeBox->insertItem(i18n("Symbolic Links"));
290
typeBox->insertItem(i18n("Special Files (Sockets, Device Files, ...)"));
291
typeBox->insertItem(i18n("Executable Files"));
292
typeBox->insertItem(i18n("SUID Executable Files"));
293
typeBox->insertItem(i18n("All Images"));
294
typeBox->insertItem(i18n("All Video"));
295
typeBox->insertItem(i18n("All Sounds"));
298
initSpecialMimeTypes();
300
for ( KMimeType::List::ConstIterator it = m_types.begin();
301
it != m_types.end(); ++it )
303
KMimeType::Ptr typ = *it;
304
typeBox->insertItem(typ->pixmap( KIcon::Small ), typ->comment());
308
// The editor was available, so lets use it.
309
connect( regexpContentCb, SIGNAL(toggled(bool) ), editRegExp, SLOT(setEnabled(bool)) );
310
editRegExp->setEnabled(false);
311
connect( editRegExp, SIGNAL(clicked()), this, SLOT( slotEditRegExp() ) );
314
regexpContentCb->hide();
317
tmp = sizeEdit->fontMetrics().width(" 00000 ");
318
sizeEdit->setMinimumSize(tmp, sizeEdit->sizeHint().height());
320
QGridLayout *grid2 = new QGridLayout( pages[2], 5, 4,
321
KDialog::marginHint(),
322
KDialog::spacingHint() );
323
grid2->addWidget( typeL, 0, 0 );
324
grid2->addWidget( textL, 1, 0 );
325
grid2->addMultiCellWidget( typeBox, 0, 0, 1, 3 );
326
grid2->addMultiCellWidget( textEdit, 1, 1, 1, 3 );
327
grid2->addWidget( regexpContentCb, 2, 2);
328
grid2->addWidget( caseContextCb, 2, 1 );
329
grid2->addWidget( binaryContextCb, 3, 1);
331
grid2->addWidget( textMetaKey, 4, 0 );
332
grid2->addWidget( metainfokeyEdit, 4, 1 );
333
grid2->addWidget( textMetaInfo, 4, 2, AlignHCenter );
334
grid2->addWidget( metainfoEdit, 4, 3 );
336
metainfokeyEdit->setText("*");
339
// The editor was available, so lets use it.
340
grid2->addWidget( editRegExp, 2, 3 );
343
addTab( pages[0], i18n("Name/&Location") );
344
addTab( pages[2], i18n("C&ontents") );
345
addTab( pages[1], i18n("&Properties") );
349
const QString whatsmetainfo
350
= i18n("<qt>Search within files' specific comments/metainfo<br>"
351
"These are some examples:<br>"
353
"<li><b>Audio files (mp3...)</b> Search in id3 tag for a title, an album</li>"
354
"<li><b>Images (png...)</b> Search images with a special resolution, comment...</li>"
357
const QString whatsmetainfokey
358
= i18n("<qt>If specified, search only in this field<br>"
360
"<li><b>Audio files (mp3...)</b> This can be Title, Album...</li>"
361
"<li><b>Images (png...)</b> Search only in Resolution, Bitdepth...</li>"
364
QWhatsThis::add(textMetaInfo,whatsmetainfo);
365
QToolTip::add(metainfoEdit,whatsmetainfo);
366
QWhatsThis::add(textMetaKey,whatsmetainfokey);
367
QToolTip::add(metainfokeyEdit,whatsmetainfokey);
374
KfindTabWidget::~KfindTabWidget()
381
void KfindTabWidget::setURL( const KURL & url )
383
KConfig *conf = KGlobal::config();
384
conf->setGroup("History");
386
QStringList sl = conf->readPathListEntry("Directories");
387
dirBox->clear(); // make sure there is no old Stuff in there
390
dirBox->insertStringList(sl);
391
// If the _searchPath already exists in the list we do not
392
// want to add it again
393
int indx = sl.findIndex(m_url.prettyURL());
395
dirBox->insertItem(m_url.prettyURL(), 0); // make it the first one
397
dirBox->setCurrentItem(indx);
401
dirBox ->insertItem( m_url.prettyURL() );
402
dirBox ->insertItem( "file:" + QDir::homeDirPath() );
403
dirBox ->insertItem( "file:/" );
404
dirBox ->insertItem( "file:/usr" );
406
dirBox ->insertItem( "file:/lib" );
407
dirBox ->insertItem( "file:/home" );
408
dirBox ->insertItem( "file:/etc" );
409
dirBox ->insertItem( "file:/var" );
410
dirBox ->insertItem( "file:/mnt" );
414
void KfindTabWidget::initMimeTypes()
416
KMimeType::List tmp = KMimeType::allMimeTypes();
417
KSortedMimeTypeList sortedList;
418
for ( KMimeType::List::ConstIterator it = tmp.begin();
419
it != tmp.end(); ++it )
421
KMimeType * type = *it;
422
if ((!type->comment().isEmpty())
423
&& (!type->name().startsWith("kdedevice/"))
424
&& (!type->name().startsWith("all/")))
425
sortedList.append(type);
428
for ( KMimeType *type = sortedList.first(); type; type = sortedList.next())
430
m_types.append(type);
434
void KfindTabWidget::initSpecialMimeTypes()
436
KMimeType::List tmp = KMimeType::allMimeTypes();
438
for ( KMimeType::List::ConstIterator it = tmp.begin(); it != tmp.end(); ++it )
440
KMimeType * type = *it;
442
if(!type->comment().isEmpty()) {
443
if(type->name().startsWith("image/"))
444
m_ImageTypes.append(type->name());
445
else if(type->name().startsWith("video/"))
446
m_VideoTypes.append(type->name());
447
else if(type->name().startsWith("audio/"))
448
m_AudioTypes.append(type->name());
453
void KfindTabWidget::saveHistory()
455
save_pattern(nameBox, "History", "Patterns");
456
save_pattern(dirBox, "History", "Directories");
459
void KfindTabWidget::loadHistory()
461
// Load pattern history
462
KConfig *conf = KGlobal::config();
463
conf->setGroup("History");
464
QStringList sl = conf->readListEntry("Patterns");
466
nameBox->insertStringList(sl);
468
nameBox->insertItem("*");
470
sl = conf->readPathListEntry("Directories");
472
dirBox->insertStringList(sl);
473
// If the _searchPath already exists in the list we do not
474
// want to add it again
475
int indx = sl.findIndex(m_url.prettyURL());
477
dirBox->insertItem(m_url.prettyURL(), 0); // make it the first one
479
dirBox->setCurrentItem(indx);
483
dirBox ->insertItem( m_url.prettyURL() );
484
dirBox ->insertItem( "file:" + QDir::homeDirPath() );
485
dirBox ->insertItem( "file:/" );
486
dirBox ->insertItem( "file:/usr" );
488
dirBox ->insertItem( "file:/lib" );
489
dirBox ->insertItem( "file:/home" );
490
dirBox ->insertItem( "file:/etc" );
491
dirBox ->insertItem( "file:/var" );
492
dirBox ->insertItem( "file:/mnt" );
496
void KfindTabWidget::slotEditRegExp()
498
if ( ! regExpDialog )
499
regExpDialog = KParts::ComponentFactory::createInstanceFromQuery<QDialog>( "KRegExpEditor/KRegExpEditor", QString::null, this );
501
KRegExpEditorInterface *iface = static_cast<KRegExpEditorInterface *>( regExpDialog->qt_cast( "KRegExpEditorInterface" ) );
505
iface->setRegExp( textEdit->text() );
506
bool ok = regExpDialog->exec();
508
textEdit->setText( iface->regExp() );
511
void KfindTabWidget::setFocus()
514
nameBox->lineEdit()->selectAll();
517
void KfindTabWidget::slotSizeBoxChanged(int index)
519
sizeEdit->setEnabled((bool)(index != 0));
520
sizeUnitBox->setEnabled((bool)(index != 0));
523
void KfindTabWidget::setDefaults()
525
QDate dt = KGlobal::locale()->calendar()->addYears(QDate::currentDate(), -1);
527
fromDate ->setDate(dt);
528
toDate ->setDate(QDate::currentDate());
530
timeBox->setValue(1);
531
betweenType->setCurrentItem(1);
533
typeBox ->setCurrentItem(0);
534
sizeBox ->setCurrentItem(0);
535
sizeUnitBox ->setCurrentItem(1);
536
sizeEdit->setValue(1);
540
Checks if dates are correct and popups a error box
543
bool KfindTabWidget::isDateValid()
546
if ( !findCreated->isChecked() ) return TRUE;
548
if (rb[1]->isChecked())
550
if (timeBox->value() > 0 ) return TRUE;
552
KMessageBox::sorry(this, i18n("Unable to search within a period which is less than a minute."));
556
// If we can not parse either of the dates or
557
// "from" date is bigger than "to" date return FALSE.
561
if ( ! fromDate->getDate(&hi1).isValid() ||
562
! toDate->getDate(&hi2).isValid() )
563
str = i18n("The date is not valid.");
564
else if ( hi1 > hi2 )
565
str = i18n("Invalid date range.");
566
else if ( QDate::currentDate() < hi1 )
567
str = i18n("Unable to search dates in the future.");
570
KMessageBox::sorry(0, str);
576
void KfindTabWidget::setQuery(KQuery *query)
578
KIO::filesize_t size;
579
KIO::filesize_t sizeunit;
580
bool itemAlreadyContained(false);
581
// only start if we have valid dates
582
if (!isDateValid()) return;
584
query->setPath(KURL(dirBox->currentText().stripWhiteSpace()));
586
for (int idx=0; idx<dirBox->count(); idx++)
587
if (dirBox->text(idx)==dirBox->currentText())
588
itemAlreadyContained=true;
590
if (!itemAlreadyContained)
591
dirBox->insertItem(dirBox->currentText().stripWhiteSpace(),0);
593
QString regex = nameBox->currentText().isEmpty() ? "*" : nameBox->currentText();
594
query->setRegExp(regex, caseSensCb->isChecked());
595
itemAlreadyContained=false;
596
for (int idx=0; idx<nameBox->count(); idx++)
597
if (nameBox->text(idx)==nameBox->currentText())
598
itemAlreadyContained=true;
600
if (!itemAlreadyContained)
601
nameBox->insertItem(nameBox->currentText(),0);
603
query->setRecursive(subdirsCb->isChecked());
605
switch (sizeUnitBox->currentItem())
608
sizeunit = 1; //one byte
611
sizeunit = 1048576; //1M
614
sizeunit = 1073741824; //1GB
616
case 1: //fall to default case
618
sizeunit = 1024; //1k
621
size = sizeEdit->value() * sizeunit;
623
// TODO: troeder: do we need this check since it is very unlikely-
624
// to exceed ULLONG_MAX with INT_MAX * 1024^3.-
625
// Or is there an arch where this can happen?
627
if (size < 0) // overflow
628
if (KMessageBox::warningYesNo(this, i18n("Size is too big. Set maximum size value?"), i18n("Error"),i18n("Set"),i18n("Do Not Set"))
631
sizeEdit->setValue(INT_MAX);
632
sizeUnitBox->setCurrentItem(0);
639
// set range mode and size value
640
query->setSizeRange(sizeBox->currentItem(),size,0);
646
// Add date predicate
647
if (findCreated->isChecked()) { // Modified
648
if (rb[0]->isChecked()) { // Between dates
650
fromDate->getDate(&q1);
651
toDate->getDate(&q2);
653
// do not generate negative numbers .. find doesn't handle that
654
time_t time1 = epoch.secsTo(q1);
655
time_t time2 = epoch.secsTo(q2.addDays(1)) - 1; // Include the last day
657
query->setTimeRange(time1, time2);
661
time_t cur = time(NULL);
662
time_t minutes = cur;
664
switch (betweenType->currentItem())
667
minutes = timeBox->value();
670
minutes = 60 * timeBox->value();
673
minutes = 60 * 24 * timeBox->value();
676
minutes = 60 * 24 * (time_t)(timeBox->value() * 30.41667);
679
minutes = 12 * 60 * 24 * (time_t)(timeBox->value() * 30.41667);
683
query->setTimeRange(cur - minutes * 60, 0);
687
query->setTimeRange(0, 0);
689
query->setUsername( m_usernameBox->currentText() );
690
query->setGroupname( m_groupBox->currentText() );
692
query->setFileType(typeBox->currentItem());
694
int id = typeBox->currentItem()-10;
696
if ((id >= -3) && (id < (int) m_types.count()))
701
query->setMimeType( m_ImageTypes );
704
query->setMimeType( m_VideoTypes );
707
query->setMimeType( m_AudioTypes );
710
query->setMimeType( m_types[id]->name() );
715
query->setMimeType( QString::null );
719
query->setMetaInfo(metainfoEdit->text(), metainfokeyEdit->text());
721
//Use locate to speed-up search ?
722
query->setUseFileIndex(useLocateCb->isChecked());
724
query->setContext(textEdit->text(), caseContextCb->isChecked(),
725
binaryContextCb->isChecked(), regexpContentCb->isChecked());
728
QString KfindTabWidget::date2String(const QDate & date) {
729
return(KGlobal::locale()->formatDate(date, true));
732
QDate &KfindTabWidget::string2Date(const QString & str, QDate *qd) {
733
return *qd = KGlobal::locale()->readDate(str);
736
void KfindTabWidget::getDirectory()
739
KFileDialog::getExistingDirectory( dirBox->text(dirBox->currentItem()).stripWhiteSpace(),
742
if (!result.isEmpty())
744
for (int i = 0; i < dirBox->count(); i++)
745
if (result == dirBox->text(i)) {
746
dirBox->setCurrentItem(i);
749
dirBox->insertItem(result, 0);
750
dirBox->setCurrentItem(0);
754
void KfindTabWidget::beginSearch()
756
/// dirlister->openURL(KURL(dirBox->currentText().stripWhiteSpace()));
762
void KfindTabWidget::endSearch()
768
Disables/enables all edit fields depending on their
769
respective check buttons.
771
void KfindTabWidget::fixLayout()
774
// If "All files" is checked - disable all edits
775
// and second radio group on page two
777
if(! findCreated->isChecked()) {
778
fromDate->setEnabled(FALSE);
779
toDate->setEnabled(FALSE);
780
timeBox->setEnabled(FALSE);
782
rb[i]->setEnabled(FALSE);
783
betweenType->setEnabled(FALSE);
787
rb[i]->setEnabled(TRUE);
789
fromDate->setEnabled(rb[0]->isChecked());
790
toDate->setEnabled(rb[0]->isChecked());
791
timeBox->setEnabled(rb[1]->isChecked());
792
betweenType->setEnabled(rb[1]->isChecked());
795
// Size box on page three
796
sizeEdit->setEnabled(sizeBox->currentItem() != 0);
797
sizeUnitBox->setEnabled(sizeBox->currentItem() != 0);
800
bool KfindTabWidget::isSearchRecursive()
802
return subdirsCb->isChecked();
807
Digit validator. Allows only digits to be typed.
809
KDigitValidator::KDigitValidator( QWidget * parent, const char *name )
810
: QValidator( parent, name )
812
r = new QRegExp("^[0-9]*$");
815
KDigitValidator::~KDigitValidator()
820
QValidator::State KDigitValidator::validate( QString & input, int & ) const
822
if (r->search(input) < 0) {
823
// Beep on user if he enters non-digit
824
QApplication::beep();
825
return QValidator::Invalid;
828
return QValidator::Acceptable;
831
//*******************************************************
832
// Static utility functions
833
//*******************************************************
834
static void save_pattern(QComboBox *obj,
835
const QString & group, const QString & entry)
837
// QComboBox allows insertion of items more than specified by
838
// maxCount() (QT bug?). This API call will truncate list if needed.
839
obj->setMaxCount(15);
841
// make sure the current item is saved first so it will be the
842
// default when started next time
844
QString cur = obj->currentText();
846
for (int i = 0; i < obj->count(); i++) {
847
if( cur != obj->text(i) ) {
848
sl.append(obj->text(i));
852
KConfig *conf = KGlobal::config();
853
conf->setGroup(group);
854
conf->writePathEntry(entry, sl);
857
QSize KfindTabWidget::sizeHint() const
859
// #44662: avoid a huge default size when the comboboxes have very large items
860
// Like in minicli, we changed the combobox size policy so that they can resize down,
861
// and then we simply provide a reasonable size hint for the whole window, depending
862
// on the screen width.
863
QSize sz = QTabWidget::sizeHint();
864
KfindTabWidget* me = const_cast<KfindTabWidget*>( this );
865
const int screenWidth = qApp->desktop()->screenGeometry(me).width();
866
if ( sz.width() > screenWidth / 2 )
867
sz.setWidth( screenWidth / 2 );
871
#include "kftabdlg.moc"