~ubuntu-branches/ubuntu/trusty/krusader/trusty

« back to all changes in this revision

Viewing changes to krusader/Filter/advancedfilter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-08-08 13:47:36 UTC
  • mfrom: (1.2.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20110808134736-8e630ivgd2c3sgg5
Tags: 1:2.4.0~beta1-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include <QtGui/QLayout>
42
42
#include <QtGui/QLabel>
43
43
#include <QtGui/QButtonGroup>
 
44
#include <QtGui/QSpinBox>
44
45
 
45
46
#include <KLocale>
46
47
#include <KDebug>
71
72
    sizeLayout->setSpacing(6);
72
73
    sizeLayout->setContentsMargins(11, 11, 11, 11);
73
74
 
74
 
    biggerThanEnabled = new QCheckBox(sizeGroup);
75
 
    biggerThanEnabled->setText(i18n("&Bigger than"));
76
 
    sizeLayout->addWidget(biggerThanEnabled, 0, 0);
77
 
 
78
 
    biggerThanAmount = new KLineEdit(sizeGroup);
79
 
    biggerThanAmount->setEnabled(false);
80
 
    QSizePolicy biggerThanPolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
81
 
    biggerThanPolicy.setHeightForWidth(biggerThanAmount->sizePolicy().hasHeightForWidth());
82
 
    biggerThanAmount->setSizePolicy(biggerThanPolicy);
83
 
    sizeLayout->addWidget(biggerThanAmount, 0, 1);
84
 
 
85
 
    biggerThanType = new KComboBox(false, sizeGroup);
86
 
    biggerThanType->addItem(i18n("Bytes"));
87
 
    biggerThanType->addItem(i18n("KB"));
88
 
    biggerThanType->addItem(i18n("MB"));
89
 
    biggerThanType->setEnabled(false);
90
 
    sizeLayout->addWidget(biggerThanType, 0, 2);
91
 
 
92
 
    smallerThanEnabled = new QCheckBox(sizeGroup);
93
 
    smallerThanEnabled->setText(i18n("&Smaller than"));
94
 
    sizeLayout->addWidget(smallerThanEnabled, 0, 3);
95
 
 
96
 
    smallerThanAmount = new KLineEdit(sizeGroup);
97
 
    smallerThanAmount->setEnabled(false);
98
 
    QSizePolicy smallerThanPolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
99
 
    smallerThanPolicy.setHeightForWidth(smallerThanAmount->sizePolicy().hasHeightForWidth());
100
 
    smallerThanAmount->setSizePolicy(smallerThanPolicy);
101
 
    sizeLayout->addWidget(smallerThanAmount, 0, 4);
102
 
 
103
 
    smallerThanType = new KComboBox(false, sizeGroup);
104
 
    smallerThanType->addItem(i18n("Bytes"));
105
 
    smallerThanType->addItem(i18n("KB"));
106
 
    smallerThanType->addItem(i18n("MB"));
107
 
    smallerThanType->setEnabled(false);
108
 
    sizeLayout->addWidget(smallerThanType, 0, 5);
109
 
 
110
 
    // set a tighter box around the type box
111
 
 
112
 
    int height = QFontMetrics(biggerThanType->font()).height() + 2;
113
 
    biggerThanType->setMaximumHeight(height);
114
 
    smallerThanType->setMaximumHeight(height);
 
75
    minSizeEnabled = new QCheckBox(sizeGroup);
 
76
    minSizeEnabled->setText(i18n("At Least"));
 
77
    minSizeEnabled->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
 
78
    sizeLayout->addWidget(minSizeEnabled, 0, 0);
 
79
 
 
80
    minSizeAmount = new QSpinBox(sizeGroup);
 
81
    minSizeAmount->setRange(0, 999999999);
 
82
    minSizeAmount->setEnabled(false);
 
83
    sizeLayout->addWidget(minSizeAmount, 0, 1);
 
84
 
 
85
    minSizeType = new KComboBox(false, sizeGroup);
 
86
    minSizeType->addItem(i18n("Byte"));
 
87
    minSizeType->addItem(i18n("KiB"));
 
88
    minSizeType->addItem(i18n("MiB"));
 
89
    minSizeType->addItem(i18n("GiB"));
 
90
    minSizeType->setEnabled(false);
 
91
    sizeLayout->addWidget(minSizeType, 0, 2);
 
92
 
 
93
    maxSizeEnabled = new QCheckBox(sizeGroup);
 
94
    maxSizeEnabled->setText(i18n("At Most"));
 
95
    maxSizeEnabled->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
 
96
    sizeLayout->addWidget(maxSizeEnabled, 0, 3);
 
97
 
 
98
    maxSizeAmount = new QSpinBox(sizeGroup);
 
99
    maxSizeAmount->setRange(0, 999999999);
 
100
    maxSizeAmount->setEnabled(false);
 
101
    sizeLayout->addWidget(maxSizeAmount, 0, 4);
 
102
 
 
103
    maxSizeType = new KComboBox(false, sizeGroup);
 
104
    maxSizeType->addItem(i18n("Byte"));
 
105
    maxSizeType->addItem(i18n("KiB"));
 
106
    maxSizeType->addItem(i18n("MiB"));
 
107
    maxSizeType->addItem(i18n("GiB"));
 
108
    maxSizeType->setEnabled(false);
 
109
    sizeLayout->addWidget(maxSizeType, 0, 5);
115
110
 
116
111
    filterLayout->addWidget(sizeGroup, 0, 0);
117
112
 
128
123
    dateLayout->setSpacing(6);
129
124
    dateLayout->setContentsMargins(11, 11, 11, 11);
130
125
 
 
126
    anyDateEnabled = new QRadioButton(dateGroup);
 
127
    anyDateEnabled->setText(i18n("Any date"));
 
128
    btnGroup->addButton(anyDateEnabled);
 
129
    anyDateEnabled->setChecked(true);
 
130
 
131
131
    modifiedBetweenEnabled = new QRadioButton(dateGroup);
132
132
    modifiedBetweenEnabled->setText(i18n("&Modified between"));
133
133
    btnGroup->addButton(modifiedBetweenEnabled);
134
134
 
135
 
    dateLayout->addWidget(modifiedBetweenEnabled, 0, 0, 1, 2);
136
 
 
137
135
    modifiedBetweenData1 = new KLineEdit(dateGroup);
138
136
    modifiedBetweenData1->setEnabled(false);
139
137
    modifiedBetweenData1->setText("");
140
 
    dateLayout->addWidget(modifiedBetweenData1, 0, 2, 1, 2);
141
138
 
142
139
    modifiedBetweenBtn1 = new QToolButton(dateGroup);
143
140
    modifiedBetweenBtn1->setEnabled(false);
144
141
    modifiedBetweenBtn1->setText("");
145
142
    modifiedBetweenBtn1->setIcon(QIcon(iconDate));
146
 
    dateLayout->addWidget(modifiedBetweenBtn1, 0, 4);
147
143
 
148
144
    QLabel *andLabel = new QLabel(dateGroup);
149
145
    andLabel->setText(i18n("an&d"));
150
 
    dateLayout->addWidget(andLabel, 0, 5);
151
146
 
152
147
    modifiedBetweenData2 = new KLineEdit(dateGroup);
153
148
    modifiedBetweenData2->setEnabled(false);
154
149
    modifiedBetweenData2->setText("");
155
150
    andLabel->setBuddy(modifiedBetweenData2);
156
 
    dateLayout->addWidget(modifiedBetweenData2, 0, 6);
157
151
 
158
152
    modifiedBetweenBtn2 = new QToolButton(dateGroup);
159
153
    modifiedBetweenBtn2->setEnabled(false);
160
154
    modifiedBetweenBtn2->setText("");
161
155
    modifiedBetweenBtn2->setIcon(QIcon(iconDate));
162
 
    dateLayout->addWidget(modifiedBetweenBtn2, 0, 7);
163
156
 
164
157
    notModifiedAfterEnabled = new QRadioButton(dateGroup);
165
158
    notModifiedAfterEnabled->setText(i18n("&Not modified after"));
166
159
    btnGroup->addButton(notModifiedAfterEnabled);
167
 
    dateLayout->addWidget(notModifiedAfterEnabled, 1, 0, 1, 2);
168
160
 
169
161
    notModifiedAfterData = new KLineEdit(dateGroup);
170
162
    notModifiedAfterData->setEnabled(false);
171
163
    notModifiedAfterData->setText("");
172
 
    dateLayout->addWidget(notModifiedAfterData, 1, 2, 1, 2);
173
164
 
174
165
    notModifiedAfterBtn = new QToolButton(dateGroup);
175
166
    notModifiedAfterBtn->setEnabled(false);
176
167
    notModifiedAfterBtn->setText("");
177
168
    notModifiedAfterBtn->setIcon(QIcon(iconDate));
178
 
    dateLayout->addWidget(notModifiedAfterBtn, 1, 4);
179
169
 
180
170
    modifiedInTheLastEnabled = new QRadioButton(dateGroup);
181
171
    modifiedInTheLastEnabled->setText(i18n("Mod&ified in the last"));
182
172
    btnGroup->addButton(modifiedInTheLastEnabled);
183
 
    dateLayout->addWidget(modifiedInTheLastEnabled, 2, 0);
184
173
 
185
 
    modifiedInTheLastData = new KLineEdit(dateGroup);
 
174
    modifiedInTheLastData = new QSpinBox(dateGroup);
 
175
    modifiedInTheLastData->setRange(0, 99999);
186
176
    modifiedInTheLastData->setEnabled(false);
187
 
    modifiedInTheLastData->setText("");
188
 
    dateLayout->addWidget(modifiedInTheLastData, 2, 2);
189
177
 
190
178
    modifiedInTheLastType = new KComboBox(dateGroup);
191
179
    modifiedInTheLastType->addItem(i18n("days"));
193
181
    modifiedInTheLastType->addItem(i18n("months"));
194
182
    modifiedInTheLastType->addItem(i18n("years"));
195
183
    modifiedInTheLastType->setEnabled(false);
196
 
    dateLayout->addWidget(modifiedInTheLastType, 2, 3, 1, 2);
197
184
 
198
 
    notModifiedInTheLastData = new KLineEdit(dateGroup);
 
185
    notModifiedInTheLastData = new QSpinBox(dateGroup);
 
186
    notModifiedInTheLastData->setRange(0, 99999);
199
187
    notModifiedInTheLastData->setEnabled(false);
200
 
    notModifiedInTheLastData->setText("");
201
 
    dateLayout->addWidget(notModifiedInTheLastData, 3, 2);
202
188
 
203
189
    QLabel *notModifiedInTheLastLbl = new QLabel(dateGroup);
204
190
    notModifiedInTheLastLbl->setText(i18n("No&t modified in the last"));
205
191
    notModifiedInTheLastLbl->setBuddy(notModifiedInTheLastData);
206
 
    dateLayout->addWidget(notModifiedInTheLastLbl, 3, 0);
207
192
 
208
193
    notModifiedInTheLastType = new KComboBox(dateGroup);
209
194
    notModifiedInTheLastType->addItem(i18n("days"));
211
196
    notModifiedInTheLastType->addItem(i18n("months"));
212
197
    notModifiedInTheLastType->addItem(i18n("years"));
213
198
    notModifiedInTheLastType->setEnabled(false);
214
 
    dateLayout->addWidget(notModifiedInTheLastType, 3, 3, 1, 2);
 
199
 
 
200
    // Date options layout
 
201
 
 
202
    dateLayout->addWidget(anyDateEnabled, 0, 0);
 
203
 
 
204
    dateLayout->addWidget(modifiedBetweenEnabled, 1, 0);
 
205
    dateLayout->addWidget(modifiedBetweenData1, 1, 1);
 
206
    dateLayout->addWidget(modifiedBetweenBtn1, 1, 2);
 
207
    dateLayout->addWidget(andLabel, 1, 3);
 
208
    dateLayout->addWidget(modifiedBetweenData2, 1, 4);
 
209
    dateLayout->addWidget(modifiedBetweenBtn2, 1, 5);
 
210
 
 
211
    dateLayout->addWidget(notModifiedAfterEnabled, 2, 0);
 
212
    dateLayout->addWidget(notModifiedAfterData, 2, 1);
 
213
    dateLayout->addWidget(notModifiedAfterBtn, 2, 2);
 
214
 
 
215
    dateLayout->addWidget(modifiedInTheLastEnabled, 3, 0);
 
216
    QHBoxLayout *modifiedInTheLastLayout = new QHBoxLayout();
 
217
    modifiedInTheLastLayout->addWidget(modifiedInTheLastData);
 
218
    modifiedInTheLastLayout->addWidget(modifiedInTheLastType);
 
219
    dateLayout->addLayout(modifiedInTheLastLayout, 3, 1);
 
220
 
 
221
    dateLayout->addWidget(notModifiedInTheLastLbl, 4, 0);
 
222
    modifiedInTheLastLayout = new QHBoxLayout();
 
223
    modifiedInTheLastLayout->addWidget(notModifiedInTheLastData);
 
224
    modifiedInTheLastLayout->addWidget(notModifiedInTheLastType);
 
225
    dateLayout->addLayout(modifiedInTheLastLayout, 4, 1);
215
226
 
216
227
    filterLayout->addWidget(dateGroup, 1, 0);
217
228
 
255
266
    QGroupBox *ownerGroup = new QGroupBox(ownershipGroup);
256
267
    QHBoxLayout *ownerHBox = new QHBoxLayout(ownerGroup);
257
268
    ownerGroup->setTitle(i18n("O&wner"));
258
 
    int width = 2 * height + height / 2;
259
269
 
260
270
    ownerR = new KComboBox(ownerGroup);
261
271
    ownerR->addItem(i18n("?"));
262
272
    ownerR->addItem(i18n("r"));
263
273
    ownerR->addItem(i18n("-"));
264
274
    ownerR->setEnabled(false);
265
 
    ownerR->setGeometry(QRect(10, 20, width, height + 6));
266
275
    ownerHBox->addWidget(ownerR);
267
276
 
268
277
    ownerW = new KComboBox(ownerGroup);
270
279
    ownerW->addItem(i18n("w"));
271
280
    ownerW->addItem(i18n("-"));
272
281
    ownerW->setEnabled(false);
273
 
    ownerW->setGeometry(QRect(10 + width, 20, width, height + 6));
274
282
    ownerHBox->addWidget(ownerW);
275
283
 
276
284
    ownerX = new KComboBox(ownerGroup);
278
286
    ownerX->addItem(i18n("x"));
279
287
    ownerX->addItem(i18n("-"));
280
288
    ownerX->setEnabled(false);
281
 
    ownerX->setGeometry(QRect(10 + 2*width, 20, width, height + 6));
282
289
    ownerHBox->addWidget(ownerX);
283
290
 
284
291
    ownershipLayout->addWidget(ownerGroup, 1, 1);
292
299
    groupR->addItem(i18n("r"));
293
300
    groupR->addItem(i18n("-"));
294
301
    groupR->setEnabled(false);
295
 
    groupR->setGeometry(QRect(10, 20, width, height + 6));
296
302
    groupHBox->addWidget(groupR);
297
303
 
298
304
    groupW = new KComboBox(groupGroup);
300
306
    groupW->addItem(i18n("w"));
301
307
    groupW->addItem(i18n("-"));
302
308
    groupW->setEnabled(false);
303
 
    groupW->setGeometry(QRect(10 + width, 20, width, height + 6));
304
309
    groupHBox->addWidget(groupW);
305
310
 
306
311
    groupX = new KComboBox(groupGroup);
308
313
    groupX->addItem(i18n("x"));
309
314
    groupX->addItem(i18n("-"));
310
315
    groupX->setEnabled(false);
311
 
    groupX->setGeometry(QRect(10 + 2*width, 20, width, height + 6));
312
316
    groupHBox->addWidget(groupX);
313
317
 
314
318
    ownershipLayout->addWidget(groupGroup, 1, 2);
322
326
    allR->addItem(i18n("r"));
323
327
    allR->addItem(i18n("-"));
324
328
    allR->setEnabled(false);
325
 
    allR->setGeometry(QRect(10, 20, width, height + 6));
326
329
    allHBox->addWidget(allR);
327
330
 
328
331
    allW = new KComboBox(allGroup);
330
333
    allW->addItem(i18n("w"));
331
334
    allW->addItem(i18n("-"));
332
335
    allW->setEnabled(false);
333
 
    allW->setGeometry(QRect(10 + width, 20, width, height + 6));
334
336
    allHBox->addWidget(allW);
335
337
 
336
338
    allX = new KComboBox(allGroup);
338
340
    allX->addItem(i18n("x"));
339
341
    allX->addItem(i18n("-"));
340
342
    allX->setEnabled(false);
341
 
    allX->setGeometry(QRect(10 + 2*width, 20, width, height + 6));
342
343
    allHBox->addWidget(allX);
343
344
 
344
345
    ownershipLayout->addWidget(allGroup, 1, 3);
356
357
 
357
358
    // Connection table
358
359
 
359
 
    connect(biggerThanEnabled, SIGNAL(toggled(bool)), biggerThanAmount, SLOT(setEnabled(bool)));
360
 
    connect(biggerThanEnabled, SIGNAL(toggled(bool)), biggerThanType, SLOT(setEnabled(bool)));
361
 
    connect(smallerThanEnabled, SIGNAL(toggled(bool)), smallerThanAmount, SLOT(setEnabled(bool)));
362
 
    connect(smallerThanEnabled, SIGNAL(toggled(bool)), smallerThanType, SLOT(setEnabled(bool)));
 
360
    connect(minSizeEnabled, SIGNAL(toggled(bool)), minSizeAmount, SLOT(setEnabled(bool)));
 
361
    connect(minSizeEnabled, SIGNAL(toggled(bool)), minSizeType, SLOT(setEnabled(bool)));
 
362
    connect(maxSizeEnabled, SIGNAL(toggled(bool)), maxSizeAmount, SLOT(setEnabled(bool)));
 
363
    connect(maxSizeEnabled, SIGNAL(toggled(bool)), maxSizeType, SLOT(setEnabled(bool)));
363
364
    connect(modifiedBetweenEnabled, SIGNAL(toggled(bool)), modifiedBetweenData1, SLOT(setEnabled(bool)));
364
365
    connect(modifiedBetweenEnabled, SIGNAL(toggled(bool)), modifiedBetweenBtn1, SLOT(setEnabled(bool)));
365
366
    connect(modifiedBetweenEnabled, SIGNAL(toggled(bool)), modifiedBetweenData2, SLOT(setEnabled(bool)));
391
392
    fillList(belongsToGroupData, GROUPSFILE);
392
393
 
393
394
    // tab order
394
 
    setTabOrder(biggerThanEnabled, biggerThanAmount);
395
 
    setTabOrder(biggerThanAmount, smallerThanEnabled);
396
 
    setTabOrder(smallerThanEnabled, smallerThanAmount);
397
 
    setTabOrder(smallerThanAmount, modifiedBetweenEnabled);
 
395
    setTabOrder(minSizeEnabled, minSizeAmount);
 
396
    setTabOrder(minSizeAmount, maxSizeEnabled);
 
397
    setTabOrder(maxSizeEnabled, maxSizeAmount);
 
398
    setTabOrder(maxSizeAmount, modifiedBetweenEnabled);
398
399
    setTabOrder(modifiedBetweenEnabled, modifiedBetweenData1);
399
400
    setTabOrder(modifiedBetweenData1, modifiedBetweenData2);
400
401
    setTabOrder(modifiedBetweenData2, notModifiedAfterEnabled);
416
417
    setTabOrder(groupX, allR);
417
418
    setTabOrder(allR, allW);
418
419
    setTabOrder(allW, allX);
419
 
    setTabOrder(allX, biggerThanType);
420
 
    setTabOrder(biggerThanType, smallerThanType);
421
 
    setTabOrder(smallerThanType, modifiedInTheLastType);
 
420
    setTabOrder(allX, minSizeType);
 
421
    setTabOrder(minSizeType, maxSizeType);
 
422
    setTabOrder(maxSizeType, modifiedInTheLastType);
422
423
    setTabOrder(modifiedInTheLastType, notModifiedInTheLastType);
423
424
}
424
425
 
