File indexing completed on 2025-01-19 03:56:04

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2021-02-18
0007  * Description : Qt5 and Qt6 interface for exiftool - private container.
0008  *               Based on ZExifTool Qt interface published at 18 Feb 2021
0009  *               https://github.com/philvl/ZExifTool
0010  *
0011  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  * SPDX-FileCopyrightText: 2021 by Philippe Vianney Liaud <philvl dot dev at gmail dot com>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #ifndef DIGIKAM_EXIFTOOL_PROCESS_P_H
0019 #define DIGIKAM_EXIFTOOL_PROCESS_P_H
0020 
0021 #include "exiftoolprocess.h"
0022 
0023 // Qt includes
0024 
0025 #include <QFile>
0026 #include <QList>
0027 #include <QMutex>
0028 #include <QFileInfo>
0029 #include <QByteArray>
0030 #include <QElapsedTimer>
0031 #include <QStandardPaths>
0032 #include <QWaitCondition>
0033 
0034 // KDE includes
0035 
0036 #include <klocalizedstring.h>
0037 
0038 // Local includes
0039 
0040 #include "digikam_debug.h"
0041 #include "digikam_config.h"
0042 #include "digikam_globals.h"
0043 #include "metaenginesettings.h"
0044 
0045 #define CMD_ID_MIN 1
0046 #define CMD_ID_MAX 2000000000
0047 
0048 namespace Digikam
0049 {
0050 
0051 class Q_DECL_HIDDEN ExifToolProcess::Private : public QObject
0052 {
0053     Q_OBJECT
0054 
0055 public:
0056 
0057     class Q_DECL_HIDDEN Command
0058     {
0059     public:
0060 
0061         Command()
0062           : id     (0),
0063             ac     (ExifToolProcess::NO_ACTION)
0064         {
0065         }
0066 
0067         int                     id;
0068         QByteArray              argsStr;
0069         ExifToolProcess::Action ac;
0070     };
0071 
0072 public:
0073 
0074     explicit Private(ExifToolProcess* const q);
0075 
0076     void readOutput(const QProcess::ProcessChannel channel);
0077     void setProcessErrorAndEmit(QProcess::ProcessError error,
0078                                 const QString& description);
0079     void setCommandResult(int cmdStatus);
0080 
0081 public Q_SLOTS:
0082 
0083     void slotExecNextCmd();
0084 
0085 public:
0086 
0087     ExifToolProcess*                   pp;
0088     QString                            etExePath;
0089     QString                            perlExePath;
0090 
0091     QElapsedTimer                      execTimer;
0092     QList<Command>                     cmdQueue;
0093     int                                cmdNumber;
0094     ExifToolProcess::Action            cmdAction;
0095     QMap<int, ExifToolProcess::Result> resultMap;
0096 
0097     int                                outAwait[2];             ///< [0] StandardOutput | [1] ErrorOutput
0098     bool                               outReady[2];             ///< [0] StandardOutput | [1] ErrorOutput
0099     QByteArray                         outBuff[2];              ///< [0] StandardOutput | [1] ErrorOutput
0100 
0101     bool                               writeChannelIsClosed;
0102 
0103     QProcess::ProcessError             processError;
0104     QString                            errorString;
0105 
0106     int                                nextCmdId;               ///< Unique identifier, even in a multi-instances or multi-thread environment
0107 
0108     QMutex                             cmdMutex;
0109 
0110     QMutex                             mutex;
0111     QWaitCondition                     condVar;
0112 };
0113 
0114 } // namespace Digikam
0115 
0116 #endif // DIGIKAM_EXIFTOOL_PROCESS_P_H