cui/source/inc/securityoptions.hxx                         |    3 
 cui/source/options/securityoptions.cxx                     |    6 +
 cui/uiconfig/ui/securityoptionsdialog.ui                   |   48 ++++++++++---
 include/unotools/securityoptions.hxx                       |    1 
 officecfg/registry/schema/org/openoffice/Office/Common.xcs |    8 ++
 sw/qa/extras/odfexport/odfexport2.cxx                      |   18 ++++
 unotools/source/config/securityoptions.cxx                 |    9 ++
 xmloff/source/core/SettingsExportHelper.cxx                |   10 ++
 8 files changed, 93 insertions(+), 10 deletions(-)

New commits:
commit ba8911931c18e6a4cc737ffc9f0f415f1ba794d7
Author:     Samuel Mehrbrodt <[email protected]>
AuthorDate: Thu Jan 25 13:01:24 2024 +0100
Commit:     Samuel Mehrbrodt <[email protected]>
CommitDate: Fri Jan 26 07:08:19 2024 +0100

    Don't export printer name & config in privacy mode
    
    Don't export printer name & printer config when
    RemovePersonalInfoOnSaving is enabled, as it might contain
    sensitive data such as printer location.
    
    Add an option to export printer settings even when
    RemovePersonalInfoOnSaving is enabled.
    
    Change-Id: I3d2ca91ad2032050c919d382c11c9ceabf331770
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162577
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <[email protected]>

diff --git a/cui/source/inc/securityoptions.hxx 
b/cui/source/inc/securityoptions.hxx
index 981c9ac29bf8..a86b4f0c605a 100644
--- a/cui/source/inc/securityoptions.hxx
+++ b/cui/source/inc/securityoptions.hxx
@@ -53,6 +53,8 @@ namespace svx
         std::unique_ptr<weld::Widget> m_xNoteAuthorImg;
         std::unique_ptr<weld::CheckButton> m_xDocumentVersionCB;
         std::unique_ptr<weld::Widget> m_xDocumentVersionImg;
+        std::unique_ptr<weld::CheckButton> m_xPrinterSettingsCB;
+        std::unique_ptr<weld::Widget> m_xPrinterSettingsImg;
 
     public:
         SecurityOptionsDialog(weld::Window* pParent);
@@ -68,6 +70,7 @@ namespace svx
         bool IsRemoveDocUserInfoChecked() const { return 
m_xDocPropertiesCB->get_active(); }
         bool IsRemoveNoteAuthorInfoChecked() const { return 
m_xNoteAuthorCB->get_active(); }
         bool IsRemoveDocVersionInfoChecked() const { return 
m_xDocumentVersionCB->get_active(); }
+        bool IsKeepPrinterSettingsChecked() const { return 
m_xPrinterSettingsCB->get_active(); }
         bool IsRecommPasswdChecked() const { return 
m_xRecommPasswdCB->get_active(); }
         bool IsCtrlHyperlinkChecked() const { return 
m_xCtrlHyperlinkCB->get_active(); }
         bool IsBlockUntrustedRefererLinksChecked() const { return 
m_xBlockUntrustedRefererLinksCB->get_active(); }
diff --git a/cui/source/options/securityoptions.cxx 
b/cui/source/options/securityoptions.cxx
index f42b0c35dd4b..d99ad64e545e 100644
--- a/cui/source/options/securityoptions.cxx
+++ b/cui/source/options/securityoptions.cxx
@@ -73,6 +73,8 @@ SecurityOptionsDialog::SecurityOptionsDialog(weld::Window* 
pParent)
     , m_xNoteAuthorImg(m_xBuilder->weld_widget("locknoteauthor"))
     , m_xDocumentVersionCB(m_xBuilder->weld_check_button("documentversion"))
     , m_xDocumentVersionImg(m_xBuilder->weld_widget("lockdocumentversion"))
+    , m_xPrinterSettingsCB(m_xBuilder->weld_check_button("printersettings"))
+    , m_xPrinterSettingsImg(m_xBuilder->weld_widget("lockprintersettings"))
 {
     m_xRemovePersInfoCB->connect_toggled(LINK(this, SecurityOptionsDialog, 
ShowPersonalInfosToggle));
     init();
@@ -103,6 +105,8 @@ void SecurityOptionsDialog::init()
         *m_xNoteAuthorImg);
     enableAndSet(SvtSecurityOptions::EOption::DocWarnKeepDocVersionInfo, 
*m_xDocumentVersionCB,
         *m_xDocumentVersionImg);
