File indexing completed on 2024-05-12 15:51:17

0001 // SPDX-FileCopyrightText: 2018 Arjen Hiemstra <ahiemstra@heimr.nl>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 #pragma once
0005 
0006 #include <memory>
0007 
0008 #include <QObject>
0009 
0010 /**
0011  * Encapsulates searching parameters for files on the file system.
0012  */
0013 class ContentQuery : public QObject
0014 {
0015     Q_OBJECT
0016 
0017     /// The type of files to search for.
0018     Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged)
0019 
0020     /// A string that should be included in the file's file name.
0021     Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged)
0022 
0023     /// A list of directories. Only these directories and their subdirectories will be searched.
0024     Q_PROPERTY(QStringList locations READ locations WRITE setLocations NOTIFY locationsChanged)
0025 
0026     /// A list of mime type names to search for.
0027     ///
0028     /// Note that if this property has not explicitly been set, the list of mime types
0029     /// is based on the type property.
0030     Q_PROPERTY(QStringList mimeTypes READ mimeTypes WRITE setMimeTypes NOTIFY mimeTypesChanged)
0031 
0032 public:
0033     /**
0034      * The type of files to search for.
0035      */
0036     enum Type {
0037         Any, ///< Do not limit results by any type.
0038         Video, ///< Only search for videos.
0039         Audio, ///< Only search for audio files.
0040         Documents, ///< Only search for documents.
0041         Images, ///< Only search for images.
0042         Comics, ///< Only search for comic books.
0043         Epub, ///< Only search for epub document.
0044     };
0045     Q_ENUM(Type)
0046 
0047     /**
0048      * Constructor
0049      *
0050      * @param parent The QObject parent.
0051      */
0052     explicit ContentQuery(QObject *parent = nullptr);
0053 
0054     /**
0055      * Destructor
0056      */
0057     ~ContentQuery();
0058 
0059     /**
0060      * Get the type property.
0061      */
0062     Type type() const;
0063     /**
0064      * Get the searchString property.
0065      */
0066     QString searchString() const;
0067     /**
0068      * Get the locations property.
0069      */
0070     QStringList locations() const;
0071     /**
0072      * Get the mimeTypes property.
0073      */
0074     QStringList mimeTypes() const;
0075 
0076 public Q_SLOTS:
0077     /**
0078      * Set the type property.
0079      *
0080      * \param type The new type.
0081      */
0082     void setType(ContentQuery::Type type);
0083     /**
0084      * Set the searchString property.
0085      *
0086      * \param searchString The new search string.
0087      */
0088     void setSearchString(const QString &searchString);
0089     /**
0090      * Set the location property.
0091      *
0092      * \param location The new location.
0093      */
0094     void setLocations(const QStringList &location);
0095     /**
0096      * Set the mimeTypes property.
0097      *
0098      * \param mimeTypes The new list of mime types.
0099      */
0100     void setMimeTypes(const QStringList &mimeTypes);
0101 
0102 Q_SIGNALS:
0103     /**
0104      * Emitted whenever the type property changes.
0105      */
0106     void typeChanged();
0107     /**
0108      * Emitted whenever the searchString property changes.
0109      */
0110     void searchStringChanged();
0111     /**
0112      * Emitted whenever the location property changes.
0113      */
0114     void locationsChanged();
0115     /**
0116      * Emitted whenever the mimeTypes property changes.
0117      */
0118     void mimeTypesChanged();
0119 
0120 private:
0121     class Private;
0122     const std::unique_ptr<Private> d;
0123 };