File indexing completed on 2024-04-28 17:06:02
0001 /* 0002 SPDX-FileCopyrightText: 2003 Shie Erlich <krusader@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2003 Rafi Yanai <krusader@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2003 Csaba Karai <krusader@users.sourceforge.net> 0005 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "advancedfilter.h" 0011 0012 // QtCore 0013 #include <QDebug> 0014 #include <QFile> 0015 #include <QTextStream> 0016 // QtGui 0017 #include <QPixmap> 0018 // QtWidgets 0019 #include <QButtonGroup> 0020 #include <QGridLayout> 0021 #include <QGroupBox> 0022 #include <QHBoxLayout> 0023 #include <QLabel> 0024 #include <QLayout> 0025 #include <QSpinBox> 0026 0027 #include <KI18n/KLocalizedString> 0028 #include <KWidgetsAddons/KMessageBox> 0029 0030 #include "../Dialogs/krdialogs.h" 0031 #include "../icon.h" 0032 #include "../krglobal.h" 0033 0034 #define USERSFILE QString("/etc/passwd") 0035 #define GROUPSFILE QString("/etc/group") 0036 0037 AdvancedFilter::AdvancedFilter(FilterTabs *tabs, QWidget *parent) 0038 : QWidget(parent) 0039 , fltTabs(tabs) 0040 { 0041 auto *filterLayout = new QGridLayout(this); 0042 filterLayout->setSpacing(6); 0043 filterLayout->setContentsMargins(11, 11, 11, 11); 0044 0045 // Options for size 0046 0047 auto *sizeGroup = new QGroupBox(this); 0048 QSizePolicy sizeGroupPolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); 0049 sizeGroupPolicy.setHeightForWidth(sizeGroup->sizePolicy().hasHeightForWidth()); 0050 sizeGroup->setSizePolicy(sizeGroupPolicy); 0051 sizeGroup->setTitle(i18n("Size")); 0052 auto *sizeLayout = new QGridLayout(sizeGroup); 0053 sizeLayout->setAlignment(Qt::AlignTop); 0054 sizeLayout->setSpacing(6); 0055 sizeLayout->setContentsMargins(11, 11, 11, 11); 0056 0057 minSizeEnabled = new QCheckBox(sizeGroup); 0058 minSizeEnabled->setText(i18n("At Least")); 0059 minSizeEnabled->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); 0060 sizeLayout->addWidget(minSizeEnabled, 0, 0); 0061 0062 minSizeAmount = new QSpinBox(sizeGroup); 0063 minSizeAmount->setRange(0, 999999999); 0064 minSizeAmount->setEnabled(false); 0065 sizeLayout->addWidget(minSizeAmount, 0, 1); 0066 0067 minSizeType = new KComboBox(false, sizeGroup); 0068 // i18n: @item:inlistbox next to a text field containing the amount 0069 minSizeType->addItem(i18n("Byte")); 0070 // i18n: @item:inlistbox next to a text field containing the amount 0071 minSizeType->addItem(i18n("KiB")); 0072 // i18n: @item:inlistbox next to a text field containing the amount 0073 minSizeType->addItem(i18n("MiB")); 0074 // i18n: @item:inlistbox next to a text field containing the amount 0075 minSizeType->addItem(i18n("GiB")); 0076 minSizeType->setEnabled(false); 0077 sizeLayout->addWidget(minSizeType, 0, 2); 0078 0079 maxSizeEnabled = new QCheckBox(sizeGroup); 0080 maxSizeEnabled->setText(i18n("At Most")); 0081 maxSizeEnabled->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); 0082 sizeLayout->addWidget(maxSizeEnabled, 0, 3); 0083 0084 maxSizeAmount = new QSpinBox(sizeGroup); 0085 maxSizeAmount->setRange(0, 999999999); 0086 maxSizeAmount->setEnabled(false); 0087 sizeLayout->addWidget(maxSizeAmount, 0, 4); 0088 0089 maxSizeType = new KComboBox(false, sizeGroup); 0090 // i18n: @item:inlistbox next to a text field containing the amount 0091 maxSizeType->addItem(i18n("Byte")); 0092 // i18n: @item:inlistbox next to a text field containing the amount 0093 maxSizeType->addItem(i18n("KiB")); 0094 // i18n: @item:inlistbox next to a text field containing the amount 0095 maxSizeType->addItem(i18n("MiB")); 0096 // i18n: @item:inlistbox next to a text field containing the amount 0097 maxSizeType->addItem(i18n("GiB")); 0098 maxSizeType->setEnabled(false); 0099 sizeLayout->addWidget(maxSizeType, 0, 5); 0100 0101 filterLayout->addWidget(sizeGroup, 0, 0); 0102 0103 // Options for date 0104 0105 Icon iconDate("view-calendar"); 0106 0107 auto *dateGroup = new QGroupBox(this); 0108 auto *btnGroup = new QButtonGroup(dateGroup); 0109 dateGroup->setTitle(i18n("Date")); 0110 btnGroup->setExclusive(true); 0111 auto *dateLayout = new QGridLayout(dateGroup); 0112 dateLayout->setAlignment(Qt::AlignTop); 0113 dateLayout->setSpacing(6); 0114 dateLayout->setContentsMargins(11, 11, 11, 11); 0115 0116 anyDateEnabled = new QRadioButton(dateGroup); 0117 anyDateEnabled->setText(i18n("Any date")); 0118 btnGroup->addButton(anyDateEnabled); 0119 anyDateEnabled->setChecked(true); 0120 0121 modifiedBetweenEnabled = new QRadioButton(dateGroup); 0122 modifiedBetweenEnabled->setText(i18n("&Modified between")); 0123 btnGroup->addButton(modifiedBetweenEnabled); 0124 0125 modifiedBetweenData1 = new KLineEdit(dateGroup); 0126 modifiedBetweenData1->setEnabled(false); 0127 modifiedBetweenData1->setText(""); 0128 0129 modifiedBetweenBtn1 = new QToolButton(dateGroup); 0130 modifiedBetweenBtn1->setEnabled(false); 0131 modifiedBetweenBtn1->setText(""); 0132 modifiedBetweenBtn1->setIcon(iconDate); 0133 0134 QLabel *andLabel = new QLabel(dateGroup); 0135 andLabel->setText(i18n("an&d")); 0136 0137 modifiedBetweenData2 = new KLineEdit(dateGroup); 0138 modifiedBetweenData2->setEnabled(false); 0139 modifiedBetweenData2->setText(""); 0140 andLabel->setBuddy(modifiedBetweenData2); 0141 0142 modifiedBetweenBtn2 = new QToolButton(dateGroup); 0143 modifiedBetweenBtn2->setEnabled(false); 0144 modifiedBetweenBtn2->setText(""); 0145 modifiedBetweenBtn2->setIcon(iconDate); 0146 0147 notModifiedAfterEnabled = new QRadioButton(dateGroup); 0148 notModifiedAfterEnabled->setText(i18n("&Not modified after")); 0149 btnGroup->addButton(notModifiedAfterEnabled); 0150 0151 notModifiedAfterData = new KLineEdit(dateGroup); 0152 notModifiedAfterData->setEnabled(false); 0153 notModifiedAfterData->setText(""); 0154 0155 notModifiedAfterBtn = new QToolButton(dateGroup); 0156 notModifiedAfterBtn->setEnabled(false); 0157 notModifiedAfterBtn->setText(""); 0158 notModifiedAfterBtn->setIcon(iconDate); 0159 0160 modifiedInTheLastEnabled = new QRadioButton(dateGroup); 0161 modifiedInTheLastEnabled->setText(i18n("Mod&ified in the last")); 0162 btnGroup->addButton(modifiedInTheLastEnabled); 0163 0164 modifiedInTheLastData = new QSpinBox(dateGroup); 0165 modifiedInTheLastData->setRange(0, 99999); 0166 modifiedInTheLastData->setEnabled(false); 0167 0168 modifiedInTheLastType = new KComboBox(dateGroup); 0169 modifiedInTheLastType->addItem(i18n("days")); 0170 modifiedInTheLastType->addItem(i18n("weeks")); 0171 modifiedInTheLastType->addItem(i18n("months")); 0172 modifiedInTheLastType->addItem(i18n("years")); 0173 modifiedInTheLastType->setEnabled(false); 0174 0175 notModifiedInTheLastData = new QSpinBox(dateGroup); 0176 notModifiedInTheLastData->setRange(0, 99999); 0177 notModifiedInTheLastData->setEnabled(false); 0178 0179 QLabel *notModifiedInTheLastLbl = new QLabel(dateGroup); 0180 notModifiedInTheLastLbl->setText(i18n("No&t modified in the last")); 0181 notModifiedInTheLastLbl->setBuddy(notModifiedInTheLastData); 0182 0183 notModifiedInTheLastType = new KComboBox(dateGroup); 0184 notModifiedInTheLastType->addItem(i18n("days")); 0185 notModifiedInTheLastType->addItem(i18n("weeks")); 0186 notModifiedInTheLastType->addItem(i18n("months")); 0187 notModifiedInTheLastType->addItem(i18n("years")); 0188 notModifiedInTheLastType->setEnabled(false); 0189 0190 // Date options layout 0191 0192 dateLayout->addWidget(anyDateEnabled, 0, 0); 0193 0194 dateLayout->addWidget(modifiedBetweenEnabled, 1, 0); 0195 dateLayout->addWidget(modifiedBetweenData1, 1, 1); 0196 dateLayout->addWidget(modifiedBetweenBtn1, 1, 2); 0197 dateLayout->addWidget(andLabel, 1, 3); 0198 dateLayout->addWidget(modifiedBetweenData2, 1, 4); 0199 dateLayout->addWidget(modifiedBetweenBtn2, 1, 5); 0200 0201 dateLayout->addWidget(notModifiedAfterEnabled, 2, 0); 0202 dateLayout->addWidget(notModifiedAfterData, 2, 1); 0203 dateLayout->addWidget(notModifiedAfterBtn, 2, 2); 0204 0205 dateLayout->addWidget(modifiedInTheLastEnabled, 3, 0); 0206 auto *modifiedInTheLastLayout = new QHBoxLayout(); 0207 modifiedInTheLastLayout->addWidget(modifiedInTheLastData); 0208 modifiedInTheLastLayout->addWidget(modifiedInTheLastType); 0209 dateLayout->addLayout(modifiedInTheLastLayout, 3, 1); 0210 0211 dateLayout->addWidget(notModifiedInTheLastLbl, 4, 0); 0212 modifiedInTheLastLayout = new QHBoxLayout(); 0213 modifiedInTheLastLayout->addWidget(notModifiedInTheLastData); 0214 modifiedInTheLastLayout->addWidget(notModifiedInTheLastType); 0215 dateLayout->addLayout(modifiedInTheLastLayout, 4, 1); 0216 0217 filterLayout->addWidget(dateGroup, 1, 0); 0218 0219 // Options for ownership 0220 0221 auto *ownershipGroup = new QGroupBox(this); 0222 ownershipGroup->setTitle(i18n("Ownership")); 0223 auto *ownershipLayout = new QGridLayout(ownershipGroup); 0224 ownershipLayout->setAlignment(Qt::AlignTop); 0225 ownershipLayout->setSpacing(6); 0226 ownershipLayout->setContentsMargins(11, 11, 11, 11); 0227 0228 auto *hboxLayout = new QHBoxLayout(); 0229 hboxLayout->setSpacing(6); 0230 hboxLayout->setContentsMargins(0, 0, 0, 0); 0231 0232 belongsToUserEnabled = new QCheckBox(ownershipGroup); 0233 belongsToUserEnabled->setText(i18n("Belongs to &user")); 0234 hboxLayout->addWidget(belongsToUserEnabled); 0235 0236 belongsToUserData = new KComboBox(ownershipGroup); 0237 belongsToUserData->setEnabled(false); 0238 belongsToUserData->setEditable(false); 0239 hboxLayout->addWidget(belongsToUserData); 0240 0241 belongsToGroupEnabled = new QCheckBox(ownershipGroup); 0242 belongsToGroupEnabled->setText(i18n("Belongs to gr&oup")); 0243 hboxLayout->addWidget(belongsToGroupEnabled); 0244 0245 belongsToGroupData = new KComboBox(ownershipGroup); 0246 belongsToGroupData->setEnabled(false); 0247 belongsToGroupData->setEditable(false); 0248 hboxLayout->addWidget(belongsToGroupData); 0249 0250 ownershipLayout->addLayout(hboxLayout, 0, 0, 1, 4); 0251 0252 permissionsEnabled = new QCheckBox(ownershipGroup); 0253 permissionsEnabled->setText(i18n("P&ermissions")); 0254 ownershipLayout->addWidget(permissionsEnabled, 1, 0); 0255 0256 auto *ownerGroup = new QGroupBox(ownershipGroup); 0257 auto *ownerHBox = new QHBoxLayout(ownerGroup); 0258 ownerGroup->setTitle(i18n("O&wner")); 0259 0260 ownerR = new KComboBox(ownerGroup); 0261 ownerR->addItem(i18n("?")); 0262 ownerR->addItem(i18n("r")); 0263 ownerR->addItem(i18n("-")); 0264 ownerR->setEnabled(false); 0265 ownerHBox->addWidget(ownerR); 0266 0267 ownerW = new KComboBox(ownerGroup); 0268 ownerW->addItem(i18n("?")); 0269 ownerW->addItem(i18n("w")); 0270 ownerW->addItem(i18n("-")); 0271 ownerW->setEnabled(false); 0272 ownerHBox->addWidget(ownerW); 0273 0274 ownerX = new KComboBox(ownerGroup); 0275 ownerX->addItem(i18n("?")); 0276 ownerX->addItem(i18n("x")); 0277 ownerX->addItem(i18n("-")); 0278 ownerX->setEnabled(false); 0279 ownerHBox->addWidget(ownerX); 0280 0281 ownershipLayout->addWidget(ownerGroup, 1, 1); 0282 0283 auto *groupGroup = new QGroupBox(ownershipGroup); 0284 auto *groupHBox = new QHBoxLayout(groupGroup); 0285 groupGroup->setTitle(i18n("Grou&p")); 0286 0287 groupR = new KComboBox(groupGroup); 0288 groupR->addItem(i18n("?")); 0289 groupR->addItem(i18n("r")); 0290 groupR->addItem(i18n("-")); 0291 groupR->setEnabled(false); 0292 groupHBox->addWidget(groupR); 0293 0294 groupW = new KComboBox(groupGroup); 0295 groupW->addItem(i18n("?")); 0296 groupW->addItem(i18n("w")); 0297 groupW->addItem(i18n("-")); 0298 groupW->setEnabled(false); 0299 groupHBox->addWidget(groupW); 0300 0301 groupX = new KComboBox(groupGroup); 0302 groupX->addItem(i18n("?")); 0303 groupX->addItem(i18n("x")); 0304 groupX->addItem(i18n("-")); 0305 groupX->setEnabled(false); 0306 groupHBox->addWidget(groupX); 0307 0308 ownershipLayout->addWidget(groupGroup, 1, 2); 0309 0310 auto *allGroup = new QGroupBox(ownershipGroup); 0311 auto *allHBox = new QHBoxLayout(allGroup); 0312 allGroup->setTitle(i18n("A&ll")); 0313 0314 allR = new KComboBox(allGroup); 0315 allR->addItem(i18n("?")); 0316 allR->addItem(i18n("r")); 0317 allR->addItem(i18n("-")); 0318 allR->setEnabled(false); 0319 allHBox->addWidget(allR); 0320 0321 allW = new KComboBox(allGroup); 0322 allW->addItem(i18n("?")); 0323 allW->addItem(i18n("w")); 0324 allW->addItem(i18n("-")); 0325 allW->setEnabled(false); 0326 allHBox->addWidget(allW); 0327 0328 allX = new KComboBox(allGroup); 0329 allX->addItem(i18n("?")); 0330 allX->addItem(i18n("x")); 0331 allX->addItem(i18n("-")); 0332 allX->setEnabled(false); 0333 allHBox->addWidget(allX); 0334 0335 ownershipLayout->addWidget(allGroup, 1, 3); 0336 0337 QLabel *infoLabel = new QLabel(ownershipGroup); 0338 QFont infoLabel_font(infoLabel->font()); 0339 infoLabel_font.setFamily("adobe-helvetica"); 0340 infoLabel_font.setItalic(true); 0341 infoLabel->setFont(infoLabel_font); 0342 infoLabel->setText(i18n("Note: a '?' is a wildcard")); 0343 0344 ownershipLayout->addWidget(infoLabel, 2, 0, 1, 4, Qt::AlignRight); 0345 0346 filterLayout->addWidget(ownershipGroup, 2, 0); 0347 0348 // Connection table 0349 0350 connect(minSizeEnabled, &QCheckBox::toggled, minSizeAmount, &QSpinBox::setEnabled); 0351 connect(minSizeEnabled, &QCheckBox::toggled, minSizeType, &KComboBox::setEnabled); 0352 connect(maxSizeEnabled, &QCheckBox::toggled, maxSizeAmount, &QSpinBox::setEnabled); 0353 connect(maxSizeEnabled, &QCheckBox::toggled, maxSizeType, &KComboBox::setEnabled); 0354 connect(modifiedBetweenEnabled, &QRadioButton::toggled, modifiedBetweenData1, &KLineEdit::setEnabled); 0355 connect(modifiedBetweenEnabled, &QRadioButton::toggled, modifiedBetweenBtn1, &QToolButton::setEnabled); 0356 connect(modifiedBetweenEnabled, &QRadioButton::toggled, modifiedBetweenData2, &KLineEdit::setEnabled); 0357 connect(modifiedBetweenEnabled, &QRadioButton::toggled, modifiedBetweenBtn2, &QToolButton::setEnabled); 0358 connect(notModifiedAfterEnabled, &QRadioButton::toggled, notModifiedAfterData, &KLineEdit::setEnabled); 0359 connect(notModifiedAfterEnabled, &QRadioButton::toggled, notModifiedAfterBtn, &QToolButton::setEnabled); 0360 connect(modifiedInTheLastEnabled, &QRadioButton::toggled, modifiedInTheLastData, &QSpinBox::setEnabled); 0361 connect(modifiedInTheLastEnabled, &QRadioButton::toggled, modifiedInTheLastType, &KComboBox::setEnabled); 0362 connect(modifiedInTheLastEnabled, &QRadioButton::toggled, notModifiedInTheLastData, &QSpinBox::setEnabled); 0363 connect(modifiedInTheLastEnabled, &QRadioButton::toggled, notModifiedInTheLastType, &KComboBox::setEnabled); 0364 connect(belongsToUserEnabled, &QCheckBox::toggled, belongsToUserData, &KComboBox::setEnabled); 0365 connect(belongsToGroupEnabled, &QCheckBox::toggled, belongsToGroupData, &KComboBox::setEnabled); 0366 connect(permissionsEnabled, &QCheckBox::toggled, ownerR, &KComboBox::setEnabled); 0367 connect(permissionsEnabled, &QCheckBox::toggled, ownerW, &KComboBox::setEnabled); 0368 connect(permissionsEnabled, &QCheckBox::toggled, ownerX, &KComboBox::setEnabled); 0369 connect(permissionsEnabled, &QCheckBox::toggled, groupR, &KComboBox::setEnabled); 0370 connect(permissionsEnabled, &QCheckBox::toggled, groupW, &KComboBox::setEnabled); 0371 connect(permissionsEnabled, &QCheckBox::toggled, groupX, &KComboBox::setEnabled); 0372 connect(permissionsEnabled, &QCheckBox::toggled, allR, &KComboBox::setEnabled); 0373 connect(permissionsEnabled, &QCheckBox::toggled, allW, &KComboBox::setEnabled); 0374 connect(permissionsEnabled, &QCheckBox::toggled, allX, &KComboBox::setEnabled); 0375 connect(modifiedBetweenBtn1, &QToolButton::clicked, this, &AdvancedFilter::modifiedBetweenSetDate1); 0376 connect(modifiedBetweenBtn2, &QToolButton::clicked, this, &AdvancedFilter::modifiedBetweenSetDate2); 0377 connect(notModifiedAfterBtn, &QToolButton::clicked, this, &AdvancedFilter::notModifiedAfterSetDate); 0378 0379 // fill the users and groups list 0380 0381 fillList(belongsToUserData, USERSFILE); 0382 fillList(belongsToGroupData, GROUPSFILE); 0383 0384 // tab order 0385 setTabOrder(minSizeEnabled, minSizeAmount); 0386 setTabOrder(minSizeAmount, maxSizeEnabled); 0387 setTabOrder(maxSizeEnabled, maxSizeAmount); 0388 setTabOrder(maxSizeAmount, modifiedBetweenEnabled); 0389 setTabOrder(modifiedBetweenEnabled, modifiedBetweenData1); 0390 setTabOrder(modifiedBetweenData1, modifiedBetweenData2); 0391 setTabOrder(modifiedBetweenData2, notModifiedAfterEnabled); 0392 setTabOrder(notModifiedAfterEnabled, notModifiedAfterData); 0393 setTabOrder(notModifiedAfterData, modifiedInTheLastEnabled); 0394 setTabOrder(modifiedInTheLastEnabled, modifiedInTheLastData); 0395 setTabOrder(modifiedInTheLastData, notModifiedInTheLastData); 0396 setTabOrder(notModifiedInTheLastData, belongsToUserEnabled); 0397 setTabOrder(belongsToUserEnabled, belongsToUserData); 0398 setTabOrder(belongsToUserData, belongsToGroupEnabled); 0399 setTabOrder(belongsToGroupEnabled, belongsToGroupData); 0400 setTabOrder(belongsToGroupData, permissionsEnabled); 0401 setTabOrder(permissionsEnabled, ownerR); 0402 setTabOrder(ownerR, ownerW); 0403 setTabOrder(ownerW, ownerX); 0404 setTabOrder(ownerX, groupR); 0405 setTabOrder(groupR, groupW); 0406 setTabOrder(groupW, groupX); 0407 setTabOrder(groupX, allR); 0408 setTabOrder(allR, allW); 0409 setTabOrder(allW, allX); 0410 setTabOrder(allX, minSizeType); 0411 setTabOrder(minSizeType, maxSizeType); 0412 setTabOrder(maxSizeType, modifiedInTheLastType); 0413 setTabOrder(modifiedInTheLastType, notModifiedInTheLastType); 0414 } 0415 0416 void AdvancedFilter::modifiedBetweenSetDate1() 0417 { 0418 changeDate(modifiedBetweenData1); 0419 } 0420 0421 void AdvancedFilter::modifiedBetweenSetDate2() 0422 { 0423 changeDate(modifiedBetweenData2); 0424 } 0425 0426 void AdvancedFilter::notModifiedAfterSetDate() 0427 { 0428 changeDate(notModifiedAfterData); 0429 } 0430 0431 void AdvancedFilter::changeDate(KLineEdit *p) 0432 { 0433 // check if the current date is valid 0434 QDate d = stringToDate(p->text()); 0435 if (!d.isValid()) 0436 d = QDate::currentDate(); 0437 0438 auto *gd = new KrGetDate(d, this); 0439 d = gd->getDate(); 0440 // if a user pressed ESC or closed the dialog, we'll return an invalid date 0441 if (d.isValid()) 0442 p->setText(dateToString(d)); 0443 delete gd; 0444 } 0445 0446 void AdvancedFilter::fillList(KComboBox *list, const QString &filename) 0447 { 0448 QFile data(filename); 0449 if (!data.open(QIODevice::ReadOnly)) { 0450 qWarning() << "Search: Unable to read " << filename << " !!!"; 0451 return; 0452 } 0453 // and read it into the temporary array 0454 QTextStream t(&data); 0455 while (!t.atEnd()) { 0456 QString s = t.readLine(); 0457 QString name = s.left(s.indexOf(':')); 0458 if (!name.startsWith('#')) 0459 list->addItem(name); 0460 } 0461 } 0462 0463 void AdvancedFilter::invalidDateMessage(KLineEdit *p) 0464 { 0465 // FIXME p->text() is empty sometimes (to reproduce, set date to "13.09.005") 0466 KMessageBox::detailedError( 0467 this, 0468 i18n("Invalid date entered."), 0469 i18n("The date %1 is not valid according to your locale. Please re-enter a valid date (use the date button for easy access).", p->text())); 0470 p->setFocus(); 0471 } 0472 0473 bool AdvancedFilter::getSettings(FilterSettings &s) 0474 { 0475 s.minSizeEnabled = minSizeEnabled->isChecked(); 0476 s.minSize.amount = minSizeAmount->value(); 0477 s.minSize.unit = static_cast<FilterSettings::SizeUnit>(minSizeType->currentIndex()); 0478 0479 s.maxSizeEnabled = maxSizeEnabled->isChecked(); 0480 s.maxSize.amount = maxSizeAmount->value(); 0481 s.maxSize.unit = static_cast<FilterSettings::SizeUnit>(maxSizeType->currentIndex()); 0482 0483 if (s.minSizeEnabled && s.maxSizeEnabled && (s.maxSize.size() < s.minSize.size())) { 0484 KMessageBox::detailedError(this, 0485 i18n("Specified sizes are inconsistent."), 0486 i18n("Please re-enter the values, so that the left side size " 0487 "will be smaller than (or equal to) the right side size.")); 0488 minSizeAmount->setFocus(); 0489 return false; 0490 } 0491 0492 s.modifiedBetweenEnabled = modifiedBetweenEnabled->isChecked(); 0493 s.modifiedBetween1 = stringToDate(modifiedBetweenData1->text()); 0494 s.modifiedBetween2 = stringToDate(modifiedBetweenData2->text()); 0495 0496 if (s.modifiedBetweenEnabled) { 0497 // check if date is valid 0498 if (!s.modifiedBetween1.isValid()) { 0499 invalidDateMessage(modifiedBetweenData1); 0500 return false; 0501 } else if (!s.modifiedBetween2.isValid()) { 0502 invalidDateMessage(modifiedBetweenData2); 0503 return false; 0504 } else if (s.modifiedBetween1 > s.modifiedBetween2) { 0505 KMessageBox::detailedError(this, 0506 i18n("Dates are inconsistent."), 0507 i18n("The date on the left is later than the date on the right. " 0508 "Please re-enter the dates, so that the left side date " 0509 "will be earlier than the right side date.")); 0510 modifiedBetweenData1->setFocus(); 0511 return false; 0512 } 0513 } 0514 0515 s.notModifiedAfterEnabled = notModifiedAfterEnabled->isChecked(); 0516 s.notModifiedAfter = stringToDate(notModifiedAfterData->text()); 0517 0518 if (s.notModifiedAfterEnabled && !s.notModifiedAfter.isValid()) { 0519 invalidDateMessage(notModifiedAfterData); 0520 return false; 0521 } 0522 0523 s.modifiedInTheLastEnabled = modifiedInTheLastEnabled->isChecked(); 0524 s.modifiedInTheLast.amount = modifiedInTheLastData->value(); 0525 s.modifiedInTheLast.unit = static_cast<FilterSettings::TimeUnit>(modifiedInTheLastType->currentIndex()); 0526 s.notModifiedInTheLast.amount = notModifiedInTheLastData->value(); 0527 s.notModifiedInTheLast.unit = static_cast<FilterSettings::TimeUnit>(notModifiedInTheLastType->currentIndex()); 0528 0529 if (s.modifiedInTheLastEnabled && s.modifiedInTheLast.amount && s.notModifiedInTheLast.amount) { 0530 if (s.modifiedInTheLast.days() < s.notModifiedInTheLast.days()) { 0531 KMessageBox::detailedError(this, 0532 i18n("Dates are inconsistent."), 0533 i18n("The date on top is later than the date on the bottom. " 0534 "Please re-enter the dates, so that the top date " 0535 "will be earlier than the bottom date.")); 0536 modifiedInTheLastData->setFocus(); 0537 return false; 0538 } 0539 } 0540 0541 s.ownerEnabled = belongsToUserEnabled->isChecked(); 0542 s.owner = belongsToUserData->currentText(); 0543 0544 s.groupEnabled = belongsToGroupEnabled->isChecked(); 0545 s.group = belongsToGroupData->currentText(); 0546 0547 s.permissionsEnabled = permissionsEnabled->isChecked(); 0548 0549 // clang-format off 0550 s.permissions = ownerR->currentText() + ownerW->currentText() + ownerX->currentText() + 0551 groupR->currentText() + groupW->currentText() + groupX->currentText() + 0552 allR->currentText() + allW->currentText() + allX->currentText(); 0553 // clang-format on 0554 0555 return true; 0556 } 0557 0558 void AdvancedFilter::applySettings(const FilterSettings &s) 0559 { 0560 minSizeEnabled->setChecked(s.minSizeEnabled); 0561 minSizeAmount->setValue(static_cast<int>(s.minSize.amount)); 0562 minSizeType->setCurrentIndex(s.minSize.unit); 0563 0564 maxSizeEnabled->setChecked(s.maxSizeEnabled); 0565 maxSizeAmount->setValue(static_cast<int>(s.maxSize.amount)); 0566 maxSizeType->setCurrentIndex(s.maxSize.unit); 0567 0568 if (s.modifiedBetweenEnabled) 0569 modifiedBetweenEnabled->setChecked(true); 0570 else if (s.notModifiedAfterEnabled) 0571 notModifiedAfterEnabled->setChecked(true); 0572 else if (s.modifiedInTheLastEnabled) 0573 modifiedInTheLastEnabled->setChecked(true); 0574 else 0575 anyDateEnabled->setChecked(true); 0576 0577 modifiedBetweenData1->setText(dateToString(s.modifiedBetween1)); 0578 modifiedBetweenData2->setText(dateToString(s.modifiedBetween2)); 0579 0580 notModifiedAfterData->setText(dateToString(s.notModifiedAfter)); 0581 0582 modifiedInTheLastData->setValue(s.modifiedInTheLast.amount); 0583 modifiedInTheLastType->setCurrentIndex(s.modifiedInTheLast.unit); 0584 notModifiedInTheLastData->setValue(s.notModifiedInTheLast.amount); 0585 notModifiedInTheLastType->setCurrentIndex(s.notModifiedInTheLast.unit); 0586 0587 belongsToUserEnabled->setChecked(s.ownerEnabled); 0588 setComboBoxValue(belongsToUserData, s.owner); 0589 0590 belongsToGroupEnabled->setChecked(s.groupEnabled); 0591 setComboBoxValue(belongsToGroupData, s.group); 0592 0593 permissionsEnabled->setChecked(s.permissionsEnabled); 0594 QString perm = s.permissions; 0595 if (perm.length() != 9) 0596 perm = "?????????"; 0597 setComboBoxValue(ownerR, QString(perm[0])); 0598 setComboBoxValue(ownerW, QString(perm[1])); 0599 setComboBoxValue(ownerX, QString(perm[2])); 0600 setComboBoxValue(groupR, QString(perm[3])); 0601 setComboBoxValue(groupW, QString(perm[4])); 0602 setComboBoxValue(groupX, QString(perm[5])); 0603 setComboBoxValue(allR, QString(perm[6])); 0604 setComboBoxValue(allW, QString(perm[7])); 0605 setComboBoxValue(allX, QString(perm[8])); 0606 }