File indexing completed on 2024-06-23 10:37:25

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 MOCKGUIDELEGATEEXTENSIONS_H
0010 #define MOCKGUIDELEGATEEXTENSIONS_H
0011 
0012 #include <openorexecutefileinterface.h>
0013 #include <openwithhandlerinterface.h>
0014 
0015 class MockOpenOrExecuteHandler : public KIO::OpenOrExecuteFileInterface
0016 {
0017 public:
0018     explicit MockOpenOrExecuteHandler(QObject *parent)
0019         : KIO::OpenOrExecuteFileInterface(parent)
0020     {
0021     }
0022     void promptUserOpenOrExecute(KJob *job, const QString &mimeType) override
0023     {
0024         Q_UNUSED(job)
0025         Q_UNUSED(mimeType);
0026         if (m_cancelIt) {
0027             Q_EMIT canceled();
0028             m_cancelIt = false;
0029             return;
0030         }
0031 
0032         Q_EMIT executeFile(m_executeFile);
0033     }
0034 
0035     void setExecuteFile(bool b)
0036     {
0037         m_executeFile = b;
0038     }
0039     void setCanceled()
0040     {
0041         m_cancelIt = true;
0042     }
0043 
0044 private:
0045     bool m_executeFile = false;
0046     bool m_cancelIt = false;
0047 };
0048 
0049 class MockOpenWithHandler : public KIO::OpenWithHandlerInterface
0050 {
0051 public:
0052     explicit MockOpenWithHandler(QObject *parent)
0053         : KIO::OpenWithHandlerInterface(parent)
0054     {
0055     }
0056     void promptUserForApplication(KJob *job, const QList<QUrl> &url, const QString &mimeType) override
0057     {
0058         Q_UNUSED(job);
0059         m_urls << url;
0060         m_mimeTypes << mimeType;
0061         if (m_chosenService) {
0062             Q_EMIT serviceSelected(m_chosenService);
0063         } else {
0064             Q_EMIT canceled();
0065         }
0066     }
0067     QList<QUrl> m_urls;
0068     QStringList m_mimeTypes;
0069     KService::Ptr m_chosenService;
0070 };
0071 
0072 #endif // MOCKGUIDELEGATEEXTENSIONS_H