summaryrefslogtreecommitdiff
path: root/xmlsecurity/source
diff options
context:
space:
mode:
authorTokieSan <eltokhy@aucegypt.edu>2023-06-20 22:52:03 +0300
committerThorsten Behrens <thorsten.behrens@allotropia.de>2023-06-24 18:19:18 +0200
commit17ba20e132d581c2298969451b510fb69c19f5fe (patch)
treec481d9c917f77aebb45c9711fbf77da9ffffadc5 /xmlsecurity/source
parent79bce686b7d3691deefcac23d5f8a090ff2e20ce (diff)
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.behrens@allotropia.de>
Diffstat (limited to 'xmlsecurity/source')
-rw-r--r--xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx75
1 files changed, 63 insertions, 12 deletions
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)