refactor: plugins default sort order

Change-Id: I5ab49d88c970bd66c63a6fe6d82cab08d2f4606a
This commit is contained in:
listenerri 2018-11-21 18:22:22 +08:00
parent 59f688410a
commit 8105f8b9f3
Notes: gerrit 2018-11-21 18:26:37 +08:00
Verified+1: <jenkins@deepin.com>
Code-Review+2: listenerri <listenerri@gmail.com>
Submitted-by: listenerri <listenerri@gmail.com>
Submitted-at: Wed, 21 Nov 2018 18:26:36 +0800
Reviewed-on: https://cr.deepin.io/39914
Project: dde/dde-dock
Branch: refs/heads/master
8 changed files with 39 additions and 56 deletions

View File

@ -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

View File

@ -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<NetworkDevice *> devices)

View File

@ -25,7 +25,6 @@
#include "pluginsiteminterface.h"
#include "item/deviceitem.h"
#include <QSettings>
#include <NetworkWorker>
#include <NetworkModel>
@ -70,7 +69,6 @@ private:
QMap<QString, DeviceItem *> m_itemsMap;
QTimer *m_delayRefreshTimer;
QSettings m_settings;
bool m_pluginLoaded;
};

View File

@ -23,7 +23,6 @@
#include "dbus/dbusaccount.h"
#include <QIcon>
#include <QSettings>
#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()

View File

@ -65,7 +65,6 @@ private:
private:
bool m_pluginLoaded;
QSettings m_settings;
PowerStatusWidget *m_powerStatusWidget;
TipsWidget *m_tipsLabel;

View File

@ -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);
}

View File

@ -25,8 +25,6 @@
#include "pluginsiteminterface.h"
#include "sounditem.h"
#include <QSettings>
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;
};

View File

@ -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)