VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 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
RevLine 
[30868]1/* $Id: UIToolPaneGlobal.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
[382]2/** @file
[73424]3 * VBox Qt GUI - UIToolPaneGlobal class implementation.
[382]4 */
5
6/*
[106061]7 * Copyright (C) 2017-2024 Oracle and/or its affiliates.
[382]8 *
[96407]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
[382]26 */
27
[41587]28/* Qt includes: */
[104393]29#include <QApplication>
[76606]30#include <QStackedLayout>
31#ifndef VBOX_WS_MAC
32# include <QStyle>
33#endif
34#include <QUuid>
[39225]35
[41587]36/* GUI includes */
[76606]37#include "UIActionPoolManager.h"
[87026]38#include "UICommon.h"
[76606]39#include "UICloudProfileManager.h"
[87354]40#include "UIExtensionPackManager.h"
[76606]41#include "UIMediumManager.h"
[86997]42#include "UINetworkManager.h"
[76606]43#include "UIToolPaneGlobal.h"
[88084]44#include "UIVMActivityOverviewWidget.h"
[76606]45#include "UIWelcomePane.h"
[382]46
[41587]47/* Other VBox includes: */
[76606]48#include <iprt/assert.h>
[41587]49
[52730]50
[73424]51UIToolPaneGlobal::UIToolPaneGlobal(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
[74561]52 : QWidget(pParent)
[68175]53 , m_pActionPool(pActionPool)
54 , m_pLayout(0)
[74561]55 , m_pPaneWelcome(0)
[87354]56 , m_pPaneExtensions(0)
[68200]57 , m_pPaneMedia(0)
58 , m_pPaneNetwork(0)
[74870]59 , m_pPaneCloud(0)
[88089]60 , m_pPaneVMActivityOverview(0)
[83482]61 , m_fActive(false)
[39399]62{
[67068]63 /* Prepare: */
64 prepare();
65}
[39399]66
[73424]67UIToolPaneGlobal::~UIToolPaneGlobal()
[67091]68{
69 /* Cleanup: */
70 cleanup();
71}
72
[83482]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
[75016]85UIToolType UIToolPaneGlobal::currentTool() const
[68221]86{
[76771]87 return m_pLayout && m_pLayout->currentWidget()
88 ? m_pLayout->currentWidget()->property("ToolType").value<UIToolType>()
89 : UIToolType_Invalid;
[68221]90}
91
[75016]92bool UIToolPaneGlobal::isToolOpened(UIToolType enmType) const
[67110]93{
[68175]94 /* Search through the stacked widgets: */
95 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
[75016]96 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
[67110]97 return true;
98 return false;
99}
100
[75016]101void UIToolPaneGlobal::openTool(UIToolType enmType)
[67110]102{
[68175]103 /* Search through the stacked widgets: */
104 int iActualIndex = -1;
105 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
[75016]106 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
[68175]107 iActualIndex = iIndex;
[67110]108
[68175]109 /* If widget with such type exists: */
110 if (iActualIndex != -1)
[67068]111 {
[68175]112 /* Activate corresponding index: */
113 m_pLayout->setCurrentIndex(iActualIndex);
[67068]114 }
[68175]115 /* Otherwise: */
116 else
117 {
118 /* Create, remember, append corresponding stacked widget: */
119 switch (enmType)
120 {
[75016]121 case UIToolType_Welcome:
[68175]122 {
123 /* Create Desktop pane: */
[74561]124 m_pPaneWelcome = new UIWelcomePane;
125 if (m_pPaneWelcome)
[68175]126 {
127 /* Configure pane: */
[75016]128 m_pPaneWelcome->setProperty("ToolType", QVariant::fromValue(UIToolType_Welcome));
[39399]129
[68175]130 /* Add into layout: */
[74561]131 m_pLayout->addWidget(m_pPaneWelcome);
132 m_pLayout->setCurrentWidget(m_pPaneWelcome);
[68175]133 }
134 break;
135 }
[87354]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 }
[75016]156 case UIToolType_Media:
[68175]157 {
[68200]158 /* Create Virtual Media Manager: */
[73721]159 m_pPaneMedia = new UIMediumManagerWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
[68200]160 AssertPtrReturnVoid(m_pPaneMedia);
[68175]161 {
[73637]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
[68175]167 /* Configure pane: */
[75016]168 m_pPaneMedia->setProperty("ToolType", QVariant::fromValue(UIToolType_Media));
[99390]169 connect(m_pPaneMedia, &UIMediumManagerWidget::sigCreateMedium,
170 this, &UIToolPaneGlobal::sigCreateMedium);
[99389]171 connect(m_pPaneMedia, &UIMediumManagerWidget::sigCopyMedium,
172 this, &UIToolPaneGlobal::sigCopyMedium);
[39546]173
[68175]174 /* Add into layout: */
[68200]175 m_pLayout->addWidget(m_pPaneMedia);
176 m_pLayout->setCurrentWidget(m_pPaneMedia);
[68175]177 }
178 break;
179 }
[75016]180 case UIToolType_Network:
[68175]181 {
[87342]182 /* Create Network Manager: */
[86997]183 m_pPaneNetwork = new UINetworkManagerWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
[68200]184 AssertPtrReturnVoid(m_pPaneNetwork);
[68175]185 {
[73637]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
[68175]191 /* Configure pane: */
[75016]192 m_pPaneNetwork->setProperty("ToolType", QVariant::fromValue(UIToolType_Network));
[39546]193
[68175]194 /* Add into layout: */
[68200]195 m_pLayout->addWidget(m_pPaneNetwork);
196 m_pLayout->setCurrentWidget(m_pPaneNetwork);
[68175]197 }
198 break;
199 }
[75016]200 case UIToolType_Cloud:
[74870]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: */
[75016]212 m_pPaneCloud->setProperty("ToolType", QVariant::fromValue(UIToolType_Cloud));
[74870]213
214 /* Add into layout: */
215 m_pLayout->addWidget(m_pPaneCloud);
216 m_pLayout->setCurrentWidget(m_pPaneCloud);
217 }
218 break;
219 }
[88074]220 case UIToolType_VMActivityOverview:
[83304]221 {
[88173]222 /* Create VM Activity Overview: */
[88089]223 m_pPaneVMActivityOverview = new UIVMActivityOverviewWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
224 AssertPtrReturnVoid(m_pPaneVMActivityOverview);
[83304]225 {
226#ifndef VBOX_WS_MAC
227 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
[88089]228 m_pPaneVMActivityOverview->setContentsMargins(iMargin, 0, iMargin, 0);
[83304]229#endif
230
231 /* Configure pane: */
[88089]232 m_pPaneVMActivityOverview->setProperty("ToolType", QVariant::fromValue(UIToolType_VMActivityOverview));
[89094]233 connect(m_pPaneVMActivityOverview, &UIVMActivityOverviewWidget::sigSwitchToMachineActivityPane,
234 this, &UIToolPaneGlobal::sigSwitchToMachineActivityPane);
[103020]235 m_pPaneVMActivityOverview->setCloudMachineItems(m_cloudItems);
[83481]236
[83304]237 /* Add into layout: */
[88089]238 m_pLayout->addWidget(m_pPaneVMActivityOverview);
239 m_pLayout->setCurrentWidget(m_pPaneVMActivityOverview);
[83304]240 }
241
242 break;
243 }
[68175]244 default:
245 AssertFailedReturnVoid();
246 }
247 }
[83482]248
249 /* Handle token change: */
250 handleTokenChange();
[67068]251}
[63950]252
[75016]253void UIToolPaneGlobal::closeTool(UIToolType enmType)
[67068]254{
[68175]255 /* Search through the stacked widgets: */
256 int iActualIndex = -1;
257 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
[75016]258 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
[68175]259 iActualIndex = iIndex;
[30868]260
[68175]261 /* If widget with such type doesn't exist: */
262 if (iActualIndex != -1)
[67068]263 {
[68175]264 /* Forget corresponding widget: */
265 switch (enmType)
[67068]266 {
[102118]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;
[68175]273 default: break;
[67068]274 }
[68175]275 /* Delete corresponding widget: */
276 QWidget *pWidget = m_pLayout->widget(iActualIndex);
277 m_pLayout->removeWidget(pWidget);
278 delete pWidget;
[67068]279 }
[83482]280
281 /* Handle token change: */
282 handleTokenChange();
[39225]283}
284
[87022]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;
[87354]294 case UIToolType_Extensions:
295 pCurrentToolWidget = m_pPaneExtensions;
296 break;
[87022]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;
[88074]306 case UIToolType_VMActivityOverview:
[88089]307 pCurrentToolWidget = m_pPaneVMActivityOverview;
[87022]308 break;
309 default:
310 break;
311 }
312 return uiCommon().helpKeyword(pCurrentToolWidget);
313}
314
[103020]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
[73424]328void UIToolPaneGlobal::prepare()
[14908]329{
[68175]330 /* Create stacked-layout: */
331 m_pLayout = new QStackedLayout(this);
332
333 /* Create desktop pane: */
[75016]334 openTool(UIToolType_Welcome);
[67091]335}
336
[73424]337void UIToolPaneGlobal::cleanup()
[30868]338{
[68175]339 /* Remove all widgets prematurelly: */
340 while (m_pLayout->count())
[67068]341 {
[68175]342 QWidget *pWidget = m_pLayout->widget(0);
343 m_pLayout->removeWidget(pWidget);
344 delete pWidget;
[67068]345 }
[14296]346}
[83482]347
348void UIToolPaneGlobal::handleTokenChange()
349{
[83483]350 /* Determine whether resource monitor is currently active tool: */
[88089]351 if (m_pPaneVMActivityOverview)
352 m_pPaneVMActivityOverview->setIsCurrentTool(m_fActive && currentTool() == UIToolType_VMActivityOverview);
[83482]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