File indexing completed on 2024-03-24 15:33:37

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                                const KIO::MetaData &metaData = KIO::MetaData(),
0104                                QWidget *parent = nullptr) override
0105     {
0106         Q_UNUSED(type)
0107         Q_UNUSED(text)
0108         Q_UNUSED(title)
0109         Q_UNUSED(primaryActionText)
0110         Q_UNUSED(secondaryActionText)
0111         Q_UNUSED(primaryActionIconName)
0112         Q_UNUSED(secondaryActionIconName)
0113         Q_UNUSED(dontAskAgainName)
0114         Q_UNUSED(details)
0115         Q_UNUSED(metaData)
0116         Q_UNUSED(parent)
0117     }
0118 
0119     void clear()
0120     {
0121         m_askUserRenameCalled = 0;
0122         m_askUserSkipCalled = 0;
0123         m_askUserDeleteCalled = 0;
0124         m_messageBoxCalled = 0;
0125         m_delType = DeletionType::Delete;
0126     }
0127 
0128     // yeah, public, for get and reset.
0129     int m_askUserRenameCalled = 0;
0130     int m_askUserSkipCalled = 0;
0131     int m_askUserDeleteCalled = 0;
0132     int m_messageBoxCalled = 0;
0133 
0134     KIO::RenameDialog_Result m_renameResult = KIO::Result_Skip;
0135     KIO::SkipDialog_Result m_skipResult = KIO::Result_Skip;
0136     bool m_deleteResult = false;
0137     int m_messageBoxResult = 0;
0138     QUrl m_newDestUrl;
0139     DeletionType m_delType;
0140 };
0141 
0142 #endif // MOCKDELEGATEEXTENSIONS_H