feat: integrating plugins config files

Change-Id: Id50d220be6c71fb26271634886abe5496efb3077
This commit is contained in:
haruyukilxz 2018-11-08 11:39:26 +08:00 committed by 流年匆忙
parent 213db42172
commit 4837c9dd35
Notes: gerrit 2018-11-09 10:57:05 +08:00
Verified+1: <jenkins@deepin.com>
Code-Review+2: 流年匆忙 <justforlxz@gmail.com>
Submitted-by: 流年匆忙 <justforlxz@gmail.com>
Submitted-at: Fri, 09 Nov 2018 10:57:03 +0800
Reviewed-on: https://cr.deepin.io/39579
Project: dde/dde-dock
Branch: refs/heads/master
11 changed files with 95 additions and 47 deletions

View File

@ -30,10 +30,12 @@
#define API_VERSION "1.0" #define API_VERSION "1.0"
DockPluginsController::DockPluginsController(DockItemController *itemControllerInter) DockPluginsController::DockPluginsController(
: QObject(itemControllerInter), DockItemController *itemControllerInter)
m_dbusDaemonInterface(QDBusConnection::sessionBus().interface()), : QObject(itemControllerInter)
m_itemControllerInter(itemControllerInter) , m_dbusDaemonInterface(QDBusConnection::sessionBus().interface())
, m_itemControllerInter(itemControllerInter)
, m_pluginsSetting("deepin", "dde-dock")
{ {
qApp->installEventFilter(this); qApp->installEventFilter(this);
} }
@ -219,3 +221,16 @@ PluginsItem *DockPluginsController::pluginItemAt(PluginsItemInterface * const it
return m_pluginList[itemInter][itemKey]; return m_pluginList[itemInter][itemKey];
} }
void DockPluginsController::saveValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant &value) {
m_pluginsSetting.beginGroup(itemInter->pluginName());
m_pluginsSetting.setValue(itemKey, value);
m_pluginsSetting.endGroup();
}
const QVariant DockPluginsController::getValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant& failback) {
m_pluginsSetting.beginGroup(itemInter->pluginName());
QVariant value { std::move(m_pluginsSetting.value(itemKey, failback)) };
m_pluginsSetting.endGroup();
return std::move(value);
}

View File

@ -46,6 +46,8 @@ public:
void itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey); void itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey);
void itemRemoved(PluginsItemInterface * const itemInter, const QString &itemKey); void itemRemoved(PluginsItemInterface * const itemInter, const QString &itemKey);
void requestContextMenu(PluginsItemInterface * const itemInter, const QString &itemKey); void requestContextMenu(PluginsItemInterface * const itemInter, const QString &itemKey);
void saveValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant &value);
const QVariant getValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant& failback = QVariant());
signals: signals:
void pluginItemInserted(PluginsItem *pluginItem) const; void pluginItemInserted(PluginsItem *pluginItem) const;
@ -68,6 +70,7 @@ private:
QDBusConnectionInterface *m_dbusDaemonInterface; QDBusConnectionInterface *m_dbusDaemonInterface;
QMap<PluginsItemInterface *, QMap<QString, PluginsItem *>> m_pluginList; QMap<PluginsItemInterface *, QMap<QString, PluginsItem *>> m_pluginList;
DockItemController *m_itemControllerInter; DockItemController *m_itemControllerInter;
QSettings m_pluginsSetting;
}; };
#endif // DOCKPLUGINSCONTROLLER_H #endif // DOCKPLUGINSCONTROLLER_H

View File

@ -62,6 +62,18 @@ public:
/// request show context menu /// request show context menu
/// ///
virtual void requestContextMenu(PluginsItemInterface * const itemInter, const QString &itemKey) = 0; virtual void requestContextMenu(PluginsItemInterface * const itemInter, const QString &itemKey) = 0;
///
/// \brief saveValue
/// save module config to .config/deepin/dde-dock.conf
///
virtual void saveValue(PluginsItemInterface * const itemInter, const QString &itemKey, const QVariant &value) = 0;
///
/// \brief getValue
/// return value from .config/deepin/dde-dock.conf
///
virtual const QVariant getValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant& failback = QVariant()) = 0;
}; };
#endif // PLUGINPROXYINTERFACE_H #endif // PLUGINPROXYINTERFACE_H

View File

