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);
m_ttbKeys->treeRoot()->addChildNode(unique_ptr<WTreeTableNode> (grpNode));
vector<WString> ourKeys = m_config->PrivateKeyIds();
for (uint i = 0; i < kList.size(); 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.
* 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())) {
lblOwnerTrust->doubleClicked().connect(std::bind(&KeyEdit::OnOwnerTrustDoubleClicked, m_keyEdit, keyNode, k.hasSecret()));
lblOwnerTrust->setToolTip(TR("TTTDoubleCLick"));
@@ -386,9 +387,10 @@ void K7Main::DisplaySubKeys(const WString& fullKeyID, bool secret)
rootNode->setChildCountPolicy(ChildCountPolicy::Enabled);
m_ttbSubKeys->setTreeRoot(unique_ptr<WTreeTableNode> (rootNode), TR("SubKeys"));
rootNode->expand();
vector<WString> ourKeys = m_config->PrivateKeyIds();
bool canEditExpiry = m_config->CanEditExpiryTime()
&& Tools::KeyHasSecret(k.primaryFingerprint())
&& m_keyEdit->IsOurKey(k.primaryFingerprint());
&& Tools::IsOurKey(k.primaryFingerprint(), ourKeys);
for (uint i = 0; i < k.numSubkeys(); i++)
{
Subkey sk = k.subkey(i);

View File

@@ -39,7 +39,9 @@ void KeyEdit::OnOwnerTrustDoubleClicked(WTreeTableNode * keyNode, bool keyHasSec
* not be editable by anyone.
*/
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"));
return;
}
@@ -118,18 +120,6 @@ void KeyEdit::FillOwnerTrustCombo(WComboBox * cmb, bool keyHasSecret)
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)
{
if (targetKeyFpr != m_targetUidValidityKeyFpr) {

View File

@@ -41,12 +41,6 @@ public:
* @param 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.
* @param uidNode

View File

@@ -104,3 +104,20 @@ bool Tools::KeyHasSecret(const WString& fpr)
}
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 GetSigStatus(const GpgME::UserID::Signature& sig);
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:
static bool IsFound(const WString& item, vector<WString>& items);
};
#endif /* TOOLS_H */