1 | /* $Id: UINetworkRequest.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UINetworkRequest class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_networking_UINetworkRequest_h
|
---|
29 | #define FEQT_INCLUDED_SRC_networking_UINetworkRequest_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QObject>
|
---|
36 | #include <QPointer>
|
---|
37 |
|
---|
38 | /* GUI inludes: */
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 | #include "UINetworkDefs.h"
|
---|
41 | #include "UINetworkReply.h"
|
---|
42 |
|
---|
43 | /** QObject extension used as network-request container. */
|
---|
44 | class SHARED_LIBRARY_STUFF UINetworkRequest : public QObject
|
---|
45 | {
|
---|
46 | Q_OBJECT;
|
---|
47 |
|
---|
48 | signals:
|
---|
49 |
|
---|
50 | /** Notifies listener about progress started. */
|
---|
51 | void sigStarted();
|
---|
52 | /** Notifies listener about progress changed.
|
---|
53 | * @param iReceived Brings the amount of bytes received.
|
---|
54 | * @param iTotal Brings the amount of total bytes to receive. */
|
---|
55 | void sigProgress(qint64 iReceived, qint64 iTotal);
|
---|
56 | /** Notifies listener about progress failed.
|
---|
57 | * @param strError Brings the error progress failed with. */
|
---|
58 | void sigFailed(const QString &strError);
|
---|
59 | /** Notifies listener about progress canceled. */
|
---|
60 | void sigCanceled();
|
---|
61 | /** Notifies listener about progress finished. */
|
---|
62 | void sigFinished();
|
---|
63 |
|
---|
64 | public:
|
---|
65 |
|
---|
66 | /** Constructs network-request.
|
---|
67 | * @param enmType Brings request type.
|
---|
68 | * @param urls Brings request urls, there can be few of them.
|
---|
69 | * @param strTarget Brings request target path.
|
---|
70 | * @param requestHeaders Brings request headers in dictionary form. */
|
---|
71 | UINetworkRequest(UINetworkRequestType enmType,
|
---|
72 | const QList<QUrl> &urls,
|
---|
73 | const QString &strTarget,
|
---|
74 | const UserDictionary &requestHeaders);
|
---|
75 | /** Destructs network-request. */
|
---|
76 | virtual ~UINetworkRequest() /* override final */;
|
---|
77 |
|
---|
78 | /** Returns the request reply. */
|
---|
79 | UINetworkReply *reply() { return m_pReply; }
|
---|
80 |
|
---|
81 | public slots:
|
---|
82 |
|
---|
83 | /** Initiates request cancelling. */
|
---|
84 | void sltCancel();
|
---|
85 |
|
---|
86 | private slots:
|
---|
87 |
|
---|
88 | /** Handles reply about progress changed.
|
---|
89 | * @param iReceived Brings the amount of bytes received.
|
---|
90 | * @param iTotal Brings the amount of total bytes to receive. */
|
---|
91 | void sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal);
|
---|
92 | /** Handles reply about progress finished. */
|
---|
93 | void sltHandleNetworkReplyFinish();
|
---|
94 |
|
---|
95 | private:
|
---|
96 |
|
---|
97 | /** Prepares request. */
|
---|
98 | void prepare();
|
---|
99 | /** Prepares request's reply. */
|
---|
100 | void prepareNetworkReply();
|
---|
101 |
|
---|
102 | /** Cleanups request's reply. */
|
---|
103 | void cleanupNetworkReply();
|
---|
104 | /** Cleanups request. */
|
---|
105 | void cleanup();
|
---|
106 |
|
---|
107 | /** Holds the request type. */
|
---|
108 | const UINetworkRequestType m_enmType;
|
---|
109 | /** Holds the request urls. */
|
---|
110 | const QList<QUrl> m_urls;
|
---|
111 | /** Holds the request target. */
|
---|
112 | const QString m_strTarget;
|
---|
113 | /** Holds the request headers. */
|
---|
114 | const UserDictionary m_requestHeaders;
|
---|
115 |
|
---|
116 | /** Holds current request url. */
|
---|
117 | QUrl m_url;
|
---|
118 | /** Holds index of current request url. */
|
---|
119 | int m_iUrlIndex;
|
---|
120 | /** Holds whether current request url is in progress. */
|
---|
121 | bool m_fRunning;
|
---|
122 |
|
---|
123 | /** Holds the request reply. */
|
---|
124 | QPointer<UINetworkReply> m_pReply;
|
---|
125 | };
|
---|
126 |
|
---|
127 | #endif /* !FEQT_INCLUDED_SRC_networking_UINetworkRequest_h */
|
---|