diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2022-12-23 13:02:57 -0500 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-01-29 13:22:28 +0000 |
commit | e2d646665c4cb4c7eeb0a73cb5f460838589bef0 (patch) | |
tree | 42987bdec2a8e09af3b6cf70ad2b244c01d92136 /desktop | |
parent | e3e259d551c0c8b7c106191f2c258e5929db1b29 (diff) |
lok: support per-user timezone
This adds support for user-specific timezone.
When none is provided during loading, the
system default is used.
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Change-Id: Ie863450687eb82bc475268a09c9112e9fd50020f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144816
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
(cherry picked from commit abaf8c0af1c6c7fe01276fdf2ae62419c7b0f654)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146211
Tested-by: Jenkins
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 4 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 49 |
2 files changed, 52 insertions, 1 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 98c734c8190a..a5560dd6be8d 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3629,10 +3629,12 @@ void DesktopLOKTest::testABI() CPPUNIT_ASSERT_EQUAL(documentClassOffset(65), offsetof(struct _LibreOfficeKitDocumentClass, getSelectionTypeAndText)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(66), offsetof(struct _LibreOfficeKitDocumentClass, getDataArea)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(67), offsetof(struct _LibreOfficeKitDocumentClass, getEditMode)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(68), + offsetof(struct _LibreOfficeKitDocumentClass, setViewTimezone)); // Extending is fine, update this, and add new assert for the offsetof the // new method - CPPUNIT_ASSERT_EQUAL(documentClassOffset(68), sizeof(struct _LibreOfficeKitDocumentClass)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(69), sizeof(struct _LibreOfficeKitDocumentClass)); } CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 97d74bc4682d..db9a9632e4c3 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <sfx2/lokhelper.hxx> #include <config_buildconfig.h> #include <config_features.h> @@ -1203,6 +1204,8 @@ static bool doc_renderSearchResult(LibreOfficeKitDocument* pThis, static void doc_sendContentControlEvent(LibreOfficeKitDocument* pThis, const char* pArguments); +static void doc_setViewTimezone(LibreOfficeKitDocument* pThis, int nId, const char* timezone); + } // extern "C" namespace { @@ -1353,6 +1356,8 @@ LibLODocument_Impl::LibLODocument_Impl(uno::Reference <css::lang::XComponent> xC m_pDocumentClass->sendContentControlEvent = doc_sendContentControlEvent; + m_pDocumentClass->setViewTimezone = doc_setViewTimezone; + gDocumentClass = m_pDocumentClass; } pClass = m_pDocumentClass.get(); @@ -2600,6 +2605,27 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, SvNumberFormatter::resetTheCurrencyTable(); } + // Set the timezone, if not empty. + const OUString aTimezone = extractParameter(aOptions, u"Timezone"); + if (!aTimezone.isEmpty()) + { + SfxLokHelper::setDefaultTimezone(true, aTimezone); + } + else + { + // Default to the TZ envar, if set. + const char* tz = ::getenv("TZ"); + if (tz) + { + SfxLokHelper::setDefaultTimezone(true, + OStringToOUString(tz, RTL_TEXTENCODING_UTF8)); + } + else + { + SfxLokHelper::setDefaultTimezone(false, OUString()); + } + } + const OUString aDeviceFormFactor = extractParameter(aOptions, u"DeviceFormFactor"); SfxLokHelper::setDeviceFormFactor(aDeviceFormFactor); @@ -6598,6 +6624,22 @@ static void doc_sendContentControlEvent(LibreOfficeKitDocument* pThis, const cha pDoc->executeContentControlEvent(aMap); } +static void doc_setViewTimezone(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis*/, int nId, + const char* pTimezone) +{ + comphelper::ProfileZone aZone("doc_setViewTimezone"); + + SolarMutexGuard aGuard; + SetLastExceptionMsg(); + + // Leave the default if we get a null timezone. + if (pTimezone) + { + OUString sTimezone = OStringToOUString(pTimezone, RTL_TEXTENCODING_UTF8); + SfxLokHelper::setViewTimezone(nId, true, sTimezone); + } +} + static char* lo_getError (LibreOfficeKit *pThis) { comphelper::ProfileZone aZone("lo_getError"); @@ -7065,8 +7107,15 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char comphelper::ProfileZone aZone("lok-init"); if (eStage == PRE_INIT) + { rtl_alloc_preInit(true); + // Set the default timezone to the TZ envar, if set. + const char* tz = ::getenv("TZ"); + SfxLokHelper::setDefaultTimezone(!!tz, tz ? OStringToOUString(tz, RTL_TEXTENCODING_UTF8) + : OUString()); + } + if (eStage != SECOND_INIT) comphelper::LibreOfficeKit::setActive(); |