xmlsecurity/inc/macrosecurity.hxx            |    7 ++
 xmlsecurity/inc/strings.hrc                  |    1 
 xmlsecurity/source/dialogs/macrosecurity.cxx |   34 ++++++++++
 xmlsecurity/uiconfig/ui/securitylevelpage.ui |   86 ++++++++++++++++++++++++++-
 4 files changed, 127 insertions(+), 1 deletion(-)

New commits:
commit 6178387f7bcc35df9272978ec936f8b53c6da80d
Author:     Rafael Lima <rafael.palma.l...@gmail.com>
AuthorDate: Thu Mar 14 00:45:43 2024 +0100
Commit:     Rafael Lima <rafael.palma.l...@gmail.com>
CommitDate: Tue Mar 19 14:48:34 2024 +0100

    tdf#159985 Warn about the need to reload file after changing macro security 
level
    
    Change-Id: I191fd5d676d6d54fb0ef15652420afdceab2fc78
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164810
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org>

diff --git a/xmlsecurity/inc/macrosecurity.hxx 
b/xmlsecurity/inc/macrosecurity.hxx
index 5d9feb94c808..162ffad3ce72 100644
--- a/xmlsecurity/inc/macrosecurity.hxx
+++ b/xmlsecurity/inc/macrosecurity.hxx
@@ -72,6 +72,8 @@ class MacroSecurityLevelTP : public MacroSecurityTP
 {
 private:
     sal_uInt16   mnCurLevel;
+    // Stores the security level when the dialog opens. Used to check if the 
value changed
+    sal_uInt16   mnInitialLevel;
 
     std::unique_ptr<weld::RadioButton> m_xVeryHighRB;
     std::unique_ptr<weld::RadioButton> m_xHighRB;
@@ -81,6 +83,11 @@ private:
     std::unique_ptr<weld::Widget> m_xHighImg;
     std::unique_ptr<weld::Widget> m_xMedImg;
     std::unique_ptr<weld::Widget> m_xLowImg;
+    std::unique_ptr<weld::Label> m_xWarningLb;
+    std::unique_ptr<weld::Image> m_xWarningImg;
+    std::unique_ptr<weld::Box> m_xWarningBox;
+
+    void SetWarningLabel(const OUString& sMsg);
 
     DECL_LINK(RadioButtonHdl, weld::Toggleable&, void);
 public:
diff --git a/xmlsecurity/inc/strings.hrc b/xmlsecurity/inc/strings.hrc
index 7e99a58d5286..b450f885df6e 100644
--- a/xmlsecurity/inc/strings.hrc
+++ b/xmlsecurity/inc/strings.hrc
@@ -64,5 +64,6 @@
 #define STR_ENCRYPT                                 
NC_("selectcertificatedialog|str_encrypt", "Encrypt")
 
 #define STR_BROKEN_MACRO_CERTIFICATE_DATA           
NC_("STR_BROKEN_MACRO_CERTIFICATE_DATA", "Macro security problem!

Broken certificate data: %{data}")
+#define STR_RELOAD_FILE_WARNING                     
NC_("STR_RELOAD_FILE_WARNING", "Reload the file to apply the new macro security 
level")
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/dialogs/macrosecurity.cxx 
b/xmlsecurity/source/dialogs/macrosecurity.cxx
index ca4df4e64c03..9432220ae5ae 100644
--- a/xmlsecurity/source/dialogs/macrosecurity.cxx
+++ b/xmlsecurity/source/dialogs/macrosecurity.cxx
@@ -105,6 +105,9 @@ MacroSecurityLevelTP::MacroSecurityLevelTP(weld::Container* 
pParent, MacroSecuri
     , m_xHighImg(m_xBuilder->weld_widget("highimg"))
     , m_xMedImg(m_xBuilder->weld_widget("medimg"))
     , m_xLowImg(m_xBuilder->weld_widget("lowimg"))
+    , m_xWarningLb(m_xBuilder->weld_label("warningmsg"))
+    , m_xWarningImg(m_xBuilder->weld_image("warningimg"))
+    , m_xWarningBox(m_xBuilder->weld_box("warningbox"))
 {
     m_xLowRB->connect_toggled( LINK( this, MacroSecurityLevelTP, 
RadioButtonHdl ) );
     m_xMediumRB->connect_toggled( LINK( this, MacroSecurityLevelTP, 
RadioButtonHdl ) );
@@ -129,6 +132,7 @@ MacroSecurityLevelTP::MacroSecurityLevelTP(weld::Container* 
pParent, MacroSecuri
     }
 
     mnCurLevel = 
static_cast<sal_uInt16>(SvtSecurityOptions::GetMacroSecurityLevel());
+    mnInitialLevel = mnCurLevel;
     bool bReadonly = SvtSecurityOptions::IsReadOnly( 
SvtSecurityOptions::EOption::MacroSecLevel );
 
     weld::RadioButton* pCheck = nullptr;
@@ -166,6 +170,28 @@ 
MacroSecurityLevelTP::MacroSecurityLevelTP(weld::Container* pParent, MacroSecuri
         m_xMediumRB->set_sensitive(false);
         m_xLowRB->set_sensitive(false);
     }
+
+    SetWarningLabel("");
+    // Use same font color as in InfobarType::WARNING
+    m_xWarningLb->set_font_color(Color(0x70, 0x43, 0x00));
+    m_xWarningImg->set_size_request(24, 24);
+}
+
+void MacroSecurityLevelTP::SetWarningLabel(const OUString& sMsg)
+{
+    m_xWarningLb->set_label(sMsg);
+    if (!sMsg.isEmpty())
+    {
+        m_xWarningLb->show();
+        m_xWarningImg->show();
+        m_xWarningBox->set_background(Color(0xFE, 0xEF, 0xB3));
+    }
+    else
+    {
+        m_xWarningLb->hide();
+        m_xWarningImg->hide();
+        m_xWarningBox->set_background(COL_TRANSPARENT);
+    }
 }
 
 IMPL_LINK_NOARG(MacroSecurityLevelTP, RadioButtonHdl, weld::Toggleable&, void)
@@ -183,6 +209,14 @@ IMPL_LINK_NOARG(MacroSecurityLevelTP, RadioButtonHdl, 
weld::Toggleable&, void)
         mnCurLevel = nNewLevel;
         m_pDlg->EnableReset();
     }
+
+    // Show warning message if a different security level is chosen
+    if (nNewLevel != mnInitialLevel)
+        SetWarningLabel(XsResId(STR_RELOAD_FILE_WARNING));
+    else
+    {
+        SetWarningLabel("");
+    }
 }
 
 void MacroSecurityLevelTP::ClosePage()
diff --git a/xmlsecurity/uiconfig/ui/securitylevelpage.ui 
b/xmlsecurity/uiconfig/ui/securitylevelpage.ui
index 911bed1c3768..96163f04378a 100644
--- a/xmlsecurity/uiconfig/ui/securitylevelpage.ui
+++ b/xmlsecurity/uiconfig/ui/securitylevelpage.ui
@@ -2,7 +2,7 @@
 <!-- Generated with glade 3.40.0 -->
 <interface domain="xsc">
   <requires lib="gtk+" version="3.20"/>
-  <!-- n-columns=2 n-rows=4 -->
+  <!-- n-columns=2 n-rows=5 -->
   <object class="GtkGrid" id="SecurityLevelPage">
     <property name="visible">True</property>
     <property name="can-focus">False</property>
@@ -111,6 +111,11 @@ All other macros, regardless whether signed or not, are 
disabled.</property>
         <property name="halign">center</property>
         <property name="valign">center</property>
         <property name="icon-name">res/lock.png</property>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="vhighimg-atkobject">
+            <property name="AtkObject::accessible-name" translatable="yes" 
context="SecurityLevelPage|vhighimg">Very high security level</property>
+          </object>
+        </child>
       </object>
       <packing>
         <property name="left-attach">0</property>
@@ -124,6 +129,11 @@ All other macros, regardless whether signed or not, are 
disabled.</property>
         <property name="halign">center</property>
         <property name="valign">center</property>
         <property name="icon-name">res/lock.png</property>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="highimg-atkobject">
+            <property name="AtkObject::accessible-name" translatable="yes" 
context="SecurityLevelPage|highimg">High security level</property>
+          </object>
+        </child>
       </object>
       <packing>
         <property name="left-attach">0</property>
@@ -137,6 +147,11 @@ All other macros, regardless whether signed or not, are 
disabled.</property>
         <property name="halign">center</property>
         <property name="valign">center</property>
         <property name="icon-name">res/lock.png</property>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="medimg-atkobject">
+            <property name="AtkObject::accessible-name" translatable="yes" 
context="SecurityLevelPage|medimg">Medium security level</property>
+          </object>
+        </child>
       </object>
       <packing>
         <property name="left-attach">0</property>
@@ -150,11 +165,80 @@ All other macros, regardless whether signed or not, are 
disabled.</property>
         <property name="halign">center</property>
         <property name="valign">center</property>
         <property name="icon-name">res/lock.png</property>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="lowimg-atkobject">
+            <property name="AtkObject::accessible-name" translatable="yes" 
context="SecurityLevelPage|lowimg">Low security level</property>
+          </object>
+        </child>
       </object>
       <packing>
         <property name="left-attach">0</property>
         <property name="top-attach">3</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkLabel" id="empty">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+      </object>
+      <packing>
+        <property name="left-attach">0</property>
+        <property name="top-attach">4</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkBox" id="warningbox">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="valign">end</property>
+        <property name="hexpand">True</property>
+        <child>
+          <object class="GtkImage" id="warningimg">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+            <property name="valign">center</property>
+            <property name="margin-start">6</property>
+            <property name="margin-end">3</property>
+            <property name="margin-top">3</property>
+            <property name="margin-bottom">3</property>
+            <property name="icon-name">vcl/res/warningbox.png</property>
+            <child internal-child="accessible">
+              <object class="AtkObject" id="warningimg-atkobject">
+                <property name="AtkObject::accessible-name" translatable="yes" 
context="SecurityLevelPage|warningimg">File reload needed</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="warningmsg">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+            <property name="no-show-all">True</property>
+            <property name="margin-start">3</property>
+            <property name="margin-end">6</property>
+            <property name="margin-top">3</property>
+            <property name="margin-bottom">3</property>
+            <property name="hexpand">True</property>
+            <property name="wrap">True</property>
+            <property name="ellipsize">end</property>
+            <property name="xalign">0</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left-attach">1</property>
+        <property name="top-attach">4</property>
+      </packing>
+    </child>
   </object>
 </interface>

Reply via email to