451
452
    delete gd;
452
453
}
453
454
 
454
 
// bool start: set it to true if this date is the beginning of the search,
455
 
// if it's the end, set it to false
456
 
void AdvancedFilter::qdate2time_t (time_t *dest, QDate d, bool start)
457
 
{
458
 
    struct tm t;
459
 
    t.tm_sec   = (start ? 0 : 59);
460
 
    t.tm_min   = (start ? 0 : 59);
461
 
    t.tm_hour  = (start ? 0 : 23);
462
 
    t.tm_mday  = d.day();
463
 
    t.tm_mon   = d.month() - 1;
464
 
    t.tm_year  = d.year() - 1900;
465
 
    t.tm_wday  = d.dayOfWeek() - 1; // actually ignored by mktime
466
 
    t.tm_yday  = d.dayOfYear() - 1; // actually ignored by mktime
467
 
    t.tm_isdst = -1; // daylight saving time information isn't available
468
 
 
469
 
    (*dest) = mktime(&t);
470
 
}
471
 
 
472
 
 
473
455
void AdvancedFilter::fillList(KComboBox *list, QString filename)
474
456
{
475
457
    QFile data(filename);
495
477
    p->setFocus();
496
478
}
497
479
 
498
 
bool AdvancedFilter::fillQuery(KRQuery *query)
 
