1 | /* $Id: UINetworkManager.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UINetworkManager class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2024 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_networkmanager_UINetworkManager_h
|
---|
29 | #define FEQT_INCLUDED_SRC_networkmanager_UINetworkManager_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QMainWindow>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "QIManagerDialog.h"
|
---|
39 |
|
---|
40 | /* Forward declarations: */
|
---|
41 | class CCloudNetwork;
|
---|
42 | #ifdef VBOX_WS_MAC
|
---|
43 | class CHostOnlyNetwork;
|
---|
44 | #else
|
---|
45 | class CHostNetworkInterface;
|
---|
46 | #endif
|
---|
47 | class CNATNetwork;
|
---|
48 | class QAbstractButton;
|
---|
49 | class QTreeWidgetItem;
|
---|
50 | class QVBoxLayout;
|
---|
51 | class QIDialogButtonBox;
|
---|
52 | class QITabWidget;
|
---|
53 | class QITreeWidget;
|
---|
54 | class UIActionPool;
|
---|
55 | class UIDetailsWidgetCloudNetwork;
|
---|
56 | class UIDetailsWidgetHostNetwork;
|
---|
57 | class UIDetailsWidgetNATNetwork;
|
---|
58 | class UIItemCloudNetwork;
|
---|
59 | class UIItemHostNetwork;
|
---|
60 | class UIItemNATNetwork;
|
---|
61 | class QIToolBar;
|
---|
62 | struct UIDataCloudNetwork;
|
---|
63 | struct UIDataHostNetwork;
|
---|
64 | struct UIDataNATNetwork;
|
---|
65 |
|
---|
66 |
|
---|
67 | /** QWidget extension providing GUI with the pane to control network related functionality. */
|
---|
68 | class UINetworkManagerWidget : public QWidget
|
---|
69 | {
|
---|
70 | Q_OBJECT;
|
---|
71 |
|
---|
72 | signals:
|
---|
73 |
|
---|
74 | /** Notifies listeners about details-widget @a fVisible. */
|
---|
75 | void sigDetailsVisibilityChanged(bool fVisible);
|
---|
76 |
|
---|
77 | /** Notifies listeners about host network details data @a fDiffers. */
|
---|
78 | void sigDetailsDataChangedHostNetwork(bool fDiffers);
|
---|
79 | /** Notifies listeners about NAT network details data @a fDiffers. */
|
---|
80 | void sigDetailsDataChangedNATNetwork(bool fDiffers);
|
---|
81 | /** Notifies listeners about cloud network details data @a fDiffers. */
|
---|
82 | void sigDetailsDataChangedCloudNetwork(bool fDiffers);
|
---|
83 |
|
---|
84 | public:
|
---|
85 |
|
---|
86 | /** Constructs Network Manager widget.
|
---|
87 | * @param enmEmbedding Brings the type of widget embedding.
|
---|
88 | * @param pActionPool Brings the action-pool reference.
|
---|
89 | * @param fShowToolbar Brings whether we should create/show toolbar. */
|
---|
90 | UINetworkManagerWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool,
|
---|
91 | bool fShowToolbar = true, QWidget *pParent = 0);
|
---|
92 |
|
---|
93 | /** Returns the menu. */
|
---|
94 | QMenu *menu() const;
|
---|
95 |
|
---|
96 | #ifdef VBOX_WS_MAC
|
---|
97 | /** Returns the toolbar. */
|
---|
98 | QIToolBar *toolbar() const { return m_pToolBar; }
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | protected:
|
---|
102 |
|
---|
103 | /** @name Event-handling stuff.
|
---|
104 | * @{ */
|
---|
105 | /** Handles resize @a pEvent. */
|
---|
106 | virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
|
---|
107 |
|
---|
108 | /** Handles show @a pEvent. */
|
---|
109 | virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
|
---|
110 | /** @} */
|
---|
111 |
|
---|
112 | public slots:
|
---|
113 |
|
---|
114 | /** @name Details-widget stuff.
|
---|
115 | * @{ */
|
---|
116 | /** Handles command to reset details changes. */
|
---|
117 | void sltResetDetailsChanges();
|
---|
118 | /** Handles command to apply details changes. */
|
---|
119 | void sltApplyDetailsChanges();
|
---|
120 | /** @} */
|
---|
121 |
|
---|
122 | private slots:
|
---|
123 |
|
---|
124 | /** @name Menu/action stuff.
|
---|
125 | * @{ */
|
---|
126 | /** Handles command to create host network. */
|
---|
127 | void sltCreateHostNetwork();
|
---|
128 | #ifndef VBOX_WS_MAC
|
---|
129 | /** Handles signal about host network @a comInterface created. */
|
---|
130 | void sigHandleHostOnlyNetworkInterfaceCreated(const CHostNetworkInterface &comInterface);
|
---|
131 | #endif
|
---|
132 | /** Handles command to remove host network. */
|
---|
133 | void sltRemoveHostNetwork();
|
---|
134 | #ifndef VBOX_WS_MAC
|
---|
135 | /** Handles signal about host network interface by the name of @a strInterfaceName was removed. */
|
---|
136 | void sigHandleHostOnlyNetworkInterfaceRemoved(const QString &strInterfaceName);
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | /** Handles command to create NAT network. */
|
---|
140 | void sltCreateNATNetwork();
|
---|
141 | /** Handles command to remove NAT network. */
|
---|
142 | void sltRemoveNATNetwork();
|
---|
143 |
|
---|
144 | /** Handles command to create cloud network. */
|
---|
145 | void sltCreateCloudNetwork();
|
---|
146 | /** Handles command to remove cloud network. */
|
---|
147 | void sltRemoveCloudNetwork();
|
---|
148 |
|
---|
149 | /** Handles command to make details @a fVisible. */
|
---|
150 | void sltToggleDetailsVisibility(bool fVisible);
|
---|
151 | /** @} */
|
---|
152 |
|
---|
153 | /** @name Tree-widget stuff.
|
---|
154 | * @{ */
|
---|
155 | /** Handles current tab-widget's index change. */
|
---|
156 | void sltHandleCurrentTabWidgetIndexChange();
|
---|
157 |
|
---|
158 | /** Handles command to adjust tree-widget. */
|
---|
159 | void sltAdjustTreeWidgets();
|
---|
160 |
|
---|
161 | /** Handles host network tree-widget current item change. */
|
---|
162 | void sltHandleCurrentItemChangeHostNetwork();
|
---|
163 | /** Handles host network context-menu request for tree-widget @a position. */
|
---|
164 | void sltHandleContextMenuRequestHostNetwork(const QPoint &position);
|
---|
165 | /** Handles command to apply host network details changes. */
|
---|
166 | void sltApplyDetailsChangesHostNetwork();
|
---|
167 |
|
---|
168 | /** Handles NAT network tree-widget current item change.
|
---|
169 | * @param fHoldPosition Holds whether we should try to keep
|
---|
170 | * port forwarding rule position intact. */
|
---|
171 | void sltHandleCurrentItemChangeNATNetworkHoldingPosition(bool fHoldPosition);
|
---|
172 | /** Handles NAT network tree-widget current item change. */
|
---|
173 | void sltHandleCurrentItemChangeNATNetwork();
|
---|
174 | /** Handles NAT network context-menu request for tree-widget @a position. */
|
---|
175 | void sltHandleContextMenuRequestNATNetwork(const QPoint &position);
|
---|
176 | /** Handles command to apply NAT network details changes. */
|
---|
177 | void sltApplyDetailsChangesNATNetwork();
|
---|
178 |
|
---|
179 | /** Handles cloud network tree-widget current item change. */
|
---|
180 | void sltHandleCurrentItemChangeCloudNetwork();
|
---|
181 | /** Handles cloud network context-menu request for tree-widget @a position. */
|
---|
182 | void sltHandleContextMenuRequestCloudNetwork(const QPoint &position);
|
---|
183 | /** Handles command to apply cloud network details changes. */
|
---|
184 | void sltApplyDetailsChangesCloudNetwork();
|
---|
185 | /** @} */
|
---|
186 |
|
---|
187 | /** @name Event-handling stuff.
|
---|
188 | * @{ */
|
---|
189 | /** Handles translation event. */
|
---|
190 | void sltRetranslateUI();
|
---|
191 | /** @} */
|
---|
192 |
|
---|
193 | private:
|
---|
194 |
|
---|
195 | /** @name Prepare/cleanup cascade.
|
---|
196 | * @{ */
|
---|
197 | /** Prepares all. */
|
---|
198 | void prepare();
|
---|
199 | /** Prepares actions. */
|
---|
200 | void prepareActions();
|
---|
201 | /** Prepares widgets. */
|
---|
202 | void prepareWidgets();
|
---|
203 | /** Prepares toolbar. */
|
---|
204 | void prepareToolBar();
|
---|
205 | /** Prepares tab-widget. */
|
---|
206 | void prepareTabWidget();
|
---|
207 | /** Prepares host network tab. */
|
---|
208 | void prepareTabHostNetwork();
|
---|
209 | /** Prepares host network tree-widget. */
|
---|
210 | void prepareTreeWidgetHostNetwork();
|
---|
211 | /** Prepares host network details-widget. */
|
---|
212 | void prepareDetailsWidgetHostNetwork();
|
---|
213 | /** Prepares NAT network tab. */
|
---|
214 | void prepareTabNATNetwork();
|
---|
215 | /** Prepares NAT network tree-widget. */
|
---|
216 | void prepareTreeWidgetNATNetwork();
|
---|
217 | /** Prepares NAT network details-widget. */
|
---|
218 | void prepareDetailsWidgetNATNetwork();
|
---|
219 | /** Prepares cloud network tab. */
|
---|
220 | void prepareTabCloudNetwork();
|
---|
221 | /** Prepares cloud network tree-widget. */
|
---|
222 | void prepareTreeWidgetCloudNetwork();
|
---|
223 | /** Prepares cloud network details-widget. */
|
---|
224 | void prepareDetailsWidgetCloudNetwork();
|
---|
225 | /** Load settings: */
|
---|
226 | void loadSettings();
|
---|
227 | /** @} */
|
---|
228 |
|
---|
229 | /** @name Loading stuff.
|
---|
230 | * @{ */
|
---|
231 | /** Loads host networks. */
|
---|
232 | void loadHostNetworks();
|
---|
233 | #ifdef VBOX_WS_MAC
|
---|
234 | /** Loads host @a comNetwork data to passed @a data container. */
|
---|
235 | void loadHostNetwork(const CHostOnlyNetwork &comNetwork, UIDataHostNetwork &data);
|
---|
236 | #else
|
---|
237 | /** Loads host @a comInterface data to passed @a data container. */
|
---|
238 | void loadHostNetwork(const CHostNetworkInterface &comInterface, UIDataHostNetwork &data);
|
---|
239 | #endif
|
---|
240 |
|
---|
241 | /** Loads NAT networks. */
|
---|
242 | void loadNATNetworks();
|
---|
243 | /** Loads NAT @a comNetwork data to passed @a data container. */
|
---|
244 | void loadNATNetwork(const CNATNetwork &comNetwork, UIDataNATNetwork &data);
|
---|
245 |
|
---|
246 | /** Loads cloud networks. */
|
---|
247 | void loadCloudNetworks();
|
---|
248 | /** Loads cloud @a comNetwork data to passed @a data container. */
|
---|
249 | void loadCloudNetwork(const CCloudNetwork &comNetwork, UIDataCloudNetwork &data);
|
---|
250 | /** @} */
|
---|
251 |
|
---|
252 | /** @name Actions stuff.
|
---|
253 | * @{ */
|
---|
254 | /** Updates action availability. */
|
---|
255 | void updateActionAvailability();
|
---|
256 | /** @} */
|
---|
257 |
|
---|
258 | /** @name Tree-widget stuff.
|
---|
259 | * @{ */
|
---|
260 | /** Creates a new host network tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */
|
---|
261 | void createItemForHostNetwork(const UIDataHostNetwork &data, bool fChooseItem);
|
---|
262 | /** Updates passed host network tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */
|
---|
263 | void updateItemForHostNetwork(const UIDataHostNetwork &data, bool fChooseItem, UIItemHostNetwork *pItem);
|
---|
264 |
|
---|
265 | /** Creates a new NAT network tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */
|
---|
266 | void createItemForNATNetwork(const UIDataNATNetwork &data, bool fChooseItem);
|
---|
267 | /** Updates passed NAT network tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */
|
---|
268 | void updateItemForNATNetwork(const UIDataNATNetwork &data, bool fChooseItem, UIItemNATNetwork *pItem);
|
---|
269 |
|
---|
270 | /** Creates a new cloud network tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */
|
---|
271 | void createItemForCloudNetwork(const UIDataCloudNetwork &data, bool fChooseItem);
|
---|
272 | /** Updates passed cloud network tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */
|
---|
273 | void updateItemForCloudNetwork(const UIDataCloudNetwork &data, bool fChooseItem, UIItemCloudNetwork *pItem);
|
---|
274 |
|
---|
275 | #ifdef VBOX_WS_MAC
|
---|
276 | /** Returns a list of busy host network names. */
|
---|
277 | QStringList busyNamesHost() const;
|
---|
278 | #endif
|
---|
279 | /** Returns a list of busy NAT network names. */
|
---|
280 | QStringList busyNamesNAT() const;
|
---|
281 | /** Returns a list of busy cloud network names. */
|
---|
282 | QStringList busyNamesCloud() const;
|
---|
283 | /** @} */
|
---|
284 |
|
---|
285 | /** @name General variables.
|
---|
286 | * @{ */
|
---|
287 | /** Holds the widget embedding type. */
|
---|
288 | const EmbedTo m_enmEmbedding;
|
---|
289 | /** Holds the action-pool reference. */
|
---|
290 | UIActionPool *m_pActionPool;
|
---|
291 | /** Holds whether we should create/show toolbar. */
|
---|
292 | const bool m_fShowToolbar;
|
---|
293 | /** @} */
|
---|
294 |
|
---|
295 | /** @name Toolbar and menu variables.
|
---|
296 | * @{ */
|
---|
297 | /** Holds the toolbar instance. */
|
---|
298 | QIToolBar *m_pToolBar;
|
---|
299 | /** @} */
|
---|
300 |
|
---|
301 | /** @name Splitter variables.
|
---|
302 | * @{ */
|
---|
303 | /** Holds the tab-widget instance. */
|
---|
304 | QITabWidget *m_pTabWidget;
|
---|
305 |
|
---|
306 | /** Holds the host network tab. */
|
---|
307 | QWidget *m_pTabHostNetwork;
|
---|
308 | /** Holds the host network layout. */
|
---|
309 | QVBoxLayout *m_pLayoutHostNetwork;
|
---|
310 | /** Holds the host network tree-widget instance. */
|
---|
311 | QITreeWidget *m_pTreeWidgetHostNetwork;
|
---|
312 | /** Holds the host network details-widget instance. */
|
---|
313 | UIDetailsWidgetHostNetwork *m_pDetailsWidgetHostNetwork;
|
---|
314 |
|
---|
315 | /** Holds the NAT network tab. */
|
---|
316 | QWidget *m_pTabNATNetwork;
|
---|
317 | /** Holds the NAT network tab layout. */
|
---|
318 | QVBoxLayout *m_pLayoutNATNetwork;
|
---|
319 | /** Holds the NAT network tree-widget instance. */
|
---|
320 | QITreeWidget *m_pTreeWidgetNATNetwork;
|
---|
321 | /** Holds the NAT network details-widget instance. */
|
---|
322 | UIDetailsWidgetNATNetwork *m_pDetailsWidgetNATNetwork;
|
---|
323 |
|
---|
324 | /** Holds the cloud network tab. */
|
---|
325 | QWidget *m_pTabCloudNetwork;
|
---|
326 | /** Holds the cloud network tab layout. */
|
---|
327 | QVBoxLayout *m_pLayoutCloudNetwork;
|
---|
328 | /** Holds the cloud network tree-widget instance. */
|
---|
329 | QITreeWidget *m_pTreeWidgetCloudNetwork;
|
---|
330 | /** Holds the cloud network details-widget instance. */
|
---|
331 | UIDetailsWidgetCloudNetwork *m_pDetailsWidgetCloudNetwork;
|
---|
332 | /** @} */
|
---|
333 | };
|
---|
334 |
|
---|
335 |
|
---|
336 | /** QIManagerDialogFactory extension used as a factory for Network Manager dialog. */
|
---|
337 | class UINetworkManagerFactory : public QIManagerDialogFactory
|
---|
338 | {
|
---|
339 | public:
|
---|
340 |
|
---|
341 | /** Constructs Media Manager factory acquiring additional arguments.
|
---|
342 | * @param pActionPool Brings the action-pool reference. */
|
---|
343 | UINetworkManagerFactory(UIActionPool *pActionPool = 0);
|
---|
344 |
|
---|
345 | protected:
|
---|
346 |
|
---|
347 | /** Creates derived @a pDialog instance.
|
---|
348 | * @param pCenterWidget Brings the widget reference to center according to. */
|
---|
349 | virtual void create(QIManagerDialog *&pDialog, QWidget *pCenterWidget) RT_OVERRIDE;
|
---|
350 |
|
---|
351 | /** Holds the action-pool reference. */
|
---|
352 | UIActionPool *m_pActionPool;
|
---|
353 | };
|
---|
354 |
|
---|
355 |
|
---|
356 | /** QIManagerDialog extension providing GUI with the dialog to control network related functionality. */
|
---|
357 | class UINetworkManager : public QIManagerDialog
|
---|
358 | {
|
---|
359 | Q_OBJECT;
|
---|
360 |
|
---|
361 | signals:
|
---|
362 |
|
---|
363 | /** Notifies listeners about data change rejected and should be reseted. */
|
---|
364 | void sigDataChangeRejected();
|
---|
365 | /** Notifies listeners about data change accepted and should be applied. */
|
---|
366 | void sigDataChangeAccepted();
|
---|
367 |
|
---|
368 | private slots:
|
---|
369 |
|
---|
370 | /** @name Button-box stuff.
|
---|
371 | * @{ */
|
---|
372 | /** Handles button-box button click. */
|
---|
373 | void sltHandleButtonBoxClick(QAbstractButton *pButton);
|
---|
374 | /** @} */
|
---|
375 |
|
---|
376 | /** @name Event-handling stuff.
|
---|
377 | * @{ */
|
---|
378 | /** Handles translation event. */
|
---|
379 | void sltRetranslateUI();
|
---|
380 | /** @} */
|
---|
381 |
|
---|
382 | private:
|
---|
383 |
|
---|
384 | /** Constructs Network Manager dialog.
|
---|
385 | * @param pCenterWidget Brings the widget reference to center according to.
|
---|
386 | * @param pActionPool Brings the action-pool reference. */
|
---|
387 | UINetworkManager(QWidget *pCenterWidget, UIActionPool *pActionPool);
|
---|
388 |
|
---|
389 | /** @name Prepare/cleanup cascade.
|
---|
390 | * @{ */
|
---|
391 | /** Configures all. */
|
---|
392 | virtual void configure() RT_OVERRIDE;
|
---|
393 | /** Configures central-widget. */
|
---|
394 | virtual void configureCentralWidget() RT_OVERRIDE;
|
---|
395 | /** Configures button-box. */
|
---|
396 | virtual void configureButtonBox() RT_OVERRIDE;
|
---|
397 | /** Perform final preparations. */
|
---|
398 | virtual void finalize() RT_OVERRIDE;
|
---|
399 | /** @} */
|
---|
400 |
|
---|
401 | /** @name Widget stuff.
|
---|
402 | * @{ */
|
---|
403 | /** Returns the widget. */
|
---|
404 | virtual UINetworkManagerWidget *widget() RT_OVERRIDE;
|
---|
405 | /** @} */
|
---|
406 |
|
---|
407 | /** @name Action related variables.
|
---|
408 | * @{ */
|
---|
409 | /** Holds the action-pool reference. */
|
---|
410 | UIActionPool *m_pActionPool;
|
---|
411 | /** @} */
|
---|
412 |
|
---|
413 | /** Allow factory access to private/protected members: */
|
---|
414 | friend class UINetworkManagerFactory;
|
---|
415 | };
|
---|
416 |
|
---|
417 | #endif /* !FEQT_INCLUDED_SRC_networkmanager_UINetworkManager_h */
|
---|