From 8ae30ec2d1b1777cbb87562892de0e65a2c7d3c9 Mon Sep 17 00:00:00 2001 From: listenerri Date: Wed, 30 Jan 2019 18:00:46 +0800 Subject: [PATCH] feat: update all plugins to support take effect in time for Deepin-Sync Change-Id: I6fec9ab494eede8a4b0f35e62ccd6f4c749ded09 --- plugins/datetime/datetimeplugin.cpp | 20 ++++++++--- plugins/datetime/datetimeplugin.h | 3 ++ plugins/network/networkplugin.cpp | 36 +++++++++++++------- plugins/network/networkplugin.h | 3 ++ plugins/onboard/onboardplugin.cpp | 30 ++++++++++------ plugins/onboard/onboardplugin.h | 3 ++ plugins/power/powerplugin.cpp | 28 ++++++++++----- plugins/power/powerplugin.h | 2 ++ plugins/shutdown/shutdownplugin.cpp | 30 ++++++++++------ plugins/shutdown/shutdownplugin.h | 3 ++ plugins/sound/soundplugin.cpp | 18 +++++++--- plugins/sound/soundplugin.h | 4 +++ plugins/tray/fashiontray/fashiontrayitem.cpp | 5 +++ plugins/tray/fashiontray/fashiontrayitem.h | 1 + plugins/tray/trayplugin.cpp | 25 ++++++++++++-- plugins/tray/trayplugin.h | 2 ++ 16 files changed, 160 insertions(+), 53 deletions(-) diff --git a/plugins/datetime/datetimeplugin.cpp b/plugins/datetime/datetimeplugin.cpp index 03f1ed400..7fe4a2d1c 100644 --- a/plugins/datetime/datetimeplugin.cpp +++ b/plugins/datetime/datetimeplugin.cpp @@ -79,10 +79,7 @@ void DatetimePlugin::pluginStateSwitched() { m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable()); - if (!pluginIsDisable()) - m_proxyInter->itemAdded(this, pluginName()); - else - m_proxyInter->itemRemoved(this, pluginName()); + refreshPluginItemsVisible(); } bool DatetimePlugin::pluginIsDisable() @@ -183,6 +180,13 @@ void DatetimePlugin::invokedMenuItem(const QString &itemKey, const QString &menu } } +void DatetimePlugin::pluginSettingsChanged() +{ + m_centralWidget->set24HourFormat(m_proxyInter->getValue(this, TIME_FORMAT_KEY, true).toBool()); + + refreshPluginItemsVisible(); +} + void DatetimePlugin::updateCurrentTimeString() { const QDateTime currentDateTime = QDateTime::currentDateTime(); @@ -200,3 +204,11 @@ void DatetimePlugin::updateCurrentTimeString() m_currentTimeString = currentString; m_centralWidget->update(); } + +void DatetimePlugin::refreshPluginItemsVisible() +{ + if (!pluginIsDisable()) + m_proxyInter->itemAdded(this, pluginName()); + else + m_proxyInter->itemRemoved(this, pluginName()); +} diff --git a/plugins/datetime/datetimeplugin.h b/plugins/datetime/datetimeplugin.h index 53b598538..cbb7c5671 100644 --- a/plugins/datetime/datetimeplugin.h +++ b/plugins/datetime/datetimeplugin.h @@ -58,8 +58,11 @@ public: void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) override; + void pluginSettingsChanged() override; + private slots: void updateCurrentTimeString(); + void refreshPluginItemsVisible(); private: QPointer m_centralWidget; diff --git a/plugins/network/networkplugin.cpp b/plugins/network/networkplugin.cpp index cd0b27092..311ccde9c 100644 --- a/plugins/network/networkplugin.cpp +++ b/plugins/network/networkplugin.cpp @@ -88,19 +88,7 @@ void NetworkPlugin::pluginStateSwitched() { 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(); - return; - } - - onDeviceListChanged(m_networkModel->devices()); + refreshPluginItemsVisible(); } bool NetworkPlugin::pluginIsDisable() @@ -171,6 +159,11 @@ void NetworkPlugin::setSortKey(const QString &itemKey, const int order) m_proxyInter->saveValue(this, key, order); } +void NetworkPlugin::pluginSettingsChanged() +{ + refreshPluginItemsVisible(); +} + bool NetworkPlugin::isConnectivity() { return NetworkModel::connectivity() == Connectivity::Full; @@ -329,3 +322,20 @@ void NetworkPlugin::onItemRequestSetAppletVisible(const bool visible) m_proxyInter->requestSetAppletVisible(this, item->path(), visible); } + +void NetworkPlugin::refreshPluginItemsVisible() +{ + if (pluginIsDisable()) { + for (auto itemKey : m_itemsMap.keys()) { + m_proxyInter->itemRemoved(this, itemKey); + } + return; + } + + if (!m_pluginLoaded) { + loadPlugin(); + return; + } + + onDeviceListChanged(m_networkModel->devices()); +} diff --git a/plugins/network/networkplugin.h b/plugins/network/networkplugin.h index 4eeca4a91..150df0215 100644 --- a/plugins/network/networkplugin.h +++ b/plugins/network/networkplugin.h @@ -54,12 +54,15 @@ public: int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE; void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE; + void pluginSettingsChanged() override; + static bool isConnectivity(); private slots: void onDeviceListChanged(const QList devices); void refreshWiredItemVisible(); void onItemRequestSetAppletVisible(const bool visible); + void refreshPluginItemsVisible(); private: DeviceItem *itemByPath(const QString &path); diff --git a/plugins/onboard/onboardplugin.cpp b/plugins/onboard/onboardplugin.cpp index d0affefdf..5f733a77b 100644 --- a/plugins/onboard/onboardplugin.cpp +++ b/plugins/onboard/onboardplugin.cpp @@ -73,16 +73,7 @@ void OnboardPlugin::pluginStateSwitched() { m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable()); - if (pluginIsDisable()) - { - m_proxyInter->itemRemoved(this, pluginName()); - } else { - if (!m_pluginLoaded) { - loadPlugin(); - return; - } - m_proxyInter->itemAdded(this, pluginName()); - } + refreshPluginItemsVisible(); } bool OnboardPlugin::pluginIsDisable() @@ -151,6 +142,11 @@ void OnboardPlugin::setSortKey(const QString &itemKey, const int order) m_proxyInter->saveValue(this, key, order); } +void OnboardPlugin::pluginSettingsChanged() +{ + refreshPluginItemsVisible(); +} + void OnboardPlugin::loadPlugin() { if (m_pluginLoaded) { @@ -165,3 +161,17 @@ void OnboardPlugin::loadPlugin() m_proxyInter->itemAdded(this, pluginName()); displayModeChanged(displayMode()); } + +void OnboardPlugin::refreshPluginItemsVisible() +{ + if (pluginIsDisable()) + { + m_proxyInter->itemRemoved(this, pluginName()); + } else { + if (!m_pluginLoaded) { + loadPlugin(); + return; + } + m_proxyInter->itemAdded(this, pluginName()); + } +} diff --git a/plugins/onboard/onboardplugin.h b/plugins/onboard/onboardplugin.h index 77bea06a9..c0521ee0f 100644 --- a/plugins/onboard/onboardplugin.h +++ b/plugins/onboard/onboardplugin.h @@ -55,8 +55,11 @@ public: int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE; void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE; + void pluginSettingsChanged() override; + private: void loadPlugin(); + void refreshPluginItemsVisible(); private: bool m_pluginLoaded; diff --git a/plugins/power/powerplugin.cpp b/plugins/power/powerplugin.cpp index 22f2aab66..76e012c9c 100644 --- a/plugins/power/powerplugin.cpp +++ b/plugins/power/powerplugin.cpp @@ -94,15 +94,7 @@ void PowerPlugin::pluginStateSwitched() { m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable()); - if (pluginIsDisable()) { - m_proxyInter->itemRemoved(this, POWER_KEY); - } else { - if (!m_pluginLoaded) { - loadPlugin(); - return; - } - updateBatteryVisible(); - } + refreshPluginItemsVisible(); } bool PowerPlugin::pluginIsDisable() @@ -171,6 +163,11 @@ void PowerPlugin::setSortKey(const QString &itemKey, const int order) m_proxyInter->saveValue(this, key, order); } +void PowerPlugin::pluginSettingsChanged() +{ + refreshPluginItemsVisible(); +} + void PowerPlugin::updateBatteryVisible() { const bool exist = !m_powerInter->batteryPercentage().isEmpty(); @@ -197,3 +194,16 @@ void PowerPlugin::loadPlugin() updateBatteryVisible(); } + +void PowerPlugin::refreshPluginItemsVisible() +{ + if (pluginIsDisable()) { + m_proxyInter->itemRemoved(this, POWER_KEY); + } else { + if (!m_pluginLoaded) { + loadPlugin(); + return; + } + updateBatteryVisible(); + } +} diff --git a/plugins/power/powerplugin.h b/plugins/power/powerplugin.h index 888522689..a0320a1d9 100644 --- a/plugins/power/powerplugin.h +++ b/plugins/power/powerplugin.h @@ -55,10 +55,12 @@ public: void refreshIcon(const QString &itemKey) Q_DECL_OVERRIDE; int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE; void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE; + void pluginSettingsChanged() override; private: void updateBatteryVisible(); void loadPlugin(); + void refreshPluginItemsVisible(); private: bool m_pluginLoaded; diff --git a/plugins/shutdown/shutdownplugin.cpp b/plugins/shutdown/shutdownplugin.cpp index 85bda7295..aeba24d5f 100644 --- a/plugins/shutdown/shutdownplugin.cpp +++ b/plugins/shutdown/shutdownplugin.cpp @@ -83,16 +83,7 @@ void ShutdownPlugin::pluginStateSwitched() { m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool()); - if (pluginIsDisable()) - { - m_proxyInter->itemRemoved(this, pluginName()); - } else { - if (!m_pluginLoaded) { - loadPlugin(); - return; - } - m_proxyInter->itemAdded(this, pluginName()); - } + refreshPluginItemsVisible(); } bool ShutdownPlugin::pluginIsDisable() @@ -219,6 +210,11 @@ void ShutdownPlugin::setSortKey(const QString &itemKey, const int order) m_proxyInter->saveValue(this, key, order); } +void ShutdownPlugin::pluginSettingsChanged() +{ + refreshPluginItemsVisible(); +} + void ShutdownPlugin::loadPlugin() { if (m_pluginLoaded) { @@ -247,3 +243,17 @@ bool ShutdownPlugin::checkSwap() return false; } + +void ShutdownPlugin::refreshPluginItemsVisible() +{ + if (pluginIsDisable()) + { + m_proxyInter->itemRemoved(this, pluginName()); + } else { + if (!m_pluginLoaded) { + loadPlugin(); + return; + } + m_proxyInter->itemAdded(this, pluginName()); + } +} diff --git a/plugins/shutdown/shutdownplugin.h b/plugins/shutdown/shutdownplugin.h index 7b9333066..67fbf7b88 100644 --- a/plugins/shutdown/shutdownplugin.h +++ b/plugins/shutdown/shutdownplugin.h @@ -55,9 +55,12 @@ public: int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE; void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE; + void pluginSettingsChanged() override; + private: void loadPlugin(); bool checkSwap(); + void refreshPluginItemsVisible(); private: bool m_pluginLoaded; diff --git a/plugins/sound/soundplugin.cpp b/plugins/sound/soundplugin.cpp index e74b3c426..3df93a7b5 100644 --- a/plugins/sound/soundplugin.cpp +++ b/plugins/sound/soundplugin.cpp @@ -54,10 +54,7 @@ void SoundPlugin::pluginStateSwitched() { m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable()); - if (pluginIsDisable()) - m_proxyInter->itemRemoved(this, SOUND_KEY); - else - m_proxyInter->itemAdded(this, SOUND_KEY); + refreshPluginItemsVisible(); } bool SoundPlugin::pluginIsDisable() @@ -128,3 +125,16 @@ void SoundPlugin::refreshIcon(const QString &itemKey) m_soundItem->refreshIcon(); } } + +void SoundPlugin::pluginSettingsChanged() +{ + refreshPluginItemsVisible(); +} + +void SoundPlugin::refreshPluginItemsVisible() +{ + if (pluginIsDisable()) + m_proxyInter->itemRemoved(this, SOUND_KEY); + else + m_proxyInter->itemAdded(this, SOUND_KEY); +} diff --git a/plugins/sound/soundplugin.h b/plugins/sound/soundplugin.h index fcda5aafa..1631b4fad 100644 --- a/plugins/sound/soundplugin.h +++ b/plugins/sound/soundplugin.h @@ -48,6 +48,10 @@ public: int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE; void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE; void refreshIcon(const QString &itemKey) Q_DECL_OVERRIDE; + void pluginSettingsChanged() override; + +private: + void refreshPluginItemsVisible(); private: SoundItem *m_soundItem; diff --git a/plugins/tray/fashiontray/fashiontrayitem.cpp b/plugins/tray/fashiontray/fashiontrayitem.cpp index 0b3c56f51..b8f4cc350 100644 --- a/plugins/tray/fashiontray/fashiontrayitem.cpp +++ b/plugins/tray/fashiontray/fashiontrayitem.cpp @@ -240,6 +240,11 @@ void FashionTrayItem::setRightSplitVisible(const bool visible) } } +void FashionTrayItem::onPluginSettingsChanged() +{ + m_controlWidget->setExpanded(m_trayPlugin->getValue(FASHION_MODE_ITEM_KEY, ExpandedKey, true).toBool()); +} + void FashionTrayItem::showEvent(QShowEvent *event) { requestResize(); diff --git a/plugins/tray/fashiontray/fashiontrayitem.h b/plugins/tray/fashiontray/fashiontrayitem.h index 262cc33a7..bccb2faa3 100644 --- a/plugins/tray/fashiontray/fashiontrayitem.h +++ b/plugins/tray/fashiontray/fashiontrayitem.h @@ -60,6 +60,7 @@ public slots: void onExpandChanged(const bool expand); void setSuggestIconSize(QSize size); void setRightSplitVisible(const bool visible); + void onPluginSettingsChanged(); protected: void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; diff --git a/plugins/tray/trayplugin.cpp b/plugins/tray/trayplugin.cpp index 670a82c95..7ddf3b589 100644 --- a/plugins/tray/trayplugin.cpp +++ b/plugins/tray/trayplugin.cpp @@ -32,6 +32,7 @@ #include "../widgets/tipswidget.h" #include "xcb/xcb_icccm.h" +#define PLUGIN_ENABLED_KEY "enable" #define FASHION_MODE_TRAYS_SORTED "fashion-mode-trays-sorted" #define SNI_WATCHER_SERVICE "org.kde.StatusNotifierWatcher" @@ -77,7 +78,7 @@ void TrayPlugin::init(PluginProxyInterface *proxyInter) m_proxyInter = proxyInter; - if (!proxyInter->getValue(this, "enable", true).toBool()) { + if (pluginIsDisable()) { qDebug() << "hide tray from config disable!!"; return; } @@ -96,9 +97,14 @@ void TrayPlugin::init(PluginProxyInterface *proxyInter) QTimer::singleShot(4000, this, &TrayPlugin::initXEmbed); } +bool TrayPlugin::pluginIsDisable() +{ + return !m_proxyInter->getValue(this, PLUGIN_ENABLED_KEY, true).toBool(); +} + void TrayPlugin::displayModeChanged(const Dock::DisplayMode mode) { - if (!m_proxyInter->getValue(this, "enable", true).toBool()) { + if (pluginIsDisable()) { return; } @@ -107,7 +113,7 @@ void TrayPlugin::displayModeChanged(const Dock::DisplayMode mode) void TrayPlugin::positionChanged(const Dock::Position position) { - if (!m_proxyInter->getValue(this, "enable", true).toBool()) { + if (pluginIsDisable()) { return; } @@ -208,6 +214,19 @@ void TrayPlugin::refreshIcon(const QString &itemKey) } } +void TrayPlugin::pluginSettingsChanged() +{ + if (pluginIsDisable()) { + return; + } + + if (displayMode() == Dock::DisplayMode::Fashion) { + m_fashionItem->onPluginSettingsChanged(); + m_fashionItem->clearTrayWidgets(); + m_fashionItem->setTrayWidgets(m_trayMap); + } +} + Dock::Position TrayPlugin::dockPosition() const { return position(); diff --git a/plugins/tray/trayplugin.h b/plugins/tray/trayplugin.h index eb6f0db2d..19f5ddf3f 100644 --- a/plugins/tray/trayplugin.h +++ b/plugins/tray/trayplugin.h @@ -48,6 +48,7 @@ public: const QString pluginName() const Q_DECL_OVERRIDE; void init(PluginProxyInterface *proxyInter) Q_DECL_OVERRIDE; + bool pluginIsDisable() override; void displayModeChanged(const Dock::DisplayMode mode) Q_DECL_OVERRIDE; void positionChanged(const Dock::Position position) Q_DECL_OVERRIDE; QWidget *itemWidget(const QString &itemKey) Q_DECL_OVERRIDE; @@ -59,6 +60,7 @@ public: void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE; void setItemIsInContainer(const QString &itemKey, const bool container) Q_DECL_OVERRIDE; void refreshIcon(const QString &itemKey) Q_DECL_OVERRIDE; + void pluginSettingsChanged() override; Dock::Position dockPosition() const; bool traysSortedInFashionMode();