480
bool AdvancedFilter::getSettings(FilterSettings &s)
499
481
{
500
 
    KIO::filesize_t minSize = 0, maxSize = 0;
501
 
 
502
 
    // size calculations ////////////////////////////////////////////////
503
 
    if (biggerThanEnabled->isChecked() &&
504
 
            !(biggerThanAmount->text().simplified()).isEmpty()) {
505
 
        minSize = biggerThanAmount->text().toULong();
506
 
        switch (biggerThanType->currentIndex()) {
507
 
        case 1 : minSize *= 1024;
508
 
            break;
509
 
        case 2 : minSize *= (1024*1024);
510
 
            break;
511
 
        }
512
 
        query->setMinimumFileSize(minSize);
513
 
    }
514
 
    if (smallerThanEnabled->isChecked() &&
515
 
            !(smallerThanAmount->text().simplified()).isEmpty()) {
516
 
        maxSize = smallerThanAmount->text().toULong();
517
 
        switch (smallerThanType->currentIndex()) {
518
 
        case 1 : maxSize *= 1024;
519
 
            break;
520
 
        case 2 : maxSize *= (1024*1024);
521
 
            break;
522
 
        }
523
 
        query->setMaximumFileSize(maxSize);
524
 
    }
525
 
    // check that minSize is smaller than maxSize
526
 
    if ((minSize > 0) && (maxSize > 0) && (maxSize < minSize)) {
 
482
    s.minSizeEnabled =  minSizeEnabled->isChecked();
 
483
    s.minSize.amount = minSizeAmount->value();
 
484
    s.minSize.unit = static_cast<FilterSettings::SizeUnit>(minSizeType->currentIndex());
 
485
 
 
486
    s.maxSizeEnabled = maxSizeEnabled->isChecked();
 
487
    s.maxSize.amount = maxSizeAmount->value();
 
488
    s.maxSize.unit = static_cast<FilterSettings::SizeUnit>(maxSizeType->currentIndex());
 
489
 
 
490
    if (s.minSizeEnabled && s.maxSizeEnabled && (s.maxSize.size() < s.minSize.size())) {
527
491
        KMessageBox::detailedError(this, i18n("Specified sizes are inconsistent!"),
528
 
                                   i18n("Please re-enter the values, so that the left side size will be smaller than (or equal to) the right side size."));
529
 
        biggerThanAmount->setFocus();
530
 
        return false;
531
 
    }
532
 
 
533
 
    // date calculations ////////////////////////////////////////////////////
534
 
    if (modifiedBetweenEnabled->isChecked()) {
535
 
        // first, if both dates are empty, than don't use them
536
 
        if (!(modifiedBetweenData1->text().simplified().isEmpty() &&
537
 
                modifiedBetweenData2->text().simplified().isEmpty())) {
538
 
            // check if date is valid
539
 
            QDate d1 = KGlobal::locale()->readDate(modifiedBetweenData1->text());
540
 
            if (!d1.isValid()) {
541
 
                invalidDateMessage(modifiedBetweenData1); return false;
542
 
            }
543
 
            QDate d2 = KGlobal::locale()->readDate(modifiedBetweenData2->text());
544
 
            if (!d2.isValid()) {
545
 
                invalidDateMessage(modifiedBetweenData2); return false;
546
 
            }
547
 
 
548
 
            if (d1 > d2) {
549
 
                KMessageBox::detailedError(this, i18n("Dates are inconsistent!"),
550
 
                                           i18n("The date on the left is later than the date on the right. Please re-enter the dates, so that the left side date will be earlier than the right side date."));
551
 
                modifiedBetweenData1->setFocus();
552
 
                return false;
553
 
            }
554
 
            // all seems to be ok, create time_t
555
 
 
556
 
            time_t newerTime, olderTime;
557
 
            qdate2time_t (&newerTime, d1, true);
558
 
            qdate2time_t (&olderTime, d2, false);
559
 
            query->setNewerThan(newerTime);
560
 
            query->setOlderThan(olderTime);
561
 
        }
562
 
    } else if (notModifiedAfterEnabled->isChecked()) {
563
 
        if (!notModifiedAfterData->text().simplified().isEmpty()) {
564
 
            QDate d = KGlobal::locale()->readDate(notModifiedAfterData->text());
565
 
            if (!d.isValid()) {
566
 
                invalidDateMessage(notModifiedAfterData); return false;
567
 
            }
568
 
            time_t olderTime;
569
 
            qdate2time_t (&olderTime, d, false);
570
 
            query->setOlderThan(olderTime);
571
 
        }
572
 
    } else if (modifiedInTheLastEnabled->isChecked()) {
573
 
        if (!(modifiedInTheLastData->text().simplified().isEmpty() &&
574
 
                notModifiedInTheLastData->text().simplified().isEmpty())) {
575
 
            QDate d1 = QDate::currentDate(); QDate d2 = QDate::currentDate();
576
 
            if (!modifiedInTheLastData->text().simplified().isEmpty()) {
577
 
                int tmp1 = modifiedInTheLastData->text().simplified().toInt();
578
 
                switch (modifiedInTheLastType->currentIndex()) {
579
 
                case 1 : tmp1 *= 7;
580
 
                    break;
581
 
                case 2 : tmp1 *= 30;
582
 
                    break;
583
 
                case 3 : tmp1 *= 365;
584
 
                    break;
585
 
                }
586
 
                d1 = d1.addDays((-1) * tmp1);
587
 
                time_t newerTime;
588
 
                qdate2time_t (&newerTime, d1, true);
589
 
                query->setNewerThan(newerTime);
590
 
            }
591
 
            if (!notModifiedInTheLastData->text().simplified().isEmpty()) {
592
 
                int tmp2 = notModifiedInTheLastData->text().simplified().toInt();
593
 
                switch (notModifiedInTheLastType->currentIndex()) {
594
 
                case 1 : tmp2 *= 7;
595
 
                    break;
596
 
                case 2 : tmp2 *= 30;
597
 
                    break;
598
 
                case 3 : tmp2 *= 365;
599
 
                    break;
600
 
                }
601
 
                d2 = d2.addDays((-1) * tmp2);
602
 
                time_t olderTime;
603
 
                qdate2time_t (&olderTime, d2, true);
604
 
                query->setOlderThan(olderTime);
605
 
            }
606
 
            if (!modifiedInTheLastData->text().simplified().isEmpty() &&
607
 
                    !notModifiedInTheLastData->text().simplified().isEmpty()) {
608
 
                if (d1 > d2) {
609
 
                    KMessageBox::detailedError(this, i18n("Dates are inconsistent!"),
610
 
                                               i18n("The date on top is later than the date on the bottom. Please re-enter the dates, so that the top date will be earlier than the bottom date."));
611
 
                    modifiedInTheLastData->setFocus();
612
 
                    return false;
613
 
                }
614
 
            }
615
 
        }
616
 
    }
617
 
    // permissions and ownership /////////////////////////////////////
618
 
    if (permissionsEnabled->isChecked()) {
619
 
        QString perm = ownerR->currentText() + ownerW->currentText() + ownerX->currentText() +
620
 
                       groupR->currentText() + groupW->currentText() + groupX->currentText() +
621
 
                       allR->currentText()   + allW->currentText()   + allX->currentText();
622
 
        query->setPermissions(perm);
623
 
    }
624
 
    if (belongsToUserEnabled->isChecked())
625
 
        query->setOwner(belongsToUserData->currentText());
626
 
    if (belongsToGroupEnabled->isChecked())
627
 
        query->setGroup(belongsToGroupData->currentText());
 
492
                            i18n("Please re-enter the values, so that the left side size "
 
493
                                 "will be smaller than (or equal to) the right side size."));
 
494
        minSizeAmount->setFocus();
 
495
        return false;
 
496
    }
 
