VirtualBox

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

Last change on this file was 106556, checked in by vboxsync, 7 weeks ago

FE/Qt: bugref:10513: Runtime UI / Machine-logic: At VM startup (if selected bridged adapter wasn't found) we should open Network settings dialog the modal way to pause startup for a moment while another adapter being chosen.

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

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