]>
cloud.milkyroute.net Git - dolphin.git/blob - 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> *
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. *
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. *
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 ***************************************************************************/
21 #include "searchcriterionvalue.h"
23 #include <kdatewidget.h>
24 #include <klineedit.h>
27 #include <nepomuk/kratingwidget.h>
28 #include <nepomuk/tag.h>
32 #include <QIntValidator>
34 #include <QHBoxLayout>
37 SearchCriterionValue::SearchCriterionValue(QWidget
* parent
) :
42 SearchCriterionValue::~SearchCriterionValue()
46 void SearchCriterionValue::initializeValue(const QString
& valueType
)
51 // -------------------------------------------------------------------------
53 DateValue::DateValue(QWidget
* parent
) :
54 SearchCriterionValue(parent
),
57 m_dateWidget
= new KDateWidget(QDate::currentDate(), this);
59 QHBoxLayout
* layout
= new QHBoxLayout(this);
61 layout
->addWidget(m_dateWidget
);
64 DateValue::~DateValue()
68 Nepomuk::Query::LiteralTerm
DateValue::value() const
70 return Nepomuk::Query::LiteralTerm(m_dateWidget
->date());
73 void DateValue::initializeValue(const QString
& valueType
)
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);
91 m_dateWidget
->setDate(date
);
94 // -------------------------------------------------------------------------
96 TagValue::TagValue(QWidget
* parent
) :
97 SearchCriterionValue(parent
),
100 m_tags
= new QComboBox(this);
101 m_tags
->setInsertPolicy(QComboBox::InsertAlphabetically
);
103 QHBoxLayout
* layout
= new QHBoxLayout(this);
104 layout
->setMargin(0);
105 layout
->addWidget(m_tags
);
107 connect(m_tags
, SIGNAL(activated(QString
)),
108 this, SIGNAL(valueChanged(QString
)));
111 TagValue::~TagValue()
115 Nepomuk::Query::LiteralTerm
TagValue::value() const
117 return Nepomuk::Query::LiteralTerm(m_tags
->currentText());
120 void TagValue::showEvent(QShowEvent
* event
)
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());
128 if (tags
.count() == 0) {
129 m_tags
->addItem(i18nc("@label", "No Tags Available"));
132 SearchCriterionValue::showEvent(event
);
135 // -------------------------------------------------------------------------
137 SizeValue::SizeValue(QWidget
* parent
) :
138 SearchCriterionValue(parent
),
142 m_lineEdit
= new KLineEdit(this);
143 m_lineEdit
->setClearButtonShown(true);
144 m_lineEdit
->setValidator(new QIntValidator(this));
145 m_lineEdit
->setAlignment(Qt::AlignRight
);
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"));
154 // set 1 MByte as default
155 m_lineEdit
->setText("1");
156 m_units
->setCurrentIndex(2);
158 QHBoxLayout
* layout
= new QHBoxLayout(this);
159 layout
->setMargin(0);
160 layout
->addWidget(m_lineEdit
);
161 layout
->addWidget(m_units
);
164 SizeValue::~SizeValue()
168 Nepomuk::Query::LiteralTerm
SizeValue::value() const
170 return Nepomuk::Query::LiteralTerm(); // TODO
173 // -------------------------------------------------------------------------
175 RatingValue::RatingValue(QWidget
* parent
) :
176 SearchCriterionValue(parent
),
179 m_ratingWidget
= new KRatingWidget(this);
181 QHBoxLayout
* layout
= new QHBoxLayout(this);
182 layout
->setMargin(0);
183 layout
->addWidget(m_ratingWidget
);
186 RatingValue::~RatingValue()
190 Nepomuk::Query::LiteralTerm
RatingValue::value() const
192 return Nepomuk::Query::LiteralTerm(m_ratingWidget
->rating());
195 #include "searchcriterionvalue.moc"