+    enableAndSet(SvtSecurityOptions::EOption::DocKeepPrinterSettings, 
*m_xPrinterSettingsCB,
+        *m_xPrinterSettingsImg);
     enableAndSet(SvtSecurityOptions::EOption::DocWarnRecommendPassword, 
*m_xRecommPasswdCB,
         *m_xRecommPasswdImg);
     enableAndSet(SvtSecurityOptions::EOption::CtrlClickHyperlink, 
*m_xCtrlHyperlinkCB,
@@ -128,6 +132,7 @@ bool SecurityOptionsDialog::SetSecurityOptions()
     CheckAndSave(SvtSecurityOptions::EOption::DocWarnKeepDocUserInfo, 
IsRemoveDocUserInfoChecked(), bModified);
     CheckAndSave(SvtSecurityOptions::EOption::DocWarnKeepNoteAuthorDateInfo, 
IsRemoveNoteAuthorInfoChecked(), bModified);
     CheckAndSave(SvtSecurityOptions::EOption::DocWarnKeepDocVersionInfo, 
IsRemoveDocVersionInfoChecked(), bModified);
+    CheckAndSave(SvtSecurityOptions::EOption::DocKeepPrinterSettings, 
IsKeepPrinterSettingsChecked(), bModified);
     CheckAndSave(SvtSecurityOptions::EOption::DocWarnRecommendPassword, 
IsRecommPasswdChecked(), bModified);
     CheckAndSave(SvtSecurityOptions::EOption::CtrlClickHyperlink, 
IsCtrlHyperlinkChecked(), bModified);
     CheckAndSave(SvtSecurityOptions::EOption::BlockUntrustedRefererLinks, 
IsBlockUntrustedRefererLinksChecked(), bModified);
@@ -143,6 +148,7 @@ void SecurityOptionsDialog::changeKeepSecurityInfosEnabled()
     m_xDocPropertiesCB->set_sensitive(bEnable);
     m_xNoteAuthorCB->set_sensitive(bEnable);
     m_xDocumentVersionCB->set_sensitive(bEnable);
+    m_xPrinterSettingsCB->set_sensitive(bEnable);
 }
 
 }
diff --git a/cui/uiconfig/ui/securityoptionsdialog.ui 
b/cui/uiconfig/ui/securityoptionsdialog.ui
index 309b964915e8..aa23fef47395 100644
--- a/cui/uiconfig/ui/securityoptionsdialog.ui
+++ b/cui/uiconfig/ui/securityoptionsdialog.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.40.0 -->
 <interface domain="cui">
   <requires lib="gtk+" version="3.20"/>
   <object class="GtkDialog" id="SecurityOptionsDialog">
@@ -275,7 +275,7 @@
                 <property name="label-xalign">0</property>
                 <property name="shadow-type">none</property>
                 <child>
-                  <!-- n-columns=2 n-rows=9 -->
+                  <!-- n-columns=2 n-rows=10 -->
                   <object class="GtkGrid" id="grid3">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
@@ -333,7 +333,7 @@
                       </object>
                       <packing>
                         <property name="left-attach">1</property>
-                        <property name="top-attach">7</property>
+                        <property name="top-attach">8</property>
                       </packing>
                     </child>
                     <child>
@@ -345,7 +345,7 @@
                       </object>
                       <packing>
                         <property name="left-attach">0</property>
-                        <property name="top-attach">7</property>
+                        <property name="top-attach">8</property>
                       </packing>
                     </child>
                     <child>
@@ -365,7 +365,7 @@
                       </object>
                       <packing>
                         <property name="left-attach">1</property>
-                        <property name="top-attach">6</property>
+                        <property name="top-attach">7</property>
                       </packing>
                     </child>
                     <child>
@@ -377,7 +377,7 @@
                       </object>
                       <packing>
                         <property name="left-attach">0</property>
-                        <property name="top-attach">6</property>
+                        <property name="top-attach">7</property>
                       </packing>
                     </child>
                     <child>
@@ -397,7 +397,7 @@
                       </object>
                       <packing>
                         <property name="left-attach">1</property>
-                        <property name="top-attach">5</property>
+                        <property name="top-attach">6</property>
                       </packing>
                     </child>
                     <child>
@@ -409,7 +409,7 @@
                       </object>
                       <packing>
                         <property name="left-attach">0</property>
