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
|
QString DolphinFacetsWidget::ratingTerm() const
|
||||||
Baloo::Term DolphinFacetsWidget::ratingTerm() const
|
|
||||||
{
|
{
|
||||||
Baloo::Term ratingTerm;
|
QStringList terms;
|
||||||
Baloo::Term modifiedTerm;
|
|
||||||
|
|
||||||
if (!m_anyRating->isChecked()) {
|
if (!m_anyRating->isChecked()) {
|
||||||
int stars = 1; // represents m_oneOrMore
|
int stars = 1; // represents m_oneOrMore
|
||||||
|
@ -131,7 +129,7 @@ Baloo::Term DolphinFacetsWidget::ratingTerm() const
|
||||||
}
|
}
|
||||||
|
|
||||||
const int rating = stars * 2;
|
const int rating = stars * 2;
|
||||||
ratingTerm = Baloo::Term("rating", rating, Baloo::Term::GreaterEqual);
|
terms << QString::fromLatin1("rating>=%1").arg(rating);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_anytime->isChecked()) {
|
if (!m_anytime->isChecked()) {
|
||||||
|
@ -146,22 +144,10 @@ Baloo::Term DolphinFacetsWidget::ratingTerm() const
|
||||||
date = date.addDays(1 - date.dayOfYear());
|
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()) {
|
return terms.join(QStringLiteral(" AND "));
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DolphinFacetsWidget::facetType() const
|
QString DolphinFacetsWidget::facetType() const
|
||||||
|
@ -179,55 +165,45 @@ QString DolphinFacetsWidget::facetType() const
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DolphinFacetsWidget::isRatingTerm(const Baloo::Term& term) const
|
bool DolphinFacetsWidget::isRatingTerm(const QString& term) const
|
||||||
{
|
{
|
||||||
const QList<Baloo::Term> subTerms = term.subTerms();
|
const QStringList subTerms = term.split(' ', QString::SkipEmptyParts);
|
||||||
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 sone of the sub terms are always "rating" and "modified" terms.
|
||||||
// If term has sub terms, then the sub terms are always "rating" and "modified" terms.
|
bool containsRating = false;
|
||||||
|
bool containsModified = false;
|
||||||
|
|
||||||
QStringList properties;
|
foreach (const QString& subTerm, subTerms) {
|
||||||
foreach (const Baloo::Term& subTerm, subTerms) {
|
if (subTerm.startsWith("rating>=")) {
|
||||||
properties << subTerm.property();
|
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 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"
|
// 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.
|
// term. To avoid code duplication we add term to subTerms list, if the list is empty.
|
||||||
QList<Baloo::Term> subTerms = term.subTerms();
|
QStringList subTerms = term.split(' ', QString::SkipEmptyParts);
|
||||||
if (subTerms.isEmpty()) {
|
|
||||||
subTerms << term;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (const Baloo::Term& subTerm, subTerms) {
|
foreach (const QString& subTerm, subTerms) {
|
||||||
const QString property = subTerm.property();
|
if (subTerm.startsWith("modified>=")) {
|
||||||
|
const QString value = subTerm.mid(10);
|
||||||
if (property == QLatin1String("modified")) {
|
const QDate date = QDate::fromString(value, Qt::ISODate);
|
||||||
const QDate date = subTerm.value().toDate();
|
|
||||||
setTimespan(date);
|
setTimespan(date);
|
||||||
} else if (property == QLatin1String("rating")) {
|
} else if (subTerm.startsWith("rating>=")) {
|
||||||
const int stars = subTerm.value().toInt() / 2;
|
const QString value = subTerm.mid(8);
|
||||||
|
const int stars = value.toInt() / 2;
|
||||||
setRating(stars);
|
setRating(stars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void DolphinFacetsWidget::setFacetType(const QString& type)
|
void DolphinFacetsWidget::setFacetType(const QString& type)
|
||||||
{
|
{
|
||||||
if (type == QLatin1String("Document")) {
|
if (type == QLatin1String("Document")) {
|
||||||
|
|
|
@ -22,11 +22,6 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include <config-baloo.h>
|
|
||||||
#ifdef HAVE_BALOO
|
|
||||||
#include <Baloo/Term>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class QButtonGroup;
|
class QButtonGroup;
|
||||||
class QDate;
|
class QDate;
|
||||||
class QRadioButton;
|
class QRadioButton;
|
||||||
|
@ -55,13 +50,11 @@ public:
|
||||||
explicit DolphinFacetsWidget(QWidget* parent = 0);
|
explicit DolphinFacetsWidget(QWidget* parent = 0);
|
||||||
virtual ~DolphinFacetsWidget();
|
virtual ~DolphinFacetsWidget();
|
||||||
|
|
||||||
#ifdef HAVE_BALOO
|
QString ratingTerm() const;
|
||||||
Baloo::Term ratingTerm() const;
|
|
||||||
QString facetType() const;
|
QString facetType() const;
|
||||||
|
|
||||||
bool isRatingTerm(const Baloo::Term& term) const;
|
bool isRatingTerm(const QString& term) const;
|
||||||
void setRatingTerm(const Baloo::Term& term);
|
void setRatingTerm(const QString& term);
|
||||||
#endif
|
|
||||||
|
|
||||||
void setFacetType(const QString& type);
|
void setFacetType(const QString& type);
|
||||||
|
|
||||||
|
|
|
@ -441,24 +441,23 @@ QUrl DolphinSearchBox::balooUrlForSearching() const
|
||||||
Baloo::Query query;
|
Baloo::Query query;
|
||||||
query.addType(m_facetsWidget->facetType());
|
query.addType(m_facetsWidget->facetType());
|
||||||
|
|
||||||
Baloo::Term term(Baloo::Term::And);
|
QStringList queryStrings;
|
||||||
|
QString ratingQuery = m_facetsWidget->ratingTerm();
|
||||||
Baloo::Term ratingTerm = m_facetsWidget->ratingTerm();
|
if (!ratingQuery.isEmpty()) {
|
||||||
if (ratingTerm.isValid()) {
|
queryStrings << ratingQuery;
|
||||||
term.addSubTerm(ratingTerm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_contentButton->isChecked()) {
|
if (m_contentButton->isChecked()) {
|
||||||
query.setSearchString(text);
|
queryStrings << text;
|
||||||
} else if (!text.isEmpty()) {
|
} else if (!text.isEmpty()) {
|
||||||
term.addSubTerm(Baloo::Term(QLatin1String("filename"), text));
|
queryStrings << QString::fromLatin1("filename:\"%1\"").arg(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_fromHereButton->isChecked()) {
|
if (m_fromHereButton->isChecked()) {
|
||||||
query.setIncludeFolder(m_searchPath.toLocalFile());
|
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.",
|
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));
|
"Query Results from '%1'", text));
|
||||||
|
@ -471,7 +470,6 @@ void DolphinSearchBox::fromBalooSearchUrl(const QUrl& url)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_BALOO
|
#ifdef HAVE_BALOO
|
||||||
const Baloo::Query query = Baloo::Query::fromSearchUrl(url);
|
const Baloo::Query query = Baloo::Query::fromSearchUrl(url);
|
||||||
const Baloo::Term term = query.term();
|
|
||||||
|
|
||||||
// Block all signals to avoid unnecessary "searchRequest" signals
|
// Block all signals to avoid unnecessary "searchRequest" signals
|
||||||
// while we adjust the search text and the facet widget.
|
// 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());
|
m_facetsWidget->setFacetType(types.first());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (const Baloo::Term& subTerm, term.subTerms()) {
|
const QStringList subTerms = query.searchString().split(' ', QString::SkipEmptyParts);
|
||||||
const QString property = subTerm.property();
|
foreach (const QString& subTerm, subTerms) {
|
||||||
|
if (subTerm.startsWith("filename:")) {
|
||||||
if (property == QLatin1String("filename")) {
|
const QString value = subTerm.mid(9);
|
||||||
setText(subTerm.value().toString());
|
setText(value);
|
||||||
} else if (m_facetsWidget->isRatingTerm(subTerm)) {
|
} else if (m_facetsWidget->isRatingTerm(subTerm)) {
|
||||||
m_facetsWidget->setRatingTerm(subTerm);
|
m_facetsWidget->setRatingTerm(subTerm);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue