Add configurable routing prefix

Change-Id: I649bbd9f4decb8466ae4aeb82e1500f712adb6f6
diff --git a/src/controller.cpp b/src/controller.cpp
index fc4037b..d99b7a6 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -50,6 +50,7 @@
                        QWidget* parent)
   : QDialog(parent)
   , m_face(face)
+  , m_localPrefixDetected(false)
   , m_invitationListenerId(0)
   , m_contactManager(m_face)
   , m_discoveryLogic(m_face,
@@ -94,6 +95,10 @@
           this, SLOT(onIdentityUpdated(const QString&)));
   connect(m_settingDialog, SIGNAL(nickUpdated(const QString&)),
           this, SLOT(onNickUpdated(const QString&)));
+  connect(this, SIGNAL(localPrefixUpdated(const QString&)),
+          m_settingDialog, SLOT(onLocalPrefixUpdated(const QString&)));
+  connect(m_settingDialog, SIGNAL(prefixUpdated(const QString&)),
+          this, SLOT(onLocalPrefixConfigured(const QString&)));
 
   // Connection to ProfileEditor
   connect(this, SIGNAL(closeDBModule()),
@@ -543,6 +548,8 @@
           this, SLOT(onRosterChanged(const chronos::ChatroomInfo&)));
   connect(this, SIGNAL(localPrefixUpdated(const QString&)),
           chatDialog, SLOT(onLocalPrefixUpdated(const QString&)));
+  connect(this, SIGNAL(localPrefixConfigured(const QString&)),
+          chatDialog, SLOT(onLocalPrefixUpdated(const QString&)));
 
   QAction* chatAction = new QAction(chatroomName, this);
   m_chatActionList[chatroomName.toStdString()] = chatAction;
@@ -617,7 +624,23 @@
 void
 Controller::onLocalPrefixUpdated(const QString& localPrefix)
 {
+  QString privateLocalPrefix("/private/local");
+
   m_localPrefix = Name(localPrefix.toStdString());
+
+  if (privateLocalPrefix != localPrefix)
+    m_localPrefixDetected = true;
+  else
+    m_localPrefixDetected = false;
+}
+
+void
+Controller::onLocalPrefixConfigured(const QString& prefix)
+{
+  if (!m_localPrefixDetected) {
+    m_localPrefix = Name(prefix.toStdString());
+    emit localPrefixConfigured(prefix);
+  }
 }
 
 void
diff --git a/src/controller.hpp b/src/controller.hpp
index c489470..81b05a9 100644
--- a/src/controller.hpp
+++ b/src/controller.hpp
@@ -114,6 +114,9 @@
   localPrefixUpdated(const QString& localPrefix);
 
   void
+  localPrefixConfigured(const QString& prefix);
+
+  void
   identityUpdated(const QString& identity);
 
   void
@@ -143,6 +146,9 @@
   onLocalPrefixUpdated(const QString& localPrefix);
 
   void
+  onLocalPrefixConfigured(const QString& prefix);
+
+  void
   onStartChatAction();
 
   void
@@ -207,6 +213,7 @@
   // Communication
   shared_ptr<ndn::Face> m_face;
   Name m_localPrefix;
+  bool m_localPrefixDetected;
   const ndn::RegisteredPrefixId* m_invitationListenerId;
 
   // Contact Manager
diff --git a/src/setting-dialog.cpp b/src/setting-dialog.cpp
index 98434ef..ad28625 100644
--- a/src/setting-dialog.cpp
+++ b/src/setting-dialog.cpp
@@ -45,21 +45,32 @@
 }
 
 void
+SettingDialog::onLocalPrefixUpdated(const QString& prefix)
+{
+  m_prefix = prefix;
+  ui->prefixLine->setText(m_prefix);
+}
+
+void
 SettingDialog::onSaveClicked()
 {
   QString identity = ui->identityLine->text();
   QString nick = ui->nickLine->text();
+  QString prefix = ui->prefixLine->text();
 
-  if(identity != m_identity)
-    {
-      m_identity = identity;
-      emit identityUpdated(identity);
-    }
-  if(nick != m_nick)
-    {
-      m_nick = nick;
-      emit nickUpdated(nick);
-    }
+  if(identity != m_identity) {
+    m_identity = identity;
+    emit identityUpdated(identity);
+  }
+  if(nick != m_nick) {
+    m_nick = nick;
+    emit nickUpdated(nick);
+  }
+  if (prefix != m_prefix) {
+    m_prefix = prefix;
+    emit prefixUpdated(prefix);
+  }
+
 
   this->close();
 }
