VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.cpp

Last change on this file was 104290, checked in by vboxsync, 7 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the runtime UI related classes.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use