diff options
author | Katarina Behrens <Katarina.Behrens@cib.de> | 2017-12-14 13:14:02 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-12-19 01:25:48 +0100 |
commit | 5c66c0711286bcfa9d3ab4a87777c2af9e1c25d9 (patch) | |
tree | fa8a93602c18c60984f9e4aee7afb06fc15d4148 | |
parent | df4fac1dbce087bbd01bbec242b93c72edcef74b (diff) |
Read/write 'encrypt to self' bit
use some template functions to avoid duplicate code
Change-Id: Ia178ea3a0561e34e0431749262f5f8f1f49b4fe7
Reviewed-on: https://gerrit.libreoffice.org/46693
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | cui/source/options/optgenrl.cxx | 9 | ||||
-rw-r--r-- | include/unotools/useroptions.hxx | 5 | ||||
-rw-r--r-- | unotools/source/config/useroptions.cxx | 50 |
3 files changed, 57 insertions, 7 deletions
diff --git a/cui/source/options/optgenrl.cxx b/cui/source/options/optgenrl.cxx index 83a98e60c7b0..c25144f04266 100644 --- a/cui/source/options/optgenrl.cxx +++ b/cui/source/options/optgenrl.cxx @@ -443,11 +443,14 @@ bool SvxGeneralTabPage::GetData_Impl() : m_pSigningKeyLB->GetSelectedEntry(); OUString aEK = m_pEncryptionKeyLB->GetSelectedEntryPos() == 0 ? OUString() : m_pEncryptionKeyLB->GetSelectedEntry(); + aUserOpt.SetToken( UserOptToken::SigningKey, aSK ); aUserOpt.SetToken( UserOptToken::EncryptionKey, aEK ); + aUserOpt.SetBoolValue( UserOptToken::EncryptToSelf, m_pEncryptToSelfCB->IsChecked() ); - bModified |= m_pSigningKeyLB->IsValueChangedFromSaved(); - bModified |= m_pEncryptionKeyLB->IsValueChangedFromSaved(); + bModified |= m_pSigningKeyLB->IsValueChangedFromSaved() || + m_pEncryptionKeyLB->IsValueChangedFromSaved() || + m_pEncryptToSelfCB->IsValueChangedFromSaved(); #endif return bModified; @@ -489,6 +492,8 @@ void SvxGeneralTabPage::SetData_Impl() OUString aEK = aUserOpt.GetToken(UserOptToken::EncryptionKey); aEK.isEmpty() ? m_pEncryptionKeyLB->SelectEntryPos( 0 ) //i.e. 'No Key' : m_pEncryptionKeyLB->SelectEntry( aEK ); + + m_pEncryptToSelfCB->Check( aUserOpt.GetEncryptToSelf() ); #endif } diff --git a/include/unotools/useroptions.hxx b/include/unotools/useroptions.hxx index 946ba8d34c10..60c18df65ae2 100644 --- a/include/unotools/useroptions.hxx +++ b/include/unotools/useroptions.hxx @@ -47,7 +47,8 @@ enum class UserOptToken Apartment = 16, SigningKey = 17, EncryptionKey = 18, - LAST = EncryptionKey, + EncryptToSelf = 19, + LAST = EncryptToSelf, }; // class SvtUserOptions -------------------------------------------------- @@ -78,12 +79,14 @@ public: OUString GetEmail () const; OUString GetSigningKey () const; OUString GetEncryptionKey () const; + bool GetEncryptToSelf () const; OUString GetFullName () const; bool IsTokenReadonly (UserOptToken nToken) const; OUString GetToken (UserOptToken nToken) const; void SetToken (UserOptToken nToken, OUString const& rNewToken); + void SetBoolValue (UserOptToken nToken, bool bNewValue); private: class Impl; diff --git a/unotools/source/config/useroptions.cxx b/unotools/source/config/useroptions.cxx index e19168da2885..adf58180204a 100644 --- a/unotools/source/config/useroptions.cxx +++ b/unotools/source/config/useroptions.cxx @@ -67,7 +67,8 @@ static o3tl::enumarray<UserOptToken, char const *> vOptionNames = { "fathersname", // UserOptToken::FathersName "apartment", // UserOptToken::Apartment "signingkey", // UserOptToken::SigningKey - "encryptionkey" // UserOptToken::EncryptionKey + "encryptionkey", // UserOptToken::EncryptionKey + "encrypttoself" // UserOptToken::EncryptToSelf }; std::weak_ptr<SvtUserOptions::Impl> SvtUserOptions::xSharedImpl; @@ -96,12 +97,19 @@ public: bool IsTokenReadonly (UserOptToken nToken) const; OUString GetToken (UserOptToken nToken) const; void SetToken (UserOptToken nToken, OUString const& rNewToken); + bool GetBoolValue (UserOptToken nToken) const; + void SetBoolValue (UserOptToken nToken, bool& bNewValue); void Notify (); private: uno::Reference<util::XChangesListener> m_xChangeListener; uno::Reference<container::XNameAccess> m_xCfg; uno::Reference<beans::XPropertySet> m_xData; + + template < typename ValueType > + ValueType GetValue_Impl( UserOptToken nToken ) const; + template < typename ValueType > + void SetValue_Impl( UserOptToken nToken, ValueType const& rNewValue ); }; void SvtUserOptions::ChangeListener::changesOccurred (util::ChangesEvent const& rEvent) @@ -153,9 +161,10 @@ SvtUserOptions::Impl::Impl() : } } -OUString SvtUserOptions::Impl::GetToken (UserOptToken nToken) const +template < typename ValueType > +ValueType SvtUserOptions::Impl::GetValue_Impl (UserOptToken nToken) const { - OUString sToken; + ValueType sToken = ValueType(); try { if (m_xData.is()) @@ -168,7 +177,8 @@ OUString SvtUserOptions::Impl::GetToken (UserOptToken nToken) const return sToken; } -void SvtUserOptions::Impl::SetToken (UserOptToken nToken, OUString const& sToken) +template < typename ValueType > +void SvtUserOptions::Impl::SetValue_Impl (UserOptToken nToken, ValueType const& sToken) { try { @@ -182,6 +192,26 @@ void SvtUserOptions::Impl::SetToken (UserOptToken nToken, OUString const& sToken } } +OUString SvtUserOptions::Impl::GetToken (UserOptToken nToken) const +{ + return GetValue_Impl<OUString>( nToken ); +} + +void SvtUserOptions::Impl::SetToken (UserOptToken nToken, OUString const& sToken) +{ + SetValue_Impl<OUString>( nToken, sToken ); +} + +bool SvtUserOptions::Impl::GetBoolValue (UserOptToken nToken) const +{ + return GetValue_Impl<bool>( nToken ); +} + +void SvtUserOptions::Impl::SetBoolValue (UserOptToken nToken, bool& bNewValue) +{ + SetValue_Impl<bool>( nToken, bNewValue ); +} + OUString SvtUserOptions::Impl::GetFullName () const { OUString sFullName; @@ -299,6 +329,18 @@ void SvtUserOptions::SetToken (UserOptToken nToken, OUString const& rNewToken) xImpl->SetToken(nToken, rNewToken); } +void SvtUserOptions::SetBoolValue (UserOptToken nToken, bool bNewValue) +{ + osl::MutexGuard aGuard(GetInitMutex()); + xImpl->SetBoolValue(nToken, bNewValue); +} + +bool SvtUserOptions::GetEncryptToSelf() const +{ + osl::MutexGuard aGuard(GetInitMutex()); + return xImpl->GetBoolValue(UserOptToken::EncryptToSelf); +} + OUString SvtUserOptions::GetFullName () const { osl::MutexGuard aGuard(GetInitMutex()); |