| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #ifndef OPENWITHHANDLERINTERFACE_H |
| 9 | #define OPENWITHHANDLERINTERFACE_H |
| 10 | |
| 11 | #include <KService> |
| 12 | #include <QObject> |
| 13 | #include <kiogui_export.h> |
| 14 | class QString; |
| 15 | |
| 16 | class KJob; |
| 17 | |
| 18 | namespace KIO |
| 19 | { |
| 20 | class OpenWithHandlerInterfacePrivate; |
| 21 | |
| 22 | /*! |
| 23 | * \class KIO::OpenWithHandlerInterface |
| 24 | * \inheaderfile KIO/OpenWithHandlerInterface |
| 25 | * \inmodule KIOGui |
| 26 | * |
| 27 | * \brief The OpenWithHandlerInterface class allows OpenUrlJob to |
| 28 | * prompt the user about which application to use to open URLs that do not |
| 29 | * have an associated application (via the "Open With" dialog). |
| 30 | * |
| 31 | * This extension mechanism for jobs is similar to KIO::JobUiDelegateExtension |
| 32 | * and UntrustedProgramHandlerInterface. |
| 33 | * |
| 34 | * \since 5.71 |
| 35 | */ |
| 36 | class KIOGUI_EXPORT OpenWithHandlerInterface : public QObject |
| 37 | { |
| 38 | Q_OBJECT |
| 39 | protected: |
| 40 | /*! |
| 41 | * Constructor |
| 42 | */ |
| 43 | explicit OpenWithHandlerInterface(QObject *parent = nullptr); |
| 44 | |
| 45 | ~OpenWithHandlerInterface() override; |
| 46 | |
| 47 | public: |
| 48 | /*! |
| 49 | * Show the "Open With" dialog. |
| 50 | * |
| 51 | * \a job the job calling this. Useful to get all its properties |
| 52 | * |
| 53 | * \a urls the URLs to open |
| 54 | * |
| 55 | * \a mimeType the MIME type of the URLs, if known. Can be empty otherwise. |
| 56 | * |
| 57 | * Implementations of this method must emit either serviceSelected or canceled. |
| 58 | * |
| 59 | * The default implementation in this base class simply emits canceled(). |
| 60 | * Any application using KIO::JobUiDelegate (from KIOWidgets) will benefit from an |
| 61 | * automatically registered subclass which implements this method using KOpenWithDialog. |
| 62 | */ |
| 63 | virtual void promptUserForApplication(KJob *job, const QList<QUrl> &urls, const QString &mimeType); |
| 64 | |
| 65 | Q_SIGNALS: |
| 66 | /*! |
| 67 | * Emitted by promptUserForApplication() once the user chooses an application. |
| 68 | * |
| 69 | * \a service the application chosen by the user |
| 70 | */ |
| 71 | void serviceSelected(const KService::Ptr &service); |
| 72 | |
| 73 | /*! |
| 74 | * Emitted by promptUserForApplication() if the user canceled the application selection dialog. |
| 75 | */ |
| 76 | void canceled(); |
| 77 | |
| 78 | /*! |
| 79 | * Emitted by promptUserForApplication() if it fully handled it including launching the app. |
| 80 | * This is a special case for the native Windows open-with dialog. |
| 81 | */ |
| 82 | void handled(); |
| 83 | |
| 84 | private: |
| 85 | QScopedPointer<OpenWithHandlerInterfacePrivate> d; |
| 86 | }; |
| 87 | |
| 88 | } |
| 89 | |
| 90 | #endif // OPENWITHHANDLERINTERFACE_H |
| 91 | |