File indexing completed on 2024-04-21 04:40:40

0001 /*
0002  *  SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "treeviewplugin.h"
0008 
0009 #include <QFile>
0010 #include <QQuickStyle>
0011 
0012 #include <QQmlEngine>
0013 
0014 static QString s_selectedStyle;
0015 
0016 TreeViewPlugin::TreeViewPlugin(QObject *parent)
0017     : QQmlExtensionPlugin(parent)
0018 {
0019     m_stylesFallbackChain << QString();
0020 }
0021 
0022 QUrl TreeViewPlugin::componentUrl(const QString &fileName) const
0023 {
0024     for (const QString &style : std::as_const(m_stylesFallbackChain)) {
0025         const QString candidate = QStringLiteral("styles/") + style + QLatin1Char('/') + fileName;
0026         if (QFile::exists(resolveFilePath(candidate))) {
0027             return QUrl(resolveFileUrl(candidate));
0028         }
0029     }
0030 
0031     return QUrl(resolveFileUrl(fileName));
0032 }
0033 
0034 void TreeViewPlugin::registerTypes(const char *uri)
0035 {
0036     Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.kirigamiaddons.treeview"));
0037     const QString style = QQuickStyle::name();
0038 
0039 
0040 #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
0041     //org.kde.desktop.plasma is a couple of files that fall back to desktop by purpose
0042     if (style.isEmpty() && QFile::exists(resolveFilePath(QStringLiteral("/styles/org.kde.desktop")))) {
0043         m_stylesFallbackChain.prepend(QStringLiteral("org.kde.desktop"));
0044     }
0045 #endif
0046 
0047     if (!style.isEmpty() && QFile::exists(resolveFilePath(QStringLiteral("/styles/") + style)) && !m_stylesFallbackChain.contains(style)) {
0048         m_stylesFallbackChain.prepend(style);
0049     }
0050 
0051     //At this point the fallback chain will be selected->org.kde.desktop->Fallback
0052     s_selectedStyle = m_stylesFallbackChain.first();
0053 
0054     qmlRegisterType(componentUrl(QStringLiteral("TreeViewDecoration.qml")), uri, 1, 0, "TreeViewDecoration");
0055     
0056 
0057     qmlProtectModule(uri, 2);
0058 }
0059 
0060 #include "treeviewplugin.moc"
0061 
0062 #include "moc_treeviewplugin.cpp"