blob: 0d4984ab1a07cb27bd35606ea437c9a1eea83b06 [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:
Zhenkai Zhu59245aa2012-09-26 16:07:04 -070042 QString getRandomString();
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070043 void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070044 bool readSettings();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070045 void writeSettings();
46 void updateLabels();
Zhenkai Zhud13acd02012-06-04 15:25:20 -070047 void resizeEvent(QResizeEvent *);
48 void showEvent(QShowEvent *);
49 void fitView();
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070050 void testDraw();
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070051 void createTrayIcon();
52 void createActions();
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070053
54private slots:
55 void returnPressed();
Zhenkai Zhu85845d22012-06-01 23:10:43 -070056 void buttonPressed();
Zhenkai Zhue837f792012-06-05 20:47:54 -070057 void checkSetting();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070058 void settingUpdated(QString, QString, QString);
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070059
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070060 // icon related
61 void iconActivated(QSystemTrayIcon::ActivationReason reason);
62 void showMessage(QString, QString);
63 void messageClicked();
64
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070065signals:
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070066 void dataReceived(QString name, const char *buf, size_t len);
67 void treeUpdated(const std::vector<Sync::MissingDataInfo>);
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070068
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070069private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070070 User m_user;
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070071 Sync::SyncAppSocket *m_sock;
Zhenkai Zhu82a62752012-06-04 17:11:04 -070072 uint32_t m_session;
73 DigestTreeScene *m_scene;
Zhenkai Zhu44b43752012-06-05 21:18:37 -070074 boost::mutex m_msgMutex;
75 boost::mutex m_sceneMutex;
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070076
77 // icon related
78 QAction *minimizeAction;
79 QAction *maximizeAction;
80 QAction *restoreAction;
81 QAction *quitAction;
82 QSystemTrayIcon *trayIcon;
83 QMenu *trayIconMenu;
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070084};
85#endif