]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/searchcriterionvalue.cpp
SVN_SILENT made messages (.desktop file)
[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 return Nepomuk::Query::LiteralTerm(m_dateWidget->date());
71 }
72
73 void DateValue::initializeValue(const QString& valueType)
74 {
75 QDate date;
76 if (valueType.isEmpty() || (valueType == "today")) {
77 date = QDate::currentDate();
78 } else if (valueType == "thisWeek") {
79 const QDate today = QDate::currentDate();
80 const int dayOfWeek = today.dayOfWeek();
81 date = today.addDays(-dayOfWeek);
82 } else if (valueType == "thisMonth") {
83 const QDate today = QDate::currentDate();
84 date = QDate(today.year(), today.month(), 1);
85 } else if (valueType == "thisYear") {
86 date = QDate(QDate::currentDate().year(), 1, 1);
87 } else {
88 // unknown value-type
89 Q_ASSERT(false);
90 }
91 m_dateWidget->setDate(date);
92 }
93
94 // -------------------------------------------------------------------------
95
96 TagValue::TagValue(QWidget* parent) :
97 SearchCriterionValue(parent),
98 m_tags(0)
99 {
100 m_tags = new QComboBox(this);
101 m_tags->setInsertPolicy(QComboBox::InsertAlphabetically);
102
103 QHBoxLayout* layout = new QHBoxLayout(this);
104 layout->setMargin(0);
105 layout->addWidget(m_tags);
106
107 connect(m_tags, SIGNAL(activated(QString)),
108 this, SIGNAL(valueChanged(QString)));
109 }
110
111 TagValue::~TagValue()
112 {
113 }
114
115 Nepomuk::Query::LiteralTerm TagValue::value() const
116 {
117 return Nepomuk::Query::LiteralTerm(m_tags->currentText());
118 }
119
120 void TagValue::showEvent(QShowEvent* event)
121 {
122 if (!event->spontaneous() && (m_tags->count() == 0)) {
123 const QList<Nepomuk::Tag> tags = Nepomuk::Tag::allTags();
124 foreach (const Nepomuk::Tag& tag, tags) {
125 m_tags->addItem(tag.label());
126 }
127
128 if (tags.count() == 0) {
129 m_tags->addItem(i18nc("@label", "No Tags Available"));
130 }
131 }
132 SearchCriterionValue::showEvent(event);
133 }
134
135 // -------------------------------------------------------------------------
136
137 SizeValue::SizeValue(QWidget* parent) :
138 SearchCriterionValue(parent),
139 m_lineEdit(0),
140 m_units(0)
141 {
142 m_lineEdit = new KLineEdit(this);
143 m_lineEdit->setClearButtonShown(true);
144 m_lineEdit->setValidator(new QIntValidator(this));
145 m_lineEdit->setAlignment(Qt::AlignRight);
146
147 m_units = new QComboBox(this);
148 // TODO: check the KByte vs. KiByte dilemma :-/
149 m_units->addItem(i18nc("@label", "Byte"));
150 m_units->addItem(i18nc("@label", "KByte"));
151 m_units->addItem(i18nc("@label", "MByte"));
152 m_units->addItem(i18nc("@label", "GByte"));
153
154 // set 1 MByte as default
155 m_lineEdit->setText("1");
156 m_units->setCurrentIndex(2);
157
158 QHBoxLayout* layout = new QHBoxLayout(this);
159 layout->setMargin(0);
160 layout->addWidget(m_lineEdit);
161 layout->addWidget(m_units);
162 }
163
164 SizeValue::~SizeValue()
165 {
166 }
167
168 Nepomuk::Query::LiteralTerm SizeValue::value() const
169 {
170 return Nepomuk::Query::LiteralTerm(); // TODO
171 }
172
173 // -------------------------------------------------------------------------
174
175 RatingValue::RatingValue(QWidget* parent) :
176 SearchCriterionValue(parent),
177 m_ratingWidget(0)
178 {
179 m_ratingWidget = new KRatingWidget(this);
180
181 QHBoxLayout* layout = new QHBoxLayout(this);
182 layout->setMargin(0);
183 layout->addWidget(m_ratingWidget);
184 }
185
186 RatingValue::~RatingValue()
187 {
188 }
189
190 Nepomuk::Query::LiteralTerm RatingValue::value() const
191 {
192 return Nepomuk::Query::LiteralTerm(m_ratingWidget->rating());
193 }
194
195 #include "searchcriterionvalue.moc"