diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 6c3bde96..5cbbca28 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -386,12 +386,10 @@ install( install( FILES - KParts/BrowserExtension KParts/Event KParts/Factory KParts/GUIActivateEvent KParts/MainWindow - KParts/OpenUrlEvent KParts/Part KParts/PartBase KParts/ReadOnlyPart diff --git a/includes/KParts/BrowserExtension b/includes/KParts/BrowserExtension deleted file mode 100644 index 5f0072f0..00000000 --- a/includes/KParts/BrowserExtension +++ /dev/null @@ -1 +0,0 @@ -#include "../../kparts/browserextension.h" diff --git a/includes/KParts/OpenUrlEvent b/includes/KParts/OpenUrlEvent deleted file mode 100644 index 5f0072f0..00000000 --- a/includes/KParts/OpenUrlEvent +++ /dev/null @@ -1 +0,0 @@ -#include "../../kparts/browserextension.h" diff --git a/kparts/CMakeLists.txt b/kparts/CMakeLists.txt index b01255d3..cb64e5f9 100644 --- a/kparts/CMakeLists.txt +++ b/kparts/CMakeLists.txt @@ -16,7 +16,6 @@ set(kparts_LIB_SRCS part.cpp mainwindow.cpp event.cpp - browserextension.cpp factory.cpp statusbarextension.cpp ) @@ -58,7 +57,6 @@ install( part.h mainwindow.h event.h - browserextension.h factory.h statusbarextension.h DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/kparts diff --git a/kparts/browserextension.cpp b/kparts/browserextension.cpp deleted file mode 100644 index d5c6b585..00000000 --- a/kparts/browserextension.cpp +++ /dev/null @@ -1,537 +0,0 @@ - /* This file is part of the KDE project - Copyright (C) 1999 Simon Hausmann - (C) 1999 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#include "browserextension.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -using namespace KParts; - - -class OpenUrlEvent::OpenUrlEventPrivate -{ -public: - OpenUrlEventPrivate(ReadOnlyPart *part, - const KUrl &url, - const OpenUrlArguments &args, - const BrowserArguments &browserArgs) - : m_part(part) - , m_url(url) - , m_args(args) - , m_browserArgs(browserArgs) - { - } - - static const char *s_strOpenUrlEvent; - ReadOnlyPart *m_part; - KUrl m_url; - OpenUrlArguments m_args; - BrowserArguments m_browserArgs; -}; - -const char *OpenUrlEvent::OpenUrlEventPrivate::s_strOpenUrlEvent = - "KParts/BrowserExtension/OpenURLevent"; - -OpenUrlEvent::OpenUrlEvent(ReadOnlyPart *part, const KUrl &url, - const OpenUrlArguments &args, - const BrowserArguments &browserArgs) - : Event(OpenUrlEventPrivate::s_strOpenUrlEvent ) - , d(new OpenUrlEventPrivate(part, url, args, browserArgs)) -{ -} - -OpenUrlEvent::~OpenUrlEvent() -{ - delete d; -} - -ReadOnlyPart *OpenUrlEvent::part() const -{ - return d->m_part; -} - -KUrl OpenUrlEvent::url() const -{ - return d->m_url; -} - -OpenUrlArguments OpenUrlEvent::arguments() const -{ - return d->m_args; -} - -BrowserArguments OpenUrlEvent::browserArguments() const -{ - return d->m_browserArgs; -} - -bool OpenUrlEvent::test(const QEvent *event) -{ - return Event::test(event, OpenUrlEventPrivate::s_strOpenUrlEvent); -} - -namespace KParts -{ - -struct BrowserArgumentsPrivate -{ - BrowserArgumentsPrivate() - { - doPost = false; - redirectedRequest = false; - lockHistory = false; - newTab = false; - forcesNewWindow = false; - } - - QString contentType; // for POST - bool doPost; - bool redirectedRequest; - bool lockHistory; - bool newTab; - bool forcesNewWindow; -}; - -} - -BrowserArguments::BrowserArguments() -{ - softReload = false; - trustedSource = false; - d = 0; // Let's build it on demand for now -} - -BrowserArguments::BrowserArguments(const BrowserArguments &args) -{ - d = 0; - (*this) = args; -} - -BrowserArguments &BrowserArguments::operator=(const BrowserArguments &args) -{ - if (this == &args) { - return *this; - } - - delete d; - d = nullptr; - - softReload = args.softReload; - postData = args.postData; - frameName = args.frameName; - docState = args.docState; - trustedSource = args.trustedSource; - - if (args.d) { - d = new BrowserArgumentsPrivate(*args.d); - } - - return *this; -} - -BrowserArguments::~BrowserArguments() -{ - delete d; - d = nullptr; -} - -void BrowserArguments::setContentType(const QString &contentType) -{ - if (!d) { - d = new BrowserArgumentsPrivate(); - } - d->contentType = contentType; -} - -void BrowserArguments::setRedirectedRequest(bool redirected) -{ - if (!d) { - d = new BrowserArgumentsPrivate(); - } - d->redirectedRequest = redirected; -} - -bool BrowserArguments::redirectedRequest() const -{ - return d ? d->redirectedRequest : false; -} - -QString BrowserArguments::contentType() const -{ - return d ? d->contentType : QString(); -} - -void BrowserArguments::setDoPost(bool enable) -{ - if (!d) { - d = new BrowserArgumentsPrivate(); - } - d->doPost = enable; -} - -bool BrowserArguments::doPost() const -{ - return d ? d->doPost : false; -} - -void BrowserArguments::setLockHistory(bool lock) -{ - if (!d) { - d = new BrowserArgumentsPrivate(); - } - d->lockHistory = lock; -} - -bool BrowserArguments::lockHistory() const -{ - return d ? d->lockHistory : false; -} - -void BrowserArguments::setNewTab(bool newTab) -{ - if (!d) { - d = new BrowserArgumentsPrivate(); - } - d->newTab = newTab; -} - -bool BrowserArguments::newTab() const -{ - return d ? d->newTab : false; -} - -void BrowserArguments::setForcesNewWindow(bool forcesNewWindow) -{ - if (!d) { - d = new BrowserArgumentsPrivate(); - } - d->forcesNewWindow = forcesNewWindow; -} - -bool BrowserArguments::forcesNewWindow() const -{ - return d ? d->forcesNewWindow : false; -} - -namespace KParts -{ - -class BrowserExtension::BrowserExtensionPrivate -{ -public: - BrowserExtensionPrivate(KParts::ReadOnlyPart *parent) - : m_urlDropHandlingEnabled(false), - m_part(parent) - { - } - - struct DelayedRequest { - KUrl m_delayedURL; - KParts::OpenUrlArguments m_delayedArgs; - KParts::BrowserArguments m_delayedBrowserArgs; - }; - - QList m_requests; - bool m_urlDropHandlingEnabled; - QBitArray m_actionStatus; - QMap m_actionText; - - static void createActionSlotMap(); - - KParts::ReadOnlyPart *m_part; - OpenUrlArguments m_args; - BrowserArguments m_browserArgs; -}; - -K_GLOBAL_STATIC(BrowserExtension::ActionSlotMap, s_actionSlotMap) -K_GLOBAL_STATIC(BrowserExtension::ActionNumberMap, s_actionNumberMap) - -void BrowserExtension::BrowserExtensionPrivate::createActionSlotMap() -{ - s_actionSlotMap->insert("cut", SLOT(cut())); - s_actionSlotMap->insert("copy", SLOT(copy())); - s_actionSlotMap->insert("paste", SLOT(paste())); - s_actionSlotMap->insert("print", SLOT(print())); - // Tricky. Those aren't actions in fact, but simply methods that a browserextension - // can have or not. No need to return them here. - //s_actionSlotMap->insert( "reparseConfiguration", SLOT(reparseConfiguration()) ); - //s_actionSlotMap->insert( "refreshMimeTypes", SLOT(refreshMimeTypes()) ); - - // Create the action-number map - ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin(); - ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->constEnd(); - for (int i = 0 ; it != itEnd ; ++it, ++i) { - // kDebug() << " action " << it.key() << " number " << i; - s_actionNumberMap->insert( it.key(), i ); - } -} - -} - -BrowserExtension::BrowserExtension(KParts::ReadOnlyPart *parent) - : QObject(parent), - d(new BrowserExtensionPrivate(parent)) -{ - // kDebug() << "BrowserExtension::BrowserExtension() " << this; - - if (s_actionSlotMap->isEmpty()) { - // Create the action-slot map - BrowserExtensionPrivate::createActionSlotMap(); - } - - // Build list with this extension's slot names. - QList slotNames; - int methodCount = metaObject()->methodCount(); - int methodOffset = metaObject()->methodOffset(); - for (int i= 0; i < methodCount; ++i) { - QMetaMethod method = metaObject()->method(methodOffset + i); - if (method.methodType() == QMetaMethod::Slot) { - slotNames.append(method.signature()); - } - } - - // Set the initial status of the actions depending on whether - // they're supported or not - ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin(); - ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->constEnd(); - for (int i = 0 ; it != itEnd ; ++it, ++i) { - // Does the extension have a slot with the name of this action ? - // ######### KDE4 TODO: use QMetaObject::indexOfMethod() ####### - d->m_actionStatus.setBit(i, slotNames.contains(it.key()+"()")); - } - - connect( - d->m_part, SIGNAL(completed()), - this, SLOT(slotCompleted()) - ); - connect( - this, SIGNAL(openUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)), - this, SLOT(slotOpenUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)) - ); - connect( - this, SIGNAL(enableAction(const char*,bool)), - this, SLOT(slotEnableAction(const char*,bool)) - ); - connect( - this, SIGNAL(setActionText(const char*,QString)), - this, SLOT(slotSetActionText(const char*,QString)) - ); -} - -BrowserExtension::~BrowserExtension() -{ - // kDebug() << "BrowserExtension::~BrowserExtension() " << this; - delete d; -} - -void BrowserExtension::setBrowserArguments( const BrowserArguments &args ) -{ - d->m_browserArgs = args; -} - -BrowserArguments BrowserExtension::browserArguments() const -{ - return d->m_browserArgs; -} - -int BrowserExtension::xOffset() -{ - return 0; -} - -int BrowserExtension::yOffset() -{ - return 0; -} - -void BrowserExtension::saveState(QDataStream &stream) -{ - // TODO add d->m_part->mimeType() - stream << d->m_part->url() << (qint32)xOffset() << (qint32)yOffset(); -} - -void BrowserExtension::restoreState( QDataStream &stream ) -{ - KUrl u; - qint32 xOfs = 0; - qint32 yOfs = 0; - stream >> u >> xOfs >> yOfs; - - OpenUrlArguments args; - args.setXOffset(xOfs); - args.setYOffset(yOfs); - // TODO add args.setMimeType - d->m_part->setArguments(args); - d->m_part->openUrl(u); -} - -bool BrowserExtension::isURLDropHandlingEnabled() const -{ - return d->m_urlDropHandlingEnabled; -} - -void BrowserExtension::setURLDropHandlingEnabled(bool enable) -{ - d->m_urlDropHandlingEnabled = enable; -} - -void BrowserExtension::slotCompleted() -{ - // empty the argument stuff, to avoid bogus/invalid values when opening a new url - setBrowserArguments(BrowserArguments()); -} - -void BrowserExtension::pasteRequest() -{ - QString plain("plain"); - QString url = QApplication::clipboard()->text(plain, QClipboard::Selection).trimmed(); - // Remove linefeeds and any whitespace surrounding it. - url.remove(QRegExp("[\\ ]*\\n+[\\ ]*")); - - // Check if it's a URL - QStringList filters = KUriFilter::self()->pluginNames(); - filters.removeAll( "kuriikwsfilter" ); - filters.removeAll( "localdomainurifilter" ); - KUriFilterData filterData; - filterData.setData( url ); - filterData.setCheckForExecutables(false); - if (KUriFilter::self()->filterUri(filterData, filters)) { - switch (filterData.uriType()) { - case KUriFilterData::LocalFile: - case KUriFilterData::LocalDir: - case KUriFilterData::NetProtocol: { - slotOpenUrlRequest(filterData.uri()); - break; - } - case KUriFilterData::Error: { - KMessageBox::sorry( d->m_part->widget(), filterData.errorMsg()); - break; - } - default: { - break; - } - } - } else if (KUriFilter::self()->filterUri(filterData, QStringList(QLatin1String("kuriikwsfilter"))) && - url.length() < 250 ) - { - if (KMessageBox::questionYesNo(d->m_part->widget(), - i18n("Do you want to search the Internet for %1?", Qt::escape(url)), - i18n("Internet Search"), KGuiItem( i18n( "&Search" ), "edit-find"), - KStandardGuiItem::cancel(), "MiddleClickSearch") == KMessageBox::Yes) - slotOpenUrlRequest(filterData.uri()); - } -} - -void BrowserExtension::slotOpenUrlRequest(const KUrl &url, - const KParts::OpenUrlArguments &args, - const KParts::BrowserArguments &browserArgs) -{ - // kDebug() << this << " BrowserExtension::slotOpenURLRequest(): url=" << url.url(); - BrowserExtensionPrivate::DelayedRequest req; - req.m_delayedURL = url; - req.m_delayedArgs = args; - req.m_delayedBrowserArgs = browserArgs; - d->m_requests.append(req); - QTimer::singleShot(0, this, SLOT(slotEmitOpenUrlRequestDelayed())); -} - -void BrowserExtension::slotEmitOpenUrlRequestDelayed() -{ - if (d->m_requests.isEmpty()) { - return; - } - BrowserExtensionPrivate::DelayedRequest req = d->m_requests.front(); - d->m_requests.pop_front(); - emit openUrlRequestDelayed(req.m_delayedURL, req.m_delayedArgs, req.m_delayedBrowserArgs); - // tricky: do not do anything here! (no access to member variables, etc.) -} - -void BrowserExtension::slotEnableAction(const char *name, bool enabled) -{ - //kDebug() << "BrowserExtension::slotEnableAction " << name << " " << enabled; - ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind(name); - if (it != s_actionNumberMap->constEnd()) { - d->m_actionStatus.setBit( it.value(), enabled ); - //kDebug() << "BrowserExtension::slotEnableAction setting bit " << it.data() << " to " << enabled; - } else { - kWarning() << "BrowserExtension::slotEnableAction unknown action " << name; - } -} - -bool BrowserExtension::isActionEnabled(const char *name) const -{ - int actionNumber = (*s_actionNumberMap)[name]; - return d->m_actionStatus[actionNumber]; -} - -void BrowserExtension::slotSetActionText(const char *name, const QString &text) -{ - //kDebug() << "BrowserExtension::slotSetActionText " << name << " " << text; - ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind(name); - if (it != s_actionNumberMap->constEnd()) { - d->m_actionText[it.value()] = text; - } else { - kWarning() << "BrowserExtension::slotSetActionText unknown action" << name; - } -} - -QString BrowserExtension::actionText(const char *name) const -{ - int actionNumber = (*s_actionNumberMap)[ name ]; - QMap::ConstIterator it = d->m_actionText.constFind(actionNumber); - if (it != d->m_actionText.constEnd()) { - return *it; - } - return QString(); -} - -// for compatibility -BrowserExtension::ActionSlotMap BrowserExtension::actionSlotMap() -{ - return *actionSlotMapPtr(); -} - -BrowserExtension::ActionSlotMap* BrowserExtension::actionSlotMapPtr() -{ - if (s_actionSlotMap->isEmpty()) { - BrowserExtensionPrivate::createActionSlotMap(); - } - return s_actionSlotMap; -} - -BrowserExtension *BrowserExtension::childObject(QObject *obj) -{ - return KGlobal::findDirectChild(obj); -} - -#include "moc_browserextension.cpp" diff --git a/kparts/browserextension.h b/kparts/browserextension.h deleted file mode 100644 index 4029c23b..00000000 --- a/kparts/browserextension.h +++ /dev/null @@ -1,639 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1999 Simon Hausmann - David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __kparts_browserextension_h__ -#define __kparts_browserextension_h__ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -class KFileItem; -class KFileItemList; - -namespace KParts { - -struct BrowserArgumentsPrivate; - -/** - * BrowserArguments is a set of web-browsing-specific arguments, - * which allow specifying how a URL should be opened by openUrl() - * (as a complement to KParts::OpenUrlArguments which are the non-web-specific arguments) - * - * The arguments remain stored in the browser extension after that, - * and can be used for instance to jump to the xOffset/yOffset position - * once the url has finished loading. - * - * The parts (with a browser extension) who care about urlargs will - * use those arguments, others will ignore them. - * - * This can also be used the other way round, when a part asks - * for a URL to be opened (with openUrlRequest or createNewWindow). - */ -struct KPARTS_EXPORT BrowserArguments -{ - BrowserArguments(); - BrowserArguments(const BrowserArguments &args); - BrowserArguments &operator=(const BrowserArguments &args); - - virtual ~BrowserArguments(); - - /** - * This buffer can be used by the part to save and restore its contents. - * See KWebKitPart for instance. - */ - QStringList docState; - - /** - * @p softReload is set when user just hits reload button. It's used - * currently for two different frameset reload strategies. In case of - * soft reload individual frames are reloaded instead of reloading whole - * frameset. - */ - bool softReload; - - /** - * KHTML-specific field, contents of the HTTP POST data. - */ - QByteArray postData; - - /** - * KHTML-specific field, header defining the type of the POST data. - */ - void setContentType(const QString &contentType); - /** - * KHTML-specific field, header defining the type of the POST data. - */ - QString contentType() const; - - /** - * KHTML-specific field, whether to do a POST instead of a GET, - * for the next openURL. - */ - void setDoPost(bool enable); - - /** - * KHTML-specific field, whether to do a POST instead of a GET, - * for the next openURL. - */ - bool doPost() const; - - /** - * Whether to lock the history when opening the next URL. - * This is used during e.g. a redirection, to avoid a new entry - * in the history. - */ - void setLockHistory(bool lock); - bool lockHistory() const; - - /** - * Whether the URL should be opened in a new tab instead in a new window. - */ - void setNewTab(bool newTab); - bool newTab() const; - - /** - * The frame in which to open the URL. KHTML/Konqueror-specific. - */ - QString frameName; - - /** - * If true, the part who asks for a URL to be opened can be 'trusted' - * to execute applications. For instance, the directory views can be - * 'trusted' whereas HTML pages are not trusted in that respect. - */ - bool trustedSource; - - /** - * @return true if the request was a result of a META refresh/redirect request or - * HTTP redirect. - */ - bool redirectedRequest() const; - - /** - * Set the redirect flag to indicate URL is a result of either a META redirect - * or HTTP redirect. - * - * @param redirected - */ - void setRedirectedRequest(bool redirected); - - /** - * Set whether the URL specifies to be opened in a new window. - * - * When openUrlRequest is emitted: - *
    - *
  • normally the url would be opened in the current view.
  • - *
  • setForcesNewWindow(true) specifies that a new window or tab should be used: - * setNewTab(true) requests a tab specifically, otherwise the user-preference is followed. - * This is typically used for target="_blank" in web browsers.
  • - *
- * - * When createNewWindow is emitted: - *
    - *
  • if setNewTab(true) was called, a tab is created.
  • - *
  • otherwise, if setForcesNewWindow(true) was called, a window is created.
  • - *
  • otherwise the user preference is followed.
  • - *
- */ - void setForcesNewWindow(bool forcesNewWindow); - - /** - * Whether the URL specifies to be opened in a new window - */ - bool forcesNewWindow() const; - -private: - BrowserArgumentsPrivate *d; -}; - -/** - * The KParts::OpenUrlEvent event informs that a given part has opened a given URL. - * Applications can use this event to send this information to interested plugins. - * - * The event should be sent before opening the URL in the part, so that the plugins - * can use part()->url() to get the old URL. - */ -class KPARTS_EXPORT OpenUrlEvent : public Event -{ -public: - OpenUrlEvent(ReadOnlyPart *part, const KUrl &url, - const OpenUrlArguments& args = OpenUrlArguments(), - const BrowserArguments& browserArgs = BrowserArguments()); - virtual ~OpenUrlEvent(); - - ReadOnlyPart *part() const; - KUrl url() const; - OpenUrlArguments arguments() const; - BrowserArguments browserArguments() const; - - static bool test(const QEvent *event); - -private: - class OpenUrlEventPrivate; - OpenUrlEventPrivate * const d; -}; - - /** - * The Browser Extension is an extension (yes, no kidding) to - * KParts::ReadOnlyPart, which allows a better integration of parts - * with browsers (in particular Konqueror). - * Remember that ReadOnlyPart only has openUrl(KUrl) and a few arguments() but not much more. - * For full-fledged browsing, we need much more than that, including - * enabling/disabling of standard actions (print, copy, paste...), - * allowing parts to save and restore their data into the back/forward history, - * allowing parts to control the location bar URL, to requests URLs - * to be opened by the hosting browser, etc. - * - * The part developer needs to define its own class derived from BrowserExtension, - * to implement the virtual methods [and the standard-actions slots, see below]. - * - * The way to associate the BrowserExtension with the part is to simply - * create the BrowserExtension as a child of the part (in QObject's terms). - * The hosting application will look for it automatically. - * - * Another aspect of the browser integration is that a set of standard - * actions are provided by the browser, but implemented by the part - * (for the actions it supports). - * - * The following standard actions are defined by the host of the view: - * - * [selection-dependent actions] - * @li @p cut : Copy selected items to clipboard and store 'not cut' in clipboard. - * @li @p copy : Copy selected items to clipboard and store 'cut' in clipboard. - * @li @p paste : Paste clipboard into view URL. - * @li @p pasteTo(const KUrl &) : Paste clipboard into given URL. - * @li @p searchProvider : Lookup selected text at default search provider - * - * [normal actions] - * @li None anymore. - * - * - * The view defines a slot with the name of the action in order to implement the action. - * The browser will detect the slot automatically and connect its action to it when - * appropriate (i.e. when the view is active). - * - * - * The selection-dependent actions are disabled by default and the view should - * enable them when the selection changes, emitting enableAction(). - * - * The normal actions do not depend on the selection. - * - * A special case is the configuration slots, not connected to any action directly. - * - * [configuration slot] - * @li @p reparseConfiguration : Re-read configuration and apply it. - * @li @p disableScrolling: no scrollbars - */ -class KPARTS_EXPORT BrowserExtension : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool urlDropHandling READ isURLDropHandlingEnabled WRITE setURLDropHandlingEnabled) -public: - /** - * Constructor - * - * @param parent The KParts::ReadOnlyPart that this extension ... "extends" :) - */ - explicit BrowserExtension(KParts::ReadOnlyPart *parent); - - virtual ~BrowserExtension(); - - /** - * Set of flags passed via the popupMenu signal, to ask for some items in the popup menu. - */ - enum PopupFlag { - DefaultPopupItems = 0x0000, /**< default value, no additional menu item */ - ShowNavigationItems = 0x0001, /**< show "back" and "forward" (usually done when clicking the background of the view, but not an item) */ - ShowUp = 0x0002, /**< show "up" (same thing, but not over e.g. HTTP). Requires ShowNavigationItems. */ - ShowReload = 0x0004, /**< show "reload" (usually done when clicking the background of the view, but not an item) */ - ShowBookmark = 0x0008, /**< show "add to bookmarks" (usually not done on the local filesystem) */ - ShowCreateDirectory = 0x0010, /**< show "create directory" (usually only done on the background of the view, or - * in hierarchical views like directory trees, where the new dir would be visible) */ - ShowTextSelectionItems=0x0020, /**< set when selecting text, for a popup that only contains text-related items. */ - NoDeletion=0x0040, /**< deletion, trashing and renaming not allowed (e.g. parent dir not writeable). - * (this is only needed if the protocol itself supports deletion, unlike e.g. HTTP) */ - IsLink = 0x0080, /**< show "Bookmark This Link" and other link-related actions (linkactions merging group) */ - ShowUrlOperations = 0x0100, /**< show copy, paste, as well as cut if NoDeletion is not set. */ - ShowProperties = 0x200 /**< show "Properties" action (usually done by directory views) */ - }; - Q_DECLARE_FLAGS(PopupFlags, PopupFlag) - - /** - * Set the parameters to use for opening the next URL. - * This is called by the "hosting" application, to pass parameters to the part. - * @see BrowserArguments - */ - virtual void setBrowserArguments(const BrowserArguments &args); - - /** - * Retrieve the set of parameters to use for opening the URL - * (this must be called from openUrl() in the part). - * @see BrowserArguments - */ - BrowserArguments browserArguments() const; - - /** - * Returns the current x offset. - * - * For a scrollview, implement this using contentsX(). - */ - virtual int xOffset(); - /** - * Returns the current y offset. - * - * For a scrollview, implement this using contentsY(). - */ - virtual int yOffset(); - - /** - * Used by the browser to save the current state of the view - * (in order to restore it if going back in navigation). - * - * If you want to save additional properties, reimplement it - * but don't forget to call the parent method (probably first). - */ - virtual void saveState(QDataStream &stream); - - /** - * Used by the browser to restore the view in the state - * it was when we left it. - * - * If you saved additional properties, reimplement it - * but don't forget to call the parent method (probably first). - */ - virtual void restoreState(QDataStream &stream); - - /** - * Returns whether url drop handling is enabled. - * See setURLDropHandlingEnabled for more information about this - * property. - */ - bool isURLDropHandlingEnabled() const; - - /** - * Enables or disables url drop handling. URL drop handling is a property - * describing whether the hosting shell component is allowed to install an - * event filter on the part's widget, to listen for URI drop events. - * Set it to true if you are exporting a BrowserExtension implementation and - * do not provide any special URI drop handling. If set to false you can be - * sure to receive all those URI drop events unfiltered. Also note that the - * implementation as of Konqueror installs the event filter only on the part's - * widget itself, not on child widgets. - */ - void setURLDropHandlingEnabled(bool enable); - - /** - * @return the status (enabled/disabled) of an action. - * When the enableAction signal is emitted, the browserextension - * stores the status of the action internally, so that it's possible - * to query later for the status of the action, using this method. - */ - bool isActionEnabled(const char *name) const; - - /** - * @return the text of an action, if it was set explicitly by the part. - * When the setActionText signal is emitted, the browserextension - * stores the text of the action internally, so that it's possible - * to query later for the text of the action, using this method. - */ - QString actionText(const char *name) const; - - typedef QMap ActionSlotMap; - /** - * Returns a map containing the action names as keys and corresponding - * SLOT()'ified method names as data entries. - * - * This is very useful for - * the host component, when connecting the own signals with the - * extension's slots. - * Basically you iterate over the map, check if the extension implements - * the slot and connect to the slot using the data value of your map - * iterator. - * Checking if the extension implements a certain slot can be done like this: - * - * \code - * extension->metaObject()->slotNames().contains( actionName + "()" ) - * \endcode - * - * (note that @p actionName is the iterator's key value if already - * iterating over the action slot map, returned by this method) - * - * Connecting to the slot can be done like this: - * - * \code - * connect( yourObject, SIGNAL( yourSignal() ), - * extension, mapIterator.data() ) - * \endcode - * - * (where "mapIterator" is your QMap iterator) - */ - static ActionSlotMap actionSlotMap(); - - /** - * @return a pointer to the static action-slot map. Preferred method to get it. - * The map is created if it doesn't exist yet - */ - static ActionSlotMap* actionSlotMapPtr(); - - /** - * Queries @p obj for a child object which inherits from this - * BrowserExtension class. Convenience method. - */ - static BrowserExtension* childObject(QObject *obj); - - /** - * Asks the hosting browser to perform a paste (using openUrlRequestDelayed()) - */ - void pasteRequest(); - - /** - * Associates a list of actions with a predefined name known by the host's popupmenu: - * "editactions" for actions related text editing, - * "linkactions" for actions related to hyperlinks, - * "partactions" for any other actions provided by the part - */ - typedef QMap> ActionGroupMap; - -Q_SIGNALS: -#if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) -public: // yes, those signals are public; don't tell moc or doxygen :) -#endif - /** - * Enables or disable a standard action held by the browser. - * - * See class documentation for the list of standard actions. - */ - void enableAction(const char *name, bool enabled); - - /** - * Change the text of a standard action held by the browser. - * This can be used to change "Paste" into "Paste Image" for instance. - * - * See class documentation for the list of standard actions. - */ - void setActionText(const char *name, const QString &text); - - /** - * Asks the host (browser) to open @p url. - * To set a reload, the x and y offsets, the service type etc., fill in the - * appropriate fields in the @p args structure. - * Hosts should not connect to this signal but to openUrlRequestDelayed(). - */ - void openUrlRequest(const KUrl &url, - const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments()); - - /** - * This signal is emitted when openUrlRequest() is called, after a 0-seconds timer. - * This allows the caller to terminate what it's doing first, before (usually) - * being destroyed. Parts should never use this signal, hosts should only connect - * to this signal. - */ - void openUrlRequestDelayed(const KUrl &url, - const KParts::OpenUrlArguments &arguments, - const KParts::BrowserArguments &browserArguments); - - /** - * Tells the hosting browser that the part opened a new URL (which can be - * queried via KParts::Part::url(). - * - * This helps the browser to update/create an entry in the history. - * The part may @em not emit this signal together with openUrlRequest(). - * Emit openUrlRequest() if you want the browser to handle a URL the user - * asked to open (from within your part/document). This signal however is - * useful if you want to handle URLs all yourself internally, while still - * telling the hosting browser about new opened URLs, in order to provide - * a proper history functionality to the user. - * An example of usage is a html rendering component which wants to emit - * this signal when a child frame document changed its URL. - * Conclusion: you probably want to use openUrlRequest() instead. - */ - void openUrlNotify(); - - /** - * Updates the URL shown in the browser's location bar to @p url. - */ - void setLocationBarUrl(const QString &url); - - /** - * Sets the URL of an icon for the currently displayed page. - */ - void setIconUrl(const KUrl &url); - - /** - * Asks the hosting browser to open a new window for the given @p url - * and return a reference to the content part. - * - * @p arguments is optional additional information about how to open the url, - * @see KParts::OpenUrlArguments - * - * @p browserArguments is optional additional information for web browsers, - * @see KParts::BrowserArguments - * - * The request for a pointer to the part is only fulfilled/processed - * if the mimeType is set in the @p browserArguments. - * (otherwise the request cannot be processed synchronously). - */ - void createNewWindow(const KUrl &url, - const KParts::OpenUrlArguments &arguments = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments(), - KParts::ReadOnlyPart** part = nullptr); - - /** - * Since the part emits the jobid in the started() signal, - * progress information is automatically displayed. - * - * However, if you don't use a KIO::Job in the part, - * you can use loadingProgress() and speedProgress() - * to display progress information. - */ - void loadingProgress(int percent); - /** - * @see loadingProgress - */ - void speedProgress(int bytesPerSecond); - - void infoMessage(const QString &); - - /** - * Emit this to make the browser show a standard popup menu for the files @p items. - * - * @param global global coordinates where the popup should be shown - * @param items list of file items which the popup applies to - * @param args OpenUrlArguments, mostly for metadata here - * @param browserArguments BrowserArguments, mostly for referrer - * @param flags enables/disables certain builtin actions in the popupmenu - * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap - */ - void popupMenu(const QPoint &global, const KFileItemList &items, - const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(), - KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems, - const KParts::BrowserExtension::ActionGroupMap &actionGroups = ActionGroupMap()); - - /** - * Emit this to make the browser show a standard popup menu for the given @p url. - * - * Give as much information about this URL as possible, - * like @p args.mimeType and the file type @p mode - * - * @param global global coordinates where the popup should be shown - * @param url the URL this popup applies to - * @param mode the file type of the url (S_IFREG, S_IFDIR...) - * @param args OpenUrlArguments, set the mimetype of the URL using setMimeType() - * @param browserArguments BrowserArguments, mostly for referrer - * @param flags enables/disables certain builtin actions in the popupmenu - * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap - */ - void popupMenu(const QPoint &global, const KUrl &url, - mode_t mode = static_cast(-1), - const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(), - KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems, - const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap()); - - /** - * Inform the hosting application about the current selection. - * Used when a set of files/URLs is selected (with full information - * about those URLs, including size, permissions etc.) - */ - void selectionInfo(const KFileItemList &items); - /** - * Inform the hosting application about the current selection. - * Used when some text is selected. - */ - void selectionInfo( const QString &text ); - /** - * Inform the hosting application about the current selection. - * Used when a set of URLs is selected. - */ - void selectionInfo( const KUrl::List &urls ); - - /** - * Inform the hosting application that the user moved the mouse over an item. - * Used when the mouse is on an URL. - */ - void mouseOverInfo(const KFileItem &item); - - /** - * Ask the hosting application to add a new HTML (aka Mozilla/Netscape) - * SideBar entry. - */ - void addWebSideBar(const KUrl &url, const QString &name); - - /** - * Ask the hosting application to move the top level widget. - */ - void moveTopLevelWidget(int x, int y); - - /** - * Ask the hosting application to resize the top level widget. - */ - void resizeTopLevelWidget(int w, int h); - - /** - * Ask the hosting application to focus @p part. - */ - void requestFocus(KParts::ReadOnlyPart *part); - - /** - * Tell the host (browser) about security state of current page - * enum PageSecurity { NotCrypted, Encrypted, Mixed }; - */ - void setPageSecurity(int); - - /** - * Inform the host about items that have been removed. - */ - void itemsRemoved(const KFileItemList &items); - -private Q_SLOTS: - void slotCompleted(); - void slotOpenUrlRequest(const KUrl &url, - const KParts::OpenUrlArguments &arguments = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments()); - - void slotEmitOpenUrlRequestDelayed(); - void slotEnableAction(const char *, bool); - void slotSetActionText(const char*, const QString&); - -public: - typedef QMap ActionNumberMap; - -private: - class BrowserExtensionPrivate; - BrowserExtensionPrivate * const d; -}; - -} - -Q_DECLARE_OPERATORS_FOR_FLAGS(KParts::BrowserExtension::PopupFlags) - -#endif diff --git a/kparts/part.cpp b/kparts/part.cpp index 995fe007..26863d4e 100644 --- a/kparts/part.cpp +++ b/kparts/part.cpp @@ -21,7 +21,6 @@ #include "part.h" #include "event.h" #include "mainwindow.h" -#include "browserextension.h" #include #include @@ -374,6 +373,7 @@ void ReadOnlyPart::setUrl(const KUrl &url) { Q_D(ReadOnlyPart); + emit urlAboutToChange(); d->m_url = url; emit urlChanged( url ); } @@ -617,11 +617,6 @@ bool ReadOnlyPart::closeStream() return doCloseStream(); } -BrowserExtension* ReadOnlyPart::browserExtension() const -{ - return findChild(); -} - void KParts::ReadOnlyPart::setArguments(const OpenUrlArguments& arguments) { Q_D(ReadOnlyPart); diff --git a/kparts/part.h b/kparts/part.h index 903cc762..17b3b89d 100644 --- a/kparts/part.h +++ b/kparts/part.h @@ -255,7 +255,6 @@ private: class ReadWritePart; class ReadOnlyPartPrivate; -class BrowserExtension; class OpenUrlArgumentsPrivate; /** @@ -416,12 +415,6 @@ public: */ virtual bool closeUrl(); - /** - * This convenience method returns the browserExtension for this part, - * or 0 if there isn't any. - */ - BrowserExtension* browserExtension() const; - /** * Sets the arguments to use for the next openUrl call. */ @@ -518,6 +511,12 @@ Q_SIGNALS: */ void canceled( const QString &errMsg ); + /** + * Emitted by the part when url() is about to change + * @since 4.24 + */ + void urlAboutToChange(); + /** * Emitted by the part when url() changes * @since 4.10 diff --git a/kparts/statusbarextension.h b/kparts/statusbarextension.h index 7627055b..0599296b 100644 --- a/kparts/statusbarextension.h +++ b/kparts/statusbarextension.h @@ -105,8 +105,8 @@ namespace KParts void setStatusBar( KStatusBar* status ); /** - * Queries @p obj for a child object which inherits from this - * BrowserExtension class. Convenience method. + * Queries @p obj for a child object which inherits StatusBarExtension + * class. Convenience method. */ static StatusBarExtension *childObject( QObject *obj );