File indexing completed on 2024-04-21 16:32:41
0001 /* 0002 SPDX-FileCopyrightText: 2001 Shie Erlich <krusader@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2001 Rafi Yanai <krusader@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 #ifndef KRARCHANDLER_H 0009 #define KRARCHANDLER_H 0010 0011 // QtCore 0012 #include <QObject> 0013 #include <QSet> 0014 #include <QStringList> 0015 #include <QUrl> 0016 0017 #include <KCoreAddons/KProcess> 0018 0019 #include "../../plugins/krarc/krarcbasemanager.h" 0020 0021 namespace KWallet 0022 { 0023 class Wallet; 0024 } 0025 0026 class KrArcObserver : public QObject 0027 { 0028 Q_OBJECT 0029 public: 0030 ~KrArcObserver() override = default; 0031 0032 virtual void processEvents() = 0; 0033 virtual void subJobStarted(const QString &jobTitle, qulonglong count) = 0; 0034 virtual void subJobStopped() = 0; 0035 virtual bool wasCancelled() = 0; 0036 virtual void error(const QString &error) = 0; 0037 virtual void detailedError(const QString &error, const QString &details) = 0; 0038 0039 public slots: 0040 virtual void incrementProgress(int) = 0; 0041 }; 0042 0043 class KrArcHandler : public QObject, public KrArcBaseManager 0044 { 0045 Q_OBJECT 0046 public: 0047 explicit KrArcHandler(QObject *parent = nullptr); 0048 0049 // return the number of files in the archive 0050 qulonglong arcFileCount(const QString &archive, const QString &type, const QString &password, KrArcObserver *observer); 0051 // unpack an archive to destination directory 0052 bool unpack(QString archive, const QString &type, const QString &password, const QString &dest, KrArcObserver *observer); 0053 // pack an archive to destination directory 0054 bool pack(QStringList fileNames, QString type, const QString &dest, qulonglong count, QMap<QString, QString> extraProps, KrArcObserver *observer); 0055 // test an archive 0056 bool test(const QString &archive, const QString &type, const QString &password, KrArcObserver *observer, qulonglong count = 0L); 0057 // returns `true` if the right unpacker exist in the system 0058 static bool arcSupported(QString type); 0059 // return the list of supported packers 0060 static QStringList supportedPackers(); 0061 // returns `true` if the url is an archive (ie: tar:/home/test/file.tar.bz2) 0062 static bool isArchive(const QUrl &url); 0063 // used to determine the type of the archive 0064 QString getType(bool &encrypted, QString fileName, const QString &mime, bool check7zEncrypted = true, bool fast = false); 0065 // queries the password from the user 0066 static QString getPassword(const QString &path); 0067 // detects the archive type 0068 void checkIf7zIsEncrypted(bool &, QString) override; 0069 // returns the registered protocol associated with the mimetype 0070 QString registeredProtocol(const QString &mimetype); 0071 // clear the cache of handled protocols 0072 static void clearProtocolCache(); 0073 0074 private: 0075 //! checks if a returned status ("exit code") of an archiving-related process is OK 0076 static bool checkStatus(const QString &type, int exitCode); 0077 0078 static bool openWallet(); 0079 0080 //! the list of archive mimetypes that are openable by the krarc protocol 0081 QSet<QString> krarcArchiveMimetypes; 0082 0083 //! the cache of handled protocols 0084 static QMap<QString, QString> *slaveMap; 0085 0086 static KWallet::Wallet *wallet; 0087 }; 0088 0089 #endif