-
Notifications
You must be signed in to change notification settings - Fork 15
/
mainwindow.h
executable file
·248 lines (183 loc) · 8.9 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
*
Copyright (C) 2017-2019 Fábio Bento (fabiobento512)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QProgressBar>
#include <QToolButton>
#include <QLabel>
#include <pugixml/pugixml.hpp>
#include <ConditionalSemaphore/conditionalsemaphore.h>
#include "projectproperties.h"
#include "updatechecker.h"
#include "SyntaxHighlighters/frequestjsonhighlighter.h"
#include "SyntaxHighlighters/frequestxmlhighlighter.h"
#include "XmlParsers/projectfilefrequest.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void applicationHasLoaded();
void saveProjectProperties();
void treeWidgetDeleteKeyPressed();
void on_pbSendRequest_clicked();
void on_lePath_textChanged(const QString &arg1);
void replyFinished(QNetworkReply *reply);
void on_treeWidget_customContextMenuRequested(const QPoint &pos);
void on_treeWidget_itemChanged(QTreeWidgetItem *item, int column);
void on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_actionSave_Project_triggered();
void on_actionNew_Project_triggered();
void on_actionSave_Project_As_triggered();
void on_actionLoad_Project_triggered();
void on_actionExit_triggered();
void on_actionAbout_triggered();
void on_actionProject1_triggered();
void on_actionProject2_triggered();
void on_actionProject3_triggered();
void on_actionProject4_triggered();
void on_actionProject5_triggered();
void on_actionProject6_triggered();
void on_cbResponseChooseHeader_currentIndexChanged(const QString &arg1);
void on_tbRequestBodyKeyValueAdd_clicked();
void on_twRequestBodyKeyValue_cellChanged(int row, int column);
void on_cbBodyType_currentIndexChanged(const QString &arg1);
void on_tbRequestBodyKeyValueRemove_clicked();
void on_tbRequestHeadersKeyValueAdd_clicked();
void on_tbRequestHeadersKeyValueRemove_clicked();
void on_twRequestHeadersKeyValue_cellChanged(int row, int column);
void on_cbRequestOverrideMainUrl_toggled(bool checked);
void on_leRequestOverrideMainUrl_textChanged(const QString &arg1);
void on_pteRequestBody_textChanged();
void on_cbDownloadResponseAsFile_toggled(bool checked);
void on_tbCopyToClipboardRequest_clicked();
void on_tbCopyToClipboardResponse_clicked();
void on_actionPreferences_triggered();
void saveCurrentSettings();
void on_cbRequestType_currentIndexChanged(const QString &arg1);
void on_actionFormat_Response_Body_triggered();
void on_actionFormat_Request_body_triggered();
void on_tbRequestBodyFile_clicked();
void tbAbortRequest_clicked();
void on_actionShow_Request_Types_Icons_triggered(bool checked);
void on_leRequestsFilter_textChanged(const QString &arg1);
void on_actionProject_Properties_triggered();
void on_actionCheck_for_updates_triggered();
void on_cbDisableGlobalHeaders_toggled(bool checked);
void on_twRequestHeadersKeyValue_currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
signals:
void signalAppIsLoaded();
void signalRequestFinishedAndProcessed();
private:
void showEvent(QShowEvent *e);
void checkForQNetworkAccessManagerTimeout(QNetworkReply *reply);
QNetworkReply* processHttpRequest(
const UtilFRequest::RequestType requestType,
const QString &fullPath,
const QString &bodyType,
const QString &requestBody,
const QVector<UtilFRequest::HttpHeader>& requestHeaders
);
QString getDownloadFileName(const QNetworkReply * const reply);
void updateWindowTitle();
void setNewProject();
void saveProjectState(const QString &filePath);
void loadProjectState(const QString &filePath);
void updateTreeWidgetItemContent(FRequestTreeWidgetRequestItem * const requestItem);
void reloadRequest(FRequestTreeWidgetRequestItem * const item);
FRequestTreeWidgetProjectItem *addProjectItem(const QString &projectName, const QString &projectUuid);
FRequestTreeWidgetRequestItem *addRequestItem(const QString &requestName, const QString &projectUuid, FRequestTreeWidgetProjectItem * const currentProject);
void closeEvent(QCloseEvent *event);
void loadRecentProjects();
void addNewRecentProject(const QString &filePath);
void reloadRecentProjectsMenu();
void saveRecentProjects();
QVector<UtilFRequest::HttpHeader> getRequestHeaders();
QVector<UtilFRequest::HttpFormKeyValueType> getRequestForm();
void buildFullPath();
void setProjectHasChanged();
QMessageBox::StandardButton askToSaveCurrentProject();
void clearOlderResponse();
void clearRequestAndResponse();
void clearEverything();
void addDefaultHeaders();
void setRequestType(UtilFRequest::RequestType requestType);
void formatRequestBody(const UtilFRequest::SerializationFormatType serializationType);
void formatResponseBody(const UtilFRequest::SerializationFormatType serializationType);
bool loadAndValidateFRequestProjectFile(const QString &filePath, pugi::xml_document &doc);
void setIconForRequest(FRequestTreeWidgetRequestItem * const item);
void setAllRequestIcons(bool showIcon);
ProjectFileFRequest::ProjectData fetchCurrentProjectData();
bool formKeyValueInBodyIsValid();
bool formKeyValueInBodyHasFiles();
bool noDuplicatedKeyExistsInRequestHeaders(const QVector<UtilFRequest::HttpHeader> &headers);
void removeAllFilesRowsFromFormKeyValueInBody();
UtilFRequest::SerializationFormatType getRequestCurrentSerializationFormatType();
UtilFRequest::SerializationFormatType getResponseCurrentSerializationFormatType();
QString getNewUuid();
QString getFullPathFromMainUrlAndPath(const QString & mainUrl, const QString & path);
void applyRequestAuthentication();
void openProjectProperties();
void removeRequest(FRequestTreeWidgetRequestItem * const itemToDelete);
void setThemePaletteForCustomWidgets();
void setFilterThemePalette();
void setTheme();
void downloadResponseAsFile(QNetworkReply *reply, QByteArray &totalLoadedData, QByteArray ¤tData, const int maxBytesForBufferAndDisplay);
void addGlobalHeaders();
public:
static constexpr int recentProjectsMaxSize=6;
private:
Ui::MainWindow *ui;
QDateTime lastStartTime;
FRequestTreeWidgetProjectItem *currentProjectItem = nullptr;
FRequestTreeWidgetRequestItem *currentItem = nullptr;
QSet<QString> uuidsInUse;
QVector<QString> uuidsToCleanUp; // this vector stores the uuids of deleted items in the application, its used to clean them in the project file
bool applicationIsFullyLoaded = false;
bool unsavedChangesExist = false;
// This conditional semaphore allow us to tell to the interface to ignore changes (not mark project as unsaved) within some time interval
Cosemaphore::ConditionalSemaphore ignoreAnyChangesToProject;
QString lastProjectFilePath;
QList<QString> recentProjectsList;
QString lastResponseFileName;
int lastReplyStatusError = 0;
ConfigFileFRequest configFileManager = ConfigFileFRequest(Util::FileSystem::getAppPath() + "/" + GlobalVars::AppConfigFileName);
ConfigFileFRequest::Settings currentSettings;
const QSize auxMinimumSize = QSize(0,0);
const QSize auxMaximumSize = QSize(16777215,16777215);
QProgressBar pbRequestProgress;
QToolButton tbAbortRequest;
QLabel lbRequestInfo;
QLabel lbProjectInfo;
std::experimental::optional<QNetworkReply*> currentReply;
QMap<UtilFRequest::RequestType, QIcon> generatedIconCache;
QNetworkAccessManager networkAccessManager;
const QString operatingSystemDefaultStyle;
// Requests Highlighters
FRequestJSONHighlighter jsonRequestBodyHighligher;
FRequestJSONHighlighter jsonResponseBodyHighligher;
FRequestXMLHighlighter xmlRequestBodyHighligher;
FRequestXMLHighlighter xmlResponseBodyHighligher;
bool currentProjectAuthenticationWasMade = false;
bool authenticationIsRunning = false;
};
#endif // MAINWINDOW_H