use signal for removal; send hello at beginning
diff --git a/chatdialog.cpp b/chatdialog.cpp
index 57de04e..26226d9 100644
--- a/chatdialog.cpp
+++ b/chatdialog.cpp
@@ -62,7 +62,8 @@
syncPrefix += m_user.getChatroom().toStdString();
try
{
- m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), bind(&ChatDialog::processRemove, this, _1));
+ m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), bind(&ChatDialog::processRemoveWrapper, this, _1));
+ sendHello();
}
catch (Sync::CcnxOperationException ex)
{
@@ -77,6 +78,7 @@
connect(setButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
connect(this, SIGNAL(dataReceived(QString, const char *, size_t)), this, SLOT(processData(QString, const char *, size_t)));
connect(this, SIGNAL(treeUpdated(const std::vector<Sync::MissingDataInfo>)), this, SLOT(processTreeUpdate(const std::vector<Sync::MissingDataInfo>)));
+ connect(this, SIGNAL(removeReceived(QString)), this, SLOT(processRemove(QString)));
connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showNormal()));
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
@@ -262,12 +264,18 @@
}
void
-ChatDialog::processRemove(std::string prefix)
+ChatDialog::processRemoveWrapper(std::string prefix)
+{
+ emit removeReceived(prefix.c_str());
+}
+
+void
+ChatDialog::processRemove(QString prefix)
{
#ifdef __DEBUG
- std::cout << "<<< remove node for prefix" << prefix << std::endl;
+ std::cout << "<<< remove node for prefix" << prefix.toStdString() << std::endl;
#endif
- bool removed = m_scene->removeNode(QString(prefix.c_str()));
+ bool removed = m_scene->removeNode(prefix);
if (removed)
{
m_scene->plot(m_sock->getRootDigest().c_str());
@@ -284,6 +292,16 @@
msg.set_type(SyncDemo::ChatMessage::CHAT);
}
+void
+ChatDialog::formHelloMessage(SyncDemo::ChatMessage &msg)
+{
+ msg.set_from(m_user.getNick().toStdString());
+ msg.set_to(m_user.getChatroom().toStdString());
+ time_t seconds = time(NULL);
+ msg.set_timestamp(seconds);
+ msg.set_type(SyncDemo::ChatMessage::HELLO);
+}
+
static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
QString
@@ -357,6 +375,14 @@
appendMessage(msg);
+ sendMsg(msg);
+
+ fitView();
+}
+
+void
+ChatDialog::sendMsg(SyncDemo::ChatMessage &msg)
+{
// send msg
size_t size = msg.ByteSize();
char *buf = new char[size];
@@ -368,6 +394,8 @@
}
m_sock->publishRaw(m_user.getPrefix().toStdString(), m_session, buf, size, 60);
+ delete buf;
+
int nextSequence = m_sock->getNextSeq(m_user.getPrefix().toStdString(), m_session);
Sync::MissingDataInfo mdi = {m_user.getPrefix().toStdString(), Sync::SeqNo(0), Sync::SeqNo(nextSequence - 1)};
std::vector<Sync::MissingDataInfo> v;
@@ -377,7 +405,14 @@
m_scene->processUpdate(v, m_sock->getRootDigest().c_str());
m_scene->msgReceived(m_user.getPrefix(), m_user.getNick());
}
- fitView();
+}
+
+void
+ChatDialog::sendHello()
+{
+ SyncDemo::ChatMessage msg;
+ formHelloMessage(msg);
+ sendMsg(msg);
}
void
@@ -431,7 +466,8 @@
syncPrefix += m_user.getChatroom().toStdString();
try
{
- m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), bind(&ChatDialog::processRemove, this, _1));
+ m_sock = new Sync::SyncAppSocket(syncPrefix, bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2), bind(&ChatDialog::processRemoveWrapper, this, _1));
+ sendHello();
}
catch (Sync::CcnxOperationException ex)
{