Adding codes to handle non-existing key or certificate
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index a63f9f9..b0276b7 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -73,6 +73,10 @@
m_contactManager->setDefaultIdentity(m_defaultIdentity);
m_nickName = m_defaultIdentity.get(-1).toUri();
m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
+ Name defaultCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(m_defaultIdentity);
+ if(defaultCertName.size() == 0)
+ showError(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
+
m_profileEditor = new ProfileEditor(m_contactManager);
m_profileEditor->setCurrentIdentity(m_defaultIdentity);
@@ -108,6 +112,9 @@
connect(ui->EditProfileButton, SIGNAL(clicked()),
this, SLOT(openProfileEditor()));
+ connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)),
+ this, SLOT(showError(const QString&)));
+
// connect(ui->AddContactButton, SIGNAL(clicked()),
// this, SLOT(openAddContactPanel()));
connect(ui->AddContactButton, SIGNAL(clicked()),
@@ -523,7 +530,14 @@
void
ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName)
{
+ // _LOG_DEBUG(identity.toStdString());
m_defaultIdentity = Name(identity.toStdString());
+ Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(m_defaultIdentity);
+ if(defaultKeyName.size() == 0)
+ showError(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
+ Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
+ if(defaultCertName.size() == 0)
+ showError(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
m_profileEditor->setCurrentIdentity(m_defaultIdentity);
m_nickName = nickName.toStdString();
m_handler->clearInterestFilter(m_inviteListenPrefix);
diff --git a/src/profileeditor.cpp b/src/profileeditor.cpp
index 7014794..f0f92d2 100644
--- a/src/profileeditor.cpp
+++ b/src/profileeditor.cpp
@@ -29,6 +29,7 @@
, ui(new Ui::ProfileEditor)
, m_tableModel(new QSqlTableModel())
, m_contactManager(contactManager)
+ , m_identityManager(ndn::Ptr<ndn::security::IdentityManager>::Create())
{
ui->setupUi(this);
@@ -82,6 +83,14 @@
void
ProfileEditor::onOkClicked()
{
+ Name defaultKeyName = m_identityManager->getPublicStorage()->getDefaultKeyNameForIdentity(m_currentIdentity);
+ if(defaultKeyName.size() == 0)
+ emit noKeyOrCert(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
+ Name defaultCertName = m_identityManager->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
+ if(defaultCertName.size() == 0)
+ emit noKeyOrCert(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
+
+
m_tableModel->submitAll();
m_contactManager->updateProfileData(m_currentIdentity);
this->hide();
diff --git a/src/profileeditor.h b/src/profileeditor.h
index 92ceaeb..7a5c6f7 100644
--- a/src/profileeditor.h
+++ b/src/profileeditor.h
@@ -16,6 +16,7 @@
#ifndef Q_MOC_RUN
#include "contact-manager.h"
+#include <ndn.cxx/security/identity/identity-manager.h>
#endif
namespace Ui {
@@ -49,11 +50,15 @@
void
onGetClicked();
+signals:
+ void
+ noKeyOrCert(const QString&);
private:
Ui::ProfileEditor *ui;
QSqlTableModel* m_tableModel;
ndn::Ptr<ContactManager> m_contactManager;
+ ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
ndn::Name m_currentIdentity;
};