-                        <property name="top-attach">5</property>
+                        <property name="top-attach">6</property>
                       </packing>
                     </child>
                     <child>
@@ -541,7 +541,7 @@
                       </object>
                       <packing>
                         <property name="left-attach">0</property>
-                        <property name="top-attach">8</property>
+                        <property name="top-attach">9</property>
                       </packing>
                     </child>
                     <child>
@@ -561,7 +561,35 @@
                       </object>
                       <packing>
                         <property name="left-attach">1</property>
-                        <property name="top-attach">8</property>
+                        <property name="top-attach">9</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="printersettings">
+                        <property name="label" translatable="yes" 
context="securityoptionsdialog|printersettings">Keep printer settings</property>
+                        <property name="visible">True</property>
+                        <property name="can-focus">True</property>
+                        <property name="receives-default">False</property>
+                        <property name="margin-start">20</property>
+                        <property name="hexpand">True</property>
+                        <property name="use-underline">True</property>
+                        <property name="draw-indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">1</property>
+                        <property name="top-attach">5</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="lockprintersettings">
+                        <property name="can-focus">False</property>
+                        <property name="halign">center</property>
+                        <property name="valign">center</property>
+                        <property name="icon-name">res/lock.png</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">0</property>
+                        <property name="top-attach">5</property>
                       </packing>
                     </child>
                   </object>
diff --git a/include/unotools/securityoptions.hxx 
b/include/unotools/securityoptions.hxx
index 650056eb2f33..1becb0b9ac4b 100644
--- a/include/unotools/securityoptions.hxx
+++ b/include/unotools/securityoptions.hxx
@@ -45,6 +45,7 @@ namespace SvtSecurityOptions
         DocWarnKeepDocUserInfo,
         DocWarnKeepNoteAuthorDateInfo,
         DocWarnKeepDocVersionInfo,
+        DocKeepPrinterSettings,
         DocWarnRecommendPassword,
         MacroSecLevel,
         MacroTrustedAuthors,
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 79c419b79a18..018fdf436db1 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -2440,6 +2440,14 @@
           </info>
           <value>false</value>
         </prop>
+        <prop oor:name="KeepDocPrinterSettingsOnSaving" oor:type="xs:boolean" 
oor:nillable="false">
+          <info>
+            <desc>
+              Specifies whether to keep printer settings on saving if 
RemovePersonalInfoOnSaving is true.
+            </desc>
+          </info>
+          <value>false</value>
+        </prop>
         <prop oor:name="RecommendPasswordProtection" oor:type="xs:boolean" 
oor:nillable="false">
           <info>
             <desc>Specifies whether to recommend password protection when 
saving
diff --git a/sw/qa/extras/odfexport/odfexport2.cxx 
b/sw/qa/extras/odfexport/odfexport2.cxx
index 4160f48ab388..b6b6bff018a9 100644
--- a/sw/qa/extras/odfexport/odfexport2.cxx
+++ b/sw/qa/extras/odfexport/odfexport2.cxx
@@ -586,6 +586,15 @@ CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData)
     assertXPath(pXmlDoc, 
"/office:document-meta/office:meta/meta:editing-duration"_ostr, 0);
     assertXPath(pXmlDoc, 
"/office:document-meta/office:meta/meta:editing-cycles"_ostr, 0);
     assertXPath(pXmlDoc, 
"/office:document-meta/office:meta/meta:template"_ostr, 0);
+    pXmlDoc = parseExport("settings.xml");
+    assertXPath(
+        pXmlDoc,
+        
"/office:document-settings/office:settings/config:config-item-set[2]/config:config-item[@config:name='PrinterName']"_ostr,
+        0);
+    assertXPath(
+        pXmlDoc,
+        
"/office:document-settings/office:settings/config:config-item-set[2]/config:config-item[@config:name='PrinterSetup']"_ostr,
+        0);
 
     // 2. Remove user info too
     
officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(false,
 pBatch);
