mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
Move away from Baloo::Term
Baloo is set to become a framework and wants to only export the bare minimum number of classes as it will need to provide ABI + API guarentees forever. The Term class is now no longer exported. It can be added back again. REVIEW: 123643
This commit is contained in:
parent
e69d348975
commit
9d4ad66abe
|
@ -112,11 +112,9 @@ DolphinFacetsWidget::~DolphinFacetsWidget()
|
|||
{
|
||||
}
|
||||
|
||||
#ifdef HAVE_BALOO
|
||||
Baloo::Term DolphinFacetsWidget::ratingTerm() const
|
||||
QString DolphinFacetsWidget::ratingTerm() const
|
||||
{
|
||||
Baloo::Term ratingTerm;
|
||||
Baloo::Term modifiedTerm;
|
||||
QStringList terms;
|
||||
|
||||
if (!m_anyRating->isChecked()) {
|
||||
int stars = 1; // represents m_oneOrMore
|
||||
|
@ -131,7 +129,7 @@ Baloo::Term DolphinFacetsWidget::ratingTerm() const
|
|||
}
|
||||
|
||||
const int rating = stars * 2;
|
||||
ratingTerm = Baloo::Term("rating", rating, Baloo::Term::GreaterEqual);
|
||||
terms << QString::fromLatin1("rating>=%1").arg(rating);
|
||||
}
|
||||
|
||||
if (!m_anytime->isChecked()) {
|
||||
|
@ -146,22 +144,10 @@ Baloo::Term DolphinFacetsWidget::ratingTerm() const
|
|||
date = date.addDays(1 - date.dayOfYear());
|
||||
}
|
||||
|
||||
modifiedTerm = Baloo::Term("modified", date, Baloo::Term::GreaterEqual);
|
||||
terms << QString::fromLatin1("modified>=%1").arg(date.toString(Qt::ISODate));
|
||||
}
|
||||
|
||||
if (ratingTerm.isValid() && modifiedTerm.isValid()) {
|
||||
Baloo::Term term(Baloo::Term::And);
|
||||
term.addSubTerm(ratingTerm);
|
||||
term.addSubTerm(modifiedTerm);
|
||||
|
||||
return term;
|
||||
} else if (modifiedTerm.isValid()) {
|
||||
return modifiedTerm;
|
||||
} else if (ratingTerm.isValid()) {
|
||||
return ratingTerm;
|
||||
}
|
||||
|
||||
return Baloo::Term();
|
||||
return terms.join(QStringLiteral(" AND "));
|
||||
}
|
||||
|
||||
QString DolphinFacetsWidget::facetType() const
|
||||
|
@ -179,55 +165,45 @@ QString DolphinFacetsWidget::facetType() const
|
|||
return QString();
|
||||
}
|
||||
|
||||
bool DolphinFacetsWidget::isRatingTerm(const Baloo::Term& term) const
|
||||
bool DolphinFacetsWidget::isRatingTerm(const QString& 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");
|
||||
const QStringList subTerms = term.split(' ', QString::SkipEmptyParts);
|
||||
|
||||
} else if (subTerms.size() == 2) {
|
||||
// If term has sub terms, then the sub terms are always "rating" and "modified" terms.
|
||||
// If term has sub terms, then sone of the sub terms are always "rating" and "modified" terms.
|
||||
bool containsRating = false;
|
||||
bool containsModified = false;
|
||||
|
||||
QStringList properties;
|
||||
foreach (const Baloo::Term& subTerm, subTerms) {
|
||||
properties << subTerm.property();
|
||||
foreach (const QString& subTerm, subTerms) {
|
||||
if (subTerm.startsWith("rating>=")) {
|
||||
containsRating = true;
|
||||
} else if (subTerm.startsWith("modified>=")) {
|
||||
containsModified = true;
|
||||
}
|
||||
|
||||
return properties.contains(QLatin1String("modified")) &&
|
||||
properties.contains(QLatin1String("rating"));
|
||||
}
|
||||
|
||||
return false;
|
||||
return containsModified || containsRating;
|
||||
}
|
||||
|
||||
void DolphinFacetsWidget::setRatingTerm(const Baloo::Term& term)
|
||||
void DolphinFacetsWidget::setRatingTerm(const QString& 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;
|
||||
}
|
||||
QStringList subTerms = term.split(' ', QString::SkipEmptyParts);
|
||||
|
||||
foreach (const Baloo::Term& subTerm, subTerms) {
|
||||
const QString property = subTerm.property();
|
||||
|
||||
if (property == QLatin1String("modified")) {
|
||||
const QDate date = subTerm.value().toDate();
|
||||
foreach (const QString& subTerm, subTerms) {
|
||||
if (subTerm.startsWith("modified>=")) {
|
||||
const QString value = subTerm.mid(10);
|
||||
const QDate date = QDate::fromString(value, Qt::ISODate);
|
||||
setTimespan(date);
|
||||
} else if (property == QLatin1String("rating")) {
|
||||
const int stars = subTerm.value().toInt() / 2;
|
||||
} else if (subTerm.startsWith("rating>=")) {
|
||||
const QString value = subTerm.mid(8);
|
||||
const int stars = value.toInt() / 2;
|
||||
setRating(stars);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void DolphinFacetsWidget::setFacetType(const QString& type)
|
||||
{
|
||||
if (type == QLatin1String("Document")) {
|
||||
|
|
|
@ -22,11 +22,6 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
#include <config-baloo.h>
|
||||
#ifdef HAVE_BALOO
|
||||
#include <Baloo/Term>
|
||||
#endif
|
||||
|
||||
class QButtonGroup;
|
||||
class QDate;
|
||||
class QRadioButton;
|
||||
|
@ -55,13 +50,11 @@ public:
|
|||
explicit DolphinFacetsWidget(QWidget* parent = 0);
|
||||
virtual ~DolphinFacetsWidget();
|
||||
|
||||
#ifdef HAVE_BALOO
|
||||
Baloo::Term ratingTerm() const;
|
||||
QString ratingTerm() const;
|
||||
QString facetType() const;
|
||||
|
||||
bool isRatingTerm(const Baloo::Term& term) const;
|
||||
void setRatingTerm(const Baloo::Term& term);
|
||||
#endif
|
||||
bool isRatingTerm(const QString& term) const;
|
||||
void setRatingTerm(const QString& term);
|
||||
|
||||
void setFacetType(const QString& type);
|
||||
|
||||
|
|
|
@ -441,24 +441,23 @@ QUrl DolphinSearchBox::balooUrlForSearching() const
|
|||
Baloo::Query query;
|
||||
query.addType(m_facetsWidget->facetType());
|
||||
|
||||
Baloo::Term term(Baloo::Term::And);
|
||||
|
||||
Baloo::Term ratingTerm = m_facetsWidget->ratingTerm();
|
||||
if (ratingTerm.isValid()) {
|
||||
term.addSubTerm(ratingTerm);
|
||||
QStringList queryStrings;
|
||||
QString ratingQuery = m_facetsWidget->ratingTerm();
|
||||
if (!ratingQuery.isEmpty()) {
|
||||
queryStrings << ratingQuery;
|
||||
}
|
||||
|
||||
if (m_contentButton->isChecked()) {
|
||||
query.setSearchString(text);
|
||||
queryStrings << text;
|
||||
} else if (!text.isEmpty()) {
|
||||
term.addSubTerm(Baloo::Term(QLatin1String("filename"), text));
|
||||
queryStrings << QString::fromLatin1("filename:\"%1\"").arg(text);
|
||||
}
|
||||
|
||||
if (m_fromHereButton->isChecked()) {
|
||||
query.setIncludeFolder(m_searchPath.toLocalFile());
|
||||
}
|
||||
|
||||
query.setTerm(term);
|
||||
query.setSearchString(queryStrings.join(" "));
|
||||
|
||||
return query.toSearchUrl(i18nc("@title UDS_DISPLAY_NAME for a KIO directory listing. %1 is the query the user entered.",
|
||||
"Query Results from '%1'", text));
|
||||
|
@ -471,7 +470,6 @@ void DolphinSearchBox::fromBalooSearchUrl(const QUrl& url)
|
|||
{
|
||||
#ifdef HAVE_BALOO
|
||||
const Baloo::Query query = Baloo::Query::fromSearchUrl(url);
|
||||
const Baloo::Term term = query.term();
|
||||
|
||||
// Block all signals to avoid unnecessary "searchRequest" signals
|
||||
// while we adjust the search text and the facet widget.
|
||||
|
@ -491,11 +489,11 @@ void DolphinSearchBox::fromBalooSearchUrl(const QUrl& url)
|
|||
m_facetsWidget->setFacetType(types.first());
|
||||
}
|
||||
|
||||
foreach (const Baloo::Term& subTerm, term.subTerms()) {
|
||||
const QString property = subTerm.property();
|
||||
|
||||
if (property == QLatin1String("filename")) {
|
||||
setText(subTerm.value().toString());
|
||||
const QStringList subTerms = query.searchString().split(' ', QString::SkipEmptyParts);
|
||||
foreach (const QString& subTerm, subTerms) {
|
||||
if (subTerm.startsWith("filename:")) {
|
||||
const QString value = subTerm.mid(9);
|
||||
setText(value);
|
||||
} else if (m_facetsWidget->isRatingTerm(subTerm)) {
|
||||
m_facetsWidget->setRatingTerm(subTerm);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue