| /* -*- 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 CHATDIALOG_H |
| #define CHATDIALOG_H |
| |
| #include <QDialog> |
| #include <QTextTable> |
| #include <QStringListModel> |
| #include <QSystemTrayIcon> |
| #include <QMenu> |
| |
| #include "invitelistdialog.h" |
| |
| #ifndef Q_MOC_RUN |
| #include "contact-item.h" |
| #include "chatbuf.pb.h" |
| #include "digesttreescene.h" |
| #include <sync-socket.h> |
| #include <sync-seq-no.h> |
| #include <ndn-cpp-dev/security/key-chain.hpp> |
| #ifdef WITH_SECURITY |
| #include "validator-invitation.h" |
| #include <validator-sync.h> |
| #else |
| #include <ndn-cpp-dev/security/validator-null.hpp> |
| #endif |
| |
| #include <boost/thread/locks.hpp> |
| #include <boost/thread/recursive_mutex.hpp> |
| #include <boost/thread/thread.hpp> |
| #endif |
| |
| typedef ndn::function<void()> OnEventualTimeout; |
| |
| #define MAX_HISTORY_ENTRY 20 |
| |
| namespace Ui { |
| class ChatDialog; |
| } |
| |
| class ChatDialog : public QDialog |
| { |
| Q_OBJECT |
| |
| public: |
| explicit ChatDialog(ndn::shared_ptr<chronos::ContactManager> contactManager, |
| ndn::shared_ptr<ndn::Face> face, |
| const ndn::Name& chatroomPrefix, |
| const ndn::Name& localPrefix, |
| const ndn::Name& defaultIdentity, |
| const std::string& nick, |
| QWidget *parent = 0); |
| |
| ~ChatDialog(); |
| |
| const ndn::Name& |
| getChatroomPrefix() const |
| { return m_chatroomPrefix; } |
| |
| const ndn::Name& |
| getLocalPrefix() const |
| { return m_localPrefix; } |
| |
| void |
| sendInvitation(ndn::shared_ptr<chronos::ContactItem> contact, bool isIntroducer); |
| |
| void |
| addChatDataRule(const ndn::Name& prefix, |
| const ndn::IdentityCertificate& identityCertificate, |
| bool isIntroducer); |
| |
| void |
| addTrustAnchor(const chronos::EndorseCertificate& selfEndorseCertificate); |
| |
| void |
| appendMessage(const SyncDemo::ChatMessage msg, bool isHistory = false); |
| |
| 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); |
| |
| void |
| publishIntroCert(const ndn::IdentityCertificate& dskCertificate, bool isIntroducer); |
| |
| protected: |
| void |
| closeEvent(QCloseEvent *e); |
| |
| void |
| changeEvent(QEvent *e); |
| |
| private: |
| |
| void |
| initializeSetting(); |
| |
| QString |
| getRandomString(); |
| |
| void |
| updateLabels(); |
| |
| void |
| initializeSync(); |
| |
| void |
| onTargetData(const ndn::Interest& interest, |
| const ndn::Data& data, |
| const ndn::OnDataValidated& onValidated, |
| const ndn::OnDataValidationFailed& onValidationFailed) |
| { m_invitationValidator->validate(data, onValidated, onValidationFailed); } |
| |
| void |
| onTargetTimeout(const ndn::Interest& interest, |
| int retry, |
| const ndn::OnDataValidated& onValidated, |
| const ndn::OnDataValidationFailed& onValidationFailed, |
| const OnEventualTimeout& timeoutNotify) |
| { |
| if(retry > 0) |
| sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, retry-1); |
| else |
| timeoutNotify(); |
| } |
| |
| void |
| sendInterest(const ndn::Interest& interest, |
| const ndn::OnDataValidated& onValidated, |
| const ndn::OnDataValidationFailed& onValidationFailed, |
| const OnEventualTimeout& timeoutNotify, |
| int retry = 1); |
| |
| void |
| onInviteReplyValidated(const ndn::shared_ptr<const ndn::Data>& data, |
| const ndn::Name& identity, |
| bool isIntroduce); |
| |
| void |
| onInviteReplyValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, |
| const ndn::Name& identity); |
| |
| void |
| onInviteReplyTimeout(const ndn::Name& identity); |
| |
| |
| void |
| invitationRejected(const ndn::Name& identity); |
| |
| void |
| invitationAccepted(const ndn::Name& identity, |
| ndn::shared_ptr<const ndn::Data> data, |
| const std::string& inviteePrefix, |
| bool isIntroducer); |
| |
| void |
| onLocalPrefix(const ndn::Interest& interest, |
| ndn::Data& data); |
| |
| void |
| onLocalPrefixTimeout(const ndn::Interest& interest); |
| |
| // void |
| // fetchHistory(std::string name); |
| |
| void |
| formChatMessage(const QString &text, SyncDemo::ChatMessage &msg); |
| |
| void |
| formControlMessage(SyncDemo::ChatMessage &msg, SyncDemo::ChatMessage::ChatMessageType type); |
| |
| void |
| sendMsg(SyncDemo::ChatMessage &msg); |
| |
| void |
| resizeEvent(QResizeEvent *); |
| |
| void |
| showEvent(QShowEvent *); |
| |
| void |
| fitView(); |
| |
| void |
| createActions(); |
| |
| void |
| createTrayIcon(); |
| |
| QString |
| formatTime(time_t); |
| |
| void |
| printTimeInCell(QTextTable *, time_t); |
| |
| void |
| disableTreeDisplay(); |
| |
| signals: |
| void |
| dataReceived(ndn::shared_ptr<const ndn::Data> data, bool show, bool isHistory); |
| |
| void |
| treeUpdated(const std::vector<Sync::MissingDataInfo>); |
| |
| void |
| removeReceived(QString prefix); |
| |
| void |
| closeChatDialog(const ndn::Name& chatroomPrefix); |
| |
| void |
| noNdnConnection(const QString& msg); |
| |
| void |
| inivationRejection(const QString& msg); |
| |
| void |
| triggerHello(); |
| |
| void |
| triggerJoin(); |
| |
| void |
| triggerLeave(); |
| |
| void |
| triggerReplot(); |
| |
| void |
| triggerEnableTreeDisplay(); |
| |
| void |
| triggerReap(); |
| |
| public slots: |
| void |
| processTreeUpdate(const std::vector<Sync::MissingDataInfo>&); |
| |
| void |
| processData(ndn::shared_ptr<const ndn::Data> data, bool show, bool isHistory); |
| |
| void |
| processRemove(QString prefix); |
| |
| private slots: |
| void |
| returnPressed(); |
| |
| void |
| treeButtonPressed(); |
| |
| void |
| settingUpdated(QString, QString, QString); |
| |
| void |
| sendJoinWrapper(); |
| |
| void |
| sendJoin(); |
| |
| void |
| sendHelloWrapper(); |
| |
| void |
| sendHello(); |
| |
| void |
| sendLeave(); |
| |
| void |
| sendLeaveWrapper(); |
| |
| void |
| replot(); |
| |
| void |
| replotWrapper(); |
| |
| void |
| updateRosterList(QStringList); |
| |
| void |
| enableTreeDisplay(); |
| |
| void |
| enableTreeDisplayWrapper(); |
| |
| void |
| updateLocalPrefix(); |
| |
| void |
| summonReaper(); |
| |
| void |
| reap(); |
| |
| void |
| reapWrapper(); |
| |
| void |
| iconActivated(QSystemTrayIcon::ActivationReason reason); |
| |
| void |
| messageClicked(); |
| |
| void |
| showMessage(QString, QString); |
| |
| void |
| openInviteListDialog(); |
| |
| void |
| sendInvitationWrapper(QString, bool); |
| |
| void |
| quit(); |
| |
| private: |
| Ui::ChatDialog *ui; |
| ndn::shared_ptr<chronos::ContactManager> m_contactManager; |
| ndn::shared_ptr<ndn::Face> m_face; |
| ndn::shared_ptr<boost::asio::io_service> m_ioService; |
| |
| ndn::Name m_chatroomPrefix; |
| ndn::Name m_localPrefix; |
| ndn::Name m_localChatPrefix; |
| ndn::Name m_defaultIdentity; |
| User m_user; |
| std::string m_nick; |
| |
| ndn::Scheduler m_scheduler; |
| ndn::EventId m_replotEventId; |
| |
| #ifndef WITH_SECURITY |
| ndn::shared_ptr<ndn::Validator> m_invitationValidator; |
| ndn::shared_ptr<ndn::Validator> m_syncValidator; |
| #else |
| ndn::shared_ptr<chronos::ValidatorInvitation> m_invitationValidator; |
| ndn::shared_ptr<Sync::ValidatorSync> m_syncValidator; |
| #endif |
| ndn::shared_ptr<ndn::KeyChain> m_keyChain; |
| |
| ndn::Name m_newLocalPrefix; |
| bool m_newLocalPrefixReady; |
| |
| |
| Sync::SyncSocket *m_sock; |
| uint64_t m_session; |
| DigestTreeScene *m_scene; |
| boost::recursive_mutex m_msgMutex; |
| boost::recursive_mutex m_sceneMutex; |
| int64_t m_lastMsgTime; |
| int m_randomizedInterval; |
| |
| |
| QStringListModel *m_rosterModel; |
| QSystemTrayIcon *trayIcon; |
| |
| QAction *minimizeAction; |
| QAction *maximizeAction; |
| QAction *restoreAction; |
| QAction *updateLocalPrefixAction; |
| QAction *quitAction; |
| QMenu *trayIconMenu; |
| |
| bool m_joined; |
| |
| QList<QString> m_zombieList; |
| int m_zombieIndex; |
| |
| InviteListDialog* m_inviteListDialog; |
| }; |
| |
| #endif // ChatDIALOG_H |