blob: 116e20e6b1c0cd2ae2a0dc9edd0f322ad66e7e8a [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 Zhu82a62752012-06-04 17:11:04 -070028 void processRemove(const std::string);
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 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 Zhu10ccb5a2012-06-04 21:55:14 -070040
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070041private:
42 void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070043 bool readSettings();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070044 void writeSettings();
45 void updateLabels();
Zhenkai Zhud13acd02012-06-04 15:25:20 -070046 void resizeEvent(QResizeEvent *);
47 void showEvent(QShowEvent *);
48 void fitView();
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070049 void testDraw();
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070050 void createTrayIcon();
51 void createActions();
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070052
53private slots:
54 void returnPressed();
Zhenkai Zhu85845d22012-06-01 23:10:43 -070055 void buttonPressed();
Zhenkai Zhue837f792012-06-05 20:47:54 -070056 void checkSetting();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070057 void settingUpdated(QString, QString, QString);
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070058
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070059 // icon related
60 void iconActivated(QSystemTrayIcon::ActivationReason reason);
61 void showMessage(QString, QString);
62 void messageClicked();
63
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070064signals:
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070065 void dataReceived(QString name, const char *buf, size_t len);
66 void treeUpdated(const std::vector<Sync::MissingDataInfo>);
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070067
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070068private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070069 User m_user;
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070070 Sync::SyncAppSocket *m_sock;
Zhenkai Zhu82a62752012-06-04 17:11:04 -070071 uint32_t m_session;
72 DigestTreeScene *m_scene;
Zhenkai Zhu44b43752012-06-05 21:18:37 -070073 boost::mutex m_msgMutex;
74 boost::mutex m_sceneMutex;
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070075
76 // icon related
77 QAction *minimizeAction;
78 QAction *maximizeAction;
79 QAction *restoreAction;
80 QAction *quitAction;
81 QSystemTrayIcon *trayIcon;
82 QMenu *trayIconMenu;
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070083};
84#endif