1 | /* $Id: UIMachineLogicScale.cpp 38311 2011-08-04 13:08:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIMachineLogicScale class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010 Oracle Corporation
|
---|
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 |
|
---|
20 | /* Local includes */
|
---|
21 | #include "COMDefs.h"
|
---|
22 | #include "VBoxGlobal.h"
|
---|
23 | #include "UIMessageCenter.h"
|
---|
24 |
|
---|
25 | #include "UISession.h"
|
---|
26 | #include "UIActionsPool.h"
|
---|
27 | #include "UIMachineLogicScale.h"
|
---|
28 | #include "UIMachineWindow.h"
|
---|
29 | #include "UIDownloaderAdditions.h"
|
---|
30 |
|
---|
31 | #ifdef Q_WS_MAC
|
---|
32 | #include "VBoxUtils.h"
|
---|
33 | #endif /* Q_WS_MAC */
|
---|
34 |
|
---|
35 | UIMachineLogicScale::UIMachineLogicScale(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
|
---|
36 | : UIMachineLogic(pParent, pSession, pActionsPool, UIVisualStateType_Scale)
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | UIMachineLogicScale::~UIMachineLogicScale()
|
---|
41 | {
|
---|
42 | #ifdef Q_WS_MAC
|
---|
43 | /* Cleanup the dock stuff before the machine window(s): */
|
---|
44 | cleanupDock();
|
---|
45 | #endif /* Q_WS_MAC */
|
---|
46 |
|
---|
47 | /* Cleanup machine window(s): */
|
---|
48 | cleanupMachineWindow();
|
---|
49 |
|
---|
50 | /* Cleanup handlers: */
|
---|
51 | cleanupHandlers();
|
---|
52 |
|
---|
53 | /* Cleanup actions groups: */
|
---|
54 | cleanupActionGroups();
|
---|
55 | }
|
---|
56 |
|
---|
57 | bool UIMachineLogicScale::checkAvailability()
|
---|
58 | {
|
---|
59 | /* Base class availability: */
|
---|
60 | if (!UIMachineLogic::checkAvailability())
|
---|
61 | return false;
|
---|
62 |
|
---|
63 | /* Take the toggle hot key from the menu item. Since
|
---|
64 | * VBoxGlobal::extractKeyFromActionText gets exactly the
|
---|
65 | * linked key without the 'Host+' part we are adding it here. */
|
---|
66 | QString strHotKey = QString("Host+%1")
|
---|
67 | .arg(VBoxGlobal::extractKeyFromActionText(actionsPool()->action(UIActionIndex_Toggle_Scale)->text()));
|
---|
68 | Assert(!strHotKey.isEmpty());
|
---|
69 |
|
---|
70 | /* Show the info message. */
|
---|
71 | if (!msgCenter().confirmGoingScale(strHotKey))
|
---|
72 | return false;
|
---|
73 |
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | void UIMachineLogicScale::initialize()
|
---|
78 | {
|
---|
79 | /* Prepare required features: */
|
---|
80 | prepareRequiredFeatures();
|
---|
81 |
|
---|
82 | /* Prepare session connections: */
|
---|
83 | prepareSessionConnections();
|
---|
84 |
|
---|
85 | /* Prepare action groups:
|
---|
86 | * Note: This has to be done before prepareActionConnections
|
---|
87 | * cause here actions/menus are recreated. */
|
---|
88 | prepareActionGroups();
|
---|
89 |
|
---|
90 | /* Prepare action connections: */
|
---|
91 | prepareActionConnections();
|
---|
92 |
|
---|
93 | /* Prepare handlers: */
|
---|
94 | prepareHandlers();
|
---|
95 |
|
---|
96 | /* Prepare scale machine window: */
|
---|
97 | prepareMachineWindows();
|
---|
98 |
|
---|
99 | /* If there is an Additions download running, update the parent window
|
---|
100 | * information. */
|
---|
101 | if (UIDownloaderAdditions *pDl = UIDownloaderAdditions::current())
|
---|
102 | pDl->setParentWidget(mainMachineWindow()->machineWindow());
|
---|
103 |
|
---|
104 | #ifdef Q_WS_MAC
|
---|
105 | /* Prepare dock: */
|
---|
106 | prepareDock();
|
---|
107 | #endif /* Q_WS_MAC */
|
---|
108 |
|
---|
109 | /* Power up machine: */
|
---|
110 | uisession()->powerUp();
|
---|
111 |
|
---|
112 | /* Initialization: */
|
---|
113 | sltMachineStateChanged();
|
---|
114 | sltAdditionsStateChanged();
|
---|
115 | sltMouseCapabilityChanged();
|
---|
116 |
|
---|
117 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
118 | prepareDebugger();
|
---|
119 | #endif /* VBOX_WITH_DEBUGGER_GUI */
|
---|
120 |
|
---|
121 | /* Retranslate logic part: */
|
---|
122 | retranslateUi();
|
---|
123 | }
|
---|
124 |
|
---|
125 | void UIMachineLogicScale::prepareActionGroups()
|
---|
126 | {
|
---|
127 | /* Base class action groups: */
|
---|
128 | UIMachineLogic::prepareActionGroups();
|
---|
129 |
|
---|
130 | /* Guest auto-resize isn't allowed in scale-mode: */
|
---|
131 | actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setVisible(false);
|
---|
132 |
|
---|
133 | /* Adjust-window isn't allowed in scale-mode: */
|
---|
134 | actionsPool()->action(UIActionIndex_Simple_AdjustWindow)->setVisible(false);
|
---|
135 | }
|
---|
136 |
|
---|
137 | void UIMachineLogicScale::prepareMachineWindows()
|
---|
138 | {
|
---|
139 | /* Do not create window(s) if they created already: */
|
---|
140 | if (isMachineWindowsCreated())
|
---|
141 | return;
|
---|
142 |
|
---|
143 | #ifdef Q_WS_MAC // TODO: Is that really need here?
|
---|
144 | /* We have to make sure that we are getting the front most process.
|
---|
145 | * This is necessary for Qt versions > 4.3.3: */
|
---|
146 | ::darwinSetFrontMostProcess();
|
---|
147 | #endif /* Q_WS_MAC */
|
---|
148 |
|
---|
149 | /* Get monitors count: */
|
---|
150 | ulong uMonitorCount = session().GetMachine().GetMonitorCount();
|
---|
151 | /* Create machine window(s): */
|
---|
152 | for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
|
---|
153 | addMachineWindow(UIMachineWindow::create(this, visualStateType(), uScreenId));
|
---|
154 | /* Order machine window(s): */
|
---|
155 | for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId)
|
---|
156 | machineWindows()[uScreenId - 1]->machineWindow()->raise();
|
---|
157 |
|
---|
158 | /* Remember what machine window(s) created: */
|
---|
159 | setMachineWindowsCreated(true);
|
---|
160 | }
|
---|
161 |
|
---|
162 | void UIMachineLogicScale::cleanupMachineWindow()
|
---|
163 | {
|
---|
164 | /* Do not cleanup machine window(s) if not present: */
|
---|
165 | if (!isMachineWindowsCreated())
|
---|
166 | return;
|
---|
167 |
|
---|
168 | /* Cleanup machine window(s): */
|
---|
169 | foreach (UIMachineWindow *pMachineWindow, machineWindows())
|
---|
170 | UIMachineWindow::destroy(pMachineWindow);
|
---|
171 | }
|
---|
172 |
|
---|
173 | void UIMachineLogicScale::cleanupActionGroups()
|
---|
174 | {
|
---|
175 | /* Reenable guest-autoresize action: */
|
---|
176 | actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setVisible(true);
|
---|
177 |
|
---|
178 | /* Reenable adjust-window action: */
|
---|
179 | actionsPool()->action(UIActionIndex_Simple_AdjustWindow)->setVisible(true);
|
---|
180 | }
|
---|
181 |
|
---|