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