diff --git a/autotests/qml/qmltesthelper.cpp b/autotests/qml/qmltesthelper.cpp index f7a406319..c43e2eb5c 100644 --- a/autotests/qml/qmltesthelper.cpp +++ b/autotests/qml/qmltesthelper.cpp @@ -16,13 +16,15 @@ * along with this program. If not, see . * ============================================================ */ #include "qmltesthelper.h" +#include "qml/qmlplugins.h" #include #include QmlTestHelper::QmlTestHelper() { - qmlRegisterType("org.kde.falkon.test", 1, 0, "TestItem"); + QmlPlugins::registerQmlTypes(); + qmlRegisterType("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" diff --git a/config.h.cmake b/config.h.cmake index d35648e5b..c0f35ad53 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -9,3 +9,7 @@ /* Disable DBus support */ #cmakedefine DISABLE_DBUS + +if (LibIntl_FOUND) + target_compile_definitions(FalkonPrivate PRIVATE LibIntl_FOUND=1) +endif() diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index 4f348a1a1..d65cd8950 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -37,14 +37,13 @@ Plugins::Plugins(QObject* parent) : QObject(parent) , m_pluginsLoaded(false) , m_speedDial(new SpeedDial(this)) + , m_qmlSupportLoaded(false) { loadSettings(); if (!MainApplication::isTestModeEnabled()) { loadPythonSupport(); } - - loadQmlSupport(); } QList Plugins::getAvailablePlugins() @@ -292,6 +291,7 @@ void Plugins::loadPythonSupport() void Plugins::loadQmlSupport() { QmlPlugins::registerQmlTypes(); + m_qmlSupportLoaded = true; } Plugins::Plugin Plugins::loadPlugin(const QString &id) @@ -397,6 +397,10 @@ Plugins::Plugin Plugins::loadPythonPlugin(const QString &name) Plugins::Plugin Plugins::loadQmlPlugin(const QString &name) { + if (!m_qmlSupportLoaded) { + loadQmlSupport(); + } + QString fullPath; if (QFileInfo(name).isAbsolute()) { fullPath = name; diff --git a/src/lib/plugins/plugins.h b/src/lib/plugins/plugins.h index bcff69dc8..b686edda7 100644 --- a/src/lib/plugins/plugins.h +++ b/src/lib/plugins/plugins.h @@ -147,6 +147,7 @@ private: QList m_internalPlugins; QLibrary *m_pythonPlugin = nullptr; + bool m_qmlSupportLoaded; }; Q_DECLARE_METATYPE(Plugins::Plugin) diff --git a/src/lib/plugins/qml/api/bookmarks/qmlbookmarks.cpp b/src/lib/plugins/qml/api/bookmarks/qmlbookmarks.cpp index 9d40775d9..406e31ed7 100644 --- a/src/lib/plugins/qml/api/bookmarks/qmlbookmarks.cpp +++ b/src/lib/plugins/qml/api/bookmarks/qmlbookmarks.cpp @@ -89,80 +89,36 @@ BookmarkItem *QmlBookmarks::getBookmarkItem(QObject *object) const return item; } -/** - * @brief Checks if the url is bookmarked - * @param String representing the url to check - * @return true if bookmarked, else false - */ bool QmlBookmarks::isBookmarked(const QString &url) const { return mApp->bookmarks()->isBookmarked(QUrl::fromEncoded(url.toUtf8())); } -/** - * @brief Get the root bookmark item - * @return Root boomkark item - */ QmlBookmarkTreeNode *QmlBookmarks::rootItem() const { return bookmarkTreeNodeData->get(mApp->bookmarks()->rootItem()); } -/** - * @brief Get the bookmarks toolbar - * @return Bookmarks toolbar - */ QmlBookmarkTreeNode *QmlBookmarks::toolbarFolder() const { return bookmarkTreeNodeData->get(mApp->bookmarks()->toolbarFolder()); } -/** - * @brief Get the bookmarks menu folder - * @return Bookmarks menu folder - */ QmlBookmarkTreeNode *QmlBookmarks::menuFolder() const { return bookmarkTreeNodeData->get(mApp->bookmarks()->menuFolder()); } -/** - * @brief Get the unsorted bookmarks folder - * @return Unsorted bookmarks folder - */ QmlBookmarkTreeNode *QmlBookmarks::unsortedFolder() const { return bookmarkTreeNodeData->get(mApp->bookmarks()->unsortedFolder()); } -/** - * @brief Get the last used bookmarks folder - * @return Last used bookmarks folder - */ QmlBookmarkTreeNode *QmlBookmarks::lastUsedFolder() const { return bookmarkTreeNodeData->get(mApp->bookmarks()->lastUsedFolder()); } -/** - * @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 - */ bool QmlBookmarks::create(const QVariantMap &map) const { if (!map.contains(QSL("parent"))) { @@ -200,12 +156,6 @@ bool QmlBookmarks::create(const QVariantMap &map) const return true; } -/** - * @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 - */ bool QmlBookmarks::remove(QmlBookmarkTreeNode *treeNode) const { auto item = getBookmarkItem(treeNode); @@ -216,16 +166,6 @@ bool QmlBookmarks::remove(QmlBookmarkTreeNode *treeNode) const return mApp->bookmarks()->removeBookmark(item); } -/** - * @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. - */ QList QmlBookmarks::search(const QVariantMap &map) const { if (!map.contains(QSL("query")) && !map.contains(QSL("url"))) { @@ -248,19 +188,6 @@ QList QmlBookmarks::search(const QVariantMap &map) const return ret; } -/** - * @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 - */ bool QmlBookmarks::update(QObject *object, const QVariantMap &changes) const { auto treeNode = qobject_cast(object); @@ -299,12 +226,6 @@ bool QmlBookmarks::update(QObject *object, const QVariantMap &changes) const return true; } -/** - * @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 - */ QmlBookmarkTreeNode *QmlBookmarks::get(const QString &string) const { auto items = mApp->bookmarks()->searchBookmarks(QUrl(string)); @@ -317,12 +238,6 @@ QmlBookmarkTreeNode *QmlBookmarks::get(const QString &string) const return nullptr; } -/** - * @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) - */ QList QmlBookmarks::getChildren(QObject *object) const { QList ret; @@ -343,8 +258,5 @@ QList QmlBookmarks::getChildren(QObject *object) const bool QmlBookmarks::isTreeNodeEqualsItem(QmlBookmarkTreeNode *treeNode, BookmarkItem *item) const { - return treeNode->title() == item->title() - && treeNode->url() == item->urlString() - && treeNode->description() == item->description() - && (int)(treeNode->type()) == (int)(item->type()); + return treeNode->item() == item; } diff --git a/src/lib/plugins/qml/api/bookmarks/qmlbookmarks.h b/src/lib/plugins/qml/api/bookmarks/qmlbookmarks.h index 322049a26..de0150780 100644 --- a/src/lib/plugins/qml/api/bookmarks/qmlbookmarks.h +++ b/src/lib/plugins/qml/api/bookmarks/qmlbookmarks.h @@ -32,17 +32,102 @@ class QmlBookmarks : public QObject 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 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 getChildren(QObject *object) const; Q_SIGNALS: diff --git a/src/lib/plugins/qml/api/bookmarks/qmlbookmarktreenode.cpp b/src/lib/plugins/qml/api/bookmarks/qmlbookmarktreenode.cpp index 1648ae79f..71775d9b8 100644 --- a/src/lib/plugins/qml/api/bookmarks/qmlbookmarktreenode.cpp +++ b/src/lib/plugins/qml/api/bookmarks/qmlbookmarktreenode.cpp @@ -28,6 +28,11 @@ QmlBookmarkTreeNode::QmlBookmarkTreeNode(BookmarkItem *item) QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); } +BookmarkItem *QmlBookmarkTreeNode::item() +{ + return m_item; +} + QmlBookmarkTreeNode::Type QmlBookmarkTreeNode::type() const { if (!m_item) { diff --git a/src/lib/plugins/qml/api/bookmarks/qmlbookmarktreenode.h b/src/lib/plugins/qml/api/bookmarks/qmlbookmarktreenode.h index b4366e98e..7900bc56f 100644 --- a/src/lib/plugins/qml/api/bookmarks/qmlbookmarktreenode.h +++ b/src/lib/plugins/qml/api/bookmarks/qmlbookmarktreenode.h @@ -87,6 +87,7 @@ public: explicit QmlBookmarkTreeNode(BookmarkItem *item = nullptr); + BookmarkItem *item(); Type type() const; QString title() const; QString url() const; diff --git a/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.cpp b/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.cpp index 279fb8e75..de4fe08e4 100644 --- a/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.cpp +++ b/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.cpp @@ -213,9 +213,6 @@ void QmlBrowserActionButton::setIcon(const QString &icon) m_iconUrl = icon; if (QIcon::hasThemeIcon(m_iconUrl)) { AbstractButtonInterface::setIcon(QIcon::fromTheme(m_iconUrl)); - } else if (m_iconUrl.startsWith(QSL(":"))) { - // Icon is loaded from falkon resource - AbstractButtonInterface::setIcon(QIcon(m_iconUrl)); } else { const QString pluginPath = m_popup->creationContext()->contextProperty("__path__").toString(); QmlFileUtils fileUtils(pluginPath); diff --git a/src/lib/plugins/qml/api/clipboard/qmlclipboard.cpp b/src/lib/plugins/qml/api/clipboard/qmlclipboard.cpp index 89599f351..4e8a563fd 100644 --- a/src/lib/plugins/qml/api/clipboard/qmlclipboard.cpp +++ b/src/lib/plugins/qml/api/clipboard/qmlclipboard.cpp @@ -24,10 +24,6 @@ QmlClipboard::QmlClipboard(QObject *parent) { } -/** - * @brief Copy the string to clipboard - * @param String representing the text to be copied - */ void QmlClipboard::copy(const QString &text) { mApp->clipboard()->setText(text); diff --git a/src/lib/plugins/qml/api/clipboard/qmlclipboard.h b/src/lib/plugins/qml/api/clipboard/qmlclipboard.h index 7135f4cf0..5e2cbbccf 100644 --- a/src/lib/plugins/qml/api/clipboard/qmlclipboard.h +++ b/src/lib/plugins/qml/api/clipboard/qmlclipboard.h @@ -28,5 +28,9 @@ class QmlClipboard : public QObject Q_OBJECT public: explicit QmlClipboard(QObject *parent = nullptr); + /** + * @brief Copy the string to clipboard + * @param String representing the text to be copied + */ Q_INVOKABLE void copy(const QString &text); }; diff --git a/src/lib/plugins/qml/api/cookies/qmlcookies.cpp b/src/lib/plugins/qml/api/cookies/qmlcookies.cpp index 020956086..3602a8688 100644 --- a/src/lib/plugins/qml/api/cookies/qmlcookies.cpp +++ b/src/lib/plugins/qml/api/cookies/qmlcookies.cpp @@ -26,7 +26,6 @@ QmlCookies::QmlCookies(QObject *parent) : QObject(parent) { connect(mApp->cookieJar(), &CookieJar::cookieAdded, this, [this](QNetworkCookie network_cookie){ - // FIXME: improve this QmlCookie *cookie = cookieData->get(&network_cookie); QVariantMap map; map.insert(QSL("cookie"), QVariant::fromValue(cookie)); @@ -35,7 +34,6 @@ QmlCookies::QmlCookies(QObject *parent) }); connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, [this](QNetworkCookie network_cookie){ - // FIXME: improve this QmlCookie *cookie = cookieData->get(&network_cookie); QVariantMap map; map.insert(QSL("cookie"), QVariant::fromValue(cookie)); @@ -61,16 +59,6 @@ QNetworkCookie *QmlCookies::getNetworkCookie(const QVariantMap &map) return 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 - */ QmlCookie *QmlCookies::get(const QVariantMap &map) { QNetworkCookie *netCookie = getNetworkCookie(map); @@ -80,21 +68,6 @@ QmlCookie *QmlCookies::get(const QVariantMap &map) return cookieData->get(netCookie); } -/** - * @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) - */ QList QmlCookies::getAll(const QVariantMap &map) { QList qmlCookies; @@ -117,24 +90,6 @@ QList QmlCookies::getAll(const QVariantMap &map) return qmlCookies; } -/** - * @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 - */ void QmlCookies::set(const QVariantMap &map) { const QString name = map.value(QSL("name")).toString(); @@ -155,14 +110,6 @@ void QmlCookies::set(const QVariantMap &map) mApp->webProfile()->cookieStore()->setCookie(cookie); } -/** - * @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 - */ void QmlCookies::remove(const QVariantMap &map) { QNetworkCookie *netCookie = getNetworkCookie(map); diff --git a/src/lib/plugins/qml/api/cookies/qmlcookies.h b/src/lib/plugins/qml/api/cookies/qmlcookies.h index 12a6e50ef..cb6fb87ba 100644 --- a/src/lib/plugins/qml/api/cookies/qmlcookies.h +++ b/src/lib/plugins/qml/api/cookies/qmlcookies.h @@ -28,9 +28,60 @@ 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 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: /** diff --git a/src/lib/plugins/qml/api/events/qmlkeyevent.cpp b/src/lib/plugins/qml/api/events/qmlkeyevent.cpp index a9fc646fe..cd7170ef0 100644 --- a/src/lib/plugins/qml/api/events/qmlkeyevent.cpp +++ b/src/lib/plugins/qml/api/events/qmlkeyevent.cpp @@ -22,69 +22,46 @@ QmlKeyEvent::QmlKeyEvent(QKeyEvent *keyEvent, QObject *parent) : QObject(parent) , m_keyEvent(keyEvent) { + delete 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(); } diff --git a/src/lib/plugins/qml/api/events/qmlmouseevent.cpp b/src/lib/plugins/qml/api/events/qmlmouseevent.cpp index c4552707c..e1d050518 100644 --- a/src/lib/plugins/qml/api/events/qmlmouseevent.cpp +++ b/src/lib/plugins/qml/api/events/qmlmouseevent.cpp @@ -27,96 +27,60 @@ QmlMouseEvent::QmlMouseEvent(QMouseEvent *mouseEvent, QObject *parent) 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(); } diff --git a/src/lib/plugins/qml/api/events/qmlwheelevent.cpp b/src/lib/plugins/qml/api/events/qmlwheelevent.cpp index fea5e780d..192ec487c 100644 --- a/src/lib/plugins/qml/api/events/qmlwheelevent.cpp +++ b/src/lib/plugins/qml/api/events/qmlwheelevent.cpp @@ -27,112 +27,70 @@ QmlWheelEvent::QmlWheelEvent(QWheelEvent *wheelEvent, QObject *parent) 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(); } diff --git a/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp b/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp index ece019bba..f379628d9 100644 --- a/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp +++ b/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.cpp @@ -26,10 +26,6 @@ QmlWebEngineUrlRequestJob::QmlWebEngineUrlRequestJob(QWebEngineUrlRequestJob *jo { } -/** - * @brief Fails the request with the error - * @param error - */ void QmlWebEngineUrlRequestJob::fail(QmlWebEngineUrlRequestJob::Error error) { if (!m_job) { @@ -38,10 +34,6 @@ void QmlWebEngineUrlRequestJob::fail(QmlWebEngineUrlRequestJob::Error error) m_job->fail(QWebEngineUrlRequestJob::Error(error)); } -/** - * @brief Redirects the request to the url - * @param urlString, represents the url to which the request is to be redirected - */ void QmlWebEngineUrlRequestJob::redirect(const QString &urlString) { if (!m_job) { @@ -50,12 +42,6 @@ void QmlWebEngineUrlRequestJob::redirect(const QString &urlString) return m_job->redirect(QUrl::fromEncoded(urlString.toUtf8())); } -/** - * @brief Replies to the request - * @param A JavaScript object containing - * - content: String representing the reply data - * - contentType: String representing the contentType of reply data - */ void QmlWebEngineUrlRequestJob::reply(const QVariantMap &map) { if (!m_job) { diff --git a/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.h b/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.h index 0efcf8744..ec0c1abdd 100644 --- a/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.h +++ b/src/lib/plugins/qml/api/extensionscheme/qmlwebengineurlrequestjob.h @@ -51,8 +51,22 @@ public: }; 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; diff --git a/src/lib/plugins/qml/api/history/qmlhistory.cpp b/src/lib/plugins/qml/api/history/qmlhistory.cpp index 539417d7e..da47c29a6 100644 --- a/src/lib/plugins/qml/api/history/qmlhistory.cpp +++ b/src/lib/plugins/qml/api/history/qmlhistory.cpp @@ -35,12 +35,6 @@ QmlHistory::QmlHistory(QObject *parent) }); } -/** - * @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 - */ QList QmlHistory::search(const QString &text) { QList list; @@ -53,25 +47,12 @@ QList QmlHistory::search(const QString &text) return list; } -/** - * @brief Get the visit count of a url - * @param String representing the url - * @return Integer representing the visit count of the given url - */ int QmlHistory::getVisits(const QString &url) { HistoryEntry *entry = mApp->history()->getHistoryEntry(url); return entry->count; } -/** - * @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 - */ void QmlHistory::addUrl(const QVariantMap &map) { if (!map.contains(QSL("title")) || !map.contains(QSL("url"))) { @@ -86,23 +67,11 @@ void QmlHistory::addUrl(const QVariantMap &map) mApp->history()->addHistoryEntry(QUrl::fromEncoded(url.toUtf8()), title); } -/** - * @brief Deletes a url from the history - * @param String representing the url of the history entry - */ void QmlHistory::deleteUrl(const QString &url) { mApp->history()->deleteHistoryEntry(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 - */ void QmlHistory::deleteRange(const QVariantMap &map) { if (!map.contains(QSL("startTime")) || !map.contains(QSL("endTime"))) { @@ -114,9 +83,6 @@ void QmlHistory::deleteRange(const QVariantMap &map) mApp->history()->deleteRange(startTime, endTime); } -/** - * @brief Clears all the history - */ void QmlHistory::deleteAll() { mApp->history()->clearHistory(); diff --git a/src/lib/plugins/qml/api/history/qmlhistory.h b/src/lib/plugins/qml/api/history/qmlhistory.h index addbc53e1..b27d4e31f 100644 --- a/src/lib/plugins/qml/api/history/qmlhistory.h +++ b/src/lib/plugins/qml/api/history/qmlhistory.h @@ -28,11 +28,45 @@ 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 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: /** diff --git a/src/lib/plugins/qml/api/history/qmlhistoryitem.cpp b/src/lib/plugins/qml/api/history/qmlhistoryitem.cpp index 05c2199d2..08b6bc137 100644 --- a/src/lib/plugins/qml/api/history/qmlhistoryitem.cpp +++ b/src/lib/plugins/qml/api/history/qmlhistoryitem.cpp @@ -25,10 +25,6 @@ QmlHistoryItem::QmlHistoryItem(HistoryEntry *entry, QObject *parent) QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); } -/** - * @brief Get the id of the HistoryEntry - * @return Integer representing the id of the HistoryEntry if it exists, else 0 - */ int QmlHistoryItem::id() const { if (!m_entry) { @@ -37,10 +33,6 @@ int QmlHistoryItem::id() const return m_entry->id; } -/** - * @brief Get the url of the HistoryEntry - * @return String representing the url of the HistoryEntry - */ QString QmlHistoryItem::url() const { if (!m_entry) { @@ -49,10 +41,6 @@ QString QmlHistoryItem::url() const return QString::fromUtf8(m_entry->url.toEncoded()); } -/** - * @brief Get the title of the HistoryEntry - * @return String representing the title of the HistoryEntry - */ QString QmlHistoryItem::title() const { if (!m_entry) { @@ -61,10 +49,6 @@ QString QmlHistoryItem::title() const return m_entry->title; } -/** - * @brief Get the visit count of the HistoryEntry - * @return Integer representing the visit count of the HistoryEntry - */ int QmlHistoryItem::visitCount() const { if (!m_entry) { @@ -73,10 +57,6 @@ int QmlHistoryItem::visitCount() const return m_entry->count; } -/** - * @brief Get the last visit time of the HistoryEntry - * @return Last visit time of the HistoryEntry - */ QDateTime QmlHistoryItem::lastVisitTime() const { if (!m_entry) { diff --git a/src/lib/plugins/qml/api/i18n/qmli18n.cpp b/src/lib/plugins/qml/api/i18n/qmli18n.cpp index ef1da46e5..5e6e6a2ab 100644 --- a/src/lib/plugins/qml/api/i18n/qmli18n.cpp +++ b/src/lib/plugins/qml/api/i18n/qmli18n.cpp @@ -37,17 +37,11 @@ void QmlI18n::initTranslations() textdomain(domain.toUtf8()); } -/** - * @brief wrapper for gettext function - */ QString QmlI18n::i18n(const QString &string) { return QString::fromUtf8(gettext(string.toUtf8())); } -/** - * @brief wrapper for ngettext function - */ QString QmlI18n::i18np(const QString &string1, const QString &string2, int count) { return QString::fromUtf8(ngettext(string1.toUtf8(), string2.toUtf8(), count)); diff --git a/src/lib/plugins/qml/api/i18n/qmli18n.h b/src/lib/plugins/qml/api/i18n/qmli18n.h index dc82e3af8..076548c5a 100644 --- a/src/lib/plugins/qml/api/i18n/qmli18n.h +++ b/src/lib/plugins/qml/api/i18n/qmli18n.h @@ -18,11 +18,10 @@ #pragma once #include -#include -// libintl.h redefines inline which causes MSVC to abort compilation with the message -// fatal error C1189: #error : The C++ Standard Library forbids macroizing keywords -#undef inline +extern "C" { +#include +} /** * @brief The class exposing GNU Gettext to QML @@ -33,7 +32,13 @@ class QmlI18n : public QObject 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; diff --git a/src/lib/plugins/qml/api/menus/qmlaction.cpp b/src/lib/plugins/qml/api/menus/qmlaction.cpp index 2895a934f..39d4ffaf9 100644 --- a/src/lib/plugins/qml/api/menus/qmlaction.cpp +++ b/src/lib/plugins/qml/api/menus/qmlaction.cpp @@ -41,9 +41,6 @@ void QmlAction::setProperties(const QVariantMap &map) QIcon icon; if (QIcon::hasThemeIcon(iconPath)) { icon = QIcon::fromTheme(iconPath); - } else if (iconPath.startsWith(QSL(":"))) { - // Icon is loaded from falkon resource - icon = QIcon(iconPath); } else { QmlFileUtils fileUtils(m_pluginPath); icon = QIcon(fileUtils.resolve(iconPath)); @@ -57,10 +54,6 @@ void QmlAction::setProperties(const QVariantMap &map) } } -/** - * @brief Updates the properties of the action - * @param A JavaScript object containing the updated properties of the action. - */ void QmlAction::update(const QVariantMap &map) { setProperties(map); diff --git a/src/lib/plugins/qml/api/menus/qmlaction.h b/src/lib/plugins/qml/api/menus/qmlaction.h index 093108b31..1c204434d 100644 --- a/src/lib/plugins/qml/api/menus/qmlaction.h +++ b/src/lib/plugins/qml/api/menus/qmlaction.h @@ -30,6 +30,10 @@ class QmlAction : public QObject 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); diff --git a/src/lib/plugins/qml/api/menus/qmlmenu.cpp b/src/lib/plugins/qml/api/menus/qmlmenu.cpp index 35a68b1be..c546e51d6 100644 --- a/src/lib/plugins/qml/api/menus/qmlmenu.cpp +++ b/src/lib/plugins/qml/api/menus/qmlmenu.cpp @@ -29,13 +29,6 @@ QmlMenu::QmlMenu(QMenu *menu, QObject *parent) connect(m_menu, &QMenu::triggered, this, &QmlMenu::triggered); } -/** - * @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) - */ QmlAction *QmlMenu::addAction(const QVariantMap &map) { if (!m_menu) { @@ -51,12 +44,6 @@ QmlAction *QmlMenu::addAction(const QVariantMap &map) return qmlAction; } -/** - * @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) - */ QmlMenu *QmlMenu::addMenu(const QVariantMap &map) { if (!m_menu) { @@ -72,9 +59,6 @@ QmlMenu *QmlMenu::addMenu(const QVariantMap &map) QIcon icon; if (QIcon::hasThemeIcon(iconPath)) { icon = QIcon::fromTheme(iconPath); - } else if (iconPath.startsWith(QSL(":"))) { - // Icon is loaded from falkon resource - icon = QIcon(iconPath); } else { QmlFileUtils fileUtils(m_pluginPath); icon = QIcon(fileUtils.resolve(iconPath)); @@ -90,9 +74,6 @@ QmlMenu *QmlMenu::addMenu(const QVariantMap &map) return newQmlMenu; } -/** - * @brief Adds a separator to menu - */ void QmlMenu::addSeparator() { if (!m_menu) { diff --git a/src/lib/plugins/qml/api/menus/qmlmenu.h b/src/lib/plugins/qml/api/menus/qmlmenu.h index fa1334683..bbce738ae 100644 --- a/src/lib/plugins/qml/api/menus/qmlmenu.h +++ b/src/lib/plugins/qml/api/menus/qmlmenu.h @@ -28,8 +28,24 @@ 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); diff --git a/src/lib/plugins/qml/api/menus/qmlwebhittestresult.cpp b/src/lib/plugins/qml/api/menus/qmlwebhittestresult.cpp index a2635b8d1..1166e1643 100644 --- a/src/lib/plugins/qml/api/menus/qmlwebhittestresult.cpp +++ b/src/lib/plugins/qml/api/menus/qmlwebhittestresult.cpp @@ -25,149 +25,85 @@ QmlWebHitTestResult::QmlWebHitTestResult(const WebHitTestResult &webHitTestResul QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } -/** - * @brief Checks if the context menu is requested on image. - * @return true if image, else false - */ bool QmlWebHitTestResult::isImage() const { return !m_webHitTestResult.imageUrl().isEmpty(); } -/** - * @brief Checks if the context menu is requested on editable content. - * @return true if the content is editable, else false - */ bool QmlWebHitTestResult::isContentEditable() const { return m_webHitTestResult.isContentEditable(); } -/** - * @brief Checks if the context menu is requested on the selected content. - * @return true if content is selected, else false. - */ bool QmlWebHitTestResult::isContentSelected() const { return m_webHitTestResult.isContentSelected(); } -/** - * @brief Checks if the context menu is requested on null element. - * @return true if the element is null, else false - */ bool QmlWebHitTestResult::isNull() const { return m_webHitTestResult.isNull(); } -/** - * @brief Checks if the context menu is requested on a link. - * @return true if the element is link, else false - */ bool QmlWebHitTestResult::isLink() const { return !m_webHitTestResult.linkUrl().isEmpty(); } -/** - * @brief Checks if the context menu is requested on a media element. - * @return true if the element is media, else false - */ bool QmlWebHitTestResult::isMedia() const { return !m_webHitTestResult.mediaUrl().isEmpty(); } -/** - * @brief Checks if the context menu requested on media element is paused. - * @return true if media is paused, else false - */ bool QmlWebHitTestResult::mediaPaused() const { return m_webHitTestResult.mediaPaused(); } -/** - * @brief Checks if the context menu requested on media element is muted. - * @return true if media is muted, else false - */ bool QmlWebHitTestResult::mediaMuted() const { return m_webHitTestResult.mediaMuted(); } -/** - * @brief Gets the tagName of the element on which the context menu is requested. - * @return String representing the tag name of the element - */ QString QmlWebHitTestResult::tagName() const { return m_webHitTestResult.tagName(); } -/** - * @brief Gets the base url on which the context menu is requested. - * @return String representing the base url - */ QString QmlWebHitTestResult::baseUrl() const { const QUrl base = m_webHitTestResult.baseUrl(); return QString::fromUtf8(base.toEncoded()); } -/** - * @brief Gets the link title on which the context menu is requested. - * @return String representing the link title - */ QString QmlWebHitTestResult::linkTitle() const { return m_webHitTestResult.linkTitle(); } -/** - * @brief Gets the link url on which the context menu is requested. - * @return String representing the link url - */ QString QmlWebHitTestResult::linkUrl() const { const QUrl link = m_webHitTestResult.linkUrl(); return QString::fromUtf8(link.toEncoded()); } -/** - * @brief Gets the url of image on which the context menu is requested. - * @return String representing the image url - */ QString QmlWebHitTestResult::imageUrl() const { const QUrl image = m_webHitTestResult.imageUrl(); return QString::fromUtf8(image.toEncoded()); } -/** - * @brief Gets the url of media on which the context menu is requested. - * @return String representing the media url - */ QString QmlWebHitTestResult::mediaUrl() const { const QUrl media = m_webHitTestResult.mediaUrl(); return QString::fromUtf8(media.toEncoded()); } -/** - * @brief Gets the position at which the context menu is requested. - * @return QPoint representing the position - */ QPoint QmlWebHitTestResult::pos() const { return m_webHitTestResult.pos(); } -/** - * @brief Gets the viewport position at which the context menu is requested. - * @return QPoint representing the viewport position - */ QPointF QmlWebHitTestResult::viewportPos() const { return m_webHitTestResult.viewportPos(); diff --git a/src/lib/plugins/qml/api/menus/qmlwebhittestresult.h b/src/lib/plugins/qml/api/menus/qmlwebhittestresult.h index 007a35a89..b4ea46328 100644 --- a/src/lib/plugins/qml/api/menus/qmlwebhittestresult.h +++ b/src/lib/plugins/qml/api/menus/qmlwebhittestresult.h @@ -26,23 +26,79 @@ 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; diff --git a/src/lib/plugins/qml/api/notifications/qmlnotifications.cpp b/src/lib/plugins/qml/api/notifications/qmlnotifications.cpp index 01cd1cdec..def166ca1 100644 --- a/src/lib/plugins/qml/api/notifications/qmlnotifications.cpp +++ b/src/lib/plugins/qml/api/notifications/qmlnotifications.cpp @@ -26,34 +26,12 @@ QmlNotifications::QmlNotifications(QObject *parent) { } -/** - * @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 - */ void QmlNotifications::create(const QVariantMap &map) { const QString iconUrl = map.value(QSL("icon")).toString(); - QPixmap icon; - if (iconUrl.startsWith(QSL(":"))) { - // Icon is loaded from falkon resource - icon = QPixmap(iconUrl); - } else { - QmlFileUtils fileUtils(m_pluginPath); - const QString iconPath = fileUtils.resolve(iconUrl); - icon = QPixmap(iconPath); - } + 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); diff --git a/src/lib/plugins/qml/api/notifications/qmlnotifications.h b/src/lib/plugins/qml/api/notifications/qmlnotifications.h index 0bf3f32f1..924c94687 100644 --- a/src/lib/plugins/qml/api/notifications/qmlnotifications.h +++ b/src/lib/plugins/qml/api/notifications/qmlnotifications.h @@ -27,6 +27,22 @@ 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: diff --git a/src/lib/plugins/qml/api/settings/qmlsettings.cpp b/src/lib/plugins/qml/api/settings/qmlsettings.cpp index 55bd648f1..f085ee566 100644 --- a/src/lib/plugins/qml/api/settings/qmlsettings.cpp +++ b/src/lib/plugins/qml/api/settings/qmlsettings.cpp @@ -26,13 +26,11 @@ QmlSettings::QmlSettings(QObject *parent) m_settingsPath = DataPaths::currentProfilePath() + QL1S("/extensions"); } -/** - * @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 - */ +QmlSettings::~QmlSettings() +{ + m_settings->deleteLater(); +} + bool QmlSettings::setValue(const QVariantMap &map) { if (!m_settings) { @@ -49,13 +47,6 @@ bool QmlSettings::setValue(const QVariantMap &map) return true; } -/** - * @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 - */ QVariant QmlSettings::value(const QVariantMap &map) { if (!m_settings) { @@ -72,11 +63,6 @@ QVariant QmlSettings::value(const QVariantMap &map) return m_settings->value(key, defaultValue); } -/** - * @brief Checks if a given key exists. - * @param QString representing the key - * @return true if key exists, else false - */ bool QmlSettings::contains(const QString &key) { if (!m_settings) { @@ -86,11 +72,6 @@ bool QmlSettings::contains(const QString &key) return m_settings->contains(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 - */ bool QmlSettings::remove(const QString &key) { if (!m_settings) { @@ -101,10 +82,6 @@ bool QmlSettings::remove(const QString &key) return true; } -/** - * @brief syncs the settings - * @return true if success, else false - */ bool QmlSettings::sync() { if (!m_settings) { diff --git a/src/lib/plugins/qml/api/settings/qmlsettings.h b/src/lib/plugins/qml/api/settings/qmlsettings.h index 8e3e05591..b2392ce59 100644 --- a/src/lib/plugins/qml/api/settings/qmlsettings.h +++ b/src/lib/plugins/qml/api/settings/qmlsettings.h @@ -35,10 +35,39 @@ class QmlSettings : public QObject 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: diff --git a/src/lib/plugins/qml/api/sidebar/qmlsidebar.cpp b/src/lib/plugins/qml/api/sidebar/qmlsidebar.cpp index 34a45a38f..c12b7255a 100644 --- a/src/lib/plugins/qml/api/sidebar/qmlsidebar.cpp +++ b/src/lib/plugins/qml/api/sidebar/qmlsidebar.cpp @@ -135,9 +135,6 @@ QAction *QmlSideBarHelper::createMenuAction() action->setShortcut(QKeySequence(m_shortcut)); if (QIcon::hasThemeIcon(m_iconUrl)) { action->setIcon(QIcon::fromTheme(m_iconUrl)); - } else if (m_iconUrl.startsWith(QSL(":"))) { - // Icon is loaded from falkon resource - action->setIcon(QIcon(m_iconUrl)); } else { const QString pluginPath = m_item->creationContext()->contextProperty("__path__").toString(); QmlFileUtils fileUtils(pluginPath); diff --git a/src/lib/plugins/qml/api/tabs/qmltab.cpp b/src/lib/plugins/qml/api/tabs/qmltab.cpp index 677f517d1..427f3fd76 100644 --- a/src/lib/plugins/qml/api/tabs/qmltab.cpp +++ b/src/lib/plugins/qml/api/tabs/qmltab.cpp @@ -38,9 +38,6 @@ QmlTab::QmlTab(WebTab *webTab, QObject *parent) createConnections(); } -/** - * @brief Detaches the tab - */ void QmlTab::detach() { if (!m_webTab) { @@ -50,10 +47,6 @@ void QmlTab::detach() m_webTab->detach(); } -/** - * @brief Set the zoom level of the tab - * @param Integer representing the zoom level - */ void QmlTab::setZoomLevel(int zoomLevel) { if (!m_webTab) { @@ -63,9 +56,6 @@ void QmlTab::setZoomLevel(int zoomLevel) m_webTab->setZoomLevel(zoomLevel); } -/** - * @brief Stops webview associated with the tab - */ void QmlTab::stop() { if (!m_webTab) { @@ -75,9 +65,6 @@ void QmlTab::stop() m_webTab->stop(); } -/** - * @brief Reloads webview associated with the tab - */ void QmlTab::reload() { if (!m_webTab) { @@ -87,9 +74,6 @@ void QmlTab::reload() m_webTab->reload(); } -/** - * @brief Unloads the tab - */ void QmlTab::unload() { if (!m_webTab) { @@ -99,10 +83,6 @@ void QmlTab::unload() m_webTab->unload(); } -/** - * @brief Loads webview associated with the tab - * @param String representing the url to load - */ void QmlTab::load(const QString &url) { if (!m_webTab) { @@ -114,9 +94,6 @@ void QmlTab::load(const QString &url) m_webTab->load(req); } -/** - * @brief Decreases the zoom level of the tab - */ void QmlTab::zoomIn() { if (!m_webTab) { @@ -126,9 +103,6 @@ void QmlTab::zoomIn() m_webTab->webView()->zoomIn(); } -/** - * @brief Increases the zoom level of the tab - */ void QmlTab::zoomOut() { if (!m_webTab) { @@ -138,9 +112,6 @@ void QmlTab::zoomOut() m_webTab->webView()->zoomOut(); } -/** - * @brief Resets the tab zoom level - */ void QmlTab::zoomReset() { if (!m_webTab) { @@ -150,9 +121,6 @@ void QmlTab::zoomReset() m_webTab->webView()->zoomReset(); } -/** - * @brief Performs edit undo on the tab - */ void QmlTab::undo() { if (!m_webTab) { @@ -162,9 +130,6 @@ void QmlTab::undo() m_webTab->webView()->editUndo(); } -/** - * @brief Performs edit redo on the tab - */ void QmlTab::redo() { if (!m_webTab) { @@ -174,9 +139,6 @@ void QmlTab::redo() m_webTab->webView()->editRedo(); } -/** - * @brief Performs edit select-all on the tab - */ void QmlTab::selectAll() { if (!m_webTab) { @@ -186,9 +148,6 @@ void QmlTab::selectAll() m_webTab->webView()->editSelectAll(); } -/** - * @brief Reloads the tab by bypassing the cache - */ void QmlTab::reloadBypassCache() { if (!m_webTab) { @@ -198,9 +157,6 @@ void QmlTab::reloadBypassCache() m_webTab->webView()->reloadBypassCache(); } -/** - * @brief Loads the previous page - */ void QmlTab::back() { if (!m_webTab) { @@ -210,9 +166,6 @@ void QmlTab::back() m_webTab->webView()->back(); } -/** - * @brief Loads the next page - */ void QmlTab::forward() { if (!m_webTab) { @@ -222,9 +175,6 @@ void QmlTab::forward() m_webTab->webView()->forward(); } -/** - * @brief Prints the page - */ void QmlTab::printPage() { if (!m_webTab) { @@ -234,9 +184,6 @@ void QmlTab::printPage() m_webTab->webView()->printPage(); } -/** - * @brief Shows the page source - */ void QmlTab::showSource() { if (!m_webTab) { @@ -246,9 +193,6 @@ void QmlTab::showSource() m_webTab->webView()->showSource(); } -/** - * @brief Sends page by mail - */ void QmlTab::sendPageByMail() { if (!m_webTab) { @@ -258,11 +202,6 @@ void QmlTab::sendPageByMail() m_webTab->webView()->sendPageByMail(); } -/** - * @brief execute JavaScript function in a page - * @param value, representing JavaScript function - * @return QVariant, the return value of executed javascript - */ QVariant QmlTab::execJavaScript(const QJSValue &value) { if (!m_webPage && !m_webTab) { @@ -275,11 +214,6 @@ QVariant QmlTab::execJavaScript(const QJSValue &value) return webPage->execJavaScript(value.toString()); } -/** - * @brief Gets result of web hit test at a given point - * @param point - * @return result of web hit test - */ QmlWebHitTestResult *QmlTab::hitTestContent(const QPoint &point) { if (!m_webPage && !m_webTab) { @@ -431,6 +365,9 @@ bool QmlTab::canGoForward() const void QmlTab::setWebPage(WebPage *webPage) { + if (m_webPage) { + removeConnections(); + } m_webPage = webPage; TabbedWebView *tabbedWebView = qobject_cast(m_webPage->view()); m_webTab = tabbedWebView->webTab(); @@ -441,29 +378,37 @@ void QmlTab::setWebPage(WebPage *webPage) void QmlTab::createConnections() { - connect(m_webTab, &WebTab::titleChanged, this, [this](const QString &title){ + 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); - connect(m_webTab, &WebTab::pinnedChanged, this, [this](bool pinned){ + auto pinnedChangedConnection = connect(m_webTab, &WebTab::pinnedChanged, this, [this](bool pinned){ emit pinnedChanged(pinned); }); + m_lambdaConnections.append(pinnedChangedConnection); - connect(m_webTab, &WebTab::loadingChanged, this, [this](bool loading){ + auto loadingChangedConnection = connect(m_webTab, &WebTab::loadingChanged, this, [this](bool loading){ emit loadingChanged(loading); }); + m_lambdaConnections.append(loadingChangedConnection); - connect(m_webTab, &WebTab::mutedChanged, this, [this](bool muted){ + auto mutedChangedConnection = connect(m_webTab, &WebTab::mutedChanged, this, [this](bool muted){ emit mutedChanged(muted); }); + m_lambdaConnections.append(mutedChangedConnection); - connect(m_webTab, &WebTab::restoredChanged, this, [this](bool restored){ + auto restoredChangedConnection = connect(m_webTab, &WebTab::restoredChanged, this, [this](bool restored){ emit restoredChanged(restored); }); + m_lambdaConnections.append(restoredChangedConnection); - connect(m_webTab, &WebTab::playingChanged, this, [this](bool playing){ + 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); @@ -473,6 +418,21 @@ void QmlTab::createConnections() } } +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() { } diff --git a/src/lib/plugins/qml/api/tabs/qmltab.h b/src/lib/plugins/qml/api/tabs/qmltab.h index e5ac876d2..fcebd323f 100644 --- a/src/lib/plugins/qml/api/tabs/qmltab.h +++ b/src/lib/plugins/qml/api/tabs/qmltab.h @@ -18,11 +18,12 @@ #pragma once #include +#include +#include + #include "webtab.h" #include "../windows/qmlwindow.h" -#include #include "qml/api/menus/qmlwebhittestresult.h" -#include /** * @brief The class exposing a browser tab to QML @@ -110,25 +111,91 @@ class QmlTab : public QObject 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); @@ -193,6 +260,7 @@ Q_SIGNALS: private: WebTab *m_webTab; WebPage *m_webPage; + QList m_lambdaConnections; QString url() const; QString title() const; @@ -211,6 +279,7 @@ private: bool canGoForward() const; void createConnections(); + void removeConnections(); }; class QmlTabData diff --git a/src/lib/plugins/qml/api/tabs/qmltabs.cpp b/src/lib/plugins/qml/api/tabs/qmltabs.cpp index a423e8cfd..e18afb913 100644 --- a/src/lib/plugins/qml/api/tabs/qmltabs.cpp +++ b/src/lib/plugins/qml/api/tabs/qmltabs.cpp @@ -31,15 +31,6 @@ QmlTabs::QmlTabs(QObject *parent) connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, &QmlTabs::windowCreated); } -/** - * @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 - */ bool QmlTabs::setCurrentIndex(const QVariantMap &map) { if (!map.contains(QSL("index"))) { @@ -57,11 +48,6 @@ bool QmlTabs::setCurrentIndex(const QVariantMap &map) return true; } -/** - * @brief Sets the next tab as current tab - * @param Integer representing the window - * @return True if success, else false - */ bool QmlTabs::nextTab(int windowId) { const auto window = getWindow(windowId); @@ -72,11 +58,6 @@ bool QmlTabs::nextTab(int windowId) return true; } -/** - * @brief Sets the prvious tab as current tab - * @param Integer representing the window - * @return True if success, else false - */ bool QmlTabs::previousTab(int windowId) { const auto window = getWindow(windowId); @@ -87,17 +68,6 @@ bool QmlTabs::previousTab(int windowId) return true; } -/** - * @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 - */ bool QmlTabs::moveTab(const QVariantMap &map) { if (!map.contains(QSL("from"))) { @@ -120,15 +90,6 @@ bool QmlTabs::moveTab(const QVariantMap &map) return true; } -/** - * @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 - */ bool QmlTabs::pinTab(const QVariantMap &map) { if (!map.contains(QSL("index"))) { @@ -153,15 +114,6 @@ bool QmlTabs::pinTab(const QVariantMap &map) return true; } -/** - * @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 - */ bool QmlTabs::unpinTab(const QVariantMap &map) { if (!map.contains(QSL("index"))) { @@ -186,15 +138,6 @@ bool QmlTabs::unpinTab(const QVariantMap &map) return true; } -/** - * @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 - */ bool QmlTabs::detachTab(const QVariantMap &map) { if (!map.contains(QSL("index"))) { @@ -212,15 +155,6 @@ bool QmlTabs::detachTab(const QVariantMap &map) return true; } -/** - * @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 - */ bool QmlTabs::duplicate(const QVariantMap &map) { if (!map.contains(QSL("index"))) { @@ -238,15 +172,6 @@ bool QmlTabs::duplicate(const QVariantMap &map) return true; } -/** - * @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 - */ bool QmlTabs::closeTab(const QVariantMap &map) { if (!map.contains(QSL("index"))) { @@ -264,15 +189,6 @@ bool QmlTabs::closeTab(const QVariantMap &map) return true; } -/** - * @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 - */ bool QmlTabs::reloadTab(const QVariantMap &map) { if (!map.contains(QSL("index"))) { @@ -290,15 +206,6 @@ bool QmlTabs::reloadTab(const QVariantMap &map) return true; } -/** - * @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 - */ bool QmlTabs::stopTab(const QVariantMap &map) { if (!map.contains(QSL("index"))) { @@ -316,15 +223,6 @@ bool QmlTabs::stopTab(const QVariantMap &map) return true; } -/** - * @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 - */ QmlTab *QmlTabs::get(const QVariantMap &map) const { if (!map.contains(QSL("index"))) { @@ -342,11 +240,6 @@ QmlTab *QmlTabs::get(const QVariantMap &map) const return tabData->get(webTab); } -/** - * @brief Get the normal tabs count in a window - * @param Integer representing the window - * @return Number of normal tabs in the window - */ int QmlTabs::normalTabsCount(int windowId) const { const auto window = getWindow(windowId); @@ -356,11 +249,6 @@ int QmlTabs::normalTabsCount(int windowId) const return window->tabWidget()->normalTabsCount(); } -/** - * @brief Get the pinned tabs count in a window - * @param Integer representing the window - * @return Number of pinned tabs in the window - */ int QmlTabs::pinnedTabsCount(int windowId) const { const auto window = getWindow(windowId); @@ -370,15 +258,6 @@ int QmlTabs::pinnedTabsCount(int windowId) const return window->tabWidget()->pinnedTabsCount(); } -/** - * @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) - */ QList QmlTabs::getAll(const QVariantMap &map) const { const auto window = getWindow(map); @@ -397,18 +276,6 @@ QList QmlTabs::getAll(const QVariantMap &map) const return list; } -/** - * @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 - */ QList QmlTabs::search(const QVariantMap &map) { const QString title = map.value(QSL("title")).toString(); @@ -426,15 +293,6 @@ QList QmlTabs::search(const QVariantMap &map) return list; } -/** - * @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 - */ bool QmlTabs::addTab(const QVariantMap &map) { const QString urlString = map.value(QSL("url")).toString(); diff --git a/src/lib/plugins/qml/api/tabs/qmltabs.h b/src/lib/plugins/qml/api/tabs/qmltabs.h index 3646f5e2c..f068e95d3 100644 --- a/src/lib/plugins/qml/api/tabs/qmltabs.h +++ b/src/lib/plugins/qml/api/tabs/qmltabs.h @@ -29,22 +29,164 @@ 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 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 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: /** diff --git a/src/lib/plugins/qml/api/topsites/qmltopsites.cpp b/src/lib/plugins/qml/api/topsites/qmltopsites.cpp index c1ce28a9b..978486026 100644 --- a/src/lib/plugins/qml/api/topsites/qmltopsites.cpp +++ b/src/lib/plugins/qml/api/topsites/qmltopsites.cpp @@ -27,15 +27,8 @@ QmlTopSites::QmlTopSites(QObject *parent) { } -/** - * @brief Get the topsites. These refer to the sites which - * are displayed in the speed-dial (New tab page) - * @return List of MostVisitedUrl objects of type [QmlMostVisitedUrl](@ref QmlMostVisitedUrl) - */ QList QmlTopSites::get() const { - // FIXME: this slows the startup of browser - QList pages = mApp->plugins()->speedDial()->pages(); QList list; foreach(SpeedDial::Page page, pages) { diff --git a/src/lib/plugins/qml/api/topsites/qmltopsites.h b/src/lib/plugins/qml/api/topsites/qmltopsites.h index 6121640fc..4d52dbae0 100644 --- a/src/lib/plugins/qml/api/topsites/qmltopsites.h +++ b/src/lib/plugins/qml/api/topsites/qmltopsites.h @@ -28,5 +28,10 @@ class QmlTopSites : public QObject Q_OBJECT public: explicit QmlTopSites(QObject *parent = nullptr); + /** + * @brief Get the topsites. These refer to the sites which + * are displayed in the speed-dial (New tab page) + * @return List of MostVisitedUrl objects of type [QmlMostVisitedUrl](@ref QmlMostVisitedUrl) + */ Q_INVOKABLE QList get() const; }; diff --git a/src/lib/plugins/qml/api/userscript/qmluserscripts.cpp b/src/lib/plugins/qml/api/userscript/qmluserscripts.cpp index 2842f8056..b2f9a0103 100644 --- a/src/lib/plugins/qml/api/userscript/qmluserscripts.cpp +++ b/src/lib/plugins/qml/api/userscript/qmluserscripts.cpp @@ -59,11 +59,6 @@ QList QmlUserScripts::toQObjectList(QList list) con return userScriptList; } -/** - * @brief Checks if the script is in collection - * @param object of type QmlUserScript - * @return true if the the script in in collection, else false - */ bool QmlUserScripts::contains(QObject *object) const { QmlUserScript *userScript = qobject_cast(object); @@ -74,11 +69,6 @@ bool QmlUserScripts::contains(QObject *object) const return mApp->webProfile()->scripts()->contains(webEngineScript); } -/** - * @brief Finds a script in collection by name - * @param name of the script - * @return object of type QmlUserScript, representing the script of given name - */ QObject *QmlUserScripts::findScript(const QString &name) const { QWebEngineScript webEngineScript = mApp->webProfile()->scripts()->findScript(name); @@ -87,20 +77,12 @@ QObject *QmlUserScripts::findScript(const QString &name) const return qmlUserScript; } -/** - * @brief Finds all scripts in collection by a given name - * @return list of objects, each of type QmlUserScript, representing the script of given name - */ QList QmlUserScripts::findScripts(const QString &name) const { QList list = mApp->webProfile()->scripts()->findScripts(name); return toQObjectList(list); } -/** - * @brief Inserts a script into collection - * @param object of type QmlUserScript - */ void QmlUserScripts::insert(QObject *object) { QmlUserScript *userScript = qobject_cast(object); @@ -112,10 +94,6 @@ void QmlUserScripts::insert(QObject *object) m_webEngineScripts.append(webEngineScript); } -/** - * @brief Inserts a list of scripts into collection - * @param list of objects, each of type QmlUserScript - */ void QmlUserScripts::insert(const QList &list) { for (QObject *object : list) { @@ -129,10 +107,6 @@ void QmlUserScripts::insert(const QList &list) } } -/** - * @brief Removes a script from collection - * @param object of type QmlUserScript - */ void QmlUserScripts::remove(QObject *object) const { QmlUserScript *userScript = qobject_cast(object); @@ -143,10 +117,6 @@ void QmlUserScripts::remove(QObject *object) const mApp->webProfile()->scripts()->remove(webEngineScript); } -/** - * @brief Gets all the scripts of the collection - * @return list of objects, each of type QmlUserScript - */ QList QmlUserScripts::toList() const { QList list = mApp->webProfile()->scripts()->toList(); diff --git a/src/lib/plugins/qml/api/userscript/qmluserscripts.h b/src/lib/plugins/qml/api/userscript/qmluserscripts.h index 5a9ffc21d..cb8fc5ce1 100644 --- a/src/lib/plugins/qml/api/userscript/qmluserscripts.h +++ b/src/lib/plugins/qml/api/userscript/qmluserscripts.h @@ -41,12 +41,42 @@ class FALKON_EXPORT QmlUserScripts : public QObject 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 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 &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 toList() const; private: int count() const; diff --git a/src/lib/plugins/qml/api/windows/qmlwindows.cpp b/src/lib/plugins/qml/api/windows/qmlwindows.cpp index e123845d0..b707e978f 100644 --- a/src/lib/plugins/qml/api/windows/qmlwindows.cpp +++ b/src/lib/plugins/qml/api/windows/qmlwindows.cpp @@ -35,29 +35,16 @@ QmlWindows::QmlWindows(QObject *parent) }); } -/** - * @brief Gets a browser window - * @param Integer representing the browser window - * @return Object of type [QmlWindow](@ref QmlWindow) - */ QmlWindow *QmlWindows::get(int id) const { return windowData->get(getBrowserWindow(id)); } -/** - * @brief Gets the current browser window - * @return Object of type [QmlWindow](@ref QmlWindow) - */ QmlWindow *QmlWindows::getCurrent() const { return windowData->get(mApp->getWindow()); } -/** - * @brief Get all the browser window - * @return List of windows of type [QmlWindow](@ref QmlWindow) - */ QList QmlWindows::getAll() const { QList list; @@ -67,15 +54,6 @@ QList QmlWindows::getAll() const return list; } -/** - * @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 - */ QmlWindow *QmlWindows::create(const QVariantMap &map) const { const QUrl url = QUrl::fromEncoded(map.value(QSL("url")).toString().toUtf8()); @@ -84,10 +62,6 @@ QmlWindow *QmlWindows::create(const QVariantMap &map) const return windowData->get(window); } -/** - * @brief Removes a browser window - * @param Integer representing the window id - */ void QmlWindows::remove(int windowId) const { BrowserWindow *window = getBrowserWindow(windowId); diff --git a/src/lib/plugins/qml/api/windows/qmlwindows.h b/src/lib/plugins/qml/api/windows/qmlwindows.h index 4cbe37a9b..835ee71d6 100644 --- a/src/lib/plugins/qml/api/windows/qmlwindows.h +++ b/src/lib/plugins/qml/api/windows/qmlwindows.h @@ -28,10 +28,36 @@ 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 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: /** diff --git a/src/lib/plugins/qml/qmlplugininterface.cpp b/src/lib/plugins/qml/qmlplugininterface.cpp index f898949bf..b37f3b9d6 100644 --- a/src/lib/plugins/qml/qmlplugininterface.cpp +++ b/src/lib/plugins/qml/qmlplugininterface.cpp @@ -39,6 +39,7 @@ QmlPluginInterface::QmlPluginInterface() : m_settingsWindow(nullptr) + , m_qmlReusableTab(new QmlTab()) { } @@ -221,10 +222,9 @@ bool QmlPluginInterface::acceptNavigationRequest(WebPage *page, const QUrl &url, if (!m_acceptNavigationRequest.isCallable()) { return true; } - QmlTab *qmlTab = new QmlTab(); - qmlTab->setWebPage(page); + m_qmlReusableTab->setWebPage(page); QJSValueList args; - args.append(m_engine->newQObject(qmlTab)); + args.append(m_engine->newQObject(m_qmlReusableTab)); args.append(QString::fromUtf8(url.toEncoded())); args.append(type); args.append(isMainFrame); diff --git a/src/lib/plugins/qml/qmlplugininterface.h b/src/lib/plugins/qml/qmlplugininterface.h index aad2b88d0..db0926c49 100644 --- a/src/lib/plugins/qml/qmlplugininterface.h +++ b/src/lib/plugins/qml/qmlplugininterface.h @@ -24,6 +24,8 @@ #include "desktopfile.h" #include "plugininterface.h" +class QmlTab; + class QmlPluginInterface : public QObject, public PluginInterface { Q_OBJECT @@ -72,13 +74,13 @@ Q_SIGNALS: void qmlPluginUnloaded(); private: - QQmlEngine *m_engine; + QQmlEngine *m_engine = nullptr; QString m_name; QJSValue m_init; QJSValue m_unload; QJSValue m_testPlugin; QJSValue m_populateWebViewMenu; - QQmlComponent *m_settingsWindow; + QQmlComponent *m_settingsWindow = nullptr; QJSValue m_mouseDoubleClick; QJSValue m_mousePress; QJSValue m_mouseRelease; @@ -88,6 +90,7 @@ private: QJSValue m_keyRelease; QJSValue m_acceptNavigationRequest; QList m_childItems; + QmlTab *m_qmlReusableTab = nullptr; QJSValue readInit() const; void setInit(const QJSValue &init);