1 | /* $Id: UIDetailsElements.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIDetailsElement[Name] classes implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-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 <QDir>
|
---|
30 | #include <QGraphicsLinearLayout>
|
---|
31 | #include <QTimer>
|
---|
32 |
|
---|
33 | /* GUI includes: */
|
---|
34 | #include "UICommon.h"
|
---|
35 | #include "UIConverter.h"
|
---|
36 | #include "UIDetailsElements.h"
|
---|
37 | #include "UIDetailsGenerator.h"
|
---|
38 | #include "UIDetailsModel.h"
|
---|
39 | #include "UIErrorString.h"
|
---|
40 | #include "UIGraphicsRotatorButton.h"
|
---|
41 | #include "UIGraphicsTextPane.h"
|
---|
42 | #include "UIIconPool.h"
|
---|
43 | #include "UIMachinePreview.h"
|
---|
44 | #include "UIThreadPool.h"
|
---|
45 |
|
---|
46 | /* COM includes: */
|
---|
47 | #include "CAudioAdapter.h"
|
---|
48 | #include "CMedium.h"
|
---|
49 | #include "CMediumAttachment.h"
|
---|
50 | #include "CNetworkAdapter.h"
|
---|
51 | #include "CRecordingScreenSettings.h"
|
---|
52 | #include "CRecordingSettings.h"
|
---|
53 | #include "CSerialPort.h"
|
---|
54 | #include "CSharedFolder.h"
|
---|
55 | #include "CStorageController.h"
|
---|
56 | #include "CSystemProperties.h"
|
---|
57 | #include "CUSBController.h"
|
---|
58 | #include "CUSBDeviceFilter.h"
|
---|
59 | #include "CUSBDeviceFilters.h"
|
---|
60 | #include "CVRDEServer.h"
|
---|
61 |
|
---|
62 | UIDetailsUpdateTask::UIDetailsUpdateTask(const CMachine &comMachine)
|
---|
63 | : UITask(UITask::Type_DetailsPopulation)
|
---|
64 | , m_comMachine(comMachine)
|
---|
65 | {
|
---|
66 | }
|
---|
67 |
|
---|
68 | UIDetailsUpdateTask::UIDetailsUpdateTask(const CCloudMachine &comCloudMachine)
|
---|
69 | : UITask(UITask::Type_DetailsPopulation)
|
---|
70 | , m_comCloudMachine(comCloudMachine)
|
---|
71 | {
|
---|
72 | }
|
---|
73 |
|
---|
74 | CMachine UIDetailsUpdateTask::machine() const
|
---|
75 | {
|
---|
76 | /* Acquire copy under a proper lock: */
|
---|
77 | m_machineMutex.lock();
|
---|
78 | const CMachine comMachine = m_comMachine;
|
---|
79 | m_machineMutex.unlock();
|
---|
80 | return comMachine;
|
---|
81 | }
|
---|
82 |
|
---|
83 | CCloudMachine UIDetailsUpdateTask::cloudMachine() const
|
---|
84 | {
|
---|
85 | /* Acquire copy under a proper lock: */
|
---|
86 | m_machineMutex.lock();
|
---|
87 | const CCloudMachine comCloudMachine = m_comCloudMachine;
|
---|
88 | m_machineMutex.unlock();
|
---|
89 | return comCloudMachine;
|
---|
90 | }
|
---|
91 |
|
---|
92 | UITextTable UIDetailsUpdateTask::table() const
|
---|
93 | {
|
---|
94 | /* Acquire copy under a proper lock: */
|
---|
95 | m_tableMutex.lock();
|
---|
96 | const UITextTable guiTable = m_guiTable;
|
---|
97 | m_tableMutex.unlock();
|
---|
98 | return guiTable;
|
---|
99 | }
|
---|
100 |
|
---|
101 | void UIDetailsUpdateTask::setTable(const UITextTable &guiTable)
|
---|
102 | {
|
---|
103 | /* Assign under a proper lock: */
|
---|
104 | m_tableMutex.lock();
|
---|
105 | m_guiTable = guiTable;
|
---|
106 | m_tableMutex.unlock();
|
---|
107 | }
|
---|
108 |
|
---|
109 | UIDetailsElementInterface::UIDetailsElementInterface(UIDetailsSet *pParent, DetailsElementType type, bool fOpened)
|
---|
110 | : UIDetailsElement(pParent, type, fOpened)
|
---|
111 | , m_pTask(0)
|
---|
112 | {
|
---|
113 | /* Listen for the global thread-pool: */
|
---|
114 | connect(uiCommon().threadPool(), &UIThreadPool::sigTaskComplete,
|
---|
115 | this, &UIDetailsElementInterface::sltUpdateAppearanceFinished);
|
---|
116 |
|
---|
117 | /* Translate finally: */
|
---|
118 | retranslateUi();
|
---|
119 | }
|
---|
120 |
|
---|
121 | void UIDetailsElementInterface::retranslateUi()
|
---|
122 | {
|
---|
123 | /* Assign corresponding name: */
|
---|
124 | setName(gpConverter->toString(elementType()));
|
---|
125 | }
|
---|
126 |
|
---|
127 | void UIDetailsElementInterface::updateAppearance()
|
---|
128 | {
|
---|
129 | /* Call to base-class: */
|
---|
130 | UIDetailsElement::updateAppearance();
|
---|
131 |
|
---|
132 | /* Prepare/start update task: */
|
---|
133 | if (!m_pTask)
|
---|
134 | {
|
---|
135 | /* Prepare update task: */
|
---|
136 | m_pTask = createUpdateTask();
|
---|
137 | /* Post task into global thread-pool: */
|
---|
138 | uiCommon().threadPool()->enqueueTask(m_pTask);
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | void UIDetailsElementInterface::sltUpdateAppearanceFinished(UITask *pTask)
|
---|
143 | {
|
---|
144 | /* Make sure that is one of our tasks: */
|
---|
145 | if (pTask->type() != UITask::Type_DetailsPopulation)
|
---|
146 | return;
|
---|
147 |
|
---|
148 | /* Skip unrelated tasks: */
|
---|
149 | if (m_pTask != pTask)
|
---|
150 | return;
|
---|
151 |
|
---|
152 | /* Assign new text if changed: */
|
---|
153 | const UITextTable newText = qobject_cast<UIDetailsUpdateTask*>(pTask)->table();
|
---|
154 | if (text() != newText)
|
---|
155 | setText(newText);
|
---|
156 |
|
---|
157 | /* Mark task processed: */
|
---|
158 | m_pTask = 0;
|
---|
159 |
|
---|
160 | /* Notify listeners about update task complete: */
|
---|
161 | emit sigBuildDone();
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | UIDetailsElementPreview::UIDetailsElementPreview(UIDetailsSet *pParent, bool fOpened)
|
---|
166 | : UIDetailsElement(pParent, DetailsElementType_Preview, fOpened)
|
---|
167 | {
|
---|
168 | /* Create preview: */
|
---|
169 | m_pPreview = new UIMachinePreview(this);
|
---|
170 | AssertPtr(m_pPreview);
|
---|
171 | {
|
---|
172 | /* Configure preview: */
|
---|
173 | connect(m_pPreview, &UIMachinePreview::sigSizeHintChanged,
|
---|
174 | this, &UIDetailsElementPreview::sltPreviewSizeHintChanged);
|
---|
175 | }
|
---|
176 |
|
---|
177 | /* Translate finally: */
|
---|
178 | retranslateUi();
|
---|
179 | }
|
---|
180 |
|
---|
181 | void UIDetailsElementPreview::updateLayout()
|
---|
182 | {
|
---|
183 | /* Call to base-class: */
|
---|
184 | UIDetailsElement::updateLayout();
|
---|
185 |
|
---|
186 | /* Show/hide preview: */
|
---|
187 | if ((isClosed() || isAnimationRunning()) && m_pPreview->isVisible())
|
---|
188 | m_pPreview->hide();
|
---|
189 | if (!isClosed() && !isAnimationRunning() && !m_pPreview->isVisible())
|
---|
190 | m_pPreview->show();
|
---|
191 |
|
---|
192 | /* Layout Preview: */
|
---|
193 | const int iMargin = data(ElementData_Margin).toInt();
|
---|
194 | m_pPreview->setPos(iMargin, 2 * iMargin + minimumHeaderHeight());
|
---|
195 | m_pPreview->resize(m_pPreview->minimumSizeHint());
|
---|
196 | }
|
---|
197 |
|
---|
198 | void UIDetailsElementPreview::sltPreviewSizeHintChanged()
|
---|
199 | {
|
---|
200 | /* Recursively update size-hints: */
|
---|
201 | updateGeometry();
|
---|
202 | /* Update whole model layout: */
|
---|
203 | model()->updateLayout();
|
---|
204 | }
|
---|
205 |
|
---|
206 | void UIDetailsElementPreview::retranslateUi()
|
---|
207 | {
|
---|
208 | /* Assign corresponding name: */
|
---|
209 | setName(gpConverter->toString(elementType()));
|
---|
210 | }
|
---|
211 |
|
---|
212 | int UIDetailsElementPreview::minimumWidthHint() const
|
---|
213 | {
|
---|
214 | /* Prepare variables: */
|
---|
215 | int iMargin = data(ElementData_Margin).toInt();
|
---|
216 |
|
---|
217 | /* Calculating proposed width: */
|
---|
218 | int iProposedWidth = 0;
|
---|
219 |
|
---|
220 | /* Maximum between header width and preview width: */
|
---|
221 | iProposedWidth += qMax(minimumHeaderWidth(), m_pPreview->minimumSizeHint().toSize().width());
|
---|
222 |
|
---|
223 | /* Two margins: */
|
---|
224 | iProposedWidth += 2 * iMargin;
|
---|
225 |
|
---|
226 | /* Return result: */
|
---|
227 | return iProposedWidth;
|
---|
228 | }
|
---|
229 |
|
---|
230 | int UIDetailsElementPreview::minimumHeightHintForElement(bool fClosed) const
|
---|
231 | {
|
---|
232 | /* Prepare variables: */
|
---|
233 | int iMargin = data(ElementData_Margin).toInt();
|
---|
234 |
|
---|
235 | /* Calculating proposed height: */
|
---|
236 | int iProposedHeight = 0;
|
---|
237 |
|
---|
238 | /* Two margins: */
|
---|
239 | iProposedHeight += 2 * iMargin;
|
---|
240 |
|
---|
241 | /* Header height: */
|
---|
242 | iProposedHeight += minimumHeaderHeight();
|
---|
243 |
|
---|
244 | /* Element is opened? */
|
---|
245 | if (!fClosed)
|
---|
246 | {
|
---|
247 | iProposedHeight += iMargin;
|
---|
248 | iProposedHeight += m_pPreview->minimumSizeHint().toSize().height();
|
---|
249 | }
|
---|
250 | else
|
---|
251 | {
|
---|
252 | /* Additional height during animation: */
|
---|
253 | if (button()->isAnimationRunning())
|
---|
254 | iProposedHeight += additionalHeight();
|
---|
255 | }
|
---|
256 |
|
---|
257 | /* Return result: */
|
---|
258 | return iProposedHeight;
|
---|
259 | }
|
---|
260 |
|
---|
261 | void UIDetailsElementPreview::updateAppearance()
|
---|
262 | {
|
---|
263 | /* Call to base-class: */
|
---|
264 | UIDetailsElement::updateAppearance();
|
---|
265 |
|
---|
266 | /* Set new machine attribute directly: */
|
---|
267 | m_pPreview->setMachine(machine());
|
---|
268 | m_pPreview->resize(m_pPreview->minimumSizeHint());
|
---|
269 | emit sigBuildDone();
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | void UIDetailsUpdateTaskGeneral::run()
|
---|
274 | {
|
---|
275 | /* Acquire corresponding machine: */
|
---|
276 | CMachine comMachine = machine();
|
---|
277 | if (comMachine.isNull())
|
---|
278 | return;
|
---|
279 |
|
---|
280 | /* Generate details table: */
|
---|
281 | setTable(UIDetailsGenerator::generateMachineInformationGeneral(comMachine, m_fOptions));
|
---|
282 | }
|
---|
283 |
|
---|
284 | void UIDetailsUpdateTaskGeneralCloud::run()
|
---|
285 | {
|
---|
286 | /* Acquire corresponding machine: */
|
---|
287 | CCloudMachine comCloudMachine = cloudMachine();
|
---|
288 | if (comCloudMachine.isNull())
|
---|
289 | return;
|
---|
290 |
|
---|
291 | /* Generate details table: */
|
---|
292 | setTable(UIDetailsGenerator::generateMachineInformationGeneral(comCloudMachine, m_fOptions));
|
---|
293 | }
|
---|
294 |
|
---|
295 | UITask *UIDetailsElementGeneral::createUpdateTask()
|
---|
296 | {
|
---|
297 | return isLocal()
|
---|
298 | ? static_cast<UITask*>(new UIDetailsUpdateTaskGeneral(machine(), model()->optionsGeneral()))
|
---|
299 | : static_cast<UITask*>(new UIDetailsUpdateTaskGeneralCloud(cloudMachine(), model()->optionsGeneral()));
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | void UIDetailsUpdateTaskSystem::run()
|
---|
304 | {
|
---|
305 | /* Acquire corresponding machine: */
|
---|
306 | CMachine comMachine = machine();
|
---|
307 | if (comMachine.isNull())
|
---|
308 | return;
|
---|
309 |
|
---|
310 | /* Generate details table: */
|
---|
311 | setTable(UIDetailsGenerator::generateMachineInformationSystem(comMachine, m_fOptions));
|
---|
312 | }
|
---|
313 |
|
---|
314 | UITask *UIDetailsElementSystem::createUpdateTask()
|
---|
315 | {
|
---|
316 | return new UIDetailsUpdateTaskSystem(machine(), model()->optionsSystem());
|
---|
317 | }
|
---|
318 |
|
---|
319 |
|
---|
320 | void UIDetailsUpdateTaskDisplay::run()
|
---|
321 | {
|
---|
322 | /* Acquire corresponding machine: */
|
---|
323 | CMachine comMachine = machine();
|
---|
324 | if (comMachine.isNull())
|
---|
325 | return;
|
---|
326 |
|
---|
327 | /* Generate details table: */
|
---|
328 | setTable(UIDetailsGenerator::generateMachineInformationDisplay(comMachine, m_fOptions));
|
---|
329 | }
|
---|
330 |
|
---|
331 | UITask *UIDetailsElementDisplay::createUpdateTask()
|
---|
332 | {
|
---|
333 | return new UIDetailsUpdateTaskDisplay(machine(), model()->optionsDisplay());
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | void UIDetailsUpdateTaskStorage::run()
|
---|
338 | {
|
---|
339 | /* Acquire corresponding machine: */
|
---|
340 | CMachine comMachine = machine();
|
---|
341 | if (comMachine.isNull())
|
---|
342 | return;
|
---|
343 |
|
---|
344 | /* Generate details table: */
|
---|
345 | setTable(UIDetailsGenerator::generateMachineInformationStorage(comMachine, m_fOptions));
|
---|
346 | }
|
---|
347 |
|
---|
348 | UITask *UIDetailsElementStorage::createUpdateTask()
|
---|
349 | {
|
---|
350 | return new UIDetailsUpdateTaskStorage(machine(), model()->optionsStorage());
|
---|
351 | }
|
---|
352 |
|
---|
353 |
|
---|
354 | void UIDetailsUpdateTaskAudio::run()
|
---|
355 | {
|
---|
356 | /* Acquire corresponding machine: */
|
---|
357 | CMachine comMachine = machine();
|
---|
358 | if (comMachine.isNull())
|
---|
359 | return;
|
---|
360 |
|
---|
361 | /* Generate details table: */
|
---|
362 | setTable(UIDetailsGenerator::generateMachineInformationAudio(comMachine, m_fOptions));
|
---|
363 | }
|
---|
364 |
|
---|
365 | UITask *UIDetailsElementAudio::createUpdateTask()
|
---|
366 | {
|
---|
367 | return new UIDetailsUpdateTaskAudio(machine(), model()->optionsAudio());
|
---|
368 | }
|
---|
369 |
|
---|
370 | void UIDetailsUpdateTaskNetwork::run()
|
---|
371 | {
|
---|
372 | /* Acquire corresponding machine: */
|
---|
373 | CMachine comMachine = machine();
|
---|
374 | if (comMachine.isNull())
|
---|
375 | return;
|
---|
376 |
|
---|
377 | /* Generate details table: */
|
---|
378 | setTable(UIDetailsGenerator::generateMachineInformationNetwork(comMachine, m_fOptions));
|
---|
379 | }
|
---|
380 |
|
---|
381 | UITask *UIDetailsElementNetwork::createUpdateTask()
|
---|
382 | {
|
---|
383 | return new UIDetailsUpdateTaskNetwork(machine(), model()->optionsNetwork());
|
---|
384 | }
|
---|
385 |
|
---|
386 | void UIDetailsUpdateTaskSerial::run()
|
---|
387 | {
|
---|
388 | /* Acquire corresponding machine: */
|
---|
389 | CMachine comMachine = machine();
|
---|
390 | if (comMachine.isNull())
|
---|
391 | return;
|
---|
392 |
|
---|
393 | /* Generate details table: */
|
---|
394 | setTable(UIDetailsGenerator::generateMachineInformationSerial(comMachine, m_fOptions));
|
---|
395 | }
|
---|
396 |
|
---|
397 | UITask *UIDetailsElementSerial::createUpdateTask()
|
---|
398 | {
|
---|
399 | return new UIDetailsUpdateTaskSerial(machine(), model()->optionsSerial());
|
---|
400 | }
|
---|
401 |
|
---|
402 | void UIDetailsUpdateTaskUSB::run()
|
---|
403 | {
|
---|
404 | /* Acquire corresponding machine: */
|
---|
405 | CMachine comMachine = machine();
|
---|
406 | if (comMachine.isNull())
|
---|
407 | return;
|
---|
408 |
|
---|
409 | /* Generate details table: */
|
---|
410 | setTable(UIDetailsGenerator::generateMachineInformationUSB(comMachine, m_fOptions));
|
---|
411 | }
|
---|
412 |
|
---|
413 | UITask *UIDetailsElementUSB::createUpdateTask()
|
---|
414 | {
|
---|
415 | return new UIDetailsUpdateTaskUSB(machine(), model()->optionsUsb());
|
---|
416 | }
|
---|
417 |
|
---|
418 |
|
---|
419 | void UIDetailsUpdateTaskSF::run()
|
---|
420 | {
|
---|
421 | /* Acquire corresponding machine: */
|
---|
422 | CMachine comMachine = machine();
|
---|
423 | if (comMachine.isNull())
|
---|
424 | return;
|
---|
425 |
|
---|
426 | /* Generate details table: */
|
---|
427 | setTable(UIDetailsGenerator::generateMachineInformationSharedFolders(comMachine, m_fOptions));
|
---|
428 | }
|
---|
429 |
|
---|
430 | UITask *UIDetailsElementSF::createUpdateTask()
|
---|
431 | {
|
---|
432 | return new UIDetailsUpdateTaskSF(machine(), model()->optionsSharedFolders());
|
---|
433 | }
|
---|
434 |
|
---|
435 |
|
---|
436 | void UIDetailsUpdateTaskUI::run()
|
---|
437 | {
|
---|
438 | /* Acquire corresponding machine: */
|
---|
439 | CMachine comMachine = machine();
|
---|
440 | if (comMachine.isNull())
|
---|
441 | return;
|
---|
442 |
|
---|
443 | /* Generate details table: */
|
---|
444 | setTable(UIDetailsGenerator::generateMachineInformationUI(comMachine, m_fOptions));
|
---|
445 | }
|
---|
446 |
|
---|
447 | UITask *UIDetailsElementUI::createUpdateTask()
|
---|
448 | {
|
---|
449 | return new UIDetailsUpdateTaskUI(machine(), model()->optionsUserInterface());
|
---|
450 | }
|
---|
451 |
|
---|
452 |
|
---|
453 | void UIDetailsUpdateTaskDescription::run()
|
---|
454 | {
|
---|
455 | /* Acquire corresponding machine: */
|
---|
456 | CMachine comMachine = machine();
|
---|
457 | if (comMachine.isNull())
|
---|
458 | return;
|
---|
459 |
|
---|
460 | /* Generate details table: */
|
---|
461 | setTable(UIDetailsGenerator::generateMachineInformationDescription(comMachine, m_fOptions));
|
---|
462 | }
|
---|
463 |
|
---|
464 | UITask *UIDetailsElementDescription::createUpdateTask()
|
---|
465 | {
|
---|
466 | return new UIDetailsUpdateTaskDescription(machine(), model()->optionsDescription());
|
---|
467 | }
|
---|