File indexing completed on 2024-06-02 04:17:20
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2016-08-14 0007 * Description : An unit test to read or write metadata through multi-core threads. 0008 * 0009 * SPDX-FileCopyrightText: 2016-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_META_READER_THREAD_UTEST_H 0016 #define DIGIKAM_META_READER_THREAD_UTEST_H 0017 0018 // Qt includes 0019 0020 #include <QList> 0021 #include <QUrl> 0022 #include <QMap> 0023 #include <QElapsedTimer> 0024 0025 // Local includes 0026 0027 #include "abstractunittest.h" 0028 #include "metaenginesettingscontainer.h" 0029 #include "dmetadatasettingscontainer.h" 0030 #include "actionthreadbase.h" 0031 0032 using namespace Digikam; 0033 0034 // ------------------------------------------------------------------------- 0035 // Multi-threads manager for separated job 0036 0037 class MetaReaderThread : public ActionThreadBase 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 0043 enum Direction 0044 { 0045 NOT_DEFINED = -1, 0046 READ_INFO_FROM_FILE = 0, /// Read lead metadata info from file used to populate the core-database. 0047 READ_PREVIEW_FROM_FILE = 1, /// Read preview from file to populate thumbs-database. 0048 WRITE_INFO_TO_SIDECAR = 2 /// Write metadata info to sidecar. 0049 }; 0050 0051 public: 0052 0053 explicit MetaReaderThread(QObject* const parent); 0054 ~MetaReaderThread() override; 0055 0056 void readMetadata(const QList<QUrl>& list, 0057 Direction direction, 0058 const MetaEngineSettingsContainer& settings, 0059 const QString& temp); 0060 0061 QString stats(const QStringList& mimeTypes); 0062 0063 static QString directionToString(Direction direction); 0064 0065 public: 0066 0067 QElapsedTimer m_timer; 0068 0069 protected Q_SLOTS: 0070 0071 void slotJobFinished(); 0072 void slotStats(const QUrl& url, bool p); 0073 0074 Q_SIGNALS: 0075 0076 void done(); 0077 0078 private: 0079 0080 QMultiMap<QUrl, bool> m_stats; // Map of type-mime, and file processed. 0081 }; 0082 0083 // ------------------------------------------------------------------------- 0084 // Separated job multi-threaded to run operations over file metadata 0085 0086 class Mytask : public ActionJob 0087 { 0088 Q_OBJECT 0089 0090 public: 0091 0092 explicit Mytask(QObject* const parent = nullptr); 0093 0094 public: 0095 0096 QUrl url; 0097 MetaReaderThread::Direction direction; 0098 MetaEngineSettingsContainer settings; 0099 QString tempDir; 0100 0101 protected: 0102 0103 void run() override; 0104 0105 Q_SIGNALS: 0106 0107 void signalStats(const QUrl&, bool); 0108 }; 0109 0110 // ------------------------------------------------------------------------- 0111 // Unit-test class 0112 0113 class MetaReaderThreadTest : public AbstractUnitTest 0114 { 0115 Q_OBJECT 0116 0117 public: 0118 0119 explicit MetaReaderThreadTest(QObject* const parent = nullptr); 0120 0121 private: 0122 0123 void runMetaReader(const QString& path, 0124 const QStringList& mimeTypes, 0125 MetaReaderThread::Direction direction, 0126 const MetaEngineSettingsContainer& settings, 0127 int threadsToUse); 0128 0129 private Q_SLOTS: 0130 0131 void testMetaReaderThread(); 0132 }; 0133 0134 #endif // DIGIKAM_META_READER_THREAD_UTEST_H