digiKam
exiftoolprocess.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2021-02-18
7  * Description : Qt5 and Qt6 interface for exiftool.
8  * Based on ZExifTool Qt interface published at 18 Feb 2021
9  * https://github.com/philvl/ZExifTool
10  *
11  * Copyright (C) 2021-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  * Copyright (c) 2021 by Philippe Vianney Liaud <philvl dot dev at gmail dot com>
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General
16  * Public License as published by the Free Software Foundation;
17  * either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #ifndef DIGIKAM_EXIFTOOL_PROCESS_H
28 #define DIGIKAM_EXIFTOOL_PROCESS_H
29 
30 // Qt Core
31 
32 #include <QObject>
33 #include <QString>
34 #include <QProcess>
35 #include <QMutex>
36 
37 // Local includes
38 
39 #include "digikam_export.h"
40 
41 namespace Digikam
42 {
43 
44 class DIGIKAM_EXPORT ExifToolProcess : public QObject
45 {
46  Q_OBJECT
47 
48 public:
49 
53  enum Action
54  {
55  LOAD_METADATA = 0,
66  NO_ACTION
67  };
68 
73  {
74  COPY_EXIF = 0x01,
75  COPY_MAKERNOTES = 0x02,
76  COPY_IPTC = 0x04,
77  COPY_XMP = 0x08,
78  COPY_ICC = 0x10,
79  COPY_ALL = 0x20,
80  COPY_NONE = 0x40
81  };
82 
87  {
88  WRITE_EXISTING_TAGS = 0x01,
89  CREATE_NEW_TAGS = 0x02,
90  CREATE_NEW_GROUPS = 0x04,
91  ALL_MODES = WRITE_EXISTING_TAGS |
92  CREATE_NEW_TAGS |
93  CREATE_NEW_GROUPS
94  };
95 
100  {
101  TRANS_ALL_XMP = 0x01,
102  TRANS_ALL_IPTC = 0x02,
103  TRANS_ALL_EXIF = 0x04
104  };
105 
106 public:
107 
111  explicit ExifToolProcess(QObject* const parent);
112 
117  ~ExifToolProcess();
118 
119 public:
120 
124  void setProgram(const QString& etExePath,
125  const QString& perlExePath = QString());
126 
127  QString program() const;
128 
129  bool checkExifToolProgram();
130 
134  bool start();
135 
139  void terminate();
140 
146  void kill();
147 
148 public:
149 
153  bool isRunning() const;
154 
158  bool isBusy() const;
159 
164  qint64 processId() const;
165 
169  QProcess::ProcessState state() const;
170 
174  QProcess::ProcessError error() const;
175 
179  QString errorString() const;
180 
184  QProcess::ExitStatus exitStatus() const;
185 
186  int exitCode() const;
187 
192  bool waitForStarted(int msecs = 30000) const;
193 
198  bool waitForFinished(int msecs = 30000) const;
199 
204  int command(const QByteArrayList& args, Action ac);
205 
206 Q_SIGNALS:
207 
208  void signalStarted(int cmdAction);
209 
210  void signalStateChanged(int cmdAction,
211  QProcess::ProcessState newState);
212 
213  void signalErrorOccurred(int cmdAction,
214  QProcess::ProcessError error);
215 
216  void signalFinished(int cmdAction,
217  int exitCode,
218  QProcess::ExitStatus exitStatus);
219 
220  void signalCmdCompleted(int cmdAction,
221  int execTime,
222  const QByteArray& cmdOutputChannel,
223  const QByteArray& cmdErrorChannel);
224 
225 private Q_SLOTS:
226 
227  void slotStarted();
228  void slotStateChanged(QProcess::ProcessState newState);
229  void slotErrorOccurred(QProcess::ProcessError error);
230  void slotReadyReadStandardOutput();
231  void slotReadyReadStandardError();
232  void slotFinished(int exitCode,
233  QProcess::ExitStatus exitStatus);
234 
235 private:
236 
237  QString exifToolBin() const;
238 
239 private:
240 
241  class Private;
242  Private* const d;
243 };
244 
245 } // namespace Digikam
246 
247 #endif // DIGIKAM_EXIFTOOL_PROCESS_H
Definition: exiftoolprocess_p.h:49
Definition: exiftoolprocess.h:45
TranslateTagsOps
Definition: exiftoolprocess.h:100
CopyTagsSource
Definition: exiftoolprocess.h:73
WritingTagsMode
Definition: exiftoolprocess.h:87
void signalStarted(int cmdAction)
void signalStateChanged(int cmdAction, QProcess::ProcessState newState)
void signalErrorOccurred(int cmdAction, QProcess::ProcessError error)
void signalFinished(int cmdAction, int exitCode, QProcess::ExitStatus exitStatus)
void signalCmdCompleted(int cmdAction, int execTime, const QByteArray &cmdOutputChannel, const QByteArray &cmdErrorChannel)
Action
Definition: exiftoolprocess.h:54
@ LOAD_CHUNKS
Load Exif, Iptc, and Xmp chunks from a file as byte-array for MetaEngine.
Definition: exiftoolprocess.h:56
@ VERSION_STRING
Return the ExifTool version as string.
Definition: exiftoolprocess.h:63
@ COPY_TAGS
Copy tags from one file to another one. See CopyTagsSource enum for details.
Definition: exiftoolprocess.h:64
@ APPLY_CHANGES_EXV
Apply tag changes in a file with ExifTool using an EXV container.
Definition: exiftoolprocess.h:58
@ APPLY_CHANGES
Apply tag changes in a file with ExifTool.
Definition: exiftoolprocess.h:57
@ TRANS_TAGS
Translate tags in file. See TranslateTagsOps enum for details.
Definition: exiftoolprocess.h:65
@ READ_FORMATS
Return the list of readable ExifTool file formats.
Definition: exiftoolprocess.h:59
@ TRANSLATIONS_LIST
List of ExifTool languages available for translations.
Definition: exiftoolprocess.h:61
@ TAGS_DATABASE
List of ExifTool tags from database.
Definition: exiftoolprocess.h:62
@ WRITE_FORMATS
Return the list of writable ExifTool file formats.
Definition: exiftoolprocess.h:60
Definition: datefolderview.cpp:43