┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2009-11-13 23:21:47 +0000
committerPeter Penz <[email protected]>2009-11-13 23:21:47 +0000
commit041a2f059422d6e7b600510a086a3527f3b5dd1c (patch)
treeec2aad61a3483bb29287d14ce3f781060c39b25e /src
parent3d7b54b21a47e98d1d02c7d21061a6bd43b8d1c7 (diff)
* allow searching for ratings
* minor general cleanups svn path=/trunk/KDE/kdebase/apps/; revision=1048809
Diffstat (limited to 'src')
-rw-r--r--src/search/searchcriterionselector.cpp34
-rw-r--r--src/search/searchcriterionselector.h2
-rw-r--r--src/search/searchcriterionvalue.cpp31
-rw-r--r--src/search/searchcriterionvalue.h15
4 files changed, 68 insertions, 14 deletions
diff --git a/src/search/searchcriterionselector.cpp b/src/search/searchcriterionselector.cpp
index 104f83c1c..a0d7b73e7 100644
--- a/src/search/searchcriterionselector.cpp
+++ b/src/search/searchcriterionselector.cpp
@@ -91,7 +91,14 @@ QString SearchCriterionSelector::toString() const
QString criterion = comp.prefix + descr.identifier() + comp.operation;
if (!m_valueWidget->value().isEmpty()) {
- criterion += '"' + m_valueWidget->value() + '"';
+ const QString value = m_valueWidget->value();
+ if (value.contains(' ')) {
+ criterion += '"' + value + '"';
+ } else {
+ // Don't surround the value by " if no space is part of the value.
+ // This increases the readability of the search-URL.
+ criterion += value;
+ }
}
return criterion;
}
@@ -173,6 +180,8 @@ void SearchCriterionSelector::createDescriptions()
"lastModified",
dateComps,
dateValue);
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Date) == 0);
+ m_descriptions.append(date);
// add "Size" description
QList<SearchCriterionDescription::Comparator> sizeComps = defaultComps;
@@ -184,11 +193,14 @@ void SearchCriterionSelector::createDescriptions()
"contentSize",
sizeComps,
sizeValue);
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Size) == 1);
+ m_descriptions.append(size);
// add "Tag" description
QList<SearchCriterionDescription::Comparator> tagComps;
tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label All (tags)", "All")));
- tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Equal to"), ":"));
+ tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Equal to"), ":", "+"));
+ tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Not Equal to"), ":", "-"));
TagValue* tagValue = new TagValue(this);
tagValue->hide();
@@ -196,14 +208,22 @@ void SearchCriterionSelector::createDescriptions()
"tag",
tagComps,
tagValue);
-
- Q_ASSERT(static_cast<int>(SearchCriterionSelector::Date) == 0);
- Q_ASSERT(static_cast<int>(SearchCriterionSelector::Size) == 1);
Q_ASSERT(static_cast<int>(SearchCriterionSelector::Tag) == 2);
- m_descriptions.append(date);
- m_descriptions.append(size);
m_descriptions.append(tag);
+ // add "Rating" description
+ QList<SearchCriterionDescription::Comparator> ratingComps = defaultComps;
+ ratingComps.insert(0, SearchCriterionDescription::Comparator(i18nc("@label Any (rating)", "Any")));
+
+ RatingValue* ratingValue = new RatingValue(this);
+ ratingValue->hide();
+ SearchCriterionDescription rating(i18nc("@label", "Rating:"),
+ "rating",
+ ratingComps,
+ ratingValue);
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Rating) == 3);
+ m_descriptions.append(rating);
+
// add all descriptions to the combo box and connect the value widgets
int i = 0;
foreach (const SearchCriterionDescription& desc, m_descriptions) {
diff --git a/src/search/searchcriterionselector.h b/src/search/searchcriterionselector.h
index 27cbb2e46..b240d7648 100644
--- a/src/search/searchcriterionselector.h
+++ b/src/search/searchcriterionselector.h
@@ -45,7 +45,7 @@ class SearchCriterionSelector : public QWidget
Q_OBJECT
public:
- enum Type { Date, Size, Tag };
+ enum Type { Date, Size, Tag, Rating };
SearchCriterionSelector(Type type, QWidget* parent = 0);
virtual ~SearchCriterionSelector();
diff --git a/src/search/searchcriterionvalue.cpp b/src/search/searchcriterionvalue.cpp
index 7d8e2d8cd..9db19364b 100644
--- a/src/search/searchcriterionvalue.cpp
+++ b/src/search/searchcriterionvalue.cpp
@@ -24,6 +24,7 @@
#include <klineedit.h>
#include <klocale.h>
+#include <nepomuk/kratingwidget.h>
#include <nepomuk/tag.h>
#include <QComboBox>
@@ -71,12 +72,8 @@ QString DateValue::value() const
void DateValue::initializeValue(const QString& valueType)
{
- if (valueType.isEmpty()) {
- return;
- }
-
- QDate date;
- if (valueType == "today") {
+ QDate date;
+ if (valueType.isEmpty() || (valueType == "today")) {
date = QDate::currentDate();
} else if (valueType == "thisWeek") {
const QDate today = QDate::currentDate();
@@ -173,4 +170,26 @@ QString SizeValue::value() const
return QString();
}
+// -------------------------------------------------------------------------
+
+RatingValue::RatingValue(QWidget* parent) :
+ SearchCriterionValue(parent),
+ m_ratingWidget(0)
+{
+ m_ratingWidget = new KRatingWidget(this);
+
+ QHBoxLayout* layout = new QHBoxLayout(this);
+ layout->setMargin(0);
+ layout->addWidget(m_ratingWidget);
+}
+
+RatingValue::~RatingValue()
+{
+}
+
+QString RatingValue::value() const
+{
+ return QString::number(m_ratingWidget->rating());
+}
+
#include "searchcriterionvalue.moc"
diff --git a/src/search/searchcriterionvalue.h b/src/search/searchcriterionvalue.h
index 652b58a7c..cabe75cf2 100644
--- a/src/search/searchcriterionvalue.h
+++ b/src/search/searchcriterionvalue.h
@@ -25,6 +25,7 @@
class QComboBox;
class KDateWidget;
+class KRatingWidget;
class KLineEdit;
/**
@@ -111,4 +112,18 @@ public:
QComboBox* m_units;
};
+/** @brief Allows to input a rating value as search criterion. */
+class RatingValue : public SearchCriterionValue
+{
+ Q_OBJECT
+
+public:
+ RatingValue(QWidget* parent = 0);
+ virtual ~RatingValue();
+ virtual QString value() const;
+
+ private:
+ KRatingWidget* m_ratingWidget;
+};
+
#endif // SEARCHCRITERIONVALUE_H