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