File indexing completed on 2024-12-22 04:41:15
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "qmlplugins.h" 0019 #include "qmlplugininterface.h" 0020 #include "qmlengine.h" 0021 #include "api/bookmarks/qmlbookmarktreenode.h" 0022 #include "api/bookmarks/qmlbookmarks.h" 0023 #include "api/topsites/qmlmostvisitedurl.h" 0024 #include "api/topsites/qmltopsites.h" 0025 #include "api/history/qmlhistoryitem.h" 0026 #include "api/history/qmlhistory.h" 0027 #include "api/cookies/qmlcookie.h" 0028 #include "api/cookies/qmlcookies.h" 0029 #include "api/tabs/qmltab.h" 0030 #include "api/tabs/qmltabs.h" 0031 #include "api/notifications/qmlnotifications.h" 0032 #include "api/clipboard/qmlclipboard.h" 0033 #include "api/windows/qmlwindow.h" 0034 #include "api/windows/qmlwindows.h" 0035 #include "api/browseraction/qmlbrowseraction.h" 0036 #include "api/sidebar/qmlsidebar.h" 0037 #include "api/menus/qmlmenu.h" 0038 #include "api/menus/qmlaction.h" 0039 #include "api/menus/qmlwebhittestresult.h" 0040 #include "api/settings/qmlsettings.h" 0041 #include "api/events/qmlqzobjects.h" 0042 #include "api/events/qmlkeyevent.h" 0043 #include "api/events/qmlmouseevent.h" 0044 #include "api/events/qmlwheelevent.h" 0045 #include "api/userscript/qmluserscript.h" 0046 #include "api/userscript/qmluserscripts.h" 0047 #include "api/userscript/qmlexternaljsobject.h" 0048 #include "api/extensionscheme/qmlextensionscheme.h" 0049 #include "api/extensionscheme/qmlwebengineurlrequestjob.h" 0050 #include "api/fileutils/qmlfileutils.h" 0051 #include "api/qmlenums.h" 0052 #include "qml/qmlstaticdata.h" 0053 #include <QQmlEngine> 0054 #include <QQmlContext> 0055 0056 // static 0057 void QmlPlugins::registerQmlTypes() 0058 { 0059 const char *url = "org.kde.falkon"; 0060 const int majorVersion = 1; 0061 const int minorVersion = 0; 0062 // PluginInterface 0063 qmlRegisterType<QmlPluginInterface>(url, majorVersion, minorVersion, "PluginInterface"); 0064 0065 // Bookmarks 0066 qmlRegisterUncreatableType<QmlBookmarkTreeNode>(url, majorVersion, minorVersion, "BookmarkTreeNode", QSL("Unable to register type: BookmarkTreeNode")); 0067 0068 qmlRegisterSingletonType<QmlBookmarks>(url, majorVersion, minorVersion, "Bookmarks", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0069 Q_UNUSED(engine) 0070 Q_UNUSED(scriptEngine) 0071 0072 return QmlStaticData::instance().getBookmarksSingleton(); 0073 }); 0074 0075 // TopSites 0076 qmlRegisterUncreatableType<QmlMostVisitedUrl>(url, majorVersion, minorVersion, "MostVisitedURL", QSL("Unable to register type: MostVisitedURL")); 0077 0078 qmlRegisterSingletonType<QmlTopSites>(url, majorVersion, minorVersion, "TopSites", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0079 Q_UNUSED(engine) 0080 Q_UNUSED(scriptEngine) 0081 0082 return QmlStaticData::instance().getTopSitesSingleton(); 0083 }); 0084 0085 // History 0086 qmlRegisterUncreatableType<QmlHistoryItem>(url, majorVersion, minorVersion, "HistoryItem", QSL("Unable to register type: HistoryItem")); 0087 0088 qmlRegisterSingletonType<QmlHistory>(url, majorVersion, minorVersion, "History", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0089 Q_UNUSED(engine) 0090 Q_UNUSED(scriptEngine) 0091 0092 return QmlStaticData::instance().getHistorySingleton(); 0093 }); 0094 0095 // Cookies 0096 qmlRegisterUncreatableType<QmlCookie>(url, majorVersion, minorVersion, "Cookie", QSL("Unable to register type: Cookie")); 0097 0098 qmlRegisterSingletonType<QmlCookies>(url, majorVersion, minorVersion, "Cookies", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0099 Q_UNUSED(engine) 0100 Q_UNUSED(scriptEngine) 0101 0102 return QmlStaticData::instance().getCookiesSingleton(); 0103 }); 0104 0105 // Tabs 0106 qmlRegisterUncreatableType<QmlTab>(url, majorVersion, minorVersion, "Tab", QSL("Unable to register type: Tab")); 0107 0108 qmlRegisterSingletonType<QmlTabs>(url, majorVersion, minorVersion, "Tabs", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0109 Q_UNUSED(engine) 0110 Q_UNUSED(scriptEngine) 0111 0112 return QmlStaticData::instance().getTabsSingleton(); 0113 }); 0114 0115 // Notifications 0116 qmlRegisterSingletonType<QmlNotifications>(url, majorVersion, minorVersion, "Notifications", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0117 Q_UNUSED(scriptEngine) 0118 0119 auto *qmlEngine = qobject_cast<QmlEngine*>(engine); 0120 if (!qmlEngine) { 0121 qWarning() << "Unable to cast QQmlEngine * to QmlEngine *"; 0122 return nullptr; 0123 } 0124 QString filePath = qmlEngine->extensionPath(); 0125 0126 auto *object = new QmlNotifications(); 0127 object->setPluginPath(filePath); 0128 return object; 0129 }); 0130 0131 // Clipboard 0132 qmlRegisterSingletonType<QmlClipboard>(url, majorVersion, minorVersion, "Clipboard", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0133 Q_UNUSED(engine) 0134 Q_UNUSED(scriptEngine) 0135 0136 return QmlStaticData::instance().getClipboardSingleton(); 0137 }); 0138 0139 // Windows 0140 qmlRegisterUncreatableType<QmlWindow>(url, majorVersion, minorVersion, "Window", QSL("Unable to register type: Window")); 0141 0142 qmlRegisterSingletonType<QmlWindows>(url, majorVersion, minorVersion, "Windows", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0143 Q_UNUSED(engine) 0144 Q_UNUSED(scriptEngine) 0145 0146 return QmlStaticData::instance().getWindowsSingleton(); 0147 }); 0148 0149 // BrowserAction 0150 qmlRegisterType<QmlBrowserAction>(url, majorVersion, minorVersion, "BrowserAction"); 0151 0152 // SideBar 0153 qmlRegisterType<QmlSideBar>(url, majorVersion, minorVersion, "SideBar"); 0154 0155 // Menu 0156 qmlRegisterUncreatableType<QmlMenu>(url, majorVersion, minorVersion, "Menu", QSL("Unable to register type: Menu")); 0157 0158 // Action 0159 qmlRegisterUncreatableType<QmlAction>(url, majorVersion, minorVersion, "Action", QSL("Unable to register type: Action")); 0160 0161 // WebHitTestResult 0162 qmlRegisterUncreatableType<QmlWebHitTestResult>(url, majorVersion, minorVersion, "WebHitTestResult", QSL("Unable to register type: WebHitTestResult")); 0163 0164 // Settings 0165 qmlRegisterType<QmlSettings>(url, majorVersion, minorVersion, "Settings"); 0166 0167 // Qz::Objects 0168 qmlRegisterUncreatableType<QmlQzObjects>(url, majorVersion, minorVersion, "QzObjects", QSL("Unable to register type: QzObjects")); 0169 0170 // KeyEvents 0171 qmlRegisterUncreatableType<QmlKeyEvent>(url, majorVersion, minorVersion, "KeyEvent", QSL("Unable to register type: KeyEvent")); 0172 0173 // MouseEvents 0174 qmlRegisterUncreatableType<QmlMouseEvent>(url, majorVersion, minorVersion, "MouseEvent", QSL("Unable to register type: MouseEvent")); 0175 0176 // WheelEvents 0177 qmlRegisterUncreatableType<QmlWheelEvent>(url, majorVersion, minorVersion, "WheelEvent", QSL("Unable to register type: WheelEvent")); 0178 0179 // UserScripts 0180 qmlRegisterType<QmlUserScript>(url, majorVersion, minorVersion, "UserScript"); 0181 0182 qmlRegisterSingletonType<QmlUserScripts>(url, majorVersion, minorVersion, "UserScripts", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0183 Q_UNUSED(engine) 0184 Q_UNUSED(scriptEngine) 0185 0186 return QmlStaticData::instance().getUserScriptsSingleton(); 0187 }); 0188 0189 qmlRegisterSingletonType<QmlExternalJsObject>(url, majorVersion, minorVersion, "ExternalJsObject", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0190 Q_UNUSED(engine) 0191 Q_UNUSED(scriptEngine) 0192 0193 return QmlStaticData::instance().getExternalJsObjectSingleton(); 0194 }); 0195 0196 // ExtensionScheme 0197 qmlRegisterType<QmlExtensionScheme>(url, majorVersion, minorVersion, "ExtensionScheme"); 0198 0199 qmlRegisterUncreatableType<QmlWebEngineUrlRequestJob>(url, majorVersion, minorVersion, "WebEngineUrlRequestJob", QSL("Unable to register type: WebEngineUrlRequestJob")); 0200 0201 // FileUtils 0202 qmlRegisterSingletonType<QmlFileUtils>(url, majorVersion, minorVersion, "FileUtils", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0203 Q_UNUSED(scriptEngine) 0204 0205 auto *qmlEngine = qobject_cast<QmlEngine*>(engine); 0206 if (!qmlEngine) { 0207 qWarning() << "Unable to cast QQmlEngine * to QmlEngine *"; 0208 return nullptr; 0209 } 0210 QString filePath = qmlEngine->extensionPath(); 0211 return new QmlFileUtils(filePath); 0212 }); 0213 0214 qmlRegisterUncreatableType<QmlEnums>(url, majorVersion, minorVersion, "Enums", QSL("Unable to register type: Enums")); 0215 }