VirtualBox

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

Last change on this file since 98963 was 98963, checked in by vboxsync, 23 months ago

FE/Qt: bugref:10322: Runtime UI: A bunch of sanity fixes for various UISession getters which can be used at startup if COM init or VM startup were failed; There will be more.

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

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