VirtualBox

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

Last change on this file was 104393, checked in by vboxsync, 5 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the UIActionPool class.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.9 KB
RevLine 
[30868]1/* $Id: UIToolPaneMachine.cpp 104393 2024-04-22 13:02:56Z vboxsync $ */
[382]2/** @file
[73424]3 * VBox Qt GUI - UIToolPaneMachine class implementation.
[382]4 */
5
6/*
[98103]7 * Copyright (C) 2017-2023 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"
[103550]38#include "UICommon.h"
[92615]39#include "UIDetails.h"
[76606]40#include "UIErrorPane.h"
[92615]41#include "UIFileManager.h"
[103771]42#include "UIGlobalSession.h"
[76606]43#include "UIIconPool.h"
44#include "UISnapshotPane.h"
45#include "UIToolPaneMachine.h"
46#include "UIVirtualMachineItem.h"
[92615]47#include "UIVMActivityToolWidget.h"
[76606]48#include "UIVMLogViewerWidget.h"
[382]49
[92615]50
[41587]51/* Other VBox includes: */
[76606]52#include <iprt/assert.h>
[41587]53
[52730]54
[73424]55UIToolPaneMachine::UIToolPaneMachine(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
[74557]56 : QWidget(pParent)
[68175]57 , m_pActionPool(pActionPool)
58 , m_pLayout(0)
[74557]59 , m_pPaneError(0)
[68175]60 , m_pPaneDetails(0)
[67068]61 , m_pPaneSnapshots(0)
[70185]62 , m_pPaneLogViewer(0)
[88071]63 , m_pPaneVMActivityMonitor(0)
[92615]64 , m_pPaneFileManager(0)
[83482]65 , m_fActive(false)
[39399]66{
[67068]67 /* Prepare: */
68 prepare();
69}
[39399]70
[73424]71UIToolPaneMachine::~UIToolPaneMachine()
[67091]72{
73 /* Cleanup: */
74 cleanup();
75}
76
[83482]77void UIToolPaneMachine::setActive(bool fActive)
78{
79 /* Save activity: */
80 if (m_fActive != fActive)
81 {
82 m_fActive = fActive;
83
84 /* Handle token change: */
85 handleTokenChange();
86 }
87}
88
[75016]89UIToolType UIToolPaneMachine::currentTool() const
[68221]90{
[76771]91 return m_pLayout && m_pLayout->currentWidget()
92 ? m_pLayout->currentWidget()->property("ToolType").value<UIToolType>()
93 : UIToolType_Invalid;
[68221]94}
95
[75016]96bool UIToolPaneMachine::isToolOpened(UIToolType enmType) const
[67110]97{
[68175]98 /* Search through the stacked widgets: */
99 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
[75016]100 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
[67110]101 return true;
102 return false;
103}
104
[75016]105void UIToolPaneMachine::openTool(UIToolType enmType)
[67110]106{
[68175]107 /* Search through the stacked widgets: */
108 int iActualIndex = -1;
109 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
[75016]110 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
[68175]111 iActualIndex = iIndex;
[67110]112
[68175]113 /* If widget with such type exists: */
114 if (iActualIndex != -1)
[67068]115 {
[68175]116 /* Activate corresponding index: */
117 m_pLayout->setCurrentIndex(iActualIndex);
[67068]118 }
[68175]119 /* Otherwise: */
120 else
121 {
122 /* Create, remember, append corresponding stacked widget: */
123 switch (enmType)
124 {
[75016]125 case UIToolType_Error:
[68175]126 {
[84078]127 /* Create Error pane: */
[84335]128 m_pPaneError = new UIErrorPane;
[74557]129 if (m_pPaneError)
[68175]130 {
[84078]131#ifndef VBOX_WS_MAC
132 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
133 m_pPaneError->setContentsMargins(iMargin, 0, iMargin, 0);
134#endif
135
[68175]136 /* Configure pane: */
[75016]137 m_pPaneError->setProperty("ToolType", QVariant::fromValue(UIToolType_Error));
[39399]138
[68175]139 /* Add into layout: */
[74557]140 m_pLayout->addWidget(m_pPaneError);
141 m_pLayout->setCurrentWidget(m_pPaneError);
[68175]142 }
143 break;
144 }
[75016]145 case UIToolType_Details:
[68175]146 {
147 /* Create Details pane: */
[73424]148 m_pPaneDetails = new UIDetails;
[68175]149 AssertPtrReturnVoid(m_pPaneDetails);
150 {
151 /* Configure pane: */
[75016]152 m_pPaneDetails->setProperty("ToolType", QVariant::fromValue(UIToolType_Details));
[73424]153 connect(this, &UIToolPaneMachine::sigToggleStarted, m_pPaneDetails, &UIDetails::sigToggleStarted);
154 connect(this, &UIToolPaneMachine::sigToggleFinished, m_pPaneDetails, &UIDetails::sigToggleFinished);
155 connect(m_pPaneDetails, &UIDetails::sigLinkClicked, this, &UIToolPaneMachine::sigLinkClicked);
[75144]156 m_pPaneDetails->setItems(m_items);
[39546]157
[68175]158 /* Add into layout: */
159 m_pLayout->addWidget(m_pPaneDetails);
160 m_pLayout->setCurrentWidget(m_pPaneDetails);
161 }
162 break;
163 }
[75016]164 case UIToolType_Snapshots:
[68175]165 {
166 /* Create Snapshots pane: */
[73676]167 m_pPaneSnapshots = new UISnapshotPane(m_pActionPool, false /* show toolbar? */);
[68175]168 AssertPtrReturnVoid(m_pPaneSnapshots);
169 {
[73637]170#ifndef VBOX_WS_MAC
171 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
172 m_pPaneSnapshots->setContentsMargins(iMargin, 0, iMargin, 0);
173#endif
174
[68175]175 /* Configure pane: */
[75016]176 m_pPaneSnapshots->setProperty("ToolType", QVariant::fromValue(UIToolType_Snapshots));
[75093]177 connect(m_pPaneSnapshots, &UISnapshotPane::sigCurrentItemChange,
178 this, &UIToolPaneMachine::sigCurrentSnapshotItemChange);
[96635]179 m_pPaneSnapshots->setMachineItems(m_items);
[39546]180
[68175]181 /* Add into layout: */
182 m_pLayout->addWidget(m_pPaneSnapshots);
183 m_pLayout->setCurrentWidget(m_pPaneSnapshots);
184 }
185 break;
186 }
[75016]187 case UIToolType_Logs:
[70185]188 {
189 /* Create the Logviewer pane: */
[73697]190 m_pPaneLogViewer = new UIVMLogViewerWidget(EmbedTo_Stack, m_pActionPool, false /* show toolbar */);
[70185]191 AssertPtrReturnVoid(m_pPaneLogViewer);
192 {
[73637]193#ifndef VBOX_WS_MAC
194 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
195 m_pPaneLogViewer->setContentsMargins(iMargin, 0, iMargin, 0);
196#endif
197
[70185]198 /* Configure pane: */
[75016]199 m_pPaneLogViewer->setProperty("ToolType", QVariant::fromValue(UIToolType_Logs));
[102723]200 connect(m_pPaneLogViewer, &UIVMLogViewerWidget::sigDetach,
[102787]201 this, &UIToolPaneMachine::sltDetachToolPane);
[88686]202 m_pPaneLogViewer->setSelectedVMListItems(m_items);
[70185]203
204 /* Add into layout: */
205 m_pLayout->addWidget(m_pPaneLogViewer);
206 m_pLayout->setCurrentWidget(m_pPaneLogViewer);
207 }
208 break;
209 }
[88071]210 case UIToolType_VMActivity:
[85396]211 {
[89036]212 m_pPaneVMActivityMonitor = new UIVMActivityToolWidget(EmbedTo_Stack, m_pActionPool,
213 false /* Show toolbar */, 0 /* Parent */);
[88071]214 AssertPtrReturnVoid(m_pPaneVMActivityMonitor);
[85396]215#ifndef VBOX_WS_MAC
216 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
[88071]217 m_pPaneVMActivityMonitor->setContentsMargins(iMargin, 0, iMargin, 0);
[85396]218#endif
219
220 /* Configure pane: */
[88071]221 m_pPaneVMActivityMonitor->setProperty("ToolType", QVariant::fromValue(UIToolType_VMActivity));
[89036]222 m_pPaneVMActivityMonitor->setSelectedVMListItems(m_items);
[85396]223 /* Add into layout: */
[88071]224 m_pLayout->addWidget(m_pPaneVMActivityMonitor);
225 m_pLayout->setCurrentWidget(m_pPaneVMActivityMonitor);
[85396]226
[89094]227 connect(m_pPaneVMActivityMonitor, &UIVMActivityToolWidget::sigSwitchToActivityOverviewPane,
228 this, &UIToolPaneMachine::sigSwitchToActivityOverviewPane);
[85396]229 break;
230 }
[92615]231 case UIToolType_FileManager:
232 {
[92633]233 if (!m_items.isEmpty())
234 m_pPaneFileManager = new UIFileManager(EmbedTo_Stack, m_pActionPool,
[103771]235 gpGlobalSession->virtualBox().FindMachine(m_items[0]->id().toString()),
[92633]236 0, false /* fShowToolbar */);
[92638]237 else
238 m_pPaneFileManager = new UIFileManager(EmbedTo_Stack, m_pActionPool, CMachine(),
239 0, false /* fShowToolbar */);
240 AssertPtrReturnVoid(m_pPaneFileManager);
[92615]241#ifndef VBOX_WS_MAC
[92638]242 const int iMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 4;
243 m_pPaneFileManager->setContentsMargins(iMargin, 0, iMargin, 0);
[92615]244#endif
[92638]245 /* Configure pane: */
246 m_pPaneFileManager->setProperty("ToolType", QVariant::fromValue(UIToolType_FileManager));
[92688]247 m_pPaneFileManager->setSelectedVMListItems(m_items);
[92638]248 /* Add into layout: */
249 m_pLayout->addWidget(m_pPaneFileManager);
250 m_pLayout->setCurrentWidget(m_pPaneFileManager);
[92615]251 break;
252 }
[68175]253 default:
254 AssertFailedReturnVoid();
255 }
256 }
[83482]257
258 /* Handle token change: */
259 handleTokenChange();
[67068]260}
[63950]261
[75016]262void UIToolPaneMachine::closeTool(UIToolType enmType)
[67068]263{
[68175]264 /* Search through the stacked widgets: */
265 int iActualIndex = -1;
266 for (int iIndex = 0; iIndex < m_pLayout->count(); ++iIndex)
[75016]267 if (m_pLayout->widget(iIndex)->property("ToolType").value<UIToolType>() == enmType)
[68175]268 iActualIndex = iIndex;
[30868]269
[68175]270 /* If widget with such type doesn't exist: */
271 if (iActualIndex != -1)
[67068]272 {
[68175]273 /* Forget corresponding widget: */
274 switch (enmType)
[67068]275 {
[85398]276 case UIToolType_Error: m_pPaneError = 0; break;
277 case UIToolType_Details: m_pPaneDetails = 0; break;
278 case UIToolType_Snapshots: m_pPaneSnapshots = 0; break;
279 case UIToolType_Logs: m_pPaneLogViewer = 0; break;
[92467]280 case UIToolType_VMActivity: m_pPaneVMActivityMonitor = 0; break;
[68175]281 default: break;
[67068]282 }
[68175]283 /* Delete corresponding widget: */
284 QWidget *pWidget = m_pLayout->widget(iActualIndex);
285 m_pLayout->removeWidget(pWidget);
286 delete pWidget;
[67068]287 }
[83482]288
289 /* Handle token change: */
290 handleTokenChange();
[39225]291}
292
[74557]293void UIToolPaneMachine::setErrorDetails(const QString &strDetails)
[39225]294{
[74557]295 /* Update Error pane: */
296 if (m_pPaneError)
297 m_pPaneError->setErrorDetails(strDetails);
[39225]298}
299
[73424]300void UIToolPaneMachine::setItems(const QList<UIVirtualMachineItem*> &items)
[14908]301{
[75144]302 /* Cache passed value: */
303 m_items = items;
304
[103020]305 /* Update details pane if it is open: */
[75016]306 if (isToolOpened(UIToolType_Details))
307 {
308 AssertPtrReturnVoid(m_pPaneDetails);
[75144]309 m_pPaneDetails->setItems(m_items);
[75016]310 }
[96635]311 /* Update snapshots pane if it is open: */
312 if (isToolOpened(UIToolType_Snapshots))
313 {
314 AssertPtrReturnVoid(m_pPaneSnapshots);
315 m_pPaneSnapshots->setMachineItems(m_items);
316 }
[92688]317 /* Update logs pane if it is open: */
[88644]318 if (isToolOpened(UIToolType_Logs))
319 {
320 AssertPtrReturnVoid(m_pPaneLogViewer);
321 m_pPaneLogViewer->setSelectedVMListItems(m_items);
322 }
[92688]323 /* Update performance monitor pane if it is open: */
[89036]324 if (isToolOpened(UIToolType_VMActivity))
325 {
326 AssertPtrReturnVoid(m_pPaneVMActivityMonitor);
327 m_pPaneVMActivityMonitor->setSelectedVMListItems(m_items);
328 }
[103020]329 /* Update file manager pane if it is open: */
[92640]330 if (isToolOpened(UIToolType_FileManager))
331 {
332 AssertPtrReturnVoid(m_pPaneFileManager);
333 if (!m_items.isEmpty() && m_items[0])
[92688]334 m_pPaneFileManager->setSelectedVMListItems(m_items);
[92640]335 }
[67068]336}
[14478]337
[75093]338bool UIToolPaneMachine::isCurrentStateItemSelected() const
339{
[99218]340 return m_pPaneSnapshots ? m_pPaneSnapshots->isCurrentStateItemSelected() : false;
[75093]341}
342
[99218]343QUuid UIToolPaneMachine::currentSnapshotId()
344{
345 return m_pPaneSnapshots ? m_pPaneSnapshots->currentSnapshotId() : QUuid();
346}
347
[87022]348QString UIToolPaneMachine::currentHelpKeyword() const
349{
350 QWidget *pCurrentToolWidget = 0;
351 switch (currentTool())
352 {
353 case UIToolType_Error:
354 pCurrentToolWidget = m_pPaneError;
355 break;
356 case UIToolType_Details:
357 pCurrentToolWidget = m_pPaneDetails;
358 break;
359 case UIToolType_Snapshots:
360 pCurrentToolWidget = m_pPaneSnapshots;
361 break;
362 case UIToolType_Logs:
363 pCurrentToolWidget = m_pPaneLogViewer;
364 break;
[88071]365 case UIToolType_VMActivity:
366 pCurrentToolWidget = m_pPaneVMActivityMonitor;
[87022]367 break;
368 default:
369 break;
370 }
371 return uiCommon().helpKeyword(pCurrentToolWidget);
372}
373
[73424]374void UIToolPaneMachine::prepare()
[67091]375{
[68175]376 /* Create stacked-layout: */
377 m_pLayout = new QStackedLayout(this);
378
[74557]379 /* Create Details pane: */
[75016]380 openTool(UIToolType_Details);
[67091]381}
382
[73424]383void UIToolPaneMachine::cleanup()
[30868]384{
[68175]385 /* Remove all widgets prematurelly: */
386 while (m_pLayout->count())
[67068]387 {
[68175]388 QWidget *pWidget = m_pLayout->widget(0);
389 m_pLayout->removeWidget(pWidget);
390 delete pWidget;
[67068]391 }
[14296]392}
[83482]393
394void UIToolPaneMachine::handleTokenChange()
395{
396 // printf("UIToolPaneMachine::handleTokenChange: Active = %d, current tool = %d\n", m_fActive, currentTool());
397}
[102787]398
399void UIToolPaneMachine::sltDetachToolPane()
400{
401 AssertPtrReturnVoid(sender());
402 UIToolType enmToolType = UIToolType_Invalid;
403 if (sender() == m_pPaneLogViewer)
404 enmToolType = UIToolType_Logs;
405
406 if (enmToolType != UIToolType_Invalid)
407 emit sigDetachToolPane(enmToolType);
408}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use