[Libreoffice-commits] core.git: cui/source cui/uiconfig include/svl include/unotools officecfg/registry sfx2/source svl/qa svl/source unotools/source

Tamás Zolnai (via logerrit) logerrit at kemper.freedesktop.org
Tue Mar 26 18:10:15 UTC 2019


 cui/source/options/optfltr.cxx                             |   10 ++
 cui/source/options/optfltr.hxx                             |    1 
 cui/uiconfig/ui/optfltrembedpage.ui                        |   63 +++++++++++--
 include/svl/lockfilecommon.hxx                             |    2 
 include/svl/msodocumentlockfile.hxx                        |    8 +
 include/unotools/fltrcfg.hxx                               |    3 
 officecfg/registry/schema/org/openoffice/Office/Common.xcs |    8 +
 sfx2/source/doc/docfile.cxx                                |   46 +++++++++
 svl/qa/unit/lockfiles/test_lockfiles.cxx                   |    2 
 svl/source/misc/lockfilecommon.cxx                         |    2 
 svl/source/misc/msodocumentlockfile.cxx                    |   19 ++-
 unotools/source/config/fltrcfg.cxx                         |   25 ++++-
 12 files changed, 165 insertions(+), 24 deletions(-)

New commits:
commit 41dc917b9b55b8c0c4307ffc58a1fb7257df2b69
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Mon Mar 25 13:28:27 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Tue Mar 26 19:09:46 2019 +0100

    Generate MSO lock files when the related MSO compat. option is set
    
    Added a new compatibility option to the Tools -> Load / Save ->
    Microsoft.
    When this option is set on the UI or or set in the configuration files
    LO generates lock files for MSO supported file formats, similar to
    the lock files MSO generates itself.
    
    Change-Id: I2f882723841162add01be9d3f7285a5162a60331
    Reviewed-on: https://gerrit.libreoffice.org/69678
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/cui/source/options/optfltr.cxx b/cui/source/options/optfltr.cxx
index e70bdef191b3..f29c14c78837 100644
--- a/cui/source/options/optfltr.cxx
+++ b/cui/source/options/optfltr.cxx
@@ -153,6 +153,7 @@ OfaMSFilterTabPage2::OfaMSFilterTabPage2( vcl::Window* pParent, const SfxItemSet
 
     get( aHighlightingRB, "highlighting");
     get( aShadingRB,      "shading"     );
+    get( aMSOLockFileCB,  "mso_lockfile");
 
     Size aControlSize(248, 55);
     aControlSize = LogicToPixel(aControlSize, MapMode(MapUnit::MapAppFont));
@@ -183,6 +184,7 @@ void OfaMSFilterTabPage2::dispose()
     m_pCheckLBContainer.clear();
     aHighlightingRB.clear();
     aShadingRB.clear();
+    aMSOLockFileCB.clear();
 
     SfxTabPage::dispose();
 }
@@ -252,6 +254,11 @@ bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* )
             rOpt.SetCharBackground2Shading();
     }
 
+    if( aMSOLockFileCB->IsValueChangedFromSaved() )
+    {
+        rOpt.EnableMSOLockFileCreation(aMSOLockFileCB->IsChecked());
+    }
+
     return true;
 }
 
@@ -318,6 +325,9 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* )
         aShadingRB->Check();
 
     aHighlightingRB->SaveValue();
+
+    aMSOLockFileCB->Check(rOpt.IsMSOLockFileCreationIsEnabled());
+    aMSOLockFileCB->SaveValue();
 }
 
 void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, MSFltrPg2_CheckBoxEntries _nType )
diff --git a/cui/source/options/optfltr.hxx b/cui/source/options/optfltr.hxx
index 9183532e1225..54f00c7b99d1 100644
--- a/cui/source/options/optfltr.hxx
+++ b/cui/source/options/optfltr.hxx
@@ -88,6 +88,7 @@ class OfaMSFilterTabPage2 : public SfxTabPage
 
     VclPtr<RadioButton> aHighlightingRB;
     VclPtr<RadioButton> aShadingRB;
+    VclPtr<CheckBox>    aMSOLockFileCB;
 
     virtual ~OfaMSFilterTabPage2() override;
     virtual void dispose() override;