497
 
 
498
    s.modifiedBetweenEnabled = modifiedBetweenEnabled->isChecked();
 
499
    s.modifiedBetween1 = KGlobal::locale()->readDate(modifiedBetweenData1->text());
 
500
    s.modifiedBetween2 = KGlobal::locale()->readDate(modifiedBetweenData2->text());
 
501
 
 
502
    if (s.modifiedBetweenEnabled) {
 
503
        // check if date is valid
 
504
        if (!s.modifiedBetween1.isValid()) {
 
505
            invalidDateMessage(modifiedBetweenData1);
 
506
            return false;
 
507
        } else if (!s.modifiedBetween2.isValid()) {
 
508
            invalidDateMessage(modifiedBetweenData2);
 
509
            return false;
 
510
        } else if (s.modifiedBetween1 > s.modifiedBetween2) {
 
511
            KMessageBox::detailedError(this, i18n("Dates are inconsistent!"),
 
512
                                i18n("The date on the left is later than the date on the right. "
 
513
                                     "Please re-enter the dates, so that the left side date "
 
514
                                     "will be earlier than the right side date."));
 
515
            modifiedBetweenData1->setFocus();
 
516
            return false;
 
517
        }
 
518
    }
 
519
 
 
520
    s.notModifiedAfterEnabled = notModifiedAfterEnabled->isChecked();
 
