]>
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 const QDateTime
dateTime(m_dateWidget
->date());
71 return Nepomuk::Query::LiteralTerm(dateTime
);
74 void DateValue::initializeValue(const QString
& valueType
)
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);
92 m_dateWidget
->setDate(date
);
95 // -------------------------------------------------------------------------
97 TagValue::TagValue(QWidget
* parent
) :
98 SearchCriterionValue(parent
),
101 m_tags
= new QComboBox(this);
102 m_tags
->setInsertPolicy(QComboBox::InsertAlphabetically
);
104 QHBoxLayout
* layout
= new QHBoxLayout(this);
105 layout
->setMargin(0);
106 layout
->addWidget(m_tags
);
108 connect(m_tags
, SIGNAL(activated(QString
)),
109 this, SIGNAL(valueChanged(QString
)));
112 TagValue::~TagValue()
116 Nepomuk::Query::LiteralTerm
TagValue::value() const
118 return Nepomuk::Query::LiteralTerm(m_tags
->currentText());
121 void TagValue::showEvent(QShowEvent
* event
)
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());
129 if (tags
.count() == 0) {
130 m_tags
->addItem(i18nc("@label", "No Tags Available"));
133 SearchCriterionValue::showEvent(event
);
136 // -------------------------------------------------------------------------
138 SizeValue::SizeValue(QWidget
* parent
) :
139 SearchCriterionValue(parent
),
143 m_lineEdit
= new KLineEdit(this);
144 m_lineEdit
->setClearButtonShown(true);
145 m_lineEdit
->setValidator(new QIntValidator(this));
146 m_lineEdit
->setAlignment(Qt::AlignRight
);
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"));
155 // set 1 MByte as default
156 m_lineEdit
->setText("1");
157 m_units
->setCurrentIndex(2);
159 QHBoxLayout
* layout
= new QHBoxLayout(this);
160 layout
->setMargin(0);
161 layout
->addWidget(m_lineEdit
);
162 layout
->addWidget(m_units
);
165 SizeValue::~SizeValue()
169 Nepomuk::Query::LiteralTerm
SizeValue::value() const
171 return Nepomuk::Query::LiteralTerm(); // TODO
174 // -------------------------------------------------------------------------
176 RatingValue::RatingValue(QWidget
* parent
) :
177 SearchCriterionValue(parent
),
180 m_ratingWidget
= new KRatingWidget(this);
182 QHBoxLayout
* layout
= new QHBoxLayout(this);
183 layout
->setMargin(0);
184 layout
->addWidget(m_ratingWidget
);
187 RatingValue::~RatingValue()
191 Nepomuk::Query::LiteralTerm
RatingValue::value() const
193 return Nepomuk::Query::LiteralTerm(m_ratingWidget
->rating());
196 #include "searchcriterionvalue.moc"