File indexing completed on 2025-03-09 03:56:12
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2015-04-13 0007 * Description : Generic process launcher with a capture of console output 0008 * 0009 * SPDX-FileCopyrightText: 2011-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_PROCESS_LAUNCHER_H 0016 #define DIGIKAM_PROCESS_LAUNCHER_H 0017 0018 // Qt includes 0019 0020 #include <QThread> 0021 #include <QString> 0022 #include <QStringList> 0023 0024 // Local includes 0025 0026 #include "digikam_export.h" 0027 0028 namespace Digikam 0029 { 0030 0031 class DIGIKAM_EXPORT ProcessLauncher : public QThread 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 0037 explicit ProcessLauncher(QObject* const parent = nullptr); 0038 ~ProcessLauncher(); 0039 0040 void setProgram(const QString& prog); 0041 void setArguments(const QStringList& args); 0042 void setWorkingDirectory(const QString& dir); 0043 void setTimeOut(int msecs); 0044 0045 /** 0046 * If turned on, all traces from the process are printed on the console. 0047 */ 0048 void setConsoleTraces(bool b); 0049 0050 /** 0051 * Start the process. 0052 */ 0053 void startProcess(); 0054 0055 /** 0056 * Return the exit code from the process. 0057 */ 0058 int exitCode() const; 0059 0060 /** 0061 * Return the elapsed time in ms to run the process. 0062 */ 0063 qint64 elapsedTime() const; 0064 0065 /** 0066 * Return the process outout as string. 0067 */ 0068 QString output() const; 0069 0070 /** 0071 * Return true if the process is startd and completed without error. 0072 */ 0073 bool success() const; 0074 0075 Q_SIGNALS: 0076 0077 void signalComplete(bool success, int exitCode); 0078 0079 private: 0080 0081 void run() override; 0082 0083 private Q_SLOTS: 0084 0085 void slotReadyRead(); 0086 0087 private: 0088 0089 class Private; 0090 Private* const d; 0091 }; 0092 0093 } // namespace Digikam 0094 0095 #endif // DIGIKAM_PROCESS_LAUNCHER_H