Basic invitation works now
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index 5128105..e2c8359 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -18,6 +18,7 @@
#include <QDir>
#ifndef Q_MOC_RUN
+#include <ndn.cxx/common.h>
#include <boost/filesystem.hpp>
#include "logging.h"
#include "exception.h"
@@ -36,7 +37,8 @@
, m_contactListModel(new QStringListModel)
, m_addContactPanel(new AddContactPanel(contactManager))
, m_setAliasDialog(new SetAliasDialog(contactManager))
- , m_menuInvite(new QAction("&Invite", this))
+ , m_startChatDialog(new StartChatDialog)
+ , m_menuInvite(new QAction("&Chat", this))
, m_menuAlias(new QAction("&Set Alias", this))
{
@@ -70,6 +72,9 @@
connect(m_setAliasDialog, SIGNAL(aliasChanged()),
this, SLOT(refreshContactList()));
+ connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&, const QString&, bool)),
+ this, SLOT(startChatroom(const QString&, const QString&, bool)));
+
}
@@ -92,8 +97,6 @@
QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
string alias = text.toUtf8().constData();
- m_currentSelectedContact = alias;
-
int i = 0;
for(; i < m_contactList.size(); i++)
{
@@ -107,7 +110,9 @@
ui->NameData->setText(name);
ui->NameSpaceData->setText(nameSpace);
ui->InstitutionData->setText(institution);
-
+
+ m_currentSelectedContactAlias = alias;
+ m_currentSelectedContactNamespace = m_contactList[i]->getNameSpace().toUri();
// _LOG_DEBUG("current Alias: " << m_currentSelectedContact);
}
@@ -135,6 +140,8 @@
{
QMenu menu(ui->ContactList);
menu.addAction(m_menuInvite);
+ connect(m_menuInvite, SIGNAL(triggered()),
+ this, SLOT(openStartChatDialog()));
menu.addAction(m_menuAlias);
connect(m_menuAlias, SIGNAL(triggered()),
this, SLOT(openSetAliasDialog()));
@@ -145,10 +152,33 @@
void
ContactPanel::openSetAliasDialog()
{
- m_setAliasDialog->setTargetIdentity(m_currentSelectedContact);
+ m_setAliasDialog->setTargetIdentity(m_currentSelectedContactNamespace);
m_setAliasDialog->show();
}
+void
+ContactPanel::openStartChatDialog()
+{
+ TimeInterval ti = time::NowUnixTimestamp();
+ ostringstream oss;
+ oss << ti.total_seconds();
+
+ Name chatroom("/ndn/broadcast/chronos");
+ chatroom.append(string("chatroom-") + oss.str());
+
+ m_startChatDialog->setInvitee(m_currentSelectedContactNamespace, chatroom.toUri());
+ m_startChatDialog->show();
+}
+
+void
+ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer)
+{
+ _LOG_DEBUG("room: " << chatroom.toUtf8().constData());
+ _LOG_DEBUG("invitee: " << invitee.toUtf8().constData());
+ _LOG_DEBUG("introducer: " << std::boolalpha << isIntroducer);
+}
+
+
#if WAF
#include "contactpanel.moc"
#include "contactpanel.cpp.moc"
diff --git a/src/contactpanel.h b/src/contactpanel.h
index 54c586b..dff0e56 100644
--- a/src/contactpanel.h
+++ b/src/contactpanel.h
@@ -19,6 +19,7 @@
#include "profileeditor.h"
#include "addcontactpanel.h"
#include "setaliasdialog.h"
+#include "startchatdialog.h"
#ifndef Q_MOC_RUN
#include "contact-manager.h"
@@ -49,6 +50,9 @@
void
openSetAliasDialog();
+
+ void
+ openStartChatDialog();
void
refreshContactList();
@@ -56,6 +60,9 @@
void
showContextMenu(const QPoint& pos);
+ void
+ startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer);
+
private:
Ui::ContactPanel *ui;
ndn::Ptr<ContactManager> m_contactManager;
@@ -63,13 +70,15 @@
ProfileEditor* m_profileEditor;
AddContactPanel* m_addContactPanel;
SetAliasDialog* m_setAliasDialog;
+ StartChatDialog* m_startChatDialog;
QAction* m_menuInvite;
QAction* m_menuAlias;
std::vector<ndn::Ptr<ContactItem> > m_contactList;
- std::string m_currentSelectedContact;
+ std::string m_currentSelectedContactAlias;
+ std::string m_currentSelectedContactNamespace;
};
#endif // CONTACTPANEL_H
diff --git a/src/startchatdialog.cpp b/src/startchatdialog.cpp
new file mode 100644
index 0000000..561096a
--- /dev/null
+++ b/src/startchatdialog.cpp
@@ -0,0 +1,57 @@
+/* -*- 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 "startchatdialog.h"
+#include "ui_startchatdialog.h"
+
+using namespace std;
+
+StartChatDialog::StartChatDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::StartChatDialog)
+{
+ ui->setupUi(this);
+ connect(ui->okButton, SIGNAL(clicked()),
+ this, SLOT(onOkClicked()));
+ connect(ui->cancelButton, SIGNAL(clicked()),
+ this, SLOT(onCancelClicked()));
+}
+
+StartChatDialog::~StartChatDialog()
+{
+ delete ui;
+}
+
+void
+StartChatDialog::setInvitee(const string& invitee, const string& chatroom)
+{
+ m_invitee = invitee;
+ ui->chatroomInput->setText(QString::fromUtf8(chatroom.c_str()));
+}
+
+void
+StartChatDialog::onOkClicked()
+{
+ QString chatroom = ui->chatroomInput->text();
+ QString invitee = QString::fromUtf8(m_invitee.c_str());
+ bool isIntroducer = ui->introCheckBox->isChecked();
+ emit chatroomConfirmed(chatroom, invitee, isIntroducer);
+ this->close();
+}
+
+void
+StartChatDialog::onCancelClicked()
+{ this->close(); }
+
+
+#if WAF
+#include "startchatdialog.moc"
+#include "startchatdialog.cpp.moc"
+#endif
diff --git a/src/startchatdialog.h b/src/startchatdialog.h
new file mode 100644
index 0000000..f317ec6
--- /dev/null
+++ b/src/startchatdialog.h
@@ -0,0 +1,51 @@
+/* -*- 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 STARTCHATDIALOG_H
+#define STARTCHATDIALOG_H
+
+#include <QDialog>
+
+#ifndef Q_MOC_RUN
+#include <string>
+#endif
+
+namespace Ui {
+class StartChatDialog;
+}
+
+class StartChatDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit StartChatDialog(QWidget *parent = 0);
+ ~StartChatDialog();
+
+ void
+ setInvitee(const std::string& invitee, const std::string& chatroom);
+
+signals:
+ void
+ chatroomConfirmed(const QString& chatroomName, const QString& invitee, bool isIntroducer);
+
+private slots:
+ void
+ onOkClicked();
+
+ void
+ onCancelClicked();
+
+private:
+ Ui::StartChatDialog *ui;
+ std::string m_invitee;
+};
+
+#endif // STARTCHATDIALOG_H
diff --git a/src/startchatdialog.ui b/src/startchatdialog.ui
new file mode 100644
index 0000000..bfe6217
--- /dev/null
+++ b/src/startchatdialog.ui
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>StartChatDialog</class>
+ <widget class="QDialog" name="StartChatDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>300</width>
+ <height>200</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <widget class="QPushButton" name="okButton">
+ <property name="geometry">
+ <rect>
+ <x>180</x>
+ <y>150</y>
+ <width>100</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>OK</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="chatroomInput">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>70</y>
+ <width>260</width>
+ <height>21</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QLabel" name="introLabel">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>30</y>
+ <width>260</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Chatroom Prefix:</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="cancelButton">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>150</y>
+ <width>100</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="introCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>110</y>
+ <width>260</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Set invitee as introducer</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>