┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/search/filters
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2010-07-24 16:37:07 +0000
committerPeter Penz <[email protected]>2010-07-24 16:37:07 +0000
commit49eb864b03b6370e403c6f048ab18d1478eab045 (patch)
treef056b119de4d358e056287b90ec2e05f53fe2004 /src/search/filters
parent4ba9eb8ea34baee7e5e100a0d3c33f23f75cf708 (diff)
Unify the search interface for non-indexed and indexed folders
svn path=/trunk/KDE/kdebase/apps/; revision=1154073
Diffstat (limited to 'src/search/filters')
-rw-r--r--src/search/filters/abstractsearchfilterwidget.cpp66
-rw-r--r--src/search/filters/abstractsearchfilterwidget.h67
-rw-r--r--src/search/filters/datesearchfilterwidget.cpp113
-rw-r--r--src/search/filters/datesearchfilterwidget.h53
-rw-r--r--src/search/filters/ratingsearchfilterwidget.cpp108
-rw-r--r--src/search/filters/ratingsearchfilterwidget.h44
-rw-r--r--src/search/filters/tagsearchfilterwidget.cpp89
-rw-r--r--src/search/filters/tagsearchfilterwidget.h44
8 files changed, 584 insertions, 0 deletions
diff --git a/src/search/filters/abstractsearchfilterwidget.cpp b/src/search/filters/abstractsearchfilterwidget.cpp
new file mode 100644
index 000000000..5b44f94b4
--- /dev/null
+++ b/src/search/filters/abstractsearchfilterwidget.cpp
@@ -0,0 +1,66 @@
+/***************************************************************************
+* Copyright (C) 2010 by Peter Penz <[email protected]> *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+* **************************************************************************/
+
+#include "abstractsearchfilterwidget.h"
+
+#include <QPushButton>
+
+class SearchFilterButton : public QPushButton
+{
+public:
+ SearchFilterButton(QWidget* parent = 0);
+ virtual QSize sizeHint() const;
+};
+
+SearchFilterButton::SearchFilterButton(QWidget* parent) :
+ QPushButton(parent)
+{
+ setCheckable(true);
+}
+
+QSize SearchFilterButton::sizeHint() const
+{
+ // Provide a larger preferred width, as this leads to a less
+ // cluttered layout for all search filters
+ const QSize defaultSize = QPushButton::sizeHint();
+ QFontMetrics fontMetrics(font());
+ const int minWidth = fontMetrics.height() * 8;
+ const int width = qMax(minWidth, defaultSize.width());
+ return QSize(width, defaultSize.height());
+}
+
+
+
+AbstractSearchFilterWidget::AbstractSearchFilterWidget(QWidget* parent) :
+ QWidget(parent)
+{
+}
+
+AbstractSearchFilterWidget::~AbstractSearchFilterWidget()
+{
+}
+
+QPushButton* AbstractSearchFilterWidget::createButton()
+{
+ SearchFilterButton* button = new SearchFilterButton(this);
+ connect(button, SIGNAL(toggled(bool)), this, SIGNAL(filterChanged()));
+ return button;
+}
+
+#include "abstractsearchfilterwidget.moc"
diff --git a/src/search/filters/abstractsearchfilterwidget.h b/src/search/filters/abstractsearchfilterwidget.h
new file mode 100644
index 000000000..95f288b08
--- /dev/null
+++ b/src/search/filters/abstractsearchfilterwidget.h
@@ -0,0 +1,67 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Peter Penz <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef ABSTRACTSEARCHFILTERWIDGET_H
+#define ABSTRACTSEARCHFILTERWIDGET_H
+
+#include <nepomuk/term.h>
+#include <QWidget>
+
+class QPushButton;
+
+/**
+ * @brief Base class for widgets that act as filter for searching.
+ *
+ * Derived classes need to implement the methods filterLabel() and
+ * queryTerm(). It is recommended to use createButton() for a filter-switch.
+ * The created button will automatically emit the signal filterChanged().
+ */
+class AbstractSearchFilterWidget : public QWidget {
+ Q_OBJECT
+
+public:
+ AbstractSearchFilterWidget(QWidget* parent = 0);
+ virtual ~AbstractSearchFilterWidget();
+
+ /**
+ * @return Label that describes the kind of filter.
+ */
+ virtual QString filterLabel() const = 0;
+
+ /**
+ * @return Query-term for this filter, that respects the currently
+ * selected filter-switches.
+ */
+ virtual Nepomuk::Query::Term queryTerm() const = 0;
+
+protected:
+ /**
+ * @return A checkable button, that automatically emits the signal
+ * filterChanged() when being pressed.
+ */
+ QPushButton* createButton();
+
+signals:
+ /**
+ * Is emitted, if a filter-switch has been changed by the user.
+ */
+ void filterChanged();
+};
+
+#endif
diff --git a/src/search/filters/datesearchfilterwidget.cpp b/src/search/filters/datesearchfilterwidget.cpp
new file mode 100644
index 000000000..0be95d09e
--- /dev/null
+++ b/src/search/filters/datesearchfilterwidget.cpp
@@ -0,0 +1,113 @@
+/***************************************************************************
+* Copyright (C) 2010 by Peter Penz <[email protected]> *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+* **************************************************************************/
+
+#include "datesearchfilterwidget.h"
+
+#define DISABLE_NEPOMUK_LEGACY
+
+#include <klocale.h>
+#include <nepomuk/comparisonterm.h>
+#include <nepomuk/literalterm.h>
+#include <nepomuk/orterm.h>
+#include <nepomuk/property.h>
+#include <nepomuk/query.h>
+#include "nie.h"
+#include <QDate>
+#include <QDateTime>
+#include <QLabel>
+#include <QPushButton>
+#include <QHBoxLayout>
+
+DateSearchFilterWidget::DateSearchFilterWidget(QWidget* parent) :
+ AbstractSearchFilterWidget(parent),
+ m_dateButtons()
+{
+ QHBoxLayout* layout = new QHBoxLayout(this);
+ layout->setSpacing(0);
+
+ for (int i = Today; i <= ThisYear; ++i) {
+ QPushButton* button = createButton();
+ switch (i) {
+ case Today: button->setText(i18nc("@action:button", "Today")); break;
+ case Yesterday: button->setText(i18nc("@action:button", "Yesterday")); break;
+ case ThisWeek: button->setText(i18nc("@action:button", "This Week")); break;
+ case ThisMonth: button->setText(i18nc("@action:button", "This Month")); break;
+ case ThisYear: button->setText(i18nc("@action:button", "This Year")); break;
+ default: Q_ASSERT(false);
+ }
+
+ layout->addWidget(button);
+ m_dateButtons.append(button);
+ }
+ layout->addStretch(1);
+}
+
+DateSearchFilterWidget::~DateSearchFilterWidget()
+{
+}
+
+
+QString DateSearchFilterWidget::filterLabel() const
+{
+ return i18nc("@title:group", "Date");
+}
+
+Nepomuk::Query::Term DateSearchFilterWidget::queryTerm() const
+{
+ Nepomuk::Query::OrTerm orTerm;
+
+ int index = 0;
+ foreach (const QPushButton* button, m_dateButtons) {
+ if (button->isChecked()) {
+ QDate today = QDate::currentDate();
+ QDate date;
+ switch (index) {
+ case Today:
+ // Current date is already set
+ break;
+ case Yesterday:
+ date.addDays(-1);
+ break;
+ case ThisWeek:
+ date.addDays(-today.dayOfWeek());
+ break;
+ case ThisMonth:
+ date = QDate(today.year(), today.month(), 1);
+ break;
+ case ThisYear:
+ date = QDate(today.year(), 1, 1);
+ break;
+ default:
+ Q_ASSERT(false);
+ }
+
+ const QDateTime dateTime(date);
+ const Nepomuk::Query::LiteralTerm term(dateTime);
+ const Nepomuk::Query::ComparisonTerm compTerm(Nepomuk::Vocabulary::NIE::lastModified(),
+ term,
+ Nepomuk::Query::ComparisonTerm::GreaterOrEqual);
+ orTerm.addSubTerm(compTerm);
+ }
+ ++index;
+ }
+
+ return orTerm;
+}
+
+#include "datesearchfilterwidget.moc"
diff --git a/src/search/filters/datesearchfilterwidget.h b/src/search/filters/datesearchfilterwidget.h
new file mode 100644
index 000000000..9099489ad
--- /dev/null
+++ b/src/search/filters/datesearchfilterwidget.h
@@ -0,0 +1,53 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Peter Penz <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef DATESEARCHFILTERWIDGET_H
+#define DATESEARCHFILTERWIDGET_H
+
+#include <search/filters/abstractsearchfilterwidget.h>
+#include <QList>
+
+class QPushButton;
+
+/**
+ * @brief Allows to filter the search by defined date values like
+ * today, yesterday, ...
+ */
+class DateSearchFilterWidget : public AbstractSearchFilterWidget {
+ Q_OBJECT
+
+public:
+ DateSearchFilterWidget(QWidget* parent = 0);
+ virtual ~DateSearchFilterWidget();
+ virtual QString filterLabel() const;
+ virtual Nepomuk::Query::Term queryTerm() const;
+
+private:
+ enum DateFilterType {
+ Today,
+ Yesterday,
+ ThisWeek,
+ ThisMonth,
+ ThisYear
+ };
+
+ QList<QPushButton*> m_dateButtons;
+};
+
+#endif
diff --git a/src/search/filters/ratingsearchfilterwidget.cpp b/src/search/filters/ratingsearchfilterwidget.cpp
new file mode 100644
index 000000000..768764172
--- /dev/null
+++ b/src/search/filters/ratingsearchfilterwidget.cpp
@@ -0,0 +1,108 @@
+/***************************************************************************
+* Copyright (C) 2010 by Peter Penz <[email protected]> *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+* **************************************************************************/
+
+#include "ratingsearchfilterwidget.h"
+
+#define DISABLE_NEPOMUK_LEGACY
+
+#include <klocale.h>
+#include <nepomuk/comparisonterm.h>
+#include <nepomuk/literalterm.h>
+#include <nepomuk/orterm.h>
+#include <nepomuk/kratingpainter.h>
+#include <nepomuk/property.h>
+#include <nepomuk/query.h>
+#include "nie.h"
+#include <Soprano/LiteralValue>
+#include <Soprano/Vocabulary/NAO>
+#include <QFontMetrics>
+#include <QIcon>
+#include <QLabel>
+#include <QPainter>
+#include <QPushButton>
+#include <QHBoxLayout>
+
+namespace {
+ // Only show the ratings 0, 2, 4, ... 10
+ const int RatingInc = 2;
+};
+
+RatingSearchFilterWidget::RatingSearchFilterWidget(QWidget* parent) :
+ AbstractSearchFilterWidget(parent),
+ m_ratingButtons()
+{
+ QHBoxLayout* layout = new QHBoxLayout(this);
+ layout->setSpacing(0);
+
+ QFontMetrics fontMetrics(font());
+ const int iconHeight = fontMetrics.height();
+
+ KRatingPainter ratingPainter;
+ const int maxRating = ratingPainter.maxRating();
+ const QSize iconSize(iconHeight * (maxRating / 2), iconHeight);
+ const QRect paintRect(QPoint(0, 0), iconSize);
+
+ for (int rating = 0; rating <= ratingPainter.maxRating(); rating += RatingInc) {
+ // Create pixmap that represents the rating
+ QPixmap pixmap(iconSize);
+ pixmap.fill(Qt::transparent);
+ QPainter painter(&pixmap);
+ ratingPainter.paint(&painter, paintRect, rating);
+
+ // Create button with the rating pixmap as icon
+ QPushButton* button = createButton();
+ button->setIconSize(iconSize);
+ button->setIcon(QIcon(pixmap));
+
+ layout->addWidget(button);
+ m_ratingButtons.append(button);
+ }
+
+ layout->addStretch(1);
+}
+
+RatingSearchFilterWidget::~RatingSearchFilterWidget()
+{
+}
+
+QString RatingSearchFilterWidget::filterLabel() const
+{
+ return i18nc("@title:group", "Rating");
+}
+
+Nepomuk::Query::Term RatingSearchFilterWidget::queryTerm() const
+{
+ Nepomuk::Query::OrTerm orTerm;
+
+ int rating = 0;
+ foreach (const QPushButton* ratingButton, m_ratingButtons) {
+ if (ratingButton->isChecked()) {
+ const Nepomuk::Query::LiteralTerm term(rating);
+ const Nepomuk::Query::ComparisonTerm compTerm(Soprano::Vocabulary::NAO::numericRating(),
+ term,
+ Nepomuk::Query::ComparisonTerm::Equal);
+ orTerm.addSubTerm(compTerm);
+ }
+ rating += RatingInc;
+ }
+
+ return orTerm;
+}
+
+#include "ratingsearchfilterwidget.moc"
diff --git a/src/search/filters/ratingsearchfilterwidget.h b/src/search/filters/ratingsearchfilterwidget.h
new file mode 100644
index 000000000..05de1adec
--- /dev/null
+++ b/src/search/filters/ratingsearchfilterwidget.h
@@ -0,0 +1,44 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Peter Penz <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef RATINGSEARCHFILTERWIDGET_H
+#define RATINGSEARCHFILTERWIDGET_H
+
+#include <search/filters/abstractsearchfilterwidget.h>
+#include <QList>
+
+class QPushButton;
+
+/**
+ * @brief Allows to filter the search by rating.
+ */
+class RatingSearchFilterWidget : public AbstractSearchFilterWidget {
+ Q_OBJECT
+
+public:
+ RatingSearchFilterWidget(QWidget* parent = 0);
+ virtual ~RatingSearchFilterWidget();
+ virtual QString filterLabel() const;
+ virtual Nepomuk::Query::Term queryTerm() const;
+
+private:
+ QList<QPushButton*> m_ratingButtons;
+};
+
+#endif
diff --git a/src/search/filters/tagsearchfilterwidget.cpp b/src/search/filters/tagsearchfilterwidget.cpp
new file mode 100644
index 000000000..cb2d20dcc
--- /dev/null
+++ b/src/search/filters/tagsearchfilterwidget.cpp
@@ -0,0 +1,89 @@
+/***************************************************************************
+* Copyright (C) 2010 by Peter Penz <[email protected]> *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+* **************************************************************************/
+
+#include "tagsearchfilterwidget.h"
+
+#define DISABLE_NEPOMUK_LEGACY
+#include <nepomuk/tag.h>
+#include <nepomuk/comparisonterm.h>
+#include <nepomuk/literalterm.h>
+#include <nepomuk/orterm.h>
+#include <nepomuk/property.h>
+#include <nepomuk/query.h>
+#include <klocale.h>
+#include <Soprano/LiteralValue>
+#include <Soprano/Vocabulary/NAO>
+#include <QLabel>
+#include <QPushButton>
+#include <QHBoxLayout>
+
+static bool tagLabelLessThan(const Nepomuk::Tag& t1, const Nepomuk::Tag& t2)
+{
+ return t1.genericLabel() < t2.genericLabel();
+}
+
+TagSearchFilterWidget::TagSearchFilterWidget(QWidget* parent) :
+ AbstractSearchFilterWidget(parent),
+ m_tagButtons()
+{
+ QHBoxLayout* layout = new QHBoxLayout(this);
+ layout->setSpacing(0);
+
+ QList<Nepomuk::Tag> tags = Nepomuk::Tag::allTags();
+ qSort(tags.begin(), tags.end(), tagLabelLessThan);
+
+ // TODO: handle case if no tag is available
+ foreach (const Nepomuk::Tag& tag, tags) {
+ QPushButton* button = createButton();
+ button->setText(tag.genericLabel());
+
+ layout->addWidget(button);
+ m_tagButtons.append(button);
+ }
+
+ layout->addStretch(1);
+}
+
+TagSearchFilterWidget::~TagSearchFilterWidget()
+{
+}
+
+QString TagSearchFilterWidget::filterLabel() const
+{
+ return i18nc("@title:group", "Tag");
+}
+
+Nepomuk::Query::Term TagSearchFilterWidget::queryTerm() const
+{
+ Nepomuk::Query::OrTerm orTerm;
+
+ foreach (const QPushButton* tagButton, m_tagButtons) {
+ if (tagButton->isChecked()) {
+ const Nepomuk::Query::LiteralTerm term(tagButton->text());
+ const Nepomuk::Query::ComparisonTerm compTerm(Soprano::Vocabulary::NAO::hasTag(),
+ term,
+ Nepomuk::Query::ComparisonTerm::Equal);
+ orTerm.addSubTerm(compTerm);
+ }
+ }
+
+ return orTerm;
+}
+
+#include "tagsearchfilterwidget.moc"
diff --git a/src/search/filters/tagsearchfilterwidget.h b/src/search/filters/tagsearchfilterwidget.h
new file mode 100644
index 000000000..9897e408b
--- /dev/null
+++ b/src/search/filters/tagsearchfilterwidget.h
@@ -0,0 +1,44 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Peter Penz <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef TAGSEARCHFILTERWIDGET_H
+#define TAGSEARCHFILTERWIDGET_H
+
+#include <search/filters/abstractsearchfilterwidget.h>
+#include <QList>
+
+class QPushButton;
+
+/**
+ * @brief Allows to filter the search by tags.
+ */
+class TagSearchFilterWidget : public AbstractSearchFilterWidget {
+ Q_OBJECT
+
+public:
+ TagSearchFilterWidget(QWidget* parent = 0);
+ virtual ~TagSearchFilterWidget();
+ virtual QString filterLabel() const;
+ virtual Nepomuk::Query::Term queryTerm() const;
+
+private:
+ QList<QPushButton*> m_tagButtons;
+};
+
+#endif