OSDN Git Service

ソースツリー内のipadicを自動的に参照できるよう変更。
[wordring-tm/wordring-tm.git] / proxy / tmsocket.h
1 #ifndef TMSOCKET_H
2 #define TMSOCKET_H
3
4 #include "html.h"
5 #include "text.h"
6
7 #include <QObject>
8
9 #include <QString>
10 #include <QList>
11
12 #include <QMutex>
13
14 #include <QWebSocket>
15 #include <QWebSocketServer>
16
17 namespace TM
18 {
19
20 class Widget;
21
22 class HtmlData : public RangeData
23 {
24 public:
25         typedef std::shared_ptr<HtmlData> pointer;
26
27         enum : int { Type = UserData::User + 1, };
28
29 private:
30         HtmlData(HtmlNode node_, int begin_, int tail_);
31
32 public:
33         int type() const;
34
35         static pointer create(HtmlNode node_, int begin_, int tail_);
36
37 private:
38         HtmlNode m_node;
39 };
40
41 class TextConverter
42 {
43 public:
44         //TextConverter();
45
46         Text::pointer to_text(HtmlRange range);
47         Text::pointer stuff_text(Text::pointer parent, QString const &string);
48
49         bool is_ignorable_white_space(QChar const &ch);
50
51         static bool is_white_space(QChar const &ch);
52
53 private:
54         int m_state;
55 };
56
57 class SocketConnection : public QObject
58 {
59         Q_OBJECT
60
61 public:
62         SocketConnection(Widget *widget, QWebSocket *socket);
63         virtual ~SocketConnection();
64
65         //quint16 port() const;
66         QWebSocket* socket();
67         void send_message(QString const &message);
68         void send_message(QJsonObject const &json);
69
70         void set_edit_mode(bool edit_mode);
71         //void set_source_language(int code);
72         //void set_target_language(int code);
73
74 signals:
75         void editCmd(int id, QString html);
76
77 public slots:
78         void changeEditMode(bool edit_mode);
79
80 private:
81         void do_edit(QJsonObject const &json);
82         void do_focus(QJsonObject const &json);
83         void do_blur(QJsonObject const &json);
84         void do_load(QJsonObject const &json);
85
86         Text::pointer to_text(HtmlRange range) const;
87
88 private slots:
89         void onTextMessageReceived(QString const &message);
90         void onBinaryMessageReceived(QByteArray const &message);
91
92 private:
93         QMutex m_mutex;
94
95         bool m_edit_mode;
96         int m_source_language;
97         int m_target_language;
98
99         Widget *m_widget;
100
101         HtmlDocument m_document;
102 };
103
104 class SocketServer : public QObject
105 {
106         Q_OBJECT
107 public:
108         SocketServer(Widget *widget, quint16 port, QObject *parent);
109
110         quint16 port() const;
111
112 signals:
113
114 public slots:
115         void onNewConnection();
116         void onDisconnected();
117
118 private:
119         void attachConnections(QWebSocket* socket);
120         void detachConnections(QWebSocket* socket);
121 signals:
122
123 private:
124         QWebSocketServer *m_server;
125         Widget *m_widget;
126 };
127
128 } // namespace TM
129
130 #endif // TMSOCKET_H