Falkon Develop
Cross-platform Qt-based web browser
qmlstaticdata.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "qmlstaticdata.h"
22#include "api/tabs/qmltab.h"
26#include "pluginproxy.h"
27
28#include <QQmlEngine>
29
31 : QObject(parent)
32{
33 const QList<BrowserWindow*> windows = mApp->windows();
34 for (BrowserWindow *window : windows) {
35 m_windowIdHash.insert(window, m_newWindowId++);
36 }
37
38 connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, [this](BrowserWindow *window) {
39 m_windowIdHash.insert(window, m_newWindowId++);
40 });
41
42 connect(mApp->plugins(), &PluginProxy::mainWindowDeleted, this, [this](BrowserWindow *window) {
43 m_windowIdHash.remove(window);
44 });
45}
46
48{
49 qDeleteAll(m_bookmarkTreeNodes);
50 qDeleteAll(m_cookies);
51 qDeleteAll(m_historyItems);
52 qDeleteAll(m_tabs);
53 qDeleteAll(m_urls);
54 qDeleteAll(m_windows);
55}
56
58{
59 static QmlStaticData qmlStaticData;
60 return qmlStaticData;
61}
62
64{
65 QmlBookmarkTreeNode *node = m_bookmarkTreeNodes.value(item);
66 if (!node) {
67 node = new QmlBookmarkTreeNode(item);
68 m_bookmarkTreeNodes.insert(item, node);
69 }
70 return node;
71}
72
73QmlCookie *QmlStaticData::getCookie(const QNetworkCookie &cookie)
74{
75 QmlCookie *qmlCookie = m_cookies.value(cookie);
76 if (!qmlCookie) {
77 qmlCookie = new QmlCookie(new QNetworkCookie(cookie));
78 m_cookies.insert(cookie, qmlCookie);
79 }
80 return qmlCookie;
81}
82
84{
85 QmlHistoryItem *item = m_historyItems.value(entry);
86 if (!item) {
87 item = new QmlHistoryItem(entry);
88 m_historyItems.insert(entry, item);
89 }
90 return item;
91}
92
94{
95 QmlTab *tab = m_tabs.value(webTab);
96 if (!tab) {
97 tab = new QmlTab(webTab);
98 m_tabs.insert(webTab, tab);
99 }
100 return tab;
101}
102
103QmlMostVisitedUrl *QmlStaticData::getMostVisitedUrl(const QString &title, const QString &url)
104{
105 QmlMostVisitedUrl *visitedUrl = m_urls.value({title, url});
106 if (!visitedUrl) {
107 visitedUrl = new QmlMostVisitedUrl(title, url);
108 m_urls.insert({title, url}, visitedUrl);
109 }
110 return visitedUrl;
111}
112
114{
115 QmlWindow *qmlWindow = m_windows.value(window);
116 if (!qmlWindow) {
117 qmlWindow = new QmlWindow(window);
118 m_windows.insert(window, qmlWindow);
119 }
120 return qmlWindow;
121}
122
123QHash<BrowserWindow*, int> QmlStaticData::windowIdHash()
124{
125 return m_windowIdHash;
126}
127
128QIcon QmlStaticData::getIcon(const QString &iconPath, const QString &pluginPath)
129{
130 QIcon icon;
131 if (QIcon::hasThemeIcon(iconPath)) {
132 icon = QIcon::fromTheme(iconPath);
133 } else {
134 QmlFileUtils fileUtils(pluginPath);
135 icon = QIcon(fileUtils.resolve(iconPath));
136 }
137 return icon;
138}
139
141{
142 static auto *bookmarks = new QmlBookmarks(this);
143 QQmlEngine::setObjectOwnership(bookmarks, QQmlEngine::CppOwnership);
144 return bookmarks;
145}
146
148{
149 static auto *history = new QmlHistory(this);
150 QQmlEngine::setObjectOwnership(history, QQmlEngine::CppOwnership);
151 return history;
152}
153
155{
156 static auto *cookies = new QmlCookies(this);
157 QQmlEngine::setObjectOwnership(cookies, QQmlEngine::CppOwnership);
158 return cookies;
159}
160
162{
163 static auto *topSites = new QmlTopSites(this);
164 QQmlEngine::setObjectOwnership(topSites, QQmlEngine::CppOwnership);
165 return topSites;
166}
167
169{
170 static auto *tabs = new QmlTabs(this);
171 QQmlEngine::setObjectOwnership(tabs, QQmlEngine::CppOwnership);
172 return tabs;
173}
174
176{
177 static auto *clipboard = new QmlClipboard(this);
178 QQmlEngine::setObjectOwnership(clipboard, QQmlEngine::CppOwnership);
179 return clipboard;
180}
181
183{
184 static auto *windows = new QmlWindows(this);
185 QQmlEngine::setObjectOwnership(windows, QQmlEngine::CppOwnership);
186 return windows;
187}
188
190{
191 static auto *externalJsObject = new QmlExternalJsObject(this);
192 QQmlEngine::setObjectOwnership(externalJsObject, QQmlEngine::CppOwnership);
193 return externalJsObject;
194}
195
197{
198 static auto *userScripts = new QmlUserScripts(this);
199 QQmlEngine::setObjectOwnership(userScripts, QQmlEngine::CppOwnership);
200 return userScripts;
201}
void mainWindowDeleted(BrowserWindow *window)
void mainWindowCreated(BrowserWindow *window)
The class exposing the bookmark item to QML.
The class exposing the Bookmarks API to QML.
Definition: qmlbookmarks.h:29
The class exposing application clipboard to QML.
Definition: qmlclipboard.h:27
The class exposing Cookies API to QML.
Definition: qmlcookies.h:27
The QmlFileUtils class, exposed to QML as FileUtils.
Definition: qmlfileutils.h:26
Q_INVOKABLE QString resolve(const QString &filePath)
Get the path of the file within the plugin directory. If the filePath provided is resolved to be outs...
The class exposing the History API to QML.
Definition: qmlhistory.h:27
The class exposing HistoryEntry to QML.
The class exposing MostVisitedUrl type to QML.
QmlClipboard * getClipboardSingleton()
QHash< BrowserWindow *, int > windowIdHash()
QmlCookie * getCookie(const QNetworkCookie &cookie)
QmlBookmarks * getBookmarksSingleton()
QmlTab * getTab(WebTab *webTab)
QmlUserScripts * getUserScriptsSingleton()
QmlHistoryItem * getHistoryItem(const HistoryEntry &entry)
QmlExternalJsObject * getExternalJsObjectSingleton()
QmlTopSites * getTopSitesSingleton()
QmlStaticData(QObject *parent=nullptr)
static QmlStaticData & instance()
QmlWindow * getWindow(BrowserWindow *window)
QIcon getIcon(const QString &iconPath, const QString &pluginPath)
QmlTabs * getTabsSingleton()
QmlCookies * getCookiesSingleton()
QmlMostVisitedUrl * getMostVisitedUrl(const QString &title=QString(), const QString &url=QString())
QmlBookmarkTreeNode * getBookmarkTreeNode(BookmarkItem *item)
QmlWindows * getWindowsSingleton()
QmlHistory * getHistorySingleton()
The class exposing a browser tab to QML.
Definition: qmltab.h:32
The class exposing Tabs API to QML.
Definition: qmltabs.h:28
The class exposing TopSites API to QML.
Definition: qmltopsites.h:27
The class exposing QWebEngineScriptCollection to QML.
The class exposing Browser window to QML.
Definition: qmlwindow.h:27
The class exposing Windows API to QML.
Definition: qmlwindows.h:27
Definition: webtab.h:40
#define mApp
Definition: history.h:39