Add SettingDialog
diff --git a/src/settingdialog.cpp b/src/settingdialog.cpp
index ff617a2..291d7e6 100644
--- a/src/settingdialog.cpp
+++ b/src/settingdialog.cpp
@@ -1,56 +1,50 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
 #include "settingdialog.h"
-#include <QRegExp>
-#include <QValidator>
+#include "ui_settingdialog.h"
 
-SettingDialog::SettingDialog(QWidget *parent, QString nick, QString chatroom, QString prefix)
-  : QDialog(parent)
+using namespace std;
+
+SettingDialog::SettingDialog(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::SettingDialog)
 {
-  setupUi(this);
+    ui->setupUi(this);
+}
 
-  QRegExp noWhiteSpace("^\\S+.*$");
-  QValidator *nwsValidator = new QRegExpValidator(noWhiteSpace, this);
-  nickEdit->setPlaceholderText(nick);
-  nickEdit->setValidator(nwsValidator);
-  roomEdit->setPlaceholderText(chatroom);
-  roomEdit->setValidator(nwsValidator);
-  prefixEdit->setPlaceholderText(prefix);
-
-  // simple validator for ccnx prefix
-  QRegExp rx("(^(/[^/]+)+$)|(^/$)");
-  QValidator *validator = new QRegExpValidator(rx, this);
-  prefixEdit->setValidator(validator);
-
-  if (nick.isEmpty())
-  {
-    prefixEdit->hide();
-    prefixLabel->hide();
-  }
-
-  okButton->setDefault(true);
-
-  connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
-  connect(okButton, SIGNAL(clicked()), this, SLOT(update()));
+SettingDialog::~SettingDialog()
+{
+    delete ui;
 }
 
 void
