VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/UIToolPaneGlobal.cpp

Last change on this file was 106061, checked in by vboxsync, 7 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
Line 
1/* $Id: UIToolPaneGlobal.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIToolPaneGlobal class implementation.
4 */
5
6/*
7 * Copyright (C) 2017-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/* Qt includes: */
29#include <QApplication>
30#include <QStackedLayout>
31#ifndef VBOX_WS_MAC
32# include <QStyle>
33#endif
34#include <QUuid>
35
36/* GUI includes */
37#include "UIActionPoolManager.h"
38#include "UICommon.h"
39#include "UICloudProfileManager.h"
40#include "UIExtensionPackManager.h"
41#include "UIMediumManager.h"
42#include "UINetworkManager.h"
43#include "UIToolPaneGlobal.h"
44#include "UIVMActivityOverviewWidget.h"
45#include "UIWelcomePane.h"
46
47/* Other VBox includes: */
48#include <iprt/assert.h>
49
50
51UIToolPaneGlobal::UIToolPaneGlobal(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
52 : QWidget(pParent)
53 , m_pActionPool(pActionPool)
54 , m_pLayout(0)
55 , m_pPaneWelcome(0)
56 , m_pPaneExtensions(0)
57 , m_pPaneMedia(0)
58 , m_pPaneNetwork(0)
59 , m_pPaneCloud(0)
60 , m_pPaneVMActivityOverview(0)
61 , m_fActive(false)
62{
63 /* Prepare: */
64 prepare();
65}
66
67UIToolPaneGlobal::~UIToolPaneGlobal()
68{
69 /* Cleanup: */
70 cleanup();
71}
72
73void UIToolPaneGlobal::setActive(bool fActive)
74{
75 /* Save activity: */
76 if (m_fActive != fActive)
77 {
78 m_fActive = fActive;
79
80 /* Handle token change: */
81 handleTokenChange();
82 }
83}
84
85UIToolType UIToolPaneGlobal::currentTool() const
86{
87 return m_pLayout && m_pLayout->currentWidget()
88 ? m_pLayout->currentWidget()->property("ToolType").value<UIToolType>()
89 : UIToolType_Invalid;
90}
91
92bool UIToolPaneGlobal::isToolOpened(UIToolType enmType) const
93{
94 /* Search through the stacked widgets: */
95 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
96 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
97 return true;
98 return false;
99}
100
101void UIToolPaneGlobal::openTool(UIToolType enmType)
102{
103 /* Search through the stacked widgets: */
104 int iActualIndex = -1;
105 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
106 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
107 iActualIndex = iIndex;
108
109 /* If widget with such type exists: */
110 if (iActualIndex != -1)
111 {
112 /* Activate corresponding index: */
113 m_pLayout->setCurrentIndex(iActualIndex);
114 }
115 /* Otherwise: */
116 else
117 {
118 /* Create, remember, append corresponding stacked widget: */
119 switch (enmType)
120 {
121 case UIToolType_Welcome:
122 {
123 /* Create Desktop pane: */
124 m_pPaneWelcome = new UIWelcomePane;
125 if (m_pPaneWelcome)
126 {
127 /* Configure pane: */
128 m_pPaneWelcome->setProperty("ToolType", QVariant::fromValue(UIToolType_Welcome));
129
130 /* Add into layout: */
131 m_pLayout->addWidget(m_pPaneWelcome);
132 m_pLayout->setCurrentWidget(m_pPaneWelcome);
133 }
134 break;
135 }
136 case UIToolType_Extensions:
137 {
138 /* Create Extension Pack Manager: */
139 m_pPaneExtensions = new UIExtensionPackManagerWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
140 AssertPtrReturnVoid(m_pPaneExtensions);
141 {
142#ifndef VBOX_WS_MAC
143 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
144 m_pPaneExtensions->setContentsMargins(iMargin, 0, iMargin, 0);
145#endif
146
147 /* Configure pane: */
148 m_pPaneExtensions->setProperty("ToolType", QVariant::fromValue(UIToolType_Extensions));
149
150 /* Add into layout: */
151 m_pLayout->addWidget(m_pPaneExtensions);
152 m_pLayout->setCurrentWidget(m_pPaneExtensions);
153 }
154 break;
155 }
156 case UIToolType_Media:
157 {
158 /* Create Virtual Media Manager: */
159 m_pPaneMedia = new UIMediumManagerWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
160 AssertPtrReturnVoid(m_pPaneMedia);
161 {
162#ifndef VBOX_WS_MAC
163 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
164 m_pPaneMedia->setContentsMargins(iMargin, 0, iMargin, 0);
165#endif
166
167 /* Configure pane: */
168 m_pPaneMedia->setProperty("ToolType", QVariant::fromValue(UIToolType_Media));
169 connect(m_pPaneMedia, &UIMediumManagerWidget::sigCreateMedium,
170 this, &UIToolPaneGlobal::sigCreateMedium);
171 connect(m_pPaneMedia, &UIMediumManagerWidget::sigCopyMedium,
172 this, &UIToolPaneGlobal::sigCopyMedium);
173
174 /* Add into layout: */
175 m_pLayout->addWidget(m_pPaneMedia);
176 m_pLayout->setCurrentWidget(m_pPaneMedia);
177 }
178 break;
179 }
180 case UIToolType_Network:
181 {
182 /* Create Network Manager: */
183 m_pPaneNetwork = new UINetworkManagerWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
184 AssertPtrReturnVoid(m_pPaneNetwork);
185 {
186#ifndef VBOX_WS_MAC
187 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
188 m_pPaneNetwork->setContentsMargins(iMargin, 0, iMargin, 0);
189#endif
190
191 /* Configure pane: */
192 m_pPaneNetwork->setProperty("ToolType", QVariant::fromValue(UIToolType_Network));
193
194 /* Add into layout: */
195 m_pLayout->addWidget(m_pPaneNetwork);
196 m_pLayout->setCurrentWidget(m_pPaneNetwork);
197 }
198 break;
199 }
200 case UIToolType_Cloud:
201 {
202 /* Create Cloud Profile Manager: */
203 m_pPaneCloud = new UICloudProfileManagerWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
204 AssertPtrReturnVoid(m_pPaneCloud);
205 {
206#ifndef VBOX_WS_MAC
207 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
208 m_pPaneCloud->setContentsMargins(iMargin, 0, iMargin, 0);
209#endif
210
211 /* Configure pane: */
212 m_pPaneCloud->setProperty("ToolType", QVariant::fromValue(UIToolType_Cloud));
213
214 /* Add into layout: */
215 m_pLayout->addWidget(m_pPaneCloud);
216 m_pLayout->setCurrentWidget(m_pPaneCloud);
217 }
218 break;
219 }
220 case UIToolType_VMActivityOverview:
221 {
222 /* Create VM Activity Overview: */
223 m_pPaneVMActivityOverview = new UIVMActivityOverviewWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
224 AssertPtrReturnVoid(m_pPaneVMActivityOverview);
225 {
226#ifndef VBOX_WS_MAC
227 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
228 m_pPaneVMActivityOverview->setContentsMargins(iMargin, 0, iMargin, 0);
229#endif
230
231 /* Configure pane: */
232 m_pPaneVMActivityOverview->setProperty("ToolType", QVariant::fromValue(UIToolType_VMActivityOverview));
233 connect(m_pPaneVMActivityOverview, &UIVMActivityOverviewWidget::sigSwitchToMachineActivityPane,
234 this, &UIToolPaneGlobal::sigSwitchToMachineActivityPane);
235 m_pPaneVMActivityOverview->setCloudMachineItems(m_cloudItems);
236
237 /* Add into layout: */
238 m_pLayout->addWidget(m_pPaneVMActivityOverview);
239 m_pLayout->setCurrentWidget(m_pPaneVMActivityOverview);
240 }
241
242 break;
243 }
244 default:
245 AssertFailedReturnVoid();
246 }
247 }
248
249 /* Handle token change: */
250 handleTokenChange();
251}
252
253void UIToolPaneGlobal::closeTool(UIToolType enmType)
254{
255 /* Search through the stacked widgets: */
256 int iActualIndex = -1;
257 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
258 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
259 iActualIndex = iIndex;
260
261 /* If widget with such type doesn't exist: */
262 if (iActualIndex != -1)
263 {
264 /* Forget corresponding widget: */
265 switch (enmType)
266 {
267 case UIToolType_Welcome: m_pPaneWelcome = 0; break;
268 case UIToolType_Extensions: m_pPaneExtensions = 0; break;
269 case UIToolType_Media: m_pPaneMedia = 0; break;
270 case UIToolType_Network: m_pPaneNetwork = 0; break;
271 case UIToolType_Cloud: m_pPaneCloud = 0; break;
272 case UIToolType_VMActivityOverview: m_pPaneVMActivityOverview = 0; break;
273 default: break;
274 }
275 /* Delete corresponding widget: */
276 QWidget *pWidget = m_pLayout->widget(iActualIndex);
277 m_pLayout->removeWidget(pWidget);
278 delete pWidget;
279 }
280
281 /* Handle token change: */
282 handleTokenChange();
283}
284
285QString UIToolPaneGlobal::currentHelpKeyword() const
286{
287 QWidget *pCurrentToolWidget = 0;
288 //UIToolType currentTool() const;
289 switch (currentTool())
290 {
291 case UIToolType_Welcome:
292 pCurrentToolWidget = m_pPaneWelcome;
293 break;
294 case UIToolType_Extensions:
295 pCurrentToolWidget = m_pPaneExtensions;
296 break;
297 case UIToolType_Media:
298 pCurrentToolWidget = m_pPaneMedia;
299 break;
300 case UIToolType_Network:
301 pCurrentToolWidget = m_pPaneNetwork;
302 break;
303 case UIToolType_Cloud:
304 pCurrentToolWidget = m_pPaneCloud;
305 break;
306 case UIToolType_VMActivityOverview:
307 pCurrentToolWidget = m_pPaneVMActivityOverview;
308 break;
309 default:
310 break;
311 }
312 return uiCommon().helpKeyword(pCurrentToolWidget);
313}
314
315void UIToolPaneGlobal::setCloudMachineItems(const QList<UIVirtualMachineItemCloud*> &cloudItems)
316{
317 /* Cache passed value: */
318 m_cloudItems = cloudItems;
319
320 /* Update activity overview pane if open: */
321 if (isToolOpened(UIToolType_VMActivityOverview))
322 {
323 AssertPtrReturnVoid(m_pPaneVMActivityOverview);
324 m_pPaneVMActivityOverview->setCloudMachineItems(m_cloudItems);
325 }
326}
327
328void UIToolPaneGlobal::prepare()
329{
330 /* Create stacked-layout: */
331 m_pLayout = new QStackedLayout(this);
332
333 /* Create desktop pane: */
334 openTool(UIToolType_Welcome);
335}
336
337void UIToolPaneGlobal::cleanup()
338{
339 /* Remove all widgets prematurelly: */
340 while (m_pLayout->count())
341 {
342 QWidget *pWidget = m_pLayout->widget(0);
343 m_pLayout->removeWidget(pWidget);
344 delete pWidget;
345 }
346}
347
348void UIToolPaneGlobal::handleTokenChange()
349{
350 /* Determine whether resource monitor is currently active tool: */
351 if (m_pPaneVMActivityOverview)
352 m_pPaneVMActivityOverview->setIsCurrentTool(m_fActive && currentTool() == UIToolType_VMActivityOverview);
353}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette