VirtualBox

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

Last change on this file since 103020 was 103020, checked in by vboxsync, 9 months ago

FE/Qt: bugref:10501: Missing part fix for r161204; Passing cloud items through Global tool pone.

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