521
    s.notModifiedAfter = KGlobal::locale()->readDate(notModifiedAfterData->text());
 
522
 
 
523
    if(s.notModifiedAfterEnabled && !s.notModifiedAfter.isValid()) {
 
524
        invalidDateMessage(notModifiedAfterData);
 
525
        return false;
 
526
    }
 
527
 
 
528
    s.modifiedInTheLastEnabled = modifiedInTheLastEnabled->isChecked();
 
529
    s.modifiedInTheLast.amount = modifiedInTheLastData->value();
 
530
    s.modifiedInTheLast.unit =
 
531
        static_cast<FilterSettings::TimeUnit>(modifiedInTheLastType->currentIndex());
 
532
    s.notModifiedInTheLast.amount = notModifiedInTheLastData->value();
 
533
    s.notModifiedInTheLast.unit =
 
534
        static_cast<FilterSettings::TimeUnit>(notModifiedInTheLastType->currentIndex());
 
535
 
 
536
    if (s.modifiedInTheLastEnabled  &&
 
537
            s.modifiedInTheLast.amount && s.notModifiedInTheLast.amount) {
 
538
        if (s.modifiedInTheLast.days() < s.notModifiedInTheLast.days()) {
 
539
            KMessageBox::detailedError(this, i18n("Dates are inconsistent!"),
 
540
                                i18n("The date on top is later than the date on the bottom. "
 
541
                                     "Please re-enter the dates, so that the top date "
 
542
                                     "will be earlier than the bottom date."));
 
543
            modifiedInTheLastData->setFocus();
 
544
            return false;
 
545
        }
 
546
    }
 
