File indexing completed on 2024-04-14 03:53:18

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef OPENWITHHANDLERINTERFACE_H
0009 #define OPENWITHHANDLERINTERFACE_H
0010 
0011 #include <KService>
0012 #include <QObject>
0013 #include <kiogui_export.h>
0014 class QString;
0015 
0016 class KJob;
0017 
0018 namespace KIO
0019 {
0020 class OpenWithHandlerInterfacePrivate;
0021 
0022 /**
0023  * @class OpenWithHandlerInterface openwithhandlerinterface.h <KIO/OpenWithHandlerInterface>
0024  * @brief The OpenWithHandlerInterface class allows OpenUrlJob to
0025  * prompt the user about which application to use to open URLs that do not
0026  * have an associated application (via the "Open With" dialog).
0027  *
0028  * This extension mechanism for jobs is similar to KIO::JobUiDelegateExtension
0029  * and UntrustedProgramHandlerInterface.
0030  *
0031  * @since 5.71
0032  */
0033 class KIOGUI_EXPORT OpenWithHandlerInterface : public QObject
0034 {
0035     Q_OBJECT
0036 protected:
0037     /**
0038      * Constructor
0039      */
0040     explicit OpenWithHandlerInterface(QObject *parent = nullptr);
0041 
0042     /**
0043      * Destructor
0044      */
0045     ~OpenWithHandlerInterface() override;
0046 
0047 public:
0048     /**
0049      * Show the "Open With" dialog.
0050      * @param job the job calling this. Useful to get all its properties
0051      * @param urls the URLs to open
0052      * @param mimeType the MIME type of the URLs, if known. Can be empty otherwise.
0053      *
0054      * Implementations of this method must emit either serviceSelected or canceled.
0055      *
0056      * The default implementation in this base class simply emits canceled().
0057      * Any application using KIO::JobUiDelegate (from KIOWidgets) will benefit from an
0058      * automatically registered subclass which implements this method using KOpenWithDialog.
0059      */
0060     virtual void promptUserForApplication(KJob *job, const QList<QUrl> &urls, const QString &mimeType);
0061 
0062 Q_SIGNALS:
0063     /**
0064      * Emitted by promptUserForApplication() once the user chooses an application.
0065      * @param service the application chosen by the user
0066      */
0067     void serviceSelected(const KService::Ptr &service);
0068 
0069     /**
0070      * Emitted by promptUserForApplication() if the user canceled the application selection dialog.
0071      */
0072     void canceled();
0073 
0074     /**
0075      * Emitted by promptUserForApplication() if it fully handled it including launching the app.
0076      * This is a special case for the native Windows open-with dialog.
0077      */
0078     void handled();
0079 
0080 private:
0081     QScopedPointer<OpenWithHandlerInterfacePrivate> d;
0082 };
0083 
0084 }
0085 
0086 #endif // OPENWITHHANDLERINTERFACE_H