discovery: Add hierarchical model for chatroom invitation
Change-Id: I19e74745a5998fe075a373357df542fef317ae5f
diff --git a/src/discovery-panel.cpp b/src/discovery-panel.cpp
index cbc98e0..20e36ab 100644
--- a/src/discovery-panel.cpp
+++ b/src/discovery-panel.cpp
@@ -13,6 +13,7 @@
#include <QItemSelectionModel>
#include <QModelIndex>
+#include <QMessageBox>
#ifndef Q_MOC_RUN
#endif
@@ -21,7 +22,8 @@
namespace chronochat {
static const time::seconds REFRESH_INTERVAL(60);
-static const uint8_t ROUTING_HINT_SEPARATOR[2] = {0xF0, 0x2E};
+static const ndn::Name::Component ROUTING_HINT_SEPARATOR =
+ ndn::name::Component::fromEscapedString("%F0%2E");
DiscoveryPanel::DiscoveryPanel(QWidget *parent)
: QDialog(parent)
@@ -43,6 +45,12 @@
SLOT(onSelectedParticipantChanged(const QItemSelection &, const QItemSelection &)));
connect(ui->join, SIGNAL(clicked()),
this, SLOT(onJoinClicked()));
+ connect(ui->requestInvitation, SIGNAL(clicked()),
+ this, SLOT(onRequestInvitation()));
+
+ ui->join->setEnabled(false);
+ ui->requestInvitation->setEnabled(false);
+ ui->InChatroomWarning->clear();
}
DiscoveryPanel::~DiscoveryPanel()
@@ -73,6 +81,9 @@
m_chatroom.clear();
m_chatroomListModel->setStringList(m_chatroomList);
+ ui->join->setEnabled(false);
+ ui->requestInvitation->setEnabled(false);
+ ui->InChatroomWarning->clear();
}
// public slots
@@ -90,7 +101,7 @@
}
void
-DiscoveryPanel::onChatroomInfoReady(const ChatroomInfo& info)
+DiscoveryPanel::onChatroomInfoReady(const ChatroomInfo& info, bool isParticipant)
{
ui->NameData->setText(QString::fromStdString(info.getName().toUri()));
ui->NameSpaceData->setText(QString::fromStdString(info.getSyncPrefix().toUri()));
@@ -124,10 +135,16 @@
ui->requestInvitation->setEnabled(false);
}
}
+ ui->InChatroomWarning->clear();
+ if (isParticipant) {
+ ui->join->setEnabled(false);
+ ui->requestInvitation->setEnabled(false);
+ ui->InChatroomWarning->setText(QString("You are already in this chatroom"));
+ }
std::list<Name>roster = info.getParticipants();
m_rosterList.clear();
- Name::Component routingHint = Name::Component(ROUTING_HINT_SEPARATOR, 2);
+ Name::Component routingHint = Name::Component(ROUTING_HINT_SEPARATOR);
for (const auto& participant : roster) {
size_t i;
for (i = 0; i < participant.size(); ++i) {
@@ -196,6 +213,19 @@
emit startChatroom(m_chatroom, false);
}
+void
+DiscoveryPanel::onRequestInvitation()
+{
+ emit sendInvitationRequest(m_chatroom, m_participant);
+}
+
+void
+DiscoveryPanel::onInvitationRequestResult(const std::string& message)
+{
+ QMessageBox::information(this, tr("Chatroom Discovery"),
+ tr(message.c_str()));
+}
+
} // namespace chronochat
#if WAF