diff --git a/calendar-client/src/dbus/dbustimedate.cpp b/calendar-common/src/dbustimedate.cpp similarity index 92% rename from calendar-client/src/dbus/dbustimedate.cpp rename to calendar-common/src/dbustimedate.cpp index 718da1c1..73ad18ba 100644 --- a/calendar-client/src/dbus/dbustimedate.cpp +++ b/calendar-common/src/dbustimedate.cpp @@ -42,6 +42,15 @@ int DBusTimedate::shortDateFormat() return m_hasDateTimeFormat ? getPropertyByName("ShortDateFormat").toInt() : 1; } +Qt::DayOfWeek DBusTimedate::weekBegins() +{ + if (m_hasDateTimeFormat) { + // WeekBegins是从0开始的,加1才能对应DayOfWeek + return Qt::DayOfWeek(getPropertyByName("WeekBegins").toInt() + 1); + } + return Qt::Monday; +} + void DBusTimedate::propertiesChanged(const QDBusMessage &msg) { QList arguments = msg.arguments(); diff --git a/calendar-client/src/dbus/dbustimedate.h b/calendar-common/src/dbustimedate.h similarity index 86% rename from calendar-client/src/dbus/dbustimedate.h rename to calendar-common/src/dbustimedate.h index 1f674ffe..48717bae 100644 --- a/calendar-client/src/dbus/dbustimedate.h +++ b/calendar-common/src/dbustimedate.h @@ -13,13 +13,16 @@ class DBusTimedate : public QDBusAbstractInterface Q_OBJECT Q_PROPERTY(int ShortTimeFormat READ shortTimeFormat NOTIFY ShortTimeFormatChanged) Q_PROPERTY(int ShortDateFormat READ shortDateFormat NOTIFY ShortDateFormatChanged) + Q_PROPERTY(int WeekBegins READ weekBegins NOTIFY WeekBeginsChanged) public: explicit DBusTimedate(QObject *parent = nullptr); int shortTimeFormat(); int shortDateFormat(); + Qt::DayOfWeek weekBegins(); signals: void ShortDateFormatChanged(int value) const; void ShortTimeFormatChanged(int value) const; + void WeekBeginsChanged(int value) const; public slots: void propertiesChanged(const QDBusMessage &msg); diff --git a/calendar-service/src/calendarDataManager/daccountmanagemodule.cpp b/calendar-service/src/calendarDataManager/daccountmanagemodule.cpp index b3a945cc..5c34c5d7 100644 --- a/calendar-service/src/calendarDataManager/daccountmanagemodule.cpp +++ b/calendar-service/src/calendarDataManager/daccountmanagemodule.cpp @@ -26,6 +26,15 @@ DAccountManageModule::DAccountManageModule(QObject *parent) &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, &DAccountManageModule::slotSettingChange); + } else { + connect(&m_timeDateDbus, + &DBusTimedate::ShortTimeFormatChanged, + this, + &DAccountManageModule::slotSettingChange); + connect(&m_timeDateDbus, + &DBusTimedate::WeekBeginsChanged, + this, + &DAccountManageModule::slotSettingChange); } m_isSupportUid = m_syncFileManage->getSyncoperation()->hasAvailable(); if(Dtk::Core::DSysInfo::isCommunityEdition()){ @@ -335,22 +344,39 @@ DCalendarGeneralSettings::Ptr DAccountManageModule::getGeneralSettings() { auto cg = m_accountManagerDB->getCalendarGeneralSettings(); if (getFirstDayOfWeekSource() == DCalendarGeneralSettings::Source_System) { - bool ok; - auto dayofWeek = Qt::DayOfWeek(m_reginFormatConfig->value(firstDayOfWeek_key).toInt(&ok)); - if (ok) { - cg->setFirstDayOfWeek(dayofWeek); + // deepin23使用dconfig存储系统配置 + if (m_reginFormatConfig->isValid()) { + bool ok; + auto dayofWeek = + Qt::DayOfWeek(m_reginFormatConfig->value(firstDayOfWeek_key).toInt(&ok)); + if (ok) { + cg->setFirstDayOfWeek(dayofWeek); + } else { + qWarning() << "Unable to get first day of week from control center config file"; + } } else { - qWarning() << "Unable to get first day of week from control center config file"; + // 在deepin20.9使用dbus获取系统配置 + cg->setFirstDayOfWeek(m_timeDateDbus.weekBegins()); } } if (getTimeFormatTypeSource() == DCalendarGeneralSettings::Source_System) { - auto shortTimeFormat = m_reginFormatConfig->value(shortTimeFormat_key).toString(); - if (shortTimeFormat.isEmpty()) { - qWarning() << "Unable to short time format from control center config file"; - } else if (shortTimeFormat.contains("ap")) { - cg->setTimeShowType(DCalendarGeneralSettings::Twelve); + // 在deepin23使用dconfig获取系统配置 + if (m_reginFormatConfig->isValid()) { + auto shortTimeFormat = m_reginFormatConfig->value(shortTimeFormat_key).toString(); + if (shortTimeFormat.isEmpty()) { + qWarning() << "Unable to short time format from control center config file"; + } else if (shortTimeFormat.contains("ap")) { + cg->setTimeShowType(DCalendarGeneralSettings::Twelve); + } else { + cg->setTimeShowType(DCalendarGeneralSettings::TwentyFour); + } } else { - cg->setTimeShowType(DCalendarGeneralSettings::TwentyFour); + // 在deepin20.9使用dbus获取系统配置 + if (m_timeDateDbus.shortTimeFormat() == 0) { + cg->setTimeShowType(DCalendarGeneralSettings::Twelve); + } else { + cg->setTimeShowType(DCalendarGeneralSettings::TwentyFour); + } } } return cg; diff --git a/calendar-service/src/calendarDataManager/daccountmanagemodule.h b/calendar-service/src/calendarDataManager/daccountmanagemodule.h index fb74d8f3..a6cdd605 100644 --- a/calendar-service/src/calendarDataManager/daccountmanagemodule.h +++ b/calendar-service/src/calendarDataManager/daccountmanagemodule.h @@ -11,6 +11,7 @@ #include "daccountmodule.h" #include "daccountmanagerdatabase.h" #include "daccountservice.h" +#include "dbustimedate.h" #include #include @@ -120,6 +121,7 @@ public slots: QTimer m_timer; bool m_isSupportUid = false; QSettings m_settings; + DBusTimedate m_timeDateDbus; }; #endif // DACCOUNTMANAGEMODULE_H