]>
cloud.milkyroute.net Git - dolphin.git/blob - src/search/filters/datesearchfilterwidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 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 "datesearchfilterwidget.h"
22 #define DISABLE_NEPOMUK_LEGACY
25 #include <nepomuk/comparisonterm.h>
26 #include <nepomuk/literalterm.h>
27 #include <nepomuk/orterm.h>
28 #include <nepomuk/property.h>
29 #include <nepomuk/query.h>
34 #include <QPushButton>
35 #include <QHBoxLayout>
37 DateSearchFilterWidget::DateSearchFilterWidget(QWidget
* parent
) :
38 AbstractSearchFilterWidget(parent
),
41 QHBoxLayout
* layout
= new QHBoxLayout(this);
42 layout
->setSpacing(0);
44 for (int i
= Today
; i
<= ThisYear
; ++i
) {
45 QPushButton
* button
= createButton();
47 case Today
: button
->setText(i18nc("@action:button", "Today")); break;
48 case Yesterday
: button
->setText(i18nc("@action:button", "Yesterday")); break;
49 case ThisWeek
: button
->setText(i18nc("@action:button", "This Week")); break;
50 case ThisMonth
: button
->setText(i18nc("@action:button", "This Month")); break;
51 case ThisYear
: button
->setText(i18nc("@action:button", "This Year")); break;
52 default: Q_ASSERT(false);
55 layout
->addWidget(button
);
56 m_dateButtons
.append(button
);
58 layout
->addStretch(1);
61 DateSearchFilterWidget::~DateSearchFilterWidget()
66 QString
DateSearchFilterWidget::filterLabel() const
68 return i18nc("@title:group", "Date");
71 Nepomuk::Query::Term
DateSearchFilterWidget::queryTerm() const
73 Nepomuk::Query::OrTerm orTerm
;
76 foreach (const QPushButton
* button
, m_dateButtons
) {
77 if (button
->isChecked()) {
78 QDate today
= QDate::currentDate();
82 // Current date is already set
88 date
.addDays(-today
.dayOfWeek());
91 date
= QDate(today
.year(), today
.month(), 1);
94 date
= QDate(today
.year(), 1, 1);
100 const QDateTime
dateTime(date
);
101 const Nepomuk::Query::LiteralTerm
term(dateTime
);
102 const Nepomuk::Query::ComparisonTerm
compTerm(Nepomuk::Vocabulary::NIE::lastModified(),
104 Nepomuk::Query::ComparisonTerm::GreaterOrEqual
);
105 orTerm
.addSubTerm(compTerm
);
113 #include "datesearchfilterwidget.moc"