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