-
Notifications
You must be signed in to change notification settings - Fork 77
feat: add applet visibility control to DAppletItemModel and #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wjyrich
wants to merge
1
commit into
linuxdeepin:master
Choose a base branch
from
wjyrich:task-393299-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "appletconfigmanager.h" | ||
|
|
||
| #include "pluginloader.h" | ||
|
|
||
| #include <DConfig> | ||
| #include <QLoggingCategory> | ||
| #include <QSet> | ||
|
|
||
| DS_BEGIN_NAMESPACE | ||
|
|
||
| DCORE_USE_NAMESPACE | ||
|
|
||
| Q_DECLARE_LOGGING_CATEGORY(dsLoaderLog) | ||
|
|
||
| static constexpr auto AppId{"org.deepin.dde.shell"}; | ||
| static constexpr auto ConfigName{"org.deepin.dde.shell"}; | ||
| static constexpr auto EnableKey{"enable"}; | ||
|
|
||
| AppletConfigManager::AppletConfigManager(QObject *parent) | ||
| : QObject(parent) | ||
| { | ||
| } | ||
|
|
||
| QStringList AppletConfigManager::disabledPlugins() const | ||
| { | ||
| return m_disabledPlugins; | ||
| } | ||
|
|
||
| bool AppletConfigManager::isAppletEnabled(const QString &pluginId) const | ||
| { | ||
| return !m_disabledPlugins.contains(pluginId); | ||
| } | ||
|
|
||
| void AppletConfigManager::setAppletEnabled(const QString &pluginId, bool enabled) | ||
| { | ||
| const bool currentlyEnabled = isAppletEnabled(pluginId); | ||
| if (currentlyEnabled == enabled) | ||
| return; | ||
|
|
||
| if (enabled) | ||
| m_disabledPlugins.removeAll(pluginId); | ||
| else | ||
| m_disabledPlugins.append(pluginId); | ||
| Q_EMIT appletEnabledChanged(pluginId, enabled); | ||
| } | ||
|
|
||
| void AppletConfigManager::ensureAppletConfigs() | ||
| { | ||
| auto loader = DPluginLoader::instance(); | ||
| const auto plugins = loader->plugins(); | ||
| QSet<QString> pluginIds; | ||
| for (const auto &plugin : plugins) { | ||
| // Top-level panels/applets are created by AppletManager and are not | ||
| // controlled by DConfig. Only child applets can be toggled at runtime. | ||
| if (plugin.value(QLatin1String("Parent")).toString().isEmpty()) | ||
| continue; | ||
| pluginIds.insert(plugin.pluginId()); | ||
| } | ||
|
|
||
| for (const auto &pluginId : pluginIds) { | ||
| if (m_appletConfigs.contains(pluginId)) | ||
| continue; | ||
| if (!isAppletEnabled(pluginId)) | ||
| continue; | ||
|
|
||
| auto config = DConfig::create(QLatin1String(AppId), | ||
| QLatin1String(ConfigName), | ||
| QLatin1Char('/') + pluginId, | ||
| this); | ||
| m_appletConfigs.insert(pluginId, config); | ||
| if (!config || !config->isValid()) { | ||
| qCWarning(dsLoaderLog) << "Unable to create applet DConfig; applet remains enabled:" << pluginId; | ||
| setAppletEnabled(pluginId, true); | ||
| continue; | ||
| } | ||
|
|
||
| setAppletEnabled(pluginId, config->value(QLatin1String(EnableKey), true).toBool()); | ||
| QObject::connect(config, &DConfig::valueChanged, this, [this, pluginId, config](const QString &key) { | ||
| if (key == QLatin1String(EnableKey)) | ||
| setAppletEnabled(pluginId, config->value(QLatin1String(EnableKey), true).toBool()); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| DS_END_NAMESPACE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "dsglobal.h" | ||
|
|
||
| #include <QObject> | ||
| #include <QMap> | ||
| #include <QStringList> | ||
|
|
||
| namespace Dtk::Core { | ||
| class DConfig; | ||
| } | ||
|
|
||
| DS_BEGIN_NAMESPACE | ||
|
|
||
| class AppletConfigManager : public QObject | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| explicit AppletConfigManager(QObject *parent = nullptr); | ||
|
|
||
| QStringList disabledPlugins() const; | ||
| bool isAppletEnabled(const QString &pluginId) const; | ||
| void ensureAppletConfigs(); | ||
|
|
||
| Q_SIGNALS: | ||
| void appletEnabledChanged(const QString &pluginId, bool enabled); | ||
|
|
||
| private: | ||
| void setAppletEnabled(const QString &pluginId, bool enabled); | ||
|
|
||
| QMap<QString, Dtk::Core::DConfig *> m_appletConfigs; | ||
| QStringList m_disabledPlugins; | ||
| }; | ||
|
|
||
| DS_END_NAMESPACE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前不是有这个流程么,再写一个,之前的不能复用么,