@ -30,8 +30,7 @@ DatetimePlugin::DatetimePlugin(QObject *parent)
m_dateTipsLabel(new TipsWidget), m_dateTipsLabel(new TipsWidget),
m_refershTimer(new QTimer(this)), m_refershTimer(new QTimer(this))
m_settings("deepin", "dde-dock-datetime")
{ {
m_dateTipsLabel->setObjectName("datetime"); m_dateTipsLabel->setObjectName("datetime");
@ -60,6 +59,15 @@ void DatetimePlugin::init(PluginProxyInterface *proxyInter)
{ {
m_proxyInter = proxyInter; m_proxyInter = proxyInter;
// transfer config
QSettings settings("deepin", "dde-dock-datetime");
if (QFile::exists(settings.fileName())) {
Dock::DisplayMode mode = displayMode();
const QString key = QString("pos_%1").arg(mode);
proxyInter->saveValue(this, key, settings.value(key, mode == Dock::DisplayMode::Fashion ? 5 : -1));
QFile::remove(settings.fileName());
}
if (m_centralWidget->enabled()) if (m_centralWidget->enabled())
m_proxyInter->itemAdded(this, QString()); m_proxyInter->itemAdded(this, QString());
} }
@ -87,9 +95,9 @@ int DatetimePlugin::itemSortKey(const QString &itemKey)
const QString key = QString("pos_%1").arg(mode); const QString key = QString("pos_%1").arg(mode);
if (mode == Dock::DisplayMode::Fashion) { if (mode == Dock::DisplayMode::Fashion) {
return m_settings.value(key, 5).toInt(); return m_proxyInter->getValue(this, key, 5).toInt();
} else { } else {
return m_settings.value(key, -1).toInt(); return m_proxyInter->getValue(this, key, -1).toInt();
} }
} }
@ -98,7 +106,7 @@ void DatetimePlugin::setSortKey(const QString &itemKey, const int order)
Q_UNUSED(itemKey); Q_UNUSED(itemKey);
const QString key = QString("pos_%1").arg(displayMode()); const QString key = QString("pos_%1").arg(displayMode());
m_settings.setValue(key, order); m_proxyInter->saveValue(this, key, order);
} }
QWidget *DatetimePlugin::itemWidget(const QString &itemKey) QWidget *DatetimePlugin::itemWidget(const QString &itemKey)

View File

@ -68,7 +68,6 @@ private:
QTimer *m_refershTimer; QTimer *m_refershTimer;
QString m_currentTimeString; QString m_currentTimeString;
QSettings m_settings;
}; };
#endif // DATETIMEPLUGIN_H #endif // DATETIMEPLUGIN_H

View File

@ -31,7 +31,6 @@ ShutdownPlugin::ShutdownPlugin(QObject *parent)
: QObject(parent), : QObject(parent),
m_pluginLoaded(false), m_pluginLoaded(false),
m_settings("deepin", "dde-dock-shutdown"),
m_tipsLabel(new TipsWidget) m_tipsLabel(new TipsWidget)
{ {
m_tipsLabel->setText(tr("Shutdown")); m_tipsLabel->setText(tr("Shutdown"));
@ -66,6 +65,12 @@ void ShutdownPlugin::init(PluginProxyInterface *proxyInter)
{ {
m_proxyInter = proxyInter; m_proxyInter = proxyInter;
// transfer config
QSettings settings("deepin", "dde-dock-shutdown");
if (QFile::exists(settings.fileName())) {
QFile::remove(settings.fileName());
}
if (!pluginIsDisable()) { if (!pluginIsDisable()) {
loadPlugin(); loadPlugin();
} }
@ -73,7 +78,7 @@ void ShutdownPlugin::init(PluginProxyInterface *proxyInter)
void ShutdownPlugin::pluginStateSwitched() void ShutdownPlugin::pluginStateSwitched()
{ {
m_settings.setValue(PLUGIN_STATE_KEY, !m_settings.value(PLUGIN_STATE_KEY, true).toBool()); m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool());
if (pluginIsDisable()) if (pluginIsDisable())
{ {
@ -83,13 +88,13 @@ void ShutdownPlugin::pluginStateSwitched()
loadPlugin(); loadPlugin();
return; return;
} }
m_proxyInter->itemAdded(this, QString()); m_proxyInter->itemAdded(this, pluginName());
} }
} }
bool ShutdownPlugin::pluginIsDisable() bool ShutdownPlugin::pluginIsDisable()
{ {
return !m_settings.value(PLUGIN_STATE_KEY, true).toBool(); return !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool();
} }
const QString ShutdownPlugin::itemCommand(const QString &itemKey) const QString ShutdownPlugin::itemCommand(const QString &itemKey)
@ -196,13 +201,13 @@ int ShutdownPlugin::itemSortKey(const QString &itemKey)
//return m_settings.value(key, 4).toInt(); //return m_settings.value(key, 4).toInt();
//} //}
return m_settings.value(key, 4).toInt(); return m_proxyInter->getValue(this, key, 4).toInt();
} }
void ShutdownPlugin::setSortKey(const QString &itemKey, const int order) void ShutdownPlugin::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 ShutdownPlugin::requestContextMenu(const QString &itemKey) void ShutdownPlugin::requestContextMenu(const QString &itemKey)
@ -223,6 +228,6 @@ void ShutdownPlugin::loadPlugin()
connect(m_shutdownWidget, &PluginWidget::requestContextMenu, this, &ShutdownPlugin::requestContextMenu); connect(m_shutdownWidget, &PluginWidget::requestContextMenu, this, &ShutdownPlugin::requestContextMenu);
m_proxyInter->itemAdded(this, QString()); m_proxyInter->itemAdded(this, pluginName());
displayModeChanged(displayMode()); displayModeChanged(displayMode());
} }

