├── tcpClient
├── client.config
├── map
│ ├── dir.png
│ └── file.png
├── config.qrc
├── FileType.qrc
├── protocol.cpp
├── main.cpp
├── online.h
├── opewidget.h
├── privatechat.h
├── opewidget.cpp
├── sharefile.h
├── tcpClient.pro
├── tcpclient.h
├── privatechat.ui
├── friend.h
├── online.cpp
├── privatechat.cpp
├── online.ui
├── book.h
├── tcpclient.ui
├── protocol.h
├── sharefile.cpp
├── friend.cpp
├── tcpclient.cpp
├── book.cpp
└── tcpClient.pro.user
├── tcpServer
├── server.config
├── cloud.db
├── config.qrc
├── main.cpp
├── protocol.cpp
├── tcpserver.ui
├── tcpserver.h
├── mytcpserver.h
├── mytcpsocket.h
├── tcpserver.cpp
├── opedb.h
├── tcpServer.pro
├── mytcpserver.cpp
├── protocol.h
├── opedb.cpp
├── mytcpsocket.cpp
└── tcpServer.pro.user
└── README.md
/tcpClient/client.config:
--------------------------------------------------------------------------------
1 | 127.0.0.1
2 | 8888
--------------------------------------------------------------------------------
/tcpServer/server.config:
--------------------------------------------------------------------------------
1 | 127.0.0.1
2 | 8888
--------------------------------------------------------------------------------
/tcpServer/cloud.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dl0520dl/TinyDisk/HEAD/tcpServer/cloud.db
--------------------------------------------------------------------------------
/tcpClient/map/dir.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dl0520dl/TinyDisk/HEAD/tcpClient/map/dir.png
--------------------------------------------------------------------------------
/tcpClient/map/file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dl0520dl/TinyDisk/HEAD/tcpClient/map/file.png
--------------------------------------------------------------------------------
/tcpClient/config.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | client.config
4 |
5 |
6 |
--------------------------------------------------------------------------------
/tcpServer/config.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | server.config
4 |
5 |
6 |
--------------------------------------------------------------------------------
/tcpClient/FileType.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | map/dir.png
4 | map/file.png
5 |
6 |
7 |
--------------------------------------------------------------------------------
/tcpServer/main.cpp:
--------------------------------------------------------------------------------
1 | #include "tcpserver.h"
2 | #include
3 |
4 | #include "opedb.h"
5 |
6 | int main(int argc, char *argv[])
7 | {
8 | QApplication a(argc, argv);
9 | OpeDB::getInstance().init();
10 | tcpServer w;
11 | w.show();
12 | return a.exec();
13 | }
14 |
--------------------------------------------------------------------------------
/tcpClient/protocol.cpp:
--------------------------------------------------------------------------------
1 | #include "protocol.h"
2 |
3 | PDU *mkPDU(unit uiMsgLen)
4 | {
5 | unit uiPDULen = sizeof(PDU) + uiMsgLen;
6 | PDU *pdu = (PDU*)malloc(uiPDULen);
7 | if(NULL == pdu){
8 | exit(EXIT_FAILURE);
9 | }
10 | memset(pdu, 0, uiPDULen);
11 | pdu->uiMsgLen = uiMsgLen;
12 | pdu->uiPDULen = uiPDULen;
13 | return pdu;
14 | }
15 |
--------------------------------------------------------------------------------
/tcpServer/protocol.cpp:
--------------------------------------------------------------------------------
1 | #include "protocol.h"
2 |
3 | PDU *mkPDU(unit uiMsgLen)
4 | {
5 | unit uiPDULen = sizeof(PDU) + uiMsgLen;
6 | PDU *pdu = (PDU*)malloc(uiPDULen);
7 | if(NULL == pdu){
8 | exit(EXIT_FAILURE);
9 | }
10 | memset(pdu, 0, uiPDULen);
11 | pdu->uiMsgLen = uiMsgLen;
12 | pdu->uiPDULen = uiPDULen;
13 | return pdu;
14 | }
15 |
--------------------------------------------------------------------------------
/tcpClient/main.cpp:
--------------------------------------------------------------------------------
1 | #include "tcpclient.h"
2 |
3 | #include
4 | #include "opewidget.h"
5 | #include "online.h"
6 | #include "friend.h"
7 | #include "sharefile.h"
8 |
9 | int main(int argc, char *argv[])
10 | {
11 | QApplication a(argc, argv);
12 |
13 | tcpClient::getInstance().show();
14 |
15 |
16 | // ShareFile w;
17 | // w.show();
18 |
19 | return a.exec();
20 | }
21 |
--------------------------------------------------------------------------------
/tcpServer/tcpserver.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | tcpServer
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | tcpServer
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tcpClient/online.h:
--------------------------------------------------------------------------------
1 | #ifndef ONLINE_H
2 | #define ONLINE_H
3 |
4 | #include
5 | #include "protocol.h"
6 |
7 |
8 | namespace Ui {
9 | class Online;
10 | }
11 |
12 | class Online : public QWidget
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit Online(QWidget *parent = nullptr);
18 | ~Online();
19 |
20 | void showUser(PDU *pdu); // 设置页面显示所有的在线用户
21 |
22 | private slots:
23 | void on_addFriend_pb_clicked();
24 |
25 | private:
26 | Ui::Online *ui;
27 | };
28 |
29 | #endif // ONLINE_H
30 |
--------------------------------------------------------------------------------
/tcpServer/tcpserver.h:
--------------------------------------------------------------------------------
1 | #ifndef TCPSERVER_H
2 | #define TCPSERVER_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui {
8 | class tcpServer;
9 | }
10 |
11 | //QT_END_NAMESPACE
12 |
13 | class tcpServer : public QWidget
14 | {
15 | Q_OBJECT
16 |
17 | public:
18 | explicit tcpServer(QWidget *parent = nullptr);
19 | ~tcpServer();
20 | void loadConfig();
21 |
22 | private:
23 | Ui::tcpServer *ui;
24 |
25 | QString m_strIP;
26 | quint16 m_usPort;
27 | };
28 | #endif // TCPSERVER_H
29 |
--------------------------------------------------------------------------------
/tcpServer/mytcpserver.h:
--------------------------------------------------------------------------------
1 | #ifndef MYTCPSERVER_H
2 | #define MYTCPSERVER_H
3 |
4 | #include
5 | #include
6 | #include "mytcpsocket.h"
7 |
8 | class MyTcpServer : public QTcpServer
9 | {
10 | Q_OBJECT
11 | private:
12 |
13 | public:
14 | MyTcpServer();
15 | static MyTcpServer &getInstance();
16 | void incomingConnection(qintptr socketDescriptor);
17 |
18 | void resend(const char *pername, PDU *pdu);
19 |
20 | public slots:
21 | void deleteSocket(MyTcpSocket *mysocket);
22 |
23 | private:
24 | QList m_tcpSocketList;
25 | };
26 |
27 | #endif // MYTCPSERVER_H
28 |
--------------------------------------------------------------------------------
/tcpClient/opewidget.h:
--------------------------------------------------------------------------------
1 | #ifndef OPEWIDGET_H
2 | #define OPEWIDGET_H
3 |
4 | #include
5 | #include
6 | #include "book.h"
7 | #include "friend.h"
8 | #include
9 |
10 | class OpeWidget : public QWidget
11 | {
12 | Q_OBJECT
13 | public:
14 | explicit OpeWidget(QWidget *parent = nullptr);
15 | static OpeWidget &getInstance();
16 | Friend *getFriend();
17 | Book *getBook();
18 |
19 | signals:
20 |
21 | public slots:
22 |
23 |
24 | private:
25 | QListWidget *m_pListW;
26 | Friend *m_pFriend;
27 | Book *m_pBook;
28 |
29 | QStackedWidget *m_pSW;
30 | };
31 |
32 | #endif // OPEWIDGET_H
33 |
--------------------------------------------------------------------------------
/tcpClient/privatechat.h:
--------------------------------------------------------------------------------
1 | #ifndef PRIVATECHAT_H
2 | #define PRIVATECHAT_H
3 |
4 | #include
5 | #include "protocol.h"
6 |
7 | namespace Ui {
8 | class PrivateChat;
9 | }
10 |
11 | class PrivateChat : public QWidget
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit PrivateChat(QWidget *parent = nullptr);
17 | ~PrivateChat();
18 |
19 | static PrivateChat &getInstance();
20 |
21 | void setChatName(QString name);
22 | void updateMsg(const PDU *pdu);
23 |
24 | private slots:
25 | void on_sendMsg_pb_clicked();
26 |
27 | private:
28 | Ui::PrivateChat *ui;
29 | QString m_strChatName;
30 | QString m_strLoginName;
31 | };
32 |
33 | #endif // PRIVATECHAT_H
34 |
--------------------------------------------------------------------------------
/tcpServer/mytcpsocket.h:
--------------------------------------------------------------------------------
1 | #ifndef MYTCPSOCKET_H
2 | #define MYTCPSOCKET_H
3 |
4 | #include
5 | #include "protocol.h"
6 | #include "opedb.h"
7 | #include
8 | #include
9 | #include
10 |
11 | class MyTcpSocket : public QTcpSocket
12 | {
13 | Q_OBJECT
14 | public:
15 | MyTcpSocket();
16 | QString getName();
17 | void copyDir(QString strSrcDir, QString strDestDir);
18 |
19 | signals:
20 | void offline(MyTcpSocket *mysocket);
21 |
22 | public slots:
23 | void recvMsg();
24 | void clientOffline();
25 | void sendFileToClient();
26 |
27 | private:
28 | QString m_strName;
29 | QFile m_file;
30 | qint64 m_iTotal;
31 | qint64 m_iReceived;
32 | bool m_bUpload;
33 |
34 | QTimer *m_pTimer;
35 |
36 | };
37 |
38 | #endif // MYTCPSOCKET_H
39 |
--------------------------------------------------------------------------------
/tcpClient/opewidget.cpp:
--------------------------------------------------------------------------------
1 | #include "opewidget.h"
2 |
3 | OpeWidget::OpeWidget(QWidget *parent) : QWidget(parent)
4 | {
5 | m_pListW = new QListWidget(this);
6 | m_pListW->addItem("好友");
7 | m_pListW->addItem("文件");
8 |
9 | m_pFriend = new Friend;
10 | m_pBook = new Book;
11 |
12 | m_pSW = new QStackedWidget;
13 | m_pSW->addWidget(m_pFriend);
14 | m_pSW->addWidget(m_pBook);
15 |
16 | QHBoxLayout *pMain = new QHBoxLayout;
17 | pMain->addWidget(m_pListW);
18 | pMain->addWidget(m_pSW);
19 | setLayout(pMain);
20 |
21 | connect(m_pListW, SIGNAL(currentRowChanged(int)), m_pSW, SLOT(setCurrentIndex(int)));
22 | }
23 |
24 | OpeWidget &OpeWidget::getInstance()
25 | {
26 | static OpeWidget instance;
27 | return instance;
28 | }
29 |
30 | Friend *OpeWidget::getFriend()
31 | {
32 | return m_pFriend;
33 | }
34 |
35 | Book *OpeWidget::getBook()
36 | {
37 | return m_pBook;
38 | }
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TinyDisk
2 | #### 基于QT实现的一个简单的网盘系统,分为好友操作和文件操作两部分。
3 | ## 一、环境:
4 | ##### 数据库:SQLite3
5 | ##### QT:5.14.2
6 | ## 二、好友操作实现的功能:
7 | ##### 好友的添加/删除/查找/私聊/群发消息(群聊)...
8 | 
9 |
10 | ## 三、文件操作实现的功能:
11 | ##### 文件的上传/下载/移动/分享/重命名...
12 | 
13 |
14 | ## 四、运行方法:
15 | ##### 1.在tcpServer下opedb.cpp中,把cloud.db文件改成自己的路径:
16 | 
17 | ##### 2.先启动tcpServer(右击选择运行),再启动tcpClient。
18 | ##### 3.cloud.db数据库中已经创建了几个用户,可直接登录:
19 | ##### 用户名:jack 密码:jack
20 | ##### 用户名:tom 密码:tom
21 | ##### 用户名:sam 密码:sam
22 | ## Tips:
23 | ##### 1.每一个用户注册时都会生成一个同名的根文件夹,其位置在与项目路径同级的build-tcpServer-Desktop_Qt_5_14_2_MinGW_32_bit-Debug文件夹下,且后续该用户所有的网盘文件/文件夹都存储在此。
24 | ##### 2.如要测试私聊/好友群发/分享文件等交互性功能,需要同时运行多个用户才能实现。
25 |
26 |
27 |
--------------------------------------------------------------------------------
/tcpClient/sharefile.h:
--------------------------------------------------------------------------------
1 | #ifndef SHAREFILE_H
2 | #define SHAREFILE_H
3 |
4 | #include
5 |
6 | #include
7 | #include // 垂直布局
8 | #include // 水平布局
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | class ShareFile : public QWidget
15 | {
16 | Q_OBJECT
17 | public:
18 | explicit ShareFile(QWidget *parent = nullptr);
19 |
20 | static ShareFile &getInstance();
21 |
22 | void updateFriend(QListWidget *pFriendList);
23 |
24 | signals:
25 |
26 | public slots:
27 | void cancelSelect();
28 | void selectAll();
29 | void shareConfirm();
30 | void shareCancel();
31 |
32 | private:
33 | QPushButton *m_pSelectAllPB;
34 | QPushButton *m_pCancelSelectPB;
35 |
36 | QPushButton *m_pConfirmPB;
37 | QPushButton *m_pCancelPB;
38 |
39 | QScrollArea *m_pSA;
40 | QWidget *m_pFriendW;
41 | QVBoxLayout *m_pFriendWVBL;
42 | QButtonGroup *m_pButtonGroup;
43 |
44 | };
45 |
46 | #endif // SHAREFILE_H
47 |
--------------------------------------------------------------------------------
/tcpClient/tcpClient.pro:
--------------------------------------------------------------------------------
1 | QT += core gui network
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++17
6 |
7 | # You can make your code fail to compile if it uses deprecated APIs.
8 | # In order to do so, uncomment the following line.
9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
10 |
11 | SOURCES += \
12 | book.cpp \
13 | friend.cpp \
14 | main.cpp \
15 | online.cpp \
16 | opewidget.cpp \
17 | privatechat.cpp \
18 | protocol.cpp \
19 | sharefile.cpp \
20 | tcpclient.cpp
21 |
22 | HEADERS += \
23 | book.h \
24 | friend.h \
25 | online.h \
26 | opewidget.h \
27 | privatechat.h \
28 | protocol.h \
29 | sharefile.h \
30 | tcpclient.h
31 |
32 | FORMS += \
33 | online.ui \
34 | privatechat.ui \
35 | tcpclient.ui
36 |
37 | # Default rules for deployment.
38 | qnx: target.path = /tmp/$${TARGET}/bin
39 | else: unix:!android: target.path = /opt/$${TARGET}/bin
40 | !isEmpty(target.path): INSTALLS += target
41 |
42 | RESOURCES += \
43 | FileType.qrc \
44 | config.qrc
45 |
--------------------------------------------------------------------------------
/tcpServer/tcpserver.cpp:
--------------------------------------------------------------------------------
1 | #include "tcpserver.h"
2 | #include "ui_tcpserver.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "mytcpserver.h"
9 |
10 | tcpServer::tcpServer(QWidget *parent)
11 | : QWidget(parent)
12 | , ui(new Ui::tcpServer)
13 | {
14 | ui->setupUi(this);
15 | loadConfig();
16 |
17 | MyTcpServer::getInstance().listen(QHostAddress(m_strIP), m_usPort);
18 | }
19 |
20 | tcpServer::~tcpServer()
21 | {
22 | delete ui;
23 | }
24 |
25 | void tcpServer::loadConfig()
26 | {
27 | QFile file(":/server.config");
28 | if(file.open(QIODevice::ReadOnly))
29 | {
30 | QByteArray baData = file.readAll();
31 | QString strData = baData.toStdString().c_str();
32 | file.close();
33 | strData.replace("\r\n"," ");
34 | QStringList strList = strData.split(" ");
35 | m_strIP = strList.at(0);
36 | m_usPort = strList.at(1).toUShort();
37 | qDebug() << "IP:" << m_strIP << "port:" << m_usPort;
38 | }
39 | else
40 | {
41 | QMessageBox::critical(this, "open config", "open config failed");
42 | }
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/tcpClient/tcpclient.h:
--------------------------------------------------------------------------------
1 | #ifndef TCPCLIENT_H
2 | #define TCPCLIENT_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include "protocol.h"
8 | #include "opewidget.h"
9 |
10 | QT_BEGIN_NAMESPACE
11 | namespace Ui {
12 | class tcpClient;
13 | }
14 | QT_END_NAMESPACE
15 |
16 | class tcpClient : public QWidget
17 | {
18 | Q_OBJECT
19 |
20 | public:
21 | tcpClient(QWidget *parent = nullptr);
22 | ~tcpClient();
23 | void loadConfig();
24 |
25 | static tcpClient &getInstance();
26 |
27 | QTcpSocket &gettcpSocket();
28 |
29 | QString loginName();
30 | QString currentPath();
31 | void setCurrentPath(QString preContentPath);
32 |
33 |
34 | public slots:
35 | void showConnect();
36 | void recvMsg();
37 |
38 | private slots:
39 | // void on_send_pb_clicked();
40 |
41 | void on_login_clicked();
42 |
43 | void on_zhuce_clicked();
44 |
45 | void on_zhuxiao_clicked();
46 |
47 | private:
48 | Ui::tcpClient *ui;
49 | QString m_strIP;
50 | quint16 m_usPort;
51 |
52 | QTcpSocket m_tcpSocket;
53 | QString m_strLoginName;
54 | QString m_strCurPath;
55 |
56 | QFile m_file;
57 | };
58 | #endif // TCPCLIENT_H
59 |
--------------------------------------------------------------------------------
/tcpServer/opedb.h:
--------------------------------------------------------------------------------
1 | #ifndef OPEDB_H
2 | #define OPEDB_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | class OpeDB : public QObject
10 | {
11 | Q_OBJECT
12 | public:
13 | explicit OpeDB(QObject *parent = 0);
14 | static OpeDB& getInstance();
15 | void init();
16 | //~OpeDB();
17 | bool handleRegist(const char *name, const char *pwd);
18 | bool handleLogin(const char *name, const char *pwd);
19 | void handleOffline(const char *name);
20 | QStringList handleAllOnline();
21 | int handleSearchUser(const char *name);
22 | //加好友,首先判断对方是否在线,如果在线的话,①对方已经是好友,②对方不是好友
23 | int handleAddFriend(const char *pername, const char *name);
24 | int getIdByUserName(const char *name); // 根据用户名获取用户id
25 | void handleAddFriendAgree(const char *addedName, const char *sourceName); // 处理同意好友申请
26 | QStringList handleFlushFriend(const char *name); // 处理同意好友申请
27 | bool handleDeleteFriend(const char *sourceName, const char *deleteName); // 删除好友申请
28 | QStringList handleGroupChat(const char *name);
29 |
30 |
31 | signals:
32 |
33 | public slots:
34 | private:
35 | QSqlDatabase m_db;
36 |
37 |
38 | };
39 |
40 | #endif // OPEDB_H
41 |
--------------------------------------------------------------------------------
/tcpClient/privatechat.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | PrivateChat
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 300
11 |
12 |
13 |
14 | Form
15 |
16 |
17 | -
18 |
19 |
-
20 |
21 |
22 | -
23 |
24 |
-
25 |
26 |
27 | -
28 |
29 |
30 |
31 | Agency FB
32 | 14
33 |
34 |
35 |
36 | 发送
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/tcpServer/tcpServer.pro:
--------------------------------------------------------------------------------
1 | QT += core gui network sql
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mytcpserver.cpp \
21 | mytcpsocket.cpp \
22 | opedb.cpp \
23 | protocol.cpp \
24 | tcpserver.cpp
25 |
26 | HEADERS += \
27 | mytcpserver.h \
28 | mytcpsocket.h \
29 | opedb.h \
30 | protocol.h \
31 | tcpserver.h
32 |
33 | FORMS += \
34 | tcpserver.ui
35 |
36 | # Default rules for deployment.
37 | qnx: target.path = /tmp/$${TARGET}/bin
38 | else: unix:!android: target.path = /opt/$${TARGET}/bin
39 | !isEmpty(target.path): INSTALLS += target
40 |
41 | DISTFILES +=
42 |
43 | RESOURCES += \
44 | config.qrc
45 |
--------------------------------------------------------------------------------
/tcpClient/friend.h:
--------------------------------------------------------------------------------
1 | #ifndef FRIEND_H
2 | #define FRIEND_H
3 |
4 | #include
5 | // 页面所用到的部件
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include // 垂直布局
11 | #include // 水平布局
12 |
13 | #include "online.h"
14 | #include "protocol.h"
15 |
16 |
17 |
18 | class Friend : public QWidget
19 | {
20 | Q_OBJECT
21 | public:
22 | explicit Friend(QWidget *parent = nullptr);
23 | void showAllOnlineUser(PDU *pdu);
24 | void updateFriendList(PDU *pdu);
25 | QString m_strSearchName;
26 | void updateGroupMsg(PDU *pdu);
27 |
28 | QListWidget *getFriendList();
29 |
30 | signals:
31 |
32 | public slots:
33 | void showOnline();
34 | void searchUser();
35 | void flushFriend();
36 | void deleteFriend();
37 | void privateChat();
38 | void groupChat();
39 |
40 |
41 |
42 | private:
43 | QTextEdit *m_pShowMsgTE; // 显示群聊信息
44 | QListWidget *m_pFriendListWidget; // 好友列表
45 | QLineEdit *m_pInputMsgLE; // 群聊信息输入框
46 | QPushButton *m_pDelFriendPB; // 删除好友
47 | QPushButton *m_pFlushFriendPB; // 刷新好友列表
48 | QPushButton *m_pShowOnlineUserPB; // 显示所有在线用户
49 | QPushButton *m_pSearchUserPB; // 查找用户
50 | QPushButton *m_pMsgSendPB; // 群聊发送消息
51 | QPushButton *m_pPrivateChatPB; // 私聊按钮,默认群聊
52 |
53 | Online *m_pOnline;
54 |
55 | };
56 |
57 | #endif // FRIEND_H
58 |
--------------------------------------------------------------------------------
/tcpClient/online.cpp:
--------------------------------------------------------------------------------
1 | #include "online.h"
2 | #include "ui_online.h"
3 | #include
4 | #include "tcpclient.h"
5 | #include
6 |
7 | Online::Online(QWidget *parent) :
8 | QWidget(parent),
9 | ui(new Ui::Online)
10 | {
11 | ui->setupUi(this);
12 | }
13 |
14 | Online::~Online()
15 | {
16 | delete ui;
17 | }
18 |
19 | void Online::showUser(PDU *pdu)
20 | {
21 | if(NULL == pdu){
22 | return;
23 | }
24 | unit uiSize = pdu->uiMsgLen / 32;
25 | char caTmp[32];
26 | for(unit i = 0; i < uiSize; i++){
27 | memcpy(caTmp, (char*)(pdu->caMsg) + i * 32, 32);
28 | // 补充:不显示自己信息,防止之后添加自己为好友等操作错误
29 | if(strcmp(caTmp, tcpClient::getInstance().loginName().toStdString().c_str()) == 0)
30 | {
31 | continue;
32 | }
33 | ui->online_lw->addItem(caTmp);
34 | }
35 | }
36 |
37 | void Online::on_addFriend_pb_clicked()
38 | {
39 | QListWidgetItem *pItem = ui->online_lw->currentItem();
40 | if(NULL == pItem)
41 | {
42 | QMessageBox::warning(this, "添加好友", "请选择要添加的好友");
43 | return;
44 | }
45 | QString strPerUserName = pItem->text();
46 | QString strLoginName = tcpClient::getInstance().loginName();
47 | PDU *pdu = mkPDU(0);
48 | qDebug() << "on_addfriend_pb_clicked " << strPerUserName << " " << strLoginName;
49 | pdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_REQUEST;
50 | memcpy(pdu->caData, strPerUserName.toStdString().c_str(), strPerUserName.size());
51 | memcpy(pdu->caData + 32, strLoginName.toStdString().c_str(), strLoginName.size());
52 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
53 | free(pdu);
54 | pdu = NULL;
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/tcpServer/mytcpserver.cpp:
--------------------------------------------------------------------------------
1 | #include "mytcpserver.h"
2 | #include
3 | #include
4 |
5 | MyTcpServer::MyTcpServer()
6 | {
7 |
8 | }
9 |
10 | MyTcpServer &MyTcpServer::getInstance()
11 | {
12 | static MyTcpServer instance;
13 | return instance;
14 | }
15 |
16 | void MyTcpServer::incomingConnection(qintptr socketDescriptor)
17 | {
18 | qDebug() << "new client connected";
19 | MyTcpSocket *pTcpSocket = new MyTcpSocket;
20 | pTcpSocket->setSocketDescriptor(socketDescriptor);
21 | m_tcpSocketList.append(pTcpSocket);
22 | connect(pTcpSocket, SIGNAL(offline(MyTcpSocket*)), this, SLOT(deleteSocket(MyTcpSocket*)));
23 | }
24 |
25 | void MyTcpServer::resend(const char *pername, PDU *pdu)
26 | {
27 | if(NULL == pername || NULL == pdu)
28 | {
29 | return;
30 | }
31 | // 查找目标用户名的Socket
32 | QString strName = pername;
33 | for(int i = 0; i < m_tcpSocketList.size(); i++)
34 | {
35 | if(strName == m_tcpSocketList.at(i)->getName()) // 查找到
36 | {
37 | m_tcpSocketList.at(i)->write((char*)pdu, pdu -> uiPDULen); // 转发消息
38 | break;
39 | }
40 | }
41 | return;
42 | }
43 |
44 |
45 | void MyTcpServer::deleteSocket(MyTcpSocket *mysocket)
46 | {
47 | QList::iterator iter = m_tcpSocketList.begin();
48 | for(; iter != m_tcpSocketList.end(); iter++){
49 | if(mysocket == *iter)
50 | {
51 | (*iter)->deleteLater();
52 |
53 | *iter = NULL;
54 | m_tcpSocketList.erase(iter);
55 | break;
56 | }
57 | }
58 | // for(int i = 0; i < m_tcpSocketList.size(); i++){
59 | // qDebug() << m_tcpSocketList.at(i)->getName();
60 | // }
61 | }
62 |
--------------------------------------------------------------------------------
/tcpClient/privatechat.cpp:
--------------------------------------------------------------------------------
1 | #include "privatechat.h"
2 | #include "ui_privatechat.h"
3 | #include "protocol.h"
4 | #include "tcpclient.h"
5 | #include
6 |
7 |
8 | PrivateChat::PrivateChat(QWidget *parent) :
9 | QWidget(parent),
10 | ui(new Ui::PrivateChat)
11 | {
12 | ui->setupUi(this);
13 | }
14 |
15 | PrivateChat::~PrivateChat()
16 | {
17 | delete ui;
18 | }
19 |
20 | PrivateChat &PrivateChat::getInstance()
21 | {
22 | static PrivateChat instance;
23 | return instance;
24 | }
25 |
26 | void PrivateChat::setChatName(QString name)
27 | {
28 | m_strChatName = name;
29 | m_strLoginName = tcpClient::getInstance().loginName();
30 |
31 | }
32 |
33 | //
34 | void PrivateChat::updateMsg(const PDU *pdu)
35 | {
36 | if(NULL == pdu)
37 | {
38 | return;
39 | }
40 | char sourceName[32] = {'\0'};
41 | memcpy(sourceName, pdu->caData, 32);
42 | QString strMsg = QString("%1 says: %2").arg(sourceName).arg((char*)pdu->caMsg);
43 | ui->showMsg_te->append(strMsg);
44 | }
45 |
46 | void PrivateChat::on_sendMsg_pb_clicked()
47 | {
48 | QString strMsg = ui->inputMsg_le->text();
49 | ui->inputMsg_le->clear();
50 | if(NULL == strMsg)
51 | {
52 | QMessageBox::warning(this, "私聊", "聊天信息不能为空");
53 | }
54 | else
55 | {
56 | PDU *pdu = mkPDU(strMsg.size() + 1);
57 | pdu->uiMsgType = ENUM_MSG_TYPE_PRIVATE_CHAT_REQUEST;
58 |
59 | memcpy(pdu->caData, m_strLoginName.toStdString().c_str(), 32);
60 | memcpy(pdu->caData + 32, m_strChatName.toStdString().c_str(), 32);
61 | strcpy((char*)pdu->caMsg, strMsg.toStdString().c_str());
62 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
63 | free(pdu);
64 | pdu = NULL;
65 |
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/tcpClient/online.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Online
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 300
11 |
12 |
13 |
14 | Form
15 |
16 |
17 | -
18 |
19 |
-
20 |
21 |
22 | true
23 |
24 |
25 |
26 | -
27 |
28 |
-
29 |
30 |
31 | Qt::Vertical
32 |
33 |
34 |
35 | 20
36 | 40
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 | 加好友
45 |
46 |
47 |
48 | -
49 |
50 |
51 | Qt::Vertical
52 |
53 |
54 |
55 | 20
56 | 40
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/tcpClient/book.h:
--------------------------------------------------------------------------------
1 | #ifndef BOOK_H
2 | #define BOOK_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include // 垂直布局
10 | #include // 水平布局
11 | #include "protocol.h"
12 | #include
13 |
14 | #include "online.h"
15 | #include "protocol.h"
16 |
17 | class Book : public QWidget
18 | {
19 | Q_OBJECT
20 | public:
21 | explicit Book(QWidget *parent = nullptr);
22 | void updateFileList(PDU *pdu);
23 | void clearEnterDir();
24 | QString enterDir();
25 |
26 | void setDownLoadStatus(bool status);
27 |
28 | qint64 m_iTotal = 0;
29 | qint64 m_iReceived = 0;
30 |
31 | bool getDownloadStatus();
32 | QString getFileSavePath();
33 | QString getShareFileName();
34 |
35 | signals:
36 |
37 | public slots:
38 | void createDir();
39 | void flushFile();
40 | void deleteDir();
41 | void renameFile();
42 | void enterDir(const QModelIndex &index);
43 | void returnPreContent();
44 | void uploadFile();
45 | void uploadFileData();
46 | void deleteFile();
47 |
48 | void downloadFile();
49 | void shareFile();
50 |
51 | void moveFile();
52 | void selectDestDir();
53 |
54 |
55 | private:
56 | QListWidget *m_pFileListWidget; // 文件列表
57 | QPushButton *m_pReturnPB; // 返回主页面
58 | QPushButton *m_pCreateDirPB; // 新建文件夹
59 | QPushButton *m_pDeleteDirPB; // 删除文件夹
60 | QPushButton *m_pRenameFilePB; // 重命名文件
61 | QPushButton *m_pFlushFilePB; // 刷新文件
62 | QPushButton *m_pUploadFilePB; // 上传文件
63 | QPushButton *m_pDownLoadFilePB; // 下载文件
64 | QPushButton *m_pDeleteFilePB; // 删除文件
65 | QPushButton *m_pShareFilePB; // 分享文件
66 | QPushButton *m_pMoveFilePB; //移动文件
67 | QPushButton *m_pSelectMoveToDirPB; //移动文件到其他文件夹
68 |
69 | QString m_strEnterDir;
70 | QString m_strUploadFilePath;
71 | QString m_strFileSavePath;
72 | QString m_strShareFileName;
73 | QString m_strMoveFileName;
74 | QString m_strMoveFilePath;
75 | QString m_strDestDirPath;
76 |
77 | QTimer *m_pTimer;
78 | bool m_bDownload;
79 | };
80 |
81 | #endif // BOOK_H
82 |
--------------------------------------------------------------------------------
/tcpClient/tcpclient.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | tcpClient
4 |
5 |
6 |
7 | 0
8 | 0
9 | 459
10 | 327
11 |
12 |
13 |
14 | tcpClient
15 |
16 |
17 |
18 |
19 | 11
20 | 11
21 | 391
22 | 281
23 |
24 |
25 |
26 | -
27 |
28 |
-
29 |
30 |
31 |
32 | Agency FB
33 | 16
34 |
35 |
36 |
37 | 用户名:
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 | Agency FB
46 | 16
47 |
48 |
49 |
50 | 密 码:
51 |
52 |
53 |
54 | -
55 |
56 |
57 | -
58 |
59 |
60 |
61 | Agency FB
62 | 12
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 |
--------------------------------------------------------------------------------
/tcpClient/protocol.h:
--------------------------------------------------------------------------------
1 | #ifndef PROTOCOL_H
2 | #define PROTOCOL_H
3 |
4 | #include
5 | #include
6 | #include
7 | typedef unsigned int unit;
8 |
9 |
10 | enum ENUM_MSG_TYPE{
11 | ENUM_MSG_TYPE_MIN = 0,
12 | ENUM_MSG_TYPE_REGIST_REQUEST, // 注册请求
13 | ENUM_MSG_TYPE_REGIST_RESPOND, // 注册回复
14 |
15 | ENUM_MSG_TYPE_LOGIN_REQUEST, // 登录请求
16 | ENUM_MSG_TYPE_LOGIN_RESPOND, // 登录回复
17 |
18 | ENUM_MSG_TYPE_ALL_ONLINE_REQUEST, //在线用户请求
19 | ENUM_MSG_TYPE_ALL_ONLINE_RESPOND, //在线用户回复
20 |
21 | ENUM_MSG_TYPE_SEARCH_USER_REQUEST, //搜索用户请求
22 | ENUM_MSG_TYPE_SEARCH_USER_RESPOND, //搜索用户回复
23 |
24 | ENUM_MSG_TYPE_ADD_FRIEND_REQUEST, //添加好友请求
25 | ENUM_MSG_TYPE_ADD_FRIEND_RESPOND, //添加好友回复
26 |
27 | ENUM_MSG_TYPE_ADD_FRIEND_AGREE, //同意好友请求
28 | ENUM_MSG_TYPE_ADD_FRIEND_REFUSE, //拒绝好友请求
29 |
30 | ENUM_MSG_TYPE_FLUSH_FRIEND_REQUEST, //刷新好友请求
31 | ENUM_MSG_TYPE_FLUSH_FRIEND_RESPOND, //刷新好友回复
32 |
33 | ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST, //删除好友请求
34 | ENUM_MSG_TYPE_DELETE_FRIEND_RESPOND, //删除好友回复
35 |
36 | ENUM_MSG_TYPE_PRIVATE_CHAT_REQUEST, //私聊好友请求
37 | ENUM_MSG_TYPE_PRIVATE_CHAT_RESPOND, //私聊好友回复
38 |
39 | ENUM_MSG_TYPE_GROUP_CHAT_REQUEST, //私聊好友请求
40 | ENUM_MSG_TYPE_GROUP_CHAT_RESPOND, //私聊好友回复
41 |
42 | ENUM_MSG_TYPE_CREATE_DIR_REQUEST, //创建文件夹请求
43 | ENUM_MSG_TYPE_CREATE_DIR_RESPOND, //创建文件夹回复
44 |
45 | ENUM_MSG_TYPE_FLUSH_FILE_REQUEST, //刷新文件请求
46 | ENUM_MSG_TYPE_FLUSH_FILE_RESPOND, //刷新文件回复
47 |
48 | ENUM_MSG_TYPE_DELETE_DIR_REQUEST, //刷新文件夹请求
49 | ENUM_MSG_TYPE_DELETE_DIR_RESPOND, //删除文件夹回复
50 |
51 | ENUM_MSG_TYPE_RENAME_FILE_REQUEST, //重命名文件请求
52 | ENUM_MSG_TYPE_RENAME_FILE_RESPOND, //重命名文件回复
53 |
54 | ENUM_MSG_TYPE_ENTER_DIR_REQUEST, //进入文件夹请求
55 | ENUM_MSG_TYPE_ENTER_DIR_RESPOND, //进入文件夹回复
56 |
57 | ENUM_MSG_TYPE_UPLOAD_FILE_REQUEST, //上传文件请求
58 | ENUM_MSG_TYPE_UPLOAD_FILE_RESPOND, //上传文件回复
59 |
60 | ENUM_MSG_TYPE_DELETE_FILE_REQUEST, //删除文件请求
61 | ENUM_MSG_TYPE_DELETE_FILE_RESPOND, //删除文件回复
62 |
63 | ENUM_MSG_TYPE_DOWNLOAD_FILE_REQUEST, //下载文件请求
64 | ENUM_MSG_TYPE_DOWNLOAD_FILE_RESPOND, //下载文件回复
65 |
66 | ENUM_MSG_TYPE_SHARE_FILE_REQUEST, //分享文件请求
67 | ENUM_MSG_TYPE_SHARE_FILE_RESPOND, //分享文件回复
68 |
69 | ENUM_MSG_TYPE_SHARE_FILE_NOTE_REQUEST, //分享文件通知请求
70 | ENUM_MSG_TYPE_SHARE_FILE_NOTE_RESPOND, //分享文件通知回复
71 |
72 | ENUM_MSG_TYPE_MOVE_FILE_REQUEST, //移动文件请求
73 | ENUM_MSG_TYPE_MOVE_FILE_RESPOND, //移动文件回复
74 |
75 | ENUM_MSG_TYPE_MAX = 0x00ffffff
76 | };
77 |
78 |
79 | #define REGIST_OK "regist ok"
80 | #define REGIST_FAILED "regist failed : name existed"
81 | #define LOGIN_OK "login ok"
82 | #define LOGIN_FAILED "login failed : name error or pwd error or relogin error"
83 | #define SEARCH_USER_NO "No Such Person"
84 | #define SEARCH_USER_ONLINE "Online"
85 | #define SEARCH_USER_OFFLINE "Offline"
86 |
87 | #define UNKNOWN_ERROR "unknown error"
88 | #define EXISTED_FRIEND "friend exist"
89 | #define ADD_FRIEND_OFFLINE "added friend offline"
90 | #define ADD_FRIEND_NO_EXISTED "no such person"
91 | #define ADD_FRIEND_OK "add friend ok"
92 |
93 | #define DELETE_OK "delete ok"
94 | #define DELETE_FAILED "delete failed"
95 |
96 | #define DIR_N0_EXSIT "dir no exist"
97 | #define DIR_ALREADY_EXSIT "dir already exist"
98 | #define CREATE_DIR_OK "create dir ok"
99 |
100 | #define DIR_DELETE_OK "dir delete ok"
101 | #define DIR_DELETE_FAILED "dir delete failed"
102 |
103 | #define RENAME_FILE_OK "rename file ok"
104 | #define RENAME_FILE_FAILED "rename file failed"
105 |
106 |
107 | #define ENTER_DIR_FAILED "enter dir failed"
108 |
109 | #define UPLOAD_FILE_OK "upload file ok"
110 | #define UPLOAD_FILE_FAILED "upload file failed"
111 |
112 | #define FILE_DELETE_OK "file delete ok"
113 | #define FILE_DELETE_FAILED "file delete failed"
114 |
115 | #define SHARE_FILE_OK "share file ok"
116 | #define SHARE_FILE_FAILED "share file failed"
117 |
118 | #define MOVE_FILE_OK "move file ok"
119 | #define MOVE_FILE_FAILED "move file failed, not dir"
120 |
121 | #define COMMON_ERROR "failed:system is busy"
122 |
123 | struct PDU
124 | {
125 | unit uiPDULen; //总的协议数据单元大小
126 | unit uiMsgType; //消息类型
127 | char caData[64];
128 | unit uiMsgLen; //实际消息长度
129 | int caMsg[]; //实际消息
130 | };
131 |
132 | struct FileInfo
133 | {
134 | char caFileName[32]; //文件名字
135 | int iFileType; //文件类型
136 |
137 | };
138 |
139 | PDU *mkPDU(unit uiMsgLen);
140 | #endif // PROTOCOL_H
141 |
--------------------------------------------------------------------------------
/tcpServer/protocol.h:
--------------------------------------------------------------------------------
1 | #ifndef PROTOCOL_H
2 | #define PROTOCOL_H
3 |
4 | #include
5 | #include
6 | #include
7 | typedef unsigned int unit;
8 |
9 |
10 | #define REGIST_OK "regist ok"
11 | #define REGIST_FAILED "regist failed : name existed"
12 |
13 |
14 | #define LOGIN_OK "login ok"
15 | #define LOGIN_FAILED "login failed : name error or pwd error or relogin error"
16 |
17 | #define SEARCH_USER_NO "No Such Person"
18 | #define SEARCH_USER_ONLINE "Online"
19 | #define SEARCH_USER_OFFLINE "Offline"
20 |
21 | #define UNKNOWN_ERROR "unknown error"
22 | #define EXISTED_FRIEND "friend exist"
23 | #define ADD_FRIEND_OFFLINE "added friend offline"
24 | #define ADD_FRIEND_NO_EXISTED "no such person"
25 | #define ADD_FRIEND_OK "add friend ok"
26 |
27 | #define DELETE_OK "delete ok"
28 | #define DELETE_FAILED "delete failed"
29 |
30 | #define DIR_N0_EXSIT "dir no exist"
31 | #define DIR_ALREADY_EXSIT "dir already exist"
32 | #define CREATE_DIR_OK "create dir ok"
33 |
34 | #define DIR_DELETE_OK "dir delete ok"
35 | #define DIR_DELETE_FAILED "dir delete failed"
36 |
37 | #define RENAME_FILE_OK "rename file ok"
38 | #define RENAME_FILE_FAILED "rename file failed"
39 |
40 | #define ENTER_DIR_FAILED "enter dir failed"
41 |
42 | #define UPLOAD_FILE_OK "upload file ok"
43 | #define UPLOAD_FILE_FAILED "upload file failed"
44 |
45 |
46 | #define FILE_DELETE_OK "file delete ok"
47 | #define FILE_DELETE_FAILED "file delete failed"
48 |
49 | #define SHARE_FILE_OK "share file ok"
50 | #define SHARE_FILE_FAILED "share file failed"
51 |
52 | #define MOVE_FILE_OK "move file ok"
53 | #define MOVE_FILE_FAILED "move file failed, not dir"
54 |
55 | #define COMMON_ERROR "failed:system is busy"
56 |
57 | enum ENUM_MSG_TYPE{
58 | ENUM_MSG_TYPE_MIN = 0,
59 | ENUM_MSG_TYPE_REGIST_REQUEST, // 注册请求
60 | ENUM_MSG_TYPE_REGIST_RESPOND, // 注册回复
61 |
62 | ENUM_MSG_TYPE_LOGIN_REQUEST, // 登录请求
63 | ENUM_MSG_TYPE_LOGIN_RESPOND, // 登录回复
64 | ENUM_MSG_TYPE_ALL_ONLINE_REQUEST, //在线用户请求
65 | ENUM_MSG_TYPE_ALL_ONLINE_RESPOND, //在线用户回复
66 |
67 | ENUM_MSG_TYPE_SEARCH_USER_REQUEST, //搜索用户请求
68 | ENUM_MSG_TYPE_SEARCH_USER_RESPOND, //搜索用户回复
69 |
70 | ENUM_MSG_TYPE_ADD_FRIEND_REQUEST, //添加好友请求
71 | ENUM_MSG_TYPE_ADD_FRIEND_RESPOND, //添加好友回复
72 |
73 | ENUM_MSG_TYPE_ADD_FRIEND_AGREE, //同意好友请求
74 | ENUM_MSG_TYPE_ADD_FRIEND_REFUSE, //拒绝好友请求
75 |
76 | ENUM_MSG_TYPE_FLUSH_FRIEND_REQUEST, //刷新好友请求
77 | ENUM_MSG_TYPE_FLUSH_FRIEND_RESPOND, //刷新好友回复
78 |
79 | ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST, //删除好友请求
80 | ENUM_MSG_TYPE_DELETE_FRIEND_RESPOND, //删除好友回复
81 |
82 | ENUM_MSG_TYPE_PRIVATE_CHAT_REQUEST, //私聊好友请求
83 | ENUM_MSG_TYPE_PRIVATE_CHAT_RESPOND, //私聊好友回复
84 |
85 | ENUM_MSG_TYPE_GROUP_CHAT_REQUEST, //私聊好友请求
86 | ENUM_MSG_TYPE_GROUP_CHAT_RESPOND, //私聊好友回复
87 |
88 | ENUM_MSG_TYPE_CREATE_DIR_REQUEST, //创建文件夹请求
89 | ENUM_MSG_TYPE_CREATE_DIR_RESPOND, //创建文件夹回复
90 |
91 | ENUM_MSG_TYPE_FLUSH_FILE_REQUEST, //刷新文件请求
92 | ENUM_MSG_TYPE_FLUSH_FILE_RESPOND, //刷新文件回复
93 |
94 | ENUM_MSG_TYPE_DELETE_DIR_REQUEST, //刷新文件夹请求
95 | ENUM_MSG_TYPE_DELETE_DIR_RESPOND, //删除文件夹回复
96 |
97 | ENUM_MSG_TYPE_RENAME_FILE_REQUEST, //重命名文件请求
98 | ENUM_MSG_TYPE_RENAME_FILE_RESPOND, //重命名文件回复
99 |
100 | ENUM_MSG_TYPE_ENTER_DIR_REQUEST, //进入文件夹请求
101 | ENUM_MSG_TYPE_ENTER_DIR_RESPOND, //进入文件夹回复
102 |
103 | ENUM_MSG_TYPE_UPLOAD_FILE_REQUEST, //上传文件请求
104 | ENUM_MSG_TYPE_UPLOAD_FILE_RESPOND, //上传文件回复
105 |
106 | ENUM_MSG_TYPE_DELETE_FILE_REQUEST, //删除文件请求
107 | ENUM_MSG_TYPE_DELETE_FILE_RESPOND, //删除文件回复
108 |
109 | ENUM_MSG_TYPE_DOWNLOAD_FILE_REQUEST, //下载文件请求
110 | ENUM_MSG_TYPE_DOWNLOAD_FILE_RESPOND, //下载文件回复
111 |
112 | ENUM_MSG_TYPE_SHARE_FILE_REQUEST, //分享文件请求
113 | ENUM_MSG_TYPE_SHARE_FILE_RESPOND, //分享文件回复
114 |
115 | ENUM_MSG_TYPE_SHARE_FILE_NOTE_REQUEST, //分享文件通知请求
116 | ENUM_MSG_TYPE_SHARE_FILE_NOTE_RESPOND, //分享文件通知回复
117 |
118 | ENUM_MSG_TYPE_MOVE_FILE_REQUEST, //移动文件请求
119 | ENUM_MSG_TYPE_MOVE_FILE_RESPOND, //移动文件回复
120 |
121 | ENUM_MSG_TYPE_MAX = 0x00ffffff,
122 | };
123 |
124 | struct PDU
125 | {
126 | unit uiPDULen; //总的协议数据单元大小
127 | unit uiMsgType; //消息类型
128 | char caData[64];
129 | unit uiMsgLen; //实际消息长度
130 | int caMsg[]; //实际消息
131 | };
132 |
133 | struct FileInfo
134 | {
135 | char caFileName[32]; //文件名字
136 | int iFileType; //文件类型
137 |
138 | };
139 |
140 | PDU *mkPDU(unit uiMsgLen);
141 | #endif // PROTOCOL_H
142 |
--------------------------------------------------------------------------------
/tcpClient/sharefile.cpp:
--------------------------------------------------------------------------------
1 | #include "sharefile.h"
2 | #include
3 | #include "tcpclient.h"
4 | #include "opewidget.h"
5 |
6 | ShareFile::ShareFile(QWidget *parent) : QWidget(parent)
7 | {
8 | m_pSelectAllPB = new QPushButton("全选");
9 | m_pCancelSelectPB = new QPushButton("取消选择");
10 | m_pConfirmPB = new QPushButton("确定");
11 | m_pCancelPB = new QPushButton("取消");
12 | m_pSA = new QScrollArea;
13 | m_pFriendW = new QWidget;
14 | m_pButtonGroup = new QButtonGroup(m_pFriendW);
15 | m_pButtonGroup->setExclusive(false);
16 | m_pFriendWVBL = new QVBoxLayout(m_pFriendW);
17 | QHBoxLayout *pTopHBL = new QHBoxLayout;
18 | pTopHBL->addWidget(m_pSelectAllPB);
19 | pTopHBL->addWidget(m_pCancelSelectPB);
20 | pTopHBL->addStretch();
21 |
22 |
23 |
24 | QHBoxLayout *pDownHBL = new QHBoxLayout;
25 | pDownHBL->addWidget(m_pConfirmPB);
26 | pDownHBL->addWidget(m_pCancelPB);
27 | pDownHBL->addStretch();
28 |
29 | QVBoxLayout *pMainVBL = new QVBoxLayout;
30 | pMainVBL->addLayout(pTopHBL);
31 | pMainVBL->addWidget(m_pSA);
32 | pMainVBL->addLayout(pDownHBL);
33 | setLayout(pMainVBL);
34 |
35 | connect(m_pCancelSelectPB, SIGNAL(clicked(bool)), this, SLOT(cancelSelect()));
36 | connect(m_pSelectAllPB, SIGNAL(clicked(bool)), this, SLOT(selectAll()));
37 | connect(m_pConfirmPB, SIGNAL(clicked(bool)), this, SLOT(shareConfirm()));
38 | connect(m_pCancelPB, SIGNAL(clicked(bool)), this, SLOT(shareCancel()));
39 | }
40 |
41 | ShareFile &ShareFile::getInstance()
42 | {
43 | static ShareFile instance;
44 | return instance;
45 | }
46 |
47 | void ShareFile::updateFriend(QListWidget *pFriendList)
48 | {
49 | if(NULL == pFriendList)
50 | {
51 | return;
52 | }
53 | QAbstractButton *tmp;
54 | QList preFriendList = m_pButtonGroup->buttons();
55 | for(int i = 0; i < preFriendList.size(); i++)
56 | {
57 | tmp = preFriendList[i];
58 | m_pFriendWVBL->removeWidget(tmp);
59 | m_pButtonGroup->removeButton(tmp);
60 | preFriendList.removeOne(tmp);
61 | delete tmp;
62 | tmp = NULL;
63 | }
64 | QCheckBox *pCB;
65 | for (int i = 0; i < pFriendList->count(); i++)
66 | {
67 | qDebug() << "好友名字" << pFriendList->item(i)->text();
68 | pCB = new QCheckBox(pFriendList->item(i)->text());
69 | m_pFriendWVBL->addWidget(pCB);
70 | m_pButtonGroup->addButton(pCB);
71 |
72 | }
73 | m_pSA->setWidget(m_pFriendW);
74 |
75 |
76 | }
77 |
78 | void ShareFile::cancelSelect()
79 | {
80 | QList cbList = m_pButtonGroup->buttons();
81 | for(int i = 0; i < cbList.size(); i++)
82 | {
83 | if(cbList[i]->isChecked())
84 | {
85 | cbList[i]->setChecked(false);
86 | }
87 | }
88 | }
89 |
90 | void ShareFile::selectAll()
91 | {
92 | QList cbList = m_pButtonGroup->buttons();
93 | for(int i = 0; i < cbList.size(); i++)
94 | {
95 | if(!cbList[i]->isChecked())
96 | {
97 | cbList[i]->setChecked(true);
98 | }
99 | }
100 | }
101 |
102 | void ShareFile::shareConfirm()
103 | {
104 | QString strName = tcpClient::getInstance().loginName();
105 | QString strCurPath = tcpClient::getInstance().currentPath();
106 | QString shareFileName = OpeWidget::getInstance().getBook()->getShareFileName();
107 |
108 | QString strSharePath = strCurPath + "/" + shareFileName; //完整的文件路径
109 | QList cbList = m_pButtonGroup->buttons();
110 | int shareNum = 0;
111 | for(int i = 0; i < cbList.size(); i++)
112 | {
113 | if(cbList[i]->isChecked())
114 | {
115 | shareNum++;
116 | }
117 | }
118 | PDU *pdu = mkPDU(32 * shareNum + strSharePath.size() + 1);
119 | pdu->uiMsgType = ENUM_MSG_TYPE_SHARE_FILE_REQUEST;
120 | sprintf(pdu->caData, "%s %d", strName.toStdString().c_str(), shareNum);
121 | int j = 0;
122 | for(int i = 0; i < cbList.size(); i++)
123 | {
124 | if(cbList[i]->isChecked())
125 | {
126 | qDebug() << "选中分享的好友:" << cbList[i]->text().split('\t')[0].toStdString().c_str();
127 | memcpy((char*)(pdu->caMsg) + j * 32, cbList[i]->text().split('\t')[0].toStdString().c_str(), cbList[i]->text().split('\t')[0].size());
128 | j++;
129 | }
130 | }
131 | memcpy((char*)(pdu->caMsg) + shareNum * 32, strSharePath.toStdString().c_str(), strSharePath.size());
132 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
133 | free(pdu);
134 | pdu = NULL;
135 | hide();
136 | }
137 |
138 | void ShareFile::shareCancel()
139 | {
140 | hide();
141 | }
142 |
--------------------------------------------------------------------------------
/tcpClient/friend.cpp:
--------------------------------------------------------------------------------
1 | #include "friend.h"
2 | #include "protocol.h"
3 | #include "tcpclient.h"
4 | #include
5 | #include
6 | #include "privatechat.h"
7 |
8 |
9 | Friend::Friend(QWidget *parent) : QWidget(parent)
10 | {
11 | m_pShowMsgTE = new QTextEdit; // 显示群发信息
12 | m_pFriendListWidget = new QListWidget; // 好友列表
13 | m_pInputMsgLE = new QLineEdit; // 群聊信息输入框
14 | m_pDelFriendPB = new QPushButton("删除好友"); // 删除好友
15 | m_pFlushFriendPB = new QPushButton("刷新好友"); // 刷新好友列表
16 | m_pShowOnlineUserPB = new QPushButton("显示在线用户"); // 显示所有在线用户
17 | m_pSearchUserPB = new QPushButton("查找用户"); // 查找用户
18 |
19 | m_pMsgSendPB = new QPushButton("好友群发"); // 群聊发送消息
20 | m_pPrivateChatPB = new QPushButton("私聊"); // 私聊按钮,默认群聊
21 |
22 | QVBoxLayout *pLeftPBVBL = new QVBoxLayout;
23 | pLeftPBVBL->addWidget(m_pDelFriendPB);
24 | pLeftPBVBL->addWidget(m_pFlushFriendPB);
25 | pLeftPBVBL->addWidget(m_pShowOnlineUserPB);
26 | pLeftPBVBL->addWidget(m_pSearchUserPB);
27 | pLeftPBVBL->addWidget(m_pPrivateChatPB);
28 |
29 | QHBoxLayout *pTopHBL = new QHBoxLayout;
30 | pTopHBL->addWidget(m_pShowMsgTE);
31 | pTopHBL->addWidget(m_pFriendListWidget);
32 | pTopHBL->addLayout(pLeftPBVBL);
33 |
34 | QHBoxLayout *pMsgHBL = new QHBoxLayout;
35 | pMsgHBL->addWidget(m_pInputMsgLE);
36 | pMsgHBL->addWidget(m_pMsgSendPB);
37 |
38 | m_pOnline = new Online;
39 |
40 | QVBoxLayout *pMain = new QVBoxLayout;
41 | pMain->addLayout(pTopHBL);
42 | pMain->addLayout(pMsgHBL);
43 | pMain->addWidget(m_pOnline);
44 | m_pOnline->hide();
45 |
46 | setLayout(pMain);
47 |
48 |
49 | connect(m_pShowOnlineUserPB, SIGNAL(clicked(bool)), this, SLOT(showOnline()));
50 |
51 | connect(m_pSearchUserPB, SIGNAL(clicked(bool)), this, SLOT(searchUser()));
52 | connect(m_pFlushFriendPB, SIGNAL(clicked(bool)), this, SLOT(flushFriend()));
53 | connect(m_pDelFriendPB, SIGNAL(clicked(bool)), this, SLOT(deleteFriend()));
54 | connect(m_pPrivateChatPB, SIGNAL(clicked(bool)), this, SLOT(privateChat()));
55 | connect(m_pMsgSendPB, SIGNAL(clicked(bool)), this, SLOT(groupChat()));
56 |
57 |
58 | }
59 |
60 | void Friend::showAllOnlineUser(PDU *pdu)
61 | {
62 | if(NULL == pdu){
63 | return;
64 | }
65 | m_pOnline->showUser(pdu);
66 | }
67 |
68 | void Friend::updateFriendList(PDU *pdu)
69 | {
70 | if(NULL == pdu)
71 | {
72 | return;
73 | }
74 | char caName[32] = {'\0'};
75 | char onlineStatus[4] = {'\0'};
76 | unit strSize = pdu->uiMsgLen / 36;
77 |
78 | m_pFriendListWidget->clear();
79 | for(unit i = 0; i < strSize ; i++)
80 | {
81 | memcpy(caName, (char*)(pdu->caMsg) + i * 36, 32);
82 | memcpy(onlineStatus, (char*)(pdu->caMsg) + 32 + i * 36, 4);
83 | qDebug() << "客户端好友" << caName << " " << onlineStatus;
84 | m_pFriendListWidget->addItem(QString("%1\t%2").arg(caName)
85 | .arg(strcmp(onlineStatus, "1") == 0?"在线":"离线"));
86 | }
87 | return;
88 | }
89 |
90 | void Friend::updateGroupMsg(PDU *pdu)
91 | {
92 | if(NULL == pdu)
93 | {
94 | return;
95 | }
96 | QString strMsg = QString("%1 says: %2").arg(pdu->caData).arg((char*)pdu->caMsg);
97 | m_pShowMsgTE->append(strMsg);
98 | }
99 |
100 | QListWidget *Friend::getFriendList()
101 | {
102 | return m_pFriendListWidget;
103 | }
104 |
105 | void Friend::showOnline()
106 | {
107 | if(m_pOnline->isHidden()){
108 | m_pOnline->show();
109 | PDU *pdu = mkPDU(0);
110 | pdu->uiMsgType = ENUM_MSG_TYPE_ALL_ONLINE_REQUEST;
111 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
112 | free(pdu);
113 | pdu = NULL;
114 | }
115 | else{
116 | m_pOnline->hide();
117 | }
118 | }
119 |
120 | void Friend::searchUser()
121 | {
122 | m_strSearchName = QInputDialog::getText(this, "搜索", "用户名:");
123 | if(!m_strSearchName.isEmpty()){
124 | PDU *pdu = mkPDU(0);
125 | memcpy(pdu->caData, m_strSearchName.toStdString().c_str(), m_strSearchName.size());
126 | pdu->uiMsgType = ENUM_MSG_TYPE_SEARCH_USER_REQUEST;
127 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
128 | free(pdu);
129 | pdu = NULL;
130 | }
131 | }
132 |
133 | void Friend::flushFriend()
134 | {
135 | QString strName = tcpClient::getInstance().loginName();
136 | PDU *pdu = mkPDU(0);
137 | pdu->uiMsgType = ENUM_MSG_TYPE_FLUSH_FRIEND_REQUEST;
138 | memcpy(pdu->caData, strName.toStdString().c_str(), strName.size());
139 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
140 | free(pdu);
141 | pdu = NULL;
142 | }
143 |
144 | void Friend::deleteFriend()
145 | {
146 | QListWidgetItem *deleteItem = m_pFriendListWidget->currentItem();
147 | if(NULL == deleteItem)
148 | {
149 | QMessageBox::warning(this, "删除好友", "请选择要删除的好友");
150 | return;
151 | }
152 | QString deleteName = deleteItem->text().split("\t")[0];
153 | QString sourceName = tcpClient::getInstance().loginName(); // 登录用户用户名
154 | PDU *pdu = mkPDU(0);
155 | pdu->uiMsgType = ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST;
156 | memcpy(pdu->caData, sourceName.toStdString().c_str(), 32);
157 | memcpy(pdu->caData + 32, deleteName.toStdString().c_str(), 32);
158 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
159 | free(pdu);
160 | pdu = NULL;
161 | }
162 |
163 | void Friend::privateChat()
164 | {
165 | QListWidgetItem *privateChatItem = m_pFriendListWidget->currentItem();
166 | if(NULL == privateChatItem)
167 | {
168 | QMessageBox::warning(this, "私聊好友", "请选择要私聊的好友");
169 | return;
170 | }
171 | QString privateChatName = privateChatItem->text().split("\t")[0];
172 | PrivateChat::getInstance().setChatName(privateChatName);
173 | if(PrivateChat::getInstance().isHidden())
174 | {
175 | PrivateChat::getInstance().show();
176 | }
177 |
178 | }
179 |
180 | void Friend::groupChat()
181 | {
182 | QString strMsg = m_pInputMsgLE->text();
183 | if(NULL == strMsg)
184 | {
185 | QMessageBox::warning(this, "好友群发", "信息不能为空");
186 | return;
187 | }
188 | PDU *pdu = mkPDU(strMsg.size() + 1);
189 | pdu->uiMsgType = ENUM_MSG_TYPE_GROUP_CHAT_REQUEST;
190 | QString sourceName = tcpClient::getInstance().loginName();
191 | strncpy(pdu->caData ,sourceName.toStdString().c_str(), sourceName.size()); //群发的人
192 | strncpy((char*)pdu->caMsg, strMsg.toStdString().c_str(), strMsg.size()); //群发的信息
193 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
194 | free(pdu);
195 | pdu = NULL;
196 | }
197 |
--------------------------------------------------------------------------------
/tcpServer/opedb.cpp:
--------------------------------------------------------------------------------
1 | #include "opedb.h"
2 | #include
3 | #include
4 |
5 | OpeDB::OpeDB(QObject *parent) : QObject(parent)
6 | {
7 | m_db = QSqlDatabase::addDatabase("QSQLITE");
8 | }
9 |
10 | OpeDB &OpeDB::getInstance()
11 | {
12 | static OpeDB instance;
13 | return instance;
14 | }
15 |
16 | void OpeDB::init()
17 | {
18 | m_db.setHostName("localhost");
19 | m_db.setDatabaseName("D:\\Qt\\tcpServer\\cloud.db");
20 | if(m_db.open())
21 | {
22 | QSqlQuery query;
23 | query.exec("select * from userInfo");
24 | while(query.next())
25 | {
26 | QString data = QString("%1, %2, %3, %4").arg(query.value(0).toString()).arg(query.value(1).toString())
27 | .arg(query.value(2).toString()).arg(query.value(3).toString());
28 | qDebug() << data;
29 | }
30 | }
31 | else
32 | {
33 | QMessageBox::critical(NULL, "打开数据库", "打开数据库失败");
34 | }
35 | }
36 |
37 | bool OpeDB::handleRegist(const char *name, const char *pwd)
38 | {
39 | if(name == NULL || pwd == NULL){
40 | return false;
41 | }
42 | QString data = QString("insert into userInfo(name, pwd) values(\'%1\',\'%2\')").arg(name).arg(pwd);
43 | QSqlQuery query;
44 | return query.exec(data);
45 | }
46 |
47 | bool OpeDB::handleLogin(const char *name, const char *pwd)
48 | {
49 | if(name == NULL || pwd == NULL){
50 | return false;
51 | }
52 | QString data = QString("select * from userInfo where name=\'%1\' and pwd=\'%2\' and online=0").arg(name).arg(pwd);
53 | QSqlQuery query;
54 | query.exec(data);
55 | if(query.next())
56 | {
57 | data = QString("update userInfo set online=1 where name=\'%1\' and pwd=\'%2\'").arg(name).arg(pwd);
58 | QSqlQuery query;
59 | query.exec(data);
60 | return true;
61 | }
62 | else{
63 | return false;
64 | }
65 | }
66 |
67 | void OpeDB::handleOffline(const char *name)
68 | {
69 | if(name == NULL){
70 | return;
71 | }
72 | QString data = QString("update userInfo set online=0 where name=\'%1\'").arg(name);
73 | QSqlQuery query;
74 | query.exec(data);
75 | }
76 |
77 | QStringList OpeDB::handleAllOnline()
78 | {
79 | QString data = QString("select name from userInfo where online=1");
80 | QSqlQuery query;
81 | query.exec(data);
82 | QStringList result;
83 | result.clear();
84 | while(query.next())
85 | {
86 | result.append(query.value(0).toString());
87 | }
88 | return result;
89 | }
90 |
91 | int OpeDB::handleSearchUser(const char *name)
92 | {
93 | if(NULL == name){
94 | return -1;
95 | }
96 | QString data = QString("select online from userInfo where name=\'%1\'").arg(name);
97 | QSqlQuery query;
98 | query.exec(data);
99 | //存在这个人
100 | if(query.next()){
101 | int ret = query.value(0).toInt();
102 | if(ret == 1){
103 | return 1; //此人在线
104 | }else if(ret == 0){
105 | return 0; //此人不在线
106 | }
107 | }
108 | else{
109 | return -1; //没这个人
110 | }
111 | return -1;
112 | }
113 |
114 | int OpeDB::handleAddFriend(const char *pername, const char *name)
115 | {
116 | if(NULL == pername || NULL == name){
117 | return -1;
118 | }
119 | QString data = QString("select * from friend"
120 | " where (id = (select id from userInfo where name = \'%1\') and "
121 | "friendId = (select id from userInfo where name = \'%2\')) or " // 好友是双向的,数据库只存了单向,注意是or关系
122 | "(id = (select id from userInfo where name = \'%3\') and "
123 | "friendId = (select id from userInfo where name = \'%4\'))")
124 | .arg(pername).arg(name).arg(name).arg(pername);
125 | qDebug() << data;
126 | QSqlQuery query;
127 | query.exec(data);
128 | if(query.next())
129 | {
130 | return 0; //双方已经是好友
131 | }
132 | else //不是好友
133 | {
134 | QString data = QString("select online from userInfo where name=\'%1\'").arg(pername);
135 | QSqlQuery query;
136 | query.exec(data);
137 | if(query.next()){
138 | int ret = query.value(0).toInt();
139 | if(ret == 1){
140 | return 1; //此人在线
141 | }else if(ret == 0){
142 | return 2; //此人不在线
143 | }
144 | }
145 | else{
146 | return 3; //没这个人
147 | }
148 | }
149 | return -1;
150 | }
151 |
152 | int OpeDB::getIdByUserName(const char *name)
153 | {
154 | if(NULL == name)
155 | {
156 | return -1;
157 | }
158 | QString data = QString("select id from userInfo where name=\'%1\'").arg(name);
159 | QSqlQuery query;
160 | query.exec(data);
161 | qDebug() << data;
162 | if(query.next())
163 | {
164 | return query.value(0).toInt();
165 | }
166 | else
167 | {
168 | return -1; // 不存在该用户
169 | }
170 | }
171 |
172 | void OpeDB::handleAddFriendAgree(const char *addedName, const char *sourceName)
173 | {
174 | if(NULL == addedName || NULL == sourceName)
175 | {
176 | return;
177 | }
178 | int sourceUserId = -1;
179 | int addedUserId = -1;
180 | sourceUserId = getIdByUserName(sourceName);
181 | addedUserId = getIdByUserName(addedName);
182 | qDebug() << sourceUserId << " " << addedUserId;
183 | QString strQuery = QString("insert into friend values(%1, %2) ").arg(sourceUserId).arg(addedUserId);
184 | QSqlQuery query;
185 | query.exec(strQuery);
186 | return;
187 |
188 | //qDebug() << "handleAddFriendAgree " << strQuery;
189 | }
190 |
191 | QStringList OpeDB::handleFlushFriend(const char *name)
192 | {
193 | QStringList strFriendList;
194 | strFriendList.clear();
195 | if(NULL == name)
196 | {
197 | return strFriendList;
198 | }
199 | QString data = QString("select id from userInfo where name = \'%1\' and online = 1 ").arg(name);
200 | QSqlQuery query;
201 | query.exec(data);
202 | int sourceId = -1; // 请求方name对应的id
203 |
204 | if (query.next())
205 | {
206 | sourceId = query.value(0).toInt();
207 | }
208 |
209 | data = QString("select name, online from userInfo where id in (select id from friend where friendId= \'%1\') or id in (select friendId from friend where id = \'%2\')").arg(sourceId).arg(sourceId);
210 | query.exec(data);
211 | qDebug() << data;
212 | //既要返回好友的名字,同时返回好友的在线状态
213 | while(query.next())
214 | {
215 | qDebug() << "yes";
216 | char friendName[32] = {'\0'};
217 | char friendOnlineStatus[4] = {'\0'};
218 | memcpy(friendName, query.value(0).toString().toStdString().c_str(), 32);
219 | memcpy(friendOnlineStatus, query.value(1).toString().toStdString().c_str(), 4);
220 | strFriendList.append(friendName);
221 | strFriendList.append(friendOnlineStatus);
222 | qDebug() << "好友信息 " << friendName << " " << friendOnlineStatus;
223 | //qDebug() << strFriendList;
224 | }
225 | return strFriendList;
226 | }
227 |
228 | QStringList OpeDB::handleGroupChat(const char *name)
229 | {
230 | QStringList strFriendList;
231 | strFriendList.clear();
232 | if(NULL == name)
233 | {
234 | return strFriendList;
235 | }
236 | strFriendList = handleFlushFriend(name);
237 | strFriendList.append(name);
238 | strFriendList.append("1");
239 | return strFriendList;
240 | }
241 |
242 | bool OpeDB::handleDeleteFriend(const char *sourceName, const char *deleteName)
243 | {
244 | if(NULL == sourceName || NULL == deleteName)
245 | {
246 | return false;
247 | }
248 | int sourceId = getIdByUserName(sourceName);
249 | int deleteId = getIdByUserName(deleteName); // 请求方name对应的id
250 | qDebug() << sourceId << deleteId;
251 | QString data = QString("delete from friend where (id=\'%1\' and friendId=\'%2\') or (id=\'%3\' and friendId =\'%4\')").arg(sourceId).arg(deleteId).arg(deleteId).arg(sourceId);
252 | QSqlQuery query;
253 | query.exec(data);
254 | qDebug() << data;
255 | return true;
256 | }
257 |
--------------------------------------------------------------------------------
/tcpClient/tcpclient.cpp:
--------------------------------------------------------------------------------
1 | #include "tcpclient.h"
2 | #include "ui_tcpclient.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "privatechat.h"
8 |
9 | tcpClient::tcpClient(QWidget *parent)
10 | : QWidget(parent)
11 | , ui(new Ui::tcpClient)
12 | {
13 | ui->setupUi(this);
14 |
15 | resize(450, 300);
16 | loadConfig();
17 | connect(&m_tcpSocket, SIGNAL(connected()), this, SLOT(showConnect()));
18 | connect(&m_tcpSocket, SIGNAL(readyRead()), this, SLOT(recvMsg()));
19 | //连接服务器
20 | m_tcpSocket.connectToHost(QHostAddress(m_strIP), m_usPort);
21 | }
22 |
23 | tcpClient::~tcpClient()
24 | {
25 | delete ui;
26 | }
27 |
28 | void tcpClient::loadConfig()
29 | {
30 | QFile file(":/client.config");
31 | if(file.open(QIODevice::ReadOnly))
32 | {
33 | QByteArray baData = file.readAll();
34 | file.close();
35 | QString strData = baData.toStdString().c_str();
36 | strData.replace("\r\n"," ");
37 | QStringList strList = strData.split(" ");
38 | m_strIP = strList.at(0);
39 | m_usPort = strList.at(1).toUShort();
40 | // qDebug() << "IP:" << m_strIP << "port:" << m_usPort;
41 | }
42 | else
43 | {
44 | QMessageBox::critical(this, "open config", "open config failed");
45 | }
46 | }
47 |
48 | tcpClient &tcpClient::getInstance()
49 | {
50 | static tcpClient instance;
51 | return instance;
52 | }
53 |
54 | QTcpSocket &tcpClient::gettcpSocket()
55 | {
56 | return m_tcpSocket;
57 | }
58 |
59 | QString tcpClient::loginName()
60 | {
61 | return m_strLoginName;
62 | }
63 |
64 | QString tcpClient::currentPath()
65 | {
66 | return m_strCurPath;
67 | }
68 |
69 | void tcpClient::setCurrentPath(QString preContentPath)
70 | {
71 | m_strCurPath = preContentPath;
72 | }
73 |
74 |
75 |
76 | void tcpClient::showConnect()
77 | {
78 | QMessageBox::information(this, "连接服务器", "连接服务器成功");
79 | }
80 |
81 | void tcpClient::recvMsg()
82 | {
83 | if(!OpeWidget::getInstance().getBook()->getDownloadStatus())
84 | {
85 | qDebug() << m_tcpSocket.bytesAvailable();
86 | unit uiPDULen = 0;
87 | m_tcpSocket.read((char*)&uiPDULen, sizeof(unit));
88 | unit uiMsgLen = uiPDULen - sizeof(PDU);
89 | PDU *pdu = mkPDU(uiMsgLen);
90 | m_tcpSocket.read((char*)pdu + sizeof(unit), uiPDULen - sizeof(unit));
91 | // qDebug() << pdu->uiMsgType << (char*)pdu->caMsg;
92 | switch (pdu->uiMsgType)
93 | {
94 | case ENUM_MSG_TYPE_REGIST_RESPOND:
95 | {
96 | if(0 == strcmp(pdu->caData, REGIST_OK))
97 | {
98 | QMessageBox::information(this, "注册", REGIST_OK);
99 | }
100 | else if(0 == strcmp(pdu -> caData, REGIST_FAILED))
101 | {
102 | QMessageBox::warning(this, "注册", REGIST_FAILED);
103 | }
104 | break;
105 | }
106 | case ENUM_MSG_TYPE_LOGIN_RESPOND:
107 | {
108 | if(0 == strcmp(pdu->caData, LOGIN_OK))
109 | {
110 | m_strCurPath = QString("./%1").arg(m_strLoginName);
111 | QMessageBox::information(this, "登录", LOGIN_OK);
112 | OpeWidget::getInstance().show();
113 | this->hide();
114 | }
115 | else if(0 == strcmp(pdu -> caData, LOGIN_FAILED))
116 | {
117 | QMessageBox::warning(this, "登录", LOGIN_FAILED);
118 | }
119 | break;
120 | }
121 | case ENUM_MSG_TYPE_ALL_ONLINE_RESPOND:
122 | {
123 | OpeWidget::getInstance().getFriend()->showAllOnlineUser(pdu);
124 | break;
125 | }
126 | case ENUM_MSG_TYPE_SEARCH_USER_RESPOND:
127 | {
128 |
129 | if(0 == strcmp(SEARCH_USER_NO, pdu->caData)){
130 | QMessageBox::information(this, "搜索", QString("%1: not exist").arg(OpeWidget::getInstance().getFriend()->m_strSearchName));
131 | }else if(0 == strcmp(SEARCH_USER_ONLINE, pdu->caData)){
132 | QMessageBox::information(this, "搜索", QString("%1: online").arg(OpeWidget::getInstance().getFriend()->m_strSearchName));
133 | }else if(0 == strcmp(SEARCH_USER_OFFLINE, pdu->caData)){
134 | QMessageBox::information(this, "搜索", QString("%1: offline").arg(OpeWidget::getInstance().getFriend()->m_strSearchName));
135 | }
136 | break;
137 | }
138 | case ENUM_MSG_TYPE_ADD_FRIEND_REQUEST:
139 | {
140 | char caName[32] = {'\0'};
141 | strncpy(caName, pdu->caData + 32, 32);
142 | int ret = QMessageBox::information(this, "加好友", QString("%1 want to be your friend?").arg(caName),
143 | QMessageBox::Yes, QMessageBox::No);
144 | PDU *respdu = mkPDU(0);
145 | strncpy(respdu->caData, pdu->caData, 32); // 被加好友者用户名
146 | strncpy(respdu->caData + 32, pdu->caData + 32, 32); // 加好友者用户名
147 | if(QMessageBox::Yes == ret){
148 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_AGREE;
149 | }
150 | else
151 | {
152 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_REFUSE;
153 | }
154 | m_tcpSocket.write((char*)respdu, respdu->uiPDULen);
155 | free(respdu);
156 | respdu = NULL;
157 | break;
158 | }
159 | case ENUM_MSG_TYPE_ADD_FRIEND_RESPOND:
160 | {
161 | QMessageBox::information(this, "添加好友", pdu->caData);
162 | break;
163 | }
164 | case ENUM_MSG_TYPE_ADD_FRIEND_AGREE: // 对方同意加好友
165 | {
166 | QMessageBox::information(this, "添加好友", QString("%1 已同意您的好友申请!").arg(pdu->caData));
167 | break;
168 | }
169 | case ENUM_MSG_TYPE_ADD_FRIEND_REFUSE: // 对方拒绝加好友
170 | {
171 | QMessageBox::information(this, "添加好友", QString("%1 已拒绝您的好友申请!").arg(pdu->caData));
172 | break;
173 | }
174 | case ENUM_MSG_TYPE_FLUSH_FRIEND_RESPOND:
175 | {
176 |
177 | OpeWidget::getInstance().getFriend()->updateFriendList(pdu);
178 | break;
179 | }
180 | case ENUM_MSG_TYPE_DELETE_FRIEND_RESPOND:
181 | {
182 | if(0 == strcmp(pdu->caData, DELETE_OK))
183 | {
184 | QMessageBox::information(this, "删除好友", pdu->caData);
185 | }
186 | else if(0 == strcmp(pdu -> caData, DELETE_FAILED))
187 | {
188 | QMessageBox::warning(this, "删除好友", pdu->caData);
189 | }
190 | break;
191 | }
192 | case ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST: // 处理服务器转发过来的删除好友请求
193 | {
194 | char sourceName[32] = {'\0'}; // 获取发送方用户名
195 | strncpy(sourceName, pdu->caData, 32);
196 | QMessageBox::information(this, "删除好友", QString("%1 已解除与您的好友关系!").arg(sourceName));
197 | break;
198 | }
199 | case ENUM_MSG_TYPE_PRIVATE_CHAT_REQUEST : // 处理服务器转发过来的删除好友请求
200 | {
201 | if(PrivateChat::getInstance().isHidden())
202 | {
203 | PrivateChat::getInstance().show();
204 | }
205 | char sourceName[32] = {'\0'}; // 获取发送方用户名
206 | char sendName[32] = {'\0'};
207 | strncpy(sourceName, pdu->caData, 32);
208 | strncpy(sendName, pdu->caData + 32, 32);
209 | QString ownName = sourceName;
210 | PrivateChat::getInstance().setChatName(ownName);
211 | PrivateChat::getInstance().updateMsg(pdu);
212 | break;
213 | }
214 | case ENUM_MSG_TYPE_GROUP_CHAT_REQUEST : // 处理服务器转发过来的群发信息请求
215 | {
216 | OpeWidget::getInstance().getFriend()->updateGroupMsg(pdu);
217 | break;
218 | }
219 | case ENUM_MSG_TYPE_CREATE_DIR_RESPOND : // 处理服务器转发过来的群发信息请求
220 | {
221 | QMessageBox::information(this, "创建文件夹", pdu->caData);
222 | break;
223 | }
224 | case ENUM_MSG_TYPE_FLUSH_FILE_RESPOND : // 处理服务器转发过来的群发信息请求
225 | {
226 |
227 | OpeWidget::getInstance().getBook()->updateFileList(pdu);
228 | QString strEnterDir = OpeWidget::getInstance().getBook()->enterDir();
229 |
230 | if(NULL != strEnterDir)
231 | {
232 |
233 | m_strCurPath = m_strCurPath + "/" + strEnterDir;
234 | qDebug() << "进入的文件夹路径:" << m_strCurPath << "文件夹名字:" << strEnterDir;
235 |
236 | }
237 | break;
238 | }
239 | case ENUM_MSG_TYPE_DELETE_DIR_RESPOND : // 处理服务器转发过来的群发信息请求
240 | {
241 | QMessageBox::information(this, "删除文件夹", pdu->caData);
242 | break;
243 | }
244 | case ENUM_MSG_TYPE_RENAME_FILE_RESPOND : // 处理服务器转发过来的群发信息请求
245 | {
246 | QMessageBox::information(this, "重命名文件", pdu->caData);
247 | break;
248 | }
249 | case ENUM_MSG_TYPE_ENTER_DIR_RESPOND : // 处理服务器转发过来的群发信息请求
250 | {
251 | OpeWidget::getInstance().getBook()->clearEnterDir();
252 | QMessageBox::information(this, "进入文件夹", pdu->caData);
253 | break;
254 | }
255 | case ENUM_MSG_TYPE_UPLOAD_FILE_RESPOND : // 处理服务器转发过来的群发信息请求
256 | {
257 | QMessageBox::information(this, "上传文件", pdu->caData);
258 | break;
259 | }
260 | case ENUM_MSG_TYPE_DELETE_FILE_RESPOND : // 处理服务器转发过来的群发信息请求
261 | {
262 | QMessageBox::information(this, "删除文件", pdu->caData);
263 | break;
264 | }
265 | case ENUM_MSG_TYPE_DOWNLOAD_FILE_RESPOND : // 处理服务器转发过来的群发信息请求
266 | {
267 | qDebug() << "pdu->caData:" << pdu->caData;
268 | char caFileName[32] = {'\0'};
269 | sscanf(pdu->caData, "%s %lld", caFileName, &(OpeWidget::getInstance().getBook()->m_iTotal));
270 | qDebug() << "respond:" << caFileName << " " << OpeWidget::getInstance().getBook()->m_iTotal;
271 | if(strlen(caFileName) > 0 && OpeWidget::getInstance().getBook()->m_iTotal > 0)
272 | {
273 | OpeWidget::getInstance().getBook()->setDownLoadStatus(true);
274 | QString strFileSavePath = OpeWidget::getInstance().getBook()->getFileSavePath();
275 | m_file.setFileName(strFileSavePath);
276 | if(!m_file.open(QIODevice::WriteOnly))
277 | {
278 | QMessageBox::warning(this, "下载文件", "获取保存文件路径失败");
279 | }
280 |
281 | }
282 | break;
283 | }
284 | case ENUM_MSG_TYPE_SHARE_FILE_RESPOND : // 处理服务器转发过来的群发信息请求
285 | {
286 | QMessageBox::information(this, "共享文件", pdu->caData);
287 | break;
288 | }
289 | case ENUM_MSG_TYPE_SHARE_FILE_NOTE_REQUEST : // 处理服务器转发过来的群发信息请求
290 | {
291 | char *pPath = new char[pdu->uiMsgLen];
292 | memcpy(pPath, pdu->caMsg, pdu->uiMsgLen);
293 | qDebug() << "pPath:" << pPath;
294 | char *pos = strrchr(pPath, '/');
295 | if(NULL != pos)
296 | {
297 | pos++;
298 | qDebug() << "pos:" << pos;
299 | QString strNote = QString("%1 share file->%2 \n Do you accept?").arg(pdu->caData).arg(pos);
300 | qDebug() << "strNote:" << strNote;
301 | int ret = QMessageBox::question(this, "共享文件", strNote);
302 | if(QMessageBox::Yes == ret)
303 | {
304 | PDU *respdu = mkPDU(pdu->uiMsgLen);
305 | respdu->uiMsgType = ENUM_MSG_TYPE_SHARE_FILE_NOTE_RESPOND;
306 | memcpy(respdu->caMsg, pdu->caMsg, pdu->uiMsgLen);
307 | QString strName = tcpClient::getInstance().loginName();
308 | qDebug() << "被分享者:" << strName;
309 | strcpy(respdu->caData, strName.toStdString().c_str());
310 | m_tcpSocket.write((char*)respdu, respdu->uiPDULen);
311 | // free(respdu);
312 | // respdu = NULL;
313 | }
314 | }
315 | else
316 | {
317 | qDebug() << "没有pos";
318 | }
319 |
320 | break;
321 | }
322 | case ENUM_MSG_TYPE_MOVE_FILE_RESPOND : // 处理服务器转发过来的群发信息请求
323 | {
324 | QMessageBox::information(this, "移动文件", pdu->caData);
325 | break;
326 | }
327 | default:
328 | break;
329 | }
330 | free(pdu);
331 | pdu = NULL;
332 | }
333 | else
334 | {
335 | Book *pBook = OpeWidget::getInstance().getBook();
336 | QByteArray buffer = m_tcpSocket.readAll();
337 | m_file.write(buffer);
338 | pBook->m_iReceived += buffer.size();
339 | qDebug() << "buffer:" << buffer.size();
340 | if(pBook->m_iTotal == pBook->m_iReceived)
341 | {
342 | m_file.close();
343 | pBook->m_iTotal = 0;
344 | pBook->m_iReceived = 0;
345 | pBook->setDownLoadStatus(false);
346 | QMessageBox::information(this, "下载文件", "下载文件成功");
347 | }
348 | else if(pBook->m_iTotal < pBook->m_iReceived)
349 | {
350 | qDebug() << "总共的:" << pBook->m_iTotal << " 下载的" << pBook->m_iReceived;
351 | m_file.close();
352 | pBook->m_iTotal = 0;
353 | pBook->m_iReceived = 0;
354 | pBook->setDownLoadStatus(false);
355 | QMessageBox::critical(this, "下载文件", "下载文件失败");
356 | }
357 |
358 | }
359 | }
360 |
361 | #if 0
362 | void tcpClient::on_send_pb_clicked()
363 | {
364 | QString strMsg = ui->lineEdit->text();
365 | if(!strMsg.isEmpty())
366 | {
367 | PDU *pdu = mkPDU(strMsg.size());
368 | pdu->uiMsgType = 8888;
369 | memcpy(pdu->caMsg, strMsg.toStdString().c_str(), strMsg.size());
370 | m_tcpSocket.write((char*)pdu, pdu->uiPDULen);
371 | free(pdu);
372 | pdu = NULL;
373 | }
374 | else
375 | {
376 | QMessageBox::warning(this, "信息发送", "信息发送为空");
377 | }
378 | }
379 | #endif
380 |
381 | void tcpClient::on_login_clicked()
382 | {
383 | QString strName = ui->username_le->text();
384 | m_strLoginName = strName;
385 | QString strPwd = ui->pwd_le->text();
386 | if(!strName.isEmpty() && !strPwd.isEmpty())
387 | {
388 | PDU *pdu = mkPDU(0);
389 | pdu->uiMsgType = ENUM_MSG_TYPE_LOGIN_REQUEST;
390 | strncpy(pdu->caData, strName.toStdString().c_str(), 32);
391 | strncpy(pdu->caData + 32, strPwd.toStdString().c_str(), 32);
392 | m_tcpSocket.write((char*)pdu, pdu->uiPDULen);
393 | free(pdu);
394 | pdu = NULL;
395 | }
396 | else
397 | {
398 | QMessageBox::critical(this, "登录", "登录失败!用户名或密码为空");
399 | }
400 | }
401 |
402 | void tcpClient::on_zhuce_clicked()
403 | {
404 | QString strName = ui->username_le->text();
405 | QString strPwd = ui->pwd_le->text();
406 | if(!strName.isEmpty() && !strPwd.isEmpty())
407 | {
408 | PDU *pdu = mkPDU(0);
409 | pdu->uiMsgType = ENUM_MSG_TYPE_REGIST_REQUEST;
410 | strncpy(pdu->caData, strName.toStdString().c_str(), 32);
411 | strncpy(pdu->caData + 32, strPwd.toStdString().c_str(), 32);
412 | m_tcpSocket.write((char*)pdu, pdu->uiPDULen);
413 | free(pdu);
414 | pdu = NULL;
415 | }
416 | else
417 | {
418 | QMessageBox::critical(this, "注册", "注册失败!用户名或密码为空");
419 | }
420 | }
421 |
422 | void tcpClient::on_zhuxiao_clicked()
423 | {
424 |
425 | }
426 |
--------------------------------------------------------------------------------
/tcpClient/book.cpp:
--------------------------------------------------------------------------------
1 | #include "book.h"
2 | #include "tcpclient.h"
3 | #include
4 | #include
5 | #include
6 | #include "opewidget.h"
7 | #include "sharefile.h"
8 |
9 |
10 | Book::Book(QWidget *parent) : QWidget(parent)
11 | {
12 | m_strEnterDir.clear();
13 | m_bDownload = false;
14 | m_pTimer = new QTimer;
15 |
16 | m_pFileListWidget = new QListWidget; // 文件列表
17 |
18 | m_pReturnPB = new QPushButton("返回"); // 返回主页面
19 | m_pCreateDirPB = new QPushButton("新建文件夹"); // 新建文件夹
20 | m_pDeleteDirPB = new QPushButton("删除文件夹"); // 删除文件夹
21 | m_pRenameFilePB = new QPushButton("重命名文件"); // 重命名文件
22 | m_pFlushFilePB = new QPushButton("刷新文件"); // 刷新文件
23 |
24 | m_pUploadFilePB = new QPushButton("上传文件"); // 上传文件
25 | m_pDownLoadFilePB = new QPushButton("下载文件"); // 下载文件
26 | m_pDeleteFilePB = new QPushButton("删除文件"); // 删除文件
27 | m_pShareFilePB = new QPushButton("分享文件"); // 分享文件
28 | m_pMoveFilePB = new QPushButton("移动文件"); //移动文件
29 | m_pSelectMoveToDirPB = new QPushButton("目标目录"); //移动文件到其他文件夹
30 | m_pSelectMoveToDirPB->setEnabled(false);
31 |
32 | QVBoxLayout *pDirVBL = new QVBoxLayout;
33 | pDirVBL->addWidget(m_pReturnPB);
34 | pDirVBL->addWidget(m_pCreateDirPB);
35 | pDirVBL->addWidget(m_pDeleteDirPB);
36 | pDirVBL->addWidget(m_pRenameFilePB);
37 | pDirVBL->addWidget(m_pFlushFilePB);
38 |
39 |
40 | QVBoxLayout *pFileVBL = new QVBoxLayout;
41 | pFileVBL->addWidget(m_pUploadFilePB);
42 | pFileVBL->addWidget(m_pDownLoadFilePB);
43 | pFileVBL->addWidget(m_pDeleteFilePB);
44 | pFileVBL->addWidget(m_pShareFilePB);
45 | pFileVBL->addWidget(m_pMoveFilePB);
46 | pFileVBL->addWidget(m_pSelectMoveToDirPB);
47 |
48 |
49 | QHBoxLayout *pMain = new QHBoxLayout;
50 | pMain->addWidget(m_pFileListWidget);
51 | pMain->addLayout(pDirVBL);
52 | pMain->addLayout(pFileVBL);
53 |
54 | setLayout(pMain);
55 |
56 | connect(m_pCreateDirPB, SIGNAL(clicked(bool)), this, SLOT(createDir()));
57 | connect(m_pFlushFilePB, SIGNAL(clicked(bool)), this, SLOT(flushFile()));
58 | connect(m_pDeleteDirPB, SIGNAL(clicked(bool)), this, SLOT(deleteDir()));
59 | connect(m_pRenameFilePB, SIGNAL(clicked(bool)), this, SLOT(renameFile()));
60 | connect(m_pFileListWidget ,SIGNAL(doubleClicked(QModelIndex)), this, SLOT(enterDir(QModelIndex)));
61 | connect(m_pReturnPB, SIGNAL(clicked(bool)), this, SLOT(returnPreContent()));
62 | connect(m_pUploadFilePB, SIGNAL(clicked(bool)), this, SLOT(uploadFile()));
63 | connect(m_pTimer, SIGNAL(timeout()), this, SLOT(uploadFileData()));
64 | connect(m_pDeleteFilePB, SIGNAL(clicked(bool)), this, SLOT(deleteFile()));
65 | connect(m_pDownLoadFilePB, SIGNAL(clicked(bool)), this, SLOT(downloadFile()));
66 | connect(m_pShareFilePB, SIGNAL(clicked(bool)), this, SLOT(shareFile()));
67 | connect(m_pMoveFilePB, SIGNAL(clicked(bool)), this, SLOT(moveFile()));
68 | connect(m_pSelectMoveToDirPB, SIGNAL(clicked(bool)), this, SLOT(selectDestDir()));
69 | }
70 |
71 | void Book::updateFileList(PDU *pdu)
72 | {
73 | if(NULL == pdu)
74 | {
75 | return;
76 | }
77 | // char FileName[32] = {'\0'};
78 | // char FileType[4] = {'\0'};
79 | // unit strSize = pdu->uiMsgLen / 32;
80 |
81 | // m_pFileListWidget->clear();
82 | FileInfo *pFileInfo = NULL;
83 | int iCount = pdu->uiMsgLen/sizeof(FileInfo);
84 | m_pFileListWidget->clear();
85 | for(int i = 0; i < iCount ; i++)
86 | {
87 | // memcpy(FileName, (char*)(pdu->caMsg) + i * 32, 32);
88 | // memcpy(FileType, (char*)(pdu->caMsg) + 32 + i * 32, 32);
89 | // qDebug() << "客户端好友" << FileName << " " << FileType;
90 | // m_pFileListWidget->addItem(QString("%1\t%2").arg(FileName)
91 | // .arg(strcmp(FileType, "1") == 0?"普通文件":"文件夹"));
92 | pFileInfo = (FileInfo*)(pdu->caMsg) + i;
93 | qDebug() << pFileInfo->caFileName << " " << pFileInfo->iFileType;
94 | QListWidgetItem *pItem = new QListWidgetItem;
95 | if(0 == pFileInfo->iFileType)
96 | {
97 | pItem->setIcon(QIcon(QPixmap(":/map/dir.png")));
98 | }
99 | else if(1 == pFileInfo->iFileType)
100 | {
101 | pItem->setIcon(QIcon(QPixmap(":/map/file.png")));
102 | }
103 | pItem->setText(pFileInfo->caFileName);
104 | m_pFileListWidget->addItem(pItem);
105 |
106 | }
107 | return;
108 | }
109 |
110 | void Book::clearEnterDir()
111 | {
112 | m_strEnterDir.clear();
113 | }
114 |
115 | QString Book::enterDir()
116 | {
117 | return m_strEnterDir;
118 | }
119 |
120 | void Book::setDownLoadStatus(bool status)
121 | {
122 | m_bDownload = status;
123 | }
124 |
125 | bool Book:: getDownloadStatus()
126 | {
127 | return m_bDownload;
128 | }
129 |
130 | QString Book::getFileSavePath()
131 | {
132 | return m_strFileSavePath;
133 | }
134 |
135 | QString Book::getShareFileName()
136 | {
137 | return m_strShareFileName;
138 | }
139 |
140 |
141 |
142 | void Book::createDir()
143 | {
144 | QString newDirName = QInputDialog::getText(this, "新建文件夹", "文件夹名字:");
145 | if(NULL == newDirName)
146 | {
147 | QMessageBox::warning(this, "新建文件夹", "文件夹名不能为空");
148 | return;
149 | }
150 | else if(newDirName.size() >= 32)
151 | {
152 | QMessageBox::warning(this, "新建文件夹", "too long");
153 | }
154 | QString strLoginName = tcpClient::getInstance().loginName();
155 | QString strCurPath = tcpClient::getInstance().currentPath();
156 | PDU *pdu = mkPDU(strCurPath.size() + 1);
157 | pdu->uiMsgType = ENUM_MSG_TYPE_CREATE_DIR_REQUEST;
158 | strncpy(pdu->caData, strLoginName.toStdString().c_str(), 32);
159 | strncpy(pdu->caData + 32, newDirName.toStdString().c_str(), 32);
160 | memcpy(pdu->caMsg, strCurPath.toStdString().c_str(), strCurPath.size());
161 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
162 | free(pdu);
163 | pdu = NULL;
164 | }
165 |
166 | void Book::flushFile()
167 | {
168 | clearEnterDir();
169 | QString strCurPath = tcpClient::getInstance().currentPath();
170 | qDebug() << "book flush路径" << strCurPath;
171 | PDU *pdu = mkPDU(strCurPath.size() + 1);
172 | pdu->uiMsgType = ENUM_MSG_TYPE_FLUSH_FILE_REQUEST;
173 | strncpy((char*)(pdu->caMsg), strCurPath.toStdString().c_str(), strCurPath.size());
174 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
175 | free(pdu);
176 | pdu = NULL;
177 |
178 | }
179 |
180 | void Book::deleteDir()
181 | {
182 | QString strCurPath = tcpClient::getInstance().currentPath();
183 | QListWidgetItem *pItem = m_pFileListWidget->currentItem();
184 | if(NULL == pItem)
185 | {
186 | QMessageBox::warning(this, "删除文件夹", "请选择删除的文件夹");
187 | }
188 | else
189 | {
190 | QString deleteName = pItem->text();
191 | PDU *pdu = mkPDU(strCurPath.size() + 1);
192 | pdu->uiMsgType = ENUM_MSG_TYPE_DELETE_DIR_REQUEST;
193 | strncpy((char*)(pdu->caData), deleteName.toStdString().c_str(), deleteName.size());
194 | memcpy(pdu->caMsg, strCurPath.toStdString().c_str(), strCurPath.size());
195 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
196 | free(pdu);
197 | pdu = NULL;
198 | }
199 |
200 | }
201 |
202 | void Book::renameFile()
203 | {
204 | QString strCurPath = tcpClient::getInstance().currentPath();
205 | QListWidgetItem *pItem = m_pFileListWidget->currentItem();
206 | if(NULL == pItem)
207 | {
208 | QMessageBox::warning(this, "重命名文件", "请选择重命名的文件");
209 | }
210 | else
211 | {
212 | QString newFileName = QInputDialog::getText(this, "重命名文件", "文件新名字:");
213 | QString oldFileName = pItem->text();
214 | if(newFileName.isEmpty())
215 | {
216 | QMessageBox::warning(this, "重命名文件", "文件名不能为空");
217 | }
218 | PDU *pdu = mkPDU(strCurPath.size() + 1);
219 | pdu->uiMsgType = ENUM_MSG_TYPE_RENAME_FILE_REQUEST;
220 | strncpy((char*)(pdu->caData), oldFileName.toStdString().c_str(), oldFileName.size());
221 | strncpy((char*)(pdu->caData + 32), newFileName.toStdString().c_str(), newFileName.size());
222 | memcpy(pdu->caMsg, strCurPath.toStdString().c_str(), strCurPath.size());
223 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
224 | free(pdu);
225 | pdu = NULL;
226 | }
227 | }
228 |
229 | void Book::enterDir(const QModelIndex &index)
230 | {
231 |
232 | QString selectDirName = index.data().toString(); //选择的文件名字
233 | qDebug() << selectDirName;
234 | m_strEnterDir = selectDirName;
235 | QString strCurPath = tcpClient::getInstance().currentPath();
236 | PDU *pdu = mkPDU(strCurPath.size() + 1);
237 | pdu->uiMsgType = ENUM_MSG_TYPE_ENTER_DIR_REQUEST;
238 | strncpy(pdu->caData, selectDirName.toStdString().c_str(), selectDirName.size());
239 | memcpy(pdu->caMsg, strCurPath.toStdString().c_str(), strCurPath.size());
240 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
241 | free(pdu);
242 | pdu = NULL;
243 | }
244 |
245 | void Book::returnPreContent()
246 | {
247 | QString strCurPath = tcpClient::getInstance().currentPath();
248 | QString strRootPath = "./" + tcpClient::getInstance().loginName();
249 | if(strCurPath == strRootPath)
250 | {
251 | QMessageBox::warning(this, "返回上一级目录", "已经在根目录");
252 | }
253 | else
254 | {
255 | //"目录的格式: ./aa/bb/cc"
256 | int index = strCurPath.lastIndexOf('/');
257 | QString newPath = strCurPath.remove(index, strCurPath.size() - index);
258 | qDebug() << "上一级目录为:" << newPath;
259 | tcpClient::getInstance().setCurrentPath(newPath);
260 | clearEnterDir();
261 | flushFile();
262 | }
263 | }
264 |
265 | void Book::uploadFile()
266 | {
267 | QString strCurPath = tcpClient::getInstance().currentPath();
268 | m_strUploadFilePath = QFileDialog::getOpenFileName();
269 | qDebug() << m_strUploadFilePath;
270 | if(NULL == m_strUploadFilePath)
271 | {
272 | QMessageBox::warning(this, "上传文件", "文件不能为空");
273 | }
274 | else
275 | {
276 |
277 | int index = m_strUploadFilePath.lastIndexOf('/');
278 | QString newFileName = m_strUploadFilePath.right(m_strUploadFilePath.size() - index - 1);
279 | qDebug() << newFileName;
280 |
281 | QFile file(m_strUploadFilePath );
282 | qint64 uploadFileSize = file.size();
283 | QString strCurPath = tcpClient::getInstance().currentPath();
284 | PDU *pdu = mkPDU(strCurPath.size() + 1);
285 | pdu->uiMsgType = ENUM_MSG_TYPE_UPLOAD_FILE_REQUEST;
286 | memcpy(pdu->caMsg, strCurPath.toStdString().c_str(), strCurPath.size());
287 | sprintf(pdu->caData, "%s %lld", newFileName.toStdString().c_str(), uploadFileSize);
288 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
289 | free(pdu);
290 | pdu = NULL;
291 |
292 | m_pTimer->start(1000);
293 | }
294 |
295 | }
296 |
297 | void Book::uploadFileData()
298 | {
299 | m_pTimer->stop();
300 | QFile file(m_strUploadFilePath);
301 | if(!file.open(QIODevice::ReadOnly))
302 | {
303 | QMessageBox::warning(this, "上传文件", "打开文件失败");
304 | return;
305 | }
306 | char *pBuffer = new char[4096];
307 | qint64 ret = 0;
308 | while(true)
309 | {
310 | ret = file.read(pBuffer, 4096);
311 | if(ret > 0 && ret <= 4096)
312 | {
313 | tcpClient::getInstance().gettcpSocket().write(pBuffer, ret);
314 | }
315 | else if(0 == ret)
316 | {
317 | break;
318 | }
319 | else
320 | {
321 | QMessageBox::warning(this, "上传文件", "上传文件失败");
322 | break;
323 | }
324 | }
325 | file.close();
326 | delete []pBuffer;
327 | pBuffer = NULL;
328 | }
329 |
330 | void Book::deleteFile()
331 | {
332 | QString strCurPath = tcpClient::getInstance().currentPath();
333 | QListWidgetItem *pItem = m_pFileListWidget->currentItem();
334 | if(NULL == pItem)
335 | {
336 | QMessageBox::warning(this, "删除文件", "请选择删除的文件");
337 | }
338 | else
339 | {
340 | QString deleteName = pItem->text();
341 | PDU *pdu = mkPDU(strCurPath.size() + 1);
342 | pdu->uiMsgType = ENUM_MSG_TYPE_DELETE_FILE_REQUEST;
343 | strncpy((char*)(pdu->caData), deleteName.toStdString().c_str(), deleteName.size());
344 | memcpy(pdu->caMsg, strCurPath.toStdString().c_str(), strCurPath.size());
345 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
346 | free(pdu);
347 | pdu = NULL;
348 | }
349 |
350 | }
351 |
352 | void Book::downloadFile()
353 | {
354 | QListWidgetItem *pItem = m_pFileListWidget->currentItem();
355 | if(NULL == pItem)
356 | {
357 | QMessageBox::warning(this, "下载文件", "请选择下载的文件");
358 | }
359 | else
360 | {
361 | QString strFileSavePath = QFileDialog::getSaveFileName();
362 | if(strFileSavePath.isEmpty())
363 | {
364 | QMessageBox::warning(this, "下载文件", "请选择文件保存位置");
365 | m_strFileSavePath.clear();
366 | }
367 | else
368 | {
369 | m_strFileSavePath = strFileSavePath;
370 | qDebug() << "文件保存的位置:" << m_strFileSavePath;
371 |
372 | }
373 | QString strCurPath = tcpClient::getInstance().currentPath();
374 | QString downloadName = pItem->text();
375 | PDU *pdu = mkPDU(strCurPath.size() + 1);
376 | pdu->uiMsgType = ENUM_MSG_TYPE_DOWNLOAD_FILE_REQUEST;
377 | strcpy(pdu->caData, downloadName.toStdString().c_str());
378 | memcpy(pdu->caMsg, strCurPath.toStdString().c_str(), strCurPath.size());
379 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
380 | free(pdu);
381 | pdu = NULL;
382 | }
383 | }
384 |
385 | void Book::shareFile()
386 | {
387 | QListWidgetItem *pItem = m_pFileListWidget->currentItem();
388 | if(NULL == pItem)
389 | {
390 | QMessageBox::warning(this, "分享文件", "请选择分享的文件");
391 | return;
392 | }
393 | else
394 | {
395 | m_strShareFileName = pItem->text();
396 | qDebug() << "选中的文件为: " << m_strShareFileName;
397 | }
398 | Friend *pFriend = OpeWidget::getInstance().getFriend();
399 | QListWidget *pFriendList = pFriend->getFriendList();
400 | ShareFile::getInstance().updateFriend(pFriendList);
401 | if(ShareFile::getInstance().isHidden())
402 | {
403 | ShareFile::getInstance().show();
404 |
405 | }
406 |
407 |
408 | }
409 |
410 | void Book::moveFile()
411 | {
412 | QListWidgetItem *pItem = m_pFileListWidget->currentItem();
413 | if(NULL == pItem)
414 | {
415 | QMessageBox::warning(this, "移动文件", "请选择移动的文件");
416 | }
417 | else
418 | {
419 | m_strMoveFileName = pItem->text();
420 | qDebug() << "移动的文件为: " << m_strMoveFileName;
421 | QString strCurPath = tcpClient::getInstance().currentPath();
422 | m_strMoveFilePath = strCurPath + '/' + m_strMoveFileName;
423 | m_pSelectMoveToDirPB->setEnabled(true);
424 |
425 | }
426 | }
427 |
428 | void Book::selectDestDir()
429 | {
430 | QListWidgetItem *pItem = m_pFileListWidget->currentItem();
431 | if(NULL == pItem)
432 | {
433 | QMessageBox::warning(this, "移动文件", "请选择移动到的文件夹");
434 | }
435 | else
436 | {
437 | QString destDirName = pItem->text();
438 | QString strCurPath = tcpClient::getInstance().currentPath();
439 | m_strDestDirPath = strCurPath + '/' + destDirName;
440 |
441 | int srcLen = m_strMoveFilePath.size();
442 | int destLen = m_strDestDirPath.size();
443 | PDU *pdu = mkPDU(srcLen + destLen + 2);
444 | pdu->uiMsgType = ENUM_MSG_TYPE_MOVE_FILE_REQUEST;
445 | sprintf(pdu->caData, "%d %d %s", srcLen, destLen, m_strMoveFileName.toStdString().c_str());
446 | memcpy(pdu->caMsg, m_strMoveFilePath.toStdString().c_str(), srcLen);
447 | memcpy((char*)(pdu->caMsg) + (srcLen + 1), m_strDestDirPath.toStdString().c_str(), destLen);
448 | tcpClient::getInstance().gettcpSocket().write((char*)pdu, pdu->uiPDULen);
449 | free(pdu);
450 | pdu = NULL;
451 | }
452 | m_pSelectMoveToDirPB->setEnabled(false);
453 | }
454 |
455 |
--------------------------------------------------------------------------------
/tcpServer/mytcpsocket.cpp:
--------------------------------------------------------------------------------
1 | #include "mytcpsocket.h"
2 | #include
3 | #include
4 | #include
5 |
6 |
7 | MyTcpSocket::MyTcpSocket()
8 | {
9 | connect(this, SIGNAL(readyRead()), this, SLOT(recvMsg()));
10 | connect(this, SIGNAL(disconnected()), this, SLOT(clientOffline()));
11 | m_bUpload = false;
12 | m_pTimer = new QTimer;
13 | connect(m_pTimer, SIGNAL(timeout()), this, SLOT(sendFileToClient()));
14 |
15 | }
16 |
17 | QString MyTcpSocket::getName()
18 | {
19 | return m_strName;
20 | }
21 |
22 | void MyTcpSocket::copyDir(QString strSrcDir, QString strDestDir)
23 | {
24 | QDir dir;
25 | dir.mkdir(strDestDir);
26 | dir.setPath(strSrcDir);
27 | QFileInfoList fileInfoList = dir.entryInfoList();
28 | QString srcTmp;
29 | QString destTmp;
30 | for(int i = 0; i < fileInfoList.size(); i++)
31 | {
32 | if(fileInfoList[i].isFile())
33 | {
34 | srcTmp += strSrcDir + '/' + fileInfoList[i].fileName();
35 | destTmp = strDestDir + '/' + fileInfoList[i].fileName();
36 | QFile::copy(srcTmp, destTmp);
37 | }
38 | else if(fileInfoList[i].isDir())
39 | {
40 | if(QString(".") == fileInfoList[i].fileName() || QString("..") == fileInfoList[i].fileName())
41 | {
42 | continue;
43 | }
44 | srcTmp += strSrcDir + '/' + fileInfoList[i].fileName();
45 | destTmp = strDestDir + '/' + fileInfoList[i].fileName();
46 | copyDir(srcTmp, destTmp);
47 | }
48 | }
49 | }
50 |
51 | void MyTcpSocket::recvMsg()
52 | {
53 | if(!m_bUpload)
54 | {
55 | qDebug() << this->bytesAvailable();
56 | unit uiPDULen = 0;
57 | this->read((char*)&uiPDULen, sizeof(unit));
58 | unit uiMsgLen = uiPDULen - sizeof(PDU);
59 | PDU *pdu = mkPDU(uiMsgLen);
60 | this->read((char*)pdu + sizeof(unit), uiPDULen - sizeof(unit));
61 | switch (pdu->uiMsgType)
62 | {
63 | case ENUM_MSG_TYPE_REGIST_REQUEST:
64 | {
65 | char caName[32] = {'\0'};
66 | char caPwd[32] = {'\0'};
67 | // 拷贝读取的信息
68 | strncpy(caName, pdu -> caData, 32);
69 | strncpy(caPwd, pdu -> caData + 32, 32);
70 | bool ret = OpeDB::getInstance().handleRegist(caName, caPwd); //处理请求,插入数据库
71 | PDU *respdu = mkPDU(0);
72 | respdu->uiMsgType = ENUM_MSG_TYPE_REGIST_RESPOND;
73 | if(ret)
74 | {
75 | strcpy(respdu->caData, REGIST_OK);
76 | QDir dir;
77 | dir.mkdir(QString("./%1").arg(caName));
78 | }
79 | else
80 | {
81 | strcpy(respdu->caData, REGIST_FAILED);
82 | }
83 | write((char*)respdu, respdu->uiPDULen);
84 | free(respdu);
85 | respdu = NULL;
86 | break;
87 |
88 | }
89 | case ENUM_MSG_TYPE_LOGIN_REQUEST:
90 | {
91 | char caName[32] = {'\0'};
92 | char caPwd[32] = {'\0'};
93 | // 拷贝读取的信息
94 | strncpy(caName, pdu -> caData, 32);
95 | strncpy(caPwd, pdu -> caData + 32, 32);
96 | bool ret = OpeDB::getInstance().handleLogin(caName, caPwd); //处理请求,插入数据库
97 | PDU *respdu = mkPDU(0);
98 | respdu->uiMsgType = ENUM_MSG_TYPE_LOGIN_RESPOND;
99 | if(ret)
100 | {
101 | strcpy(respdu->caData, LOGIN_OK);
102 | m_strName = caName;
103 | }
104 | else
105 | {
106 | strcpy(respdu->caData, LOGIN_FAILED);
107 | }
108 | write((char*)respdu, respdu->uiPDULen);
109 | free(respdu);
110 | respdu = NULL;
111 | break;
112 | }
113 | case ENUM_MSG_TYPE_ALL_ONLINE_REQUEST:
114 | {
115 | QStringList ret = OpeDB::getInstance().handleAllOnline();
116 | unit uiMsgLen = ret.size()*32;
117 | PDU *respdu = mkPDU(uiMsgLen);
118 | respdu->uiMsgType = ENUM_MSG_TYPE_ALL_ONLINE_RESPOND;
119 | for(int i = 0; i < ret.size(); i++){
120 | memcpy((char*)(respdu->caMsg) + i*32, ret.at(i).toStdString().c_str(),
121 | ret.at(i).size());
122 | }
123 | write((char*)respdu, respdu->uiPDULen);
124 | free(respdu);
125 | respdu = NULL;
126 |
127 | break;
128 | }
129 | case ENUM_MSG_TYPE_SEARCH_USER_REQUEST:
130 | {
131 | int ret = OpeDB::getInstance().handleSearchUser(pdu->caData);
132 | PDU *respdu = mkPDU(0);
133 | respdu->uiMsgType = ENUM_MSG_TYPE_SEARCH_USER_RESPOND;
134 | if(-1 == ret){
135 | strcpy(respdu->caData, SEARCH_USER_NO);
136 | }else if(1 == ret){
137 | strcpy(respdu->caData, SEARCH_USER_ONLINE);
138 | }else if(0 == ret){
139 | strcpy(respdu->caData, SEARCH_USER_OFFLINE);
140 | }
141 | write((char*)respdu, respdu->uiPDULen);
142 | free(respdu);
143 | respdu = NULL;
144 | break;
145 | }
146 | case ENUM_MSG_TYPE_ADD_FRIEND_REQUEST:
147 | {
148 | char caPerName[32] = {'\0'};
149 | char caName[32] = {'\0'};
150 | // 拷贝读取的信息
151 | strncpy(caPerName, pdu->caData, 32);
152 | strncpy(caName, pdu->caData + 32, 32);
153 | int ret = OpeDB::getInstance().handleAddFriend(caPerName, caName);
154 | PDU *respdu = mkPDU(0);
155 | respdu->uiMsgType = ENUM_MSG_TYPE_SEARCH_USER_RESPOND;
156 | if(-1 == ret){ //未知错误
157 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_RESPOND;
158 | strcpy(respdu->caData, UNKNOWN_ERROR);
159 | write((char*)respdu, respdu->uiPDULen);
160 | free(respdu);
161 | respdu = NULL;
162 | }
163 | else if(0 == ret){ //该好友已经存在
164 | // respdu = mkPDU(0);
165 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_RESPOND;
166 | strcpy(respdu->caData, EXISTED_FRIEND);
167 | write((char*)respdu, respdu->uiPDULen);
168 | free(respdu);
169 | respdu = NULL;
170 | }
171 | else if(1 == ret){ //
172 | MyTcpServer::getInstance().resend(caPerName, pdu);
173 | // respdu = mkPDU(0);
174 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_RESPOND;
175 | strcpy(respdu->caData, ADD_FRIEND_OK); // 表示加好友请求已发送
176 | write((char*)respdu, respdu->uiPDULen);
177 | free(respdu);
178 | respdu = NULL;
179 | }
180 | else if(2 == ret){ //不在线
181 | // respdu = mkPDU(0);
182 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_RESPOND;
183 | strcpy(respdu->caData, ADD_FRIEND_OFFLINE );
184 | write((char*)respdu, respdu->uiPDULen);
185 | free(respdu);
186 | respdu = NULL;
187 | }
188 | else if(3 == ret){ //不存在此人
189 | // respdu = mkPDU(0);
190 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_RESPOND;
191 | strcpy(respdu->caData ,ADD_FRIEND_NO_EXISTED);
192 | write((char*)respdu, respdu->uiPDULen);
193 | free(respdu);
194 | respdu = NULL;
195 | }
196 | break;
197 | }
198 | case ENUM_MSG_TYPE_ADD_FRIEND_AGREE:
199 | {
200 | char addedName[32] = {'\0'};
201 | char sourceName[32] = {'\0'};
202 | // 拷贝读取的信息
203 | strncpy(addedName, pdu->caData, 32);
204 | strncpy(sourceName, pdu->caData + 32, 32);
205 | PDU *respdu = mkPDU(0);
206 | OpeDB::getInstance().handleAddFriendAgree(addedName, sourceName);
207 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_AGREE;
208 | // 将新的好友关系信息写入数据库
209 |
210 | // 服务器需要转发给发送好友请求方其被同意的消息
211 | MyTcpServer::getInstance().resend(sourceName, pdu);
212 | write((char*)respdu, respdu->uiPDULen);
213 | free(respdu);
214 | respdu = NULL;
215 | break;
216 | }
217 | case ENUM_MSG_TYPE_ADD_FRIEND_REFUSE:
218 | {
219 | char sourceName[32] = {'\0'};
220 | // 拷贝读取的信息
221 | strncpy(sourceName, pdu -> caData + 32, 32);
222 | PDU *respdu = mkPDU(0);
223 | respdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_REFUSE;
224 | // 服务器需要转发给发送好友请求方其被拒绝的消息
225 | MyTcpServer::getInstance().resend(sourceName, pdu);
226 | write((char*)respdu, respdu->uiPDULen);
227 | free(respdu);
228 | respdu = NULL;
229 | break;
230 | }
231 | case ENUM_MSG_TYPE_FLUSH_FRIEND_REQUEST:
232 | {
233 | // 拷贝读取的信息
234 | char sourceName[32] = {'\0'};
235 | strncpy(sourceName, pdu->caData, 32);
236 | QStringList strList = OpeDB::getInstance().handleFlushFriend(sourceName);
237 | unit uiMsgLen = strList.size() / 2 * 36; // 36 char[32] 好友名字+ 4 int 在线状态
238 | PDU* respdu = mkPDU(uiMsgLen);
239 | respdu->uiMsgType = ENUM_MSG_TYPE_FLUSH_FRIEND_RESPOND;
240 | for(int i = 0; i * 2 < strList.size(); i++)
241 | {
242 | memcpy((char*)(respdu->caMsg) + 36 * i, strList.at(i * 2).toStdString().c_str(), 32);
243 | memcpy((char*)(respdu->caMsg) + 36 * i + 32, strList.at(i * 2 + 1).toStdString().c_str(), 4);
244 |
245 | }
246 | write((char*)respdu, respdu->uiPDULen);
247 | free(respdu);
248 | respdu = NULL;
249 | break;
250 | }
251 | case ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST:
252 | {
253 | char sourceName[32] = {'\0'};
254 | char deleteName[32] = {'\0'};
255 | strncpy(sourceName, pdu->caData, 32);
256 | strncpy(deleteName, pdu->caData + 32, 32);
257 | bool ret = OpeDB::getInstance().handleDeleteFriend(sourceName, deleteName);
258 |
259 | PDU* respdu = mkPDU(0);
260 | respdu->uiMsgType = ENUM_MSG_TYPE_DELETE_FRIEND_RESPOND;
261 | if(ret)
262 | {
263 | strcpy(respdu->caData, DELETE_OK);
264 | }
265 | else
266 | {
267 | strcpy(respdu->caData, DELETE_FAILED);
268 | }
269 | MyTcpServer::getInstance().resend(deleteName, pdu);
270 | write((char*)respdu, respdu->uiPDULen);
271 | free(respdu);
272 | respdu = NULL;
273 | break;
274 | }
275 | case ENUM_MSG_TYPE_PRIVATE_CHAT_REQUEST:
276 | {
277 | char sourceName[32] = {'\0'};
278 | char chatName[32] = {'\0'};
279 | strncpy(sourceName, pdu->caData, 32);
280 | strncpy(chatName, pdu->caData + 32, 32);
281 | MyTcpServer::getInstance().resend(chatName, pdu);
282 | MyTcpServer::getInstance().resend(sourceName, pdu);
283 | break;
284 | }
285 | case ENUM_MSG_TYPE_GROUP_CHAT_REQUEST:
286 | {
287 | char sourceName[32] = {'\0'};
288 | strncpy(sourceName, pdu->caData, 32);
289 | QStringList onlineFriend = OpeDB::getInstance().handleGroupChat(sourceName);
290 | QString tmp;
291 | for(int i = 0; i * 2 < onlineFriend.size(); i++)
292 | {
293 | tmp = onlineFriend.at(i * 2);
294 | MyTcpServer::getInstance().resend(tmp.toStdString().c_str(), pdu);
295 | }
296 | break;
297 | }
298 | case ENUM_MSG_TYPE_CREATE_DIR_REQUEST:
299 | {
300 | QDir dir;
301 | QString strCurPath = QString("%1").arg((char*)pdu->caMsg);
302 | bool ret = dir.exists(QString(strCurPath));
303 | qDebug() << "strcurpath: " << strCurPath;
304 | PDU *respdu = mkPDU(0);
305 | if(ret)
306 | {
307 | char strNewPath[32] = {'\0'};
308 | memcpy(strNewPath, pdu->caData + 32, 32);
309 | QString newPath = strCurPath + "/" + strNewPath;
310 | qDebug() << newPath;
311 | bool isExist = dir.exists(newPath);
312 | if(isExist)
313 | {
314 | respdu->uiMsgType = ENUM_MSG_TYPE_CREATE_DIR_RESPOND;
315 | strcpy(respdu->caData, DIR_ALREADY_EXSIT);
316 | }
317 | else
318 | { respdu->uiMsgType = ENUM_MSG_TYPE_CREATE_DIR_RESPOND;
319 | strcpy(respdu->caData, CREATE_DIR_OK);
320 | dir.mkdir(newPath);
321 | }
322 | }
323 | else
324 | {
325 | respdu->uiMsgType = ENUM_MSG_TYPE_CREATE_DIR_RESPOND;
326 | strcpy(respdu->caData, DIR_N0_EXSIT);
327 | }
328 | write((char*)respdu, respdu->uiPDULen);
329 | free(respdu);
330 | respdu = NULL;
331 | break;
332 | }
333 | case ENUM_MSG_TYPE_FLUSH_FILE_REQUEST:
334 | {
335 | char *pCurPath = new char[pdu->uiMsgLen];
336 | memcpy(pCurPath, pdu->caMsg, pdu->uiMsgLen); //当前的路径
337 | qDebug() << "刷新请求的路径:" << pCurPath;
338 | QDir dir(pCurPath);
339 | QFileInfoList fileList = dir.entryInfoList();
340 | int fileCount = fileList.size();
341 | PDU *respdu = mkPDU(sizeof(FileInfo) * (fileCount));
342 | respdu->uiMsgType = ENUM_MSG_TYPE_FLUSH_FILE_RESPOND;
343 | FileInfo *pFileInfo = NULL;
344 | QString strFileName;
345 | //遍历当前路径下所有的文件和文件夹
346 | for(int i = 0; i < fileList.size(); i++){
347 | //qDebug() << fileList.at(i).fileName() << " " << fileList.at(i).size()
348 | // << "文件夹:" << fileList.at(i).isDir() << "常规文件:" << fileList.at(i).isFile();
349 | pFileInfo = (FileInfo*)(respdu->caMsg) + i;
350 | strFileName = fileList[i].fileName();
351 | memcpy(pFileInfo->caFileName, strFileName.toStdString().c_str(), strFileName.size());
352 | if(fileList[i].isDir())
353 | {
354 | pFileInfo->iFileType = 0;
355 | }
356 | else if(fileList[i].isFile())
357 | {
358 | pFileInfo->iFileType = 1;
359 | }
360 | }
361 | write((char*)respdu, respdu->uiPDULen);
362 | free(respdu);
363 | respdu = NULL;
364 | break;
365 | }
366 | case ENUM_MSG_TYPE_DELETE_DIR_REQUEST:
367 | {
368 | char strDirName[32] = {'\0'};
369 | strcpy(strDirName, pdu->caData);
370 | char *pDirPath = new char[pdu->uiMsgLen];
371 | memcpy(pDirPath, pdu->caMsg, pdu->uiMsgLen);
372 | QString strPath = QString("%1/%2").arg(pDirPath).arg(strDirName);
373 | qDebug() << strPath;
374 | bool ret = false;
375 | QFileInfo fileInfo(strPath);
376 | if(fileInfo.isDir())
377 | {
378 | QDir dir;
379 | dir.setPath(strPath);
380 | ret = dir.removeRecursively();
381 | }
382 | else if(fileInfo.isFile())
383 | {
384 | ret = false;
385 | }
386 | PDU *respdu;
387 | if(ret)
388 | {
389 | respdu = mkPDU(strlen(DIR_DELETE_OK) + 1);
390 | respdu->uiMsgType = ENUM_MSG_TYPE_DELETE_DIR_RESPOND;
391 | memcpy(respdu->caData, DIR_DELETE_OK, strlen(DIR_DELETE_OK));
392 | }
393 | else
394 | {
395 | respdu = mkPDU(strlen(DIR_DELETE_FAILED) + 1);
396 | respdu->uiMsgType = ENUM_MSG_TYPE_DELETE_DIR_RESPOND;
397 | memcpy(respdu->caData, DIR_DELETE_FAILED, strlen(DIR_DELETE_FAILED));
398 | }
399 | write((char*)respdu, respdu->uiPDULen);
400 | free(respdu);
401 | respdu = NULL;
402 | break;
403 | }
404 | case ENUM_MSG_TYPE_RENAME_FILE_REQUEST:
405 | {
406 | char oldFileName[32] = {'\0'};
407 | char newFileName[32] = {'\0'};
408 | strncpy(oldFileName, pdu->caData, 32);
409 | strncpy(newFileName, pdu->caData + 32, 32);
410 | char *pPath = new char[pdu->uiMsgLen];
411 | memcpy(pPath, pdu->caMsg, pdu->uiMsgLen);
412 | QString strOldPath = QString("%1/%2").arg(pPath).arg(oldFileName);
413 | QString strNewPath = QString("%1/%2").arg(pPath).arg(newFileName);
414 | qDebug() << "oldpath:" << strOldPath << "newpath:" << strNewPath;
415 | bool ret = false;
416 |
417 | QDir dir;
418 | ret = dir.rename(strOldPath, strNewPath);
419 | PDU *respdu = mkPDU(0);
420 | respdu->uiMsgType = ENUM_MSG_TYPE_RENAME_FILE_RESPOND;
421 | if(ret)
422 | {
423 | memcpy(respdu->caData, RENAME_FILE_OK, strlen(RENAME_FILE_OK));
424 | }
425 | else
426 | {
427 | memcpy(respdu->caData, RENAME_FILE_FAILED, strlen(RENAME_FILE_FAILED));
428 | }
429 | write((char*)respdu, respdu->uiPDULen);
430 | free(respdu);
431 | respdu = NULL;
432 | break;
433 | }
434 | case ENUM_MSG_TYPE_ENTER_DIR_REQUEST:
435 | {
436 | char caEnterDirName[32] = {'\0'};
437 | strncpy(caEnterDirName, pdu->caData, 32);
438 | char *pPath = new char[pdu->uiMsgLen];
439 | memcpy(pPath, pdu->caMsg, pdu->uiMsgLen);
440 | QString strNewPath = QString("%1/%2").arg(pPath).arg(caEnterDirName);
441 | qDebug() << strNewPath;
442 | QFileInfo fileInfo(strNewPath);
443 | if(fileInfo.isDir())
444 | {
445 | QDir dir(strNewPath);
446 | QFileInfoList fileList = dir.entryInfoList();
447 | int fileCount = fileList.size();
448 | PDU *respdu = mkPDU(sizeof(FileInfo) * (fileCount));
449 | respdu->uiMsgType = ENUM_MSG_TYPE_FLUSH_FILE_RESPOND;
450 | FileInfo *pFileInfo;
451 | QString strFileName;
452 | for(int i = 0; i < fileList.size(); i++){
453 | pFileInfo = (FileInfo*)(respdu->caMsg) + i;
454 | strFileName = fileList[i].fileName();
455 | memcpy(pFileInfo->caFileName, strFileName.toStdString().c_str(), strFileName.size());
456 | if(fileList[i].isDir())
457 | {
458 | pFileInfo->iFileType = 0;
459 | }
460 | else if(fileList[i].isFile())
461 | {
462 | pFileInfo->iFileType = 1;
463 | }
464 | }
465 | write((char*)respdu, respdu->uiPDULen);
466 | free(respdu);
467 | respdu = NULL;
468 | }
469 | else if(fileInfo.isFile())
470 | {
471 | PDU *respdu = mkPDU(0);
472 | respdu->uiMsgType = ENUM_MSG_TYPE_ENTER_DIR_RESPOND;
473 | memcpy(respdu->caData, ENTER_DIR_FAILED, strlen(ENTER_DIR_FAILED));
474 | write((char*)respdu, respdu->uiPDULen);
475 | free(respdu);
476 | respdu = NULL;
477 | }
478 |
479 | break;
480 | }
481 | case ENUM_MSG_TYPE_UPLOAD_FILE_REQUEST:
482 | {
483 | char uploadFileName[32] = {'\0'};
484 | qint64 uploadFileSize = 0;
485 | sscanf(pdu->caData, "%s %lld", uploadFileName, &uploadFileSize);
486 | char *pPath = new char[pdu->uiMsgLen];
487 | memcpy(pPath, pdu->caMsg, pdu->uiMsgLen);
488 | QString strNewPath = QString("%1/%2").arg(pPath).arg(uploadFileName);
489 | qDebug() << strNewPath;
490 | delete []pPath;
491 | pPath = NULL;
492 |
493 | m_file.setFileName(strNewPath);
494 | if(m_file.open(QIODevice::WriteOnly))
495 | {
496 | m_bUpload = true;
497 | m_iTotal = uploadFileSize;
498 | m_iReceived = 0;
499 | }
500 | break;
501 | }
502 | case ENUM_MSG_TYPE_DELETE_FILE_REQUEST:
503 | {
504 | char strFileName[32] = {'\0'};
505 | strcpy(strFileName, pdu->caData);
506 | char *pDirPath = new char[pdu->uiMsgLen];
507 | memcpy(pDirPath, pdu->caMsg, pdu->uiMsgLen);
508 | QString strPath = QString("%1/%2").arg(pDirPath).arg(strFileName);
509 | qDebug() << strPath;
510 | bool ret = false;
511 | QFileInfo fileInfo(strPath);
512 | if(fileInfo.isDir())
513 | {
514 | ret = false;
515 | }
516 | else if(fileInfo.isFile())
517 | {
518 |
519 | QDir dir;
520 | ret = dir.remove(strPath);
521 | }
522 | PDU *respdu;
523 | if(ret)
524 | {
525 | respdu = mkPDU(strlen(FILE_DELETE_OK) + 1);
526 | respdu->uiMsgType = ENUM_MSG_TYPE_DELETE_FILE_RESPOND;
527 | memcpy(respdu->caData, FILE_DELETE_OK, strlen(FILE_DELETE_OK));
528 | }
529 | else
530 | {
531 | respdu = mkPDU(strlen(FILE_DELETE_FAILED) + 1);
532 | respdu->uiMsgType = ENUM_MSG_TYPE_DELETE_FILE_RESPOND;
533 | memcpy(respdu->caData, FILE_DELETE_FAILED, strlen(FILE_DELETE_FAILED));
534 | }
535 | write((char*)respdu, respdu->uiPDULen);
536 | free(respdu);
537 | respdu = NULL;
538 | break;
539 | }
540 | case ENUM_MSG_TYPE_DOWNLOAD_FILE_REQUEST:
541 | {
542 | char caFileName[32] = {'\0'};
543 | strcpy(caFileName, pdu->caData);
544 | char *pPath = new char[pdu->uiMsgLen];
545 | memcpy(pPath, pdu->caMsg, pdu->uiMsgLen);
546 | QString strNewPath = QString("%1/%2").arg(pPath).arg(caFileName);
547 |
548 | qDebug() << "当前下载文件的地址:" << strNewPath;
549 | delete []pPath;
550 | pPath = NULL;
551 |
552 | QFileInfo fileInfo(strNewPath);
553 | qint64 fileSize = fileInfo.size();
554 | qDebug() << "caFileName" << caFileName << "filesize" << fileSize;
555 | PDU *respdu = mkPDU(0);
556 | respdu->uiMsgType = ENUM_MSG_TYPE_DOWNLOAD_FILE_RESPOND;
557 | sprintf(respdu->caData, "%s %lld", caFileName, fileSize);
558 |
559 | write((char*)respdu, respdu->uiPDULen);
560 | free(respdu);
561 | respdu = NULL;
562 |
563 | m_file.setFileName(strNewPath);
564 | m_file.open(QIODevice::ReadOnly);
565 | m_pTimer->start(1000);
566 | break;
567 | }
568 | case ENUM_MSG_TYPE_SHARE_FILE_REQUEST:
569 | {
570 | char strSendName[32] = {'\0'};
571 | int shareNum = 0;
572 | sscanf(pdu->caData, "%s %d", strSendName, &shareNum);
573 | qDebug() << "分享文件的人:" << strSendName << " 人数:" << shareNum;
574 | int size = shareNum * 32;
575 | PDU *respdu = mkPDU(pdu->uiMsgLen - size);
576 | respdu->uiMsgType = ENUM_MSG_TYPE_SHARE_FILE_NOTE_REQUEST;
577 |
578 | strcpy(respdu->caData, strSendName);
579 | memcpy(respdu->caMsg, (char*)(pdu->caMsg) + size, pdu->uiMsgLen - size); //文件路径
580 | qDebug() << "接收到文件的路径为:" << respdu->caMsg;
581 | char caReceiveName[32] = {'\0'};
582 | for(int i = 0; i < shareNum; i++)
583 | {
584 | memcpy(caReceiveName, (char*)(pdu->caMsg) + i * 32, 32);
585 | qDebug() << "接收到文件的好友为:" << caReceiveName;
586 | MyTcpServer::getInstance().resend(caReceiveName, respdu);
587 | }
588 | free(respdu);
589 | respdu = NULL;
590 | respdu = mkPDU(0);
591 | respdu->uiMsgType = ENUM_MSG_TYPE_SHARE_FILE_RESPOND;
592 | strcpy(respdu->caData, SHARE_FILE_OK);
593 | write((char*)respdu, respdu->uiPDULen);
594 | free(respdu);
595 | respdu = NULL;
596 |
597 | break;
598 | }
599 | case ENUM_MSG_TYPE_SHARE_FILE_NOTE_RESPOND:
600 | {
601 | QString strReceivePath = QString("./%1").arg(pdu->caData);
602 | QString strSharePath = QString("%1").arg((char*)(pdu->caMsg));
603 |
604 | int index = strSharePath.lastIndexOf('/');
605 | QString strFileName = strSharePath.right(strSharePath.size() - index - 1);
606 | qDebug() << "被分享者的路径:" << strReceivePath;
607 | qDebug() << "被分享的文件名:" << strFileName;
608 | strReceivePath = strReceivePath + '/' + strFileName;
609 | qDebug() << "被分享者的路径:" << strReceivePath;
610 | QFileInfo fileInfo(strSharePath);
611 | if(fileInfo.isDir())
612 | {
613 | copyDir(strSharePath, strReceivePath);
614 | }
615 | else if(fileInfo.isFile())
616 | {
617 | QFile::copy(strSharePath, strReceivePath);
618 | }
619 | break;
620 | }
621 | case ENUM_MSG_TYPE_MOVE_FILE_REQUEST:
622 | {
623 | char caFileName[32] = {'\0'};
624 | int srcLen = 0;
625 | int destLen = 0;
626 | sscanf(pdu->caData, "%d%d%s", &srcLen, &destLen, caFileName);
627 | char *pSrcPath = new char[srcLen + 1];
628 | char *pDestPath = new char[destLen + 1 + 32];
629 | memset(pSrcPath, '\0', srcLen + 1);
630 | memset(pDestPath, '\0', destLen + 1 + 32);
631 |
632 | memcpy(pSrcPath, pdu->caMsg, srcLen);
633 | memcpy(pDestPath, (char*)(pdu->caMsg) + (srcLen + 1), destLen);
634 |
635 | QFileInfo fileInfo(pDestPath);
636 | PDU *respdu = mkPDU(0);
637 | respdu->uiMsgType = ENUM_MSG_TYPE_MOVE_FILE_RESPOND;
638 | if(fileInfo.isDir())
639 | {
640 | strcat(pDestPath, "/");
641 | strcat(pDestPath, caFileName);
642 |
643 | bool ret = QFile::rename(pSrcPath, pDestPath);
644 | if(ret)
645 | {
646 | strcpy(respdu->caData, MOVE_FILE_OK);
647 | }
648 | else
649 | {
650 | strcpy(respdu->caData, COMMON_ERROR);
651 | }
652 |
653 | }
654 | else if(fileInfo.isFile())
655 | {
656 | strcpy(respdu->caData, MOVE_FILE_FAILED);
657 | }
658 | write((char*)respdu, respdu->uiPDULen);
659 | free(respdu);
660 | respdu = NULL;
661 | break;
662 | }
663 |
664 |
665 | default:
666 | break;
667 | }
668 | free(pdu);
669 | pdu = NULL;
670 | }
671 | else
672 | {
673 | PDU *respdu = mkPDU(0);
674 | respdu->uiMsgType = ENUM_MSG_TYPE_UPLOAD_FILE_RESPOND;
675 | QByteArray buffer = readAll();
676 | m_file.write(buffer);
677 | m_iReceived += buffer.size();
678 | if(m_iTotal == m_iReceived)
679 | {
680 | m_file.close();
681 | m_bUpload = false;
682 | strcpy(respdu->caData, UPLOAD_FILE_OK);
683 | write((char*)respdu, respdu->uiPDULen);
684 | free(respdu);
685 | respdu = NULL;
686 | }
687 | else if(m_iTotal < m_iReceived)
688 | {
689 | m_file.close();
690 | m_bUpload = false;
691 | strcpy(respdu->caData, UPLOAD_FILE_FAILED);
692 | }
693 |
694 | }
695 | }
696 |
697 | void MyTcpSocket::clientOffline()
698 | {
699 | OpeDB::getInstance().handleOffline(m_strName.toStdString().c_str());
700 | emit offline(this);
701 | }
702 |
703 | void MyTcpSocket::sendFileToClient()
704 | {
705 | m_pTimer->stop();
706 | char *buffer = new char[4096];
707 | qint64 ret = 0;
708 | while(true)
709 | {
710 | ret = m_file.read(buffer, 4096);
711 | if(ret > 0 && ret <= 4096)
712 | {
713 | write(buffer, ret);
714 | }
715 | else if(0 == ret)
716 | {
717 | m_file.close();
718 | break;
719 | }
720 | else if(ret < 0)
721 | {
722 | qDebug() << "发送文件内容给Client失败";
723 | m_file.close();
724 | break;
725 | }
726 | }
727 | delete []buffer;
728 | buffer = NULL;
729 | }
730 |
--------------------------------------------------------------------------------
/tcpServer/tcpServer.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {bb85f564-1f46-4df4-bcf3-0842f8e2c5b7}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 | -fno-delayed-template-parsing
60 |
61 | true
62 |
63 |
64 |
65 | ProjectExplorer.Project.Target.0
66 |
67 | Desktop Qt 5.14.2 MinGW 32-bit
68 | Desktop Qt 5.14.2 MinGW 32-bit
69 | qt.qt5.5142.win32_mingw73_kit
70 | 0
71 | 0
72 | 0
73 |
74 | D:/Qt/build-tcpServer-Desktop_Qt_5_14_2_MinGW_32_bit-Debug
75 |
76 |
77 | true
78 | QtProjectManager.QMakeBuildStep
79 | true
80 |
81 | false
82 | false
83 | false
84 |
85 |
86 | true
87 | Qt4ProjectManager.MakeStep
88 |
89 | false
90 |
91 |
92 | false
93 |
94 | 2
95 | Build
96 | Build
97 | ProjectExplorer.BuildSteps.Build
98 |
99 |
100 |
101 | true
102 | Qt4ProjectManager.MakeStep
103 |
104 | true
105 | clean
106 |
107 | false
108 |
109 | 1
110 | Clean
111 | Clean
112 | ProjectExplorer.BuildSteps.Clean
113 |
114 | 2
115 | false
116 |
117 | Debug
118 | Qt4ProjectManager.Qt4BuildConfiguration
119 | 2
120 |
121 |
122 | D:/Qt/build-tcpServer-Desktop_Qt_5_14_2_MinGW_32_bit-Release
123 |
124 |
125 | true
126 | QtProjectManager.QMakeBuildStep
127 | false
128 |
129 | false
130 | false
131 | true
132 |
133 |
134 | true
135 | Qt4ProjectManager.MakeStep
136 |
137 | false
138 |
139 |
140 | false
141 |
142 | 2
143 | Build
144 | Build
145 | ProjectExplorer.BuildSteps.Build
146 |
147 |
148 |
149 | true
150 | Qt4ProjectManager.MakeStep
151 |
152 | true
153 | clean
154 |
155 | false
156 |
157 | 1
158 | Clean
159 | Clean
160 | ProjectExplorer.BuildSteps.Clean
161 |
162 | 2
163 | false
164 |
165 | Release
166 | Qt4ProjectManager.Qt4BuildConfiguration
167 | 0
168 |
169 |
170 | D:/Qt/build-tcpServer-Desktop_Qt_5_14_2_MinGW_32_bit-Profile
171 |
172 |
173 | true
174 | QtProjectManager.QMakeBuildStep
175 | true
176 |
177 | false
178 | true
179 | true
180 |
181 |
182 | true
183 | Qt4ProjectManager.MakeStep
184 |
185 | false
186 |
187 |
188 | false
189 |
190 | 2
191 | Build
192 | Build
193 | ProjectExplorer.BuildSteps.Build
194 |
195 |
196 |
197 | true
198 | Qt4ProjectManager.MakeStep
199 |
200 | true
201 | clean
202 |
203 | false
204 |
205 | 1
206 | Clean
207 | Clean
208 | ProjectExplorer.BuildSteps.Clean
209 |
210 | 2
211 | false
212 |
213 | Profile
214 | Qt4ProjectManager.Qt4BuildConfiguration
215 | 0
216 |
217 | 3
218 |
219 |
220 | 0
221 | Deploy
222 | Deploy
223 | ProjectExplorer.BuildSteps.Deploy
224 |
225 | 1
226 | ProjectExplorer.DefaultDeployConfiguration
227 |
228 | 1
229 |
230 |
231 | dwarf
232 |
233 | cpu-cycles
234 |
235 |
236 | 250
237 |
238 | -e
239 | cpu-cycles
240 | --call-graph
241 | dwarf,4096
242 | -F
243 | 250
244 |
245 | -F
246 | true
247 | 4096
248 | false
249 | false
250 | 1000
251 |
252 | true
253 |
254 | false
255 | false
256 | false
257 | false
258 | true
259 | 0.01
260 | 10
261 | true
262 | kcachegrind
263 | 1
264 | 25
265 |
266 | 1
267 | true
268 | false
269 | true
270 | valgrind
271 |
272 | 0
273 | 1
274 | 2
275 | 3
276 | 4
277 | 5
278 | 6
279 | 7
280 | 8
281 | 9
282 | 10
283 | 11
284 | 12
285 | 13
286 | 14
287 |
288 | 2
289 |
290 | Qt4ProjectManager.Qt4RunConfiguration:D:/Qt/tcpServer/tcpServer.pro
291 | D:/Qt/tcpServer/tcpServer.pro
292 |
293 | false
294 |
295 | false
296 | true
297 | true
298 | false
299 | false
300 | true
301 |
302 | D:/Qt/build-tcpServer-Desktop_Qt_5_14_2_MinGW_32_bit-Debug
303 |
304 | 1
305 |
306 |
307 |
308 | ProjectExplorer.Project.Target.1
309 |
310 | Desktop Qt 5.14.2 MinGW 64-bit
311 | Desktop Qt 5.14.2 MinGW 64-bit
312 | qt.qt5.5142.win64_mingw73_kit
313 | 0
314 | 0
315 | 0
316 |
317 | D:/Qt/build-tcpServer-Desktop_Qt_5_14_2_MinGW_64_bit-Debug
318 |
319 |
320 | true
321 | QtProjectManager.QMakeBuildStep
322 | true
323 |
324 | false
325 | false
326 | false
327 |
328 |
329 | true
330 | Qt4ProjectManager.MakeStep
331 |
332 | false
333 |
334 |
335 | false
336 |
337 | 2
338 | Build
339 | Build
340 | ProjectExplorer.BuildSteps.Build
341 |
342 |
343 |
344 | true
345 | Qt4ProjectManager.MakeStep
346 |
347 | true
348 | clean
349 |
350 | false
351 |
352 | 1
353 | Clean
354 | Clean
355 | ProjectExplorer.BuildSteps.Clean
356 |
357 | 2
358 | false
359 |
360 | Debug
361 | Qt4ProjectManager.Qt4BuildConfiguration
362 | 2
363 |
364 |
365 | D:/Qt/build-tcpServer-Desktop_Qt_5_14_2_MinGW_64_bit-Release
366 |
367 |
368 | true
369 | QtProjectManager.QMakeBuildStep
370 | false
371 |
372 | false
373 | false
374 | true
375 |
376 |
377 | true
378 | Qt4ProjectManager.MakeStep
379 |
380 | false
381 |
382 |
383 | false
384 |
385 | 2
386 | Build
387 | Build
388 | ProjectExplorer.BuildSteps.Build
389 |
390 |
391 |
392 | true
393 | Qt4ProjectManager.MakeStep
394 |
395 | true
396 | clean
397 |
398 | false
399 |
400 | 1
401 | Clean
402 | Clean
403 | ProjectExplorer.BuildSteps.Clean
404 |
405 | 2
406 | false
407 |
408 | Release
409 | Qt4ProjectManager.Qt4BuildConfiguration
410 | 0
411 |
412 |
413 | D:/Qt/build-tcpServer-Desktop_Qt_5_14_2_MinGW_64_bit-Profile
414 |
415 |
416 | true
417 | QtProjectManager.QMakeBuildStep
418 | true
419 |
420 | false
421 | true
422 | true
423 |
424 |
425 | true
426 | Qt4ProjectManager.MakeStep
427 |
428 | false
429 |
430 |
431 | false
432 |
433 | 2
434 | Build
435 | Build
436 | ProjectExplorer.BuildSteps.Build
437 |
438 |
439 |
440 | true
441 | Qt4ProjectManager.MakeStep
442 |
443 | true
444 | clean
445 |
446 | false
447 |
448 | 1
449 | Clean
450 | Clean
451 | ProjectExplorer.BuildSteps.Clean
452 |
453 | 2
454 | false
455 |
456 | Profile
457 | Qt4ProjectManager.Qt4BuildConfiguration
458 | 0
459 |
460 | 3
461 |
462 |
463 | 0
464 | Deploy
465 | Deploy
466 | ProjectExplorer.BuildSteps.Deploy
467 |
468 | 1
469 | ProjectExplorer.DefaultDeployConfiguration
470 |
471 | 1
472 |
473 |
474 | dwarf
475 |
476 | cpu-cycles
477 |
478 |
479 | 250
480 |
481 | -e
482 | cpu-cycles
483 | --call-graph
484 | dwarf,4096
485 | -F
486 | 250
487 |
488 | -F
489 | true
490 | 4096
491 | false
492 | false
493 | 1000
494 |
495 | true
496 |
497 | false
498 | false
499 | false
500 | false
501 | true
502 | 0.01
503 | 10
504 | true
505 | kcachegrind
506 | 1
507 | 25
508 |
509 | 1
510 | true
511 | false
512 | true
513 | valgrind
514 |
515 | 0
516 | 1
517 | 2
518 | 3
519 | 4
520 | 5
521 | 6
522 | 7
523 | 8
524 | 9
525 | 10
526 | 11
527 | 12
528 | 13
529 | 14
530 |
531 | 2
532 |
533 |
534 | ProjectExplorer.CustomExecutableRunConfiguration
535 |
536 |
537 | false
538 |
539 | false
540 | true
541 | false
542 | false
543 | true
544 |
545 |
546 |
547 | 1
548 |
549 |
550 |
551 | ProjectExplorer.Project.TargetCount
552 | 2
553 |
554 |
555 | ProjectExplorer.Project.Updater.FileVersion
556 | 22
557 |
558 |
559 | Version
560 | 22
561 |
562 |
563 |
--------------------------------------------------------------------------------
/tcpClient/tcpClient.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {bb85f564-1f46-4df4-bcf3-0842f8e2c5b7}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 | true
60 | true
61 | true
62 | true
63 |
64 |
65 | 0
66 | true
67 |
68 | -fno-delayed-template-parsing
69 |
70 | true
71 |
72 | true
73 | true
74 | Builtin.DefaultTidyAndClazy
75 | 8
76 | true
77 |
78 |
79 |
80 | true
81 |
82 |
83 |
84 |
85 | ProjectExplorer.Project.Target.0
86 |
87 | Desktop Qt 5.14.2 MinGW 32-bit
88 | Desktop Qt 5.14.2 MinGW 32-bit
89 | qt.qt5.5142.win32_mingw73_kit
90 | 0
91 | 0
92 | 0
93 |
94 | D:/Qt/build-tcpClient-Desktop_Qt_5_14_2_MinGW_32_bit-Debug
95 |
96 |
97 | true
98 | QtProjectManager.QMakeBuildStep
99 | true
100 |
101 | false
102 | false
103 | false
104 |
105 |
106 | true
107 | Qt4ProjectManager.MakeStep
108 |
109 | false
110 |
111 |
112 | false
113 |
114 | 2
115 | Build
116 | Build
117 | ProjectExplorer.BuildSteps.Build
118 |
119 |
120 |
121 | true
122 | Qt4ProjectManager.MakeStep
123 |
124 | true
125 | clean
126 |
127 | false
128 |
129 | 1
130 | Clean
131 | Clean
132 | ProjectExplorer.BuildSteps.Clean
133 |
134 | 2
135 | false
136 |
137 | Debug
138 | Qt4ProjectManager.Qt4BuildConfiguration
139 | 2
140 |
141 |
142 | D:/Qt/build-tcpClient-Desktop_Qt_5_14_2_MinGW_32_bit-Release
143 |
144 |
145 | true
146 | QtProjectManager.QMakeBuildStep
147 | false
148 |
149 | false
150 | false
151 | true
152 |
153 |
154 | true
155 | Qt4ProjectManager.MakeStep
156 |
157 | false
158 |
159 |
160 | false
161 |
162 | 2
163 | Build
164 | Build
165 | ProjectExplorer.BuildSteps.Build
166 |
167 |
168 |
169 | true
170 | Qt4ProjectManager.MakeStep
171 |
172 | true
173 | clean
174 |
175 | false
176 |
177 | 1
178 | Clean
179 | Clean
180 | ProjectExplorer.BuildSteps.Clean
181 |
182 | 2
183 | false
184 |
185 | Release
186 | Qt4ProjectManager.Qt4BuildConfiguration
187 | 0
188 |
189 |
190 | D:/Qt/build-tcpClient-Desktop_Qt_5_14_2_MinGW_32_bit-Profile
191 |
192 |
193 | true
194 | QtProjectManager.QMakeBuildStep
195 | true
196 |
197 | false
198 | true
199 | true
200 |
201 |
202 | true
203 | Qt4ProjectManager.MakeStep
204 |
205 | false
206 |
207 |
208 | false
209 |
210 | 2
211 | Build
212 | Build
213 | ProjectExplorer.BuildSteps.Build
214 |
215 |
216 |
217 | true
218 | Qt4ProjectManager.MakeStep
219 |
220 | true
221 | clean
222 |
223 | false
224 |
225 | 1
226 | Clean
227 | Clean
228 | ProjectExplorer.BuildSteps.Clean
229 |
230 | 2
231 | false
232 |
233 | Profile
234 | Qt4ProjectManager.Qt4BuildConfiguration
235 | 0
236 |
237 | 3
238 |
239 |
240 | 0
241 | Deploy
242 | Deploy
243 | ProjectExplorer.BuildSteps.Deploy
244 |
245 | 1
246 | ProjectExplorer.DefaultDeployConfiguration
247 |
248 | 1
249 |
250 |
251 | dwarf
252 |
253 | cpu-cycles
254 |
255 |
256 | 250
257 |
258 | -e
259 | cpu-cycles
260 | --call-graph
261 | dwarf,4096
262 | -F
263 | 250
264 |
265 | -F
266 | true
267 | 4096
268 | false
269 | false
270 | 1000
271 |
272 | true
273 |
274 | false
275 | false
276 | false
277 | false
278 | true
279 | 0.01
280 | 10
281 | true
282 | kcachegrind
283 | 1
284 | 25
285 |
286 | 1
287 | true
288 | false
289 | true
290 | valgrind
291 |
292 | 0
293 | 1
294 | 2
295 | 3
296 | 4
297 | 5
298 | 6
299 | 7
300 | 8
301 | 9
302 | 10
303 | 11
304 | 12
305 | 13
306 | 14
307 |
308 | 2
309 |
310 | Qt4ProjectManager.Qt4RunConfiguration:D:/Qt/tcpClient/tcpClient.pro
311 | D:/Qt/tcpClient/tcpClient.pro
312 |
313 | false
314 |
315 | false
316 | true
317 | true
318 | false
319 | false
320 | true
321 |
322 | D:/Qt/build-tcpClient-Desktop_Qt_5_14_2_MinGW_32_bit-Debug
323 |
324 | 1
325 |
326 |
327 |
328 | ProjectExplorer.Project.Target.1
329 |
330 | Desktop Qt 5.14.2 MinGW 64-bit
331 | Desktop Qt 5.14.2 MinGW 64-bit
332 | qt.qt5.5142.win64_mingw73_kit
333 | 0
334 | 0
335 | 0
336 |
337 | D:/Qt/build-tcpClient-Desktop_Qt_5_14_2_MinGW_64_bit-Debug
338 |
339 |
340 | true
341 | QtProjectManager.QMakeBuildStep
342 | true
343 |
344 | false
345 | false
346 | false
347 |
348 |
349 | true
350 | Qt4ProjectManager.MakeStep
351 |
352 | false
353 |
354 |
355 | false
356 |
357 | 2
358 | Build
359 | Build
360 | ProjectExplorer.BuildSteps.Build
361 |
362 |
363 |
364 | true
365 | Qt4ProjectManager.MakeStep
366 |
367 | true
368 | clean
369 |
370 | false
371 |
372 | 1
373 | Clean
374 | Clean
375 | ProjectExplorer.BuildSteps.Clean
376 |
377 | 2
378 | false
379 |
380 | Debug
381 | Qt4ProjectManager.Qt4BuildConfiguration
382 | 2
383 |
384 |
385 | D:/Qt/build-tcpClient-Desktop_Qt_5_14_2_MinGW_64_bit-Release
386 |
387 |
388 | true
389 | QtProjectManager.QMakeBuildStep
390 | false
391 |
392 | false
393 | false
394 | true
395 |
396 |
397 | true
398 | Qt4ProjectManager.MakeStep
399 |
400 | false
401 |
402 |
403 | false
404 |
405 | 2
406 | Build
407 | Build
408 | ProjectExplorer.BuildSteps.Build
409 |
410 |
411 |
412 | true
413 | Qt4ProjectManager.MakeStep
414 |
415 | true
416 | clean
417 |
418 | false
419 |
420 | 1
421 | Clean
422 | Clean
423 | ProjectExplorer.BuildSteps.Clean
424 |
425 | 2
426 | false
427 |
428 | Release
429 | Qt4ProjectManager.Qt4BuildConfiguration
430 | 0
431 |
432 |
433 | D:/Qt/build-tcpClient-Desktop_Qt_5_14_2_MinGW_64_bit-Profile
434 |
435 |
436 | true
437 | QtProjectManager.QMakeBuildStep
438 | true
439 |
440 | false
441 | true
442 | true
443 |
444 |
445 | true
446 | Qt4ProjectManager.MakeStep
447 |
448 | false
449 |
450 |
451 | false
452 |
453 | 2
454 | Build
455 | Build
456 | ProjectExplorer.BuildSteps.Build
457 |
458 |
459 |
460 | true
461 | Qt4ProjectManager.MakeStep
462 |
463 | true
464 | clean
465 |
466 | false
467 |
468 | 1
469 | Clean
470 | Clean
471 | ProjectExplorer.BuildSteps.Clean
472 |
473 | 2
474 | false
475 |
476 | Profile
477 | Qt4ProjectManager.Qt4BuildConfiguration
478 | 0
479 |
480 | 3
481 |
482 |
483 | 0
484 | Deploy
485 | Deploy
486 | ProjectExplorer.BuildSteps.Deploy
487 |
488 | 1
489 | ProjectExplorer.DefaultDeployConfiguration
490 |
491 | 1
492 |
493 |
494 | dwarf
495 |
496 | cpu-cycles
497 |
498 |
499 | 250
500 |
501 | -e
502 | cpu-cycles
503 | --call-graph
504 | dwarf,4096
505 | -F
506 | 250
507 |
508 | -F
509 | true
510 | 4096
511 | false
512 | false
513 | 1000
514 |
515 | true
516 |
517 | false
518 | false
519 | false
520 | false
521 | true
522 | 0.01
523 | 10
524 | true
525 | kcachegrind
526 | 1
527 | 25
528 |
529 | 1
530 | true
531 | false
532 | true
533 | valgrind
534 |
535 | 0
536 | 1
537 | 2
538 | 3
539 | 4
540 | 5
541 | 6
542 | 7
543 | 8
544 | 9
545 | 10
546 | 11
547 | 12
548 | 13
549 | 14
550 |
551 | 2
552 |
553 |
554 | ProjectExplorer.CustomExecutableRunConfiguration
555 |
556 |
557 | false
558 |
559 | false
560 | true
561 | false
562 | false
563 | true
564 |
565 |
566 |
567 | 1
568 |
569 |
570 |
571 | ProjectExplorer.Project.TargetCount
572 | 2
573 |
574 |
575 | ProjectExplorer.Project.Updater.FileVersion
576 | 22
577 |
578 |
579 | Version
580 | 22
581 |
582 |
583 |
--------------------------------------------------------------------------------