547
 
 
548
    s.ownerEnabled = belongsToUserEnabled->isChecked();
 
549
    s.owner = belongsToUserData->currentText();
 
550
 
 
551
    s.groupEnabled = belongsToGroupEnabled->isChecked();
 
552
    s.group = belongsToGroupData->currentText();
 
553
 
 
554
    s.permissionsEnabled = permissionsEnabled->isChecked();
 
555
    s.permissions = ownerR->currentText() + ownerW->currentText() + ownerX->currentText() +
 
556
                    groupR->currentText() + groupW->currentText() + groupX->currentText() +
 
557
                    allR->currentText()   + allW->currentText()   + allX->currentText();
628
558
 
629
559
    return true;
630
560
}
631
561
 
632
 
void AdvancedFilter::loadFromProfile(QString name)
633
 
{
634
 
    KConfigGroup cfg(krConfig, name);
635
 
 
636
 
    smallerThanEnabled->setChecked(cfg.readEntry("Smaller Than Enabled", false));
637
 
    smallerThanAmount->setText(cfg.readEntry("Smaller Than Amount", ""));
638
 
    smallerThanType->setCurrentIndex(cfg.readEntry("Smaller Than Type", 0));
639
 
 
640
 
    biggerThanEnabled->setChecked(cfg.readEntry("Bigger Than Enabled", false));
641
 
    biggerThanAmount->setText(cfg.readEntry("Bigger Than Amount", ""));
642
 
    biggerThanType->setCurrentIndex(cfg.readEntry("Bigger Than Type", 0));
643
 
 
644
 
    modifiedBetweenEnabled->setChecked(cfg.readEntry("Modified Between Enabled", false));
645
 
    notModifiedAfterEnabled->setChecked(cfg.readEntry("Not Modified After Enabled", false));
646
 
    modifiedInTheLastEnabled->setChecked(cfg.readEntry("Modified In The Last Enabled", false));
647
 
 
648
 
    modifiedBetweenData1->setText(cfg.readEntry("Modified Between 1", ""));
649
 
    modifiedBetweenData2->setText(cfg.readEntry("Modified Between 2", ""));
650
 
 
651
 
    notModifiedAfterData->setText(cfg.readEntry("Not Modified After", ""));
652
 
    modifiedInTheLastData->setText(cfg.readEntry("Modified In The Last", ""));
653
 
    notModifiedInTheLastData->setText(cfg.readEntry("Not Modified In The Last", ""));
654
 
 
655
 
    modifiedInTheLastType->setCurrentIndex(cfg.readEntry("Modified In The Last Type", 0));
656
 
    notModifiedInTheLastType->setCurrentIndex(cfg.readEntry("Not Modified In The Last Type", 0));
657
 
 
658
 
    belongsToUserEnabled->setChecked(cfg.readEntry("Belongs To User Enabled", false));
659
 
    belongsToGroupEnabled->setChecked(cfg.readEntry("Belongs To Group Enabled", false));
660
 
 
661
 
    QString user = cfg.readEntry("Belongs To User", "");
662
 
    for (int i = belongsToUserData->count(); i >= 0; i--) {
663
 
        belongsToUserData->setCurrentIndex(i);
664
 
        if (belongsToUserData->currentText() == user)
665
 
            break;
666
 
    }
667
 
 
668
 
    QString group = cfg.readEntry("Belongs To Group", "");
669
 
    for (int i = belongsToGroupData->count(); i >= 0; i--) {
670
 
        belongsToGroupData->setCurrentIndex(i);
671
 
        if (belongsToGroupData->currentText() == group)
672
 
            break;
673
 
    }
674
 
 
675
 
    permissionsEnabled->setChecked(cfg.readEntry("Permissions Enabled", false));
676
 
 
677
 
    ownerW->setCurrentIndex(cfg.readEntry("Owner Write", 0));
678
 
    ownerR->setCurrentIndex(cfg.readEntry("Owner Read", 0));
679
 
    ownerX->setCurrentIndex(cfg.readEntry("Owner Execute", 0));
680
 
    groupW->setCurrentIndex(cfg.readEntry("Group Write", 0));
681
 
    groupR->setCurrentIndex(cfg.readEntry("Group Read", 0));
682
 
    groupX->setCurrentIndex(cfg.readEntry("Group Execute", 0));
683
 
    allW->setCurrentIndex(cfg.readEntry("All Write", 0));
684
 
    allR->setCurrentIndex(cfg.readEntry("All Read", 0));
685
 
    allX->setCurrentIndex(cfg.readEntry("All Execute", 0));
686
 
}
687
 
 
688
 
