]>
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>
31 #include <Nepomuk2/Query/AndTerm>
32 #include <Nepomuk2/Query/ComparisonTerm>
33 #include <Nepomuk2/Query/LiteralTerm>
34 #include <Nepomuk2/Query/OrTerm>
35 #include <Nepomuk2/Query/Query>
36 #include <Nepomuk2/Query/ResourceTypeTerm>
37 #include <Nepomuk2/Vocabulary/NFO>
38 #include <Nepomuk2/Vocabulary/NIE>
39 #include <Soprano/Vocabulary/NAO>
42 DolphinFacetsWidget::DolphinFacetsWidget(QWidget
* parent
) :
61 m_documents
= createCheckBox(i18nc("@option:check", "Documents"));
62 m_images
= createCheckBox(i18nc("@option:check", "Images"));
63 m_audio
= createCheckBox(i18nc("@option:check", "Audio Files"));
64 m_videos
= createCheckBox(i18nc("@option:check", "Videos"));
66 QVBoxLayout
* typeLayout
= new QVBoxLayout();
67 typeLayout
->setSpacing(0);
68 typeLayout
->addWidget(m_documents
);
69 typeLayout
->addWidget(m_images
);
70 typeLayout
->addWidget(m_audio
);
71 typeLayout
->addWidget(m_videos
);
72 typeLayout
->addStretch();
74 QButtonGroup
* timespanGroup
= new QButtonGroup(this);
75 m_anytime
= createRadioButton(i18nc("@option:option", "Anytime"), timespanGroup
);
76 m_today
= createRadioButton(i18nc("@option:option", "Today"), timespanGroup
);
77 m_yesterday
= createRadioButton(i18nc("@option:option", "Yesterday"), timespanGroup
);
78 m_thisWeek
= createRadioButton(i18nc("@option:option", "This Week"), timespanGroup
);
79 m_thisMonth
= createRadioButton(i18nc("@option:option", "This Month"), timespanGroup
);
80 m_thisYear
= createRadioButton(i18nc("@option:option", "This Year"), timespanGroup
);
82 QVBoxLayout
* timespanLayout
= new QVBoxLayout();
83 timespanLayout
->setSpacing(0);
84 timespanLayout
->addWidget(m_anytime
);
85 timespanLayout
->addWidget(m_today
);
86 timespanLayout
->addWidget(m_yesterday
);
87 timespanLayout
->addWidget(m_thisWeek
);
88 timespanLayout
->addWidget(m_thisMonth
);
89 timespanLayout
->addWidget(m_thisYear
);
90 timespanLayout
->addStretch();
92 QButtonGroup
* ratingGroup
= new QButtonGroup(this);
93 m_anyRating
= createRadioButton(i18nc("@option:option", "Any Rating"), ratingGroup
);
94 m_oneOrMore
= createRadioButton(i18nc("@option:option", "1 or more"), ratingGroup
);
95 m_twoOrMore
= createRadioButton(i18nc("@option:option", "2 or more"), ratingGroup
);
96 m_threeOrMore
= createRadioButton(i18nc("@option:option", "3 or more"), ratingGroup
);
97 m_fourOrMore
= createRadioButton(i18nc("@option:option", "4 or more"), ratingGroup
);
98 m_maxRating
= createRadioButton(i18nc("@option:option", "Highest Rating"), ratingGroup
);
100 QVBoxLayout
* ratingLayout
= new QVBoxLayout();
101 ratingLayout
->setSpacing(0);
102 ratingLayout
->addWidget(m_anyRating
);
103 ratingLayout
->addWidget(m_oneOrMore
);
104 ratingLayout
->addWidget(m_twoOrMore
);
105 ratingLayout
->addWidget(m_threeOrMore
);
106 ratingLayout
->addWidget(m_fourOrMore
);
107 ratingLayout
->addWidget(m_maxRating
);
109 QHBoxLayout
* topLayout
= new QHBoxLayout(this);
110 topLayout
->addLayout(typeLayout
);
111 topLayout
->addLayout(timespanLayout
);
112 topLayout
->addLayout(ratingLayout
);
113 topLayout
->addStretch();
115 m_anytime
->setChecked(true);
116 m_anyRating
->setChecked(true);
119 DolphinFacetsWidget::~DolphinFacetsWidget()
124 Nepomuk2::Query::Term
DolphinFacetsWidget::facetsTerm() const
126 Nepomuk2::Query::AndTerm andTerm
;
128 const bool hasTypeFilter
= m_documents
->isChecked() ||
129 m_images
->isChecked() ||
130 m_audio
->isChecked() ||
131 m_videos
->isChecked();
133 Nepomuk2::Query::OrTerm orTerm
;
135 if (m_documents
->isChecked()) {
136 orTerm
.addSubTerm(Nepomuk2::Query::ResourceTypeTerm(Nepomuk2::Vocabulary::NFO::Document()));
139 if (m_images
->isChecked()) {
140 orTerm
.addSubTerm(Nepomuk2::Query::ResourceTypeTerm(Nepomuk2::Vocabulary::NFO::Image()));
143 if (m_audio
->isChecked()) {
144 orTerm
.addSubTerm(Nepomuk2::Query::ComparisonTerm(Nepomuk2::Vocabulary::NIE::mimeType(),
145 Nepomuk2::Query::LiteralTerm("audio")));
148 if (m_videos
->isChecked()) {
149 orTerm
.addSubTerm(Nepomuk2::Query::ComparisonTerm(Nepomuk2::Vocabulary::NIE::mimeType(),
150 Nepomuk2::Query::LiteralTerm("video")));
153 andTerm
.addSubTerm(orTerm
);
156 if (!m_anyRating
->isChecked()) {
157 int stars
= 1; // represents m_oneOrMore
158 if (m_twoOrMore
->isChecked()) {
160 } else if (m_threeOrMore
->isChecked()) {
162 } else if (m_fourOrMore
->isChecked()) {
164 } else if (m_maxRating
->isChecked()) {
168 const int rating
= stars
* 2;
169 Nepomuk2::Query::ComparisonTerm
term(Soprano::Vocabulary::NAO::numericRating(),
170 Nepomuk2::Query::LiteralTerm(rating
),
171 Nepomuk2::Query::ComparisonTerm::GreaterOrEqual
);
172 andTerm
.addSubTerm(term
);
175 if (!m_anytime
->isChecked()) {
176 QDate date
= QDate::currentDate(); // represents m_today
177 if (m_yesterday
->isChecked()) {
179 } else if (m_thisWeek
->isChecked()) {
180 date
.addDays(1 - date
.dayOfWeek());
181 } else if (m_thisMonth
->isChecked()) {
182 date
.addDays(1 - date
.day());
183 } else if (m_thisYear
->isChecked()) {
184 date
.addDays(1 - date
.dayOfYear());
187 Nepomuk2::Query::ComparisonTerm
term(Nepomuk2::Vocabulary::NIE::lastModified(),
188 Nepomuk2::Query::LiteralTerm(QDateTime(date
)),
189 Nepomuk2::Query::ComparisonTerm::GreaterOrEqual
);
190 andTerm
.addSubTerm(term
);
197 QCheckBox
* DolphinFacetsWidget::createCheckBox(const QString
& text
)
199 QCheckBox
* checkBox
= new QCheckBox(text
);
200 connect(checkBox
, SIGNAL(clicked()), this, SIGNAL(facetChanged()));
204 QRadioButton
* DolphinFacetsWidget::createRadioButton(const QString
& text
,
207 QRadioButton
* button
= new QRadioButton(text
);
208 connect(button
, SIGNAL(clicked()), this, SIGNAL(facetChanged()));
209 group
->addButton(button
);
213 #include "dolphinfacetswidget.moc"