File indexing completed on 2024-12-15 04:14:22

0001 /*
0002  * Copyright 2018 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  * 
0004  * This program is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU General Public License as
0006  * published by the Free Software Foundation; either version 2 of
0007  * the License or (at your option) version 3 or any later version
0008  * accepted by the membership of KDE e.V. (or its successor approved
0009  * by the membership of KDE e.V.), which shall act as a proxy
0010  * defined in Section 14 of version 3 of the license.
0011  * 
0012  * This program is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015  * GNU General Public License for more details.
0016  * 
0017  * You should have received a copy of the GNU General Public License
0018  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019  */
0020 
0021 #ifndef CONTENTQUERY_H
0022 #define CONTENTQUERY_H
0023 
0024 #include <memory>
0025 
0026 #include <QObject>
0027 
0028 /**
0029  * Encapsulates searching parameters for files on the file system.
0030  *
0031  *
0032  */
0033 class ContentQuery : public QObject
0034 {
0035     Q_OBJECT
0036     /**
0037      * The type of files to search for.
0038      */
0039     Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged)
0040     /**
0041      * A string that should be included in the file's file name.
0042      */
0043     Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged)
0044     /**
0045      * A list of directories. Only these directories and their subdirectories will be searched.
0046      */
0047     Q_PROPERTY(QStringList locations READ locations WRITE setLocations NOTIFY locationsChanged)
0048     /**
0049      * A list of mime type names to search for.
0050      *
0051      * Note that if this property has not explicitly been set, the list of mime types
0052      * is based on the type property.
0053      */
0054     Q_PROPERTY(QStringList mimeTypes READ mimeTypes WRITE setMimeTypes NOTIFY mimeTypesChanged)
0055 
0056 public:
0057     /**
0058      * The type of files to search for.
0059      */
0060     enum Type {
0061         Any, ///< Do not limit results by any type.
0062         Video, ///< Only search for videos.
0063         Audio, ///< Only search for audio files.
0064         Documents, ///< Only search for documents.
0065         Images, ///< Only search for images.
0066         Comics, ///< Only search for comic books.
0067     };
0068     Q_ENUM(Type)
0069 
0070     /**
0071      * Constructor
0072      *
0073      * @param parent The QObject parent.
0074      */
0075     explicit ContentQuery(QObject* parent = nullptr);
0076 
0077     /**
0078      * Destructor
0079      */
0080     ~ContentQuery();
0081 
0082     /**
0083      * Get the type property.
0084      */
0085     Type type() const;
0086     /**
0087      * Get the searchString property.
0088      */
0089     QString searchString() const;
0090     /**
0091      * Get the locations property.
0092      */
0093     QStringList locations() const;
0094     /**
0095      * Get the mimeTypes property.
0096      */
0097     QStringList mimeTypes() const;
0098 
0099 public Q_SLOTS:
0100     /**
0101      * Set the type property.
0102      *
0103      * \param type The new type.
0104      */
0105     void setType(Type type);
0106     /**
0107      * Set the searchString property.
0108      *
0109      * \param searchString The new search string.
0110      */
0111     void setSearchString(const QString& searchString);
0112     /**
0113      * Set the location property.
0114      *
0115      * \param location The new location.
0116      */
0117     void setLocations(const QStringList& location);
0118     /**
0119      * Set the mimeTypes property.
0120      *
0121      * \param mimeTypes The new list of mime types.
0122      */
0123     void setMimeTypes(const QStringList& mimeTypes);
0124 
0125 Q_SIGNALS:
0126     /**
0127      * Emitted whenever the type property changes.
0128      */
0129     void typeChanged();
0130     /**
0131      * Emitted whenever the searchString property changes.
0132      */
0133     void searchStringChanged();
0134     /**
0135      * Emitted whenever the location property changes.
0136      */
0137     void locationsChanged();
0138     /**
0139      * Emitted whenever the mimeTypes property changes.
0140      */
0141     void mimeTypesChanged();
0142 
0143 private:
0144     class Private;
0145     const std::unique_ptr<Private> d;
0146 };
0147 
0148 #endif // CONTENTQUERY_H