Reorganize code.

Move KeyEdit::IsOurKey to Tools::IsOurKey.
This commit is contained in:
SET
2020-11-14 11:25:00 +01:00
parent bb4df1423a
commit 6ac7ea7c0f
5 changed files with 32 additions and 22 deletions

View File

@@ -253,6 +253,7 @@ void K7Main::DisplayKeys(const vector<GpgME::Key>& kList, const WString& grpLabe
{ {
WTreeTableNode * grpNode = new WTreeTableNode(grpLabel); WTreeTableNode * grpNode = new WTreeTableNode(grpLabel);
m_ttbKeys->treeRoot()->addChildNode(unique_ptr<WTreeTableNode> (grpNode)); m_ttbKeys->treeRoot()->addChildNode(unique_ptr<WTreeTableNode> (grpNode));
vector<WString> ourKeys = m_config->PrivateKeyIds();
for (uint i = 0; i < kList.size(); i++) for (uint i = 0; i < kList.size(); i++)
{ {
const GpgME::Key k = kList.at(i); const GpgME::Key k = kList.at(i);
@@ -272,7 +273,7 @@ void K7Main::DisplayKeys(const vector<GpgME::Key>& kList, const WString& grpLabe
* Here we allow the owner trust level of primary keys to be changed anytime. * Here we allow the owner trust level of primary keys to be changed anytime.
* Kleopatra doesn't do that for primary keys having ultimate trust level. * Kleopatra doesn't do that for primary keys having ultimate trust level.
*/ */
bool isOurKey = m_keyEdit->IsOurKey(k.primaryFingerprint()); bool isOurKey = Tools::IsOurKey(k.primaryFingerprint(), ourKeys);
if (!isOurKey || (isOurKey && k.hasSecret())) { if (!isOurKey || (isOurKey && k.hasSecret())) {
lblOwnerTrust->doubleClicked().connect(std::bind(&KeyEdit::OnOwnerTrustDoubleClicked, m_keyEdit, keyNode, k.hasSecret())); lblOwnerTrust->doubleClicked().connect(std::bind(&KeyEdit::OnOwnerTrustDoubleClicked, m_keyEdit, keyNode, k.hasSecret()));
lblOwnerTrust->setToolTip(TR("TTTDoubleCLick")); lblOwnerTrust->setToolTip(TR("TTTDoubleCLick"));
@@ -386,9 +387,10 @@ void K7Main::DisplaySubKeys(const WString& fullKeyID, bool secret)
rootNode->setChildCountPolicy(ChildCountPolicy::Enabled); rootNode->setChildCountPolicy(ChildCountPolicy::Enabled);
m_ttbSubKeys->setTreeRoot(unique_ptr<WTreeTableNode> (rootNode), TR("SubKeys")); m_ttbSubKeys->setTreeRoot(unique_ptr<WTreeTableNode> (rootNode), TR("SubKeys"));
rootNode->expand(); rootNode->expand();
vector<WString> ourKeys = m_config->PrivateKeyIds();
bool canEditExpiry = m_config->CanEditExpiryTime() bool canEditExpiry = m_config->CanEditExpiryTime()
&& Tools::KeyHasSecret(k.primaryFingerprint()) && Tools::KeyHasSecret(k.primaryFingerprint())
&& m_keyEdit->IsOurKey(k.primaryFingerprint()); && Tools::IsOurKey(k.primaryFingerprint(), ourKeys);
for (uint i = 0; i < k.numSubkeys(); i++) for (uint i = 0; i < k.numSubkeys(); i++)
{ {
Subkey sk = k.subkey(i); Subkey sk = k.subkey(i);

View File

@@ -39,7 +39,9 @@ void KeyEdit::OnOwnerTrustDoubleClicked(WTreeTableNode * keyNode, bool keyHasSec
* not be editable by anyone. * not be editable by anyone.
*/ */
WText * lblFpr = static_cast<WText*> (keyNode->columnWidget(3)); WText * lblFpr = static_cast<WText*> (keyNode->columnWidget(3));
if (!IsOurKey(lblFpr->text()) && Tools::KeyHasSecret(lblFpr->text())) { vector<WString> ourKeys = m_owner->m_config->PrivateKeyIds();
if (!Tools::IsOurKey(lblFpr->text(), ourKeys)
&& Tools::KeyHasSecret(lblFpr->text())) {
m_owner->m_tmwMessage->SetText(TR("OwnerTrustReadOnly")); m_owner->m_tmwMessage->SetText(TR("OwnerTrustReadOnly"));
return; return;
} }
@@ -118,18 +120,6 @@ void KeyEdit::FillOwnerTrustCombo(WComboBox * cmb, bool keyHasSecret)
cmb->setModelColumn(1); cmb->setModelColumn(1);
} }
bool KeyEdit::IsOurKey(const WString& fpr)
{
vector<WString> ourKeys = m_owner->m_config->PrivateKeyIds();
vector<WString> ::iterator it;
for (it = ourKeys.begin(); it != ourKeys.end(); it++)
{
if (*it == fpr)
return true;
}
return false;
}
void KeyEdit::OnUidValidityClicked(WTreeTableNode* uidNode, vector<WString>& privateKeys, const WString& targetKeyFpr) void KeyEdit::OnUidValidityClicked(WTreeTableNode* uidNode, vector<WString>& privateKeys, const WString& targetKeyFpr)
{ {
if (targetKeyFpr != m_targetUidValidityKeyFpr) { if (targetKeyFpr != m_targetUidValidityKeyFpr) {

View File

@@ -41,12 +41,6 @@ public:
* @param keyHasSecret * @param keyHasSecret
*/ */
void OnOwnerTrustBlurred(WTreeTableNode * keyNode, bool keyHasSecret); void OnOwnerTrustBlurred(WTreeTableNode * keyNode, bool keyHasSecret);
/**
* If the fingerprint is that of a private key we manage, returns true.
* @param fpr
* @return
*/
bool IsOurKey(const WString& fpr);
/** /**
* Shows a popup with parameters for key certification. * Shows a popup with parameters for key certification.
* @param uidNode * @param uidNode

View File

@@ -104,3 +104,20 @@ bool Tools::KeyHasSecret(const WString& fpr)
} }
return (!k.isNull()); return (!k.isNull());
} }
bool Tools::IsFound(const WString& item, vector<WString>& items)
{
// std:find should be more aesthetic.
vector<WString> ::iterator it;
for (it = items.begin(); it != items.end(); it++)
{
if ((*it) == item)
return true;
}
return false;
}
bool Tools::IsOurKey(const WString& fpr, vector<WString>& ourPrivKeys)
{
return IsFound(fpr, ourPrivKeys);
}

View File

@@ -44,9 +44,16 @@ public:
static WString GetUidStatus(const GpgME::UserID& uid); static WString GetUidStatus(const GpgME::UserID& uid);
static WString GetSigStatus(const GpgME::UserID::Signature& sig); static WString GetSigStatus(const GpgME::UserID::Signature& sig);
static bool KeyHasSecret(const WString& fpr); static bool KeyHasSecret(const WString& fpr);
/**
* If the fingerprint is that of a private key we manage, returns true.
* @param fpr
* @param ourPrivKeys
* @return
*/
static bool IsOurKey(const WString& fpr, vector<WString>& ourPrivKeys);
private: private:
static bool IsFound(const WString& item, vector<WString>& items);
}; };
#endif /* TOOLS_H */ #endif /* TOOLS_H */