mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
feat: integrating plugins config files
Change-Id: Id50d220be6c71fb26271634886abe5496efb3077
This commit is contained in:
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
@ -30,10 +30,12 @@
|
||||
|
||||
#define API_VERSION "1.0"
|
||||
|
||||
DockPluginsController::DockPluginsController(DockItemController *itemControllerInter)
|
||||
: QObject(itemControllerInter),
|
||||
m_dbusDaemonInterface(QDBusConnection::sessionBus().interface()),
|
||||
m_itemControllerInter(itemControllerInter)
|
||||
DockPluginsController::DockPluginsController(
|
||||
DockItemController *itemControllerInter)
|
||||
: QObject(itemControllerInter)
|
||||
, m_dbusDaemonInterface(QDBusConnection::sessionBus().interface())
|
||||
, m_itemControllerInter(itemControllerInter)
|
||||
, m_pluginsSetting("deepin", "dde-dock")
|
||||
{
|
||||
qApp->installEventFilter(this);
|
||||
}
|
||||
@ -219,3 +221,16 @@ PluginsItem *DockPluginsController::pluginItemAt(PluginsItemInterface * const it
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
void itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey);
|
||||
void itemRemoved(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:
|
||||
void pluginItemInserted(PluginsItem *pluginItem) const;
|
||||
@ -68,6 +70,7 @@ private:
|
||||
QDBusConnectionInterface *m_dbusDaemonInterface;
|
||||
QMap<PluginsItemInterface *, QMap<QString, PluginsItem *>> m_pluginList;
|
||||
DockItemController *m_itemControllerInter;
|
||||
QSettings m_pluginsSetting;
|
||||
};
|
||||
|
||||
#endif // DOCKPLUGINSCONTROLLER_H
|
||||
|
@ -62,6 +62,18 @@ public:
|
||||
/// request show context menu
|
||||
///
|
||||
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
|
||||
|
@ -30,8 +30,7 @@ DatetimePlugin::DatetimePlugin(QObject *parent)
|
||||
|
||||
m_dateTipsLabel(new TipsWidget),
|
||||
|
||||
m_refershTimer(new QTimer(this)),
|
||||
m_settings("deepin", "dde-dock-datetime")
|
||||
m_refershTimer(new QTimer(this))
|
||||
{
|
||||
m_dateTipsLabel->setObjectName("datetime");
|
||||
|
||||
@ -60,6 +59,15 @@ void DatetimePlugin::init(PluginProxyInterface *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())
|
||||
m_proxyInter->itemAdded(this, QString());
|
||||
}
|
||||
@ -87,9 +95,9 @@ int DatetimePlugin::itemSortKey(const QString &itemKey)
|
||||
const QString key = QString("pos_%1").arg(mode);
|
||||
|
||||
if (mode == Dock::DisplayMode::Fashion) {
|
||||
return m_settings.value(key, 5).toInt();
|
||||
return m_proxyInter->getValue(this, key, 5).toInt();
|
||||
} 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);
|
||||
|
||||
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)
|
||||
|
@ -68,7 +68,6 @@ private:
|
||||
QTimer *m_refershTimer;
|
||||
|
||||
QString m_currentTimeString;
|
||||
QSettings m_settings;
|
||||
};
|
||||
|
||||
#endif // DATETIMEPLUGIN_H
|
||||
|
@ -31,7 +31,6 @@ ShutdownPlugin::ShutdownPlugin(QObject *parent)
|
||||
: QObject(parent),
|
||||
|
||||
m_pluginLoaded(false),
|
||||
m_settings("deepin", "dde-dock-shutdown"),
|
||||
m_tipsLabel(new TipsWidget)
|
||||
{
|
||||
m_tipsLabel->setText(tr("Shutdown"));
|
||||
@ -66,6 +65,12 @@ void ShutdownPlugin::init(PluginProxyInterface *proxyInter)
|
||||
{
|
||||
m_proxyInter = proxyInter;
|
||||
|
||||
// transfer config
|
||||
QSettings settings("deepin", "dde-dock-shutdown");
|
||||
if (QFile::exists(settings.fileName())) {
|
||||
QFile::remove(settings.fileName());
|
||||
}
|
||||
|
||||
if (!pluginIsDisable()) {
|
||||
loadPlugin();
|
||||
}
|
||||
@ -73,7 +78,7 @@ void ShutdownPlugin::init(PluginProxyInterface *proxyInter)
|
||||
|
||||
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())
|
||||
{
|
||||
@ -83,13 +88,13 @@ void ShutdownPlugin::pluginStateSwitched()
|
||||
loadPlugin();
|
||||
return;
|
||||
}
|
||||
m_proxyInter->itemAdded(this, QString());
|
||||
m_proxyInter->itemAdded(this, pluginName());
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@ -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_proxyInter->getValue(this, key, 4).toInt();
|
||||
}
|
||||
|
||||
void ShutdownPlugin::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 ShutdownPlugin::requestContextMenu(const QString &itemKey)
|
||||
@ -223,6 +228,6 @@ void ShutdownPlugin::loadPlugin()
|
||||
|
||||
connect(m_shutdownWidget, &PluginWidget::requestContextMenu, this, &ShutdownPlugin::requestContextMenu);
|
||||
|
||||
m_proxyInter->itemAdded(this, QString());
|
||||
m_proxyInter->itemAdded(this, pluginName());
|
||||
displayModeChanged(displayMode());
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ private:
|
||||
|
||||
private:
|
||||
bool m_pluginLoaded;
|
||||
QSettings m_settings;
|
||||
|
||||
PluginWidget *m_shutdownWidget;
|
||||
TipsWidget *m_tipsLabel;
|
||||
|
@ -39,9 +39,7 @@ SystemTrayPlugin::SystemTrayPlugin(QObject *parent)
|
||||
m_trayInter(new DBusTrayManager(this)),
|
||||
m_systemTraysLoader(new SystemTraysManager(this)),
|
||||
m_trayApplet(new TrayApplet),
|
||||
m_tipsLabel(new TipsWidget),
|
||||
|
||||
m_containerSettings(new QSettings("deepin", "dde-dock-tray"))
|
||||
m_tipsLabel(new TipsWidget)
|
||||
{
|
||||
m_trayApplet->setObjectName("sys-tray");
|
||||
m_fashionItem = new FashionTrayItem(position());
|
||||
@ -58,7 +56,15 @@ const QString SystemTrayPlugin::pluginName() const
|
||||
|
||||
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!!";
|
||||
return;
|
||||
}
|
||||
@ -93,7 +99,7 @@ void SystemTrayPlugin::init(PluginProxyInterface *proxyInter)
|
||||
|
||||
void SystemTrayPlugin::displayModeChanged(const Dock::DisplayMode mode)
|
||||
{
|
||||
if (!m_containerSettings->value("enable", true).toBool()) {
|
||||
if (!m_proxyInter->getValue(this, "enable", true).toBool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -156,10 +162,10 @@ bool SystemTrayPlugin::itemAllowContainer(const QString &itemKey)
|
||||
bool SystemTrayPlugin::itemIsInContainer(const QString &itemKey)
|
||||
{
|
||||
const QString widKey = getWindowClass(XWindowTrayWidget::toWinId(itemKey));
|
||||
if (!widKey.isEmpty())
|
||||
return m_containerSettings->value(widKey, false).toBool();
|
||||
else
|
||||
return m_containerSettings->value(itemKey, false).toBool();
|
||||
|
||||
return m_proxyInter
|
||||
->getValue(this, widKey.isEmpty() ? itemKey : widKey, false)
|
||||
.toBool();
|
||||
}
|
||||
|
||||
int SystemTrayPlugin::itemSortKey(const QString &itemKey)
|
||||
@ -167,26 +173,22 @@ int SystemTrayPlugin::itemSortKey(const QString &itemKey)
|
||||
Dock::DisplayMode mode = displayMode();
|
||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(mode);
|
||||
|
||||
if (mode == Dock::DisplayMode::Fashion) {
|
||||
return m_containerSettings->value(key, 3).toInt();
|
||||
} else {
|
||||
return m_containerSettings->value(key, 1).toInt();
|
||||
}
|
||||
return m_proxyInter
|
||||
->getValue(this, key, mode == Dock::DisplayMode::Fashion ? 3 : 1)
|
||||
.toInt();
|
||||
}
|
||||
|
||||
void SystemTrayPlugin::setSortKey(const QString &itemKey, const int order)
|
||||
{
|
||||
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)
|
||||
{
|
||||
const QString widKey = getWindowClass(XWindowTrayWidget::toWinId(itemKey));
|
||||
if (widKey.isEmpty())
|
||||
m_containerSettings->setValue(itemKey, container);
|
||||
else
|
||||
m_containerSettings->setValue(widKey, container);
|
||||
|
||||
m_proxyInter->saveValue(this, widKey.isEmpty() ? itemKey : widKey, container);
|
||||
}
|
||||
|
||||
void SystemTrayPlugin::updateTipsContent()
|
||||
|
@ -87,8 +87,6 @@ private:
|
||||
|
||||
TrayApplet *m_trayApplet;
|
||||
TipsWidget *m_tipsLabel;
|
||||
|
||||
QSettings *m_containerSettings;
|
||||
};
|
||||
|
||||
#endif // SYSTEMTRAYPLUGIN_H
|
||||
|
@ -33,8 +33,7 @@ DWIDGET_USE_NAMESPACE
|
||||
TrashPlugin::TrashPlugin(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_trashWidget(new TrashWidget),
|
||||
m_tipsLabel(new QLabel),
|
||||
m_settings("deepin", "dde-dock-trash")
|
||||
m_tipsLabel(new QLabel)
|
||||
{
|
||||
m_tipsLabel->setObjectName("trash");
|
||||
m_tipsLabel->setStyleSheet("color:white;"
|
||||
@ -50,6 +49,15 @@ const QString TrashPlugin::pluginName() const
|
||||
|
||||
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...
|
||||
QString applicationName = qApp->applicationName();
|
||||
qApp->setApplicationName("dde-file-manager");
|
||||
@ -121,24 +129,24 @@ void TrashPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId,
|
||||
int TrashPlugin::itemSortKey(const QString &itemKey)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (displayMode == Dock::Fashion)
|
||||
m_proxyInter->itemAdded(this, QString());
|
||||
m_proxyInter->itemAdded(this, pluginName());
|
||||
else
|
||||
m_proxyInter->itemRemoved(this, QString());
|
||||
m_proxyInter->itemRemoved(this, pluginName());
|
||||
}
|
||||
|
||||
void TrashPlugin::showContextMenu()
|
||||
{
|
||||
m_proxyInter->requestContextMenu(this, QString());
|
||||
m_proxyInter->requestContextMenu(this, pluginName());
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ private:
|
||||
private:
|
||||
TrashWidget *m_trashWidget;
|
||||
QLabel *m_tipsLabel;
|
||||
QSettings m_settings;
|
||||
};
|
||||
|
||||
#endif // TRASHPLUGIN_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user