Revert "do not use sync app socket for local prefix discovery"
This reverts commit ba70734c2a43e9fc663aff4061e22a20e01c199e.
diff --git a/chatdialog.cpp b/chatdialog.cpp
index 7ed7cfd..6fdc657 100644
--- a/chatdialog.cpp
+++ b/chatdialog.cpp
@@ -55,7 +55,7 @@
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
connect(setButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
connect(treeButton, SIGNAL(pressed()), this, SLOT(treeButtonPressed()));
- connect(refreshButton, SIGNAL(pressed()), this, SLOT(updateLocalPrefix()));
+ connect(refreshButton, SIGNAL(pressed()), this, SLOT(getLocalPrefix()));
connect(this, SIGNAL(dataReceived(QString, const char *, size_t, bool, bool)), this, SLOT(processData(QString, const char *, size_t, bool, bool)));
connect(this, SIGNAL(treeUpdated(const std::vector<Sync::MissingDataInfo>)), this, SLOT(processTreeUpdate(const std::vector<Sync::MissingDataInfo>)));
connect(m_timer, SIGNAL(timeout()), this, SLOT(replot()));
@@ -76,6 +76,7 @@
bind(&ChatDialog::processRemoveWrapper, this, _1));
Sync::CcnxWrapperPtr handle = Sync::CcnxWrapper::Create();
handle->setInterestFilter(m_user.getPrefix().toStdString(), bind(&ChatDialog::respondHistoryRequest, this, _1));
+ QTimer::singleShot(100, this, SLOT(getLocalPrefix()));
QTimer::singleShot(600, this, SLOT(sendJoin()));
m_timer->start(FRESHNESS * 1000);
@@ -546,42 +547,60 @@
return randStr.c_str();
}
-QString
+void
ChatDialog::getLocalPrefix()
{
+// /*
+// * this method tries to use ccncat
+// * however, it does not work in Mac OS X app bundle
+// * it works well in command line though
+// */
+
+// std::string cmd = CCN_EXEC;
+// cmd += " -c -v ";
+// cmd += LOCAL_PREFIX_QUERY;
+// QString localPrefix;
+// #define MAX_PREFIX_LEN 100
+// FILE *fp = popen(cmd.c_str(), "r");
+// if (fp != NULL)
+// {
+// char prefix[MAX_PREFIX_LEN];
+// if (fgets(prefix, MAX_PREFIX_LEN, fp) != NULL)
+// {
+// localPrefix = prefix;
+// localPrefix.remove('\n');
+// }
+// else
+// {
+// localPrefix = DEFAULT_LOCAL_PREFIX;
+// }
+// pclose(fp);
+// }
+// else
+// {
+// localPrefix = DEFAULT_LOCAL_PREFIX;
+// }
+// return localPrefix;
std::cerr << "trying to get local prefix" << std::endl;
- try
- {
- Sync::CcnxWrapperPtr handle = Sync::CcnxWrapper::Create();
- QString originPrefix = QString::fromStdString (handle->getLocalPrefix()).trimmed ();
- std::cerr << "got: " << originPrefix.toStdString () << std::endl;
-
- if (originPrefix != "" && m_user.getOriginPrefix () != originPrefix)
- {
- // emit settingUpdated(m_user.getNick (), m_user.getChatroom (), originPrefix);
- return originPrefix;
- }
- else
+ if (m_sock != NULL)
{
- return DEFAULT_LOCAL_PREFIX;
- }
- }
- catch (Sync::CcnxOperationException ex)
- {
- QMessageBox::critical(this, tr("Chronos"), tr("Canno connect to ccnd.\n Have you started your ccnd?"), QMessageBox::Ok);
- std::exit(1);
- }
-}
+ std::cerr << "trying to get local prefix2" << std::endl;
+ QString originPrefix = QString::fromStdString (m_sock->getLocalPrefix()).trimmed ();
+ std::cerr << "got: " << originPrefix.toStdString () << std::endl;
-void
-ChatDialog::updateLocalPrefix()
-{
- QString localPrefix = getLocalPrefix();
- if (localPrefix != m_user.getOriginPrefix())
- {
- emit settingUpdated(m_user.getNick(), m_user.getChatroom(), localPrefix);
- }
+ if (originPrefix != "" && m_user.getOriginPrefix () != originPrefix)
+ {
+ // m_user.setOriginPrefix(originPrefix);
+ emit settingUpdated(m_user.getNick (), m_user.getChatroom (), originPrefix);
+ // connect(&dialog, SIGNAL(updated(QString, QString, QString)), this, SLOT());
+ }
+ }
+ else
+ {
+ std::cerr << "socket is not availble" << std::endl;
+ // QTimer::singleShot(1000, this, SLOT(getLocalPrefix())); // try again
+ }
}
bool
@@ -590,9 +609,13 @@
QSettings s(ORGANIZATION, APPLICATION);
QString nick = s.value("nick", "").toString();
QString chatroom = s.value("chatroom", "").toString();
+ // QString originPrefix = s.value("originPrefix", "").toString();
+ // Sync::CcnxWrapperPtr wrapper = Sync::CcnxWrapper::Create ();
+ // QString originPrefix = QString::fromStdString (wrapper->getLocalPrefix());
+ // Sync::CcnxWrapper::Destroy ();
- QString originPrefix = getLocalPrefix();
+ QString originPrefix = DEFAULT_LOCAL_PREFIX;
m_minimaniho = s.value("minimaniho", false).toBool();
if (nick == "" || chatroom == "" || originPrefix == "") {
@@ -672,9 +695,6 @@
std::cerr << "Errrrr.. msg was not probally initialized "<<__FILE__ <<":"<<__LINE__<<". what is happening?" << std::endl;
abort();
}
-#ifdef __DEBUG
- std::cout << "Sending message for " << msg.from() << " prefix = " << m_user.getPrefix().toStdString() << std::endl;
-#endif
m_sock->publishRaw(m_user.getPrefix().toStdString(), m_session, buf, size, FRESHNESS);
delete buf;
@@ -695,9 +715,6 @@
void
ChatDialog::sendJoin()
{
-#ifdef __DEBUG
- std::cout << "Sending join for " << m_user.getPrefix().toStdString() << std::endl;
-#endif
SyncDemo::ChatMessage msg;
formControlMessage(msg, SyncDemo::ChatMessage::JOIN);
sendMsg(msg);
diff --git a/chatdialog.h b/chatdialog.h
index 8e09749..f0c58c2 100644
--- a/chatdialog.h
+++ b/chatdialog.h
@@ -47,7 +47,6 @@
void processRemove(QString);
private:
- QString getLocalPrefix();
void fetchHistory(std::string name);
QString getRandomString();
void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
@@ -78,7 +77,8 @@
void replot();
void updateRosterList(QStringList);
void enableTreeDisplay();
- void updateLocalPrefix();
+ void getLocalPrefix();
+
// icon related
void iconActivated(QSystemTrayIcon::ActivationReason reason);
void showMessage(QString, QString);
diff --git a/digesttreescene.cpp b/digesttreescene.cpp
index 403610e..64f6949 100644
--- a/digesttreescene.cpp
+++ b/digesttreescene.cpp
@@ -33,9 +33,6 @@
p->setPrefix(v[i].prefix.c_str());
p->setSeq(v[i].high);
m_roster.insert(p->getPrefix(), p);
-#ifdef __DEBUG
- std::cout << "<<<<<<< Adding user. Prefix = " << p->getPrefix().toStdString() << std::endl;
-#endif
}
else
{
@@ -94,9 +91,6 @@
void
DigestTreeScene::msgReceived(QString prefix, QString nick)
{
-#ifdef __DEBUG
- std::cout << "<<<<<<< MsgReceived. Prefix = " << prefix.toStdString() << ". Nick = " << nick.toStdString() << std::endl;
-#endif
Roster_iterator it = m_roster.find(prefix);
if (it != m_roster.end())
{