diff --git a/src/contentlist/CMakeLists.txt b/src/contentlist/CMakeLists.txt index cc42555..8882144 100644 --- a/src/contentlist/CMakeLists.txt +++ b/src/contentlist/CMakeLists.txt @@ -1,30 +1,31 @@ set(qmlplugin_SRCS qmlplugin.cpp ContentList.cpp ContentListerBase.cpp FilesystemContentLister.cpp + ContentQuery.cpp ) if(KF5Baloo_FOUND) set(qmlplugin_baloo_SRCS BalooContentLister.cpp ) endif() add_library (contentlistqmlplugin SHARED ${qmlplugin_SRCS} ${qmlplugin_baloo_SRCS}) target_link_libraries (contentlistqmlplugin Qt5::Qml KF5::FileMetaData ) if(KF5Baloo_FOUND) target_compile_definitions(contentlistqmlplugin PRIVATE -DBALOO_FOUND="${KF5Baloo_FOUND}") target_link_libraries(contentlistqmlplugin KF5::Baloo ) endif() install (TARGETS contentlistqmlplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/contentlist) install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/contentlist) diff --git a/src/contentlist/ContentQuery.cpp b/src/contentlist/ContentQuery.cpp new file mode 100644 index 0000000..3216fd8 --- /dev/null +++ b/src/contentlist/ContentQuery.cpp @@ -0,0 +1,65 @@ +/* + * Copyright 2018 Arjen Hiemstra + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ContentQuery.h" + +class ContentQuery::Private +{ +public: + Type type = Any; + QString searchString; +}; + +ContentQuery::ContentQuery(QObject* parent) + : QObject(parent), d(new Private) +{ +} + +ContentQuery::~ContentQuery() +{ +} + +ContentQuery::Type ContentQuery::type() const +{ + return d->type; +} + +QString ContentQuery::searchString() const +{ + return d->searchString; +} + +void ContentQuery::setType(ContentQuery::Type type) +{ + if(type == d->type) + return; + + d->type = type; + emit typeChanged(); +} + +void ContentQuery::setSearchString(const QString& searchString) +{ + if(searchString == d->searchString) + return; + + d->searchString = searchString; + emit searchStringChanged(); +} diff --git a/src/contentlist/ContentQuery.h b/src/contentlist/ContentQuery.h new file mode 100644 index 0000000..df4c30b --- /dev/null +++ b/src/contentlist/ContentQuery.h @@ -0,0 +1,109 @@ +/* + * Copyright 2018 Arjen Hiemstra + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef CONTENTQUERY_H +#define CONTENTQUERY_H + +#include + +#include + +/** + * Encapsulates searching parameters for files on the file system. + * + * + */ +class ContentQuery : public QObject +{ + Q_OBJECT + /** + * The type of files to search for. + */ + Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged) + /** + * A string that should be included in the file's file name. + */ + Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged) + +public: + /** + * The type of files to search for. + */ + enum Type { + Any, ///< Do not limit results by any type. + Video, ///< Only search for videos. + Audio, ///< Only search for audio files. + Documents, ///< Only search for documents. + Images, ///< Only search for images. + Comics, ///< Only search for comic books. + }; + Q_ENUM(Type) + + /** + * Constructor + * + * @param parent The QObject parent. + */ + explicit ContentQuery(QObject* parent = nullptr); + + /** + * Destructor + */ + ~ContentQuery(); + + /** + * Get the type property. + */ + Type type() const; + /** + * Get the searchString property. + */ + QString searchString() const; + +public Q_SLOTS: + /** + * Set the type property. + * + * \param type The new type. + */ + void setType(Type type); + /** + * Set the searchString property. + * + * \param searchString The new search string. + */ + void setSearchString(const QString& searchString); + +Q_SIGNALS: + /** + * Emitted whenever the type property changes. + */ + void typeChanged(); + /** + * Emitted whenever the searchString property changes. + */ + void searchStringChanged(); + +private: + class Private; + const std::unique_ptr d; +}; + +#endif // CONTENTQUERY_H diff --git a/src/contentlist/qmlplugin.cpp b/src/contentlist/qmlplugin.cpp index 07166be..25c385a 100644 --- a/src/contentlist/qmlplugin.cpp +++ b/src/contentlist/qmlplugin.cpp @@ -1,35 +1,37 @@ /* * Copyright (C) 2015 Dan Leinir Turthra Jensen * * 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) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * 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, see . * */ #include "qmlplugin.h" -#include "ContentList.h" - #include +#include "ContentList.h" +#include "ContentQuery.h" + void QmlPlugins::initializeEngine(QQmlEngine *, const char *) { } void QmlPlugins::registerTypes(const char *uri) { qmlRegisterType(uri, 0, 1, "ContentList"); + qmlRegisterType(uri, 0, 1, "ContentQuery"); }