File indexing completed on 2024-05-05 05:50:42

0001 /*
0002     SPDX-FileCopyrightText: 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
0003 
0004     SPDX-License-Identifier: BSD-2-Clause
0005 */
0006 
0007 #ifndef QUERIES_H
0008 #define QUERIES_H
0009 
0010 #include "kerfuffle_export.h"
0011 
0012 #include <QCheckBox>
0013 #include <QHash>
0014 #include <QMutex>
0015 #include <QString>
0016 #include <QVariant>
0017 #include <QWaitCondition>
0018 
0019 namespace Kerfuffle
0020 {
0021 typedef QHash<QString, QVariant> QueryData;
0022 
0023 class KERFUFFLE_EXPORT Query
0024 {
0025 public:
0026     /**
0027      * Execute the response. It needs to be called from the GUI thread.
0028      */
0029     virtual void execute() = 0;
0030 
0031     /**
0032      * Will block until the response have been set.
0033      * Useful for worker threads that need to show a dialog.
0034      */
0035     void waitForResponse();
0036 
0037     QVariant response() const;
0038 
0039 protected:
0040     /**
0041      * Protected constructor
0042      */
0043     Query();
0044     virtual ~Query()
0045     {
0046     }
0047 
0048     void setResponse(const QVariant &response);
0049 
0050     QueryData m_data;
0051 
0052 private:
0053     QWaitCondition m_responseCondition;
0054     QMutex m_responseMutex;
0055 };
0056 
0057 /* *****************************************************************
0058  * Used to query the user if an existing file should be overwritten.
0059  * *****************************************************************
0060  */
0061 class KERFUFFLE_EXPORT OverwriteQuery : public Query
0062 {
0063 public:
0064     explicit OverwriteQuery(const QString &filename);
0065     void execute() override;
0066     bool responseCancelled();
0067     bool responseOverwriteAll();
0068     bool responseOverwrite();
0069     bool responseRename();
0070     bool responseSkip();
0071     bool responseAutoSkip();
0072     QString newFilename();
0073 
0074     void setNoRenameMode(bool enableNoRenameMode);
0075     bool noRenameMode();
0076     void setMultiMode(bool enableMultiMode);
0077     bool multiMode();
0078 
0079 private:
0080     bool m_noRenameMode;
0081     bool m_multiMode;
0082 };
0083 
0084 /* **************************************
0085  * Used to query the user for a password.
0086  * **************************************
0087  */
0088 class KERFUFFLE_EXPORT PasswordNeededQuery : public Query
0089 {
0090 public:
0091     explicit PasswordNeededQuery(const QString &archiveFilename, bool incorrectTryAgain = false);
0092     void execute() override;
0093 
0094     bool responseCancelled();
0095     QString password();
0096 };
0097 
0098 /* *************************************************************
0099  * Used to query the user if a corrupt archive should be loaded.
0100  * *************************************************************
0101  */
0102 class KERFUFFLE_EXPORT LoadCorruptQuery : public Query
0103 {
0104 public:
0105     explicit LoadCorruptQuery(const QString &archiveFilename);
0106     void execute() override;
0107 
0108     bool responseYes();
0109 };
0110 
0111 class KERFUFFLE_EXPORT ContinueExtractionQuery : public Query
0112 {
0113 public:
0114     explicit ContinueExtractionQuery(const QString &error, const QString &archiveEntry);
0115     void execute() override;
0116 
0117     bool responseCancelled();
0118     bool dontAskAgain();
0119 
0120 private:
0121     QCheckBox m_chkDontAskAgain;
0122 };
0123 
0124 }
0125 
0126 Q_DECLARE_METATYPE(Kerfuffle::Query *)
0127 
0128 #endif /* ifndef QUERIES_H */