diff --git a/cui/uiconfig/ui/optfltrembedpage.ui b/cui/uiconfig/ui/optfltrembedpage.ui
index 0e65b6cdce69..df931247be30 100644
--- a/cui/uiconfig/ui/optfltrembedpage.ui
+++ b/cui/uiconfig/ui/optfltrembedpage.ui
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.4 -->
 <interface domain="cui">
   <requires lib="gtk+" version="3.18"/>
   <requires lib="LibreOffice" version="1.0"/>
@@ -48,8 +49,8 @@
                   <object class="GtkLabel" id="label2">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
                     <property name="label" translatable="yes" context="optfltrembedpage|label2">[L]: Load and convert the object</property>
+                    <property name="xalign">0</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -61,8 +62,8 @@
                   <object class="GtkLabel" id="label3">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
                     <property name="label" translatable="yes" context="optfltrembedpage|label3">[S]: Convert and save the object</property>
+                    <property name="xalign">0</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -88,8 +89,6 @@
       <packing>
         <property name="left_attach">0</property>
         <property name="top_attach">0</property>
-        <property name="width">1</property>
-        <property name="height">1</property>
       </packing>
     </child>
     <child>
@@ -184,8 +183,60 @@
       <packing>
         <property name="left_attach">0</property>
         <property name="top_attach">1</property>
-        <property name="width">1</property>
-        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkFrame" id="frame3">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label_xalign">0</property>
+        <property name="shadow_type">none</property>
+        <child>
+          <object class="GtkAlignment" id="alignment3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="top_padding">6</property>
+            <property name="left_padding">12</property>
+            <child>
+              <object class="GtkButtonBox" id="buttonbox2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="layout_style">start</property>
+                <child>
+                  <object class="GtkCheckButton" id="mso_lockfile">
+                    <property name="label" translatable="yes" context="optfltrembedpage|mso_lockfile">Create MSO lock file</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="xalign">0</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child type="label">
+          <object class="GtkLabel" id="label6">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes" context="optfltrembedpage|label5">Lock files</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">2</property>
       </packing>
     </child>
   </object>
diff --git a/include/svl/lockfilecommon.hxx b/include/svl/lockfilecommon.hxx
index e99ed64d7f36..97210d010279 100644
--- a/include/svl/lockfilecommon.hxx
+++ b/include/svl/lockfilecommon.hxx
@@ -68,7 +68,7 @@ public:
     static OUString GetCurrentLocalTime();
     static LockFileEntry GenerateOwnEntry();
 
-    INetURLObject ResolveLinks( const INetURLObject& aDocURL ) const;
+    static INetURLObject ResolveLinks( const INetURLObject& aDocURL );
 };
 
 }
diff --git a/include/svl/msodocumentlockfile.hxx b/include/svl/msodocumentlockfile.hxx
index 5a6753389370..7deed847669f 100644
--- a/include/svl/msodocumentlockfile.hxx
+++ b/include/svl/msodocumentlockfile.hxx
@@ -55,9 +55,9 @@ class SVL_DLLPUBLIC MSODocumentLockFile : public GenDocumentLockFile
 private:
     OUString m_sOrigURL;
 
-    bool isWordFormat(const OUString& aOrigURL) const;
-    bool isExcelFormat(const OUString& aOrigURL) const;
-    bool isPowerPointFormat(const OUString& aOrigURL) const;
+    static bool isWordFormat(const OUString& aOrigURL);
+    static bool isExcelFormat(const OUString& aOrigURL);
+    static bool isPowerPointFormat(const OUString& aOrigURL);
 
 protected:
     virtual void
@@ -74,6 +74,8 @@ public:
     virtual LockFileEntry GetLockData() override;
 
     virtual void RemoveFile() override;
+
+    static bool IsMSOSupportedFileFormat(const OUString& aURL);
 };
 }
 
diff --git a/include/unotools/fltrcfg.hxx b/include/unotools/fltrcfg.hxx
index ab0eb1364e81..bc5630cac444 100644
--- a/include/unotools/fltrcfg.hxx
+++ b/include/unotools/fltrcfg.hxx
@@ -91,6 +91,9 @@ public:
     void SetCharBackground2Highlighting();
     void SetCharBackground2Shading();
 
