VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp@ 100064

Last change on this file since 100064 was 100064, checked in by vboxsync, 18 months ago

FE/Qt: bugref:10421. Replacing VBOX_WS_X11 with VBOX_WS_NIX.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 100.7 KB
Line 
1/* $Id: UISession.cpp 100064 2023-06-04 09:10:01Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UISession class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-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 <QApplication>
30#include <QRegExp>
31#include <QWidget>
32
33/* GUI includes: */
34#include "UIActionPoolRuntime.h"
35#include "UICommon.h"
36#include "UIConsoleEventHandler.h"
37#include "UIConverter.h"
38#include "UIDetailsGenerator.h"
39#include "UIExtraDataManager.h"
40#include "UIFrameBuffer.h"
41#include "UIIconPool.h"
42#include "UIMachine.h"
43#include "UIMachineLogic.h"
44#include "UIMachineView.h"
45#include "UIMachineWindow.h"
46#include "UIMedium.h"
47#include "UIMessageCenter.h"
48#include "UIModalWindowManager.h"
49#include "UIMousePointerShapeData.h"
50#include "UINotificationCenter.h"
51#include "UISession.h"
52#include "UISettingsDialogSpecific.h"
53#include "UITextTable.h"
54#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
55# include "UIKeyboardHandler.h"
56# include <signal.h>
57#endif
58
59/* COM includes: */
60#include "CAudioAdapter.h"
61#include "CAudioSettings.h"
62#include "CEmulatedUSB.h"
63#include "CGraphicsAdapter.h"
64#include "CHostNetworkInterface.h"
65#include "CHostUSBDevice.h"
66#include "CHostVideoInputDevice.h"
67#include "CMedium.h"
68#include "CMediumAttachment.h"
69#include "CRecordingSettings.h"
70#include "CSnapshot.h"
71#include "CStorageController.h"
72#include "CSystemProperties.h"
73#include "CUSBController.h"
74#include "CUSBDevice.h"
75#include "CUSBDeviceFilter.h"
76#include "CUSBDeviceFilters.h"
77#include "CVRDEServer.h"
78#include "CVRDEServerInfo.h"
79#ifdef VBOX_WITH_NETFLT
80# include "CNetworkAdapter.h"
81#endif
82
83/* Other VBox includes: */
84#ifdef VBOX_WITH_DEBUGGER_GUI
85# include <VBox/dbggui.h>
86# include <iprt/ldr.h>
87#endif
88
89/* VirtualBox interface declarations: */
90#include <VBox/com/VirtualBox.h>
91
92/* External includes: */
93#ifdef VBOX_WS_NIX
94# include <X11/Xlib.h>
95# include <X11/Xutil.h>
96#endif
97
98
99#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
100static void signalHandlerSIGUSR1(int sig, siginfo_t *, void *);
101#endif
102
103UISession::UISession(UIMachine *pMachine)
104 : QObject(pMachine)
105 /* Base variables: */
106 , m_pMachine(pMachine)
107 , m_fValid(false)
108 , m_pConsoleEventhandler(0)
109 /* Common variables: */
110 , m_enmMachineStatePrevious(KMachineState_Null)
111 , m_enmMachineState(KMachineState_Null)
112 /* Guest additions flags: */
113 , m_ulGuestAdditionsRunLevel(0)
114 , m_fIsGuestSupportsGraphics(false)
115 , m_fIsGuestSupportsSeamless(false)
116#ifdef VBOX_WITH_DEBUGGER_GUI
117 /* Debug UI stuff: */
118 , m_pDbgGui(0)
119 , m_pDbgGuiVT(0)
120#endif /* VBOX_WITH_DEBUGGER_GUI */
121{
122}
123
124bool UISession::prepare()
125{
126 /* Prepare COM stuff: */
127 if (!prepareCOMStuff())
128 return false;
129
130 /* Cache media early if requested: */
131 if (uiCommon().agressiveCaching())
132 recacheMachineMedia();
133
134 /* Prepare GUI stuff: */
135 prepareConsoleEventHandlers();
136 prepareFramebuffers();
137 prepareConnections();
138 prepareSignalHandling();
139
140 /* True by default: */
141 return true;
142}
143
144bool UISession::initialize()
145{
146 /* Preprocess initialization: */
147 if (!preprocessInitialization())
148 return false;
149
150 /* Notify user about mouse&keyboard auto-capturing: */
151 if (gEDataManager->autoCaptureEnabled())
152 UINotificationMessage::remindAboutAutoCapture();
153
154 m_enmMachineState = machine().GetState();
155
156 /* Apply debug settings from the command line. */
157 if (!debugger().isNull() && debugger().isOk())
158 {
159 if (uiCommon().areWeToExecuteAllInIem())
160 debugger().SetExecuteAllInIEM(true);
161 if (!uiCommon().isDefaultWarpPct())
162 debugger().SetVirtualTimeRate(uiCommon().getWarpPct());
163 }
164
165 /* Apply ad-hoc reconfigurations from the command line: */
166 if (uiCommon().hasFloppyImageToMount())
167 mountAdHocImage(KDeviceType_Floppy, UIMediumDeviceType_Floppy, uiCommon().getFloppyImage().toString());
168 if (uiCommon().hasDvdImageToMount())
169 mountAdHocImage(KDeviceType_DVD, UIMediumDeviceType_DVD, uiCommon().getDvdImage().toString());
170
171 /* Power UP if this is NOT separate process: */
172 if (!uiCommon().isSeparateProcess())
173 if (!powerUp())
174 return false;
175
176 /* Make sure all the pending Console events converted to signals
177 * during the powerUp() progress above reached their destinations.
178 * That is necessary to make sure all the pending machine state change events processed.
179 * We can't just use the machine state directly acquired from IMachine because there
180 * will be few places which are using stale machine state, not just this one. */
181 QApplication::sendPostedEvents(0, QEvent::MetaCall);
182
183 /* Check if we missed a really quick termination after successful startup: */
184 if (isTurnedOff())
185 {
186 LogRel(("GUI: Aborting startup due to invalid machine state detected: %d\n", machineState()));
187 return false;
188 }
189
190 /* Fetch corresponding states: */
191 if (uiCommon().isSeparateProcess())
192 sltAdditionsChange();
193
194#ifdef VBOX_GUI_WITH_PIDFILE
195 uiCommon().createPidfile();
196#endif /* VBOX_GUI_WITH_PIDFILE */
197
198 /* Mark as valid finally: */
199 m_fValid = true;
200
201 /* True by default: */
202 return true;
203}
204
205bool UISession::powerUp()
206{
207 /* Power UP machine: */
208 CProgress comProgress = uiCommon().shouldStartPaused() ? console().PowerUpPaused() : console().PowerUp();
209
210 /* Check for immediate failure: */
211 if (!console().isOk() || comProgress.isNull())
212 {
213 if (uiCommon().showStartVMErrors())
214 msgCenter().cannotStartMachine(console(), machineName());
215 LogRel(("GUI: Aborting startup due to power up issue detected...\n"));
216 return false;
217 }
218
219 /* Some logging right after we powered up: */
220 LogRel(("GUI: Qt version: %s\n", UICommon::qtRTVersionString().toUtf8().constData()));
221#ifdef VBOX_WS_NIX
222 LogRel(("GUI: X11 Window Manager code: %d\n", (int)uiCommon().typeOfWindowManager()));
223#endif
224#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
225 LogRel(("GUI: HID LEDs sync is %s\n", uimachine()->isHidLedsSyncEnabled() ? "enabled" : "disabled"));
226#else
227 LogRel(("GUI: HID LEDs sync is not supported on this platform\n"));
228#endif
229
230 /* Enable 'manual-override',
231 * preventing automatic Runtime UI closing
232 * and visual representation mode changes: */
233 uimachine()->setManualOverrideMode(true);
234
235 /* Show "Starting/Restoring" progress dialog: */
236 if (isSaved())
237 {
238 msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_state_restore_90px.png", 0, 0);
239 /* After restoring from 'saved' state, machine-window(s) geometry should be adjusted: */
240 machineLogic()->adjustMachineWindowsGeometry();
241 }
242 else
243 {
244#ifdef VBOX_IS_QT6_OR_LATER /** @todo why is this any problem on qt6? */
245 msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_start_90px.png", 0, 0);
246#else
247 msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_start_90px.png");
248#endif
249 /* After VM start, machine-window(s) size-hint(s) should be sent: */
250 machineLogic()->sendMachineWindowsSizeHints();
251 }
252
253 /* Check for progress failure: */
254 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
255 {
256 if (uiCommon().showStartVMErrors())
257 msgCenter().cannotStartMachine(comProgress, machineName());
258 LogRel(("GUI: Aborting startup due to power up progress issue detected...\n"));
259 return false;
260 }
261
262 /* Disable 'manual-override' finally: */
263 uimachine()->setManualOverrideMode(false);
264
265 /* True by default: */
266 return true;
267}
268
269WId UISession::mainMachineWindowId() const
270{
271 return mainMachineWindow() ? mainMachineWindow()->winId() : 0;
272}
273
274void UISession::acquireMachinePixmap(const QSize &size, QPixmap &pixmap)
275{
276 QPixmap machinePixmap;
277 if (machine().isNotNull())
278 machinePixmap = generalIconPool().userMachinePixmap(machine(), size);
279 if (machinePixmap.isNull())
280 machinePixmap = generalIconPool().guestOSTypePixmap(osTypeId(), size);
281 if (!machinePixmap.isNull())
282 pixmap = machinePixmap;
283}
284
285void UISession::acquireUserMachineIcon(QIcon &icon)
286{
287 QIcon machineIcon;
288 if (machine().isNotNull())
289 machineIcon = generalIconPool().userMachineIcon(machine());
290 if (machineIcon.isNull())
291 machineIcon = generalIconPool().guestOSTypeIcon(osTypeId());
292 if (machineIcon.isNull())
293 machineIcon = QIcon(":/VirtualBox_48px.png");
294 if (!machineIcon.isNull())
295 icon = machineIcon;
296}
297
298bool UISession::acquireChipsetType(KChipsetType &enmType)
299{
300 CMachine comMachine = machine();
301 if (comMachine.isNull())
302 return false;
303 const KChipsetType enmChipsetType = comMachine.GetChipsetType();
304 const bool fSuccess = comMachine.isOk();
305 if (!fSuccess)
306 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
307 else
308 enmType = enmChipsetType;
309 return fSuccess;
310}
311
312bool UISession::acquireLiveMachineState(KMachineState &enmState)
313{
314 CMachine comMachine = machine();
315 if (comMachine.isNull())
316 return false;
317 const KMachineState enmMachineState = comMachine.GetState();
318 const bool fSuccess = comMachine.isOk();
319 if (!fSuccess)
320 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
321 else
322 enmState = enmMachineState;
323 return fSuccess;
324}
325
326bool UISession::reset()
327{
328 CConsole comConsole = console();
329 comConsole.Reset();
330 const bool fSuccess = comConsole.isOk();
331 if (!fSuccess)
332 UINotificationMessage::cannotResetMachine(comConsole);
333 return fSuccess;
334}
335
336bool UISession::setPause(bool fPause)
337{
338 CConsole comConsole = console();
339 if (fPause)
340 comConsole.Pause();
341 else
342 comConsole.Resume();
343 const bool fSuccess = comConsole.isOk();
344 if (!fSuccess)
345 {
346 if (fPause)
347 UINotificationMessage::cannotPauseMachine(comConsole);
348 else
349 UINotificationMessage::cannotResumeMachine(comConsole);
350 }
351 return fSuccess;
352}
353
354bool UISession::acquireSettingsFilePath(QString &strPath)
355{
356 CMachine comMachine = machine();
357 const QString strSettingsFilePath = comMachine.GetSettingsFilePath();
358 const bool fSuccess = comMachine.isOk();
359 if (!fSuccess)
360 UINotificationMessage::cannotSaveMachineSettings(comMachine);
361 else
362 strPath = strSettingsFilePath;
363 return fSuccess;
364}
365
366bool UISession::saveSettings()
367{
368 CMachine comMachine = machine();
369 comMachine.SaveSettings();
370 const bool fSuccess = comMachine.isOk();
371 if (!fSuccess)
372 UINotificationMessage::cannotSaveMachineSettings(comMachine);
373 return fSuccess;
374}
375
376bool UISession::acquireSnapshotCount(ulong &uCount)
377{
378 CMachine comMachine = machine();
379 const ULONG uSnapshotCount = comMachine.GetSnapshotCount();
380 const bool fSuccess = comMachine.isOk();
381 if (!fSuccess)
382 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
383 else
384 uCount = uSnapshotCount;
385 return fSuccess;
386}
387
388bool UISession::acquireCurrentSnapshotName(QString &strName)
389{
390 CMachine comMachine = machine();
391 CSnapshot comSnapshot = comMachine.GetCurrentSnapshot();
392 bool fSuccess = comMachine.isOk();
393 if (!fSuccess)
394 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
395 {
396 const QString strSnapshotName = comSnapshot.GetName();
397 fSuccess = comSnapshot.isOk();
398 if (!fSuccess)
399 UINotificationMessage::cannotAcquireSnapshotParameter(comSnapshot);
400 else
401 strName = strSnapshotName;
402 }
403 return fSuccess;
404}
405
406bool UISession::acquireMaxSnapshotIndex(const QString &strNameTemplate, ulong &uIndex)
407{
408 CMachine comMachine = machine();
409 CSnapshot comSnapshot = comMachine.FindSnapshot(QString());
410 return searchMaxSnapshotIndex(comMachine, comSnapshot, strNameTemplate, uIndex);
411}
412
413void UISession::takeSnapshot(const QString &strName, const QString &strDescription)
414{
415 CMachine comMachine = machine();
416 UINotificationProgressSnapshotTake *pNotification = new UINotificationProgressSnapshotTake(comMachine,
417 strName,
418 strDescription);
419 gpNotificationCenter->append(pNotification);
420}
421
422bool UISession::putScancode(LONG iCode)
423{
424 CKeyboard comKeyboard = keyboard();
425 comKeyboard.PutScancode(iCode);
426 const bool fSuccess = comKeyboard.isOk();
427 if (!fSuccess)
428 UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
429 return fSuccess;
430}
431
432bool UISession::putScancodes(const QVector<LONG> &codes)
433{
434 CKeyboard comKeyboard = keyboard();
435 if (comKeyboard.isNull())
436 return false;
437 comKeyboard.PutScancodes(codes);
438 const bool fSuccess = comKeyboard.isOk();
439 if (!fSuccess)
440 UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
441 return fSuccess;
442}
443
444bool UISession::putCAD()
445{
446 CKeyboard comKeyboard = keyboard();
447 comKeyboard.PutCAD();
448 const bool fSuccess = comKeyboard.isOk();
449 if (!fSuccess)
450 UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
451 return fSuccess;
452}
453
454bool UISession::releaseKeys()
455{
456 CKeyboard comKeyboard = keyboard();
457 comKeyboard.ReleaseKeys();
458 const bool fSuccess = comKeyboard.isOk();
459 if (!fSuccess)
460 UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
461 return fSuccess;
462}
463
464bool UISession::putUsageCode(LONG iUsageCode, LONG iUsagePage, bool fKeyRelease)
465{
466 CKeyboard comKeyboard = keyboard();
467 comKeyboard.PutUsageCode(iUsageCode, iUsagePage, fKeyRelease);
468 const bool fSuccess = comKeyboard.isOk();
469 if (!fSuccess)
470 UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
471 return fSuccess;
472}
473
474bool UISession::acquireWhetherAbsoluteSupported(bool &fSupported)
475{
476 CMouse comMouse = mouse();
477 if (comMouse.isNull())
478 return false;
479 const BOOL fAbsoluteSupported = comMouse.GetAbsoluteSupported();
480 const bool fSuccess = comMouse.isOk();
481 if (!fSuccess)
482 UINotificationMessage::cannotAcquireMouseParameter(comMouse);
483 else
484 fSupported = fAbsoluteSupported == TRUE;
485 return fSuccess;
486}
487
488bool UISession::acquireWhetherRelativeSupported(bool &fSupported)
489{
490 CMouse comMouse = mouse();
491 if (comMouse.isNull())
492 return false;
493 const BOOL fRelativeSupported = comMouse.GetRelativeSupported();
494 const bool fSuccess = comMouse.isOk();
495 if (!fSuccess)
496 UINotificationMessage::cannotAcquireMouseParameter(comMouse);
497 else
498 fSupported = fRelativeSupported == TRUE;
499 return fSuccess;
500}
501
502bool UISession::acquireWhetherTouchScreenSupported(bool &fSupported)
503{
504 CMouse comMouse = mouse();
505 if (comMouse.isNull())
506 return false;
507 const BOOL fTouchScreenSupported = comMouse.GetTouchScreenSupported();
508 const bool fSuccess = comMouse.isOk();
509 if (!fSuccess)
510 UINotificationMessage::cannotAcquireMouseParameter(comMouse);
511 else
512 fSupported = fTouchScreenSupported == TRUE;
513 return fSuccess;
514}
515
516bool UISession::acquireWhetherTouchPadSupported(bool &fSupported)
517{
518 CMouse comMouse = mouse();
519 if (comMouse.isNull())
520 return false;
521 const BOOL fTouchPadSupported = comMouse.GetTouchPadSupported();
522 const bool fSuccess = comMouse.isOk();
523 if (!fSuccess)
524 UINotificationMessage::cannotAcquireMouseParameter(comMouse);
525 else
526 fSupported = fTouchPadSupported == TRUE;
527 return fSuccess;
528}
529
530bool UISession::acquireWhetherNeedsHostCursor(bool &fNeeds)
531{
532 CMouse comMouse = mouse();
533 if (comMouse.isNull())
534 return false;
535 const BOOL fNeedsHostCursor = comMouse.GetNeedsHostCursor();
536 const bool fSuccess = comMouse.isOk();
537 if (!fSuccess)
538 UINotificationMessage::cannotAcquireMouseParameter(comMouse);
539 else
540 fNeeds = fNeedsHostCursor == TRUE;
541 return fSuccess;
542}
543
544bool UISession::putMouseEvent(long iDx, long iDy, long iDz, long iDw, long iButtonState)
545{
546 CMouse comMouse = mouse();
547 if (comMouse.isNull())
548 return false;
549 comMouse.PutMouseEvent(iDx, iDy, iDz, iDw, iButtonState);
550 const bool fSuccess = comMouse.isOk();
551 if (!fSuccess)
552 UINotificationMessage::cannotChangeMouseParameter(comMouse);
553 return fSuccess;
554}
555
556bool UISession::putMouseEventAbsolute(long iX, long iY, long iDz, long iDw, long iButtonState)
557{
558 CMouse comMouse = mouse();
559 if (comMouse.isNull())
560 return false;
561 comMouse.PutMouseEventAbsolute(iX, iY, iDz, iDw, iButtonState);
562 const bool fSuccess = comMouse.isOk();
563 if (!fSuccess)
564 UINotificationMessage::cannotChangeMouseParameter(comMouse);
565 return fSuccess;
566}
567
568bool UISession::putEventMultiTouch(long iCount, const QVector<LONG64> &contacts, bool fIsTouchScreen, ulong uScanTime)
569{
570 CMouse comMouse = mouse();
571 if (comMouse.isNull())
572 return false;
573 comMouse.PutEventMultiTouch(iCount, contacts, fIsTouchScreen, uScanTime);
574 const bool fSuccess = comMouse.isOk();
575 if (!fSuccess)
576 UINotificationMessage::cannotChangeMouseParameter(comMouse);
577 return fSuccess;
578}
579
580bool UISession::acquireClipboardMode(KClipboardMode &enmMode)
581{
582 CMachine comMachine = machine();
583 if (comMachine.isNull())
584 return false;
585 const KClipboardMode enmClipboardMode = comMachine.GetClipboardMode();
586 const bool fSuccess = comMachine.isOk();
587 if (!fSuccess)
588 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
589 else
590 enmMode = enmClipboardMode;
591 return fSuccess;
592}
593
594bool UISession::setClipboardMode(KClipboardMode enmMode)
595{
596 CMachine comMachine = machine();
597 comMachine.SetClipboardMode(enmMode);
598 const bool fSuccess = comMachine.isOk();
599 if (!fSuccess)
600 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
601 return fSuccess;
602}
603
604bool UISession::acquireDnDMode(KDnDMode &enmMode)
605{
606 CMachine comMachine = machine();
607 if (comMachine.isNull())
608 return false;
609 const KDnDMode enmDnDMode = comMachine.GetDnDMode();
610 const bool fSuccess = comMachine.isOk();
611 if (!fSuccess)
612 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
613 else
614 enmMode = enmDnDMode;
615 return fSuccess;
616}
617
618bool UISession::setDnDMode(KDnDMode enmMode)
619{
620 CMachine comMachine = machine();
621 comMachine.SetDnDMode(enmMode);
622 const bool fSuccess = comMachine.isOk();
623 if (!fSuccess)
624 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
625 return fSuccess;
626}
627
628bool UISession::acquireAmountOfStorageDevices(ulong &cHardDisks, ulong &cOpticalDrives, ulong &cFloppyDrives)
629{
630 const CMachine comMachine = machine();
631 if (comMachine.isNull())
632 return false;
633 ulong cActualHardDisks = 0, cActualOpticalDrives = 0, cActualFloppyDrives = 0;
634 const CMediumAttachmentVector comAttachments = comMachine.GetMediumAttachments();
635 bool fSuccess = comMachine.isOk();
636 if (!fSuccess)
637 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
638 else
639 {
640 foreach (const CMediumAttachment &comAttachment, comAttachments)
641 {
642 /* Get device type: */
643 const KDeviceType enmDeviceType = comAttachment.GetType();
644 fSuccess = comAttachment.isOk();
645 if (!fSuccess)
646 {
647 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
648 break;
649 }
650
651 /* And advance corresponding amount: */
652 switch (enmDeviceType)
653 {
654 case KDeviceType_HardDisk: ++cActualHardDisks; break;
655 case KDeviceType_DVD: ++cActualOpticalDrives; break;
656 case KDeviceType_Floppy: ++cActualFloppyDrives; break;
657 default: break;
658 }
659 }
660 }
661 if (fSuccess)
662 {
663 cHardDisks = cActualHardDisks;
664 cOpticalDrives = cActualOpticalDrives;
665 cFloppyDrives = cActualFloppyDrives;
666 }
667 return fSuccess;
668}
669
670bool UISession::storageDevices(KDeviceType enmActualDeviceType, QList<StorageDeviceInfo> &guiStorageDevices)
671{
672 const CMachine comMachine = machine();
673 const CMediumAttachmentVector comAttachments = comMachine.GetMediumAttachments();
674 bool fSuccess = comMachine.isOk();
675 if (!fSuccess)
676 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
677 else
678 {
679 foreach (const CMediumAttachment &comAttachment, comAttachments)
680 {
681 /* Get device type: */
682 const KDeviceType enmDeviceType = comAttachment.GetType();
683 fSuccess = comAttachment.isOk();
684 if (!fSuccess)
685 {
686 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
687 break;
688 }
689 /* And make sure it's actual one: */
690 if (enmDeviceType != enmActualDeviceType)
691 continue;
692
693 /* Get controller name: */
694 const QString strControllerName = comAttachment.GetController();
695 fSuccess = comAttachment.isOk();
696 if (!fSuccess)
697 {
698 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
699 break;
700 }
701 /* And search for it's presence: */
702 const CStorageController comController = comMachine.GetStorageControllerByName(strControllerName);
703 fSuccess = comMachine.isOk();
704 if (!fSuccess)
705 {
706 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
707 break;
708 }
709
710 /* Fill structure fields: */
711 StorageDeviceInfo guiStorageDevice;
712 guiStorageDevice.m_strControllerName = strControllerName; // already confirmed
713 const KStorageBus enmStorageBus = comController.GetBus();
714 fSuccess = comController.isOk();
715 if (!fSuccess)
716 {
717 UINotificationMessage::cannotAcquireStorageControllerParameter(comController);
718 break;
719 }
720 switch (enmStorageBus)
721 {
722 case KStorageBus_IDE: guiStorageDevice.m_icon = UIIconPool::iconSet(":/ide_16px.png"); break;
723 case KStorageBus_SATA: guiStorageDevice.m_icon = UIIconPool::iconSet(":/sata_16px.png"); break;
724 case KStorageBus_SCSI: guiStorageDevice.m_icon = UIIconPool::iconSet(":/scsi_16px.png"); break;
725 case KStorageBus_Floppy: guiStorageDevice.m_icon = UIIconPool::iconSet(":/floppy_16px.png"); break;
726 case KStorageBus_SAS: guiStorageDevice.m_icon = UIIconPool::iconSet(":/sas_16px.png"); break;
727 case KStorageBus_USB: guiStorageDevice.m_icon = UIIconPool::iconSet(":/usb_16px.png"); break;
728 case KStorageBus_PCIe: guiStorageDevice.m_icon = UIIconPool::iconSet(":/pcie_16px.png"); break;
729 case KStorageBus_VirtioSCSI: guiStorageDevice.m_icon = UIIconPool::iconSet(":/virtio_scsi_16px.png"); break;
730 default: break;
731 }
732 const long iPort = comAttachment.GetPort();
733 fSuccess = comAttachment.isOk();
734 if (!fSuccess)
735 {
736 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
737 break;
738 }
739 const long iDevice = comAttachment.GetDevice();
740 fSuccess = comAttachment.isOk();
741 if (!fSuccess)
742 {
743 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
744 break;
745 }
746 if (fSuccess)
747 {
748 const StorageSlot guiStorageSlot(enmStorageBus, iPort, iDevice);
749 guiStorageDevice.m_guiStorageSlot = guiStorageSlot;
750 }
751
752 /* Append or break if necessary: */
753 if (fSuccess)
754 guiStorageDevices << guiStorageDevice;
755 else
756 break;
757 }
758 }
759 return fSuccess;
760}
761
762bool UISession::acquireEncryptedMedia(EncryptedMediumMap &media)
763{
764 EncryptedMediumMap encryptedMedia;
765 CMachine comMachine = machine();
766 const CMediumAttachmentVector comAttachments = comMachine.GetMediumAttachments();
767 bool fSuccess = comMachine.isOk();
768 if (!fSuccess)
769 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
770 else
771 {
772 foreach (const CMediumAttachment &comAttachment, comAttachments)
773 {
774 const KDeviceType enmType = comAttachment.GetType();
775 fSuccess = comAttachment.isOk();
776 if (!fSuccess)
777 {
778 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
779 break;
780 }
781
782 /* Look for hard-drive attachments only: */
783 if (enmType != KDeviceType_HardDisk)
784 continue;
785
786 /* Get the attachment medium: */
787 const CMedium comMedium = comAttachment.GetMedium();
788 fSuccess = comAttachment.isOk();
789 if (!fSuccess)
790 {
791 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
792 break;
793 }
794
795 /* Get the medium ID: */
796 const QUuid uId = comMedium.GetId();
797 fSuccess = comMedium.isOk();
798 if (!fSuccess)
799 {
800 UINotificationMessage::cannotAcquireMediumParameter(comMedium);
801 break;
802 }
803
804 /* Update the map with this medium if it's encrypted: */
805 QString strCipher;
806 const QString strPasswordId = comMedium.GetEncryptionSettings(strCipher);
807 if (comMedium.isOk()) // GetEncryptionSettings failure is a valid case
808 encryptedMedia.insert(strPasswordId, uId);
809 }
810 }
811
812 if (fSuccess)
813 media = encryptedMedia;
814 return fSuccess;
815}
816
817bool UISession::addEncryptionPassword(const QString &strId, const QString &strPassword, bool fClearOnSuspend)
818{
819 CConsole comConsole = console();
820 comConsole.AddEncryptionPassword(strId, strPassword, fClearOnSuspend);
821 const bool fSuccess = comConsole.isOk();
822 if (!fSuccess)
823 msgCenter().cannotAddDiskEncryptionPassword(comConsole);
824 return fSuccess;
825}
826
827bool UISession::acquireAmountOfImmutableImages(ulong &cAmount)
828{
829 CMachine comMachine = machine();
830 return UICommon::acquireAmountOfImmutableImages(comMachine, cAmount);
831}
832
833bool UISession::mountBootMedium(const QUuid &uMediumId)
834{
835 AssertReturn(!uMediumId.isNull(), false);
836
837 /* Get recommended controller bus & type: */
838 CVirtualBox comVBox = uiCommon().virtualBox();
839 const CGuestOSType comOsType = comVBox.GetGuestOSType(osTypeId());
840 if (!comVBox.isOk())
841 {
842 UINotificationMessage::cannotAcquireVirtualBoxParameter(comVBox);
843 return false;
844 }
845 const KStorageBus enmRecommendedDvdBus = comOsType.GetRecommendedDVDStorageBus();
846 if (!comOsType.isOk())
847 {
848 UINotificationMessage::cannotAcquireGuestOSTypeParameter(comOsType);
849 return false;
850 }
851 const KStorageControllerType enmRecommendedDvdType = comOsType.GetRecommendedDVDStorageController();
852 if (!comOsType.isOk())
853 {
854 UINotificationMessage::cannotAcquireGuestOSTypeParameter(comOsType);
855 return false;
856 }
857
858 /* Search for an attachment of required bus & type: */
859 CMachine comMachine = machine();
860 CMediumAttachmentVector comMediumAttachments = comMachine.GetMediumAttachments();
861 bool fSuccess = comMachine.isOk();
862 if (!fSuccess)
863 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
864 else
865 {
866 CMediumAttachment comChosenAttachment;
867 QString strChosenControllerName;
868 LONG iChosenAttachmentPort = 0;
869 LONG iChosenAttachmentDevice = 0;
870 foreach (const CMediumAttachment &comAttachment, comMediumAttachments)
871 {
872 /* Get attachment type: */
873 const KDeviceType enmCurrentDeviceType = comAttachment.GetType();
874 fSuccess = comAttachment.isOk();
875 if (!fSuccess)
876 {
877 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
878 break;
879 }
880 /* And make sure it's DVD: */
881 if (enmCurrentDeviceType != KDeviceType_DVD)
882 continue;
883
884 /* Get controller name: */
885 const QString strControllerName = comAttachment.GetController();
886 fSuccess = comAttachment.isOk();
887 if (!fSuccess)
888 {
889 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
890 break;
891 }
892 /* And look for corresponding controller: */
893 const CStorageController comCurrentController = comMachine.GetStorageControllerByName(strControllerName);
894 fSuccess = comMachine.isOk();
895 if (!fSuccess)
896 {
897 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
898 break;
899 }
900
901 /* Get current controller bus: */
902 const KStorageBus enmCurrentBus = comCurrentController.GetBus();
903 fSuccess = comCurrentController.isOk();
904 if (!fSuccess)
905 {
906 UINotificationMessage::cannotAcquireStorageControllerParameter(comCurrentController);
907 break;
908 }
909 /* Get current controller type: */
910 const KStorageControllerType enmCurrentType = comCurrentController.GetControllerType();
911 fSuccess = comCurrentController.isOk();
912 if (!fSuccess)
913 {
914 UINotificationMessage::cannotAcquireStorageControllerParameter(comCurrentController);
915 break;
916 }
917 /* And check if they are suitable: */
918 if ( enmCurrentBus != enmRecommendedDvdBus
919 || enmCurrentType != enmRecommendedDvdType)
920 continue;
921
922 /* Get current attachment port: */
923 iChosenAttachmentPort = comAttachment.GetPort();
924 fSuccess = comAttachment.isOk();
925 if (!fSuccess)
926 {
927 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
928 break;
929 }
930 /* Get current attachment device: */
931 iChosenAttachmentDevice = comAttachment.GetDevice();
932 fSuccess = comAttachment.isOk();
933 if (!fSuccess)
934 {
935 UINotificationMessage::cannotAcquireMediumAttachmentParameter(comAttachment);
936 break;
937 }
938
939 /* Everything is nice it seems: */
940 comChosenAttachment = comAttachment;
941 strChosenControllerName = strControllerName;
942 break;
943 }
944 AssertMsgReturn(!comChosenAttachment.isNull(), ("Storage Controller is NOT properly configured!\n"), false);
945
946 /* Get medium to mount: */
947 const UIMedium guiMedium = uiCommon().medium(uMediumId);
948 const CMedium comMedium = guiMedium.medium();
949
950 /* Mount medium to the predefined port/device: */
951 comMachine.MountMedium(strChosenControllerName,
952 iChosenAttachmentPort, iChosenAttachmentDevice,
953 comMedium, false /* force */);
954 fSuccess = comMachine.isOk();
955 if (!fSuccess)
956 {
957 QWidget *pParent = windowManager().realParentWindow(activeMachineWindow());
958 msgCenter().cannotRemountMedium(machine(), guiMedium, true /* mount? */, false /* retry? */, pParent);
959 }
960 else
961 fSuccess = saveSettings();
962 }
963
964 return fSuccess;
965}
966
967void UISession::prepareStorageMenu(QMenu *pMenu,
968 QObject *pListener, const char *pszSlotName,
969 const QString &strControllerName, const StorageSlot &storageSlot)
970{
971 CMachine comMachine = machine();
972 uiCommon().prepareStorageMenu(pMenu,
973 pListener, pszSlotName,
974 comMachine, strControllerName, storageSlot);
975}
976
977void UISession::updateMachineStorage(const UIMediumTarget &target, UIActionPool *pActionPool)
978{
979 CMachine comMachine = machine();
980 uiCommon().updateMachineStorage(comMachine, target, pActionPool);
981}
982
983void UISession::acquireWhetherUSBControllerEnabled(bool &fEnabled)
984{
985 fEnabled = false;
986
987 /* Check whether USB device filters are available: */
988 CMachine comMachine = machine();
989 if (comMachine.isNull())
990 return;
991 CUSBDeviceFilters comUSBDeviceFilters = comMachine.GetUSBDeviceFilters();
992 if (!comMachine.isOk() || comUSBDeviceFilters.isNull())
993 return;
994 /* Check whether USB controllers are available: */
995 CUSBControllerVector comUSBControllers = comMachine.GetUSBControllers();
996 if (!comMachine.isOk() || comUSBControllers.isEmpty())
997 return;
998 /* Check whether USB proxy is available: */
999 const BOOL fUSBProxyAvailable = comMachine.GetUSBProxyAvailable();
1000 if (!comMachine.isOk() || fUSBProxyAvailable == FALSE)
1001 return;
1002
1003 fEnabled = true;
1004}
1005
1006void UISession::acquireWhetherVideoInputDevicesEnabled(bool &fEnabled)
1007{
1008 fEnabled = false;
1009
1010 /* Check whether video input devices are available: */
1011 CHost comHost = uiCommon().host();
1012 CHostVideoInputDeviceVector comVideoInputDevices = comHost.GetVideoInputDevices();
1013 if (!comHost.isOk() || comVideoInputDevices.isEmpty())
1014 return;
1015 /* Check whether USB controllers are available: */
1016 CMachine comMachine = machine();
1017 if (comMachine.isNull())
1018 return;
1019 CUSBControllerVector comUSBControllers = comMachine.GetUSBControllers();
1020 if (!comMachine.isOk() || comUSBControllers.isEmpty())
1021 return;
1022
1023 fEnabled = true;
1024}
1025
1026bool UISession::usbDevices(QList<USBDeviceInfo> &guiUSBDevices)
1027{
1028 const CHost comHost = uiCommon().host();
1029 const CHostUSBDeviceVector comHostUSBDevices = comHost.GetUSBDevices();
1030 bool fSuccess = comHost.isOk();
1031 if (!fSuccess)
1032 UINotificationMessage::cannotAcquireHostParameter(comHost);
1033 else
1034 {
1035 foreach (const CHostUSBDevice &comHostUSBDevice, comHostUSBDevices)
1036 {
1037 /* Get USB device from current host USB device,
1038 * this stuff requires #include <VBox/com/VirtualBox.h> */
1039 const CUSBDevice comUSBDevice(comHostUSBDevice);
1040
1041 /* Fill structure fields: */
1042 USBDeviceInfo guiUSBDevice;
1043 if (fSuccess)
1044 {
1045 guiUSBDevice.m_uId = comUSBDevice.GetId();
1046 fSuccess = comUSBDevice.isOk();
1047 }
1048 if (fSuccess)
1049 {
1050 /// @todo make sure UICommon::usbDetails is checked for errors as well
1051 guiUSBDevice.m_strName = uiCommon().usbDetails(comUSBDevice);
1052 fSuccess = comUSBDevice.isOk();
1053 }
1054 if (fSuccess)
1055 {
1056 /// @todo make sure UICommon::usbToolTip is checked for errors as well
1057 guiUSBDevice.m_strToolTip = uiCommon().usbToolTip(comUSBDevice);
1058 fSuccess = comUSBDevice.isOk();
1059 }
1060 if (fSuccess)
1061 {
1062 /* Check if that USB device was already attached to this session;
1063 * Nothing to check for errors here because error is valid case as well. */
1064 const CUSBDevice comAttachedDevice = console().FindUSBDeviceById(guiUSBDevice.m_uId);
1065 guiUSBDevice.m_fIsChecked = !comAttachedDevice.isNull();
1066 }
1067 if (fSuccess)
1068 {
1069 guiUSBDevice.m_fIsEnabled = comHostUSBDevice.GetState() != KUSBDeviceState_Unavailable;
1070 fSuccess = comHostUSBDevice.isOk();
1071 }
1072
1073 /* Append or break if necessary: */
1074 if (fSuccess)
1075 guiUSBDevices << guiUSBDevice;
1076 else
1077 break;
1078 }
1079 }
1080 return fSuccess;
1081}
1082
1083bool UISession::attachUSBDevice(const QUuid &uId)
1084{
1085 CConsole comConsole = console();
1086 comConsole.AttachUSBDevice(uId, QString(""));
1087 const bool fSuccess = comConsole.isOk();
1088 if (!fSuccess)
1089 {
1090 CHost comHost = uiCommon().host();
1091 /* Nothing to check for errors here because error is valid case as well. */
1092 CHostUSBDevice comHostUSBDevice = comHost.FindUSBDeviceById(uId);
1093 /* Get USB device from current host USB device,
1094 * this stuff requires #include <VBox/com/VirtualBox.h> */
1095 CUSBDevice comUSBDevice(comHostUSBDevice);
1096 UINotificationMessage::cannotAttachUSBDevice(comConsole, uiCommon().usbDetails(comUSBDevice));
1097 /// @todo make sure UICommon::usbDetails is checked for errors as well
1098 }
1099 return fSuccess;
1100}
1101
1102bool UISession::detachUSBDevice(const QUuid &uId)
1103{
1104 CConsole comConsole = console();
1105 comConsole.DetachUSBDevice(uId);
1106 const bool fSuccess = comConsole.isOk();
1107 if (!fSuccess)
1108 {
1109 CUSBDevice comUSBDevice = CConsole(comConsole).FindUSBDeviceById(uId);
1110 UINotificationMessage::cannotDetachUSBDevice(comConsole, uiCommon().usbDetails(comUSBDevice));
1111 /// @todo make sure UICommon::usbDetails is checked for errors as well
1112 }
1113 return fSuccess;
1114}
1115
1116bool UISession::webcamDevices(QList<WebcamDeviceInfo> &guiWebcamDevices)
1117{
1118 const CHost comHost = uiCommon().host();
1119 const CHostVideoInputDeviceVector comHostVideoInputDevices = comHost.GetVideoInputDevices();
1120 bool fSuccess = comHost.isOk();
1121 if (!fSuccess)
1122 UINotificationMessage::cannotAcquireHostParameter(comHost);
1123 else
1124 {
1125 CConsole comConsole = console();
1126 CEmulatedUSB comEmulatedUSB = comConsole.GetEmulatedUSB();
1127 fSuccess = comConsole.isOk();
1128 if (!fSuccess)
1129 UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
1130 else
1131 {
1132 const QVector<QString> attachedWebcamPaths = comEmulatedUSB.GetWebcams();
1133 fSuccess = comEmulatedUSB.isOk();
1134 if (!fSuccess)
1135 UINotificationMessage::cannotAcquireEmulatedUSBParameter(comEmulatedUSB);
1136 else
1137 {
1138 foreach (const CHostVideoInputDevice &comHostVideoInputDevice, comHostVideoInputDevices)
1139 {
1140 /* Fill structure fields: */
1141 WebcamDeviceInfo guiWebcamDevice;
1142 if (fSuccess)
1143 {
1144 guiWebcamDevice.m_strName = comHostVideoInputDevice.GetName();
1145 fSuccess = comHostVideoInputDevice.isOk();
1146 }
1147 if (fSuccess)
1148 {
1149 guiWebcamDevice.m_strPath = comHostVideoInputDevice.GetPath();
1150 fSuccess = comHostVideoInputDevice.isOk();
1151 }
1152 if (fSuccess)
1153 {
1154 /// @todo make sure UICommon::usbToolTip is checked for errors as well
1155 guiWebcamDevice.m_strToolTip = uiCommon().usbToolTip(comHostVideoInputDevice);
1156 fSuccess = comHostVideoInputDevice.isOk();
1157 }
1158 if (fSuccess)
1159 guiWebcamDevice.m_fIsChecked = attachedWebcamPaths.contains(guiWebcamDevice.m_strPath);
1160
1161 /* Append or break if necessary: */
1162 if (fSuccess)
1163 guiWebcamDevices << guiWebcamDevice;
1164 else
1165 break;
1166 }
1167 }
1168 }
1169 }
1170 return fSuccess;
1171}
1172
1173bool UISession::webcamAttach(const QString &strPath, const QString &strName)
1174{
1175 CConsole comConsole = console();
1176 CEmulatedUSB comDispatcher = comConsole.GetEmulatedUSB();
1177 bool fSuccess = comConsole.isOk();
1178 if (!fSuccess)
1179 UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
1180 else
1181 {
1182 comDispatcher.WebcamAttach(strPath, "");
1183 fSuccess = comDispatcher.isOk();
1184 if (!fSuccess)
1185 UINotificationMessage::cannotAttachWebCam(comDispatcher, strName, machineName());
1186 }
1187 return fSuccess;
1188}
1189
1190bool UISession::webcamDetach(const QString &strPath, const QString &strName)
1191{
1192 CConsole comConsole = console();
1193 CEmulatedUSB comDispatcher = comConsole.GetEmulatedUSB();
1194 bool fSuccess = comConsole.isOk();
1195 if (!fSuccess)
1196 UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
1197 else
1198 {
1199 comDispatcher.WebcamDetach(strPath);
1200 fSuccess = comDispatcher.isOk();
1201 if (!fSuccess)
1202 UINotificationMessage::cannotDetachWebCam(comDispatcher, strName, machineName());
1203 }
1204 return fSuccess;
1205}
1206
1207bool UISession::acquireWhetherNetworkAdapterEnabled(ulong uSlot, bool &fEnabled)
1208{
1209 CMachine comMachine = machine();
1210 CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(uSlot);
1211 bool fSuccess = comMachine.isOk();
1212 if (!fSuccess)
1213 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1214 else
1215 {
1216 const BOOL fAdapterEnabled = comAdapter.GetEnabled();
1217 fSuccess = comAdapter.isOk();
1218 if (!fSuccess)
1219 UINotificationMessage::cannotAcquireNetworkAdapterParameter(comAdapter);
1220 else
1221 fEnabled = fAdapterEnabled == TRUE;
1222 }
1223 return fSuccess;
1224}
1225
1226bool UISession::acquireWhetherAtLeastOneNetworkAdapterEnabled(bool &fEnabled)
1227{
1228 /* Acquire system properties: */
1229 CVirtualBox comVBox = uiCommon().virtualBox();
1230 AssertReturn(comVBox.isNotNull(), false);
1231 CSystemProperties comProperties = comVBox.GetSystemProperties();
1232 if (!comVBox.isOk())
1233 {
1234 UINotificationMessage::cannotAcquireVirtualBoxParameter(comVBox);
1235 return false;
1236 }
1237
1238 /* Acquire chipset type: */
1239 KChipsetType enmChipsetType = KChipsetType_Null;
1240 bool fSuccess = acquireChipsetType(enmChipsetType);
1241 if (fSuccess)
1242 {
1243 /* Acquire maximum network adapters count: */
1244 const ulong uSlots = comProperties.GetMaxNetworkAdapters(enmChipsetType);
1245 fSuccess = comProperties.isOk();
1246 if (!fSuccess)
1247 UINotificationMessage::cannotAcquireSystemPropertiesParameter(comProperties);
1248 else
1249 {
1250 /* Search for 1st enabled adapter: */
1251 for (ulong uSlot = 0; uSlot < uSlots; ++uSlot)
1252 {
1253 bool fAdapterEnabled = false;
1254 fSuccess = acquireWhetherNetworkAdapterEnabled(uSlot, fAdapterEnabled);
1255 if (!fSuccess)
1256 break;
1257 if (!fAdapterEnabled)
1258 continue;
1259 fEnabled = true;
1260 break;
1261 }
1262 }
1263 }
1264 return fSuccess;
1265}
1266
1267bool UISession::acquireWhetherNetworkCableConnected(ulong uSlot, bool &fConnected)
1268{
1269 CMachine comMachine = machine();
1270 CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(uSlot);
1271 bool fSuccess = comMachine.isOk();
1272 if (!fSuccess)
1273 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1274 else
1275 {
1276 const BOOL fCableConnected = comAdapter.GetCableConnected();
1277 fSuccess = comAdapter.isOk();
1278 if (!fSuccess)
1279 UINotificationMessage::cannotAcquireNetworkAdapterParameter(comAdapter);
1280 else
1281 fConnected = fCableConnected == TRUE;
1282 }
1283 return fSuccess;
1284}
1285
1286bool UISession::setNetworkCableConnected(ulong uSlot, bool fConnected)
1287{
1288 CMachine comMachine = machine();
1289 CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(uSlot);
1290 bool fSuccess = comMachine.isOk();
1291 if (!fSuccess)
1292 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1293 else
1294 {
1295 comAdapter.SetCableConnected(fConnected);
1296 fSuccess = comAdapter.isOk();
1297 if (!fSuccess)
1298 UINotificationMessage::cannotToggleNetworkCable(comAdapter, machineName(), fConnected);
1299 }
1300 return fSuccess;
1301}
1302
1303bool UISession::guestAdditionsUpgradable()
1304{
1305 if (!machine().isOk())
1306 return false;
1307
1308 /* Auto GA update is currently for Windows and Linux guests only */
1309 const CGuestOSType osType = uiCommon().vmGuestOSType(uimachine()->osTypeId());
1310 if (!osType.isOk())
1311 return false;
1312
1313 const QString strGuestFamily = osType.GetFamilyId();
1314 bool fIsWindowOrLinux = strGuestFamily.contains("windows", Qt::CaseInsensitive) || strGuestFamily.contains("linux", Qt::CaseInsensitive);
1315
1316 if (!fIsWindowOrLinux)
1317 return false;
1318
1319 /* Also check whether we have something to update automatically: */
1320 if (m_ulGuestAdditionsRunLevel < (ulong)KAdditionsRunLevelType_Userland)
1321 return false;
1322
1323 return true;
1324}
1325
1326bool UISession::acquireGuestAdditionsVersion(QString &strVersion)
1327{
1328 CGuest comGuest = guest();
1329 const QString strGAVersion = comGuest.GetAdditionsVersion();
1330 const bool fSuccess = comGuest.isOk();
1331 if (!fSuccess)
1332 UINotificationMessage::cannotAcquireGuestParameter(comGuest);
1333 else
1334 strVersion = strGAVersion;
1335 return fSuccess;
1336}
1337
1338bool UISession::acquireGuestAdditionsRevision(ulong &uRevision)
1339{
1340 CGuest comGuest = guest();
1341 const ULONG uGARevision = comGuest.GetAdditionsRevision();
1342 const bool fSuccess = comGuest.isOk();
1343 if (!fSuccess)
1344 UINotificationMessage::cannotAcquireGuestParameter(comGuest);
1345 else
1346 uRevision = uGARevision;
1347 return fSuccess;
1348}
1349
1350bool UISession::acquireWhetherAudioAdapterPresent(bool &fPresent)
1351{
1352 CMachine comMachine = machine();
1353 if (comMachine.isNull())
1354 return false;
1355 CAudioSettings comSettings = comMachine.GetAudioSettings();
1356 const bool fSuccess = comMachine.isOk();
1357 if (!fSuccess)
1358 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1359 else
1360 {
1361 CAudioAdapter comAdapter = comSettings.GetAdapter();
1362 fPresent = comSettings.isOk() && comAdapter.isNotNull();
1363 }
1364 return fSuccess;
1365}
1366
1367bool UISession::acquireWhetherAudioAdapterEnabled(bool &fEnabled)
1368{
1369 CMachine comMachine = machine();
1370 CAudioSettings comSettings = comMachine.GetAudioSettings();
1371 bool fSuccess = comMachine.isOk();
1372 if (!fSuccess)
1373 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1374 else
1375 {
1376 CAudioAdapter comAdapter = comSettings.GetAdapter();
1377 fSuccess = comSettings.isOk();
1378 if (!fSuccess)
1379 UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
1380 {
1381 const BOOL fAdapterEnabled = comAdapter.GetEnabled();
1382 fSuccess = comAdapter.isOk();
1383 if (!fSuccess)
1384 UINotificationMessage::cannotAcquireAudioAdapterParameter(comAdapter);
1385 else
1386 fEnabled = fAdapterEnabled == TRUE;
1387 }
1388 }
1389 return fSuccess;
1390}
1391
1392bool UISession::acquireWhetherAudioAdapterOutputEnabled(bool &fEnabled)
1393{
1394 CMachine comMachine = machine();
1395 CAudioSettings comSettings = comMachine.GetAudioSettings();
1396 bool fSuccess = comMachine.isOk();
1397 if (!fSuccess)
1398 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1399 else
1400 {
1401 CAudioAdapter comAdapter = comSettings.GetAdapter();
1402 fSuccess = comSettings.isOk();
1403 if (!fSuccess)
1404 UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
1405 {
1406 const BOOL fOutputEnabled = comAdapter.GetEnabledOut();
1407 fSuccess = comAdapter.isOk();
1408 if (!fSuccess)
1409 UINotificationMessage::cannotAcquireAudioAdapterParameter(comAdapter);
1410 else
1411 fEnabled = fOutputEnabled == TRUE;
1412 }
1413 }
1414 return fSuccess;
1415}
1416
1417bool UISession::acquireWhetherAudioAdapterInputEnabled(bool &fEnabled)
1418{
1419 CMachine comMachine = machine();
1420 CAudioSettings comSettings = comMachine.GetAudioSettings();
1421 bool fSuccess = comMachine.isOk();
1422 if (!fSuccess)
1423 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1424 else
1425 {
1426 CAudioAdapter comAdapter = comSettings.GetAdapter();
1427 fSuccess = comSettings.isOk();
1428 if (!fSuccess)
1429 UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
1430 {
1431 const BOOL fInputEnabled = comAdapter.GetEnabledIn();
1432 fSuccess = comAdapter.isOk();
1433 if (!fSuccess)
1434 UINotificationMessage::cannotAcquireAudioAdapterParameter(comAdapter);
1435 else
1436 fEnabled = fInputEnabled == TRUE;
1437 }
1438 }
1439 return fSuccess;
1440}
1441
1442bool UISession::setAudioAdapterOutputEnabled(bool fEnabled)
1443{
1444 CMachine comMachine = machine();
1445 CAudioSettings comSettings = comMachine.GetAudioSettings();
1446 bool fSuccess = comMachine.isOk();
1447 if (!fSuccess)
1448 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1449 else
1450 {
1451 CAudioAdapter comAdapter = comSettings.GetAdapter();
1452 fSuccess = comSettings.isOk();
1453 if (!fSuccess)
1454 UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
1455 {
1456 comAdapter.SetEnabledOut(fEnabled);
1457 fSuccess = comAdapter.isOk();
1458 if (!fSuccess)
1459 UINotificationMessage::cannotToggleAudioOutput(comAdapter, machineName(), fEnabled);
1460 }
1461 }
1462 return fSuccess;
1463}
1464
1465bool UISession::setAudioAdapterInputEnabled(bool fEnabled)
1466{
1467 CMachine comMachine = machine();
1468 CAudioSettings comSettings = comMachine.GetAudioSettings();
1469 bool fSuccess = comMachine.isOk();
1470 if (!fSuccess)
1471 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1472 else
1473 {
1474 CAudioAdapter comAdapter = comSettings.GetAdapter();
1475 fSuccess = comSettings.isOk();
1476 if (!fSuccess)
1477 UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
1478 {
1479 comAdapter.SetEnabledIn(fEnabled);
1480 fSuccess = comAdapter.isOk();
1481 if (!fSuccess)
1482 UINotificationMessage::cannotToggleAudioInput(comAdapter, machineName(), fEnabled);
1483 }
1484 }
1485 return fSuccess;
1486}
1487
1488UIFrameBuffer *UISession::frameBuffer(ulong uScreenId) const
1489{
1490 return m_frameBufferVector.value((int)uScreenId, 0);
1491}
1492
1493QSize UISession::frameBufferSize(ulong uScreenId) const
1494{
1495 UIFrameBuffer *pFramebuffer = frameBuffer(uScreenId);
1496 return pFramebuffer ? QSize(pFramebuffer->width(), pFramebuffer->height()) : QSize();
1497}
1498
1499bool UISession::acquireGraphicsControllerType(KGraphicsControllerType &enmType)
1500{
1501 CMachine comMachine = machine();
1502 CGraphicsAdapter comAdapter = comMachine.GetGraphicsAdapter();
1503 bool fSuccess = comMachine.isOk();
1504 if (!fSuccess)
1505 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1506 else
1507 {
1508 const KGraphicsControllerType enmControllerType = comAdapter.GetGraphicsControllerType();
1509 fSuccess = comAdapter.isOk();
1510 if (!fSuccess)
1511 UINotificationMessage::cannotAcquireGraphicsAdapterParameter(comAdapter);
1512 else
1513 enmType = enmControllerType;
1514 }
1515 return fSuccess;
1516}
1517
1518bool UISession::acquireVRAMSize(ulong &uSize)
1519{
1520 CMachine comMachine = machine();
1521 CGraphicsAdapter comAdapter = comMachine.GetGraphicsAdapter();
1522 bool fSuccess = comMachine.isOk();
1523 if (!fSuccess)
1524 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1525 else
1526 {
1527 const ULONG uVRAMSize = comAdapter.GetVRAMSize();
1528 fSuccess = comAdapter.isOk();
1529 if (!fSuccess)
1530 UINotificationMessage::cannotAcquireGraphicsAdapterParameter(comAdapter);
1531 else
1532 uSize = uVRAMSize;
1533 }
1534 return fSuccess;
1535}
1536
1537bool UISession::acquireWhetherAccelerate3DEnabled(bool &fEnabled)
1538{
1539 CMachine comMachine = machine();
1540 CGraphicsAdapter comAdapter = comMachine.GetGraphicsAdapter();
1541 bool fSuccess = comMachine.isOk();
1542 if (!fSuccess)
1543 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1544 else
1545 {
1546 const BOOL fAccelerate3DEnabeld = comAdapter.GetAccelerate3DEnabled();
1547 fSuccess = comAdapter.isOk();
1548 if (!fSuccess)
1549 UINotificationMessage::cannotAcquireGraphicsAdapterParameter(comAdapter);
1550 else
1551 fEnabled = fAccelerate3DEnabeld == TRUE;
1552 }
1553 return fSuccess;
1554}
1555
1556bool UISession::acquireMonitorCount(ulong &uCount)
1557{
1558 // WORKAROUND:
1559 // We certainly don't want to get into
1560 // 'no visible screens' case if something
1561 // gone wrong... Inventing sane default.
1562 uCount = 1;
1563
1564 CMachine comMachine = machine();
1565 if (comMachine.isNull())
1566 return false;
1567 CGraphicsAdapter comAdapter = comMachine.GetGraphicsAdapter();
1568 bool fSuccess = comMachine.isOk();
1569 if (!fSuccess)
1570 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1571 else
1572 {
1573 const ULONG uMonitorCount = comAdapter.GetMonitorCount();
1574 fSuccess = comAdapter.isOk();
1575 if (!fSuccess)
1576 UINotificationMessage::cannotAcquireGraphicsAdapterParameter(comAdapter);
1577 else
1578 uCount = uMonitorCount;
1579 }
1580 return fSuccess;
1581}
1582
1583bool UISession::acquireGuestScreenParameters(ulong uScreenId,
1584 ulong &uWidth, ulong &uHeight, ulong &uBitsPerPixel,
1585 long &xOrigin, long &yOrigin, KGuestMonitorStatus &enmMonitorStatus)
1586{
1587 CDisplay comDisplay = display();
1588 ULONG uGuestWidth = 0, uGuestHeight = 0, uGuestBitsPerPixel = 0;
1589 LONG iGuestXOrigin = 0, iGuestYOrigin = 0;
1590 KGuestMonitorStatus enmGuestMonitorStatus = KGuestMonitorStatus_Disabled;
1591 comDisplay.GetScreenResolution(uScreenId, uGuestWidth, uGuestHeight, uGuestBitsPerPixel,
1592 iGuestXOrigin, iGuestYOrigin, enmGuestMonitorStatus);
1593 const bool fSuccess = comDisplay.isOk();
1594 if (!fSuccess)
1595 UINotificationMessage::cannotAcquireDisplayParameter(comDisplay);
1596 else
1597 {
1598 uWidth = uGuestWidth;
1599 uHeight = uGuestHeight;
1600 uBitsPerPixel = uGuestBitsPerPixel;
1601 xOrigin = iGuestXOrigin;
1602 yOrigin = iGuestYOrigin;
1603 enmMonitorStatus = enmGuestMonitorStatus;
1604 }
1605 return fSuccess;
1606}
1607
1608bool UISession::acquireSavedGuestScreenInfo(ulong uScreenId,
1609 long &xOrigin, long &yOrigin,
1610 ulong &uWidth, ulong &uHeight, bool &fEnabled)
1611{
1612 CMachine comMachine = machine();
1613 ULONG uGuestXOrigin = 0, uGuestYOrigin = 0, uGuestWidth = 0, uGuestHeight = 0;
1614 BOOL fGuestEnabled = FALSE;
1615 comMachine.QuerySavedGuestScreenInfo(uScreenId, uGuestXOrigin, uGuestYOrigin, uGuestWidth, uGuestHeight, fGuestEnabled);
1616 const bool fSuccess = comMachine.isOk();
1617 if (!fSuccess)
1618 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1619 else
1620 {
1621 xOrigin = uGuestXOrigin;
1622 yOrigin = uGuestYOrigin;
1623 uWidth = uGuestWidth;
1624 uHeight = uGuestHeight;
1625 fEnabled = fGuestEnabled == TRUE;
1626 }
1627 return fSuccess;
1628}
1629
1630bool UISession::setVideoModeHint(ulong uScreenId, bool fEnabled, bool fChangeOrigin, long xOrigin, long yOrigin,
1631 ulong uWidth, ulong uHeight, ulong uBitsPerPixel, bool fNotify)
1632{
1633 CDisplay comDisplay = display();
1634 comDisplay.SetVideoModeHint(uScreenId, fEnabled, fChangeOrigin, xOrigin, yOrigin,
1635 uWidth, uHeight, uBitsPerPixel, fNotify);
1636 const bool fSuccess = comDisplay.isOk();
1637 if (!fSuccess)
1638 UINotificationMessage::cannotChangeDisplayParameter(comDisplay);
1639 return fSuccess;
1640}
1641
1642bool UISession::acquireVideoModeHint(ulong uScreenId, bool &fEnabled, bool &fChangeOrigin,
1643 long &xOrigin, long &yOrigin, ulong &uWidth, ulong &uHeight,
1644 ulong &uBitsPerPixel)
1645{
1646 CDisplay comDisplay = display();
1647 BOOL fGuestEnabled = FALSE, fGuestChangeOrigin = FALSE;
1648 LONG iGuestXOrigin = 0, iGuestYOrigin = 0;
1649 ULONG uGuestWidth = 0, uGuestHeight = 0, uGuestBitsPerPixel = 0;
1650 comDisplay.GetVideoModeHint(uScreenId, fGuestEnabled, fGuestChangeOrigin,
1651 iGuestXOrigin, iGuestYOrigin, uGuestWidth, uGuestHeight,
1652 uGuestBitsPerPixel);
1653 const bool fSuccess = comDisplay.isOk();
1654 if (!fSuccess)
1655 UINotificationMessage::cannotAcquireDisplayParameter(comDisplay);
1656 else
1657 {
1658 fEnabled = fGuestEnabled == TRUE;
1659 fChangeOrigin = fGuestChangeOrigin == TRUE;
1660 xOrigin = iGuestXOrigin;
1661 yOrigin = iGuestYOrigin;
1662 uWidth = uGuestWidth;
1663 uHeight = uGuestHeight;
1664 uBitsPerPixel = uGuestBitsPerPixel;
1665 }
1666 return fSuccess;
1667}
1668
1669bool UISession::acquireScreenShot(ulong uScreenId, ulong uWidth, ulong uHeight, KBitmapFormat enmFormat, uchar *pBits)
1670{
1671 CDisplay comDisplay = display();
1672 bool fSuccess = false;
1673 /* For separate process: */
1674 if (uiCommon().isSeparateProcess())
1675 {
1676 /* Take screen-data to array first: */
1677 const QVector<BYTE> screenData = comDisplay.TakeScreenShotToArray(uScreenId, uWidth, uHeight, enmFormat);
1678 fSuccess = comDisplay.isOk();
1679 if (!fSuccess)
1680 UINotificationMessage::cannotAcquireDisplayParameter(comDisplay);
1681 else
1682 {
1683 /* And copy that data to screen-shot if it is Ok: */
1684 if (!screenData.isEmpty())
1685 memcpy(pBits, screenData.data(), uWidth * uHeight * 4);
1686 }
1687 }
1688 /* For the same process: */
1689 else
1690 {
1691 /* Take the screen-shot directly: */
1692 comDisplay.TakeScreenShot(uScreenId, pBits, uWidth, uHeight, enmFormat);
1693 fSuccess = comDisplay.isOk();
1694 if (!fSuccess)
1695 UINotificationMessage::cannotAcquireDisplayParameter(comDisplay);
1696 }
1697 return fSuccess;
1698}
1699
1700bool UISession::acquireSavedScreenshotInfo(ulong uScreenId, ulong &uWidth, ulong &uHeight, QVector<KBitmapFormat> &formats)
1701{
1702 CMachine comMachine = machine();
1703 ULONG uGuestWidth = 0, uGuestHeight = 0;
1704 QVector<KBitmapFormat> guestFormats = comMachine.QuerySavedScreenshotInfo(uScreenId, uGuestWidth, uGuestHeight);
1705 const bool fSuccess = comMachine.isOk();
1706 if (!fSuccess)
1707 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1708 else
1709 {
1710 uWidth = uGuestWidth;
1711 uHeight = uGuestHeight;
1712 formats = guestFormats;
1713 }
1714 return fSuccess;
1715}
1716
1717bool UISession::acquireSavedScreenshot(ulong uScreenId, KBitmapFormat enmFormat,
1718 ulong &uWidth, ulong &uHeight, QVector<BYTE> &screenshot)
1719{
1720 CMachine comMachine = machine();
1721 ULONG uGuestWidth = 0, uGuestHeight = 0;
1722 const QVector<BYTE> guestScreenshot = comMachine.ReadSavedScreenshotToArray(uScreenId, enmFormat,
1723 uGuestWidth, uGuestHeight);
1724 const bool fSuccess = comMachine.isOk();
1725 if (!fSuccess)
1726 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1727 else
1728 {
1729 uWidth = uGuestWidth;
1730 uHeight = uGuestHeight;
1731 screenshot = guestScreenshot;
1732 }
1733 return fSuccess;
1734}
1735
1736bool UISession::notifyScaleFactorChange(ulong uScreenId, ulong uScaleFactorWMultiplied, ulong uScaleFactorHMultiplied)
1737{
1738 CDisplay comDisplay = display();
1739 comDisplay.NotifyScaleFactorChange(uScreenId, uScaleFactorWMultiplied, uScaleFactorHMultiplied);
1740 const bool fSuccess = comDisplay.isOk();
1741 if (!fSuccess)
1742 UINotificationMessage::cannotChangeDisplayParameter(comDisplay);
1743 return fSuccess;
1744}
1745
1746bool UISession::notifyHiDPIOutputPolicyChange(bool fUnscaledHiDPI)
1747{
1748 CDisplay comDisplay = display();
1749 comDisplay.NotifyHiDPIOutputPolicyChange(fUnscaledHiDPI);
1750 const bool fSuccess = comDisplay.isOk();
1751 if (!fSuccess)
1752 UINotificationMessage::cannotChangeDisplayParameter(comDisplay);
1753 return fSuccess;
1754}
1755
1756bool UISession::setSeamlessMode(bool fEnabled)
1757{
1758 CDisplay comDisplay = display();
1759 comDisplay.SetSeamlessMode(fEnabled);
1760 const bool fSuccess = comDisplay.isOk();
1761 if (!fSuccess)
1762 UINotificationMessage::cannotChangeDisplayParameter(comDisplay);
1763 return fSuccess;
1764}
1765
1766bool UISession::viewportChanged(ulong uScreenId, ulong xOrigin, ulong yOrigin, ulong uWidth, ulong uHeight)
1767{
1768 CDisplay comDisplay = display();
1769 if (comDisplay.isNull())
1770 return false;
1771 comDisplay.ViewportChanged(uScreenId, xOrigin, yOrigin, uWidth, uHeight);
1772 const bool fSuccess = comDisplay.isOk();
1773 if (!fSuccess)
1774 UINotificationMessage::cannotChangeDisplayParameter(comDisplay);
1775 return fSuccess;
1776}
1777
1778bool UISession::invalidateAndUpdate()
1779{
1780 CDisplay comDisplay = display();
1781 comDisplay.InvalidateAndUpdate();
1782 const bool fSuccess = comDisplay.isOk();
1783 if (!fSuccess)
1784 UINotificationMessage::cannotChangeDisplayParameter(comDisplay);
1785 return fSuccess;
1786}
1787
1788bool UISession::invalidateAndUpdateScreen(ulong uScreenId)
1789{
1790 CDisplay comDisplay = display();
1791 comDisplay.InvalidateAndUpdateScreen(uScreenId);
1792 const bool fSuccess = comDisplay.isOk();
1793 if (!fSuccess)
1794 UINotificationMessage::cannotChangeDisplayParameter(comDisplay);
1795 return fSuccess;
1796}
1797
1798bool UISession::acquireWhetherVRDEServerPresent(bool &fPresent)
1799{
1800 CMachine comMachine = machine();
1801 if (comMachine.isNull())
1802 return false;
1803 CVRDEServer comServer = comMachine.GetVRDEServer();
1804 fPresent = comMachine.isOk() && comServer.isNotNull();
1805 return true;
1806}
1807
1808bool UISession::acquireWhetherVRDEServerEnabled(bool &fEnabled)
1809{
1810 CMachine comMachine = machine();
1811 CVRDEServer comServer = comMachine.GetVRDEServer();
1812 bool fSuccess = comMachine.isOk();
1813 if (!fSuccess)
1814 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1815 else
1816 {
1817 const BOOL fServerEnabled = comServer.GetEnabled();
1818 fSuccess = comServer.isOk();
1819 if (!fSuccess)
1820 UINotificationMessage::cannotAcquireVRDEServerParameter(comServer);
1821 else
1822 fEnabled = fServerEnabled == TRUE;
1823 }
1824 return fSuccess;
1825}
1826
1827bool UISession::setVRDEServerEnabled(bool fEnabled)
1828{
1829 CMachine comMachine = machine();
1830 CVRDEServer comServer = comMachine.GetVRDEServer();
1831 bool fSuccess = comMachine.isOk();
1832 if (!fSuccess)
1833 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1834 else
1835 {
1836 comServer.SetEnabled(fEnabled);
1837 fSuccess = comServer.isOk();
1838 if (!fSuccess)
1839 UINotificationMessage::cannotToggleVRDEServer(comServer, machineName(), fEnabled);
1840 }
1841 return fSuccess;
1842}
1843
1844bool UISession::acquireVRDEServerPort(long &iPort)
1845{
1846 CConsole comConsole = console();
1847 const CVRDEServerInfo comVRDEServerInfo = comConsole.GetVRDEServerInfo();
1848 bool fSuccess = comConsole.isOk();
1849 if (!fSuccess)
1850 UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
1851 else
1852 {
1853 const LONG iVRDEPort = comVRDEServerInfo.GetPort();
1854 fSuccess = comVRDEServerInfo.isOk();
1855 if (!fSuccess)
1856 UINotificationMessage::cannotAcquireVRDEServerInfoParameter(comVRDEServerInfo);
1857 else
1858 iPort = iVRDEPort;
1859 }
1860 return fSuccess;
1861}
1862
1863bool UISession::acquireWhetherRecordingSettingsPresent(bool &fPresent)
1864{
1865 CMachine comMachine = machine();
1866 CRecordingSettings comSettings = comMachine.GetRecordingSettings();
1867 fPresent = comMachine.isOk() && comSettings.isNotNull();
1868 return true;
1869}
1870
1871bool UISession::acquireWhetherRecordingSettingsEnabled(bool &fEnabled)
1872{
1873 CMachine comMachine = machine();
1874 CRecordingSettings comSettings = comMachine.GetRecordingSettings();
1875 bool fSuccess = comMachine.isOk();
1876 if (!fSuccess)
1877 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1878 else
1879 {
1880 const BOOL fSettingsEnabled = comSettings.GetEnabled();
1881 fSuccess = comSettings.isOk();
1882 if (!fSuccess)
1883 UINotificationMessage::cannotAcquireRecordingSettingsParameter(comSettings);
1884 else
1885 fEnabled = fSettingsEnabled == TRUE;
1886 }
1887 return fSuccess;
1888}
1889
1890bool UISession::setRecordingSettingsEnabled(bool fEnabled)
1891{
1892 CMachine comMachine = machine();
1893 CRecordingSettings comSettings = comMachine.GetRecordingSettings();
1894 bool fSuccess = comMachine.isOk();
1895 if (!fSuccess)
1896 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
1897 else
1898 {
1899 comSettings.SetEnabled(fEnabled);
1900 fSuccess = comSettings.isOk();
1901 if (!fSuccess)
1902 UINotificationMessage::cannotToggleRecording(comSettings, machineName(), fEnabled);
1903 }
1904 return fSuccess;
1905}
1906
1907bool UISession::acquireDeviceActivity(const QVector<KDeviceType> &deviceTypes, QVector<KDeviceActivity> &states)
1908{
1909 CConsole comConsole = console();
1910 const QVector<KDeviceActivity> currentStates = comConsole.GetDeviceActivity(deviceTypes);
1911 const bool fSuccess = comConsole.isOk();
1912 if (!fSuccess)
1913 UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
1914 else
1915 states = currentStates;
1916 return fSuccess;
1917}
1918
1919void UISession::acquireHardDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent)
1920{
1921 CMachine comMachine = machine();
1922 if (comMachine.isNull())
1923 return;
1924 UIDetailsGenerator::acquireHardDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent);
1925}
1926
1927void UISession::acquireOpticalDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent, bool &fAttachmentsMounted)
1928{
1929 CMachine comMachine = machine();
1930 if (comMachine.isNull())
1931 return;
1932 UIDetailsGenerator::acquireOpticalDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent, fAttachmentsMounted);
1933}
1934
1935void UISession::acquireFloppyDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent, bool &fAttachmentsMounted)
1936{
1937 CMachine comMachine = machine();
1938 if (comMachine.isNull())
1939 return;
1940 UIDetailsGenerator::acquireFloppyDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent, fAttachmentsMounted);
1941}
1942
1943void UISession::acquireAudioStatusInfo(QString &strInfo, bool &fAudioEnabled, bool &fEnabledOutput, bool &fEnabledInput)
1944{
1945 CMachine comMachine = machine();
1946 if (comMachine.isNull())
1947 return;
1948 UIDetailsGenerator::acquireAudioStatusInfo(comMachine, strInfo, fAudioEnabled, fEnabledOutput, fEnabledInput);
1949}
1950
1951void UISession::acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected)
1952{
1953 CMachine comMachine = machine();
1954 if (comMachine.isNull())
1955 return;
1956 UIDetailsGenerator::acquireNetworkStatusInfo(comMachine, strInfo, fAdaptersPresent, fCablesDisconnected);
1957}
1958
1959void UISession::acquireUsbStatusInfo(QString &strInfo, bool &fUsbEnableds)
1960{
1961 CMachine comMachine = machine();
1962 if (comMachine.isNull())
1963 return;
1964 CConsole comConsole = console();
1965 if (comConsole.isNull())
1966 return;
1967 UIDetailsGenerator::acquireUsbStatusInfo(comMachine, comConsole, strInfo, fUsbEnableds);
1968}
1969
1970void UISession::acquireSharedFoldersStatusInfo(QString &strInfo, bool &fFoldersPresent)
1971{
1972 CMachine comMachine = machine();
1973 if (comMachine.isNull())
1974 return;
1975 CConsole comConsole = console();
1976 if (comConsole.isNull())
1977 return;
1978 CGuest comGuest = guest();
1979 if (comGuest.isNull())
1980 return;
1981 UIDetailsGenerator::acquireSharedFoldersStatusInfo(comMachine, comConsole, comGuest, strInfo, fFoldersPresent);
1982}
1983
1984void UISession::acquireDisplayStatusInfo(QString &strInfo, bool &fAcceleration3D)
1985{
1986 CMachine comMachine = machine();
1987 if (comMachine.isNull())
1988 return;
1989 UIDetailsGenerator::acquireDisplayStatusInfo(comMachine, strInfo, fAcceleration3D);
1990}
1991
1992void UISession::acquireRecordingStatusInfo(QString &strInfo, bool &fRecordingEnabled, bool &fMachinePaused)
1993{
1994 CMachine comMachine = machine();
1995 if (comMachine.isNull())
1996 return;
1997 fMachinePaused = isPaused();
1998 UIDetailsGenerator::acquireRecordingStatusInfo(comMachine, strInfo, fRecordingEnabled);
1999}
2000
2001void UISession::acquireFeaturesStatusInfo(QString &strInfo, KVMExecutionEngine &enmEngine,
2002 bool fNestedPagingEnabled, bool fUxEnabled,
2003 KParavirtProvider enmProvider)
2004{
2005 CMachine comMachine = machine();
2006 if (comMachine.isNull())
2007 return;
2008 UIDetailsGenerator::acquireFeaturesStatusInfo(comMachine, strInfo,
2009 enmEngine,
2010 fNestedPagingEnabled, fUxEnabled,
2011 enmProvider);
2012}
2013
2014void UISession::generateMachineInformationGeneral(const UIExtraDataMetaDefs::DetailsElementOptionTypeGeneral &fOptions,
2015 UITextTable &returnTable)
2016{
2017 CMachine comMachine = machine();
2018 returnTable = UIDetailsGenerator::generateMachineInformationGeneral(comMachine, fOptions);
2019}
2020
2021void UISession::generateMachineInformationSystem(const UIExtraDataMetaDefs::DetailsElementOptionTypeSystem &fOptions,
2022 UITextTable &returnTable)
2023{
2024 CMachine comMachine = machine();
2025 returnTable = UIDetailsGenerator::generateMachineInformationSystem(comMachine, fOptions);
2026}
2027
2028void UISession::generateMachineInformationDisplay(const UIExtraDataMetaDefs::DetailsElementOptionTypeDisplay &fOptions,
2029 UITextTable &returnTable)
2030{
2031 CMachine comMachine = machine();
2032 returnTable = UIDetailsGenerator::generateMachineInformationDisplay(comMachine, fOptions);
2033}
2034
2035void UISession::generateMachineInformationStorage(const UIExtraDataMetaDefs::DetailsElementOptionTypeStorage &fOptions,
2036 UITextTable &returnTable)
2037{
2038 CMachine comMachine = machine();
2039 returnTable = UIDetailsGenerator::generateMachineInformationStorage(comMachine, fOptions);
2040}
2041
2042void UISession::generateMachineInformationAudio(const UIExtraDataMetaDefs::DetailsElementOptionTypeAudio &fOptions,
2043 UITextTable &returnTable)
2044{
2045 CMachine comMachine = machine();
2046 returnTable = UIDetailsGenerator::generateMachineInformationAudio(comMachine, fOptions);
2047}
2048
2049void UISession::generateMachineInformationNetwork(const UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork &fOptions,
2050 UITextTable &returnTable)
2051{
2052 CMachine comMachine = machine();
2053 returnTable = UIDetailsGenerator::generateMachineInformationNetwork(comMachine, fOptions);
2054}
2055void UISession::generateMachineInformationSerial(const UIExtraDataMetaDefs::DetailsElementOptionTypeSerial &fOptions,
2056 UITextTable &returnTable)
2057{
2058 CMachine comMachine = machine();
2059 returnTable = UIDetailsGenerator::generateMachineInformationSerial(comMachine, fOptions);
2060}
2061
2062void UISession::generateMachineInformationUSB(const UIExtraDataMetaDefs::DetailsElementOptionTypeUsb &fOptions,
2063 UITextTable &returnTable)
2064{
2065 CMachine comMachine = machine();
2066 returnTable = UIDetailsGenerator::generateMachineInformationUSB(comMachine, fOptions);
2067}
2068
2069void UISession::generateMachineInformationSharedFolders(const UIExtraDataMetaDefs::DetailsElementOptionTypeSharedFolders &fOptions,
2070 UITextTable &returnTable)
2071{
2072 CMachine comMachine = machine();
2073 returnTable = UIDetailsGenerator::generateMachineInformationSharedFolders(comMachine, fOptions);
2074}
2075
2076bool UISession::setLogEnabled(bool fEnabled)
2077{
2078 CMachineDebugger comDebugger = debugger();
2079 comDebugger.SetLogEnabled(fEnabled ? TRUE : FALSE);
2080 const bool fSuccess = comDebugger.isOk();
2081 if (!fSuccess)
2082 UINotificationMessage::cannotChangeMachineDebuggerParameter(comDebugger);
2083 return fSuccess;
2084}
2085
2086bool UISession::acquireWhetherLogEnabled(bool &fEnabled)
2087{
2088 CMachineDebugger comDebugger = debugger();
2089 if (comDebugger.isNull())
2090 return false;
2091 const BOOL fLogEnabled = comDebugger.GetLogEnabled();
2092 const bool fSuccess = comDebugger.isOk();
2093 if (!fSuccess)
2094 UINotificationMessage::cannotAcquireMachineDebuggerParameter(comDebugger);
2095 else
2096 fEnabled = fLogEnabled == TRUE;
2097 return fSuccess;
2098}
2099
2100bool UISession::acquireLogFolder(QString &strFolder)
2101{
2102 CMachine comMachine = machine();
2103 const QString strLogFolder = comMachine.GetLogFolder();
2104 const bool fSuccess = comMachine.isOk();
2105 if (!fSuccess)
2106 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
2107 else
2108 strFolder = strLogFolder;
2109 return fSuccess;
2110}
2111
2112bool UISession::acquireEffectiveParavirtProvider(KParavirtProvider &enmProvider)
2113{
2114 CMachine comMachine = machine();
2115 if (comMachine.isNull())
2116 return false;
2117 const KParavirtProvider enmParavirtProvider = comMachine.GetEffectiveParavirtProvider();
2118 const bool fSuccess = comMachine.isOk();
2119 if (!fSuccess)
2120 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
2121 else
2122 enmProvider = enmParavirtProvider;
2123 return fSuccess;
2124}
2125
2126bool UISession::acquireExecutionEngineType(KVMExecutionEngine &enmType)
2127{
2128 CMachineDebugger comDebugger = debugger();
2129 if (comDebugger.isNull())
2130 return false;
2131 const KVMExecutionEngine enmEngineType = comDebugger.GetExecutionEngine();
2132 const bool fSuccess = comDebugger.isOk();
2133 if (!fSuccess)
2134 UINotificationMessage::cannotAcquireMachineDebuggerParameter(comDebugger);
2135 else
2136 enmType = enmEngineType;
2137 return fSuccess;
2138}
2139
2140bool UISession::acquireWhetherHwVirtExNestedPagingEnabled(bool &fEnabled)
2141{
2142 CMachineDebugger comDebugger = debugger();
2143 if (comDebugger.isNull())
2144 return false;
2145 const BOOL fFeatureEnabled = comDebugger.GetHWVirtExNestedPagingEnabled();
2146 const bool fSuccess = comDebugger.isOk();
2147 if (!fSuccess)
2148 UINotificationMessage::cannotAcquireMachineDebuggerParameter(comDebugger);
2149 else
2150 fEnabled = fFeatureEnabled == TRUE;
2151 return fSuccess;
2152}
2153
2154bool UISession::acquireWhetherHwVirtExUXEnabled(bool &fEnabled)
2155{
2156 CMachineDebugger comDebugger = debugger();
2157 if (comDebugger.isNull())
2158 return false;
2159 const BOOL fFeatureEnabled = comDebugger.GetHWVirtExUXEnabled();
2160 const bool fSuccess = comDebugger.isOk();
2161 if (!fSuccess)
2162 UINotificationMessage::cannotAcquireMachineDebuggerParameter(comDebugger);
2163 else
2164 fEnabled = fFeatureEnabled == TRUE;
2165 return fSuccess;
2166}
2167
2168bool UISession::acquireEffectiveCPULoad(ulong &uLoad)
2169{
2170 CMachineDebugger comDebugger = debugger();
2171 ULONG uPctExecuting;
2172 ULONG uPctHalted;
2173 ULONG uPctOther;
2174 comDebugger.GetCPULoad(0x7fffffff, uPctExecuting, uPctHalted, uPctOther);
2175 const bool fSuccess = comDebugger.isOk();
2176 if (!fSuccess)
2177 UINotificationMessage::cannotAcquireMachineDebuggerParameter(comDebugger);
2178 else
2179 uLoad = uPctExecuting + uPctOther;
2180 return fSuccess;
2181}
2182
2183bool UISession::acquireUptime(LONG64 &iUpTime)
2184{
2185 CMachineDebugger comDebugger = debugger();
2186 const LONG64 iGuestUpTime = comDebugger.GetUptime();
2187 const bool fSuccess = comDebugger.isOk();
2188 if (!fSuccess)
2189 UINotificationMessage::cannotAcquireMachineDebuggerParameter(comDebugger);
2190 else
2191 iUpTime = iGuestUpTime;
2192 return fSuccess;
2193}
2194
2195#ifdef VBOX_WITH_DEBUGGER_GUI
2196bool UISession::dbgCreated(void *pActionDebug)
2197{
2198 if (m_pDbgGui)
2199 return true;
2200
2201 RTLDRMOD hLdrMod = uiCommon().getDebuggerModule();
2202 if (hLdrMod == NIL_RTLDRMOD)
2203 return false;
2204
2205 PFNDBGGUICREATE pfnGuiCreate;
2206 int rc = RTLdrGetSymbol(hLdrMod, "DBGGuiCreate", (void**)&pfnGuiCreate);
2207 if (RT_SUCCESS(rc))
2208 {
2209 ISession *pISession = session().raw();
2210 rc = pfnGuiCreate(pISession, &m_pDbgGui, &m_pDbgGuiVT);
2211 if (RT_SUCCESS(rc))
2212 {
2213 if ( DBGGUIVT_ARE_VERSIONS_COMPATIBLE(m_pDbgGuiVT->u32Version, DBGGUIVT_VERSION)
2214 || m_pDbgGuiVT->u32EndVersion == m_pDbgGuiVT->u32Version)
2215 {
2216 m_pDbgGuiVT->pfnSetParent(m_pDbgGui, activeMachineWindow());
2217 m_pDbgGuiVT->pfnSetMenu(m_pDbgGui, pActionDebug);
2218 dbgAdjustRelativePos();
2219 return true;
2220 }
2221
2222 LogRel(("GUI: DBGGuiCreate failed, incompatible versions (loaded %#x/%#x, expected %#x)\n",
2223 m_pDbgGuiVT->u32Version, m_pDbgGuiVT->u32EndVersion, DBGGUIVT_VERSION));
2224 }
2225 else
2226 LogRel(("GUI: DBGGuiCreate failed, rc=%Rrc\n", rc));
2227 }
2228 else
2229 LogRel(("GUI: RTLdrGetSymbol(,\"DBGGuiCreate\",) -> %Rrc\n", rc));
2230
2231 m_pDbgGui = 0;
2232 m_pDbgGuiVT = 0;
2233 return false;
2234}
2235
2236void UISession::dbgDestroy()
2237{
2238 if (m_pDbgGui)
2239 {
2240 m_pDbgGuiVT->pfnDestroy(m_pDbgGui);
2241 m_pDbgGui = 0;
2242 m_pDbgGuiVT = 0;
2243 }
2244}
2245
2246void UISession::dbgShowStatistics()
2247{
2248 const QByteArray &expandBytes = uiCommon().getDebuggerStatisticsExpand().toUtf8();
2249 const QByteArray &filterBytes = uiCommon().getDebuggerStatisticsFilter().toUtf8();
2250 m_pDbgGuiVT->pfnShowStatistics(m_pDbgGui, filterBytes.constData(), expandBytes.constData());
2251}
2252
2253void UISession::dbgShowCommandLine()
2254{
2255 m_pDbgGuiVT->pfnShowCommandLine(m_pDbgGui);
2256}
2257
2258void UISession::dbgAdjustRelativePos()
2259{
2260 if (m_pDbgGui)
2261 {
2262 const QRect rct = activeMachineWindow()->frameGeometry();
2263 m_pDbgGuiVT->pfnAdjustRelativePos(m_pDbgGui, rct.x(), rct.y(), rct.width(), rct.height());
2264 }
2265}
2266#endif /* VBOX_WITH_DEBUGGER_GUI */
2267
2268bool UISession::acquireWhetherGuestEnteredACPIMode(bool &fEntered)
2269{
2270 CConsole comConsole = console();
2271 const BOOL fGuestEntered = comConsole.GetGuestEnteredACPIMode();
2272 const bool fSuccess = comConsole.isOk();
2273 if (!fSuccess)
2274 UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
2275 else
2276 fEntered = fGuestEntered == TRUE;
2277 return fSuccess;
2278}
2279
2280void UISession::saveState()
2281{
2282 if ( isPaused()
2283 || (isRunning() && pause()))
2284 {
2285 /* Enable 'manual-override',
2286 * preventing automatic Runtime UI closing: */
2287 uimachine()->setManualOverrideMode(true);
2288
2289 /* Now, do the magic: */
2290 LogRel(("GUI: Saving VM state..\n"));
2291 UINotificationProgressMachineSaveState *pNotification =
2292 new UINotificationProgressMachineSaveState(machine());
2293 connect(pNotification, &UINotificationProgressMachineSaveState::sigMachineStateSaved,
2294 this, &UISession::sltHandleMachineStateSaved);
2295 gpNotificationCenter->append(pNotification);
2296 }
2297}
2298
2299void UISession::shutdown()
2300{
2301 /* Check whether guest is in proper mode: */
2302 bool fValidMode = false;
2303 acquireWhetherGuestEnteredACPIMode(fValidMode);
2304 if (!fValidMode)
2305 UINotificationMessage::cannotSendACPIToMachine();
2306 else
2307 {
2308 /* Now, do the magic: */
2309 LogRel(("GUI: Sending ACPI shutdown signal..\n"));
2310 CConsole comConsole = console();
2311 comConsole.PowerButton();
2312 if (!comConsole.isOk())
2313 UINotificationMessage::cannotACPIShutdownMachine(comConsole);
2314 }
2315}
2316
2317void UISession::powerOff(bool fIncludingDiscard)
2318{
2319 /* Enable 'manual-override',
2320 * preventing automatic Runtime UI closing: */
2321 uimachine()->setManualOverrideMode(true);
2322
2323 /* Now, do the magic: */
2324 LogRel(("GUI: Powering VM off..\n"));
2325 UINotificationProgressMachinePowerOff *pNotification =
2326 new UINotificationProgressMachinePowerOff(machine(),
2327 console(),
2328 fIncludingDiscard);
2329 connect(pNotification, &UINotificationProgressMachinePowerOff::sigMachinePoweredOff,
2330 this, &UISession::sltHandleMachinePoweredOff);
2331 gpNotificationCenter->append(pNotification);
2332}
2333
2334void UISession::sltInstallGuestAdditionsFrom(const QString &strSource)
2335{
2336 if (!guestAdditionsUpgradable())
2337 return sltMountDVDAdHoc(strSource);
2338
2339 /* Update guest additions automatically: */
2340 UINotificationProgressGuestAdditionsInstall *pNotification =
2341 new UINotificationProgressGuestAdditionsInstall(guest(), strSource);
2342 connect(pNotification, &UINotificationProgressGuestAdditionsInstall::sigGuestAdditionsInstallationFailed,
2343 this, &UISession::sltMountDVDAdHoc);
2344 gpNotificationCenter->append(pNotification);
2345}
2346
2347void UISession::sltMountDVDAdHoc(const QString &strSource)
2348{
2349 mountAdHocImage(KDeviceType_DVD, UIMediumDeviceType_DVD, strSource);
2350}
2351
2352void UISession::sltDetachCOM()
2353{
2354 /* Cleanup everything COM related: */
2355 cleanupFramebuffers();
2356 cleanupConsoleEventHandlers();
2357 cleanupCOMStuff();
2358}
2359
2360void UISession::sltStateChange(KMachineState enmState)
2361{
2362 /* Check if something had changed: */
2363 if (m_enmMachineState != enmState)
2364 {
2365 /* Store new data: */
2366 m_enmMachineStatePrevious = m_enmMachineState;
2367 m_enmMachineState = enmState;
2368
2369 /* Notify listeners about machine state changed: */
2370 emit sigMachineStateChange();
2371 }
2372}
2373
2374void UISession::sltAdditionsChange()
2375{
2376 /* Acquire actual states: */
2377 const ulong ulGuestAdditionsRunLevel = guest().GetAdditionsRunLevel();
2378 LONG64 iLastUpdatedIgnored;
2379 const bool fIsGuestSupportsGraphics = guest().GetFacilityStatus(KAdditionsFacilityType_Graphics, iLastUpdatedIgnored)
2380 == KAdditionsFacilityStatus_Active;
2381 const bool fIsGuestSupportsSeamless = guest().GetFacilityStatus(KAdditionsFacilityType_Seamless, iLastUpdatedIgnored)
2382 == KAdditionsFacilityStatus_Active;
2383
2384 /* Check if something had changed: */
2385 if ( m_ulGuestAdditionsRunLevel != ulGuestAdditionsRunLevel
2386 || m_fIsGuestSupportsGraphics != fIsGuestSupportsGraphics
2387 || m_fIsGuestSupportsSeamless != fIsGuestSupportsSeamless)
2388 {
2389 /* Store new data: */
2390 m_ulGuestAdditionsRunLevel = ulGuestAdditionsRunLevel;
2391 m_fIsGuestSupportsGraphics = fIsGuestSupportsGraphics;
2392 m_fIsGuestSupportsSeamless = fIsGuestSupportsSeamless;
2393
2394 /* Notify listeners about GA state really changed: */
2395 LogRel(("GUI: UISession::sltAdditionsChange: GA state really changed, notifying listeners.\n"));
2396 emit sigAdditionsStateActualChange();
2397 }
2398 else
2399 LogRel(("GUI: UISession::sltAdditionsChange: GA state doesn't really changed, still notifying listeners.\n"));
2400
2401 /* Notify listeners about GA state change event came: */
2402 emit sigAdditionsStateChange();
2403}
2404
2405void UISession::sltHandleMachineStateSaved(bool fSuccess)
2406{
2407 /* Let user try again if saving failed: */
2408 if (!fSuccess)
2409 {
2410 /* Disable 'manual-override' finally: */
2411 uimachine()->setManualOverrideMode(false);
2412 }
2413 /* Close Runtime UI otherwise: */
2414 else
2415 uimachine()->closeRuntimeUI();
2416}
2417
2418void UISession::sltHandleMachinePoweredOff(bool fSuccess, bool fIncludingDiscard)
2419{
2420 /* Let user try again if power off failed: */
2421 if (!fSuccess)
2422 {
2423 /* Disable 'manual-override' finally: */
2424 uimachine()->setManualOverrideMode(false);
2425 }
2426 /* Check for other tasks otherwise: */
2427 else
2428 {
2429 if (fIncludingDiscard)
2430 {
2431 /* Now, do more magic! */
2432 UINotificationProgressSnapshotRestore *pNotification =
2433 new UINotificationProgressSnapshotRestore(uiCommon().managedVMUuid());
2434 connect(pNotification, &UINotificationProgressSnapshotRestore::sigSnapshotRestored,
2435 this, &UISession::sltHandleSnapshotRestored);
2436 gpNotificationCenter->append(pNotification);
2437 }
2438 else
2439 uimachine()->closeRuntimeUI();
2440 }
2441}
2442
2443void UISession::sltHandleSnapshotRestored(bool)
2444{
2445 /* Close Runtime UI independent of snapshot restoring state: */
2446 uimachine()->closeRuntimeUI();
2447}
2448
2449bool UISession::prepareCOMStuff()
2450{
2451 /* Open session: */
2452 m_comSession = uiCommon().openSession(uiCommon().managedVMUuid(),
2453 uiCommon().isSeparateProcess()
2454 ? KLockType_Shared
2455 : KLockType_VM);
2456 if (m_comSession.isNull())
2457 return false;
2458
2459 /* Get machine: */
2460 m_comMachine = m_comSession.GetMachine();
2461 if (m_comMachine.isNull())
2462 return false;
2463
2464 /* Get console: */
2465 m_comConsole = m_comSession.GetConsole();
2466 if (m_comConsole.isNull())
2467 return false;
2468
2469 /* Get display: */
2470 m_comDisplay = m_comConsole.GetDisplay();
2471 if (m_comDisplay.isNull())
2472 return false;
2473
2474 /* Get guest: */
2475 m_comGuest = m_comConsole.GetGuest();
2476 if (m_comGuest.isNull())
2477 return false;
2478
2479 /* Get mouse: */
2480 m_comMouse = m_comConsole.GetMouse();
2481 if (m_comMouse.isNull())
2482 return false;
2483
2484 /* Get keyboard: */
2485 m_comKeyboard = m_comConsole.GetKeyboard();
2486 if (m_comKeyboard.isNull())
2487 return false;
2488
2489 /* Get debugger: */
2490 m_comDebugger = m_comConsole.GetDebugger();
2491 if (m_comDebugger.isNull())
2492 return false;
2493
2494 /* Update machine attributes: */
2495 m_strMachineName = machine().GetName();
2496 m_strOSTypeId = machine().GetOSTypeId();
2497
2498 /* Update machine-state: */
2499 m_enmMachineState = machine().GetState();
2500
2501 /* True by default: */
2502 return true;
2503}
2504
2505void UISession::prepareConsoleEventHandlers()
2506{
2507 /* Create console event-handler: */
2508 m_pConsoleEventhandler = new UIConsoleEventHandler(this);
2509
2510 /* Console event connections: */
2511 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigAdditionsChange,
2512 this, &UISession::sltAdditionsChange);
2513 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigAudioAdapterChange,
2514 this, &UISession::sigAudioAdapterChange);
2515 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigClipboardModeChange,
2516 this, &UISession::sigClipboardModeChange);
2517 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigCPUExecutionCapChange,
2518 this, &UISession::sigCPUExecutionCapChange);
2519 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigDnDModeChange,
2520 this, &UISession::sigDnDModeChange);
2521 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigGuestMonitorChange,
2522 this, &UISession::sigGuestMonitorChange);
2523 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMediumChange,
2524 this, &UISession::sigMediumChange);
2525 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigNetworkAdapterChange,
2526 this, &UISession::sigNetworkAdapterChange);
2527 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigRecordingChange,
2528 this, &UISession::sigRecordingChange);
2529 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigSharedFolderChange,
2530 this, &UISession::sigSharedFolderChange);
2531 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigStateChange,
2532 this, &UISession::sltStateChange);
2533 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigStorageDeviceChange,
2534 this, &UISession::sigStorageDeviceChange);
2535 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigUSBControllerChange,
2536 this, &UISession::sigUSBControllerChange);
2537 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigUSBDeviceStateChange,
2538 this, &UISession::sigUSBDeviceStateChange);
2539 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigVRDEChange,
2540 this, &UISession::sigVRDEChange);
2541 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigRuntimeError,
2542 this, &UISession::sigRuntimeError);
2543
2544#ifdef VBOX_WS_MAC
2545 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigShowWindow,
2546 this, &UISession::sigShowWindows, Qt::QueuedConnection);
2547#endif
2548
2549 /* Console keyboard connections: */
2550 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigKeyboardLedsChange,
2551 this, &UISession::sigKeyboardLedsChange);
2552
2553 /* Console mouse connections: */
2554 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMousePointerShapeChange,
2555 this, &UISession::sigMousePointerShapeChange);
2556 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMouseCapabilityChange,
2557 this, &UISession::sigMouseCapabilityChange);
2558 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigCursorPositionChange,
2559 this, &UISession::sigCursorPositionChange);
2560}
2561
2562void UISession::prepareFramebuffers()
2563{
2564 /* Acquire guest-screen count: */
2565 ulong cGuestScreenCount = 0;
2566 acquireMonitorCount(cGuestScreenCount);
2567 m_frameBufferVector.resize(cGuestScreenCount);
2568
2569 /* Create new frame-buffers: */
2570 for (int iIndex = 0; iIndex < m_frameBufferVector.size(); ++iIndex)
2571 m_frameBufferVector[iIndex] = new UIFrameBuffer;
2572}
2573
2574void UISession::prepareConnections()
2575{
2576 /* UICommon connections: */
2577 connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UISession::sltDetachCOM);
2578}
2579
2580void UISession::prepareSignalHandling()
2581{
2582#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
2583 struct sigaction sa;
2584 sa.sa_sigaction = &signalHandlerSIGUSR1;
2585 sigemptyset(&sa.sa_mask);
2586 sa.sa_flags = SA_RESTART | SA_SIGINFO;
2587 sigaction(SIGUSR1, &sa, NULL);
2588#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
2589}
2590
2591void UISession::cleanupFramebuffers()
2592{
2593 /* Cleanup framebuffers finally: */
2594 for (int i = m_frameBufferVector.size() - 1; i >= 0; --i)
2595 {
2596 UIFrameBuffer *pFrameBuffer = m_frameBufferVector[i];
2597 if (pFrameBuffer)
2598 {
2599 /* Mark framebuffer as unused: */
2600 pFrameBuffer->setMarkAsUnused(true);
2601 /* Detach framebuffer from Display: */
2602 pFrameBuffer->detach();
2603 /* Delete framebuffer reference: */
2604 delete pFrameBuffer;
2605 }
2606 }
2607 m_frameBufferVector.clear();
2608}
2609
2610void UISession::cleanupConsoleEventHandlers()
2611{
2612 /* Destroy console event-handler: */
2613 delete m_pConsoleEventhandler;
2614 m_pConsoleEventhandler = 0;
2615}
2616
2617void UISession::cleanupCOMStuff()
2618{
2619 /* Detach debugger: */
2620 if (!m_comDebugger.isNull())
2621 m_comDebugger.detach();
2622
2623 /* Detach keyboard: */
2624 if (!m_comKeyboard.isNull())
2625 m_comKeyboard.detach();
2626
2627 /* Detach mouse: */
2628 if (!m_comMouse.isNull())
2629 m_comMouse.detach();
2630
2631 /* Detach guest: */
2632 if (!m_comGuest.isNull())
2633 m_comGuest.detach();
2634
2635 /* Detach display: */
2636 if (!m_comDisplay.isNull())
2637 m_comDisplay.detach();
2638
2639 /* Detach console: */
2640 if (!m_comConsole.isNull())
2641 m_comConsole.detach();
2642
2643 /* Detach machine: */
2644 if (!m_comMachine.isNull())
2645 m_comMachine.detach();
2646
2647 /* Close session: */
2648 if (!m_comSession.isNull() && uiCommon().isVBoxSVCAvailable())
2649 {
2650 m_comSession.UnlockMachine();
2651 m_comSession.detach();
2652 }
2653}
2654
2655UIMachineLogic *UISession::machineLogic() const
2656{
2657 return uimachine() ? uimachine()->machineLogic() : 0;
2658}
2659
2660UIMachineWindow *UISession::activeMachineWindow() const
2661{
2662 return machineLogic() ? machineLogic()->activeMachineWindow() : 0;
2663}
2664
2665QWidget *UISession::mainMachineWindow() const
2666{
2667 return machineLogic() ? machineLogic()->mainMachineWindow() : 0;
2668}
2669
2670bool UISession::preprocessInitialization()
2671{
2672#ifdef VBOX_WITH_NETFLT
2673 /* Skip network interface name checks if VM in saved state: */
2674 if (!isSaved())
2675 {
2676 /* Make sure all the attached and enabled network
2677 * adapters are present on the host. This check makes sense
2678 * in two cases only - when attachement type is Bridged Network
2679 * or Host-only Interface. NOTE: Only currently enabled
2680 * attachement type is checked (incorrect parameters check for
2681 * currently disabled attachement types is skipped). */
2682 QStringList failedInterfaceNames;
2683 QStringList availableInterfaceNames;
2684
2685 /* Create host network interface names list: */
2686 foreach (const CHostNetworkInterface &comNetIface, uiCommon().host().GetNetworkInterfaces())
2687 {
2688 availableInterfaceNames << comNetIface.GetName();
2689 availableInterfaceNames << comNetIface.GetShortName();
2690 }
2691
2692 /* Enumerate all the virtual network adapters: */
2693 const ulong cCount = uiCommon().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(machine().GetChipsetType());
2694 for (ulong uAdapterIndex = 0; uAdapterIndex < cCount; ++uAdapterIndex)
2695 {
2696 CNetworkAdapter comNetworkAdapter = machine().GetNetworkAdapter(uAdapterIndex);
2697 if (comNetworkAdapter.GetEnabled())
2698 {
2699 /* Get physical network interface name for
2700 * currently enabled network attachement type: */
2701 QString strInterfaceName;
2702 switch (comNetworkAdapter.GetAttachmentType())
2703 {
2704 case KNetworkAttachmentType_Bridged:
2705 strInterfaceName = comNetworkAdapter.GetBridgedInterface();
2706 break;
2707# ifndef VBOX_WITH_VMNET
2708 case KNetworkAttachmentType_HostOnly:
2709 strInterfaceName = comNetworkAdapter.GetHostOnlyInterface();
2710 break;
2711# endif /* !VBOX_WITH_VMNET */
2712 default:
2713 break;
2714 }
2715
2716 if ( !strInterfaceName.isEmpty()
2717 && !availableInterfaceNames.contains(strInterfaceName))
2718 {
2719 LogRel(("GUI: Invalid network interface found: %s\n", strInterfaceName.toUtf8().constData()));
2720 failedInterfaceNames << QString("%1 (adapter %2)").arg(strInterfaceName).arg(uAdapterIndex + 1);
2721 }
2722 }
2723 }
2724
2725 /* Check if non-existent interfaces found: */
2726 if (!failedInterfaceNames.isEmpty())
2727 {
2728 if (msgCenter().warnAboutNetworkInterfaceNotFound(machineName(), failedInterfaceNames.join(", ")))
2729 machineLogic()->openNetworkSettingsDialog();
2730 else
2731 {
2732 LogRel(("GUI: Aborting startup due to preprocess initialization issue detected...\n"));
2733 return false;
2734 }
2735 }
2736 }
2737#endif /* VBOX_WITH_NETFLT */
2738
2739 /* Check for USB enumeration warning. Don't return false even if we have a warning: */
2740 CHost comHost = uiCommon().host();
2741 if (comHost.GetUSBDevices().isEmpty() && comHost.isWarning())
2742 {
2743 /* Do not bitch if USB disabled: */
2744 if (!machine().GetUSBControllers().isEmpty())
2745 {
2746 /* Do not bitch if there are no filters (check if enabled too?): */
2747 if (!machine().GetUSBDeviceFilters().GetDeviceFilters().isEmpty())
2748 UINotificationMessage::cannotEnumerateHostUSBDevices(comHost);
2749 }
2750 }
2751
2752 /* True by default: */
2753 return true;
2754}
2755
2756bool UISession::mountAdHocImage(KDeviceType enmDeviceType, UIMediumDeviceType enmMediumType, const QString &strMediumName)
2757{
2758 /* Get VBox: */
2759 CVirtualBox comVBox = uiCommon().virtualBox();
2760
2761 /* Prepare medium to mount: */
2762 UIMedium guiMedium;
2763
2764 /* The 'none' medium name means ejecting what ever is in the drive,
2765 * in that case => leave the guiMedium variable null. */
2766 if (strMediumName != "none")
2767 {
2768 /* Open the medium: */
2769 const CMedium comMedium = comVBox.OpenMedium(strMediumName, enmDeviceType, KAccessMode_ReadWrite, false /* fForceNewUuid */);
2770 if (!comVBox.isOk() || comMedium.isNull())
2771 {
2772 UINotificationMessage::cannotOpenMedium(comVBox, strMediumName);
2773 return false;
2774 }
2775
2776 /* Make sure medium ID is valid: */
2777 const QUuid uMediumId = comMedium.GetId();
2778 AssertReturn(!uMediumId.isNull(), false);
2779
2780 /* Try to find UIMedium among cached: */
2781 guiMedium = uiCommon().medium(uMediumId);
2782 if (guiMedium.isNull())
2783 {
2784 /* Cache new one if necessary: */
2785 guiMedium = UIMedium(comMedium, enmMediumType, KMediumState_Created);
2786 uiCommon().createMedium(guiMedium);
2787 }
2788 }
2789
2790 /* Search for a suitable storage slots: */
2791 QList<ExactStorageSlot> aFreeStorageSlots;
2792 QList<ExactStorageSlot> aBusyStorageSlots;
2793 foreach (const CStorageController &comController, machine().GetStorageControllers())
2794 {
2795 foreach (const CMediumAttachment &comAttachment, machine().GetMediumAttachmentsOfController(comController.GetName()))
2796 {
2797 /* Look for an optical devices only: */
2798 if (comAttachment.GetType() == enmDeviceType)
2799 {
2800 /* Append storage slot to corresponding list: */
2801 if (comAttachment.GetMedium().isNull())
2802 aFreeStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(),
2803 comAttachment.GetPort(), comAttachment.GetDevice());
2804 else
2805 aBusyStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(),
2806 comAttachment.GetPort(), comAttachment.GetDevice());
2807 }
2808 }
2809 }
2810
2811 /* Make sure at least one storage slot found: */
2812 QList<ExactStorageSlot> sStorageSlots = aFreeStorageSlots + aBusyStorageSlots;
2813 if (sStorageSlots.isEmpty())
2814 {
2815 UINotificationMessage::cannotMountImage(machineName(), strMediumName);
2816 return false;
2817 }
2818
2819 /* Try to mount medium into first available storage slot: */
2820 while (!sStorageSlots.isEmpty())
2821 {
2822 const ExactStorageSlot storageSlot = sStorageSlots.takeFirst();
2823 machine().MountMedium(storageSlot.controller, storageSlot.port, storageSlot.device, guiMedium.medium(), false /* force */);
2824 if (machine().isOk())
2825 break;
2826 }
2827
2828 /* Show error message if necessary: */
2829 if (!machine().isOk())
2830 {
2831 msgCenter().cannotRemountMedium(machine(), guiMedium, true /* mount? */, false /* retry? */, activeMachineWindow());
2832 return false;
2833 }
2834
2835 /* Save machine settings: */
2836 if (!saveSettings())
2837 return false;
2838
2839 /* True by default: */
2840 return true;
2841}
2842
2843void UISession::recacheMachineMedia()
2844{
2845 /* Compose a list of machine media: */
2846 CMediumVector comMedia;
2847
2848 /* Enumerate all the controllers: */
2849 foreach (const CStorageController &comController, machine().GetStorageControllers())
2850 {
2851 /* Enumerate all the attachments: */
2852 foreach (const CMediumAttachment &comAttachment, machine().GetMediumAttachmentsOfController(comController.GetName()))
2853 {
2854 /* Skip unrelated device types: */
2855 const KDeviceType enmDeviceType = comAttachment.GetType();
2856 if ( enmDeviceType != KDeviceType_HardDisk
2857 && enmDeviceType != KDeviceType_Floppy
2858 && enmDeviceType != KDeviceType_DVD)
2859 continue;
2860 if ( comAttachment.GetIsEjected()
2861 || comAttachment.GetMedium().isNull())
2862 continue;
2863 comMedia.append(comAttachment.GetMedium());
2864 }
2865 }
2866
2867 /* Start media enumeration: */
2868 uiCommon().enumerateMedia(comMedia);
2869}
2870
2871/* static */
2872bool UISession::searchMaxSnapshotIndex(const CMachine &comMachine,
2873 const CSnapshot &comSnapshot,
2874 const QString &strNameTemplate,
2875 ulong &uIndex)
2876{
2877 bool fSuccess = true;
2878 ulong uMaxIndex = 0;
2879 QRegExp regExp(QString("^") + strNameTemplate.arg("([0-9]+)") + QString("$"));
2880 if (!comSnapshot.isNull())
2881 {
2882 /* Check current snapshot name: */
2883 const QString strName = comSnapshot.GetName();
2884 fSuccess = comSnapshot.isOk();
2885 if (!fSuccess)
2886 UINotificationMessage::cannotAcquireSnapshotParameter(comSnapshot);
2887 else
2888 {
2889 const int iPos = regExp.indexIn(strName);
2890 if (iPos != -1)
2891 uMaxIndex = regExp.cap(1).toULong() > uMaxIndex ? regExp.cap(1).toULong() : uMaxIndex;
2892 /* Traversing all the snapshot children: */
2893 QVector<CSnapshot> comSnapshotChildren = comSnapshot.GetChildren();
2894 fSuccess = comSnapshot.isOk();
2895 if (!fSuccess)
2896 UINotificationMessage::cannotAcquireSnapshotParameter(comSnapshot);
2897 else
2898 foreach (const CSnapshot &comSnapshotChild, comSnapshotChildren)
2899 {
2900 ulong uMaxIndexOfChildren = 0;
2901 fSuccess = searchMaxSnapshotIndex(comMachine, comSnapshotChild, strNameTemplate, uMaxIndexOfChildren);
2902 if (!fSuccess)
2903 break;
2904 uMaxIndex = uMaxIndexOfChildren > uMaxIndex ? uMaxIndexOfChildren : uMaxIndex;
2905 }
2906 }
2907 }
2908 if (fSuccess)
2909 uIndex = uMaxIndex;
2910 return fSuccess;
2911}
2912
2913#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
2914/**
2915 * Custom signal handler. When switching VTs, we might not get release events
2916 * for Ctrl-Alt and in case a savestate is performed on the new VT, the VM will
2917 * be saved with modifier keys stuck. This is annoying enough for introducing
2918 * this hack.
2919 */
2920/* static */
2921static void signalHandlerSIGUSR1(int sig, siginfo_t * /* pInfo */, void * /*pSecret */)
2922{
2923 /* Only SIGUSR1 is interesting: */
2924 if (sig == SIGUSR1)
2925 if (gpMachine)
2926 gpMachine->machineLogic()->keyboardHandler()->releaseAllPressedKeys();
2927}
2928#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette