desktop/source/lib/init.cxx | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
New commits: commit 4fcaf961e243fb0f03e42df380d9843ed2f2080c Author: Pranam Lashkari <lpra...@collabora.com> AuthorDate: Wed Apr 3 00:08:45 2024 +0530 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Apr 3 14:26:01 2024 +0200 LOK: set creation date when online creates file from template problem: when online created file using WOPI clients, creation dates were never set. in online files are created using templates, even empty files are created using an empty template Change-Id: I3f022427745de7204faac9418620e2a87f9cf684 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165705 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index bfe4ff5fd699..2c4fba114092 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -3382,6 +3382,19 @@ static void lo_registerCallback (LibreOfficeKit* pThis, pApp->m_pCallbackData = pLib->mpCallbackData = pData; } +static SfxObjectShell* getSfxObjectShell(LibreOfficeKitDocument* pThis) +{ + LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); + if (!pDocument) + return nullptr; + + SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(pDocument->mxComponent.get()); + if (!pBaseModel) + return nullptr; + + return pBaseModel->GetObjectShell(); +} + static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const char* pFormat, const char* pFilterOptions) { comphelper::ProfileZone aZone("doc_saveAs"); @@ -3531,6 +3544,7 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha const uno::Sequence<OUString> aOptionSeq = comphelper::string::convertCommaSeparated(aFilterOptions); std::vector<OUString> aFilteredOptionVec; bool bTakeOwnership = false; + bool bCreateFromTemplate = false; MediaDescriptor aSaveMediaDescriptor; for (const auto& rOption : aOptionSeq) { @@ -3538,10 +3552,21 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha bTakeOwnership = true; else if (rOption == "NoFileSync") aSaveMediaDescriptor[u"NoFileSync"_ustr] <<= true; + else if (rOption == "FromTemplate") + bCreateFromTemplate = true; else aFilteredOptionVec.push_back(rOption); } + if (bCreateFromTemplate && bTakeOwnership) + { + if (SfxObjectShell* pObjectShell = getSfxObjectShell(pThis)) + { + DateTime now( ::DateTime::SYSTEM ); + pObjectShell->getDocProperties()->setCreationDate(now.GetUNODateTime()); + } + } + aSaveMediaDescriptor[u"Overwrite"_ustr] <<= true; aSaveMediaDescriptor[u"FilterName"_ustr] <<= aFilterName; @@ -5931,15 +5956,7 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis) static char* getDocReadOnly(LibreOfficeKitDocument* pThis) { - LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); - if (!pDocument) - return nullptr; - - SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(pDocument->mxComponent.get()); - if (!pBaseModel) - return nullptr; - - SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + SfxObjectShell* pObjectShell = getSfxObjectShell(pThis); if (!pObjectShell) return nullptr;