File indexing completed on 2024-04-28 04:58:10
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> 0004 SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef BROWSEREXTENSION_H 0010 #define BROWSEREXTENSION_H 0011 0012 #include "libkonq_export.h" 0013 0014 #include <kparts/openurlarguments.h> 0015 #include <kparts/readonlypart.h> 0016 0017 #include <memory> 0018 0019 #include <QAction> 0020 #include <qplatformdefs.h> //mode_t 0021 0022 #include "browserarguments.h" 0023 #include "windowargs.h" 0024 #include "browserinterface.h" 0025 #include "kf5compat.h" 0026 0027 template<class Key, class T> 0028 class QMap; 0029 template<typename T> 0030 class QList; 0031 0032 class KFileItem; 0033 class KFileItemList; 0034 class QPoint; 0035 struct DelayedRequest; 0036 0037 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 0038 0039 class LIBKONQ_EXPORT BrowserExtension : public KParts::NavigationExtension 0040 { 0041 Q_OBJECT 0042 public: 0043 explicit BrowserExtension(KParts::ReadOnlyPart *parent); 0044 0045 ~BrowserExtension() override; 0046 0047 /** 0048 * Set the parameters to use for opening the next URL. 0049 * This is called by the "hosting" application, to pass parameters to the part. 0050 * @see BrowserArguments 0051 */ 0052 void setBrowserArguments(const BrowserArguments &args); 0053 0054 /** 0055 * Retrieve the set of parameters to use for opening the URL 0056 * (this must be called from openUrl() in the part). 0057 * @see BrowserArguments 0058 */ 0059 BrowserArguments browserArguments() const; 0060 0061 void setBrowserInterface(BrowserInterface *impl); 0062 0063 BrowserInterface *browserInterface() const; 0064 0065 Q_SIGNALS: 0066 /** 0067 * Asks the host (browser) to open @p url. 0068 * To set a reload, the x and y offsets, the service type etc., fill in the 0069 * appropriate fields in the @p args structure. 0070 * Hosts should not connect to this signal but to openUrlRequestDelayed(). 0071 */ 0072 void browserOpenUrlRequest(const QUrl &url, 0073 const KParts::OpenUrlArguments &arguments = KParts::OpenUrlArguments(), 0074 const BrowserArguments &browserArguments = BrowserArguments()); 0075 0076 /** 0077 * This signal is emitted when openUrlRequest() is called, after a 0-seconds timer. 0078 * This allows the caller to terminate what it's doing first, before (usually) 0079 * being destroyed. Parts should never use this signal, hosts should only connect 0080 * to this signal. 0081 */ 0082 void browserOpenUrlRequestDelayed(const QUrl &url, const KParts::OpenUrlArguments &arguments, const BrowserArguments &browserArguments); 0083 0084 /** 0085 * Asks the hosting browser to open a new window for the given @p url 0086 * and return a reference to the content part. 0087 * 0088 * @p arguments is optional additional information about how to open the url, 0089 * @see KParts::OpenUrlArguments 0090 * 0091 * @p browserArguments is optional additional information for web browsers, 0092 * @see BrowserArguments 0093 * 0094 * The request for a pointer to the part is only fulfilled/processed 0095 * if the mimeType is set in the @p browserArguments. 0096 * (otherwise the request cannot be processed synchronously). 0097 */ 0098 void browserCreateNewWindow(const QUrl &url, 0099 const KParts::OpenUrlArguments &arguments = KParts::OpenUrlArguments(), 0100 const BrowserArguments &browserArguments = BrowserArguments(), 0101 const WindowArgs &windowArgs = WindowArgs(), 0102 KParts::ReadOnlyPart **part = nullptr); 0103 0104 0105 /** 0106 * Emit this to make the browser show a standard popup menu for the files @p items. 0107 * 0108 * @param global global coordinates where the popup should be shown 0109 * @param items list of file items which the popup applies to 0110 * @param args OpenUrlArguments, mostly for metadata here 0111 * @param browserArguments BrowserArguments, mostly for referrer 0112 * @param flags enables/disables certain builtin actions in the popupmenu 0113 * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap 0114 */ 0115 void browserPopupMenuFromFiles(const QPoint &global, 0116 const KFileItemList &items, 0117 const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), 0118 const BrowserArguments &browserArguments = BrowserArguments(), 0119 KParts::NavigationExtension::PopupFlags flags = KParts::NavigationExtension::DefaultPopupItems, 0120 const KParts::NavigationExtension::ActionGroupMap &actionGroups = ActionGroupMap()); 0121 0122 /** 0123 * Emit this to make the browser show a standard popup menu for the given @p url. 0124 * 0125 * Give as much information about this URL as possible, 0126 * like @p args.mimeType and the file type @p mode 0127 * 0128 * @param global global coordinates where the popup should be shown 0129 * @param url the URL this popup applies to 0130 * @param mode the file type of the url (S_IFREG, S_IFDIR...) 0131 * @param args OpenUrlArguments, set the mimetype of the URL using setMimeType() 0132 * @param browserArguments BrowserArguments, mostly for referrer 0133 * @param flags enables/disables certain builtin actions in the popupmenu 0134 * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap 0135 */ 0136 void browserPopupMenuFromUrl(const QPoint &global, 0137 const QUrl &url, 0138 mode_t mode = static_cast<mode_t>(-1), 0139 const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), 0140 const BrowserArguments &browserArguments = BrowserArguments(), 0141 KParts::NavigationExtension::PopupFlags flags = KParts::NavigationExtension::DefaultPopupItems, 0142 const KParts::NavigationExtension::ActionGroupMap &actionGroups = ActionGroupMap()); 0143 0144 private Q_SLOTS: 0145 void slotCompleted(); 0146 void slotEmitOpenUrlRequestDelayed(); 0147 void slotOpenUrlRequest(const QUrl &url, 0148 const KParts::OpenUrlArguments &arguments, 0149 const BrowserArguments &browserArguments); 0150 0151 private: 0152 BrowserArguments m_browserArgs; 0153 QList<DelayedRequest> m_requests; 0154 BrowserInterface *m_browserInterface = nullptr; 0155 }; 0156 0157 #else 0158 using BrowserExtension = KParts::BrowserExtension; 0159 #endif 0160 0161 #endif