]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/searchcriterionvalue.cpp
Implemented search restriction to filenames.
[dolphin.git] / src / search / searchcriterionvalue.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Adam Kidder <thekidder@gmail.com> *
3 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "searchcriterionvalue.h"
22
23 #include <kdatewidget.h>
24 #include <klineedit.h>
25 #include <klocale.h>
26
27 #include <nepomuk/kratingwidget.h>
28 #include <nepomuk/tag.h>
29
30 #include <QComboBox>
31 #include <QDate>
32 #include <QIntValidator>
33 #include <QLabel>
34 #include <QHBoxLayout>
35 #include <QShowEvent>
36
37 SearchCriterionValue::SearchCriterionValue(QWidget* parent) :
38 QWidget(parent)
39 {
40 }
41
42 SearchCriterionValue::~SearchCriterionValue()
43 {
44 }
45
46 void SearchCriterionValue::initializeValue(const QString& valueType)
47 {
48 Q_UNUSED(valueType);
49 }
50
51 // -------------------------------------------------------------------------
52
53 DateValue::DateValue(QWidget* parent) :
54 SearchCriterionValue(parent),
55 m_dateWidget(0)
56 {
57 m_dateWidget = new KDateWidget(QDate::currentDate(), this);
58
59 QHBoxLayout* layout = new QHBoxLayout(this);
60 layout->setMargin(0);
61 layout->addWidget(m_dateWidget);
62 }
63
64 DateValue::~DateValue()
65 {
66 }
67
68 Nepomuk::Query::LiteralTerm DateValue::value() const
69 {
70 const QDateTime dateTime(m_dateWidget->date());
71 return Nepomuk::Query::LiteralTerm(dateTime);
72 }
73
74 void DateValue::initializeValue(const QString& valueType)
75 {
76 QDate date;
77 if (valueType.isEmpty() || (valueType == "today")) {
78 date = QDate::currentDate();
79 } else if (valueType == "thisWeek") {
80 const QDate today = QDate::currentDate();
81 const int dayOfWeek = today.dayOfWeek();
82 date = today.addDays(-dayOfWeek);
83 } else if (valueType == "thisMonth") {
84 const QDate today = QDate::currentDate();
85 date = QDate(today.year(), today.month(), 1);
86 } else if (valueType == "thisYear") {
87 date = QDate(QDate::currentDate().year(), 1, 1);
88 } else {
89 // unknown value-type
90 Q_ASSERT(false);
91 }
92 m_dateWidget->setDate(date);
93 }
94
95 // -------------------------------------------------------------------------
96
97 TagValue::TagValue(QWidget* parent) :
98 SearchCriterionValue(parent),
99 m_tags(0)
100 {
101 m_tags = new QComboBox(this);
102 m_tags->setInsertPolicy(QComboBox::InsertAlphabetically);
103
104 QHBoxLayout* layout = new QHBoxLayout(this);
105 layout->setMargin(0);
106 layout->addWidget(m_tags);
107
108 connect(m_tags, SIGNAL(activated(QString)),
109 this, SIGNAL(valueChanged(QString)));
110 }
111
112 TagValue::~TagValue()
113 {
114 }
115
116 Nepomuk::Query::LiteralTerm TagValue::value() const
117 {
118 return Nepomuk::Query::LiteralTerm(m_tags->currentText());
119 }
120
121 void TagValue::showEvent(QShowEvent* event)
122 {
123 if (!event->spontaneous() && (m_tags->count() == 0)) {
124 const QList<Nepomuk::Tag> tags = Nepomuk::Tag::allTags();
125 foreach (const Nepomuk::Tag& tag, tags) {
126 m_tags->addItem(tag.label());
127 }
128
129 if (tags.count() == 0) {
130 m_tags->addItem(i18nc("@label", "No Tags Available"));
131 }
132 }
133 SearchCriterionValue::showEvent(event);
134 }
135
136 // -------------------------------------------------------------------------
137
138 SizeValue::SizeValue(QWidget* parent) :
139 SearchCriterionValue(parent),
140 m_lineEdit(0),
141 m_units(0)
142 {
143 m_lineEdit = new KLineEdit(this);
144 m_lineEdit->setClearButtonShown(true);
145 m_lineEdit->setValidator(new QIntValidator(this));
146 m_lineEdit->setAlignment(Qt::AlignRight);
147
148 m_units = new QComboBox(this);
149 // TODO: check the KByte vs. KiByte dilemma :-/
150 m_units->addItem(i18nc("@label", "Byte"));
151 m_units->addItem(i18nc("@label", "KByte"));
152 m_units->addItem(i18nc("@label", "MByte"));
153 m_units->addItem(i18nc("@label", "GByte"));
154
155 // set 1 MByte as default
156 m_lineEdit->setText("1");
157 m_units->setCurrentIndex(2);
158
159 QHBoxLayout* layout = new QHBoxLayout(this);
160 layout->setMargin(0);
161 layout->addWidget(m_lineEdit);
162 layout->addWidget(m_units);
163 }
164
165 SizeValue::~SizeValue()
166 {
167 }
168
169 Nepomuk::Query::LiteralTerm SizeValue::value() const
170 {
171 return Nepomuk::Query::LiteralTerm(); // TODO
172 }
173
174 // -------------------------------------------------------------------------
175
176 RatingValue::RatingValue(QWidget* parent) :
177 SearchCriterionValue(parent),
178 m_ratingWidget(0)
179 {
180 m_ratingWidget = new KRatingWidget(this);
181
182 QHBoxLayout* layout = new QHBoxLayout(this);
183 layout->setMargin(0);
184 layout->addWidget(m_ratingWidget);
185 }
186
187 RatingValue::~RatingValue()
188 {
189 }
190
191 Nepomuk::Query::LiteralTerm RatingValue::value() const
192 {
193 return Nepomuk::Query::LiteralTerm(m_ratingWidget->rating());
194 }
195
196 #include "searchcriterionvalue.moc"