blob: c95aabf46a5313054ed430d935b29fdf8bcec01b [file] [log] [blame]
/* -*- 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: Zhenkai Zhu <zhenkai@cs.ucla.edu>
* Alexander Afanasyev <alexander.afanasyev@ucla.edu>
* Yingdi Yu <yingdi@cs.ucla.edu>
*/
#ifndef CHAT_DIALOG_H
#define CHAT_DIALOG_H
#include <QDialog>
#include <QTextTable>
#include <QStringListModel>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QTimer>
#include "invite-list-dialog.h"
#ifndef Q_MOC_RUN
#include "contact-manager.h"
#include "invitation.h"
#include "contact.h"
#include "chatbuf.pb.h"
#include "intro-cert-list.pb.h"
#include "digest-tree-scene.h"
#include "trust-tree-scene.h"
#include "trust-tree-node.h"
#include <sync-socket.h>
#include <sync-seq-no.h>
#include <ndn-cpp-dev/security/key-chain.hpp>
#include "validator-invitation.h"
#include <boost/thread/locks.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/thread.hpp>
#endif
#define MAX_HISTORY_ENTRY 20
namespace Ui {
class ChatDialog;
}
class ChatDialog : public QDialog
{
Q_OBJECT
public:
explicit
ChatDialog(chronos::ContactManager* contactManager,
ndn::shared_ptr<ndn::Face> face,
const ndn::IdentityCertificate& myCertificate,
const ndn::Name& chatroomPrefix,
const ndn::Name& localPrefix,
const std::string& nick,
bool witSecurity,
QWidget* parent = 0);
~ChatDialog();
void
addSyncAnchor(const chronos::Invitation& invitation);
void
processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>&, Sync::SyncSocket *);
void
processDataWrapper(const ndn::shared_ptr<const ndn::Data>& data);
void
processDataNoShowWrapper(const ndn::shared_ptr<const ndn::Data>& data);
void
processRemoveWrapper(std::string);
protected:
void
closeEvent(QCloseEvent *e);
void
changeEvent(QEvent *e);
void
resizeEvent(QResizeEvent *);
void
showEvent(QShowEvent *);
private:
void
updatePrefix();
void
updateLabels();
void
initializeSync();
void
sendInvitation(ndn::shared_ptr<chronos::Contact> contact, bool isIntroducer);
void
replyWrapper(const ndn::Interest& interest,
ndn::Data& data,
size_t routablePrefixOffset,
bool isIntroducer);
void
replyTimeoutWrapper(const ndn::Interest& interest,
size_t routablePrefixOffset);
void
onReplyValidated(const ndn::shared_ptr<const ndn::Data>& data,
size_t inviteeRoutablePrefixOffset,
bool isIntroduce);
void
onReplyValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
const std::string& failureInfo);
void
invitationRejected(const ndn::Name& identity);
void
invitationAccepted(const ndn::IdentityCertificate& inviteeCert,
const ndn::Name& inviteePrefix,
bool isIntroducer);
void
fetchIntroCert(const ndn::Name& identity, const ndn::Name& prefix);
void
onIntroCertList(const ndn::Interest& interest, const ndn::Data& data);
void
onIntroCertListTimeout(const ndn::Interest& interest, int retry, const std::string& msg);
void
introCertWrapper(const ndn::Interest& interest, ndn::Data& data);
void
introCertTimeoutWrapper(const ndn::Interest& interest, int retry, const QString& msg);
void
onCertListInterest(const ndn::Name& prefix, const ndn::Interest& interest);
void
onCertListRegisterFailed(const ndn::Name& prefix, const std::string& msg);
void
onCertSingleInterest(const ndn::Name& prefix, const ndn::Interest& interest);
void
onCertSingleRegisterFailed(const ndn::Name& prefix, const std::string& msg);
void
sendMsg(SyncDemo::ChatMessage &msg);
void
disableSyncTreeDisplay();
void
appendMessage(const SyncDemo::ChatMessage msg, bool isHistory = false);
void
processRemove(QString prefix);
ndn::Name
getInviteeRoutablePrefix(const ndn::Name& invitee);
void
formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
void
formControlMessage(SyncDemo::ChatMessage &msg, SyncDemo::ChatMessage::ChatMessageType type);
QString
formatTime(time_t);
void
printTimeInCell(QTextTable *, time_t);
std::string
getRandomString();
void
showMessage(const QString&, const QString&);
void
fitView();
void
summonReaper();
void
getTree(TrustTreeNodeList& nodeList);
void
plotTrustTree();
signals:
void
processData(const ndn::shared_ptr<const ndn::Data>& data, bool show, bool isHistory);
void
processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
void
closeChatDialog(const QString& chatroomName);
void
inivationRejection(const QString& msg);
void
showChatMessage(const QString& chatroomName, const QString& from, const QString& data);
void
resetIcon();
void
reply(const ndn::Interest& interest,
const ndn::shared_ptr<const ndn::Data>& data,
size_t routablePrefixOffset, bool isIntroducer);
void
replyTimeout(const ndn::Interest& interest,
size_t routablePrefixOffset);
void
introCert(const ndn::Interest& interest,
const ndn::shared_ptr<const ndn::Data>& data);
void
introCertTimeout(const ndn::Interest& interest,
int retry, const QString& msg);
void
waitForContactList();
public slots:
void
onLocalPrefixUpdated(const QString& localPrefix);
void
onClose();
private slots:
void
onReturnPressed();
void
onSyncTreeButtonPressed();
void
onTrustTreeButtonPressed();
void
onProcessData(const ndn::shared_ptr<const ndn::Data>& data,
bool show, bool isHistory);
void
onProcessTreeUpdate(const std::vector<Sync::MissingDataInfo>&);
void
onReplot();
void
onRosterChanged(QStringList);
void
onInviteListDialogRequested();
void
sendJoin();
void
sendHello();
void
sendLeave();
void
enableSyncTreeDisplay();
void
reap();
void
onSendInvitation(QString);
void
onReply(const ndn::Interest& interest,
const ndn::shared_ptr<const ndn::Data>& data,
size_t routablePrefixOffset, bool isIntroducer);
void
onReplyTimeout(const ndn::Interest& interest,
size_t routablePrefixOffset);
void
onIntroCert(const ndn::Interest& interest,
const ndn::shared_ptr<const ndn::Data>& data);
void
onIntroCertTimeout(const ndn::Interest& interest,
int retry, const QString& msg);
private:
Ui::ChatDialog *ui;
ndn::KeyChain m_keyChain;
chronos::ContactManager* m_contactManager;
ndn::shared_ptr<ndn::Face> m_face;
ndn::IdentityCertificate m_myCertificate;
ndn::Name m_identity;
ndn::Name m_certListPrefix;
const ndn::RegisteredPrefixId* m_certListPrefixId;
ndn::Name m_certSinglePrefix;
const ndn::RegisteredPrefixId* m_certSinglePrefixId;
std::string m_chatroomName;
ndn::Name m_chatroomPrefix;
ndn::Name m_localPrefix;
bool m_useRoutablePrefix;
ndn::Name m_chatPrefix;
ndn::Name m_localChatPrefix;
std::string m_nick;
DigestTreeScene *m_scene;
TrustTreeScene *m_trustScene;
QStringListModel *m_rosterModel;
QTimer* m_timer;
int64_t m_lastMsgTime;
int m_randomizedInterval;
bool m_joined;
Sync::SyncSocket *m_sock;
uint64_t m_session;
ndn::shared_ptr<ndn::SecRuleRelative> m_dataRule;
InviteListDialog* m_inviteListDialog;
ndn::shared_ptr<chronos::ValidatorInvitation> m_invitationValidator;
boost::recursive_mutex m_msgMutex;
boost::recursive_mutex m_sceneMutex;
QList<QString> m_zombieList;
int m_zombieIndex;
};
#endif // CHAT_DIALOG_H