View File

@ -61,7 +61,6 @@ private:
private: private:
bool m_pluginLoaded; bool m_pluginLoaded;
QSettings m_settings;
PluginWidget *m_shutdownWidget; PluginWidget *m_shutdownWidget;
TipsWidget *m_tipsLabel; TipsWidget *m_tipsLabel;

View File

@ -39,9 +39,7 @@ SystemTrayPlugin::SystemTrayPlugin(QObject *parent)
m_trayInter(new DBusTrayManager(this)), m_trayInter(new DBusTrayManager(this)),
m_systemTraysLoader(new SystemTraysManager(this)), m_systemTraysLoader(new SystemTraysManager(this)),
m_trayApplet(new TrayApplet), m_trayApplet(new TrayApplet),
m_tipsLabel(new TipsWidget), m_tipsLabel(new TipsWidget)
m_containerSettings(new QSettings("deepin", "dde-dock-tray"))
{ {
m_trayApplet->setObjectName("sys-tray"); m_trayApplet->setObjectName("sys-tray");
m_fashionItem = new FashionTrayItem(position()); m_fashionItem = new FashionTrayItem(position());
@ -58,7 +56,15 @@ const QString SystemTrayPlugin::pluginName() const
void SystemTrayPlugin::init(PluginProxyInterface *proxyInter) void SystemTrayPlugin::init(PluginProxyInterface *proxyInter)
{ {
if (!m_containerSettings->value("enable", true).toBool()) { // transfex config
QSettings settings("deepin", "dde-dock-shutdown");
if (QFile::exists(settings.fileName())) {
proxyInter->saveValue(this, "enable", settings.value("enable", true));
QFile::remove(settings.fileName());
}
if (!proxyInter->getValue(this, "enable", true).toBool()) {
qDebug() << "hide tray from config disable!!"; qDebug() << "hide tray from config disable!!";
return; return;
} }
@ -93,7 +99,7 @@ void SystemTrayPlugin::init(PluginProxyInterface *proxyInter)
void SystemTrayPlugin::displayModeChanged(const Dock::DisplayMode mode) void SystemTrayPlugin::displayModeChanged(const Dock::DisplayMode mode)
{ {
if (!m_containerSettings->value("enable", true).toBool()) { if (!m_proxyInter->getValue(this, "enable", true).toBool()) {
return; return;
} }
@ -156,10 +162,10 @@ bool SystemTrayPlugin::itemAllowContainer(const QString &itemKey)
bool SystemTrayPlugin::itemIsInContainer(const QString &itemKey) bool SystemTrayPlugin::itemIsInContainer(const QString &itemKey)
{ {
const QString widKey = getWindowClass(XWindowTrayWidget::toWinId(itemKey)); const QString widKey = getWindowClass(XWindowTrayWidget::toWinId(itemKey));
if (!widKey.isEmpty())
return m_containerSettings->value(widKey, false).toBool(); return m_proxyInter
else ->getValue(this, widKey.isEmpty() ? itemKey : widKey, false)
return m_containerSettings->value(itemKey, false).toBool(); .toBool();
} }
int SystemTrayPlugin::itemSortKey(const QString &itemKey) int SystemTrayPlugin::itemSortKey(const QString &itemKey)
@ -167,26 +173,22 @@ int SystemTrayPlugin::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);
if (mode == Dock::DisplayMode::Fashion) { return m_proxyInter
return m_containerSettings->value(key, 3).toInt(); ->getValue(this, key, mode == Dock::DisplayMode::Fashion ? 3 : 1)
} else { .toInt();
return m_containerSettings->value(key, 1).toInt();
}
} }
void SystemTrayPlugin::setSortKey(const QString &itemKey, const int order) void SystemTrayPlugin::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_containerSettings->setValue(key, order); m_proxyInter->saveValue(this, key, order);
} }
void SystemTrayPlugin::setItemIsInContainer(const QString &itemKey, const bool container) void SystemTrayPlugin::setItemIsInContainer(const QString &itemKey, const bool container)
{ {
const QString widKey = getWindowClass(XWindowTrayWidget::toWinId(itemKey)); const QString widKey = getWindowClass(XWindowTrayWidget::toWinId(itemKey));
if (widKey.isEmpty())
m_containerSettings->setValue(itemKey, container); m_proxyInter->saveValue(this, widKey.isEmpty() ? itemKey : widKey, container);
else
m_containerSettings->setValue(widKey, container);
} }
void SystemTrayPlugin::updateTipsContent() void SystemTrayPlugin::updateTipsContent()

View File

@ -87,8 +87,6 @@ private:
TrayApplet *m_trayApplet; TrayApplet *m_trayApplet;
TipsWidget *m_tipsLabel; TipsWidget *m_tipsLabel;
QSettings *m_containerSettings;
}; };
#endif // SYSTEMTRAYPLUGIN_H #endif // SYSTEMTRAYPLUGIN_H

