VirtualBox

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

Last change on this file since 27484 was 27484, checked in by vboxsync, 15 years ago

FE/Qt4: new core: next try

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.7 KB
Line 
1/* $Id: UISession.cpp 27484 2010-03-18 15:08:42Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * UISession stuff implementation
6 */
7
8/*
9 * Copyright (C) 2010 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24/* Global inclues */
25#include <QApplication>
26#include <QWidget>
27#include <QTimer>
28
29/* Local includes */
30#include "UISession.h"
31#include "UIMachine.h"
32#include "UIActionsPool.h"
33#include "UIMachineLogic.h"
34#include "UIMachineWindow.h"
35#include "UIMachineMenuBar.h"
36#include "VBoxProblemReporter.h"
37#include "UIFirstRunWzd.h"
38
39#ifdef Q_WS_X11
40# include <QX11Info>
41# include <X11/Xlib.h>
42# include <X11/Xutil.h>
43# ifndef VBOX_WITHOUT_XCURSOR
44# include <X11/Xcursor/Xcursor.h>
45# endif
46#endif
47
48#if defined (Q_WS_MAC)
49# include "VBoxUtils.h"
50#endif
51
52/* Guest mouse pointer shape change event: */
53class UIMousePointerShapeChangeEvent : public QEvent
54{
55public:
56
57 UIMousePointerShapeChangeEvent(bool bIsVisible, bool bIsAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight, const uchar *pShape)
58 : QEvent((QEvent::Type)UIConsoleEventType_MousePointerShapeChange)
59 , m_bIsVisible(bIsVisible), m_bIsAlpha(bIsAlpha), m_uXHot(uXHot), m_uYHot(uYHot), m_uWidth(uWidth), m_uHeight(uHeight), m_pData(0)
60 {
61 uint dataSize = ((((m_uWidth + 7) / 8 * m_uHeight) + 3) & ~3) + m_uWidth * 4 * m_uHeight;
62 if (pShape)
63 {
64 m_pData = new uchar[dataSize];
65 memcpy((void*)m_pData, (void*)pShape, dataSize);
66 }
67 }
68
69 virtual ~UIMousePointerShapeChangeEvent()
70 {
71 if (m_pData) delete[] m_pData;
72 }
73
74 bool isVisible() const { return m_bIsVisible; }
75 bool hasAlpha() const { return m_bIsAlpha; }
76 uint xHot() const { return m_uXHot; }
77 uint yHot() const { return m_uYHot; }
78 uint width() const { return m_uWidth; }
79 uint height() const { return m_uHeight; }
80 const uchar *shapeData() const { return m_pData; }
81
82private:
83
84 bool m_bIsVisible, m_bIsAlpha;
85 uint m_uXHot, m_uYHot, m_uWidth, m_uHeight;
86 const uchar *m_pData;
87};
88
89/* Guest mouse absolute positioning capability change event: */
90class UIMouseCapabilityChangeEvent : public QEvent
91{
92public:
93
94 UIMouseCapabilityChangeEvent(bool bSupportsAbsolute, bool bSupportsRelative, bool bNeedsHostCursor)
95 : QEvent((QEvent::Type)UIConsoleEventType_MouseCapabilityChange)
96 , m_bSupportsAbsolute(bSupportsAbsolute), m_bSupportsRelative(bSupportsRelative), m_bNeedsHostCursor(bNeedsHostCursor) {}
97
98 bool supportsAbsolute() const { return m_bSupportsAbsolute; }
99 bool supportsRelative() const { return m_bSupportsRelative; }
100 bool needsHostCursor() const { return m_bNeedsHostCursor; }
101
102private:
103
104 bool m_bSupportsAbsolute;
105 bool m_bSupportsRelative;
106 bool m_bNeedsHostCursor;
107};
108
109/* Keyboard LEDs change event: */
110class UIKeyboardLedsChangeEvent : public QEvent
111{
112public:
113
114 UIKeyboardLedsChangeEvent(bool bNumLock, bool bCapsLock, bool bScrollLock)
115 : QEvent((QEvent::Type)UIConsoleEventType_KeyboardLedsChange)
116 , m_bNumLock(bNumLock), m_bCapsLock(bCapsLock), m_bScrollLock(bScrollLock) {}
117
118 bool numLock() const { return m_bNumLock; }
119 bool capsLock() const { return m_bCapsLock; }
120 bool scrollLock() const { return m_bScrollLock; }
121
122private:
123
124 bool m_bNumLock;
125 bool m_bCapsLock;
126 bool m_bScrollLock;
127};
128
129/* Machine state change event: */
130class UIStateChangeEvent : public QEvent
131{
132public:
133
134 UIStateChangeEvent(KMachineState machineState)
135 : QEvent((QEvent::Type)UIConsoleEventType_StateChange)
136 , m_machineState(machineState) {}
137
138 KMachineState machineState() const { return m_machineState; }
139
140private:
141
142 KMachineState m_machineState;
143};
144
145/* Guest Additions state change event: */
146class UIAdditionsStateChangeEvent : public QEvent
147{
148public:
149
150 UIAdditionsStateChangeEvent()
151 : QEvent((QEvent::Type)UIConsoleEventType_AdditionsStateChange) {}
152};
153
154/* Network adapter change event: */
155class UINetworkAdapterChangeEvent : public QEvent
156{
157public:
158
159 UINetworkAdapterChangeEvent(const CNetworkAdapter &networkAdapter)
160 : QEvent((QEvent::Type)UIConsoleEventType_NetworkAdapterChange)
161 , m_networkAdapter(networkAdapter) {}
162
163 const CNetworkAdapter& networkAdapter() { return m_networkAdapter; }
164
165private:
166
167 const CNetworkAdapter m_networkAdapter;
168};
169
170/* Serial port change event: */
171class UISerialPortChangeEvent : public QEvent
172{
173public:
174
175 UISerialPortChangeEvent(const CSerialPort &serialPort)
176 : QEvent((QEvent::Type)UIConsoleEventType_SerialPortChange)
177 , m_serialPort(serialPort) {}
178
179 const CSerialPort& serialPort() { return m_serialPort; }
180
181private:
182
183 const CSerialPort m_serialPort;
184};
185
186/* Parallel port change event: */
187class UIParallelPortChangeEvent : public QEvent
188{
189public:
190
191 UIParallelPortChangeEvent(const CParallelPort &parallelPort)
192 : QEvent((QEvent::Type)UIConsoleEventType_ParallelPortChange)
193 , m_parallelPort(parallelPort) {}
194
195 const CParallelPort& parallelPort() { return m_parallelPort; }
196
197private:
198
199 const CParallelPort m_parallelPort;
200};
201
202/* Storage controller change event: */
203class UIStorageControllerChangeEvent : public QEvent
204{
205public:
206
207 UIStorageControllerChangeEvent()
208 : QEvent((QEvent::Type)UIConsoleEventType_StorageControllerChange) {}
209};
210
211/* Storage medium change event: */
212class UIMediumChangeEvent : public QEvent
213{
214public:
215
216 UIMediumChangeEvent(const CMediumAttachment &mediumAttachment)
217 : QEvent((QEvent::Type)UIConsoleEventType_MediumChange)
218 , m_mediumAttachment(mediumAttachment) {}
219 const CMediumAttachment& mediumAttachment() { return m_mediumAttachment; }
220
221private:
222
223 const CMediumAttachment m_mediumAttachment;
224};
225
226/* CPU change event: */
227class UICPUChangeEvent : public QEvent
228{
229public:
230
231 UICPUChangeEvent(ulong uCPU, bool bRemove)
232 : QEvent((QEvent::Type)UIConsoleEventType_CPUChange)
233 , m_uCPU(uCPU), m_bRemove(bRemove) {}
234
235 ulong cpu() const { return m_uCPU; }
236 bool remove() const { return m_bRemove; }
237
238private:
239
240 ulong m_uCPU;
241 bool m_bRemove;
242};
243
244/* VRDP server change event: */
245class UIVRDPServerChangeEvent : public QEvent
246{
247public:
248
249 UIVRDPServerChangeEvent()
250 : QEvent((QEvent::Type)UIConsoleEventType_VRDPServerChange) {}
251};
252
253/* Remote display info change event: */
254class UIRemoteDisplayInfoChangeEvent : public QEvent
255{
256public:
257
258 UIRemoteDisplayInfoChangeEvent()
259 : QEvent((QEvent::Type)UIConsoleEventType_RemoteDisplayInfoChange) {}
260};
261
262/* USB controller change event: */
263class UIUSBControllerChangeEvent : public QEvent
264{
265public:
266
267 UIUSBControllerChangeEvent()
268 : QEvent((QEvent::Type)UIConsoleEventType_USBControllerChange) {}
269};
270
271/* USB device state change event: */
272class UIUSBDeviceUIStateChangeEvent : public QEvent
273{
274public:
275
276 UIUSBDeviceUIStateChangeEvent(const CUSBDevice &device, bool bAttached, const CVirtualBoxErrorInfo &error)
277 : QEvent((QEvent::Type)UIConsoleEventType_USBDeviceStateChange)
278 , m_device(device), m_bAttached(bAttached), m_error(error) {}
279
280 const CUSBDevice& device() const { return m_device; }
281 bool attached() const { return m_bAttached; }
282 const CVirtualBoxErrorInfo& error() const { return m_error; }
283
284private:
285
286 const CUSBDevice m_device;
287 bool m_bAttached;
288 const CVirtualBoxErrorInfo m_error;
289};
290
291/* Shared folder change event: */
292class UISharedFolderChangeEvent : public QEvent
293{
294public:
295
296 UISharedFolderChangeEvent()
297 : QEvent((QEvent::Type)UIConsoleEventType_SharedFolderChange) {}
298};
299
300/* VM Runtime error event: */
301class UIRuntimeErrorEvent : public QEvent
302{
303public:
304
305 UIRuntimeErrorEvent(bool bFatal, const QString &strErrorID, const QString &strMessage)
306 : QEvent((QEvent::Type)UIConsoleEventType_RuntimeError)
307 , m_bFatal(bFatal), m_strErrorID(strErrorID), m_strMessage(strMessage) {}
308
309 bool fatal() const { return m_bFatal; }
310 QString errorID() const { return m_strErrorID; }
311 QString message() const { return m_strMessage; }
312
313private:
314
315 bool m_bFatal;
316 QString m_strErrorID;
317 QString m_strMessage;
318};
319
320/* Can show window event: */
321class UICanUIShowWindowEvent : public QEvent
322{
323public:
324
325 UICanUIShowWindowEvent()
326 : QEvent((QEvent::Type)UIConsoleEventType_CanShowWindow) {}
327};
328
329/* Show window event: */
330class UIShowWindowEvent : public QEvent
331{
332public:
333
334 UIShowWindowEvent()
335 : QEvent((QEvent::Type)UIConsoleEventType_ShowWindow) {}
336};
337
338class UIConsoleCallback : VBOX_SCRIPTABLE_IMPL(IConsoleCallback)
339{
340public:
341
342 UIConsoleCallback(UISession *pEventHandler)
343 : m_pEventHandler(pEventHandler)
344#if defined (Q_WS_WIN)
345 , m_iRefCount(0)
346#endif
347 {
348 }
349
350 virtual ~UIConsoleCallback()
351 {
352 }
353
354 NS_DECL_ISUPPORTS
355
356#if defined (Q_WS_WIN)
357 STDMETHOD_(ULONG, AddRef)()
358 {
359 return ::InterlockedIncrement(&m_iRefCount);
360 }
361 STDMETHOD_(ULONG, Release)()
362 {
363 long iCount = ::InterlockedDecrement(&m_iRefCount);
364 if (iCount == 0)
365 delete this;
366 return iCount;
367 }
368#endif
369
370 VBOX_SCRIPTABLE_DISPATCH_IMPL(IConsoleCallback)
371
372 STDMETHOD(OnMousePointerShapeChange)(BOOL bIsVisible, BOOL bAlpha, ULONG uXHot, ULONG uYHot, ULONG uWidth, ULONG uHeight, BYTE *pShape)
373 {
374 QApplication::postEvent(m_pEventHandler, new UIMousePointerShapeChangeEvent(bIsVisible, bAlpha, uXHot, uYHot, uWidth, uHeight, pShape));
375 return S_OK;
376 }
377
378 STDMETHOD(OnMouseCapabilityChange)(BOOL bSupportsAbsolute, BOOL bSupportsRelative, BOOL bNeedHostCursor)
379 {
380 QApplication::postEvent(m_pEventHandler, new UIMouseCapabilityChangeEvent(bSupportsAbsolute, bSupportsRelative, bNeedHostCursor));
381 return S_OK;
382 }
383
384 STDMETHOD(OnKeyboardLedsChange)(BOOL bNumLock, BOOL bCapsLock, BOOL bScrollLock)
385 {
386 QApplication::postEvent(m_pEventHandler, new UIKeyboardLedsChangeEvent(bNumLock, bCapsLock, bScrollLock));
387 return S_OK;
388 }
389
390 STDMETHOD(OnStateChange)(MachineState_T machineState)
391 {
392 QApplication::postEvent(m_pEventHandler, new UIStateChangeEvent((KMachineState)machineState));
393 return S_OK;
394 }
395
396 STDMETHOD(OnAdditionsStateChange)()
397 {
398 QApplication::postEvent(m_pEventHandler, new UIAdditionsStateChangeEvent);
399 return S_OK;
400 }
401
402 STDMETHOD(OnNetworkAdapterChange)(INetworkAdapter *pNetworkAdapter)
403 {
404 QApplication::postEvent(m_pEventHandler, new UINetworkAdapterChangeEvent(CNetworkAdapter(pNetworkAdapter)));
405 return S_OK;
406 }
407
408 STDMETHOD(OnSerialPortChange)(ISerialPort *pSerialPort)
409 {
410 QApplication::postEvent(m_pEventHandler, new UISerialPortChangeEvent(CSerialPort(pSerialPort)));
411 return S_OK;
412 }
413
414 STDMETHOD(OnParallelPortChange)(IParallelPort *pParallelPort)
415 {
416 QApplication::postEvent(m_pEventHandler, new UIParallelPortChangeEvent(CParallelPort(pParallelPort)));
417 return S_OK;
418 }
419
420 STDMETHOD(OnStorageControllerChange)()
421 {
422 QApplication::postEvent(m_pEventHandler, new UIStorageControllerChangeEvent);
423 return S_OK;
424 }
425
426 STDMETHOD(OnMediumChange)(IMediumAttachment *pMediumAttachment)
427 {
428 QApplication::postEvent(m_pEventHandler, new UIMediumChangeEvent(CMediumAttachment(pMediumAttachment)));
429 return S_OK;
430 }
431
432 STDMETHOD(OnCPUChange)(ULONG uCPU, BOOL bRemove)
433 {
434 QApplication::postEvent(m_pEventHandler, new UICPUChangeEvent(uCPU, bRemove));
435 return S_OK;
436 }
437
438 STDMETHOD(OnVRDPServerChange)()
439 {
440 QApplication::postEvent(m_pEventHandler, new UIVRDPServerChangeEvent);
441 return S_OK;
442 }
443
444 STDMETHOD(OnRemoteDisplayInfoChange)()
445 {
446 QApplication::postEvent(m_pEventHandler, new UIRemoteDisplayInfoChangeEvent);
447 return S_OK;
448 }
449
450 STDMETHOD(OnUSBControllerChange)()
451 {
452 QApplication::postEvent(m_pEventHandler, new UIUSBControllerChangeEvent);
453 return S_OK;
454 }
455
456 STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *pDevice, BOOL bAttached, IVirtualBoxErrorInfo *pError)
457 {
458 QApplication::postEvent(m_pEventHandler, new UIUSBDeviceUIStateChangeEvent(CUSBDevice(pDevice), bAttached, CVirtualBoxErrorInfo(pError)));
459 return S_OK;
460 }
461
462 STDMETHOD(OnSharedFolderChange)(Scope_T scope)
463 {
464 NOREF(scope);
465 QApplication::postEvent(m_pEventHandler, new UISharedFolderChangeEvent);
466 return S_OK;
467 }
468
469 STDMETHOD(OnRuntimeError)(BOOL bFatal, IN_BSTR strId, IN_BSTR strMessage)
470 {
471 QApplication::postEvent(m_pEventHandler, new UIRuntimeErrorEvent(bFatal, QString::fromUtf16(strId), QString::fromUtf16(strMessage)));
472 return S_OK;
473 }
474
475 STDMETHOD(OnCanShowWindow)(BOOL *pbCanShow)
476 {
477 if (!pbCanShow)
478 return E_POINTER;
479
480 *pbCanShow = TRUE;
481 return S_OK;
482 }
483
484 STDMETHOD(OnShowWindow)(ULONG64 *puWinId)
485 {
486 if (!puWinId)
487 return E_POINTER;
488
489#if defined (Q_WS_MAC)
490 /* Let's try the simple approach first - grab the focus.
491 * Getting a window out of the dock (minimized or whatever it's called)
492 * needs to be done on the GUI thread, so post it a note: */
493 *puWinId = 0;
494 if (!m_pEventHandler)
495 return S_OK;
496
497 if (::darwinSetFrontMostProcess())
498 QApplication::postEvent(m_pEventHandler, new UIShowWindowEvent);
499 else
500 {
501 /* It failed for some reason, send the other process our PSN so it can try.
502 * (This is just a precaution should Mac OS X start imposing the same sensible
503 * focus stealing restrictions that other window managers implement). */
504 *puWinId = ::darwinGetCurrentProcessId();
505 }
506#else
507 /* Return the ID of the top-level console window. */
508 *puWinId = (ULONG64)m_pEventHandler->winId();
509#endif
510
511 return S_OK;
512 }
513
514private:
515
516 UISession *m_pEventHandler;
517
518#if defined (Q_WS_WIN)
519 long m_iRefCount;
520#endif
521};
522
523#if !defined (Q_WS_WIN)
524NS_DECL_CLASSINFO(UIConsoleCallback)
525NS_IMPL_THREADSAFE_ISUPPORTS1_CI(UIConsoleCallback, IConsoleCallback)
526#endif
527
528UISession::UISession(UIMachine *pMachine, CSession &sessionReference)
529 : QObject(pMachine)
530 /* Base variables: */
531 , m_pMachine(pMachine)
532 , m_session(sessionReference)
533 , m_callback(CConsoleCallback(new UIConsoleCallback(this)))
534 /* Common variables: */
535 , m_pMenuPool(0)
536 , m_machineState(KMachineState_Null)
537#if defined(Q_WS_WIN)
538 , m_alphaCursor(0)
539#endif
540 /* Common flags: */
541 , m_fIsFirstTimeStarted(false)
542 , m_fIsIgnoreRutimeMediumsChanging(false)
543 , m_fIsGuestResizeIgnored(false)
544 , m_fIsSeamlessModeRequested(false)
545 /* Guest additions flags: */
546 , m_fIsGuestAdditionsActive(false)
547 , m_fIsGuestSupportsGraphics(false)
548 , m_fIsGuestSupportsSeamless(false)
549 /* Mouse flags: */
550 , m_fNumLock(false)
551 , m_fCapsLock(false)
552 , m_fScrollLock(false)
553 , m_uNumLockAdaptionCnt(2)
554 , m_uCapsLockAdaptionCnt(2)
555 /* Mouse flags: */
556 , m_fIsMouseSupportsAbsolute(false)
557 , m_fIsMouseSupportsRelative(false)
558 , m_fIsMouseHostCursorNeeded(false)
559 , m_fIsMouseCaptured(false)
560 , m_fIsMouseIntegrated(true)
561 , m_fIsValidPointerShapePresent(false)
562 , m_fIsHidingHostPointer(true)
563{
564 /* Register console callback: */
565 session().GetConsole().RegisterCallback(m_callback);
566
567 /* Prepare main menu: */
568 prepareMenuPool();
569
570 /* Load uisession settings: */
571 loadSessionSettings();
572}
573
574UISession::~UISession()
575{
576 /* Save uisession settings: */
577 saveSessionSettings();
578
579 /* Cleanup main menu: */
580 cleanupMenuPool();
581
582 /* Unregister console callback: */
583 session().GetConsole().UnregisterCallback(m_callback);
584
585#if defined(Q_WS_WIN)
586 /* Destroy alpha cursor: */
587 if (m_alphaCursor)
588 DestroyIcon(m_alphaCursor);
589#endif
590}
591
592void UISession::powerUp()
593{
594 /* Do nothing if we had started already: */
595 if (isRunning() || isPaused())
596 return;
597
598 /* Prepare powerup: */
599 preparePowerUp();
600
601 /* Get current machine/console: */
602 CMachine machine = session().GetMachine();
603 CConsole console = session().GetConsole();
604
605 /* Power UP machine: */
606 CProgress progress = vboxGlobal().isStartPausedEnabled() || vboxGlobal().isDebuggerAutoShowEnabled() ?
607 console.PowerUpPaused() : console.PowerUp();
608
609 /* Check for immediate failure: */
610 if (!console.isOk())
611 {
612 if (vboxGlobal().showStartVMErrors())
613 vboxProblem().cannotStartMachine(console);
614 QTimer::singleShot(0, this, SLOT(sltCloseVirtualSession()));
615 return;
616 }
617
618 /* Guard progressbar warnings from auto-closing: */
619 if (uimachine()->machineLogic())
620 uimachine()->machineLogic()->setPreventAutoClose(true);
621
622 /* Show "Starting/Restoring" progress dialog: */
623 if (isSaved())
624 vboxProblem().showModalProgressDialog(progress, machine.GetName(), mainMachineWindow(), 0);
625 else
626 vboxProblem().showModalProgressDialog(progress, machine.GetName(), mainMachineWindow());
627
628 /* Allow further auto-closing: */
629 if (uimachine()->machineLogic())
630 uimachine()->machineLogic()->setPreventAutoClose(false);
631
632 /* Check for a progress failure: */
633 if (progress.GetResultCode() != 0)
634 {
635 if (vboxGlobal().showStartVMErrors())
636 vboxProblem().cannotStartMachine(progress);
637 QTimer::singleShot(0, this, SLOT(sltCloseVirtualSession()));
638 return;
639 }
640
641 /* Check if we missed a really quick termination after successful startup, and process it if we did: */
642 if (isTurnedOff())
643 {
644 QTimer::singleShot(0, this, SLOT(sltCloseVirtualSession()));
645 return;
646 }
647
648#if 0 // TODO: Rework debugger logic!
649# ifdef VBOX_WITH_DEBUGGER_GUI
650 /* Open the debugger in "full screen" mode requested by the user. */
651 else if (vboxGlobal().isDebuggerAutoShowEnabled())
652 {
653 /* console in upper left corner of the desktop. */
654 QRect rct (0, 0, 0, 0);
655 QDesktopWidget *desktop = QApplication::desktop();
656 if (desktop)
657 rct = desktop->availableGeometry(pos());
658 move (QPoint (rct.x(), rct.y()));
659
660 if (vboxGlobal().isDebuggerAutoShowStatisticsEnabled())
661 sltShowDebugStatistics();
662 if (vboxGlobal().isDebuggerAutoShowCommandLineEnabled())
663 sltShowDebugCommandLine();
664
665 if (!vboxGlobal().isStartPausedEnabled())
666 machineWindowWrapper()->machineView()->pause (false);
667 }
668# endif
669#endif
670
671 /* Warn listeners about machine was started: */
672 emit sigMachineStarted();
673}
674
675UIActionsPool* UISession::actionsPool() const
676{
677 return m_pMachine->actionsPool();
678}
679
680QWidget* UISession::mainMachineWindow() const
681{
682 return uimachine()->machineLogic()->mainMachineWindow()->machineWindow();
683}
684
685QMenu* UISession::newMenu(UIMainMenuType fOptions /* = UIMainMenuType_ALL */)
686{
687 /* Create new menu: */
688 QMenu *pMenu = m_pMenuPool->createMenu(actionsPool(), fOptions);
689
690 /* Re-init menu pool for the case menu were recreated: */
691 reinitMenuPool();
692
693 /* Return newly created menu: */
694 return pMenu;
695}
696
697QMenuBar* UISession::newMenuBar(UIMainMenuType fOptions /* = UIMainMenuType_ALL */)
698{
699 /* Create new menubar: */
700 QMenuBar *pMenuBar = m_pMenuPool->createMenuBar(actionsPool(), fOptions);
701
702 /* Re-init menu pool for the case menu were recreated: */
703 reinitMenuPool();
704
705 /* Return newly created menubar: */
706 return pMenuBar;
707}
708
709bool UISession::setPause(bool fOn)
710{
711 if (isPaused() == fOn)
712 return true;
713
714 CConsole console = session().GetConsole();
715
716 if (fOn)
717 console.Pause();
718 else
719 console.Resume();
720
721 bool ok = console.isOk();
722 if (!ok)
723 {
724 if (fOn)
725 vboxProblem().cannotPauseMachine(console);
726 else
727 vboxProblem().cannotResumeMachine(console);
728 }
729
730 return ok;
731}
732
733void UISession::sltInstallGuestAdditionsFrom(const QString &strSource)
734{
735 CMachine machine = session().GetMachine();
736 CVirtualBox vbox = vboxGlobal().virtualBox();
737 QString strUuid;
738
739 CMedium image = vbox.FindDVDImage(strSource);
740 if (image.isNull())
741 {
742 image = vbox.OpenDVDImage(strSource, strUuid);
743 if (vbox.isOk())
744 strUuid = image.GetId();
745 }
746 else
747 strUuid = image.GetId();
748
749 if (!vbox.isOk())
750 {
751 vboxProblem().cannotOpenMedium(0, vbox, VBoxDefs::MediumType_DVD, strSource);
752 return;
753 }
754
755 AssertMsg(!strUuid.isNull(), ("Guest Additions image UUID should be valid!\n"));
756
757 QString strCntName;
758 LONG iCntPort = -1, iCntDevice = -1;
759 /* Searching for the first suitable slot */
760 {
761 CStorageControllerVector controllers = machine.GetStorageControllers();
762 int i = 0;
763 while (i < controllers.size() && strCntName.isNull())
764 {
765 CStorageController controller = controllers[i];
766 CMediumAttachmentVector attachments = machine.GetMediumAttachmentsOfController(controller.GetName());
767 int j = 0;
768 while (j < attachments.size() && strCntName.isNull())
769 {
770 CMediumAttachment attachment = attachments[j];
771 if (attachment.GetType() == KDeviceType_DVD)
772 {
773 strCntName = controller.GetName();
774 iCntPort = attachment.GetPort();
775 iCntDevice = attachment.GetDevice();
776 }
777 ++ j;
778 }
779 ++ i;
780 }
781 }
782
783 if (!strCntName.isNull())
784 {
785 bool fIsMounted = false;
786
787 /* Mount medium to the predefined port/device */
788 machine.MountMedium(strCntName, iCntPort, iCntDevice, strUuid, false /* force */);
789 if (machine.isOk())
790 fIsMounted = true;
791 else
792 {
793 /* Ask for force mounting */
794 if (vboxProblem().cannotRemountMedium(0, machine, VBoxMedium(image, VBoxDefs::MediumType_DVD),
795 true /* mount? */, true /* retry? */) == QIMessageBox::Ok)
796 {
797 /* Force mount medium to the predefined port/device */
798 machine.MountMedium(strCntName, iCntPort, iCntDevice, strUuid, true /* force */);
799 if (machine.isOk())
800 fIsMounted = true;
801 else
802 vboxProblem().cannotRemountMedium(0, machine, VBoxMedium(image, VBoxDefs::MediumType_DVD),
803 true /* mount? */, false /* retry? */);
804 }
805 }
806 }
807 else
808 vboxProblem().cannotMountGuestAdditions(machine.GetName());
809}
810
811void UISession::sltCloseVirtualSession()
812{
813 m_pMachine->closeVirtualMachine();
814}
815
816bool UISession::event(QEvent *pEvent)
817{
818 switch (pEvent->type())
819 {
820 case UIConsoleEventType_MousePointerShapeChange:
821 {
822 /* Convert to mouse shape change event: */
823 UIMousePointerShapeChangeEvent *pConsoleEvent = static_cast<UIMousePointerShapeChangeEvent*>(pEvent);
824
825 /* In case of shape data is present: */
826 if (pConsoleEvent->shapeData())
827 {
828 /* We are ignoring visibility flag: */
829 m_fIsHidingHostPointer = false;
830
831 /* And updating current cursor shape: */
832 setPointerShape(pConsoleEvent->shapeData(), pConsoleEvent->hasAlpha(),
833 pConsoleEvent->xHot(), pConsoleEvent->yHot(),
834 pConsoleEvent->width(), pConsoleEvent->height());
835 }
836 /* In case of shape data is NOT present: */
837 else
838 {
839 /* Remember if we should hide the cursor: */
840 m_fIsHidingHostPointer = !pConsoleEvent->isVisible();
841 }
842
843 /* Notify listeners about mouse capability changed: */
844 emit sigMousePointerShapeChange();
845
846 /* Accept event: */
847 pEvent->accept();
848 return true;
849 }
850
851 case UIConsoleEventType_MouseCapabilityChange:
852 {
853 /* Convert to mouse capability event: */
854 UIMouseCapabilityChangeEvent *pConsoleEvent = static_cast<UIMouseCapabilityChangeEvent*>(pEvent);
855
856 /* Check if something had changed: */
857 if (m_fIsMouseSupportsAbsolute != pConsoleEvent->supportsAbsolute() ||
858 m_fIsMouseSupportsRelative != pConsoleEvent->supportsRelative() ||
859 m_fIsMouseHostCursorNeeded != pConsoleEvent->needsHostCursor())
860 {
861 /* Store new data: */
862 m_fIsMouseSupportsAbsolute = pConsoleEvent->supportsAbsolute();
863 m_fIsMouseSupportsRelative = pConsoleEvent->supportsRelative();
864 m_fIsMouseHostCursorNeeded = pConsoleEvent->needsHostCursor();
865
866 /* Notify listeners about mouse capability changed: */
867 emit sigMouseCapabilityChange();
868 }
869
870 /* Accept event: */
871 pEvent->accept();
872 return true;
873 }
874
875 case UIConsoleEventType_KeyboardLedsChange:
876 {
877 /* Convert to keyboard LEDs change event: */
878 UIKeyboardLedsChangeEvent *pConsoleEvent = static_cast<UIKeyboardLedsChangeEvent*>(pEvent);
879
880 /* Check if something had changed: */
881 if (m_fNumLock != pConsoleEvent->numLock() ||
882 m_fCapsLock != pConsoleEvent->capsLock() ||
883 m_fScrollLock != pConsoleEvent->scrollLock())
884 {
885 /* Store new num lock data: */
886 if (m_fNumLock != pConsoleEvent->numLock())
887 {
888 m_fNumLock = pConsoleEvent->numLock();
889 m_uNumLockAdaptionCnt = 2;
890 }
891
892 /* Store new caps lock data: */
893 if (m_fCapsLock != pConsoleEvent->capsLock())
894 {
895 m_fCapsLock = pConsoleEvent->capsLock();
896 m_uCapsLockAdaptionCnt = 2;
897 }
898
899 /* Store new scroll lock data: */
900 if (m_fScrollLock != pConsoleEvent->scrollLock())
901 {
902 m_fScrollLock = pConsoleEvent->scrollLock();
903 }
904
905 /* Notify listeners about mouse capability changed: */
906 emit sigKeyboardLedsChange();
907 }
908
909 /* Accept event: */
910 pEvent->accept();
911 return true;
912 }
913
914 case UIConsoleEventType_StateChange:
915 {
916 /* Convert to machine state event: */
917 UIStateChangeEvent *pConsoleEvent = static_cast<UIStateChangeEvent*>(pEvent);
918
919 /* Check if something had changed: */
920 if (m_machineState != pConsoleEvent->machineState())
921 {
922 /* Store new data: */
923 m_machineState = pConsoleEvent->machineState();
924
925 /* Notify listeners about machine state changed: */
926 emit sigMachineStateChange();
927 }
928
929 /* Accept event: */
930 pEvent->accept();
931 return true;
932 }
933
934 case UIConsoleEventType_AdditionsStateChange:
935 {
936 /* Get our guest: */
937 CGuest guest = session().GetConsole().GetGuest();
938
939 /* Variable flags: */
940 bool fIsGuestAdditionsActive = guest.GetAdditionsActive();
941 bool fIsGuestSupportsGraphics = guest.GetSupportsGraphics();
942 bool fIsGuestSupportsSeamless = guest.GetSupportsSeamless();
943
944 /* Check if something had changed: */
945 if (m_fIsGuestAdditionsActive != fIsGuestAdditionsActive ||
946 m_fIsGuestSupportsGraphics != fIsGuestSupportsGraphics ||
947 m_fIsGuestSupportsSeamless != fIsGuestSupportsSeamless)
948 {
949 /* Store new data: */
950 m_fIsGuestAdditionsActive = fIsGuestAdditionsActive;
951 m_fIsGuestSupportsGraphics = fIsGuestSupportsGraphics;
952 m_fIsGuestSupportsSeamless = fIsGuestSupportsSeamless;
953
954 /* Notify listeners about guest additions state changed: */
955 emit sigAdditionsStateChange();
956 }
957
958 /* Accept event: */
959 pEvent->accept();
960 return true;
961 }
962
963 case UIConsoleEventType_NetworkAdapterChange:
964 {
965 UINetworkAdapterChangeEvent *pConsoleEvent = static_cast<UINetworkAdapterChangeEvent*>(pEvent);
966 emit sigNetworkAdapterChange(pConsoleEvent->networkAdapter());
967 return true;
968 }
969
970 case UIConsoleEventType_SerialPortChange:
971 {
972 UISerialPortChangeEvent *pConsoleEvent = static_cast<UISerialPortChangeEvent*>(pEvent);
973 emit sigSerialPortChange(pConsoleEvent->serialPort());
974 return true;
975 }
976
977 case UIConsoleEventType_ParallelPortChange:
978 {
979 UIParallelPortChangeEvent *pConsoleEvent = static_cast<UIParallelPortChangeEvent*>(pEvent);
980 emit sigParallelPortChange(pConsoleEvent->parallelPort());
981 return true;
982 }
983
984 case UIConsoleEventType_StorageControllerChange:
985 {
986 emit sigStorageControllerChange();
987 return true;
988 }
989
990 case UIConsoleEventType_MediumChange:
991 {
992 UIMediumChangeEvent *pConsoleEvent = static_cast<UIMediumChangeEvent*>(pEvent);
993 emit sigMediumChange(pConsoleEvent->mediumAttachment());
994 return true;
995 }
996
997 case UIConsoleEventType_CPUChange:
998 {
999 UICPUChangeEvent *pConsoleEvent = static_cast<UICPUChangeEvent*>(pEvent);
1000 emit sigCPUChange(pConsoleEvent->cpu(), pConsoleEvent->remove());
1001 return true;
1002 }
1003
1004 case UIConsoleEventType_VRDPServerChange:
1005 {
1006 emit sigVRDPServerChange();
1007 return true;
1008 }
1009
1010 case UIConsoleEventType_RemoteDisplayInfoChange:
1011 {
1012 emit sigRemoteDisplayInfoChange();
1013 return true;
1014 }
1015
1016 case UIConsoleEventType_USBControllerChange:
1017 {
1018 emit sigUSBControllerChange();
1019 return true;
1020 }
1021
1022 case UIConsoleEventType_USBDeviceStateChange:
1023 {
1024 UIUSBDeviceUIStateChangeEvent *pConsoleEvent = static_cast<UIUSBDeviceUIStateChangeEvent*>(pEvent);
1025 emit sigUSBDeviceStateChange(pConsoleEvent->device(), pConsoleEvent->attached(), pConsoleEvent->error());
1026 return true;
1027 }
1028
1029 case UIConsoleEventType_SharedFolderChange:
1030 {
1031 emit sigSharedFolderChange();
1032 return true;
1033 }
1034
1035 case UIConsoleEventType_RuntimeError:
1036 {
1037 UIRuntimeErrorEvent *pConsoleEvent = static_cast<UIRuntimeErrorEvent*>(pEvent);
1038 emit sigRuntimeError(pConsoleEvent->fatal(), pConsoleEvent->errorID(), pConsoleEvent->message());
1039 return true;
1040 }
1041
1042#ifdef Q_WS_MAC
1043 /* posted OnShowWindow */
1044 case UIConsoleEventType_ShowWindow:
1045 {
1046 /* Dunno what Qt3 thinks a window that has minimized to the dock
1047 * should be - it is not hidden, neither is it minimized. OTOH it is
1048 * marked shown and visible, but not activated. This latter isn't of
1049 * much help though, since at this point nothing is marked activated.
1050 * I might have overlooked something, but I'm buggered what if I know
1051 * what. So, I'll just always show & activate the stupid window to
1052 * make it get out of the dock when the user wishes to show a VM. */
1053#if 0
1054 // TODO_NEW_CORE
1055 window()->show();
1056 window()->activateWindow();
1057#endif
1058 return true;
1059 }
1060#endif
1061
1062 default:
1063 break;
1064 }
1065 return QObject::event(pEvent);
1066}
1067
1068void UISession::prepareMenuPool()
1069{
1070 m_pMenuPool = new UIMachineMenuBar;
1071}
1072
1073void UISession::loadSessionSettings()
1074{
1075 /* Get uisession machine: */
1076 CMachine machine = session().GetConsole().GetMachine();
1077
1078 /* Availability settings: */
1079 {
1080 /* VRDP Stuff: */
1081 CVRDPServer vrdpServer = machine.GetVRDPServer();
1082 if (vrdpServer.isNull())
1083 {
1084 /* Hide VRDP Action: */
1085 uimachine()->actionsPool()->action(UIActionIndex_Toggle_VRDP)->setVisible(false);
1086 }
1087 }
1088
1089 /* Load extra-data settings: */
1090 {
1091 /* Temporary: */
1092 QString strSettings;
1093
1094 /* Is there shoul be First RUN Wizard? */
1095 strSettings = machine.GetExtraData(VBoxDefs::GUI_FirstRun);
1096 if (strSettings == "yes")
1097 m_fIsFirstTimeStarted = true;
1098
1099 /* Ignore mediums mounted at runtime? */
1100 strSettings = machine.GetExtraData(VBoxDefs::GUI_SaveMountedAtRuntime);
1101 if (strSettings == "no")
1102 m_fIsIgnoreRutimeMediumsChanging = true;
1103
1104 /* Should guest autoresize? */
1105 strSettings = machine.GetExtraData(VBoxDefs::GUI_AutoresizeGuest);
1106 QAction *pGuestAutoresizeSwitch = uimachine()->actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize);
1107 pGuestAutoresizeSwitch->blockSignals(true);
1108 pGuestAutoresizeSwitch->setChecked(strSettings != "off");
1109 pGuestAutoresizeSwitch->blockSignals(false);
1110 }
1111}
1112
1113void UISession::saveSessionSettings()
1114{
1115 /* Get uisession machine: */
1116 CMachine machine = session().GetConsole().GetMachine();
1117
1118 /* Save extra-data settings: */
1119 {
1120 /* Disable First RUN Wizard for the since now: */
1121 machine.SetExtraData(VBoxDefs::GUI_FirstRun, QString());
1122
1123 /* Remember if guest should autoresize: */
1124 machine.SetExtraData(VBoxDefs::GUI_AutoresizeGuest,
1125 uimachine()->actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->isChecked() ?
1126 QString() : "off");
1127
1128 // TODO: Move to fullscreen/seamless logic:
1129 //machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, mMiniToolBar->isAutoHide() ? "on" : "off");
1130 }
1131}
1132
1133void UISession::cleanupMenuPool()
1134{
1135 delete m_pMenuPool;
1136 m_pMenuPool = 0;
1137}
1138
1139WId UISession::winId() const
1140{
1141 return mainMachineWindow()->winId();
1142}
1143
1144void UISession::setPointerShape(const uchar *pShapeData, bool fHasAlpha,
1145 uint uXHot, uint uYHot, uint uWidth, uint uHeight)
1146{
1147 AssertMsg(pShapeData, ("Shape data must not be NULL!\n"));
1148
1149 m_fIsValidPointerShapePresent = false;
1150 const uchar *srcAndMaskPtr = pShapeData;
1151 uint andMaskSize = (uWidth + 7) / 8 * uHeight;
1152 const uchar *srcShapePtr = pShapeData + ((andMaskSize + 3) & ~3);
1153 uint srcShapePtrScan = uWidth * 4;
1154
1155#if defined (Q_WS_WIN)
1156
1157 BITMAPV5HEADER bi;
1158 HBITMAP hBitmap;
1159 void *lpBits;
1160
1161 ::ZeroMemory(&bi, sizeof (BITMAPV5HEADER));
1162 bi.bV5Size = sizeof(BITMAPV5HEADER);
1163 bi.bV5Width = uWidth;
1164 bi.bV5Height = - (LONG)uHeight;
1165 bi.bV5Planes = 1;
1166 bi.bV5BitCount = 32;
1167 bi.bV5Compression = BI_BITFIELDS;
1168 bi.bV5RedMask = 0x00FF0000;
1169 bi.bV5GreenMask = 0x0000FF00;
1170 bi.bV5BlueMask = 0x000000FF;
1171 if (fHasAlpha)
1172 bi.bV5AlphaMask = 0xFF000000;
1173 else
1174 bi.bV5AlphaMask = 0;
1175
1176 HDC hdc = GetDC(NULL);
1177
1178 /* Create the DIB section with an alpha channel: */
1179 hBitmap = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (void **)&lpBits, NULL, (DWORD) 0);
1180
1181 ReleaseDC(NULL, hdc);
1182
1183 HBITMAP hMonoBitmap = NULL;
1184 if (fHasAlpha)
1185 {
1186 /* Create an empty mask bitmap: */
1187 hMonoBitmap = CreateBitmap(uWidth, uHeight, 1, 1, NULL);
1188 }
1189 else
1190 {
1191 /* Word aligned AND mask. Will be allocated and created if necessary. */
1192 uint8_t *pu8AndMaskWordAligned = NULL;
1193
1194 /* Width in bytes of the original AND mask scan line. */
1195 uint32_t cbAndMaskScan = (uWidth + 7) / 8;
1196
1197 if (cbAndMaskScan & 1)
1198 {
1199 /* Original AND mask is not word aligned. */
1200
1201 /* Allocate memory for aligned AND mask. */
1202 pu8AndMaskWordAligned = (uint8_t *)RTMemTmpAllocZ((cbAndMaskScan + 1) * uHeight);
1203
1204 Assert(pu8AndMaskWordAligned);
1205
1206 if (pu8AndMaskWordAligned)
1207 {
1208 /* According to MSDN the padding bits must be 0.
1209 * Compute the bit mask to set padding bits to 0 in the last byte of original AND mask. */
1210 uint32_t u32PaddingBits = cbAndMaskScan * 8 - uWidth;
1211 Assert(u32PaddingBits < 8);
1212 uint8_t u8LastBytesPaddingMask = (uint8_t)(0xFF << u32PaddingBits);
1213
1214 Log(("u8LastBytesPaddingMask = %02X, aligned w = %d, width = %d, cbAndMaskScan = %d\n",
1215 u8LastBytesPaddingMask, (cbAndMaskScan + 1) * 8, uWidth, cbAndMaskScan));
1216
1217 uint8_t *src = (uint8_t *)srcAndMaskPtr;
1218 uint8_t *dst = pu8AndMaskWordAligned;
1219
1220 unsigned i;
1221 for (i = 0; i < uHeight; i++)
1222 {
1223 memcpy(dst, src, cbAndMaskScan);
1224
1225 dst[cbAndMaskScan - 1] &= u8LastBytesPaddingMask;
1226
1227 src += cbAndMaskScan;
1228 dst += cbAndMaskScan + 1;
1229 }
1230 }
1231 }
1232
1233 /* Create the AND mask bitmap: */
1234 hMonoBitmap = ::CreateBitmap(uWidth, uHeight, 1, 1,
1235 pu8AndMaskWordAligned? pu8AndMaskWordAligned: srcAndMaskPtr);
1236
1237 if (pu8AndMaskWordAligned)
1238 {
1239 RTMemTmpFree(pu8AndMaskWordAligned);
1240 }
1241 }
1242
1243 Assert(hBitmap);
1244 Assert(hMonoBitmap);
1245 if (hBitmap && hMonoBitmap)
1246 {
1247 DWORD *dstShapePtr = (DWORD *) lpBits;
1248
1249 for (uint y = 0; y < uHeight; y ++)
1250 {
1251 memcpy(dstShapePtr, srcShapePtr, srcShapePtrScan);
1252 srcShapePtr += srcShapePtrScan;
1253 dstShapePtr += uWidth;
1254 }
1255
1256 ICONINFO ii;
1257 ii.fIcon = FALSE;
1258 ii.xHotspot = uXHot;
1259 ii.yHotspot = uYHot;
1260 ii.hbmMask = hMonoBitmap;
1261 ii.hbmColor = hBitmap;
1262
1263 HCURSOR hAlphaCursor = CreateIconIndirect(&ii);
1264 Assert(hAlphaCursor);
1265 if (hAlphaCursor)
1266 {
1267 /* Set the new cursor: */
1268 m_cursor = QCursor(hAlphaCursor);
1269 if (m_alphaCursor)
1270 DestroyIcon(m_alphaCursor);
1271 m_alphaCursor = hAlphaCursor;
1272 m_fIsValidPointerShapePresent = true;
1273 }
1274 }
1275
1276 if (hMonoBitmap)
1277 DeleteObject(hMonoBitmap);
1278 if (hBitmap)
1279 DeleteObject(hBitmap);
1280
1281#elif defined (Q_WS_X11) && !defined (VBOX_WITHOUT_XCURSOR)
1282
1283 XcursorImage *img = XcursorImageCreate(uWidth, uHeight);
1284 Assert(img);
1285 if (img)
1286 {
1287 img->xhot = uXHot;
1288 img->yhot = uYHot;
1289
1290 XcursorPixel *dstShapePtr = img->pixels;
1291
1292 for (uint y = 0; y < uHeight; y ++)
1293 {
1294 memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
1295
1296 if (!fHasAlpha)
1297 {
1298 /* Convert AND mask to the alpha channel: */
1299 uchar byte = 0;
1300 for (uint x = 0; x < uWidth; x ++)
1301 {
1302 if (!(x % 8))
1303 byte = *(srcAndMaskPtr ++);
1304 else
1305 byte <<= 1;
1306
1307 if (byte & 0x80)
1308 {
1309 /* Linux doesn't support inverted pixels (XOR ops,
1310 * to be exact) in cursor shapes, so we detect such
1311 * pixels and always replace them with black ones to
1312 * make them visible at least over light colors */
1313 if (dstShapePtr [x] & 0x00FFFFFF)
1314 dstShapePtr [x] = 0xFF000000;
1315 else
1316 dstShapePtr [x] = 0x00000000;
1317 }
1318 else
1319 dstShapePtr [x] |= 0xFF000000;
1320 }
1321 }
1322
1323 srcShapePtr += srcShapePtrScan;
1324 dstShapePtr += uWidth;
1325 }
1326
1327 /* Set the new cursor: */
1328 m_cursor = QCursor(XcursorImageLoadCursor(QX11Info::display(), img));
1329 m_fIsValidPointerShapePresent = true;
1330
1331 XcursorImageDestroy(img);
1332 }
1333
1334#elif defined(Q_WS_MAC)
1335
1336 /* Create a ARGB image out of the shape data. */
1337 QImage image (uWidth, uHeight, QImage::Format_ARGB32);
1338 const uint8_t* pbSrcMask = static_cast<const uint8_t*> (srcAndMaskPtr);
1339 unsigned cbSrcMaskLine = RT_ALIGN (uWidth, 8) / 8;
1340 for (unsigned int y = 0; y < uHeight; ++y)
1341 {
1342 for (unsigned int x = 0; x < uWidth; ++x)
1343 {
1344 unsigned int color = ((unsigned int*)srcShapePtr)[y*uWidth+x];
1345 /* If the alpha channel isn't in the shape data, we have to
1346 * create them from the and-mask. This is a bit field where 1
1347 * represent transparency & 0 opaque respectively. */
1348 if (!fHasAlpha)
1349 {
1350 if (!(pbSrcMask[x / 8] & (1 << (7 - (x % 8)))))
1351 color |= 0xff000000;
1352 else
1353 {
1354 /* This isn't quite right, but it's the best we can do I think... */
1355 if (color & 0x00ffffff)
1356 color = 0xff000000;
1357 else
1358 color = 0x00000000;
1359 }
1360 }
1361 image.setPixel (x, y, color);
1362 }
1363 /* Move one scanline forward. */
1364 pbSrcMask += cbSrcMaskLine;
1365 }
1366
1367 /* Set the new cursor: */
1368 m_cursor = QCursor(QPixmap::fromImage(image), uXHot, uYHot);
1369 m_fIsValidPointerShapePresent = true;
1370 NOREF(srcShapePtrScan);
1371
1372#else
1373
1374# warning "port me"
1375
1376#endif
1377}
1378
1379void UISession::reinitMenuPool()
1380{
1381 /* Get uisession machine: */
1382 CMachine machine = session().GetConsole().GetMachine();
1383
1384 /* Availability settings: */
1385 {
1386 /* USB Stuff: */
1387 CUSBController usbController = machine.GetUSBController();
1388 if ( usbController.isNull()
1389 || !usbController.GetProxyAvailable())
1390 {
1391 /* Hide USB menu if controller is NULL or no USB proxy available: */
1392 uimachine()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->setVisible(false);
1393 }
1394 else
1395 {
1396 /* Enable/Disable USB menu depending on USB controller: */
1397 uimachine()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->setEnabled(usbController.GetEnabled());
1398 }
1399 }
1400
1401 /* Prepare some initial settings: */
1402 {
1403 /* Initialize CD/FD menus: */
1404 int iDevicesCountCD = 0;
1405 int iDevicesCountFD = 0;
1406 const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
1407 foreach (const CMediumAttachment &attachment, attachments)
1408 {
1409 if (attachment.GetType() == KDeviceType_DVD)
1410 ++ iDevicesCountCD;
1411 if (attachment.GetType() == KDeviceType_Floppy)
1412 ++ iDevicesCountFD;
1413 }
1414 QAction *pOpticalDevicesMenu = uimachine()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices);
1415 QAction *pFloppyDevicesMenu = uimachine()->actionsPool()->action(UIActionIndex_Menu_FloppyDevices);
1416 pOpticalDevicesMenu->setData(iDevicesCountCD);
1417 pOpticalDevicesMenu->setVisible(iDevicesCountCD);
1418 pFloppyDevicesMenu->setData(iDevicesCountFD);
1419 pFloppyDevicesMenu->setVisible(iDevicesCountFD);
1420 }
1421}
1422
1423void UISession::preparePowerUp()
1424{
1425#ifdef VBOX_WITH_UPDATE_REQUEST
1426 /* Check for updates if necessary: */
1427 vboxGlobal().showUpdateDialog(false /* force request? */);
1428#endif
1429
1430 /* Notify user about mouse&keyboard auto-capturing: */
1431 if (vboxGlobal().settings().autoCapture())
1432 vboxProblem().remindAboutAutoCapture();
1433
1434 /* Shows first run wizard if necessary: */
1435 if (isFirstTimeStarted())
1436 {
1437 UIFirstRunWzd wzd(mainMachineWindow(), session().GetMachine());
1438 wzd.exec();
1439 }
1440}
1441
Note: See TracBrowser for help on using the repository browser.

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