mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Bring back PIM plugin
This commit is contained in:
parent
75fe50ca48
commit
97ba8c6af3
@ -272,7 +272,6 @@ QString Scripts::getFormData(const QPoint &pos)
|
|||||||
" var input = fe.elements[i];"
|
" var input = fe.elements[i];"
|
||||||
" res.inputs.push([input.name, input.value]);"
|
" res.inputs.push([input.name, input.value]);"
|
||||||
"}"
|
"}"
|
||||||
"console.log(res);"
|
|
||||||
"return res;"
|
"return res;"
|
||||||
"})()");
|
"})()");
|
||||||
|
|
||||||
|
@ -20,11 +20,10 @@
|
|||||||
#include "PIM_settings.h"
|
#include "PIM_settings.h"
|
||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
|
#include "webhittestresult.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QWebPage>
|
|
||||||
#include <QWebFrame>
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
@ -99,10 +98,10 @@ void PIM_Handler::showSettings(QWidget* parent)
|
|||||||
m_settings.data()->raise();
|
m_settings.data()->raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIM_Handler::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &hitTest)
|
void PIM_Handler::populateWebViewMenu(QMenu* menu, WebView* view, const WebHitTestResult &hitTest)
|
||||||
{
|
{
|
||||||
m_view = view;
|
m_view = view;
|
||||||
m_element = hitTest.element();
|
m_clickedPos = hitTest.pos();
|
||||||
|
|
||||||
if (!hitTest.isContentEditable()) {
|
if (!hitTest.isContentEditable()) {
|
||||||
return;
|
return;
|
||||||
@ -152,20 +151,23 @@ bool PIM_Handler::keyPress(WebView* view, QKeyEvent* event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QWebElement document = view->page()->mainFrame()->documentElement();
|
QString source = QL1S("var inputs = document.getElementsByTagName('input');"
|
||||||
const QWebElementCollection elements = document.findAll("input[type=\"text\"]");
|
"var table = %1;"
|
||||||
|
"for (var i = 0; i < inputs.length; ++i) {"
|
||||||
|
" var input = inputs[i];"
|
||||||
|
" if (input.type != 'text' || input.name == '')"
|
||||||
|
" continue;"
|
||||||
|
" for (var key in table) {"
|
||||||
|
" if (!table.hasOwnProperty(key))"
|
||||||
|
" continue;"
|
||||||
|
" if (key == input.name || input.name.indexOf(key) != -1) {"
|
||||||
|
" input.value = table[key];"
|
||||||
|
" break;"
|
||||||
|
" }"
|
||||||
|
" }"
|
||||||
|
"}");
|
||||||
|
|
||||||
foreach (QWebElement element, elements) {
|
view->page()->runJavaScript(source.arg(matchingJsTable()));
|
||||||
const QString name = element.attribute("name");
|
|
||||||
if (name.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
PI_Type match = nameMatch(name);
|
|
||||||
if (match != PI_Invalid) {
|
|
||||||
element.evaluateJavaScript(QString("this.value = \"%1\"").arg(m_allInfo[match]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -182,14 +184,24 @@ void PIM_Handler::webPageCreated(WebPage* page)
|
|||||||
|
|
||||||
void PIM_Handler::pimInsert()
|
void PIM_Handler::pimInsert()
|
||||||
{
|
{
|
||||||
QAction* action = qobject_cast<QAction*>(sender());
|
if (!m_view || m_clickedPos.isNull())
|
||||||
if (m_element.isNull() || !action) {
|
return;
|
||||||
|
|
||||||
|
QAction* action = qobject_cast<QAction*>(sender());
|
||||||
|
if (!action)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
QString info = action->data().toString();
|
QString info = action->data().toString();
|
||||||
info.replace(QLatin1Char('"'), QLatin1String("\\\""));
|
info.replace(QLatin1Char('"'), QLatin1String("\\\""));
|
||||||
m_element.evaluateJavaScript(QString("var newVal = this.value.substring(0, this.selectionStart) + \"%1\" + this.value.substring(this.selectionEnd); this.value = newVal;").arg(info));
|
|
||||||
|
QString source = QL1S("var e = document.elementFromPoint(%1, %2);"
|
||||||
|
"if (e) {"
|
||||||
|
" var v = e.value.substring(0, e.selectionStart);"
|
||||||
|
" v += \"%3\" + e.value.substring(e.selectionEnd);"
|
||||||
|
" e.value = v;"
|
||||||
|
"}");
|
||||||
|
source = source.arg(QString::number(m_clickedPos.x()), QString::number(m_clickedPos.y()), info);
|
||||||
|
m_view->page()->runJavaScript(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIM_Handler::pageLoadFinished()
|
void PIM_Handler::pageLoadFinished()
|
||||||
@ -203,37 +215,42 @@ void PIM_Handler::pageLoadFinished()
|
|||||||
loadSettings();
|
loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QWebElement document = page->mainFrame()->documentElement();
|
QString source = QL1S("var inputs = document.getElementsByTagName('input');"
|
||||||
const QWebElementCollection elements = document.findAll("input[type=\"text\"]");
|
"var table = %1;"
|
||||||
|
"for (var i = 0; i < inputs.length; ++i) {"
|
||||||
|
" var input = inputs[i];"
|
||||||
|
" if (input.type != 'text' || input.name == '')"
|
||||||
|
" continue;"
|
||||||
|
" for (var key in table) {"
|
||||||
|
" if (!table.hasOwnProperty(key) || table[key] == '')"
|
||||||
|
" continue;"
|
||||||
|
" if (key == input.name || input.name.indexOf(key) != -1) {"
|
||||||
|
" input.style['-webkit-appearance'] = 'none';"
|
||||||
|
" input.style['-webkit-box-shadow'] = 'inset 0 0 2px 1px #EEE000';"
|
||||||
|
" break;"
|
||||||
|
" }"
|
||||||
|
" }"
|
||||||
|
"}");
|
||||||
|
|
||||||
foreach (QWebElement element, elements) {
|
page->runJavaScript(source.arg(matchingJsTable()));
|
||||||
const QString name = element.attribute("name");
|
|
||||||
if (name.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
PI_Type match = nameMatch(name);
|
|
||||||
if (match != PI_Invalid) {
|
|
||||||
element.setStyleProperty("-webkit-appearance", "none");
|
|
||||||
element.setStyleProperty("-webkit-box-shadow", "inset 0 0 2px 1px #EEE000");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PIM_Handler::PI_Type PIM_Handler::nameMatch(const QString &name)
|
QString PIM_Handler::matchingJsTable() const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < PI_Max; ++i) {
|
QString values;
|
||||||
if (!m_allInfo[PI_Type(i)].isEmpty()) {
|
|
||||||
foreach (const QString &n, m_infoMatches[PI_Type(i)]) {
|
QHashIterator<PI_Type, QStringList> i(m_infoMatches);
|
||||||
if (name == n) {
|
while (i.hasNext()) {
|
||||||
return PI_Type(i);
|
i.next();
|
||||||
}
|
foreach (const QString &value, i.value()) {
|
||||||
if (name.contains(n)) {
|
QString key = m_allInfo.value(i.key());
|
||||||
return PI_Type(i);
|
key.replace(QL1C('"'), QL1S("\\\""));
|
||||||
}
|
values.append(QSL("\"%1\":\"%2\",").arg(value, key));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PI_Invalid;
|
if (!values.isEmpty())
|
||||||
|
values = values.left(values.size() - 1);
|
||||||
|
|
||||||
|
return QSL("{ %1 }").arg(values);
|
||||||
}
|
}
|
||||||
|
@ -20,15 +20,14 @@
|
|||||||
#define PIM_HANDLER_H
|
#define PIM_HANDLER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QWebElement>
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QWebHitTestResult>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
class WebView;
|
class WebView;
|
||||||
class WebPage;
|
class WebPage;
|
||||||
|
class WebHitTestResult;
|
||||||
|
|
||||||
class PIM_Settings;
|
class PIM_Settings;
|
||||||
|
|
||||||
@ -38,7 +37,7 @@ class PIM_Handler : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit PIM_Handler(const QString &sPath, QObject* parent = 0);
|
explicit PIM_Handler(const QString &sPath, QObject* parent = 0);
|
||||||
|
|
||||||
void populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &hitTest);
|
void populateWebViewMenu(QMenu* menu, WebView* view, const WebHitTestResult &hitTest);
|
||||||
bool keyPress(WebView* view, QKeyEvent* event);
|
bool keyPress(WebView* view, QKeyEvent* event);
|
||||||
|
|
||||||
void unloadPlugin();
|
void unloadPlugin();
|
||||||
@ -75,7 +74,7 @@ private:
|
|||||||
PI_Invalid = 128
|
PI_Invalid = 128
|
||||||
};
|
};
|
||||||
|
|
||||||
PI_Type nameMatch(const QString &name);
|
QString matchingJsTable() const;
|
||||||
|
|
||||||
QHash<PI_Type, QString> m_allInfo;
|
QHash<PI_Type, QString> m_allInfo;
|
||||||
QHash<PI_Type, QStringList> m_infoMatches;
|
QHash<PI_Type, QStringList> m_infoMatches;
|
||||||
@ -83,7 +82,7 @@ private:
|
|||||||
|
|
||||||
QPointer<PIM_Settings> m_settings;
|
QPointer<PIM_Settings> m_settings;
|
||||||
QPointer<WebView> m_view;
|
QPointer<WebView> m_view;
|
||||||
QWebElement m_element;
|
QPoint m_clickedPos;
|
||||||
|
|
||||||
QString m_settingsFile;
|
QString m_settingsFile;
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
|
@ -38,7 +38,7 @@ PluginSpec PIM_Plugin::pluginSpec()
|
|||||||
spec.name = "PIM";
|
spec.name = "PIM";
|
||||||
spec.info = "Personal Information Manager";
|
spec.info = "Personal Information Manager";
|
||||||
spec.description = "Adds ability for Qupzilla to store some personal data";
|
spec.description = "Adds ability for Qupzilla to store some personal data";
|
||||||
spec.version = "0.1.2";
|
spec.version = "0.2.0";
|
||||||
spec.author = QString::fromUtf8("Mladen Pejaković <pejakm@autistici.org>");
|
spec.author = QString::fromUtf8("Mladen Pejaković <pejakm@autistici.org>");
|
||||||
spec.icon = QPixmap(":/PIM/data/PIM.png");
|
spec.icon = QPixmap(":/PIM/data/PIM.png");
|
||||||
spec.hasSettings = true;
|
spec.hasSettings = true;
|
||||||
@ -81,7 +81,7 @@ void PIM_Plugin::showSettings(QWidget* parent)
|
|||||||
m_handler->showSettings(parent);
|
m_handler->showSettings(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIM_Plugin::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r)
|
void PIM_Plugin::populateWebViewMenu(QMenu* menu, WebView* view, const WebHitTestResult &r)
|
||||||
{
|
{
|
||||||
m_handler->populateWebViewMenu(menu, view, r);
|
m_handler->populateWebViewMenu(menu, view, r);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
QTranslator* getTranslator(const QString &locale);
|
QTranslator* getTranslator(const QString &locale);
|
||||||
void showSettings(QWidget* parent = 0);
|
void showSettings(QWidget* parent = 0);
|
||||||
|
|
||||||
void populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r);
|
void populateWebViewMenu(QMenu* menu, WebView* view, const WebHitTestResult &r);
|
||||||
bool keyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event);
|
bool keyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -44,5 +44,4 @@ isEqual(QT_MAJOR_VERSION, 5): !qtHaveModule(KWallet): disablePlugin(KWalletPassw
|
|||||||
disablePlugin(AccessKeysNavigation)
|
disablePlugin(AccessKeysNavigation)
|
||||||
disablePlugin(CopyTitle)
|
disablePlugin(CopyTitle)
|
||||||
disablePlugin(MailHandle)
|
disablePlugin(MailHandle)
|
||||||
disablePlugin(PIM)
|
|
||||||
disablePlugin(Videoner)
|
disablePlugin(Videoner)
|
||||||
|
Loading…
Reference in New Issue
Block a user