From 7dcfcfc8468bed729653edb578c77df82296a331 Mon Sep 17 00:00:00 2001 From: shaojun Date: Tue, 3 Sep 2019 09:37:59 +0800 Subject: [PATCH] fix(datetime): connect control-center 24 hours setting --- plugins/datetime/datetimeplugin.cpp | 32 ++++++++++++++++++++--------- plugins/datetime/datetimeplugin.h | 4 ++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/plugins/datetime/datetimeplugin.cpp b/plugins/datetime/datetimeplugin.cpp index 36f0ab09d..d61af38ef 100644 --- a/plugins/datetime/datetimeplugin.cpp +++ b/plugins/datetime/datetimeplugin.cpp @@ -26,11 +26,15 @@ #include #define PLUGIN_STATE_KEY "enable" -#define TIME_FORMAT_KEY "24HourFormat" +#define TIME_FORMAT_KEY "Use24HourFormat" DatetimePlugin::DatetimePlugin(QObject *parent) : QObject(parent) { + m_interface = new QDBusInterface("com.deepin.daemon.Timedate", "/com/deepin/daemon/Timedate", "com.deepin.daemon.Timedate"); + + QDBusConnection sessionBus = QDBusConnection::sessionBus(); + sessionBus.connect("com.deepin.daemon.Timedate", "/com/deepin/daemon/Timedate", "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(propertiesChanged())); } const QString DatetimePlugin::pluginName() const @@ -178,22 +182,25 @@ void DatetimePlugin::invokedMenuItem(const QString &itemKey, const QString &menu if (menuId == "open") { DDBusSender() - .service("com.deepin.dde.ControlCenter") - .interface("com.deepin.dde.ControlCenter") - .path("/com/deepin/dde/ControlCenter") - .method(QString("ShowModule")) - .arg(QString("datetime")) - .call(); + .service("com.deepin.dde.ControlCenter") + .interface("com.deepin.dde.ControlCenter") + .path("/com/deepin/dde/ControlCenter") + .method(QString("ShowModule")) + .arg(QString("datetime")) + .call(); } else { - const bool value = m_proxyInter->getValue(this, TIME_FORMAT_KEY, true).toBool(); - m_proxyInter->saveValue(this, TIME_FORMAT_KEY, !value); + const bool value = m_interface->property(TIME_FORMAT_KEY).toBool(); + m_interface->setProperty(TIME_FORMAT_KEY, !value); m_centralWidget->set24HourFormat(!value); } } void DatetimePlugin::pluginSettingsChanged() { - m_centralWidget->set24HourFormat(m_proxyInter->getValue(this, TIME_FORMAT_KEY, true).toBool()); + const bool value = m_interface->property(TIME_FORMAT_KEY).toBool(); + + m_proxyInter->saveValue(this, TIME_FORMAT_KEY, value); + m_centralWidget->set24HourFormat(value); refreshPluginItemsVisible(); } @@ -223,3 +230,8 @@ void DatetimePlugin::refreshPluginItemsVisible() else m_proxyInter->itemRemoved(this, pluginName()); } + +void DatetimePlugin::propertiesChanged() +{ + pluginSettingsChanged(); +} diff --git a/plugins/datetime/datetimeplugin.h b/plugins/datetime/datetimeplugin.h index cbb7c5671..d17c15278 100644 --- a/plugins/datetime/datetimeplugin.h +++ b/plugins/datetime/datetimeplugin.h @@ -30,6 +30,7 @@ #include #include +class QDBusInterface; class DatetimePlugin : public QObject, PluginsItemInterface { Q_OBJECT @@ -63,6 +64,7 @@ public: private slots: void updateCurrentTimeString(); void refreshPluginItemsVisible(); + void propertiesChanged(); private: QPointer m_centralWidget; @@ -71,6 +73,8 @@ private: QTimer *m_refershTimer; QString m_currentTimeString; + + QDBusInterface *m_interface; }; #endif // DATETIMEPLUGIN_H