File indexing completed on 2024-11-10 03:56:09

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2013-08-09
0007  * Description : Thread actions manager for maintenance tools.
0008  *
0009  * SPDX-FileCopyrightText: 2013-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2017-2018 by Mario Frank <mario dot frank at uni minus potsdam dot de>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_MAINTENANCE_THREAD_H
0017 #define DIGIKAM_MAINTENANCE_THREAD_H
0018 
0019 // Qt includes
0020 
0021 #include <QList>
0022 
0023 // Local includes
0024 
0025 #include "actionthreadbase.h"
0026 #include "metadatasynchronizer.h"
0027 #include "metadataremover.h"
0028 #include "iteminfo.h"
0029 #include "identity.h"
0030 
0031 class QImage;
0032 
0033 namespace Digikam
0034 {
0035 
0036 class ImageQualityContainer;
0037 class MaintenanceData;
0038 
0039 class MaintenanceThread : public ActionThreadBase
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044 
0045     explicit MaintenanceThread(QObject* const parent);
0046     ~MaintenanceThread() override;
0047 
0048     void setUseMultiCore(const bool b);
0049 
0050     void syncMetadata(const ItemInfoList& items, MetadataSynchronizer::SyncDirection dir, bool tagsOnly);
0051     void removeMetadata(const ItemInfoList& items, MetadataRemover::RemoveAction action);
0052     void generateThumbs(const QStringList& paths);
0053     void generateFingerprints(const QList<qlonglong>& itemIds, bool rebuildAll);
0054     void generateTags(const QStringList& paths, int modelType);
0055     void sortByImageQuality(const QStringList& paths, const ImageQualityContainer& quality);
0056 
0057     void computeDatabaseJunk(bool thumbsDb = false, bool facesDb = false, bool similarityDb = false);
0058     void cleanCoreDb(const QList<qlonglong>& imageIds);
0059     void cleanThumbsDb(const QList<int>& thumbnailIds);
0060     void cleanFacesDb(const QList<Identity>& staleIdentities);
0061     void cleanSimilarityDb(const QList<qlonglong>& imageIds);
0062     void shrinkDatabases();
0063 
0064     void cancel();
0065 
0066     QString getThumbFingerprintPath();
0067 
0068 Q_SIGNALS:
0069 
0070     /** Emit when the task has started it's work.
0071      */
0072     void signalStarted();
0073 
0074     /** Emit when an item have been processed. QImage can be used to pass item thumbnail processed.
0075      */
0076     void signalAdvance(const QImage&);
0077 
0078     /** Emit when an itam was processed and on additional information is necessary.
0079      */
0080     void signalAdvance();
0081 
0082     /** Emit when a items list have been fully processed.
0083      */
0084     void signalCompleted();
0085 
0086     /** Signal to emit to sub-tasks to cancel processing.
0087      */
0088     void signalCanceled();
0089 
0090     /** Signal to emit junk data for db cleaner.
0091      */
0092     void signalData(const QList<qlonglong>& staleImageIds,
0093                     const QList<int>& staleThumbIds,
0094                     const QList<Identity>& staleIdentities,
0095                     const QList<qlonglong>& staleSimilarityImageIds);
0096 
0097     /**
0098      * Signal to emit the count of additional items to process.
0099      */
0100     void signalAddItemsToProcess(int count);
0101 
0102     /**
0103      * Signal to emit after processing with info if the processing was done
0104      * and if yes, without errors.
0105      */
0106     void signalFinished(bool done, bool errorFree);
0107 
0108 private Q_SLOTS:
0109 
0110     void slotThreadFinished();
0111 
0112 private:
0113 
0114     /**
0115      * This function generates from the given list
0116      * a list of lists with each embedded list having size
0117      * of at most chunkSize. If chunkSize is zero, the original
0118      * list is the only chunk.
0119      * @param toChunk The list to chunk
0120      * @param chunkSize The chunk size (0 for take everything)
0121      */
0122 /*
0123     template<typename T>
0124     QList<QList<T>> chunkList(const QList<T>& toChunk, int chunkSize=0)
0125     {
0126         QList<QList<T>> chunks;
0127 
0128         // Chunk size 0 means all
0129 
0130         if (chunkSize == 0)
0131         {
0132             chunks << toChunk;
0133             return chunks;
0134         }
0135 
0136         // Buffer the input list
0137         QList<T> toChunkList = toChunk;
0138         QList<T> currentChunk;
0139 
0140         while (!toChunkList.isEmpty())
0141         {
0142             // Set the current chunk to the first n elements
0143             currentChunk = toChunkList.mid(0,chunkSize);
0144             // Set the buffer list to the rest, i.e.
0145             // start at position n and take all from this position
0146             // If n is bigger than the size, an empty list is returned.
0147             // see qarraydata.cpp in Qt implementation.
0148             toChunkList  = toChunkList.mid(chunkSize);
0149             chunks << currentChunk;
0150         }
0151 
0152         return chunks;
0153     }
0154 
0155     int getChunkSize(int elementCount);
0156 */
0157 
0158     MaintenanceData* const data;
0159 };
0160 
0161 } // namespace Digikam
0162 
0163 #endif // DIGIKAM_MAINTENANCE_THREAD_H