Skip to content

Commit

Permalink
fix: default locale for time
Browse files Browse the repository at this point in the history
fix: default locale for time

Dont verify the locale directly, verify the string.

Issue: linuxdeepin/developer-center#6994
  • Loading branch information
FeiWang1119 committed Jan 22, 2024
1 parent bc8e6c1 commit 9333477
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/session-widgets/lockcontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ LockContent::LockContent(SessionBaseModel *const model, QWidget *parent)
once = true;

QString localeName = regionValue(localeName_key);
m_timeWidget->updateLocale(QLocale(localeName));
m_timeWidget->updateLocale(localeName);
}

void LockContent::initUI()
Expand Down Expand Up @@ -220,7 +220,7 @@ void LockContent::onValueChanged(const QDBusMessage &dbusMessage)
} else if (interfaceName == longDateFormat_key) {
m_longDateFormat = regionValue(longDateFormat_key);
}
m_timeWidget->updateLocale(QLocale(m_localeName), m_shortTimeFormat, m_longDateFormat);
m_timeWidget->updateLocale(m_localeName, m_shortTimeFormat, m_longDateFormat);
}

QString LockContent::configPath(std::shared_ptr<User> user) const
Expand Down Expand Up @@ -304,7 +304,7 @@ void LockContent::onCurrentUserChanged(std::shared_ptr<User> user)

auto logoLocale = qApp->applicationName() == "dde-lock" ? QLocale::system().name() : user->locale();
m_logoWidget->updateLocale(logoLocale);
m_timeWidget->updateLocale(locale, m_shortTimeFormat, m_longDateFormat);
m_timeWidget->updateLocale(locale.name(), m_shortTimeFormat, m_longDateFormat);

m_timeWidget->set24HourFormat(user->isUse24HourFormat());
m_timeWidget->setWeekdayFormatType(user->weekdayFormat());
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/timewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ void TimeWidget::set24HourFormat(bool use24HourFormat)
refreshTime();
}

void TimeWidget::updateLocale(const QLocale &locale, const QString &shortTimeFormat, const QString &longDateFormat)
void TimeWidget::updateLocale(const QString &locale, const QString &shortTimeFormat, const QString &longDateFormat)
{
m_locale = locale.name().isEmpty() ? QLocale::system() : locale;
m_locale = locale.isEmpty() ? QLocale::system() : QLocale(locale);
if (!shortTimeFormat.isEmpty())
m_shortTimeFormat = shortTimeFormat;
if (!longDateFormat.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/timewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TimeWidget : public QWidget
explicit TimeWidget(QWidget *parent = nullptr);
inline bool get24HourFormat() const { return m_use24HourFormat; }
void set24HourFormat(bool use24HourFormat);
void updateLocale(const QLocale &locale, const QString &shortTimeFormat = "", const QString &longDateFormat = "");
void updateLocale(const QString &locale, const QString &shortTimeFormat = "", const QString &longDateFormat = "");

public Q_SLOTS:
void setWeekdayFormatType(int type);
Expand Down

0 comments on commit 9333477

Please sign in to comment.