sfx2/source/doc/docfile.cxx |   39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

New commits:
commit b1f25771fd7e5671f081bcb80ed58e8678f3105f
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Oct 20 19:52:07 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Oct 21 17:22:45 2022 +0200

    sfx2: avoid showing 2 dialogs in case WebDAV LOCK request fails
    
    ... with 403 error code, which typically indicates read-only; one dialog
    is enough - also for the initial load of the document.
    
    (cherry picked from commit 855d62fc841abc62e0eca079e9b30f9d0888a93f)
    
    There is an Infobar anyway that the user can click to try again to
    edit the document, and if that fails there will be a dialog that offers
    opening a copy.
    
    If opening a file:// document writable fails and it is opened read-only,
    there is also no extra error dialog, just the Infobar, so this is making
    WebDAV more consistent.
    
    Change-Id: Ice62d167199f384b246b9d60dab4eed456a62288
    (cherry picked from commit 48fa1f49d97ce04c9d3749ae02b2874af6477e82)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141620
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index a0f789884d4c..2f773fca6e62 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -52,6 +52,7 @@
 #include <com/sun/star/ucb/CommandFailedException.hpp>
 #include <com/sun/star/ucb/CommandAbortedException.hpp>
 #include <com/sun/star/ucb/InteractiveLockingLockedException.hpp>
+#include <com/sun/star/ucb/InteractiveNetworkReadException.hpp>
 #include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp>
 #include <com/sun/star/ucb/Lock.hpp>
 #include <com/sun/star/ucb/NameClashException.hpp>
@@ -1243,6 +1244,37 @@ namespace
     }
 }
 
+namespace
+{
+
+// for LOCK request, suppress dialog on 403, typically indicates read-only
+// document and there's a 2nd dialog prompting to open a copy anyway
+class LockInteractionHandler : public 
::cppu::WeakImplHelper<task::XInteractionHandler>
+{
+private:
+    uno::Reference<task::XInteractionHandler> m_xHandler;
+
+public:
+    explicit LockInteractionHandler(uno::Reference<task::XInteractionHandler> 
const& xHandler)
+        : m_xHandler(xHandler)
+    {
+    }
+
+    virtual void SAL_CALL handle(uno::Reference<task::XInteractionRequest> 
const& xRequest) override
+    {
+        ucb::InteractiveNetworkWriteException readException;
+        ucb::InteractiveNetworkReadException writeException;
+        if ((xRequest->getRequest() >>= readException)
+            || (xRequest->getRequest() >>= writeException))
+        {
+            return; // 403 gets reported as one of these; ignore to avoid 
dialog
+        }
+        m_xHandler->handle(xRequest);
+    }
+};
+
+} // namespace
+
 #endif // HAVE_FEATURE_MULTIUSER_ENVIRONMENT
 
 // sets SID_DOC_READONLY if the document cannot be opened for editing
@@ -1289,6 +1321,13 @@ SfxMedium::LockFileResult 
SfxMedium::LockOrigFileOnDemand(bool bLoading, bool bN
                     if( !bResult )
                     {
                         uno::Reference< task::XInteractionHandler > xCHandler 
= GetInteractionHandler( true );
+                        // Dialog with error is superfluous:
+                        // on loading, will result in read-only with infobar.
+                        // bNoUI case for Reload failing, will open dialog 
later.
+                        if (bLoading || bNoUI)
+                        {
+                            xCHandler = new LockInteractionHandler(xCHandler);
+                        }
                         Reference< css::ucb::XCommandEnvironment > xComEnv = 
new ::ucbhelper::CommandEnvironment(
                             xCHandler, Reference< css::ucb::XProgressHandler 
>() );
 

Reply via email to