File indexing completed on 2024-04-21 03:56:00
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Alan Alpert <alan.alpert@nokia.com> 0003 * SPDX-FileCopyrightText: 2010 Ménard Alexis <menard@kde.org> 0004 * SPDX-FileCopyrightText: 2010 Marco Martin <mart@kde.org> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "kirigamiplugin.h" 0010 0011 #include <QIcon> 0012 #if defined(Q_OS_ANDROID) 0013 #include <QResource> 0014 #endif 0015 #include <QQmlContext> 0016 #include <QQuickItem> 0017 0018 #include "platform/styleselector.h" 0019 0020 #ifdef KIRIGAMI_BUILD_TYPE_STATIC 0021 #include "loggingcategory.h" 0022 #include <QDebug> 0023 #endif 0024 0025 // This is required for declarative registration to work on Windows. 0026 // This is normally generated by Qt but since we need a manually written plugin 0027 // file, we need to include this ourselves. 0028 extern void qml_register_types_org_kde_kirigami(); 0029 Q_GHS_KEEP_REFERENCE(qml_register_types_org_kde_kirigami) 0030 0031 // we can't do this in the plugin object directly, as that can live in a different thread 0032 // and event filters are only allowed in the same thread as the filtered object 0033 class LanguageChangeEventFilter : public QObject 0034 { 0035 Q_OBJECT 0036 public: 0037 bool eventFilter(QObject *receiver, QEvent *event) override 0038 { 0039 if (event->type() == QEvent::LanguageChange && receiver == QCoreApplication::instance()) { 0040 Q_EMIT languageChangeEvent(); 0041 } 0042 return QObject::eventFilter(receiver, event); 0043 } 0044 0045 Q_SIGNALS: 0046 void languageChangeEvent(); 0047 }; 0048 0049 KirigamiPlugin::KirigamiPlugin(QObject *parent) 0050 : QQmlExtensionPlugin(parent) 0051 { 0052 // See above. 0053 volatile auto registration = &qml_register_types_org_kde_kirigami; 0054 Q_UNUSED(registration) 0055 0056 auto filter = new LanguageChangeEventFilter; 0057 filter->moveToThread(QCoreApplication::instance()->thread()); 0058 QCoreApplication::instance()->installEventFilter(filter); 0059 connect(filter, &LanguageChangeEventFilter::languageChangeEvent, this, &KirigamiPlugin::languageChangeEvent); 0060 } 0061 0062 QUrl KirigamiPlugin::componentUrl(const QString &fileName) const 0063 { 0064 return Kirigami::Platform::StyleSelector::componentUrl(fileName); 0065 } 0066 0067 void KirigamiPlugin::registerTypes(const char *uri) 0068 { 0069 #if defined(Q_OS_ANDROID) 0070 QResource::registerResource(QStringLiteral("assets:/android_rcc_bundle.rcc")); 0071 #endif 0072 0073 Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.kirigami")); 0074 0075 Kirigami::Platform::StyleSelector::setBaseUrl(baseUrl()); 0076 0077 if (QIcon::themeName().isEmpty() && !qEnvironmentVariableIsSet("XDG_CURRENT_DESKTOP")) { 0078 #if defined(Q_OS_ANDROID) 0079 QIcon::setThemeSearchPaths({QStringLiteral("assets:/qml/org/kde/kirigami"), QStringLiteral(":/icons")}); 0080 #else 0081 QIcon::setThemeSearchPaths({Kirigami::Platform::StyleSelector::resolveFilePath(QStringLiteral(".")), QStringLiteral(":/icons")}); 0082 #endif 0083 QIcon::setThemeName(QStringLiteral("breeze-internal")); 0084 } else { 0085 QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << Kirigami::Platform::StyleSelector::resolveFilePath(QStringLiteral("icons"))); 0086 } 0087 0088 qmlRegisterType(componentUrl(QStringLiteral("Action.qml")), uri, 2, 0, "Action"); 0089 qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationHeader.qml")), uri, 2, 0, "AbstractApplicationHeader"); 0090 qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationWindow.qml")), uri, 2, 0, "AbstractApplicationWindow"); 0091 qmlRegisterType(componentUrl(QStringLiteral("ApplicationWindow.qml")), uri, 2, 0, "ApplicationWindow"); 0092 qmlRegisterType(componentUrl(QStringLiteral("OverlayDrawer.qml")), uri, 2, 0, "OverlayDrawer"); 0093 qmlRegisterType(componentUrl(QStringLiteral("ContextDrawer.qml")), uri, 2, 0, "ContextDrawer"); 0094 qmlRegisterType(componentUrl(QStringLiteral("GlobalDrawer.qml")), uri, 2, 0, "GlobalDrawer"); 0095 qmlRegisterType(componentUrl(QStringLiteral("Heading.qml")), uri, 2, 0, "Heading"); 0096 qmlRegisterType(componentUrl(QStringLiteral("Separator.qml")), uri, 2, 0, "Separator"); 0097 qmlRegisterType(componentUrl(QStringLiteral("PageRow.qml")), uri, 2, 0, "PageRow"); 0098 0099 qmlRegisterType(componentUrl(QStringLiteral("OverlaySheet.qml")), uri, 2, 0, "OverlaySheet"); 0100 qmlRegisterType(componentUrl(QStringLiteral("Page.qml")), uri, 2, 0, "Page"); 0101 qmlRegisterType(componentUrl(QStringLiteral("ScrollablePage.qml")), uri, 2, 0, "ScrollablePage"); 0102 qmlRegisterType(componentUrl(QStringLiteral("SwipeListItem.qml")), uri, 2, 0, "SwipeListItem"); 0103 0104 // 2.1 0105 qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationItem.qml")), uri, 2, 1, "AbstractApplicationItem"); 0106 qmlRegisterType(componentUrl(QStringLiteral("ApplicationItem.qml")), uri, 2, 1, "ApplicationItem"); 0107 0108 // 2.3 0109 qmlRegisterType(componentUrl(QStringLiteral("FormLayout.qml")), uri, 2, 3, "FormLayout"); 0110 0111 // 2.4 0112 qmlRegisterType(componentUrl(QStringLiteral("AbstractCard.qml")), uri, 2, 4, "AbstractCard"); 0113 qmlRegisterType(componentUrl(QStringLiteral("Card.qml")), uri, 2, 4, "Card"); 0114 qmlRegisterType(componentUrl(QStringLiteral("CardsListView.qml")), uri, 2, 4, "CardsListView"); 0115 qmlRegisterType(componentUrl(QStringLiteral("CardsGridView.qml")), uri, 2, 4, "CardsGridView"); 0116 qmlRegisterType(componentUrl(QStringLiteral("CardsLayout.qml")), uri, 2, 4, "CardsLayout"); 0117 qmlRegisterType(componentUrl(QStringLiteral("InlineMessage.qml")), uri, 2, 4, "InlineMessage"); 0118 0119 // 2.5 0120 qmlRegisterType(componentUrl(QStringLiteral("ListItemDragHandle.qml")), uri, 2, 5, "ListItemDragHandle"); 0121 qmlRegisterType(componentUrl(QStringLiteral("ActionToolBar.qml")), uri, 2, 5, "ActionToolBar"); 0122 0123 // 2.6 0124 qmlRegisterType(componentUrl(QStringLiteral("AboutPage.qml")), uri, 2, 6, "AboutPage"); 0125 qmlRegisterType(componentUrl(QStringLiteral("LinkButton.qml")), uri, 2, 6, "LinkButton"); 0126 qmlRegisterType(componentUrl(QStringLiteral("UrlButton.qml")), uri, 2, 6, "UrlButton"); 0127 0128 // 2.7 0129 qmlRegisterType(componentUrl(QStringLiteral("ActionTextField.qml")), uri, 2, 7, "ActionTextField"); 0130 0131 // 2.8 0132 qmlRegisterType(componentUrl(QStringLiteral("SearchField.qml")), uri, 2, 8, "SearchField"); 0133 qmlRegisterType(componentUrl(QStringLiteral("PasswordField.qml")), uri, 2, 8, "PasswordField"); 0134 0135 // 2.10 0136 qmlRegisterType(componentUrl(QStringLiteral("ListSectionHeader.qml")), uri, 2, 10, "ListSectionHeader"); 0137 0138 // 2.11 0139 qmlRegisterType(componentUrl(QStringLiteral("PagePoolAction.qml")), uri, 2, 11, "PagePoolAction"); 0140 0141 // 2.12 0142 qmlRegisterType(componentUrl(QStringLiteral("ShadowedImage.qml")), uri, 2, 12, "ShadowedImage"); 0143 qmlRegisterType(componentUrl(QStringLiteral("PlaceholderMessage.qml")), uri, 2, 12, "PlaceholderMessage"); 0144 0145 // 2.14 0146 qmlRegisterType(componentUrl(QStringLiteral("FlexColumn.qml")), uri, 2, 14, "FlexColumn"); 0147 qmlRegisterType(componentUrl(QStringLiteral("CheckableListItem.qml")), uri, 2, 14, "CheckableListItem"); 0148 0149 // 2.19 0150 qmlRegisterType(componentUrl(QStringLiteral("AboutItem.qml")), uri, 2, 19, "AboutItem"); 0151 qmlRegisterType(componentUrl(QStringLiteral("NavigationTabBar.qml")), uri, 2, 19, "NavigationTabBar"); 0152 qmlRegisterType(componentUrl(QStringLiteral("NavigationTabButton.qml")), uri, 2, 19, "NavigationTabButton"); 0153 qmlRegisterType(componentUrl(QStringLiteral("Dialog.qml")), uri, 2, 19, "Dialog"); 0154 qmlRegisterType(componentUrl(QStringLiteral("MenuDialog.qml")), uri, 2, 19, "MenuDialog"); 0155 qmlRegisterType(componentUrl(QStringLiteral("PromptDialog.qml")), uri, 2, 19, "PromptDialog"); 0156 qmlRegisterType(componentUrl(QStringLiteral("Chip.qml")), uri, 2, 19, "Chip"); 0157 qmlRegisterType(componentUrl(QStringLiteral("LoadingPlaceholder.qml")), uri, 2, 19, "LoadingPlaceholder"); 0158 0159 // 2.20 0160 qmlRegisterType(componentUrl(QStringLiteral("SelectableLabel.qml")), uri, 2, 20, "SelectableLabel"); 0161 qmlRegisterType(componentUrl(QStringLiteral("InlineViewHeader.qml")), uri, 2, 20, "InlineViewHeader"); 0162 } 0163 0164 void KirigamiPlugin::initializeEngine(QQmlEngine *engine, const char *uri) 0165 { 0166 Q_UNUSED(uri); 0167 connect(this, &KirigamiPlugin::languageChangeEvent, engine, &QQmlEngine::retranslate); 0168 } 0169 0170 #ifdef KIRIGAMI_BUILD_TYPE_STATIC 0171 KirigamiPlugin &KirigamiPlugin::getInstance() 0172 { 0173 static KirigamiPlugin instance; 0174 return instance; 0175 } 0176 0177 void KirigamiPlugin::registerTypes(QQmlEngine *engine) 0178 { 0179 if (engine) { 0180 engine->addImportPath(QLatin1String(":/")); 0181 } else { 0182 qCWarning(KirigamiLog) 0183 << "Registering Kirigami on a null QQmlEngine instance - you likely want to pass a valid engine, or you will want to manually add the " 0184 "qrc root path :/ to your import paths list so the engine is able to load the plugin"; 0185 } 0186 } 0187 #endif 0188 0189 #include "kirigamiplugin.moc" 0190 #include "moc_kirigamiplugin.cpp"