-
Notifications
You must be signed in to change notification settings - Fork 7
/
guibehind.h
217 lines (179 loc) · 5.91 KB
/
guibehind.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* DUKTO - A simple, fast and multi-platform file transfer tool for LAN users
* Copyright (C) 2011 Emanuele Colombo
* 2020 KylinSoft Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef GUIBEHIND_H
#define GUIBEHIND_H
#include <QObject>
#include <QNetworkInterface>
#include <QtNetwork/QUdpSocket>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QHostInfo>
#include <QQuickView>
#include <QQmlProperty>
#include <QQmlContext>
#include <QDesktopServices>
#include <QFileDialog>
#include <QApplication>
#include <QDesktopWidget>
#include <QStringList>
#include <QThread>
#include <QHash>
#include <QIcon>
#include <QTimer>
#include <QDebug>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include "buddylistitemmodel.h"
#include "recentlistitemmodel.h"
#include "ipaddressitemmodel.h"
#include "theme.h"
#include "chatwidget.h"
#include "peer.h"
#include "ksocket.h"
#include "daemonipcdbus.h"
#define NETWORK_PORT 9696
#define UDP_NETWORK_PORT 9695
#define UDP_BROADCAST 0x01
#define UDP_UNICAST 0x02
#define UDP_GOODBYE 0x03
class MiniWebServer;
class Settings;
class DuktoWindow;
class QNetworkAccessManager;
class QNetworkReply;
class DuktoProtocol;
class KTcpServer;
class GuiBehind : public QObject
{
Q_OBJECT
Q_PROPERTY(QString currentPath READ currentPath NOTIFY currentPathChanged)
Q_PROPERTY(QString iconPath READ iconPath WRITE setIconPath NOTIFY iconPathChanged)
Q_PROPERTY(QString appVersion READ appVersion NOTIFY appVersionChanged)
public:
explicit GuiBehind(DuktoWindow* view);
virtual ~GuiBehind();
// 管理所有的Tcp连接
/*<mac , KSocket in a thread>*/
QMap<QString, KSocket *> sockets;
// 好友列表界面model
BuddyListItemModel mBuddiesList;
// 管理所有的聊天窗口
QMap<QString, ChatWidget *> cws;
QMap<QString, QStringList> tmpMsgs;
inline Settings* settings() { return mSettings; }
QString currentPath();
void setCurrentPath(QString path);
QString sizeHuman(qint64 size);
void close();
// app icon in about qml
// 关于界面的图标路径
QString iconPath();
void setIconPath(QString path);
// app version in about qml
// 关于界面的版本号
QString appVersion();
void setAppVersion(QString path);
ChatWidget * createCW(QString mac);
signals:
void currentPathChanged();
void iconPathChanged();
void appVersionChanged();
public slots:
void periodicHello();
void peerListAdded(Peer peer);
void peerListRemoved(Peer peer);
void openDestinationFolder();
void refreshIpList();
void changeDestinationFolder();
void showSendPage(QString ip_mac);
void changeThemeColor(QString color);
void sendTextComplete_add_recentlist(QString text , QString mac);
void sendFileComplete_add_recentlist(QStringList *files, qint64 totalSize, QString dir, QString mac);
void receiveTextComplete(QString text, QString mac);
void receiveFileComplete(QStringList *files, qint64 totalSize, QString dir, QString mac);
void reSaveCw(QString ip_mac);
void newMsgAlert(QString mac);
void removeRecentItem(QString mac);
void msgAlert();
// 查看用户手册
void viewUserGuide();
private:
DuktoWindow *mView;
QTimer *mPeriodicHelloTimer;
MiniWebServer *mMiniWebServer;
Settings *mSettings;
RecentListItemModel mRecentList;
IpAddressItemModel mIpAddresses;
DuktoProtocol *mDuktoProtocol;
Theme mTheme;
DaemonIpcDbus *mDaemonIpcDbus;
int cwx;
int cwy;
int timeFlag;
QTimer *alertTimer;
QIcon iconDukto;
QIcon iconBlank;
};
class DuktoProtocol : public QObject
{
Q_OBJECT
public:
DuktoProtocol(GuiBehind *gb);
virtual ~DuktoProtocol();
void initialize();
void sayHello(QHostAddress dest);
void sayGoodbye();
// 废弃的KSocket列表
QList<KSocket *> discardSockets;
GuiBehind *gbehind;
QString pSystemSignature;
public slots:
void newUdpData();
void newIncomingConnection(qintptr socketDescriptor);
void newOutgoingConnection(QString targetIP, QString remoteID, ChatWidget *cw);
void updateRemoteID(QString ip, QString user_name , QString system , QString mac , QString Platform , KSocket*);
void updateSockets(QString pRemoteID);
void addUpBuddy(QString ip, QString user_name , QString system , QString mac , QString Platform);
// 绑定聊天窗口和socket
void connectSocketAndChatWidget(ChatWidget *);
signals:
void peerListAdded(Peer peer);
void peerListRemoved(Peer peer);
private:
QString getSystemSignature();
QString getMac();
void sendToAllBroadcast(QByteArray *packet);
void handleMessage(QByteArray &data, QHostAddress &sender);
QUdpSocket *mSocket;
KTcpServer *mTcpServer;
/*<systemflag , Peer>*/
QHash<QString, Peer> mPeers;
};
class KTcpServer : public QTcpServer
{
Q_OBJECT
public:
KTcpServer();
protected:
void incomingConnection(qintptr socketDescriptor);
signals:
void newConn(qintptr socketDescriptor);
};
#endif // GUIBEHIND_H