]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchoptionsconfigurator.cpp
Added some default search criterions. A lot of fine tuning of the UI has to be made...
[dolphin.git] / src / search / dolphinsearchoptionsconfigurator.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "dolphinsearchoptionsconfigurator.h"
21
22 #include "searchcriterionselector.h"
23
24 #include <kcombobox.h>
25 #include <kdialog.h>
26 #include <kicon.h>
27 #include <klineedit.h>
28 #include <klocale.h>
29 #include <kseparator.h>
30
31 #include <QButtonGroup>
32 #include <QHBoxLayout>
33 #include <QLabel>
34 #include <QPushButton>
35 #include <QVBoxLayout>
36
37 DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) :
38 QWidget(parent),
39 m_searchFromBox(0),
40 m_searchWhatBox(0),
41 m_addSelectorButton(0),
42 m_vBoxLayout(0)
43 {
44 m_vBoxLayout = new QVBoxLayout(this);
45
46 // add "search" configuration
47 QLabel* searchLabel = new QLabel(i18nc("@label", "Search:"));
48
49 m_searchFromBox = new KComboBox(this);
50 m_searchFromBox->addItem(i18nc("@label", "Everywhere"));
51 m_searchFromBox->addItem(i18nc("@label", "From Here"));
52
53 // add "what" configuration
54 QLabel* whatLabel = new QLabel(i18nc("@label", "What:"));
55
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"));
61
62 QWidget* filler = new QWidget(this);
63
64 // add button "Save"
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()));
70
71 // add button "Close"
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()));
77
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()));
84
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);
94
95 // add default search criterions
96 SearchCriterionSelector* dateCriterion = new SearchCriterionSelector(SearchCriterionSelector::Date, this);
97 connect(dateCriterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
98
99 SearchCriterionSelector* fileSizeCriterion = new SearchCriterionSelector(SearchCriterionSelector::FileSize, this);
100 connect(fileSizeCriterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
101
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));
107 }
108
109 DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator()
110 {
111 }
112
113 void DolphinSearchOptionsConfigurator::addSelector()
114 {
115 SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Undefined, this);
116 connect(selector, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
117
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();
122 }
123
124 void DolphinSearchOptionsConfigurator::removeCriterion()
125 {
126 QWidget* criterion = qobject_cast<QWidget*>(sender());
127 Q_ASSERT(criterion != 0);
128 m_vBoxLayout->removeWidget(criterion);
129 criterion->deleteLater();
130
131 updateSelectorButton();
132 }
133
134 void DolphinSearchOptionsConfigurator::updateSelectorButton()
135 {
136 const int selectors = m_vBoxLayout->count() - 1;
137 m_addSelectorButton->setEnabled(selectors < 10);
138 }
139
140 void DolphinSearchOptionsConfigurator::saveQuery()
141 {
142 KDialog dialog(0, Qt::Dialog);
143
144 QWidget* container = new QWidget(&dialog);
145
146 QLabel* label = new QLabel(i18nc("@label", "Name:"), container);
147 KLineEdit* lineEdit = new KLineEdit(container);
148 lineEdit->setMinimumWidth(250);
149
150 QHBoxLayout* layout = new QHBoxLayout(container);
151 layout->addWidget(label, Qt::AlignRight);
152 layout->addWidget(lineEdit);
153
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"));
159
160 KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"),
161 "SaveSearchOptionsDialog");
162 dialog.restoreDialogSize(dialogConfig);
163 dialog.exec(); // TODO...
164 }
165
166 #include "dolphinsearchoptionsconfigurator.moc"