summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
Diffstat (limited to 'cui')
-rw-r--r--cui/source/inc/cuioptgenrl.hxx13
-rw-r--r--cui/source/options/optgenrl.cxx154
-rw-r--r--cui/uiconfig/ui/optuserpage.ui135
3 files changed, 193 insertions, 109 deletions
diff --git a/cui/source/inc/cuioptgenrl.hxx b/cui/source/inc/cuioptgenrl.hxx
index 0ee8cacb6c50..ffebb3acc1d7 100644
--- a/cui/source/inc/cuioptgenrl.hxx
+++ b/cui/source/inc/cuioptgenrl.hxx
@@ -34,12 +34,16 @@ private:
std::unique_ptr<weld::CheckButton> m_xUseDataCB;
std::unique_ptr<weld::Widget> m_xUseDataImg;
std::unique_ptr<weld::Widget> m_xCryptoFrame;
- std::unique_ptr<weld::ComboBox> m_xSigningKeyLB;
+ std::unique_ptr<weld::Entry> m_xSigningKeyLB;
std::unique_ptr<weld::Label> m_xSigningKeyFT;
std::unique_ptr<weld::Widget> m_xSigningKeyImg;
- std::unique_ptr<weld::ComboBox> m_xEncryptionKeyLB;
+ std::unique_ptr<weld::Button> m_xSigningKeyButton;
+ std::unique_ptr<weld::Button> m_xRemoveSigningKeyButton;
+ std::unique_ptr<weld::Entry> m_xEncryptionKeyLB;
std::unique_ptr<weld::Label> m_xEncryptionKeyFT;
std::unique_ptr<weld::Widget> m_xEncryptionKeyImg;
+ std::unique_ptr<weld::Button> m_xEncryptionKeyButton;
+ std::unique_ptr<weld::Button> m_xRemoveEncryptionKeyButton;
std::unique_ptr<weld::CheckButton> m_xEncryptToSelfCB;
std::unique_ptr<weld::Widget> m_xEncryptToSelfImg;
// rows
@@ -52,7 +56,12 @@ private:
unsigned nNameRow;
unsigned nShortNameField;
+ OUString msCurrentSigningKey;
+ OUString msCurrentEncryptionKey;
+
DECL_LINK( ModifyHdl_Impl, weld::Entry&, void );
+ DECL_LINK( ChooseKeyButtonHdl, weld::Button&, void );
+ DECL_LINK( RemoveKeyButtonHdl, weld::Button&, void );
bool GetData_Impl();
void SetData_Impl();
diff --git a/cui/source/options/optgenrl.cxx b/cui/source/options/optgenrl.cxx
index ff2216b6e41c..c956a9eb1ed8 100644
--- a/cui/source/options/optgenrl.cxx
+++ b/cui/source/options/optgenrl.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <comphelper/diagnose_ex.hxx>
#include <comphelper/string.hxx>
#include <comphelper/processfactory.hxx>
@@ -27,6 +28,7 @@
#endif
#include <com/sun/star/xml/crypto/SEInitializer.hpp>
#include <comphelper/xmlsechelper.hxx>
+#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
#include <i18nlangtag/languagetag.hxx>
#include <i18nlangtag/mslangid.hxx>
@@ -219,12 +221,16 @@ SvxGeneralTabPage::SvxGeneralTabPage(weld::Container* pPage, weld::DialogControl
, m_xUseDataCB(m_xBuilder->weld_check_button(u"usefordocprop"_ustr))
, m_xUseDataImg(m_xBuilder->weld_widget(u"lockusefordocprop"_ustr))
, m_xCryptoFrame(m_xBuilder->weld_widget( u"cryptography"_ustr))
- , m_xSigningKeyLB(m_xBuilder->weld_combo_box(u"signingkey"_ustr))
+ , m_xSigningKeyLB(m_xBuilder->weld_entry(u"signingkey"_ustr))
, m_xSigningKeyFT(m_xBuilder->weld_label(u"signingkeylabel"_ustr))
, m_xSigningKeyImg(m_xBuilder->weld_widget(u"locksigningkey"_ustr))
- , m_xEncryptionKeyLB(m_xBuilder->weld_combo_box(u"encryptionkey"_ustr))
+ , m_xSigningKeyButton(m_xBuilder->weld_button(u"picksigningkey"_ustr))
+ , m_xRemoveSigningKeyButton(m_xBuilder->weld_button(u"removesigningkey"_ustr))
+ , m_xEncryptionKeyLB(m_xBuilder->weld_entry(u"encryptionkey"_ustr))
, m_xEncryptionKeyFT(m_xBuilder->weld_label(u"encryptionkeylabel"_ustr))
, m_xEncryptionKeyImg(m_xBuilder->weld_widget(u"lockencryptionkey"_ustr))
+ , m_xEncryptionKeyButton(m_xBuilder->weld_button(u"pickencryptionkey"_ustr))
+ , m_xRemoveEncryptionKeyButton(m_xBuilder->weld_button(u"removeencryptionkey"_ustr))
, m_xEncryptToSelfCB(m_xBuilder->weld_check_button(u"encrypttoself"_ustr))
, m_xEncryptToSelfImg(m_xBuilder->weld_widget(u"lockencrypttoself"_ustr))
{
@@ -301,68 +307,89 @@ void SvxGeneralTabPage::InitCryptography()
{
#if HAVE_FEATURE_GPGME
m_xCryptoFrame->show();
+ m_xSigningKeyButton->connect_clicked(LINK(this, SvxGeneralTabPage, ChooseKeyButtonHdl));
+ m_xEncryptionKeyButton->connect_clicked(LINK(this, SvxGeneralTabPage, ChooseKeyButtonHdl));
+ m_xRemoveSigningKeyButton->connect_clicked(LINK(this, SvxGeneralTabPage, RemoveKeyButtonHdl));
+ m_xRemoveEncryptionKeyButton->connect_clicked(LINK(this, SvxGeneralTabPage, RemoveKeyButtonHdl));
+#endif
+
+}
+
+IMPL_LINK(SvxGeneralTabPage, ChooseKeyButtonHdl, weld::Button&, rButton, void)
+{
try
{
- uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext
- = xml::crypto::SEInitializer::create(comphelper::getProcessComponentContext())
- ->createSecurityContext("");
- uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContextGPG
- = xml::crypto::GPGSEInitializer::create(comphelper::getProcessComponentContext())
- ->createSecurityContext("");
- if (xSecurityContextGPG.is())
- {
- uno::Reference<xml::crypto::XSecurityEnvironment> xSE = xSecurityContextGPG->getSecurityEnvironment();
- uno::Sequence<uno::Reference<security::XCertificate>> xCertificates = xSE->getPersonalCertificates();
+ uno::Reference<security::XDocumentDigitalSignatures> xD(
+ security::DocumentDigitalSignatures::createDefault(
+ comphelper::getProcessComponentContext()));
+ xD->setParentWindow(GetDialogController()->getDialog()->GetXWindow());
- if (xCertificates.hasElements())
- {
- for (auto& xCert : asNonConstRange(xCertificates))
- {
- const auto aIssuer = comphelper::xmlsec::GetContentPart(
- xCert->getSubjectName(), xCert->getCertificateKind());
- m_xSigningKeyLB->append_text(aIssuer);
- m_xEncryptionKeyLB->append_text(aIssuer);
- }
- }
- }
+ OUString aDescription;
- if (xSecurityContext.is())
+ uno::Reference<security::XCertificate> xCertificate;
+ if (m_xSigningKeyButton.get() == &rButton)
+ {
+ xCertificate = xD->selectSigningCertificate(aDescription);
+ }
+ else if (m_xEncryptionKeyButton.get() == &rButton)
{
- uno::Reference<xml::crypto::XSecurityEnvironment> xSE = xSecurityContext->getSecurityEnvironment();
- uno::Sequence<uno::Reference<security::XCertificate>> xCertificates
- = xSE->getPersonalCertificates();
+ auto xCerts = xD->chooseEncryptionCertificate();
+ if(xCerts.hasElements())
+ xCertificate = xCerts[0];
+ }
- if (xCertificates.hasElements())
- {
- for (auto& xCert : asNonConstRange(xCertificates))
- {
- const auto aIssuer
- = comphelper::xmlsec::GetContentPart(xCert->getSubjectName(),
- xCert->getCertificateKind());
- m_xSigningKeyLB->append_text(aIssuer);
- }
- }
+ if(!xCertificate.is())
+ return;
+
+ OUString aKeyThumbprint
+ = comphelper::xmlsec::GetHexString(xCertificate->getSHA1Thumbprint(), "");
+ OUString aIssuer = comphelper::xmlsec::GetContentPart(xCertificate->getIssuerName(),
+ xCertificate->getCertificateKind());
+ OUString aSubject = comphelper::xmlsec::GetContentPart(xCertificate->getSubjectName(),
+ xCertificate->getCertificateKind());
+ OUString aKeyDisplayName;
+ switch (xCertificate->getCertificateKind())
+ {
+ case security::CertificateKind::CertificateKind_X509:
+ aKeyDisplayName = u"(X.509) "_ustr + aIssuer + u" "_ustr + aSubject;
+ break;
+ case security::CertificateKind::CertificateKind_OPENPGP:
+ aKeyDisplayName = u"(OpenPGP) "_ustr + aIssuer;
+ break;
+ default:
+ break;
}
- if (xSecurityContext.is() || xSecurityContextGPG.is())
+ if (m_xSigningKeyButton.get() == &rButton)
{
- //tdf#115015: wrap checkbox text and listboxes if necessary
- int nPrefWidth(m_xEncryptToSelfCB->get_preferred_size().Width());
- int nMaxWidth = m_xEncryptToSelfCB->get_approximate_digit_width() * 40;
- if (nPrefWidth > nMaxWidth)
- {
- m_xSigningKeyLB->set_size_request(nMaxWidth, -1);
- m_xEncryptionKeyLB->set_size_request(nMaxWidth, -1);
- m_xEncryptToSelfCB->set_label_wrap(true);
- m_xEncryptToSelfCB->set_size_request(nMaxWidth, -1);
- }
+ msCurrentSigningKey = aKeyThumbprint;
+ m_xSigningKeyLB->set_text(aKeyDisplayName);
+ }
+ else if (m_xEncryptionKeyButton.get() == &rButton)
+ {
+ msCurrentEncryptionKey = aKeyThumbprint;
+ m_xEncryptionKeyLB->set_text(aKeyDisplayName);
}
}
- catch ( uno::Exception const & )
- {}
-#endif
+ catch (const css::uno::Exception&)
+ {
+ TOOLS_WARN_EXCEPTION("cui.options", "" );
+ }
+}
+IMPL_LINK(SvxGeneralTabPage, RemoveKeyButtonHdl, weld::Button&, rButton, void)
+{
+ if (m_xRemoveSigningKeyButton.get() == &rButton)
+ {
+ msCurrentSigningKey.clear();
+ m_xSigningKeyLB->set_text(u""_ustr);
+ }
+ else if (m_xRemoveEncryptionKeyButton.get() == &rButton)
+ {
+ msCurrentEncryptionKey.clear();
+ m_xEncryptionKeyLB->set_text(u""_ustr);
+ }
}
void SvxGeneralTabPage::SetLinks ()
@@ -497,13 +524,10 @@ bool SvxGeneralTabPage::GetData_Impl()
}
#if HAVE_FEATURE_GPGME
- OUString aSK = m_xSigningKeyLB->get_active() == 0 ? OUString() //i.e. no key
- : m_xSigningKeyLB->get_active_text();
- OUString aEK = m_xEncryptionKeyLB->get_active() == 0 ? OUString()
- : m_xEncryptionKeyLB->get_active_text();
-
- aUserOpt.SetToken( UserOptToken::SigningKey, aSK );
- aUserOpt.SetToken( UserOptToken::EncryptionKey, aEK );
+ aUserOpt.SetToken( UserOptToken::SigningKey, msCurrentSigningKey );
+ aUserOpt.SetToken( UserOptToken::SigningKeyDisplayName, m_xSigningKeyLB->get_text() );
+ aUserOpt.SetToken( UserOptToken::EncryptionKey, msCurrentEncryptionKey );
+ aUserOpt.SetToken( UserOptToken::EncryptionKeyDisplayName, m_xEncryptionKeyLB->get_text() );
aUserOpt.SetBoolValue( UserOptToken::EncryptToSelf, m_xEncryptToSelfCB->get_active() );
bModified |= m_xSigningKeyLB->get_value_changed_from_saved() ||
@@ -550,12 +574,12 @@ void SvxGeneralTabPage::SetData_Impl()
#if HAVE_FEATURE_GPGME
bEnable = !aUserOpt.IsTokenReadonly(UserOptToken::SigningKey);
- m_xSigningKeyLB->set_sensitive(bEnable);
+ m_xSigningKeyButton->set_sensitive(bEnable);
m_xSigningKeyFT->set_sensitive(bEnable);
m_xSigningKeyImg->set_visible(!bEnable);
bEnable = !aUserOpt.IsTokenReadonly(UserOptToken::EncryptionKey);
- m_xEncryptionKeyLB->set_sensitive(bEnable);
+ m_xEncryptionKeyButton->set_sensitive(bEnable);
m_xEncryptionKeyFT->set_sensitive(bEnable);
m_xEncryptionKeyImg->set_visible(!bEnable);
@@ -563,13 +587,11 @@ void SvxGeneralTabPage::SetData_Impl()
m_xEncryptToSelfCB->set_sensitive(bEnable);
m_xEncryptToSelfImg->set_visible(!bEnable);
- OUString aSK = aUserOpt.GetToken(UserOptToken::SigningKey);
- aSK.isEmpty() ? m_xSigningKeyLB->set_active( 0 ) //i.e. 'No Key'
- : m_xSigningKeyLB->set_active_text( aSK );
+ msCurrentSigningKey = aUserOpt.GetToken(UserOptToken::SigningKey);
+ m_xSigningKeyLB->set_text(aUserOpt.GetToken(UserOptToken::SigningKeyDisplayName));
- OUString aEK = aUserOpt.GetToken(UserOptToken::EncryptionKey);
- aEK.isEmpty() ? m_xEncryptionKeyLB->set_active( 0 ) //i.e. 'No Key'
- : m_xEncryptionKeyLB->set_active_text( aEK );
+ msCurrentEncryptionKey = aUserOpt.GetToken(UserOptToken::EncryptionKey);
+ m_xEncryptionKeyLB->set_text(aUserOpt.GetToken(UserOptToken::EncryptionKeyDisplayName));
m_xEncryptToSelfCB->set_active( aUserOpt.GetEncryptToSelf() );
#endif
diff --git a/cui/uiconfig/ui/optuserpage.ui b/cui/uiconfig/ui/optuserpage.ui
index 0c69fb176123..f486669fd4e5 100644
--- a/cui/uiconfig/ui/optuserpage.ui
+++ b/cui/uiconfig/ui/optuserpage.ui
@@ -1,7 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.40.0 -->
<interface domain="cui">
<requires lib="gtk+" version="3.20"/>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="icon-name">sfx2/res/deleterow.png</property>
+ </object>
+ <object class="GtkImage" id="image2">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="icon-name">sfx2/res/deleterow.png</property>
+ </object>
<object class="GtkBox" id="OptUserPage">
<property name="visible">True</property>
<property name="can-focus">False</property>
@@ -1086,7 +1096,7 @@
<property name="label-xalign">0</property>
<property name="shadow-type">none</property>
<child>
- <!-- n-columns=3 n-rows=3 -->
+ <!-- n-columns=5 n-rows=3 -->
<object class="GtkGrid" id="grid14">
<property name="visible">True</property>
<property name="can-focus">False</property>
@@ -1123,44 +1133,6 @@
</packing>
</child>
<child>
- <object class="GtkComboBoxText" id="encryptionkey">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="hexpand">True</property>
- <items>
- <item translatable="yes" context="optuserpage|liststore1">No key</item>
- </items>
- <child internal-child="accessible">
- <object class="AtkObject" id="encryptionkey-atkobject">
- <property name="AtkObject::accessible-description" translatable="yes" context="extended tip | encryptionkey">Select your OpenPGP key from the drop-down list for encrypting ODF documents.</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="left-attach">2</property>
- <property name="top-attach">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBoxText" id="signingkey">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="hexpand">True</property>
- <items>
- <item translatable="yes" context="optuserpage|liststore1">No key</item>
- </items>
- <child internal-child="accessible">
- <object class="AtkObject" id="signingkey-atkobject">
- <property name="AtkObject::accessible-description" translatable="yes" context="extended tip | signingkey">Select your key from the drop-down list for signing ODF documents.</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="left-attach">2</property>
- <property name="top-attach">0</property>
- </packing>
- </child>
- <child>
<object class="GtkCheckButton" id="encrypttoself">
<property name="label" translatable="yes" context="optuserpage|encrypttoself">When _encrypting documents, always encrypt to self</property>
<property name="visible">True</property>
@@ -1177,7 +1149,7 @@
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
- <property name="width">2</property>
+ <property name="width">3</property>
</packing>
</child>
<child>
@@ -1219,6 +1191,87 @@
<property name="top-attach">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkEntry" id="signingkey">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="editable">False</property>
+ <property name="placeholder-text" translatable="yes" context="optuserpage|signingkey">No key</property>
+ </object>
+ <packing>
+ <property name="left-attach">2</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="encryptionkey">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="editable">False</property>
+ <property name="placeholder-text" translatable="yes" context="optuserpage|encryptionkey">No key</property>
+ </object>
+ <packing>
+ <property name="left-attach">2</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="picksigningkey">
+ <property name="label" translatable="yes" context="optuserpage|picksigningkey">Select...</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">4</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="pickencryptionkey">
+ <property name="label" translatable="yes" context="optuserpage|pickencryptionkey">Select...</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">4</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="removesigningkey">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ <property name="tooltip-text" translatable="yes" context="optuserpage|removesigningkey">Clear Signing Key</property>
+ <property name="image">image1</property>
+ <property name="always-show-image">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">3</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="removeencryptionkey">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ <property name="tooltip-text" translatable="yes" context="optuserpage|removeencryptionkey">Clear Encryption Key</property>
+ <property name="image">image2</property>
+ <property name="always-show-image">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">3</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
</object>
</child>
<child type="label">