VirtualBox

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

Last change on this file since 102139 was 102139, checked in by vboxsync, 17 months ago

FE/Qt: bugref:10513: Get rid of UISettingsDialog/Specific usage; Keeping files for now, but not include or compile them.

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

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