-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.h
116 lines (82 loc) · 2.19 KB
/
mainwindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
TRANSFERMODE:
0 - ALL
1 - PDF
2 - JPEG
3 - DOC
4 - ACCESS
5 - EXCEL
6 - TXT
7 - 质控
8 - 生产
9 - 库存
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QFile>
#include <QMessageBox>
#include <QDataStream>
#include <QTextStream>
#include <QFileDialog>
#include <QString>
#include <QCryptographicHash>
#include <QMainWindow>
#include <vector>
#include <map>
#include "dialog.h"
#include "client.h"
#include "Blockchain.h"
#include "File.h"
#include "server.h"
#include <iostream>
using namespace std;
namespace Ui {
class MainWindow;
}
struct Package;
class Server;
struct Connection {
QString ipAddr;
quint16 portAddr;
Connection(const QString& ip, quint16 port): ipAddr(ip), portAddr(port) {}
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void updateBlockchain();
signals:
void addNewHost(const vector<Connection>& hosts);
private slots:
void on_UpdateBlockchain_clicked();
void on_Store_clicked();
void on_Save_clicked();
void on_View_clicked();
void on_Connect_clicked();
// void blockChainReceived(const QString& blockChainText, const Blockchain<File>& otherChain);
void saveConnection(const QString& ip, quint16 port);
void addText(const QString& updates);
void displayError(int socketError, const QString &message, const QString& ip, quint16 port);
bool setUpConnection(const QString& ip, quint16 port);
void newBlockchain(const Blockchain<File>& importedChain, const QByteArray& packet);
void updateLengthDisplay();
void changeMode();
private:
//order of declation = order of being initialized!
Ui::MainWindow *ui;
Blockchain<File>* bChain;
vector<Connection> connections;
map<QByteArray, vector<Connection>> hashMap;
QByteArray bChainHash;
bool closing;
quint64 spIndex;
qint8 mode;
Server* server;
Client client;
//returns most common hash (or none if blockchain is already up to date / no connections available)
QByteArray checkForUpdates();
bool removeConnectection(const QString& ip, quint16 port);
};
#endif // MAINWINDOW_H