]>
cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchoptionsconfigurator.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinsearchoptionsconfigurator.h"
22 #include "searchcriterionselector.h"
24 #include <kcombobox.h>
27 #include <klineedit.h>
29 #include <kseparator.h>
31 #include <QButtonGroup>
32 #include <QHBoxLayout>
34 #include <QPushButton>
35 #include <QVBoxLayout>
37 DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget
* parent
) :
41 m_addSelectorButton(0),
44 m_vBoxLayout
= new QVBoxLayout(this);
46 // add "search" configuration
47 QLabel
* searchLabel
= new QLabel(i18nc("@label", "Search:"));
49 m_searchFromBox
= new KComboBox(this);
50 m_searchFromBox
->addItem(i18nc("@label", "Everywhere"));
51 m_searchFromBox
->addItem(i18nc("@label", "From Here"));
53 // add "what" configuration
54 QLabel
* whatLabel
= new QLabel(i18nc("@label", "What:"));
56 m_searchWhatBox
= new KComboBox(this);
57 m_searchWhatBox
->addItem(i18nc("@label", "All"));
58 m_searchWhatBox
->addItem(i18nc("@label", "Images"));
59 m_searchWhatBox
->addItem(i18nc("@label", "Text"));
60 m_searchWhatBox
->addItem(i18nc("@label", "Filenames"));
62 QWidget
* filler
= new QWidget(this);
65 QPushButton
* saveButton
= new QPushButton(this);
66 saveButton
->setIcon(KIcon("document-save"));
67 saveButton
->setText(i18nc("@action:button", "Save"));
68 saveButton
->setToolTip(i18nc("@info", "Save search options"));
69 connect(saveButton
, SIGNAL(clicked()), this, SLOT(saveQuery()));
72 QPushButton
* closeButton
= new QPushButton(this);
73 closeButton
->setIcon(KIcon("dialog-close"));
74 closeButton
->setText(i18nc("@action:button", "Close"));
75 closeButton
->setToolTip(i18nc("@info", "Close search options"));
76 connect(closeButton
, SIGNAL(clicked()), this, SLOT(hide()));
78 // add "Add selector" button
79 m_addSelectorButton
= new QPushButton(this);
80 m_addSelectorButton
->setIcon(KIcon("list-add"));
81 m_addSelectorButton
->setToolTip(i18nc("@info", "Add search option"));
82 m_addSelectorButton
->setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
83 connect(m_addSelectorButton
, SIGNAL(clicked()), this, SLOT(addSelector()));
85 QHBoxLayout
* hBoxLayout
= new QHBoxLayout(this);
86 hBoxLayout
->addWidget(searchLabel
);
87 hBoxLayout
->addWidget(m_searchFromBox
);
88 hBoxLayout
->addWidget(whatLabel
);
89 hBoxLayout
->addWidget(m_searchWhatBox
);
90 hBoxLayout
->addWidget(filler
, 1);
91 hBoxLayout
->addWidget(saveButton
);
92 hBoxLayout
->addWidget(closeButton
);
93 hBoxLayout
->addWidget(m_addSelectorButton
);
95 // add default search criterions
96 SearchCriterionSelector
* dateCriterion
= new SearchCriterionSelector(SearchCriterionSelector::Date
, this);
97 connect(dateCriterion
, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
99 SearchCriterionSelector
* fileSizeCriterion
= new SearchCriterionSelector(SearchCriterionSelector::FileSize
, this);
100 connect(fileSizeCriterion
, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
102 m_vBoxLayout
->addWidget(new KSeparator(this));
103 m_vBoxLayout
->addLayout(hBoxLayout
);
104 m_vBoxLayout
->addWidget(dateCriterion
);
105 m_vBoxLayout
->addWidget(fileSizeCriterion
);
106 m_vBoxLayout
->addWidget(new KSeparator(this));
109 DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator()
113 void DolphinSearchOptionsConfigurator::addSelector()
115 SearchCriterionSelector
* selector
= new SearchCriterionSelector(SearchCriterionSelector::Undefined
, this);
116 connect(selector
, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
118 // insert the new selector before the KSeparator at the bottom
119 const int index
= m_vBoxLayout
->count() - 1;
120 m_vBoxLayout
->insertWidget(index
, selector
);
121 updateSelectorButton();
124 void DolphinSearchOptionsConfigurator::removeCriterion()
126 QWidget
* criterion
= qobject_cast
<QWidget
*>(sender());
127 Q_ASSERT(criterion
!= 0);
128 m_vBoxLayout
->removeWidget(criterion
);
129 criterion
->deleteLater();
131 updateSelectorButton();
134 void DolphinSearchOptionsConfigurator::updateSelectorButton()
136 const int selectors
= m_vBoxLayout
->count() - 1;
137 m_addSelectorButton
->setEnabled(selectors
< 10);
140 void DolphinSearchOptionsConfigurator::saveQuery()
142 KDialog
dialog(0, Qt::Dialog
);
144 QWidget
* container
= new QWidget(&dialog
);
146 QLabel
* label
= new QLabel(i18nc("@label", "Name:"), container
);
147 KLineEdit
* lineEdit
= new KLineEdit(container
);
148 lineEdit
->setMinimumWidth(250);
150 QHBoxLayout
* layout
= new QHBoxLayout(container
);
151 layout
->addWidget(label
, Qt::AlignRight
);
152 layout
->addWidget(lineEdit
);
154 dialog
.setMainWidget(container
);
155 dialog
.setCaption(i18nc("@title:window", "Save Search Options"));
156 dialog
.setButtons(KDialog::Ok
| KDialog::Cancel
);
157 dialog
.setDefaultButton(KDialog::Ok
);
158 dialog
.setButtonText(KDialog::Ok
, i18nc("@action:button", "Save"));
160 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
161 "SaveSearchOptionsDialog");
162 dialog
.restoreDialogSize(dialogConfig
);
163 dialog
.exec(); // TODO...
166 #include "dolphinsearchoptionsconfigurator.moc"