cui/inc/strings.hrc                   |    1 
 cui/source/options/optaboutconfig.cxx |   44 ++++++++++++++++++++++++++++++----
 cui/source/options/optaboutconfig.hxx |    2 -
 3 files changed, 42 insertions(+), 5 deletions(-)

New commits:
commit 240db3251e80333597bc9f0b68e1885ef9c520ae
Author:     Samuel Mehrbrodt <[email protected]>
AuthorDate: Thu May 11 10:17:18 2023 +0200
Commit:     Samuel Mehrbrodt <[email protected]>
CommitDate: Mon May 15 12:41:32 2023 +0200

    tdf#104005 Don't allow changing finalized properties
    
    Change-Id: Ic9e42ba6aed2fadd0f28dfc6be0a639cdd16bb34

diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc
index 4051cbb4e444..9a224a3bb9a0 100644
--- a/cui/inc/strings.hrc
+++ b/cui/inc/strings.hrc
@@ -380,6 +380,7 @@
 #define RID_SVXSTR_REGISTERED_DATABASES             
NC_("RID_SVXSTR_REGISTERED_DATABASES", "Registered Databases")
 
 #define RID_SVXSTR_CANNOTCONVERTURL_ERR             
NC_("RID_SVXSTR_CANNOTCONVERTURL_ERR", "The URL <%1> cannot be converted to a 
filesystem path.")
+#define RID_CUISTR_OPT_READONLY                     
NC_("RID_CUISTR_OPT_READONLY", "This property is locked for editing.")
 
 #define RID_SVXSTR_ABOUT_VERSION                    
NC_("aboutdialog|textbuffer1", "Version: 
%ABOUTBOXPRODUCTVERSION%ABOUTBOXPRODUCTVERSIONSUFFIX")
 #define RID_SVXSTR_ABOUT_COPYRIGHT                  
NC_("aboutdialog|copyright", "Copyright © 2000–2021 LibreOffice contributors.")
diff --git a/cui/source/options/optaboutconfig.cxx 
b/cui/source/options/optaboutconfig.cxx
index 217b0bc5308f..b0687a7a797e 100644
--- a/cui/source/options/optaboutconfig.cxx
+++ b/cui/source/options/optaboutconfig.cxx
@@ -14,6 +14,10 @@
 #include <com/sun/star/configuration/theDefaultProvider.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/UnknownPropertyException.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/configuration/ReadWriteAccess.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
 #include <com/sun/star/container/XNameReplace.hpp>
 #include <com/sun/star/container/XHierarchicalName.hpp>
@@ -22,10 +26,14 @@
 #include <com/sun/star/util/SearchAlgorithms2.hpp>
 #include <unotools/textsearch.hxx>
 #include <vcl/event.hxx>
+#include <vcl/svapp.hxx>
 #include <sal/log.hxx>
 #include <tools/diagnose_ex.h>
 #include <tools/debug.hxx>
 
+#include <dialmgr.hxx>
+#include <strings.hrc>
+
 #include <memory>
 #include <vector>
 #include <iostream>
@@ -54,18 +62,21 @@ struct Prop_Impl
 struct UserData
 {
     bool bIsPropertyPath;
+    bool bIsReadOnly;
     OUString sPropertyPath;
     int aLineage;
     Reference<XNameAccess> aXNameAccess;
 
-    explicit UserData( OUString const & rPropertyPath )
+    explicit UserData( OUString const & rPropertyPath, bool isReadOnly )
         : bIsPropertyPath( true )
+        , bIsReadOnly( isReadOnly )
         , sPropertyPath(rPropertyPath)
         , aLineage(0)
     {}
 
     explicit UserData( Reference<XNameAccess> const & rXNameAccess, int rIndex 
)
         : bIsPropertyPath( false )
+        , bIsReadOnly( false )
         , aLineage(rIndex)
         , aXNameAccess( rXNameAccess )
     {}
@@ -200,9 +211,9 @@ CuiAboutConfigTabPage::~CuiAboutConfigTabPage()
 
 void CuiAboutConfigTabPage::InsertEntry(const OUString& rPropertyPath, const 
OUString& rProp, const OUString& rStatus,
                                         const OUString& rType, const OUString& 
rValue, const weld::TreeIter* pParentEntry,
-                                        bool bInsertToPrefBox)
+                                        bool bInsertToPrefBox, bool 
bIsReadOnly)
 {
-    m_vectorUserData.push_back(std::make_unique<UserData>(rPropertyPath));
+    m_vectorUserData.push_back(std::make_unique<UserData>(rPropertyPath, 
bIsReadOnly));
     if (bInsertToPrefBox)
     {
         OUString 
sId(OUString::number(reinterpret_cast<sal_Int64>(m_vectorUserData.back().get())));
@@ -308,6 +319,22 @@ void CuiAboutConfigTabPage::FillItems(const Reference< 
XNameAccess >& xNameAcces
               }
             );
 
+            css::uno::Reference<css::configuration::XReadWriteAccess> 
m_xReadWriteAccess;
+            m_xReadWriteAccess = css::configuration::ReadWriteAccess::create(
+                ::comphelper::getProcessComponentContext(), "*");
+            beans::Property aProperty;
+            bool bReadOnly = false;
+            try
+            {
+                aProperty = 
m_xReadWriteAccess->getPropertyByHierarchicalName(sPath + "/"
+                                                                              
+ sPropertyName);
+                bReadOnly = (aProperty.Attributes & 
beans::PropertyAttribute::READONLY) != 0;
+            }
+            catch (css::beans::UnknownPropertyException)
+            {
+                SAL_WARN("cui.options", "unknown property: " << sPath + "/" + 
sPropertyName);
+            }
+
             OUString sType = aNode.getValueTypeName();
             OUStringBuffer sValue;
 
@@ -469,7 +496,7 @@ void CuiAboutConfigTabPage::FillItems(const Reference< 
XNameAccess >& xNameAcces
             for(int j = 1; j < lineage; ++j)
                 index = sPath.indexOf("/", index + 1);
 
-            InsertEntry(sPath, sPath.copy(index+1), seqItems[i], sType, 
sValue.makeStringAndClear(), pParentEntry, !bLoadAll);
+            InsertEntry(sPath, sPath.copy(index+1), seqItems[i], sType, 
sValue.makeStringAndClear(), pParentEntry, !bLoadAll, bReadOnly);
         }
     }
 }
@@ -573,6 +600,15 @@ IMPL_LINK_NOARG( CuiAboutConfigTabPage, StandardHdl_Impl, 
weld::Button&, void )
         return;
 
     UserData *pUserData = 
reinterpret_cast<UserData*>(m_xPrefBox->get_id(*m_xScratchIter).toInt64());
+    if (pUserData && pUserData->bIsReadOnly)
+    {
+        std::unique_ptr<weld::MessageDialog> xMessageBox(
+            Application::CreateMessageDialog(m_xDialog.get(), 
VclMessageType::Info, VclButtonsType::Ok,
+                                             
CuiResId(RID_CUISTR_OPT_READONLY)));
+        xMessageBox->run();
+        return;
+    }
+
     if (pUserData && pUserData->bIsPropertyPath)
     {
         //if selection is a node
diff --git a/cui/source/options/optaboutconfig.hxx 
b/cui/source/options/optaboutconfig.hxx
index b7781859eb4b..ab1cdcfb6ee6 100644
--- a/cui/source/options/optaboutconfig.hxx
+++ b/cui/source/options/optaboutconfig.hxx
@@ -67,7 +67,7 @@ public:
    explicit CuiAboutConfigTabPage(weld::Window* pParent);
    virtual ~CuiAboutConfigTabPage() override;
    void     InsertEntry(const OUString &rPropertyPath, const OUString& rProp, 
const OUString& rStatus, const OUString& rType, const OUString& rValue,
-                        const weld::TreeIter* pParentEntry, bool 
bInsertToPrefBox);
+                        const weld::TreeIter* pParentEntry, bool 
bInsertToPrefBox, bool bIsReadOnly);
    void     Reset();
    void     FillItems(const css::uno::Reference<css::container::XNameAccess>& 
xNameAccess,
                       const weld::TreeIter* pParentEntry = nullptr, int 
lineage = 0, bool bLoadAll = false);

Reply via email to