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: can set special timezone when on deepin #1457

Merged
merged 1 commit into from
Oct 26, 2023
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
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ option(ENABLE_ASAN "Enable asan" OFF)
option(DISABLE_AUTHENTICATION "disable build authentication plugins" OFF)
option(DISABLE_UPDATE "disable build update plugins" OFF)
option(DISABLE_LANGUAGE "disable lanugage settings in control center" OFF)
option(USE_DEEPIN_ZONE "enable special timezone file on deepin" OFF)
set(DEEPIN_TIME_ZONE_PATH "/usr/share/dde/zoneinfo/zone1970.tab" CACHE STRING "deepin timezone path")

# asan 自己有内存泄露,暂不使用
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down Expand Up @@ -56,6 +58,11 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(UT_COMPILER -fprofile-instr-generate -ftest-coverage)
endif()

if (USE_DEEPIN_ZONE)
add_definitions(-DUSE_DEEPIN_ZONE)
add_definitions(-DDEEPIN_TIME_ZONE_PATH="${DEEPIN_TIME_ZONE_PATH}")
endif ()

# 增加安全编译参数
ADD_DEFINITIONS(${SAFE_COMPILER})

Expand Down Expand Up @@ -249,10 +256,10 @@ install(FILES misc/dde-control-center.desktop DESTINATION ${CMAKE_INSTALL_DATARO

#service
configure_file(
${CMAKE_SOURCE_DIR}/misc/org.deepin.dde.ControlCenter1.service.in
${CMAKE_CURRENT_BINARY_DIR}/org.deepin.dde.ControlCenter1.service
${CMAKE_SOURCE_DIR}/misc/org.deepin.dde.ControlCenter1.service.in
${CMAKE_CURRENT_BINARY_DIR}/org.deepin.dde.ControlCenter1.service
@ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.deepin.dde.ControlCenter1.service
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.deepin.dde.ControlCenter1.service
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services)

# dev files
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ PACK_VER = $(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$1}')
%:
dh $@ --parallel
override_dh_auto_configure:
dh_auto_configure -- -DCVERSION=$(DEB_VERSION_UPSTREAM) -DDVERSION=$(PACK_VER)
dh_auto_configure -- -DCVERSION=$(DEB_VERSION_UPSTREAM) -DDVERSION=$(PACK_VER) -DUSE_DEEPIN_ZONE=ON

5 changes: 3 additions & 2 deletions src/plugin-datetime/operation/datetimedbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ bool DatetimeDBusProxy::GetZoneInfo(const QString &zone, QObject *receiver, cons
argumentList << QVariant::fromValue(zone);
return m_timedateInter->callWithCallback(QStringLiteral("GetZoneInfo"), argumentList, receiver, member);
}

// System Timedate
void DatetimeDBusProxy::SetTimezone(const QString &timezone, const QString &message)
void DatetimeDBusProxy::SetTimezone(const QString &timezone)
{
m_systemtimedatedInter->asyncCall(QStringLiteral("SetTimezone"), timezone, message);
m_timedateInter->asyncCall(QStringLiteral("SetTimezone"), timezone);
}

void DatetimeDBusProxy::SetNTPServer(const QString &server, const QString &message)
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-datetime/operation/datetimedbusproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Q_SLOTS:
ZoneInfo GetZoneInfo(const QString &zone);
bool GetZoneInfo(const QString &zone, QObject *receiver, const char *member);
// System Timedate
void SetTimezone(const QString &timezone, const QString &message);
void SetTimezone(const QString &timezone);
void SetNTPServer(const QString &server, const QString &message);
void SetNTPServer(const QString &server,
const QString &message,
Expand Down
4 changes: 2 additions & 2 deletions src/plugin-datetime/operation/datetimeworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DatetimeWorker::DatetimeWorker(DatetimeModel *model, QObject *parent)
connect(m_timedateInter, &DatetimeDBusProxy::TimezoneChanged, m_model, &DatetimeModel::setTimeZoneInfo);

m_model->setCurrentTimeZone(GetZoneInfo(QTimeZone::systemTimeZoneId()));
m_model->setCurrentUseTimeZone(GetZoneInfo(QTimeZone::systemTimeZoneId()));
m_model->setCurrentUseTimeZone(GetZoneInfo(m_timedateInter->timezone()));
m_model->set24HourFormat(m_timedateInter->use24HourFormat());

refreshNtpServerList();
Expand Down Expand Up @@ -116,7 +116,7 @@ void DatetimeWorker::set24HourType(bool state)
#ifndef DCC_DISABLE_TIMEZONE
void DatetimeWorker::setTimezone(const QString &timezone)
{
m_timedateInter->SetTimezone(timezone, tr("Authentication is required to set the system timezone"));
m_timedateInter->SetTimezone(timezone);
}

void DatetimeWorker::removeUserTimeZone(const ZoneInfo &info)
Expand Down
16 changes: 15 additions & 1 deletion src/plugin-datetime/window/widgets/timezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ const QString tzDirPath = std::visit([] {
return tzDirPath;
});

#if USE_DEEPIN_ZONE
const QString kZoneTabFileDeepin = QStringLiteral(DEEPIN_TIME_ZONE_PATH);
const QString kZoneTabFile = std::visit([] {
if (QFile(kZoneTabFileDeepin).exists()) {
return kZoneTabFileDeepin;
}
return tzDirPath + "/zone1970.tab";
});
#else
// Absolute path to zone.tab file.
const QString kZoneTabFile = std::visit([] {
return tzDirPath + "/zone1970.tab";
});
#endif

// Absolute path to backward timezone file.
const char kTimezoneAliasFile[] = "/timezone_alias";
Expand Down Expand Up @@ -179,7 +189,11 @@ QString GetLocalTimezoneName(const QString &timezone, const QString &locale)
if (timezone.isEmpty()) {
return false;
}

#if USE_DEEPIN_ZONE
if (kZoneTabFile == kZoneTabFileDeepin && QFile(kZoneTabFile).exists()) {
return true;
}
#endif
// If |filepath| is a file or a symbolic link to file, it is a valid timezone.
const QString filepath(tzDirPath + QDir::separator() + timezone);
return QFile::exists(filepath);
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-datetime/window/widgets/timezone_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool TimezoneMap::setTimezone(const QString &timezone)
return true;
} else {
// NOTE(xushaohua): "Etc/UTC" can not be set on the map
qWarning() << "Timezone not found:" << timezone;
qInfo() << "Timezone not found:" << timezone;
}

return false;
Expand Down