1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 17:42:10 +01:00
falkonOfficial/src/lib/plugins/pluginproxy.cpp

203 lines
5.2 KiB
C++
Raw Normal View History

2011-03-03 18:29:20 +01:00
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
2011-03-03 18:29:20 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
2011-03-02 16:57:41 +01:00
#include "pluginproxy.h"
#include "plugininterface.h"
#include "mainapplication.h"
#include "settings.h"
2011-03-02 16:57:41 +01:00
#include <QMenu>
PluginProxy::PluginProxy()
: Plugins()
2011-03-02 16:57:41 +01:00
{
}
void PluginProxy::unloadPlugin(Plugins::Plugin* plugin)
{
m_mousePressHandlers.removeOne(plugin->instance);
m_mouseReleaseHandlers.removeOne(plugin->instance);
m_mouseMoveHandlers.removeOne(plugin->instance);
m_keyPressHandlers.removeOne(plugin->instance);
m_keyReleaseHandlers.removeOne(plugin->instance);
Plugins::unloadPlugin(plugin);
}
void PluginProxy::registerAppEventHandler(const PluginProxy::EventHandlerType &type, PluginInterface* obj)
{
switch (type) {
2012-03-05 13:16:34 +01:00
case MouseDoubleClickHandler:
if (!m_mouseDoubleClickHandlers.contains(obj)) {
m_mouseDoubleClickHandlers.append(obj);
}
break;
case MousePressHandler:
if (!m_mousePressHandlers.contains(obj)) {
m_mousePressHandlers.append(obj);
}
break;
case MouseReleaseHandler:
if (!m_mouseReleaseHandlers.contains(obj)) {
m_mouseReleaseHandlers.append(obj);
}
break;
case MouseMoveHandler:
if (!m_mouseMoveHandlers.contains(obj)) {
m_mouseMoveHandlers.append(obj);
}
break;
case KeyPressHandler:
if (!m_keyPressHandlers.contains(obj)) {
m_keyPressHandlers.append(obj);
}
break;
case KeyReleaseHandler:
if (!m_keyReleaseHandlers.contains(obj)) {
m_keyReleaseHandlers.append(obj);
}
break;
default:
qWarning("PluginProxy::registerAppEventHandler registering unknown event handler type");
break;
}
2011-03-02 16:57:41 +01:00
}
void PluginProxy::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r)
2011-03-02 16:57:41 +01:00
{
if (!menu || !view || m_loadedPlugins.count() == 0) {
2011-03-02 16:57:41 +01:00
return;
}
2011-03-02 16:57:41 +01:00
menu->addSeparator();
int count = menu->actions().count();
foreach(PluginInterface * iPlugin, m_loadedPlugins) {
iPlugin->populateWebViewMenu(menu, view, r);
}
2011-03-02 16:57:41 +01:00
if (menu->actions().count() == count) {
menu->removeAction(menu->actions().at(count - 1));
}
2011-03-02 16:57:41 +01:00
}
2012-03-05 13:16:34 +01:00
bool PluginProxy::processMouseDoubleClick(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
{
bool accepted = false;
foreach(PluginInterface * iPlugin, m_mouseDoubleClickHandlers) {
if (iPlugin->mouseDoubleClick(type, obj, event)) {
accepted = true;
}
}
return accepted;
}
bool PluginProxy::processMousePress(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
2011-03-02 16:57:41 +01:00
{
bool accepted = false;
foreach(PluginInterface * iPlugin, m_mousePressHandlers) {
if (iPlugin->mousePress(type, obj, event)) {
accepted = true;
}
}
return accepted;
2011-03-02 16:57:41 +01:00
}
bool PluginProxy::processMouseRelease(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
2011-03-02 16:57:41 +01:00
{
bool accepted = false;
foreach(PluginInterface * iPlugin, m_mouseReleaseHandlers) {
if (iPlugin->mouseRelease(type, obj, event)) {
accepted = true;
}
}
return accepted;
2011-03-02 16:57:41 +01:00
}
bool PluginProxy::processMouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
{
bool accepted = false;
foreach(PluginInterface * iPlugin, m_mouseMoveHandlers) {
if (iPlugin->mouseMove(type, obj, event)) {
accepted = true;
}
}
return accepted;
}
bool PluginProxy::processKeyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event)
{
bool accepted = false;
foreach(PluginInterface * iPlugin, m_keyPressHandlers) {
if (iPlugin->keyPress(type, obj, event)) {
accepted = true;
}
}
return accepted;
}
bool PluginProxy::processKeyRelease(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event)
{
bool accepted = false;
foreach(PluginInterface * iPlugin, m_keyReleaseHandlers) {
if (iPlugin->keyRelease(type, obj, event)) {
accepted = true;
}
}
return accepted;
}
2012-03-05 13:16:34 +01:00
void PluginProxy::emitWebViewCreated(WebView* view)
{
emit webViewCreated(view);
}
void PluginProxy::emitWebViewDeleted(WebView* view)
{
emit webViewDeleted(view);
}
void PluginProxy::emitMainWindowCreated(QupZilla* window)
{
emit mainWindowCreated(window);
}
void PluginProxy::emitMainWindowDeleted(QupZilla* window)
{
emit mainWindowDeleted(window);
}