X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/67f58d5082cbab3a1a4a83926e77ade299ec07ea..016cf47c53c28aa57cf58c37d5acdcfce0bc47b0:/src/search/dolphinfacetswidget.cpp diff --git a/src/search/dolphinfacetswidget.cpp b/src/search/dolphinfacetswidget.cpp index 1a912af48..b7315a01c 100644 --- a/src/search/dolphinfacetswidget.cpp +++ b/src/search/dolphinfacetswidget.cpp @@ -20,7 +20,9 @@ #include "dolphinfacetswidget.h" #include +#include #include +#include #include #include #include @@ -44,10 +46,10 @@ DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : m_fourOrMore(0), m_maxRating(0) { - m_documents = new QCheckBox(i18nc("@option:check", "Documents")); - m_images = new QCheckBox(i18nc("@option:check", "Images")); - m_audio = new QCheckBox(i18nc("@option:check", "Audio")); - m_videos = new QCheckBox(i18nc("@option:check", "Videos")); + m_documents = createCheckBox(i18nc("@option:check", "Documents")); + m_images = createCheckBox(i18nc("@option:check", "Images")); + m_audio = createCheckBox(i18nc("@option:check", "Audio Files")); + m_videos = createCheckBox(i18nc("@option:check", "Videos")); QVBoxLayout* typeLayout = new QVBoxLayout(); typeLayout->setSpacing(0); @@ -57,12 +59,13 @@ DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : typeLayout->addWidget(m_videos); typeLayout->addStretch(); - m_anytime = new QRadioButton(i18nc("@option:option", "Anytime")); - m_today = new QRadioButton(i18nc("@option:option", "Today")); - m_yesterday = new QRadioButton(i18nc("@option:option", "Yesterday")); - m_thisWeek = new QRadioButton(i18nc("@option:option", "This Week")); - m_thisMonth = new QRadioButton(i18nc("@option:option", "This Month")); - m_thisYear = new QRadioButton(i18nc("@option:option", "This Year")); + QButtonGroup* timespanGroup = new QButtonGroup(this); + m_anytime = createRadioButton(i18nc("@option:option", "Anytime"), timespanGroup); + m_today = createRadioButton(i18nc("@option:option", "Today"), timespanGroup); + m_yesterday = createRadioButton(i18nc("@option:option", "Yesterday"), timespanGroup); + m_thisWeek = createRadioButton(i18nc("@option:option", "This Week"), timespanGroup); + m_thisMonth = createRadioButton(i18nc("@option:option", "This Month"), timespanGroup); + m_thisYear = createRadioButton(i18nc("@option:option", "This Year"), timespanGroup); QVBoxLayout* timespanLayout = new QVBoxLayout(); timespanLayout->setSpacing(0); @@ -74,12 +77,13 @@ DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : timespanLayout->addWidget(m_thisYear); timespanLayout->addStretch(); - m_anyRating = new QRadioButton(i18nc("@option:option", "Any Rating")); - m_oneOrMore = new QRadioButton(i18nc("@option:option", "1 or more")); - m_twoOrMore = new QRadioButton(i18nc("@option:option", "2 or more")); - m_threeOrMore = new QRadioButton(i18nc("@option:option", "3 or more")); - m_fourOrMore = new QRadioButton(i18nc("@option:option", "4 or more")); - m_maxRating = new QRadioButton(i18nc("@option:option", "Maximum Rating")); + QButtonGroup* ratingGroup = new QButtonGroup(this); + m_anyRating = createRadioButton(i18nc("@option:option", "Any Rating"), ratingGroup); + m_oneOrMore = createRadioButton(i18nc("@option:option", "1 or more"), ratingGroup); + m_twoOrMore = createRadioButton(i18nc("@option:option", "2 or more"), ratingGroup); + m_threeOrMore = createRadioButton(i18nc("@option:option", "3 or more"), ratingGroup); + m_fourOrMore = createRadioButton(i18nc("@option:option", "4 or more"), ratingGroup); + m_maxRating = createRadioButton(i18nc("@option:option", "Highest Rating"), ratingGroup); QVBoxLayout* ratingLayout = new QVBoxLayout(); ratingLayout->setSpacing(0); @@ -96,7 +100,6 @@ DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) : topLayout->addLayout(ratingLayout); topLayout->addStretch(); - // TODO: m_anytime->setChecked(true); m_anyRating->setChecked(true); } @@ -105,4 +108,90 @@ DolphinFacetsWidget::~DolphinFacetsWidget() { } +#ifdef HAVE_BALOO +Baloo::Term DolphinFacetsWidget::ratingTerm() const +{ + if (!m_anyRating->isChecked()) { + int stars = 1; // represents m_oneOrMore + if (m_twoOrMore->isChecked()) { + stars = 2; + } else if (m_threeOrMore->isChecked()) { + stars = 3; + } else if (m_fourOrMore->isChecked()) { + stars = 4; + } else if (m_maxRating->isChecked()) { + stars = 5; + } + + const int rating = stars * 2; + + Baloo::Term term("rating", rating, Baloo::Term::GreaterEqual); + return term; + } + + return Baloo::Term(); + + /* + // FIXME: Handle date time filters + if (!m_anytime->isChecked()) { + QDate date = QDate::currentDate(); // represents m_today + if (m_yesterday->isChecked()) { + date = date.addDays(-1); + } else if (m_thisWeek->isChecked()) { + date = date.addDays(1 - date.dayOfWeek()); + } else if (m_thisMonth->isChecked()) { + date = date.addDays(1 - date.day()); + } else if (m_thisYear->isChecked()) { + date = date.addDays(1 - date.dayOfYear()); + } + + Nepomuk2::Query::ComparisonTerm term(Nepomuk2::Vocabulary::NIE::lastModified(), + Nepomuk2::Query::LiteralTerm(QDateTime(date)), + Nepomuk2::Query::ComparisonTerm::GreaterOrEqual); + andTerm.addSubTerm(term); + } + */ +} + +QStringList DolphinFacetsWidget::facetTypes() const +{ + QStringList types; + if (m_documents->isChecked()) { + types << "Document"; + } + + if (m_images->isChecked()) { + types << "Image"; + } + + if (m_audio->isChecked()) { + types << "Audio"; + } + + if (m_videos->isChecked()) { + types << "Video"; + } + + return types; +} + +#endif + + +QCheckBox* DolphinFacetsWidget::createCheckBox(const QString& text) +{ + QCheckBox* checkBox = new QCheckBox(text); + connect(checkBox, SIGNAL(clicked()), this, SIGNAL(facetChanged())); + return checkBox; +} + +QRadioButton* DolphinFacetsWidget::createRadioButton(const QString& text, + QButtonGroup* group) +{ + QRadioButton* button = new QRadioButton(text); + connect(button, SIGNAL(clicked()), this, SIGNAL(facetChanged())); + group->addButton(button); + return button; +} + #include "dolphinfacetswidget.moc"