Skip to content

Commit

Permalink
feat: get system setting from dbus
Browse files Browse the repository at this point in the history
在旧版本系统使用dbus获取系统配置

Log:
  • Loading branch information
myml committed Mar 1, 2024
1 parent d808d6f commit 4293744
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<QVariant> arguments = msg.arguments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 37 additions & 11 deletions calendar-service/src/calendarDataManager/daccountmanagemodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()){
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "daccountmodule.h"
#include "daccountmanagerdatabase.h"
#include "daccountservice.h"
#include "dbustimedate.h"

#include <QObject>
#include <QSharedPointer>
Expand Down Expand Up @@ -120,6 +121,7 @@ public slots:
QTimer m_timer;
bool m_isSupportUid = false;
QSettings m_settings;
DBusTimedate m_timeDateDbus;
};

#endif // DACCOUNTMANAGEMODULE_H

0 comments on commit 4293744

Please sign in to comment.