diff --git a/interfaces/pluginproxyinterface.h b/interfaces/pluginproxyinterface.h index a7235857e..d58d13792 100644 --- a/interfaces/pluginproxyinterface.h +++ b/interfaces/pluginproxyinterface.h @@ -66,14 +66,20 @@ public: /// /// \brief saveValue /// save module config to .config/deepin/dde-dock.conf + /// all key-values of all plugins will be save to that file + /// and grouped by the returned value of pluginName() function which is defined in PluginsItemInterface + /// \param itemInter the plugin object + /// \param key the key of data + /// \param value the data /// - virtual void saveValue(PluginsItemInterface * const itemInter, const QString &itemKey, const QVariant &value) = 0; + virtual void saveValue(PluginsItemInterface * const itemInter, const QString &key, const QVariant &value) = 0; /// /// \brief getValue + /// SeeAlse: saveValue /// return value from .config/deepin/dde-dock.conf /// - virtual const QVariant getValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant& failback = QVariant()) = 0; + virtual const QVariant getValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant& fallback = QVariant()) = 0; }; #endif // PLUGINPROXYINTERFACE_H diff --git a/plugins/network/networkplugin.cpp b/plugins/network/networkplugin.cpp index c4d719634..253d1e44e 100644 --- a/plugins/network/networkplugin.cpp +++ b/plugins/network/networkplugin.cpp @@ -27,7 +27,7 @@ using namespace dde::network; #define WIRED_ITEM "wired" #define WIRELESS_ITEM "wireless" -#define STATE_KEY "disabled" +#define STATE_KEY "enabled" NetworkPlugin::NetworkPlugin(QObject *parent) : QObject(parent), @@ -35,7 +35,6 @@ NetworkPlugin::NetworkPlugin(QObject *parent) m_networkModel(nullptr), m_networkWorker(nullptr), m_delayRefreshTimer(new QTimer), - m_settings("deepin", "dde-dock-network"), m_pluginLoaded(false) { } @@ -87,7 +86,14 @@ void NetworkPlugin::refershIcon(const QString &itemKey) void NetworkPlugin::pluginStateSwitched() { - m_settings.setValue(STATE_KEY, !pluginIsDisable()); + m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable()); + + if (pluginIsDisable()) { + for (auto itemKey : m_itemsMap.keys()) { + m_proxyInter->itemRemoved(this, itemKey); + } + return; + } if (!m_pluginLoaded) { loadPlugin(); @@ -99,7 +105,7 @@ void NetworkPlugin::pluginStateSwitched() bool NetworkPlugin::pluginIsDisable() { - return m_settings.value(STATE_KEY, false).toBool(); + return !m_proxyInter->getValue(this, STATE_KEY, true).toBool(); } const QString NetworkPlugin::itemCommand(const QString &itemKey) @@ -153,20 +159,16 @@ QWidget *NetworkPlugin::itemPopupApplet(const QString &itemKey) int NetworkPlugin::itemSortKey(const QString &itemKey) { - Dock::DisplayMode mode = displayMode(); - const QString key = QString("pos_%1_%2").arg(itemKey).arg(mode); + const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode()); - if (mode == Dock::DisplayMode::Fashion) { - return m_settings.value(key, 2).toInt(); - } else { - return m_settings.value(key, 3).toInt(); - } + return m_proxyInter->getValue(this, key, displayMode() == Dock::DisplayMode::Fashion ? 2 : 2).toInt(); } void NetworkPlugin::setSortKey(const QString &itemKey, const int order) { const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode()); - m_settings.setValue(key, order); + + m_proxyInter->saveValue(this, key, order); } void NetworkPlugin::onDeviceListChanged(const QList devices) diff --git a/plugins/network/networkplugin.h b/plugins/network/networkplugin.h index 6fb785b79..f6fb19178 100644 --- a/plugins/network/networkplugin.h +++ b/plugins/network/networkplugin.h @@ -25,7 +25,6 @@ #include "pluginsiteminterface.h" #include "item/deviceitem.h" -#include #include #include @@ -70,7 +69,6 @@ private: QMap m_itemsMap; QTimer *m_delayRefreshTimer; - QSettings m_settings; bool m_pluginLoaded; }; diff --git a/plugins/power/powerplugin.cpp b/plugins/power/powerplugin.cpp index 2e757c905..98eeaf2d3 100644 --- a/plugins/power/powerplugin.cpp +++ b/plugins/power/powerplugin.cpp @@ -23,7 +23,6 @@ #include "dbus/dbusaccount.h" #include -#include #define PLUGIN_STATE_KEY "enable" @@ -31,7 +30,6 @@ PowerPlugin::PowerPlugin(QObject *parent) : QObject(parent), m_pluginLoaded(false), - m_settings("deepin", "dde-dock-power"), m_tipsLabel(new TipsWidget) { m_tipsLabel->setVisible(false); @@ -94,7 +92,7 @@ void PowerPlugin::init(PluginProxyInterface *proxyInter) void PowerPlugin::pluginStateSwitched() { - m_settings.setValue(PLUGIN_STATE_KEY, !m_settings.value(PLUGIN_STATE_KEY, true).toBool()); + m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable()); if (pluginIsDisable()) { m_proxyInter->itemRemoved(this, POWER_KEY); @@ -109,7 +107,7 @@ void PowerPlugin::pluginStateSwitched() bool PowerPlugin::pluginIsDisable() { - return !m_settings.value(PLUGIN_STATE_KEY, true).toBool(); + return !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool(); } const QString PowerPlugin::itemCommand(const QString &itemKey) @@ -154,22 +152,16 @@ void PowerPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, int PowerPlugin::itemSortKey(const QString &itemKey) { - Dock::DisplayMode mode = displayMode(); - const QString key = QString("pos_%1_%2").arg(itemKey).arg(mode); + const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode()); - //if (mode == Dock::DisplayMode::Fashion) { - //return m_settings.value(key, 4).toInt(); - //} else { - //return m_settings.value(key, 4).toInt(); - //} - - return m_settings.value(key, 4).toInt(); + return m_proxyInter->getValue(this, key, displayMode() == Dock::DisplayMode::Fashion ? 3 : 3).toInt(); } void PowerPlugin::setSortKey(const QString &itemKey, const int order) { const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode()); - m_settings.setValue(key, order); + + m_proxyInter->saveValue(this, key, order); } void PowerPlugin::updateBatteryVisible() diff --git a/plugins/power/powerplugin.h b/plugins/power/powerplugin.h index 835fc9214..a7cf54c79 100644 --- a/plugins/power/powerplugin.h +++ b/plugins/power/powerplugin.h @@ -65,7 +65,6 @@ private: private: bool m_pluginLoaded; - QSettings m_settings; PowerStatusWidget *m_powerStatusWidget; TipsWidget *m_tipsLabel; diff --git a/plugins/sound/soundplugin.cpp b/plugins/sound/soundplugin.cpp index ca22022b8..c9044a9b2 100644 --- a/plugins/sound/soundplugin.cpp +++ b/plugins/sound/soundplugin.cpp @@ -26,7 +26,6 @@ SoundPlugin::SoundPlugin(QObject *parent) : QObject(parent), - m_settings("deepin", "dde-dock-sound"), m_soundItem(nullptr) { } @@ -48,23 +47,23 @@ void SoundPlugin::init(PluginProxyInterface *proxyInter) m_soundItem = new SoundItem; connect(m_soundItem, &SoundItem::requestContextMenu, [this] { m_proxyInter->requestContextMenu(this, SOUND_KEY); }); - if (m_settings.value(STATE_KEY, true).toBool()) + if (!pluginIsDisable()) m_proxyInter->itemAdded(this, SOUND_KEY); } void SoundPlugin::pluginStateSwitched() { - m_settings.setValue(STATE_KEY, !m_settings.value(STATE_KEY, true).toBool()); + m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable()); - if (m_settings.value(STATE_KEY).toBool()) - m_proxyInter->itemAdded(this, SOUND_KEY); - else + if (pluginIsDisable()) m_proxyInter->itemRemoved(this, SOUND_KEY); + else + m_proxyInter->itemAdded(this, SOUND_KEY); } bool SoundPlugin::pluginIsDisable() { - return !m_settings.value(STATE_KEY, true).toBool(); + return !m_proxyInter->getValue(this, STATE_KEY, true).toBool(); } QWidget *SoundPlugin::itemWidget(const QString &itemKey) @@ -104,22 +103,14 @@ void SoundPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, int SoundPlugin::itemSortKey(const QString &itemKey) { - Q_UNUSED(itemKey); + const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode()); - Dock::DisplayMode mode = displayMode(); - const QString key = QString("pos_%1").arg(mode); - - if (mode == Dock::DisplayMode::Fashion) { - return m_settings.value(key, 1).toInt(); - } else { - return m_settings.value(key, 2).toInt(); - } + return m_proxyInter->getValue(this, key, displayMode() == Dock::DisplayMode::Fashion ? 1 : 1).toInt(); } void SoundPlugin::setSortKey(const QString &itemKey, const int order) { - Q_UNUSED(itemKey); + const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode()); - const QString key = QString("pos_%1").arg(displayMode()); - m_settings.setValue(key, order); + m_proxyInter->saveValue(this, key, order); } diff --git a/plugins/sound/soundplugin.h b/plugins/sound/soundplugin.h index 42ed3b555..7a9a1ca0b 100644 --- a/plugins/sound/soundplugin.h +++ b/plugins/sound/soundplugin.h @@ -25,8 +25,6 @@ #include "pluginsiteminterface.h" #include "sounditem.h" -#include - class SoundPlugin : public QObject, PluginsItemInterface { Q_OBJECT @@ -54,7 +52,6 @@ public: void setSortKey(const QString &itemKey, const int order); private: - QSettings m_settings; SoundItem *m_soundItem; }; diff --git a/plugins/tray/trayplugin.cpp b/plugins/tray/trayplugin.cpp index 4c27736df..24845e4a9 100644 --- a/plugins/tray/trayplugin.cpp +++ b/plugins/tray/trayplugin.cpp @@ -159,9 +159,7 @@ int TrayPlugin::itemSortKey(const QString &itemKey) Dock::DisplayMode mode = displayMode(); const QString key = QString("pos_%1_%2").arg(itemKey).arg(mode); - return m_proxyInter - ->getValue(this, key, mode == Dock::DisplayMode::Fashion ? 1 : 1) - .toInt(); + return m_proxyInter->getValue(this, key, mode == Dock::DisplayMode::Fashion ? 1 : 0).toInt(); } void TrayPlugin::setSortKey(const QString &itemKey, const int order)