Request 806 (accepted)
Update to Plasma 5.1.90
Submit package home:sebas:b...l:frameworks / baloo-widgets to package home:plfiori...l:frameworks / baloo-widgets
[-] [+] | Changed | baloo-widgets.spec |
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/CMakeLists.txt ^ |
@@ -28,8 +28,16 @@ VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/baloowidgets_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5BalooWidgetsConfigVersion.cmake") +include_directories( + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_BINARY_DIR}/src + ${CMAKE_SOURCE_DIR}/src/naturalqueryparser + ${CMAKE_BINARY_DIR}/src/naturalqueryparser + ${CMAKE_BINARY_DIR}/src/naturalqueryparser/baloo +) + add_subdirectory(src) -add_subdirectory(test) +#add_subdirectory(test) add_subdirectory(autotests) # Config files | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/CMakeLists.txt ^ |
@@ -1,4 +1,5 @@ add_definitions(-DTRANSLATION_DOMAIN=\"baloowidgets\") +add_subdirectory(naturalqueryparser) set(widgets_SRCS kblocklayout.cpp @@ -16,6 +17,7 @@ groupedlineedit.cpp querybuilder.cpp querybuildercompleter.cpp + filefetchjob.cpp ) add_library(KF5BalooWidgets ${widgets_SRCS}) @@ -34,7 +36,7 @@ KF5::Completion KF5::FileMetaData KF5::WidgetsAddons - KF5::BalooFiles + KF5::Baloo KF5::BalooNaturalQueryParser KF5::CoreAddons KF5::ConfigGui | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/extractor.cpp ^ |
@@ -29,6 +29,7 @@ #include <KFileMetaData/ExtractorCollection> #include <KFileMetaData/Extractor> #include <KFileMetaData/PropertyInfo> +#include <KFileMetaData/UserMetaData> #include <iostream> @@ -60,12 +61,27 @@ QDataStream stream(&arr, QIODevice::WriteOnly); QVariantMap map; - QMapIterator<KFileMetaData::Property::Property, QVariant> it(result.properties()); while (it.hasNext()) { it.next(); KFileMetaData::PropertyInfo pi(it.key()); - map.insert(pi.name(), it.value()); + map.insertMulti(pi.name(), it.value()); + } + + KFileMetaData::UserMetaData md(url); + QStringList tags = md.tags(); + if (!tags.isEmpty()) { + map.insert("tags", tags); + } + + int rating = md.rating(); + if (rating) { + map.insert("rating", rating); + } + + QString comment = md.userComment(); + if (!comment.isEmpty()) { + map.insert("userComment", comment); } stream << map; | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/filefetchjob.cpp ^ |
@@ -0,0 +1,87 @@ +/* + * <one line to give the library's name and an idea of what it does.> + * Copyright (C) 2014 Vishesh Handa <me@vhanda.in> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "filefetchjob.h" + +#include <QTimer> +#include <Baloo/File> + +#include <KFileMetaData/UserMetaData> +#include <KFileMetaData/PropertyInfo> + +using namespace Baloo; + +FileFetchJob::FileFetchJob(const QStringList& urls, QObject* parent) + : KJob(parent) + , m_urls(urls) +{ +} + +void FileFetchJob::start() +{ + QTimer::singleShot(0, this, SLOT(doStart())); +} + +static QVariantMap convertPropertyMap(const KFileMetaData::PropertyMap& propMap) +{ + QVariantMap map; + KFileMetaData::PropertyMap::const_iterator it = propMap.constBegin(); + for (; it != propMap.constEnd(); it++) { + KFileMetaData::PropertyInfo pi(it.key()); + map.insertMulti(pi.name(), it.value()); + } + + return map; +} + +void FileFetchJob::doStart() +{ + for (const QString& filePath : m_urls) { + Baloo::File file(filePath); + file.load(); + + QVariantMap prop = convertPropertyMap(file.properties()); + + KFileMetaData::UserMetaData md(filePath); + QStringList tags = md.tags(); + if (!tags.isEmpty()) { + prop.insert("tags", tags); + } + + int rating = md.rating(); + if (rating) { + prop.insert("rating", rating); + } + + QString comment = md.userComment(); + if (!comment.isEmpty()) { + prop.insert("userComment", comment); + } + + m_data << prop; + } + + emitResult(); +} + +QList<QVariantMap> Baloo::FileFetchJob::data() const +{ + return m_data; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/filefetchjob.h ^ |
@@ -0,0 +1,48 @@ +/* + * <one line to give the library's name and an idea of what it does.> + * Copyright (C) 2014 Vishesh Handa <me@vhanda.in> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BALOO_FILEFETCHJOB_H +#define BALOO_FILEFETCHJOB_H + +#include <KJob> +#include <QVariantMap> + +namespace Baloo { + +class FileFetchJob : public KJob +{ + Q_OBJECT +public: + FileFetchJob(const QStringList& urls, QObject* parent = 0); + + QList<QVariantMap> data() const; + + virtual void start(); + +private Q_SLOTS: + void doStart(); + +private: + QStringList m_urls; + QList<QVariantMap> m_data; +}; +} + +#endif // BALOO_FILEFETCHJOB_H | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/filemetadataconfigwidget.cpp ^ |
@@ -74,8 +74,7 @@ m_provider = new FileMetaDataProvider(q); m_provider->setReadOnly(true); - connect(m_provider, SIGNAL(loadingFinished()), - q, SLOT(slotLoadingFinished())); + connect(m_provider, SIGNAL(loadingFinished()), q, SLOT(slotLoadingFinished())); } FileMetaDataConfigWidget::Private::~Private() | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/filemetadataprovider.cpp ^ |
@@ -22,9 +22,8 @@ #include "tagwidget.h" #include "kcommentwidget_p.h" #include "indexeddataretriever.h" +#include "filefetchjob.h" -#include <Baloo/FileFetchJob> -#include <Baloo/File> #include <Baloo/IndexerConfig> #include <KFileMetaData/PropertyInfo> @@ -163,40 +162,16 @@ } namespace { - QVariantMap convertPropertyMap(const KFileMetaData::PropertyMap& propMap) - { - QVariantMap map; - KFileMetaData::PropertyMap::const_iterator it = propMap.constBegin(); - for (; it != propMap.constEnd(); it++) { - KFileMetaData::PropertyInfo pi(it.key()); - map.insertMulti(pi.name(), it.value()); - } - - return map; - } } void FileMetaDataProvider::Private::slotFileFetchFinished(KJob* job) { - Baloo::FileFetchJob* fetchJob = static_cast<Baloo::FileFetchJob*>(job); - QList<Baloo::File> files = fetchJob->files(); + FileFetchJob* fetchJob = static_cast<FileFetchJob*>(job); + QList<QVariantMap> files = fetchJob->data(); if (files.size() == 1) { - Baloo::File file = files.first(); - m_data = convertPropertyMap(file.properties()); + m_data = files.first(); insertBasicData(); - - if (file.rating()) { - m_data.insert("rating", file.rating()); - } - - if (!file.tags().isEmpty()) { - m_data.insert("tags", file.tags()); - } - - if (!file.userComment().isEmpty()) { - m_data.insert("userComment", file.userComment()); - } } else { // @@ -204,28 +179,16 @@ // QSet<QString> allProperties; QList<QVariantMap> propertyList; - foreach (const Baloo::File& file, files) { - QVariantMap properties = convertPropertyMap(file.properties()); - if (file.rating()) { - properties.insert("rating", file.rating()); - } - - if (!file.tags().isEmpty()) { - properties.insert("tags", file.tags()); - } - - if (!file.userComment().isEmpty()) { - properties.insert("userComment", file.userComment()); - } - propertyList << properties; - allProperties.unite(properties.uniqueKeys().toSet()); + foreach (const QVariantMap& fileData, files) { + propertyList << fileData; + allProperties.unite(fileData.uniqueKeys().toSet()); } // Special handling for certain properties - totalPropertyAndInsert("duration", propertyList, allProperties ); - totalPropertyAndInsert("characterCount", propertyList, allProperties ); - totalPropertyAndInsert("wordCount", propertyList, allProperties ); - totalPropertyAndInsert("lineCount", propertyList, allProperties ); + totalPropertyAndInsert("duration", propertyList, allProperties); + totalPropertyAndInsert("characterCount", propertyList, allProperties); + totalPropertyAndInsert("wordCount", propertyList, allProperties); + totalPropertyAndInsert("lineCount", propertyList, allProperties); foreach (const QString& propUri, allProperties) { foreach (const QVariantMap& map, propertyList) { @@ -288,7 +251,7 @@ } else { m_data.insert("kfileitem#size", format.formatByteSize(item.size())); } - + m_data.insert("kfileitem#type", item.mimeComment()); m_data.insert("kfileitem#modified", format.formatRelativeDateTime(item.time(KFileItem::ModificationTime), QLocale::LongFormat) ); m_data.insert("kfileitem#owner", item.user()); @@ -312,7 +275,6 @@ void FileMetaDataProvider::Private::insertEditableData() { - // Insert tags, ratings and comments, if Nepomuk activated if (!m_readOnly) { if (!m_data.contains("tags")) m_data.insert("tags", QVariant()); | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/filemetadatawidget.cpp ^ |
@@ -50,6 +50,7 @@ #include <sys/types.h> #include <sys/extattr.h> #endif +#include <errno.h> // FIXME: Load the catalog properly!! //static const KCatalogLoader loader("baloowidgets"); | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/groupedlineedit.cpp ^ |
@@ -160,7 +160,7 @@ void GroupedLineEdit::paintEvent(QPaintEvent *e) { - static unsigned char colors[] = { + static const unsigned char colors[] = { 0 , 87 , 174, 243, 195, 0 , 0 , 179, 119, @@ -191,7 +191,7 @@ double(viewport()->height() - 2) ); - unsigned char *c = colors + (color_index * 3); + const unsigned char *c = colors + (color_index * 3); QColor color(c[0], c[1], c[2]); path.addRoundedRect(rectangle, 5.0, 5.0); | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/indexeddataretriever.cpp ^ |
@@ -20,20 +20,16 @@ #include "indexeddataretriever.h" -#include <QtCore/QProcess> -#include <QtCore/QFileInfo> -#include <QtCore/QStandardPaths> +#include <QProcess> +#include <QFileInfo> +#include <QStandardPaths> +#include <QDebug> using namespace Baloo; IndexedDataRetriever::IndexedDataRetriever(const QString& fileUrl, QObject* parent): KJob(parent) { - m_url = fileUrl; - - // Point to the actual file in the case of a system link - QFileInfo fileInfo(m_url); - if( fileInfo.isSymLink() ) - m_url = fileInfo.canonicalFilePath(); + m_url = QFileInfo(fileUrl).canonicalFilePath(); } IndexedDataRetriever::~IndexedDataRetriever() @@ -47,7 +43,7 @@ m_process = new QProcess(this); m_process->setReadChannel(QProcess::StandardOutput); - connect( m_process, SIGNAL(finished(int)), this, SLOT(slotIndexedFile(int)) ); + connect(m_process, static_cast<void (QProcess::*)(int)>(&QProcess::finished), this, &IndexedDataRetriever::slotIndexedFile); m_process->start(exe, QStringList() << m_url); } | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/kcommentwidget.cpp ^ |
@@ -41,7 +41,7 @@ m_label = new QLabel(this); m_label->setWordWrap(true); m_label->setAlignment(Qt::AlignTop); - connect(m_label, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString))); + connect(m_label, &QLabel::linkActivated, this, &KCommentWidget::slotLinkActivated); m_sizeHintHelper = new QLabel(this); m_sizeHintHelper->hide(); | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/kcommentwidget_p.h ^ |
@@ -22,7 +22,7 @@ #define KCOMMENT_WIDGET #include <QtCore/QString> -#include <QtWidgets//QWidget> +#include <QtWidgets/QWidget> class QLabel; | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/kedittagsdialog.cpp ^ |
@@ -69,8 +69,8 @@ QLabel* newTagLabel = new QLabel(i18nc("@label", "Create new tag:")); m_newTagEdit = new QLineEdit(this); m_newTagEdit->setClearButtonEnabled(true); - connect(m_newTagEdit, SIGNAL(textEdited(QString)), - this, SLOT(slotTextEdited(QString))); + m_newTagEdit->setFocus(); + connect(m_newTagEdit, &QLineEdit::textEdited, this, &KEditTagsDialog::slotTextEdited); QHBoxLayout* newTagLayout = new QHBoxLayout(); newTagLayout->addWidget(newTagLabel); @@ -161,7 +161,7 @@ void KEditTagsDialog::loadTags() { Baloo::TagListJob* job = new Baloo::TagListJob(); - connect(job, SIGNAL(finished(KJob*)), this, SLOT(slotTagsLoaded(KJob*))); + connect(job, &Baloo::TagListJob::finished, this, &KEditTagsDialog::slotTagsLoaded); job->start(); } | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser ^ |
+(directory) | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/CMakeLists.txt ^ |
@@ -0,0 +1,66 @@ +remove_definitions(-DTRANSLATION_DOMAIN) +add_definitions(-DTRANSLATION_DOMAIN=\"baloo_naturalqueryparser\") + +set(QUERYPARSER_SRCS + completionproposal.cpp + pass_comparators.cpp + pass_dateperiods.cpp + pass_datevalues.cpp + pass_decimalvalues.cpp + pass_filenames.cpp + pass_filesize.cpp + pass_numbers.cpp + pass_periodnames.cpp + pass_properties.cpp + pass_propertyinfo.cpp + pass_splitunits.cpp + pass_subqueries.cpp + pass_typehints.cpp + patternmatcher.cpp + naturalqueryparser.cpp + naturalfilequeryparser.cpp + utils.cpp +) + +add_library(KF5BalooNaturalQueryParser ${QUERYPARSER_SRCS}) +add_library(KF5::BalooNaturalQueryParser ALIAS KF5BalooNaturalQueryParser) + +target_link_libraries(KF5BalooNaturalQueryParser + KF5::Baloo + KF5::KDELibs4Support + KF5::FileMetaData +) + +set_target_properties(KF5BalooNaturalQueryParser PROPERTIES + VERSION ${BALOO_WIDGETS_VERSION} + SOVERSION ${BALOO_WIDGETS_VERSION} + EXPORT_NAME BalooNaturalQueryParser +) + +generate_export_header(KF5BalooNaturalQueryParser BASE_NAME BALOO_NATURALQUERYPARSER EXPORT_FILE_NAME naturalqueryparser_export.h) +ecm_generate_headers(KF5BalooNaturalQueryParser_CamelCase_HEADERS + HEADER_NAMES + CompletionProposal + NaturalQueryParser + NaturalFileQueryParser + + PREFIX baloo + REQUIRED_HEADERS KF5BalooNaturalQueryParser_HEADERS +) + +install(TARGETS KF5BalooNaturalQueryParser EXPORT KF5BalooWidgetsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/naturalqueryparser_export.h + ${KF5BalooNaturalQueryParser_HEADERS} + DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/Baloo/baloo + COMPONENT Devel +) + +install(FILES + ${KF5BalooNaturalQueryParser_CamelCase_HEADERS} + DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/Baloo/Baloo + COMPONENT Devel +) + +add_subdirectory(autotests) | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/Messages.sh ^ |
@@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT `find . -name "*.cpp" | grep -v "/autotests/"` -o $podir/baloo_naturalqueryparser.pot | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/autotests ^ |
+(directory) | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/autotests/CMakeLists.txt ^ |
@@ -0,0 +1,9 @@ +# +# Query Parser +# +set(queryParser_SRC naturalqueryparsertest.cpp) + +ecm_add_test(naturalqueryparsertest.cpp + TEST_NAME "naturalqueryparsertest" + LINK_LIBRARIES Qt5::Test KF5::Baloo KF5BalooNaturalQueryParser +) | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/autotests/naturalqueryparsertest.cpp ^ |
@@ -0,0 +1,159 @@ +/* + * This file is part of the Baloo Query Parser + * Copyright (C) 2014 Denis Steckelmacher <steckdenis@yahoo.fr> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "naturalqueryparsertest.h" + +#include <Baloo/Query> +#include <Baloo/Term> + +#include "../naturalfilequeryparser.h" + +#include <qtest_kde.h> + +#include <QtCore/QDateTime> + +using namespace Baloo; + +namespace QTest { + template<> + char *toString(const Query &query) + { + Query *q = const_cast<Query *>(&query); // query.toJSON does not modify query but is not marked const + + return qstrdup(q->toJSON().constData()); + } +} + + +void NaturalQueryParserTest::testSearchString() +{ + QString search_string(QLatin1String("correct horse battery staple ")); + + QCOMPARE( + NaturalFileQueryParser::parseQuery(search_string).searchString(), + search_string + ); +} + +void NaturalQueryParserTest::testNumbers() +{ + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("size > 1024")), + Query(Term(QLatin1String("size"), 1024LL, Term::Greater)) + ); +} + +void NaturalQueryParserTest::testDecimal() +{ + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("size > 1024.38")), + Query(Term(QLatin1String("size"), 1024.38, Term::Greater)) + ); +} + +void NaturalQueryParserTest::testFilesize() +{ + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("size > 2K")), + Query(Term(QLatin1String("size"), 2048, Term::Greater)) + ); +} + +void NaturalQueryParserTest::testDatetime() +{ + Query expected; + QDateTime now = QDateTime::currentDateTime(); + + // Today + expected.setDateFilter(now.date().year(), now.date().month(), now.date().day()); + expected.setTerm(Term()); + + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("today")), + expected + ); + + // Yesterday + now = now.addDays(-1); + expected.setDateFilter(now.date().year(), now.date().month(), now.date().day()); + + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("yesterday")), + expected + ); + + // A specific date + expected.setDateFilter(2011, 1, 2); + + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("January 2, 2011")), + expected + ); +} + +void NaturalQueryParserTest::testFilename() +{ + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("\"*.txt\""), NaturalQueryParser::DetectFilenamePattern), + Query(Term(QLatin1String("filename"), QRegExp(QLatin1String("^.*\\\\.txt$")), Term::Contains)) + ); +} + +void NaturalQueryParserTest::testTypehints() +{ + Query expected; + + expected.setType(QLatin1String("Email")); + + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("emails")), + expected + ); +} + +void NaturalQueryParserTest::testReduction() +{ + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("size > 2K and size < 3K")), + Query(Term(QLatin1String("size"), 2048, Term::Greater) && Term(QLatin1String("size"), 3072, Term::Less)) + ); + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("size > 2K or size < 3K")), + Query(Term(QLatin1String("size"), 2048, Term::Greater) || Term(QLatin1String("size"), 3072, Term::Less)) + ); +} + +void NaturalQueryParserTest::testTags() +{ + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("tagged as Important")), + Query(Term(QLatin1String("tags"), QLatin1String("Important"), Term::Contains)) + ); +} + +void NaturalQueryParserTest::testPropertyInfo() +{ + QCOMPARE( + NaturalFileQueryParser::parseQuery(QLatin1String("bitRate > 44000")), + Query(Term(QLatin1String("bitRate"), 44000, Term::Greater)) + ); +} + +QTEST_KDEMAIN_CORE(NaturalQueryParserTest) | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/autotests/naturalqueryparsertest.h ^ |
@@ -0,0 +1,46 @@ +/* + * This file is part of the Baloo Query Parser + * Copyright (C) 2014 Denis Steckelmacher <steckdenis@yahoo.fr> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef BALOO_NATURALQUERYPARSERTEST_H +#define BALOO_NATURALQUERYPARSERTEST_H + +#include <QObject> + +namespace Baloo { + +class NaturalQueryParserTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testSearchString(); + void testNumbers(); + void testDecimal(); + void testFilesize(); + void testDatetime(); + void testFilename(); + void testTypehints(); + void testReduction(); + void testTags(); + void testPropertyInfo(); +}; +} + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/completionproposal.cpp ^ |
@@ -0,0 +1,85 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "completionproposal.h" + +#include "klocalizedstring.h" + +using namespace Baloo; + +struct CompletionProposal::Private +{ + QStringList pattern; + int last_matched_part; + int position; + int length; + CompletionProposal::Type type; + KLocalizedString description; +}; + +CompletionProposal::CompletionProposal(const QStringList &pattern, + int last_matched_part, + int position, + int length, + Type type, + const KLocalizedString &description) +: d(new Private) +{ + d->pattern = pattern; + d->last_matched_part = last_matched_part; + d->position = position; + d->length = length; + d->type = type; + d->description = description; +} + +CompletionProposal::~CompletionProposal() +{ + delete d; +} + +int CompletionProposal::position() const +{ + return d->position; +} + +int CompletionProposal::length() const +{ + return d->length; +} + +int CompletionProposal::lastMatchedPart() const +{ + return d->last_matched_part; +} + +QStringList CompletionProposal::pattern() const +{ + return d->pattern; +} + +CompletionProposal::Type CompletionProposal::type() const +{ + return d->type; +} + +KLocalizedString CompletionProposal::description() const +{ + return d->description; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/completionproposal.h ^ |
@@ -0,0 +1,124 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __BALOO_SEARCH_COMPLETION_PROPOSAL_H__ +#define __BALOO_SEARCH_COMPLETION_PROPOSAL_H__ + +#include <QtCore/QtGlobal> +#include <QtCore/QStringList> + +#include "naturalqueryparser_export.h" +#include "klocalizedstring.h" + +namespace Baloo +{ + +/** + * \class CompletionProposal completionproposal.h Baloo/Query/CompletionProposal + * \brief Information about an auto-completion proposal + * + * When parsing an user query, QueryParser may find that a pattern that nearly + * matches and that the user may want to use. In this case, one or more + * completion proposals are used to describe what patterns can be used. + */ +class BALOO_NATURALQUERYPARSER_EXPORT CompletionProposal +{ + private: + Q_DISABLE_COPY(CompletionProposal) + + public: + /** + * \brief Data-type used by the first placeholder of the pattern + * + * If the pattern is "sent by $1", the type of "$1" is Contact. This + * way, a GUI can show to the user a list of his or her contacts. + */ + enum Type + { + NoType, /*!< No specific type (integer, string, something that does not need any auto-completion list) */ + DateTime, /*!< A date-time */ + Tag, /*!< A valid tag name */ + Contact, /*!< Something that can be parsed unambiguously to a contact (a contact name, email, pseudo, etc) */ + Email, /*!< An e-mail address */ + PropertyName, /*!< A property name. List of these names can be found in kde:kfilemetadata/src/propertyinfo.h */ + }; + + /** + * \param pattern list of terms matched by the proposal ("sent", + * "by", "$1" for instance) + * \param last_matched_part index of the last part of the mattern + * that has been matched against the user + * query + * \param position position in the user query of the pattern matched + * \param length length in the user query of the terms matched + * \param type if the pattern contains "$1", this is the type of + * the value matched by this placeholder + * \param description human description of the pattern + */ + CompletionProposal(const QStringList &pattern, + int last_matched_part, + int position, + int length, + Type type, + const KLocalizedString &description); + ~CompletionProposal(); + + /** + * \return list of terms that make the pattern + */ + QStringList pattern() const; + + /** + * \return index of the last matched part of the pattern + */ + int lastMatchedPart() const; + + /** + * \return position in the user query of the pattern + * + * As an user query can contain spaces and separators that are + * ignored by the pattern matcher, position() and length() are + * used to find the sub-string of the user query that has matched + * against the pattern. + */ + int position() const; + + /** + * \sa position + */ + int length() const; + + /** + * \return type of the value represented by the "$1" term in the pattern + */ + Type type() const; + + /** + * \return description of the pattern + */ + KLocalizedString description() const; + + private: + struct Private; + Private *const d; +}; + +} + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/naturalfilequeryparser.cpp ^ |
@@ -0,0 +1,93 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "naturalfilequeryparser.h" +#include "naturalqueryparser_p.h" +#include "pass_properties.h" +#include "pass_propertyinfo.h" + +using namespace Baloo; + +struct NaturalFileQueryParser::Private +{ + PassPropertyInfo pass_propertyinfo; +}; + +NaturalFileQueryParser::NaturalFileQueryParser() +: d(new Private) +{ +} + +NaturalFileQueryParser::~NaturalFileQueryParser() +{ + delete d; +} + +void NaturalFileQueryParser::addSpecificPatterns(int cursor_position, NaturalQueryParser::ParserFlags flags) const +{ + NaturalQueryParser::addSpecificPatterns(cursor_position, flags); + + // Properties associated with any Baloo resource + passProperties().setProperty(QLatin1String("rating"), PassProperties::Integer); + runPass(passProperties(), cursor_position, + i18nc("Numeric rating of a resource", "rated as $1;rated $1;score is $1;score|scored $1;having $1 stars|star"), + ki18n("Rating (0 to 10)"), CompletionProposal::NoType); + passProperties().setProperty(QLatin1String("usercomment"), PassProperties::String); + runPass(passProperties(), cursor_position, + i18nc("Comment of a resource", "described as $1;description|comment is $1;described|description|comment $1"), + ki18n("Comment or description"), CompletionProposal::NoType); + + // File-related properties + passProperties().setProperty(QLatin1String("author"), PassProperties::Contact); + runPass(passProperties(), cursor_position, + i18nc("Author of a document", "written|created|composed by $1;author is $1;by $1"), + ki18n("Author"), CompletionProposal::Contact); + passProperties().setProperty(QLatin1String("size"), PassProperties::IntegerOrDouble); + runPass(passProperties(), cursor_position, + i18nc("Size of a file", "size is $1;size $1;being $1 large;$1 large"), + ki18n("Size")); + passProperties().setProperty(QLatin1String("filename"), PassProperties::String); + runPass(passProperties(), cursor_position, + i18nc("Name of a file or contact", "name is $1;name $1;named $1"), + ki18n("Name")); + passProperties().setProperty(QLatin1String("_k_datecreated"), PassProperties::DateTime); + runPass(passProperties(), cursor_position, + i18nc("Date of creation", "created|dated at|on|in|of $1;created|dated $1;creation date|time|datetime is $1"), + ki18n("Date of creation"), CompletionProposal::DateTime); + passProperties().setProperty(QLatin1String("_k_datemodified"), PassProperties::DateTime); + runPass(passProperties(), cursor_position, + i18nc("Date of last modification", "modified|edited at|on $1;modified|edited $1;modification|edition date|time|datetime is $1"), + ki18n("Date of last modification"), CompletionProposal::DateTime); + + // Tags + passProperties().setProperty(QLatin1String("tags"), PassProperties::Tag); + runPass(passProperties(), cursor_position, + i18nc("A document is associated with a tag", "tagged as $1;has tag $1;tag is $1;# $1"), + ki18n("Tag name"), CompletionProposal::Tag); + + // Generic properties using a simpler and more discoverable syntax + runPass(d->pass_propertyinfo, cursor_position, + i18nc("$1 is a property name (non-translatable unfortunately) and $2 is the value against which the property is matched. Note that the equal/greater/smaller sign has already been folded in $2", "$1 is $2;$1 $2"), + ki18n("File property"), CompletionProposal::PropertyName); +} + +Query NaturalFileQueryParser::parseQuery(const QString& query, ParserFlags flags) +{ + return NaturalFileQueryParser().parse(query, flags); +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/naturalfilequeryparser.h ^ |
@@ -0,0 +1,72 @@ +/* + This file is part of the Baloo KDE project. + Copyright (C) 2007-2010 Sebastian Trueg <trueg@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef _BALOO_NATURAL_FILE_QUERY_PARSER_H_ +#define _BALOO_NATURAL_FILE_QUERY_PARSER_H_ + +#include "naturalqueryparser.h" + +namespace Baloo { +/** + * \class NaturalFileQueryParser naturalqueryparser.h baloo/naturalqueryparser.h + * + * \brief Parser for desktop file user queries. + * + * Natural query parser tailored for File queries. It extends NaturalQueryParser + * (please read its documentation for advice and important notices) by providing + * patterns specifically targetting file queries. For instance, the user can + * specify which type a file must have, or what its size should be. + */ +class BALOO_NATURALQUERYPARSER_EXPORT NaturalFileQueryParser : public NaturalQueryParser +{ +public: + /** + * Create a new query parser. + */ + NaturalFileQueryParser(); + + /** + * Destructor + */ + ~NaturalFileQueryParser(); + + /** + * Convenience method to quickly parse a query without creating an object. + * + * \warning The parser caches many useful information that is slow to + * retrieve from the Baloo database. If you have to parse + * many queries, consider using a QueryParser object. + * + * \param query The query string to parse + * \param flags a set of flags influencing the parsing process. + * \return The parsed query or an invalid Query object in case the parsing failed. + */ + static Query parseQuery( const QString& query, ParserFlags flags = NoParserFlags); + +protected: + virtual void addSpecificPatterns(int cursor_position, NaturalQueryParser::ParserFlags flags) const; + +private: + struct Private; + Private *d; +}; + +} + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/naturalqueryparser.cpp ^ |
@@ -0,0 +1,788 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "naturalqueryparser.h" +#include "naturalqueryparser_p.h" +#include "completionproposal.h" +#include "utils.h" + +#include "pass_splitunits.h" +#include "pass_numbers.h" +#include "pass_decimalvalues.h" +#include "pass_filenames.h" +#include "pass_filesize.h" +#include "pass_typehints.h" +#include "pass_properties.h" +#include "pass_dateperiods.h" +#include "pass_datevalues.h" +#include "pass_periodnames.h" +#include "pass_subqueries.h" +#include "pass_comparators.h" + +#include <Baloo/Term> +#include <Baloo/Query> + +#include <klocale.h> +#include <kcalendarsystem.h> +#include <klocalizedstring.h> + +#include <QtCore/QList> + +using namespace Baloo; + +struct Field { + enum Flags { + Unset = 0, + Absolute, + Relative + }; + + int value; + Flags flags; + + void reset() + { + value = 0; + flags = Unset; + } +}; + +struct DateTimeSpec { + Field fields[PassDatePeriods::MaxPeriod]; + + void reset() + { + for (int i=0; i<int(PassDatePeriods::MaxPeriod); ++i) { + fields[i].reset(); + } + } +}; + +struct NaturalQueryParser::Private +{ + Private() + : separators(i18nc( + "Characters that are kept in the query for further processing but are considered word boundaries", + ".,;:!?()[]{}<>=#+-")) + { + } + + void foldDateTimes(); + void handleDateTimeComparison(DateTimeSpec &spec, const Term &term); + + Term intervalComparison(const QString &prop, + const Term &min, + const Term &max); + Term dateTimeComparison(const QString &prop, + const Term &term); + Term tuneTerm(Term term, Query &query); + + NaturalQueryParser *parser; + QList<Term> terms; + QList<CompletionProposal *> proposals; + + // Parsing passes (they cache translations, queries, etc) + PassSplitUnits pass_splitunits; + PassNumbers pass_numbers; + PassDecimalValues pass_decimalvalues; + PassFileNames pass_filenames; + PassFileSize pass_filesize; + PassTypeHints pass_typehints; + PassComparators pass_comparators; + PassProperties pass_properties; + PassDatePeriods pass_dateperiods; + PassDateValues pass_datevalues; + PassPeriodNames pass_periodnames; + PassSubqueries pass_subqueries; + + // Locale-specific + QString separators; +}; + +NaturalQueryParser::NaturalQueryParser() +: d(new Private) +{ + d->parser = this; +} + +NaturalQueryParser::~NaturalQueryParser() +{ + qDeleteAll(d->proposals); + delete d; +} + +Query NaturalQueryParser::parse(const QString &query, ParserFlags flags, int cursor_position) const +{ + qDeleteAll(d->proposals); + + d->terms.clear(); + d->proposals.clear(); + + // Split the query into terms + QList<int> positions; + QStringList parts = split(query, true, &positions); + + for (int i=0; i<parts.count(); ++i) { + const QString &part = parts.at(i); + int position = positions.at(i); + int length = part.length(); + + if (position > 0 && + query.at(position - 1) == QLatin1Char('"')) { + // Absorb the starting quote into the term's position + --position; + ++length; + } + if (position + length < query.length() && + query.at(position + length) == QLatin1Char('"')) { + // Absorb the ending quote into the term's position + ++length; + } + + d->terms.append(Term(QString(), part, Term::Equal)); + setTermRange(d->terms.last(), position, position + length - 1); + } + + // Run the parsing passes + addSpecificPatterns(cursor_position, flags); + + // Product the query + int unused; + Term term = fuseTerms(d->terms, 0, unused); + Query rs; + + rs.setTerm(d->tuneTerm(term, rs)); + + return rs; +} + +QList<CompletionProposal *> NaturalQueryParser::completionProposals() const +{ + return d->proposals; +} + +void NaturalQueryParser::addSpecificPatterns(int cursor_position, NaturalQueryParser::ParserFlags flags) const +{ + // Prepare literal values + runPass(d->pass_splitunits, cursor_position, QLatin1String("$1")); + runPass(d->pass_numbers, cursor_position, QLatin1String("$1")); + runPass(d->pass_filesize, cursor_position, QLatin1String("$1 $2")); + runPass(d->pass_typehints, cursor_position, QLatin1String("$1")); + + if (flags & DetectFilenamePattern) { + runPass(d->pass_filenames, cursor_position, QLatin1String("$1")); + } + + // Date-time periods + runPass(d->pass_periodnames, cursor_position, QLatin1String("$1")); + + d->pass_dateperiods.setKind(PassDatePeriods::VariablePeriod, PassDatePeriods::Offset); + runPass(d->pass_dateperiods, cursor_position, + i18nc("Adding an offset to a period of time ($1=period, $2=offset)", "in $2 $1")); + d->pass_dateperiods.setKind(PassDatePeriods::VariablePeriod, PassDatePeriods::InvertedOffset); + runPass(d->pass_dateperiods, cursor_position, | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/naturalqueryparser.h ^ |
@@ -0,0 +1,185 @@ +/* + This file is part of the Baloo KDE project. + Copyright (C) 2007-2010 Sebastian Trueg <trueg@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#ifndef _BALOO_NATURAL_QUERY_PARSER_H_ +#define _BALOO_NATURAL_QUERY_PARSER_H_ + +#include <Baloo/Query> +#include "completionproposal.h" +#include "naturalqueryparser_export.h" + +#include <QtCore/QString> + +class PatternMatcher; +class PassProperties; + +namespace Baloo { +/** + * \class NaturalQueryParser naturalqueryparser.h baloo/naturalqueryparser.h + * + * \brief Parser for desktop user queries. + * + * \warning This is NOT a SPARQL parser. + * \note Don't forget to insert the "baloo_naturalqueryparser" localization catalog + * for this class to be localized. Do so using KLocale::insertCatalog. + * + * The NaturalQueryParser can be used to parse user queries, ie. queries that the user + * would enter in any search interface, and convert them into Query instances. + * + * The syntax is language-dependent and as natural as possible. Words are + * by default matched against the content of documents, and special patterns + * like "sent by X" are recognized and changed to property comparisons. + * + * Natural date-times can also be used and are recognized as date-time + * literals. "sent on March 6" and "created last week" work as expected. + * + * \section naturalqueryparser_examples Examples + * + * %Query everything that contains the term "baloo": + * \code + * baloo + * \endcode + * + * %Query everything that contains both the terms "Hello" and "World": + * \code + * Hello World + * \endcode + * + * %Query everything that contains the term "Hello World": + * \code + * "Hello World" + * \endcode + * + * %Query everything that has a tag whose label matches "baloo": + * \code + * tagged as baloo, has tag baloo + * \endcode + * + * %Query everything that has a tag labeled "baloo" or a tag labeled "scribo": + * \code + * tagged as baloo OR tagged as scribo + * \endcode + * + * \note "tagged as baloo or scribo" currently does not work as expected + * + * %Query everything that has a tag labeled "baloo" but not a tag labeled "scribo": + * \code + * tagged as baloo and not tagged as scribo + * \endcode + * + * Some properties also accept nested queries. For instance, this %Query + * returns the list of documents related to emails tagged as important. + * \code + * documents related to mails tagged as important + * \endcode + * + * More complex nested queries can be built, and are ended with a comma + * (in English): + * \code + * documents related to mails from Smith and tagged as important, size > 2M + * \endcode + * + * \author Denis Steckelmacher <steckdenis@yahoo.fr> + * + * \since 4.14 + */ +class BALOO_NATURALQUERYPARSER_EXPORT NaturalQueryParser +{ +public: + /** + * Create a new query parser. + */ + NaturalQueryParser(); + + /** + * Destructor + */ + virtual ~NaturalQueryParser(); + + /** + * Flags to change the behaviour of the parser. + */ + enum ParserFlag { + /** + * No flags. Default for parse() + */ + NoParserFlags = 0x0, + + /** + * Try to detect filename pattern like *.mp3 + * or hello*.txt and use regular expressions to match these terms + */ + DetectFilenamePattern = 0x1 + }; + Q_DECLARE_FLAGS( ParserFlags, ParserFlag ) + + /** + * Parse a user query. + * + * \param query The query string to parse + * \param flags a set of flags influencing the parsing process. + * \param cursor_position position of the cursor in a line edit used + * by the user to enter the query. It is used + * to provide auto-completion proposals. + * + * \return The parsed query or an invalid Query object + * in case the parsing failed. + */ + Query parse(const QString& query, + ParserFlags flags = NoParserFlags, + int cursor_position = -1) const; + + /** + * List of completion proposals related to the previously parsed query + * + * \note The query parser is responsible for deleting the CompletionProposal + * objects. + */ + QList<CompletionProposal *> completionProposals() const; + +private: + void addCompletionProposal(CompletionProposal *proposal) const; + QStringList split(const QString &query, bool is_user_query, QList<int> *positions = NULL) const; + QList<Term> &terms() const; + +protected: + virtual void addSpecificPatterns(int cursor_position, NaturalQueryParser::ParserFlags flags) const; + + template<typename T> + void runPass(const T &pass, + int cursor_position, + const QString &pattern, + const KLocalizedString &description = KLocalizedString(), + CompletionProposal::Type type = CompletionProposal::NoType) const; + + // Some passes that subclass may want to use + PassProperties &passProperties() const; + +private: + struct Private; + Private* const d; + + friend class ::PatternMatcher; +}; + +} + +Q_DECLARE_OPERATORS_FOR_FLAGS(Baloo::NaturalQueryParser::ParserFlags) + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/naturalqueryparser_p.h ^ |
@@ -0,0 +1,32 @@ +#ifndef __BALOO_NATURALQUERYPARSER_P_H__ +#define __BALOO_NATURALQUERYPARSER_P_H__ + +#include "naturalqueryparser.h" +#include "patternmatcher.h" + +namespace Baloo +{ + +template<typename T> +void NaturalQueryParser::runPass(const T &pass, + int cursor_position, + const QString &pattern, + const KLocalizedString &description, + CompletionProposal::Type type) const +{ + // Split the pattern at ";" characters, as a locale can have more than one + // pattern that can be used for a given rule + QStringList rules = pattern.split(QLatin1Char(';')); + + Q_FOREACH(const QString &rule, rules) { + // Split the rule into parts that have to be matched + QStringList parts = split(rule, false); + PatternMatcher matcher(this, terms(), cursor_position, parts, type, description); + + matcher.runPass(pass); + } +} + +} + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_comparators.cpp ^ |
@@ -0,0 +1,41 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_comparators.h" + +PassComparators::PassComparators() +: comparator(Baloo::Term::Equal) +{ +} + +void PassComparators::setComparator(Baloo::Term::Comparator comparator) +{ + this->comparator = comparator; +} + +QList<Baloo::Term> PassComparators::run(const QList<Baloo::Term> &match) const +{ + Baloo::Term term(match.at(0)); + + // Set the comparator of the term and ignore the property and the value, that + // will be (or are already) filled by other passes + term.setComparator(comparator); + + return QList<Baloo::Term>() << term; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_comparators.h ^ |
@@ -0,0 +1,40 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_COMPARATORS_H__ +#define __PASS_COMPARATORS_H__ + +#include <QtCore/QList> + +#include <Baloo/Term> + +class PassComparators +{ + public: + PassComparators(); + + void setComparator(Baloo::Term::Comparator comparator); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + Baloo::Term::Comparator comparator; +}; + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_dateperiods.cpp ^ |
@@ -0,0 +1,127 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_dateperiods.h" +#include "utils.h" + +#include <Baloo/Term> + +#include <klocalizedstring.h> + +PassDatePeriods::PassDatePeriods() +: period(Year), + value_type(Value), + value(0) +{ + registerPeriod(Year, + i18nc("Space-separated list of words representing a year", "year years")); + registerPeriod(Month, + i18nc("Space-separated list of words representing a month", "month months")); + registerPeriod(Week, + i18nc("Space-separated list of words representing a week", "week weeks")); + registerPeriod(Day, + i18nc("Space-separated list of words representing a day", "day days")); + registerPeriod(Hour, + i18nc("Space-separated list of words representing an hour", "hour hours")); + registerPeriod(Minute, + i18nc("Space-separated list of words representing a minute", "minute minutes")); + registerPeriod(Second, + i18nc("Space-separated list of words representing a second", "second seconds")); + + periods.insert(nameOfPeriod(DayOfWeek), DayOfWeek); +} + +void PassDatePeriods::registerPeriod(Period period, const QString &names) +{ + Q_FOREACH(const QString &name, names.split(QLatin1Char(' '))) { + periods.insert(name, period); + } + + // Also insert the plain English name, used to get the period corresponding + // to a name extracted from an URL + periods.insert(nameOfPeriod(period), period); +} + +void PassDatePeriods::setKind(PassDatePeriods::Period period, PassDatePeriods::ValueType value_type, int value) +{ + this->period = period; + this->value_type = value_type; + this->value = value; +} + +QString PassDatePeriods::nameOfPeriod(Period period) +{ + static const char *const period_names[] = { + "year", "month", "week", "dayofweek", "day", "hour", "minute", "second", "" + }; + + return QLatin1String(period_names[(int)period]); +} + +PassDatePeriods::Period PassDatePeriods::periodFromName(const QString &name) const +{ + return periods.value(name); +} + +QString PassDatePeriods::propertyName(Period period, bool offset) +{ + return QString::fromLatin1("_k_date_%1_%2") + .arg(nameOfPeriod(period)) + .arg(QLatin1String(offset ? "offset" : "value")); +} + +QList<Baloo::Term> PassDatePeriods::run(const QList<Baloo::Term> &match) const +{ + int value_match_index = 0; + + Period p = period; + long long v = value; + + if (p == VariablePeriod && !match.isEmpty()) { + // Parse the period from match.at(0) + QString period_name = stringValueIfLiteral(match.at(0)); + + if (period_name.isNull() || !periods.contains(period_name)) { + return QList<Baloo::Term>(); + } + + p = periodFromName(period_name); + value_match_index = 1; + } + + if (v == 0 && value_match_index < match.count()) { + // Parse the value either from match.at(0) (there was no period) or + // match.at(1) + const Baloo::Term &period_value = match.at(value_match_index); + + if (period_value.value().type() != QVariant::LongLong) { + return QList<Baloo::Term>(); + } + + v = period_value.value().toLongLong(); + } + + // Create a comparison on the right "property", that will be used in a later + // pass to build a real date-time object + return QList<Baloo::Term>() << Baloo::Term( + propertyName(p, value_type != Value), + value_type == InvertedOffset ? -v : v, + Baloo::Term::Equal + ); +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_dateperiods.h ^ |
@@ -0,0 +1,74 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_DATEPERIODS_H__ +#define __PASS_DATEPERIODS_H__ + +#include <QtCore/QString> +#include <QtCore/QList> +#include <QtCore/QHash> +#include <QtCore/QUrl> + +namespace Baloo { class Term; } + +class PassDatePeriods +{ + public: + enum Period { + Year = 0, + Month, + Week, + DayOfWeek, + Day, + Hour, + Minute, + Second, + VariablePeriod, + MaxPeriod = VariablePeriod + }; + + enum ValueType { + Value, + Offset, + InvertedOffset + }; + + public: + PassDatePeriods(); + + void setKind(Period period, ValueType value_type, int value = 0); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + Period periodFromName(const QString &name) const; + static QString nameOfPeriod(Period period); + static QString propertyName(Period period, bool offset); + + private: + void registerPeriod(Period period, const QString &names); + + private: + QHash<QString, Period> periods; + + Period period; + ValueType value_type; + int value; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_datevalues.cpp ^ |
@@ -0,0 +1,112 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_datevalues.h" +#include "pass_dateperiods.h" +#include "utils.h" + +#include <Baloo/Term> + +PassDateValues::PassDateValues() +: pm(false) +{ +} + +void PassDateValues::setPm(bool pm) +{ + this->pm = pm; +} + +QList<Baloo::Term> PassDateValues::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + bool valid_input = true; + bool progress = false; + + static const PassDatePeriods::Period periods[7] = { + PassDatePeriods::Year, PassDatePeriods::Month, PassDatePeriods::Day, + PassDatePeriods::DayOfWeek, PassDatePeriods::Hour, PassDatePeriods::Minute, + PassDatePeriods::Second + }; + // Conservative minimum values (not every calendar already reached year 2000+) + static const int min_values[7] = { + 0 /* Y */, 1 /* M */, 1 /* D */, 1 /* DW */, 0 /* H */, 0 /* M */, 0 /* S */ + }; + // Conservative maximum values (some calendars may have months of 100+ days) + static const int max_values[7] = { + 1<<30 /* Y */, 60 /* M */, 500 /* D */, 7 /* DW */, 24 /* H */, 60 /* M */, 60 /* S */ + }; + + // See if a match sets a value for any period + for (int i=0; i<7; ++i) { + PassDatePeriods::Period period = periods[i]; + + if (i < match.count() && match.at(i).value().isValid()) { + const Baloo::Term &term = match.at(i); + bool value_is_integer; + long long value = term.value().toLongLong(&value_is_integer); + + if (term.property().startsWith(QLatin1String("_k_date"))) { + // The term is already a date part, no need to change it + rs.append(term); + continue; + } + + if (!term.property().isNull()) { + // This term has already a property (and is therefore a comparison) + valid_input = false; + break; + } + + if (!value_is_integer) { + // Something that is neither a date part nor a valid integer + valid_input = false; + break; + } + + if (value < min_values[i] || value > max_values[i]) { + // Integer too big or too small to be a valid date part + valid_input = false; + break; + } + + if (period == PassDatePeriods::Hour && pm) { + value += 12; + } + + // Build a comparison of the right type + Baloo::Term comparison( + PassDatePeriods::propertyName(period, false), + value, + Baloo::Term::Equal + ); + + copyTermRange(comparison, term); + + progress = true; + rs.append(comparison); + } + } + + if (!valid_input || !progress) { + rs.clear(); + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_datevalues.h ^ |
@@ -0,0 +1,40 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_DATEVALUES_H__ +#define __PASS_DATEVALUES_H__ + +#include <QtCore/QList> + +namespace Baloo { class Term; } + +class PassDateValues +{ + public: + PassDateValues(); + + void setPm(bool pm); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + bool pm; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_decimalvalues.cpp ^ |
@@ -0,0 +1,64 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_decimalvalues.h" +#include "utils.h" + +#include <Baloo/Term> + +static const double scales[] = { + 1.0, + 0.1, + 0.01, + 0.001, + 0.0001, + 0.00001, + 0.000001, + 0.0000001, + 0.00000001, + 0.000000001, + 0.0000000001, + 0.00000000001, + 0.000000000001 +}; + +QList<Baloo::Term> PassDecimalValues::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + bool has_integer_part; + bool has_decimal_part; + long long integer_part = longValueIfLiteral(match.at(0), &has_integer_part); + long long decimal_part = longValueIfLiteral(match.at(1), &has_decimal_part); + int decimal_length = termEnd(match.at(1)) - termStart(match.at(1)) + 1; + + if (has_integer_part && + has_decimal_part && + decimal_length <= 12) { + + double scale = scales[decimal_length]; + + rs.append(Baloo::Term( + QString(), + double(integer_part) + (double(decimal_part) * scale), + Baloo::Term::Equal + )); + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_decimalvalues.h ^ |
@@ -0,0 +1,33 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_DECIMALVALUES_H__ +#define __PASS_DECIMALVALUES_H__ + +#include <QtCore/QList> + +namespace Baloo { class Term; } + +class PassDecimalValues +{ + public: + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_filenames.cpp ^ |
@@ -0,0 +1,58 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_filenames.h" +#include "utils.h" + +#include <Baloo/Term> + +#include <QtCore/QRegExp> + +QList<Baloo::Term> PassFileNames::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + const QString value = stringValueIfLiteral(match.at(0)); + + if (value.contains(QLatin1Char('.'))) { + if (value.contains(QLatin1Char('*')) || value.contains(QLatin1Char('?'))) { + // Filename globbing (original code here from Vishesh Handa) + QString regex = QRegExp::escape(value); + + regex.replace(QLatin1String("\\*"), QLatin1String(".*")); + regex.replace(QLatin1String("\\?"), QLatin1String(".")); + regex.replace(QLatin1String("\\"), QLatin1String("\\\\")); + regex.prepend(QLatin1Char('^')); + regex.append(QLatin1Char('$')); + + rs.append(Baloo::Term( + QLatin1String("filename"), + QRegExp(regex), // NOTE: QRegExp::toString gives the literal value entered by the user, but some backends may want to use the actual QRegExp object + Baloo::Term::Contains + )); + } else { + rs.append(Baloo::Term( + QLatin1String("filename"), + value, + Baloo::Term::Contains + )); + } + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_filenames.h ^ |
@@ -0,0 +1,33 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_FILENAMES_H__ +#define __PASS_FILENAMES_H__ + +#include <QtCore/QList> + +namespace Baloo { class Term; } + +class PassFileNames +{ + public: + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_filesize.cpp ^ |
@@ -0,0 +1,78 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_filesize.h" +#include "utils.h" + +#include <Baloo/Term> + +#include <klocalizedstring.h> + +PassFileSize::PassFileSize() +{ + // File size units + registerUnits(1000LL, i18nc("Lower-case units corresponding to a kilobyte", "kb kilobyte kilobytes")); + registerUnits(1000000LL, i18nc("Lower-case units corresponding to a megabyte", "mb megabyte megabytes")); + registerUnits(1000000000LL, i18nc("Lower-case units corresponding to a gigabyte", "gb gigabyte gigabytes")); + registerUnits(1000000000000LL, i18nc("Lower-case units corresponding to a terabyte", "tb terabyte terabytes")); + + registerUnits(1LL << 10, i18nc("Lower-case units corresponding to a kibibyte", "kib k kibibyte kibibytes")); + registerUnits(1LL << 20, i18nc("Lower-case units corresponding to a mebibyte", "mib m mebibyte mebibytes")); + registerUnits(1LL << 30, i18nc("Lower-case units corresponding to a gibibyte", "gib g gibibyte gibibytes")); + registerUnits(1LL << 40, i18nc("Lower-case units corresponding to a tebibyte", "tib t tebibyte tebibytes")); +} + +void PassFileSize::registerUnits(long long int multiplier, const QString &units) +{ + Q_FOREACH(const QString &unit, units.split(QLatin1Char(' '))) { + multipliers.insert(unit, multiplier); + } +} + +QList<Baloo::Term> PassFileSize::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + + // Unit + QString unit = stringValueIfLiteral(match.at(1)).toLower(); + + if (multipliers.contains(unit)) { + long long int multiplier = multipliers.value(unit); + QVariant value = match.at(0).value(); + + if (!match.at(0).property().isNull()) { + return rs; + } else if (value.type() == QVariant::Double) { + value = QVariant(value.toDouble() * double(multiplier)); + } else if (value.type() == QVariant::LongLong) { + value = QVariant(value.toLongLong() * multiplier); + } else { + // String or anything that is not a number + return rs; + } + + rs.append(Baloo::Term( + QLatin1String("size"), + value, + Baloo::Term::Equal + )); + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_filesize.h ^ |
@@ -0,0 +1,43 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_FILESIZE_H__ +#define __PASS_FILESIZE_H__ + +#include <QtCore/QString> +#include <QtCore/QList> +#include <QtCore/QHash> + +namespace Baloo { class Term; } + +class PassFileSize +{ + public: + PassFileSize(); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + void registerUnits(long long int multiplier, const QString &units); + + private: + QHash<QString, long long int> multipliers; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_numbers.cpp ^ |
@@ -0,0 +1,78 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_numbers.h" +#include "utils.h" + +#include <Baloo/Term> + +#include <klocalizedstring.h> + +PassNumbers::PassNumbers() +{ + registerNames(0, i18nc("Space-separated list of words meaning 0", "zero nought null")); + registerNames(1, i18nc("Space-separated list of words meaning 1", "one a first")); + registerNames(2, i18nc("Space-separated list of words meaning 2", "two second")); + registerNames(3, i18nc("Space-separated list of words meaning 3", "three third")); + registerNames(4, i18nc("Space-separated list of words meaning 4", "four fourth")); + registerNames(5, i18nc("Space-separated list of words meaning 5", "five fifth")); + registerNames(6, i18nc("Space-separated list of words meaning 6", "six sixth")); + registerNames(7, i18nc("Space-separated list of words meaning 7", "seven seventh")); + registerNames(8, i18nc("Space-separated list of words meaning 8", "eight eighth")); + registerNames(9, i18nc("Space-separated list of words meaning 9", "nine ninth")); + registerNames(10, i18nc("Space-separated list of words meaning 10", "ten tenth")); +} + +void PassNumbers::registerNames(long long int number, const QString &names) +{ + Q_FOREACH(const QString &name, names.split(QLatin1Char(' '))) { + number_names.insert(name, number); + } +} + +QList<Baloo::Term> PassNumbers::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + + // Convert a string to a number + const QString value = stringValueIfLiteral(match.at(0)); + + if (number_names.contains(value)) { + // Named number + rs.append(Baloo::Term( + QString(), + number_names.value(value), + Baloo::Term::Equal + )); + } else { + // Integer + bool ok; + long long int as_integer = value.toLongLong(&ok); + + if (ok) { + rs.append(Baloo::Term( + QString(), + as_integer, + Baloo::Term::Equal + )); + } + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_numbers.h ^ |
@@ -0,0 +1,42 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_NUMBERS_H__ +#define __PASS_NUMBERS_H__ + +#include <QtCore/QList> +#include <QtCore/QHash> + +namespace Baloo { class Term; } + +class PassNumbers +{ + public: + PassNumbers(); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + void registerNames(long long int number, const QString &names); + + private: + QHash<QString, long long int> number_names; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_periodnames.cpp ^ |
@@ -0,0 +1,101 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_periodnames.h" +#include "pass_dateperiods.h" +#include "utils.h" + +#include <Baloo/Term> + +#include <kcalendarsystem.h> +#include <klocale.h> + +PassPeriodNames::PassPeriodNames() +{ + const KCalendarSystem *cal = KLocale::global()->calendar(); + + // List of all the day names (try to get as many days as the calendar can provide) + for (int day=1; + insertName(day_names, + day, + cal->weekDayName(day, KCalendarSystem::ShortDayName), + cal->weekDayName(day, KCalendarSystem::LongDayName)); + ++day) { + } + + // List of all the month names (NOTE: Using the current year, and a previous + // year that is a leap year (or not a leap year if the current year is one)) + int years[2]; + + years[0] = cal->year(QDate::currentDate()); + years[1] = years[0]; + + while (cal->isLeapYear(years[0]) == cal->isLeapYear(years[1])) { + --years[1]; + } + + for (int year=0; year<2; ++year) { + for (int month=1; + insertName(month_names, + month, + cal->monthName(month, years[year], KCalendarSystem::ShortName), + cal->monthName(month, years[year], KCalendarSystem::LongName)); + ++month) { + } + } +} + +bool PassPeriodNames::insertName(QHash<QString, int> &hash, int value, const QString &shortName, const QString &longName) +{ + if (shortName.isEmpty() || longName.isEmpty()) { + return false; + } + + hash.insert(shortName.toLower(), value); + hash.insert(longName.toLower(), value); + + return true; +} + +QList<Baloo::Term> PassPeriodNames::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + QString name = stringValueIfLiteral(match.at(0)).toLower(); + + PassDatePeriods::Period period = PassDatePeriods::VariablePeriod; + int value; + + if (day_names.contains(name)) { + period = PassDatePeriods::DayOfWeek; + value = day_names.value(name); + } else if (month_names.contains(name)) { + period = PassDatePeriods::Month; + value = month_names.value(name); + } + + if (period != PassDatePeriods::VariablePeriod) { + rs.append(Baloo::Term( + PassDatePeriods::propertyName(period, false), + QVariant((long long)value), + Baloo::Term::Equal + )); + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_periodnames.h ^ |
@@ -0,0 +1,43 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_PERIODNAMES_H__ +#define __PASS_PERIODNAMES_H__ + +#include <QtCore/QString> +#include <QtCore/QList> +#include <QtCore/QHash> + +namespace Baloo { class Term; } + +class PassPeriodNames +{ + public: + PassPeriodNames(); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + bool insertName(QHash<QString, int> &hash, int value, const QString &shortName, const QString &longName); + + QHash<QString, int> day_names; + QHash<QString, int> month_names; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_properties.cpp ^ |
@@ -0,0 +1,94 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_properties.h" +#include "utils.h" + +PassProperties::PassProperties() +{ +} + +void PassProperties::setProperty(const QString &property, Types range) +{ + this->property = property; + this->range = range; +} + +QVariant PassProperties::convertToRange(const QVariant &value) const +{ + switch (range) { + case Integer: + if (value.type() == QVariant::LongLong) { + return value; + } + break; + + case IntegerOrDouble: + if (value.type() == QVariant::LongLong || value.type() == QVariant::Double) { + return value; + } + break; + + case String: + if (value.type() == QVariant::String) { + return value; + } + break; + + case DateTime: + if (value.type() == QVariant::DateTime) { + return value; + } + break; + + case Tag: + case Contact: + case EmailAddress: + if (value.type() == QVariant::String) { + return value; + } + break; + } + + return QVariant(); +} + +QList<Baloo::Term> PassProperties::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + Baloo::Term term = match.at(0); + QVariant value = convertToRange(term.value()); + + // If the term could be converted to the range of the desired property, + // then build a comparison + if (value.isValid()) { + term.setValue(value); + term.setProperty(property); + + // Mutate "equals" to "contains" for String ranges + if (term.comparator() == Baloo::Term::Equal && + (range == String || range == Tag)) { + term.setComparator(Baloo::Term::Contains); + } + + rs.append(term); + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_properties.h ^ |
@@ -0,0 +1,54 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_PROPERTIES_H__ +#define __PASS_PROPERTIES_H__ + +#include <QtCore/QString> + +#include <Baloo/Term> + +class PassProperties +{ + public: + enum Types { + Integer, + IntegerOrDouble, + String, + DateTime, + Tag, + Contact, + EmailAddress + }; + + PassProperties(); + + void setProperty(const QString &property, Types range); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + QVariant convertToRange(const QVariant &value) const; + + private: + QString property; + Types range; +}; + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_propertyinfo.cpp ^ |
@@ -0,0 +1,53 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2014 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_propertyinfo.h" +#include "utils.h" + +#include <KFileMetaData/PropertyInfo> + +PassPropertyInfo::PassPropertyInfo() +{ + // Query PropertyInfo for all the valid property names + int lastProperty = KFileMetaData::Property::LastProperty; + + for (int i=0; i<lastProperty; ++i) { + KFileMetaData::PropertyInfo info((KFileMetaData::Property::Property)i); + + if (!info.name().isEmpty()) { + validPropertyNames.insert(info.name()); + } + } +} + +QList<Baloo::Term> PassPropertyInfo::run(const QList<Baloo::Term> &match) const +{ + Q_ASSERT(match.count() == 2); + QList<Baloo::Term> rs; + QString propertyName = stringValueIfLiteral(match.at(0)); + Baloo::Term term = match.at(1); + + // Build a simple property comparison if the property name is something valid + if (!propertyName.isNull() && validPropertyNames.contains(propertyName)) { + term.setProperty(propertyName); + rs.append(term); + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_propertyinfo.h ^ |
@@ -0,0 +1,38 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2014 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_PROPERTYINFO_H__ +#define __PASS_PROPERTYINFO_H__ + +#include <QtCore/QSet> + +#include <Baloo/Term> + +class PassPropertyInfo +{ + public: + PassPropertyInfo(); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + QSet<QString> validPropertyNames; +}; + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_splitunits.cpp ^ |
@@ -0,0 +1,98 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_splitunits.h" +#include "utils.h" + +#include <Baloo/Term> + +#include <klocalizedstring.h> + +PassSplitUnits::PassSplitUnits() +: known_units( + QSet<QString>::fromList( + i18nc( + "List of lowercase prefixes or suffix that need to be split from values", + "k m g b kb mb gb tb kib mib gib tib h am pm th rd nd st" + ).split(QLatin1Char(' ')) + ) + ) +{ +} + +QList<Baloo::Term> PassSplitUnits::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + Baloo::Term value_term; + Baloo::Term unit_term; + + QString value = stringValueIfLiteral(match.at(0)); + int value_position = termStart(match.at(0)); + + if (value.isNull()) { + return rs; + } + + // Possible prefix + QString prefix; + + for (int i=0; i<value.size() && value.at(i).isLetter(); ++i) { + prefix.append(value.at(i).toLower()); + } + + if (prefix.size() < value.size() && known_units.contains(prefix)) { + unit_term.setValue(prefix); + + setTermRange(unit_term, value_position, value_position + prefix.size() - 1); + + value = value.mid(prefix.size()); + value_position += prefix.size(); + } + + // Possible postfix + QString postfix; + + for (int i=value.size()-1; i>=0 && value.at(i).isLetter(); --i) { + postfix.prepend(value.at(i).toLower()); + } + + if (postfix.size() < value.size() && known_units.contains(postfix)) { + value.resize(value.size() - postfix.size()); + + unit_term.setValue(postfix); + + setTermRange( + unit_term, + value_position + value.size(), + value_position + value.size() + postfix.size() - 1 + ); + } + + // Value + value_term.setValue(value); + + setTermRange(value_term, value_position, value_position + value.size() - 1); + + if (unit_term.value().isValid()) { + rs.append(value_term); + rs.append(unit_term); + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_splitunits.h ^ |
@@ -0,0 +1,40 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_SPLITUNITS_H__ +#define __PASS_SPLITUNITS_H__ + +#include <QtCore/QString> +#include <QtCore/QList> +#include <QtCore/QSet> + +namespace Baloo { class Term; } + +class PassSplitUnits +{ + public: + PassSplitUnits(); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + QSet<QString> known_units; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_subqueries.cpp ^ |
@@ -0,0 +1,40 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_subqueries.h" +#include "utils.h" + +#include <Baloo/Term> + +void PassSubqueries::setProperty(const QString &property) +{ + this->property = property; +} + +QList<Baloo::Term> PassSubqueries::run(const QList<Baloo::Term> &match) const +{ + // Fuse the matched terms (... in "related to ... ,") into a subquery + int end_index; + Baloo::Term fused_term = fuseTerms(match, 0, end_index); + + fused_term.setProperty(property); // FIXME: Do backends understand terms having a property and subterms and no value? (for instance "related = AND(term, term, term)") + fused_term.setComparator(Baloo::Term::Equal); + + return QList<Baloo::Term>() << fused_term; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_subqueries.h ^ |
@@ -0,0 +1,39 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_SUBQUERIES_H__ +#define __PASS_SUBQUERIES_H__ + +#include <QtCore/QList> +#include <QtCore/QString> + +namespace Baloo { class Term; } + +class PassSubqueries +{ + public: + void setProperty(const QString &property); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + QString property; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_typehints.cpp ^ |
@@ -0,0 +1,76 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pass_typehints.h" +#include "utils.h" + +#include <Baloo/Term> + +#include <klocalizedstring.h> + +PassTypeHints::PassTypeHints() +{ + registerHints(QLatin1String("File"), + i18nc("List of words representing a file", "file files")); + registerHints(QLatin1String("Image"), + i18nc("List of words representing an image", "image images picture pictures photo photos")); + registerHints(QLatin1String("Video"), + i18nc("List of words representing a video", "video videos movie movies film films")); + registerHints(QLatin1String("Audio"), + i18nc("List of words representing an audio file", "music musics")); + registerHints(QLatin1String("Document"), + i18nc("List of words representing a document", "document documents")); + registerHints(QLatin1String("Email"), + i18nc("List of words representing an email", "mail mails email emails e-mail e-mails message messages")); + registerHints(QLatin1String("Archive"), + i18nc("List of words representing an archive", "archive archives tarball tarballs zip")); + registerHints(QLatin1String("Folder"), + i18nc("List of words representing a folder", "folder folders directory directories")); + registerHints(QLatin1String("Contact"), + i18nc("List of words representing a contact", "contact contacts person people")); + registerHints(QLatin1String("Note"), + i18nc("List of words representing a note", "note notes")); +} + +void PassTypeHints::registerHints(const QString &type, const QString &hints) +{ + Q_FOREACH(const QString &hint, hints.split(QLatin1Char(' '))) { + type_hints.insert(hint, type); + } +} + +QList<Baloo::Term> PassTypeHints::run(const QList<Baloo::Term> &match) const +{ + QList<Baloo::Term> rs; + const QString value = stringValueIfLiteral(match.at(0)).toLower(); + + if (value.isNull()) { + return rs; + } + + if (type_hints.contains(value)) { + rs.append(Baloo::Term( + QLatin1String("_k_typehint"), + type_hints.value(value), + Baloo::Term::Equal + )); + } + + return rs; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/pass_typehints.h ^ |
@@ -0,0 +1,44 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PASS_TYPEHINTS_H__ +#define __PASS_TYPEHINTS_H__ + +#include <QtCore/QString> +#include <QtCore/QList> +#include <QtCore/QHash> +#include <QtCore/QUrl> + +namespace Baloo { class Term; } + +class PassTypeHints +{ + public: + PassTypeHints(); + + QList<Baloo::Term> run(const QList<Baloo::Term> &match) const; + + private: + void registerHints(const QString &type, const QString &hints); + + private: + QHash<QString, QString> type_hints; +}; + +#endif \ No newline at end of file | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/patternmatcher.cpp ^ |
@@ -0,0 +1,226 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "patternmatcher.h" +#include "naturalqueryparser.h" +#include "utils.h" + +#include <QRegExp> + +PatternMatcher::PatternMatcher(const Baloo::NaturalQueryParser *parser, + QList<Baloo::Term> &terms, + int cursor_position, + const QStringList &pattern, + Baloo::CompletionProposal::Type completion_type, + const KLocalizedString &completion_description) +: parser(parser), + terms(terms), + cursor_position(cursor_position), + pattern(pattern), + completion_type(completion_type), + completion_description(completion_description), + capture_count(captureCount()) +{ +} + +int PatternMatcher::captureCount() const +{ + int max_capture = 0; + int capture; + + Q_FOREACH(const QString &p, pattern) { + if (p.at(0) == QLatin1Char('$')) { + capture = p.mid(1).toInt(); + + if (capture > max_capture) { + max_capture = capture; + } + } + } + + return max_capture; +} + +int PatternMatcher::matchPattern(int first_term_index, + QList<Baloo::Term> &matched_terms, + int &start_position, + int &end_position) const +{ + Q_ASSERT(first_term_index < terms.count()); + + int pattern_index = 0; + int term_index = first_term_index; + bool has_matched_a_literal = false; + bool match_anything = false; // Match "$$" + bool contains_catchall = false; + + start_position = 1 << 30; + end_position = 0; + + while (pattern_index < pattern.count() && term_index < terms.count()) { + const Baloo::Term &term = terms.at(term_index); + int capture_index = -1; + + // Always update start and end position, they will be simply discarded + // if the pattern ends not matching. + start_position = qMin(start_position, termStart(term)); + end_position = qMax(end_position, termEnd(term)); + + if (pattern.at(pattern_index) == QLatin1String("$$")) { + // Start to match anything + match_anything = true; + contains_catchall = true; + ++pattern_index; + + continue; + } + + bool match = matchTerm(term, pattern.at(pattern_index), capture_index); + + if (match_anything) { + if (!match) { + // The stop pattern is not yet matched, continue to match + // anything + matched_terms.append(term); + } else { + // The terminating pattern is matched, stop to match anything + match_anything = false; + ++pattern_index; + } + } else if (match) { + if (capture_index != -1) { + matched_terms[capture_index] = term; + } else { + has_matched_a_literal = true; // At least one literal has been matched, enable auto-completion + } + + // Try to match the next pattern + ++pattern_index; + } else { + // The pattern does not match, abort + break; + } + + // Match the next term + ++term_index; + } + + // See if the partially matched pattern can be used to provide a completion proposal + if ((has_matched_a_literal || completion_type == Baloo::CompletionProposal::PropertyName) && + term_index - first_term_index > 0) { + addCompletionProposal(pattern_index, first_term_index, term_index); + } + + if (contains_catchall || pattern_index == pattern.count()) { + // Patterns containing "$$" typically end with an optional terminating + // term. Allow them to match even if we reach the end of the term list + // without encountering the terminating term. + return (term_index - first_term_index); + } else { + return 0; + } +} + +bool PatternMatcher::matchTerm(const Baloo::Term &term, const QString &pattern, int &capture_index) const +{ + if (pattern.at(0) == QLatin1Char('$')) { + // Placeholder + capture_index = pattern.mid(1).toInt() - 1; + + return true; + } else { + // Literal value that has to be matched against a regular expression + QString value = stringValueIfLiteral(term); + QStringList allowed_values = pattern.split(QLatin1Char('|')); + + if (value.isNull()) { + return false; + } + + Q_FOREACH(const QString &allowed_value, allowed_values) { + if (QRegExp(allowed_value, Qt::CaseInsensitive, QRegExp::RegExp2).exactMatch(value)) { + return true; + } + } + + return false; + } +} + +void PatternMatcher::addCompletionProposal(int first_pattern_index_not_matching, + int first_term_index_matching, + int first_term_index_not_matching) const +{ + // Don't count terms that are not literal terms. This avoids problems when the + // user types "sent to size > 2M", that is seen here as "sent to <comparison>". + if (!terms.at(first_term_index_not_matching - 1).property().isNull()) { + if (--first_term_index_not_matching <= 0) { + return; // Avoid an underflow when the pattern is only "$1" for instance. + } + } + + const Baloo::Term &first_matching = terms.at(first_term_index_matching); + const Baloo::Term &last_matching = terms.at(first_term_index_not_matching - 1); + + // Check that the completion proposal would be valid + if (completion_description.isEmpty()) { + return; + } + + if (cursor_position < termStart(first_matching)) { + return; + } + + if (first_term_index_not_matching < terms.count() && + cursor_position > termStart(terms.at(first_term_index_not_matching))) { + return; + } + + // Replace pattern parts that have matched with their matched terms, and + // replace "a|b|c" with "a". This makes the pattern nicer for the user + int pattern_parts_to_replace = first_term_index_not_matching - first_term_index_matching; + QStringList user_friendly_pattern(pattern); + | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/patternmatcher.h ^ |
@@ -0,0 +1,113 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __PATTERNMATCHER_H__ +#define __PATTERNMATCHER_H__ + +#include "completionproposal.h" +#include "utils.h" + +#include <Baloo/Term> + +#include <QtCore/QStringList> + +namespace Baloo { class NaturalQueryParser; } + +class PatternMatcher +{ + public: + PatternMatcher(const Baloo::NaturalQueryParser *parser, + QList<Baloo::Term> &terms, + int cursor_position, + const QStringList &pattern, + Baloo::CompletionProposal::Type completion_type, + const KLocalizedString &completion_description); + + template<typename T> + void runPass(const T &pass) + { + QList<Baloo::Term> matched_terms; + + for (int i=0; i<capture_count; ++i) { + matched_terms.append(Baloo::Term()); + } + + // Try to start to match the pattern at every position in the term list + for (int index=0; index<terms.count(); ++index) { + int start_position; + int end_position; + int matched_length = matchPattern(index, matched_terms, start_position, end_position); + + if (matched_length > 0) { + // The pattern matched, run the pass on the matching terms + QList<Baloo::Term> replacement = pass.run(matched_terms); + + if (replacement.count() > 0) { + // Replace terms first_match_index..i with replacement + for (int i=0; i<matched_length; ++i) { + terms.removeAt(index); + } + + for (int i=replacement.count()-1; i>=0; --i) { + terms.insert(index, replacement.at(i)); + } + + // If the pass returned only one replacement term, set + // its position. If more terms are returned, the pass + // must handle positions itself + if (replacement.count() == 1) { + setTermRange(terms[index], start_position, end_position); + } + + // Re-explore the terms vector as indexes have changed + index = -1; + } + + // If the pattern contains "$$", terms are appended to the end + // of matched_terms. Remove them now that they are not needed anymore + while (matched_terms.count() > capture_count) { + matched_terms.removeLast(); + } + } + } + } + + private: + int captureCount() const; + int matchPattern(int first_term_index, + QList<Baloo::Term> &matched_terms, + int &start_position, + int &end_position) const; + bool matchTerm(const Baloo::Term &term, const QString &pattern, int &capture_index) const; + void addCompletionProposal(int first_pattern_index_not_matching, + int first_term_index_matching, + int first_term_index_not_matching) const; + + private: + const Baloo::NaturalQueryParser *parser; + QList<Baloo::Term> &terms; + int cursor_position; + QStringList pattern; + Baloo::CompletionProposal::Type completion_type; + KLocalizedString completion_description; + + int capture_count; +}; + +#endif | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/utils.cpp ^ |
@@ -0,0 +1,171 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "utils.h" +#include "pass_dateperiods.h" + +#include <klocalizedstring.h> + +bool localeWordsSeparatedBySpaces() +{ + return i18nc("Are words of your language separated by spaces (Y/N) ?", "Y") == QLatin1String("Y"); +} + +int termStart(const Baloo::Term &term) +{ + return term.userData(QLatin1String("start_position")).toInt(); +} + +int termEnd(const Baloo::Term &term) +{ + return term.userData(QLatin1String("end_position")).toInt(); +} + +void setTermRange(Baloo::Term &term, int start, int end) +{ + term.setUserData(QLatin1String("start_position"), start); + term.setUserData(QLatin1String("end_position"), end); +} + +QString stringValueIfLiteral(const Baloo::Term &term) +{ + if (!term.property().isNull()) { + return QString(); + } + + if (term.value().type() != QVariant::String) { + return QString(); + } + + return term.value().toString(); +} + +long long int longValueIfLiteral(const Baloo::Term& term, bool *ok) +{ + if (!term.property().isNull()) { + *ok = false; + return 0; + } + + if (term.value().type() != QVariant::LongLong) { + *ok = false; + return 0; + } + + *ok = true; + return term.value().toLongLong(); +} + +void copyTermRange(Baloo::Term &target, const Baloo::Term &source) +{ + setTermRange( + target, + termStart(source), + termEnd(source) + ); +} + +Baloo::Term fuseTerms(const QList<Baloo::Term> &terms, int first_term_index, int &end_term_index) +{ + Baloo::Term fused_term; + bool words_separated_by_spaces = localeWordsSeparatedBySpaces(); + bool build_and = true; + bool build_not = false; + bool first = true; + + QString and_string = i18n("and"); + QString or_string = i18n("or"); + QString not_string = i18n("not"); + + // Fuse terms in nested AND and OR terms. "a AND b OR c" is fused as + // "(a AND b) OR c" + for (end_term_index=first_term_index; end_term_index<terms.size(); ++end_term_index) { + Baloo::Term term = terms.at(end_term_index); + QVariant value = term.value(); + + if (value.type() == QVariant::String) { + QString content = value.toString().toLower(); + + if (content == or_string) { + // Consume the OR term, the next term will be ORed with the previous + build_and = false; + continue; + } else if (content == and_string || + content == QLatin1String("+")) { + // Consume the AND term + build_and = true; + continue; + } else if (content == QLatin1String("!") || + content == not_string || + content == QLatin1String("-")) { + // Consume the negation + build_not = true; + continue; + } else if (content == QLatin1String("(")) { + // Fuse the nested query + term = fuseTerms(terms, end_term_index + 1, end_term_index); + } else if (content == QLatin1String(")")) { + // Done + return fused_term; + } else if (content.size() <= 2 && words_separated_by_spaces) { + // Ignore small terms, they are typically "to", "a", etc. + continue; + } + } + + // Negate the term if needed + if (build_not) { + term.setNegation(!term.isNegated()); // TODO: Replace with a method that properly inverts all the Term's operators and apply De Morgan laws to boolean terms + } + + // Add term to the fused term + int start_position = termStart(term); + int end_position = termEnd(term); + + if (first) { + fused_term = term; + first = false; + } else { + start_position = qMin(start_position, termStart(fused_term)); + end_position = qMax(end_position, termEnd(fused_term)); + + if (build_and) { + if (fused_term.operation() == Baloo::Term::And) { + fused_term.addSubTerm(term); + } else { + fused_term = (fused_term && term); + } + } else { + if (fused_term.operation() == Baloo::Term::Or) { + fused_term.addSubTerm(term); + } else { + fused_term = (fused_term || term); + } + } + } + + setTermRange(fused_term, start_position, end_position); + + // Default to AND, and don't invert terms + build_and = true; + build_not = false; + } + + return fused_term; +} | ||
[-] [+] | Added | baloo-widgets-5.1.90.tar.xz/src/naturalqueryparser/utils.h ^ |
@@ -0,0 +1,42 @@ +/* This file is part of the Baloo query parser + Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __UTILS_H__ +#define __UTILS_H__ + +#include <Baloo/Term> + +#include <QtCore/QString> +#include <QtCore/QList> + +bool localeWordsSeparatedBySpaces(); + +int termStart(const Baloo::Term &term); +int termEnd(const Baloo::Term &term); +void setTermRange(Baloo::Term &term, int start, int end); + +QString stringValueIfLiteral(const Baloo::Term &term); +long long longValueIfLiteral(const Baloo::Term &term, bool *ok); +void copyTermRange(Baloo::Term &target, const Baloo::Term &source); + +Baloo::Term fuseTerms(const QList<Baloo::Term> &terms, + int first_term_index, + int &end_term_index); + +#endif | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/querybuilder.cpp ^ |
@@ -21,8 +21,9 @@ #include "groupedlineedit.h" #include "querybuildercompleter_p.h" -#include <baloo/completionproposal.h> -#include <baloo/naturalqueryparser.h> +#include "completionproposal.h" +#include "naturalqueryparser.h" + #include <baloo/term.h> #include <klocalizedstring.h> @@ -54,10 +55,8 @@ d->completer = new QueryBuilderCompleter(this); d->parsing_enabled = true; - connect(this, SIGNAL(textChanged()), - this, SLOT(reparse())); - connect(d->completer, SIGNAL(proposalSelected(CompletionProposal*,QString)), - this, SLOT(proposalSelected(CompletionProposal*,QString))); + connect(this, &QueryBuilder::textChanged, this, &QueryBuilder::reparse); + connect(d->completer, &QueryBuilderCompleter::proposalSelected, this, &QueryBuilder::proposalSelected); } void QueryBuilder::setParsingEnabled(bool enable) @@ -181,4 +180,3 @@ setCursorPosition(put_cursor_at); } -#include "querybuilder.moc" | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/querybuildercompleter.cpp ^ |
@@ -19,7 +19,7 @@ #include "querybuildercompleter_p.h" -#include <baloo/completionproposal.h> +#include "completionproposal.h" #include <klocalizedstring.h> #include <QListWidget> @@ -48,8 +48,7 @@ parent->installEventFilter(this); - connect(this, SIGNAL(itemActivated(QListWidgetItem*)), - this, SLOT(proposalActivated(QListWidgetItem*))); + connect(this, &QueryBuilderCompleter::itemActivated, this, &QueryBuilderCompleter::proposalActivated); // Load the list of all the valid property names int lastProperty = KFileMetaData::Property::LastProperty; @@ -276,4 +275,3 @@ return rs; } -#include "querybuildercompleter.moc" | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/tagcheckbox.cpp ^ |
@@ -68,6 +68,7 @@ case QEvent::MouseMove: { QMouseEvent* me = static_cast<QMouseEvent*>(event); enableUrlHover( tagRect().contains(me->pos()) ); + break; } case QEvent::MouseButtonRelease: { @@ -76,6 +77,7 @@ emit tagClicked( m_tag ); return true; } + break; } default: | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/widgetfactory.cpp ^ |
@@ -1,6 +1,5 @@ /* - <one line to give the library's name and an idea of what it does.> - Copyright (C) 2012 Vishesh Handa <me@vhanda.in> + Copyright (C) 2012-2014 Vishesh Handa <vhanda@kde.org> Code largely copied/adapted from KFileMetadataProvider Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> @@ -26,7 +25,7 @@ #include "kcommentwidget_p.h" #include "KRatingWidget" -#include <Baloo/FileModifyjob> +#include <KFileMetaData/UserMetaData> #include <QtWidgets/QLabel> #include <QtCore/QTime> @@ -74,6 +73,27 @@ // // Widget Creation // +static QString toString(const QVariant& value) +{ + switch (value.type()) { + case QVariant::Int: + return QLocale().toString(value.toInt()); + case QVariant::Double: + return QLocale().toString(value.toDouble()); + + case QVariant::List: { + QStringList list; + for (const QVariant& var : value.toList()) { + list << toString(var); + } + + return list.join(", "); + } + + default: + return value.toString(); + } +} QWidget* WidgetFactory::createWidget(const QString& prop, const QVariant& value, QWidget* parent) { @@ -104,24 +124,13 @@ if (dt.isValid()) { QTime time = dt.time(); if (!time.hour() && !time.minute() && !time.second()){ - valueString = form.formatRelativeDate(dt.date(), QLocale::LongFormat); - } - else{ - valueString = form.formatRelativeDateTime(dt, QLocale::LongFormat); - } + valueString = form.formatRelativeDate(dt.date(), QLocale::LongFormat); + } else { + valueString = form.formatRelativeDateTime(dt, QLocale::LongFormat); + } } else { - switch (value.type()) { - case QVariant::Int: - valueString = QLocale().toString(value.toInt()); - break; - case QVariant::Double: - valueString = QLocale().toString(value.toDouble()); - break; - default: - valueString = value.toString(); - break; - } + valueString = toString(value); } } widget = createValueWidget(valueString, parent); @@ -139,10 +148,8 @@ tagWidget->setReadyOnly(m_readOnly); tagWidget->setSelectedTags(tags); - connect(tagWidget, SIGNAL(selectionChanged(QStringList)), - this, SLOT(slotTagsChanged(QStringList))); - connect(tagWidget, SIGNAL(tagClicked(QString)), - this, SLOT(slotTagClicked(QString))); + connect(tagWidget, &TagWidget::selectionChanged, this, &WidgetFactory::slotTagsChanged); + connect(tagWidget, &TagWidget::tagClicked, this, &WidgetFactory::slotTagClicked); m_tagWidget = tagWidget; m_prevTags = tags; @@ -156,8 +163,7 @@ commentWidget->setText(comment); commentWidget->setReadOnly(m_readOnly); - connect(commentWidget, SIGNAL(commentChanged(QString)), - this, SLOT(slotCommentChanged(QString))); + connect(commentWidget, &KCommentWidget::commentChanged, this, &WidgetFactory::slotCommentChanged); m_commentWidget = commentWidget; @@ -174,8 +180,7 @@ const QFontMetrics metrics(parent->font()); ratingWidget->setPixmapSize(metrics.height()); - connect(ratingWidget, SIGNAL(ratingChanged(uint)), - this, SLOT(slotRatingChanged(uint))); + connect(ratingWidget, static_cast<void (KRatingWidget::*)(uint)>(&KRatingWidget::ratingChanged), this, &WidgetFactory::slotRatingChanged); m_ratingWidget = ratingWidget; @@ -217,7 +222,7 @@ valueWidget->setWordWrap(true); valueWidget->setAlignment(Qt::AlignTop | Qt::AlignLeft); valueWidget->setText(m_readOnly ? plainText(value) : value); - connect(valueWidget, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString))); + connect(valueWidget, &ValueWidget::linkActivated, this, &WidgetFactory::slotLinkActivated); return valueWidget; } @@ -228,41 +233,43 @@ void WidgetFactory::slotCommentChanged(const QString& comment) { - KJob* job = Baloo::FileModifyJob::modifyUserComment(m_items, comment); - startChangeDataJob(job); + for (const QString& filePath : m_items) { + KFileMetaData::UserMetaData md(filePath); + md.setUserComment(comment); + } + emit dataChangeStarted(); + emit dataChangeFinished(); } void WidgetFactory::slotRatingChanged(uint rating) { - KJob* job = Baloo::FileModifyJob::modifyRating(m_items, rating); - startChangeDataJob(job); + for (const QString& filePath : m_items) { + KFileMetaData::UserMetaData md(filePath); + md.setRating(rating); + } + emit dataChangeStarted(); + emit dataChangeFinished(); } void WidgetFactory::slotTagsChanged(const QStringList& tags) { if (m_tagWidget) { - KJob* job = Baloo::FileModifyJob::modifyTags(m_items, tags); + for (const QString& filePath : m_items) { + KFileMetaData::UserMetaData md(filePath); + md.setTags(tags); + } // FIXME: vHanda : Remove the tags that are no longer applicable // When multiple tags are selected one doesn't want to loose the old tags // of any of the resources. Unless specifically removed. // QSet<Tag> removedTags = m_prevTags.toSet().subtract( tags.toSet() ); // Remove these tags! - - m_prevTags = tags; - startChangeDataJob(job); + // m_prevTags = tags; + emit dataChangeStarted(); + emit dataChangeFinished(); } } -void WidgetFactory::startChangeDataJob(KJob* job) -{ - connect(job, SIGNAL(result(KJob*)), - this, SIGNAL(dataChangeFinished())); - - emit dataChangeStarted(); - job->start(); -} - // // Notifications // | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/src/widgetfactory.h ^ |
@@ -67,8 +67,6 @@ QWidget* createCommentWidget(const QString& comment, QWidget* parent); QWidget* createValueWidget(const QString& value, QWidget* parent); - void startChangeDataJob(KJob* job); - TagWidget* m_tagWidget; KRatingWidget* m_ratingWidget; KCommentWidget* m_commentWidget; | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/test/CMakeLists.txt ^ |
@@ -1,6 +1,6 @@ add_executable(tagwidgetapp tagwidgetapp.cpp tagwidgettest.cpp) target_link_libraries(tagwidgetapp - KF5::BalooFiles + KF5::Baloo KF5::BalooWidgets Qt5::Widgets Qt5::Core @@ -8,7 +8,7 @@ add_executable(metadatawidgetapp metadatawidgetapp.cpp metadatawidgettest.cpp) target_link_libraries(metadatawidgetapp - KF5::BalooFiles + KF5::Baloo KF5::BalooWidgets Qt5::Widgets Qt5::Core @@ -16,7 +16,7 @@ add_executable(metadataconfigwidgetapp metadataconfigwidgetapp.cpp) target_link_libraries(metadataconfigwidgetapp - KF5::BalooFiles + KF5::Baloo KF5::BalooWidgets Qt5::Widgets Qt5::Core | ||
[-] [+] | Changed | baloo-widgets-5.1.90.tar.xz/test/querybuilderapp.cpp ^ |
@@ -20,14 +20,13 @@ #include "querybuilder.h" #include <QApplication> -#include <Baloo/NaturalFileQueryParser> +#include "natural_query_parser.h" #include <kcomponentdata.h> int main(int argc, char **argv) { QApplication app(argc, argv); - KComponentData data("QueryBuilderApp"); Baloo::NaturalFileQueryParser parser; Baloo::QueryBuilder builder(&parser, 0); | ||
[-] [+] | Changed | baloo-widgets.yaml ^ |
@@ -1,5 +1,5 @@ Name : baloo-widgets -Version : 5.0.90 +Version : 5.1.90 Release : 2 Group : System/Base License : LGPLv2+ @@ -10,8 +10,6 @@ Sources: - "%{name}-%{version}.tar.xz" -Patches: - - 0001-Remove-double-slash.patch RpmLintIgnore: - devel-file-in-non-devel-package @@ -65,3 +63,4 @@ - "%{_kf5_libdir}/*.so" - "%{_kf5_cmakedir}/KF5BalooWidgets" - "%{_kf5_includedir}/BalooWidgets" + - "%{_kf5_includedir}/Baloo" |