Kaydet (Commit) 41dc917b authored tarafından Tamás Zolnai's avatar Tamás Zolnai

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: 's avatarTamás Zolnai <tamas.zolnai@collabora.com>
üst cd19a766
......@@ -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 )
......
......@@ -88,6 +88,7 @@ class OfaMSFilterTabPage2 : public SfxTabPage
VclPtr<RadioButton> aHighlightingRB;
VclPtr<RadioButton> aShadingRB;
VclPtr<CheckBox> aMSOLockFileCB;
virtual ~OfaMSFilterTabPage2() override;
virtual void dispose() override;
......
<?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>
......
......@@ -68,7 +68,7 @@ public:
static OUString GetCurrentLocalTime();
static LockFileEntry GenerateOwnEntry();
INetURLObject ResolveLinks( const INetURLObject& aDocURL ) const;
static INetURLObject ResolveLinks( const INetURLObject& aDocURL );
};
}
......
......@@ -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);
};
}
......
......@@ -91,6 +91,9 @@ public:
void SetCharBackground2Highlighting();
void SetCharBackground2Shading();
bool IsMSOLockFileCreationIsEnabled() const;
void EnableMSOLockFileCreation(bool bEnable);
static SvtFilterOptions& Get();
};
......
......@@ -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>
......
......@@ -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
}
......
......@@ -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();
}
......
......@@ -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();
......
......@@ -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: */
......@@ -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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment