Skip to content

Commit 08cef5e

Browse files
committed
fix: Fix the issue where the time does not follow the regional format
Fix the issue where the time does not follow the regional format Log: Fix the issue where the time does not follow the regional format pms: BUG-342705
1 parent 1eda0b5 commit 08cef5e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/widgets/centertopwidget.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ void CenterTopWidget::setCurrentUser(User *user)
8080
}
8181
}
8282

83+
#ifdef ENABLE_DSS_SNIPE
84+
m_timeWidget->updateLocale(QLocale(getUserLocale(user)));
85+
#else
8386
auto locale = qApp->applicationName() == "dde-lock" ? QLocale::system().name() : user->locale();
8487
m_timeWidget->updateLocale(QLocale(locale));
88+
#endif // ENABLE_DSS_SNIPE
8589
m_timeWidget->set24HourFormat(user->isUse24HourFormat());
8690
m_timeWidget->setWeekdayFormatType(user->weekdayFormat());
8791
m_timeWidget->setShortDateFormat(user->shortDateFormat());
@@ -105,8 +109,12 @@ void CenterTopWidget::setCurrentUser(User *user)
105109
void CenterTopWidget::updateTimeFormat(bool use24)
106110
{
107111
if (!m_currentUser.isNull()) {
112+
#ifdef ENABLE_DSS_SNIPE
113+
m_timeWidget->updateLocale(QLocale(getUserLocale(m_currentUser)));
114+
#else
108115
auto locale = qApp->applicationName() == "dde-lock" ? QLocale::system().name() : m_currentUser->locale();
109116
m_timeWidget->updateLocale(QLocale(locale));
117+
#endif // ENABLE_DSS_SNIPE
110118
m_timeWidget->set24HourFormat(use24);
111119
m_timeWidget->setVisible(true);
112120
}
@@ -219,6 +227,22 @@ QString CenterTopWidget::getRegionFormatValue(const QString &userConfigDbusPath,
219227
return reply.value().toString();
220228
}
221229

230+
QString CenterTopWidget::getUserLocale(const User *user) const
231+
{
232+
if (!user)
233+
return QLocale::system().name();
234+
235+
if (qApp->applicationName() == "dde-lock")
236+
return QLocale::system().name();
237+
238+
QString userConfigDbusPath = getRegionFormatConfigPath(user);
239+
QString localeName = getRegionFormatValue(userConfigDbusPath, localeNameKey);
240+
if (localeName.isEmpty()) {
241+
localeName = user->locale();
242+
}
243+
return localeName;
244+
}
245+
222246
void CenterTopWidget::updateRegionFormatConnection(const User *user)
223247
{
224248
if (!user) {

src/widgets/centertopwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private slots:
4141
private:
4242
QString getRegionFormatConfigPath(const User *user) const;
4343
QString getRegionFormatValue(const QString &userConfigDbusPath, const QString& key) const;
44+
QString getUserLocale(const User *user) const;
4445
void updateRegionFormatConnection(const User *user);
4546
void updateUserDateTimeFormat();
4647
#endif // ENABLE_DSS_SNIPE

0 commit comments

Comments
 (0)