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