[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3-desktop' - sfx2/source uui/source

Mike Kaganski mike.kaganski at collabora.com
Mon Mar 12 14:44:43 UTC 2018


 sfx2/source/doc/docfile.cxx   |   51 ++++++++++++++++++++++++++++++------------
 uui/source/iahndl-locking.cxx |    3 +-
 uui/source/ids.hrc            |   35 ++++++++++++++--------------
 uui/source/trylater.cxx       |   29 ++++++++++++++++++-----
 uui/source/trylater.hxx       |    2 -
 uui/source/trylater.src       |    4 +++
 6 files changed, 84 insertions(+), 40 deletions(-)

New commits:
commit ea0a6c66e8ae2002953a458c1a8cc8fd54ccc297
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Wed Feb 21 00:45:04 2018 +0300

    tdf#115742: allow ignoring stale lockfile on save
    
    This change reuses TryLaterQueryBox, but only uses the new option to
    ignore the lock and save. Other options ("Try Again" and "Save As")
    are not used, because this functionality is not implemented currently
    (TODO/LATER).
    
    Change-Id: Idf825be23cf97d2b338c0cf5d532f8460843bf48
    Reviewed-on: https://gerrit.libreoffice.org/50371
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/51149
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index a7b8af14c13a..b80374fa39f7 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -29,6 +29,7 @@
 #include <com/sun/star/container/XChild.hpp>
 #include <com/sun/star/document/XDocumentRevisionListPersistence.hpp>
 #include <com/sun/star/document/LockedDocumentRequest.hpp>
+#include <com/sun/star/document/LockedOnSavingRequest.hpp>
 #include <com/sun/star/document/OwnLockOnDocumentRequest.hpp>
 #include <com/sun/star/document/LockFileIgnoreRequest.hpp>
 #include <com/sun/star/document/LockFileCorruptRequest.hpp>
@@ -67,6 +68,7 @@
 #include <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/security/DocumentSignatureInformation.hpp>
 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
+#include <o3tl/make_unique.hxx>
 #include <tools/urlobj.hxx>
 #include <unotools/configmgr.hxx>
 #include <unotools/tempfile.hxx>
@@ -858,7 +860,7 @@ SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEnt
     // show the interaction regarding the document opening
     uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler();
 
-    if ( ::svt::DocumentLockFile::IsInteractionAllowed() && xHandler.is() && ( bIsLoading || bOwnLock ) )
+    if ( ::svt::DocumentLockFile::IsInteractionAllowed() && xHandler.is() && ( bIsLoading || !bHandleSysLocked || bOwnLock ) )
     {
         OUString aDocumentURL = GetURLObject().GetLastName();
         OUString aInfo;
@@ -873,27 +875,32 @@ SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEnt
             xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
                 document::OwnLockOnDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo, !bIsLoading ) ) );
         }
-        else /*logically therefore bIsLoading is set */
+        else
         {
+            // Use a fourth continuation in case there's no filesystem lock:
+            // "Ignore lock file and open/replace the document"
+            if (!bHandleSysLocked)
+                nContinuations = 4;
+
             if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
                 aInfo = aData[LockFileComponent::OOOUSERNAME];
             else
                 aInfo = aData[LockFileComponent::SYSUSERNAME];
 
             if ( !aInfo.isEmpty() && !aData[LockFileComponent::EDITTIME].isEmpty() )
+                aInfo += " ( " + aData[LockFileComponent::EDITTIME] + " )";
+
+            if (!bIsLoading) // so, !bHandleSysLocked
             {
-                aInfo +=  " ( " ;
-                aInfo += aData[LockFileComponent::EDITTIME];
-                aInfo += " )";
+                xInteractionRequestImpl = new ::ucbhelper::InteractionRequest(uno::makeAny(
+                    document::LockedOnSavingRequest(OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo)));
+                // Currently, only the last "Retry" continuation (meaning ignore the lock and try overwriting) can be returned.
+            }
+            else /*logically therefore bIsLoading is set */
+            {
+                xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
+                    document::LockedDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) );
             }