+    bool IsMSOLockFileCreationIsEnabled() const;
+    void EnableMSOLockFileCreation(bool bEnable);
+
     static SvtFilterOptions& Get();
 };
 
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 5179d366e919..191d92eebaa2 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -3827,6 +3827,14 @@
             </info>
             <value>true</value>
           </prop>
+          <prop oor:name="CreateMSOLockFiles" oor:type="xs:boolean" oor:nillable="false">
+            <info>
+              <desc>Specifies if LO should create MSO lock files next to the LO lock files
+              when openning a file. This makes MSO to be able to read the user name from
+              the lock file and show it for the user.</desc>
+            </info>
+            <value>false</value>
+          </prop>
         </group>
         <group oor:name="Export">
           <info>
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 167a52130c12..64e0523f8c60 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -115,6 +115,7 @@
 #include <sot/storage.hxx>
 #include <unotools/saveopt.hxx>
 #include <svl/documentlockfile.hxx>
+#include <svl/msodocumentlockfile.hxx>
 #include <com/sun/star/document/DocumentRevisionListPersistence.hpp>
 
 #include <helper.hxx>
@@ -132,6 +133,7 @@
 #include <vcl/weld.hxx>
 #include <vcl/svapp.hxx>
 #include <tools/diagnose_ex.h>
+#include <unotools/fltrcfg.hxx>
 
 #include <com/sun/star/io/WrongFormatException.hpp>
 
@@ -264,6 +266,7 @@ public:
     bool m_bSalvageMode:1;
     bool m_bVersionsAlreadyLoaded:1;
     bool m_bLocked:1;
+    bool m_bMSOLockFileCreated : 1;
     bool m_bDisableUnlockWebDAV:1;
     bool m_bGotDateTime:1;
     bool m_bRemoveBackup:1;
@@ -344,6 +347,7 @@ SfxMedium_Impl::SfxMedium_Impl() :
     m_bSalvageMode( false ),
     m_bVersionsAlreadyLoaded( false ),
     m_bLocked( false ),
+    m_bMSOLockFileCreated( false ),
     m_bDisableUnlockWebDAV( false ),
     m_bGotDateTime( false ),
     m_bRemoveBackup( false ),
@@ -1415,6 +1419,15 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b
                         try
                         {
                             ::svt::DocumentLockFile aLockFile( pImpl->m_aLogicName );
+
+                            std::unique_ptr<svt::MSODocumentLockFile> pMSOLockFile;
+                            const SvtFilterOptions& rOpt = SvtFilterOptions::Get();
+                            if (rOpt.IsMSOLockFileCreationIsEnabled() && svt::MSODocumentLockFile::IsMSOSupportedFileFormat(pImpl->m_aLogicName))
+                            {
+                                pMSOLockFile.reset(new svt::MSODocumentLockFile(pImpl->m_aLogicName));
+                                pImpl->m_bMSOLockFileCreated = true;
+                            }
+
                             bool  bIoErr = false;
 
                             if (!bHandleSysLocked)
@@ -1422,6 +1435,8 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b
                                 try
                                 {
                                     bResult = aLockFile.CreateOwnLockFile();
+                                    if(pMSOLockFile)
+                                        bResult &= pMSOLockFile->CreateOwnLockFile();
                                 }
                                 catch (const uno::Exception&)
                                 {
@@ -1446,6 +1461,9 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b
                                     bResult = true;
                                     // take the ownership over the lock file
                                     aLockFile.OverwriteOwnLockFile();
+
+                                    if(pMSOLockFile)
+                                        pMSOLockFile->OverwriteOwnLockFile();
                                 }
                             }
 
@@ -1500,6 +1518,9 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b
                                     {
                                         // take the ownership over the lock file
                                         bResult = aLockFile.OverwriteOwnLockFile();
+
+                                        if(pMSOLockFile)
+                                            pMSOLockFile->OverwriteOwnLockFile();
                                     }
                                     else if (bLoading && !bHandleSysLocked)
                                         eResult = LockFileResult::FailedLockFile;
@@ -3055,6 +3076,31 @@ void SfxMedium::UnlockFile( bool bReleaseLockStream )
     }
     catch( const uno::Exception& )
     {}
