File indexing completed on 2024-04-14 03:52:46

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org>
0004     SPDX-FileCopyrightText: 2020 Ahmad Samir <a.samirh78@gmail.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef MOCKDELEGATEEXTENSIONS_H
0010 #define MOCKDELEGATEEXTENSIONS_H
0011 
0012 #include <QUrl>
0013 #include <askuseractioninterface.h>
0014 #include <untrustedprogramhandlerinterface.h>
0015 
0016 class MockUntrustedProgramHandler : public KIO::UntrustedProgramHandlerInterface
0017 {
0018 public:
0019     explicit MockUntrustedProgramHandler(QObject *parent)
0020         : KIO::UntrustedProgramHandlerInterface(parent)
0021     {
0022     }
0023     void showUntrustedProgramWarning(KJob *job, const QString &programName) override
0024     {
0025         Q_UNUSED(job)
0026         m_calls << programName;
0027         Q_EMIT result(m_retVal);
0028     }
0029 
0030     void setRetVal(bool b)
0031     {
0032         m_retVal = b;
0033     }
0034 
0035     QStringList m_calls;
0036 
0037 private:
0038     bool m_retVal = false;
0039 };
0040 
0041 class MockAskUserInterface : public KIO::AskUserActionInterface
0042 {
0043 public:
0044     explicit MockAskUserInterface(QObject *parent = nullptr)
0045         : KIO::AskUserActionInterface(parent)
0046     {
0047     }
0048 
0049     void askUserRename(KJob *job,
0050                        const QString &title,
0051                        const QUrl &src,
0052                        const QUrl &dest,
0053                        KIO::RenameDialog_Options options,
0054                        KIO::filesize_t sizeSrc = KIO::filesize_t(-1),
0055                        KIO::filesize_t sizeDest = KIO::filesize_t(-1),
0056                        const QDateTime &ctimeSrc = QDateTime(),
0057                        const QDateTime &ctimeDest = QDateTime(),
0058                        const QDateTime &mtimeSrc = QDateTime(),
0059                        const QDateTime &mtimeDest = QDateTime()) override
0060     {
0061         Q_UNUSED(title)
0062         Q_UNUSED(src)
0063         Q_UNUSED(dest)
0064         Q_UNUSED(options)
0065         Q_UNUSED(sizeSrc)
0066         Q_UNUSED(sizeDest)
0067         Q_UNUSED(ctimeSrc)
0068         Q_UNUSED(ctimeDest)
0069         Q_UNUSED(mtimeSrc)
0070         Q_UNUSED(mtimeDest)
0071 
0072         ++m_askUserRenameCalled;
0073         Q_EMIT askUserRenameResult(m_renameResult, m_newDestUrl, job);
0074     }
0075 
0076     void askUserSkip(KJob *job, KIO::SkipDialog_Options options, const QString &error_text) override
0077     {
0078         Q_UNUSED(options)
0079         Q_UNUSED(error_text)
0080 
0081         ++m_askUserSkipCalled;
0082         Q_EMIT askUserSkipResult(m_skipResult, job);
0083     }
0084 
0085     void askUserDelete(const QList<QUrl> &urls, DeletionType deletionType, ConfirmationType confirmationType, QWidget *parent = nullptr) override
0086     {
0087         Q_UNUSED(confirmationType)
0088 
0089         ++m_askUserDeleteCalled;
0090         m_delType = deletionType;
0091         Q_EMIT askUserDeleteResult(m_deleteResult, urls, deletionType, parent);
0092     }
0093 
0094     void requestUserMessageBox(MessageDialogType type,
0095                                const QString &text,
0096                                const QString &title,
0097                                const QString &primaryActionText,
0098                                const QString &secondaryActionText,
0099                                const QString &primaryActionIconName = QString(),
0100                                const QString &secondaryActionIconName = QString(),
0101                                const QString &dontAskAgainName = QString(),
0102                                const QString &details = QString(),
0103                                QWidget *parent = nullptr) override
0104     {
0105         Q_UNUSED(type)
0106         Q_UNUSED(text)
0107         Q_UNUSED(title)
0108         Q_UNUSED(primaryActionText)
0109         Q_UNUSED(secondaryActionText)
0110         Q_UNUSED(primaryActionIconName)
0111         Q_UNUSED(secondaryActionIconName)
0112         Q_UNUSED(dontAskAgainName)
0113         Q_UNUSED(details)
0114         Q_UNUSED(parent)
0115     }
0116 
0117     void askIgnoreSslErrors(const QVariantMap & /*sslErrorData*/, QWidget * /*parent*/) override
0118     {
0119     }
0120 
0121     void clear()
0122     {
0123         m_askUserRenameCalled = 0;
0124         m_askUserSkipCalled = 0;
0125         m_askUserDeleteCalled = 0;
0126         m_messageBoxCalled = 0;
0127         m_delType = DeletionType::Delete;
0128     }
0129 
0130     // yeah, public, for get and reset.
0131     int m_askUserRenameCalled = 0;
0132     int m_askUserSkipCalled = 0;
0133     int m_askUserDeleteCalled = 0;
0134     int m_messageBoxCalled = 0;
0135 
0136     KIO::RenameDialog_Result m_renameResult = KIO::Result_Skip;
0137     KIO::SkipDialog_Result m_skipResult = KIO::Result_Skip;
0138     bool m_deleteResult = false;
0139     int m_messageBoxResult = 0;
0140     QUrl m_newDestUrl;
0141     DeletionType m_delType;
0142 };
0143 
0144 #endif // MOCKDELEGATEEXTENSIONS_H