1 /*****************************************************************************
2  * Copyright (C) 2004 Shie Erlich <erlich@users.sourceforge.net>             *
3  * Copyright (C) 2004 Rafi Yanai <yanai@users.sourceforge.net>               *
4  * Copyright (C) 2004 Jonas Bähr <jonas.baehr@web.de>                        *
5  * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org]              *
6  *                                                                           *
7  * This file is part of Krusader [https://krusader.org].                     *
8  *                                                                           *
9  * Krusader is free software: you can redistribute it and/or modify          *
10  * it under the terms of the GNU General Public License as published by      *
11  * the Free Software Foundation, either version 2 of the License, or         *
12  * (at your option) any later version.                                       *
13  *                                                                           *
14  * Krusader is distributed in the hope that it will be useful,               *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
17  * GNU General Public License for more details.                              *
18  *                                                                           *
19  * You should have received a copy of the GNU General Public License         *
20  * along with Krusader.  If not, see [http://www.gnu.org/licenses/].         *
21  *****************************************************************************/
22 
23 #include "addplaceholderpopup.h"
24 
25 // for ParameterDialog
26 #include "../krglobal.h" // for konfig-access
27 #include "../icon.h"
28 #include "../BookMan/krbookmarkbutton.h"
29 #include "../GUI/profilemanager.h"
30 
31 // QtWidgets
32 #include <QCheckBox>
33 #include <QDialogButtonBox>
34 #include <QFileDialog>
35 #include <QFrame>
36 #include <QHBoxLayout>
37 #include <QLabel>
38 #include <QSpinBox>
39 #include <QToolButton>
40 #include <QVBoxLayout>
41 
42 #include <KConfigCore/KSharedConfig>
43 #include <KI18n/KLocalizedString>
44 #include <KCompletion/KLineEdit>
45 #include <KCompletion/KComboBox>
46 #include <KIOWidgets/KUrlCompletion>
47 
48 #define ACTIVE_MASK  0x0100
49 #define OTHER_MASK  0x0200
50 #define LEFT_MASK   0x0400
51 #define RIGHT_MASK   0x0800
52 #define INDEPENDENT_MASK 0x1000
53 #define EXECUTABLE_ID  0xFFFF
54 
AddPlaceholderPopup(QWidget * parent)55 AddPlaceholderPopup::AddPlaceholderPopup(QWidget *parent) : QMenu(parent)
56 {
57 
58     _activeSub = new QMenu(i18n("Active panel"), this);
59     _otherSub = new QMenu(i18n("Other panel"), this);
60     _leftSub = new QMenu(i18n("Left panel"), this);
61     _rightSub = new QMenu(i18n("Right panel"), this);
62     _independentSub = new QMenu(i18n("Panel independent"), this);
63 
64     addMenu(_activeSub);
65     addMenu(_otherSub);
66     addMenu(_leftSub);
67     addMenu(_rightSub);
68     addMenu(_independentSub);
69 
70     QAction *chooseExecAct = _independentSub->addAction(i18n("Choose executable..."));
71     chooseExecAct->setData(QVariant(EXECUTABLE_ID));
72 
73     _independentSub->addSeparator();
74 
75     // read the expressions array from the user menu and populate menus
76     Expander expander;
77     for (int i = 0; i < expander.placeholderCount(); ++i) {
78         if (expander.placeholder(i)->expression().isEmpty()) {
79             if (expander.placeholder(i)->needPanel()) {
80                 _activeSub->addSeparator();
81                 _otherSub->addSeparator();
82                 _leftSub->addSeparator();
83                 _rightSub->addSeparator();
84             } else
85                 _independentSub->addSeparator();
86         } else {
87             QAction * action;
88 
89             if (expander.placeholder(i)->needPanel()) {
90                 action = _activeSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
91                 action->setData(QVariant(i | ACTIVE_MASK));
92                 action = _otherSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
93                 action->setData(QVariant(i | OTHER_MASK));
94                 action = _leftSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
95                 action->setData(QVariant(i | LEFT_MASK));
96                 action = _rightSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
97                 action->setData(QVariant(i | RIGHT_MASK));
98             } else {
99                 action = _independentSub->addAction(i18n(expander.placeholder(i)->description().toUtf8()));
100                 action->setData(QVariant(i | INDEPENDENT_MASK));
101             }
102         }
103     }
104 
105 }
106 
107 
getPlaceholder(const QPoint & pos)108 QString AddPlaceholderPopup::getPlaceholder(const QPoint& pos)
109 {
110     QAction *res = exec(pos);
111     if (res == 0)
112         return QString();
113 
114     // add the selected flag to the command line
115     if (res->data().toInt() == EXECUTABLE_ID) {   // did the user need an executable ?
116         // select an executable
117         QString filename = QFileDialog::getOpenFileName(this);
118         if (!filename.isEmpty()) {
119             return filename + ' '; // with extra space
120             // return filename; // without extra space
121         }
122     } else { // user selected something from the menus
123         Expander expander;
124         const exp_placeholder* currentPlaceholder = expander.placeholder(res->data().toInt() & ~(ACTIVE_MASK | OTHER_MASK | LEFT_MASK | RIGHT_MASK | INDEPENDENT_MASK));
125 //       if ( &currentPlaceholder->expFunc == 0 ) {
126 //          KMessageBox::sorry( this, "BOFH Excuse #93:\nFeature not yet implemented" );
127 //          return QString();
128 //       }
129         ParameterDialog* parameterDialog = new ParameterDialog(currentPlaceholder, this);
130         QString panel, parameter = parameterDialog->getParameter();
131         delete parameterDialog;
132         // indicate the panel with 'a' 'o', 'l', 'r' or '_'.
133         if (res->data().toInt() & ACTIVE_MASK)
134             panel = 'a';
135         else if (res->data().toInt() & OTHER_MASK)
136             panel = 'o';
137         else if (res->data().toInt() & LEFT_MASK)
138             panel = 'l';
139         else if (res->data().toInt() & RIGHT_MASK)
140             panel = 'r';
141         else if (res->data().toInt() & INDEPENDENT_MASK)
142             panel = '_';
143         //return '%' + panel + currentPlaceholder->expression() + parameter + "% "; // with extra space
144         return '%' + panel + currentPlaceholder->expression() + parameter + '%'; // without extra space
145     }
146     return QString();
147 }
148 
149 
150 ////////////////////////////////////////////////////////////////////////////////////////////
151 /////////////////////////////// ParameterDialog ////////////////////////////////////
152 ////////////////////////////////////////////////////////////////////////////////////////////
153 
ParameterDialog(const exp_placeholder * currentPlaceholder,QWidget * parent)154 ParameterDialog::ParameterDialog(const exp_placeholder* currentPlaceholder, QWidget *parent) : QDialog(parent)
155 {
156     setWindowTitle(i18n("User Action Parameter Dialog"));
157     QVBoxLayout *mainLayout = new QVBoxLayout;
158     setLayout(mainLayout);
159 
160     _parameter.clear();
161     _parameterCount = currentPlaceholder->parameterCount();
162 
163     QWidget *page = new QWidget(this);
164     mainLayout->addWidget(page);
165     QVBoxLayout* layout = new QVBoxLayout(page);
166     layout->setSpacing(11);
167     layout->setContentsMargins(0, 0, 0, 0);
168 
169     layout->addWidget(new QLabel(i18n("This placeholder allows some parameter:"), page));
170 
171     for (int i = 0; i < _parameterCount; ++i) {
172         if (currentPlaceholder->parameter(i).preset() == "__placeholder")
173             _parameter.append(new ParameterPlaceholder(currentPlaceholder->parameter(i), page));
174         else if (currentPlaceholder->parameter(i).preset() == "__yes")
175             _parameter.append(new ParameterYes(currentPlaceholder->parameter(i), page));
176         else if (currentPlaceholder->parameter(i).preset() == "__no")
177             _parameter.append(new ParameterNo(currentPlaceholder->parameter(i), page));
178         else if (currentPlaceholder->parameter(i).preset() == "__file")
179             _parameter.append(new ParameterFile(currentPlaceholder->parameter(i), page));
180         else if (currentPlaceholder->parameter(i).preset().indexOf("__choose") != -1)
181             _parameter.append(new ParameterChoose(currentPlaceholder->parameter(i), page));
182         else if (currentPlaceholder->parameter(i).preset() == "__select")
183             _parameter.append(new ParameterSelect(currentPlaceholder->parameter(i), page));
184         else if (currentPlaceholder->parameter(i).preset() == "__goto")
185             _parameter.append(new ParameterGoto(currentPlaceholder->parameter(i), page));
186         else if (currentPlaceholder->parameter(i).preset() == "__syncprofile")
187             _parameter.append(new ParameterSyncprofile(currentPlaceholder->parameter(i), page));
188         else if (currentPlaceholder->parameter(i).preset() == "__searchprofile")
189             _parameter.append(new ParameterSearch(currentPlaceholder->parameter(i), page));
190         else if (currentPlaceholder->parameter(i).preset() == "__panelprofile")
191             _parameter.append(new ParameterPanelprofile(currentPlaceholder->parameter(i), page));
192         else if (currentPlaceholder->parameter(i).preset().indexOf("__int") != -1)
193             _parameter.append(new ParameterInt(currentPlaceholder->parameter(i), page));
194         else
195             _parameter.append(new ParameterText(currentPlaceholder->parameter(i), page));
196 
197         layout->addWidget(_parameter.last());
198     }
199 
200     QFrame * line = new QFrame(page);
201     line->setFrameShape(QFrame::HLine);
202     line->setFrameShadow(QFrame::Sunken);
203     layout->addWidget(line);
204 
205     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults);
206     mainLayout->addWidget(buttonBox);
207 
208     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
209     okButton->setDefault(true);
210     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
211     connect(okButton, SIGNAL(clicked()), this, SLOT(slotOk()));
212     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
213     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
214     connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), this, SLOT(reset()));
215 }
216 
getParameter()217 QString ParameterDialog::getParameter()
218 {
219     if (_parameterCount == 0)   // meaning no parameters
220         return QString();
221 
222     if (exec() == -1)
223         return QString();
224 
225     int lastParameter = _parameterCount;
226     while (--lastParameter > -1) {
227         if (_parameter[ lastParameter ]->text() != _parameter[ lastParameter ]->preset()  ||  _parameter[ lastParameter ]->necessary())
228             break;
229     }
230 
231     if (lastParameter < 0)  // all parameters have default-values
232         return QString();
233 
234     QString parameter;
235     for (int i = 0; i <= lastParameter; ++i) {
236         if (i > 0)
237             parameter += ", ";
238         parameter += '\"' + _parameter[ i ]->text().replace('\"', "\\\"") + '\"';
239     }
240     return '(' + parameter + ')';
241 }
242 
reset()243 void ParameterDialog::reset()
244 {
245     for (int i = 0; i < _parameterCount; ++i)
246         _parameter[ i ]->reset();
247 }
248 
slotOk()249 void ParameterDialog::slotOk()
250 {
251     bool valid = true;
252     for (int i = 0; i < _parameterCount; ++i) {
253         if (_parameter[ i ]->necessary() && ! _parameter[ i ]->valid())
254             valid = false;
255     }
256 
257     if (valid)
258         accept();
259 }
260 
261 ///////////// ParameterText
ParameterText(const exp_parameter & parameter,QWidget * parent)262 ParameterText::ParameterText(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
263 {
264     QVBoxLayout* layout = new QVBoxLayout(this);
265     layout->setSpacing(6);
266     layout->setContentsMargins(0, 0, 0, 0);
267 
268     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
269     layout->addWidget(_lineEdit = new KLineEdit(parameter.preset(), this));
270     _preset = parameter.preset();
271 }
272 
text()273 QString ParameterText::text()
274 {
275     return _lineEdit->text();
276 }
preset()277 QString ParameterText::preset()
278 {
279     return _preset;
280 }
reset()281 void ParameterText::reset()
282 {
283     _lineEdit->setText(_preset);
284 }
valid()285 bool ParameterText::valid()
286 {
287     if (_lineEdit->text().isEmpty())
288         return false;
289     else
290         return true;
291 }
292 
293 ///////////// ParameterPlaceholder
ParameterPlaceholder(const exp_parameter & parameter,QWidget * parent)294 ParameterPlaceholder::ParameterPlaceholder(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
295 {
296     QVBoxLayout* layout = new QVBoxLayout(this);
297     layout->setSpacing(6);
298     layout->setContentsMargins(0, 0, 0, 0);
299 
300     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
301     QWidget * hboxWidget = new QWidget(this);
302     layout->addWidget(hboxWidget);
303     QHBoxLayout * hbox = new QHBoxLayout(hboxWidget);
304 
305     hbox->setContentsMargins(0, 0, 0, 0);
306     hbox->setSpacing(6);
307     _lineEdit = new KLineEdit(hboxWidget);
308     hbox->addWidget(_lineEdit);
309     _button = new QToolButton(hboxWidget);
310     _button->setIcon(Icon("list-add"));
311     hbox->addWidget(_button);
312     connect(_button, SIGNAL(clicked()), this, SLOT(addPlaceholder()));
313 }
314 
text()315 QString ParameterPlaceholder::text()
316 {
317     return _lineEdit->text();
318 }
preset()319 QString ParameterPlaceholder::preset()
320 {
321     return QString();
322 }
reset()323 void ParameterPlaceholder::reset()
324 {
325     _lineEdit->setText(QString());
326 }
valid()327 bool ParameterPlaceholder::valid()
328 {
329     if (_lineEdit->text().isEmpty())
330         return false;
331     else
332         return true;
333 }
addPlaceholder()334 void ParameterPlaceholder::addPlaceholder()
335 {
336     AddPlaceholderPopup* popup = new AddPlaceholderPopup(this);
337     QString exp = popup->getPlaceholder(mapToGlobal(QPoint(_button->pos().x() + _button->width() + 6, _button->pos().y() + _button->height() / 2)));
338     _lineEdit->insert(exp);
339     delete popup;
340 }
341 
342 ///////////// ParameterYes
ParameterYes(const exp_parameter & parameter,QWidget * parent)343 ParameterYes::ParameterYes(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
344 {
345     QVBoxLayout* layout = new QVBoxLayout(this);
346     layout->setSpacing(6);
347     layout->setContentsMargins(0, 0, 0, 0);
348 
349     layout->addWidget(_checkBox = new QCheckBox(i18n(parameter.description().toUtf8()), this));
350     _checkBox->setChecked(true);
351 }
352 
text()353 QString ParameterYes::text()
354 {
355     if (_checkBox->isChecked())
356         return QString();
357     else
358         return "No";
359 }
preset()360 QString ParameterYes::preset()
361 {
362     return QString();
363 }
reset()364 void ParameterYes::reset()
365 {
366     _checkBox->setChecked(true);
367 }
valid()368 bool ParameterYes::valid()
369 {
370     return true;
371 }
372 
373 ///////////// ParameterNo
ParameterNo(const exp_parameter & parameter,QWidget * parent)374 ParameterNo::ParameterNo(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
375 {
376     QVBoxLayout* layout = new QVBoxLayout(this);
377     layout->setSpacing(6);
378     layout->setContentsMargins(0, 0, 0, 0);
379 
380     layout->addWidget(_checkBox = new QCheckBox(i18n(parameter.description().toUtf8()), this));
381     _checkBox->setChecked(false);
382 }
383 
text()384 QString ParameterNo::text()
385 {
386     if (_checkBox->isChecked())
387         return "Yes";
388     else
389         return QString();
390 }
preset()391 QString ParameterNo::preset()
392 {
393     return QString();
394 }
reset()395 void ParameterNo::reset()
396 {
397     _checkBox->setChecked(false);
398 }
valid()399 bool ParameterNo::valid()
400 {
401     return true;
402 }
403 
404 ///////////// ParameterFile
ParameterFile(const exp_parameter & parameter,QWidget * parent)405 ParameterFile::ParameterFile(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
406 {
407     QVBoxLayout* layout = new QVBoxLayout(this);
408     layout->setSpacing(6);
409     layout->setContentsMargins(0, 0, 0, 0);
410 
411     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
412 
413     QWidget * hboxWidget = new QWidget(this);
414     layout->addWidget(hboxWidget);
415     QHBoxLayout * hbox = new QHBoxLayout(hboxWidget);
416 
417     hbox->setContentsMargins(0, 0, 0, 0);
418     hbox->setSpacing(6);
419     _lineEdit = new KLineEdit(hboxWidget);
420     hbox->addWidget(_lineEdit);
421     _button = new QToolButton(hboxWidget);
422     hbox->addWidget(_button);
423     _button->setIcon(Icon("document-open"));
424     connect(_button, SIGNAL(clicked()), this, SLOT(addFile()));
425 }
426 
text()427 QString ParameterFile::text()
428 {
429     return _lineEdit->text();
430 }
preset()431 QString ParameterFile::preset()
432 {
433     return QString();
434 }
reset()435 void ParameterFile::reset()
436 {
437     _lineEdit->setText(QString());
438 }
valid()439 bool ParameterFile::valid()
440 {
441     if (_lineEdit->text().isEmpty())
442         return false;
443     else
444         return true;
445 }
addFile()446 void ParameterFile::addFile()
447 {
448     QString filename = QFileDialog::getOpenFileName(this);
449     _lineEdit->insert(filename);
450 }
451 
452 ///////////// ParameterChoose
ParameterChoose(const exp_parameter & parameter,QWidget * parent)453 ParameterChoose::ParameterChoose(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
454 {
455     QVBoxLayout* layout = new QVBoxLayout(this);
456     layout->setSpacing(6);
457     layout->setContentsMargins(0, 0, 0, 0);
458 
459     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
460     layout->addWidget(_combobox = new KComboBox(this));
461     _combobox->addItems(parameter.preset().section(':', 1).split(';'));
462 }
463 
text()464 QString ParameterChoose::text()
465 {
466     return _combobox->currentText();
467 }
preset()468 QString ParameterChoose::preset()
469 {
470     return _combobox->itemText(0);
471 }
reset()472 void ParameterChoose::reset()
473 {
474     _combobox->setCurrentIndex(0);
475 }
valid()476 bool ParameterChoose::valid()
477 {
478     return true;
479 }
480 
481 ///////////// ParameterSelect
ParameterSelect(const exp_parameter & parameter,QWidget * parent)482 ParameterSelect::ParameterSelect(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
483 {
484     QVBoxLayout* layout = new QVBoxLayout(this);
485     layout->setSpacing(6);
486     layout->setContentsMargins(0, 0, 0, 0);
487 
488     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
489     layout->addWidget(_combobox = new KComboBox(this));
490     _combobox->setEditable(true);
491 
492     KConfigGroup group(krConfig, "Private");
493     QStringList lst = group.readEntry("Predefined Selections", QStringList());
494     if (lst.size() > 0)
495         _combobox->addItems(lst);
496 
497     _combobox->lineEdit()->setText("*");
498 }
499 
text()500 QString ParameterSelect::text()
501 {
502     return _combobox->currentText();
503 }
preset()504 QString ParameterSelect::preset()
505 {
506     return "*";
507 }
reset()508 void ParameterSelect::reset()
509 {
510     _combobox->lineEdit()->setText("*");
511 }
valid()512 bool ParameterSelect::valid()
513 {
514     return true;
515 }
516 
517 ///////////// ParameterGoto
ParameterGoto(const exp_parameter & parameter,QWidget * parent)518 ParameterGoto::ParameterGoto(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
519 {
520     QVBoxLayout* layout = new QVBoxLayout(this);
521     layout->setSpacing(6);
522     layout->setContentsMargins(0, 0, 0, 0);
523 
524     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
525 
526     QWidget * hboxWidget = new QWidget(this);
527     QHBoxLayout * hbox = new QHBoxLayout(hboxWidget);
528 
529     hbox->setContentsMargins(0, 0, 0, 0);
530     hbox->setSpacing(6);
531     _lineEdit = new KLineEdit(hboxWidget);
532     _lineEdit->setCompletionObject(new KUrlCompletion(KUrlCompletion::DirCompletion));
533     hbox->addWidget(_lineEdit);
534     _dirButton = new QToolButton(hboxWidget);
535     hbox->addWidget(_dirButton);
536     _dirButton->setIcon(Icon("document-open"));
537     connect(_dirButton, SIGNAL(clicked()), this, SLOT(setDir()));
538     _placeholderButton = new QToolButton(hboxWidget);
539     _placeholderButton->setIcon(Icon("list-add"));
540     hbox->addWidget(_placeholderButton);
541     connect(_placeholderButton, SIGNAL(clicked()), this, SLOT(addPlaceholder()));
542 
543     layout->addWidget(hboxWidget);
544 }
545 
text()546 QString ParameterGoto::text()
547 {
548     return _lineEdit->text();
549 }
preset()550 QString ParameterGoto::preset()
551 {
552     return QString();
553 }
reset()554 void ParameterGoto::reset()
555 {
556     _lineEdit->setText(QString());
557 }
valid()558 bool ParameterGoto::valid()
559 {
560     if (_lineEdit->text().isEmpty())
561         return false;
562     else
563         return true;
564 }
setDir()565 void ParameterGoto::setDir()
566 {
567     QString folder = QFileDialog::getExistingDirectory(this);
568     _lineEdit->setText(folder);
569 }
addPlaceholder()570 void ParameterGoto::addPlaceholder()
571 {
572     AddPlaceholderPopup* popup = new AddPlaceholderPopup(this);
573     QString exp = popup->getPlaceholder(mapToGlobal(QPoint(_placeholderButton->pos().x() + _placeholderButton->width() + 6, _placeholderButton->pos().y() + _placeholderButton->height() / 2)));
574     _lineEdit->insert(exp);
575     delete popup;
576 }
577 
578 ///////////// ParameterSyncprofile
ParameterSyncprofile(const exp_parameter & parameter,QWidget * parent)579 ParameterSyncprofile::ParameterSyncprofile(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
580 {
581     QVBoxLayout* layout = new QVBoxLayout(this);
582     layout->setSpacing(6);
583     layout->setContentsMargins(0, 0, 0, 0);
584 
585     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
586     layout->addWidget(_combobox = new KComboBox(this));
587 
588     _combobox->addItems(ProfileManager::availableProfiles("SynchronizerProfile"));
589 }
590 
text()591 QString ParameterSyncprofile::text()
592 {
593     return _combobox->currentText();
594 }
preset()595 QString ParameterSyncprofile::preset()
596 {
597     return _combobox->itemText(0);
598 }
reset()599 void ParameterSyncprofile::reset()
600 {
601     _combobox->setCurrentIndex(0);
602 }
valid()603 bool ParameterSyncprofile::valid()
604 {
605     return true;
606 }
607 
608 ///////////// ParameterSearch
ParameterSearch(const exp_parameter & parameter,QWidget * parent)609 ParameterSearch::ParameterSearch(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
610 {
611     QVBoxLayout* layout = new QVBoxLayout(this);
612     layout->setSpacing(6);
613     layout->setContentsMargins(0, 0, 0, 0);
614 
615     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
616     layout->addWidget(_combobox = new KComboBox(this));
617 
618     _combobox->addItems(ProfileManager::availableProfiles("SearcherProfile"));
619 }
620 
text()621 QString ParameterSearch::text()
622 {
623     return _combobox->currentText();
624 }
preset()625 QString ParameterSearch::preset()
626 {
627     return _combobox->itemText(0);
628 }
reset()629 void ParameterSearch::reset()
630 {
631     _combobox->setCurrentIndex(0);
632 }
valid()633 bool ParameterSearch::valid()
634 {
635     return true;
636 }
637 
638 ///////////// ParameterPanelprofile
ParameterPanelprofile(const exp_parameter & parameter,QWidget * parent)639 ParameterPanelprofile::ParameterPanelprofile(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
640 {
641     QVBoxLayout* layout = new QVBoxLayout(this);
642     layout->setSpacing(6);
643     layout->setContentsMargins(0, 0, 0, 0);
644 
645     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
646     layout->addWidget(_combobox = new KComboBox(this));
647 
648     _combobox->addItems(ProfileManager::availableProfiles("Panel"));
649 }
650 
text()651 QString ParameterPanelprofile::text()
652 {
653     return _combobox->currentText();
654 }
preset()655 QString ParameterPanelprofile::preset()
656 {
657     return _combobox->itemText(0);
658 }
reset()659 void ParameterPanelprofile::reset()
660 {
661     _combobox->setCurrentIndex(0);
662 }
valid()663 bool ParameterPanelprofile::valid()
664 {
665     return true;
666 }
667 
668 ///////////// ParameterInt
ParameterInt(const exp_parameter & parameter,QWidget * parent)669 ParameterInt::ParameterInt(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent)
670 {
671     QHBoxLayout* layout = new QHBoxLayout(this);
672     layout->setSpacing(6);
673     layout->setContentsMargins(0, 0, 0, 0);
674 
675     layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this));
676     layout->addWidget(_spinbox = new QSpinBox(this));
677     QStringList para = parameter.preset().section(':', 1).split(';');
678 
679     _spinbox->setMinimum(para[0].toInt());
680     _spinbox->setMaximum(para[1].toInt());
681     _spinbox->setSingleStep(para[2].toInt());
682     _spinbox->setValue(para[3].toInt());
683 
684     _default = _spinbox->value();
685 }
686 
text()687 QString ParameterInt::text()
688 {
689     return _spinbox->text();
690 }
preset()691 QString ParameterInt::preset()
692 {
693     return QString("%1").arg(_default);
694 }
reset()695 void ParameterInt::reset()
696 {
697     return _spinbox->setValue(_default);
698 }
valid()699 bool ParameterInt::valid()
700 {
701     return true;
702 }
703 
704