]>
cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinfacetswidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 * **************************************************************************/
20 #include "dolphinfacetswidget.h"
23 #include <QButtonGroup>
26 #include <QRadioButton>
27 #include <QHBoxLayout>
28 #include <QVBoxLayout>
30 DolphinFacetsWidget::DolphinFacetsWidget(QWidget
* parent
) :
49 m_documents
= createCheckBox(i18nc("@option:check", "Documents"));
50 m_images
= createCheckBox(i18nc("@option:check", "Images"));
51 m_audio
= createCheckBox(i18nc("@option:check", "Audio Files"));
52 m_videos
= createCheckBox(i18nc("@option:check", "Videos"));
54 QVBoxLayout
* typeLayout
= new QVBoxLayout();
55 typeLayout
->setSpacing(0);
56 typeLayout
->addWidget(m_documents
);
57 typeLayout
->addWidget(m_images
);
58 typeLayout
->addWidget(m_audio
);
59 typeLayout
->addWidget(m_videos
);
60 typeLayout
->addStretch();
62 QButtonGroup
* timespanGroup
= new QButtonGroup(this);
63 m_anytime
= createRadioButton(i18nc("@option:option", "Anytime"), timespanGroup
);
64 m_today
= createRadioButton(i18nc("@option:option", "Today"), timespanGroup
);
65 m_yesterday
= createRadioButton(i18nc("@option:option", "Yesterday"), timespanGroup
);
66 m_thisWeek
= createRadioButton(i18nc("@option:option", "This Week"), timespanGroup
);
67 m_thisMonth
= createRadioButton(i18nc("@option:option", "This Month"), timespanGroup
);
68 m_thisYear
= createRadioButton(i18nc("@option:option", "This Year"), timespanGroup
);
70 QVBoxLayout
* timespanLayout
= new QVBoxLayout();
71 timespanLayout
->setSpacing(0);
72 timespanLayout
->addWidget(m_anytime
);
73 timespanLayout
->addWidget(m_today
);
74 timespanLayout
->addWidget(m_yesterday
);
75 timespanLayout
->addWidget(m_thisWeek
);
76 timespanLayout
->addWidget(m_thisMonth
);
77 timespanLayout
->addWidget(m_thisYear
);
78 timespanLayout
->addStretch();
80 QButtonGroup
* ratingGroup
= new QButtonGroup(this);
81 m_anyRating
= createRadioButton(i18nc("@option:option", "Any Rating"), ratingGroup
);
82 m_oneOrMore
= createRadioButton(i18nc("@option:option", "1 or more"), ratingGroup
);
83 m_twoOrMore
= createRadioButton(i18nc("@option:option", "2 or more"), ratingGroup
);
84 m_threeOrMore
= createRadioButton(i18nc("@option:option", "3 or more"), ratingGroup
);
85 m_fourOrMore
= createRadioButton(i18nc("@option:option", "4 or more"), ratingGroup
);
86 m_maxRating
= createRadioButton(i18nc("@option:option", "Highest Rating"), ratingGroup
);
88 QVBoxLayout
* ratingLayout
= new QVBoxLayout();
89 ratingLayout
->setSpacing(0);
90 ratingLayout
->addWidget(m_anyRating
);
91 ratingLayout
->addWidget(m_oneOrMore
);
92 ratingLayout
->addWidget(m_twoOrMore
);
93 ratingLayout
->addWidget(m_threeOrMore
);
94 ratingLayout
->addWidget(m_fourOrMore
);
95 ratingLayout
->addWidget(m_maxRating
);
97 QHBoxLayout
* topLayout
= new QHBoxLayout(this);
98 topLayout
->addLayout(typeLayout
);
99 topLayout
->addLayout(timespanLayout
);
100 topLayout
->addLayout(ratingLayout
);
101 topLayout
->addStretch();
103 m_anytime
->setChecked(true);
104 m_anyRating
->setChecked(true);
107 DolphinFacetsWidget::~DolphinFacetsWidget()
112 Baloo::Term
DolphinFacetsWidget::ratingTerm() const
114 if (!m_anyRating
->isChecked()) {
115 int stars
= 1; // represents m_oneOrMore
116 if (m_twoOrMore
->isChecked()) {
118 } else if (m_threeOrMore
->isChecked()) {
120 } else if (m_fourOrMore
->isChecked()) {
122 } else if (m_maxRating
->isChecked()) {
126 const int rating
= stars
* 2;
128 Baloo::Term
term("rating", rating
, Baloo::Term::GreaterEqual
);
132 return Baloo::Term();
135 // FIXME: Handle date time filters
136 if (!m_anytime->isChecked()) {
137 QDate date = QDate::currentDate(); // represents m_today
138 if (m_yesterday->isChecked()) {
139 date = date.addDays(-1);
140 } else if (m_thisWeek->isChecked()) {
141 date = date.addDays(1 - date.dayOfWeek());
142 } else if (m_thisMonth->isChecked()) {
143 date = date.addDays(1 - date.day());
144 } else if (m_thisYear->isChecked()) {
145 date = date.addDays(1 - date.dayOfYear());
148 Nepomuk2::Query::ComparisonTerm term(Nepomuk2::Vocabulary::NIE::lastModified(),
149 Nepomuk2::Query::LiteralTerm(QDateTime(date)),
150 Nepomuk2::Query::ComparisonTerm::GreaterOrEqual);
151 andTerm.addSubTerm(term);
156 QStringList
DolphinFacetsWidget::facetTypes() const
159 if (m_documents
->isChecked()) {
163 if (m_images
->isChecked()) {
167 if (m_audio
->isChecked()) {
171 if (m_videos
->isChecked()) {
181 QCheckBox
* DolphinFacetsWidget::createCheckBox(const QString
& text
)
183 QCheckBox
* checkBox
= new QCheckBox(text
);
184 connect(checkBox
, SIGNAL(clicked()), this, SIGNAL(facetChanged()));
188 QRadioButton
* DolphinFacetsWidget::createRadioButton(const QString
& text
,
191 QRadioButton
* button
= new QRadioButton(text
);
192 connect(button
, SIGNAL(clicked()), this, SIGNAL(facetChanged()));
193 group
->addButton(button
);
197 #include "dolphinfacetswidget.moc"