File indexing completed on 2024-05-19 04:59:18

0001 /* ============================================================
0002 * Personal Information Manager plugin for Falkon
0003 * Copyright (C) 2012-2014  David Rosca <nowrep@gmail.com>
0004 * Copyright (C) 2012-2014  Mladen Pejaković <pejakm@autistici.org>
0005 *
0006 * This program is free software: you can redistribute it and/or modify
0007 * it under the terms of the GNU General Public License as published by
0008 * the Free Software Foundation, either version 3 of the License, or
0009 * (at your option) any later version.
0010 *
0011 * This program is distributed in the hope that it will be useful,
0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 * GNU General Public License for more details.
0015 *
0016 * You should have received a copy of the GNU General Public License
0017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 * ============================================================ */
0019 #include "PIM_plugin.h"
0020 #include "PIM_handler.h"
0021 #include "PIM_settings.h"
0022 #include "mainapplication.h"
0023 #include "pluginproxy.h"
0024 #include "browserwindow.h"
0025 #include "webview.h"
0026 #include "../config.h"
0027 
0028 PIM_Plugin::PIM_Plugin()
0029     : QObject()
0030     , m_handler(nullptr)
0031 {
0032 }
0033 
0034 void PIM_Plugin::init(InitState state, const QString &settingsPath)
0035 {
0036     Q_UNUSED(state)
0037 
0038     m_handler = new PIM_Handler(settingsPath, this);
0039 
0040     mApp->plugins()->registerAppEventHandler(PluginProxy::KeyPressHandler, this);
0041 
0042     connect(mApp->plugins(), SIGNAL(webPageCreated(WebPage*)), m_handler, SLOT(webPageCreated(WebPage*)));
0043 }
0044 
0045 void PIM_Plugin::unload()
0046 {
0047     m_handler->unloadPlugin();
0048     m_handler->deleteLater();
0049 }
0050 
0051 bool PIM_Plugin::testPlugin()
0052 {
0053     // Require the version that the plugin was built with
0054     return (QString::fromLatin1(Qz::VERSION) == QLatin1String(FALKON_VERSION));
0055 }
0056 
0057 void PIM_Plugin::showSettings(QWidget* parent)
0058 {
0059     m_handler->showSettings(parent);
0060 }
0061 
0062 void PIM_Plugin::populateWebViewMenu(QMenu* menu, WebView* view, const WebHitTestResult &r)
0063 {
0064     m_handler->populateWebViewMenu(menu, view, r);
0065 }
0066 
0067 bool PIM_Plugin::keyPress(Qz::ObjectName type, QObject* obj, QKeyEvent* event)
0068 {
0069     if (type == Qz::ON_WebView) {
0070         auto* view = qobject_cast<WebView*>(obj);
0071         return m_handler->keyPress(view, event);
0072     }
0073 
0074     return false;
0075 }