View File

@ -33,8 +33,7 @@ DWIDGET_USE_NAMESPACE
TrashPlugin::TrashPlugin(QObject *parent) TrashPlugin::TrashPlugin(QObject *parent)
: QObject(parent), : QObject(parent),
m_trashWidget(new TrashWidget), m_trashWidget(new TrashWidget),
m_tipsLabel(new QLabel), m_tipsLabel(new QLabel)
m_settings("deepin", "dde-dock-trash")
{ {
m_tipsLabel->setObjectName("trash"); m_tipsLabel->setObjectName("trash");
m_tipsLabel->setStyleSheet("color:white;" m_tipsLabel->setStyleSheet("color:white;"
@ -50,6 +49,15 @@ const QString TrashPlugin::pluginName() const
void TrashPlugin::init(PluginProxyInterface *proxyInter) void TrashPlugin::init(PluginProxyInterface *proxyInter)
{ {
// transfex config
QSettings settings("deepin", "dde-dock-trash");
if (QFile::exists(settings.fileName())) {
const QString &key = QString("pos_%1_%2").arg(pluginName()).arg(displayMode());
proxyInter->saveValue(this, key, settings.value(key));
QFile::remove(settings.fileName());
}
// blumia: we are using i10n translation from DFM so... // blumia: we are using i10n translation from DFM so...
QString applicationName = qApp->applicationName(); QString applicationName = qApp->applicationName();
qApp->setApplicationName("dde-file-manager"); qApp->setApplicationName("dde-file-manager");
@ -121,24 +129,24 @@ void TrashPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId,
int TrashPlugin::itemSortKey(const QString &itemKey) int TrashPlugin::itemSortKey(const QString &itemKey)
{ {
const QString &key = QString("pos_%1_%2").arg(itemKey).arg(displayMode()); const QString &key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
return m_settings.value(key, -1).toInt(); return m_proxyInter->getValue(this, key, -1).toInt();
} }
void TrashPlugin::setSortKey(const QString &itemKey, const int order) void TrashPlugin::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 TrashPlugin::displayModeChanged(const Dock::DisplayMode displayMode) void TrashPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
{ {
if (displayMode == Dock::Fashion) if (displayMode == Dock::Fashion)
m_proxyInter->itemAdded(this, QString()); m_proxyInter->itemAdded(this, pluginName());
else else
m_proxyInter->itemRemoved(this, QString()); m_proxyInter->itemRemoved(this, pluginName());
} }
void TrashPlugin::showContextMenu() void TrashPlugin::showContextMenu()
{ {
m_proxyInter->requestContextMenu(this, QString()); m_proxyInter->requestContextMenu(this, pluginName());
} }

View File

@ -63,7 +63,6 @@ private:
private: private:
TrashWidget *m_trashWidget; TrashWidget *m_trashWidget;
QLabel *m_tipsLabel; QLabel *m_tipsLabel;
QSettings m_settings;
}; };
#endif // TRASHPLUGIN_H #endif // TRASHPLUGIN_H