File indexing completed on 2024-04-28 09:45:56

0001 /*
0002     kquery.h
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 */
0007 
0008 #ifndef KQUERY_H
0009 #define KQUERY_H
0010 
0011 #include <time.h>
0012 
0013 #include <QList>
0014 #include <QObject>
0015 #include <QPair>
0016 #include <QUrl>
0017 #include <QQueue>
0018 #include <QRegExp>
0019 #include <QStringList>
0020 
0021 #include <KIO/ListJob>
0022 #include <KProcess>
0023 
0024 class KFileItem;
0025 
0026 class KQuery : public QObject
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     explicit KQuery(QObject *parent = nullptr);
0032     ~KQuery() override;
0033 
0034     /* Functions to set Query requirements */
0035     void setSizeRange(int mode, KIO::filesize_t value1, KIO::filesize_t value2);
0036     void setTimeRange(time_t from, time_t to);
0037     void setRegExp(const QString &regexp, bool caseSensitive);
0038     void setRecursive(bool recursive);
0039     void setPath(const QUrl &url);
0040     void setFileType(int filetype);
0041     void setMimeType(const QStringList &mimetype);
0042     void setContext(const QString &context, bool casesensitive, bool search_binary);
0043     void setUsername(const QString &username);
0044     void setGroupname(const QString &groupname);
0045     void setMetaInfo(const QString &metainfo, const QString &metainfokey);
0046     void setUseFileIndex(bool);
0047     void setShowHiddenFiles(bool);
0048 
0049     void start();
0050     void kill();
0051     const QUrl &url()
0052     {
0053         return m_url;
0054     }
0055 
0056 private:
0057     /* Check if file meets the find's requirements*/
0058     inline void processQuery(const KFileItem &);
0059 
0060 public Q_SLOTS:
0061     /* List of files found using slocate */
0062     void slotListEntries(const QStringList&);
0063 
0064 protected Q_SLOTS:
0065     /* List of files found using KIO */
0066     void slotListEntries(KIO::Job *, const KIO::UDSEntryList &);
0067     void slotResult(KJob *);
0068 
0069     void slotreadyReadStandardOutput();
0070     void slotreadyReadStandardError();
0071     void slotendProcessLocate(int, QProcess::ExitStatus);
0072 
0073 Q_SIGNALS:
0074     void foundFileList(const QList< QPair<KFileItem, QString> > &);
0075     void result(int);
0076 
0077 private:
0078     void checkEntries();
0079 
0080     int m_filetype;
0081     int m_sizemode;
0082     KIO::filesize_t m_sizeboundary1;
0083     KIO::filesize_t m_sizeboundary2;
0084     QUrl m_url;
0085     time_t m_timeFrom;
0086     time_t m_timeTo;
0087     QRegExp m_regexp;// regexp for file content
0088     bool m_recursive;
0089     QStringList m_mimetype;
0090     QString m_context;
0091     QString m_username;
0092     QString m_groupname;
0093     QString m_metainfo;
0094     QString m_metainfokey;
0095     bool m_casesensitive;
0096     bool m_search_binary;
0097     bool m_useLocate;
0098     bool m_showHiddenFiles;
0099     QByteArray bufferLocate;
0100     QStringList locateList;
0101     KProcess *processLocate = nullptr;
0102     QList<QRegExp *> m_regexps;// regexps for file name
0103 //  QValueList<bool> m_regexpsContainsGlobs;  // what should this be good for ? Alex
0104     KIO::ListJob *job;
0105     bool m_insideCheckEntries;
0106     QQueue<KFileItem> m_fileItems;
0107     QRegExp metaKeyRx;
0108     int m_result;
0109     QStringList ignore_mimetypes;
0110     QStringList ooo_mimetypes;   // OpenOffice.org mimetypes
0111     QStringList koffice_mimetypes;
0112 
0113     QList< QPair<KFileItem, QString> > m_foundFilesList;
0114 };
0115 
0116 #endif