xmlsecurity/inc/digitalsignaturesdialog.hxx            |    1 
 xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx |   75 ++++++++++++++---
 xmlsecurity/uiconfig/ui/digitalsignaturesdialog.ui     |    8 -
 3 files changed, 68 insertions(+), 16 deletions(-)

New commits:
commit 17ba20e132d581c2298969451b510fb69c19f5fe
Author:     TokieSan <elto...@aucegypt.edu>
AuthorDate: Tue Jun 20 22:52:03 2023 +0300
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Sat Jun 24 18:19:18 2023 +0200

    Certificate Manager button is hidden in case no manager exists.
    
    A new function is implemented to check for that in
    digitalsignaturesdialog.cxx
    
    Change-Id: I4cf1c710e6a145e8f0d10716cb81394bdcf7a74f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153367
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/xmlsecurity/inc/digitalsignaturesdialog.hxx 
b/xmlsecurity/inc/digitalsignaturesdialog.hxx
index 218c3e99c8b3..21b048117670 100644
--- a/xmlsecurity/inc/digitalsignaturesdialog.hxx
+++ b/xmlsecurity/inc/digitalsignaturesdialog.hxx
@@ -89,6 +89,7 @@ private:
     void                ImplGetSignatureInformations(bool bUseTempStream, bool 
bCacheLastSignature);
     void                ImplFillSignaturesBox();
     void                ImplShowSignaturesDetails();
+    bool                IsThereCertificateMgr();
 
     css::uno::Reference<css::security::XCertificate> getCertificate(const 
SignatureInformation& rInfo);
     css::uno::Reference<css::xml::crypto::XSecurityEnvironment> 
getSecurityEnvironmentForCertificate(
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx 
b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 0a306a008db0..ed73366234df 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -115,6 +115,16 @@ namespace
 
         m_nODF = nTmp;
     }
+    const std::vector<std::u16string_view> aGUIServersWindows = { 
u"Gpg4win\\kleopatra.exe",
+                                                   
u"Gpg4win\\bin\\kleopatra.exe",
+                                                   
u"GNU\\GnuPG\\kleopatra.exe",
+                                                   
u"GNU\\GnuPG\\launch-gpa.exe",
+                                                   u"GNU\\GnuPG\\gpa.exe",
+                                                   u"GnuPG\\bin\\gpa.exe",
+                                                   
u"GNU\\GnuPG\\bin\\kleopatra.exe",
+                                                   
u"GNU\\GnuPG\\bin\\launch-gpa.exe",
+                                                   
u"GNU\\GnuPG\\bin\\gpa.exe"};
+    const std::vector<std::u16string_view> aGUIServersNix = { u"kleopatra", 
u"seahorse", u"gpa", u"kgpg" };
 }
 
 DigitalSignaturesDialog::DigitalSignaturesDialog(
@@ -201,6 +211,11 @@ DigitalSignaturesDialog::DigitalSignaturesDialog(
         m_xRemoveBtn->hide();
         m_xStartCertMgrBtn->hide();
     }
+
+    if ( !IsThereCertificateMgr() )
+    {
+        m_xStartCertMgrBtn->hide();
+    }
 }
 
 DigitalSignaturesDialog::~DigitalSignaturesDialog()
@@ -473,22 +488,54 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, RemoveButtonHdl, 
weld::Button&, void)
     }
 }
 
