Allow changing alias
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index abfbb08..5128105 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -25,6 +25,7 @@
 
 namespace fs = boost::filesystem;
 using namespace ndn;
+using namespace std;
 
 INIT_LOGGER("ContactPanel");
 
@@ -34,6 +35,9 @@
     , m_contactManager(contactManager)
     , m_contactListModel(new QStringListModel)
     , m_addContactPanel(new AddContactPanel(contactManager))
+    , m_setAliasDialog(new SetAliasDialog(contactManager))
+    , m_menuInvite(new QAction("&Invite", this))
+    , m_menuAlias(new QAction("&Set Alias", this))
 {
   
     ui->setupUi(this);
@@ -46,21 +50,28 @@
 
     m_profileEditor = new ProfileEditor(m_contactManager);
 
-    QStringList contactNameList;
-    contactNameList << "Alex" << "Wentao" << "Yingdi";
-
-    m_contactListModel->setStringList(contactNameList);
+    refreshContactList();
     ui->ContactList->setModel(m_contactListModel);
 
     QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
 
     connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
 	    this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
+    connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)),
+            this, SLOT(showContextMenu(const QPoint&)));
     connect(ui->EditProfileButton, SIGNAL(clicked()), 
             this, SLOT(openProfileEditor()));
 
     connect(ui->AddContactButton, SIGNAL(clicked()),
             this, SLOT(openAddContactPanel()));
+
+    connect(m_addContactPanel, SIGNAL(newContactAdded()),
+            this, SLOT(refreshContactList()));
+    connect(m_setAliasDialog, SIGNAL(aliasChanged()),
+            this, SLOT(refreshContactList()));
+
+
+
 }
 
 ContactPanel::~ContactPanel()
@@ -69,6 +80,8 @@
     delete m_contactListModel;
     delete m_profileEditor;
     delete m_addContactPanel;
+
+    delete m_menuInvite;
 }
 
 void
@@ -77,7 +90,25 @@
 {
   QModelIndexList items = selected.indexes();
   QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
-  ui->NameData->setText(text);
+  string alias = text.toUtf8().constData();
+
+  m_currentSelectedContact = alias;
+
+  int i = 0;
+  for(; i < m_contactList.size(); i++)
+    {
+      if(alias == m_contactList[i]->getAlias())
+        break;
+    }
+  
+  QString name = QString::fromUtf8(m_contactList[i]->getName().c_str());
+  QString institution = QString::fromUtf8(m_contactList[i]->getInstitution().c_str());
+  QString nameSpace = QString::fromUtf8(m_contactList[i]->getNameSpace().toUri().c_str());
+  ui->NameData->setText(name);
+  ui->NameSpaceData->setText(nameSpace);
+  ui->InstitutionData->setText(institution);
+  
+  // _LOG_DEBUG("current Alias: " << m_currentSelectedContact);
 }
 
 void
@@ -88,6 +119,36 @@
 ContactPanel::openAddContactPanel()
 { m_addContactPanel->show(); }
 
+void
+ContactPanel::refreshContactList()
+{
+  m_contactList = m_contactManager->getContactItemList();
+  QStringList contactNameList;
+  for(int i = 0; i < m_contactList.size(); i++)
+    contactNameList << QString::fromUtf8(m_contactList[i]->getAlias().c_str());
+
+  m_contactListModel->setStringList(contactNameList);
+}
+
+void
+ContactPanel::showContextMenu(const QPoint& pos)
+{
+  QMenu menu(ui->ContactList);
+  menu.addAction(m_menuInvite);
+  menu.addAction(m_menuAlias);
+  connect(m_menuAlias, SIGNAL(triggered()),
+          this, SLOT(openSetAliasDialog()));
+  menu.exec(ui->ContactList->mapToGlobal(pos));
+
+}
+
+void
+ContactPanel::openSetAliasDialog()
+{
+  m_setAliasDialog->setTargetIdentity(m_currentSelectedContact);
+  m_setAliasDialog->show();
+}
+
 #if WAF
 #include "contactpanel.moc"
 #include "contactpanel.cpp.moc"