include/sfx2/sfxsids.hrc | 4 + include/sfx2/viewsh.hxx | 2 offapi/com/sun/star/document/MediaDescriptor.idl | 12 ++++ offapi/com/sun/star/frame/XModel2.idl | 3 + sfx2/source/appl/appuno.cxx | 36 +++++++++++++ sfx2/source/doc/objserv.cxx | 10 ++- sfx2/source/doc/sfxbasemodel.cxx | 10 +++ sfx2/source/view/viewsh.cxx | 62 +++++++++++++++-------- sw/qa/python/check_xmodel.py | 6 +- 9 files changed, 118 insertions(+), 27 deletions(-)
New commits: commit e37b70442ebf9e1628e7da16b7b6acf498897dee Author: Samuel Mehrbrodt <[email protected]> AuthorDate: Wed Oct 23 08:24:31 2019 +0200 Commit: Samuel Mehrbrodt <[email protected]> CommitDate: Wed Oct 23 15:22:16 2019 +0200 Add document-level option to lock down save Change-Id: I40b5e8c780894645e467e3891062c499707d69c7 Reviewed-on: https://gerrit.libreoffice.org/81359 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <[email protected]> diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index d323147ec456..33da857c096f 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -267,8 +267,9 @@ class SvxSearchItem; #define SID_REDACTION_STYLE (SID_SFX_START + 1734) #define SID_DIALOG_PARENT (SID_SFX_START + 1735) #define SID_LOCK_PRINT (SID_SFX_START + 1736) +#define SID_LOCK_SAVE (SID_SFX_START + 1737) -// SID_SFX_free_START (SID_SFX_START + 1737) +// SID_SFX_free_START (SID_SFX_START + 1738) // 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 6a82b3cd8189..a1a225aa1b28 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -291,6 +291,7 @@ public: bool isContentExtractionLocked(); bool isExportLocked(); bool isPrintLocked(); + bool isSaveLocked(); 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 b7ff7c50356a..e6035517f26b 100644 --- a/offapi/com/sun/star/document/MediaDescriptor.idl +++ b/offapi/com/sun/star/document/MediaDescriptor.idl @@ -582,6 +582,12 @@ service MediaDescriptor @since LibreOffice 6.4 */ [optional,property] boolean LockPrint; + + /** Setting this option will disable the save function. + * + @since LibreOffice 6.4 + */ + [optional,property] boolean LockSave; }; diff --git a/offapi/com/sun/star/frame/XModel2.idl b/offapi/com/sun/star/frame/XModel2.idl index b68ac819dc27..128d5ced20d6 100644 --- a/offapi/com/sun/star/frame/XModel2.idl +++ b/offapi/com/sun/star/frame/XModel2.idl @@ -145,6 +145,8 @@ interface XModel2 : com::sun::star::frame::XModel <li>com::sun::star::document::MediaDescriptor::LockContentExtraction</li> <li>com::sun::star::document::MediaDescriptor::LockExport</li> <li>com::sun::star::document::MediaDescriptor::LockPrint</li> + <li>com::sun::star::document::MediaDescriptor::LockSave</li> + </ul> @throws com::sun::star::lang::IllegalArgumentException When trying to set an unsupported property diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index 79247883dcfc..c633978076d9 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -172,6 +172,7 @@ static char const sImageFilter[] = "ImageFilter"; static char const sLockContentExtraction[] = "LockContentExtraction"; static char const sLockExport[] = "LockExport"; static char const sLockPrint[] = "LockPrint"; +static char const sLockSave[] = "LockSave"; static bool isMediaDescriptor( sal_uInt16 nSlotId ) { @@ -870,6 +871,14 @@ void TransformParameters( sal_uInt16 nSlotId, const uno::Sequence<beans::Propert if (bOK) rSet.Put( SfxBoolItem( SID_LOCK_PRINT, bVal ) ); } + else if (aName == sLockSave) + { + bool bVal = false; + bool bOK = (rProp.Value >>= bVal); + DBG_ASSERT( bOK, "invalid type for LockSave" ); + if (bOK) + rSet.Put( SfxBoolItem( SID_LOCK_SAVE, bVal ) ); + } #ifdef DBG_UTIL else --nFoundArgs; @@ -1093,6 +1102,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b nAdditional++; if ( rSet.GetItemState( SID_LOCK_PRINT ) == SfxItemState::SET ) nAdditional++; + if ( rSet.GetItemState( SID_LOCK_SAVE ) == SfxItemState::SET ) + nAdditional++; // consider additional arguments nProps += nAdditional; @@ -1256,6 +1267,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b continue; if ( nId == SID_LOCK_PRINT ) continue; + if ( nId == SID_LOCK_SAVE ) + continue; } OString aDbg = "Unknown item detected: " + OString::number(static_cast<sal_Int32>(nId)); @@ -1663,6 +1676,11 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b pValue[nActProp].Name = sLockPrint; pValue[nActProp++].Value <<= static_cast<const SfxBoolItem*>(pItem)->GetValue() ; } + if ( rSet.GetItemState( SID_LOCK_SAVE, false, &pItem ) == SfxItemState::SET ) + { + pValue[nActProp].Name = sLockSave; + pValue[nActProp++].Value <<= static_cast<const SfxBoolItem*>(pItem)->GetValue() ; + } } rArgs = aSequ; diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 8c7c5ab3f8af..6aa2b644b8f3 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -1203,11 +1203,13 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) } case SID_SAVEDOC: { - if ( !IsReadOnly() ) - rSet.Put(SfxStringItem( - nWhich, SfxResId(STR_SAVEDOC))); - else + SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this); + if ( IsReadOnly() || (pFrame && pFrame->GetViewShell()->isSaveLocked())) + { rSet.DisableItem(nWhich); + break; + } + rSet.Put(SfxStringItem(nWhich, SfxResId(STR_SAVEDOC))); } break; diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 67bacd79502d..395672aaae97 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -1089,6 +1089,11 @@ void SAL_CALL SfxBaseModel::setArgs(const Sequence<beans::PropertyValue>& aArgs) rArg.Value >>= bValue; pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_PRINT, bValue)); } + else if (rArg.Name == "LockSave") + { + rArg.Value >>= bValue; + pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_SAVE, bValue)); + } else { throw lang::IllegalArgumentException("Setting property not supported: " + rArg.Name, diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 123aa18dcb58..236d173ef140 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::isSaveLocked() +{ + Reference<XModel> xModel = GetCurrentDocument(); + if (!xModel.is()) + return false; + comphelper::NamedValueCollection aArgs(xModel->getArgs()); + return aArgs.getOrDefault("LockSave", true); +} + Reference < XController > SfxViewShell::GetController() const { return pImpl->m_pController.get(); diff --git a/sw/qa/python/check_xmodel.py b/sw/qa/python/check_xmodel.py index 5b1f8722016b..c257ef33fb79 100644 --- a/sw/qa/python/check_xmodel.py +++ b/sw/qa/python/check_xmodel.py @@ -35,7 +35,8 @@ class TestXModel(unittest.TestCase): p3 = PropertyValue(Name="LockContentExtraction", Value=True) p4 = PropertyValue(Name="LockExport", Value=True) p5 = PropertyValue(Name="LockPrint", Value=True) - xDoc.setArgs([p1, p2, p3, p4, p5]) + p6 = PropertyValue(Name="LockSave", Value=True) + xDoc.setArgs([p1, p2, p3, p4, p5, p6]) # Make sure that all properties are returned with getArgs() args = xDoc.getArgs() @@ -44,6 +45,7 @@ class TestXModel(unittest.TestCase): self.assertTrue(p3 in args) self.assertTrue(p4 in args) self.assertTrue(p5 in args) + self.assertTrue(p6 in args) xDoc.close(True) commit d5d96e04ad8014f3e68351ccb54221d9610b565b Author: Samuel Mehrbrodt <[email protected]> AuthorDate: Tue Oct 22 15:58:31 2019 +0200 Commit: Samuel Mehrbrodt <[email protected]> CommitDate: Wed Oct 23 15:21:24 2019 +0200 Add document-level option to lock down printing Change-Id: I85694021d74be79293079d04d5ba1d9b48cfa557 Reviewed-on: https://gerrit.libreoffice.org/81340 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <[email protected]> diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index 0b5eeb73a32b..d323147ec456 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -266,6 +266,7 @@ class SvxSearchItem; #define SID_IS_REDACT_MODE (SID_SFX_START + 1733) #define SID_REDACTION_STYLE (SID_SFX_START + 1734) #define SID_DIALOG_PARENT (SID_SFX_START + 1735) +#define SID_LOCK_PRINT (SID_SFX_START + 1736) // SID_SFX_free_START (SID_SFX_START + 1737) // SID_SFX_free_END (SID_SFX_START + 3999) diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index 525cc111d216..6a82b3cd8189 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -290,6 +290,7 @@ public: css::uno::Reference< css::datatransfer::clipboard::XClipboardNotifier > GetClipboardNotifier() const; bool isContentExtractionLocked(); bool isExportLocked(); + bool isPrintLocked(); 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 f7c248d85803..b7ff7c50356a 100644 --- a/offapi/com/sun/star/document/MediaDescriptor.idl +++ b/offapi/com/sun/star/document/MediaDescriptor.idl @@ -576,6 +576,12 @@ service MediaDescriptor @since LibreOffice 6.4 */ [optional,property] boolean LockExport; + + /** Setting this option will disable all print functions (including Printer setup) + + @since LibreOffice 6.4 + */ + [optional,property] boolean LockPrint; }; diff --git a/offapi/com/sun/star/frame/XModel2.idl b/offapi/com/sun/star/frame/XModel2.idl index 3cdbda4dfc09..b68ac819dc27 100644 --- a/offapi/com/sun/star/frame/XModel2.idl +++ b/offapi/com/sun/star/frame/XModel2.idl @@ -144,6 +144,7 @@ interface XModel2 : com::sun::star::frame::XModel <li>com::sun::star::document::MediaDescriptor::SuggestedSaveAsName</li> <li>com::sun::star::document::MediaDescriptor::LockContentExtraction</li> <li>com::sun::star::document::MediaDescriptor::LockExport</li> + <li>com::sun::star::document::MediaDescriptor::LockPrint</li> </ul> @throws com::sun::star::lang::IllegalArgumentException When trying to set an unsupported property diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index 6e5965770710..79247883dcfc 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -171,6 +171,7 @@ static char const sFilterProvider[] = "FilterProvider"; static char const sImageFilter[] = "ImageFilter"; static char const sLockContentExtraction[] = "LockContentExtraction"; static char const sLockExport[] = "LockExport"; +static char const sLockPrint[] = "LockPrint"; static bool isMediaDescriptor( sal_uInt16 nSlotId ) { @@ -861,6 +862,14 @@ void TransformParameters( sal_uInt16 nSlotId, const uno::Sequence<beans::Propert if (bOK) rSet.Put( SfxBoolItem( SID_LOCK_EXPORT, bVal ) ); } + else if (aName == sLockPrint) + { + bool bVal = false; + bool bOK = (rProp.Value >>= bVal); + DBG_ASSERT( bOK, "invalid type for LockPrint" ); + if (bOK) + rSet.Put( SfxBoolItem( SID_LOCK_PRINT, bVal ) ); + } #ifdef DBG_UTIL else --nFoundArgs; @@ -1082,6 +1091,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b nAdditional++; if ( rSet.GetItemState( SID_LOCK_EXPORT ) == SfxItemState::SET ) nAdditional++; + if ( rSet.GetItemState( SID_LOCK_PRINT ) == SfxItemState::SET ) + nAdditional++; // consider additional arguments nProps += nAdditional; @@ -1243,6 +1254,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b continue; if ( nId == SID_LOCK_EXPORT ) continue; + if ( nId == SID_LOCK_PRINT ) + continue; } OString aDbg = "Unknown item detected: " + OString::number(static_cast<sal_Int32>(nId)); @@ -1645,6 +1658,11 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b pValue[nActProp].Name = sLockExport; pValue[nActProp++].Value <<= static_cast<const SfxBoolItem*>(pItem)->GetValue() ; } + if ( rSet.GetItemState( SID_LOCK_PRINT, false, &pItem ) == SfxItemState::SET ) + { + pValue[nActProp].Name = sLockPrint; + 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 bb6a1484befd..67bacd79502d 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -1084,6 +1084,11 @@ void SAL_CALL SfxBaseModel::setArgs(const Sequence<beans::PropertyValue>& aArgs) rArg.Value >>= bValue; pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_EXPORT, bValue)); } + else if (rArg.Name == "LockPrint") + { + rArg.Value >>= bValue; + pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_PRINT, bValue)); + } else { throw lang::IllegalArgumentException("Setting property not supported: " + rArg.Name, diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index e8638badac64..123aa18dcb58 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -700,32 +700,34 @@ void SfxViewShell::GetState_Impl( SfxItemSet &rSet ) case SID_SETUPPRINTER: case SID_PRINTER_NAME: { - bool bEnabled = !Application::GetSettings().GetMiscSettings().GetDisablePrinting(); - if ( bEnabled ) + if (Application::GetSettings().GetMiscSettings().GetDisablePrinting() || isPrintLocked()) { - SfxPrinter *pPrinter = GetPrinter(); + rSet.DisableItem(nSID); + break; + } + + SfxPrinter *pPrinter = GetPrinter(); - if ( SID_PRINTDOCDIRECT == nSID ) + if ( SID_PRINTDOCDIRECT == nSID ) + { + OUString aPrinterName; + if ( pPrinter != nullptr ) + aPrinterName = pPrinter->GetName(); + else + aPrinterName = Printer::GetDefaultPrinterName(); + if ( !aPrinterName.isEmpty() ) { - OUString aPrinterName; - if ( pPrinter != nullptr ) - aPrinterName = pPrinter->GetName(); - else - aPrinterName = Printer::GetDefaultPrinterName(); - if ( !aPrinterName.isEmpty() ) - { - uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() ); + uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() ); - OUStringBuffer aBuffer( 60 ); - aBuffer.append( vcl::CommandInfoProvider::GetLabelForCommand( - ".uno:PrintDefault", - vcl::CommandInfoProvider::GetModuleIdentifier( xFrame ) ) ); - aBuffer.append( " (" ); - aBuffer.append( aPrinterName ); - aBuffer.append(')'); + OUStringBuffer aBuffer( 60 ); + aBuffer.append( vcl::CommandInfoProvider::GetLabelForCommand( + ".uno:PrintDefault", + vcl::CommandInfoProvider::GetModuleIdentifier( xFrame ) ) ); + aBuffer.append( " (" ); + aBuffer.append( aPrinterName ); + aBuffer.append(')'); - rSet.Put( SfxStringItem( SID_PRINTDOCDIRECT, aBuffer.makeStringAndClear() ) ); - } + rSet.Put( SfxStringItem( SID_PRINTDOCDIRECT, aBuffer.makeStringAndClear() ) ); } } break; @@ -1765,6 +1767,15 @@ bool SfxViewShell::isExportLocked() return aArgs.getOrDefault("LockExport", false); } +bool SfxViewShell::isPrintLocked() +{ + Reference<XModel> xModel = GetCurrentDocument(); + if (!xModel.is()) + return false; + comphelper::NamedValueCollection aArgs(xModel->getArgs()); + return aArgs.getOrDefault("LockPrint", false); +} + Reference < XController > SfxViewShell::GetController() const { return pImpl->m_pController.get(); diff --git a/sw/qa/python/check_xmodel.py b/sw/qa/python/check_xmodel.py index bcceed6acd77..5b1f8722016b 100644 --- a/sw/qa/python/check_xmodel.py +++ b/sw/qa/python/check_xmodel.py @@ -34,7 +34,8 @@ class TestXModel(unittest.TestCase): p2 = PropertyValue(Name="SuggestedSaveAsDir", Value="/my/dir") p3 = PropertyValue(Name="LockContentExtraction", Value=True) p4 = PropertyValue(Name="LockExport", Value=True) - xDoc.setArgs([p1, p2, p3, p4]) + p5 = PropertyValue(Name="LockPrint", Value=True) + xDoc.setArgs([p1, p2, p3, p4, p5]) # Make sure that all properties are returned with getArgs() args = xDoc.getArgs() @@ -42,6 +43,7 @@ class TestXModel(unittest.TestCase): self.assertTrue(p2 in args) self.assertTrue(p3 in args) self.assertTrue(p4 in args) + self.assertTrue(p5 in args) xDoc.close(True) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
