blob: 902316fa7e66550600c73d46ce72fe9bb5b587d7 [file] [log] [blame]
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -07001#ifndef CHATDIALOG_H
2#define CHATDIALOG_H
Zhenkai Zhub45e38a2012-06-01 15:44:36 -07003#include <boost/function.hpp>
Zhenkai Zhu9036e032012-09-27 20:59:33 -07004#include <boost/thread/recursive_mutex.hpp>
Zhenkai Zhub45e38a2012-06-01 15:44:36 -07005#include <vector>
6#include "digesttreescene.h"
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -07007#include "ui_chatdialog.h"
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -07008#include "chatbuf.pb.h"
Zhenkai Zhu90ee76c2012-06-01 16:00:25 -07009#include <sync-app-socket.h>
Zhenkai Zhu85845d22012-06-01 23:10:43 -070010#include <sync-logic.h>
11#include <sync-seq-no.h>
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070012#include <QSystemTrayIcon>
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070013
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070014#define ORGANIZATION "IRL@UCLA"
15#define APPLICATION "SYNC-DEMO"
16
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070017class QAction;
18class QMenu;
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070019class QStringListModel;
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070020
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070021class ChatDialog : public QDialog, private Ui::ChatDialog
22{
23 Q_OBJECT
24
25public:
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070026 ChatDialog(QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070027 ~ChatDialog();
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070028 void setVisible(bool visible);
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070029 void appendMessage(const SyncDemo::ChatMessage msg);
30 void processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>, Sync::SyncAppSocket *);
31 void processDataWrapper(std::string, const char *buf, size_t len);
Zhenkai Zhubb198112012-09-27 11:31:42 -070032 void processDataNoShowWrapper(std::string, const char *buf, size_t len);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070033 void processRemoveWrapper(std::string);
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070034
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070035protected:
36 void closeEvent(QCloseEvent *e);
37 void changeEvent(QEvent *e);
38
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070039public slots:
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070040 void processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
Zhenkai Zhubb198112012-09-27 11:31:42 -070041 void processData(QString name, const char *buf, size_t len, bool show);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070042 void processRemove(QString);
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070043
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070044private:
Zhenkai Zhu59245aa2012-09-26 16:07:04 -070045 QString getRandomString();
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070046 void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070047 void formHelloMessage(SyncDemo::ChatMessage &msg);
48 void sendMsg(SyncDemo::ChatMessage &msg);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070049 bool readSettings();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070050 void writeSettings();
51 void updateLabels();
Zhenkai Zhud13acd02012-06-04 15:25:20 -070052 void resizeEvent(QResizeEvent *);
53 void showEvent(QShowEvent *);
54 void fitView();
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070055 void testDraw();
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070056 void createTrayIcon();
57 void createActions();
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070058
59private slots:
60 void returnPressed();
Zhenkai Zhu85845d22012-06-01 23:10:43 -070061 void buttonPressed();
Zhenkai Zhue837f792012-06-05 20:47:54 -070062 void checkSetting();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070063 void settingUpdated(QString, QString, QString);
Zhenkai Zhu3e26bb42012-09-27 11:04:09 -070064 void sendHello();
Zhenkai Zhu86df7412012-09-27 16:30:20 -070065 void replot();
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070066 void updateRosterList();
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070067
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070068 // icon related
69 void iconActivated(QSystemTrayIcon::ActivationReason reason);
70 void showMessage(QString, QString);
71 void messageClicked();
72
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070073signals:
Zhenkai Zhubb198112012-09-27 11:31:42 -070074 void dataReceived(QString name, const char *buf, size_t len, bool show);
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070075 void treeUpdated(const std::vector<Sync::MissingDataInfo>);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070076 void removeReceived(QString prefix);
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070077
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070078private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070079 User m_user;
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070080 Sync::SyncAppSocket *m_sock;
Zhenkai Zhu82a62752012-06-04 17:11:04 -070081 uint32_t m_session;
82 DigestTreeScene *m_scene;
Zhenkai Zhu9036e032012-09-27 20:59:33 -070083 boost::recursive_mutex m_msgMutex;
84 boost::recursive_mutex m_sceneMutex;
Zhenkai Zhu3e26bb42012-09-27 11:04:09 -070085 time_t m_lastMsgTime;
Zhenkai Zhuee5c90f2012-09-27 14:05:41 -070086 int m_randomizedInterval;
Zhenkai Zhu86df7412012-09-27 16:30:20 -070087 QTimer *m_timer;
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070088 QStringListModel *m_rosterModel;
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070089
90 // icon related
91 QAction *minimizeAction;
92 QAction *maximizeAction;
93 QAction *restoreAction;
94 QAction *quitAction;
95 QSystemTrayIcon *trayIcon;
96 QMenu *trayIconMenu;
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070097};
98#endif