mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
refactor: plugins default sort order
Change-Id: I5ab49d88c970bd66c63a6fe6d82cab08d2f4606a
This commit is contained in:
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
@ -66,14 +66,20 @@ public:
|
|||||||
///
|
///
|
||||||
/// \brief saveValue
|
/// \brief saveValue
|
||||||
/// save module config to .config/deepin/dde-dock.conf
|
/// 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
|
/// \brief getValue
|
||||||
|
/// SeeAlse: saveValue
|
||||||
/// return value from .config/deepin/dde-dock.conf
|
/// 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
|
#endif // PLUGINPROXYINTERFACE_H
|
||||||
|
@ -27,7 +27,7 @@ using namespace dde::network;
|
|||||||
|
|
||||||
#define WIRED_ITEM "wired"
|
#define WIRED_ITEM "wired"
|
||||||
#define WIRELESS_ITEM "wireless"
|
#define WIRELESS_ITEM "wireless"
|
||||||
#define STATE_KEY "disabled"
|
#define STATE_KEY "enabled"
|
||||||
|
|
||||||
NetworkPlugin::NetworkPlugin(QObject *parent)
|
NetworkPlugin::NetworkPlugin(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
@ -35,7 +35,6 @@ NetworkPlugin::NetworkPlugin(QObject *parent)
|
|||||||
m_networkModel(nullptr),
|
m_networkModel(nullptr),
|
||||||
m_networkWorker(nullptr),
|
m_networkWorker(nullptr),
|
||||||
m_delayRefreshTimer(new QTimer),
|
m_delayRefreshTimer(new QTimer),
|
||||||
m_settings("deepin", "dde-dock-network"),
|
|
||||||
m_pluginLoaded(false)
|
m_pluginLoaded(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -87,7 +86,14 @@ void NetworkPlugin::refershIcon(const QString &itemKey)
|
|||||||
|
|
||||||
void NetworkPlugin::pluginStateSwitched()
|
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) {
|
if (!m_pluginLoaded) {
|
||||||
loadPlugin();
|
loadPlugin();
|
||||||
@ -99,7 +105,7 @@ void NetworkPlugin::pluginStateSwitched()
|
|||||||
|
|
||||||
bool NetworkPlugin::pluginIsDisable()
|
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)
|
const QString NetworkPlugin::itemCommand(const QString &itemKey)
|
||||||
@ -153,20 +159,16 @@ QWidget *NetworkPlugin::itemPopupApplet(const QString &itemKey)
|
|||||||
|
|
||||||
int NetworkPlugin::itemSortKey(const QString &itemKey)
|
int NetworkPlugin::itemSortKey(const QString &itemKey)
|
||||||
{
|
{
|
||||||
Dock::DisplayMode mode = displayMode();
|
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(mode);
|
|
||||||
|
|
||||||
if (mode == Dock::DisplayMode::Fashion) {
|
return m_proxyInter->getValue(this, key, displayMode() == Dock::DisplayMode::Fashion ? 2 : 2).toInt();
|
||||||
return m_settings.value(key, 2).toInt();
|
|
||||||
} else {
|
|
||||||
return m_settings.value(key, 3).toInt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkPlugin::setSortKey(const QString &itemKey, const int order)
|
void NetworkPlugin::setSortKey(const QString &itemKey, const int order)
|
||||||
{
|
{
|
||||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
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)
|
void NetworkPlugin::onDeviceListChanged(const QList<NetworkDevice *> devices)
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include "pluginsiteminterface.h"
|
#include "pluginsiteminterface.h"
|
||||||
#include "item/deviceitem.h"
|
#include "item/deviceitem.h"
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
#include <NetworkWorker>
|
#include <NetworkWorker>
|
||||||
#include <NetworkModel>
|
#include <NetworkModel>
|
||||||
|
|
||||||
@ -70,7 +69,6 @@ private:
|
|||||||
|
|
||||||
QMap<QString, DeviceItem *> m_itemsMap;
|
QMap<QString, DeviceItem *> m_itemsMap;
|
||||||
QTimer *m_delayRefreshTimer;
|
QTimer *m_delayRefreshTimer;
|
||||||
QSettings m_settings;
|
|
||||||
|
|
||||||
bool m_pluginLoaded;
|
bool m_pluginLoaded;
|
||||||
};
|
};
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include "dbus/dbusaccount.h"
|
#include "dbus/dbusaccount.h"
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
#define PLUGIN_STATE_KEY "enable"
|
#define PLUGIN_STATE_KEY "enable"
|
||||||
|
|
||||||
@ -31,7 +30,6 @@ PowerPlugin::PowerPlugin(QObject *parent)
|
|||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
|
|
||||||
m_pluginLoaded(false),
|
m_pluginLoaded(false),
|
||||||
m_settings("deepin", "dde-dock-power"),
|
|
||||||
m_tipsLabel(new TipsWidget)
|
m_tipsLabel(new TipsWidget)
|
||||||
{
|
{
|
||||||
m_tipsLabel->setVisible(false);
|
m_tipsLabel->setVisible(false);
|
||||||
@ -94,7 +92,7 @@ void PowerPlugin::init(PluginProxyInterface *proxyInter)
|
|||||||
|
|
||||||
void PowerPlugin::pluginStateSwitched()
|
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()) {
|
if (pluginIsDisable()) {
|
||||||
m_proxyInter->itemRemoved(this, POWER_KEY);
|
m_proxyInter->itemRemoved(this, POWER_KEY);
|
||||||
@ -109,7 +107,7 @@ void PowerPlugin::pluginStateSwitched()
|
|||||||
|
|
||||||
bool PowerPlugin::pluginIsDisable()
|
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)
|
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)
|
int PowerPlugin::itemSortKey(const QString &itemKey)
|
||||||
{
|
{
|
||||||
Dock::DisplayMode mode = displayMode();
|
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(mode);
|
|
||||||
|
|
||||||
//if (mode == Dock::DisplayMode::Fashion) {
|
return m_proxyInter->getValue(this, key, displayMode() == Dock::DisplayMode::Fashion ? 3 : 3).toInt();
|
||||||
//return m_settings.value(key, 4).toInt();
|
|
||||||
//} else {
|
|
||||||
//return m_settings.value(key, 4).toInt();
|
|
||||||
//}
|
|
||||||
|
|
||||||
return m_settings.value(key, 4).toInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerPlugin::setSortKey(const QString &itemKey, const int order)
|
void PowerPlugin::setSortKey(const QString &itemKey, const int order)
|
||||||
{
|
{
|
||||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
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()
|
void PowerPlugin::updateBatteryVisible()
|
||||||
|
@ -65,7 +65,6 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_pluginLoaded;
|
bool m_pluginLoaded;
|
||||||
QSettings m_settings;
|
|
||||||
|
|
||||||
PowerStatusWidget *m_powerStatusWidget;
|
PowerStatusWidget *m_powerStatusWidget;
|
||||||
TipsWidget *m_tipsLabel;
|
TipsWidget *m_tipsLabel;
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
SoundPlugin::SoundPlugin(QObject *parent)
|
SoundPlugin::SoundPlugin(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_settings("deepin", "dde-dock-sound"),
|
|
||||||
m_soundItem(nullptr)
|
m_soundItem(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -48,23 +47,23 @@ void SoundPlugin::init(PluginProxyInterface *proxyInter)
|
|||||||
m_soundItem = new SoundItem;
|
m_soundItem = new SoundItem;
|
||||||
connect(m_soundItem, &SoundItem::requestContextMenu, [this] { m_proxyInter->requestContextMenu(this, SOUND_KEY); });
|
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);
|
m_proxyInter->itemAdded(this, SOUND_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundPlugin::pluginStateSwitched()
|
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())
|
if (pluginIsDisable())
|
||||||
m_proxyInter->itemAdded(this, SOUND_KEY);
|
|
||||||
else
|
|
||||||
m_proxyInter->itemRemoved(this, SOUND_KEY);
|
m_proxyInter->itemRemoved(this, SOUND_KEY);
|
||||||
|
else
|
||||||
|
m_proxyInter->itemAdded(this, SOUND_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundPlugin::pluginIsDisable()
|
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)
|
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)
|
int SoundPlugin::itemSortKey(const QString &itemKey)
|
||||||
{
|
{
|
||||||
Q_UNUSED(itemKey);
|
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||||
|
|
||||||
Dock::DisplayMode mode = displayMode();
|
return m_proxyInter->getValue(this, key, displayMode() == Dock::DisplayMode::Fashion ? 1 : 1).toInt();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundPlugin::setSortKey(const QString &itemKey, const int order)
|
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_proxyInter->saveValue(this, key, order);
|
||||||
m_settings.setValue(key, order);
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
#include "pluginsiteminterface.h"
|
#include "pluginsiteminterface.h"
|
||||||
#include "sounditem.h"
|
#include "sounditem.h"
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
class SoundPlugin : public QObject, PluginsItemInterface
|
class SoundPlugin : public QObject, PluginsItemInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -54,7 +52,6 @@ public:
|
|||||||
void setSortKey(const QString &itemKey, const int order);
|
void setSortKey(const QString &itemKey, const int order);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings m_settings;
|
|
||||||
SoundItem *m_soundItem;
|
SoundItem *m_soundItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,9 +159,7 @@ int TrayPlugin::itemSortKey(const QString &itemKey)
|
|||||||
Dock::DisplayMode mode = displayMode();
|
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(mode);
|
||||||
|
|
||||||
return m_proxyInter
|
return m_proxyInter->getValue(this, key, mode == Dock::DisplayMode::Fashion ? 1 : 0).toInt();
|
||||||
->getValue(this, key, mode == Dock::DisplayMode::Fashion ? 1 : 1)
|
|
||||||
.toInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayPlugin::setSortKey(const QString &itemKey, const int order)
|
void TrayPlugin::setSortKey(const QString &itemKey, const int order)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user