VirtualBox

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

Last change on this file since 102599 was 102599, checked in by vboxsync, 14 months ago

FE/Qt: bugref:10543: A bit of fixes for Runtime UI to acquire real machine architecture instead of using x86.

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