1 | /* $Id: UINetworkManager.h 78665 2019-05-22 15:27:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UINetworkManager stuff declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef FEQT_INCLUDED_SRC_net_UINetworkManager_h
|
---|
19 | #define FEQT_INCLUDED_SRC_net_UINetworkManager_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QObject>
|
---|
26 | #include <QUuid>
|
---|
27 |
|
---|
28 | /* GUI inludes: */
|
---|
29 | #include "UILibraryDefs.h"
|
---|
30 | #include "UINetworkDefs.h"
|
---|
31 |
|
---|
32 | /* Forward declarations: */
|
---|
33 | class QUrl;
|
---|
34 | class QWidget;
|
---|
35 | class UINetworkCustomer;
|
---|
36 | class UINetworkManagerDialog;
|
---|
37 | class UINetworkManagerIndicator;
|
---|
38 | class UINetworkRequest;
|
---|
39 |
|
---|
40 | /** QObject class extension.
|
---|
41 | * Providing network access for VirtualBox application purposes. */
|
---|
42 | class SHARED_LIBRARY_STUFF UINetworkManager : public QObject
|
---|
43 | {
|
---|
44 | Q_OBJECT;
|
---|
45 |
|
---|
46 | signals:
|
---|
47 |
|
---|
48 | /** Asks listeners (network-requests) to cancel. */
|
---|
49 | void sigCancelNetworkRequests();
|
---|
50 |
|
---|
51 | /** Requests to add @a pNetworkRequest to network-manager state-indicators. */
|
---|
52 | void sigAddNetworkManagerIndicatorDescription(UINetworkRequest *pNetworkRequest);
|
---|
53 | /** Requests to remove network-request with @a uuid from network-manager state-indicators. */
|
---|
54 | void sigRemoveNetworkManagerIndicatorDescription(const QUuid &uuid);
|
---|
55 |
|
---|
56 | public:
|
---|
57 |
|
---|
58 | /** Creates singleton instance. */
|
---|
59 | static void create();
|
---|
60 | /** Destroys singleton instance. */
|
---|
61 | static void destroy();
|
---|
62 |
|
---|
63 | /** Returns the singleton instance. */
|
---|
64 | static UINetworkManager *instance() { return s_pInstance; }
|
---|
65 |
|
---|
66 | /** Returns pointer to network-manager dialog. */
|
---|
67 | UINetworkManagerDialog *window() const;
|
---|
68 |
|
---|
69 | /** Creates network-manager state-indicator.
|
---|
70 | * @remarks To be cleaned up by the caller. */
|
---|
71 | UINetworkManagerIndicator *createIndicator() const;
|
---|
72 |
|
---|
73 | /** Registers @a pNetworkRequest in network-manager. */
|
---|
74 | void registerNetworkRequest(UINetworkRequest *pNetworkRequest);
|
---|
75 | /** Unregisters network-request with @a uuid from network-manager. */
|
---|
76 | void unregisterNetworkRequest(const QUuid &uuid);
|
---|
77 |
|
---|
78 | public slots:
|
---|
79 |
|
---|
80 | /** Shows network-manager dialog. */
|
---|
81 | void show();
|
---|
82 |
|
---|
83 | protected:
|
---|
84 |
|
---|
85 | /** Allows UINetworkCustomer to create network-request. */
|
---|
86 | friend class UINetworkCustomer;
|
---|
87 |
|
---|
88 | /** Creates network-request of the passed @a type
|
---|
89 | * on the basis of the passed @a urls, @a strTarget and the @a requestHeaders for the @a pCustomer specified. */
|
---|
90 | void createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> &urls, const QString &strTarget,
|
---|
91 | const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer);
|
---|
92 |
|
---|
93 | private:
|
---|
94 |
|
---|
95 | /** Constructs network manager. */
|
---|
96 | UINetworkManager();
|
---|
97 | /** Destructs network manager. */
|
---|
98 | ~UINetworkManager();
|
---|
99 |
|
---|
100 | /** Prepares all. */
|
---|
101 | void prepare();
|
---|
102 | /** Cleanups all. */
|
---|
103 | void cleanup();
|
---|
104 |
|
---|
105 | /** Prepares @a pNetworkRequest. */
|
---|
106 | void prepareNetworkRequest(UINetworkRequest *pNetworkRequest);
|
---|
107 | /** Cleanups network-request with passed @a uuid. */
|
---|
108 | void cleanupNetworkRequest(QUuid uuid);
|
---|
109 | /** Cleanups all network-requests. */
|
---|
110 | void cleanupNetworkRequests();
|
---|
111 |
|
---|
112 | private slots:
|
---|
113 |
|
---|
114 | /** Handles progress for @a iReceived amount of bytes among @a iTotal for request specified by @a uuid. */
|
---|
115 | void sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
|
---|
116 | /** Handles canceling of request specified by @a uuid. */
|
---|
117 | void sltHandleNetworkRequestCancel(const QUuid &uuid);
|
---|
118 | /** Handles finishing of request specified by @a uuid. */
|
---|
119 | void sltHandleNetworkRequestFinish(const QUuid &uuid);
|
---|
120 | /** Handles @a strError of request specified by @a uuid. */
|
---|
121 | void sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &strError);
|
---|
122 |
|
---|
123 | private:
|
---|
124 |
|
---|
125 | /** Holds the singleton instance. */
|
---|
126 | static UINetworkManager *s_pInstance;
|
---|
127 |
|
---|
128 | /** Holds the map of current requests. */
|
---|
129 | QMap<QUuid, UINetworkRequest*> m_requests;
|
---|
130 |
|
---|
131 | /** Holds the network manager dialog instance. */
|
---|
132 | UINetworkManagerDialog *m_pNetworkManagerDialog;
|
---|
133 | };
|
---|
134 |
|
---|
135 | /** Singleton Network Manager 'official' name. */
|
---|
136 | #define gNetworkManager UINetworkManager::instance()
|
---|
137 |
|
---|
138 | #endif /* !FEQT_INCLUDED_SRC_net_UINetworkManager_h */
|
---|
139 |
|
---|