+bool DolphinFacetsWidget::isRatingTerm(const Baloo::Term& term) const
+{
+ const QList<Baloo::Term> subTerms = term.subTerms();
+ if (subTerms.isEmpty()) {
+ // If term has no sub terms, then the term itself is either a "rating" term
+ // or a "modified" term.
+ return term.property() == QLatin1String("modified") ||
+ term.property() == QLatin1String("rating");
+
+ } else if (subTerms.size() == 2) {
+ // If term has sub terms, then the sub terms are always "rating" and "modified" terms.
+
+ QStringList properties;
+ foreach (const Baloo::Term& subTerm, subTerms) {
+ properties << subTerm.property();
+ }
+
+ return properties.contains(QLatin1String("modified")) &&
+ properties.contains(QLatin1String("rating"));
+ }
+
+ return false;
+}
+
+void DolphinFacetsWidget::setRatingTerm(const Baloo::Term& term)
+{
+ // If term has sub terms, then the sub terms are always "rating" and "modified" terms.
+ // If term has no sub terms, then the term itself is either a "rating" term or a "modified"
+ // term. To avoid code duplication we add term to subTerms list, if the list is empty.
+ QList<Baloo::Term> subTerms = term.subTerms();
+ if (subTerms.isEmpty()) {
+ subTerms << term;
+ }
+
+ foreach (const Baloo::Term& subTerm, subTerms) {
+ const QString property = subTerm.property();
+
+ if (property == QLatin1String("modified")) {
+ const QDate date = subTerm.value().toDate();
+ setTimespan(date);
+ } else if (property == QLatin1String("rating")) {
+ const int stars = subTerm.value().toInt() / 2;
+ setRating(stars);
+ }
+ }
+}
+