File indexing completed on 2024-05-12 16:06:33
0001 /* 0002 SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef UNRAR_H 0008 #define UNRAR_H 0009 0010 #include <QObject> 0011 #include <QProcess> 0012 #include <QStringList> 0013 0014 #include <unrarflavours.h> 0015 0016 class QEventLoop; 0017 class QTemporaryDir; 0018 0019 #if defined(WITH_KPTY) 0020 class KPtyProcess; 0021 #endif 0022 0023 class Unrar : public QObject 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 /** 0029 * Creates a new unrar object. 0030 */ 0031 Unrar(); 0032 0033 /** 0034 * Destroys the unrar object. 0035 */ 0036 ~Unrar() override; 0037 0038 /** 0039 * Opens given rar archive. 0040 */ 0041 bool open(const QString &fileName); 0042 0043 /** 0044 * Returns the list of files from the archive. 0045 */ 0046 QStringList list(); 0047 0048 /** 0049 * Returns the content of the file with the given name. 0050 */ 0051 QByteArray contentOf(const QString &fileName) const; 0052 0053 /** 0054 * Returns a new device for reading the file with the given name. 0055 */ 0056 QIODevice *createDevice(const QString &fileName) const; 0057 0058 static bool isAvailable(); 0059 static bool isSuitableVersionAvailable(); 0060 0061 private Q_SLOTS: 0062 void readFromStdout(); 0063 void readFromStderr(); 0064 void finished(int exitCode, QProcess::ExitStatus exitStatus); 0065 0066 private: 0067 int startSyncProcess(const ProcessArgs &args); 0068 void writeToProcess(const QByteArray &data); 0069 0070 #if defined(WITH_KPTY) 0071 KPtyProcess *mProcess; 0072 #else 0073 QProcess *mProcess; 0074 #endif 0075 QEventLoop *mLoop; 0076 QString mFileName; 0077 QByteArray mStdOutData; 0078 QByteArray mStdErrData; 0079 QTemporaryDir *mTempDir; 0080 }; 0081 0082 #endif