Add nick name in settings
diff --git a/src/chatdialog.cpp b/src/chatdialog.cpp
index 4ecb7db..17ec238 100644
--- a/src/chatdialog.cpp
+++ b/src/chatdialog.cpp
@@ -37,6 +37,8 @@
                        const ndn::Name& chatroomPrefix,
 		       const ndn::Name& localPrefix,
                        const ndn::Name& defaultIdentity,
+                       const std::string& nick,
+                       bool trial,
 		       QWidget *parent) 
 : QDialog(parent)
   , ui(new Ui::ChatDialog)
@@ -45,6 +47,7 @@
   , m_localPrefix(localPrefix)
   , m_defaultIdentity(defaultIdentity)
   , m_invitationPolicyManager(ndn::Ptr<InvitationPolicyManager>(new InvitationPolicyManager(m_chatroomPrefix.get(-1).toUri())))
+  , m_nick(nick)
   , m_sock(NULL)
   , m_lastMsgTime(0)
   // , m_historyInitialized(false)
@@ -57,7 +60,7 @@
   ui->setupUi(this);
 
   m_localChatPrefix = m_localPrefix;
-  m_localChatPrefix.append("FH").append(m_defaultIdentity);
+  m_localChatPrefix.append("%F0.").append(m_defaultIdentity);
   m_localChatPrefix.append("chronos").append(m_chatroomPrefix.get(-1));
 
   m_session = time(NULL);
@@ -77,7 +80,7 @@
 
   m_timer = new QTimer(this);
 
-  setWrapper();
+  setWrapper(trial);
 
   connect(ui->inviteButton, SIGNAL(clicked()),
           this, SLOT(openInviteListDialog()));
@@ -188,13 +191,18 @@
 
 ChatDialog::~ChatDialog()
 {
-  delete ui;
-  sendLeave();
-  m_handler->shutdown();
+  _LOG_DEBUG("about to leave 4!");
+  if(m_sock != NULL)
+    {
+      sendLeave();
+      delete m_sock;
+      m_sock = NULL;
+    }
+  // m_handler->shutdown();
 }
 
 void
-ChatDialog::setWrapper()
+ChatDialog::setWrapper(bool trial)
 {
   m_identityManager = ndn::Ptr<ndn::security::IdentityManager>::Create();
   // ndn::Ptr<ndn::security::EncryptionManager> encryptionManager = ndn::Ptr<ndn::security::EncryptionManager>(new ndn::security::BasicEncryptionManager(privateStorage, "/tmp/encryption.db"));
@@ -205,13 +213,30 @@
   m_keychain = ndn::Ptr<ndn::security::Keychain>(new ndn::security::Keychain(m_identityManager, m_invitationPolicyManager, NULL));
 
   m_handler = ndn::Ptr<ndn::Wrapper>(new ndn::Wrapper(m_keychain));
+
+  if(trial == true)
+    {
+      ndn::Ptr<ndn::Interest> interest = ndn::Ptr<ndn::Interest>(new ndn::Interest(ndn::Name("/local/ndn/prefix")));
+      ndn::Ptr<ndn::Closure> closure = ndn::Ptr<ndn::Closure>(new ndn::Closure(boost::bind(&ChatDialog::onUnverified,
+                                                                                           this,
+                                                                                           _1),
+                                                                               boost::bind(&ChatDialog::onTimeout,
+                                                                                           this,
+                                                                                           _1,
+                                                                                           _2),
+                                                                               boost::bind(&ChatDialog::onUnverified,
+                                                                                           this,
+                                                                                           _1)));
+
+      m_handler->sendInterest(interest, closure);
+    }
 }
 
 void
 ChatDialog::initializeSetting()
 {
   // TODO: nick name may be changed.
-  m_user.setNick(QString::fromStdString(m_defaultIdentity.get(-1).toUri()));
+  m_user.setNick(QString::fromStdString(m_nick));
   m_user.setChatroom(QString::fromStdString(m_chatroomPrefix.get(-1).toUri()));
   m_user.setOriginPrefix(QString::fromStdString(m_localPrefix.toUri()));
   m_user.setPrefix(QString::fromStdString(m_localChatPrefix.toUri()));
@@ -261,6 +286,8 @@
   const ndn::Blob& sigBits = sha256sig->getSignatureBits();
 
   interestName.append(sigBits.buf(), sigBits.size());
+  interestName.appendVersion();
+
 
   ndn::Ptr<ndn::Interest> interest = ndn::Ptr<ndn::Interest>(new ndn::Interest(interestName));
   ndn::Ptr<ndn::Closure> closure = ndn::Ptr<ndn::Closure>(new ndn::Closure(boost::bind(&ChatDialog::onInviteReplyVerified,
@@ -321,7 +348,10 @@
   ndn::Ptr<const ndn::signature::Sha256WithRsa> sha256sig = boost::dynamic_pointer_cast<const ndn::signature::Sha256WithRsa> (data->getSignature());
   const ndn::Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName();
   ndn::Ptr<ndn::security::IdentityCertificate> dskCertificate = m_invitationPolicyManager->getValidatedDskCertificate(keyLocatorName);
-  m_syncPolicyManager->addChatDataRule(inviteePrefix, *dskCertificate, isIntroducer);
+  ndn::Name tmpPrefix(inviteePrefix);
+  ndn::Name prefix = tmpPrefix.getPrefix(tmpPrefix.size()-1);
+  m_syncPolicyManager->addChatDataRule(prefix, *dskCertificate, isIntroducer);
+  // m_syncPolicyManager->addChatDataRule(inviteePrefix, *dskCertificate, isIntroducer);
   publishIntroCert(dskCertificate, isIntroducer);
 }
 
@@ -361,6 +391,11 @@
 {}
 
 void
+ChatDialog::onTimeout(ndn::Ptr<ndn::Closure> closure, 
+                      ndn::Ptr<ndn::Interest> interest)
+{}
+
+void
 ChatDialog::initializeSync()
 {
   
@@ -970,6 +1005,16 @@
   sendInvitation(inviteeItem, isIntroducer);
 }
 
+void
+ChatDialog::closeEvent(QCloseEvent *e)
+{
+  hide();
+  _LOG_DEBUG("about to leave 1");
+  emit closeChatDialog(m_chatroomPrefix);
+}
+
+
+
 
 #if WAF
 #include "chatdialog.moc"