Fixing the Add/Delete Contact bug, now when a contact is added and removed, the panelPolicyManager will add/remove the contact into/from trust anchors

Change-Id: Ia7a8bc5c6cbe1744018410c0ca0019db3e5d3994
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index 13e4adb..2d722d7 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -629,6 +629,7 @@
 
   try{
     m_contactStorage->addContact(contactItem);
+    emit contactAdded(contactItem.getNameSpace());
   }catch(exception& e){
     emit warning(e.what());
     _LOG_ERROR("Exception: " << e.what());
@@ -636,6 +637,15 @@
   }
 }
 
+void
+ContactManager::removeContact(const ndn::Name& contactNameSpace)
+{
+  Ptr<ContactItem> contact = getContact(contactNameSpace);
+  if(contact == NULL)
+    return;
+  m_contactStorage->removeContact(contactNameSpace);
+  emit contactRemoved(contact->getPublicKeyName());
+}
 
 
 #if WAF
diff --git a/src/contact-manager.h b/src/contact-manager.h
index 6de23d4..a19135f 100644
--- a/src/contact-manager.h
+++ b/src/contact-manager.h
@@ -84,6 +84,10 @@
   void
   addContact(const ndn::security::IdentityCertificate& idCert, const Profile& profile);
 
+  void
+  removeContact(const ndn::Name& contactNameSpace);
+  
+
 private:
   void
   setKeychain();
@@ -168,6 +172,12 @@
   void
   warning(QString msg);
 
+  void
+  contactRemoved(const ndn::Name& identity);
+
+  void
+  contactAdded(const ndn::Name& identity);                                         
+
 private slots:
   
   
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index 4ee8d71..e9fafaa 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -148,6 +148,11 @@
           this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::security::IdentityCertificate&)));
   connect(m_invitationDialog, SIGNAL(invitationRejected(const ChronosInvitation&)),
           this, SLOT(rejectInvitation(const ChronosInvitation&)));
+  
+  connect(&*m_contactManager, SIGNAL(contactAdded(const ndn::Name&)),
+          this, SLOT(addContactIntoPanelPolicy(const ndn::Name&)));
+  connect(&*m_contactManager, SIGNAL(contactRemoved(const ndn::Name&)),
+          this, SLOT(removeContactFromPanelPolicy(const ndn::Name&)));
 
   connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)),
           this, SLOT(updateDefaultIdentity(const QString&, const QString&)));
@@ -644,6 +649,18 @@
 { m_invitationDialog->show(); }
 
 void
+ContactPanel::addContactIntoPanelPolicy(const Name& contactNameSpace)
+{
+  Ptr<ContactItem> contact = m_contactManager->getContact(contactNameSpace);
+  if(contact != NULL)
+    m_panelPolicyManager->addTrustAnchor(contact->getSelfEndorseCertificate());
+}
+
+void
+ContactPanel::removeContactFromPanelPolicy(const Name& keyName)
+{ m_panelPolicyManager->removeTrustAnchor(keyName); }
+
+void
 ContactPanel::refreshContactList()
 {
   m_contactList = m_contactManager->getContactItemList();
diff --git a/src/contactpanel.h b/src/contactpanel.h
index d36e547..b171e54 100644
--- a/src/contactpanel.h
+++ b/src/contactpanel.h
@@ -197,6 +197,11 @@
   void
   removeChatDialog(const ndn::Name& chatroomName);
 
+  void 
+  addContactIntoPanelPolicy(const ndn::Name& nameSpace);
+
+  void 
+  removeContactFromPanelPolicy(const ndn::Name& keyName);
   
 
 private:
diff --git a/src/panel-policy-manager.cpp b/src/panel-policy-manager.cpp
index ecb03b1..96900e7 100644
--- a/src/panel-policy-manager.cpp
+++ b/src/panel-policy-manager.cpp
@@ -180,6 +180,12 @@
   m_trustAnchors.insert(pair <Name, Publickey > (selfEndorseCertificate.getPublicKeyName(), selfEndorseCertificate.getPublicKeyInfo())); 
 }
 
+void
+PanelPolicyManager::removeTrustAnchor(const Name& keyName)
+{  
+  m_trustAnchors.erase(keyName); 
+}
+
 Ptr<Publickey>
 PanelPolicyManager::getTrustedKey(const ndn::Name& inviterCertName)
 {
diff --git a/src/panel-policy-manager.h b/src/panel-policy-manager.h
index b28c90a..f38e0e8 100644
--- a/src/panel-policy-manager.h
+++ b/src/panel-policy-manager.h
@@ -79,6 +79,9 @@
   void
   addTrustAnchor(const EndorseCertificate& selfEndorseCertificate);
 
+  void
+  removeTrustAnchor(const ndn::Name& keyName);
+
 // private:
 //   void 
 //   onCertificateVerified(ndn::Ptr<ndn::Data> certData,