+bool DigitalSignaturesDialog::IsThereCertificateMgr()
+{
+    static std::vector<std::u16string_view> aGUIServers;
+#ifdef _WIN32
+    static const OUString aPath = [] {
+        sal::systools::CoTaskMemAllocated<wchar_t> sPath;
+        HRESULT hr
+            = SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, KF_FLAG_DEFAULT, 
nullptr, &sPath);
+        if (SUCCEEDED(hr))
+            return OUString(o3tl::toU(sPath));
+        return OUString();
+    }();
+    if (aPath.isEmpty())
+        return false;
+    aGUIServers = aGUIServersWindows;
+#else
+    const char* cPath = getenv("PATH");
+    if (!cPath)
+        return false;
+    OUString aPath(cPath, strlen(cPath), osl_getThreadTextEncoding());
+    aGUIServers = aGUIServersNix;
+#endif
+
+    if (aGUIServers.empty())
+        return false;
+
+    OUString sFoundGUIServer, sExecutable;
+
+    for ( auto const &rServer : aGUIServers )
+    {
+        osl::FileBase::RC searchError = 
osl::File::searchFileURL(OUString(rServer), aPath, sFoundGUIServer );
+        if (searchError == osl::FileBase::E_None)
+        {
+            osl::File::getSystemPathFromFileURL( sFoundGUIServer, sExecutable 
);
+            break;
+        }
+    }
+
+    return ( !sExecutable.isEmpty() );
+}
+
 IMPL_LINK_NOARG(DigitalSignaturesDialog, CertMgrButtonHdl, weld::Button&, void)
 {
+    static std::vector<std::u16string_view> aGUIServers;
 #ifdef _WIN32
     // FIXME: call GpgME::dirInfo("bindir") somewhere in
     // SecurityEnvironmentGpg or whatnot
     // FIXME: perhaps poke GpgME for uiserver, and hope it returns something 
useful?
-    static const std::u16string_view aGUIServers[] = { 
u"Gpg4win\\kleopatra.exe",
-                                                   
u"Gpg4win\\bin\\kleopatra.exe",
-                                                   
u"GNU\\GnuPG\\kleopatra.exe",
-                                                   
u"GNU\\GnuPG\\launch-gpa.exe",
-                                                   u"GNU\\GnuPG\\gpa.exe",
-                                                   u"GnuPG\\bin\\gpa.exe",
-                                                   
u"GNU\\GnuPG\\bin\\kleopatra.exe",
-                                                   
u"GNU\\GnuPG\\bin\\launch-gpa.exe",
-                                                   u"GNU\\GnuPG\\bin\\gpa.exe",
-                                                 };
     static const OUString aPath = [] {
         sal::systools::CoTaskMemAllocated<wchar_t> sPath;
         HRESULT hr
@@ -499,17 +546,21 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, 
CertMgrButtonHdl, weld::Button&, void)
     }();
     if (aPath.isEmpty())
         return;
+    aGUIServers = aGUIServersWindows;
 #else
-    static const std::u16string_view aGUIServers[] = { u"kleopatra", 
u"seahorse", u"gpa", u"kgpg" };
     const char* cPath = getenv("PATH");
     if (!cPath)
         return;
     OUString aPath(cPath, strlen(cPath), osl_getThreadTextEncoding());
+    aGUIServers = aGUIServersNix;
 #endif
 
+    if (aGUIServers.empty())
+        return;
+
     OUString sFoundGUIServer, sExecutable;
 
-    for ( auto const &rServer : aGUIServers )
+    for ( auto const &rServer : aGUIServers)
     {
         osl::FileBase::RC searchError = 
osl::File::searchFileURL(OUString(rServer), aPath, sFoundGUIServer );
         if (searchError == osl::FileBase::E_None)
diff --git a/xmlsecurity/uiconfig/ui/digitalsignaturesdialog.ui 
b/xmlsecurity/uiconfig/ui/digitalsignaturesdialog.ui
index cf2404c613dd..44d0c2ff3aa5 100644
--- a/xmlsecurity/uiconfig/ui/digitalsignaturesdialog.ui
+++ b/xmlsecurity/uiconfig/ui/digitalsignaturesdialog.ui
@@ -210,7 +210,7 @@
                 <property name="can_focus">False</property>
                 <property name="spacing">12</property>
                 <property name="homogeneous">True</property>
-                <property name="layout_style">spread</property>
+                <property name="layout_style">end</property>
                 <child>
                   <object class="GtkButton" id="view">
                     <property name="label" translatable="yes" 
context="digitalsignaturesdialog|view">View Certificate...</property>
@@ -224,7 +224,7 @@
                     </child>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
+                    <property name="expand">True</property>
                     <property name="fill">True</property>
                     <property name="position">0</property>
                   </packing>
@@ -243,7 +243,7 @@
                     </child>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
+                    <property name="expand">True</property>
                     <property name="fill">True</property>
                     <property name="position">1</property>
                   </packing>
@@ -261,7 +261,7 @@
                     </child>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
+                    <property name="expand">True</property>
                     <property name="fill">True</property>
                     <property name="position">2</property>
                   </packing>

Reply via email to