diff --git a/src/setting-dialog.hpp b/src/setting-dialog.hpp
index 443b87d..ddc8206 100644
--- a/src/setting-dialog.hpp
+++ b/src/setting-dialog.hpp
@@ -42,10 +42,16 @@
   void
   nickUpdated(const QString& nick);
 
+  void
+  prefixUpdated(const QString& prefix);
+
 public slots:
   void
   onIdentityUpdated(const QString& identity);
 
+  void
+  onLocalPrefixUpdated(const QString& prefix);
+
 private slots:
   void
   onSaveClicked();
@@ -57,6 +63,7 @@
   Ui::SettingDialog* ui;
   QString m_identity;
   QString m_nick;
+  QString m_prefix;
 };
 
 } // namespace chronos
diff --git a/src/setting-dialog.ui b/src/setting-dialog.ui
index f3b4d86..dc5301b 100644
--- a/src/setting-dialog.ui
+++ b/src/setting-dialog.ui
@@ -6,80 +6,106 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>300</width>
-    <height>124</height>
+    <width>400</width>
+    <height>150</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Dialog</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_2">
-   <item>
-    <layout class="QVBoxLayout" name="verticalLayout">
-     <item>
-      <layout class="QHBoxLayout" name="identityLayout" stretch="3,7">
-       <item>
-        <widget class="QLabel" name="identityLabel">
-         <property name="font">
-          <font>
-           <weight>75</weight>
-           <bold>true</bold>
-          </font>
-         </property>
-         <property name="text">
-          <string>Identity:</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QLineEdit" name="identityLine"/>
-       </item>
-      </layout>
-     </item>
-     <item>
-      <layout class="QHBoxLayout" name="nickLayout" stretch="3,7">
-       <item>
-        <widget class="QLabel" name="nickLabel">
-         <property name="font">
-          <font>
-           <weight>75</weight>
-           <bold>true</bold>
-          </font>
-         </property>
-         <property name="text">
-          <string>nick:</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QLineEdit" name="nickLine"/>
-       </item>
-      </layout>
-     </item>
-     <item>
-      <layout class="QHBoxLayout" name="buttonLayout">
-       <item>
-        <widget class="QPushButton" name="cancelButton">
-         <property name="text">
-          <string>Cancel</string>
-         </property>
-         <property name="autoDefault">
-          <bool>false</bool>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QPushButton" name="saveButton">
-         <property name="text">
-          <string>Save</string>
-         </property>
-        </widget>
-       </item>
-      </layout>
-     </item>
-    </layout>
-   </item>
-  </layout>
+  <widget class="QWidget" name="">
+   <property name="geometry">
+    <rect>
+     <x>10</x>
+     <y>13</y>
+     <width>381</width>
+     <height>133</height>
+    </rect>
+   </property>
+   <layout class="QVBoxLayout" name="verticalLayout">
+    <item>
+     <layout class="QHBoxLayout" name="identityLayout" stretch="3,7">
+      <item>
+       <widget class="QLabel" name="identityLabel">
+        <property name="font">
+         <font>
+          <weight>75</weight>
+          <bold>true</bold>
+         </font>
+        </property>
+        <property name="text">
+         <string>Identity:</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLineEdit" name="identityLine"/>
+      </item>
+     </layout>
+    </item>
+    <item>
+     <layout class="QHBoxLayout" name="nickLayout" stretch="3,7">
+      <item>
+       <widget class="QLabel" name="nickLabel">
+        <property name="font">
+         <font>
+          <weight>75</weight>
+          <bold>true</bold>
+         </font>
+        </property>
+        <property name="text">
+         <string>nick:</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLineEdit" name="nickLine"/>
+      </item>
+     </layout>
+    </item>
+    <item>
+     <layout class="QHBoxLayout" name="prefixLayout" stretch="3,7">
+      <item>
+       <widget class="QLabel" name="prefixLabel">
+        <property name="font">
+         <font>
+          <weight>75</weight>
+          <bold>true</bold>
+         </font>
+        </property>
+        <property name="text">
+         <string>routbale prefix:</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLineEdit" name="prefixLine"/>
+      </item>
+     </layout>
+    </item>
+    <item>
+     <layout class="QHBoxLayout" name="buttonLayout">
+      <item>
+       <widget class="QPushButton" name="cancelButton">
+        <property name="text">
+         <string>Cancel</string>
+        </property>
+        <property name="autoDefault">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QPushButton" name="saveButton">
+        <property name="text">
+         <string>Save</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </item>
+   </layout>
+  </widget>
  </widget>
  <resources/>
  <connections/>