From 901bdac85d5e135a53952cee779ad254c978a4b4 Mon Sep 17 00:00:00 2001 From: nowrep Date: Fri, 12 Apr 2013 18:05:45 +0200 Subject: [PATCH] [Plugins] Added possibility to unregister scheme handlers. It is important to unregister scheme handler when unloading a plugin, otherwise it will crash on next createRequest call. --- src/lib/network/networkmanager.cpp | 9 +++++++++ src/lib/network/networkmanager.h | 1 + src/lib/plugins/pluginproxy.h | 1 + 3 files changed, 11 insertions(+) diff --git a/src/lib/network/networkmanager.cpp b/src/lib/network/networkmanager.cpp index 5fe191201..1b9e7c982 100644 --- a/src/lib/network/networkmanager.cpp +++ b/src/lib/network/networkmanager.cpp @@ -608,6 +608,15 @@ bool NetworkManager::registerSchemeHandler(const QString &scheme, SchemeHandler* return true; } +bool NetworkManager::unregisterSchemeHandler(const QString &scheme, SchemeHandler* handler) +{ + if (!m_schemeHandlers.contains(scheme) || m_schemeHandlers[scheme] != handler) { + return false; + } + + return m_schemeHandlers.remove(scheme) == 1; +} + void NetworkManager::saveCertificates() { Settings settings; diff --git a/src/lib/network/networkmanager.h b/src/lib/network/networkmanager.h index 6e926a723..6c794ba53 100644 --- a/src/lib/network/networkmanager.h +++ b/src/lib/network/networkmanager.h @@ -55,6 +55,7 @@ public: NetworkProxyFactory* proxyFactory() const; bool registerSchemeHandler(const QString &scheme, SchemeHandler* handler); + bool unregisterSchemeHandler(const QString &scheme, SchemeHandler* handler); void disconnectObjects(); diff --git a/src/lib/plugins/pluginproxy.h b/src/lib/plugins/pluginproxy.h index 2f004147d..a6f12911b 100644 --- a/src/lib/plugins/pluginproxy.h +++ b/src/lib/plugins/pluginproxy.h @@ -81,5 +81,6 @@ private: #define QZ_REGISTER_EVENT_HANDLER(Type) mApp->plugins()->registerAppEventHandler(Type, this); #define QZ_REGISTER_SCHEME_HANDLER(Scheme, Object) mApp->networkManager()->registerSchemeHandler(Scheme, Object); +#define QZ_UNREGISTER_SCHEME_HANDLER(Scheme, Object) mApp->networkManager()->unregisterSchemeHandler(Scheme, Object); #endif // PLUGINPROXY_H