File indexing completed on 2025-01-19 03:53:32

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2015-06-01
0007  * Description : DB Jobs thread for listing and scanning
0008  *
0009  * SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_DB_JOBS_THREAD_H
0016 #define DIGIKAM_DB_JOBS_THREAD_H
0017 
0018 // Local includes
0019 
0020 #include "dbengineparameters.h"
0021 #include "dbjobinfo.h"
0022 #include "dbjob.h"
0023 #include "haariface.h"
0024 #include "itemlisterrecord.h"
0025 #include "actionthreadbase.h"
0026 #include "digikam_export.h"
0027 
0028 namespace Digikam
0029 {
0030 
0031 class DBJob;
0032 
0033 class DIGIKAM_DATABASE_EXPORT DBJobsThread : public ActionThreadBase
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038 
0039     explicit DBJobsThread(QObject* const parent);
0040     ~DBJobsThread() override;
0041 
0042     /**
0043      * @brief hasErrors: a method to check for jobs errors
0044      * @return bool: true if the error list is not empty
0045      */
0046     bool hasErrors();
0047 
0048     /**
0049      * @brief A method to get all errors reported from jobs
0050      * @return String list with errors
0051      */
0052     QList<QString>& errorsList();
0053 
0054 protected:
0055 
0056     /**
0057      * @brief Connects the signals of job to the signals of the thread
0058      * @param j: Job that wanted to be connected
0059      */
0060     void connectFinishAndErrorSignals(DBJob* const j);
0061 
0062 public Q_SLOTS:
0063 
0064     /**
0065      * @brief Appends the error string to m_errorsList
0066      * @param errString: error string reported from the job
0067      */
0068     void error(const QString& errString);
0069 
0070 Q_SIGNALS:
0071 
0072     void finished();
0073     void data(const QList<ItemListerRecord>& records);
0074 
0075 private:
0076 
0077     QStringList m_errorsList;
0078 };
0079 
0080 // ---------------------------------------------
0081 
0082 class DIGIKAM_DATABASE_EXPORT AlbumsDBJobsThread : public DBJobsThread
0083 {
0084     Q_OBJECT
0085 
0086 public:
0087 
0088     explicit AlbumsDBJobsThread(QObject* const parent);
0089     ~AlbumsDBJobsThread() override;
0090 
0091     /**
0092      * @brief Starts PAlbums listing and scanning job(s)
0093      * @param info: represents the albums job info
0094      */
0095     void albumsListing(const AlbumsDBJobInfo& info);
0096 
0097 Q_SIGNALS:
0098 
0099     void foldersData(const QHash<int, int>&);
0100     void faceFoldersData(const QMap<QString, QHash<int, int> >&);
0101 };
0102 
0103 // ---------------------------------------------
0104 
0105 class DIGIKAM_DATABASE_EXPORT TagsDBJobsThread : public DBJobsThread
0106 {
0107     Q_OBJECT
0108 
0109 public:
0110 
0111     explicit TagsDBJobsThread(QObject* const parent);
0112     ~TagsDBJobsThread() override;
0113 
0114     /**
0115      * @brief Starts tags listing and scanning job(s)
0116      * @param info: represents the tags job info
0117      */
0118     void tagsListing(const TagsDBJobInfo& info);
0119 
0120 Q_SIGNALS:
0121 
0122     void foldersData(const QHash<int, int>&);
0123     void faceFoldersData(const QMap<QString, QHash<int, int> >&);
0124 };
0125 
0126 // ---------------------------------------------
0127 
0128 class DIGIKAM_DATABASE_EXPORT DatesDBJobsThread : public DBJobsThread
0129 {
0130     Q_OBJECT
0131 
0132 public:
0133 
0134     explicit DatesDBJobsThread(QObject* const parent);
0135     ~DatesDBJobsThread() override;
0136 
0137     /**
0138      * @brief Starts dates listing and scanning
0139      * @param info: represents the dates job info
0140      */
0141     void datesListing(const DatesDBJobInfo& info);
0142 
0143 Q_SIGNALS:
0144 
0145     void foldersData(const QHash<QDateTime, int>&);
0146 };
0147 
0148 // ---------------------------------------------
0149 
0150 class DIGIKAM_DATABASE_EXPORT SearchesDBJobsThread : public DBJobsThread
0151 {
0152     Q_OBJECT
0153 
0154 public:
0155 
0156     explicit SearchesDBJobsThread(QObject* const parent);
0157     ~SearchesDBJobsThread() override;
0158 
0159     /**
0160      * @brief Starts searches listing and scanning
0161      * @param info: represents the searches job info
0162      */
0163     void searchesListing(const SearchesDBJobInfo& info);
0164 
0165 public Q_SLOTS:
0166 
0167     void slotImageProcessed();
0168     void slotDuplicatesResults(const HaarIface::DuplicatesResultsMap&);
0169 
0170 Q_SIGNALS:
0171 
0172     void signalProgress(int percentage);
0173 
0174 private:
0175     HaarIface::DuplicatesResultsMap m_results;
0176     QScopedPointer<HaarIface>       m_haarIface;
0177     bool                            m_isAlbumUpdate;
0178     int                             m_processedImages;
0179     int                             m_totalImages2Scan;
0180 };
0181 
0182 // ---------------------------------------------
0183 
0184 class DIGIKAM_DATABASE_EXPORT GPSDBJobsThread : public DBJobsThread
0185 {
0186     Q_OBJECT
0187 
0188 public:
0189 
0190     explicit GPSDBJobsThread(QObject* const parent);
0191     ~GPSDBJobsThread() override;
0192 
0193     /**
0194      * @brief Starts GPS listing and scanning
0195      * @param info: represents the GPS job info
0196      */
0197     void GPSListing(const GPSDBJobInfo& info);
0198 
0199 Q_SIGNALS:
0200 
0201     void directQueryData(const QList<QVariant>& data);
0202 };
0203 
0204 } // namespace Digikam
0205 
0206 #endif // DIGIKAM_DB_JOBS_THREAD_H