+
+    if(pImpl->m_bMSOLockFileCreated)
+    {
+        ::svt::MSODocumentLockFile aMSOLockFile( pImpl->m_aLogicName );
+
+        try
+        {
+            pImpl->m_bLocked = false;
+            // TODO/LATER: A warning could be shown in case the file is not the own one
+            aMSOLockFile.RemoveFile();
+        }
+        catch( const io::WrongFormatException& )
+        {
+            try
+            {
+                // erase the empty or corrupt file
+                aMSOLockFile.RemoveFileDirectly();
+            }
+            catch( const uno::Exception& )
+            {}
+        }
+        catch( const uno::Exception& )
+        {}
+        pImpl->m_bMSOLockFileCreated = false;
+    }
 #endif
 }
 
diff --git a/svl/qa/unit/lockfiles/test_lockfiles.cxx b/svl/qa/unit/lockfiles/test_lockfiles.cxx
index 8083c143f461..5f23240f387c 100644
--- a/svl/qa/unit/lockfiles/test_lockfiles.cxx
+++ b/svl/qa/unit/lockfiles/test_lockfiles.cxx
@@ -88,7 +88,7 @@ OUString readLockFile(const OUString& aSource)
 
 OUString GetLockFileName(const svt::GenDocumentLockFile& rLockFile)
 {
-    INetURLObject aDocURL = rLockFile.ResolveLinks(INetURLObject(rLockFile.GetURL()));
+    INetURLObject aDocURL = svt::LockFileCommon::ResolveLinks(INetURLObject(rLockFile.GetURL()));
     return aDocURL.GetName();
 }
 
diff --git a/svl/source/misc/lockfilecommon.cxx b/svl/source/misc/lockfilecommon.cxx
index 4b279c3c03e6..175220a532eb 100644
--- a/svl/source/misc/lockfilecommon.cxx
+++ b/svl/source/misc/lockfilecommon.cxx
@@ -94,7 +94,7 @@ OUString LockFileCommon::GenerateURL( const OUString& aOrigURL, const OUString&
 }
 
 
