1 | /* $Id: UIVMInformationDialog.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMInformationDialog class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-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 <QPushButton>
|
---|
30 | #include <QScrollBar>
|
---|
31 | #include <QVBoxLayout>
|
---|
32 |
|
---|
33 | /* GUI includes: */
|
---|
34 | #include "QITabWidget.h"
|
---|
35 | #include "QIDialogButtonBox.h"
|
---|
36 | #include "UIActionPool.h"
|
---|
37 | #include "UICommon.h"
|
---|
38 | #include "UIConverter.h"
|
---|
39 | #include "UIExtraDataManager.h"
|
---|
40 | #include "UIIconPool.h"
|
---|
41 | #include "UIInformationConfiguration.h"
|
---|
42 | #include "UIInformationRuntime.h"
|
---|
43 | #include "UIGuestProcessControlWidget.h"
|
---|
44 | #include "UILoggingDefs.h"
|
---|
45 | #include "UIMachineLogic.h"
|
---|
46 | #include "UIMachine.h"
|
---|
47 | #include "UIMachineView.h"
|
---|
48 | #include "UIMessageCenter.h"
|
---|
49 | #include "UIVMActivityMonitorContainer.h"
|
---|
50 | #include "UISession.h"
|
---|
51 | #include "UIShortcutPool.h"
|
---|
52 | #include "UITranslationEventListener.h"
|
---|
53 | #include "UIVirtualBoxEventHandler.h"
|
---|
54 | #include "UIVMInformationDialog.h"
|
---|
55 | #include "VBoxUtils.h"
|
---|
56 |
|
---|
57 | UIVMInformationDialog::UIVMInformationDialog(UIActionPool *pActionPool)
|
---|
58 | : QMainWindowWithRestorableGeometry(0)
|
---|
59 | , m_pTabWidget(0)
|
---|
60 | , m_fCloseEmitted(false)
|
---|
61 | , m_iGeometrySaveTimerId(-1)
|
---|
62 | , m_pActionPool(pActionPool)
|
---|
63 | {
|
---|
64 | prepare();
|
---|
65 | }
|
---|
66 |
|
---|
67 | bool UIVMInformationDialog::shouldBeMaximized() const
|
---|
68 | {
|
---|
69 | return gEDataManager->sessionInformationDialogShouldBeMaximized();
|
---|
70 | }
|
---|
71 |
|
---|
72 | void UIVMInformationDialog::sltRetranslateUI()
|
---|
73 | {
|
---|
74 | /* Setup dialog title: */
|
---|
75 | setWindowTitle(tr("%1 - Session Information").arg(m_strMachineName));
|
---|
76 |
|
---|
77 | /* Translate tabs: */
|
---|
78 | m_pTabWidget->setTabText(Tabs_ConfigurationDetails, tr("Configuration &Details"));
|
---|
79 | m_pTabWidget->setTabText(Tabs_RuntimeInformation, tr("&Runtime Information"));
|
---|
80 | m_pTabWidget->setTabText(Tabs_ActivityMonitor, tr("VM &Activity"));
|
---|
81 | m_pTabWidget->setTabText(3, tr("&Guest Control"));
|
---|
82 |
|
---|
83 | /* Retranslate button box buttons: */
|
---|
84 | if (m_pButtonBox)
|
---|
85 | {
|
---|
86 | m_pButtonBox->button(QDialogButtonBox::Close)->setText(tr("Close"));
|
---|
87 | m_pButtonBox->button(QDialogButtonBox::Help)->setText(tr("Help"));
|
---|
88 | m_pButtonBox->button(QDialogButtonBox::Close)->setStatusTip(tr("Close dialog without saving"));
|
---|
89 | m_pButtonBox->button(QDialogButtonBox::Help)->setStatusTip(tr("Show dialog help"));
|
---|
90 | m_pButtonBox->button(QDialogButtonBox::Close)->setShortcut(Qt::Key_Escape);
|
---|
91 | m_pButtonBox->button(QDialogButtonBox::Help)->setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
|
---|
92 | m_pButtonBox->button(QDialogButtonBox::Close)->setToolTip(tr("Close this dialog (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Close)->shortcut().toString()));
|
---|
93 | m_pButtonBox->button(QDialogButtonBox::Help)->setToolTip(tr("Show Help (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Help)->shortcut().toString()));
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | void UIVMInformationDialog::closeEvent(QCloseEvent *pEvent)
|
---|
98 | {
|
---|
99 | if (!m_fCloseEmitted)
|
---|
100 | {
|
---|
101 | m_fCloseEmitted = true;
|
---|
102 | UIVMInformationDialog::sigClose();
|
---|
103 | pEvent->ignore();
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | bool UIVMInformationDialog::event(QEvent *pEvent)
|
---|
108 | {
|
---|
109 | switch (pEvent->type())
|
---|
110 | {
|
---|
111 | case QEvent::Resize:
|
---|
112 | case QEvent::Move:
|
---|
113 | {
|
---|
114 | if (m_iGeometrySaveTimerId != -1)
|
---|
115 | killTimer(m_iGeometrySaveTimerId);
|
---|
116 | m_iGeometrySaveTimerId = startTimer(300);
|
---|
117 | break;
|
---|
118 | }
|
---|
119 | case QEvent::Timer:
|
---|
120 | {
|
---|
121 | QTimerEvent *pTimerEvent = static_cast<QTimerEvent*>(pEvent);
|
---|
122 | if (pTimerEvent->timerId() == m_iGeometrySaveTimerId)
|
---|
123 | {
|
---|
124 | killTimer(m_iGeometrySaveTimerId);
|
---|
125 | m_iGeometrySaveTimerId = -1;
|
---|
126 | saveDialogGeometry();
|
---|
127 | }
|
---|
128 | break;
|
---|
129 | }
|
---|
130 | default:
|
---|
131 | break;
|
---|
132 | }
|
---|
133 | return QMainWindowWithRestorableGeometry::event(pEvent);
|
---|
134 | }
|
---|
135 |
|
---|
136 | void UIVMInformationDialog::sltHandlePageChanged(int iIndex)
|
---|
137 | {
|
---|
138 | /* Focus the browser on shown page: */
|
---|
139 | m_pTabWidget->widget(iIndex)->setFocus();
|
---|
140 | }
|
---|
141 |
|
---|
142 | void UIVMInformationDialog::sltMachineStateChange(const QUuid &uMachineId, const KMachineState state)
|
---|
143 | {
|
---|
144 | if (m_uMachineId != uMachineId)
|
---|
145 | return;
|
---|
146 | QWidget *pWidget = m_tabs.value(Tabs_GuestControl);
|
---|
147 | if (!pWidget)
|
---|
148 | return;
|
---|
149 | pWidget->setEnabled(state == KMachineState_Running);
|
---|
150 | }
|
---|
151 |
|
---|
152 | void UIVMInformationDialog::sltAdditionsStateChange()
|
---|
153 | {
|
---|
154 | if (!m_pTabWidget)
|
---|
155 | return;
|
---|
156 | UIVMActivityMonitorContainer *pVMActivityMonitorContainer =
|
---|
157 | qobject_cast<UIVMActivityMonitorContainer*>(m_pTabWidget->widget(Tabs_ActivityMonitor));
|
---|
158 | if (!pVMActivityMonitorContainer)
|
---|
159 | return;
|
---|
160 | pVMActivityMonitorContainer->guestAdditionsStateChange(uiCommon().managedVMUuid());
|
---|
161 | }
|
---|
162 |
|
---|
163 | void UIVMInformationDialog::saveDialogGeometry()
|
---|
164 | {
|
---|
165 | const QRect geo = currentGeometry();
|
---|
166 | LogRel2(("GUI: UIVMInformationDialog: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
|
---|
167 | geo.x(), geo.y(), geo.width(), geo.height()));
|
---|
168 | gEDataManager->setSessionInformationDialogGeometry(geo, isCurrentlyMaximized());
|
---|
169 | }
|
---|
170 |
|
---|
171 | void UIVMInformationDialog::prepare()
|
---|
172 | {
|
---|
173 | connect(gpMachine, &UIMachine::sigAdditionsStateChange,
|
---|
174 | this, &UIVMInformationDialog::sltAdditionsStateChange);
|
---|
175 | #ifndef VBOX_WS_MAC
|
---|
176 | /* Assign window icon: */
|
---|
177 | setWindowIcon(UIIconPool::iconSetFull(":/session_info_32px.png", ":/session_info_16px.png"));
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | m_uMachineId = uiCommon().managedVMUuid();
|
---|
181 | m_strMachineName = gpMachine->machineName();
|
---|
182 |
|
---|
183 | /* Prepare stuff: */
|
---|
184 | prepareCentralWidget();
|
---|
185 | prepareConnections();
|
---|
186 |
|
---|
187 | /* Apply language settings: */
|
---|
188 | sltRetranslateUI();
|
---|
189 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
190 | this, &UIVMInformationDialog::sltRetranslateUI);
|
---|
191 |
|
---|
192 | /* Load settings: */
|
---|
193 | loadDialogGeometry();
|
---|
194 | }
|
---|
195 |
|
---|
196 | void UIVMInformationDialog::prepareCentralWidget()
|
---|
197 | {
|
---|
198 | /* Create central-widget: */
|
---|
199 | setCentralWidget(new QWidget);
|
---|
200 | AssertPtrReturnVoid(centralWidget());
|
---|
201 | {
|
---|
202 | /* Create main-layout: */
|
---|
203 | new QVBoxLayout(centralWidget());
|
---|
204 | AssertPtrReturnVoid(centralWidget()->layout());
|
---|
205 | {
|
---|
206 | /* Create tab-widget: */
|
---|
207 | prepareTabWidget();
|
---|
208 | /* Create button-box: */
|
---|
209 | prepareButtonBox();
|
---|
210 | }
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | void UIVMInformationDialog::prepareTabWidget()
|
---|
215 | {
|
---|
216 | /* Create tab-widget: */
|
---|
217 | m_pTabWidget = new QITabWidget;
|
---|
218 | AssertPtrReturnVoid(m_pTabWidget);
|
---|
219 | {
|
---|
220 | /* Prepare tab-widget: */
|
---|
221 | m_pTabWidget->setTabIcon(Tabs_ConfigurationDetails, UIIconPool::iconSet(":/session_info_details_16px.png"));
|
---|
222 | m_pTabWidget->setTabIcon(Tabs_RuntimeInformation, UIIconPool::iconSet(":/session_info_runtime_16px.png"));
|
---|
223 |
|
---|
224 | /* Create Configuration Details tab: */
|
---|
225 | UIInformationConfiguration *pInformationConfigurationWidget = new UIInformationConfiguration(this);
|
---|
226 | if (pInformationConfigurationWidget)
|
---|
227 | {
|
---|
228 | m_tabs.insert(Tabs_ConfigurationDetails, pInformationConfigurationWidget);
|
---|
229 | m_pTabWidget->addTab(m_tabs.value(Tabs_ConfigurationDetails), QString());
|
---|
230 | }
|
---|
231 |
|
---|
232 | /* Create Runtime Information tab: */
|
---|
233 | UIInformationRuntime *pInformationRuntimeWidget =
|
---|
234 | new UIInformationRuntime(this);
|
---|
235 | if (pInformationRuntimeWidget)
|
---|
236 | {
|
---|
237 | m_tabs.insert(Tabs_RuntimeInformation, pInformationRuntimeWidget);
|
---|
238 | m_pTabWidget->addTab(m_tabs.value(Tabs_RuntimeInformation), QString());
|
---|
239 | }
|
---|
240 |
|
---|
241 | /* Create Activity Monitor tab: */
|
---|
242 | UIVMActivityMonitorContainer *pVMActivityMonitorContainer = new UIVMActivityMonitorContainer(this, m_pActionPool, EmbedTo_Dialog);
|
---|
243 | if (pVMActivityMonitorContainer)
|
---|
244 | {
|
---|
245 | pVMActivityMonitorContainer->addLocalMachine(gpMachine->uisession()->machine());
|
---|
246 | m_tabs.insert(Tabs_ActivityMonitor, pVMActivityMonitorContainer);
|
---|
247 | m_pTabWidget->addTab(m_tabs.value(Tabs_ActivityMonitor), QString());
|
---|
248 | }
|
---|
249 | #ifdef DEBUG
|
---|
250 | /* Create Guest Process Control tab: */
|
---|
251 | UIGuestProcessControlWidget *pGuestProcessControlWidget =
|
---|
252 | new UIGuestProcessControlWidget(EmbedTo_Dialog, gpMachine->uisession()->guest(),
|
---|
253 | this, m_strMachineName, false /* fShowToolbar */);
|
---|
254 | if (pGuestProcessControlWidget)
|
---|
255 | {
|
---|
256 | m_tabs.insert(3, pGuestProcessControlWidget);
|
---|
257 | m_pTabWidget->addTab(m_tabs.value(3), QString());
|
---|
258 | }
|
---|
259 | #endif
|
---|
260 | m_pTabWidget->setCurrentIndex(Tabs_ActivityMonitor);
|
---|
261 |
|
---|
262 | /* Assign tab-widget page change handler: */
|
---|
263 | connect(m_pTabWidget, &QITabWidget::currentChanged, this, &UIVMInformationDialog::sltHandlePageChanged);
|
---|
264 |
|
---|
265 | /* Add tab-widget into main-layout: */
|
---|
266 | centralWidget()->layout()->addWidget(m_pTabWidget);
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | void UIVMInformationDialog::prepareButtonBox()
|
---|
271 | {
|
---|
272 | /* Create button-box: */
|
---|
273 | m_pButtonBox = new QIDialogButtonBox;
|
---|
274 | AssertPtrReturnVoid(m_pButtonBox);
|
---|
275 | {
|
---|
276 | /* Configure button-box: */
|
---|
277 | m_pButtonBox->setStandardButtons(QDialogButtonBox::Close | QDialogButtonBox::Help);
|
---|
278 | m_pButtonBox->button(QDialogButtonBox::Close)->setShortcut(Qt::Key_Escape);
|
---|
279 | m_pButtonBox->button(QDialogButtonBox::Help)->setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
|
---|
280 | uiCommon().setHelpKeyword(m_pButtonBox->button(QDialogButtonBox::Help), "vm-session-information");
|
---|
281 | connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIVMInformationDialog::sigClose);
|
---|
282 | connect(m_pButtonBox->button(QDialogButtonBox::Help), &QPushButton::pressed,
|
---|
283 | m_pButtonBox, &QIDialogButtonBox::sltHandleHelpRequest);
|
---|
284 | /* add button-box into main-layout: */
|
---|
285 | centralWidget()->layout()->addWidget(m_pButtonBox);
|
---|
286 | }
|
---|
287 | }
|
---|
288 |
|
---|
289 | void UIVMInformationDialog::prepareConnections()
|
---|
290 | {
|
---|
291 | connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
|
---|
292 | this, &UIVMInformationDialog::sltMachineStateChange);
|
---|
293 | }
|
---|
294 |
|
---|
295 | void UIVMInformationDialog::loadDialogGeometry()
|
---|
296 | {
|
---|
297 | const QRect geo = gEDataManager->sessionInformationDialogGeometry(this, gpMachine->activeWindow());
|
---|
298 | LogRel2(("GUI: UIVMInformationDialog: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
|
---|
299 | geo.x(), geo.y(), geo.width(), geo.height()));
|
---|
300 | restoreGeometry(geo);
|
---|
301 | }
|
---|