]>
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>
36 #include <QVBoxLayout>
38 DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget
* parent
) :
43 m_addSelectorButton(0),
46 m_vBoxLayout
= new QVBoxLayout(this);
48 // add "search" configuration
49 QLabel
* searchLabel
= new QLabel(i18nc("@label", "Search:"));
51 m_searchFromBox
= new KComboBox(this);
52 m_searchFromBox
->addItem(i18nc("@label", "Everywhere"));
53 m_searchFromBox
->addItem(i18nc("@label", "From Here"));
55 // add "what" configuration
56 QLabel
* whatLabel
= new QLabel(i18nc("@label", "What:"));
58 m_searchWhatBox
= new KComboBox(this);
59 m_searchWhatBox
->addItem(i18nc("@label", "All"));
60 m_searchWhatBox
->addItem(i18nc("@label", "Images"));
61 m_searchWhatBox
->addItem(i18nc("@label", "Text"));
62 m_searchWhatBox
->addItem(i18nc("@label", "Filenames"));
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(slotAddSelectorButtonClicked()));
85 QHBoxLayout
* firstLineLayout
= new QHBoxLayout();
86 firstLineLayout
->addWidget(searchLabel
);
87 firstLineLayout
->addWidget(m_searchFromBox
);
88 firstLineLayout
->addWidget(whatLabel
);
89 firstLineLayout
->addWidget(m_searchWhatBox
);
90 firstLineLayout
->addWidget(new QWidget(this), 1); // filler
91 firstLineLayout
->addWidget(m_addSelectorButton
);
93 QHBoxLayout
* lastLineLayout
= new QHBoxLayout();
94 lastLineLayout
->addWidget(new QWidget(this), 1); // filler
95 lastLineLayout
->addWidget(saveButton
);
96 lastLineLayout
->addWidget(closeButton
);
98 m_vBoxLayout
->addWidget(new KSeparator(this));
99 m_vBoxLayout
->addLayout(firstLineLayout
);
100 m_vBoxLayout
->addLayout(lastLineLayout
);
101 m_vBoxLayout
->addWidget(new KSeparator(this));
104 DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator()
108 void DolphinSearchOptionsConfigurator::showEvent(QShowEvent
* event
)
110 if (!event
->spontaneous() && !m_initialized
) {
111 // add default search criterions
112 SearchCriterionSelector
* dateCriterion
= new SearchCriterionSelector(SearchCriterionSelector::Date
, this);
113 SearchCriterionSelector
* sizeCriterion
= new SearchCriterionSelector(SearchCriterionSelector::Size
, this);
114 SearchCriterionSelector
* tagCriterion
= new SearchCriterionSelector(SearchCriterionSelector::Tag
, this);
116 // Add the items in the same order as available in the description combo (verified by Q_ASSERTs). This
117 // is not mandatory from an implementation point of view, but preferable from a usability point of view.
118 Q_ASSERT(static_cast<int>(SearchCriterionSelector::Date
) == 0);
119 Q_ASSERT(static_cast<int>(SearchCriterionSelector::Size
) == 1);
120 Q_ASSERT(static_cast<int>(SearchCriterionSelector::Tag
) == 2);
121 addSelector(dateCriterion
);
122 addSelector(sizeCriterion
);
123 addSelector(tagCriterion
);
125 m_initialized
= true;
127 QWidget::showEvent(event
);
130 void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked()
132 SearchCriterionSelector
* selector
= new SearchCriterionSelector(SearchCriterionSelector::Tag
, this);
133 addSelector(selector
);
136 void DolphinSearchOptionsConfigurator::removeCriterion()
138 QWidget
* criterion
= qobject_cast
<QWidget
*>(sender());
139 Q_ASSERT(criterion
!= 0);
140 m_vBoxLayout
->removeWidget(criterion
);
141 criterion
->deleteLater();
143 updateSelectorButton();
146 void DolphinSearchOptionsConfigurator::updateSelectorButton()
148 const int selectors
= m_vBoxLayout
->count() - 1;
149 m_addSelectorButton
->setEnabled(selectors
< 10);
152 void DolphinSearchOptionsConfigurator::saveQuery()
154 KDialog
dialog(0, Qt::Dialog
);
156 QWidget
* container
= new QWidget(&dialog
);
158 QLabel
* label
= new QLabel(i18nc("@label", "Name:"), container
);
159 KLineEdit
* lineEdit
= new KLineEdit(container
);
160 lineEdit
->setMinimumWidth(250);
162 QHBoxLayout
* layout
= new QHBoxLayout(container
);
163 layout
->addWidget(label
, Qt::AlignRight
);
164 layout
->addWidget(lineEdit
);
166 dialog
.setMainWidget(container
);
167 dialog
.setCaption(i18nc("@title:window", "Save Search Options"));
168 dialog
.setButtons(KDialog::Ok
| KDialog::Cancel
);
169 dialog
.setDefaultButton(KDialog::Ok
);
170 dialog
.setButtonText(KDialog::Ok
, i18nc("@action:button", "Save"));
172 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
173 "SaveSearchOptionsDialog");
174 dialog
.restoreDialogSize(dialogConfig
);
175 dialog
.exec(); // TODO...
178 void DolphinSearchOptionsConfigurator::addSelector(SearchCriterionSelector
* selector
)
180 connect(selector
, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
182 // insert the new selector before the lastLineLayout and the KSeparator at the bottom
183 const int index
= m_vBoxLayout
->count() - 2;
184 m_vBoxLayout
->insertWidget(index
, selector
);
185 updateSelectorButton();
188 #include "dolphinsearchoptionsconfigurator.moc"