Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get system setting from dbus #172

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading