mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Merge branch 'arcpatch-D14521' into anmolgautam
This commit is contained in:
commit
87987e25eb
|
@ -37,3 +37,29 @@ falkon_tests(
|
||||||
databasepasswordbackendtest
|
databasepasswordbackendtest
|
||||||
databaseencryptedpasswordbackendtest
|
databaseencryptedpasswordbackendtest
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(falkon_autotests_SRCS
|
||||||
|
qml/qmltestitem.cpp
|
||||||
|
qml/qmltesthelper.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
macro(falkon_qml_tests)
|
||||||
|
foreach(_testname ${ARGN})
|
||||||
|
add_executable(${_testname} qml/${_testname}.cpp ${falkon_autotests_SRCS})
|
||||||
|
target_link_libraries(${_testname} Qt5::Test FalkonPrivate)
|
||||||
|
add_test(NAME falkon-qml-${_testname} COMMAND ${_testname})
|
||||||
|
ecm_mark_as_test(${_testname})
|
||||||
|
set_tests_properties(falkon-qml-${_testname} PROPERTIES RUN_SERIAL TRUE)
|
||||||
|
endforeach(_testname)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
falkon_qml_tests(
|
||||||
|
qmlbookmarksapitest
|
||||||
|
qmltopsitesapitest
|
||||||
|
qmlhistoryapitest
|
||||||
|
qmlcookiesapitest
|
||||||
|
qmlclipboardapitest
|
||||||
|
qmltabsapitest
|
||||||
|
qmlwindowsapitest
|
||||||
|
qmluserscriptapitest
|
||||||
|
)
|
||||||
|
|
162
autotests/qml/qmlbookmarksapitest.cpp
Normal file
162
autotests/qml/qmlbookmarksapitest.cpp
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlbookmarksapitest.h"
|
||||||
|
#include "autotests.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "bookmarks.h"
|
||||||
|
#include "bookmarkitem.h"
|
||||||
|
#include "qml/api/bookmarks/qmlbookmarktreenode.h"
|
||||||
|
|
||||||
|
void QmlBookmarksApiTest::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlBookmarksApiTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlBookmarksApiTest::testBookmarkTreeNodeType()
|
||||||
|
{
|
||||||
|
auto type = BookmarkItem::Type(m_testHelper.evaluate("Falkon.Bookmarks.rootItem().type").toInt());
|
||||||
|
QCOMPARE(mApp->bookmarks()->rootItem()->type(), type);
|
||||||
|
|
||||||
|
type = BookmarkItem::Type(m_testHelper.evaluate("Falkon.Bookmarks.toolbarFolder().type").toInt());
|
||||||
|
QCOMPARE(mApp->bookmarks()->toolbarFolder()->type(), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlBookmarksApiTest::testBookmarkTreeNode()
|
||||||
|
{
|
||||||
|
QObject *bookmark = m_testHelper.evaluateQObject("Falkon.Bookmarks.toolbarFolder()");
|
||||||
|
QVERIFY(bookmark);
|
||||||
|
auto toolbarFolder = mApp->bookmarks()->toolbarFolder();
|
||||||
|
|
||||||
|
QCOMPARE(toolbarFolder->title(), bookmark->property("title").toString());
|
||||||
|
QCOMPARE(toolbarFolder->urlString(), bookmark->property("url").toString());
|
||||||
|
QCOMPARE(toolbarFolder->description(), bookmark->property("description").toString());
|
||||||
|
QCOMPARE(!mApp->bookmarks()->canBeModified(toolbarFolder), bookmark->property("unmodifiable").toBool());
|
||||||
|
QObject* parent = qvariant_cast<QObject*>(bookmark->property("parent"));
|
||||||
|
QVERIFY(parent);
|
||||||
|
QCOMPARE(mApp->bookmarks()->rootItem()->title(), parent->property("title").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlBookmarksApiTest::testBookmarksCreation()
|
||||||
|
{
|
||||||
|
auto item = new BookmarkItem(BookmarkItem::Url);
|
||||||
|
item->setTitle("Example Domain");
|
||||||
|
item->setUrl(QUrl("https://example.com/"));
|
||||||
|
item->setDescription("Testing bookmark description");
|
||||||
|
|
||||||
|
QObject *qmlBookmarks = m_testHelper.evaluateQObject("Falkon.Bookmarks");
|
||||||
|
QVERIFY(qmlBookmarks);
|
||||||
|
|
||||||
|
QSignalSpy qmlBookmarksSpy(qmlBookmarks, SIGNAL(created(QmlBookmarkTreeNode*)));
|
||||||
|
mApp->bookmarks()->addBookmark(mApp->bookmarks()->rootItem(), item);
|
||||||
|
|
||||||
|
QCOMPARE(qmlBookmarksSpy.count(), 1);
|
||||||
|
|
||||||
|
QObject *created = qvariant_cast<QObject*>(qmlBookmarksSpy.at(0).at(0));
|
||||||
|
QVERIFY(created);
|
||||||
|
QCOMPARE(item->title(), created->property("title").toString());
|
||||||
|
|
||||||
|
qRegisterMetaType<BookmarkItem*>();
|
||||||
|
QSignalSpy bookmarksSpy(mApp->bookmarks(), &Bookmarks::bookmarkAdded);
|
||||||
|
|
||||||
|
auto out = m_testHelper.evaluate("Falkon.Bookmarks.create({"
|
||||||
|
" parent: Falkon.Bookmarks.toolbarFolder(),"
|
||||||
|
" title: 'Example Plugin',"
|
||||||
|
" url: 'https://another-example.com'"
|
||||||
|
"});");
|
||||||
|
QVERIFY(out.toBool());
|
||||||
|
|
||||||
|
QCOMPARE(bookmarksSpy.count(), 1);
|
||||||
|
BookmarkItem* createdItem = qvariant_cast<BookmarkItem*>(bookmarksSpy.at(0).at(0));
|
||||||
|
QVERIFY(createdItem);
|
||||||
|
QCOMPARE(createdItem->title(), QString("Example Plugin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlBookmarksApiTest::testBookmarksExistence()
|
||||||
|
{
|
||||||
|
// in continuation from testBookmarksCreation
|
||||||
|
|
||||||
|
auto result = m_testHelper.evaluate("Falkon.Bookmarks.isBookmarked('https://example.com/')").toBool();
|
||||||
|
QVERIFY(result);
|
||||||
|
QCOMPARE(mApp->bookmarks()->isBookmarked(QUrl("https://example.com/")), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlBookmarksApiTest::testBookmarksModification()
|
||||||
|
{
|
||||||
|
// in continuation from testBookmarksExistence
|
||||||
|
|
||||||
|
QObject *qmlBookmarks = m_testHelper.evaluateQObject("Falkon.Bookmarks");
|
||||||
|
QVERIFY(qmlBookmarks);
|
||||||
|
|
||||||
|
QSignalSpy qmlBookmarksSpy(qmlBookmarks, SIGNAL(changed(QmlBookmarkTreeNode*)));
|
||||||
|
BookmarkItem* item = mApp->bookmarks()->searchBookmarks("https://example.com/").at(0);
|
||||||
|
item->setTitle("Modified Example Domain");
|
||||||
|
mApp->bookmarks()->changeBookmark(item);
|
||||||
|
|
||||||
|
QCOMPARE(qmlBookmarksSpy.count(), 1);
|
||||||
|
|
||||||
|
QObject *modified = qvariant_cast<QObject*>(qmlBookmarksSpy.at(0).at(0));
|
||||||
|
QVERIFY(modified);
|
||||||
|
QCOMPARE(modified->property("title").toString(), QString("Modified Example Domain"));
|
||||||
|
|
||||||
|
qRegisterMetaType<BookmarkItem*>();
|
||||||
|
QSignalSpy bookmarksSpy(mApp->bookmarks(), &Bookmarks::bookmarkChanged);
|
||||||
|
|
||||||
|
auto out = m_testHelper.evaluate("Falkon.Bookmarks.update(Falkon.Bookmarks.get('https://another-example.com'),{"
|
||||||
|
" title: 'Modified Example Plugin'"
|
||||||
|
"})");
|
||||||
|
QVERIFY(out.toBool());
|
||||||
|
|
||||||
|
QCOMPARE(bookmarksSpy.count(), 1);
|
||||||
|
BookmarkItem* modifiedItem = qvariant_cast<BookmarkItem*>(bookmarksSpy.at(0).at(0));
|
||||||
|
QVERIFY(modifiedItem);
|
||||||
|
QCOMPARE(modifiedItem->title(), QString("Modified Example Plugin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlBookmarksApiTest::testBookmarksRemoval()
|
||||||
|
{
|
||||||
|
// in continuation from testBookmarksModification
|
||||||
|
|
||||||
|
QObject *qmlBookmarks = m_testHelper.evaluateQObject("Falkon.Bookmarks");
|
||||||
|
QVERIFY(qmlBookmarks);
|
||||||
|
|
||||||
|
QSignalSpy qmlBookmarksSpy(qmlBookmarks, SIGNAL(removed(QmlBookmarkTreeNode*)));
|
||||||
|
BookmarkItem* item = mApp->bookmarks()->searchBookmarks("https://example.com/").at(0);
|
||||||
|
mApp->bookmarks()->removeBookmark(item);
|
||||||
|
|
||||||
|
QCOMPARE(qmlBookmarksSpy.count(), 1);
|
||||||
|
|
||||||
|
QObject *removed = qvariant_cast<QObject*>(qmlBookmarksSpy.at(0).at(0));
|
||||||
|
QVERIFY(removed);
|
||||||
|
QCOMPARE(removed->property("title").toString(), QString("Modified Example Domain"));
|
||||||
|
|
||||||
|
qRegisterMetaType<BookmarkItem*>();
|
||||||
|
QSignalSpy bookmarksSpy(mApp->bookmarks(), &Bookmarks::bookmarkRemoved);
|
||||||
|
|
||||||
|
auto out = m_testHelper.evaluate("Falkon.Bookmarks.remove(Falkon.Bookmarks.get('https://another-example.com'))");
|
||||||
|
QVERIFY(out.toBool());
|
||||||
|
|
||||||
|
QCOMPARE(bookmarksSpy.count(), 1);
|
||||||
|
BookmarkItem* removedItem = qvariant_cast<BookmarkItem*>(bookmarksSpy.at(0).at(0));
|
||||||
|
QVERIFY(removedItem);
|
||||||
|
QCOMPARE(removedItem->title(), QString("Modified Example Plugin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
FALKONTEST_MAIN(QmlBookmarksApiTest)
|
|
@ -18,20 +18,26 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "qmlmostvisitedurl.h"
|
|
||||||
|
|
||||||
/**
|
#include "bookmarkitem.h"
|
||||||
* @brief The class exposing TopSites API to QML
|
#include "qmltesthelper.h"
|
||||||
*/
|
|
||||||
class QmlTopSites : public QObject
|
class QmlBookmarksApiTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
QmlTestHelper m_testHelper;
|
||||||
explicit QmlTopSites(QObject *parent = nullptr);
|
|
||||||
/**
|
private Q_SLOTS:
|
||||||
* @brief Get the topsites. These refer to the sites which
|
void initTestCase();
|
||||||
* are displayed in the speed-dial (New tab page)
|
void cleanupTestCase();
|
||||||
* @return List of MostVisitedUrl objects of type [QmlMostVisitedUrl](@ref QmlMostVisitedUrl)
|
|
||||||
*/
|
void testBookmarkTreeNodeType();
|
||||||
Q_INVOKABLE QList<QObject*> get() const;
|
void testBookmarkTreeNode();
|
||||||
|
|
||||||
|
void testBookmarksCreation();
|
||||||
|
void testBookmarksExistence();
|
||||||
|
void testBookmarksModification();
|
||||||
|
void testBookmarksRemoval();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(BookmarkItem *)
|
|
@ -15,29 +15,24 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlengine.h"
|
#include "qmlclipboardapitest.h"
|
||||||
|
#include "autotests.h"
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include <QClipboard>
|
||||||
|
|
||||||
QmlEngine::QmlEngine(QObject *parent)
|
void QmlClipboardApiTest::initTestCase()
|
||||||
: QQmlEngine(parent)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QmlEngine::extensionName()
|
void QmlClipboardApiTest::cleanupTestCase()
|
||||||
{
|
{
|
||||||
return m_extensionName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlEngine::setExtensionName(const QString &name)
|
void QmlClipboardApiTest::testClipboard()
|
||||||
{
|
{
|
||||||
m_extensionName = name;
|
m_testHelper.evaluate("Falkon.Clipboard.copy('this text is copied')");
|
||||||
|
QCOMPARE(mApp->clipboard()->text(), "this text is copied");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QmlEngine::extensionPath()
|
FALKONTEST_MAIN(QmlClipboardApiTest)
|
||||||
{
|
|
||||||
return m_extensionPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlEngine::setExtensionPath(const QString &path)
|
|
||||||
{
|
|
||||||
m_extensionPath = path;
|
|
||||||
}
|
|
|
@ -15,9 +15,19 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlwindowtype.h"
|
#pragma once
|
||||||
|
|
||||||
QmlWindowType::QmlWindowType(QObject *parent)
|
#include <QObject>
|
||||||
: QObject(parent)
|
#include "qmltesthelper.h"
|
||||||
|
|
||||||
|
class QmlClipboardApiTest : public QObject
|
||||||
{
|
{
|
||||||
}
|
Q_OBJECT
|
||||||
|
QmlTestHelper m_testHelper;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
void testClipboard();
|
||||||
|
};
|
117
autotests/qml/qmlcookiesapitest.cpp
Normal file
117
autotests/qml/qmlcookiesapitest.cpp
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlcookiesapitest.h"
|
||||||
|
#include "autotests.h"
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "cookiejar.h"
|
||||||
|
#include "qml/api/cookies/qmlcookie.h"
|
||||||
|
#include <QWebEngineProfile>
|
||||||
|
|
||||||
|
void QmlCookiesApiTest::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlCookiesApiTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlCookiesApiTest::testCookieAdditionRemoval()
|
||||||
|
{
|
||||||
|
QSignalSpy cookieAddSpy(mApp->cookieJar(), &CookieJar::cookieAdded);
|
||||||
|
m_testHelper.evaluate("Falkon.Cookies.set({"
|
||||||
|
" name: 'Example',"
|
||||||
|
" url: '.example.com',"
|
||||||
|
" expirationDate: Date.now() + 60*1000"
|
||||||
|
"})");
|
||||||
|
QTRY_COMPARE(cookieAddSpy.count(), 1);
|
||||||
|
QNetworkCookie netCookie = qvariant_cast<QNetworkCookie>(cookieAddSpy.at(0).at(0));
|
||||||
|
QCOMPARE(netCookie.name(), "Example");
|
||||||
|
QObject *object = m_testHelper.evaluateQObject("Falkon.Cookies");
|
||||||
|
QVERIFY(object);
|
||||||
|
QSignalSpy qmlCookieSpy(object, SIGNAL(changed(QVariantMap)));
|
||||||
|
QNetworkCookie anotherNetCookie;
|
||||||
|
anotherNetCookie.setName(QString("Hello").toLocal8Bit());
|
||||||
|
anotherNetCookie.setDomain(".mydomain.com");
|
||||||
|
anotherNetCookie.setExpirationDate(QDateTime::currentDateTime().addSecs(60));
|
||||||
|
mApp->webProfile()->cookieStore()->setCookie(anotherNetCookie);
|
||||||
|
QTRY_COMPARE(qmlCookieSpy.count(), 1);
|
||||||
|
QVariantMap addedQmlCookieMap = QVariant(qmlCookieSpy.at(0).at(0)).toMap();
|
||||||
|
QObject *addedQmlCookie = qvariant_cast<QObject*>(addedQmlCookieMap.value("cookie"));
|
||||||
|
bool removed = addedQmlCookieMap.value("removed").toBool();
|
||||||
|
QCOMPARE(addedQmlCookie->property("name").toString(), "Hello");
|
||||||
|
QCOMPARE(removed, false);
|
||||||
|
|
||||||
|
mApp->webProfile()->cookieStore()->deleteCookie(netCookie);
|
||||||
|
QTRY_COMPARE(qmlCookieSpy.count(), 2);
|
||||||
|
QVariantMap removedQmlCookieMap = QVariant(qmlCookieSpy.at(1).at(0)).toMap();
|
||||||
|
QObject *removedQmlCookie = qvariant_cast<QObject*>(removedQmlCookieMap.value("cookie"));
|
||||||
|
removed = removedQmlCookieMap.value("removed").toBool();
|
||||||
|
QCOMPARE(removedQmlCookie->property("name").toString(), "Example");
|
||||||
|
QCOMPARE(removed, true);
|
||||||
|
|
||||||
|
QSignalSpy cookieRemoveSpy(mApp->cookieJar(), &CookieJar::cookieRemoved);
|
||||||
|
m_testHelper.evaluate("Falkon.Cookies.remove({"
|
||||||
|
" name: 'Hello',"
|
||||||
|
" url: '.mydomain.com',"
|
||||||
|
"})");
|
||||||
|
QTRY_COMPARE(cookieRemoveSpy.count(), 1);
|
||||||
|
netCookie = qvariant_cast<QNetworkCookie>(cookieRemoveSpy.at(0).at(0));
|
||||||
|
QCOMPARE(netCookie.name(), "Hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlCookiesApiTest::testCookieGet()
|
||||||
|
{
|
||||||
|
QDateTime current = QDateTime::currentDateTime();
|
||||||
|
QSignalSpy cookieAddSpy(mApp->cookieJar(), &CookieJar::cookieAdded);
|
||||||
|
|
||||||
|
QNetworkCookie netCookie_1;
|
||||||
|
netCookie_1.setName(QString("Apple").toLocal8Bit());
|
||||||
|
netCookie_1.setDomain(".apple-domain.com");
|
||||||
|
netCookie_1.setExpirationDate(current.addSecs(60));
|
||||||
|
mApp->webProfile()->cookieStore()->setCookie(netCookie_1);
|
||||||
|
|
||||||
|
QNetworkCookie netCookie_2;
|
||||||
|
netCookie_2.setName(QString("Mango").toLocal8Bit());
|
||||||
|
netCookie_2.setDomain(".mango-domain.com");
|
||||||
|
netCookie_2.setExpirationDate(current.addSecs(120));
|
||||||
|
mApp->webProfile()->cookieStore()->setCookie(netCookie_2);
|
||||||
|
|
||||||
|
QNetworkCookie netCookie_3;
|
||||||
|
netCookie_3.setName(QString("Mango").toLocal8Bit());
|
||||||
|
netCookie_3.setDomain(".yet-another-mango-domain.com");
|
||||||
|
netCookie_3.setExpirationDate(current.addSecs(180));
|
||||||
|
mApp->webProfile()->cookieStore()->setCookie(netCookie_3);
|
||||||
|
|
||||||
|
QTRY_COMPARE(cookieAddSpy.count(), 3);
|
||||||
|
|
||||||
|
QObject *mangoCookie = m_testHelper.evaluateQObject("Falkon.Cookies.get({"
|
||||||
|
" name: 'Mango',"
|
||||||
|
" url: '.mango-domain.com'"
|
||||||
|
"})");
|
||||||
|
QVERIFY(mangoCookie);
|
||||||
|
QCOMPARE(mangoCookie->property("name").toString(), "Mango");
|
||||||
|
// FIXME: Here current.addSecs differes from expirationDate by some ms
|
||||||
|
// a solution is to convert both to string, but this is not the best solution
|
||||||
|
QCOMPARE(mangoCookie->property("expirationDate").toDateTime().toString(), current.addSecs(120).toString());
|
||||||
|
|
||||||
|
QList<QVariant> mangoCookies = m_testHelper.evaluate("Falkon.Cookies.getAll({name: 'Mango'})").toVariant().toList();
|
||||||
|
QCOMPARE(mangoCookies.length(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
FALKONTEST_MAIN(QmlCookiesApiTest)
|
34
autotests/qml/qmlcookiesapitest.h
Normal file
34
autotests/qml/qmlcookiesapitest.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmltesthelper.h"
|
||||||
|
|
||||||
|
class QmlCookiesApiTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
QmlTestHelper m_testHelper;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
void testCookieAdditionRemoval();
|
||||||
|
void testCookieGet();
|
||||||
|
};
|
89
autotests/qml/qmlhistoryapitest.cpp
Normal file
89
autotests/qml/qmlhistoryapitest.cpp
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlhistoryapitest.h"
|
||||||
|
#include "autotests.h"
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "history.h"
|
||||||
|
#include "qml/api/history/qmlhistoryitem.h"
|
||||||
|
#include "qml/api/history/qmlhistory.h"
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(HistoryEntry)
|
||||||
|
|
||||||
|
void QmlHistoryApiTest::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlHistoryApiTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlHistoryApiTest::testAddition()
|
||||||
|
{
|
||||||
|
qRegisterMetaType<HistoryEntry>();
|
||||||
|
QSignalSpy historySpy(mApp->history(), &History::historyEntryAdded);
|
||||||
|
m_testHelper.evaluate("Falkon.History.addUrl({"
|
||||||
|
" url: 'https://example.com',"
|
||||||
|
" title: 'Example Domain'"
|
||||||
|
"})");
|
||||||
|
QTRY_COMPARE(historySpy.count(), 1);
|
||||||
|
HistoryEntry entry = qvariant_cast<HistoryEntry>(historySpy.at(0).at(0));
|
||||||
|
QCOMPARE(entry.title, "Example Domain");
|
||||||
|
|
||||||
|
auto object = m_testHelper.evaluateQObject("Falkon.History");
|
||||||
|
QSignalSpy qmlHistorySpy(object, SIGNAL(visited(QmlHistoryItem*)));
|
||||||
|
mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain");
|
||||||
|
QTRY_COMPARE(qmlHistorySpy.count(), 1);
|
||||||
|
mApp->history()->clearHistory();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlHistoryApiTest::testSearch()
|
||||||
|
{
|
||||||
|
QSignalSpy historySpy(mApp->history(), &History::historyEntryAdded);
|
||||||
|
mApp->history()->addHistoryEntry(QUrl("https://example.com"), "Example Domain");
|
||||||
|
mApp->history()->addHistoryEntry(QUrl("https://another-example.com"), "Another Example Domain");
|
||||||
|
mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain");
|
||||||
|
QTRY_COMPARE(historySpy.count(), 3);
|
||||||
|
auto list = m_testHelper.evaluate("Falkon.History.search('example')").toVariant().toList();
|
||||||
|
QCOMPARE(list.length(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlHistoryApiTest::testVisits()
|
||||||
|
{
|
||||||
|
int visits = m_testHelper.evaluate("Falkon.History.getVisits('https://sample.com')").toInt();
|
||||||
|
QCOMPARE(visits, 1);
|
||||||
|
QSignalSpy historySpy(mApp->history(), &History::historyEntryEdited);
|
||||||
|
mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain");
|
||||||
|
QTRY_COMPARE(historySpy.count(), 1);
|
||||||
|
visits = m_testHelper.evaluate("Falkon.History.getVisits('https://sample.com')").toInt();
|
||||||
|
QCOMPARE(visits, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlHistoryApiTest::testRemoval()
|
||||||
|
{
|
||||||
|
QSignalSpy historySpy(mApp->history(), &History::historyEntryDeleted);
|
||||||
|
m_testHelper.evaluate("Falkon.History.deleteUrl('https://sample.com')");
|
||||||
|
QTRY_COMPARE(historySpy.count(), 1);
|
||||||
|
|
||||||
|
auto object = m_testHelper.evaluateQObject("Falkon.History");
|
||||||
|
QSignalSpy qmlHistorySpy(object, SIGNAL(visitRemoved(QmlHistoryItem*)));
|
||||||
|
mApp->history()->deleteHistoryEntry("https://example.com", "Example Domain");
|
||||||
|
QTRY_COMPARE(qmlHistorySpy.count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
FALKONTEST_MAIN(QmlHistoryApiTest)
|
|
@ -18,15 +18,19 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
|
||||||
class QmlExternalJsObject : public QObject
|
class QmlHistoryApiTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
QmlTestHelper m_testHelper;
|
||||||
explicit QmlExternalJsObject(QObject *parent = nullptr);
|
|
||||||
~QmlExternalJsObject();
|
private Q_SLOTS:
|
||||||
Q_INVOKABLE void registerExtraObject(const QVariantMap &map);
|
void initTestCase();
|
||||||
Q_INVOKABLE void unregisterExtraObject(QObject *object);
|
void cleanupTestCase();
|
||||||
private:
|
|
||||||
QList<QObject *> m_objects;
|
void testAddition();
|
||||||
|
void testSearch();
|
||||||
|
void testVisits();
|
||||||
|
void testRemoval();
|
||||||
};
|
};
|
114
autotests/qml/qmltabsapitest.cpp
Normal file
114
autotests/qml/qmltabsapitest.cpp
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmltabsapitest.h"
|
||||||
|
#include "autotests.h"
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "tabwidget.h"
|
||||||
|
|
||||||
|
void QmlTabsApiTest::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlTabsApiTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlTabsApiTest::testInitWindowCount()
|
||||||
|
{
|
||||||
|
QCOMPARE(mApp->windowCount(), 1);
|
||||||
|
QCOMPARE(mApp->getWindow()->tabCount(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlTabsApiTest::testTabsAPI()
|
||||||
|
{
|
||||||
|
// Tab Insertion
|
||||||
|
QObject *qmlTabsObject = m_testHelper.evaluateQObject("Falkon.Tabs");
|
||||||
|
QVERIFY(qmlTabsObject);
|
||||||
|
QSignalSpy qmlTabsInsertedSpy(qmlTabsObject, SIGNAL(tabInserted(QVariantMap)));
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.addTab({"
|
||||||
|
" url: 'https://example.com/'"
|
||||||
|
"})");
|
||||||
|
QCOMPARE(qmlTabsInsertedSpy.count(), 1);
|
||||||
|
QVariantMap retMap1 = QVariant(qmlTabsInsertedSpy.at(0).at(0)).toMap();
|
||||||
|
int index1 = retMap1.value(QSL("index"), -1).toInt();
|
||||||
|
int windowId1 = retMap1.value(QSL("windowId"), -1).toInt();
|
||||||
|
QCOMPARE(index1, 0);
|
||||||
|
QCOMPARE(windowId1, 0);
|
||||||
|
|
||||||
|
QObject *qmlTabObject1 = m_testHelper.evaluateQObject("Falkon.Tabs.get({index: 0})");
|
||||||
|
QVERIFY(qmlTabObject1);
|
||||||
|
QCOMPARE(qmlTabObject1->property("url").toString(), "https://example.com/");
|
||||||
|
QCOMPARE(qmlTabObject1->property("index").toInt(), 0);
|
||||||
|
QCOMPARE(qmlTabObject1->property("pinned").toBool(), false);
|
||||||
|
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.addTab({"
|
||||||
|
" url: 'https://another-example.com/',"
|
||||||
|
"})");
|
||||||
|
QCOMPARE(qmlTabsInsertedSpy.count(), 2);
|
||||||
|
QVariantMap retMap2 = QVariant(qmlTabsInsertedSpy.at(1).at(0)).toMap();
|
||||||
|
int index2 = retMap2.value(QSL("index"), -1).toInt();
|
||||||
|
int windowId2 = retMap2.value(QSL("windowId"), -1).toInt();
|
||||||
|
QCOMPARE(index2, 1);
|
||||||
|
QCOMPARE(windowId2, 0);
|
||||||
|
|
||||||
|
bool pinnedTab = m_testHelper.evaluate("Falkon.Tabs.pinTab({index: 1})").toBool();
|
||||||
|
QVERIFY(pinnedTab);
|
||||||
|
QObject *qmlTabObject2 = m_testHelper.evaluateQObject("Falkon.Tabs.get({index: 0})");
|
||||||
|
QVERIFY(qmlTabObject2);
|
||||||
|
QCOMPARE(qmlTabObject2->property("url").toString(), "https://another-example.com/");
|
||||||
|
QCOMPARE(qmlTabObject2->property("index").toInt(), 0);
|
||||||
|
QCOMPARE(qmlTabObject2->property("pinned").toBool(), true);
|
||||||
|
|
||||||
|
bool unpinnedTab = m_testHelper.evaluate("Falkon.Tabs.unpinTab({index: 0})").toBool();
|
||||||
|
QVERIFY(unpinnedTab);
|
||||||
|
QObject *qmlTabObject3 = m_testHelper.evaluateQObject("Falkon.Tabs.get({index: 0})");
|
||||||
|
QVERIFY(qmlTabObject3);
|
||||||
|
QCOMPARE(qmlTabObject3->property("url").toString(), "https://another-example.com/");
|
||||||
|
QCOMPARE(qmlTabObject3->property("index").toInt(), 0);
|
||||||
|
QCOMPARE(qmlTabObject3->property("pinned").toBool(), false);
|
||||||
|
|
||||||
|
// Next-Previous-Current
|
||||||
|
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0);
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.nextTab()");
|
||||||
|
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1);
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.nextTab()");
|
||||||
|
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0);
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.previousTab()");
|
||||||
|
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1);
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.previousTab()");
|
||||||
|
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0);
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.setCurrentIndex({index: 1})");
|
||||||
|
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1);
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.setCurrentIndex({index: 0})");
|
||||||
|
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0);
|
||||||
|
|
||||||
|
// Move Tab
|
||||||
|
QSignalSpy qmlTabsMovedSpy(qmlTabsObject, SIGNAL(tabMoved(QVariantMap)));
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.moveTab({from: 0, to:1, windowId: 0})");
|
||||||
|
QCOMPARE(qmlTabsMovedSpy.count(), 1);
|
||||||
|
|
||||||
|
// Tab Removal
|
||||||
|
QCOMPARE(mApp->getWindow()->tabCount(), 2);
|
||||||
|
QSignalSpy qmlTabsRemovedSpy(qmlTabsObject, SIGNAL(tabRemoved(QVariantMap)));
|
||||||
|
m_testHelper.evaluate("Falkon.Tabs.closeTab({index: 0})");
|
||||||
|
QCOMPARE(qmlTabsRemovedSpy.count(), 1);
|
||||||
|
QCOMPARE(mApp->getWindow()->tabCount(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
FALKONTEST_MAIN(QmlTabsApiTest)
|
34
autotests/qml/qmltabsapitest.h
Normal file
34
autotests/qml/qmltabsapitest.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmltesthelper.h"
|
||||||
|
|
||||||
|
class QmlTabsApiTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
QmlTestHelper m_testHelper;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
void testInitWindowCount();
|
||||||
|
void testTabsAPI();
|
||||||
|
};
|
57
autotests/qml/qmltesthelper.cpp
Normal file
57
autotests/qml/qmltesthelper.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmltesthelper.h"
|
||||||
|
#include "qml/qmlplugins.h"
|
||||||
|
#include <QQmlComponent>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
QmlTestHelper::QmlTestHelper()
|
||||||
|
{
|
||||||
|
QmlPlugins::registerQmlTypes();
|
||||||
|
qmlRegisterType<QmlTestItem>("org.kde.falkon.test", 1, 0, "TestItem");
|
||||||
|
QQmlComponent component(&engine);
|
||||||
|
component.setData("import org.kde.falkon 1.0 as Falkon\n"
|
||||||
|
"import org.kde.falkon.test 1.0 as FalkonTest\n"
|
||||||
|
"import QtQuick 2.7\n"
|
||||||
|
"FalkonTest.TestItem {"
|
||||||
|
" evalFunc: function(source) {"
|
||||||
|
" return eval(source);"
|
||||||
|
" }"
|
||||||
|
"}"
|
||||||
|
, QUrl());
|
||||||
|
testItem = qobject_cast<QmlTestItem*>(component.create());
|
||||||
|
Q_ASSERT(testItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJSValue QmlTestHelper::evaluate(const QString &source)
|
||||||
|
{
|
||||||
|
auto out = testItem->evaluate(source);
|
||||||
|
if (out.isError()) {
|
||||||
|
qWarning() << "Error:" << out.toString();
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *QmlTestHelper::evaluateQObject(const QString &source)
|
||||||
|
{
|
||||||
|
auto out = evaluate(source);
|
||||||
|
if (out.isQObject()) {
|
||||||
|
return out.toQObject();
|
||||||
|
}
|
||||||
|
return out.toVariant().value<QObject*>();
|
||||||
|
}
|
|
@ -15,9 +15,17 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlqzobjects.h"
|
#pragma once
|
||||||
|
|
||||||
QmlQzObjects::QmlQzObjects(QObject *parent)
|
#include "qmltestitem.h"
|
||||||
: QObject(parent)
|
#include <QQmlEngine>
|
||||||
|
|
||||||
|
class QmlTestHelper
|
||||||
{
|
{
|
||||||
}
|
public:
|
||||||
|
explicit QmlTestHelper();
|
||||||
|
QJSValue evaluate(const QString &source);
|
||||||
|
QObject *evaluateQObject(const QString &source);
|
||||||
|
QQmlEngine engine;
|
||||||
|
QmlTestItem *testItem;
|
||||||
|
};
|
|
@ -15,9 +15,25 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlwindowstate.h"
|
#include "qmltestitem.h"
|
||||||
|
|
||||||
QmlWindowState::QmlWindowState(QObject *parent)
|
QmlTestItem::QmlTestItem(QObject *parent) :
|
||||||
: QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJSValue QmlTestItem::evalFunc()
|
||||||
|
{
|
||||||
|
return m_evalFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlTestItem::setEvalFunc(const QJSValue &func)
|
||||||
|
{
|
||||||
|
m_evalFunc = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJSValue QmlTestItem::evaluate(const QString &source)
|
||||||
|
{
|
||||||
|
Q_ASSERT(m_evalFunc.isCallable());
|
||||||
|
return m_evalFunc.call({source});
|
||||||
|
}
|
|
@ -18,19 +18,19 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QJSValue>
|
||||||
|
|
||||||
/**
|
class QmlTestItem : public QObject
|
||||||
* @brief The class exposing application
|
|
||||||
* clipboard to QML
|
|
||||||
*/
|
|
||||||
class QmlClipboard : public QObject
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QJSValue evalFunc READ evalFunc WRITE setEvalFunc)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QmlClipboard(QObject *parent = nullptr);
|
explicit QmlTestItem(QObject *parent = nullptr);
|
||||||
/**
|
QJSValue evalFunc();
|
||||||
* @brief Copy the string to clipboard
|
void setEvalFunc(const QJSValue &func);
|
||||||
* @param String representing the text to be copied
|
QJSValue evaluate(const QString &source);
|
||||||
*/
|
|
||||||
Q_INVOKABLE void copy(const QString &text);
|
private:
|
||||||
|
QJSValue m_evalFunc;
|
||||||
};
|
};
|
|
@ -15,25 +15,30 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmltopsites.h"
|
#include "qmltopsitesapitest.h"
|
||||||
#include "speeddial.h"
|
#include "autotests.h"
|
||||||
|
#include "qmltesthelper.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "pluginproxy.h"
|
#include "pluginproxy.h"
|
||||||
|
#include "speeddial.h"
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QmlMostVisitedUrlData, mostVisitedUrlData)
|
void QmlTopSitesApiTest::initTestCase()
|
||||||
|
|
||||||
QmlTopSites::QmlTopSites(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QObject*> QmlTopSites::get() const
|
void QmlTopSitesApiTest::cleanupTestCase()
|
||||||
{
|
{
|
||||||
QList<SpeedDial::Page> pages = mApp->plugins()->speedDial()->pages();
|
|
||||||
QList<QObject*> list;
|
|
||||||
foreach(SpeedDial::Page page, pages) {
|
|
||||||
auto mostVisitedUrl = mostVisitedUrlData->get(page.title, page.url);
|
|
||||||
list.append(mostVisitedUrl);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlTopSitesApiTest::testTopSites()
|
||||||
|
{
|
||||||
|
mApp->plugins()->speedDial()->addPage(QUrl("https://example.com"), "Example Domain");
|
||||||
|
auto list = m_testHelper.evaluate("Falkon.TopSites.get()").toVariant().toList();
|
||||||
|
QCOMPARE(list.length(), 1);
|
||||||
|
QObject* object = qvariant_cast<QObject*>(list.at(0));
|
||||||
|
QVERIFY(object);
|
||||||
|
QCOMPARE(object->property("title").toString(), "Example Domain");
|
||||||
|
QCOMPARE(object->property("url").toString(), "https://example.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
FALKONTEST_MAIN(QmlTopSitesApiTest)
|
|
@ -16,12 +16,18 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "browserwindow.h"
|
|
||||||
|
|
||||||
class FALKON_EXPORT QmlPlugins
|
#include <QObject>
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
|
||||||
|
class QmlTopSitesApiTest : public QObject
|
||||||
{
|
{
|
||||||
public:
|
Q_OBJECT
|
||||||
static void registerQmlTypes();
|
QmlTestHelper m_testHelper;
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BrowserWindow *)
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
void testTopSites();
|
||||||
|
};
|
98
autotests/qml/qmluserscriptapitest.cpp
Normal file
98
autotests/qml/qmluserscriptapitest.cpp
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmluserscriptapitest.h"
|
||||||
|
#include "autotests.h"
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include <QWebEngineProfile>
|
||||||
|
#include <QWebEngineScript>
|
||||||
|
#include <QWebEngineScriptCollection>
|
||||||
|
#include "qml/api/userscript/qmluserscript.h"
|
||||||
|
#include "qml/api/userscript/qmluserscripts.h"
|
||||||
|
|
||||||
|
void QmlUserScriptApiTest::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScriptApiTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScriptApiTest::testCount()
|
||||||
|
{
|
||||||
|
int count = m_testHelper.evaluate("Falkon.UserScripts.count").toInt();
|
||||||
|
QCOMPARE(count, mApp->webProfile()->scripts()->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScriptApiTest::testSize()
|
||||||
|
{
|
||||||
|
int size = m_testHelper.evaluate("Falkon.UserScripts.size").toInt();
|
||||||
|
QCOMPARE(size, mApp->webProfile()->scripts()->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScriptApiTest::testEmpty()
|
||||||
|
{
|
||||||
|
bool empty = m_testHelper.evaluate("Falkon.UserScripts.empty").toBool();
|
||||||
|
QCOMPARE(empty, mApp->webProfile()->scripts()->isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScriptApiTest::testContains()
|
||||||
|
{
|
||||||
|
QWebEngineScript script = mApp->webProfile()->scripts()->toList().at(0);
|
||||||
|
QObject *object = m_testHelper.evaluateQObject("Falkon.UserScripts");
|
||||||
|
QmlUserScripts *userScripts = dynamic_cast<QmlUserScripts*>(object);
|
||||||
|
QVERIFY(userScripts);
|
||||||
|
QmlUserScript *userScript = new QmlUserScript();
|
||||||
|
userScript->setWebEngineScript(script);
|
||||||
|
bool contains = userScripts->contains(userScript);
|
||||||
|
QCOMPARE(contains, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScriptApiTest::testFind()
|
||||||
|
{
|
||||||
|
QWebEngineScript script = mApp->webProfile()->scripts()->toList().at(0);
|
||||||
|
QObject *object = m_testHelper.evaluateQObject("Falkon.UserScripts");
|
||||||
|
QmlUserScripts *userScripts = dynamic_cast<QmlUserScripts*>(object);
|
||||||
|
QVERIFY(userScripts);
|
||||||
|
QObject *scriptFound = userScripts->findScript(script.name());
|
||||||
|
QVERIFY(scriptFound);
|
||||||
|
QCOMPARE(scriptFound->property("name").toString(), script.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScriptApiTest::testInsertRemove()
|
||||||
|
{
|
||||||
|
int initialCount = m_testHelper.evaluate("Falkon.UserScripts.count").toInt();
|
||||||
|
QObject *object = m_testHelper.evaluateQObject("Falkon.UserScripts");
|
||||||
|
QmlUserScripts *userScripts = dynamic_cast<QmlUserScripts*>(object);
|
||||||
|
QVERIFY(userScripts);
|
||||||
|
QmlUserScript *userScript = new QmlUserScript();
|
||||||
|
userScript->setProperty("name", "Hello World");
|
||||||
|
userScript->setProperty("sourceCode", "(function() {"
|
||||||
|
" alert('Hello World')"
|
||||||
|
"})()");
|
||||||
|
userScripts->insert(userScript);
|
||||||
|
int finalCount = m_testHelper.evaluate("Falkon.UserScripts.count").toInt();
|
||||||
|
QCOMPARE(finalCount, initialCount + 1);
|
||||||
|
|
||||||
|
userScripts->remove(userScript);
|
||||||
|
|
||||||
|
int ultimateCount = m_testHelper.evaluate("Falkon.UserScripts.count").toInt();
|
||||||
|
QCOMPARE(ultimateCount, initialCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
FALKONTEST_MAIN(QmlUserScriptApiTest)
|
|
@ -17,17 +17,22 @@
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QQmlEngine>
|
#include <QObject>
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
|
||||||
class QmlEngine : public QQmlEngine
|
class QmlUserScriptApiTest : public QObject
|
||||||
{
|
{
|
||||||
public:
|
Q_OBJECT
|
||||||
explicit QmlEngine(QObject *parent = nullptr);
|
QmlTestHelper m_testHelper;
|
||||||
QString extensionName();
|
|
||||||
void setExtensionName(const QString &name);
|
private Q_SLOTS:
|
||||||
QString extensionPath();
|
void initTestCase();
|
||||||
void setExtensionPath(const QString &path);
|
void cleanupTestCase();
|
||||||
private:
|
|
||||||
QString m_extensionName;
|
void testCount();
|
||||||
QString m_extensionPath;
|
void testSize();
|
||||||
|
void testEmpty();
|
||||||
|
void testContains();
|
||||||
|
void testFind();
|
||||||
|
void testInsertRemove();
|
||||||
};
|
};
|
67
autotests/qml/qmlwindowsapitest.cpp
Normal file
67
autotests/qml/qmlwindowsapitest.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlwindowsapitest.h"
|
||||||
|
#include "autotests.h"
|
||||||
|
#include "qmltesthelper.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "qml/api/windows/qmlwindow.h"
|
||||||
|
#include "pluginproxy.h"
|
||||||
|
#include "browserwindow.h"
|
||||||
|
|
||||||
|
void QmlWindowsApiTest::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlWindowsApiTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlWindowsApiTest::testWindowsAPI()
|
||||||
|
{
|
||||||
|
QObject *currentWindowObject = m_testHelper.evaluateQObject("Falkon.Windows.getCurrent()");
|
||||||
|
QVERIFY(currentWindowObject);
|
||||||
|
QCOMPARE(currentWindowObject->property("title").toString(), mApp->getWindow()->windowTitle());
|
||||||
|
QCOMPARE(currentWindowObject->property("type").toInt(), (int)mApp->getWindow()->windowType());
|
||||||
|
QCOMPARE(currentWindowObject->property("tabs").toList().length(), mApp->getWindow()->tabCount());
|
||||||
|
|
||||||
|
QObject *windowObject = m_testHelper.evaluateQObject("Falkon.Windows");
|
||||||
|
QVERIFY(windowObject);
|
||||||
|
QSignalSpy qmlWindowCreatedSignal(windowObject, SIGNAL(created(QmlWindow*)));
|
||||||
|
qRegisterMetaType<BrowserWindow*>();
|
||||||
|
QSignalSpy windowCreatedSingal(mApp->plugins(), SIGNAL(mainWindowCreated(BrowserWindow*)));
|
||||||
|
QObject *newQmlWindow = m_testHelper.evaluateQObject("Falkon.Windows.create({})");
|
||||||
|
QVERIFY(newQmlWindow);
|
||||||
|
QCOMPARE(mApp->windowCount(), 2);
|
||||||
|
// FIXME: signal is emitted 2 times here -
|
||||||
|
// 1st for the initial window, 2nd for the created window
|
||||||
|
QTRY_COMPARE(qmlWindowCreatedSignal.count(), 2);
|
||||||
|
QTRY_COMPARE(windowCreatedSingal.count(), 2);
|
||||||
|
QObject *newQmlSignalWindow = qvariant_cast<QObject*>(qmlWindowCreatedSignal.at(1).at(0));
|
||||||
|
QVERIFY(newQmlSignalWindow);
|
||||||
|
QCOMPARE(newQmlWindow->property("id").toInt(), newQmlSignalWindow->property("id").toInt());
|
||||||
|
|
||||||
|
int qmlWindowCount = m_testHelper.evaluate("Falkon.Windows.getAll().length").toInt();
|
||||||
|
QCOMPARE(qmlWindowCount, mApp->windowCount());
|
||||||
|
|
||||||
|
QSignalSpy qmlWindowRemovedSignal(windowObject, SIGNAL(removed(QmlWindow*)));
|
||||||
|
int newQmlWindowId = newQmlSignalWindow->property("id").toInt();
|
||||||
|
m_testHelper.evaluate(QString("Falkon.Windows.remove(%1)").arg(newQmlWindowId));
|
||||||
|
QTRY_COMPARE(qmlWindowRemovedSignal.count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
FALKONTEST_MAIN(QmlWindowsApiTest)
|
|
@ -15,16 +15,19 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlclipboard.h"
|
#pragma once
|
||||||
#include "mainapplication.h"
|
|
||||||
#include <QClipboard>
|
|
||||||
|
|
||||||
QmlClipboard::QmlClipboard(QObject *parent)
|
#include <QObject>
|
||||||
: QObject(parent)
|
#include "qmltesthelper.h"
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlClipboard::copy(const QString &text)
|
class QmlWindowsApiTest : public QObject
|
||||||
{
|
{
|
||||||
mApp->clipboard()->setText(text);
|
Q_OBJECT
|
||||||
}
|
QmlTestHelper m_testHelper;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
void testWindowsAPI();
|
||||||
|
};
|
|
@ -46,6 +46,7 @@ Comment[nl]=Een snelle en veilige webbrowser
|
||||||
Comment[nn]=Ein kjapp og sikker nettlesar
|
Comment[nn]=Ein kjapp og sikker nettlesar
|
||||||
Comment[pl]=Szybka i bezpieczna przeglądarka sieciowa
|
Comment[pl]=Szybka i bezpieczna przeglądarka sieciowa
|
||||||
Comment[pt]=Um navegador Web rápido e seguro
|
Comment[pt]=Um navegador Web rápido e seguro
|
||||||
|
Comment[pt_BR]=Um navegar Web rápido e seguro
|
||||||
Comment[sv]=En snabb och säker webbläsare
|
Comment[sv]=En snabb och säker webbläsare
|
||||||
Comment[uk]=Проста і безпечна програма для перегляду інтернету
|
Comment[uk]=Проста і безпечна програма для перегляду інтернету
|
||||||
Comment[x-test]=xxA fast and secure web browserxx
|
Comment[x-test]=xxA fast and secure web browserxx
|
||||||
|
@ -156,6 +157,7 @@ Name[nl]=Privébrowsing starten
|
||||||
Name[nn]=Start privat nettlesing
|
Name[nn]=Start privat nettlesing
|
||||||
Name[pl]=Rozpocznij prywatne przeglądanie
|
Name[pl]=Rozpocznij prywatne przeglądanie
|
||||||
Name[pt]=Iniciar a navegação privada
|
Name[pt]=Iniciar a navegação privada
|
||||||
|
Name[pt_BR]=Iniciar navegação privada
|
||||||
Name[sv]=Starta privat webbläsning
|
Name[sv]=Starta privat webbläsning
|
||||||
Name[uk]=Конфіденційний перегляд
|
Name[uk]=Конфіденційний перегляд
|
||||||
Name[x-test]=xxStart private browsingxx
|
Name[x-test]=xxStart private browsingxx
|
||||||
|
|
|
@ -7,6 +7,7 @@ Name[da]=AdBlock
|
||||||
Name[de]=AdBlock
|
Name[de]=AdBlock
|
||||||
Name[en_GB]=AdBlock
|
Name[en_GB]=AdBlock
|
||||||
Name[es]=AdBlock
|
Name[es]=AdBlock
|
||||||
|
Name[fi]=Mainosesto
|
||||||
Name[fr]=AdBlock
|
Name[fr]=AdBlock
|
||||||
Name[gl]=Bloqueador de publicidade
|
Name[gl]=Bloqueador de publicidade
|
||||||
Name[id]=AdBlock
|
Name[id]=AdBlock
|
||||||
|
@ -28,6 +29,7 @@ Comment[da]=Blokerer uønskede webindhold
|
||||||
Comment[de]=Blockiert unerwünschte Web-Inhalte
|
Comment[de]=Blockiert unerwünschte Web-Inhalte
|
||||||
Comment[en_GB]=Blocks unwanted web content
|
Comment[en_GB]=Blocks unwanted web content
|
||||||
Comment[es]=Bloquea contenido web no deseado
|
Comment[es]=Bloquea contenido web no deseado
|
||||||
|
Comment[fi]=Estää epätoivotun verkkosisällön
|
||||||
Comment[fr]=Blocage des contenus Web indésirables
|
Comment[fr]=Blocage des contenus Web indésirables
|
||||||
Comment[gl]=Bloquea contenido web non desexado
|
Comment[gl]=Bloquea contenido web non desexado
|
||||||
Comment[id]=Memblokir konten web yang tak diinginkan
|
Comment[id]=Memblokir konten web yang tak diinginkan
|
||||||
|
@ -36,6 +38,7 @@ Comment[nl]=Blokkeert niet-gewilde webinhoud
|
||||||
Comment[nn]=Blokkerer uønskt vevinnhald
|
Comment[nn]=Blokkerer uønskt vevinnhald
|
||||||
Comment[pl]=Blokuje niechciane treści z sieci
|
Comment[pl]=Blokuje niechciane treści z sieci
|
||||||
Comment[pt]=Bloqueia o conteúdo Web indesejado
|
Comment[pt]=Bloqueia o conteúdo Web indesejado
|
||||||
|
Comment[pt_BR]=Bloqueie conteúdos web indesejados
|
||||||
Comment[sv]=Blockerar oönskat webbinnehåll
|
Comment[sv]=Blockerar oönskat webbinnehåll
|
||||||
Comment[uk]=Блокує небажані інтернет-дані
|
Comment[uk]=Блокує небажані інтернет-дані
|
||||||
Comment[x-test]=xxBlocks unwanted web contentxx
|
Comment[x-test]=xxBlocks unwanted web contentxx
|
||||||
|
|
|
@ -43,6 +43,7 @@ Comment[nl]=Breeze-team
|
||||||
Comment[nn]=Breeze-laget
|
Comment[nn]=Breeze-laget
|
||||||
Comment[pl]=Zespół Bryzy
|
Comment[pl]=Zespół Bryzy
|
||||||
Comment[pt]=Equipa do Brisa
|
Comment[pt]=Equipa do Brisa
|
||||||
|
Comment[pt_BR]=Equipe Breeze
|
||||||
Comment[sv]=Breeze-gruppen
|
Comment[sv]=Breeze-gruppen
|
||||||
Comment[uk]=Команда Breeze
|
Comment[uk]=Команда Breeze
|
||||||
Comment[x-test]=xxBreeze Teamxx
|
Comment[x-test]=xxBreeze Teamxx
|
||||||
|
|
|
@ -1,262 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlbookmarks.h"
|
|
||||||
#include "bookmarks.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QmlBookmarkTreeNodeData, bookmarkTreeNodeData)
|
|
||||||
|
|
||||||
QmlBookmarks::QmlBookmarks(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
connect(mApp->bookmarks(), &Bookmarks::bookmarkAdded, this, [this](BookmarkItem *item){
|
|
||||||
auto treeNode = bookmarkTreeNodeData->get(item);
|
|
||||||
emit created(treeNode);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(mApp->bookmarks(), &Bookmarks::bookmarkChanged, this, [this](BookmarkItem *item){
|
|
||||||
auto treeNode = bookmarkTreeNodeData->get(item);
|
|
||||||
emit changed(treeNode);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(mApp->bookmarks(), &Bookmarks::bookmarkRemoved, this, [this](BookmarkItem *item){
|
|
||||||
auto treeNode = bookmarkTreeNodeData->get(item);
|
|
||||||
emit removed(treeNode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
BookmarkItem *QmlBookmarks::getBookmarkItem(QmlBookmarkTreeNode *treeNode) const
|
|
||||||
{
|
|
||||||
auto bookmarks = mApp->bookmarks();
|
|
||||||
QList<BookmarkItem*> items;
|
|
||||||
|
|
||||||
if (treeNode->url().isEmpty()) {
|
|
||||||
if (isTreeNodeEqualsItem(treeNode, bookmarks->rootItem())) {
|
|
||||||
return bookmarks->rootItem();
|
|
||||||
|
|
||||||
} else if (isTreeNodeEqualsItem(treeNode, bookmarks->toolbarFolder())) {
|
|
||||||
return bookmarks->toolbarFolder();
|
|
||||||
|
|
||||||
} else if (isTreeNodeEqualsItem(treeNode, bookmarks->menuFolder())) {
|
|
||||||
return bookmarks->menuFolder();
|
|
||||||
|
|
||||||
} else if (isTreeNodeEqualsItem(treeNode, bookmarks->unsortedFolder())) {
|
|
||||||
return bookmarks->unsortedFolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
items = bookmarks->searchBookmarks(treeNode->title());
|
|
||||||
} else {
|
|
||||||
items = bookmarks->searchBookmarks(QUrl::fromEncoded(treeNode->url().toUtf8()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto item : qAsConst(items)) {
|
|
||||||
if (isTreeNodeEqualsItem(treeNode, item)) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
BookmarkItem *QmlBookmarks::getBookmarkItem(QObject *object) const
|
|
||||||
{
|
|
||||||
auto treeNode = qobject_cast<QmlBookmarkTreeNode*>(object);
|
|
||||||
if (!treeNode) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto item = getBookmarkItem(treeNode);
|
|
||||||
if (!item || item->urlString() != treeNode->url()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlBookmarks::isBookmarked(const QString &url) const
|
|
||||||
{
|
|
||||||
return mApp->bookmarks()->isBookmarked(QUrl::fromEncoded(url.toUtf8()));
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode *QmlBookmarks::rootItem() const
|
|
||||||
{
|
|
||||||
return bookmarkTreeNodeData->get(mApp->bookmarks()->rootItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode *QmlBookmarks::toolbarFolder() const
|
|
||||||
{
|
|
||||||
return bookmarkTreeNodeData->get(mApp->bookmarks()->toolbarFolder());
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode *QmlBookmarks::menuFolder() const
|
|
||||||
{
|
|
||||||
return bookmarkTreeNodeData->get(mApp->bookmarks()->menuFolder());
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode *QmlBookmarks::unsortedFolder() const
|
|
||||||
{
|
|
||||||
return bookmarkTreeNodeData->get(mApp->bookmarks()->unsortedFolder());
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode *QmlBookmarks::lastUsedFolder() const
|
|
||||||
{
|
|
||||||
return bookmarkTreeNodeData->get(mApp->bookmarks()->lastUsedFolder());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlBookmarks::create(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("parent"))) {
|
|
||||||
qWarning() << "Unable to create new bookmark:" << "parent not found";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const QString title = map.value(QSL("title")).toString();
|
|
||||||
const QString urlString = map.value(QSL("url")).toString();
|
|
||||||
const QString description = map.value(QSL("description")).toString();
|
|
||||||
|
|
||||||
BookmarkItem::Type type;
|
|
||||||
if (map.contains(QSL("type"))) {
|
|
||||||
type = BookmarkItem::Type(map.value(QSL("type")).toInt());
|
|
||||||
} else if (urlString.isEmpty()){
|
|
||||||
if (!title.isEmpty()) {
|
|
||||||
type = BookmarkItem::Folder;
|
|
||||||
} else {
|
|
||||||
type = BookmarkItem::Invalid;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
type = BookmarkItem::Url;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto object = map.value(QSL("parent")).value<QObject*>();
|
|
||||||
auto parent = getBookmarkItem(object);
|
|
||||||
if (!parent) {
|
|
||||||
qWarning() << "Unable to create new bookmark:" << "parent not found";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto item = new BookmarkItem(type);
|
|
||||||
item->setTitle(title);
|
|
||||||
item->setUrl(QUrl::fromEncoded(urlString.toUtf8()));
|
|
||||||
item->setDescription(description);
|
|
||||||
mApp->bookmarks()->addBookmark(parent, item);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlBookmarks::remove(QmlBookmarkTreeNode *treeNode) const
|
|
||||||
{
|
|
||||||
auto item = getBookmarkItem(treeNode);
|
|
||||||
if (!item) {
|
|
||||||
qWarning() << "Unable to remove bookmark:" <<"BookmarkItem not found";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mApp->bookmarks()->removeBookmark(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlBookmarks::search(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("query")) && !map.contains(QSL("url"))) {
|
|
||||||
qWarning() << "Unable to search bookmarks";
|
|
||||||
return QList<QObject*>();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString query = map.value(QSL("query")).toString();
|
|
||||||
const QString urlString = map.value(QSL("url")).toString();
|
|
||||||
QList<BookmarkItem*> items;
|
|
||||||
if (urlString.isEmpty()) {
|
|
||||||
items = mApp->bookmarks()->searchBookmarks(query);
|
|
||||||
} else {
|
|
||||||
items = mApp->bookmarks()->searchBookmarks(QUrl::fromEncoded(urlString.toUtf8()));
|
|
||||||
}
|
|
||||||
QList<QObject*> ret;
|
|
||||||
for (auto item : qAsConst(items)) {
|
|
||||||
ret.append(bookmarkTreeNodeData->get(item));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlBookmarks::update(QObject *object, const QVariantMap &changes) const
|
|
||||||
{
|
|
||||||
auto treeNode = qobject_cast<QmlBookmarkTreeNode*>(object);
|
|
||||||
if (!treeNode) {
|
|
||||||
qWarning() << "Unable to update bookmark:" << "unable to cast QVariant to QmlBookmarkTreeNode";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto item = getBookmarkItem(treeNode);
|
|
||||||
if (!item) {
|
|
||||||
qWarning() << "Unable to update bookmark:" << "bookmark not found";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mApp->bookmarks()->canBeModified(item)) {
|
|
||||||
qWarning() << "Unable to update bookmark:" << "bookmark can not be modified";
|
|
||||||
}
|
|
||||||
|
|
||||||
QString newTitle = treeNode->title();
|
|
||||||
if (changes.contains(QSL("title"))) {
|
|
||||||
newTitle = changes.value(QSL("title")).toString();
|
|
||||||
}
|
|
||||||
QString newDescription = treeNode->description();
|
|
||||||
if (changes.contains(QSL("description"))) {
|
|
||||||
newDescription = changes.value(QSL("description")).toString();
|
|
||||||
}
|
|
||||||
QString newKeyword = treeNode->keyword();
|
|
||||||
if (changes.contains(QSL("keyword"))) {
|
|
||||||
newKeyword = changes.value(QSL("keyword")).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
item->setTitle(newTitle);
|
|
||||||
item->setDescription(newDescription);
|
|
||||||
item->setKeyword(newKeyword);
|
|
||||||
mApp->bookmarks()->changeBookmark(item);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode *QmlBookmarks::get(const QString &string) const
|
|
||||||
{
|
|
||||||
auto items = mApp->bookmarks()->searchBookmarks(QUrl(string));
|
|
||||||
for (const auto item : qAsConst(items)) {
|
|
||||||
if (item->urlString() == string) {
|
|
||||||
return bookmarkTreeNodeData->get(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlBookmarks::getChildren(QObject *object) const
|
|
||||||
{
|
|
||||||
QList<QObject*> ret;
|
|
||||||
|
|
||||||
auto bookmarkItem = getBookmarkItem(object);
|
|
||||||
if (!bookmarkItem) {
|
|
||||||
qWarning() << "Unable to get children:" << "parent not found";
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto items = bookmarkItem->children();
|
|
||||||
for (auto item : qAsConst(items)) {
|
|
||||||
ret.append(bookmarkTreeNodeData->get(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlBookmarks::isTreeNodeEqualsItem(QmlBookmarkTreeNode *treeNode, BookmarkItem *item) const
|
|
||||||
{
|
|
||||||
return treeNode->item() == item;
|
|
||||||
}
|
|
|
@ -1,156 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlbookmarktreenode.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing the Bookmarks API to QML
|
|
||||||
*/
|
|
||||||
class QmlBookmarks : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit QmlBookmarks(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Checks if the url is bookmarked
|
|
||||||
* @param String representing the url to check
|
|
||||||
* @return true if bookmarked, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool isBookmarked(const QString &url) const;
|
|
||||||
/**
|
|
||||||
* @brief Get the root bookmark item
|
|
||||||
* @return Root boomkark item
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlBookmarkTreeNode *rootItem() const;
|
|
||||||
/**
|
|
||||||
* @brief Get the bookmarks toolbar
|
|
||||||
* @return Bookmarks toolbar
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlBookmarkTreeNode *toolbarFolder() const;
|
|
||||||
/**
|
|
||||||
* @brief Get the bookmarks menu folder
|
|
||||||
* @return Bookmarks menu folder
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlBookmarkTreeNode *menuFolder() const;
|
|
||||||
/**
|
|
||||||
* @brief Get the unsorted bookmarks folder
|
|
||||||
* @return Unsorted bookmarks folder
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlBookmarkTreeNode *unsortedFolder() const;
|
|
||||||
/**
|
|
||||||
* @brief Get the last used bookmarks folder
|
|
||||||
* @return Last used bookmarks folder
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlBookmarkTreeNode *lastUsedFolder() const;
|
|
||||||
/**
|
|
||||||
* @brief Creates a bookmark item
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - parent:
|
|
||||||
* Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode), representing
|
|
||||||
* the parent of the new bookmark item. This is required field.
|
|
||||||
* - title:
|
|
||||||
* String representing the title of the new bookmark item. Defaults to empty string
|
|
||||||
* - url:
|
|
||||||
* String representing the url of the new bookmark item. Defaults to empty string
|
|
||||||
* - description
|
|
||||||
* String representing the description of the new bookmark item. Defaults to empty string
|
|
||||||
* - type:
|
|
||||||
* [Type](@ref QmlBookmarkTreeNode::Type) representing the type of the new bookmark item.
|
|
||||||
* Defaults to [Url](@ref QmlBookmarkTreeNode::Url) if url is provided, else
|
|
||||||
* [Folder](@ref QmlBookmarkTreeNode::Folder) if title is provided, else
|
|
||||||
* [Invalid](@ref QmlBookmarkTreeNode::Invalid)
|
|
||||||
* @return true if the bookmark it created, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool create(const QVariantMap &map) const;
|
|
||||||
/**
|
|
||||||
* @brief Removes a bookmark item
|
|
||||||
* @param treeNode:
|
|
||||||
* Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode) to be removed
|
|
||||||
* @return true if the bookmark is removed, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool remove(QmlBookmarkTreeNode *treeNode) const;
|
|
||||||
/**
|
|
||||||
* @brief QmlBookmarks::search
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - query:
|
|
||||||
* String containing search query
|
|
||||||
* - url:
|
|
||||||
* String representing url to be search
|
|
||||||
* @return List containing [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode). If both
|
|
||||||
* query and url are not supplied then empty list is returned.
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject*> search(const QVariantMap &map) const;
|
|
||||||
/**
|
|
||||||
* @brief Updates a bookmark item
|
|
||||||
* @param Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode), representing the bookmark
|
|
||||||
* to update
|
|
||||||
* @param JavaScript object containing the values to be updated
|
|
||||||
* - title:
|
|
||||||
* String representing the new title of the bookmark item
|
|
||||||
* - description:
|
|
||||||
* String representing the new description of the bookmark item
|
|
||||||
* - keyword:
|
|
||||||
* String representing the new keyword of the bookmark item
|
|
||||||
* @return true if the bookmark is updated, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool update(QObject *object, const QVariantMap &changes) const;
|
|
||||||
/**
|
|
||||||
* @brief Get the first matched bookmark item
|
|
||||||
* @param String representing the query
|
|
||||||
* @return Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode) if
|
|
||||||
* the query is matched with a bookmark, else null
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlBookmarkTreeNode *get(const QString &string) const;
|
|
||||||
/**
|
|
||||||
* @brief Get children of the bookmark item
|
|
||||||
* @param Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode), representing
|
|
||||||
* the parent whose children are requested.
|
|
||||||
* @return List containing the children, of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode)
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject*> getChildren(QObject *object) const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when a new bookmark item is created
|
|
||||||
* @param bookmark item, exposed to QML as [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode)
|
|
||||||
*/
|
|
||||||
void created(QmlBookmarkTreeNode *treeNode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when a bookmark item is edited
|
|
||||||
* @param bookmark item, exposed to QML as [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode)
|
|
||||||
*/
|
|
||||||
void changed(QmlBookmarkTreeNode *treeNode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when a bookmark item is removed
|
|
||||||
* @param bookmark item, exposed to QML as [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode)
|
|
||||||
*/
|
|
||||||
void removed(QmlBookmarkTreeNode *treeNode);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool isTreeNodeEqualsItem(QmlBookmarkTreeNode *treeNode, BookmarkItem *item) const;
|
|
||||||
BookmarkItem *getBookmarkItem(QmlBookmarkTreeNode *treeNode) const;
|
|
||||||
BookmarkItem *getBookmarkItem(QObject *object) const;
|
|
||||||
};
|
|
|
@ -1,147 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlbookmarktreenode.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "bookmarks.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QmlBookmarkTreeNodeData, bookmarkTreeNodeData)
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode::QmlBookmarkTreeNode(BookmarkItem *item)
|
|
||||||
: m_item(item)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
BookmarkItem *QmlBookmarkTreeNode::item()
|
|
||||||
{
|
|
||||||
return m_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode::Type QmlBookmarkTreeNode::type() const
|
|
||||||
{
|
|
||||||
if (!m_item) {
|
|
||||||
return Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (m_item->type()) {
|
|
||||||
case BookmarkItem::Root:
|
|
||||||
return Root;
|
|
||||||
|
|
||||||
case BookmarkItem::Url:
|
|
||||||
return Url;
|
|
||||||
|
|
||||||
case BookmarkItem::Folder:
|
|
||||||
return Folder;
|
|
||||||
|
|
||||||
case BookmarkItem::Separator:
|
|
||||||
return Separator;
|
|
||||||
|
|
||||||
case BookmarkItem::Invalid:
|
|
||||||
default:
|
|
||||||
return Invalid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBookmarkTreeNode::title() const
|
|
||||||
{
|
|
||||||
if (!m_item) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_item->title();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBookmarkTreeNode::url() const
|
|
||||||
{
|
|
||||||
if (!m_item) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_item->urlString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBookmarkTreeNode::description() const
|
|
||||||
{
|
|
||||||
if (!m_item) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_item->description();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBookmarkTreeNode::keyword() const
|
|
||||||
{
|
|
||||||
if (!m_item) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_item->keyword();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlBookmarkTreeNode::visitCount() const
|
|
||||||
{
|
|
||||||
if (!m_item) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_item->visitCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode *QmlBookmarkTreeNode::parent() const
|
|
||||||
{
|
|
||||||
if (!m_item) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bookmarkTreeNodeData->get(m_item->parent());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlBookmarkTreeNode::unmodifiable() const
|
|
||||||
{
|
|
||||||
return !mApp->bookmarks()->canBeModified(m_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlBookmarkTreeNode::children() const
|
|
||||||
{
|
|
||||||
const auto items = m_item->children();
|
|
||||||
QList<QObject*> ret;
|
|
||||||
for (const auto &item : qAsConst(items)) {
|
|
||||||
ret.append(bookmarkTreeNodeData->get(item));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNodeData::QmlBookmarkTreeNodeData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNodeData::~QmlBookmarkTreeNodeData()
|
|
||||||
{
|
|
||||||
qDeleteAll(m_nodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBookmarkTreeNode *QmlBookmarkTreeNodeData::get(BookmarkItem *item)
|
|
||||||
{
|
|
||||||
QmlBookmarkTreeNode *node = m_nodes.value(item);
|
|
||||||
if (!node) {
|
|
||||||
node = new QmlBookmarkTreeNode(item);
|
|
||||||
m_nodes.insert(item, node);
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
|
@ -1,114 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "bookmarkitem.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing the bookmark item to QML
|
|
||||||
*/
|
|
||||||
class QmlBookmarkTreeNode : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief type of bookmark tree node.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(Type type READ type CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief title of bookmark tree node.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString title READ title CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief url of bookmark tree node.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString url READ url CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief description of bookmark tree node.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString description READ description CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief keyword of bookmark tree node.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString keyword READ keyword CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief visit count of bookmark tree node.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int visitCount READ visitCount CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief parent of bookmark tree node.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QmlBookmarkTreeNode* parent READ parent CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if bookmark tree node is unmodifiable.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool unmodifiable READ unmodifiable CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief gets children of bookmark tree node.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QList<QObject*> children READ children CONSTANT)
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief The Type enum
|
|
||||||
*
|
|
||||||
* Contains the information of the type of the bookmark item,
|
|
||||||
*/
|
|
||||||
enum Type {
|
|
||||||
Root = BookmarkItem::Root, //!< Represents the root bookmark item
|
|
||||||
Url = BookmarkItem::Url, //!< Represents the single bookmark item of type url
|
|
||||||
Folder = BookmarkItem::Folder, //!< Represents the bookmark folder
|
|
||||||
Separator = BookmarkItem::Separator, //!< Represents the bookmark seperator
|
|
||||||
Invalid = BookmarkItem::Invalid //!< Represents invalid bookmark item
|
|
||||||
};
|
|
||||||
Q_ENUM(Type)
|
|
||||||
|
|
||||||
explicit QmlBookmarkTreeNode(BookmarkItem *item = nullptr);
|
|
||||||
|
|
||||||
BookmarkItem *item();
|
|
||||||
Type type() const;
|
|
||||||
QString title() const;
|
|
||||||
QString url() const;
|
|
||||||
QString description() const;
|
|
||||||
QString keyword() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
BookmarkItem *m_item;
|
|
||||||
|
|
||||||
int visitCount() const;
|
|
||||||
QmlBookmarkTreeNode *parent() const;
|
|
||||||
bool unmodifiable() const;
|
|
||||||
QList<QObject*> children() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlBookmarkTreeNodeData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit QmlBookmarkTreeNodeData();
|
|
||||||
~QmlBookmarkTreeNodeData();
|
|
||||||
QmlBookmarkTreeNode *get(BookmarkItem *item);
|
|
||||||
private:
|
|
||||||
QHash<BookmarkItem*, QmlBookmarkTreeNode*> m_nodes;
|
|
||||||
};
|
|
|
@ -1,258 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlbrowseraction.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include "navigationbar.h"
|
|
||||||
#include "statusbar.h"
|
|
||||||
#include "pluginproxy.h"
|
|
||||||
#include "qml/api/fileutils/qmlfileutils.h"
|
|
||||||
#include <QQuickWindow>
|
|
||||||
#include <QQmlContext>
|
|
||||||
|
|
||||||
QmlBrowserAction::QmlBrowserAction(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_popup(nullptr)
|
|
||||||
{
|
|
||||||
m_button = new QmlBrowserActionButton();
|
|
||||||
|
|
||||||
connect(this, &QmlBrowserAction::identityChanged, m_button, &QmlBrowserActionButton::setId);
|
|
||||||
connect(this, &QmlBrowserAction::nameChanged, m_button, &QmlBrowserActionButton::setName);
|
|
||||||
connect(this, &QmlBrowserAction::titleChanged, m_button, &QmlBrowserActionButton::setTitle);
|
|
||||||
connect(this, &QmlBrowserAction::toolTipChanged, m_button, &QmlBrowserActionButton::setToolTip);
|
|
||||||
connect(this, &QmlBrowserAction::iconChanged, m_button, &QmlBrowserActionButton::setIcon);
|
|
||||||
connect(this, &QmlBrowserAction::badgeTextChanged, m_button, &QmlBrowserActionButton::setBadgeText);
|
|
||||||
connect(this, &QmlBrowserAction::popupChanged, m_button, &QmlBrowserActionButton::setPopup);
|
|
||||||
|
|
||||||
connect(m_button, &QmlBrowserActionButton::clicked, this, &QmlBrowserAction::clicked);
|
|
||||||
|
|
||||||
connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, &QmlBrowserAction::addButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::componentComplete()
|
|
||||||
{
|
|
||||||
for (BrowserWindow *window : mApp->windows()) {
|
|
||||||
addButton(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBrowserAction::~QmlBrowserAction()
|
|
||||||
{
|
|
||||||
for (BrowserWindow *window : mApp->windows()) {
|
|
||||||
removeButton(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBrowserActionButton *QmlBrowserAction::button() const
|
|
||||||
{
|
|
||||||
return m_button;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBrowserAction::Locations QmlBrowserAction::location() const
|
|
||||||
{
|
|
||||||
return m_locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBrowserAction::identity() const
|
|
||||||
{
|
|
||||||
return m_identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::setIdentity(const QString &identity)
|
|
||||||
{
|
|
||||||
m_identity = identity;
|
|
||||||
emit identityChanged(m_identity);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBrowserAction::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
emit nameChanged(m_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBrowserAction::title() const
|
|
||||||
{
|
|
||||||
return m_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::setTitle(const QString &title)
|
|
||||||
{
|
|
||||||
m_title = title;
|
|
||||||
emit titleChanged(m_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBrowserAction::toolTip() const
|
|
||||||
{
|
|
||||||
return m_toolTip;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::setToolTip(const QString &toolTip)
|
|
||||||
{
|
|
||||||
m_toolTip = toolTip;
|
|
||||||
emit toolTipChanged(m_toolTip);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBrowserAction::icon() const
|
|
||||||
{
|
|
||||||
return m_icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::setIcon(const QString &icon)
|
|
||||||
{
|
|
||||||
m_icon = icon;
|
|
||||||
emit iconChanged(m_icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBrowserAction::badgeText() const
|
|
||||||
{
|
|
||||||
return m_badgeText;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::setBadgeText(const QString &badgeText)
|
|
||||||
{
|
|
||||||
m_badgeText = badgeText;
|
|
||||||
emit badgeTextChanged(m_badgeText);
|
|
||||||
}
|
|
||||||
|
|
||||||
QQmlComponent* QmlBrowserAction::popup() const
|
|
||||||
{
|
|
||||||
return m_popup;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::setPopup(QQmlComponent* popup)
|
|
||||||
{
|
|
||||||
m_popup = popup;
|
|
||||||
emit popupChanged(m_popup);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::setLocation(const Locations &locations)
|
|
||||||
{
|
|
||||||
m_locations = locations;
|
|
||||||
emit locationChanged(m_locations);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::addButton(BrowserWindow *window)
|
|
||||||
{
|
|
||||||
if (location().testFlag(NavigationToolBar)) {
|
|
||||||
window->navigationBar()->addToolButton(button());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location().testFlag(StatusBar)) {
|
|
||||||
window->statusBar()->addButton(button());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserAction::removeButton(BrowserWindow *window)
|
|
||||||
{
|
|
||||||
if (location().testFlag(NavigationToolBar)) {
|
|
||||||
window->navigationBar()->removeToolButton(button());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location().testFlag(StatusBar)) {
|
|
||||||
window->statusBar()->removeButton(button());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlBrowserActionButton::QmlBrowserActionButton(QObject *parent)
|
|
||||||
: AbstractButtonInterface(parent)
|
|
||||||
{
|
|
||||||
connect(this, &AbstractButtonInterface::clicked, this, &QmlBrowserActionButton::positionPopup);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBrowserActionButton::id() const
|
|
||||||
{
|
|
||||||
return m_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserActionButton::setId(const QString &id)
|
|
||||||
{
|
|
||||||
m_id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlBrowserActionButton::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserActionButton::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserActionButton::setTitle(const QString &title)
|
|
||||||
{
|
|
||||||
AbstractButtonInterface::setTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserActionButton::setToolTip(const QString &toolTip)
|
|
||||||
{
|
|
||||||
AbstractButtonInterface::setToolTip(toolTip);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserActionButton::setIcon(const QString &icon)
|
|
||||||
{
|
|
||||||
m_iconUrl = icon;
|
|
||||||
if (QIcon::hasThemeIcon(m_iconUrl)) {
|
|
||||||
AbstractButtonInterface::setIcon(QIcon::fromTheme(m_iconUrl));
|
|
||||||
} else {
|
|
||||||
const QString pluginPath = m_popup->creationContext()->contextProperty("__path__").toString();
|
|
||||||
QmlFileUtils fileUtils(pluginPath);
|
|
||||||
m_iconUrl = fileUtils.resolve(icon);
|
|
||||||
AbstractButtonInterface::setIcon(QIcon(m_iconUrl));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserActionButton::setBadgeText(const QString &badgeText)
|
|
||||||
{
|
|
||||||
AbstractButtonInterface::setBadgeText(badgeText);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserActionButton::setPopup(QQmlComponent *popup)
|
|
||||||
{
|
|
||||||
m_popup = popup;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBrowserActionButton::positionPopup(ClickController *clickController)
|
|
||||||
{
|
|
||||||
if (!m_popup) {
|
|
||||||
qWarning() << "No popup to show";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQuickWindow *quickWindow = dynamic_cast<QQuickWindow*>(m_popup->create(m_popup->creationContext()));
|
|
||||||
if (!quickWindow) {
|
|
||||||
qWarning() << "Cannot create QQuickWindow from popup";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
quickWindow->setFlags(Qt::Popup);
|
|
||||||
quickWindow->setPosition(clickController->callPopupPosition(quickWindow->size()));
|
|
||||||
|
|
||||||
connect(quickWindow, &QQuickWindow::activeChanged, this, [quickWindow, clickController]{
|
|
||||||
if (!quickWindow->isActive()) {
|
|
||||||
quickWindow->destroy();
|
|
||||||
clickController->callPopupClosed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
quickWindow->show();
|
|
||||||
quickWindow->requestActivate();
|
|
||||||
}
|
|
|
@ -1,211 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "abstractbuttoninterface.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include <QQmlComponent>
|
|
||||||
#include <QQmlParserStatus>
|
|
||||||
|
|
||||||
class QmlBrowserActionButton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing BrowserAction API to QML
|
|
||||||
*/
|
|
||||||
class QmlBrowserAction : public QObject, public QQmlParserStatus
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_INTERFACES(QQmlParserStatus)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief identity for the button. This is a required property.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString identity READ identity WRITE setIdentity NOTIFY identityChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief name of the button. This is a required property.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief title of the button.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief tool tip of the button.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY toolTipChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief icon path of button
|
|
||||||
*
|
|
||||||
* The icon path will be search in the following order
|
|
||||||
* - Theme icon: if the icon is found as a theme icon, then it will
|
|
||||||
* be used even if the icon file with same name is present
|
|
||||||
* in the plugin directory
|
|
||||||
* - Falkon resource: for the icons starting with ":", they are searched in
|
|
||||||
* falkon resource file
|
|
||||||
* - Files in plugin directory: All other paths will be resolved relative to
|
|
||||||
* the plugin directory. If the icon path is outside the
|
|
||||||
* plugin directory, then it will be resolved as empty path.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief badge text of the button
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString badgeText READ badgeText WRITE setBadgeText NOTIFY badgeTextChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief the popup shown when the button is clicked. This must be a QML Window.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QQmlComponent* popup READ popup WRITE setPopup NOTIFY popupChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief represents locations where the button is to be added.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(Locations location READ location WRITE setLocation NOTIFY locationChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief The Location enum
|
|
||||||
*/
|
|
||||||
enum Location {
|
|
||||||
NavigationToolBar = 0x1, //!< to add the button in navigation tool bar
|
|
||||||
StatusBar = 0x2 //!< to add the button in status bar
|
|
||||||
};
|
|
||||||
Q_DECLARE_FLAGS(Locations, Location)
|
|
||||||
Q_ENUM(Locations)
|
|
||||||
|
|
||||||
explicit QmlBrowserAction(QObject *parent = nullptr);
|
|
||||||
~QmlBrowserAction();
|
|
||||||
void classBegin() {}
|
|
||||||
void componentComplete();
|
|
||||||
QmlBrowserActionButton *button() const;
|
|
||||||
Locations location() const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when identity property is changed
|
|
||||||
* @param QString representing identity
|
|
||||||
*/
|
|
||||||
void identityChanged(const QString &identity);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when name property is changed
|
|
||||||
* @param QString representing name
|
|
||||||
*/
|
|
||||||
void nameChanged(const QString &name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when title property is changed
|
|
||||||
* @param QString representing title
|
|
||||||
*/
|
|
||||||
void titleChanged(const QString &title);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when the toolTip property is changed
|
|
||||||
* @param QString representing toolTip
|
|
||||||
*/
|
|
||||||
void toolTipChanged(const QString &toolTip);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when the icon property is changed
|
|
||||||
* @param QString representing icon
|
|
||||||
*/
|
|
||||||
void iconChanged(const QString &icon);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when the badgeText property is changed
|
|
||||||
* @param QString representing badgeText
|
|
||||||
*/
|
|
||||||
void badgeTextChanged(const QString &badgeText);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when the popup property is changed
|
|
||||||
* @param QQmComponent representing popup
|
|
||||||
*/
|
|
||||||
void popupChanged(QQmlComponent *popup);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when the locations property is changed
|
|
||||||
* @param locations
|
|
||||||
*/
|
|
||||||
void locationChanged(const Locations &locations);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when the button is clicked
|
|
||||||
*/
|
|
||||||
void clicked();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_identity;
|
|
||||||
QString m_name;
|
|
||||||
QString m_title;
|
|
||||||
QString m_toolTip;
|
|
||||||
QString m_icon;
|
|
||||||
QString m_badgeText;
|
|
||||||
QQmlComponent* m_popup;
|
|
||||||
Locations m_locations;
|
|
||||||
QmlBrowserActionButton *m_button;
|
|
||||||
|
|
||||||
QString identity() const;
|
|
||||||
void setIdentity(const QString &identity);
|
|
||||||
QString name() const;
|
|
||||||
void setName(const QString &name);
|
|
||||||
QString title() const;
|
|
||||||
void setTitle(const QString &title);
|
|
||||||
QString toolTip() const;
|
|
||||||
void setToolTip(const QString &toolTip);
|
|
||||||
QString icon() const;
|
|
||||||
void setIcon(const QString &icon);
|
|
||||||
QString badgeText() const;
|
|
||||||
void setBadgeText(const QString &badgeText);
|
|
||||||
QQmlComponent* popup() const;
|
|
||||||
void setPopup(QQmlComponent* popup);
|
|
||||||
void setLocation(const Locations &locations);
|
|
||||||
|
|
||||||
void addButton(BrowserWindow *window);
|
|
||||||
void removeButton(BrowserWindow *window);
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlBrowserActionButton : public AbstractButtonInterface
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlBrowserActionButton(QObject *parent = nullptr);
|
|
||||||
QString id() const;
|
|
||||||
void setId(const QString &id);
|
|
||||||
QString name() const;
|
|
||||||
void setName(const QString &name);
|
|
||||||
void setTitle(const QString &title);
|
|
||||||
void setToolTip(const QString &toolTip);
|
|
||||||
void setIcon(const QString &icon);
|
|
||||||
void setBadgeText(const QString &badgeText);
|
|
||||||
void setPopup(QQmlComponent *popup);
|
|
||||||
|
|
||||||
void positionPopup(ClickController *clickController);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_id;
|
|
||||||
QString m_name;
|
|
||||||
QString m_iconUrl;
|
|
||||||
QQmlComponent *m_popup = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QmlBrowserAction::Locations)
|
|
|
@ -1,103 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlcookie.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlCookie::QmlCookie(QNetworkCookie *cookie, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_cookie(cookie)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlCookie::domain() const
|
|
||||||
{
|
|
||||||
if (!m_cookie) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return m_cookie->domain();
|
|
||||||
}
|
|
||||||
|
|
||||||
QDateTime QmlCookie::expirationDate() const
|
|
||||||
{
|
|
||||||
if (!m_cookie) {
|
|
||||||
return QDateTime();
|
|
||||||
}
|
|
||||||
return m_cookie->expirationDate();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlCookie::name() const
|
|
||||||
{
|
|
||||||
if (!m_cookie) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return QString(m_cookie->name());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlCookie::path() const
|
|
||||||
{
|
|
||||||
if (!m_cookie) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return m_cookie->path();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlCookie::secure() const
|
|
||||||
{
|
|
||||||
if (!m_cookie) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return m_cookie->isSecure();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlCookie::session() const
|
|
||||||
{
|
|
||||||
if (!m_cookie) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return m_cookie->isSessionCookie();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlCookie::value() const
|
|
||||||
{
|
|
||||||
if (!m_cookie) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return QString(m_cookie->value());
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlCookieData::QmlCookieData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlCookieData::~QmlCookieData()
|
|
||||||
{
|
|
||||||
qDeleteAll(m_cookies);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlCookie *QmlCookieData::get(QNetworkCookie *cookie)
|
|
||||||
{
|
|
||||||
QmlCookie *qmlCookie = m_cookies.value(cookie);
|
|
||||||
if (!qmlCookie) {
|
|
||||||
QNetworkCookie *netCookie = new QNetworkCookie(*cookie);
|
|
||||||
qmlCookie = new QmlCookie(netCookie);
|
|
||||||
m_cookies.insert(netCookie, qmlCookie);
|
|
||||||
}
|
|
||||||
return qmlCookie;
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QDateTime>
|
|
||||||
#include <QNetworkCookie>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing QNetworkCookie to QML
|
|
||||||
*/
|
|
||||||
class QmlCookie : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief domain of the cookie
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString domain READ domain CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief expiration date of the cookie
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QDateTime expirationDate READ expirationDate CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief name of the cookie
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString name READ name CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief path of the cookie
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString path READ path CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if cookie is secure
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool secure READ secure CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if cookie is a session cookie
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool session READ session CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief value of the cookie
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString value READ value CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlCookie(QNetworkCookie *cookie = nullptr, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QNetworkCookie *m_cookie;
|
|
||||||
|
|
||||||
QString domain() const;
|
|
||||||
QDateTime expirationDate() const;
|
|
||||||
QString name() const;
|
|
||||||
QString path() const;
|
|
||||||
bool secure() const;
|
|
||||||
bool session() const;
|
|
||||||
QString value() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlCookieData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit QmlCookieData();
|
|
||||||
~QmlCookieData();
|
|
||||||
QmlCookie *get(QNetworkCookie *cookie);
|
|
||||||
private:
|
|
||||||
QHash<QNetworkCookie*, QmlCookie*> m_cookies;
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QmlCookie*)
|
|
|
@ -1,121 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlcookies.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "cookiejar.h"
|
|
||||||
#include "qwebengineprofile.h"
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QmlCookieData, cookieData)
|
|
||||||
|
|
||||||
QmlCookies::QmlCookies(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
connect(mApp->cookieJar(), &CookieJar::cookieAdded, this, [this](QNetworkCookie network_cookie){
|
|
||||||
QmlCookie *cookie = cookieData->get(&network_cookie);
|
|
||||||
QVariantMap map;
|
|
||||||
map.insert(QSL("cookie"), QVariant::fromValue(cookie));
|
|
||||||
map.insert(QSL("removed"), false);
|
|
||||||
emit changed(map);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, [this](QNetworkCookie network_cookie){
|
|
||||||
QmlCookie *cookie = cookieData->get(&network_cookie);
|
|
||||||
QVariantMap map;
|
|
||||||
map.insert(QSL("cookie"), QVariant::fromValue(cookie));
|
|
||||||
map.insert(QSL("removed"), true);
|
|
||||||
emit changed(map);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkCookie *QmlCookies::getNetworkCookie(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("name")) || !map.contains(QSL("url"))) {
|
|
||||||
qWarning() << "Error:" << "Wrong arguments passed to" << __FUNCTION__;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
const QString name = map.value(QSL("name")).toString();
|
|
||||||
const QString url = map.value(QSL("url")).toString();
|
|
||||||
QVector<QNetworkCookie> cookies = mApp->cookieJar()->getAllCookies();
|
|
||||||
for (const QNetworkCookie &cookie : qAsConst(cookies)) {
|
|
||||||
if (cookie.name() == name && cookie.domain() == url) {
|
|
||||||
return new QNetworkCookie(cookie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlCookie *QmlCookies::get(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
QNetworkCookie *netCookie = getNetworkCookie(map);
|
|
||||||
if (!netCookie) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return cookieData->get(netCookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlCookies::getAll(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
QList<QObject*> qmlCookies;
|
|
||||||
const QString name = map.value(QSL("name")).toString();
|
|
||||||
const QString url = map.value(QSL("url")).toString();
|
|
||||||
const QString path = map.value(QSL("path")).toString();
|
|
||||||
const bool secure = map.value(QSL("secure")).toBool();
|
|
||||||
const bool session = map.value(QSL("session")).toBool();
|
|
||||||
QVector<QNetworkCookie> cookies = mApp->cookieJar()->getAllCookies();
|
|
||||||
for (QNetworkCookie cookie : qAsConst(cookies)) {
|
|
||||||
if ((!map.contains(QSL("name")) || cookie.name() == name)
|
|
||||||
&& (!map.contains(QSL("url")) || cookie.domain() == url)
|
|
||||||
&& (!map.contains(QSL("path")) || cookie.path() == path)
|
|
||||||
&& (!map.contains(QSL("secure")) || cookie.isSecure() == secure)
|
|
||||||
&& (!map.contains(QSL("session")) || cookie.isSessionCookie() == session)) {
|
|
||||||
QmlCookie *qmlCookie = cookieData->get(&cookie);
|
|
||||||
qmlCookies.append(qmlCookie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return qmlCookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlCookies::set(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
const QString name = map.value(QSL("name")).toString();
|
|
||||||
const QString url = map.value(QSL("url")).toString();
|
|
||||||
const QString path = map.value(QSL("path")).toString();
|
|
||||||
const bool secure = map.value(QSL("secure")).toBool();
|
|
||||||
const QDateTime expirationDate = QDateTime::fromMSecsSinceEpoch(map.value(QSL("expirationDate")).toDouble());
|
|
||||||
const bool httpOnly = map.value(QSL("httpOnly")).toBool();
|
|
||||||
const QString value = map.value(QSL("value")).toString();
|
|
||||||
QNetworkCookie cookie;
|
|
||||||
cookie.setName(name.toUtf8());
|
|
||||||
cookie.setDomain(url);
|
|
||||||
cookie.setPath(path);
|
|
||||||
cookie.setSecure(secure);
|
|
||||||
cookie.setExpirationDate(expirationDate);
|
|
||||||
cookie.setHttpOnly(httpOnly);
|
|
||||||
cookie.setValue(value.toUtf8());
|
|
||||||
mApp->webProfile()->cookieStore()->setCookie(cookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlCookies::remove(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
QNetworkCookie *netCookie = getNetworkCookie(map);
|
|
||||||
if (!netCookie) {
|
|
||||||
qWarning() << "Error:" << "Cannot find cookie";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mApp->webProfile()->cookieStore()->deleteCookie(*netCookie);
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlcookie.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing Cookies API to QML
|
|
||||||
*/
|
|
||||||
class QmlCookies : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlCookies(QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Get a cookie
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - name:
|
|
||||||
* String representing the name of the cookie
|
|
||||||
* - url:
|
|
||||||
* String representing the url of the cookie
|
|
||||||
* @return Cookie of type [QmlCookie](@ref QmlCookie)
|
|
||||||
* if such cookie exists, else null
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlCookie *get(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Get all cookies matching a criteria
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - name:
|
|
||||||
* String representing the name of the cookie
|
|
||||||
* - url:
|
|
||||||
* String representing the url of the cookie
|
|
||||||
* - path:
|
|
||||||
* String representing the path of the cookie
|
|
||||||
* - secure:
|
|
||||||
* Bool representing if the cookie is secure
|
|
||||||
* - session:
|
|
||||||
* Bool representing if the cookie is a session cookie
|
|
||||||
* @return List containing cookies, each of type [QmlCookie](@ref QmlCookie)
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject*> getAll(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Set a cookie
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - name:
|
|
||||||
* String representing the name of the cookie
|
|
||||||
* - url:
|
|
||||||
* String representing the name of the cookie
|
|
||||||
* - path:
|
|
||||||
* String representing the path of the cookie
|
|
||||||
* - secure:
|
|
||||||
* Bool representing if the cookie is secure
|
|
||||||
* - expirationDate:
|
|
||||||
* A JavaScript Date object, representing the expiration date of the cookie
|
|
||||||
* - httpOnly:
|
|
||||||
* Bool representing if the cookie is httpOnly
|
|
||||||
* - value:
|
|
||||||
* String representing the value of the cookie
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void set(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Remove a cookie
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - name:
|
|
||||||
* String representing the name of the cookie
|
|
||||||
* - url:
|
|
||||||
* String representing the url of the cookie
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void remove(const QVariantMap &map);
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when a cookie is added or removed
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - cookie:
|
|
||||||
* Object of type [QmlCookie](@ref QmlCookie), which is added or removed
|
|
||||||
* - removed:
|
|
||||||
* Bool representing if the cookie is removed
|
|
||||||
*/
|
|
||||||
void changed(const QVariantMap &map);
|
|
||||||
private:
|
|
||||||
QNetworkCookie *getNetworkCookie(const QVariantMap &map);
|
|
||||||
};
|
|
|
@ -1,95 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlkeyevent.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlKeyEvent::QmlKeyEvent(QKeyEvent *keyEvent, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_keyEvent(keyEvent)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlKeyEvent::count() const
|
|
||||||
{
|
|
||||||
if (!m_keyEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_keyEvent->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlKeyEvent::isAutoRepeat() const
|
|
||||||
{
|
|
||||||
if (!m_keyEvent) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return m_keyEvent->isAutoRepeat();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlKeyEvent::key() const
|
|
||||||
{
|
|
||||||
if (!m_keyEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_keyEvent->key();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlKeyEvent::modifiers() const
|
|
||||||
{
|
|
||||||
if (!m_keyEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return (int)m_keyEvent->modifiers();
|
|
||||||
}
|
|
||||||
|
|
||||||
quint32 QmlKeyEvent::nativeModifiers() const
|
|
||||||
{
|
|
||||||
if (!m_keyEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_keyEvent->nativeModifiers();
|
|
||||||
}
|
|
||||||
|
|
||||||
quint32 QmlKeyEvent::nativeScanCode() const
|
|
||||||
{
|
|
||||||
if (!m_keyEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_keyEvent->nativeScanCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
quint32 QmlKeyEvent::nativeVirtualKey() const
|
|
||||||
{
|
|
||||||
if (!m_keyEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_keyEvent->nativeVirtualKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlKeyEvent::text() const
|
|
||||||
{
|
|
||||||
if (!m_keyEvent) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return m_keyEvent->text();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlKeyEvent::makeNull()
|
|
||||||
{
|
|
||||||
m_keyEvent = nullptr;
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QKeyEvent>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing KeyEvent to QML
|
|
||||||
*/
|
|
||||||
class QmlKeyEvent : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* @brief number of keys involved in this event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int count READ count CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief checks if the event comes from an auto-repeating key
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool autoRepeat READ isAutoRepeat CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief key code which is pressed/released
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int key READ key CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief modifiers associated with the event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int modifiers READ modifiers CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief native modifiers of the event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(quint32 nativeModifiers READ nativeModifiers CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief native scan code of the event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(quint32 nativeScanCode READ nativeScanCode CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief native virtual key, or key sum of the event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(quint32 nativeVirtualKey READ nativeVirtualKey CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Returns the Unicode text that this key generated
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString text READ text CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlKeyEvent(QKeyEvent *keyEvent = nullptr, QObject *parent = nullptr);
|
|
||||||
int count() const;
|
|
||||||
bool isAutoRepeat() const;
|
|
||||||
int key() const;
|
|
||||||
int modifiers() const;
|
|
||||||
quint32 nativeModifiers() const;
|
|
||||||
quint32 nativeScanCode() const;
|
|
||||||
quint32 nativeVirtualKey() const;
|
|
||||||
QString text() const;
|
|
||||||
|
|
||||||
void makeNull();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QKeyEvent *m_keyEvent;
|
|
||||||
};
|
|
|
@ -1,127 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlmouseevent.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlMouseEvent::QmlMouseEvent(QMouseEvent *mouseEvent, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_mouseEvent(mouseEvent)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlMouseEvent::button() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return (int)m_mouseEvent->button();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlMouseEvent::buttons() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return (int)m_mouseEvent->buttons();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint QmlMouseEvent::globalPos() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return QPoint(-1, -1);
|
|
||||||
}
|
|
||||||
return m_mouseEvent->globalPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlMouseEvent::globalX() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_mouseEvent->globalX();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlMouseEvent::globalY() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_mouseEvent->globalY();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF QmlMouseEvent::localPos() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return QPointF(-1, -1);
|
|
||||||
}
|
|
||||||
return m_mouseEvent->localPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint QmlMouseEvent::pos() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return QPoint(-1, -1);
|
|
||||||
}
|
|
||||||
return m_mouseEvent->pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF QmlMouseEvent::screenPos() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return QPointF(-1, -1);
|
|
||||||
}
|
|
||||||
return m_mouseEvent->screenPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlMouseEvent::source() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return (int)m_mouseEvent->source();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF QmlMouseEvent::windowPos() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return QPointF(-1, -1);
|
|
||||||
}
|
|
||||||
return m_mouseEvent->windowPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlMouseEvent::x() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_mouseEvent->x();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlMouseEvent::y() const
|
|
||||||
{
|
|
||||||
if (!m_mouseEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_mouseEvent->y();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlMouseEvent::makeNull()
|
|
||||||
{
|
|
||||||
m_mouseEvent = nullptr;
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QMouseEvent>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing MouseEvent to QML
|
|
||||||
*/
|
|
||||||
class QmlMouseEvent : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* @brief button associated with the event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int button READ button CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief button state associated with the event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int buttons READ buttons CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief global position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPoint globalPos READ globalPos CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief global x position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int globalX READ globalX CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief global y position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int globalY READ globalY CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief local position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPointF localPos READ localPos CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPoint pos READ pos CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief screen position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPointF screenPos READ screenPos CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief source of the event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int source READ source CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief window position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPointF windowPos READ windowPos CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief x position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int x READ x CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief y position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int y READ y CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlMouseEvent(QMouseEvent *mouseEvent = nullptr, QObject *parent = nullptr);
|
|
||||||
int button() const;
|
|
||||||
int buttons() const;
|
|
||||||
QPoint globalPos() const;
|
|
||||||
int globalX() const;
|
|
||||||
int globalY() const;
|
|
||||||
QPointF localPos() const;
|
|
||||||
QPoint pos() const;
|
|
||||||
QPointF screenPos() const;
|
|
||||||
int source() const;
|
|
||||||
QPointF windowPos() const;
|
|
||||||
int x() const;
|
|
||||||
int y() const;
|
|
||||||
|
|
||||||
void makeNull();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QMouseEvent *m_mouseEvent;
|
|
||||||
};
|
|
|
@ -1,42 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <qzcommon.h>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing Qz ObjectName to QML
|
|
||||||
*/
|
|
||||||
class QmlQzObjects : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief The ObjectName enum
|
|
||||||
*/
|
|
||||||
enum ObjectName {
|
|
||||||
ON_WebView = Qz::ON_WebView, //!< Represents object is webview
|
|
||||||
ON_TabBar = Qz::ON_TabBar, //!< Represents object is tabbar
|
|
||||||
ON_TabWidget = Qz::ON_TabWidget, //!< Represents object is tabwidget
|
|
||||||
ON_BrowserWindow = Qz::ON_BrowserWindow //!< Represents object is browser window
|
|
||||||
};
|
|
||||||
Q_ENUM(ObjectName)
|
|
||||||
|
|
||||||
explicit QmlQzObjects(QObject *parent = nullptr);
|
|
||||||
};
|
|
|
@ -1,143 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlwheelevent.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlWheelEvent::QmlWheelEvent(QWheelEvent *wheelEvent, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_wheelEvent(wheelEvent)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint QmlWheelEvent::angleDelta() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return QPoint(-1, -1);
|
|
||||||
}
|
|
||||||
return m_wheelEvent->angleDelta();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWheelEvent::buttons() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return (int)m_wheelEvent->buttons();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint QmlWheelEvent::globalPos() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return QPoint(-1, -1);
|
|
||||||
}
|
|
||||||
return m_wheelEvent->globalPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF QmlWheelEvent::globalPosF() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return QPointF(-1, -1);
|
|
||||||
}
|
|
||||||
return m_wheelEvent->globalPosF();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWheelEvent::globalX() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_wheelEvent->globalX();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWheelEvent::globalY() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_wheelEvent->globalY();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWheelEvent::inverted() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return m_wheelEvent->inverted();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWheelEvent::phase() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return (int)m_wheelEvent->phase();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint QmlWheelEvent::pixelDelta() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return QPoint(-1, -1);
|
|
||||||
}
|
|
||||||
return m_wheelEvent->pixelDelta();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint QmlWheelEvent::pos() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return QPoint(-1, -1);
|
|
||||||
}
|
|
||||||
return m_wheelEvent->pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF QmlWheelEvent::posF() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return QPointF(-1, -1);
|
|
||||||
}
|
|
||||||
return m_wheelEvent->posF();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWheelEvent::source() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return (int)m_wheelEvent->source();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWheelEvent::x() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_wheelEvent->x();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWheelEvent::y() const
|
|
||||||
{
|
|
||||||
if (!m_wheelEvent) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return m_wheelEvent->y();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlWheelEvent::makeNull()
|
|
||||||
{
|
|
||||||
m_wheelEvent = nullptr;
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QWheelEvent>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing WheelEvent to QML
|
|
||||||
*/
|
|
||||||
class QmlWheelEvent : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* @brief the distance that the wheel is rotated, in eighths of a degree
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief mouse state at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int buttons READ buttons CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief global position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPoint globalPos READ globalPos CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief global position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPointF globalPosF READ globalPosF CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief global x position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int globalX READ globalX CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief global y position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int globalY READ globalY CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief checks if the delta values delivered with the event are inverted
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool inverted READ inverted CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief scrolling phase of this wheel event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int phase READ phase CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief scrolling distance in pixels on screen
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPoint pixelDelta READ pixelDelta CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPoint pos READ pos CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPointF posF READ posF CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief source of the event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int source READ source CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief x position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int x READ x CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief y position of mouse cursor at the time of event
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int y READ y CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlWheelEvent(QWheelEvent *wheelEvent = nullptr, QObject *parent = nullptr);
|
|
||||||
QPoint angleDelta() const;
|
|
||||||
int buttons() const;
|
|
||||||
QPoint globalPos() const;
|
|
||||||
QPointF globalPosF() const;
|
|
||||||
int globalX() const;
|
|
||||||
int globalY() const;
|
|
||||||
bool inverted() const;
|
|
||||||
int phase() const;
|
|
||||||
QPoint pixelDelta() const;
|
|
||||||
QPoint pos() const;
|
|
||||||
QPointF posF() const;
|
|
||||||
int source() const;
|
|
||||||
int x() const;
|
|
||||||
int y() const;
|
|
||||||
|
|
||||||
void makeNull();
|
|
||||||
private:
|
|
||||||
QWheelEvent *m_wheelEvent;
|
|
||||||
};
|
|
|
@ -1,59 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlextensionscheme.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "networkmanager.h"
|
|
||||||
#include <QWebEngineUrlRequestJob>
|
|
||||||
#include <QQmlEngine>
|
|
||||||
#include <QMap>
|
|
||||||
|
|
||||||
QmlExtensionScheme::QmlExtensionScheme(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
m_schemeHandler = new QmlExtensionSchemeHandler;
|
|
||||||
connect(m_schemeHandler, &QmlExtensionSchemeHandler::_requestStarted, this, [this](QWebEngineUrlRequestJob *job) {
|
|
||||||
QmlWebEngineUrlRequestJob *request = new QmlWebEngineUrlRequestJob(job);
|
|
||||||
emit requestStarted(request);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlExtensionScheme::~QmlExtensionScheme()
|
|
||||||
{
|
|
||||||
mApp->networkManager()->unregisterExtensionSchemeHandler(m_schemeHandler);
|
|
||||||
m_schemeHandler->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlExtensionScheme::componentComplete()
|
|
||||||
{
|
|
||||||
mApp->networkManager()->registerExtensionSchemeHandler(m_name, m_schemeHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlExtensionScheme::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlExtensionScheme::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlExtensionSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
|
|
||||||
{
|
|
||||||
emit _requestStarted(job);
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "schemehandlers/extensionschemehandler.h"
|
|
||||||
#include "qmlwebengineurlrequestjob.h"
|
|
||||||
#include <QQmlParserStatus>
|
|
||||||
#include <QJSValue>
|
|
||||||
|
|
||||||
class QmlExtensionSchemeHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The QmlExtensionScheme class, exposed to QML as ExtensionScheme
|
|
||||||
*/
|
|
||||||
class QmlExtensionScheme : public QObject, public QQmlParserStatus
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* @brief extension scheme handle name
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
|
||||||
public:
|
|
||||||
explicit QmlExtensionScheme(QObject *parent = nullptr);
|
|
||||||
~QmlExtensionScheme();
|
|
||||||
void classBegin() {}
|
|
||||||
void componentComplete();
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when the request to the scheme handle is started
|
|
||||||
* @param request of the type [QmlWebEngineUrlRequestJob](@ref QmlWebEngineUrlRequestJob)
|
|
||||||
*/
|
|
||||||
void requestStarted(QmlWebEngineUrlRequestJob *request);
|
|
||||||
private:
|
|
||||||
QString m_name;
|
|
||||||
QmlExtensionSchemeHandler *m_schemeHandler;
|
|
||||||
|
|
||||||
QString name() const;
|
|
||||||
void setName(const QString &name);
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlExtensionSchemeHandler : public ExtensionSchemeHandler
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
void requestStarted(QWebEngineUrlRequestJob *job);
|
|
||||||
Q_SIGNALS:
|
|
||||||
void _requestStarted(QWebEngineUrlRequestJob *job);
|
|
||||||
};
|
|
|
@ -1,85 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlwebengineurlrequestjob.h"
|
|
||||||
#include <QBuffer>
|
|
||||||
#include <QVariantMap>
|
|
||||||
#include <qztools.h>
|
|
||||||
|
|
||||||
QmlWebEngineUrlRequestJob::QmlWebEngineUrlRequestJob(QWebEngineUrlRequestJob *job, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_job(job)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlWebEngineUrlRequestJob::fail(QmlWebEngineUrlRequestJob::Error error)
|
|
||||||
{
|
|
||||||
if (!m_job) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_job->fail(QWebEngineUrlRequestJob::Error(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlWebEngineUrlRequestJob::redirect(const QString &urlString)
|
|
||||||
{
|
|
||||||
if (!m_job) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return m_job->redirect(QUrl::fromEncoded(urlString.toUtf8()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlWebEngineUrlRequestJob::reply(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!m_job) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!map.contains(QSL("content")) || !map.contains(QSL("contentType"))) {
|
|
||||||
qWarning() << "Unable to call" << __FUNCTION__ << ": invalid parameters";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QByteArray content = map.value(QSL("content")).toString().toUtf8();
|
|
||||||
QByteArray contentType = map.value(QSL("contentType")).toString().toUtf8();
|
|
||||||
QBuffer *buffer = new QBuffer();
|
|
||||||
buffer->open(QIODevice::ReadWrite);
|
|
||||||
buffer->write(content);
|
|
||||||
buffer->seek(0);
|
|
||||||
m_job->reply(contentType, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebEngineUrlRequestJob::initiator() const
|
|
||||||
{
|
|
||||||
if (!m_job) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return QString::fromUtf8(m_job->initiator().toEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebEngineUrlRequestJob::requestUrl() const
|
|
||||||
{
|
|
||||||
if (!m_job) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return QString::fromUtf8(m_job->requestUrl().toEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebEngineUrlRequestJob::requestMethod() const
|
|
||||||
{
|
|
||||||
if (!m_job) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return QString::fromUtf8(m_job->requestMethod());
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QWebEngineUrlRequestJob>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The QmlWebEngineUrlRequestJob class
|
|
||||||
*/
|
|
||||||
class QmlWebEngineUrlRequestJob : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* @brief initiator of the QWebEngineUrlRequestJob
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString initiator READ initiator CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief request url of the QWebEngineUrlRequestJob
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString requestUrl READ requestUrl CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief request method of the QWebEngineUrlRequestJob
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString requestMethod READ requestMethod CONSTANT)
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief The Error enum, exposes QWebEngineUrlRequestJob::Error to QML
|
|
||||||
*/
|
|
||||||
enum Error {
|
|
||||||
NoError = QWebEngineUrlRequestJob::NoError, //! No error
|
|
||||||
UrlNotFound = QWebEngineUrlRequestJob::UrlNotFound, //! Url not found error
|
|
||||||
UrlInvaild = QWebEngineUrlRequestJob::UrlInvalid, //! Url invalid error
|
|
||||||
RequestAborted = QWebEngineUrlRequestJob::RequestAborted, //! Request aborted
|
|
||||||
RequestDenied = QWebEngineUrlRequestJob::RequestDenied, //! Request denied
|
|
||||||
RequestFailed = QWebEngineUrlRequestJob::RequestFailed //! Request failed
|
|
||||||
};
|
|
||||||
Q_ENUM(Error)
|
|
||||||
explicit QmlWebEngineUrlRequestJob(QWebEngineUrlRequestJob *job = nullptr, QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Fails the request with the error
|
|
||||||
* @param error
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void fail(Error error);
|
|
||||||
/**
|
|
||||||
* @brief Redirects the request to the url
|
|
||||||
* @param urlString, represents the url to which the request is to be redirected
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void redirect(const QString &urlString);
|
|
||||||
/**
|
|
||||||
* @brief Replies to the request
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - content: String representing the reply data
|
|
||||||
* - contentType: String representing the contentType of reply data
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void reply(const QVariantMap &map);
|
|
||||||
private:
|
|
||||||
QWebEngineUrlRequestJob *m_job;
|
|
||||||
|
|
||||||
QString initiator() const;
|
|
||||||
QString requestUrl() const;
|
|
||||||
QString requestMethod() const;
|
|
||||||
};
|
|
|
@ -1,62 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlfileutils.h"
|
|
||||||
#include "datapaths.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include <QFile>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
QmlFileUtils::QmlFileUtils(QString filePath, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
// Get the plugin root directory - of the form
|
|
||||||
// some-path-in-plugin-paths/qml/plugin-directory
|
|
||||||
const QStringList dirs = DataPaths::allPaths(DataPaths::Plugins);
|
|
||||||
for (QString path : qAsConst(dirs)) {
|
|
||||||
path.append(QSL("/qml/"));
|
|
||||||
if (filePath.contains(path)) {
|
|
||||||
m_path = path;
|
|
||||||
QString pluginDirName = filePath.remove(path).split(QSL("/"))[0];
|
|
||||||
m_path.append(pluginDirName);
|
|
||||||
m_path.append(QSL("/"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlFileUtils::resolve(const QString &filePath)
|
|
||||||
{
|
|
||||||
const QUrl resolvedUrl = QUrl::fromLocalFile(m_path).resolved(QUrl::fromEncoded(filePath.toUtf8()));
|
|
||||||
const QString resolvedPath = resolvedUrl.toLocalFile();
|
|
||||||
if (resolvedPath.contains(m_path)) {
|
|
||||||
return resolvedPath;
|
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray QmlFileUtils::readAllFileContents(const QString &fileName)
|
|
||||||
{
|
|
||||||
const QString path = resolve(fileName);
|
|
||||||
return QzTools::readAllFileByteContents(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlFileUtils::exists(const QString &filePath)
|
|
||||||
{
|
|
||||||
const QString path = resolve(filePath);
|
|
||||||
return QFile(path).exists();
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The QmlFileUtils class, exposed to QML as FileUtils
|
|
||||||
*/
|
|
||||||
class QmlFileUtils : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlFileUtils(QString filePath, QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Get the path of the file within the plugin directory.
|
|
||||||
* If the filePath provided is resolved to be outside the plugin
|
|
||||||
* directory then empty string is returned
|
|
||||||
* @param file path within the plugin directory
|
|
||||||
* @return resolved path
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QString resolve(const QString &filePath);
|
|
||||||
/**
|
|
||||||
* @brief Read the contents of the file within the plugin directory
|
|
||||||
* @param file path within the plugin directory
|
|
||||||
* @return contents of the file
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QByteArray readAllFileContents(const QString &fileName);
|
|
||||||
/**
|
|
||||||
* @brief Checks if the file exists within the plugin directory
|
|
||||||
* @param file path within the plugin directory
|
|
||||||
* @return true if file exists, otherwise false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool exists(const QString &filePath);
|
|
||||||
private:
|
|
||||||
QString m_path;
|
|
||||||
};
|
|
|
@ -1,89 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlhistory.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "history.h"
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QmlHistoryItemData, historyItemData)
|
|
||||||
|
|
||||||
QmlHistory::QmlHistory(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
connect(mApp->history(), &History::historyEntryAdded, this, [this](HistoryEntry entry){
|
|
||||||
QmlHistoryItem *historyItem = historyItemData->get(&entry);
|
|
||||||
emit visited(historyItem);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(mApp->history(), &History::historyEntryDeleted, this, [this](HistoryEntry entry){
|
|
||||||
QmlHistoryItem *historyItem = historyItemData->get(&entry);
|
|
||||||
emit visitRemoved(historyItem);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlHistory::search(const QString &text)
|
|
||||||
{
|
|
||||||
QList<QObject*> list;
|
|
||||||
QList<HistoryEntry*> result = mApp->history()->searchHistoryEntry(text);
|
|
||||||
|
|
||||||
for (const auto entry : qAsConst(result)) {
|
|
||||||
auto item = historyItemData->get(entry);
|
|
||||||
list.append(item);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlHistory::getVisits(const QString &url)
|
|
||||||
{
|
|
||||||
HistoryEntry *entry = mApp->history()->getHistoryEntry(url);
|
|
||||||
return entry->count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistory::addUrl(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("title")) || !map.contains(QSL("url"))) {
|
|
||||||
qWarning() << "Error:" << "wrong arguments passed to" << __FUNCTION__;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString title = map.value(QSL("title")).toString();
|
|
||||||
const QString url = map.value(QSL("url")).toString();
|
|
||||||
|
|
||||||
title = title.isEmpty() ? url : title;
|
|
||||||
|
|
||||||
mApp->history()->addHistoryEntry(QUrl::fromEncoded(url.toUtf8()), title);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistory::deleteUrl(const QString &url)
|
|
||||||
{
|
|
||||||
mApp->history()->deleteHistoryEntry(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistory::deleteRange(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("startTime")) || !map.contains(QSL("endTime"))) {
|
|
||||||
qWarning() << "Error:" << "wrong arguments passed to" << __FUNCTION__;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const double startTime = map.value(QSL("startTime")).toDouble();
|
|
||||||
const double endTime = map.value(QSL("endTime")).toDouble();
|
|
||||||
mApp->history()->deleteRange(startTime, endTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistory::deleteAll()
|
|
||||||
{
|
|
||||||
mApp->history()->clearHistory();
|
|
||||||
}
|
|
|
@ -1,85 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlhistoryitem.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing the History API to QML
|
|
||||||
*/
|
|
||||||
class QmlHistory : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlHistory(QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Searches History Entries against a search query
|
|
||||||
* @param String representing the search query
|
|
||||||
* @return List of History Entries, each of type [QmlHistoryItem](@ref QmlHistoryItem),
|
|
||||||
* matching the search query
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject*> search(const QString &text);
|
|
||||||
/**
|
|
||||||
* @brief Get the visit count of a url
|
|
||||||
* @param String representing the url
|
|
||||||
* @return Integer representing the visit count of the given url
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE int getVisits(const QString &url);
|
|
||||||
/**
|
|
||||||
* @brief Add url to the history
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - title:
|
|
||||||
* String representing the title of the hisotry entry
|
|
||||||
* - url:
|
|
||||||
* String representing the url of the history entry
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void addUrl(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Deletes a url from the history
|
|
||||||
* @param String representing the url of the history entry
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void deleteUrl(const QString &url);
|
|
||||||
/**
|
|
||||||
* @brief Deletes history entries within the given range
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - startTime:
|
|
||||||
* A JavaScript Date object representing the start time
|
|
||||||
* - endTime:
|
|
||||||
* A JavaScript Date object representing the end time
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void deleteRange(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Clears all the history
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void deleteAll();
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when a HistoryEntry is added
|
|
||||||
* @param Object of type [QmlHistoryItem](@ref QmlHistoryItem), representing
|
|
||||||
* the added History Entry
|
|
||||||
*/
|
|
||||||
void visited(QmlHistoryItem *historyItem);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when a HistoryEntry is removed
|
|
||||||
* @param Object of type [QmlHistoryItem](@ref QmlHistoryItem), representing
|
|
||||||
* the removed History Entry
|
|
||||||
*/
|
|
||||||
void visitRemoved(QmlHistoryItem *historyItem);
|
|
||||||
};
|
|
|
@ -1,85 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlhistoryitem.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlHistoryItem::QmlHistoryItem(HistoryEntry *entry, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_entry(entry)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlHistoryItem::id() const
|
|
||||||
{
|
|
||||||
if (!m_entry) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return m_entry->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlHistoryItem::url() const
|
|
||||||
{
|
|
||||||
if (!m_entry) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return QString::fromUtf8(m_entry->url.toEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlHistoryItem::title() const
|
|
||||||
{
|
|
||||||
if (!m_entry) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return m_entry->title;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlHistoryItem::visitCount() const
|
|
||||||
{
|
|
||||||
if (!m_entry) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return m_entry->count;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDateTime QmlHistoryItem::lastVisitTime() const
|
|
||||||
{
|
|
||||||
if (!m_entry) {
|
|
||||||
return QDateTime().currentDateTime().addMonths(1);
|
|
||||||
}
|
|
||||||
return m_entry->date;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlHistoryItemData::QmlHistoryItemData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlHistoryItemData::~QmlHistoryItemData()
|
|
||||||
{
|
|
||||||
qDeleteAll(m_items);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlHistoryItem *QmlHistoryItemData::get(HistoryEntry *entry)
|
|
||||||
{
|
|
||||||
QmlHistoryItem *item = m_items.value(entry);
|
|
||||||
if (!item) {
|
|
||||||
item = new QmlHistoryItem(entry);
|
|
||||||
m_items.insert(entry, item);
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "history.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing HistoryEntry to QML
|
|
||||||
*/
|
|
||||||
class QmlHistoryItem : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief id of the history item
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int id READ id CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief url of the history item
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString url READ url CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief title of the history item
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString title READ title CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief visit count of the history item
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int visitCount READ visitCount CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief last visit time of the history item
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QDateTime lastVisitTime READ lastVisitTime CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlHistoryItem(HistoryEntry *entry = nullptr, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
private:
|
|
||||||
HistoryEntry *m_entry;
|
|
||||||
|
|
||||||
int id() const;
|
|
||||||
QString url() const;
|
|
||||||
QString title() const;
|
|
||||||
int visitCount() const;
|
|
||||||
QDateTime lastVisitTime() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlHistoryItemData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit QmlHistoryItemData();
|
|
||||||
~QmlHistoryItemData();
|
|
||||||
QmlHistoryItem *get(HistoryEntry *entry);
|
|
||||||
private:
|
|
||||||
QHash<HistoryEntry*, QmlHistoryItem*> m_items;
|
|
||||||
};
|
|
|
@ -1,46 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmli18n.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include <QStandardPaths>
|
|
||||||
|
|
||||||
QmlI18n::QmlI18n(const QString &pluginName, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
m_pluginName = pluginName;
|
|
||||||
setlocale(LC_MESSAGES, "");
|
|
||||||
initTranslations();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlI18n::initTranslations()
|
|
||||||
{
|
|
||||||
QString domain = QString("falkon_%1").arg(m_pluginName);
|
|
||||||
QString localeDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "locale", QStandardPaths::LocateDirectory);
|
|
||||||
bindtextdomain(domain.toUtf8(), localeDir.toUtf8());
|
|
||||||
textdomain(domain.toUtf8());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlI18n::i18n(const QString &string)
|
|
||||||
{
|
|
||||||
return QString::fromUtf8(gettext(string.toUtf8()));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlI18n::i18np(const QString &string1, const QString &string2, int count)
|
|
||||||
{
|
|
||||||
return QString::fromUtf8(ngettext(string1.toUtf8(), string2.toUtf8(), count));
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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>
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include <libintl.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing GNU Gettext to QML
|
|
||||||
*/
|
|
||||||
class QmlI18n : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlI18n(const QString &pluginName, QObject *parent = nullptr);
|
|
||||||
void initTranslations();
|
|
||||||
/**
|
|
||||||
* @brief wrapper for gettext function
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QString i18n(const QString &string);
|
|
||||||
/**
|
|
||||||
* @brief wrapper for ngettext function
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QString i18np(const QString &string1, const QString &string2, int count);
|
|
||||||
private:
|
|
||||||
QString m_pluginName;
|
|
||||||
};
|
|
|
@ -1,65 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlaction.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include "qml/api/fileutils/qmlfileutils.h"
|
|
||||||
|
|
||||||
QmlAction::QmlAction(QAction *action, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_action(action)
|
|
||||||
{
|
|
||||||
connect(m_action, &QAction::triggered, this, &QmlAction::triggered);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlAction::setProperties(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!m_action) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMapIterator<QString, QVariant> it(map);
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
const QString key = it.key();
|
|
||||||
if (key == QSL("icon")) {
|
|
||||||
QString iconPath = map.value(key).toString();
|
|
||||||
QIcon icon;
|
|
||||||
if (QIcon::hasThemeIcon(iconPath)) {
|
|
||||||
icon = QIcon::fromTheme(iconPath);
|
|
||||||
} else {
|
|
||||||
QmlFileUtils fileUtils(m_pluginPath);
|
|
||||||
icon = QIcon(fileUtils.resolve(iconPath));
|
|
||||||
}
|
|
||||||
m_action->setIcon(icon);
|
|
||||||
} else if (key == QSL("shortcut")) {
|
|
||||||
m_action->setShortcut(QKeySequence(map.value(key).toString()));
|
|
||||||
} else {
|
|
||||||
m_action->setProperty(key.toUtf8(), map.value(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlAction::update(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
setProperties(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlAction::setPluginPath(const QString &path)
|
|
||||||
{
|
|
||||||
m_pluginPath = path;
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QAction>
|
|
||||||
#include <QVariantMap>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing Action API to QML
|
|
||||||
*/
|
|
||||||
class QmlAction : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlAction(QAction *action, QObject *parent = nullptr);
|
|
||||||
void setProperties(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Updates the properties of the action
|
|
||||||
* @param A JavaScript object containing the updated properties of the action.
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void update(const QVariantMap &map);
|
|
||||||
void setPluginPath(const QString &path);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when the action is triggered.
|
|
||||||
*/
|
|
||||||
void triggered();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QAction *m_action;
|
|
||||||
QString m_pluginPath;
|
|
||||||
};
|
|
|
@ -1,89 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlmenu.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include "qml/api/fileutils/qmlfileutils.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlMenu::QmlMenu(QMenu *menu, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_menu(menu)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
|
|
||||||
|
|
||||||
connect(m_menu, &QMenu::triggered, this, &QmlMenu::triggered);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlAction *QmlMenu::addAction(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!m_menu) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QAction *action = new QAction();
|
|
||||||
QmlAction *qmlAction = new QmlAction(action, this);
|
|
||||||
qmlAction->setPluginPath(m_pluginPath);
|
|
||||||
qmlAction->setProperties(map);
|
|
||||||
m_menu->addAction(action);
|
|
||||||
|
|
||||||
return qmlAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlMenu *QmlMenu::addMenu(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!m_menu) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMenu *newMenu = new QMenu();
|
|
||||||
QMapIterator<QString, QVariant> it(map);
|
|
||||||
while (it.hasNext()) {
|
|
||||||
const QString key = it.key();
|
|
||||||
if (key == QSL("icon")) {
|
|
||||||
QString iconPath = map.value(key).toString();
|
|
||||||
QIcon icon;
|
|
||||||
if (QIcon::hasThemeIcon(iconPath)) {
|
|
||||||
icon = QIcon::fromTheme(iconPath);
|
|
||||||
} else {
|
|
||||||
QmlFileUtils fileUtils(m_pluginPath);
|
|
||||||
icon = QIcon(fileUtils.resolve(iconPath));
|
|
||||||
}
|
|
||||||
newMenu->setIcon(icon);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
newMenu->setProperty(key.toUtf8(), map.value(key));
|
|
||||||
}
|
|
||||||
m_menu->addMenu(newMenu);
|
|
||||||
QmlMenu *newQmlMenu = new QmlMenu(newMenu, this);
|
|
||||||
newQmlMenu->setPluginPath(m_pluginPath);
|
|
||||||
return newQmlMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlMenu::addSeparator()
|
|
||||||
{
|
|
||||||
if (!m_menu) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_menu->addSeparator();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlMenu::setPluginPath(const QString &path)
|
|
||||||
{
|
|
||||||
m_pluginPath = path;
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlaction.h"
|
|
||||||
#include <QMenu>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing WebView contextmenu to QML as Menu API
|
|
||||||
*/
|
|
||||||
class QmlMenu : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlMenu(QMenu *menu, QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Adds action to menu
|
|
||||||
* @param A JavaScript object containing properties for action.
|
|
||||||
* The icon property must be in form of url of the path
|
|
||||||
* and shortcut in form string.
|
|
||||||
* @return action of type [QmlAction](@ref QmlAction)
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlAction *addAction(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Adds sub-menu to menu
|
|
||||||
* @param A JavaScript object containing properties of menu.
|
|
||||||
* The icon property must be in form of url of the path.
|
|
||||||
* @return menu of type [QmlMenu](@ref QmlMenu)
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlMenu *addMenu(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Adds a separator to menu
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void addSeparator();
|
|
||||||
void setPluginPath(const QString &path);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when the menu is triggred
|
|
||||||
*/
|
|
||||||
void triggered();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QMenu *m_menu;
|
|
||||||
QString m_pluginPath;
|
|
||||||
};
|
|
|
@ -1,110 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlwebhittestresult.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlWebHitTestResult::QmlWebHitTestResult(const WebHitTestResult &webHitTestResult, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_webHitTestResult(webHitTestResult)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWebHitTestResult::isImage() const
|
|
||||||
{
|
|
||||||
return !m_webHitTestResult.imageUrl().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWebHitTestResult::isContentEditable() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.isContentEditable();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWebHitTestResult::isContentSelected() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.isContentSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWebHitTestResult::isNull() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWebHitTestResult::isLink() const
|
|
||||||
{
|
|
||||||
return !m_webHitTestResult.linkUrl().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWebHitTestResult::isMedia() const
|
|
||||||
{
|
|
||||||
return !m_webHitTestResult.mediaUrl().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWebHitTestResult::mediaPaused() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.mediaPaused();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWebHitTestResult::mediaMuted() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.mediaMuted();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebHitTestResult::tagName() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.tagName();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebHitTestResult::baseUrl() const
|
|
||||||
{
|
|
||||||
const QUrl base = m_webHitTestResult.baseUrl();
|
|
||||||
return QString::fromUtf8(base.toEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebHitTestResult::linkTitle() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.linkTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebHitTestResult::linkUrl() const
|
|
||||||
{
|
|
||||||
const QUrl link = m_webHitTestResult.linkUrl();
|
|
||||||
return QString::fromUtf8(link.toEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebHitTestResult::imageUrl() const
|
|
||||||
{
|
|
||||||
const QUrl image = m_webHitTestResult.imageUrl();
|
|
||||||
return QString::fromUtf8(image.toEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWebHitTestResult::mediaUrl() const
|
|
||||||
{
|
|
||||||
const QUrl media = m_webHitTestResult.mediaUrl();
|
|
||||||
return QString::fromUtf8(media.toEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint QmlWebHitTestResult::pos() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF QmlWebHitTestResult::viewportPos() const
|
|
||||||
{
|
|
||||||
return m_webHitTestResult.viewportPos();
|
|
||||||
}
|
|
|
@ -1,114 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "webhittestresult.h"
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing result of WebHitTest to QML
|
|
||||||
*/
|
|
||||||
class QmlWebHitTestResult : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* @brief Gets the tagName of the element on which the context menu is requested.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString tagName READ tagName CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Gets the base url on which the context menu is requested.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString baseUrl READ baseUrl CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Gets the link title on which the context menu is requested.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString linkTitle READ linkTitle CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Gets the link url on which the context menu is requested.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString linkUrl READ linkUrl CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Gets the url of image on which the context menu is requested.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString imageUrl READ imageUrl CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Gets the url of media on which the context menu is requested.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString mediaUrl READ mediaUrl CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Gets the position at which the context menu is requested.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPoint pos READ pos CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Gets the viewport position at which the context menu is requested.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QPointF viewportPos READ viewportPos CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlWebHitTestResult(const WebHitTestResult &webHitTestResult, QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Checks if the context menu is requested on image.
|
|
||||||
* @return true if image, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool isImage() const;
|
|
||||||
/**
|
|
||||||
* @brief Checks if the context menu is requested on editable content.
|
|
||||||
* @return true if the content is editable, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool isContentEditable() const;
|
|
||||||
/**
|
|
||||||
* @brief Checks if the context menu is requested on the selected content.
|
|
||||||
* @return true if content is selected, else false.
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool isContentSelected() const;
|
|
||||||
/**
|
|
||||||
* @brief Checks if the context menu is requested on null element.
|
|
||||||
* @return true if the element is null, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool isNull() const;
|
|
||||||
/**
|
|
||||||
* @brief Checks if the context menu is requested on a link.
|
|
||||||
* @return true if the element is link, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool isLink() const;
|
|
||||||
/**
|
|
||||||
* @brief Checks if the context menu is requested on a media element.
|
|
||||||
* @return true if the element is media, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool isMedia() const;
|
|
||||||
/**
|
|
||||||
* @brief Checks if the context menu requested on media element is paused.
|
|
||||||
* @return true if media is paused, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool mediaPaused() const;
|
|
||||||
/**
|
|
||||||
* @brief Checks if the context menu requested on media element is muted.
|
|
||||||
* @return true if media is muted, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool mediaMuted() const;
|
|
||||||
QString tagName() const;
|
|
||||||
QString baseUrl() const;
|
|
||||||
QString linkTitle() const;
|
|
||||||
QString linkUrl() const;
|
|
||||||
QString imageUrl() const;
|
|
||||||
QString mediaUrl() const;
|
|
||||||
QPoint pos() const;
|
|
||||||
QPointF viewportPos() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
WebHitTestResult m_webHitTestResult;
|
|
||||||
};
|
|
|
@ -1,43 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlnotifications.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "desktopnotificationsfactory.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include "qml/api/fileutils/qmlfileutils.h"
|
|
||||||
|
|
||||||
QmlNotifications::QmlNotifications(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlNotifications::create(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
const QString iconUrl = map.value(QSL("icon")).toString();
|
|
||||||
QmlFileUtils fileUtils(m_pluginPath);
|
|
||||||
const QString iconPath = fileUtils.resolve(iconUrl);
|
|
||||||
QPixmap icon = QPixmap(iconPath);
|
|
||||||
const QString heading = map.value(QSL("heading")).toString();
|
|
||||||
const QString message = map.value(QSL("message")).toString();
|
|
||||||
mApp->desktopNotifications()->showNotification(icon, heading, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlNotifications::setPluginPath(const QString &path)
|
|
||||||
{
|
|
||||||
m_pluginPath = path;
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class to display notifications
|
|
||||||
*/
|
|
||||||
class QmlNotifications : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlNotifications(QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Create and display a notification
|
|
||||||
* @param JavaScript object containing
|
|
||||||
* - icon:
|
|
||||||
* String representing the icon file url. The icon path will be
|
|
||||||
* search in the following order
|
|
||||||
* - Falkon resource: for the icons starting with ":", they are searched in
|
|
||||||
* falkon resource file
|
|
||||||
* - Files in plugin directory: All other paths will be resolved relative to
|
|
||||||
* the plugin directory. If the icon path is outside the
|
|
||||||
* plugin directory, then it will be resolved as empty path.
|
|
||||||
* - heading:
|
|
||||||
* String representing the heading of the notification
|
|
||||||
* - message:
|
|
||||||
* String representing the message of the notification
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void create(const QVariantMap &map);
|
|
||||||
void setPluginPath(const QString &path);
|
|
||||||
private:
|
|
||||||
QString m_pluginPath;
|
|
||||||
};
|
|
|
@ -1,110 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlsettings.h"
|
|
||||||
#include "datapaths.h"
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
QmlSettings::QmlSettings(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_settings(nullptr)
|
|
||||||
{
|
|
||||||
m_settingsPath = DataPaths::currentProfilePath() + QL1S("/extensions");
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlSettings::~QmlSettings()
|
|
||||||
{
|
|
||||||
m_settings->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlSettings::setValue(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!m_settings) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!map.contains(QSL("key")) || !map.contains(QSL("value"))) {
|
|
||||||
qWarning() << "Unable to set value:" << "cannot determine Key-Value from the argument";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const QString key = map.value(QSL("key")).toString();
|
|
||||||
const QVariant value = map.value(QSL("value"));
|
|
||||||
m_settings->setValue(key, value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant QmlSettings::value(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!m_settings) {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!map.contains(QSL("key"))) {
|
|
||||||
qWarning() << "Unable to get value:" << "key not defined";
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString key = map.value(QSL("key")).toString();
|
|
||||||
const QVariant defaultValue = map.value(QSL("defaultValue"));
|
|
||||||
return m_settings->value(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlSettings::contains(const QString &key)
|
|
||||||
{
|
|
||||||
if (!m_settings) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_settings->contains(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlSettings::remove(const QString &key)
|
|
||||||
{
|
|
||||||
if (!m_settings) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_settings->remove(key);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlSettings::sync()
|
|
||||||
{
|
|
||||||
if (!m_settings) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_settings->sync();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlSettings::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSettings::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
createSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSettings::createSettings()
|
|
||||||
{
|
|
||||||
m_settingsPath += QL1S("/") + m_name + QL1S("/settings.ini");
|
|
||||||
m_settings = new QSettings(m_settingsPath, QSettings::IniFormat);
|
|
||||||
}
|
|
|
@ -1,81 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QSettings>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing Settings API to QML
|
|
||||||
*/
|
|
||||||
class QmlSettings : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief name of the folder in which settings.ini file is located
|
|
||||||
* on the standard extension path.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit QmlSettings(QObject *parent = nullptr);
|
|
||||||
~QmlSettings();
|
|
||||||
/**
|
|
||||||
* @brief Sets the value for a given key.
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - key: QString representing the key
|
|
||||||
* - value: QVariant representing the value for the key
|
|
||||||
* @return true if value is set, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool setValue(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Gets the value for a given key.
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - key: QString representing the key
|
|
||||||
* - defaultValue: QVariant representing the default value for the key
|
|
||||||
* @return QVariant representing value
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QVariant value(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Checks if a given key exists.
|
|
||||||
* @param QString representing the key
|
|
||||||
* @return true if key exists, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool contains(const QString &key);
|
|
||||||
/**
|
|
||||||
* @brief Removes the given key-value from the settings.
|
|
||||||
* @param QString representing the key
|
|
||||||
* @return true if key-value pair is removed, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool remove(const QString &key);
|
|
||||||
/**
|
|
||||||
* @brief syncs the settings
|
|
||||||
* @return true if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool sync();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QSettings *m_settings;
|
|
||||||
QString m_settingsPath;
|
|
||||||
QString m_name;
|
|
||||||
|
|
||||||
QString name() const;
|
|
||||||
void setName(const QString &name);
|
|
||||||
void createSettings();
|
|
||||||
};
|
|
|
@ -1,183 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlsidebar.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include "sidebar.h"
|
|
||||||
#include "qml/api/fileutils/qmlfileutils.h"
|
|
||||||
#include <QAction>
|
|
||||||
#include <QQuickWindow>
|
|
||||||
#include <QQmlContext>
|
|
||||||
|
|
||||||
QmlSideBar::QmlSideBar(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_item(nullptr)
|
|
||||||
{
|
|
||||||
m_sideBarHelper = new QmlSideBarHelper(this);
|
|
||||||
|
|
||||||
connect(this, &QmlSideBar::titleChanged, m_sideBarHelper, &QmlSideBarHelper::setTitle);
|
|
||||||
connect(this, &QmlSideBar::iconChanged, m_sideBarHelper, &QmlSideBarHelper::setIcon);
|
|
||||||
connect(this, &QmlSideBar::shortcutChanged, m_sideBarHelper, &QmlSideBarHelper::setShortcut);
|
|
||||||
connect(this, &QmlSideBar::checkableChanged, m_sideBarHelper, &QmlSideBarHelper::setCheckable);
|
|
||||||
connect(this, &QmlSideBar::itemChanged, m_sideBarHelper, &QmlSideBarHelper::setItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlSideBar::~QmlSideBar()
|
|
||||||
{
|
|
||||||
SideBarManager::removeSidebar(m_sideBarHelper);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBar::componentComplete()
|
|
||||||
{
|
|
||||||
SideBarManager::addSidebar(name(), sideBar());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlSideBar::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
SideBarInterface *QmlSideBar::sideBar() const
|
|
||||||
{
|
|
||||||
return m_sideBarHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBar::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
emit nameChanged(m_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlSideBar::title() const
|
|
||||||
{
|
|
||||||
return m_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBar::setTitle(const QString &title)
|
|
||||||
{
|
|
||||||
m_title = title;
|
|
||||||
emit titleChanged(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlSideBar::icon() const
|
|
||||||
{
|
|
||||||
return m_iconUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBar::setIcon(const QString &icon)
|
|
||||||
{
|
|
||||||
m_iconUrl = icon;
|
|
||||||
emit iconChanged(m_iconUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlSideBar::shortcut() const
|
|
||||||
{
|
|
||||||
return m_shortcut;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBar::setShortcut(const QString &shortcut)
|
|
||||||
{
|
|
||||||
m_shortcut = shortcut;
|
|
||||||
emit shortcutChanged(m_shortcut);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlSideBar::checkable()
|
|
||||||
{
|
|
||||||
return m_checkable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBar::setCheckable(bool checkable)
|
|
||||||
{
|
|
||||||
m_checkable = checkable;
|
|
||||||
emit checkableChanged(m_checkable);
|
|
||||||
}
|
|
||||||
|
|
||||||
QQmlComponent *QmlSideBar::item() const
|
|
||||||
{
|
|
||||||
return m_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBar::setItem(QQmlComponent *item)
|
|
||||||
{
|
|
||||||
m_item = item;
|
|
||||||
emit itemChanged(m_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlSideBarHelper::QmlSideBarHelper(QObject *parent)
|
|
||||||
: SideBarInterface(parent)
|
|
||||||
, m_item(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlSideBarHelper::title() const
|
|
||||||
{
|
|
||||||
return m_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
QAction *QmlSideBarHelper::createMenuAction()
|
|
||||||
{
|
|
||||||
QAction *action = new QAction(m_title);
|
|
||||||
action->setShortcut(QKeySequence(m_shortcut));
|
|
||||||
if (QIcon::hasThemeIcon(m_iconUrl)) {
|
|
||||||
action->setIcon(QIcon::fromTheme(m_iconUrl));
|
|
||||||
} else {
|
|
||||||
const QString pluginPath = m_item->creationContext()->contextProperty("__path__").toString();
|
|
||||||
QmlFileUtils fileUtils(pluginPath);
|
|
||||||
action->setIcon(QIcon(fileUtils.resolve(m_iconUrl)));
|
|
||||||
}
|
|
||||||
action->setCheckable(m_checkable);
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *QmlSideBarHelper::createSideBarWidget(BrowserWindow *mainWindow)
|
|
||||||
{
|
|
||||||
Q_UNUSED(mainWindow)
|
|
||||||
|
|
||||||
QQuickWindow *window = qobject_cast<QQuickWindow*>(m_item->create(m_item->creationContext()));
|
|
||||||
if (!window) {
|
|
||||||
qWarning() << "Unable to create QQuickWindow";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QWidget::createWindowContainer(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBarHelper::setTitle(const QString &title)
|
|
||||||
{
|
|
||||||
m_title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBarHelper::setIcon(const QString &icon)
|
|
||||||
{
|
|
||||||
m_iconUrl = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBarHelper::setShortcut(const QString &shortcut)
|
|
||||||
{
|
|
||||||
m_shortcut = shortcut;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBarHelper::setCheckable(bool checkable)
|
|
||||||
{
|
|
||||||
m_checkable = checkable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlSideBarHelper::setItem(QQmlComponent *item)
|
|
||||||
{
|
|
||||||
m_item = item;
|
|
||||||
}
|
|
|
@ -1,159 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "sidebarinterface.h"
|
|
||||||
#include <QQmlComponent>
|
|
||||||
#include <QQmlParserStatus>
|
|
||||||
|
|
||||||
class QmlSideBarHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing SideBar API to QML
|
|
||||||
*/
|
|
||||||
class QmlSideBar : public QObject, public QQmlParserStatus
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_INTERFACES(QQmlParserStatus)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief name of the sidebar. This is required property.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief title of the sidebar action.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief icon path of the sidebar action.
|
|
||||||
*
|
|
||||||
* The icon path will be search in the following order
|
|
||||||
* - Theme icon: if the icon is found as a theme icon, then it will
|
|
||||||
* be used even if the icon file with same name is present
|
|
||||||
* in the plugin directory
|
|
||||||
* - Falkon resource: for the icons starting with ":", they are searched in
|
|
||||||
* falkon resource file
|
|
||||||
* - Files in plugin directory: All other paths will be resolved relative to
|
|
||||||
* the plugin directory. If the icon path is outside the
|
|
||||||
* plugin directory, then it will be resolved as empty path.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief shortcut for the sidebar action.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief represents whether the sidebar action is checkable
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief the GUI of the sidebar. This must be provided as QML Window.
|
|
||||||
* This is a default property.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QQmlComponent* item READ item WRITE setItem NOTIFY itemChanged)
|
|
||||||
Q_CLASSINFO("DefaultProperty", "item")
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit QmlSideBar(QObject *parent = nullptr);
|
|
||||||
~QmlSideBar();
|
|
||||||
void classBegin() {}
|
|
||||||
void componentComplete();
|
|
||||||
QString name() const;
|
|
||||||
SideBarInterface *sideBar() const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when name property is changed.
|
|
||||||
* @param QString represening name
|
|
||||||
*/
|
|
||||||
void nameChanged(const QString &name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when title property is changed
|
|
||||||
* @param QString representing title
|
|
||||||
*/
|
|
||||||
void titleChanged(const QString &title);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when icon property is changed
|
|
||||||
* @param QString representing icon path url
|
|
||||||
*/
|
|
||||||
void iconChanged(const QString &icon);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when shortcut property is changed
|
|
||||||
* @param QString representing shortcut
|
|
||||||
*/
|
|
||||||
void shortcutChanged(const QString &shortcut);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This signal is emitted when checkable property is changed
|
|
||||||
* @param checkable
|
|
||||||
*/
|
|
||||||
void checkableChanged(bool checkable);
|
|
||||||
void itemChanged(QQmlComponent *item);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_name;
|
|
||||||
QString m_title;
|
|
||||||
QString m_iconUrl;
|
|
||||||
QString m_shortcut;
|
|
||||||
bool m_checkable;
|
|
||||||
QQmlComponent *m_item;
|
|
||||||
|
|
||||||
QmlSideBarHelper *m_sideBarHelper;
|
|
||||||
|
|
||||||
void setName(const QString &name);
|
|
||||||
QString title() const;
|
|
||||||
void setTitle(const QString &title);
|
|
||||||
QString icon() const;
|
|
||||||
void setIcon(const QString &icon);
|
|
||||||
QString shortcut() const;
|
|
||||||
void setShortcut(const QString &shortcut);
|
|
||||||
bool checkable();
|
|
||||||
void setCheckable(bool checkable);
|
|
||||||
QQmlComponent *item() const;
|
|
||||||
void setItem(QQmlComponent *item);
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlSideBarHelper : public SideBarInterface
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlSideBarHelper(QObject *parent = nullptr);
|
|
||||||
QString title() const;
|
|
||||||
QAction *createMenuAction();
|
|
||||||
QWidget *createSideBarWidget(BrowserWindow *mainWindow);
|
|
||||||
|
|
||||||
void setTitle(const QString &title);
|
|
||||||
void setIcon(const QString &icon);
|
|
||||||
void setShortcut(const QString &shortcut);
|
|
||||||
void setCheckable(bool checkable);
|
|
||||||
void setItem(QQmlComponent *item);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_title;
|
|
||||||
QString m_iconUrl;
|
|
||||||
QString m_shortcut;
|
|
||||||
bool m_checkable;
|
|
||||||
QQmlComponent *m_item;
|
|
||||||
};
|
|
|
@ -1,453 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmltab.h"
|
|
||||||
#include "loadrequest.h"
|
|
||||||
#include "tabbedwebview.h"
|
|
||||||
#include "webpage.h"
|
|
||||||
#include <QWebEngineHistory>
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QmlWindowData, windowData)
|
|
||||||
|
|
||||||
QmlTab::QmlTab(WebTab *webTab, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_webTab(webTab)
|
|
||||||
, m_webPage(nullptr)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
|
|
||||||
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
createConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::detach()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::setZoomLevel(int zoomLevel)
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->setZoomLevel(zoomLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::stop()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::reload()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::unload()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::load(const QString &url)
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadRequest req;
|
|
||||||
req.setUrl(QUrl::fromEncoded(url.toUtf8()));
|
|
||||||
m_webTab->load(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::zoomIn()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->zoomIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::zoomOut()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->zoomOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::zoomReset()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->zoomReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::undo()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->editUndo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::redo()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->editRedo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::selectAll()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->editSelectAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::reloadBypassCache()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->reloadBypassCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::back()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->back();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::forward()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->forward();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::printPage()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->printPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::showSource()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->showSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::sendPageByMail()
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_webTab->webView()->sendPageByMail();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant QmlTab::execJavaScript(const QJSValue &value)
|
|
||||||
{
|
|
||||||
if (!m_webPage && !m_webTab) {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
WebPage *webPage = m_webPage;
|
|
||||||
if (!m_webPage) {
|
|
||||||
webPage = m_webTab->webView()->page();
|
|
||||||
}
|
|
||||||
return webPage->execJavaScript(value.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWebHitTestResult *QmlTab::hitTestContent(const QPoint &point)
|
|
||||||
{
|
|
||||||
if (!m_webPage && !m_webTab) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
WebPage *webPage = m_webPage;
|
|
||||||
if (!m_webPage) {
|
|
||||||
webPage = m_webTab->webView()->page();
|
|
||||||
}
|
|
||||||
WebHitTestResult result = webPage->hitTestContent(point);
|
|
||||||
return new QmlWebHitTestResult(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlTab::url() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString::fromUtf8(m_webTab->url().toEncoded());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlTab::title() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->title();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int QmlTab::zoomLevel() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->zoomLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlTab::index() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->tabIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::pinned() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->isPinned();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::muted() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->isMuted();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::restored() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->isRestored();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::current() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->isCurrentTab();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::playing() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->isPlaying();
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindow *QmlTab::browserWindow() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return windowData->get(m_webTab->browserWindow());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::loading() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->webView()->isLoading();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlTab::loadingProgress() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->webView()->loadingProgress();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::backgroundActivity() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->webView()->backgroundActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::canGoBack() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->webView()->history()->canGoBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTab::canGoForward() const
|
|
||||||
{
|
|
||||||
if (!m_webTab) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_webTab->webView()->history()->canGoForward();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::setWebPage(WebPage *webPage)
|
|
||||||
{
|
|
||||||
if (m_webPage) {
|
|
||||||
removeConnections();
|
|
||||||
}
|
|
||||||
m_webPage = webPage;
|
|
||||||
TabbedWebView *tabbedWebView = qobject_cast<TabbedWebView*>(m_webPage->view());
|
|
||||||
m_webTab = tabbedWebView->webTab();
|
|
||||||
if (m_webTab) {
|
|
||||||
createConnections();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::createConnections()
|
|
||||||
{
|
|
||||||
Q_ASSERT(m_lambdaConnections.length() == 0);
|
|
||||||
|
|
||||||
auto titleChangedConnection = connect(m_webTab, &WebTab::titleChanged, this, [this](const QString &title){
|
|
||||||
emit titleChanged(title);
|
|
||||||
});
|
|
||||||
m_lambdaConnections.append(titleChangedConnection);
|
|
||||||
|
|
||||||
auto pinnedChangedConnection = connect(m_webTab, &WebTab::pinnedChanged, this, [this](bool pinned){
|
|
||||||
emit pinnedChanged(pinned);
|
|
||||||
});
|
|
||||||
m_lambdaConnections.append(pinnedChangedConnection);
|
|
||||||
|
|
||||||
auto loadingChangedConnection = connect(m_webTab, &WebTab::loadingChanged, this, [this](bool loading){
|
|
||||||
emit loadingChanged(loading);
|
|
||||||
});
|
|
||||||
m_lambdaConnections.append(loadingChangedConnection);
|
|
||||||
|
|
||||||
auto mutedChangedConnection = connect(m_webTab, &WebTab::mutedChanged, this, [this](bool muted){
|
|
||||||
emit mutedChanged(muted);
|
|
||||||
});
|
|
||||||
m_lambdaConnections.append(mutedChangedConnection);
|
|
||||||
|
|
||||||
auto restoredChangedConnection = connect(m_webTab, &WebTab::restoredChanged, this, [this](bool restored){
|
|
||||||
emit restoredChanged(restored);
|
|
||||||
});
|
|
||||||
m_lambdaConnections.append(restoredChangedConnection);
|
|
||||||
|
|
||||||
auto playingChangedConnection = connect(m_webTab, &WebTab::playingChanged, this, [this](bool playing){
|
|
||||||
emit playingChanged(playing);
|
|
||||||
});
|
|
||||||
m_lambdaConnections.append(playingChangedConnection);
|
|
||||||
|
|
||||||
connect(m_webTab->webView(), &TabbedWebView::zoomLevelChanged, this, &QmlTab::zoomLevelChanged);
|
|
||||||
connect(m_webTab->webView(), &TabbedWebView::backgroundActivityChanged, this, &QmlTab::backgroundActivityChanged);
|
|
||||||
|
|
||||||
if (m_webPage) {
|
|
||||||
connect(m_webPage, &WebPage::navigationRequestAccepted, this, &QmlTab::navigationRequestAccepted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTab::removeConnections()
|
|
||||||
{
|
|
||||||
for (auto connection : qAsConst(m_lambdaConnections)) {
|
|
||||||
disconnect(connection);
|
|
||||||
}
|
|
||||||
m_lambdaConnections.clear();
|
|
||||||
|
|
||||||
disconnect(m_webTab->webView(), &TabbedWebView::zoomLevelChanged, this, &QmlTab::zoomLevelChanged);
|
|
||||||
disconnect(m_webTab->webView(), &TabbedWebView::backgroundActivityChanged, this, &QmlTab::backgroundActivityChanged);
|
|
||||||
|
|
||||||
if (m_webPage) {
|
|
||||||
disconnect(m_webPage, &WebPage::navigationRequestAccepted, this, &QmlTab::navigationRequestAccepted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlTabData::QmlTabData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlTabData::~QmlTabData()
|
|
||||||
{
|
|
||||||
qDeleteAll(m_tabs);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlTab *QmlTabData::get(WebTab *webTab)
|
|
||||||
{
|
|
||||||
QmlTab *tab = m_tabs.value(webTab);
|
|
||||||
if (!tab) {
|
|
||||||
tab = new QmlTab(webTab);
|
|
||||||
m_tabs.insert(webTab, tab);
|
|
||||||
}
|
|
||||||
return tab;
|
|
||||||
}
|
|
|
@ -1,293 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QJSValue>
|
|
||||||
#include <QWebEnginePage>
|
|
||||||
|
|
||||||
#include "webtab.h"
|
|
||||||
#include "../windows/qmlwindow.h"
|
|
||||||
#include "qml/api/menus/qmlwebhittestresult.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing a browser tab to QML
|
|
||||||
*/
|
|
||||||
class QmlTab : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief url of the tab
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString url READ url CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief title of the tab
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString title READ title CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief zoom level of the tab
|
|
||||||
*
|
|
||||||
* Zoom levels are from 0 to 18
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int zoomLevel READ zoomLevel CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief index of the tab
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int index READ index CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab is pinned
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool pinned READ pinned CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab is muted
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool muted READ muted CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab is restored
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool restored READ restored CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab is the current tab
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool current READ current CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab is playing
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool playing READ playing CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief window of the tab
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QmlWindow* browserWindow READ browserWindow CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab is loading
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool loading READ loading CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief get the loading progress of the tab
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int loadingProgress READ loadingProgress CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab has associated background activity
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool backgroundActivity READ backgroundActivity CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab is can go back
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool canGoBack READ canGoBack CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the tab is can go forward
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool canGoForward READ canGoForward CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlTab(WebTab *webTab = nullptr, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Detaches the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void detach();
|
|
||||||
/**
|
|
||||||
* @brief Set the zoom level of the tab
|
|
||||||
* @param Integer representing the zoom level
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void setZoomLevel(int zoomLevel);
|
|
||||||
/**
|
|
||||||
* @brief Stops webview associated with the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void stop();
|
|
||||||
/**
|
|
||||||
* @brief Reloads webview associated with the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void reload();
|
|
||||||
/**
|
|
||||||
* @brief Unloads the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void unload();
|
|
||||||
/**
|
|
||||||
* @brief Loads webview associated with the tab
|
|
||||||
* @param String representing the url to load
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void load(const QString &url);
|
|
||||||
/**
|
|
||||||
* @brief Decreases the zoom level of the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void zoomIn();
|
|
||||||
/**
|
|
||||||
* @brief Increases the zoom level of the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void zoomOut();
|
|
||||||
/**
|
|
||||||
* @brief Resets the tab zoom level
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void zoomReset();
|
|
||||||
/**
|
|
||||||
* @brief Performs edit undo on the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void undo();
|
|
||||||
/**
|
|
||||||
* @brief Performs edit redo on the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void redo();
|
|
||||||
/**
|
|
||||||
* @brief Performs edit select-all on the tab
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void selectAll();
|
|
||||||
/**
|
|
||||||
* @brief Reloads the tab by bypassing the cache
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void reloadBypassCache();
|
|
||||||
/**
|
|
||||||
* @brief Loads the previous page
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void back();
|
|
||||||
/**
|
|
||||||
* @brief Loads the next page
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void forward();
|
|
||||||
/**
|
|
||||||
* @brief Prints the page
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void printPage();
|
|
||||||
/**
|
|
||||||
* @brief Shows the page source
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void showSource();
|
|
||||||
/**
|
|
||||||
* @brief Sends page by mail
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void sendPageByMail();
|
|
||||||
/**
|
|
||||||
* @brief execute JavaScript function in a page
|
|
||||||
* @param value, representing JavaScript function
|
|
||||||
* @return QVariant, the return value of executed javascript
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QVariant execJavaScript(const QJSValue &value);
|
|
||||||
/**
|
|
||||||
* @brief Gets result of web hit test at a given point
|
|
||||||
* @param point
|
|
||||||
* @return result of web hit test
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlWebHitTestResult *hitTestContent(const QPoint &point);
|
|
||||||
|
|
||||||
void setWebPage(WebPage *webPage);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when the tab title is changed
|
|
||||||
* @param String representing the new title
|
|
||||||
*/
|
|
||||||
void titleChanged(const QString &title);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when pinned state of the tab is changed
|
|
||||||
* @param Bool representing if a tab is pinned
|
|
||||||
*/
|
|
||||||
void pinnedChanged(bool pinned);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when loading state of the tab is changed
|
|
||||||
* @param Bool representing if the tab is loading
|
|
||||||
*/
|
|
||||||
void loadingChanged(bool loading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when muted state of the tab is changed
|
|
||||||
* @param Bool representing if the tab is muted
|
|
||||||
*/
|
|
||||||
void mutedChanged(bool muted);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when restored state of the tab is changed
|
|
||||||
* @param Bool representing if the tab is restored
|
|
||||||
*/
|
|
||||||
void restoredChanged(bool restored);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when playing state of the tab is changed
|
|
||||||
* @param Bool representing if the tab is in playing state
|
|
||||||
*/
|
|
||||||
void playingChanged(bool playing);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when zoom level of the tab is changed
|
|
||||||
* @param Integer representing the zoom level
|
|
||||||
*/
|
|
||||||
void zoomLevelChanged(int zoomLevel);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when background activity of the tab is changed
|
|
||||||
* @param Bool representing if there is background activity attached to the tab
|
|
||||||
*/
|
|
||||||
void backgroundActivityChanged(int backgroundActivityChanged);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when navigation request is accepted
|
|
||||||
* @param url, representing requested url
|
|
||||||
* @param type of navigation
|
|
||||||
* @param isMainFrame, represents if navigation is requested for a top level page.
|
|
||||||
*/
|
|
||||||
void navigationRequestAccepted(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame);
|
|
||||||
|
|
||||||
private:
|
|
||||||
WebTab *m_webTab;
|
|
||||||
WebPage *m_webPage;
|
|
||||||
QList<QMetaObject::Connection> m_lambdaConnections;
|
|
||||||
|
|
||||||
QString url() const;
|
|
||||||
QString title() const;
|
|
||||||
int zoomLevel() const;
|
|
||||||
int index() const;
|
|
||||||
bool pinned() const;
|
|
||||||
bool muted() const;
|
|
||||||
bool restored() const;
|
|
||||||
bool current() const;
|
|
||||||
bool playing() const;
|
|
||||||
QmlWindow *browserWindow() const;
|
|
||||||
bool loading() const;
|
|
||||||
int loadingProgress() const;
|
|
||||||
bool backgroundActivity() const;
|
|
||||||
bool canGoBack() const;
|
|
||||||
bool canGoForward() const;
|
|
||||||
|
|
||||||
void createConnections();
|
|
||||||
void removeConnections();
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlTabData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit QmlTabData();
|
|
||||||
~QmlTabData();
|
|
||||||
QmlTab *get(WebTab *webTab);
|
|
||||||
private:
|
|
||||||
QHash<WebTab*, QmlTab*> m_tabs;
|
|
||||||
};
|
|
|
@ -1,360 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmltabs.h"
|
|
||||||
#include "tabwidget.h"
|
|
||||||
#include "pluginproxy.h"
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QmlTabData, tabData)
|
|
||||||
|
|
||||||
QmlTabs::QmlTabs(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
for (BrowserWindow *window : mApp->windows()) {
|
|
||||||
windowCreated(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, &QmlTabs::windowCreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::setCurrentIndex(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to set current index:" << "index not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->setCurrentIndex(index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::nextTab(int windowId)
|
|
||||||
{
|
|
||||||
const auto window = getWindow(windowId);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->nextTab();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::previousTab(int windowId)
|
|
||||||
{
|
|
||||||
const auto window = getWindow(windowId);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->previousTab();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::moveTab(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("from"))) {
|
|
||||||
qWarning() << "Unable to move tab:" << "from not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!map.contains(QSL("to"))) {
|
|
||||||
qWarning() << "Unable to move tab:" << "to not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int from = map.value(QSL("from")).toInt();
|
|
||||||
const int to = map.value(QSL("to")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->moveTab(from, to);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::pinTab(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to pin tab:" << "index not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebTab *webTab = window->tabWidget()->webTab(index);
|
|
||||||
|
|
||||||
if (webTab->isPinned()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
webTab->togglePinned();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::unpinTab(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to unpin tab:" << "index not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebTab *webTab = window->tabWidget()->webTab(index);
|
|
||||||
|
|
||||||
if (!webTab->isPinned()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
webTab->togglePinned();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::detachTab(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to detatch tab:" << "index not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->detachTab(index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::duplicate(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to duplicate:" << "index not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->duplicateTab(index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::closeTab(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to close tab:" << "index not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->closeTab(index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::reloadTab(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to reload tab:" << "index not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->reloadTab(index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::stopTab(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to close tab:" << "index not defined";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
window->tabWidget()->stopTab(index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlTab *QmlTabs::get(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("index"))) {
|
|
||||||
qWarning() << "Unable to set current index:" << "index not defined";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int index = map.value(QSL("index")).toInt();
|
|
||||||
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
const auto webTab = window->tabWidget()->webTab(index);
|
|
||||||
return tabData->get(webTab);
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlTabs::normalTabsCount(int windowId) const
|
|
||||||
{
|
|
||||||
const auto window = getWindow(windowId);
|
|
||||||
if (!window) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return window->tabWidget()->normalTabsCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlTabs::pinnedTabsCount(int windowId) const
|
|
||||||
{
|
|
||||||
const auto window = getWindow(windowId);
|
|
||||||
if (!window) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return window->tabWidget()->pinnedTabsCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlTabs::getAll(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
return QList<QObject*>();
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool withPinned = map.value(QSL("withPinned")).toBool();
|
|
||||||
const auto tabList = window->tabWidget()->allTabs(withPinned);
|
|
||||||
|
|
||||||
QList<QObject*> list;
|
|
||||||
for (auto tab : tabList) {
|
|
||||||
list.append(tabData->get(tab));
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlTabs::search(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
const QString title = map.value(QSL("title")).toString();
|
|
||||||
const QString url = map.value(QSL("url")).toString();
|
|
||||||
const bool withPinned = map.value(QSL("withPinned")).toBool();
|
|
||||||
QList<QObject*> list;
|
|
||||||
foreach (BrowserWindow *window, mApp->windows()) {
|
|
||||||
foreach (WebTab *webTab, window->tabWidget()->allTabs(withPinned)) {
|
|
||||||
if (webTab->title().contains(title, Qt::CaseInsensitive)
|
|
||||||
|| QString::fromUtf8(webTab->url().toEncoded()).contains(url, Qt::CaseInsensitive)) {
|
|
||||||
list.append(tabData->get(webTab));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlTabs::addTab(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
const QString urlString = map.value(QSL("url")).toString();
|
|
||||||
const auto window = getWindow(map);
|
|
||||||
if (!window) {
|
|
||||||
qDebug() << "Unable to add tab:" << "window not found";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LoadRequest req(QUrl::fromEncoded(urlString.toUtf8()));
|
|
||||||
const int ret = window->tabWidget()->addView(req);
|
|
||||||
return ret != -1 ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
BrowserWindow *QmlTabs::getWindow(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
const int windowId = map.value(QSL("windowId"), -1).toInt();
|
|
||||||
return getWindow(windowId);
|
|
||||||
}
|
|
||||||
|
|
||||||
BrowserWindow *QmlTabs::getWindow(int windowId) const
|
|
||||||
{
|
|
||||||
if (windowId == -1) {
|
|
||||||
return mApp->getWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (BrowserWindow *window : mApp->windowIdHash().keys()) {
|
|
||||||
if (mApp->windowIdHash().value(window) == windowId) {
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qWarning() << "Unable to get window with given windowId";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTabs::windowCreated(BrowserWindow *window)
|
|
||||||
{
|
|
||||||
const int windowId = mApp->windowIdHash().value(window);
|
|
||||||
|
|
||||||
connect(window->tabWidget(), &TabWidget::changed, this, [this, windowId]{
|
|
||||||
emit changed(windowId);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(window->tabWidget(), &TabWidget::tabInserted, this, [this, windowId](int index){
|
|
||||||
QVariantMap map;
|
|
||||||
map.insert(QSL("windowId"), windowId);
|
|
||||||
map.insert(QSL("index"), index);
|
|
||||||
emit tabInserted(map);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(window->tabWidget(), &TabWidget::tabRemoved, this, [this, windowId](int index){
|
|
||||||
QVariantMap map;
|
|
||||||
map.insert(QSL("windowId"), windowId);
|
|
||||||
map.insert(QSL("index"), index);
|
|
||||||
emit tabRemoved(map);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(window->tabWidget(), &TabWidget::tabMoved, this, [this, windowId](int from, int to){
|
|
||||||
QVariantMap map;
|
|
||||||
map.insert(QSL("windowId"), windowId);
|
|
||||||
map.insert(QSL("from"), from);
|
|
||||||
map.insert(QSL("to"), to);
|
|
||||||
emit tabMoved(map);
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,233 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "mainapplication.h"
|
|
||||||
#include "qmltab.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing Tabs API to QML
|
|
||||||
*/
|
|
||||||
class QmlTabs : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlTabs(QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Sets the current tab in a window
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* Integer representing new current index
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool setCurrentIndex(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Sets the next tab as current tab
|
|
||||||
* @param Integer representing the window
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool nextTab(int windowId = -1);
|
|
||||||
/**
|
|
||||||
* @brief Sets the prvious tab as current tab
|
|
||||||
* @param Integer representing the window
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool previousTab(int windowId = -1);
|
|
||||||
/**
|
|
||||||
* @brief Moves a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - from:
|
|
||||||
* The initial index of the tab
|
|
||||||
* - to:
|
|
||||||
* The final index of the tab
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if tab is moved, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool moveTab(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Pins a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* Integer representing the tab to be pinned
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool pinTab(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Un-pins a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* Integer representing the tab to be unpinned
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool unpinTab(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Detaches a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* Integer representing the tab to be detached
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if tab is detached, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool detachTab(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Duplicates a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* Integer representing the tab to duplicate
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool duplicate(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Close a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* Integer representing the tab to be closed
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool closeTab(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Reloads a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* Integer representing the tab to be reloaded
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool reloadTab(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Stops a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* Integer representing the tab to be stoped
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if success, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool stopTab(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Gets a tab
|
|
||||||
* @param A JavaScript object contining
|
|
||||||
* - index:
|
|
||||||
* Integer representign the index of the tab
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return Tab of type [QmlTab](@ref QmlTab) if exists, else null
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlTab *get(const QVariantMap &map) const;
|
|
||||||
/**
|
|
||||||
* @brief Get the normal tabs count in a window
|
|
||||||
* @param Integer representing the window
|
|
||||||
* @return Number of normal tabs in the window
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE int normalTabsCount(int windowId = -1) const;
|
|
||||||
/**
|
|
||||||
* @brief Get the pinned tabs count in a window
|
|
||||||
* @param Integer representing the window
|
|
||||||
* @return Number of pinned tabs in the window
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE int pinnedTabsCount(int windowId = -1) const;
|
|
||||||
/**
|
|
||||||
* @brief Gets all the tabs of a window
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* - withPinned:
|
|
||||||
* Bool representing if the searched tab can be pinned
|
|
||||||
* @return List of tabs, each of type [QmlTab](@ref QmlTab)
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject*> getAll(const QVariantMap &map = QVariantMap()) const;
|
|
||||||
/**
|
|
||||||
* @brief Searches tabs against a criteria
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - title:
|
|
||||||
* String representing the title to be searched
|
|
||||||
* - url:
|
|
||||||
* String representing the url to be searched
|
|
||||||
* - withPinned:
|
|
||||||
* Bool representing if the searched tab can be pinned
|
|
||||||
* @return List of tabs, each of type [QmlTab](@ref QmlTab), which are
|
|
||||||
* matched against the criteria
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject*> search(const QVariantMap &map);
|
|
||||||
/**
|
|
||||||
* @brief Adds a tab
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - url:
|
|
||||||
* String representing the url of the tab
|
|
||||||
* - windowId:
|
|
||||||
* The id of window containing the tab
|
|
||||||
* @return True if the tab is added, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool addTab(const QVariantMap &map);
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when tabs in the tab widget are changed
|
|
||||||
* @param window id representing the window in which the change occurs
|
|
||||||
*/
|
|
||||||
void changed(int windowId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when a tab is inserted
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* The index of the inserted tab
|
|
||||||
* - windowId:
|
|
||||||
* The id of window in which the tab is inserted
|
|
||||||
*/
|
|
||||||
void tabInserted(const QVariantMap &map);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when a tab is removed
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - index:
|
|
||||||
* The index of the removed tab
|
|
||||||
* - windowId:
|
|
||||||
* The id of window in which the tab is removed
|
|
||||||
*/
|
|
||||||
void tabRemoved(const QVariantMap &map);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when a tab is moved
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - from:
|
|
||||||
* The initial index of the moved tab
|
|
||||||
* - to:
|
|
||||||
* The final index of the moved tab
|
|
||||||
* - windowId:
|
|
||||||
* The id of window in which the tab is moved
|
|
||||||
*/
|
|
||||||
void tabMoved(const QVariantMap &map);
|
|
||||||
private:
|
|
||||||
BrowserWindow *getWindow(const QVariantMap &map) const;
|
|
||||||
BrowserWindow *getWindow(int windowId) const;
|
|
||||||
void windowCreated(BrowserWindow *window);
|
|
||||||
};
|
|
|
@ -1,56 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlmostvisitedurl.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlMostVisitedUrl::QmlMostVisitedUrl(const QString &title, const QString &url, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_title(title)
|
|
||||||
, m_url(url)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlMostVisitedUrl::title() const
|
|
||||||
{
|
|
||||||
return m_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlMostVisitedUrl::url() const
|
|
||||||
{
|
|
||||||
return m_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlMostVisitedUrlData::QmlMostVisitedUrlData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlMostVisitedUrlData::~QmlMostVisitedUrlData()
|
|
||||||
{
|
|
||||||
qDeleteAll(m_urls);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlMostVisitedUrl *QmlMostVisitedUrlData::get(const QString &title, const QString &url)
|
|
||||||
{
|
|
||||||
QmlMostVisitedUrl *visitedUrl = m_urls.value({title, url});
|
|
||||||
if (!visitedUrl) {
|
|
||||||
visitedUrl = new QmlMostVisitedUrl(title, url);
|
|
||||||
m_urls.insert({title, url}, visitedUrl);
|
|
||||||
}
|
|
||||||
return visitedUrl;
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QHash>
|
|
||||||
#include <QPair>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing MostVisitedUrl type to QML
|
|
||||||
*/
|
|
||||||
class QmlMostVisitedUrl : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief title of "most visited url" item
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString title READ title CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief url of "most visited url" item
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString url READ url CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlMostVisitedUrl(const QString &title = QString(), const QString &url = QString(), QObject *parent = nullptr);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_title;
|
|
||||||
QString m_url;
|
|
||||||
|
|
||||||
QString title() const;
|
|
||||||
QString url() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlMostVisitedUrlData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit QmlMostVisitedUrlData();
|
|
||||||
~QmlMostVisitedUrlData();
|
|
||||||
QmlMostVisitedUrl *get(const QString &title = QString(), const QString &url = QString());
|
|
||||||
private:
|
|
||||||
QHash<QPair<QString, QString>, QmlMostVisitedUrl*> m_urls;
|
|
||||||
};
|
|
|
@ -1,53 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlexternaljsobject.h"
|
|
||||||
#include "javascript/externaljsobject.h"
|
|
||||||
|
|
||||||
QmlExternalJsObject::QmlExternalJsObject(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlExternalJsObject::~QmlExternalJsObject()
|
|
||||||
{
|
|
||||||
for (QObject *object : m_objects) {
|
|
||||||
ExternalJsObject::unregisterExtraObject(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlExternalJsObject::registerExtraObject(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
if (!map.contains(QSL("id")) || !map.contains(QSL("object"))) {
|
|
||||||
qWarning() << "Unable to call" << __FUNCTION__ << ": unsufficient parameters";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString id = map.value(QSL("id")).toString();
|
|
||||||
QObject *object = qvariant_cast<QObject*>(map.value(QSL("object")));
|
|
||||||
if (!object) {
|
|
||||||
qWarning() << "Unable to cast to QObject";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ExternalJsObject::registerExtraObject(id, object);
|
|
||||||
m_objects.append(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlExternalJsObject::unregisterExtraObject(QObject *object)
|
|
||||||
{
|
|
||||||
ExternalJsObject::unregisterExtraObject(object);
|
|
||||||
}
|
|
|
@ -1,117 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmluserscript.h"
|
|
||||||
|
|
||||||
QmlUserScript::QmlUserScript(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QWebEngineScript QmlUserScript::webEngineScript() const
|
|
||||||
{
|
|
||||||
return m_webEngineScript;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScript::setWebEngineScript(const QWebEngineScript &script)
|
|
||||||
{
|
|
||||||
m_webEngineScript = script;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlUserScript::null() const
|
|
||||||
{
|
|
||||||
return m_webEngineScript.isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlUserScript::name() const
|
|
||||||
{
|
|
||||||
return m_webEngineScript.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScript::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_webEngineScript.setName(name);
|
|
||||||
emit nameChanged(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlUserScript::runsOnSubFrames() const
|
|
||||||
{
|
|
||||||
return m_webEngineScript.runsOnSubFrames();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScript::setRunsOnSubFrames(bool runsOnSubFrames)
|
|
||||||
{
|
|
||||||
m_webEngineScript.setRunsOnSubFrames(runsOnSubFrames);
|
|
||||||
emit runsOnSubFramesChanged(runsOnSubFrames);
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlUserScript::worldId() const
|
|
||||||
{
|
|
||||||
return (int)m_webEngineScript.worldId();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScript::setWorldId(int worldId)
|
|
||||||
{
|
|
||||||
switch (worldId) {
|
|
||||||
case QWebEngineScript::MainWorld:
|
|
||||||
m_webEngineScript.setWorldId(QWebEngineScript::MainWorld);
|
|
||||||
break;
|
|
||||||
case QWebEngineScript::ApplicationWorld:
|
|
||||||
m_webEngineScript.setWorldId(QWebEngineScript::ApplicationWorld);
|
|
||||||
break;
|
|
||||||
case QWebEngineScript::UserWorld:
|
|
||||||
m_webEngineScript.setWorldId(QWebEngineScript::UserWorld);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
emit worldIdChanged(worldId);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlUserScript::sourceCode() const
|
|
||||||
{
|
|
||||||
return m_webEngineScript.sourceCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScript::setSourceCode(const QString &sourceCode)
|
|
||||||
{
|
|
||||||
m_webEngineScript.setSourceCode(sourceCode);
|
|
||||||
emit sourceCodeChanged(sourceCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlUserScript::InjectionPoint QmlUserScript::injectionPoint() const
|
|
||||||
{
|
|
||||||
return (InjectionPoint)m_webEngineScript.injectionPoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScript::setInjectionPoint(InjectionPoint injectionPoint)
|
|
||||||
{
|
|
||||||
switch (injectionPoint) {
|
|
||||||
case QWebEngineScript::DocumentCreation:
|
|
||||||
m_webEngineScript.setInjectionPoint(QWebEngineScript::DocumentCreation);
|
|
||||||
break;
|
|
||||||
case QWebEngineScript::DocumentReady:
|
|
||||||
m_webEngineScript.setInjectionPoint(QWebEngineScript::DocumentReady);
|
|
||||||
break;
|
|
||||||
case QWebEngineScript::Deferred:
|
|
||||||
m_webEngineScript.setInjectionPoint(QWebEngineScript::Deferred);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
emit injectionPointChanged(injectionPoint);
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qzcommon.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QWebEngineScript>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing QWebEngineScript to QML
|
|
||||||
*/
|
|
||||||
class FALKON_EXPORT QmlUserScript : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* @brief Checks if the UserScript is null
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool null READ null CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Name of the UserScript
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
|
||||||
/**
|
|
||||||
* @brief Checks if the UserScript runs on sub frames
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool runsOnSubFrames READ runsOnSubFrames WRITE setRunsOnSubFrames NOTIFY runsOnSubFramesChanged)
|
|
||||||
/**
|
|
||||||
* @brief WorldId of the UserScript
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int worldId READ worldId WRITE setWorldId NOTIFY worldIdChanged)
|
|
||||||
/**
|
|
||||||
* @brief Source code of the UserScript
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString sourceCode READ sourceCode WRITE setSourceCode NOTIFY sourceCodeChanged)
|
|
||||||
/**
|
|
||||||
* @brief Injection point of the UserScript
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(InjectionPoint injectionPoint READ injectionPoint WRITE setInjectionPoint NOTIFY injectionPointChanged)
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief The enum exposing QWebEngineScript::InjectionPoint
|
|
||||||
*/
|
|
||||||
enum InjectionPoint {
|
|
||||||
DocumentCreation = QWebEngineScript::DocumentCreation, //!< Represents QWebEngineScript::DocumentCreation
|
|
||||||
DocumentReady = QWebEngineScript::DocumentReady, //!< Represents QWebEngineScript::DocumentReady,
|
|
||||||
Deferred = QWebEngineScript::Deferred //!< Represents QWebEngineScript::Deferred
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* @brief The enum wrapping QWebEngineScript::ScriptWorldId
|
|
||||||
*/
|
|
||||||
enum ScriptWorldId {
|
|
||||||
MainWorld = QWebEngineScript::MainWorld, //!< Represents QWebEngineScript::MainWorld
|
|
||||||
ApplicationWorld = QWebEngineScript::ApplicationWorld, //!< Represents QWebEngineScript::ApplicationWorld
|
|
||||||
UserWorld = QWebEngineScript::UserWorld //! < Represents QWebEngineScript::UserWorld
|
|
||||||
};
|
|
||||||
Q_ENUM(InjectionPoint)
|
|
||||||
Q_ENUM(ScriptWorldId)
|
|
||||||
|
|
||||||
explicit QmlUserScript(QObject *parent = nullptr);
|
|
||||||
QWebEngineScript webEngineScript() const;
|
|
||||||
void setWebEngineScript(const QWebEngineScript &script);
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when the script name is changed
|
|
||||||
*/
|
|
||||||
void nameChanged(const QString &name);
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when runsOnSubFrame property of the script is changed
|
|
||||||
*/
|
|
||||||
void runsOnSubFramesChanged(bool runsOnSubFrames);
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when worldId property of the script is changed
|
|
||||||
*/
|
|
||||||
void worldIdChanged(int worldId);
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when source code of the script is changed
|
|
||||||
*/
|
|
||||||
void sourceCodeChanged(const QString &sourceCode);
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when injectionPoint property of the script is changed
|
|
||||||
*/
|
|
||||||
void injectionPointChanged(int injectionPoint);
|
|
||||||
private:
|
|
||||||
QWebEngineScript m_webEngineScript;
|
|
||||||
|
|
||||||
bool null() const;
|
|
||||||
QString name() const;
|
|
||||||
void setName(const QString &name);
|
|
||||||
bool runsOnSubFrames() const;
|
|
||||||
void setRunsOnSubFrames(bool runsOnSubFrames);
|
|
||||||
int worldId() const;
|
|
||||||
void setWorldId(int worldId);
|
|
||||||
QString sourceCode() const;
|
|
||||||
void setSourceCode(const QString &sourceCode);
|
|
||||||
InjectionPoint injectionPoint() const;
|
|
||||||
void setInjectionPoint(InjectionPoint injectionPoint);
|
|
||||||
};
|
|
|
@ -1,124 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmluserscripts.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include <QWebEngineProfile>
|
|
||||||
#include <QWebEngineScriptCollection>
|
|
||||||
|
|
||||||
QmlUserScripts::QmlUserScripts(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlUserScripts::~QmlUserScripts()
|
|
||||||
{
|
|
||||||
// remove scripts added by the plugin
|
|
||||||
for (const QWebEngineScript &webEngineScript : qAsConst(m_webEngineScripts)) {
|
|
||||||
mApp->webProfile()->scripts()->remove(webEngineScript);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlUserScripts::count() const
|
|
||||||
{
|
|
||||||
return mApp->webProfile()->scripts()->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlUserScripts::size() const
|
|
||||||
{
|
|
||||||
return mApp->webProfile()->scripts()->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlUserScripts::empty() const
|
|
||||||
{
|
|
||||||
return mApp->webProfile()->scripts()->isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject *> QmlUserScripts::toQObjectList(QList<QWebEngineScript> list) const
|
|
||||||
{
|
|
||||||
QList<QObject *> userScriptList;
|
|
||||||
for (const QWebEngineScript &script : qAsConst(list)) {
|
|
||||||
QmlUserScript *userScript = new QmlUserScript();
|
|
||||||
userScript->setWebEngineScript(script);
|
|
||||||
userScriptList.append(userScript);
|
|
||||||
}
|
|
||||||
return userScriptList;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlUserScripts::contains(QObject *object) const
|
|
||||||
{
|
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
|
||||||
if (!userScript) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
QWebEngineScript webEngineScript = userScript->webEngineScript();
|
|
||||||
return mApp->webProfile()->scripts()->contains(webEngineScript);
|
|
||||||
}
|
|
||||||
|
|
||||||
QObject *QmlUserScripts::findScript(const QString &name) const
|
|
||||||
{
|
|
||||||
QWebEngineScript webEngineScript = mApp->webProfile()->scripts()->findScript(name);
|
|
||||||
QmlUserScript *qmlUserScript = new QmlUserScript();
|
|
||||||
qmlUserScript->setWebEngineScript(webEngineScript);
|
|
||||||
return qmlUserScript;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlUserScripts::findScripts(const QString &name) const
|
|
||||||
{
|
|
||||||
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->findScripts(name);
|
|
||||||
return toQObjectList(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScripts::insert(QObject *object)
|
|
||||||
{
|
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
|
||||||
if (!userScript) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QWebEngineScript webEngineScript = userScript->webEngineScript();
|
|
||||||
mApp->webProfile()->scripts()->insert(webEngineScript);
|
|
||||||
m_webEngineScripts.append(webEngineScript);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScripts::insert(const QList<QObject *> &list)
|
|
||||||
{
|
|
||||||
for (QObject *object : list) {
|
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
|
||||||
if (!userScript) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QWebEngineScript webEngineScript = userScript->webEngineScript();
|
|
||||||
mApp->webProfile()->scripts()->insert(webEngineScript);
|
|
||||||
m_webEngineScripts.append(webEngineScript);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScripts::remove(QObject *object) const
|
|
||||||
{
|
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
|
||||||
if (!userScript) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QWebEngineScript webEngineScript = userScript->webEngineScript();
|
|
||||||
mApp->webProfile()->scripts()->remove(webEngineScript);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject *> QmlUserScripts::toList() const
|
|
||||||
{
|
|
||||||
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->toList();
|
|
||||||
return toQObjectList(list);
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmluserscript.h"
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing QWebEngineScriptCollection to QML
|
|
||||||
*/
|
|
||||||
class FALKON_EXPORT QmlUserScripts : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* @brief Number of elements in the collection
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int count READ count CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Size of the collection
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int size READ size CONSTANT)
|
|
||||||
/**
|
|
||||||
* @brief Checks if the collection is empty
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool empty READ empty CONSTANT)
|
|
||||||
public:
|
|
||||||
explicit QmlUserScripts(QObject *parent = nullptr);
|
|
||||||
~QmlUserScripts();
|
|
||||||
/**
|
|
||||||
* @brief Checks if the script is in collection
|
|
||||||
* @param object of type QmlUserScript
|
|
||||||
* @return true if the the script in in collection, else false
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE bool contains(QObject *object) const;
|
|
||||||
/**
|
|
||||||
* @brief Finds a script in collection by name
|
|
||||||
* @param name of the script
|
|
||||||
* @return object of type QmlUserScript, representing the script of given name
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QObject *findScript(const QString &name) const;
|
|
||||||
/**
|
|
||||||
* @brief Finds all scripts in collection by a given name
|
|
||||||
* @return list of objects, each of type QmlUserScript, representing the script of given name
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject *> findScripts(const QString &name) const;
|
|
||||||
/**
|
|
||||||
* @brief Inserts a script into collection
|
|
||||||
* @param object of type QmlUserScript
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void insert(QObject *object);
|
|
||||||
/**
|
|
||||||
* @brief Inserts a list of scripts into collection
|
|
||||||
* @param list of objects, each of type QmlUserScript
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void insert(const QList<QObject*> &list);
|
|
||||||
/**
|
|
||||||
* @brief Removes a script from collection
|
|
||||||
* @param object of type QmlUserScript
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void remove(QObject *object) const;
|
|
||||||
/**
|
|
||||||
* @brief Gets all the scripts of the collection
|
|
||||||
* @return list of objects, each of type QmlUserScript
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject *> toList() const;
|
|
||||||
private:
|
|
||||||
int count() const;
|
|
||||||
int size() const;
|
|
||||||
bool empty() const;
|
|
||||||
QList<QWebEngineScript> m_webEngineScripts;
|
|
||||||
|
|
||||||
QList<QObject *> toQObjectList(QList<QWebEngineScript> list) const;
|
|
||||||
};
|
|
|
@ -1,148 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlwindow.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "../tabs/qmltab.h"
|
|
||||||
#include "tabwidget.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
QmlWindow::QmlWindow(BrowserWindow *window, QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_window(window)
|
|
||||||
{
|
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWindow::id() const
|
|
||||||
{
|
|
||||||
if (!mApp->windowIdHash().contains(m_window)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mApp->windowIdHash().value(m_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWindow::incognito() const
|
|
||||||
{
|
|
||||||
return mApp->isPrivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlWindow::title() const
|
|
||||||
{
|
|
||||||
if (!m_window) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_window->windowTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindowState::WindowState QmlWindow::state() const
|
|
||||||
{
|
|
||||||
if (!m_window) {
|
|
||||||
return QmlWindowState::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_window->isFullScreen()) {
|
|
||||||
return QmlWindowState::FullScreen;
|
|
||||||
} else if (m_window->isMaximized()) {
|
|
||||||
return QmlWindowState::Maximized;
|
|
||||||
} else if (m_window->isMinimized()) {
|
|
||||||
return QmlWindowState::Minimized;
|
|
||||||
} else {
|
|
||||||
return QmlWindowState::Normal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindowType::WindowType QmlWindow::type() const
|
|
||||||
{
|
|
||||||
if (!m_window) {
|
|
||||||
return QmlWindowType::OtherRestoredWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (m_window->windowType()) {
|
|
||||||
case Qz::BW_FirstAppWindow:
|
|
||||||
return QmlWindowType::FirstAppWindow;
|
|
||||||
case Qz::BW_MacFirstWindow:
|
|
||||||
return QmlWindowType::MacFirstWindow;
|
|
||||||
case Qz::BW_NewWindow:
|
|
||||||
return QmlWindowType::NewWindow;
|
|
||||||
default:
|
|
||||||
return QmlWindowType::OtherRestoredWindow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlWindow::tabs() const
|
|
||||||
{
|
|
||||||
if (!m_window) {
|
|
||||||
return QList<QObject*>();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> list;
|
|
||||||
|
|
||||||
for (WebTab *tab : m_window->tabWidget()->allTabs(true)) {
|
|
||||||
list.append(new QmlTab(tab));
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlWindow::focussed() const
|
|
||||||
{
|
|
||||||
if (!m_window) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_window->isActiveWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWindow::height() const
|
|
||||||
{
|
|
||||||
if (!m_window) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_window->height();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlWindow::width() const
|
|
||||||
{
|
|
||||||
if (!m_window) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_window->width();
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindowData::QmlWindowData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindowData::~QmlWindowData()
|
|
||||||
{
|
|
||||||
qDeleteAll(m_windows);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindow *QmlWindowData::get(BrowserWindow *window)
|
|
||||||
{
|
|
||||||
QmlWindow *qmlWindow = m_windows.value(window);
|
|
||||||
if (!qmlWindow) {
|
|
||||||
qmlWindow = new QmlWindow(window);
|
|
||||||
m_windows.insert(window, qmlWindow);
|
|
||||||
}
|
|
||||||
return qmlWindow;
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "browserwindow.h"
|
|
||||||
#include "qmlwindowstate.h"
|
|
||||||
#include "qmlwindowtype.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing Browser window to QML
|
|
||||||
*/
|
|
||||||
class QmlWindow : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief id of window
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int id READ id CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the window is private
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool incognito READ incognito CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief title of window
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString title READ title CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief [window state](@ref QmlWindowState::WindowState) of window
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QmlWindowState::WindowState state READ state CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief [window type](@ref QmlWindowType::WindowType) of window
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QmlWindowType::WindowType type READ type CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief list of all tabs of window
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QList<QObject*> tabs READ tabs CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief checks if the window is focussed
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool focussed READ focussed CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief height of window
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int height READ height CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief width of window
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int width READ width CONSTANT)
|
|
||||||
public:
|
|
||||||
QmlWindow(BrowserWindow *window = nullptr, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
private:
|
|
||||||
BrowserWindow *m_window;
|
|
||||||
|
|
||||||
int id() const;
|
|
||||||
bool incognito() const;
|
|
||||||
QString title() const;
|
|
||||||
QmlWindowState::WindowState state() const;
|
|
||||||
QmlWindowType::WindowType type() const;
|
|
||||||
QList<QObject*> tabs() const;
|
|
||||||
bool focussed() const;
|
|
||||||
int height() const;
|
|
||||||
int width() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QmlWindowData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit QmlWindowData();
|
|
||||||
~QmlWindowData();
|
|
||||||
QmlWindow *get(BrowserWindow *window);
|
|
||||||
private:
|
|
||||||
QHash<BrowserWindow*, QmlWindow*> m_windows;
|
|
||||||
};
|
|
|
@ -1,81 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlwindows.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "pluginproxy.h"
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QmlWindowData, windowData)
|
|
||||||
|
|
||||||
QmlWindows::QmlWindows(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, [this](BrowserWindow *window){
|
|
||||||
QmlWindow *qmlWindow = windowData->get(window);
|
|
||||||
emit created(qmlWindow);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(mApp->plugins(), &PluginProxy::mainWindowDeleted, this, [this](BrowserWindow *window){
|
|
||||||
QmlWindow *qmlWindow = windowData->get(window);
|
|
||||||
emit removed(qmlWindow);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindow *QmlWindows::get(int id) const
|
|
||||||
{
|
|
||||||
return windowData->get(getBrowserWindow(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindow *QmlWindows::getCurrent() const
|
|
||||||
{
|
|
||||||
return windowData->get(mApp->getWindow());
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QObject*> QmlWindows::getAll() const
|
|
||||||
{
|
|
||||||
QList<QObject*> list;
|
|
||||||
for (BrowserWindow *window : mApp->windows()) {
|
|
||||||
list.append(windowData->get(window));
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlWindow *QmlWindows::create(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
const QUrl url = QUrl::fromEncoded(map.value(QSL("url")).toString().toUtf8());
|
|
||||||
const Qz::BrowserWindowType type = Qz::BrowserWindowType(map.value(QSL("type"), QmlWindowType::NewWindow).toInt());
|
|
||||||
BrowserWindow *window = mApp->createWindow(type, url);
|
|
||||||
return windowData->get(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlWindows::remove(int windowId) const
|
|
||||||
{
|
|
||||||
BrowserWindow *window = getBrowserWindow(windowId);
|
|
||||||
window->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
BrowserWindow *QmlWindows::getBrowserWindow(int windowId) const
|
|
||||||
{
|
|
||||||
for (BrowserWindow *window : mApp->windows()) {
|
|
||||||
if (mApp->windowIdHash().value(window) == windowId) {
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qWarning() << "Unable to get window with given id";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlwindow.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing Windows API to QML
|
|
||||||
*/
|
|
||||||
class QmlWindows : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
QmlWindows(QObject *parent = nullptr);
|
|
||||||
/**
|
|
||||||
* @brief Gets a browser window
|
|
||||||
* @param Integer representing the browser window
|
|
||||||
* @return Object of type [QmlWindow](@ref QmlWindow)
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlWindow *get(int id) const;
|
|
||||||
/**
|
|
||||||
* @brief Gets the current browser window
|
|
||||||
* @return Object of type [QmlWindow](@ref QmlWindow)
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlWindow *getCurrent() const;
|
|
||||||
/**
|
|
||||||
* @brief Get all the browser window
|
|
||||||
* @return List of windows of type [QmlWindow](@ref QmlWindow)
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QList<QObject*> getAll() const;
|
|
||||||
/**
|
|
||||||
* @brief Creates a browser window
|
|
||||||
* @param A JavaScript object containing
|
|
||||||
* - url:
|
|
||||||
* The url of the first tab of the window
|
|
||||||
* - type:
|
|
||||||
* The window [type](@ref QmlWindowType)
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE QmlWindow *create(const QVariantMap &map) const;
|
|
||||||
/**
|
|
||||||
* @brief Removes a browser window
|
|
||||||
* @param Integer representing the window id
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void remove(int windowId) const;
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when a window is created
|
|
||||||
* @param Object of type [QmlWindow](@ref QmlWindow)
|
|
||||||
*/
|
|
||||||
void created(QmlWindow *window);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The signal emitted when a window is removed
|
|
||||||
* @param Object of type [QmlWindow](@ref QmlWindow)
|
|
||||||
*/
|
|
||||||
void removed(QmlWindow *window);
|
|
||||||
private:
|
|
||||||
BrowserWindow *getBrowserWindow(int windowId) const;
|
|
||||||
};
|
|
|
@ -1,42 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing window state to QML
|
|
||||||
*/
|
|
||||||
class QmlWindowState : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief The WindowState enum
|
|
||||||
*/
|
|
||||||
enum WindowState {
|
|
||||||
FullScreen, //! Represents full screen window
|
|
||||||
Maximized, //! Represents maximized window
|
|
||||||
Minimized, //! Represents minimized window
|
|
||||||
Normal, //! Represents normal window
|
|
||||||
Invalid //! Represents a invalid window
|
|
||||||
};
|
|
||||||
Q_ENUM(WindowState)
|
|
||||||
|
|
||||||
QmlWindowState(QObject *parent = nullptr);
|
|
||||||
};
|
|
|
@ -1,42 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qzcommon.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The class exposing window type to QML
|
|
||||||
*/
|
|
||||||
class QmlWindowType : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief The WindowType enum
|
|
||||||
*/
|
|
||||||
enum WindowType {
|
|
||||||
FirstAppWindow = Qz::BW_FirstAppWindow, //! Represents first app window
|
|
||||||
MacFirstWindow = Qz::BW_MacFirstWindow, //! Represents first mac window
|
|
||||||
NewWindow = Qz::BW_NewWindow, //! Represents new window
|
|
||||||
OtherRestoredWindow = Qz::BW_OtherRestoredWindow //! Represents other restored window
|
|
||||||
};
|
|
||||||
Q_ENUM(WindowType)
|
|
||||||
|
|
||||||
QmlWindowType(QObject *parent = nullptr);
|
|
||||||
};
|
|
|
@ -1,398 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlplugininterface.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "pluginproxy.h"
|
|
||||||
#include "statusbar.h"
|
|
||||||
#include "browserwindow.h"
|
|
||||||
#include "navigationbar.h"
|
|
||||||
#include "sidebar.h"
|
|
||||||
#include "api/menus/qmlmenu.h"
|
|
||||||
#include "api/menus/qmlwebhittestresult.h"
|
|
||||||
#include "api/events/qmlqzobjects.h"
|
|
||||||
#include "api/events/qmlmouseevent.h"
|
|
||||||
#include "api/events/qmlwheelevent.h"
|
|
||||||
#include "api/events/qmlkeyevent.h"
|
|
||||||
#include "api/tabs/qmltab.h"
|
|
||||||
#include "webpage.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QQuickWindow>
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QQmlContext>
|
|
||||||
|
|
||||||
QmlPluginInterface::QmlPluginInterface()
|
|
||||||
: m_settingsWindow(nullptr)
|
|
||||||
, m_qmlReusableTab(new QmlTab())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::init(InitState state, const QString &settingsPath)
|
|
||||||
{
|
|
||||||
if (!m_init.isCallable()) {
|
|
||||||
qWarning() << "Unable to call" << __FUNCTION__ << "on" << m_name << "plugin";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(state);
|
|
||||||
args.append(settingsPath);
|
|
||||||
m_init.call(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
DesktopFile QmlPluginInterface::metaData() const
|
|
||||||
{
|
|
||||||
return DesktopFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::unload()
|
|
||||||
{
|
|
||||||
if (!m_unload.isCallable()) {
|
|
||||||
qWarning() << "Unable to call" << __FUNCTION__ << "on" << m_name << "plugin";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_unload.call();
|
|
||||||
|
|
||||||
for (QObject *childItem : m_childItems) {
|
|
||||||
childItem->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit qmlPluginUnloaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::testPlugin()
|
|
||||||
{
|
|
||||||
if (!m_testPlugin.isCallable()) {
|
|
||||||
qWarning() << "Unable to call" << __FUNCTION__ << "on" << m_name << "plugin";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue ret = m_testPlugin.call();
|
|
||||||
return ret.toBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::populateWebViewMenu(QMenu *menu, WebView *webview, const WebHitTestResult &webHitTestResult)
|
|
||||||
{
|
|
||||||
Q_UNUSED(webview)
|
|
||||||
|
|
||||||
if (!m_populateWebViewMenu.isCallable()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlMenu *qmlMenu = new QmlMenu(menu);
|
|
||||||
qmlMenu->setPluginPath(m_engine->rootContext()->contextProperty("__path__").toString());
|
|
||||||
QmlWebHitTestResult *qmlWebHitTestResult = new QmlWebHitTestResult(webHitTestResult);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(m_engine->newQObject(qmlMenu));
|
|
||||||
args.append(m_engine->newQObject(qmlWebHitTestResult));
|
|
||||||
m_populateWebViewMenu.call(args);
|
|
||||||
menu->addSeparator();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::showSettings(QWidget *parent)
|
|
||||||
{
|
|
||||||
if (!m_settingsWindow) {
|
|
||||||
qWarning() << "No dialog to show";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQuickWindow *window = qobject_cast<QQuickWindow*>(m_settingsWindow->create(m_settingsWindow->creationContext()));
|
|
||||||
if (!window) {
|
|
||||||
qWarning() << "Unable to created window";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *widget = QWidget::createWindowContainer(window);
|
|
||||||
widget->setFixedSize(window->size());
|
|
||||||
widget->show();
|
|
||||||
QzTools::centerWidgetToParent(widget, parent);
|
|
||||||
connect(widget, &QWidget::destroyed, window, &QQuickWindow::destroy);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::mouseDoubleClick(Qz::ObjectName type, QObject *obj, QMouseEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(obj)
|
|
||||||
if (!m_mouseDoubleClick.isCallable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto qmlMouseEvent = new QmlMouseEvent(event);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(QmlQzObjects::ObjectName(type));
|
|
||||||
args.append(m_engine->newQObject(qmlMouseEvent));
|
|
||||||
m_mouseDoubleClick.call(args);
|
|
||||||
qmlMouseEvent->makeNull();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::mousePress(Qz::ObjectName type, QObject *obj, QMouseEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(obj)
|
|
||||||
if (!m_mousePress.isCallable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto qmlMouseEvent = new QmlMouseEvent(event);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(QmlQzObjects::ObjectName(type));
|
|
||||||
args.append(m_engine->newQObject(qmlMouseEvent));
|
|
||||||
m_mousePress.call(args);
|
|
||||||
qmlMouseEvent->makeNull();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::mouseRelease(Qz::ObjectName type, QObject *obj, QMouseEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(obj)
|
|
||||||
if (!m_mouseRelease.isCallable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto qmlMouseEvent = new QmlMouseEvent(event);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(QmlQzObjects::ObjectName(type));
|
|
||||||
args.append(m_engine->newQObject(qmlMouseEvent));
|
|
||||||
m_mouseRelease.call(args);
|
|
||||||
qmlMouseEvent->makeNull();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::mouseMove(Qz::ObjectName type, QObject *obj, QMouseEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(obj)
|
|
||||||
if (!m_mouseMove.isCallable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto qmlMouseEvent = new QmlMouseEvent(event);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(QmlQzObjects::ObjectName(type));
|
|
||||||
args.append(m_engine->newQObject(qmlMouseEvent));
|
|
||||||
m_mouseMove.call(args);
|
|
||||||
qmlMouseEvent->makeNull();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::wheelEvent(Qz::ObjectName type, QObject *obj, QWheelEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(obj)
|
|
||||||
if (!m_wheelEvent.isCallable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto qmlWheelEvent = new QmlWheelEvent(event);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(QmlQzObjects::ObjectName(type));
|
|
||||||
args.append(m_engine->newQObject(qmlWheelEvent));
|
|
||||||
m_wheelEvent.call(args);
|
|
||||||
qmlWheelEvent->makeNull();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::keyPress(Qz::ObjectName type, QObject *obj, QKeyEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(obj)
|
|
||||||
if (!m_keyPress.isCallable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto qmlKeyEvent = new QmlKeyEvent(event);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(QmlQzObjects::ObjectName(type));
|
|
||||||
args.append(m_engine->newQObject(qmlKeyEvent));
|
|
||||||
m_keyPress.call(args);
|
|
||||||
qmlKeyEvent->makeNull();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::keyRelease(Qz::ObjectName type, QObject *obj, QKeyEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(obj)
|
|
||||||
if (!m_keyRelease.isCallable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto qmlKeyEvent = new QmlKeyEvent(event);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(QmlQzObjects::ObjectName(type));
|
|
||||||
args.append(m_engine->newQObject(qmlKeyEvent));
|
|
||||||
m_keyRelease.call(args);
|
|
||||||
qmlKeyEvent->makeNull();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlPluginInterface::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
|
|
||||||
{
|
|
||||||
if (!m_acceptNavigationRequest.isCallable()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
m_qmlReusableTab->setWebPage(page);
|
|
||||||
QJSValueList args;
|
|
||||||
args.append(m_engine->newQObject(m_qmlReusableTab));
|
|
||||||
args.append(QString::fromUtf8(url.toEncoded()));
|
|
||||||
args.append(type);
|
|
||||||
args.append(isMainFrame);
|
|
||||||
return m_acceptNavigationRequest.call(args).toBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readInit() const
|
|
||||||
{
|
|
||||||
return m_init;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setInit(const QJSValue &init)
|
|
||||||
{
|
|
||||||
m_init = init;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readUnload() const
|
|
||||||
{
|
|
||||||
return m_unload;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setUnload(const QJSValue &unload)
|
|
||||||
{
|
|
||||||
m_unload = unload;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readTestPlugin() const
|
|
||||||
{
|
|
||||||
return m_testPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setTestPlugin(const QJSValue &testPlugin)
|
|
||||||
{
|
|
||||||
m_testPlugin = testPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setEngine(QQmlEngine *engine)
|
|
||||||
{
|
|
||||||
m_engine = engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readPopulateWebViewMenu() const
|
|
||||||
{
|
|
||||||
return m_populateWebViewMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setPopulateWebViewMenu(const QJSValue &value)
|
|
||||||
{
|
|
||||||
m_populateWebViewMenu = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQmlComponent *QmlPluginInterface::settingsWindow() const
|
|
||||||
{
|
|
||||||
return m_settingsWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setSettingsWindow(QQmlComponent *settingsWindow)
|
|
||||||
{
|
|
||||||
m_settingsWindow = settingsWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readMouseDoubleClick() const
|
|
||||||
{
|
|
||||||
return m_mouseDoubleClick;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setMouseDoubleClick(const QJSValue &mouseDoubleClick)
|
|
||||||
{
|
|
||||||
m_mouseDoubleClick = mouseDoubleClick;
|
|
||||||
mApp->plugins()->registerAppEventHandler(PluginProxy::MouseDoubleClickHandler, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readMousePress() const
|
|
||||||
{
|
|
||||||
return m_mousePress;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setMousePress(const QJSValue &mousePress)
|
|
||||||
{
|
|
||||||
m_mousePress = mousePress;
|
|
||||||
mApp->plugins()->registerAppEventHandler(PluginProxy::MousePressHandler, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readMouseRelease() const
|
|
||||||
{
|
|
||||||
return m_mouseRelease;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setMouseRelease(const QJSValue &mouseRelease)
|
|
||||||
{
|
|
||||||
m_mouseRelease = mouseRelease;
|
|
||||||
mApp->plugins()->registerAppEventHandler(PluginProxy::MouseReleaseHandler, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readMouseMove() const
|
|
||||||
{
|
|
||||||
return m_mouseMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setMouseMove(const QJSValue &mouseMove)
|
|
||||||
{
|
|
||||||
m_mouseMove = mouseMove;
|
|
||||||
mApp->plugins()->registerAppEventHandler(PluginProxy::MouseMoveHandler, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readWheelEvent() const
|
|
||||||
{
|
|
||||||
return m_wheelEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setWheelEvent(const QJSValue &wheelEvent)
|
|
||||||
{
|
|
||||||
m_wheelEvent = wheelEvent;
|
|
||||||
mApp->plugins()->registerAppEventHandler(PluginProxy::WheelEventHandler, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readKeyPress() const
|
|
||||||
{
|
|
||||||
return m_keyPress;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setKeyPress(const QJSValue &keyPress)
|
|
||||||
{
|
|
||||||
m_keyPress = keyPress;
|
|
||||||
mApp->plugins()->registerAppEventHandler(PluginProxy::KeyPressHandler, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readKeyRelease() const
|
|
||||||
{
|
|
||||||
return m_keyRelease;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setKeyRelease(const QJSValue &keyRelease)
|
|
||||||
{
|
|
||||||
m_keyRelease = keyRelease;
|
|
||||||
mApp->plugins()->registerAppEventHandler(PluginProxy::KeyReleaseHandler, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlPluginInterface::readAcceptNavigationRequest() const
|
|
||||||
{
|
|
||||||
return m_acceptNavigationRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginInterface::setAcceptNavigationRequest(const QJSValue &acceptNavigationRequest)
|
|
||||||
{
|
|
||||||
m_acceptNavigationRequest = acceptNavigationRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQmlListProperty<QObject> QmlPluginInterface::childItems()
|
|
||||||
{
|
|
||||||
return QQmlListProperty<QObject>(this, m_childItems);
|
|
||||||
}
|
|
|
@ -1,122 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QJSValue>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QQmlComponent>
|
|
||||||
|
|
||||||
#include "desktopfile.h"
|
|
||||||
#include "plugininterface.h"
|
|
||||||
|
|
||||||
class QmlTab;
|
|
||||||
|
|
||||||
class QmlPluginInterface : public QObject, public PluginInterface
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_INTERFACES(PluginInterface)
|
|
||||||
Q_ENUM(InitState)
|
|
||||||
Q_PROPERTY(QJSValue init READ readInit WRITE setInit)
|
|
||||||
Q_PROPERTY(QJSValue unload READ readUnload WRITE setUnload)
|
|
||||||
Q_PROPERTY(QJSValue testPlugin READ readTestPlugin WRITE setTestPlugin)
|
|
||||||
Q_PROPERTY(QJSValue populateWebViewMenu READ readPopulateWebViewMenu WRITE setPopulateWebViewMenu)
|
|
||||||
Q_PROPERTY(QQmlComponent* settingsWindow READ settingsWindow WRITE setSettingsWindow)
|
|
||||||
Q_PROPERTY(QJSValue mouseDoubleClick READ readMouseDoubleClick WRITE setMouseDoubleClick)
|
|
||||||
Q_PROPERTY(QJSValue mousePress READ readMousePress WRITE setMousePress)
|
|
||||||
Q_PROPERTY(QJSValue mouseRelease READ readMouseRelease WRITE setMouseRelease)
|
|
||||||
Q_PROPERTY(QJSValue mouseMove READ readMouseMove WRITE setMouseMove)
|
|
||||||
Q_PROPERTY(QJSValue wheelEvent READ readWheelEvent WRITE setWheelEvent)
|
|
||||||
Q_PROPERTY(QJSValue keyPress READ readKeyPress WRITE setKeyPress)
|
|
||||||
Q_PROPERTY(QJSValue keyRelease READ readKeyRelease WRITE setKeyRelease)
|
|
||||||
Q_PROPERTY(QJSValue acceptNavigationRequest READ readAcceptNavigationRequest WRITE setAcceptNavigationRequest)
|
|
||||||
Q_PROPERTY(QQmlListProperty<QObject> childItems READ childItems)
|
|
||||||
Q_CLASSINFO("DefaultProperty", "childItems")
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit QmlPluginInterface();
|
|
||||||
DesktopFile metaData() const;
|
|
||||||
void init(InitState state, const QString &settingsPath);
|
|
||||||
void unload();
|
|
||||||
bool testPlugin();
|
|
||||||
void setEngine(QQmlEngine *engine);
|
|
||||||
void setName(const QString &name);
|
|
||||||
void populateWebViewMenu(QMenu *menu, WebView *webview, const WebHitTestResult &webHitTestResult) override;
|
|
||||||
void showSettings(QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
bool mouseDoubleClick(Qz::ObjectName type, QObject *obj, QMouseEvent *event) override;
|
|
||||||
bool mousePress(Qz::ObjectName type, QObject *obj, QMouseEvent *event) override;
|
|
||||||
bool mouseRelease(Qz::ObjectName type, QObject *obj, QMouseEvent *event) override;
|
|
||||||
bool mouseMove(Qz::ObjectName type, QObject *obj, QMouseEvent *event) override;
|
|
||||||
|
|
||||||
bool wheelEvent(Qz::ObjectName type, QObject *obj, QWheelEvent *event) override;
|
|
||||||
|
|
||||||
bool keyPress(Qz::ObjectName type, QObject *obj, QKeyEvent *event) override;
|
|
||||||
bool keyRelease(Qz::ObjectName type, QObject *obj, QKeyEvent *event) override;
|
|
||||||
|
|
||||||
bool acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void qmlPluginUnloaded();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QQmlEngine *m_engine = nullptr;
|
|
||||||
QString m_name;
|
|
||||||
QJSValue m_init;
|
|
||||||
QJSValue m_unload;
|
|
||||||
QJSValue m_testPlugin;
|
|
||||||
QJSValue m_populateWebViewMenu;
|
|
||||||
QQmlComponent *m_settingsWindow = nullptr;
|
|
||||||
QJSValue m_mouseDoubleClick;
|
|
||||||
QJSValue m_mousePress;
|
|
||||||
QJSValue m_mouseRelease;
|
|
||||||
QJSValue m_mouseMove;
|
|
||||||
QJSValue m_wheelEvent;
|
|
||||||
QJSValue m_keyPress;
|
|
||||||
QJSValue m_keyRelease;
|
|
||||||
QJSValue m_acceptNavigationRequest;
|
|
||||||
QList<QObject*> m_childItems;
|
|
||||||
QmlTab *m_qmlReusableTab = nullptr;
|
|
||||||
|
|
||||||
QJSValue readInit() const;
|
|
||||||
void setInit(const QJSValue &init);
|
|
||||||
QJSValue readUnload() const;
|
|
||||||
void setUnload(const QJSValue &unload);
|
|
||||||
QJSValue readTestPlugin() const;
|
|
||||||
void setTestPlugin(const QJSValue &testPlugin);
|
|
||||||
QJSValue readPopulateWebViewMenu() const;
|
|
||||||
void setPopulateWebViewMenu(const QJSValue &value);
|
|
||||||
QQmlComponent *settingsWindow() const;
|
|
||||||
void setSettingsWindow(QQmlComponent *settingsWindow);
|
|
||||||
QJSValue readMouseDoubleClick() const;
|
|
||||||
void setMouseDoubleClick(const QJSValue &mouseDoubleClick);
|
|
||||||
QJSValue readMousePress() const;
|
|
||||||
void setMousePress(const QJSValue &mousePress);
|
|
||||||
QJSValue readMouseRelease() const;
|
|
||||||
void setMouseRelease(const QJSValue &mouseRelease);
|
|
||||||
QJSValue readMouseMove() const;
|
|
||||||
void setMouseMove(const QJSValue &mouseMove);
|
|
||||||
QJSValue readWheelEvent() const;
|
|
||||||
void setWheelEvent(const QJSValue &wheelEvent);
|
|
||||||
QJSValue readKeyPress() const;
|
|
||||||
void setKeyPress(const QJSValue &keyPress);
|
|
||||||
QJSValue readKeyRelease() const;
|
|
||||||
void setKeyRelease(const QJSValue &keyRelease);
|
|
||||||
QJSValue readAcceptNavigationRequest() const;
|
|
||||||
void setAcceptNavigationRequest(const QJSValue &acceptNavigationRequest);
|
|
||||||
QQmlListProperty<QObject> childItems();
|
|
||||||
};
|
|
|
@ -1,65 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlpluginloader.h"
|
|
||||||
#include "qmlengine.h"
|
|
||||||
#include <QQmlContext>
|
|
||||||
|
|
||||||
QmlPluginLoader::QmlPluginLoader(const QString &path)
|
|
||||||
{
|
|
||||||
m_path = path;
|
|
||||||
initEngineAndComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginLoader::createComponent()
|
|
||||||
{
|
|
||||||
m_interface = qobject_cast<QmlPluginInterface*>(m_component->create(m_component->creationContext()));
|
|
||||||
|
|
||||||
if (!m_interface) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_interface->setEngine(m_engine);
|
|
||||||
connect(m_interface, &QmlPluginInterface::qmlPluginUnloaded, this, [this]{
|
|
||||||
delete m_component;
|
|
||||||
delete m_engine;
|
|
||||||
initEngineAndComponent();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
QQmlComponent *QmlPluginLoader::component() const
|
|
||||||
{
|
|
||||||
return m_component;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlPluginInterface *QmlPluginLoader::instance() const
|
|
||||||
{
|
|
||||||
return m_interface;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginLoader::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_interface->setName(name);
|
|
||||||
m_engine->setExtensionName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlPluginLoader::initEngineAndComponent()
|
|
||||||
{
|
|
||||||
m_engine = new QmlEngine();
|
|
||||||
m_component = new QQmlComponent(m_engine, m_path);
|
|
||||||
m_engine->setExtensionPath(m_path);
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 <QQmlEngine>
|
|
||||||
#include <QQmlComponent>
|
|
||||||
|
|
||||||
#include "qmlplugininterface.h"
|
|
||||||
|
|
||||||
class QmlEngine;
|
|
||||||
|
|
||||||
class QmlPluginLoader : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlPluginLoader(const QString &path);
|
|
||||||
void createComponent();
|
|
||||||
QQmlComponent *component() const;
|
|
||||||
QmlPluginInterface *instance() const;
|
|
||||||
void setName(const QString &name);
|
|
||||||
private:
|
|
||||||
QString m_path;
|
|
||||||
QmlEngine *m_engine;
|
|
||||||
QQmlComponent *m_component;
|
|
||||||
QmlPluginInterface *m_interface;
|
|
||||||
|
|
||||||
void initEngineAndComponent();
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QmlPluginLoader *)
|
|
|
@ -1,233 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@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 "qmlplugins.h"
|
|
||||||
#include "qmlplugininterface.h"
|
|
||||||
#include "qmlengine.h"
|
|
||||||
#include "api/bookmarks/qmlbookmarktreenode.h"
|
|
||||||
#include "api/bookmarks/qmlbookmarks.h"
|
|
||||||
#include "api/topsites/qmlmostvisitedurl.h"
|
|
||||||
#include "api/topsites/qmltopsites.h"
|
|
||||||
#include "api/history/qmlhistoryitem.h"
|
|
||||||
#include "api/history/qmlhistory.h"
|
|
||||||
#include "api/cookies/qmlcookie.h"
|
|
||||||
#include "api/cookies/qmlcookies.h"
|
|
||||||
#include "api/tabs/qmltab.h"
|
|
||||||
#include "api/tabs/qmltabs.h"
|
|
||||||
#include "api/notifications/qmlnotifications.h"
|
|
||||||
#include "api/clipboard/qmlclipboard.h"
|
|
||||||
#include "api/windows/qmlwindow.h"
|
|
||||||
#include "api/windows/qmlwindows.h"
|
|
||||||
#include "api/windows/qmlwindowstate.h"
|
|
||||||
#include "api/windows/qmlwindowtype.h"
|
|
||||||
#include "api/browseraction/qmlbrowseraction.h"
|
|
||||||
#include "api/sidebar/qmlsidebar.h"
|
|
||||||
#include "api/menus/qmlmenu.h"
|
|
||||||
#include "api/menus/qmlaction.h"
|
|
||||||
#include "api/menus/qmlwebhittestresult.h"
|
|
||||||
#include "api/settings/qmlsettings.h"
|
|
||||||
#include "api/events/qmlqzobjects.h"
|
|
||||||
#include "api/events/qmlmouseevent.h"
|
|
||||||
#include "api/events/qmlwheelevent.h"
|
|
||||||
#include "api/userscript/qmluserscript.h"
|
|
||||||
#include "api/userscript/qmluserscripts.h"
|
|
||||||
#include "api/userscript/qmlexternaljsobject.h"
|
|
||||||
#include "api/extensionscheme/qmlextensionscheme.h"
|
|
||||||
#include "api/extensionscheme/qmlwebengineurlrequestjob.h"
|
|
||||||
#include "api/fileutils/qmlfileutils.h"
|
|
||||||
|
|
||||||
#include "../config.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBINTL
|
|
||||||
#include "qml/api/i18n/qmli18n.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QQmlEngine>
|
|
||||||
#include <QQmlContext>
|
|
||||||
|
|
||||||
// static
|
|
||||||
void QmlPlugins::registerQmlTypes()
|
|
||||||
{
|
|
||||||
// PluginInterface
|
|
||||||
qmlRegisterType<QmlPluginInterface>("org.kde.falkon", 1, 0, "PluginInterface");
|
|
||||||
|
|
||||||
// Bookmarks
|
|
||||||
qmlRegisterUncreatableType<QmlBookmarkTreeNode>("org.kde.falkon", 1, 0, "BookmarkTreeNode", "Unable to register type: BookmarkTreeNode");
|
|
||||||
|
|
||||||
qmlRegisterSingletonType<QmlBookmarks>("org.kde.falkon", 1, 0, "Bookmarks", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlBookmarks();
|
|
||||||
});
|
|
||||||
|
|
||||||
// TopSites
|
|
||||||
qmlRegisterUncreatableType<QmlMostVisitedUrl>("org.kde.falkon", 1, 0, "MostVisitedURL", "Unable to register type: MostVisitedURL");
|
|
||||||
|
|
||||||
qmlRegisterSingletonType<QmlTopSites>("org.kde.falkon", 1, 0, "TopSites", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlTopSites();
|
|
||||||
});
|
|
||||||
|
|
||||||
// History
|
|
||||||
qmlRegisterUncreatableType<QmlHistoryItem>("org.kde.falkon", 1, 0, "HistoryItem", "Unable to register type: HistoryItem");
|
|
||||||
|
|
||||||
qmlRegisterSingletonType<QmlHistory>("org.kde.falkon", 1, 0, "History", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlHistory();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Cookies
|
|
||||||
qmlRegisterUncreatableType<QmlCookie>("org.kde.falkon", 1, 0, "Cookie", "Unable to register type: Cookie");
|
|
||||||
|
|
||||||
qmlRegisterSingletonType<QmlCookies>("org.kde.falkon", 1, 0, "Cookies", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlCookies();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Tabs
|
|
||||||
qmlRegisterUncreatableType<QmlTab>("org.kde.falkon", 1, 0, "Tab", "Unable to register type: Tab");
|
|
||||||
|
|
||||||
qmlRegisterSingletonType<QmlTabs>("org.kde.falkon", 1, 0, "Tabs", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlTabs();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Notifications
|
|
||||||
qmlRegisterSingletonType<QmlNotifications>("org.kde.falkon", 1, 0, "Notifications", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
QmlEngine *qmlEngine = dynamic_cast<QmlEngine *>(engine);
|
|
||||||
if (!qmlEngine) {
|
|
||||||
qWarning() << "Unable to cast QQmlEngine * to QmlEngine *";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
QString filePath = qmlEngine->extensionPath();
|
|
||||||
|
|
||||||
auto *object = new QmlNotifications();
|
|
||||||
object->setPluginPath(filePath);
|
|
||||||
return object;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clipboard
|
|
||||||
qmlRegisterSingletonType<QmlClipboard>("org.kde.falkon", 1, 0, "Clipboard", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlClipboard();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Windows
|
|
||||||
qmlRegisterUncreatableType<QmlWindow>("org.kde.falkon", 1, 0, "Window", "Unable to register type: Window");
|
|
||||||
|
|
||||||
qmlRegisterUncreatableType<QmlWindowState>("org.kde.falkon", 1, 0, "WindowState", "Unable to register type: WindowState");
|
|
||||||
|
|
||||||
qmlRegisterUncreatableType<QmlWindowType>("org.kde.falkon", 1, 0, "WindowType", "Unable to register type: WindowType");
|
|
||||||
|
|
||||||
qmlRegisterSingletonType<QmlWindows>("org.kde.falkon", 1, 0, "Windows", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlWindows();
|
|
||||||
});
|
|
||||||
|
|
||||||
// BrowserAction
|
|
||||||
qmlRegisterType<QmlBrowserAction>("org.kde.falkon", 1, 0, "BrowserAction");
|
|
||||||
|
|
||||||
// SideBar
|
|
||||||
qmlRegisterType<QmlSideBar>("org.kde.falkon", 1, 0, "SideBar");
|
|
||||||
|
|
||||||
// Menu
|
|
||||||
qmlRegisterUncreatableType<QmlMenu>("org.kde.falkon", 1, 0, "Menu", "Unable to register type: Menu");
|
|
||||||
|
|
||||||
// Action
|
|
||||||
qmlRegisterUncreatableType<QmlAction>("org.kde.falkon", 1, 0, "Action", "Unable to register type: Action");
|
|
||||||
|
|
||||||
// WebHitTestResult
|
|
||||||
qmlRegisterUncreatableType<QmlWebHitTestResult>("org.kde.falkon", 1, 0, "WebHitTestResult", "Unable to register type: WebHitTestResult");
|
|
||||||
|
|
||||||
// Settings
|
|
||||||
qmlRegisterType<QmlSettings>("org.kde.falkon", 1, 0, "Settings");
|
|
||||||
|
|
||||||
// Qz::Objects
|
|
||||||
qmlRegisterUncreatableType<QmlQzObjects>("org.kde.falkon", 1, 0, "QzObjects", "Unable to register type: QzObjects");
|
|
||||||
|
|
||||||
// MouseEvents
|
|
||||||
qmlRegisterUncreatableType<QmlMouseEvent>("org.kde.falkon", 1, 0, "MouseEvent", "Unable to register type: MouseEvent");
|
|
||||||
|
|
||||||
// WheelEvents
|
|
||||||
qmlRegisterUncreatableType<QmlWheelEvent>("org.kde.falkon", 1, 0, "WheelEvent", "Unable to register type: WheelEvent");
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBINTL
|
|
||||||
// i18n
|
|
||||||
qmlRegisterSingletonType<QmlI18n>("org.kde.falkon", 1, 0, "I18n", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
QmlEngine *qmlEngine = dynamic_cast<QmlEngine *>(engine);
|
|
||||||
if (!qmlEngine) {
|
|
||||||
qWarning() << "Unable to cast QQmlEngine * to QmlEngine *";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
QString pluginName = qmlEngine->extensionName();
|
|
||||||
return new QmlI18n(pluginName);
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// UserScripts
|
|
||||||
qmlRegisterType<QmlUserScript>("org.kde.falkon", 1, 0, "UserScript");
|
|
||||||
|
|
||||||
qmlRegisterSingletonType<QmlUserScripts>("org.kde.falkon", 1, 0, "UserScripts", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlUserScripts();
|
|
||||||
});
|
|
||||||
|
|
||||||
qmlRegisterSingletonType<QmlExternalJsObject>("org.kde.falkon", 1, 0, "ExternalJsObject", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(engine)
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
return new QmlExternalJsObject();
|
|
||||||
});
|
|
||||||
|
|
||||||
// ExtensionScheme
|
|
||||||
qmlRegisterType<QmlExtensionScheme>("org.kde.falkon", 1, 0, "ExtensionScheme");
|
|
||||||
|
|
||||||
qmlRegisterUncreatableType<QmlWebEngineUrlRequestJob>("org.kde.falkon", 1, 0, "WebEngineUrlRequestJob", "Unable to register type: WebEngineUrlRequestJob");
|
|
||||||
|
|
||||||
// FileUtils
|
|
||||||
qmlRegisterSingletonType<QmlFileUtils>("org.kde.falkon", 1, 0, "FileUtils", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
|
||||||
Q_UNUSED(scriptEngine)
|
|
||||||
|
|
||||||
QmlEngine *qmlEngine = dynamic_cast<QmlEngine *>(engine);
|
|
||||||
if (!qmlEngine) {
|
|
||||||
qWarning() << "Unable to cast QQmlEngine * to QmlEngine *";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
QString filePath = qmlEngine->extensionPath();
|
|
||||||
|
|
||||||
return new QmlFileUtils(filePath);
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -16,6 +16,7 @@ Name[nl]=Auto-schuiven
|
||||||
Name[nn]=Autorulling
|
Name[nn]=Autorulling
|
||||||
Name[pl]=Samoprzewijanie
|
Name[pl]=Samoprzewijanie
|
||||||
Name[pt]=Deslocamento Automático
|
Name[pt]=Deslocamento Automático
|
||||||
|
Name[pt_BR]=AutoScroll
|
||||||
Name[sv]=Rulla automatiskt
|
Name[sv]=Rulla automatiskt
|
||||||
Name[uk]=Автогортання
|
Name[uk]=Автогортання
|
||||||
Name[x-test]=xxAutoScrollxx
|
Name[x-test]=xxAutoScrollxx
|
||||||
|
@ -36,6 +37,7 @@ Comment[nl]=Bied ondersteuning voor auto-schuiven met middelste muisknop
|
||||||
Comment[nn]=Gjev støtte for autorulling med midtknappen på musa
|
Comment[nn]=Gjev støtte for autorulling med midtknappen på musa
|
||||||
Comment[pl]=Zapewnia obsługę samoprzewijania na środkowy przycisk myszy
|
Comment[pl]=Zapewnia obsługę samoprzewijania na środkowy przycisk myszy
|
||||||
Comment[pt]=Oferece o suporte para o deslocamento automático com o botão do meio do rato
|
Comment[pt]=Oferece o suporte para o deslocamento automático com o botão do meio do rato
|
||||||
|
Comment[pt_BR]=Fornece suporte para rolagem automática com o botão do meio do mouse
|
||||||
Comment[sv]=Tillhandahåller stöd för automatisk rullning med musens mittenknapp
|
Comment[sv]=Tillhandahåller stöd för automatisk rullning med musens mittenknapp
|
||||||
Comment[uk]=Забезпечує підтримку автогортання середньою кнопкою миші
|
Comment[uk]=Забезпечує підтримку автогортання середньою кнопкою миші
|
||||||
Comment[x-test]=xxProvides support for autoscroll with middle mouse buttonxx
|
Comment[x-test]=xxProvides support for autoscroll with middle mouse buttonxx
|
||||||
|
|
|
@ -15,6 +15,7 @@ Name[nl]=GNOME-sleutelbos wachtwoorden
|
||||||
Name[nn]=Passord for Gnome-nøkkelring
|
Name[nn]=Passord for Gnome-nøkkelring
|
||||||
Name[pl]=Hasła pęku kluczy Gnome
|
Name[pl]=Hasła pęku kluczy Gnome
|
||||||
Name[pt]=Senhas no Porta-Chaves do Gnome
|
Name[pt]=Senhas no Porta-Chaves do Gnome
|
||||||
|
Name[pt_BR]=Senhas do chaveiro do Gnome
|
||||||
Name[sv]=Gnome-nyckelring lösenord
|
Name[sv]=Gnome-nyckelring lösenord
|
||||||
Name[uk]=Паролі сховища ключів Gnome
|
Name[uk]=Паролі сховища ключів Gnome
|
||||||
Name[x-test]=xxGnome Keyring Passwordsxx
|
Name[x-test]=xxGnome Keyring Passwordsxx
|
||||||
|
@ -35,6 +36,7 @@ Comment[nl]=Biedt ondersteuning voor opslaan van GNOME-sleutelbos wachtwoorden
|
||||||
Comment[nn]=Gjev støtte for lagring av passord i Gnome-nøkkelringen
|
Comment[nn]=Gjev støtte for lagring av passord i Gnome-nøkkelringen
|
||||||
Comment[pl]=Zapewnia obsługę przechowywania haseł w pęku kluczy gnome
|
Comment[pl]=Zapewnia obsługę przechowywania haseł w pęku kluczy gnome
|
||||||
Comment[pt]=Oferece o suporte para gravar as senhas no 'gnome-keyring'
|
Comment[pt]=Oferece o suporte para gravar as senhas no 'gnome-keyring'
|
||||||
|
Comment[pt_BR]=Fornece suporte para armazenar senhas no gnome-keyring
|
||||||
Comment[sv]=Tillhandahåller stöd för att lagra lösenord i Gnome-nyckelring
|
Comment[sv]=Tillhandahåller stöd för att lagra lösenord i Gnome-nyckelring
|
||||||
Comment[uk]=Забезпечує підтримку зберігання паролів у gnome-keyring
|
Comment[uk]=Забезпечує підтримку зберігання паролів у gnome-keyring
|
||||||
Comment[x-test]=xxProvides support for storing passwords in gnome-keyringxx
|
Comment[x-test]=xxProvides support for storing passwords in gnome-keyringxx
|
||||||
|
|
|
@ -16,6 +16,7 @@ Name[nl]=GreaseMonkey
|
||||||
Name[nn]=GreaseMonkey
|
Name[nn]=GreaseMonkey
|
||||||
Name[pl]=GreaseMonkey
|
Name[pl]=GreaseMonkey
|
||||||
Name[pt]=GreaseMonkey
|
Name[pt]=GreaseMonkey
|
||||||
|
Name[pt_BR]=GreaseMonkey
|
||||||
Name[sv]=GreaseMonkey
|
Name[sv]=GreaseMonkey
|
||||||
Name[uk]=GreaseMonkey
|
Name[uk]=GreaseMonkey
|
||||||
Name[x-test]=xxGreaseMonkeyxx
|
Name[x-test]=xxGreaseMonkeyxx
|
||||||
|
@ -36,6 +37,7 @@ Comment[nl]=Biedt ondersteuning voor scripts van gebruikers
|
||||||
Comment[nn]=Gjev støtte for brukarskript
|
Comment[nn]=Gjev støtte for brukarskript
|
||||||
Comment[pl]=Zapewnia obsługę dla skryptów użytkownika
|
Comment[pl]=Zapewnia obsługę dla skryptów użytkownika
|
||||||
Comment[pt]=Oferece o suporte para programas do utilizador
|
Comment[pt]=Oferece o suporte para programas do utilizador
|
||||||
|
Comment[pt_BR]=Fornece suporte para scripts do usuário
|
||||||
Comment[sv]=Tillhandahåller stöd för användarskript
|
Comment[sv]=Tillhandahåller stöd för användarskript
|
||||||
Comment[uk]=Забезпечує підтримку скриптів користувача
|
Comment[uk]=Забезпечує підтримку скриптів користувача
|
||||||
Comment[x-test]=xxProvides support for userscriptsxx
|
Comment[x-test]=xxProvides support for userscriptsxx
|
||||||
|
|
|
@ -6,6 +6,7 @@ Name[cs]=Integrace KDE Frameworks
|
||||||
Name[da]=KDE Frameworks integration
|
Name[da]=KDE Frameworks integration
|
||||||
Name[en_GB]=KDE Frameworks Integration
|
Name[en_GB]=KDE Frameworks Integration
|
||||||
Name[es]=Integración con la infraestructura de KDE
|
Name[es]=Integración con la infraestructura de KDE
|
||||||
|
Name[fi]=KDE Frameworks -integrointi
|
||||||
Name[fr]=Intégration à KDE Frameworks
|
Name[fr]=Intégration à KDE Frameworks
|
||||||
Name[gl]=Integración coas infraestruturas de KDE
|
Name[gl]=Integración coas infraestruturas de KDE
|
||||||
Name[id]=KDE Frameworks Integration
|
Name[id]=KDE Frameworks Integration
|
||||||
|
@ -24,6 +25,7 @@ Comment[cs]=Poskytuje podporu pro KIO a ukládání hesel v Kwallet
|
||||||
Comment[da]=Giver understøttelse af KIO og lagring af adgangskoder i KWallet
|
Comment[da]=Giver understøttelse af KIO og lagring af adgangskoder i KWallet
|
||||||
Comment[en_GB]=Provides support for KIO and storing passwords in KWallet
|
Comment[en_GB]=Provides support for KIO and storing passwords in KWallet
|
||||||
Comment[es]=Implementa KIO y almacenamiento de contraseñas en KWallet
|
Comment[es]=Implementa KIO y almacenamiento de contraseñas en KWallet
|
||||||
|
Comment[fi]=Tarjoaa KIO-tuen sekä salasanojen tallentamisen KWalletiin
|
||||||
Comment[fr]=Prise en charge de KIO et de l'enregistrement de mots de passe dans KWallet
|
Comment[fr]=Prise en charge de KIO et de l'enregistrement de mots de passe dans KWallet
|
||||||
Comment[gl]=Fornece compatibilidade con KIO e permite almacenar contrasinais en KWallet
|
Comment[gl]=Fornece compatibilidade con KIO e permite almacenar contrasinais en KWallet
|
||||||
Comment[id]=Menyediakan dukungan untuk KIO dan menyimpan sandi dalam KWallet
|
Comment[id]=Menyediakan dukungan untuk KIO dan menyimpan sandi dalam KWallet
|
||||||
|
|
|
@ -16,6 +16,7 @@ Name[nl]=Muisgebaren
|
||||||
Name[nn]=Muserørsler
|
Name[nn]=Muserørsler
|
||||||
Name[pl]=Gesty myszy
|
Name[pl]=Gesty myszy
|
||||||
Name[pt]=Gestos do Rato
|
Name[pt]=Gestos do Rato
|
||||||
|
Name[pt_BR]=Gestos do mouse
|
||||||
Name[sv]=Musgester
|
Name[sv]=Musgester
|
||||||
Name[uk]=Керування мишею
|
Name[uk]=Керування мишею
|
||||||
Name[x-test]=xxMouse Gesturesxx
|
Name[x-test]=xxMouse Gesturesxx
|
||||||
|
@ -37,6 +38,7 @@ Comment[nl]=Biedt ondersteuning voor navigeren in webpagina's door muisgebaren
|
||||||
Comment[nn]=Gjev støtte for muserørsler for nettsidenavigering
|
Comment[nn]=Gjev støtte for muserørsler for nettsidenavigering
|
||||||
Comment[pl]=Zapewnia obsługę poruszania się po stronach przy użyciu gestów myszy
|
Comment[pl]=Zapewnia obsługę poruszania się po stronach przy użyciu gestów myszy
|
||||||
Comment[pt]=Oferece o suporte para navegar nas páginas Web com gestos do rato
|
Comment[pt]=Oferece o suporte para navegar nas páginas Web com gestos do rato
|
||||||
|
Comment[pt_BR]=Fornece suporte para navegação em sites usando gestos do mouse
|
||||||
Comment[sv]=Tillhandahåller stöd för att navigera på webbsidor med musgester
|
Comment[sv]=Tillhandahåller stöd för att navigera på webbsidor med musgester
|
||||||
Comment[uk]=Забезпечує підтримку навігації сторінками за допомогою жестів вказівником миші
|
Comment[uk]=Забезпечує підтримку навігації сторінками за допомогою жестів вказівником миші
|
||||||
Comment[x-test]=xxProvides support for navigating in webpages by mouse gesturesxx
|
Comment[x-test]=xxProvides support for navigating in webpages by mouse gesturesxx
|
||||||
|
|
|
@ -16,6 +16,7 @@ Name[nl]=PIM
|
||||||
Name[nn]=PIM
|
Name[nn]=PIM
|
||||||
Name[pl]=ZIO
|
Name[pl]=ZIO
|
||||||
Name[pt]=PIM
|
Name[pt]=PIM
|
||||||
|
Name[pt_BR]=PIM
|
||||||
Name[sv]=Personlig information
|
Name[sv]=Personlig information
|
||||||
Name[uk]=Керування інформацією
|
Name[uk]=Керування інформацією
|
||||||
Name[x-test]=xxPIMxx
|
Name[x-test]=xxPIMxx
|
||||||
|
@ -36,6 +37,7 @@ Comment[nl]=Biedt mogelijkheid voor Falkon om enige persoonlijke gegevens op te
|
||||||
Comment[nn]=Gjer det mogleg for Falkon å lagra nokre persondata
|
Comment[nn]=Gjer det mogleg for Falkon å lagra nokre persondata
|
||||||
Comment[pl]=Dodaje możliwość przechowywania pewnych danych osobistych
|
Comment[pl]=Dodaje możliwość przechowywania pewnych danych osobistych
|
||||||
Comment[pt]=Adiciona ao Falkon a capacidade de guardar alguns dados pessoais
|
Comment[pt]=Adiciona ao Falkon a capacidade de guardar alguns dados pessoais
|
||||||
|
Comment[pt_BR]=Adiciona a habilitade ao Falkon para armazenar alguns dados pessoais
|
||||||
Comment[sv]=Lägger till möjlighet för Falkon att lagra viss personlig information
|
Comment[sv]=Lägger till möjlighet för Falkon att lagra viss personlig information
|
||||||
Comment[uk]=Додає у Falkon можливість зберігати особисті дані
|
Comment[uk]=Додає у Falkon можливість зберігати особисті дані
|
||||||
Comment[x-test]=xxAdds ability for Falkon to store some personal dataxx
|
Comment[x-test]=xxAdds ability for Falkon to store some personal dataxx
|
||||||
|
|
|
@ -16,6 +16,7 @@ Name[nl]=Pictogrammen op de statusbalk
|
||||||
Name[nn]=Statuslinje-ikon
|
Name[nn]=Statuslinje-ikon
|
||||||
Name[pl]=Ikony paska stanu
|
Name[pl]=Ikony paska stanu
|
||||||
Name[pt]=Ícones da Barra de Estado
|
Name[pt]=Ícones da Barra de Estado
|
||||||
|
Name[pt_BR]=Ícones da barra de status
|
||||||
Name[sv]=Ikoner i statusraden
|
Name[sv]=Ikoner i statusraden
|
||||||
Name[uk]=Піктограми смужки стану
|
Name[uk]=Піктограми смужки стану
|
||||||
Name[x-test]=xxStatusBar Iconsxx
|
Name[x-test]=xxStatusBar Iconsxx
|
||||||
|
@ -36,6 +37,7 @@ Comment[nl]=Voegt extra pictogrammen en zoomwidget toe aan de statusbalk
|
||||||
Comment[nn]=Leggjer til fleire ikon og sideforstørring via statuslinja
|
Comment[nn]=Leggjer til fleire ikon og sideforstørring via statuslinja
|
||||||
Comment[pl]=Dodaje dodatkowe ikony i element do powiększania na pasku stanu
|
Comment[pl]=Dodaje dodatkowe ikony i element do powiększania na pasku stanu
|
||||||
Comment[pt]=Adiciona ícones extra e um item de ampliação à barra de estado
|
Comment[pt]=Adiciona ícones extra e um item de ampliação à barra de estado
|
||||||
|
Comment[pt_BR]=Adiciona ícones adicionais e widget de zoom na barra de status
|
||||||
Comment[sv]=Lägger till ytterligare ikoner och en zoomkomponent i statusraden
|
Comment[sv]=Lägger till ytterligare ikoner och en zoomkomponent i statusraden
|
||||||
Comment[uk]=Додає піктограми і віджет масштабування на смужку стану
|
Comment[uk]=Додає піктограми і віджет масштабування на смужку стану
|
||||||
Comment[x-test]=xxAdds additional icons and zoom widget to statusbarxx
|
Comment[x-test]=xxAdds additional icons and zoom widget to statusbarxx
|
||||||
|
|
|
@ -16,6 +16,7 @@ Name[nl]=Tabbladbeheerder
|
||||||
Name[nn]=Fanehandsamar
|
Name[nn]=Fanehandsamar
|
||||||
Name[pl]=Zarządzanie kartami
|
Name[pl]=Zarządzanie kartami
|
||||||
Name[pt]=Gestor de Páginas
|
Name[pt]=Gestor de Páginas
|
||||||
|
Name[pt_BR]=Gerenciador de abas
|
||||||
Name[sv]=Flikhanterare
|
Name[sv]=Flikhanterare
|
||||||
Name[uk]=Керування вкладками
|
Name[uk]=Керування вкладками
|
||||||
Name[x-test]=xxTab Managerxx
|
Name[x-test]=xxTab Managerxx
|
||||||
|
@ -37,6 +38,7 @@ Comment[nl]=Voegt mogelijkheid toe om tabbladen en vensters te beheren
|
||||||
Comment[nn]=Gjer det mogleg å handtera faner og vindauge
|
Comment[nn]=Gjer det mogleg å handtera faner og vindauge
|
||||||
Comment[pl]=Dodaje możliwość zarządzania kartami i oknami
|
Comment[pl]=Dodaje możliwość zarządzania kartami i oknami
|
||||||
Comment[pt]=Adiciona a capacidade para gerir páginas e janelas
|
Comment[pt]=Adiciona a capacidade para gerir páginas e janelas
|
||||||
|
Comment[pt_BR]=Adiciona a habilidade de gerenciar abas e janelas
|
||||||
Comment[sv]=Lägger till möjlighet att hantera flikar och fönster
|
Comment[sv]=Lägger till möjlighet att hantera flikar och fönster
|
||||||
Comment[uk]=Додає можливість керування вкладками і вікнами
|
Comment[uk]=Додає можливість керування вкладками і вікнами
|
||||||
Comment[x-test]=xxAdds ability to managing tabs and windowsxx
|
Comment[x-test]=xxAdds ability to managing tabs and windowsxx
|
||||||
|
|
|
@ -16,6 +16,7 @@ Name[nl]=Voorbeeld plug-in
|
||||||
Name[nn]=Eksempel-tillegg
|
Name[nn]=Eksempel-tillegg
|
||||||
Name[pl]=Przykładowa wtyczka
|
Name[pl]=Przykładowa wtyczka
|
||||||
Name[pt]='Plugin' de Exemplo
|
Name[pt]='Plugin' de Exemplo
|
||||||
|
Name[pt_BR]=Plugin de exemplo
|
||||||
Name[sv]=Exempelinsticksprogram
|
Name[sv]=Exempelinsticksprogram
|
||||||
Name[uk]=Приклад додатка
|
Name[uk]=Приклад додатка
|
||||||
Name[x-test]=xxExample Pluginxx
|
Name[x-test]=xxExample Pluginxx
|
||||||
|
@ -37,6 +38,7 @@ Comment[nl]=Zeer eenvoudige minimaal voorbeeld voor plug-in
|
||||||
Comment[nn]=Veldig enkelt og lite eksempel-tillegg
|
Comment[nn]=Veldig enkelt og lite eksempel-tillegg
|
||||||
Comment[pl]=Bardzo prosty minimalny przykład wtyczki
|
Comment[pl]=Bardzo prosty minimalny przykład wtyczki
|
||||||
Comment[pt]='Plugin' de exemplo muito simples e minimalista
|
Comment[pt]='Plugin' de exemplo muito simples e minimalista
|
||||||
|
Comment[pt_BR]=Um exemplo de plugin mínimo e simples
|
||||||
Comment[sv]=Mycket enkelt minimalt exempel på ett insticksprogram
|
Comment[sv]=Mycket enkelt minimalt exempel på ett insticksprogram
|
||||||
Comment[uk]=Дуже простий мінімальний приклад додатка
|
Comment[uk]=Дуже простий мінімальний приклад додатка
|
||||||
Comment[x-test]=xxVery simple minimal plugin examplexx
|
Comment[x-test]=xxVery simple minimal plugin examplexx
|
||||||
|
|
|
@ -16,6 +16,7 @@ Name[nl]=Verticale tabbladen
|
||||||
Name[nn]=Loddrette faner
|
Name[nn]=Loddrette faner
|
||||||
Name[pl]=Pionowe karty
|
Name[pl]=Pionowe karty
|
||||||
Name[pt]=Páginas Verticais
|
Name[pt]=Páginas Verticais
|
||||||
|
Name[pt_BR]=Abas verticais
|
||||||
Name[sv]=Vertikala flikar
|
Name[sv]=Vertikala flikar
|
||||||
Name[uk]=Вертикальні вкладки
|
Name[uk]=Вертикальні вкладки
|
||||||
Name[x-test]=xxVertical Tabsxx
|
Name[x-test]=xxVertical Tabsxx
|
||||||
|
@ -36,6 +37,7 @@ Comment[nl]=Voegt mogelijkheid toe om tabbladen in de zijbalk te tonen
|
||||||
Comment[nn]=Gjer det mogleg å visa faner i sidestolpen
|
Comment[nn]=Gjer det mogleg å visa faner i sidestolpen
|
||||||
Comment[pl]=Dodaje możliwość pokazywania kart na pasku bocznym
|
Comment[pl]=Dodaje możliwość pokazywania kart na pasku bocznym
|
||||||
Comment[pt]=Adiciona a capacidade de mostrar as páginas na barra lateral
|
Comment[pt]=Adiciona a capacidade de mostrar as páginas na barra lateral
|
||||||
|
Comment[pt_BR]=Adiciona a habilidade de mostrar abas na barra lateral
|
||||||
Comment[sv]=Lägger till möjlighet att visa flikar i sidorader
|
Comment[sv]=Lägger till möjlighet att visa flikar i sidorader
|
||||||
Comment[uk]=Додає можливість показу вкладок на бічній панелі
|
Comment[uk]=Додає можливість показу вкладок на бічній панелі
|
||||||
Comment[x-test]=xxAdds ability to show tabs in sidebarxx
|
Comment[x-test]=xxAdds ability to show tabs in sidebarxx
|
||||||
|
|
|
@ -7,6 +7,7 @@ Name[da]=Hallo Python
|
||||||
Name[de]=Hallo-Python
|
Name[de]=Hallo-Python
|
||||||
Name[en_GB]=Hello Python
|
Name[en_GB]=Hello Python
|
||||||
Name[es]=Hola Python
|
Name[es]=Hola Python
|
||||||
|
Name[fi]=Hei Python
|
||||||
Name[fr]=Hello Python
|
Name[fr]=Hello Python
|
||||||
Name[gl]=Ola, Python!
|
Name[gl]=Ola, Python!
|
||||||
Name[id]=Hello Python
|
Name[id]=Hello Python
|
||||||
|
@ -15,6 +16,7 @@ Name[nl]=Hallo Python
|
||||||
Name[nn]=Hei-Python
|
Name[nn]=Hei-Python
|
||||||
Name[pl]=Witaj Python
|
Name[pl]=Witaj Python
|
||||||
Name[pt]=Olá em Python
|
Name[pt]=Olá em Python
|
||||||
|
Name[pt_BR]=Olá Python
|
||||||
Name[sv]=Hej Python
|
Name[sv]=Hej Python
|
||||||
Name[uk]=Привіт, Python
|
Name[uk]=Привіт, Python
|
||||||
Name[x-test]=xxHello Pythonxx
|
Name[x-test]=xxHello Pythonxx
|
||||||
|
@ -27,6 +29,7 @@ Comment[da]=Eksempel Python-udvidelse
|
||||||
Comment[de]=Beispiel eines Python-Moduls
|
Comment[de]=Beispiel eines Python-Moduls
|
||||||
Comment[en_GB]=Example Python extension
|
Comment[en_GB]=Example Python extension
|
||||||
Comment[es]=Ejemplo de extensión de Python
|
Comment[es]=Ejemplo de extensión de Python
|
||||||
|
Comment[fi]=Esimerkinomainen Python-laajennus
|
||||||
Comment[fr]=Exemple d'extension Python
|
Comment[fr]=Exemple d'extension Python
|
||||||
Comment[gl]=Extensión de Python de exemplo
|
Comment[gl]=Extensión de Python de exemplo
|
||||||
Comment[id]=Contoh ekstensi Python
|
Comment[id]=Contoh ekstensi Python
|
||||||
|
@ -35,6 +38,7 @@ Comment[nl]=Voorbeeld Python-extensie
|
||||||
Comment[nn]=Eksempel på Python-tillegg
|
Comment[nn]=Eksempel på Python-tillegg
|
||||||
Comment[pl]=Przykładowe rozszerzenie Python
|
Comment[pl]=Przykładowe rozszerzenie Python
|
||||||
Comment[pt]=Extensão de exemplo em Python
|
Comment[pt]=Extensão de exemplo em Python
|
||||||
|
Comment[pt_BR]=Exemplo de extensão python
|
||||||
Comment[sv]=Exempel på Python-utökning
|
Comment[sv]=Exempel på Python-utökning
|
||||||
Comment[uk]=Приклад розширення мовою Python
|
Comment[uk]=Приклад розширення мовою Python
|
||||||
Comment[x-test]=xxExample Python extensionxx
|
Comment[x-test]=xxExample Python extensionxx
|
||||||
|
|
|
@ -4,6 +4,7 @@ Name[ca]=MiddleClickLoader
|
||||||
Name[ca@valencia]=MiddleClickLoader
|
Name[ca@valencia]=MiddleClickLoader
|
||||||
Name[cs]=Načtení prostředním tlačítkem myši
|
Name[cs]=Načtení prostředním tlačítkem myši
|
||||||
Name[es]=Cargador de clic central
|
Name[es]=Cargador de clic central
|
||||||
|
Name[fi]=Keskipainikelatain
|
||||||
Name[fr]=MiddleClickLoader
|
Name[fr]=MiddleClickLoader
|
||||||
Name[it]=Caricatore al clic centrale
|
Name[it]=Caricatore al clic centrale
|
||||||
Name[nl]=MiddleClickLoader
|
Name[nl]=MiddleClickLoader
|
||||||
|
@ -15,6 +16,7 @@ Comment=Load text in selection clipboard as URL
|
||||||
Comment[ca]=Carrega text com a URL en una selecció del porta-retalls
|
Comment[ca]=Carrega text com a URL en una selecció del porta-retalls
|
||||||
Comment[ca@valencia]=Carrega text com a URL en una selecció del porta-retalls
|
Comment[ca@valencia]=Carrega text com a URL en una selecció del porta-retalls
|
||||||
Comment[cs]=Načíst text ve schránce výběru jako URL
|
Comment[cs]=Načíst text ve schránce výběru jako URL
|
||||||
|
Comment[fi]=Lataa leikepöytävalinnan tekstin verkko-osoitteeksi
|
||||||
Comment[fr]=Charger l'URL sélectionnée dans le presse-papier
|
Comment[fr]=Charger l'URL sélectionnée dans le presse-papier
|
||||||
Comment[it]=Carica come URL il testo negli appunti della selezione
|
Comment[it]=Carica come URL il testo negli appunti della selezione
|
||||||
Comment[nl]=Tekst laden in selectieklembord als URL
|
Comment[nl]=Tekst laden in selectieklembord als URL
|
||||||
|
|
|
@ -7,6 +7,7 @@ Name[da]=Ordbog
|
||||||
Name[de]=Wörterbuch
|
Name[de]=Wörterbuch
|
||||||
Name[en_GB]=Dictionary
|
Name[en_GB]=Dictionary
|
||||||
Name[es]=Diccionario
|
Name[es]=Diccionario
|
||||||
|
Name[fi]=Sanasto
|
||||||
Name[fr]=Dictionnaire
|
Name[fr]=Dictionnaire
|
||||||
Name[gl]=Dicionario
|
Name[gl]=Dicionario
|
||||||
Name[id]=Kamus
|
Name[id]=Kamus
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user