]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/searchcriterionvalue.cpp
initial code to provide a Nepomuk query string out of the search criterions
[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/tag.h>
28
29 #include <QComboBox>
30 #include <QDate>
31 #include <QIntValidator>
32 #include <QLabel>
33 #include <QHBoxLayout>
34 #include <QShowEvent>
35
36 SearchCriterionValue::SearchCriterionValue(QWidget* parent) :
37 QWidget(parent)
38 {
39 }
40
41 SearchCriterionValue::~SearchCriterionValue()
42 {
43 }
44
45 // -------------------------------------------------------------------------
46
47 DateValue::DateValue(QWidget* parent) :
48 SearchCriterionValue(parent),
49 m_dateWidget(0)
50 {
51 m_dateWidget = new KDateWidget(QDate::currentDate(), this);
52
53 QHBoxLayout* layout = new QHBoxLayout(this);
54 layout->setMargin(0);
55 layout->addWidget(m_dateWidget);
56 }
57
58 DateValue::~DateValue()
59 {
60 }
61
62 QString DateValue::value() const
63 {
64 return m_dateWidget->date().toString(Qt::ISODate);
65 }
66
67 // -------------------------------------------------------------------------
68
69 TagValue::TagValue(QWidget* parent) :
70 SearchCriterionValue(parent),
71 m_tags(0)
72 {
73 m_tags = new QComboBox(this);
74 m_tags->setInsertPolicy(QComboBox::InsertAlphabetically);
75
76 QHBoxLayout* layout = new QHBoxLayout(this);
77 layout->setMargin(0);
78 layout->addWidget(m_tags);
79
80 connect(m_tags, SIGNAL(activated(QString)),
81 this, SIGNAL(valueChanged(QString)));
82 }
83
84 TagValue::~TagValue()
85 {
86 }
87
88 QString TagValue::value() const
89 {
90 return m_tags->currentText();
91 }
92
93 void TagValue::showEvent(QShowEvent* event)
94 {
95 if (!event->spontaneous() && (m_tags->count() == 0)) {
96 const QList<Nepomuk::Tag> tags = Nepomuk::Tag::allTags();
97 foreach (const Nepomuk::Tag& tag, tags) {
98 m_tags->addItem(tag.label());
99 }
100
101 if (tags.count() == 0) {
102 m_tags->addItem(i18nc("@label", "No Tags Available"));
103 }
104 }
105 SearchCriterionValue::showEvent(event);
106 }
107
108 // -------------------------------------------------------------------------
109
110 SizeValue::SizeValue(QWidget* parent) :
111 SearchCriterionValue(parent),
112 m_lineEdit(0),
113 m_units(0)
114 {
115 m_lineEdit = new KLineEdit(this);
116 m_lineEdit->setClearButtonShown(true);
117 m_lineEdit->setValidator(new QIntValidator(this));
118 m_lineEdit->setAlignment(Qt::AlignRight);
119
120 m_units = new QComboBox(this);
121 // TODO: check the KByte vs. KiByte dilemma :-/
122 m_units->addItem(i18nc("@label", "Byte"));
123 m_units->addItem(i18nc("@label", "KByte"));
124 m_units->addItem(i18nc("@label", "MByte"));
125 m_units->addItem(i18nc("@label", "GByte"));
126
127 // set 1 MByte as default
128 m_lineEdit->setText("1");
129 m_units->setCurrentIndex(2);
130
131 QHBoxLayout* layout = new QHBoxLayout(this);
132 layout->setMargin(0);
133 layout->addWidget(m_lineEdit);
134 layout->addWidget(m_units);
135 }
136
137 SizeValue::~SizeValue()
138 {
139 }
140
141 QString SizeValue::value() const
142 {
143 return QString();
144 }
145
146 #include "searchcriterionvalue.moc"