blob: 3f75247ef9450281fb458ae726361155fcd777b4 [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 Zhu44b43752012-06-05 21:18:37 -07004#include <boost/thread/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;
19
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070020class ChatDialog : public QDialog, private Ui::ChatDialog
21{
22 Q_OBJECT
23
24public:
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070025 ChatDialog(QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070026 ~ChatDialog();
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070027 void setVisible(bool visible);
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070028 void appendMessage(const SyncDemo::ChatMessage msg);
29 void processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>, Sync::SyncAppSocket *);
30 void processDataWrapper(std::string, const char *buf, size_t len);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070031 void processRemoveWrapper(std::string);
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070032
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070033protected:
34 void closeEvent(QCloseEvent *e);
35 void changeEvent(QEvent *e);
36
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070037public slots:
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070038 void processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
39 void processData(QString name, const char *buf, size_t len);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070040 void processRemove(QString);
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070041
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070042private:
Zhenkai Zhu59245aa2012-09-26 16:07:04 -070043 QString getRandomString();
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070044 void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070045 void formHelloMessage(SyncDemo::ChatMessage &msg);
46 void sendMsg(SyncDemo::ChatMessage &msg);
47 void sendHello();
Zhenkai Zhu82a62752012-06-04 17:11:04 -070048 bool readSettings();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070049 void writeSettings();
50 void updateLabels();
Zhenkai Zhud13acd02012-06-04 15:25:20 -070051 void resizeEvent(QResizeEvent *);
52 void showEvent(QShowEvent *);
53 void fitView();
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070054 void testDraw();
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070055 void createTrayIcon();
56 void createActions();
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070057
58private slots:
59 void returnPressed();
Zhenkai Zhu85845d22012-06-01 23:10:43 -070060 void buttonPressed();
Zhenkai Zhue837f792012-06-05 20:47:54 -070061 void checkSetting();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070062 void settingUpdated(QString, QString, QString);
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070063
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070064 // icon related
65 void iconActivated(QSystemTrayIcon::ActivationReason reason);
66 void showMessage(QString, QString);
67 void messageClicked();
68
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070069signals:
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070070 void dataReceived(QString name, const char *buf, size_t len);
71 void treeUpdated(const std::vector<Sync::MissingDataInfo>);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070072 void removeReceived(QString prefix);
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070073
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070074private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070075 User m_user;
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070076 Sync::SyncAppSocket *m_sock;
Zhenkai Zhu82a62752012-06-04 17:11:04 -070077 uint32_t m_session;
78 DigestTreeScene *m_scene;
Zhenkai Zhu44b43752012-06-05 21:18:37 -070079 boost::mutex m_msgMutex;
80 boost::mutex m_sceneMutex;
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070081
82 // icon related
83 QAction *minimizeAction;
84 QAction *maximizeAction;
85 QAction *restoreAction;
86 QAction *quitAction;
87 QSystemTrayIcon *trayIcon;
88 QMenu *trayIconMenu;
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070089};
90#endif