cui/source/options/doclinkdialog.cxx |   45 +++++++++++++++++++++++++++++++++++
 cui/source/options/doclinkdialog.hxx |    3 ++
 2 files changed, 48 insertions(+)

New commits:
commit e0dd56acca39524b63b708590f03a3cd6dcbe3ca
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Tue Nov 7 15:17:16 2023 +0100
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Wed Nov 8 10:37:50 2023 +0100

    Related: tdf#158004 - UI: Part 20 - Unify lockdown behavior of
    
    Options dialog for Databases Page.
    
    Change-Id: I573479df8048a9ff4d4aedc9780cbe0395900526
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159074
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/cui/source/options/doclinkdialog.cxx 
b/cui/source/options/doclinkdialog.cxx
index fac99002401c..f938399140ab 100644
--- a/cui/source/options/doclinkdialog.cxx
+++ b/cui/source/options/doclinkdialog.cxx
@@ -20,7 +20,11 @@
 #include "doclinkdialog.hxx"
 
 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
 #include <comphelper/processfactory.hxx>
+#include <officecfg/Office/DataAccess.hxx>
 #include <strings.hrc>
 #include <svl/filenotation.hxx>
 #include <vcl/svapp.hxx>
@@ -53,6 +57,9 @@ namespace svx
         m_xURL->DisableHistory();
         m_xURL->SetFilter(u"*.odb");
 
+        css::uno::Reference < css::uno::XComponentContext > 
xContext(::comphelper::getProcessComponentContext());
+        m_xReadWriteAccess = 
css::configuration::ReadWriteAccess::create(xContext, "*");
+
         m_xName->connect_changed( LINK(this, ODocumentLinkDialog, 
OnEntryModified) );
         m_xURL->connect_changed( LINK(this, ODocumentLinkDialog, 
OnComboBoxModified) );
         m_xBrowseFile->connect_clicked( LINK(this, ODocumentLinkDialog, 
OnBrowseFile) );
@@ -81,6 +88,44 @@ namespace svx
     void ODocumentLinkDialog::validate( )
     {
         m_xOK->set_sensitive((!m_xName->get_text().isEmpty()) && 
(!m_xURL->get_active_text().isEmpty()));
+
+        if (m_xOK->get_sensitive())
+        {
+            Reference<container::XNameAccess> xItemList = 
officecfg::Office::DataAccess::RegisteredNames::get();
+            Sequence< OUString > lNodeNames = xItemList->getElementNames();
+
+            for (const OUString& sNodeName : lNodeNames)
+            {
+                Reference<css::beans::XPropertySet> xSet;
+                xItemList->getByName(sNodeName) >>= xSet;
+
+                OUString aDatabaseName;
+                if (xSet->getPropertySetInfo()->hasPropertyByName("Name"))
+                    xSet->getPropertyValue("Name") >>= aDatabaseName;
+
+                if (!aDatabaseName.isEmpty() && m_xName->get_text() == 
aDatabaseName)
+                {
+                    const OUString aConfigPath = 
officecfg::Office::DataAccess::RegisteredNames::path() + "/" + sNodeName;
+                    if 
(m_xReadWriteAccess->hasPropertyByHierarchicalName(aConfigPath + "/Name"))
+                    {
+                        css::beans::Property aProperty = 
m_xReadWriteAccess->getPropertyByHierarchicalName(aConfigPath + "/Name");
+                        bool bReadOnly = (aProperty.Attributes & 
css::beans::PropertyAttribute::READONLY) != 0;
+
+                        m_xURL->set_sensitive(!bReadOnly);
+                        m_xBrowseFile->set_sensitive(!bReadOnly);
+                    }
+
+                    if 
(m_xReadWriteAccess->hasPropertyByHierarchicalName(aConfigPath + "/Location"))
+                    {
+                        css::beans::Property aProperty = 
m_xReadWriteAccess->getPropertyByHierarchicalName(aConfigPath + "/Location");
+                        bool bReadOnly = (aProperty.Attributes & 
css::beans::PropertyAttribute::READONLY) != 0;
+
+                        m_xName->set_sensitive(!bReadOnly);
+                    }
+                    break;
+                }
+            }
+        }
     }
 
     IMPL_LINK_NOARG(ODocumentLinkDialog, OnOk, weld::Button&, void)
diff --git a/cui/source/options/doclinkdialog.hxx 
b/cui/source/options/doclinkdialog.hxx
index 371dc6504fe9..3ea0d5027d0f 100644
--- a/cui/source/options/doclinkdialog.hxx
+++ b/cui/source/options/doclinkdialog.hxx
@@ -21,6 +21,7 @@
 
 #include <vcl/weld.hxx>
 #include <svtools/inettbc.hxx>
+#include <com/sun/star/configuration/ReadWriteAccess.hpp>
 
 namespace svx
 {
@@ -30,6 +31,8 @@ namespace svx
     {
         Link<const OUString&,bool>      m_aNameValidator;
 
+        css::uno::Reference< css::configuration::XReadWriteAccess> 
m_xReadWriteAccess;
+
         std::unique_ptr<weld::Button> m_xBrowseFile;
         std::unique_ptr<weld::Entry> m_xName;
         std::unique_ptr<weld::Button> m_xOK;

Reply via email to