1 | /* $Id: UIInformationRuntime.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIInformationRuntime 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 <QAction>
|
---|
30 | #include <QApplication>
|
---|
31 | #include <QClipboard>
|
---|
32 | #include <QHeaderView>
|
---|
33 | #include <QMenu>
|
---|
34 | #include <QVBoxLayout>
|
---|
35 | #include <QTimer>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UIConverter.h"
|
---|
39 | #include "UIGlobalSession.h"
|
---|
40 | #include "UIIconPool.h"
|
---|
41 | #include "UIInformationRuntime.h"
|
---|
42 | #include "UIGuestOSType.h"
|
---|
43 | #include "UIMachine.h"
|
---|
44 | #include "UITranslationEventListener.h"
|
---|
45 | #include "QITableWidget.h"
|
---|
46 |
|
---|
47 | /* COM includes: */
|
---|
48 | #include "CDisplay.h"
|
---|
49 | #include "CGraphicsAdapter.h"
|
---|
50 | #include "CMachineDebugger.h"
|
---|
51 | #include "CVRDEServerInfo.h"
|
---|
52 |
|
---|
53 | enum InfoRow
|
---|
54 | {
|
---|
55 | InfoRow_Title = 0,
|
---|
56 | InfoRow_Resolution,
|
---|
57 | InfoRow_Uptime,
|
---|
58 | InfoRow_ClipboardMode,
|
---|
59 | InfoRow_DnDMode,
|
---|
60 | InfoRow_ExecutionEngine,
|
---|
61 | InfoRow_NestedPaging,
|
---|
62 | InfoRow_UnrestrictedExecution,
|
---|
63 | InfoRow_Paravirtualization,
|
---|
64 | InfoRow_GuestAdditions,
|
---|
65 | InfoRow_GuestOSType,
|
---|
66 | InfoRow_RemoteDesktop,
|
---|
67 | InfoRow_Max
|
---|
68 | };
|
---|
69 |
|
---|
70 | /*********************************************************************************************************************************
|
---|
71 | * UIRuntimeInfoWidget definition. *
|
---|
72 | *********************************************************************************************************************************/
|
---|
73 | /** A QTablWidget extention to show some runtime attributes */
|
---|
74 | class UIRuntimeInfoWidget : public QITableWidget
|
---|
75 | {
|
---|
76 |
|
---|
77 | Q_OBJECT;
|
---|
78 |
|
---|
79 | public:
|
---|
80 |
|
---|
81 | UIRuntimeInfoWidget(QWidget *pParent);
|
---|
82 | void updateScreenInfo(int iScreenId = -1);
|
---|
83 | void updateGAsVersion();
|
---|
84 | void updateVRDE();
|
---|
85 | void updateClipboardMode(KClipboardMode enmMode = KClipboardMode_Max);
|
---|
86 | void updateDnDMode(KDnDMode enmMode = KDnDMode_Max);
|
---|
87 | QString tableData() const;
|
---|
88 |
|
---|
89 | private slots:
|
---|
90 |
|
---|
91 | void sltRetranslateUI();
|
---|
92 | void sltTimeout();
|
---|
93 |
|
---|
94 | private:
|
---|
95 |
|
---|
96 | void createInfoRows();
|
---|
97 | void updateUpTime();
|
---|
98 | void updateTitleRow();
|
---|
99 | void updateOSTypeRow();
|
---|
100 | void updateVirtualizationInfo();
|
---|
101 |
|
---|
102 | /** Searches the table for the @p item of enmLine and replaces its text. if not found inserts a new
|
---|
103 | * row to the end of the table. Assumes only one line of the @p enmLine exists. */
|
---|
104 | void updateInfoRow(InfoRow enmLine, const QString &strColumn0, const QString &strColumn1);
|
---|
105 | QString screenResolution(int iScreenId);
|
---|
106 | /** Creates to QITableWidgetItems of the @enmInfoRow using the @p strLabel and @p strInfo and inserts it
|
---|
107 | * to the row @p iRow. If @p iRow is -1 then the items inserted to the end of the table. */
|
---|
108 | void insertInfoRow(InfoRow enmInfoRow, const QString& strLabel, const QString &strInfo, int iRow = -1);
|
---|
109 | void computeMinimumWidth();
|
---|
110 |
|
---|
111 | /** @name Cached translated strings.
|
---|
112 | * @{ */
|
---|
113 | QString m_strTableTitle;
|
---|
114 | QString m_strScreenResolutionLabel;
|
---|
115 | QString m_strMonitorTurnedOff;
|
---|
116 | QString m_strUptimeLabel;
|
---|
117 | QString m_strClipboardModeLabel;
|
---|
118 | QString m_strDragAndDropLabel;
|
---|
119 | QString m_strExcutionEngineLabel;
|
---|
120 | QString m_strNestedPagingLabel;
|
---|
121 | QString m_strUnrestrictedExecutionLabel;
|
---|
122 | QString m_strParavirtualizationLabel;
|
---|
123 | QString m_strNestedPagingActive;
|
---|
124 | QString m_strNestedPagingInactive;
|
---|
125 | QString m_strUnrestrictedExecutionActive;
|
---|
126 | QString m_strUnrestrictedExecutionInactive;
|
---|
127 | QString m_strVRDEPortNotAvailable;
|
---|
128 | QString m_strGuestAdditionsLabel;
|
---|
129 | QString m_strGuestOSTypeLabel;
|
---|
130 | QString m_strRemoteDesktopLabel;
|
---|
131 | QString m_strExecutionEngineNotSet;
|
---|
132 | QString m_strOSNotDetected;
|
---|
133 | QString m_strGANotDetected;
|
---|
134 | /** @} */
|
---|
135 |
|
---|
136 | int m_iFontHeight;
|
---|
137 | /** Computed by computing the maximum length line. Used to avoid having horizontal scroll bars. */
|
---|
138 | int m_iMinimumWidth;
|
---|
139 | QVector<QString> m_screenResolutions;
|
---|
140 | QVector<QString*> m_labels;
|
---|
141 | QTimer *m_pTimer;
|
---|
142 | };
|
---|
143 |
|
---|
144 | /*********************************************************************************************************************************
|
---|
145 | * UIRuntimeInfoWidget implementation. *
|
---|
146 | *********************************************************************************************************************************/
|
---|
147 |
|
---|
148 | UIRuntimeInfoWidget::UIRuntimeInfoWidget(QWidget *pParent)
|
---|
149 | : QITableWidget(pParent)
|
---|
150 | , m_iMinimumWidth(0)
|
---|
151 | , m_pTimer(0)
|
---|
152 | {
|
---|
153 | setContextMenuPolicy(Qt::CustomContextMenu);
|
---|
154 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
155 | setAlternatingRowColors(true);
|
---|
156 | m_iFontHeight = QFontMetrics(font()).height();
|
---|
157 |
|
---|
158 | setColumnCount(2);
|
---|
159 | verticalHeader()->hide();
|
---|
160 | horizontalHeader()->hide();
|
---|
161 | setShowGrid(false);
|
---|
162 | setEditTriggers(QAbstractItemView::NoEditTriggers);
|
---|
163 | setFocusPolicy(Qt::NoFocus);
|
---|
164 | setSelectionMode(QAbstractItemView::NoSelection);
|
---|
165 |
|
---|
166 | m_pTimer = new QTimer(this);
|
---|
167 | if (m_pTimer)
|
---|
168 | {
|
---|
169 | connect(m_pTimer, &QTimer::timeout, this, &UIRuntimeInfoWidget::sltTimeout);
|
---|
170 | m_pTimer->start(5000);
|
---|
171 | }
|
---|
172 |
|
---|
173 | m_labels << &m_strScreenResolutionLabel
|
---|
174 | << &m_strUptimeLabel
|
---|
175 | << &m_strDragAndDropLabel
|
---|
176 | << &m_strExcutionEngineLabel
|
---|
177 | << &m_strNestedPagingLabel
|
---|
178 | << &m_strUnrestrictedExecutionLabel
|
---|
179 | << &m_strParavirtualizationLabel
|
---|
180 | << &m_strGuestAdditionsLabel
|
---|
181 | << &m_strGuestOSTypeLabel
|
---|
182 | << &m_strRemoteDesktopLabel;
|
---|
183 |
|
---|
184 |
|
---|
185 | sltRetranslateUI();
|
---|
186 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
187 | this, &UIRuntimeInfoWidget::sltRetranslateUI);
|
---|
188 | computeMinimumWidth();
|
---|
189 | }
|
---|
190 |
|
---|
191 | void UIRuntimeInfoWidget::sltRetranslateUI()
|
---|
192 | {
|
---|
193 | m_strTableTitle = QApplication::translate("UIVMInformationDialog", "Runtime Attributes");
|
---|
194 | m_strScreenResolutionLabel = QApplication::translate("UIVMInformationDialog", "Screen Resolution");
|
---|
195 | m_strMonitorTurnedOff = QApplication::translate("UIVMInformationDialog", "turned off", "Screen");
|
---|
196 | m_strUptimeLabel = QApplication::translate("UIVMInformationDialog", "VM Uptime");
|
---|
197 | m_strClipboardModeLabel = QApplication::translate("UIVMInformationDialog", "Clipboard Mode");
|
---|
198 | m_strDragAndDropLabel = QApplication::translate("UIVMInformationDialog", "Drag and Drop Mode");
|
---|
199 | m_strExcutionEngineLabel = QApplication::translate("UIVMInformationDialog", "VM Execution Engine");
|
---|
200 | m_strNestedPagingLabel = QApplication::translate("UIVMInformationDialog", "Nested Paging");
|
---|
201 | m_strUnrestrictedExecutionLabel = QApplication::translate("UIVMInformationDialog", "Unrestricted Execution");
|
---|
202 | m_strParavirtualizationLabel = QApplication::translate("UIVMInformationDialog", "Paravirtualization Interface");
|
---|
203 | m_strNestedPagingActive = QApplication::translate("UIVMInformationDialog", "Active", "Nested Paging");
|
---|
204 | m_strNestedPagingInactive = QApplication::translate("UIVMInformationDialog", "Inactive", "Nested Paging");
|
---|
205 | m_strUnrestrictedExecutionActive = QApplication::translate("UIVMInformationDialog", "Active", "Unrestricted Execution");
|
---|
206 | m_strUnrestrictedExecutionInactive = QApplication::translate("UIVMInformationDialog", "Inactive", "Unrestricted Execution");
|
---|
207 | m_strVRDEPortNotAvailable = QApplication::translate("UIVMInformationDialog", "Not Available", "VRDE Port");
|
---|
208 | m_strGuestAdditionsLabel = QApplication::translate("UIVMInformationDialog", "Guest Additions");
|
---|
209 | m_strGuestOSTypeLabel = QApplication::translate("UIVMInformationDialog", "Guest OS Type");
|
---|
210 | m_strRemoteDesktopLabel = QApplication::translate("UIVMInformationDialog", "Remote Desktop Server Port");
|
---|
211 | m_strExecutionEngineNotSet = QApplication::translate("UIVMInformationDialog", "not set", "Execution Engine");
|
---|
212 | m_strOSNotDetected = QApplication::translate("UIVMInformationDialog", "Not Detected", "Guest OS Type");
|
---|
213 | m_strGANotDetected = QApplication::translate("UIVMInformationDialog", "Not Detected", "Guest Additions Version");
|
---|
214 |
|
---|
215 | QString* strLongest = 0;
|
---|
216 | foreach (QString *strLabel, m_labels)
|
---|
217 | {
|
---|
218 | if (!strLongest)
|
---|
219 | strLongest = strLabel;
|
---|
220 | if (strLabel && strLongest->length() < strLabel->length())
|
---|
221 | strLongest = strLabel;
|
---|
222 | }
|
---|
223 | const QFontMetrics fontMetrics(font());
|
---|
224 | setColumnWidth(0, 1.5 * fontMetrics.horizontalAdvance(*strLongest));
|
---|
225 |
|
---|
226 | /* Make the API calls and populate the table: */
|
---|
227 | createInfoRows();
|
---|
228 | }
|
---|
229 |
|
---|
230 | void UIRuntimeInfoWidget::insertInfoRow(InfoRow enmInfoRow, const QString& strLabel, const QString &strInfo, int iRow /* = -1 */)
|
---|
231 | {
|
---|
232 | int iNewRow = rowCount();
|
---|
233 | if (iRow != -1 && iRow <= iNewRow)
|
---|
234 | iNewRow = iRow;
|
---|
235 | insertRow(iNewRow);
|
---|
236 |
|
---|
237 | QITableWidgetItem *pItem1 = new QITableWidgetItem(strLabel);
|
---|
238 | AssertPtrReturnVoid(pItem1);
|
---|
239 | pItem1->setData(Qt::UserRole + 1, enmInfoRow);
|
---|
240 | setItem(iNewRow, 1, pItem1);
|
---|
241 |
|
---|
242 | QITableWidgetItem *pItem2 = new QITableWidgetItem(strInfo);
|
---|
243 | AssertPtrReturnVoid(pItem2);
|
---|
244 | pItem2->setData(Qt::UserRole + 1, enmInfoRow);
|
---|
245 | setItem(iNewRow, 2, pItem2);
|
---|
246 |
|
---|
247 | int iMargin = 0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin);
|
---|
248 | setRowHeight(iNewRow, 2 * iMargin + m_iFontHeight);
|
---|
249 | }
|
---|
250 |
|
---|
251 | QString UIRuntimeInfoWidget::screenResolution(int iScreenID)
|
---|
252 | {
|
---|
253 | AssertPtrReturn(gpMachine, QString());
|
---|
254 | /* Determine resolution: */
|
---|
255 | ulong uWidth = 0;
|
---|
256 | ulong uHeight = 0;
|
---|
257 | ulong uBpp = 0;
|
---|
258 | long xOrigin = 0;
|
---|
259 | long yOrigin = 0;
|
---|
260 | KGuestMonitorStatus monitorStatus = KGuestMonitorStatus_Enabled;
|
---|
261 | gpMachine->acquireGuestScreenParameters(iScreenID, uWidth, uHeight, uBpp, xOrigin, yOrigin, monitorStatus);
|
---|
262 | QString strResolution = QString("%1x%2").arg(uWidth).arg(uHeight);
|
---|
263 | if (uBpp)
|
---|
264 | strResolution += QString("x%1").arg(uBpp);
|
---|
265 | strResolution += QString(" @%1,%2").arg(xOrigin).arg(yOrigin);
|
---|
266 | if (monitorStatus == KGuestMonitorStatus_Disabled)
|
---|
267 | {
|
---|
268 | strResolution += QString(" ");
|
---|
269 | strResolution += m_strMonitorTurnedOff;
|
---|
270 | }
|
---|
271 | return strResolution;
|
---|
272 | }
|
---|
273 |
|
---|
274 | void UIRuntimeInfoWidget::sltTimeout()
|
---|
275 | {
|
---|
276 | updateUpTime();
|
---|
277 | }
|
---|
278 |
|
---|
279 | void UIRuntimeInfoWidget::updateScreenInfo(int iScreenID /* = -1 */)
|
---|
280 | {
|
---|
281 | AssertPtrReturnVoid(gpMachine);
|
---|
282 | ulong uGuestScreens = 0;
|
---|
283 | gpMachine->acquireMonitorCount(uGuestScreens);
|
---|
284 | AssertReturnVoid(uGuestScreens > 0);
|
---|
285 |
|
---|
286 | m_screenResolutions.resize(uGuestScreens);
|
---|
287 | if (iScreenID != -1 && iScreenID >= (int)uGuestScreens)
|
---|
288 | return;
|
---|
289 | if (iScreenID == -1)
|
---|
290 | {
|
---|
291 | for (ULONG iScreen = 0; iScreen < uGuestScreens; ++iScreen)
|
---|
292 | m_screenResolutions[iScreen] = screenResolution(iScreen);
|
---|
293 | }
|
---|
294 | else
|
---|
295 | m_screenResolutions[iScreenID] = screenResolution(iScreenID);
|
---|
296 | /* Delete all the rows (not only the updated screen's row) and reinsert them: */
|
---|
297 | int iRowCount = rowCount();
|
---|
298 | for (int i = iRowCount - 1; i >= 0; --i)
|
---|
299 | {
|
---|
300 | QITableWidgetItem *pItem = static_cast<QITableWidgetItem*>(item(i, 1));
|
---|
301 | if (pItem && pItem->data(Qt::UserRole + 1) == InfoRow_Resolution)
|
---|
302 | removeRow(i);
|
---|
303 | }
|
---|
304 | for (ULONG iScreen = 0; iScreen < uGuestScreens; ++iScreen)
|
---|
305 | {
|
---|
306 | QString strLabel = uGuestScreens > 1 ?
|
---|
307 | QString("%1 %2").arg(m_strScreenResolutionLabel).arg(QString::number(iScreen)) :
|
---|
308 | QString("%1").arg(m_strScreenResolutionLabel);
|
---|
309 | /* Insert the screen resolution row at the top of the table. Row 0 is the title row: */
|
---|
310 | insertInfoRow(InfoRow_Resolution, strLabel, m_screenResolutions[iScreen], iScreen + 1);
|
---|
311 | }
|
---|
312 | resizeColumnToContents(1);
|
---|
313 | horizontalHeader()->setStretchLastSection(true);
|
---|
314 | }
|
---|
315 |
|
---|
316 | void UIRuntimeInfoWidget::updateUpTime()
|
---|
317 | {
|
---|
318 | AssertPtrReturnVoid(gpMachine);
|
---|
319 | LONG64 uUptime;
|
---|
320 | if (!gpMachine->acquireUptime(uUptime))
|
---|
321 | return;
|
---|
322 | uint64_t uUpSecs = (uUptime / 5000) * 5;
|
---|
323 | char szUptime[32];
|
---|
324 | uint64_t uUpDays = uUpSecs / (60 * 60 * 24);
|
---|
325 | uUpSecs -= uUpDays * 60 * 60 * 24;
|
---|
326 | uint64_t uUpHours = uUpSecs / (60 * 60);
|
---|
327 | uUpSecs -= uUpHours * 60 * 60;
|
---|
328 | uint64_t uUpMins = uUpSecs / 60;
|
---|
329 | uUpSecs -= uUpMins * 60;
|
---|
330 | RTStrPrintf(szUptime, sizeof(szUptime), "%dd %02d:%02d:%02d",
|
---|
331 | uUpDays, uUpHours, uUpMins, uUpSecs);
|
---|
332 | QString strUptime = QString(szUptime);
|
---|
333 | updateInfoRow(InfoRow_Uptime, QString("%1").arg(m_strUptimeLabel), strUptime);
|
---|
334 | }
|
---|
335 |
|
---|
336 | void UIRuntimeInfoWidget::updateTitleRow()
|
---|
337 | {
|
---|
338 | /* Add the title row always as 0th row: */
|
---|
339 | QITableWidgetItem *pTitleIcon = new QITableWidgetItem("");
|
---|
340 | AssertReturnVoid(pTitleIcon);
|
---|
341 | pTitleIcon->setIcon(UIIconPool::iconSet(":/state_running_16px.png"));
|
---|
342 | pTitleIcon->setData(Qt::UserRole + 1, InfoRow_Title);
|
---|
343 |
|
---|
344 | QITableWidgetItem *pTitleItem = new QITableWidgetItem(m_strTableTitle);
|
---|
345 | AssertReturnVoid(pTitleItem);
|
---|
346 | pTitleItem->setData(Qt::UserRole + 1, InfoRow_Title);
|
---|
347 |
|
---|
348 | QFont titleFont(font());
|
---|
349 | titleFont.setBold(true);
|
---|
350 | pTitleItem->setFont(titleFont);
|
---|
351 | if (rowCount() < 1)
|
---|
352 | insertRow(0);
|
---|
353 | setItem(0, 0, pTitleIcon);
|
---|
354 | setItem(0, 1, pTitleItem);
|
---|
355 | resizeColumnToContents(0);
|
---|
356 | }
|
---|
357 |
|
---|
358 | void UIRuntimeInfoWidget::updateOSTypeRow()
|
---|
359 | {
|
---|
360 | AssertPtrReturnVoid(gpMachine);
|
---|
361 | QString strOSType = gpMachine->osTypeId();
|
---|
362 | if (strOSType.isEmpty())
|
---|
363 | strOSType = m_strOSNotDetected;
|
---|
364 | else
|
---|
365 | {
|
---|
366 | strOSType = gpGlobalSession->guestOSTypeManager().getDescription(strOSType);
|
---|
367 | }
|
---|
368 | updateInfoRow(InfoRow_GuestOSType, QString("%1").arg(m_strGuestOSTypeLabel), strOSType);
|
---|
369 | }
|
---|
370 |
|
---|
371 | void UIRuntimeInfoWidget::updateVirtualizationInfo()
|
---|
372 | {
|
---|
373 | AssertPtrReturnVoid(gpMachine);
|
---|
374 | KVMExecutionEngine enmExecutionEngineType = gpMachine->vmExecutionEngine();
|
---|
375 |
|
---|
376 | QString strExecutionEngine;
|
---|
377 | switch (enmExecutionEngineType)
|
---|
378 | {
|
---|
379 | case KVMExecutionEngine_HwVirt:
|
---|
380 | strExecutionEngine = "VT-x/AMD-V"; /* no translation */
|
---|
381 | break;
|
---|
382 | case KVMExecutionEngine_Interpreter:
|
---|
383 | strExecutionEngine = "IEM (Interpreter)"; /* no translation */
|
---|
384 | break;
|
---|
385 | case KVMExecutionEngine_Recompiler:
|
---|
386 | strExecutionEngine = "IEM (Recompiler)"; /* no translation */
|
---|
387 | break;
|
---|
388 | case KVMExecutionEngine_NativeApi:
|
---|
389 | strExecutionEngine = "native API"; /* no translation */
|
---|
390 | break;
|
---|
391 | default:
|
---|
392 | AssertFailed();
|
---|
393 | RT_FALL_THRU();
|
---|
394 | case KVMExecutionEngine_NotSet:
|
---|
395 | strExecutionEngine = m_strExecutionEngineNotSet;
|
---|
396 | break;
|
---|
397 | }
|
---|
398 | QString strNestedPaging = gpMachine->isHWVirtExNestedPagingEnabled() ?
|
---|
399 | m_strNestedPagingActive : m_strNestedPagingInactive;
|
---|
400 | QString strUnrestrictedExecution = gpMachine->isHWVirtExUXEnabled() ?
|
---|
401 | m_strUnrestrictedExecutionActive : m_strUnrestrictedExecutionInactive;
|
---|
402 | QString strParavirtProvider = gpConverter->toString(gpMachine->paravirtProvider());
|
---|
403 |
|
---|
404 | updateInfoRow(InfoRow_ExecutionEngine, QString("%1").arg(m_strExcutionEngineLabel), strExecutionEngine);
|
---|
405 | updateInfoRow(InfoRow_NestedPaging, QString("%1").arg(m_strNestedPagingLabel), strNestedPaging);
|
---|
406 | updateInfoRow(InfoRow_UnrestrictedExecution, QString("%1").arg(m_strUnrestrictedExecutionLabel), strUnrestrictedExecution);
|
---|
407 | updateInfoRow(InfoRow_Paravirtualization, QString("%1").arg(m_strParavirtualizationLabel), strParavirtProvider);
|
---|
408 | }
|
---|
409 |
|
---|
410 | void UIRuntimeInfoWidget::updateGAsVersion()
|
---|
411 | {
|
---|
412 | AssertPtrReturnVoid(gpMachine);
|
---|
413 | QString strGAVersion;
|
---|
414 | gpMachine->acquireGuestAdditionsVersion(strGAVersion);
|
---|
415 | if (strGAVersion.isEmpty())
|
---|
416 | strGAVersion = m_strGANotDetected;
|
---|
417 | else
|
---|
418 | {
|
---|
419 | ulong uRevision = 0;
|
---|
420 | gpMachine->acquireGuestAdditionsRevision(uRevision);
|
---|
421 | if (uRevision != 0)
|
---|
422 | strGAVersion += QString(" r%1").arg(uRevision);
|
---|
423 | }
|
---|
424 | updateInfoRow(InfoRow_GuestAdditions, QString("%1").arg(m_strGuestAdditionsLabel), strGAVersion);
|
---|
425 | }
|
---|
426 |
|
---|
427 | void UIRuntimeInfoWidget::updateVRDE()
|
---|
428 | {
|
---|
429 | AssertPtrReturnVoid(gpMachine);
|
---|
430 | long iVRDEPort = 0;
|
---|
431 | gpMachine->acquireVRDEServerPort(iVRDEPort);
|
---|
432 | const QString strVRDEInfo = (iVRDEPort == 0 || iVRDEPort == -1)
|
---|
433 | ? m_strVRDEPortNotAvailable
|
---|
434 | : QString("%1").arg(iVRDEPort);
|
---|
435 | updateInfoRow(InfoRow_RemoteDesktop, QString("%1").arg(m_strRemoteDesktopLabel), strVRDEInfo);
|
---|
436 | }
|
---|
437 |
|
---|
438 | void UIRuntimeInfoWidget::updateClipboardMode(KClipboardMode enmMode /* = KClipboardMode_Max */)
|
---|
439 | {
|
---|
440 | AssertPtrReturnVoid(gpMachine);
|
---|
441 | if (enmMode == KClipboardMode_Max)
|
---|
442 | {
|
---|
443 | KClipboardMode enmClipboardMode = KClipboardMode_Max;
|
---|
444 | gpMachine->acquireClipboardMode(enmClipboardMode);
|
---|
445 | updateInfoRow(InfoRow_ClipboardMode, QString("%1").arg(m_strClipboardModeLabel),
|
---|
446 | gpConverter->toString(enmClipboardMode));
|
---|
447 | }
|
---|
448 | else
|
---|
449 | updateInfoRow(InfoRow_ClipboardMode, QString("%1").arg(m_strClipboardModeLabel),
|
---|
450 | gpConverter->toString(enmMode));
|
---|
451 | }
|
---|
452 |
|
---|
453 | void UIRuntimeInfoWidget::updateDnDMode(KDnDMode enmMode /* = KDnDMode_Max */)
|
---|
454 | {
|
---|
455 | AssertPtrReturnVoid(gpMachine);
|
---|
456 | if (enmMode == KDnDMode_Max)
|
---|
457 | {
|
---|
458 | KDnDMode enmDnDMode = KDnDMode_Max;
|
---|
459 | gpMachine->acquireDnDMode(enmDnDMode);
|
---|
460 | updateInfoRow(InfoRow_DnDMode, QString("%1").arg(m_strDragAndDropLabel),
|
---|
461 | gpConverter->toString(enmDnDMode));
|
---|
462 | }
|
---|
463 | else
|
---|
464 | updateInfoRow(InfoRow_DnDMode, QString("%1").arg(m_strDragAndDropLabel),
|
---|
465 | gpConverter->toString(enmMode));
|
---|
466 | }
|
---|
467 |
|
---|
468 | QString UIRuntimeInfoWidget::tableData() const
|
---|
469 | {
|
---|
470 | AssertReturn(columnCount() == 3, QString());
|
---|
471 | QStringList data;
|
---|
472 | for (int i = 0; i < rowCount(); ++i)
|
---|
473 | {
|
---|
474 | /* Skip the first column as it contains only icon and no text: */
|
---|
475 | QITableWidgetItem *pItem = static_cast<QITableWidgetItem*>(item(i, 1));
|
---|
476 | if (!pItem)
|
---|
477 | continue;
|
---|
478 | QString strColumn1 = pItem ? pItem->text() : QString();
|
---|
479 | pItem = static_cast<QITableWidgetItem*>(item(i, 2));
|
---|
480 | if (!pItem)
|
---|
481 | continue;
|
---|
482 | QString strColumn2 = pItem ? pItem->text() : QString();
|
---|
483 | if (strColumn2.isEmpty())
|
---|
484 | data << strColumn1;
|
---|
485 | else
|
---|
486 | data << strColumn1 << ": " << strColumn2;
|
---|
487 | data << "\n";
|
---|
488 | }
|
---|
489 | return data.join(QString());
|
---|
490 | }
|
---|
491 |
|
---|
492 | void UIRuntimeInfoWidget::updateInfoRow(InfoRow enmLine, const QString &strColumn0, const QString &strColumn1)
|
---|
493 | {
|
---|
494 | QITableWidgetItem *pItem = 0;
|
---|
495 | for (int i = 0; i < rowCount() && !pItem; ++i)
|
---|
496 | {
|
---|
497 | pItem = static_cast<QITableWidgetItem*>(item(i, 2));
|
---|
498 | if (!pItem)
|
---|
499 | continue;
|
---|
500 | if (pItem->data(Qt::UserRole + 1) != enmLine)
|
---|
501 | pItem = 0;
|
---|
502 | }
|
---|
503 | if (!pItem)
|
---|
504 | insertInfoRow(enmLine, strColumn0, strColumn1);
|
---|
505 | else
|
---|
506 | pItem->setText(strColumn1);
|
---|
507 | }
|
---|
508 |
|
---|
509 | void UIRuntimeInfoWidget::createInfoRows()
|
---|
510 | {
|
---|
511 | clear();
|
---|
512 | setRowCount(0);
|
---|
513 | setColumnCount(3);
|
---|
514 | updateTitleRow();
|
---|
515 | updateScreenInfo();
|
---|
516 | updateUpTime();
|
---|
517 | updateClipboardMode();
|
---|
518 | updateDnDMode();
|
---|
519 | updateVirtualizationInfo();
|
---|
520 | updateGAsVersion();
|
---|
521 | updateOSTypeRow();
|
---|
522 | updateVRDE();
|
---|
523 | resizeColumnToContents(1);
|
---|
524 | }
|
---|
525 |
|
---|
526 | void UIRuntimeInfoWidget::computeMinimumWidth()
|
---|
527 | {
|
---|
528 | m_iMinimumWidth = 0;
|
---|
529 | for (int j = 0; j < columnCount(); ++j)
|
---|
530 | m_iMinimumWidth += columnWidth(j);
|
---|
531 | }
|
---|
532 |
|
---|
533 |
|
---|
534 |
|
---|
535 | /*********************************************************************************************************************************
|
---|
536 | * UIInformationRuntime implementation. *
|
---|
537 | *********************************************************************************************************************************/
|
---|
538 |
|
---|
539 | UIInformationRuntime::UIInformationRuntime(QWidget *pParent)
|
---|
540 | : QWidget(pParent)
|
---|
541 | , m_pMainLayout(0)
|
---|
542 | , m_pRuntimeInfoWidget(0)
|
---|
543 | , m_pCopyWholeTableAction(0)
|
---|
544 | {
|
---|
545 | connect(gpMachine, &UIMachine::sigAdditionsStateChange, this, &UIInformationRuntime::sltGuestAdditionsStateChange);
|
---|
546 | connect(gpMachine, &UIMachine::sigGuestMonitorChange, this, &UIInformationRuntime::sltGuestMonitorChange);
|
---|
547 | connect(gpMachine, &UIMachine::sigVRDEChange, this, &UIInformationRuntime::sltVRDEChange);
|
---|
548 | connect(gpMachine, &UIMachine::sigClipboardModeChange, this, &UIInformationRuntime::sltClipboardChange);
|
---|
549 | connect(gpMachine, &UIMachine::sigDnDModeChange, this, &UIInformationRuntime::sltDnDModeChange);
|
---|
550 |
|
---|
551 | prepareObjects();
|
---|
552 | sltRetranslateUI();
|
---|
553 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
554 | this, &UIInformationRuntime::sltRetranslateUI);
|
---|
555 | }
|
---|
556 |
|
---|
557 | void UIInformationRuntime::sltRetranslateUI()
|
---|
558 | {
|
---|
559 | if (m_pCopyWholeTableAction)
|
---|
560 | m_pCopyWholeTableAction->setText(QApplication::translate("UIVMInformationDialog", "Copy All"));
|
---|
561 | if (m_pRuntimeInfoWidget)
|
---|
562 | m_pRuntimeInfoWidget->setWhatsThis(QApplication::translate("UIVMInformationDialog", "Displays the runtime information of the guest system"));
|
---|
563 | }
|
---|
564 |
|
---|
565 | void UIInformationRuntime::prepareObjects()
|
---|
566 | {
|
---|
567 | m_pMainLayout = new QVBoxLayout(this);
|
---|
568 | if (!m_pMainLayout)
|
---|
569 | return;
|
---|
570 | m_pMainLayout->setSpacing(0);
|
---|
571 |
|
---|
572 | m_pRuntimeInfoWidget = new UIRuntimeInfoWidget(0);
|
---|
573 | AssertReturnVoid(m_pRuntimeInfoWidget);
|
---|
574 | connect(m_pRuntimeInfoWidget, &UIRuntimeInfoWidget::customContextMenuRequested,
|
---|
575 | this, &UIInformationRuntime::sltHandleTableContextMenuRequest);
|
---|
576 | m_pMainLayout->addWidget(m_pRuntimeInfoWidget);
|
---|
577 | m_pRuntimeInfoWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
---|
578 |
|
---|
579 | m_pCopyWholeTableAction = new QAction(this);
|
---|
580 | connect(m_pCopyWholeTableAction, &QAction::triggered, this, &UIInformationRuntime::sltHandleCopyWholeTable);
|
---|
581 | }
|
---|
582 |
|
---|
583 | void UIInformationRuntime::sltGuestAdditionsStateChange()
|
---|
584 | {
|
---|
585 | if (m_pRuntimeInfoWidget)
|
---|
586 | m_pRuntimeInfoWidget->updateGAsVersion();
|
---|
587 | }
|
---|
588 |
|
---|
589 | void UIInformationRuntime::sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo)
|
---|
590 | {
|
---|
591 | Q_UNUSED(changeType);
|
---|
592 | Q_UNUSED(screenGeo);
|
---|
593 | if (m_pRuntimeInfoWidget)
|
---|
594 | m_pRuntimeInfoWidget->updateScreenInfo(uScreenId);
|
---|
595 | }
|
---|
596 |
|
---|
597 | void UIInformationRuntime::sltVRDEChange()
|
---|
598 | {
|
---|
599 | if (m_pRuntimeInfoWidget)
|
---|
600 | m_pRuntimeInfoWidget->updateVRDE();
|
---|
601 | }
|
---|
602 |
|
---|
603 | void UIInformationRuntime::sltClipboardChange(KClipboardMode enmMode)
|
---|
604 | {
|
---|
605 | if (m_pRuntimeInfoWidget)
|
---|
606 | m_pRuntimeInfoWidget->updateClipboardMode(enmMode);
|
---|
607 | }
|
---|
608 |
|
---|
609 | void UIInformationRuntime::sltDnDModeChange(KDnDMode enmMode)
|
---|
610 | {
|
---|
611 | if (m_pRuntimeInfoWidget)
|
---|
612 | m_pRuntimeInfoWidget->updateDnDMode(enmMode);
|
---|
613 | }
|
---|
614 |
|
---|
615 | void UIInformationRuntime::sltHandleTableContextMenuRequest(const QPoint &position)
|
---|
616 | {
|
---|
617 | if (!m_pCopyWholeTableAction)
|
---|
618 | return;
|
---|
619 |
|
---|
620 | QMenu menu(this);
|
---|
621 | menu.addAction(m_pCopyWholeTableAction);
|
---|
622 | menu.exec(mapToGlobal(position));
|
---|
623 | }
|
---|
624 |
|
---|
625 | void UIInformationRuntime::sltHandleCopyWholeTable()
|
---|
626 | {
|
---|
627 | QClipboard *pClipboard = QApplication::clipboard();
|
---|
628 | if (!pClipboard)
|
---|
629 | return;
|
---|
630 | if (!m_pRuntimeInfoWidget)
|
---|
631 | return;
|
---|
632 |
|
---|
633 | pClipboard->setText(m_pRuntimeInfoWidget->tableData(), QClipboard::Clipboard);
|
---|
634 | }
|
---|
635 |
|
---|
636 | #include "UIInformationRuntime.moc"
|
---|