-SettingDialog::update() 
-{
-  emit updated(nickEdit->text(), roomEdit->text(), prefixEdit->text()); 
-  accept();
+setIdentity(const std::string& identity)
+{ 
+  m_identity = identity;
+  ui->identityLine->setText(QString::fromUtf8(m_identity.c_str()));
 }
 
 void
-SettingDialog::keyPressEvent(QKeyEvent *e)
+SettingDialog::onOkClicked()
 {
-  switch(e->key()) {
-    case Qt::Key_Enter:
-      update();
-      break;
-    default:
-      QDialog::keyPressEvent(e);
-  }
+  QString text = ui->identityLine->text();
+  string identity = text.toUtf8().constData();
+  if(identity != m_identity)
+    {
+      m_identity = identity;
+      emit identitySet(text);
+    }
 }
 
+
 #if WAF
 #include "settingdialog.moc"
 #include "settingdialog.cpp.moc"
diff --git a/src/settingdialog.h b/src/settingdialog.h
index f9fc31c..a06046d 100644
--- a/src/settingdialog.h
+++ b/src/settingdialog.h
@@ -1,22 +1,44 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
 #ifndef SETTINGDIALOG_H
 #define SETTINGDIALOG_H
-#include "ui_settingdialog.h"
-#include <QKeyEvent>
 
-class SettingDialog : public QDialog, private Ui::SettingDialog
+#include <QDialog>
+
+namespace Ui {
+class SettingDialog;
+}
+
+class SettingDialog : public QDialog
 {
   Q_OBJECT
 
 public:
-  SettingDialog(QWidget *parent = 0, QString nick = QString("NULL"), QString chatroom = QString("NULL"), QString prefix = QString("NULL"));
-  virtual void keyPressEvent(QKeyEvent *e);
+  explicit SettingDialog(QWidget *parent = 0);
+  ~SettingDialog();
+
+  void
+  setIdentity(const std::string& identity);
+
+signals:
+  void
+  identitySet(const QString& identity);
 
 private slots:
-  void update();
-  
-signals:
-  void updated(QString, QString, QString);
+  void
+  onOkClicked();
 
+private:
+  Ui::SettingDialog *ui;
+  std::string m_identity;
 };
 
-#endif
+#endif // SETTINGDIALOG_H
diff --git a/src/settingdialog.ui b/src/settingdialog.ui
index d805198..5d3c04d 100644
--- a/src/settingdialog.ui
+++ b/src/settingdialog.ui
@@ -1,112 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
-  <class>SettingDialog</class>
-  <widget class="QDialog" name="SettingDialog">
-    <property name="geometry">
-      <rect>
-      <x>0</x>
-      <y>0</y>
-      <width>300</width>
-      <height>200</height>
-      </rect>
-    </property>
-    <property name="windowTitle">
-      <string>Chat Settings</string>
-    </property>
-    <layout class="QVBoxLayout">
-      <property name="spacing">
-        <number>6</number>
-      </property>
-      <item>
-        <layout class="QHBoxLayout">
-          <property name="spacing">
-            <number>6</number>
-          </property>
-          <!-- first group -->
-          <item>
-            <layout class="QVBoxLayout">
-              <property name="spacing">
-                <number>6</number>
-              </property>
-              <item>
-                <widget class="QLabel">
-                  <property name="text">
-                    <string>Nickname</string>
-                  </property>
-                </widget>
-              </item>
-              <item>
-                <widget class="QLabel">
-                  <property name="text">
-                    <string>Chatroom</string>
-                  </property>
-                </widget>
-              </item>
-              <item>
-                <widget class="QLabel" name="prefixLabel">
-                  <property name="text">
-                    <string>Prefix</string>
-                  </property>
-                </widget>
-              </item>
-            </layout>
-          </item>
-          <!-- first group -->
-
-          <!-- second group -->
-          <item>
-            <layout class="QVBoxLayout">
-              <property name="spacing">
-                <number>6</number>
-              </property>
-              <item>
-                <widget class="QLineEdit" name="nickEdit">
-                  <property name="maxLength">
-                    <number>200</number>
-                  </property>
-                </widget>
-              </item>
-              <item>
-                <widget class="QLineEdit" name="roomEdit">
-                  <property name="maxLength">
-                    <number>200</number>
-                  </property>
-                </widget>
-              </item>
-              <item>
-                <widget class="QLineEdit" name="prefixEdit">
-                  <property name="maxLength">
-                    <number>200</number>
-                  </property>
-                </widget>
-              </item>
-            </layout>
-          </item>
-          <!-- second group -->
-        </layout>
-      </item>
-      <item>
-        <layout class="QHBoxLayout">
-          <property name="spacing">
-            <number>6</number>
-          </property>
-          <item>
-            <widget class="QPushButton" name="cancelButton">
-              <property name="text">
-                <string>Cancel</string>
-              </property>
-            </widget>
-          </item>
-          <item>
-            <widget class="QPushButton" name="okButton">
-              <property name="text">
-                <string>OK</string>
-              </property>
-            </widget>
-          </item>
-        </layout>
-      </item>
-    </layout>
+ <class>SettingDialog</class>
+ <widget class="QDialog" name="SettingDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>300</width>
+    <height>140</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPushButton" name="okButton">
+   <property name="geometry">
+    <rect>
+     <x>100</x>
+     <y>90</y>
+     <width>100</width>
+     <height>32</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>OK</string>
+   </property>
   </widget>
-  <resources/>
-  <connections/>
+  <widget class="QLabel" name="msgLabel">
+   <property name="geometry">
+    <rect>
+     <x>20</x>
+     <y>20</y>
+     <width>150</width>
+     <height>16</height>
+    </rect>
+   </property>
+   <property name="font">
+    <font>
+     <weight>75</weight>
+     <bold>true</bold>
+    </font>
+   </property>
+   <property name="text">
+    <string>Current Identity:</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="identityLine">
+   <property name="geometry">
+    <rect>
+     <x>20</x>
+     <y>50</y>
+     <width>260</width>
+     <height>21</height>
+    </rect>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
 </ui>