blob: a8e385d3a2e1aea86a6ce6766bb0e2744ea6c51d [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"
Zhenkai Zhu0b3fa332012-09-27 21:58:43 -070015#define APPLICATION "CHRONOS"
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070016
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070017class QAction;
18class QMenu;
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070019class QStringListModel;
Zhenkai Zhu560ef1b2012-09-28 14:23:33 -070020class QTextTable;
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070021
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070022class ChatDialog : public QDialog, private Ui::ChatDialog
23{
24 Q_OBJECT
25
26public:
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070027 ChatDialog(QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070028 ~ChatDialog();
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070029 void setVisible(bool visible);
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070030 void appendMessage(const SyncDemo::ChatMessage msg);
31 void processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>, Sync::SyncAppSocket *);
32 void processDataWrapper(std::string, const char *buf, size_t len);
Zhenkai Zhubb198112012-09-27 11:31:42 -070033 void processDataNoShowWrapper(std::string, const char *buf, size_t len);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070034 void processRemoveWrapper(std::string);
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070035
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070036protected:
37 void closeEvent(QCloseEvent *e);
38 void changeEvent(QEvent *e);
39
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070040public slots:
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070041 void processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
Zhenkai Zhubb198112012-09-27 11:31:42 -070042 void processData(QString name, const char *buf, size_t len, bool show);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070043 void processRemove(QString);
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070044
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070045private:
Zhenkai Zhu59245aa2012-09-26 16:07:04 -070046 QString getRandomString();
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070047 void formChatMessage(const QString &text, SyncDemo::ChatMessage &msg);
Zhenkai Zhub5b78462012-09-28 14:10:37 -070048 void formControlMessage(SyncDemo::ChatMessage &msg, SyncDemo::ChatMessage::ChatMessageType type);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070049 void sendMsg(SyncDemo::ChatMessage &msg);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070050 bool readSettings();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070051 void writeSettings();
52 void updateLabels();
Zhenkai Zhud13acd02012-06-04 15:25:20 -070053 void resizeEvent(QResizeEvent *);
54 void showEvent(QShowEvent *);
55 void fitView();
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070056 void testDraw();
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070057 void createTrayIcon();
58 void createActions();
Zhenkai Zhu560ef1b2012-09-28 14:23:33 -070059 QString formatTime(time_t);
60 void printTimeInCell(QTextTable *, time_t);
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070061
62private slots:
63 void returnPressed();
Zhenkai Zhu85845d22012-06-01 23:10:43 -070064 void buttonPressed();
Zhenkai Zhub60b7e12012-09-28 11:34:21 -070065 void treeButtonPressed();
Zhenkai Zhue837f792012-06-05 20:47:54 -070066 void checkSetting();
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070067 void settingUpdated(QString, QString, QString);
Zhenkai Zhu3e26bb42012-09-27 11:04:09 -070068 void sendHello();
Zhenkai Zhu25e33e52012-09-28 13:00:07 -070069 void sendJoin();
Zhenkai Zhu86df7412012-09-27 16:30:20 -070070 void replot();
Zhenkai Zhu25e33e52012-09-28 13:00:07 -070071 void updateRosterList(QStringList);
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070072
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070073 // icon related
74 void iconActivated(QSystemTrayIcon::ActivationReason reason);
75 void showMessage(QString, QString);
76 void messageClicked();
77
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070078signals:
Zhenkai Zhubb198112012-09-27 11:31:42 -070079 void dataReceived(QString name, const char *buf, size_t len, bool show);
Zhenkai Zhu64f9ede2012-06-05 11:32:00 -070080 void treeUpdated(const std::vector<Sync::MissingDataInfo>);
Zhenkai Zhu2425b6a2012-09-26 17:11:44 -070081 void removeReceived(QString prefix);
Zhenkai Zhu10ccb5a2012-06-04 21:55:14 -070082
Zhenkai Zhu5a8d5aa2012-05-30 21:25:23 -070083private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070084 User m_user;
Zhenkai Zhub45e38a2012-06-01 15:44:36 -070085 Sync::SyncAppSocket *m_sock;
Zhenkai Zhu82a62752012-06-04 17:11:04 -070086 uint32_t m_session;
87 DigestTreeScene *m_scene;
Zhenkai Zhu9036e032012-09-27 20:59:33 -070088 boost::recursive_mutex m_msgMutex;
89 boost::recursive_mutex m_sceneMutex;
Zhenkai Zhu3e26bb42012-09-27 11:04:09 -070090 time_t m_lastMsgTime;
Zhenkai Zhuee5c90f2012-09-27 14:05:41 -070091 int m_randomizedInterval;
Zhenkai Zhu86df7412012-09-27 16:30:20 -070092 QTimer *m_timer;
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070093 QStringListModel *m_rosterModel;
Zhenkai Zhu3974a492012-09-28 14:39:45 -070094 bool m_minimaniho;
Zhenkai Zhu3a008fc2012-06-08 17:36:39 -070095
96 // icon related
97 QAction *minimizeAction;
98 QAction *maximizeAction;
99 QAction *restoreAction;
100 QAction *quitAction;
101 QSystemTrayIcon *trayIcon;
102 QMenu *trayIconMenu;
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -0700103};
104#endif