setting works
diff --git a/demo/chatdialog.cpp b/demo/chatdialog.cpp
index ca1b3ae..34f5682 100644
--- a/demo/chatdialog.cpp
+++ b/demo/chatdialog.cpp
@@ -3,23 +3,17 @@
 #include "settingdialog.h"
 #include <ctime>
 #include <iostream>
+#include <QTimer>
 
 ChatDialog::ChatDialog(QWidget *parent)
   : QDialog(parent)
 {
   setupUi(this);
+
+  readSettings();
+  updateLabels();
+
   lineEdit->setFocusPolicy(Qt::StrongFocus);
-
-  // for test only
-  m_nick = "Tester";
-  m_chatroom = "Test";
-  m_prefix = "/ndn/ucla.edu/cs/tester";
-
-  QString settingDisp = QString("<User: %1>, <Chatroom: %2>").arg(m_nick).arg(m_chatroom);
-  infoLabel->setText(settingDisp);
-  QString prefixDisp = QString("<Prefix: %1>").arg(m_prefix);
-  prefixLabel->setText(prefixDisp);
-
   DigestTreeScene *scene = new DigestTreeScene();
 
   treeViewer->setScene(scene);
@@ -66,6 +60,36 @@
   msg.set_timestamp(seconds);
 }
 
+void
+ChatDialog::readSettings()
+{
+  QSettings s(ORGANIZATION, APPLICATION);
+  m_nick = s.value("nick", "").toString();
+  m_chatroom = s.value("chatroom", "").toString();
+  m_prefix = s.value("prefix", "").toString();
+  if (m_nick == "" || m_chatroom == "" || m_prefix == "") {
+    QTimer::singleShot(500, this, SLOT(buttonPressed()));
+  }
+}
+
+void 
+ChatDialog::writeSettings()
+{
+  QSettings s(ORGANIZATION, APPLICATION);
+  s.setValue("nick", m_nick);
+  s.setValue("chatroom", m_chatroom);
+  s.setValue("prefix", m_prefix);
+}
+
+void
+ChatDialog::updateLabels()
+{
+  QString settingDisp = QString("<User: %1>, <Chatroom: %2>").arg(m_nick).arg(m_chatroom);
+  infoLabel->setText(settingDisp);
+  QString prefixDisp = QString("<Prefix: %1>").arg(m_prefix);
+  prefixLabel->setText(prefixDisp);
+}
+
 void 
 ChatDialog::returnPressed()
 {
@@ -88,7 +112,30 @@
 ChatDialog::buttonPressed()
 {
   SettingDialog dialog(this, m_nick, m_chatroom, m_prefix);
+  connect(&dialog, SIGNAL(updated(QString, QString, QString)), this, SLOT(settingUpdated(QString, QString, QString)));
   dialog.exec();
-  setButton->setFocusPolicy(Qt::NoFocus);
 }
 
+void
+ChatDialog::settingUpdated(QString nick, QString chatroom, QString prefix)
+{
+  bool needWrite = false;
+  if (!nick.isEmpty() && nick != m_nick) {
+    m_nick = nick;
+    needWrite = true;
+  }
+  if (!prefix.isEmpty() && prefix != m_prefix) {
+    m_prefix = prefix;
+    needWrite = true;
+    // TODO: set the previous prefix as left?
+  }
+  if (!chatroom.isEmpty() && chatroom != m_chatroom) {
+    m_chatroom = chatroom;
+    needWrite = true;
+    // TODO: perhaps need to do a lot. e.g. use a new SyncAppSokcet
+  }
+  if (needWrite) {
+    writeSettings();
+    updateLabels();
+  }
+}