-
-            xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
-                document::LockedDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) );
-
-            // Use a fourth continuation in case there's no filesystem lock:
-            // "Ignore lock file and open the document"
-            if (!bHandleSysLocked)
-                nContinuations = 4;
         }
 
         uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations(nContinuations);
@@ -903,7 +910,7 @@ SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEnt
         if (nContinuations > 3)
         {
             // We use InteractionRetry to reflect that user wants to
-            // ignore the (stale?) alien lock file and open the document
+            // ignore the (stale?) alien lock file and open/overwrite the document
             aContinuations[3] = new ::ucbhelper::InteractionRetry(xInteractionRequestImpl.get());
         }
         xInteractionRequestImpl->setContinuations( aContinuations );
@@ -1249,6 +1256,22 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b
                     // if system lock is used the writeable stream should be available
                     bool bHandleSysLocked = ( bLoading && bUseSystemLock && !pImpl->xStream.is() && !pImpl->m_pOutStream );
 
+                    // The file is attempted to get locked for the duration of lockfile creation on save
+                    std::unique_ptr<osl::File> pFileLock;
+                    if (!bLoading && bUseSystemLock && pImpl->pTempFile)
+                    {
+                        INetURLObject aDest(GetURLObject());
+                        OUString aDestURL(aDest.GetMainURL(INetURLObject::DecodeMechanism::NONE));
+
+                        if (comphelper::isFileUrl(aDestURL) || !aDest.removeSegment())
+                        {
+                            pFileLock = o3tl::make_unique<osl::File>(aDestURL);
+                            auto rc = pFileLock->open(osl_File_OpenFlag_Write);
+                            if (rc == osl::FileBase::E_ACCES)
+                                bHandleSysLocked = true;
+                        }
+                    }
+
                     do
                     {
                         try
diff --git a/uui/source/iahndl-locking.cxx b/uui/source/iahndl-locking.cxx
index d1c00706d769..f4a14ef9bc3f 100644
--- a/uui/source/iahndl-locking.cxx
+++ b/uui/source/iahndl-locking.cxx
@@ -111,7 +111,8 @@ handleLockedDocumentRequest_(
                                   ? aInfo
                                   : ResId( STR_UNKNOWNUSER,
                                                *xManager.get() ).toString() );
-            aMessage = ResId(STR_TRYLATER_MSG, *xManager.get()).toString();
+            aMessage = ResId(xRetry.is() ? STR_OVERWRITE_IGNORELOCK_MSG : STR_TRYLATER_MSG,
+                *xManager.get()).toString();
             aMessage = UUIInteractionHelper::replaceMessageWithArguments(
                 aMessage, aArguments );
 
diff --git a/uui/source/ids.hrc b/uui/source/ids.hrc
index d3f2a80f2d59..2d9f8128d683 100644
--- a/uui/source/ids.hrc
+++ b/uui/source/ids.hrc
@@ -54,24 +54,25 @@
 #define STR_LOCKCORRUPT_OPENREADONLY_BTN                (RID_UUI_START + 49)
 #define STR_TRYLATER_TITLE                              (RID_UUI_START + 50)
 #define STR_TRYLATER_MSG                                (RID_UUI_START + 51)
-#define STR_TRYLATER_RETRYSAVING_BTN                    (RID_UUI_START + 52)
-#define STR_TRYLATER_SAVEAS_BTN                         (RID_UUI_START + 53)
-#define STR_ALREADYOPEN_SAVE_MSG                        (RID_UUI_START + 54)
-#define STR_ALREADYOPEN_RETRY_SAVE_BTN                  (RID_UUI_START + 55)
-#define STR_ALREADYOPEN_SAVE_BTN                        (RID_UUI_START + 56)
+#define STR_OVERWRITE_IGNORELOCK_MSG                    (RID_UUI_START + 52)
+#define STR_TRYLATER_RETRYSAVING_BTN                    (RID_UUI_START + 53)
+#define STR_TRYLATER_SAVEAS_BTN                         (RID_UUI_START + 54)
+#define STR_ALREADYOPEN_SAVE_MSG                        (RID_UUI_START + 55)
+#define STR_ALREADYOPEN_RETRY_SAVE_BTN                  (RID_UUI_START + 56)
+#define STR_ALREADYOPEN_SAVE_BTN                        (RID_UUI_START + 57)
 
-#define STR_WARNING_INCOMPLETE_ENCRYPTION_TITLE         (RID_UUI_START + 57)
-#define STR_WARNING_BROKENSIGNATURE_TITLE               (RID_UUI_START + 58)
-#define STR_ENTER_PASSWORD_TO_OPEN                      (RID_UUI_START + 59)
-#define STR_ENTER_PASSWORD_TO_MODIFY                    (RID_UUI_START + 60)
-#define STR_RENAME_OR_REPLACE                           (RID_UUI_START + 61)
-#define STR_NAME_CLASH_RENAME_ONLY                      (RID_UUI_START + 62)
-#define STR_SAME_NAME_USED                              (RID_UUI_START + 63)
-#define STR_ENTER_SIMPLE_PASSWORD                       (RID_UUI_START + 64)
-#define STR_CONFIRM_SIMPLE_PASSWORD                     (RID_UUI_START + 65)
-#define STR_TITLE_CREATE_PASSWORD                       (RID_UUI_START + 66)
-#define STR_TITLE_ENTER_PASSWORD                        (RID_UUI_START + 67)
-#define STR_PASSWORD_MISMATCH                           (RID_UUI_START + 68)
+#define STR_WARNING_INCOMPLETE_ENCRYPTION_TITLE         (RID_UUI_START + 58)
+#define STR_WARNING_BROKENSIGNATURE_TITLE               (RID_UUI_START + 59)
+#define STR_ENTER_PASSWORD_TO_OPEN                      (RID_UUI_START + 60)
+#define STR_ENTER_PASSWORD_TO_MODIFY                    (RID_UUI_START + 61)
+#define STR_RENAME_OR_REPLACE                           (RID_UUI_START + 62)
+#define STR_NAME_CLASH_RENAME_ONLY                      (RID_UUI_START + 63)
+#define STR_SAME_NAME_USED                              (RID_UUI_START + 64)
+#define STR_ENTER_SIMPLE_PASSWORD                       (RID_UUI_START + 65)
+#define STR_CONFIRM_SIMPLE_PASSWORD                     (RID_UUI_START + 66)
+#define STR_TITLE_CREATE_PASSWORD                       (RID_UUI_START + 67)
+#define STR_TITLE_ENTER_PASSWORD                        (RID_UUI_START + 68)
+#define STR_PASSWORD_MISMATCH                           (RID_UUI_START + 69)
 
 #define ERRCODE_UUI_IO_ABORT                                    (ERRCODE_AREA_UUI + 0)
 #define ERRCODE_UUI_IO_ACCESSDENIED                             (ERRCODE_AREA_UUI + 1)
diff --git a/uui/source/trylater.cxx b/uui/source/trylater.cxx
index 90688a95e2a3..52c9a9de2a90 100644
--- a/uui/source/trylater.cxx
+++ b/uui/source/trylater.cxx
@@ -20,20 +20,35 @@
 #include "ids.hrc"
 #include "trylater.hxx"
 
-TryLaterQueryBox::TryLaterQueryBox( vcl::Window* pParent, ResMgr* pResMgr, const OUString& aMessage ) :
+TryLaterQueryBox::TryLaterQueryBox( vcl::Window* pParent, ResMgr* pResMgr, const OUString& aMessage, bool bEnableOverride ) :
     MessBox(pParent, 0,
             ResId(STR_TRYLATER_TITLE, *pResMgr).toString(),
             aMessage )
 {
     SetImage( QueryBox::GetStandardImage() );
 
-    AddButton(ResId(STR_TRYLATER_RETRYSAVING_BTN, *pResMgr).toString(), RET_YES,
-            ButtonDialogFlags::Default | ButtonDialogFlags::OK | ButtonDialogFlags::Focus);
-    AddButton(ResId(STR_TRYLATER_SAVEAS_BTN, *pResMgr).toString(), RET_NO);
-    AddButton( StandardButtonType::Cancel, RET_CANCEL, ButtonDialogFlags::Cancel );
+    // Currently we don't have the retry/save-as functionality implemented for cases when file is locked.
+    // So threat them mutually exclusive with overwrite here. TODO/LATER: just add the overwrite option
+    // as third option when retrying and saving with another name would be possible along with overwriting
+    if (bEnableOverride)
+    {
+        AddButton(ResId(STR_FILECHANGED_SAVEANYWAY_BTN, *pResMgr).toString(), RET_IGNORE,
+            ButtonDialogFlags::OK);
+        AddButton(StandardButtonType::Cancel, RET_CANCEL,
+            ButtonDialogFlags::Default | ButtonDialogFlags::Cancel | ButtonDialogFlags::Focus);
 
-    SetButtonHelpText( RET_YES, OUString() );
-    SetButtonHelpText( RET_NO, OUString() );
+        SetButtonHelpText(RET_IGNORE, OUString());
+    }
+    else
+    {
+        AddButton(ResId(STR_TRYLATER_RETRYSAVING_BTN, *pResMgr).toString(), RET_YES,
+                ButtonDialogFlags::Default | ButtonDialogFlags::OK | ButtonDialogFlags::Focus);
+        AddButton(ResId(STR_TRYLATER_SAVEAS_BTN, *pResMgr).toString(), RET_NO);
+        AddButton( StandardButtonType::Cancel, RET_CANCEL, ButtonDialogFlags::Cancel );
+
+        SetButtonHelpText( RET_YES, OUString() );
+        SetButtonHelpText( RET_NO, OUString() );
+    }
 }
 
 TryLaterQueryBox::~TryLaterQueryBox()
diff --git a/uui/source/trylater.hxx b/uui/source/trylater.hxx
index 961cbe5f3a14..053a6638d4a3 100644
--- a/uui/source/trylater.hxx
+++ b/uui/source/trylater.hxx
@@ -24,7 +24,7 @@
 class TryLaterQueryBox : public MessBox
 {
 public:
-    TryLaterQueryBox( vcl::Window* pParent, ResMgr* pResMgr, const OUString& aMessage );
+    TryLaterQueryBox( vcl::Window* pParent, ResMgr* pResMgr, const OUString& aMessage, bool bEnableOverride );
     virtual ~TryLaterQueryBox() override;
 };
 
diff --git a/uui/source/trylater.src b/uui/source/trylater.src
index 4459c1530c74..dc556e40e741 100644
--- a/uui/source/trylater.src
+++ b/uui/source/trylater.src
@@ -29,6 +29,10 @@ String STR_TRYLATER_MSG
 {
     Text [ en-US ] = "Document file '$(ARG1)' is locked for editing by:\n\n$(ARG2)\n\nTry again later to save document or save a copy of that document.\n\n";
 };
+String STR_OVERWRITE_IGNORELOCK_MSG
+{
+    Text [ en-US ] = "Document file '$(ARG1)' is locked for editing by:\n\n$(ARG2)\n\nYou may try to ignore the file locking and overwrite the existing document.\n\n";
+};
 String STR_TRYLATER_RETRYSAVING_BTN
 {
     Text [ en-US ] = "~Retry Saving";


More information about the Libreoffice-commits mailing list