[Libreoffice-commits] core.git: Branch 'feature/cib_contract3756' - include/sfx2 offapi/com sfx2/source sw/qa
Serge Krot (via logerrit)
logerrit at kemper.freedesktop.org
Tue Nov 12 20:58:50 UTC 2019
include/sfx2/sfxsids.hrc | 3 ++-
include/sfx2/viewsh.hxx | 1 +
offapi/com/sun/star/document/MediaDescriptor.idl | 6 ++++++
offapi/com/sun/star/frame/XModel2.idl | 1 +
sfx2/source/appl/appuno.cxx | 18 ++++++++++++++++++
sfx2/source/doc/sfxbasemodel.cxx | 5 +++++
sfx2/source/view/viewfrm.cxx | 22 +++++++++++++++++-----
sfx2/source/view/viewsh.cxx | 9 +++++++++
sw/qa/python/check_xmodel.py | 4 +++-
9 files changed, 62 insertions(+), 7 deletions(-)
New commits:
commit 2c3a9d58bcb46dafe1901466861abdf24bab6744
Author: Serge Krot <Serge.Krot at cib.de>
AuthorDate: Tue Nov 12 21:52:05 2019 +0100
Commit: Serge Krot (CIB) <Serge.Krot at cib.de>
CommitDate: Tue Nov 12 21:57:53 2019 +0100
Add document level option to lock down edit doc command
Change-Id: I431fa4cd0daa52c885030dbadcc4052b5a890d34
Reviewed-on: https://gerrit.libreoffice.org/82553
Reviewed-by: Serge Krot (CIB) <Serge.Krot at cib.de>
Tested-by: Serge Krot (CIB) <Serge.Krot at cib.de>
diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index 2e1dbf6ff748..9fa90a5f6226 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -268,8 +268,9 @@ class SvxSearchItem;
#define SID_DIALOG_PARENT (SID_SFX_START + 1735)
#define SID_LOCK_PRINT (SID_SFX_START + 1736)
#define SID_LOCK_SAVE (SID_SFX_START + 1737)
+#define SID_LOCK_EDITDOC (SID_SFX_START + 1738)
-// SID_SFX_free_START (SID_SFX_START + 1738)
+// SID_SFX_free_START (SID_SFX_START + 1739)
// SID_SFX_free_END (SID_SFX_START + 3999)
#define SID_OPEN_NEW_VIEW (SID_SFX_START + 520)
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index a1a225aa1b28..d65fae656b16 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -292,6 +292,7 @@ public:
bool isExportLocked();
bool isPrintLocked();
bool isSaveLocked();
+ bool isEditDocLocked();
SAL_DLLPRIVATE SfxInPlaceClient* GetUIActiveIPClient_Impl() const;
SAL_DLLPRIVATE void AddContextMenuInterceptor_Impl( const css::uno::Reference < css::ui::XContextMenuInterceptor >& xInterceptor );
diff --git a/offapi/com/sun/star/document/MediaDescriptor.idl b/offapi/com/sun/star/document/MediaDescriptor.idl
index 72ee23fcd2ee..728ef4ab4a29 100644
--- a/offapi/com/sun/star/document/MediaDescriptor.idl
+++ b/offapi/com/sun/star/document/MediaDescriptor.idl
@@ -590,6 +590,12 @@ service MediaDescriptor
@since LibreOffice 6.4
*/
[optional,property] boolean LockSave;
+
+ /** Setting this option will disable switching to edit mode from read-only mode.
+ *
+ @since LibreOffice 6.4
+ */
+ [optional,property] boolean LockEditDoc;
};
diff --git a/offapi/com/sun/star/frame/XModel2.idl b/offapi/com/sun/star/frame/XModel2.idl
index bab2427a3617..b616d938e8ec 100644
--- a/offapi/com/sun/star/frame/XModel2.idl
+++ b/offapi/com/sun/star/frame/XModel2.idl
@@ -146,6 +146,7 @@ interface XModel2 : com::sun::star::frame::XModel
<li>com::sun::star::document::MediaDescriptor::LockExport</li>
<li>com::sun::star::document::MediaDescriptor::LockPrint</li>
<li>com::sun::star::document::MediaDescriptor::LockSave</li>
+ <li>com::sun::star::document::MediaDescriptor::LockEditDoc</li>
<li>com::sun::star::document::MediaDescriptor::EncryptionData</li>
</ul>
diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx
index c633978076d9..bfbe90dc896b 100644
--- a/sfx2/source/appl/appuno.cxx
+++ b/sfx2/source/appl/appuno.cxx
@@ -173,6 +173,7 @@ static char const sLockContentExtraction[] = "LockContentExtraction";
static char const sLockExport[] = "LockExport";
static char const sLockPrint[] = "LockPrint";
static char const sLockSave[] = "LockSave";
+static char const sLockEditDoc[] = "LockEditDoc";
static bool isMediaDescriptor( sal_uInt16 nSlotId )
{
@@ -879,6 +880,14 @@ void TransformParameters( sal_uInt16 nSlotId, const uno::Sequence<beans::Propert
if (bOK)
rSet.Put( SfxBoolItem( SID_LOCK_SAVE, bVal ) );
}
+ else if (aName == sLockEditDoc)
+ {
+ bool bVal = false;
+ bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for LockEditDoc" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_LOCK_EDITDOC, bVal ) );
+ }
#ifdef DBG_UTIL
else
--nFoundArgs;
@@ -1104,6 +1113,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b
nAdditional++;
if ( rSet.GetItemState( SID_LOCK_SAVE ) == SfxItemState::SET )
nAdditional++;
+ if ( rSet.GetItemState( SID_LOCK_EDITDOC ) == SfxItemState::SET )
+ nAdditional++;
// consider additional arguments
nProps += nAdditional;
@@ -1269,6 +1280,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b
continue;
if ( nId == SID_LOCK_SAVE )
continue;
+ if ( nId == SID_LOCK_EDITDOC )
+ continue;
}
OString aDbg = "Unknown item detected: " + OString::number(static_cast<sal_Int32>(nId));
@@ -1681,6 +1694,11 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b
pValue[nActProp].Name = sLockSave;
pValue[nActProp++].Value <<= static_cast<const SfxBoolItem*>(pItem)->GetValue() ;
}
+ if ( rSet.GetItemState( SID_LOCK_EDITDOC, false, &pItem ) == SfxItemState::SET )
+ {
+ pValue[nActProp].Name = sLockEditDoc;
+ pValue[nActProp++].Value <<= static_cast<const SfxBoolItem*>(pItem)->GetValue();
+ }
}
rArgs = aSequ;
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index aebd3f19cbad..f8b7c0b7db18 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -1094,6 +1094,11 @@ void SAL_CALL SfxBaseModel::setArgs(const Sequence<beans::PropertyValue>& aArgs)
rArg.Value >>= bValue;
pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_SAVE, bValue));
}
+ else if (rArg.Name == "LockEditDoc")
+ {
+ rArg.Value >>= bValue;
+ pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_EDITDOC, bValue));
+ }
else if (rArg.Name == "EncryptionData")
{
pMedium->GetItemSet()->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, rArg.Value));
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index e3f39e3aab40..6dccb522c14b 100755
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -306,6 +306,10 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT ))
break;
+ SfxViewShell* pViewSh = GetViewShell();
+ if (pViewSh && pViewSh->isEditDocLocked())
+ break;
+
// Only change read-only UI and remove info bar when we succeed
struct ReadOnlyUIGuard
{
@@ -919,6 +923,7 @@ void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet )
const SfxShell *pFSh;
if ( !pSh->HasName() ||
!( pSh->Get_Impl()->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT ) ||
+ (GetViewShell() && GetViewShell()->isEditDocLocked()) ||
( pSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED &&
( !(pVSh = pSh->GetViewShell()) ||
!(pFSh = pVSh->GetFormShell()) ||
@@ -1405,11 +1410,18 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
pInfoBar->addButton(xSignButton);
}
- VclPtrInstance<PushButton> xBtn(&GetWindow());
- xBtn->SetText(SfxResId(STR_READONLY_EDIT));
- xBtn->SetSizePixel(xBtn->GetOptimalSize());
- xBtn->SetClickHdl(LINK(this, SfxViewFrame, SwitchReadOnlyHandler));
- pInfoBar->addButton(xBtn);
+ bool showEditDocumentButton = true;
+ if (m_xObjSh->GetViewShell() && m_xObjSh->GetViewShell()->isEditDocLocked())
+ showEditDocumentButton = false;
+
+ if (showEditDocumentButton)
+ {
+ VclPtrInstance<PushButton> xBtn(&GetWindow());
+ xBtn->SetText(SfxResId(STR_READONLY_EDIT));
+ xBtn->SetSizePixel(xBtn->GetOptimalSize());
+ xBtn->SetClickHdl(LINK(this, SfxViewFrame, SwitchReadOnlyHandler));
+ pInfoBar->addButton(xBtn);
+ }
}
}
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 1d75d7d354b5..a0598191f3f7 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1776,6 +1776,15 @@ bool SfxViewShell::isPrintLocked()
return aArgs.getOrDefault("LockPrint", false);
}
+bool SfxViewShell::isEditDocLocked()
+{
+ Reference<XModel> xModel = GetCurrentDocument();
+ if (!xModel.is())
+ return false;
+ comphelper::NamedValueCollection aArgs(xModel->getArgs());
+ return aArgs.getOrDefault("LockEditDoc", false);
+}
+
bool SfxViewShell::isSaveLocked()
{
Reference<XModel> xModel = GetCurrentDocument();
diff --git a/sw/qa/python/check_xmodel.py b/sw/qa/python/check_xmodel.py
index c257ef33fb79..f6894dd21a3f 100644
--- a/sw/qa/python/check_xmodel.py
+++ b/sw/qa/python/check_xmodel.py
@@ -36,7 +36,8 @@ class TestXModel(unittest.TestCase):
p4 = PropertyValue(Name="LockExport", Value=True)
p5 = PropertyValue(Name="LockPrint", Value=True)
p6 = PropertyValue(Name="LockSave", Value=True)
- xDoc.setArgs([p1, p2, p3, p4, p5, p6])
+ p7 = PropertyValue(Name="LockEditDoc", Value=True)
+ xDoc.setArgs([p1, p2, p3, p4, p5, p6, p7])
# Make sure that all properties are returned with getArgs()
args = xDoc.getArgs()
@@ -46,6 +47,7 @@ class TestXModel(unittest.TestCase):
self.assertTrue(p4 in args)
self.assertTrue(p5 in args)
self.assertTrue(p6 in args)
+ self.assertTrue(p7 in args)
xDoc.close(True)
More information about the Libreoffice-commits
mailing list