1 /* 2 SPDX-FileCopyrightText: 2008 Harald Hvaal <haraldhv@stud.ntnu.no> 3 4 SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #ifndef QUERIES_H 8 #define QUERIES_H 9 10 #include "kerfuffle_export.h" 11 12 #include <QCheckBox> 13 #include <QString> 14 #include <QHash> 15 #include <QWaitCondition> 16 #include <QMutex> 17 #include <QVariant> 18 19 namespace Kerfuffle 20 { 21 22 typedef QHash<QString, QVariant> QueryData; 23 24 class KERFUFFLE_EXPORT Query 25 { 26 public: 27 /** 28 * Execute the response. It needs to be called from the GUI thread. 29 */ 30 virtual void execute() = 0; 31 32 /** 33 * Will block until the response have been set. 34 * Useful for worker threads that need to show a dialog. 35 */ 36 void waitForResponse(); 37 38 QVariant response() const; 39 40 protected: 41 /** 42 * Protected constructor 43 */ 44 Query(); ~Query()45 virtual ~Query() {} 46 47 void setResponse(const QVariant &response); 48 49 QueryData m_data; 50 51 private: 52 QWaitCondition m_responseCondition; 53 QMutex m_responseMutex; 54 }; 55 56 /* ***************************************************************** 57 * Used to query the user if an existing file should be overwritten. 58 * ***************************************************************** 59 */ 60 class KERFUFFLE_EXPORT OverwriteQuery : public Query 61 { 62 public: 63 explicit OverwriteQuery(const QString& filename); 64 void execute() override; 65 bool responseCancelled(); 66 bool responseOverwriteAll(); 67 bool responseOverwrite(); 68 bool responseRename(); 69 bool responseSkip(); 70 bool responseAutoSkip(); 71 QString newFilename(); 72 73 void setNoRenameMode(bool enableNoRenameMode); 74 bool noRenameMode(); 75 void setMultiMode(bool enableMultiMode); 76 bool multiMode(); 77 private: 78 bool m_noRenameMode; 79 bool m_multiMode; 80 }; 81 82 /* ************************************** 83 * Used to query the user for a password. 84 * ************************************** 85 */ 86 class KERFUFFLE_EXPORT PasswordNeededQuery : public Query 87 { 88 public: 89 explicit PasswordNeededQuery(const QString& archiveFilename, bool incorrectTryAgain = false); 90 void execute() override; 91 92 bool responseCancelled(); 93 QString password(); 94 }; 95 96 /* ************************************************************* 97 * Used to query the user if a corrupt archive should be loaded. 98 * ************************************************************* 99 */ 100 class KERFUFFLE_EXPORT LoadCorruptQuery : public Query 101 { 102 public: 103 explicit LoadCorruptQuery(const QString& archiveFilename); 104 void execute() override; 105 106 bool responseYes(); 107 }; 108 109 class KERFUFFLE_EXPORT ContinueExtractionQuery : public Query 110 { 111 public: 112 explicit ContinueExtractionQuery(const QString& error, const QString& archiveEntry); 113 void execute() override; 114 115 bool responseCancelled(); 116 bool dontAskAgain(); 117 private: 118 QCheckBox m_chkDontAskAgain; 119 }; 120 121 } 122 123 #endif /* ifndef QUERIES_H */ 124