File indexing completed on 2024-05-05 17:56:44

0001 /*
0002     SPDX-FileCopyrightText: 2004 Shie Erlich <erlich@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2004 Rafi Yanai <yanai@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004 Jonas Bähr <jonas.baehr@web.de>
0005     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "addplaceholderpopup.h"
0011 
0012 // for ParameterDialog
0013 #include "../BookMan/krbookmarkbutton.h"
0014 #include "../GUI/profilemanager.h"
0015 #include "../icon.h"
0016 #include "../krglobal.h" // for konfig-access
0017 
0018 // QtWidgets
0019 #include <QCheckBox>
0020 #include <QDialogButtonBox>
0021 #include <QFileDialog>
0022 #include <QFrame>
0023 #include <QHBoxLayout>
0024 #include <QLabel>
0025 #include <QSpinBox>
0026 #include <QToolButton>
0027 #include <QVBoxLayout>
0028 
0029 #include <KCompletion/KComboBox>
0030 #include <KCompletion/KLineEdit>
0031 #include <KConfigCore/KSharedConfig>
0032 #include <KI18n/KLocalizedString>
0033 #include <KIOWidgets/KUrlCompletion>
0034 
0035 #define ACTIVE_MASK 0x0100
0036 #define OTHER_MASK 0x0200
0037 #define LEFT_MASK 0x0400
0038 #define RIGHT_MASK 0x0800
0039 #define INDEPENDENT_MASK 0x1000
0040 #define EXECUTABLE_ID 0xFFFF
0041 
0042 AddPlaceholderPopup::AddPlaceholderPopup(QWidget *parent)
0043     : QMenu(parent)
0044 {
0045     _activeSub = new QMenu(i18n("Active panel"), this);
0046     _otherSub = new QMenu(i18n("Other panel"), this);
0047     _leftSub = new QMenu(i18n("Left panel"), this);
0048     _rightSub = new QMenu(i18n("Right panel"), this);
0049     _independentSub = new QMenu(i18n("Panel independent"), this);
0050 
0051     addMenu(_activeSub);
0052     addMenu(_otherSub);
0053     addMenu(_leftSub);
0054     addMenu(_rightSub);
0055     addMenu(_independentSub);
0056 
0057     QAction *chooseExecAct = _independentSub->addAction(i18n("Choose executable..."));
0058     chooseExecAct->setData(QVariant(EXECUTABLE_ID));
0059 
0060     _independentSub->addSeparator();
0061 
0062     // read the expressions array from the user menu and populate menus
0063     Expander expander;
0064     for (int i = 0; i < expander.placeholderCount(); ++i) {
0065         if (expander.placeholder(i)->expression().isEmpty()) {
0066             if (expander.placeholder(i)->needPanel()) {
0067                 _activeSub->addSeparator();
0068                 _otherSub->addSeparator();
0069                 _leftSub->addSeparator();
0070                 _rightSub->addSeparator();
0071             } else
0072                 _independentSub->addSeparator();
0073         } else {
0074             QAction *action;
0075 
0076             if (expander.placeholder(i)->needPanel()) {
0077                 action = _activeSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
0078                 action->setData(QVariant(i | ACTIVE_MASK));
0079                 action = _otherSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
0080                 action->setData(QVariant(i | OTHER_MASK));
0081                 action = _leftSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
0082                 action->setData(QVariant(i | LEFT_MASK));
0083                 action = _rightSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
0084                 action->setData(QVariant(i | RIGHT_MASK));
0085             } else {
0086                 action = _independentSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
0087                 action->setData(QVariant(i | INDEPENDENT_MASK));
0088             }
0089         }
0090     }
0091 }
0092 
0093 QString AddPlaceholderPopup::getPlaceholder(const QPoint &pos)
0094 {
0095     QAction *res = exec(pos);
0096     if (res == nullptr)
0097         return QString();
0098 
0099     // add the selected flag to the command line
0100     if (res->data().toInt() == EXECUTABLE_ID) { // did the user need an executable ?
0101         // select an executable
0102         QString filename = QFileDialog::getOpenFileName(this);
0103         if (!filename.isEmpty()) {
0104             return filename + ' '; // with extra space
0105             // return filename; // without extra space
0106         }
0107     } else { // user selected something from the menus
0108         Expander expander;
0109         const exp_placeholder *currentPlaceholder =
0110             expander.placeholder(res->data().toInt() & ~(ACTIVE_MASK | OTHER_MASK | LEFT_MASK | RIGHT_MASK | INDEPENDENT_MASK));
0111         // if (&currentPlaceholder->expFunc == 0) {
0112         //     KMessageBox::error(this, "BOFH Excuse #93:\nFeature not yet implemented");
0113         //     return QString();
0114         // }
0115         auto *parameterDialog = new ParameterDialog(currentPlaceholder, this);
0116         QString panel, parameter = parameterDialog->getParameter();
0117         delete parameterDialog;
0118         // indicate the panel with 'a' 'o', 'l', 'r' or '_'.
0119         if (res->data().toInt() & ACTIVE_MASK)
0120             panel = 'a';
0121         else if (res->data().toInt() & OTHER_MASK)
0122             panel = 'o';
0123         else if (res->data().toInt() & LEFT_MASK)
0124             panel = 'l';
0125         else if (res->data().toInt() & RIGHT_MASK)
0126             panel = 'r';
0127         else if (res->data().toInt() & INDEPENDENT_MASK)
0128             panel = '_';
0129         // return '%' + panel + currentPlaceholder->expression() + parameter + "% "; // with extra space
0130         return '%' + panel + currentPlaceholder->expression() + parameter + '%'; // without extra space
0131     }
0132     return QString();
0133 }
0134 
0135 ////////////////////////////////////////////////////////////////////////////////////////////
0136 /////////////////////////////// ParameterDialog ////////////////////////////////////
0137 ////////////////////////////////////////////////////////////////////////////////////////////
0138 
0139 ParameterDialog::ParameterDialog(const exp_placeholder *currentPlaceholder, QWidget *parent)
0140     : QDialog(parent)
0141 {
0142     setWindowTitle(i18n("User Action Parameter Dialog"));
0143     auto *mainLayout = new QVBoxLayout;
0144     setLayout(mainLayout);
0145 
0146     _parameter.clear();
0147     _parameterCount = currentPlaceholder->parameterCount();
0148 
0149     QWidget *page = new QWidget(this);
0150     mainLayout->addWidget(page);
0151     auto *layout = new QVBoxLayout(page);
0152     layout->setSpacing(11);
0153     layout->setContentsMargins(0, 0, 0, 0);
0154 
0155     layout->addWidget(new QLabel(i18n("This placeholder allows some parameter:"), page));
0156 
0157     for (int i = 0; i < _parameterCount; ++i) {
0158         if (currentPlaceholder->parameter(i).preset() == "__placeholder")
0159             _parameter.append(new ParameterPlaceholder(currentPlaceholder->parameter(i), page));
0160         else if (currentPlaceholder->parameter(i).preset() == "__yes")
0161             _parameter.append(new ParameterYes(currentPlaceholder->parameter(i), page));
0162         else if (currentPlaceholder->parameter(i).preset() == "__no")
0163             _parameter.append(new ParameterNo(currentPlaceholder->parameter(i), page));
0164         else if (currentPlaceholder->parameter(i).preset() == "__file")
0165             _parameter.append(new ParameterFile(currentPlaceholder->parameter(i), page));
0166         else if (currentPlaceholder->parameter(i).preset().indexOf("__choose") != -1)
0167             _parameter.append(new ParameterChoose(currentPlaceholder->parameter(i), page));
0168         else if (currentPlaceholder->parameter(i).preset() == "__select")
0169             _parameter.append(new ParameterSelect(currentPlaceholder->parameter(i), page));
0170         else if (currentPlaceholder->parameter(i).preset() == "__goto")
0171             _parameter.append(new ParameterGoto(currentPlaceholder->parameter(i), page));
0172         else if (currentPlaceholder->parameter(i).preset() == "__syncprofile")
0173             _parameter.append(new ParameterSyncprofile(currentPlaceholder->parameter(i), page));
0174         else if (currentPlaceholder->parameter(i).preset() == "__searchprofile")
0175             _parameter.append(new ParameterSearch(currentPlaceholder->parameter(i), page));
0176         else if (currentPlaceholder->parameter(i).preset() == "__panelprofile")
0177             _parameter.append(new ParameterPanelprofile(currentPlaceholder->parameter(i), page));
0178         else if (currentPlaceholder->parameter(i).preset().indexOf("__int") != -1)
0179             _parameter.append(new ParameterInt(currentPlaceholder->parameter(i), page));
0180         else
0181             _parameter.append(new ParameterText(currentPlaceholder->parameter(i), page));
0182 
0183         layout->addWidget(_parameter.last());
0184     }
0185 
0186     QFrame *line = new QFrame(page);
0187     line->setFrameShape(QFrame::HLine);
0188     line->setFrameShadow(QFrame::Sunken);
0189     layout->addWidget(line);
0190 
0191     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::RestoreDefaults);
0192     mainLayout->addWidget(buttonBox);
0193 
0194     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0195     okButton->setDefault(true);
0196     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0197     connect(okButton, &QPushButton::clicked, this, &ParameterDialog::slotOk);
0198     connect(buttonBox, &QDialogButtonBox::accepted, this, &ParameterDialog::accept);
0199     connect(buttonBox, &QDialogButtonBox::rejected, this, &ParameterDialog::reject);
0200     connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &ParameterDialog::reset);
0201 }
0202 
0203 QString ParameterDialog::getParameter()
0204 {
0205     if (_parameterCount == 0) // meaning no parameters
0206         return QString();
0207 
0208     if (exec() == -1)
0209         return QString();
0210 
0211     int lastParameter = _parameterCount;
0212     while (--lastParameter > -1) {
0213         if (_parameter[lastParameter]->text() != _parameter[lastParameter]->preset() || _parameter[lastParameter]->necessary())
0214             break;
0215     }
0216 
0217     if (lastParameter < 0) // all parameters have default-values
0218         return QString();
0219 
0220     QString parameter;
0221     for (int i = 0; i <= lastParameter; ++i) {
0222         if (i > 0)
0223             parameter += ", ";
0224         parameter += '\"' + _parameter[i]->text().replace('\"', "\\\"") + '\"';
0225     }
0226     return '(' + parameter + ')';
0227 }
0228 
0229 void ParameterDialog::reset()
0230 {
0231     for (int i = 0; i < _parameterCount; ++i)
0232         _parameter[i]->reset();
0233 }
0234 
0235 void ParameterDialog::slotOk()
0236 {
0237     bool valid = true;
0238     for (int i = 0; i < _parameterCount; ++i) {
0239         if (_parameter[i]->necessary() && !_parameter[i]->valid())
0240             valid = false;
0241     }
0242 
0243     if (valid)
0244         accept();
0245 }
0246 
0247 ///////////// ParameterText
0248 ParameterText::ParameterText(const exp_parameter &parameter, QWidget *parent)
0249     : ParameterBase(parameter, parent)
0250 {
0251     auto *layout = new QVBoxLayout(this);
0252     layout->setSpacing(6);
0253     layout->setContentsMargins(0, 0, 0, 0);
0254 
0255     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0256     layout->addWidget(_lineEdit = new KLineEdit(parameter.preset(), this));
0257     _preset = parameter.preset();
0258 }
0259 
0260 QString ParameterText::text()
0261 {
0262     return _lineEdit->text();
0263 }
0264 QString ParameterText::preset()
0265 {
0266     return _preset;
0267 }
0268 void ParameterText::reset()
0269 {
0270     _lineEdit->setText(_preset);
0271 }
0272 bool ParameterText::valid()
0273 {
0274     if (_lineEdit->text().isEmpty())
0275         return false;
0276     else
0277         return true;
0278 }
0279 
0280 ///////////// ParameterPlaceholder
0281 ParameterPlaceholder::ParameterPlaceholder(const exp_parameter &parameter, QWidget *parent)
0282     : ParameterBase(parameter, parent)
0283 {
0284     auto *layout = new QVBoxLayout(this);
0285     layout->setSpacing(6);
0286     layout->setContentsMargins(0, 0, 0, 0);
0287 
0288     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0289     QWidget *hboxWidget = new QWidget(this);
0290     layout->addWidget(hboxWidget);
0291     auto *hbox = new QHBoxLayout(hboxWidget);
0292 
0293     hbox->setContentsMargins(0, 0, 0, 0);
0294     hbox->setSpacing(6);
0295     _lineEdit = new KLineEdit(hboxWidget);
0296     hbox->addWidget(_lineEdit);
0297     _button = new QToolButton(hboxWidget);
0298     _button->setIcon(Icon("list-add"));
0299     hbox->addWidget(_button);
0300     connect(_button, &QToolButton::clicked, this, &ParameterPlaceholder::addPlaceholder);
0301 }
0302 
0303 QString ParameterPlaceholder::text()
0304 {
0305     return _lineEdit->text();
0306 }
0307 QString ParameterPlaceholder::preset()
0308 {
0309     return QString();
0310 }
0311 void ParameterPlaceholder::reset()
0312 {
0313     _lineEdit->setText(QString());
0314 }
0315 bool ParameterPlaceholder::valid()
0316 {
0317     if (_lineEdit->text().isEmpty())
0318         return false;
0319     else
0320         return true;
0321 }
0322 void ParameterPlaceholder::addPlaceholder()
0323 {
0324     auto *popup = new AddPlaceholderPopup(this);
0325     QString exp = popup->getPlaceholder(mapToGlobal(QPoint(_button->pos().x() + _button->width() + 6, _button->pos().y() + _button->height() / 2)));
0326     _lineEdit->insert(exp);
0327     delete popup;
0328 }
0329 
0330 ///////////// ParameterYes
0331 ParameterYes::ParameterYes(const exp_parameter &parameter, QWidget *parent)
0332     : ParameterBase(parameter, parent)
0333 {
0334     auto *layout = new QVBoxLayout(this);
0335     layout->setSpacing(6);
0336     layout->setContentsMargins(0, 0, 0, 0);
0337 
0338     layout->addWidget(_checkBox = new QCheckBox(i18n(parameter.description().toUtf8()), this));
0339     _checkBox->setChecked(true);
0340 }
0341 
0342 QString ParameterYes::text()
0343 {
0344     if (_checkBox->isChecked())
0345         return QString();
0346     else
0347         return "No";
0348 }
0349 QString ParameterYes::preset()
0350 {
0351     return QString();
0352 }
0353 void ParameterYes::reset()
0354 {
0355     _checkBox->setChecked(true);
0356 }
0357 bool ParameterYes::valid()
0358 {
0359     return true;
0360 }
0361 
0362 ///////////// ParameterNo
0363 ParameterNo::ParameterNo(const exp_parameter &parameter, QWidget *parent)
0364     : ParameterBase(parameter, parent)
0365 {
0366     auto *layout = new QVBoxLayout(this);
0367     layout->setSpacing(6);
0368     layout->setContentsMargins(0, 0, 0, 0);
0369 
0370     layout->addWidget(_checkBox = new QCheckBox(i18n(parameter.description().toUtf8()), this));
0371     _checkBox->setChecked(false);
0372 }
0373 
0374 QString ParameterNo::text()
0375 {
0376     if (_checkBox->isChecked())
0377         return "Yes";
0378     else
0379         return QString();
0380 }
0381 QString ParameterNo::preset()
0382 {
0383     return QString();
0384 }
0385 void ParameterNo::reset()
0386 {
0387     _checkBox->setChecked(false);
0388 }
0389 bool ParameterNo::valid()
0390 {
0391     return true;
0392 }
0393 
0394 ///////////// ParameterFile
0395 ParameterFile::ParameterFile(const exp_parameter &parameter, QWidget *parent)
0396     : ParameterBase(parameter, parent)
0397 {
0398     auto *layout = new QVBoxLayout(this);
0399     layout->setSpacing(6);
0400     layout->setContentsMargins(0, 0, 0, 0);
0401 
0402     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0403 
0404     QWidget *hboxWidget = new QWidget(this);
0405     layout->addWidget(hboxWidget);
0406     auto *hbox = new QHBoxLayout(hboxWidget);
0407 
0408     hbox->setContentsMargins(0, 0, 0, 0);
0409     hbox->setSpacing(6);
0410     _lineEdit = new KLineEdit(hboxWidget);
0411     hbox->addWidget(_lineEdit);
0412     _button = new QToolButton(hboxWidget);
0413     hbox->addWidget(_button);
0414     _button->setIcon(Icon("document-open"));
0415     connect(_button, &QToolButton::clicked, this, &ParameterFile::addFile);
0416 }
0417 
0418 QString ParameterFile::text()
0419 {
0420     return _lineEdit->text();
0421 }
0422 QString ParameterFile::preset()
0423 {
0424     return QString();
0425 }
0426 void ParameterFile::reset()
0427 {
0428     _lineEdit->setText(QString());
0429 }
0430 bool ParameterFile::valid()
0431 {
0432     if (_lineEdit->text().isEmpty())
0433         return false;
0434     else
0435         return true;
0436 }
0437 void ParameterFile::addFile()
0438 {
0439     QString filename = QFileDialog::getOpenFileName(this);
0440     _lineEdit->insert(filename);
0441 }
0442 
0443 ///////////// ParameterChoose
0444 ParameterChoose::ParameterChoose(const exp_parameter &parameter, QWidget *parent)
0445     : ParameterBase(parameter, parent)
0446 {
0447     auto *layout = new QVBoxLayout(this);
0448     layout->setSpacing(6);
0449     layout->setContentsMargins(0, 0, 0, 0);
0450 
0451     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0452     layout->addWidget(_combobox = new KComboBox(this));
0453     _combobox->addItems(parameter.preset().section(':', 1).split(';'));
0454 }
0455 
0456 QString ParameterChoose::text()
0457 {
0458     return _combobox->currentText();
0459 }
0460 QString ParameterChoose::preset()
0461 {
0462     return _combobox->itemText(0);
0463 }
0464 void ParameterChoose::reset()
0465 {
0466     _combobox->setCurrentIndex(0);
0467 }
0468 bool ParameterChoose::valid()
0469 {
0470     return true;
0471 }
0472 
0473 ///////////// ParameterSelect
0474 ParameterSelect::ParameterSelect(const exp_parameter &parameter, QWidget *parent)
0475     : ParameterBase(parameter, parent)
0476 {
0477     auto *layout = new QVBoxLayout(this);
0478     layout->setSpacing(6);
0479     layout->setContentsMargins(0, 0, 0, 0);
0480 
0481     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0482     layout->addWidget(_combobox = new KComboBox(this));
0483     _combobox->setEditable(true);
0484 
0485     KConfigGroup group(krConfig, "Private");
0486     QStringList lst = group.readEntry("Predefined Selections", QStringList());
0487     if (lst.size() > 0)
0488         _combobox->addItems(lst);
0489 
0490     _combobox->lineEdit()->setText("*");
0491 }
0492 
0493 QString ParameterSelect::text()
0494 {
0495     return _combobox->currentText();
0496 }
0497 QString ParameterSelect::preset()
0498 {
0499     return "*";
0500 }
0501 void ParameterSelect::reset()
0502 {
0503     _combobox->lineEdit()->setText("*");
0504 }
0505 bool ParameterSelect::valid()
0506 {
0507     return true;
0508 }
0509 
0510 ///////////// ParameterGoto
0511 ParameterGoto::ParameterGoto(const exp_parameter &parameter, QWidget *parent)
0512     : ParameterBase(parameter, parent)
0513 {
0514     auto *layout = new QVBoxLayout(this);
0515     layout->setSpacing(6);
0516     layout->setContentsMargins(0, 0, 0, 0);
0517 
0518     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0519 
0520     QWidget *hboxWidget = new QWidget(this);
0521     auto *hbox = new QHBoxLayout(hboxWidget);
0522 
0523     hbox->setContentsMargins(0, 0, 0, 0);
0524     hbox->setSpacing(6);
0525     _lineEdit = new KLineEdit(hboxWidget);
0526     _lineEdit->setCompletionObject(new KUrlCompletion(KUrlCompletion::DirCompletion));
0527     hbox->addWidget(_lineEdit);
0528     _dirButton = new QToolButton(hboxWidget);
0529     hbox->addWidget(_dirButton);
0530     _dirButton->setIcon(Icon("document-open"));
0531     connect(_dirButton, &QToolButton::clicked, this, &ParameterGoto::setDir);
0532     _placeholderButton = new QToolButton(hboxWidget);
0533     _placeholderButton->setIcon(Icon("list-add"));
0534     hbox->addWidget(_placeholderButton);
0535     connect(_placeholderButton, &QToolButton::clicked, this, &ParameterGoto::addPlaceholder);
0536 
0537     layout->addWidget(hboxWidget);
0538 }
0539 
0540 QString ParameterGoto::text()
0541 {
0542     return _lineEdit->text();
0543 }
0544 QString ParameterGoto::preset()
0545 {
0546     return QString();
0547 }
0548 void ParameterGoto::reset()
0549 {
0550     _lineEdit->setText(QString());
0551 }
0552 bool ParameterGoto::valid()
0553 {
0554     if (_lineEdit->text().isEmpty())
0555         return false;
0556     else
0557         return true;
0558 }
0559 void ParameterGoto::setDir()
0560 {
0561     QString folder = QFileDialog::getExistingDirectory(this);
0562     _lineEdit->setText(folder);
0563 }
0564 void ParameterGoto::addPlaceholder()
0565 {
0566     auto *popup = new AddPlaceholderPopup(this);
0567     QString exp = popup->getPlaceholder(
0568         mapToGlobal(QPoint(_placeholderButton->pos().x() + _placeholderButton->width() + 6, _placeholderButton->pos().y() + _placeholderButton->height() / 2)));
0569     _lineEdit->insert(exp);
0570     delete popup;
0571 }
0572 
0573 ///////////// ParameterSyncprofile
0574 ParameterSyncprofile::ParameterSyncprofile(const exp_parameter &parameter, QWidget *parent)
0575     : ParameterBase(parameter, parent)
0576 {
0577     auto *layout = new QVBoxLayout(this);
0578     layout->setSpacing(6);
0579     layout->setContentsMargins(0, 0, 0, 0);
0580 
0581     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0582     layout->addWidget(_combobox = new KComboBox(this));
0583 
0584     _combobox->addItems(ProfileManager::availableProfiles("SynchronizerProfile"));
0585 }
0586 
0587 QString ParameterSyncprofile::text()
0588 {
0589     return _combobox->currentText();
0590 }
0591 QString ParameterSyncprofile::preset()
0592 {
0593     return _combobox->itemText(0);
0594 }
0595 void ParameterSyncprofile::reset()
0596 {
0597     _combobox->setCurrentIndex(0);
0598 }
0599 bool ParameterSyncprofile::valid()
0600 {
0601     return true;
0602 }
0603 
0604 ///////////// ParameterSearch
0605 ParameterSearch::ParameterSearch(const exp_parameter &parameter, QWidget *parent)
0606     : ParameterBase(parameter, parent)
0607 {
0608     auto *layout = new QVBoxLayout(this);
0609     layout->setSpacing(6);
0610     layout->setContentsMargins(0, 0, 0, 0);
0611 
0612     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0613     layout->addWidget(_combobox = new KComboBox(this));
0614 
0615     _combobox->addItems(ProfileManager::availableProfiles("SearcherProfile"));
0616 }
0617 
0618 QString ParameterSearch::text()
0619 {
0620     return _combobox->currentText();
0621 }
0622 QString ParameterSearch::preset()
0623 {
0624     return _combobox->itemText(0);
0625 }
0626 void ParameterSearch::reset()
0627 {
0628     _combobox->setCurrentIndex(0);
0629 }
0630 bool ParameterSearch::valid()
0631 {
0632     return true;
0633 }
0634 
0635 ///////////// ParameterPanelprofile
0636 ParameterPanelprofile::ParameterPanelprofile(const exp_parameter &parameter, QWidget *parent)
0637     : ParameterBase(parameter, parent)
0638 {
0639     auto *layout = new QVBoxLayout(this);
0640     layout->setSpacing(6);
0641     layout->setContentsMargins(0, 0, 0, 0);
0642 
0643     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0644     layout->addWidget(_combobox = new KComboBox(this));
0645 
0646     _combobox->addItems(ProfileManager::availableProfiles("Panel"));
0647 }
0648 
0649 QString ParameterPanelprofile::text()
0650 {
0651     return _combobox->currentText();
0652 }
0653 QString ParameterPanelprofile::preset()
0654 {
0655     return _combobox->itemText(0);
0656 }
0657 void ParameterPanelprofile::reset()
0658 {
0659     _combobox->setCurrentIndex(0);
0660 }
0661 bool ParameterPanelprofile::valid()
0662 {
0663     return true;
0664 }
0665 
0666 ///////////// ParameterInt
0667 ParameterInt::ParameterInt(const exp_parameter &parameter, QWidget *parent)
0668     : ParameterBase(parameter, parent)
0669 {
0670     auto *layout = new QHBoxLayout(this);
0671     layout->setSpacing(6);
0672     layout->setContentsMargins(0, 0, 0, 0);
0673 
0674     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
0675     layout->addWidget(_spinbox = new QSpinBox(this));
0676     QStringList para = parameter.preset().section(':', 1).split(';');
0677 
0678     _spinbox->setMinimum(para[0].toInt());
0679     _spinbox->setMaximum(para[1].toInt());
0680     _spinbox->setSingleStep(para[2].toInt());
0681     _spinbox->setValue(para[3].toInt());
0682 
0683     _default = _spinbox->value();
0684 }
0685 
0686 QString ParameterInt::text()
0687 {
0688     return _spinbox->text();
0689 }
0690 QString ParameterInt::preset()
0691 {
0692     return QString("%1").arg(_default);
0693 }
0694 void ParameterInt::reset()
0695 {
0696     return _spinbox->setValue(_default);
0697 }
0698 bool ParameterInt::valid()
0699 {
0700     return true;
0701 }