void AdvancedFilter::saveToProfile(QString name)
689
 
{
690
 
    KConfigGroup group(krConfig, name);
691
 
 
692
 
    group.writeEntry("Smaller Than Enabled", smallerThanEnabled->isChecked());
693
 
    group.writeEntry("Smaller Than Amount", smallerThanAmount->text());
694
 
    group.writeEntry("Smaller Than Type", smallerThanType->currentIndex());
695
 
 
696
 
    group.writeEntry("Bigger Than Enabled", biggerThanEnabled->isChecked());
697
 
    group.writeEntry("Bigger Than Amount", biggerThanAmount->text());
698
 
    group.writeEntry("Bigger Than Type", biggerThanType->currentIndex());
699
 
 
700
 
    group.writeEntry("Modified Between Enabled", modifiedBetweenEnabled->isChecked());
701
 
    group.writeEntry("Not Modified After Enabled", notModifiedAfterEnabled->isChecked());
702
 
    group.writeEntry("Modified In The Last Enabled", modifiedInTheLastEnabled->isChecked());
703
 
 
704
 
    group.writeEntry("Modified Between 1", modifiedBetweenData1->text());
705
 
    group.writeEntry("Modified Between 2", modifiedBetweenData2->text());
706
 
 
707
 
    group.writeEntry("Not Modified After", notModifiedAfterData->text());
708
 
    group.writeEntry("Modified In The Last", modifiedInTheLastData->text());
709
 
    group.writeEntry("Not Modified In The Last", notModifiedInTheLastData->text());
710
 
 
711
 
    group.writeEntry("Modified In The Last Type", modifiedInTheLastType->currentIndex());
712
 
    group.writeEntry("Not Modified In The Last Type", notModifiedInTheLastType->currentIndex());
713
 
 
714
 
    group.writeEntry("Belongs To User Enabled", belongsToUserEnabled->isChecked());
715
 
    group.writeEntry("Belongs To Group Enabled", belongsToGroupEnabled->isChecked());
716
 
 
717
 
    group.writeEntry("Belongs To User", belongsToUserData->currentText());
718
 
    group.writeEntry("Belongs To Group", belongsToGroupData->currentText());
719
 
 
720
 
    group.writeEntry("Permissions Enabled", permissionsEnabled->isChecked());
721
 
 
722
 
    group.writeEntry("Owner Write", ownerW->currentIndex());
723
 
    group.writeEntry("Owner Read", ownerR->currentIndex());
724
 
    group.writeEntry("Owner Execute", ownerX->currentIndex());
725
 
    group.writeEntry("Group Write", groupW->currentIndex());
726
 
    group.writeEntry("Group Read", groupR->currentIndex());
727
 
    group.writeEntry("Group Execute", groupX->currentIndex());
728
 
    group.writeEntry("All Write", allW->currentIndex());
729
 
    group.writeEntry("All Read", allR->currentIndex());
730
 
    group.writeEntry("All Execute", allX->currentIndex());
731
 
}
732
 
 
 
