fix(datetime): connect control-center 24 hours setting

This commit is contained in:
shaojun 2019-09-03 09:37:59 +08:00
parent 54d6447abc
commit 7dcfcfc846
2 changed files with 26 additions and 10 deletions

View File

@ -26,11 +26,15 @@
#include <QDebug>
#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();
}

View File

@ -30,6 +30,7 @@
#include <QLabel>
#include <QSettings>
class QDBusInterface;
class DatetimePlugin : public QObject, PluginsItemInterface
{
Q_OBJECT
@ -63,6 +64,7 @@ public:
private slots:
void updateCurrentTimeString();
void refreshPluginItemsVisible();
void propertiesChanged();
private:
QPointer<DatetimeWidget> m_centralWidget;
@ -71,6 +73,8 @@ private:
QTimer *m_refershTimer;
QString m_currentTimeString;
QDBusInterface *m_interface;
};
#endif // DATETIMEPLUGIN_H