mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-14 02:52:12 +01:00
Rename MessageReciever class to Communicator
This commit is contained in:
parent
c1e49ec8a4
commit
5200faf1f2
|
@ -216,6 +216,7 @@ set(SRCS ${SRCS}
|
||||||
sidebar/bookmarkssidebar.cpp
|
sidebar/bookmarkssidebar.cpp
|
||||||
sidebar/historysidebar.cpp
|
sidebar/historysidebar.cpp
|
||||||
sidebar/sidebar.cpp
|
sidebar/sidebar.cpp
|
||||||
|
sync/communicator.cpp
|
||||||
sync/fxalogin.cpp
|
sync/fxalogin.cpp
|
||||||
sync/synccrypto.cpp
|
sync/synccrypto.cpp
|
||||||
tabwidget/combotabbar.cpp
|
tabwidget/combotabbar.cpp
|
||||||
|
|
42
src/lib/sync/communicator.cpp
Normal file
42
src/lib/sync/communicator.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2019 Prasenjit Kumar Shaw <shawprasenjit07@gmail.com>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#include "communicator.h"
|
||||||
|
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
Communicator::Communicator(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Communicator::~Communicator()
|
||||||
|
{
|
||||||
|
delete m_message;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Communicator::receiveJSON(const QVariantMap &data)
|
||||||
|
{
|
||||||
|
QJsonObject obj = QJsonObject::fromVariantMap(data);
|
||||||
|
m_message = new QJsonObject(obj);
|
||||||
|
emit signalMessageReceived();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject * Communicator::getMessage()
|
||||||
|
{
|
||||||
|
return m_message;
|
||||||
|
}
|
40
src/lib/sync/communicator.h
Normal file
40
src/lib/sync/communicator.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2019 Prasenjit Kumar Shaw <shawprasenjit07@gmail.com>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
class Communicator : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Communicator(QObject *parent = nullptr);
|
||||||
|
~Communicator();
|
||||||
|
QJsonObject *getMessage();
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void receiveJSON(const QVariantMap &data);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void signalMessageReceived();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QJsonObject *m_message;
|
||||||
|
};
|
|
@ -18,10 +18,9 @@
|
||||||
#include "fxalogin.h"
|
#include "fxalogin.h"
|
||||||
#include "javascript/externaljsobject.h"
|
#include "javascript/externaljsobject.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
|
#include "communicator.h"
|
||||||
|
#include "qztools.h"
|
||||||
|
|
||||||
#include <QWebEnginePage>
|
|
||||||
#include <QWebEngineScript>
|
|
||||||
#include <QWebChannel>
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -30,9 +29,9 @@
|
||||||
FxALoginPage::FxALoginPage(QWidget* parent)
|
FxALoginPage::FxALoginPage(QWidget* parent)
|
||||||
: QWebEngineView(parent)
|
: QWebEngineView(parent)
|
||||||
{
|
{
|
||||||
m_communicator = new MessageReceiver(this);
|
m_communicator = new Communicator(this);
|
||||||
ExternalJsObject::registerExtraObject(QString("communicator"), m_communicator);
|
ExternalJsObject::registerExtraObject(QString("communicator"), m_communicator);
|
||||||
connect(m_communicator, &MessageReceiver::signalMessageReceived,
|
connect(m_communicator, &Communicator::signalMessageReceived,
|
||||||
this, &FxALoginPage::slotMessageReceived);
|
this, &FxALoginPage::slotMessageReceived);
|
||||||
|
|
||||||
m_page = new WebPage(this);
|
m_page = new WebPage(this);
|
||||||
|
@ -49,12 +48,7 @@ FxALoginPage::~FxALoginPage()
|
||||||
void FxALoginPage::pageLoadFinished(bool pageLoaded)
|
void FxALoginPage::pageLoadFinished(bool pageLoaded)
|
||||||
{
|
{
|
||||||
if (pageLoaded) {
|
if (pageLoaded) {
|
||||||
QFile scriptFile(":/data/inject.js");
|
QString injectScript = QzTools::readAllFileContents(":/data/inject.js");
|
||||||
if (!scriptFile.open(QIODevice::ReadOnly)) {
|
|
||||||
qWarning() << "Couldn't load JavaScript file to inject.";
|
|
||||||
}
|
|
||||||
QString injectScript = QString::fromUtf8(scriptFile.readAll());
|
|
||||||
scriptFile.close();
|
|
||||||
m_page->runJavaScript(injectScript, WebPage::SafeJsWorld);
|
m_page->runJavaScript(injectScript, WebPage::SafeJsWorld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,25 +103,3 @@ void FxALoginPage::sendMessage(QJsonObject msg)
|
||||||
m_page->runJavaScript(srcCode, WebPage::SafeJsWorld);
|
m_page->runJavaScript(srcCode, WebPage::SafeJsWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MessageReceiver::MessageReceiver(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageReceiver::~MessageReceiver()
|
|
||||||
{
|
|
||||||
delete m_message;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MessageReceiver::receiveJSON(const QVariantMap &data)
|
|
||||||
{
|
|
||||||
QJsonObject obj = QJsonObject::fromVariantMap(data);
|
|
||||||
m_message = new QJsonObject(obj);
|
|
||||||
emit signalMessageReceived();
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject * MessageReceiver::getMessage()
|
|
||||||
{
|
|
||||||
return m_message;
|
|
||||||
}
|
|
||||||
|
|
|
@ -21,12 +21,9 @@
|
||||||
#include <QWebEngineView>
|
#include <QWebEngineView>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QWebChannel;
|
|
||||||
class QWebEngineScript;
|
|
||||||
class QWebEnginePage;
|
|
||||||
class QJsonObject;
|
class QJsonObject;
|
||||||
class MessageReceiver;
|
|
||||||
class WebPage;
|
class WebPage;
|
||||||
|
class Communicator;
|
||||||
|
|
||||||
class FxALoginPage : public QWebEngineView
|
class FxALoginPage : public QWebEngineView
|
||||||
{
|
{
|
||||||
|
@ -45,27 +42,7 @@ private:
|
||||||
void sendMessage(QJsonObject msg);
|
void sendMessage(QJsonObject msg);
|
||||||
|
|
||||||
WebPage *m_page;
|
WebPage *m_page;
|
||||||
MessageReceiver *m_communicator;
|
Communicator *m_communicator;
|
||||||
|
|
||||||
const QUrl FxALoginUrl = QUrl("https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v3");
|
const QUrl FxALoginUrl = QUrl("https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v3");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class MessageReceiver : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
MessageReceiver(QObject *parent = nullptr);
|
|
||||||
~MessageReceiver();
|
|
||||||
QJsonObject *getMessage();
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void receiveJSON(const QVariantMap &data);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void signalMessageReceived();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QJsonObject *m_message;
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user