1 | /* $Id: UISession.cpp 98503 2023-02-08 14:13:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UISession class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QApplication>
|
---|
30 | #include <QWidget>
|
---|
31 | #ifdef VBOX_WS_WIN
|
---|
32 | # include <iprt/win/windows.h> /* Workaround for compile errors if included directly by QtWin. */
|
---|
33 | # include <QtWin>
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | /* GUI includes: */
|
---|
37 | #include "UIActionPoolRuntime.h"
|
---|
38 | #include "UICommon.h"
|
---|
39 | #include "UIConsoleEventHandler.h"
|
---|
40 | #include "UIDetailsGenerator.h"
|
---|
41 | #include "UIExtraDataManager.h"
|
---|
42 | #include "UIFrameBuffer.h"
|
---|
43 | #include "UIMachine.h"
|
---|
44 | #include "UIMachineLogic.h"
|
---|
45 | #include "UIMachineView.h"
|
---|
46 | #include "UIMachineWindow.h"
|
---|
47 | #include "UIMedium.h"
|
---|
48 | #include "UIMessageCenter.h"
|
---|
49 | #include "UIMousePointerShapeData.h"
|
---|
50 | #include "UINotificationCenter.h"
|
---|
51 | #include "UISession.h"
|
---|
52 | #include "UISettingsDialogSpecific.h"
|
---|
53 | #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
|
---|
54 | # include "UIKeyboardHandler.h"
|
---|
55 | # include <signal.h>
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | /* COM includes: */
|
---|
59 | #include "CGraphicsAdapter.h"
|
---|
60 | #include "CHostNetworkInterface.h"
|
---|
61 | #include "CHostUSBDevice.h"
|
---|
62 | #include "CMedium.h"
|
---|
63 | #include "CMediumAttachment.h"
|
---|
64 | #include "CSnapshot.h"
|
---|
65 | #include "CStorageController.h"
|
---|
66 | #include "CSystemProperties.h"
|
---|
67 | #include "CUSBController.h"
|
---|
68 | #include "CUSBDeviceFilter.h"
|
---|
69 | #include "CUSBDeviceFilters.h"
|
---|
70 | #ifdef VBOX_WITH_NETFLT
|
---|
71 | # include "CNetworkAdapter.h"
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | /* External includes: */
|
---|
75 | #ifdef VBOX_WS_X11
|
---|
76 | # include <X11/Xlib.h>
|
---|
77 | # include <X11/Xutil.h>
|
---|
78 | #endif
|
---|
79 |
|
---|
80 |
|
---|
81 | #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
|
---|
82 | static void signalHandlerSIGUSR1(int sig, siginfo_t *, void *);
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | /* static */
|
---|
86 | bool UISession::create(UISession *&pSession, UIMachine *pMachine)
|
---|
87 | {
|
---|
88 | /* Make sure NULL pointer passed: */
|
---|
89 | AssertReturn(!pSession, false);
|
---|
90 |
|
---|
91 | /* Create session UI: */
|
---|
92 | pSession = new UISession(pMachine);
|
---|
93 | AssertPtrReturn(pSession, false);
|
---|
94 |
|
---|
95 | /* Make sure it's prepared: */
|
---|
96 | if (!pSession->prepare())
|
---|
97 | {
|
---|
98 | /* Destroy session UI otherwise: */
|
---|
99 | destroy(pSession);
|
---|
100 | /* False in that case: */
|
---|
101 | return false;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* True by default: */
|
---|
105 | return true;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /* static */
|
---|
109 | void UISession::destroy(UISession *&pSession)
|
---|
110 | {
|
---|
111 | /* Make sure valid pointer passed: */
|
---|
112 | AssertPtrReturnVoid(pSession);
|
---|
113 |
|
---|
114 | /* Delete session: */
|
---|
115 | delete pSession;
|
---|
116 | pSession = 0;
|
---|
117 | }
|
---|
118 |
|
---|
119 | bool UISession::initialize()
|
---|
120 | {
|
---|
121 | /* Preprocess initialization: */
|
---|
122 | if (!preprocessInitialization())
|
---|
123 | return false;
|
---|
124 |
|
---|
125 | /* Notify user about mouse&keyboard auto-capturing: */
|
---|
126 | if (gEDataManager->autoCaptureEnabled())
|
---|
127 | UINotificationMessage::remindAboutAutoCapture();
|
---|
128 |
|
---|
129 | m_enmMachineState = machine().GetState();
|
---|
130 |
|
---|
131 | /* Apply debug settings from the command line. */
|
---|
132 | if (!debugger().isNull() && debugger().isOk())
|
---|
133 | {
|
---|
134 | if (uiCommon().areWeToExecuteAllInIem())
|
---|
135 | debugger().SetExecuteAllInIEM(true);
|
---|
136 | if (!uiCommon().isDefaultWarpPct())
|
---|
137 | debugger().SetVirtualTimeRate(uiCommon().getWarpPct());
|
---|
138 | }
|
---|
139 |
|
---|
140 | /* Apply ad-hoc reconfigurations from the command line: */
|
---|
141 | if (uiCommon().hasFloppyImageToMount())
|
---|
142 | mountAdHocImage(KDeviceType_Floppy, UIMediumDeviceType_Floppy, uiCommon().getFloppyImage().toString());
|
---|
143 | if (uiCommon().hasDvdImageToMount())
|
---|
144 | mountAdHocImage(KDeviceType_DVD, UIMediumDeviceType_DVD, uiCommon().getDvdImage().toString());
|
---|
145 |
|
---|
146 | /* Power UP if this is NOT separate process: */
|
---|
147 | if (!uiCommon().isSeparateProcess())
|
---|
148 | if (!powerUp())
|
---|
149 | return false;
|
---|
150 |
|
---|
151 | /* Make sure all the pending Console events converted to signals
|
---|
152 | * during the powerUp() progress above reached their destinations.
|
---|
153 | * That is necessary to make sure all the pending machine state change events processed.
|
---|
154 | * We can't just use the machine state directly acquired from IMachine because there
|
---|
155 | * will be few places which are using stale machine state, not just this one. */
|
---|
156 | QApplication::sendPostedEvents(0, QEvent::MetaCall);
|
---|
157 |
|
---|
158 | /* Check if we missed a really quick termination after successful startup: */
|
---|
159 | if (isTurnedOff())
|
---|
160 | {
|
---|
161 | LogRel(("GUI: Aborting startup due to invalid machine state detected: %d\n", machineState()));
|
---|
162 | return false;
|
---|
163 | }
|
---|
164 |
|
---|
165 | /* Fetch corresponding states: */
|
---|
166 | if (uiCommon().isSeparateProcess())
|
---|
167 | {
|
---|
168 | sltAdditionsChange();
|
---|
169 | }
|
---|
170 | machineLogic()->initializePostPowerUp();
|
---|
171 |
|
---|
172 | #ifdef VBOX_GUI_WITH_PIDFILE
|
---|
173 | uiCommon().createPidfile();
|
---|
174 | #endif /* VBOX_GUI_WITH_PIDFILE */
|
---|
175 |
|
---|
176 | /* True by default: */
|
---|
177 | return true;
|
---|
178 | }
|
---|
179 |
|
---|
180 | bool UISession::powerUp()
|
---|
181 | {
|
---|
182 | /* Power UP machine: */
|
---|
183 | CProgress comProgress = uiCommon().shouldStartPaused() ? console().PowerUpPaused() : console().PowerUp();
|
---|
184 |
|
---|
185 | /* Check for immediate failure: */
|
---|
186 | if (!console().isOk() || comProgress.isNull())
|
---|
187 | {
|
---|
188 | if (uiCommon().showStartVMErrors())
|
---|
189 | msgCenter().cannotStartMachine(console(), machineName());
|
---|
190 | LogRel(("GUI: Aborting startup due to power up issue detected...\n"));
|
---|
191 | return false;
|
---|
192 | }
|
---|
193 |
|
---|
194 | /* Some logging right after we powered up: */
|
---|
195 | LogRel(("GUI: Qt version: %s\n", UICommon::qtRTVersionString().toUtf8().constData()));
|
---|
196 | #ifdef VBOX_WS_X11
|
---|
197 | LogRel(("GUI: X11 Window Manager code: %d\n", (int)uiCommon().typeOfWindowManager()));
|
---|
198 | #endif
|
---|
199 | #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
|
---|
200 | LogRel(("GUI: HID LEDs sync is %s\n", uimachine()->isHidLedsSyncEnabled() ? "enabled" : "disabled"));
|
---|
201 | #else
|
---|
202 | LogRel(("GUI: HID LEDs sync is not supported on this platform\n"));
|
---|
203 | #endif
|
---|
204 |
|
---|
205 | /* Enable 'manual-override',
|
---|
206 | * preventing automatic Runtime UI closing
|
---|
207 | * and visual representation mode changes: */
|
---|
208 | uimachine()->setManualOverrideMode(true);
|
---|
209 |
|
---|
210 | /* Show "Starting/Restoring" progress dialog: */
|
---|
211 | if (isSaved())
|
---|
212 | {
|
---|
213 | msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_state_restore_90px.png", 0, 0);
|
---|
214 | /* After restoring from 'saved' state, machine-window(s) geometry should be adjusted: */
|
---|
215 | machineLogic()->adjustMachineWindowsGeometry();
|
---|
216 | }
|
---|
217 | else
|
---|
218 | {
|
---|
219 | #ifdef VBOX_IS_QT6_OR_LATER /** @todo why is this any problem on qt6? */
|
---|
220 | msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_start_90px.png", 0, 0);
|
---|
221 | #else
|
---|
222 | msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_start_90px.png");
|
---|
223 | #endif
|
---|
224 | /* After VM start, machine-window(s) size-hint(s) should be sent: */
|
---|
225 | machineLogic()->sendMachineWindowsSizeHints();
|
---|
226 | }
|
---|
227 |
|
---|
228 | /* Check for progress failure: */
|
---|
229 | if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
|
---|
230 | {
|
---|
231 | if (uiCommon().showStartVMErrors())
|
---|
232 | msgCenter().cannotStartMachine(comProgress, machineName());
|
---|
233 | LogRel(("GUI: Aborting startup due to power up progress issue detected...\n"));
|
---|
234 | return false;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /* Disable 'manual-override' finally: */
|
---|
238 | uimachine()->setManualOverrideMode(false);
|
---|
239 |
|
---|
240 | /* True by default: */
|
---|
241 | return true;
|
---|
242 | }
|
---|
243 |
|
---|
244 | WId UISession::mainMachineWindowId() const
|
---|
245 | {
|
---|
246 | return mainMachineWindow() ? mainMachineWindow()->winId() : 0;
|
---|
247 | }
|
---|
248 |
|
---|
249 | bool UISession::setPause(bool fPause)
|
---|
250 | {
|
---|
251 | if (fPause)
|
---|
252 | console().Pause();
|
---|
253 | else
|
---|
254 | console().Resume();
|
---|
255 |
|
---|
256 | const bool fOk = console().isOk();
|
---|
257 | if (!fOk)
|
---|
258 | {
|
---|
259 | if (fPause)
|
---|
260 | UINotificationMessage::cannotPauseMachine(console());
|
---|
261 | else
|
---|
262 | UINotificationMessage::cannotResumeMachine(console());
|
---|
263 | }
|
---|
264 |
|
---|
265 | return fOk;
|
---|
266 | }
|
---|
267 |
|
---|
268 | void UISession::putScancode(LONG iCode)
|
---|
269 | {
|
---|
270 | CKeyboard comKeyboard = keyboard();
|
---|
271 | comKeyboard.PutScancode(iCode);
|
---|
272 | if (!comKeyboard.isOk())
|
---|
273 | UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
|
---|
274 | }
|
---|
275 |
|
---|
276 | void UISession::putScancodes(const QVector<LONG> &codes)
|
---|
277 | {
|
---|
278 | CKeyboard comKeyboard = keyboard();
|
---|
279 | comKeyboard.PutScancodes(codes);
|
---|
280 | if (!comKeyboard.isOk())
|
---|
281 | UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
|
---|
282 | }
|
---|
283 |
|
---|
284 | void UISession::putCad()
|
---|
285 | {
|
---|
286 | CKeyboard comKeyboard = keyboard();
|
---|
287 | comKeyboard.PutCAD();
|
---|
288 | if (!comKeyboard.isOk())
|
---|
289 | UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
|
---|
290 | }
|
---|
291 |
|
---|
292 | void UISession::releaseKeys()
|
---|
293 | {
|
---|
294 | CKeyboard comKeyboard = keyboard();
|
---|
295 | comKeyboard.ReleaseKeys();
|
---|
296 | if (!comKeyboard.isOk())
|
---|
297 | UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
|
---|
298 | }
|
---|
299 |
|
---|
300 | void UISession::putUsageCode(LONG iUsageCode, LONG iUsagePage, BOOL fKeyRelease)
|
---|
301 | {
|
---|
302 | CKeyboard comKeyboard = keyboard();
|
---|
303 | comKeyboard.PutUsageCode(iUsageCode, iUsagePage, fKeyRelease);
|
---|
304 | if (!comKeyboard.isOk())
|
---|
305 | UINotificationMessage::cannotChangeKeyboardParameter(comKeyboard);
|
---|
306 | }
|
---|
307 |
|
---|
308 | BOOL UISession::getAbsoluteSupported()
|
---|
309 | {
|
---|
310 | return mouse().GetAbsoluteSupported();
|
---|
311 | }
|
---|
312 |
|
---|
313 | BOOL UISession::getRelativeSupported()
|
---|
314 | {
|
---|
315 | return mouse().GetRelativeSupported();
|
---|
316 | }
|
---|
317 |
|
---|
318 | BOOL UISession::getTouchScreenSupported()
|
---|
319 | {
|
---|
320 | return mouse().GetTouchScreenSupported();
|
---|
321 | }
|
---|
322 |
|
---|
323 | BOOL UISession::getTouchPadSupported()
|
---|
324 | {
|
---|
325 | return mouse().GetTouchPadSupported();
|
---|
326 | }
|
---|
327 |
|
---|
328 | BOOL UISession::getNeedsHostCursor()
|
---|
329 | {
|
---|
330 | return mouse().GetNeedsHostCursor();
|
---|
331 | }
|
---|
332 |
|
---|
333 | void UISession::putMouseEvent(LONG iDx, LONG iDy, LONG iDz, LONG iDw, LONG iButtonState)
|
---|
334 | {
|
---|
335 | CMouse comMouse = mouse();
|
---|
336 | comMouse.PutMouseEvent(iDx, iDy, iDz, iDw, iButtonState);
|
---|
337 | if (!comMouse.isOk())
|
---|
338 | UINotificationMessage::cannotChangeMouseParameter(comMouse);
|
---|
339 | }
|
---|
340 |
|
---|
341 | void UISession::putMouseEventAbsolute(LONG iX, LONG iY, LONG iDz, LONG iDw, LONG iButtonState)
|
---|
342 | {
|
---|
343 | CMouse comMouse = mouse();
|
---|
344 | comMouse.PutMouseEventAbsolute(iX, iY, iDz, iDw, iButtonState);
|
---|
345 | if (!comMouse.isOk())
|
---|
346 | UINotificationMessage::cannotChangeMouseParameter(comMouse);
|
---|
347 | }
|
---|
348 |
|
---|
349 | void UISession::putEventMultiTouch(LONG iCount, const QVector<LONG64> &contacts, BOOL fIsTouchScreen, ULONG uScanTime)
|
---|
350 | {
|
---|
351 | CMouse comMouse = mouse();
|
---|
352 | comMouse.PutEventMultiTouch(iCount, contacts, fIsTouchScreen, uScanTime);
|
---|
353 | if (!comMouse.isOk())
|
---|
354 | UINotificationMessage::cannotChangeMouseParameter(comMouse);
|
---|
355 | }
|
---|
356 |
|
---|
357 | bool UISession::guestAdditionsUpgradable()
|
---|
358 | {
|
---|
359 | if (!machine().isOk())
|
---|
360 | return false;
|
---|
361 |
|
---|
362 | /* Auto GA update is currently for Windows and Linux guests only */
|
---|
363 | const CGuestOSType osType = uiCommon().vmGuestOSType(machine().GetOSTypeId());
|
---|
364 | if (!osType.isOk())
|
---|
365 | return false;
|
---|
366 |
|
---|
367 | const QString strGuestFamily = osType.GetFamilyId();
|
---|
368 | bool fIsWindowOrLinux = strGuestFamily.contains("windows", Qt::CaseInsensitive) || strGuestFamily.contains("linux", Qt::CaseInsensitive);
|
---|
369 |
|
---|
370 | if (!fIsWindowOrLinux)
|
---|
371 | return false;
|
---|
372 |
|
---|
373 | /* Also check whether we have something to update automatically: */
|
---|
374 | if (m_ulGuestAdditionsRunLevel < (ULONG)KAdditionsRunLevelType_Userland)
|
---|
375 | return false;
|
---|
376 |
|
---|
377 | return true;
|
---|
378 | }
|
---|
379 |
|
---|
380 | UIFrameBuffer *UISession::frameBuffer(ulong uScreenId) const
|
---|
381 | {
|
---|
382 | Assert(uScreenId < (ulong)m_frameBufferVector.size());
|
---|
383 | return m_frameBufferVector.value((int)uScreenId, 0);
|
---|
384 | }
|
---|
385 |
|
---|
386 | void UISession::setFrameBuffer(ulong uScreenId, UIFrameBuffer *pFrameBuffer)
|
---|
387 | {
|
---|
388 | Assert(uScreenId < (ulong)m_frameBufferVector.size());
|
---|
389 | if (uScreenId < (ulong)m_frameBufferVector.size())
|
---|
390 | m_frameBufferVector[(int)uScreenId] = pFrameBuffer;
|
---|
391 | }
|
---|
392 |
|
---|
393 | QSize UISession::frameBufferSize(ulong uScreenId) const
|
---|
394 | {
|
---|
395 | UIFrameBuffer *pFramebuffer = frameBuffer(uScreenId);
|
---|
396 | return pFramebuffer ? QSize(pFramebuffer->width(), pFramebuffer->height()) : QSize();
|
---|
397 | }
|
---|
398 |
|
---|
399 | void UISession::acquireDeviceActivity(const QVector<KDeviceType> &deviceTypes, QVector<KDeviceActivity> &states)
|
---|
400 | {
|
---|
401 | CConsole comConsole = console();
|
---|
402 | states = comConsole.GetDeviceActivity(deviceTypes);
|
---|
403 | if (!comConsole.isOk())
|
---|
404 | UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
|
---|
405 | }
|
---|
406 |
|
---|
407 | void UISession::acquireHardDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent)
|
---|
408 | {
|
---|
409 | CMachine comMachine = machine();
|
---|
410 | UIDetailsGenerator::acquireHardDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent);
|
---|
411 | }
|
---|
412 |
|
---|
413 | void UISession::acquireOpticalDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent, bool &fAttachmentsMounted)
|
---|
414 | {
|
---|
415 | CMachine comMachine = machine();
|
---|
416 | UIDetailsGenerator::acquireOpticalDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent, fAttachmentsMounted);
|
---|
417 | }
|
---|
418 |
|
---|
419 | void UISession::acquireFloppyDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent, bool &fAttachmentsMounted)
|
---|
420 | {
|
---|
421 | CMachine comMachine = machine();
|
---|
422 | UIDetailsGenerator::acquireFloppyDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent, fAttachmentsMounted);
|
---|
423 | }
|
---|
424 |
|
---|
425 | void UISession::acquireAudioStatusInfo(QString &strInfo, bool &fAudioEnabled, bool &fEnabledOutput, bool &fEnabledInput)
|
---|
426 | {
|
---|
427 | CMachine comMachine = machine();
|
---|
428 | UIDetailsGenerator::acquireAudioStatusInfo(comMachine, strInfo, fAudioEnabled, fEnabledOutput, fEnabledInput);
|
---|
429 | }
|
---|
430 |
|
---|
431 | void UISession::acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected)
|
---|
432 | {
|
---|
433 | CMachine comMachine = machine();
|
---|
434 | UIDetailsGenerator::acquireNetworkStatusInfo(comMachine, strInfo, fAdaptersPresent, fCablesDisconnected);
|
---|
435 | }
|
---|
436 |
|
---|
437 | void UISession::acquireUsbStatusInfo(QString &strInfo, bool &fUsbEnableds)
|
---|
438 | {
|
---|
439 | CMachine comMachine = machine();
|
---|
440 | CConsole comConsole = console();
|
---|
441 | UIDetailsGenerator::acquireUsbStatusInfo(comMachine, comConsole, strInfo, fUsbEnableds);
|
---|
442 | }
|
---|
443 |
|
---|
444 | void UISession::acquireSharedFoldersStatusInfo(QString &strInfo, bool &fFoldersPresent)
|
---|
445 | {
|
---|
446 | CMachine comMachine = machine();
|
---|
447 | CConsole comConsole = console();
|
---|
448 | CGuest comGuest = guest();
|
---|
449 | UIDetailsGenerator::acquireSharedFoldersStatusInfo(comMachine, comConsole, comGuest, strInfo, fFoldersPresent);
|
---|
450 | }
|
---|
451 |
|
---|
452 | void UISession::acquireDisplayStatusInfo(QString &strInfo, bool &fAcceleration3D)
|
---|
453 | {
|
---|
454 | CMachine comMachine = machine();
|
---|
455 | UIDetailsGenerator::acquireDisplayStatusInfo(comMachine, strInfo, fAcceleration3D);
|
---|
456 | }
|
---|
457 |
|
---|
458 | void UISession::acquireRecordingStatusInfo(QString &strInfo, bool &fRecordingEnabled, bool &fMachinePaused)
|
---|
459 | {
|
---|
460 | CMachine comMachine = machine();
|
---|
461 | fMachinePaused = isPaused();
|
---|
462 | UIDetailsGenerator::acquireRecordingStatusInfo(comMachine, strInfo, fRecordingEnabled);
|
---|
463 | }
|
---|
464 |
|
---|
465 | void UISession::acquireCpuLoadPercentage(int &iPercentage)
|
---|
466 | {
|
---|
467 | CMachineDebugger comDebugger = debugger();
|
---|
468 | ULONG uPctExecuting;
|
---|
469 | ULONG uPctHalted;
|
---|
470 | ULONG uPctOther;
|
---|
471 | comDebugger.GetCPULoad(0x7fffffff, uPctExecuting, uPctHalted, uPctOther);
|
---|
472 | iPercentage = uPctExecuting + uPctOther;
|
---|
473 | }
|
---|
474 |
|
---|
475 | void UISession::acquireFeaturesStatusInfo(QString &strInfo, KVMExecutionEngine &enmEngine,
|
---|
476 | bool fNestedPagingEnabled, bool fUxEnabled,
|
---|
477 | KParavirtProvider enmProvider)
|
---|
478 | {
|
---|
479 | CMachine comMachine = machine();
|
---|
480 | UIDetailsGenerator::acquireFeaturesStatusInfo(comMachine, strInfo,
|
---|
481 | enmEngine,
|
---|
482 | fNestedPagingEnabled, fUxEnabled,
|
---|
483 | enmProvider);
|
---|
484 | }
|
---|
485 |
|
---|
486 | bool UISession::prepareToBeSaved()
|
---|
487 | {
|
---|
488 | return isPaused()
|
---|
489 | || (isRunning() && pause());
|
---|
490 | }
|
---|
491 |
|
---|
492 | bool UISession::prepareToBeShutdowned()
|
---|
493 | {
|
---|
494 | const bool fValidMode = console().GetGuestEnteredACPIMode();
|
---|
495 | if (!fValidMode)
|
---|
496 | UINotificationMessage::cannotSendACPIToMachine();
|
---|
497 | return fValidMode;
|
---|
498 | }
|
---|
499 |
|
---|
500 | void UISession::sltInstallGuestAdditionsFrom(const QString &strSource)
|
---|
501 | {
|
---|
502 | if (!guestAdditionsUpgradable())
|
---|
503 | return sltMountDVDAdHoc(strSource);
|
---|
504 |
|
---|
505 | /* Update guest additions automatically: */
|
---|
506 | UINotificationProgressGuestAdditionsInstall *pNotification =
|
---|
507 | new UINotificationProgressGuestAdditionsInstall(guest(), strSource);
|
---|
508 | connect(pNotification, &UINotificationProgressGuestAdditionsInstall::sigGuestAdditionsInstallationFailed,
|
---|
509 | this, &UISession::sltMountDVDAdHoc);
|
---|
510 | gpNotificationCenter->append(pNotification);
|
---|
511 | }
|
---|
512 |
|
---|
513 | void UISession::sltMountDVDAdHoc(const QString &strSource)
|
---|
514 | {
|
---|
515 | mountAdHocImage(KDeviceType_DVD, UIMediumDeviceType_DVD, strSource);
|
---|
516 | }
|
---|
517 |
|
---|
518 | void UISession::sltDetachCOM()
|
---|
519 | {
|
---|
520 | /* Cleanup everything COM related: */
|
---|
521 | cleanupFramebuffers();
|
---|
522 | cleanupConsoleEventHandlers();
|
---|
523 | cleanupNotificationCenter();
|
---|
524 | cleanupSession();
|
---|
525 | }
|
---|
526 |
|
---|
527 | void UISession::sltStateChange(KMachineState enmState)
|
---|
528 | {
|
---|
529 | /* Check if something had changed: */
|
---|
530 | if (m_enmMachineState != enmState)
|
---|
531 | {
|
---|
532 | /* Store new data: */
|
---|
533 | m_enmMachineStatePrevious = m_enmMachineState;
|
---|
534 | m_enmMachineState = enmState;
|
---|
535 |
|
---|
536 | /* Notify listeners about machine state changed: */
|
---|
537 | emit sigMachineStateChange();
|
---|
538 | }
|
---|
539 | }
|
---|
540 |
|
---|
541 | void UISession::sltAdditionsChange()
|
---|
542 | {
|
---|
543 | /* Acquire actual states: */
|
---|
544 | const ULONG ulGuestAdditionsRunLevel = guest().GetAdditionsRunLevel();
|
---|
545 | LONG64 lLastUpdatedIgnored;
|
---|
546 | const bool fIsGuestSupportsGraphics = guest().GetFacilityStatus(KAdditionsFacilityType_Graphics, lLastUpdatedIgnored)
|
---|
547 | == KAdditionsFacilityStatus_Active;
|
---|
548 | const bool fIsGuestSupportsSeamless = guest().GetFacilityStatus(KAdditionsFacilityType_Seamless, lLastUpdatedIgnored)
|
---|
549 | == KAdditionsFacilityStatus_Active;
|
---|
550 |
|
---|
551 | /* Check if something had changed: */
|
---|
552 | if ( m_ulGuestAdditionsRunLevel != ulGuestAdditionsRunLevel
|
---|
553 | || m_fIsGuestSupportsGraphics != fIsGuestSupportsGraphics
|
---|
554 | || m_fIsGuestSupportsSeamless != fIsGuestSupportsSeamless)
|
---|
555 | {
|
---|
556 | /* Store new data: */
|
---|
557 | m_ulGuestAdditionsRunLevel = ulGuestAdditionsRunLevel;
|
---|
558 | m_fIsGuestSupportsGraphics = fIsGuestSupportsGraphics;
|
---|
559 | m_fIsGuestSupportsSeamless = fIsGuestSupportsSeamless;
|
---|
560 |
|
---|
561 | /* Notify listeners about GA state really changed: */
|
---|
562 | LogRel(("GUI: UISession::sltAdditionsChange: GA state really changed, notifying listeners.\n"));
|
---|
563 | emit sigAdditionsStateActualChange();
|
---|
564 | }
|
---|
565 | else
|
---|
566 | LogRel(("GUI: UISession::sltAdditionsChange: GA state doesn't really changed, still notifying listeners.\n"));
|
---|
567 |
|
---|
568 | /* Notify listeners about GA state change event came: */
|
---|
569 | emit sigAdditionsStateChange();
|
---|
570 | }
|
---|
571 |
|
---|
572 | UISession::UISession(UIMachine *pMachine)
|
---|
573 | : QObject(pMachine)
|
---|
574 | /* Base variables: */
|
---|
575 | , m_pMachine(pMachine)
|
---|
576 | , m_pConsoleEventhandler(0)
|
---|
577 | /* Common variables: */
|
---|
578 | , m_enmMachineStatePrevious(KMachineState_Null)
|
---|
579 | , m_enmMachineState(KMachineState_Null)
|
---|
580 | /* Guest additions flags: */
|
---|
581 | , m_ulGuestAdditionsRunLevel(0)
|
---|
582 | , m_fIsGuestSupportsGraphics(false)
|
---|
583 | , m_fIsGuestSupportsSeamless(false)
|
---|
584 | {
|
---|
585 | }
|
---|
586 |
|
---|
587 | UISession::~UISession()
|
---|
588 | {
|
---|
589 | }
|
---|
590 |
|
---|
591 | bool UISession::prepare()
|
---|
592 | {
|
---|
593 | /* Prepare COM stuff: */
|
---|
594 | if (!prepareSession())
|
---|
595 | return false;
|
---|
596 |
|
---|
597 | /* Cache media early if requested: */
|
---|
598 | if (uiCommon().agressiveCaching())
|
---|
599 | recacheMachineMedia();
|
---|
600 |
|
---|
601 | /* Prepare GUI stuff: */
|
---|
602 | prepareNotificationCenter();
|
---|
603 | prepareConsoleEventHandlers();
|
---|
604 | prepareFramebuffers();
|
---|
605 | prepareConnections();
|
---|
606 | prepareSignalHandling();
|
---|
607 |
|
---|
608 | /* True by default: */
|
---|
609 | return true;
|
---|
610 | }
|
---|
611 |
|
---|
612 | bool UISession::prepareSession()
|
---|
613 | {
|
---|
614 | /* Open session: */
|
---|
615 | m_comSession = uiCommon().openSession(uiCommon().managedVMUuid(),
|
---|
616 | uiCommon().isSeparateProcess()
|
---|
617 | ? KLockType_Shared
|
---|
618 | : KLockType_VM);
|
---|
619 | if (m_comSession.isNull())
|
---|
620 | return false;
|
---|
621 |
|
---|
622 | /* Get machine: */
|
---|
623 | m_comMachine = m_comSession.GetMachine();
|
---|
624 | if (m_comMachine.isNull())
|
---|
625 | return false;
|
---|
626 |
|
---|
627 | /* Get console: */
|
---|
628 | m_comConsole = m_comSession.GetConsole();
|
---|
629 | if (m_comConsole.isNull())
|
---|
630 | return false;
|
---|
631 |
|
---|
632 | /* Get display: */
|
---|
633 | m_comDisplay = m_comConsole.GetDisplay();
|
---|
634 | if (m_comDisplay.isNull())
|
---|
635 | return false;
|
---|
636 |
|
---|
637 | /* Get guest: */
|
---|
638 | m_comGuest = m_comConsole.GetGuest();
|
---|
639 | if (m_comGuest.isNull())
|
---|
640 | return false;
|
---|
641 |
|
---|
642 | /* Get mouse: */
|
---|
643 | m_comMouse = m_comConsole.GetMouse();
|
---|
644 | if (m_comMouse.isNull())
|
---|
645 | return false;
|
---|
646 |
|
---|
647 | /* Get keyboard: */
|
---|
648 | m_comKeyboard = m_comConsole.GetKeyboard();
|
---|
649 | if (m_comKeyboard.isNull())
|
---|
650 | return false;
|
---|
651 |
|
---|
652 | /* Get debugger: */
|
---|
653 | m_comDebugger = m_comConsole.GetDebugger();
|
---|
654 | if (m_comDebugger.isNull())
|
---|
655 | return false;
|
---|
656 |
|
---|
657 | /* Update machine-name: */
|
---|
658 | m_strMachineName = machine().GetName();
|
---|
659 |
|
---|
660 | /* Update machine-state: */
|
---|
661 | m_enmMachineState = machine().GetState();
|
---|
662 |
|
---|
663 | /* True by default: */
|
---|
664 | return true;
|
---|
665 | }
|
---|
666 |
|
---|
667 | void UISession::prepareNotificationCenter()
|
---|
668 | {
|
---|
669 | UINotificationCenter::create();
|
---|
670 | }
|
---|
671 |
|
---|
672 | void UISession::prepareConsoleEventHandlers()
|
---|
673 | {
|
---|
674 | /* Create console event-handler: */
|
---|
675 | m_pConsoleEventhandler = new UIConsoleEventHandler(this);
|
---|
676 |
|
---|
677 | /* Console event connections: */
|
---|
678 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigAdditionsChange,
|
---|
679 | this, &UISession::sltAdditionsChange);
|
---|
680 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigAudioAdapterChange,
|
---|
681 | this, &UISession::sigAudioAdapterChange);
|
---|
682 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigClipboardModeChange,
|
---|
683 | this, &UISession::sigClipboardModeChange);
|
---|
684 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigCPUExecutionCapChange,
|
---|
685 | this, &UISession::sigCPUExecutionCapChange);
|
---|
686 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigDnDModeChange,
|
---|
687 | this, &UISession::sigDnDModeChange);
|
---|
688 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigGuestMonitorChange,
|
---|
689 | this, &UISession::sigGuestMonitorChange);
|
---|
690 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMediumChange,
|
---|
691 | this, &UISession::sigMediumChange);
|
---|
692 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigNetworkAdapterChange,
|
---|
693 | this, &UISession::sigNetworkAdapterChange);
|
---|
694 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigRecordingChange,
|
---|
695 | this, &UISession::sigRecordingChange);
|
---|
696 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigSharedFolderChange,
|
---|
697 | this, &UISession::sigSharedFolderChange);
|
---|
698 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigStateChange,
|
---|
699 | this, &UISession::sltStateChange);
|
---|
700 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigStorageDeviceChange,
|
---|
701 | this, &UISession::sigStorageDeviceChange);
|
---|
702 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigUSBControllerChange,
|
---|
703 | this, &UISession::sigUSBControllerChange);
|
---|
704 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigUSBDeviceStateChange,
|
---|
705 | this, &UISession::sigUSBDeviceStateChange);
|
---|
706 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigVRDEChange,
|
---|
707 | this, &UISession::sigVRDEChange);
|
---|
708 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigRuntimeError,
|
---|
709 | this, &UISession::sigRuntimeError);
|
---|
710 |
|
---|
711 | #ifdef VBOX_WS_MAC
|
---|
712 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigShowWindow,
|
---|
713 | this, &UISession::sigShowWindows, Qt::QueuedConnection);
|
---|
714 | #endif
|
---|
715 |
|
---|
716 | /* Console keyboard connections: */
|
---|
717 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigKeyboardLedsChange,
|
---|
718 | this, &UISession::sigKeyboardLedsChange);
|
---|
719 |
|
---|
720 | /* Console mouse connections: */
|
---|
721 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMousePointerShapeChange,
|
---|
722 | this, &UISession::sigMousePointerShapeChange);
|
---|
723 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMouseCapabilityChange,
|
---|
724 | this, &UISession::sigMouseCapabilityChange);
|
---|
725 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigCursorPositionChange,
|
---|
726 | this, &UISession::sigCursorPositionChange);
|
---|
727 | }
|
---|
728 |
|
---|
729 | void UISession::prepareFramebuffers()
|
---|
730 | {
|
---|
731 | /* Each framebuffer will be really prepared on first UIMachineView creation: */
|
---|
732 | m_frameBufferVector.resize(machine().GetGraphicsAdapter().GetMonitorCount());
|
---|
733 | }
|
---|
734 |
|
---|
735 | void UISession::prepareConnections()
|
---|
736 | {
|
---|
737 | /* UICommon connections: */
|
---|
738 | connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UISession::sltDetachCOM);
|
---|
739 | }
|
---|
740 |
|
---|
741 | void UISession::prepareSignalHandling()
|
---|
742 | {
|
---|
743 | #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
|
---|
744 | struct sigaction sa;
|
---|
745 | sa.sa_sigaction = &signalHandlerSIGUSR1;
|
---|
746 | sigemptyset(&sa.sa_mask);
|
---|
747 | sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
---|
748 | sigaction(SIGUSR1, &sa, NULL);
|
---|
749 | #endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
|
---|
750 | }
|
---|
751 |
|
---|
752 | void UISession::cleanupFramebuffers()
|
---|
753 | {
|
---|
754 | /* Cleanup framebuffers finally: */
|
---|
755 | for (int i = m_frameBufferVector.size() - 1; i >= 0; --i)
|
---|
756 | {
|
---|
757 | UIFrameBuffer *pFrameBuffer = m_frameBufferVector[i];
|
---|
758 | if (pFrameBuffer)
|
---|
759 | {
|
---|
760 | /* Mark framebuffer as unused: */
|
---|
761 | pFrameBuffer->setMarkAsUnused(true);
|
---|
762 | /* Detach framebuffer from Display: */
|
---|
763 | pFrameBuffer->detach();
|
---|
764 | /* Delete framebuffer reference: */
|
---|
765 | delete pFrameBuffer;
|
---|
766 | }
|
---|
767 | }
|
---|
768 | m_frameBufferVector.clear();
|
---|
769 | }
|
---|
770 |
|
---|
771 | void UISession::cleanupConsoleEventHandlers()
|
---|
772 | {
|
---|
773 | /* Destroy console event-handler: */
|
---|
774 | delete m_pConsoleEventhandler;
|
---|
775 | m_pConsoleEventhandler = 0;
|
---|
776 | }
|
---|
777 |
|
---|
778 | void UISession::cleanupNotificationCenter()
|
---|
779 | {
|
---|
780 | UINotificationCenter::destroy();
|
---|
781 | }
|
---|
782 |
|
---|
783 | void UISession::cleanupSession()
|
---|
784 | {
|
---|
785 | /* Detach debugger: */
|
---|
786 | if (!m_comDebugger.isNull())
|
---|
787 | m_comDebugger.detach();
|
---|
788 |
|
---|
789 | /* Detach keyboard: */
|
---|
790 | if (!m_comKeyboard.isNull())
|
---|
791 | m_comKeyboard.detach();
|
---|
792 |
|
---|
793 | /* Detach mouse: */
|
---|
794 | if (!m_comMouse.isNull())
|
---|
795 | m_comMouse.detach();
|
---|
796 |
|
---|
797 | /* Detach guest: */
|
---|
798 | if (!m_comGuest.isNull())
|
---|
799 | m_comGuest.detach();
|
---|
800 |
|
---|
801 | /* Detach display: */
|
---|
802 | if (!m_comDisplay.isNull())
|
---|
803 | m_comDisplay.detach();
|
---|
804 |
|
---|
805 | /* Detach console: */
|
---|
806 | if (!m_comConsole.isNull())
|
---|
807 | m_comConsole.detach();
|
---|
808 |
|
---|
809 | /* Detach machine: */
|
---|
810 | if (!m_comMachine.isNull())
|
---|
811 | m_comMachine.detach();
|
---|
812 |
|
---|
813 | /* Close session: */
|
---|
814 | if (!m_comSession.isNull() && uiCommon().isVBoxSVCAvailable())
|
---|
815 | {
|
---|
816 | m_comSession.UnlockMachine();
|
---|
817 | m_comSession.detach();
|
---|
818 | }
|
---|
819 | }
|
---|
820 |
|
---|
821 | UIMachineLogic *UISession::machineLogic() const
|
---|
822 | {
|
---|
823 | return uimachine() ? uimachine()->machineLogic() : 0;
|
---|
824 | }
|
---|
825 |
|
---|
826 | UIMachineWindow *UISession::activeMachineWindow() const
|
---|
827 | {
|
---|
828 | return machineLogic() ? machineLogic()->activeMachineWindow() : 0;
|
---|
829 | }
|
---|
830 |
|
---|
831 | QWidget *UISession::mainMachineWindow() const
|
---|
832 | {
|
---|
833 | return machineLogic() ? machineLogic()->mainMachineWindow() : 0;
|
---|
834 | }
|
---|
835 |
|
---|
836 | bool UISession::preprocessInitialization()
|
---|
837 | {
|
---|
838 | #ifdef VBOX_WITH_NETFLT
|
---|
839 | /* Skip network interface name checks if VM in saved state: */
|
---|
840 | if (!isSaved())
|
---|
841 | {
|
---|
842 | /* Make sure all the attached and enabled network
|
---|
843 | * adapters are present on the host. This check makes sense
|
---|
844 | * in two cases only - when attachement type is Bridged Network
|
---|
845 | * or Host-only Interface. NOTE: Only currently enabled
|
---|
846 | * attachement type is checked (incorrect parameters check for
|
---|
847 | * currently disabled attachement types is skipped). */
|
---|
848 | QStringList failedInterfaceNames;
|
---|
849 | QStringList availableInterfaceNames;
|
---|
850 |
|
---|
851 | /* Create host network interface names list: */
|
---|
852 | foreach (const CHostNetworkInterface &comNetIface, uiCommon().host().GetNetworkInterfaces())
|
---|
853 | {
|
---|
854 | availableInterfaceNames << comNetIface.GetName();
|
---|
855 | availableInterfaceNames << comNetIface.GetShortName();
|
---|
856 | }
|
---|
857 |
|
---|
858 | /* Enumerate all the virtual network adapters: */
|
---|
859 | const ulong cCount = uiCommon().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(machine().GetChipsetType());
|
---|
860 | for (ulong uAdapterIndex = 0; uAdapterIndex < cCount; ++uAdapterIndex)
|
---|
861 | {
|
---|
862 | CNetworkAdapter comNetworkAdapter = machine().GetNetworkAdapter(uAdapterIndex);
|
---|
863 | if (comNetworkAdapter.GetEnabled())
|
---|
864 | {
|
---|
865 | /* Get physical network interface name for
|
---|
866 | * currently enabled network attachement type: */
|
---|
867 | QString strInterfaceName;
|
---|
868 | switch (comNetworkAdapter.GetAttachmentType())
|
---|
869 | {
|
---|
870 | case KNetworkAttachmentType_Bridged:
|
---|
871 | strInterfaceName = comNetworkAdapter.GetBridgedInterface();
|
---|
872 | break;
|
---|
873 | #ifndef VBOX_WITH_VMNET
|
---|
874 | case KNetworkAttachmentType_HostOnly:
|
---|
875 | strInterfaceName = comNetworkAdapter.GetHostOnlyInterface();
|
---|
876 | break;
|
---|
877 | #endif /* !VBOX_WITH_VMNET */
|
---|
878 | default:
|
---|
879 | break;
|
---|
880 | }
|
---|
881 |
|
---|
882 | if ( !strInterfaceName.isEmpty()
|
---|
883 | && !availableInterfaceNames.contains(strInterfaceName))
|
---|
884 | {
|
---|
885 | LogRel(("GUI: Invalid network interface found: %s\n", strInterfaceName.toUtf8().constData()));
|
---|
886 | failedInterfaceNames << QString("%1 (adapter %2)").arg(strInterfaceName).arg(uAdapterIndex + 1);
|
---|
887 | }
|
---|
888 | }
|
---|
889 | }
|
---|
890 |
|
---|
891 | /* Check if non-existent interfaces found: */
|
---|
892 | if (!failedInterfaceNames.isEmpty())
|
---|
893 | {
|
---|
894 | if (msgCenter().warnAboutNetworkInterfaceNotFound(machineName(), failedInterfaceNames.join(", ")))
|
---|
895 | machineLogic()->openNetworkSettingsDialog();
|
---|
896 | else
|
---|
897 | {
|
---|
898 | LogRel(("GUI: Aborting startup due to preprocess initialization issue detected...\n"));
|
---|
899 | return false;
|
---|
900 | }
|
---|
901 | }
|
---|
902 | }
|
---|
903 | #endif /* VBOX_WITH_NETFLT */
|
---|
904 |
|
---|
905 | /* Check for USB enumeration warning. Don't return false even if we have a warning: */
|
---|
906 | CHost comHost = uiCommon().host();
|
---|
907 | if (comHost.GetUSBDevices().isEmpty() && comHost.isWarning())
|
---|
908 | {
|
---|
909 | /* Do not bitch if USB disabled: */
|
---|
910 | if (!machine().GetUSBControllers().isEmpty())
|
---|
911 | {
|
---|
912 | /* Do not bitch if there are no filters (check if enabled too?): */
|
---|
913 | if (!machine().GetUSBDeviceFilters().GetDeviceFilters().isEmpty())
|
---|
914 | UINotificationMessage::cannotEnumerateHostUSBDevices(comHost);
|
---|
915 | }
|
---|
916 | }
|
---|
917 |
|
---|
918 | /* True by default: */
|
---|
919 | return true;
|
---|
920 | }
|
---|
921 |
|
---|
922 | bool UISession::mountAdHocImage(KDeviceType enmDeviceType, UIMediumDeviceType enmMediumType, const QString &strMediumName)
|
---|
923 | {
|
---|
924 | /* Get VBox: */
|
---|
925 | CVirtualBox comVBox = uiCommon().virtualBox();
|
---|
926 |
|
---|
927 | /* Prepare medium to mount: */
|
---|
928 | UIMedium guiMedium;
|
---|
929 |
|
---|
930 | /* The 'none' medium name means ejecting what ever is in the drive,
|
---|
931 | * in that case => leave the guiMedium variable null. */
|
---|
932 | if (strMediumName != "none")
|
---|
933 | {
|
---|
934 | /* Open the medium: */
|
---|
935 | const CMedium comMedium = comVBox.OpenMedium(strMediumName, enmDeviceType, KAccessMode_ReadWrite, false /* fForceNewUuid */);
|
---|
936 | if (!comVBox.isOk() || comMedium.isNull())
|
---|
937 | {
|
---|
938 | UINotificationMessage::cannotOpenMedium(comVBox, strMediumName);
|
---|
939 | return false;
|
---|
940 | }
|
---|
941 |
|
---|
942 | /* Make sure medium ID is valid: */
|
---|
943 | const QUuid uMediumId = comMedium.GetId();
|
---|
944 | AssertReturn(!uMediumId.isNull(), false);
|
---|
945 |
|
---|
946 | /* Try to find UIMedium among cached: */
|
---|
947 | guiMedium = uiCommon().medium(uMediumId);
|
---|
948 | if (guiMedium.isNull())
|
---|
949 | {
|
---|
950 | /* Cache new one if necessary: */
|
---|
951 | guiMedium = UIMedium(comMedium, enmMediumType, KMediumState_Created);
|
---|
952 | uiCommon().createMedium(guiMedium);
|
---|
953 | }
|
---|
954 | }
|
---|
955 |
|
---|
956 | /* Search for a suitable storage slots: */
|
---|
957 | QList<ExactStorageSlot> aFreeStorageSlots;
|
---|
958 | QList<ExactStorageSlot> aBusyStorageSlots;
|
---|
959 | foreach (const CStorageController &comController, machine().GetStorageControllers())
|
---|
960 | {
|
---|
961 | foreach (const CMediumAttachment &comAttachment, machine().GetMediumAttachmentsOfController(comController.GetName()))
|
---|
962 | {
|
---|
963 | /* Look for an optical devices only: */
|
---|
964 | if (comAttachment.GetType() == enmDeviceType)
|
---|
965 | {
|
---|
966 | /* Append storage slot to corresponding list: */
|
---|
967 | if (comAttachment.GetMedium().isNull())
|
---|
968 | aFreeStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(),
|
---|
969 | comAttachment.GetPort(), comAttachment.GetDevice());
|
---|
970 | else
|
---|
971 | aBusyStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(),
|
---|
972 | comAttachment.GetPort(), comAttachment.GetDevice());
|
---|
973 | }
|
---|
974 | }
|
---|
975 | }
|
---|
976 |
|
---|
977 | /* Make sure at least one storage slot found: */
|
---|
978 | QList<ExactStorageSlot> sStorageSlots = aFreeStorageSlots + aBusyStorageSlots;
|
---|
979 | if (sStorageSlots.isEmpty())
|
---|
980 | {
|
---|
981 | UINotificationMessage::cannotMountImage(machineName(), strMediumName);
|
---|
982 | return false;
|
---|
983 | }
|
---|
984 |
|
---|
985 | /* Try to mount medium into first available storage slot: */
|
---|
986 | while (!sStorageSlots.isEmpty())
|
---|
987 | {
|
---|
988 | const ExactStorageSlot storageSlot = sStorageSlots.takeFirst();
|
---|
989 | machine().MountMedium(storageSlot.controller, storageSlot.port, storageSlot.device, guiMedium.medium(), false /* force */);
|
---|
990 | if (machine().isOk())
|
---|
991 | break;
|
---|
992 | }
|
---|
993 |
|
---|
994 | /* Show error message if necessary: */
|
---|
995 | if (!machine().isOk())
|
---|
996 | {
|
---|
997 | msgCenter().cannotRemountMedium(machine(), guiMedium, true /* mount? */, false /* retry? */, activeMachineWindow());
|
---|
998 | return false;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | /* Save machine settings: */
|
---|
1002 | machine().SaveSettings();
|
---|
1003 |
|
---|
1004 | /* Show error message if necessary: */
|
---|
1005 | if (!machine().isOk())
|
---|
1006 | {
|
---|
1007 | UINotificationMessage::cannotSaveMachineSettings(machine());
|
---|
1008 | return false;
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | /* True by default: */
|
---|
1012 | return true;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | void UISession::recacheMachineMedia()
|
---|
1016 | {
|
---|
1017 | /* Compose a list of machine media: */
|
---|
1018 | CMediumVector comMedia;
|
---|
1019 |
|
---|
1020 | /* Enumerate all the controllers: */
|
---|
1021 | foreach (const CStorageController &comController, machine().GetStorageControllers())
|
---|
1022 | {
|
---|
1023 | /* Enumerate all the attachments: */
|
---|
1024 | foreach (const CMediumAttachment &comAttachment, machine().GetMediumAttachmentsOfController(comController.GetName()))
|
---|
1025 | {
|
---|
1026 | /* Skip unrelated device types: */
|
---|
1027 | const KDeviceType enmDeviceType = comAttachment.GetType();
|
---|
1028 | if ( enmDeviceType != KDeviceType_HardDisk
|
---|
1029 | && enmDeviceType != KDeviceType_Floppy
|
---|
1030 | && enmDeviceType != KDeviceType_DVD)
|
---|
1031 | continue;
|
---|
1032 | if ( comAttachment.GetIsEjected()
|
---|
1033 | || comAttachment.GetMedium().isNull())
|
---|
1034 | continue;
|
---|
1035 | comMedia.append(comAttachment.GetMedium());
|
---|
1036 | }
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | /* Start media enumeration: */
|
---|
1040 | uiCommon().enumerateMedia(comMedia);
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
|
---|
1044 | /**
|
---|
1045 | * Custom signal handler. When switching VTs, we might not get release events
|
---|
1046 | * for Ctrl-Alt and in case a savestate is performed on the new VT, the VM will
|
---|
1047 | * be saved with modifier keys stuck. This is annoying enough for introducing
|
---|
1048 | * this hack.
|
---|
1049 | */
|
---|
1050 | /* static */
|
---|
1051 | static void signalHandlerSIGUSR1(int sig, siginfo_t * /* pInfo */, void * /*pSecret */)
|
---|
1052 | {
|
---|
1053 | /* Only SIGUSR1 is interesting: */
|
---|
1054 | if (sig == SIGUSR1)
|
---|
1055 | if (gpMachine)
|
---|
1056 | gpMachine->machineLogic()->keyboardHandler()->releaseAllPressedKeys();
|
---|
1057 | }
|
---|
1058 | #endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
|
---|