VirtualBox

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

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

© 2023 Oracle
ContactPrivacy policyTerms of Use