Warning, file /plasma/plasma-workspace/shell/containmentconfigview.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "containmentconfigview.h" 0008 #include "config-workspace.h" 0009 #include "currentcontainmentactionsmodel.h" 0010 #include "shellcorona.h" 0011 0012 #include <QDBusConnection> 0013 #include <QDBusMetaType> 0014 #include <QDebug> 0015 #include <QDir> 0016 #include <QQmlComponent> 0017 #include <QQmlContext> 0018 #include <QQmlEngine> 0019 #include <QStandardPaths> 0020 0021 #include <KConfigLoader> 0022 #include <KConfigPropertyMap> 0023 #include <KLocalizedString> 0024 #include <KPackage/Package> 0025 #include <KPackage/PackageLoader> 0026 #include <Plasma/ContainmentActions> 0027 #include <Plasma/Corona> 0028 #include <Plasma/PluginLoader> 0029 0030 using namespace Qt::StringLiterals; 0031 0032 class WallpaperConfigModel : public PlasmaQuick::ConfigModel 0033 { 0034 Q_OBJECT 0035 public: 0036 WallpaperConfigModel(QObject *parent); 0037 public Q_SLOTS: 0038 void repopulate(); 0039 }; 0040 0041 //////////////////////////////ContainmentConfigView 0042 ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow *parent) 0043 : ConfigView(cont, parent) 0044 , m_containment(cont) 0045 { 0046 qmlRegisterAnonymousType<QAbstractItemModel>("QAbstractItemModel", 1); 0047 setCurrentWallpaper(cont->containment()->wallpaperPlugin()); 0048 0049 KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Wallpaper")); 0050 pkg.setPath(m_containment->wallpaperPlugin()); 0051 KConfigGroup cfg = m_containment->config(); 0052 cfg = KConfigGroup(&cfg, u"Wallpaper"_s); 0053 0054 syncWallpaperObjects(); 0055 } 0056 0057 ContainmentConfigView::~ContainmentConfigView() 0058 { 0059 } 0060 0061 void ContainmentConfigView::init() 0062 { 0063 setSource(m_containment->corona()->kPackage().fileUrl("containmentconfigurationui")); 0064 } 0065 0066 PlasmaQuick::ConfigModel *ContainmentConfigView::containmentActionConfigModel() 0067 { 0068 if (!m_containmentActionConfigModel) { 0069 m_containmentActionConfigModel = new PlasmaQuick::ConfigModel(this); 0070 0071 const QList<KPluginMetaData> actions = Plasma::PluginLoader::self()->listContainmentActionsMetaData(QString()); 0072 0073 KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Generic")); 0074 0075 for (const KPluginMetaData &plugin : actions) { 0076 pkg.setDefaultPackageRoot(QStandardPaths::locate(QStandardPaths::GenericDataLocation, 0077 QStringLiteral(PLASMA_RELATIVE_DATA_INSTALL_DIR "/containmentactions"), 0078 QStandardPaths::LocateDirectory)); 0079 m_containmentActionConfigModel->appendCategory(plugin.iconName(), 0080 plugin.name(), 0081 pkg.filePath("ui", QStringLiteral("config.qml")), 0082 plugin.pluginId()); 0083 } 0084 } 0085 return m_containmentActionConfigModel; 0086 } 0087 0088 QAbstractItemModel *ContainmentConfigView::currentContainmentActionsModel() 0089 { 0090 if (!m_currentContainmentActionsModel) { 0091 m_currentContainmentActionsModel = new CurrentContainmentActionsModel(m_containment, this); 0092 } 0093 return m_currentContainmentActionsModel; 0094 } 0095 0096 QString ContainmentConfigView::containmentPlugin() const 0097 { 0098 return m_containment->pluginMetaData().pluginId(); 0099 } 0100 0101 void ContainmentConfigView::setContainmentPlugin(const QString &plugin) 0102 { 0103 if (plugin.isEmpty() || containmentPlugin() == plugin) { 0104 return; 0105 } 0106 0107 m_containment = static_cast<ShellCorona *>(m_containment->corona())->setContainmentTypeForScreen(m_containment->screen(), plugin); 0108 Q_EMIT containmentPluginChanged(); 0109 } 0110 0111 PlasmaQuick::ConfigModel *ContainmentConfigView::wallpaperConfigModel() 0112 { 0113 if (!m_wallpaperConfigModel) { 0114 m_wallpaperConfigModel = new WallpaperConfigModel(this); 0115 QDBusConnection::sessionBus().connect(QString(), 0116 QStringLiteral("/KPackage/Plasma/Wallpaper"), 0117 QStringLiteral("org.kde.plasma.kpackage"), 0118 QStringLiteral("packageInstalled"), 0119 m_wallpaperConfigModel, 0120 SLOT(repopulate())); 0121 QDBusConnection::sessionBus().connect(QString(), 0122 QStringLiteral("/KPackage/Plasma/Wallpaper"), 0123 QStringLiteral("org.kde.plasma.kpackage"), 0124 QStringLiteral("packageUpdated"), 0125 m_wallpaperConfigModel, 0126 SLOT(repopulate())); 0127 QDBusConnection::sessionBus().connect(QString(), 0128 QStringLiteral("/KPackage/Plasma/Wallpaper"), 0129 QStringLiteral("org.kde.plasma.kpackage"), 0130 QStringLiteral("packageUninstalled"), 0131 m_wallpaperConfigModel, 0132 SLOT(repopulate())); 0133 0134 QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.plasmashell"), 0135 QStringLiteral("/PlasmaShell"), 0136 QStringLiteral("org.kde.PlasmaShell"), 0137 QStringLiteral("wallpaperChanged"), 0138 this, 0139 SLOT(onWallpaperChanged(uint))); 0140 } 0141 return m_wallpaperConfigModel; 0142 } 0143 0144 PlasmaQuick::ConfigModel *ContainmentConfigView::containmentPluginsConfigModel() 0145 { 0146 if (!m_containmentPluginsConfigModel) { 0147 m_containmentPluginsConfigModel = new PlasmaQuick::ConfigModel(this); 0148 0149 const QList<KPluginMetaData> actions = Plasma::PluginLoader::self()->listContainmentsMetaDataOfType(QStringLiteral("Desktop")); 0150 for (const KPluginMetaData &plugin : actions) { 0151 m_containmentPluginsConfigModel->appendCategory(plugin.iconName(), plugin.name(), QString(), plugin.pluginId()); 0152 } 0153 } 0154 return m_containmentPluginsConfigModel; 0155 } 0156 0157 QQmlPropertyMap *ContainmentConfigView::wallpaperConfiguration() const 0158 { 0159 return m_currentWallpaperConfig; 0160 } 0161 0162 QString ContainmentConfigView::currentWallpaper() const 0163 { 0164 return m_currentWallpaperPlugin; 0165 } 0166 0167 void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaperPlugin) 0168 { 0169 if (m_currentWallpaperPlugin == wallpaperPlugin) { 0170 return; 0171 } 0172 0173 delete m_ownWallpaperConfig; 0174 m_ownWallpaperConfig = nullptr; 0175 0176 if (m_containment->wallpaperPlugin() == wallpaperPlugin) { 0177 syncWallpaperObjects(); 0178 } else { 0179 // we have to construct an independent ConfigPropertyMap when we want to configure wallpapers that are not the current one 0180 KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Generic")); 0181 pkg.setDefaultPackageRoot(QStringLiteral(PLASMA_RELATIVE_DATA_INSTALL_DIR "/wallpapers")); 0182 pkg.setPath(wallpaperPlugin); 0183 QFile file(pkg.filePath("config", QStringLiteral("main.xml"))); 0184 KConfigGroup cfg = m_containment->config().group(u"Wallpaper"_s).group(wallpaperPlugin); 0185 m_currentWallpaperConfig = m_ownWallpaperConfig = new KConfigPropertyMap(new KConfigLoader(cfg, &file, this), this); 0186 } 0187 0188 m_currentWallpaperPlugin = wallpaperPlugin; 0189 Q_EMIT currentWallpaperChanged(); 0190 Q_EMIT wallpaperConfigurationChanged(); 0191 } 0192 0193 void ContainmentConfigView::applyWallpaper() 0194 { 0195 QVariantMap params; 0196 for (const auto &key : m_currentWallpaperConfig->keys()) { 0197 if (key.endsWith(QLatin1String("Default"))) { 0198 continue; 0199 } 0200 if (!m_currentWallpaperConfig->value(key).isNull()) { 0201 params.insert(key, m_currentWallpaperConfig->value(key)); 0202 } 0203 } 0204 0205 if (m_currentWallpaperPlugin == QLatin1String("org.kde.image")) { 0206 params.insert("Image", m_currentWallpaperConfig->value("Image")); 0207 params.remove("PreviewImage"); 0208 } 0209 0210 auto shell = static_cast<ShellCorona *>(m_containment->corona()); 0211 shell->setWallpaper(m_currentWallpaperPlugin, params, m_containment->screen()); 0212 } 0213 0214 void ContainmentConfigView::onWallpaperChanged(uint /*screenIdx*/) 0215 { 0216 Q_EMIT wallpaperConfigurationChanged(); 0217 } 0218 0219 void ContainmentConfigView::syncWallpaperObjects() 0220 { 0221 QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value<QObject *>(); 0222 0223 if (!wallpaperGraphicsObject) { 0224 return; 0225 } 0226 rootContext()->setContextProperty(QStringLiteral("wallpaper"), wallpaperGraphicsObject); 0227 0228 // FIXME: why m_wallpaperGraphicsObject->property("configuration").value<ConfigPropertyMap *>() doesn't work? 0229 m_currentWallpaperConfig = static_cast<QQmlPropertyMap *>(wallpaperGraphicsObject->property("configuration").value<QObject *>()); 0230 } 0231 0232 WallpaperConfigModel::WallpaperConfigModel(QObject *parent) 0233 : PlasmaQuick::ConfigModel(parent) 0234 { 0235 repopulate(); 0236 } 0237 0238 void WallpaperConfigModel::repopulate() 0239 { 0240 clear(); 0241 for (const KPluginMetaData &m : KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/Wallpaper"))) { 0242 KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Wallpaper"), m.pluginId()); 0243 if (!pkg.isValid()) { 0244 continue; 0245 } 0246 appendCategory(pkg.metadata().iconName(), pkg.metadata().name(), pkg.fileUrl("ui", QStringLiteral("config.qml")).toString(), m.pluginId()); 0247 } 0248 } 0249 0250 #include "containmentconfigview.moc"