-INetURLObject LockFileCommon::ResolveLinks( const INetURLObject& aDocURL ) const
+INetURLObject LockFileCommon::ResolveLinks( const INetURLObject& aDocURL )
 {
     if ( aDocURL.HasError() )
         throw lang::IllegalArgumentException();
diff --git a/svl/source/misc/msodocumentlockfile.cxx b/svl/source/misc/msodocumentlockfile.cxx
index 8e2be6a9abe9..ddb5de6c5632 100644
--- a/svl/source/misc/msodocumentlockfile.cxx
+++ b/svl/source/misc/msodocumentlockfile.cxx
@@ -18,9 +18,9 @@
 
 namespace svt
 {
-bool MSODocumentLockFile::isWordFormat(const OUString& aOrigURL) const
+bool MSODocumentLockFile::isWordFormat(const OUString& aOrigURL)
 {
-    INetURLObject aDocURL = ResolveLinks(INetURLObject(aOrigURL));
+    INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
 
     return aDocURL.GetFileExtension().compareToIgnoreAsciiCase("DOC") == 0
            || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("DOCX") == 0
@@ -28,18 +28,18 @@ bool MSODocumentLockFile::isWordFormat(const OUString& aOrigURL) const
            || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("ODT") == 0;
 }
 
-bool MSODocumentLockFile::isExcelFormat(const OUString& aOrigURL) const
+bool MSODocumentLockFile::isExcelFormat(const OUString& aOrigURL)
 {
-    INetURLObject aDocURL = ResolveLinks(INetURLObject(aOrigURL));
+    INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
 
     return //aDocURL.GetFileExtension().compareToIgnoreAsciiCase("XLS") || // MSO does not create lockfile for XLS
         aDocURL.GetFileExtension().compareToIgnoreAsciiCase("XLSX") == 0
         || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("ODS") == 0;
 }
 
-bool MSODocumentLockFile::isPowerPointFormat(const OUString& aOrigURL) const
+bool MSODocumentLockFile::isPowerPointFormat(const OUString& aOrigURL)
 {
-    INetURLObject aDocURL = ResolveLinks(INetURLObject(aOrigURL));
+    INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
 
     return aDocURL.GetFileExtension().compareToIgnoreAsciiCase("PPTX") == 0
            || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("PPT") == 0
@@ -56,7 +56,7 @@ MSODocumentLockFile::~MSODocumentLockFile() {}
 
 OUString MSODocumentLockFile::GenerateURL(const OUString& aOrigURL, const OUString& aPrefix)
 {
-    INetURLObject aDocURL = ResolveLinks(INetURLObject(aOrigURL));
+    INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
     OUString aURL = aDocURL.GetPartBeforeLastName();
     aURL += aPrefix;
 
@@ -239,6 +239,11 @@ void MSODocumentLockFile::RemoveFile()
     RemoveFileDirectly();
 }
 
+bool MSODocumentLockFile::IsMSOSupportedFileFormat(const OUString& aURL)
+{
+    return isWordFormat(aURL) || isExcelFormat(aURL) || isPowerPointFormat(aURL);
+}
+
 } // namespace svt
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/unotools/source/config/fltrcfg.cxx b/unotools/source/config/fltrcfg.cxx
index 89b8374a761d..387f691a6a0b 100644
--- a/unotools/source/config/fltrcfg.cxx
+++ b/unotools/source/config/fltrcfg.cxx
@@ -25,6 +25,7 @@
 #include <tools/debug.hxx>
 #include <tools/solar.h>
 #include <osl/diagnose.h>
+#include <sal/log.hxx>
 
 #include <com/sun/star/uno/Sequence.hxx>
 
@@ -54,10 +55,11 @@ enum class ConfigFlags {
     UseEnhancedFields            = 0x0100000,
     WordWbctbl                   = 0x0200000,
     SmartArtShapeLoad            = 0x0400000,
-    CharBackgroundToHighlighting = 0x8000000
+    CharBackgroundToHighlighting = 0x8000000,
+    CreateMSOLockFiles           = 0x2000000
 };
 namespace o3tl {
-    template<> struct typed_flags<ConfigFlags> : is_typed_flags<ConfigFlags, 0x87fff3f> {};
+    template<> struct typed_flags<ConfigFlags> : is_typed_flags<ConfigFlags, 0xf7fff3f> {};
 }
 
 class SvtAppFilterOptions_Impl : public utl::ConfigItem
@@ -246,7 +248,8 @@ struct SvtFilterOptions_Impl
             ConfigFlags::ImpressSave |
             ConfigFlags::UseEnhancedFields |
             ConfigFlags::SmartArtShapeLoad |
-            ConfigFlags::CharBackgroundToHighlighting;
+            ConfigFlags::CharBackgroundToHighlighting|
+            ConfigFlags::CreateMSOLockFiles;
         Load();
     }
 
@@ -318,7 +321,8 @@ const Sequence<OUString>& GetPropertyNames()
             "Export/EnableWordPreview",         // 10
             "Import/ImportWWFieldsAsEnhancedFields", // 11
             "Import/SmartArtToShapes",          // 12
-            "Export/CharBackgroundToHighlighting"    // 13
+            "Export/CharBackgroundToHighlighting",   // 13
+            "Import/CreateMSOLockFiles"         // 14
     };
     return aNames;
 }
@@ -356,6 +360,7 @@ static ConfigFlags lcl_GetFlag(sal_Int32 nProp)
         case 11: nFlag = ConfigFlags::UseEnhancedFields; break;
         case 12: nFlag = ConfigFlags::SmartArtShapeLoad; break;
         case 13: nFlag = ConfigFlags::CharBackgroundToHighlighting; break;
+        case 14: nFlag = ConfigFlags::CreateMSOLockFiles; break;
 
         default: OSL_FAIL("illegal value");
     }
@@ -623,7 +628,6 @@ bool SvtFilterOptions::IsEnableWordPreview() const
     return pImpl->IsFlag( ConfigFlags::EnableWordPreview );
 }
 
-
 bool SvtFilterOptions::IsCharBackground2Highlighting() const
 {
     return pImpl->IsFlag( ConfigFlags::CharBackgroundToHighlighting );
@@ -646,4 +650,15 @@ void SvtFilterOptions::SetCharBackground2Shading()
     SetModified();
 }
 
+bool SvtFilterOptions::IsMSOLockFileCreationIsEnabled() const
+{
+    return pImpl->IsFlag( ConfigFlags::CreateMSOLockFiles );
+}
+
+void SvtFilterOptions::EnableMSOLockFileCreation(bool bEnable)
+{
+    pImpl->SetFlag( ConfigFlags::CreateMSOLockFiles, bEnable );
+    SetModified();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list