summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2019-10-22 15:58:31 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2019-12-04 05:40:55 +0100
commit75785b535e118b93fca4bedfd31aed0dd41275df (patch)
tree31e48b9daf9e29bcbb14006d2a74517f78e3b88c
parent694ddd246e140a4787ea1a93fc6f99d4d750015d (diff)
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 <Samuel.Mehrbrodt@cib.de> Conflicts: sfx2/source/view/viewsh.cxx
-rw-r--r--include/sfx2/sfxsids.hrc1
-rw-r--r--include/sfx2/viewsh.hxx1
-rw-r--r--offapi/com/sun/star/document/MediaDescriptor.idl6
-rw-r--r--offapi/com/sun/star/frame/XModel2.idl1
-rw-r--r--sfx2/source/appl/appuno.cxx18
-rw-r--r--sfx2/source/doc/sfxbasemodel.cxx5
-rw-r--r--sfx2/source/view/viewsh.cxx53
-rw-r--r--sw/qa/python/check_xmodel.py4
8 files changed, 67 insertions, 22 deletions
diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index eee454e05a42..0fc69a9ef8b7 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -264,6 +264,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 + 1736)
// SID_SFX_free_END (SID_SFX_START + 3999)
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 6906a2e6dc19..b84ba7db96b1 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -290,6 +290,7 @@ public:
;
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 84f15cca25e3..b32c4ad89f0a 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 891ca1c722d3..762e654284c0 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 )
{
@@ -870,6 +871,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;
@@ -1095,6 +1104,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;
@@ -1256,6 +1267,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;
}
OStringBuffer aDbg("Unknown item detected: ");
@@ -1661,6 +1674,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 4fffa63f4f7c..4fabe0157bef 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: " + aArgs[i].Name,
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 4bab9fc7636a..7b4394ca92c2 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;
@@ -1791,6 +1793,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()
{
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)