@@ -602,6 +611,15 @@ CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData)
     assertXPath(pXmlDoc, 
"/office:document-meta/office:meta/meta:editing-duration"_ostr, 0);
     assertXPath(pXmlDoc, 
"/office:document-meta/office:meta/meta:editing-cycles"_ostr, 0);
     assertXPath(pXmlDoc, 
"/office:document-meta/office:meta/meta:template"_ostr, 0);
+    pXmlDoc = parseExport("settings.xml");
+    assertXPath(
+        pXmlDoc,
+        
"/office:document-settings/office:settings/config:config-item-set[2]/config:config-item[@config:name='PrinterName']"_ostr,
+        0);
+    assertXPath(
+        pXmlDoc,
+        
"/office:document-settings/office:settings/config:config-item-set[2]/config:config-item[@config:name='PrinterSetup']"_ostr,
+        0);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, tdf151100)
diff --git a/unotools/source/config/securityoptions.cxx 
b/unotools/source/config/securityoptions.cxx
index a29a40894db1..8ac963c8fab4 100644
--- a/unotools/source/config/securityoptions.cxx
+++ b/unotools/source/config/securityoptions.cxx
@@ -83,6 +83,9 @@ bool IsReadOnly( EOption eOption )
         case SvtSecurityOptions::EOption::DocWarnKeepDocVersionInfo:
             bReadonly = 
officecfg::Office::Common::Security::Scripting::KeepDocVersionInfoOnSaving::isReadOnly();
             break;
+        case SvtSecurityOptions::EOption::DocKeepPrinterSettings:
+            bReadonly = 
officecfg::Office::Common::Security::Scripting::KeepDocPrinterSettingsOnSaving::isReadOnly();
+            break;
         case SvtSecurityOptions::EOption::DocWarnRecommendPassword:
             bReadonly = 
officecfg::Office::Common::Security::Scripting::RecommendPasswordProtection::isReadOnly();
             break;
@@ -327,6 +330,9 @@ bool IsOptionSet( EOption eOption )
         case SvtSecurityOptions::EOption::DocWarnKeepDocVersionInfo:
             bSet = 
officecfg::Office::Common::Security::Scripting::KeepDocVersionInfoOnSaving::get();
             break;
+        case SvtSecurityOptions::EOption::DocKeepPrinterSettings:
+            bSet = 
officecfg::Office::Common::Security::Scripting::KeepDocPrinterSettingsOnSaving::get();
+            break;
         case SvtSecurityOptions::EOption::DocWarnRecommendPassword:
             bSet = 
officecfg::Office::Common::Security::Scripting::RecommendPasswordProtection::get();
             break;
@@ -380,6 +386,9 @@ void SetOption( EOption eOption, bool bValue )
         case SvtSecurityOptions::EOption::DocWarnKeepDocVersionInfo:
              
officecfg::Office::Common::Security::Scripting::KeepDocVersionInfoOnSaving::set(bValue,
 xChanges);
             break;
+        case SvtSecurityOptions::EOption::DocKeepPrinterSettings:
+             
officecfg::Office::Common::Security::Scripting::KeepDocPrinterSettingsOnSaving::set(bValue,
 xChanges);
+            break;
         case SvtSecurityOptions::EOption::DocWarnRecommendPassword:
              
officecfg::Office::Common::Security::Scripting::RecommendPasswordProtection::set(bValue,
 xChanges);
             break;
diff --git a/xmloff/source/core/SettingsExportHelper.cxx 
b/xmloff/source/core/SettingsExportHelper.cxx
index 8cd0519918a5..ea562f101959 100644
--- a/xmloff/source/core/SettingsExportHelper.cxx
+++ b/xmloff/source/core/SettingsExportHelper.cxx
@@ -28,6 +28,7 @@
 #include <comphelper/diagnose_ex.hxx>
 #include <comphelper/base64.hxx>
 #include <comphelper/extract.hxx>
+#include <unotools/securityoptions.hxx>
 
 #include <com/sun/star/linguistic2/XSupportedLocales.hpp>
 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
@@ -276,8 +277,17 @@ void XMLSettingsExportHelper::exportSequencePropertyValue(
     {
         m_rContext.AddAttribute( XML_NAME, rName );
         m_rContext.StartElement( XML_CONFIG_ITEM_SET );
+        bool bSkipPrinterSettings = SvtSecurityOptions::IsOptionSet(
+                                        
SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo)
+                                    && !SvtSecurityOptions::IsOptionSet(
+                                           
SvtSecurityOptions::EOption::DocKeepPrinterSettings);
         for (const auto& rProp : aProps)
+        {
+            if (bSkipPrinterSettings
+                && (rProp.Name == "PrinterSetup" || rProp.Name == 
"PrinterName"))
+                continue;
             CallTypeFunction(rProp.Value, rProp.Name);
+        }
         m_rContext.EndElement( true );
     }
 }

Reply via email to