VirtualBox

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

Last change on this file since 98952 was 98952, checked in by vboxsync, 2 years ago

FE/Qt: bugref:10322: Runtime UI: Reattach machine-logic init from session to machine trigger.

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

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