562
void AdvancedFilter::applySettings(const FilterSettings &s)
 
563
{
 
564
    minSizeEnabled->setChecked(s.minSizeEnabled);
 
565
    minSizeAmount->setValue(s.minSize.amount);
 
566
    minSizeType->setCurrentIndex(s.minSize.unit);
 
567
 
 
568
    maxSizeEnabled->setChecked(s.maxSizeEnabled);
 
569
    maxSizeAmount->setValue(s.maxSize.amount);
 
570
    maxSizeType->setCurrentIndex(s.maxSize.unit);
 
571
 
 
572
    if (s.modifiedBetweenEnabled)
 
573
        modifiedBetweenEnabled->setChecked(true);
 
574
    else if (s.notModifiedAfterEnabled)
 
575
        notModifiedAfterEnabled->setChecked(true);
 
576
    else if (s.modifiedInTheLastEnabled)
 
577
        modifiedInTheLastEnabled->setChecked(true);
 
578
    else
 
579
        anyDateEnabled->setChecked(true);
 
580
 
 
581
    modifiedBetweenData1->setText(
 
582
        KGlobal::locale()->formatDate(s.modifiedBetween1, KLocale::ShortDate));
 
583
    modifiedBetweenData2->setText(
 
584
        KGlobal::locale()->formatDate(s.modifiedBetween2, KLocale::ShortDate));
 
585
 
 
586
    notModifiedAfterData->setText(
 
587
        KGlobal::locale()->formatDate(s.notModifiedAfter, KLocale::ShortDate));
 
588
 
 
589
    modifiedInTheLastData->setValue(s.modifiedInTheLast.amount);
 
590
    modifiedInTheLastType->setCurrentIndex(s.modifiedInTheLast.unit);
 
591
    notModifiedInTheLastData->setValue(s.notModifiedInTheLast.amount);
 
592
    notModifiedInTheLastType->setCurrentIndex(s.notModifiedInTheLast.unit);
 
593
 
 
594
    belongsToUserEnabled->setChecked(s.ownerEnabled);
 
595
    setComboBoxValue(belongsToUserData, s.owner);
 
596
 
 
597
    belongsToGroupEnabled->setChecked(s.groupEnabled);
 
598
    setComboBoxValue(belongsToGroupData, s.group);
 
599
 
 
600
    permissionsEnabled->setChecked(s.permissionsEnabled);
 
601
    QString perm = s.permissions;
 
602
    if (perm.length() != 9)
 
603
        perm = "?????????";
 
604
    setComboBoxValue(ownerR, QString(perm[0]));
 
605
    setComboBoxValue(ownerW, QString(perm[1]));
 
606
    setComboBoxValue(ownerX, QString(perm[2]));
 
607
    setComboBoxValue(groupR, QString(perm[3]));
 
608
    setComboBoxValue(groupW, QString(perm[4]));
 
609
    setComboBoxValue(groupX, QString(perm[5]));
 
610
    setComboBoxValue(allR, QString(perm[6]));
 
611
    setComboBoxValue(allW, QString(perm[7]));
 
612
    setComboBoxValue(allX, QString(perm[8]));
 
613
}
733
614
 
734
615
#include "advancedfilter.moc"