VirtualBox

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

Last change on this file since 104158 was 103793, checked in by vboxsync, 9 months ago

FE/Qt: UICommon: Move versioning related functionality to UIVersion / UIVersionInfo; Rework user cases accordingly.

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