1 | /* $Id: UIMachineWindowNormal.cpp 35730 2011-01-27 10:49:44Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIMachineWindowNormal 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 | /* Global includes */
|
---|
21 | #include <QDesktopWidget>
|
---|
22 | #include <QMenuBar>
|
---|
23 | #include <QTimer>
|
---|
24 | #include <QContextMenuEvent>
|
---|
25 |
|
---|
26 | /* Local includes */
|
---|
27 | #include "VBoxGlobal.h"
|
---|
28 | #include "VBoxProblemReporter.h"
|
---|
29 | #include "VBoxUtils.h"
|
---|
30 |
|
---|
31 | #include "UISession.h"
|
---|
32 | #include "UIActionsPool.h"
|
---|
33 | #include "UIIndicatorsPool.h"
|
---|
34 | #include "UIKeyboardHandler.h"
|
---|
35 | #include "UIMouseHandler.h"
|
---|
36 | #include "UIMachineLogic.h"
|
---|
37 | #include "UIMachineWindowNormal.h"
|
---|
38 | #include "UIMachineView.h"
|
---|
39 | #include "UIDownloaderAdditions.h"
|
---|
40 | #include "UIDownloaderUserManual.h"
|
---|
41 | #ifdef Q_WS_MAC
|
---|
42 | # include "UIImageTools.h"
|
---|
43 | #endif /* Q_WS_MAC */
|
---|
44 |
|
---|
45 | #include "QIStatusBar.h"
|
---|
46 | #include "QIStateIndicator.h"
|
---|
47 | #include "UIHotKeyEditor.h"
|
---|
48 |
|
---|
49 | UIMachineWindowNormal::UIMachineWindowNormal(UIMachineLogic *pMachineLogic, ulong uScreenId)
|
---|
50 | : QIWithRetranslateUI2<QMainWindow>(0, Qt::Window)
|
---|
51 | , UIMachineWindow(pMachineLogic, uScreenId)
|
---|
52 | , m_pIndicatorsPool(new UIIndicatorsPool(pMachineLogic->uisession()->session(), this))
|
---|
53 | , m_pIdleTimer(0)
|
---|
54 | {
|
---|
55 | /* "This" is machine window: */
|
---|
56 | m_pMachineWindow = this;
|
---|
57 |
|
---|
58 | /* Set the main window in VBoxGlobal */
|
---|
59 | if (uScreenId == 0)
|
---|
60 | vboxGlobal().setMainWindow(this);
|
---|
61 |
|
---|
62 | /* Prepare window icon: */
|
---|
63 | prepareWindowIcon();
|
---|
64 |
|
---|
65 | /* Prepare console connections: */
|
---|
66 | prepareConsoleConnections();
|
---|
67 |
|
---|
68 | /* Prepare menu: */
|
---|
69 | prepareMenu();
|
---|
70 |
|
---|
71 | /* Prepare status bar: */
|
---|
72 | prepareStatusBar();
|
---|
73 |
|
---|
74 | /* Prepare connections: */
|
---|
75 | prepareConnections();
|
---|
76 |
|
---|
77 | /* Retranslate normal window finally: */
|
---|
78 | retranslateUi();
|
---|
79 |
|
---|
80 | /* Prepare normal machine view container: */
|
---|
81 | prepareMachineViewContainer();
|
---|
82 |
|
---|
83 | /* Prepare normal machine view: */
|
---|
84 | prepareMachineView();
|
---|
85 |
|
---|
86 | /* Prepare handlers: */
|
---|
87 | prepareHandlers();
|
---|
88 |
|
---|
89 | /* Load normal window settings: */
|
---|
90 | loadWindowSettings();
|
---|
91 |
|
---|
92 | /* Update all the elements: */
|
---|
93 | updateAppearanceOf(UIVisualElement_AllStuff);
|
---|
94 |
|
---|
95 | #ifdef Q_WS_MAC
|
---|
96 | /* Beta label? */
|
---|
97 | if (vboxGlobal().isBeta())
|
---|
98 | {
|
---|
99 | QPixmap betaLabel = ::betaLabel(QSize(100, 16));
|
---|
100 | ::darwinLabelWindow(this, &betaLabel, true);
|
---|
101 | }
|
---|
102 | #endif /* Q_WS_MAC */
|
---|
103 |
|
---|
104 | /* Show window: */
|
---|
105 | showSimple();
|
---|
106 | }
|
---|
107 |
|
---|
108 | UIMachineWindowNormal::~UIMachineWindowNormal()
|
---|
109 | {
|
---|
110 | /* Save normal window settings: */
|
---|
111 | saveWindowSettings();
|
---|
112 |
|
---|
113 | /* Prepare handlers: */
|
---|
114 | cleanupHandlers();
|
---|
115 |
|
---|
116 | /* Cleanup normal machine view: */
|
---|
117 | cleanupMachineView();
|
---|
118 |
|
---|
119 | /* Cleanup status-bar: */
|
---|
120 | cleanupStatusBar();
|
---|
121 | }
|
---|
122 |
|
---|
123 | void UIMachineWindowNormal::sltMachineStateChanged()
|
---|
124 | {
|
---|
125 | UIMachineWindow::sltMachineStateChanged();
|
---|
126 | updateAppearanceOf(UIVisualElement_VirtualizationStuff);
|
---|
127 | }
|
---|
128 |
|
---|
129 | void UIMachineWindowNormal::sltMediumChange(const CMediumAttachment &attachment)
|
---|
130 | {
|
---|
131 | KDeviceType type = attachment.GetType();
|
---|
132 | if (type == KDeviceType_HardDisk)
|
---|
133 | updateAppearanceOf(UIVisualElement_HDStuff);
|
---|
134 | if (type == KDeviceType_DVD)
|
---|
135 | updateAppearanceOf(UIVisualElement_CDStuff);
|
---|
136 | if (type == KDeviceType_Floppy)
|
---|
137 | updateAppearanceOf(UIVisualElement_FDStuff);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void UIMachineWindowNormal::sltUSBControllerChange()
|
---|
141 | {
|
---|
142 | updateAppearanceOf(UIVisualElement_USBStuff);
|
---|
143 | }
|
---|
144 |
|
---|
145 | void UIMachineWindowNormal::sltUSBDeviceStateChange()
|
---|
146 | {
|
---|
147 | updateAppearanceOf(UIVisualElement_USBStuff);
|
---|
148 | }
|
---|
149 |
|
---|
150 | void UIMachineWindowNormal::sltNetworkAdapterChange()
|
---|
151 | {
|
---|
152 | updateAppearanceOf(UIVisualElement_NetworkStuff);
|
---|
153 | }
|
---|
154 |
|
---|
155 | void UIMachineWindowNormal::sltSharedFolderChange()
|
---|
156 | {
|
---|
157 | updateAppearanceOf(UIVisualElement_SharedFolderStuff);
|
---|
158 | }
|
---|
159 |
|
---|
160 | void UIMachineWindowNormal::sltTryClose()
|
---|
161 | {
|
---|
162 | UIMachineWindow::sltTryClose();
|
---|
163 | }
|
---|
164 |
|
---|
165 | void UIMachineWindowNormal::sltDownloaderAdditionsEmbed()
|
---|
166 | {
|
---|
167 | /* If there is an additions download running show the process bar: */
|
---|
168 | if (UIDownloaderAdditions *pDl = UIDownloaderAdditions::current())
|
---|
169 | statusBar()->addWidget(pDl->processWidget(this), 0);
|
---|
170 | }
|
---|
171 |
|
---|
172 | void UIMachineWindowNormal::sltDownloaderUserManualEmbed()
|
---|
173 | {
|
---|
174 | /* If there is an additions download running show the process bar: */
|
---|
175 | if (UIDownloaderUserManual *pDl = UIDownloaderUserManual::current())
|
---|
176 | statusBar()->addWidget(pDl->processWidget(this), 0);
|
---|
177 | }
|
---|
178 |
|
---|
179 | void UIMachineWindowNormal::sltUpdateIndicators()
|
---|
180 | {
|
---|
181 | CConsole console = session().GetConsole();
|
---|
182 | QIStateIndicator *pStateIndicator = 0;
|
---|
183 |
|
---|
184 | pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_HardDisks);
|
---|
185 | if (pStateIndicator->state() != KDeviceActivity_Null)
|
---|
186 | {
|
---|
187 | int state = console.GetDeviceActivity(KDeviceType_HardDisk);
|
---|
188 | if (pStateIndicator->state() != state)
|
---|
189 | pStateIndicator->setState(state);
|
---|
190 | }
|
---|
191 | pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks);
|
---|
192 | if (pStateIndicator->state() != KDeviceActivity_Null)
|
---|
193 | {
|
---|
194 | int state = console.GetDeviceActivity(KDeviceType_DVD);
|
---|
195 | if (pStateIndicator->state() != state)
|
---|
196 | pStateIndicator->setState(state);
|
---|
197 | }
|
---|
198 | pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_FloppyDisks);
|
---|
199 | if (pStateIndicator->state() != KDeviceActivity_Null)
|
---|
200 | {
|
---|
201 | int state = console.GetDeviceActivity(KDeviceType_Floppy);
|
---|
202 | if (pStateIndicator->state() != state)
|
---|
203 | pStateIndicator->setState(state);
|
---|
204 | }
|
---|
205 | pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_USBDevices);
|
---|
206 | if (pStateIndicator->state() != KDeviceActivity_Null)
|
---|
207 | {
|
---|
208 | int state = console.GetDeviceActivity(KDeviceType_USB);
|
---|
209 | if (pStateIndicator->state() != state)
|
---|
210 | pStateIndicator->setState(state);
|
---|
211 | }
|
---|
212 | pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters);
|
---|
213 | if (pStateIndicator->state() != KDeviceActivity_Null)
|
---|
214 | {
|
---|
215 | int state = console.GetDeviceActivity(KDeviceType_Network);
|
---|
216 | if (pStateIndicator->state() != state)
|
---|
217 | pStateIndicator->setState(state);
|
---|
218 | }
|
---|
219 | pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders);
|
---|
220 | if (pStateIndicator->state() != KDeviceActivity_Null)
|
---|
221 | {
|
---|
222 | int state = console.GetDeviceActivity(KDeviceType_SharedFolder);
|
---|
223 | if (pStateIndicator->state() != state)
|
---|
224 | pStateIndicator->setState(state);
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | void UIMachineWindowNormal::sltShowIndicatorsContextMenu(QIStateIndicator *pIndicator, QContextMenuEvent *pEvent)
|
---|
229 | {
|
---|
230 | if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks))
|
---|
231 | {
|
---|
232 | if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->isEnabled())
|
---|
233 | machineLogic()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu()->exec(pEvent->globalPos());
|
---|
234 | }
|
---|
235 | else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_FloppyDisks))
|
---|
236 | {
|
---|
237 | if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->isEnabled())
|
---|
238 | machineLogic()->actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu()->exec(pEvent->globalPos());
|
---|
239 | }
|
---|
240 | else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_USBDevices))
|
---|
241 | {
|
---|
242 | if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->isEnabled())
|
---|
243 | machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->exec(pEvent->globalPos());
|
---|
244 | }
|
---|
245 | else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters))
|
---|
246 | {
|
---|
247 | if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_NetworkAdapters)->isEnabled())
|
---|
248 | machineLogic()->actionsPool()->action(UIActionIndex_Menu_NetworkAdapters)->menu()->exec(pEvent->globalPos());
|
---|
249 | }
|
---|
250 | else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders))
|
---|
251 | {
|
---|
252 | if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_SharedFolders)->isEnabled())
|
---|
253 | machineLogic()->actionsPool()->action(UIActionIndex_Menu_SharedFolders)->menu()->exec(pEvent->globalPos());
|
---|
254 | }
|
---|
255 | else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_Mouse))
|
---|
256 | {
|
---|
257 | if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_MouseIntegration)->isEnabled())
|
---|
258 | machineLogic()->actionsPool()->action(UIActionIndex_Menu_MouseIntegration)->menu()->exec(pEvent->globalPos());
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | void UIMachineWindowNormal::sltProcessGlobalSettingChange(const char * /* aPublicName */, const char * /* aName */)
|
---|
263 | {
|
---|
264 | m_pNameHostkey->setText(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo()));
|
---|
265 | }
|
---|
266 |
|
---|
267 | void UIMachineWindowNormal::retranslateUi()
|
---|
268 | {
|
---|
269 | /* Translate parent class: */
|
---|
270 | UIMachineWindow::retranslateUi();
|
---|
271 |
|
---|
272 | m_pNameHostkey->setToolTip(
|
---|
273 | QApplication::translate("UIMachineWindowNormal", "Shows the currently assigned Host key.<br>"
|
---|
274 | "This key, when pressed alone, toggles the keyboard and mouse "
|
---|
275 | "capture state. It can also be used in combination with other keys "
|
---|
276 | "to quickly perform actions from the main menu."));
|
---|
277 | m_pNameHostkey->setText(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo()));
|
---|
278 | }
|
---|
279 |
|
---|
280 | void UIMachineWindowNormal::updateAppearanceOf(int iElement)
|
---|
281 | {
|
---|
282 | /* Update parent-class window: */
|
---|
283 | UIMachineWindow::updateAppearanceOf(iElement);
|
---|
284 |
|
---|
285 | /* Update that machine window: */
|
---|
286 | if (iElement & UIVisualElement_HDStuff)
|
---|
287 | indicatorsPool()->indicator(UIIndicatorIndex_HardDisks)->updateAppearance();
|
---|
288 | if (iElement & UIVisualElement_CDStuff)
|
---|
289 | indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks)->updateAppearance();
|
---|
290 | if (iElement & UIVisualElement_FDStuff)
|
---|
291 | indicatorsPool()->indicator(UIIndicatorIndex_FloppyDisks)->updateAppearance();
|
---|
292 | if (iElement & UIVisualElement_USBStuff &&
|
---|
293 | !indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->isHidden())
|
---|
294 | indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->updateAppearance();
|
---|
295 | if (iElement & UIVisualElement_NetworkStuff)
|
---|
296 | indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters)->updateAppearance();
|
---|
297 | if (iElement & UIVisualElement_SharedFolderStuff)
|
---|
298 | indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders)->updateAppearance();
|
---|
299 | if (iElement & UIVisualElement_VirtualizationStuff)
|
---|
300 | indicatorsPool()->indicator(UIIndicatorIndex_Virtualization)->updateAppearance();
|
---|
301 | }
|
---|
302 |
|
---|
303 | bool UIMachineWindowNormal::event(QEvent *pEvent)
|
---|
304 | {
|
---|
305 | switch (pEvent->type())
|
---|
306 | {
|
---|
307 | case QEvent::Resize:
|
---|
308 | {
|
---|
309 | QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
|
---|
310 | if (!isMaximizedChecked())
|
---|
311 | {
|
---|
312 | m_normalGeometry.setSize(pResizeEvent->size());
|
---|
313 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
314 | /* Update debugger window position */
|
---|
315 | updateDbgWindows();
|
---|
316 | #endif
|
---|
317 | }
|
---|
318 | break;
|
---|
319 | }
|
---|
320 | case QEvent::Move:
|
---|
321 | {
|
---|
322 | if (!isMaximizedChecked())
|
---|
323 | {
|
---|
324 | m_normalGeometry.moveTo(geometry().x(), geometry().y());
|
---|
325 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
326 | /* Update debugger window position */
|
---|
327 | updateDbgWindows();
|
---|
328 | #endif
|
---|
329 | }
|
---|
330 | break;
|
---|
331 | }
|
---|
332 | default:
|
---|
333 | break;
|
---|
334 | }
|
---|
335 | return QIWithRetranslateUI2<QMainWindow>::event(pEvent);
|
---|
336 | }
|
---|
337 |
|
---|
338 | #ifdef Q_WS_X11
|
---|
339 | bool UIMachineWindowNormal::x11Event(XEvent *pEvent)
|
---|
340 | {
|
---|
341 | return UIMachineWindow::x11Event(pEvent);
|
---|
342 | }
|
---|
343 | #endif
|
---|
344 |
|
---|
345 | void UIMachineWindowNormal::closeEvent(QCloseEvent *pEvent)
|
---|
346 | {
|
---|
347 | return UIMachineWindow::closeEvent(pEvent);
|
---|
348 | }
|
---|
349 |
|
---|
350 | void UIMachineWindowNormal::prepareConsoleConnections()
|
---|
351 | {
|
---|
352 | /* Base-class connections: */
|
---|
353 | UIMachineWindow::prepareConsoleConnections();
|
---|
354 |
|
---|
355 | /* Medium change updater: */
|
---|
356 | connect(machineLogic()->uisession(), SIGNAL(sigMediumChange(const CMediumAttachment &)),
|
---|
357 | this, SLOT(sltMediumChange(const CMediumAttachment &)));
|
---|
358 |
|
---|
359 | /* USB controller change updater: */
|
---|
360 | connect(machineLogic()->uisession(), SIGNAL(sigUSBControllerChange()),
|
---|
361 | this, SLOT(sltUSBControllerChange()));
|
---|
362 |
|
---|
363 | /* USB device state-change updater: */
|
---|
364 | connect(machineLogic()->uisession(), SIGNAL(sigUSBDeviceStateChange(const CUSBDevice &, bool, const CVirtualBoxErrorInfo &)),
|
---|
365 | this, SLOT(sltUSBDeviceStateChange()));
|
---|
366 |
|
---|
367 | /* Network adapter change updater: */
|
---|
368 | connect(machineLogic()->uisession(), SIGNAL(sigNetworkAdapterChange(const CNetworkAdapter &)),
|
---|
369 | this, SLOT(sltNetworkAdapterChange()));
|
---|
370 |
|
---|
371 | /* Shared folder change updater: */
|
---|
372 | connect(machineLogic()->uisession(), SIGNAL(sigSharedFolderChange()),
|
---|
373 | this, SLOT(sltSharedFolderChange()));
|
---|
374 | }
|
---|
375 |
|
---|
376 | void UIMachineWindowNormal::prepareMenu()
|
---|
377 | {
|
---|
378 | /* No view menu in normal mode */
|
---|
379 | setMenuBar(uisession()->newMenuBar(UIMainMenuType(UIMainMenuType_All ^ UIMainMenuType_View)));
|
---|
380 | }
|
---|
381 |
|
---|
382 | void UIMachineWindowNormal::prepareStatusBar()
|
---|
383 | {
|
---|
384 | /* Common setup: */
|
---|
385 | setStatusBar(new QIStatusBar(this));
|
---|
386 | QWidget *pIndicatorBox = new QWidget;
|
---|
387 | QHBoxLayout *pIndicatorBoxHLayout = new QHBoxLayout(pIndicatorBox);
|
---|
388 | VBoxGlobal::setLayoutMargin(pIndicatorBoxHLayout, 0);
|
---|
389 | pIndicatorBoxHLayout->setSpacing(5);
|
---|
390 |
|
---|
391 | /* Hard Disks: */
|
---|
392 | pIndicatorBoxHLayout->addWidget(indicatorsPool()->indicator(UIIndicatorIndex_HardDisks));
|
---|
393 |
|
---|
394 | /* Optical Disks: */
|
---|
395 | QIStateIndicator *pLedOpticalDisks = indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks);
|
---|
396 | pIndicatorBoxHLayout->addWidget(pLedOpticalDisks);
|
---|
397 | connect(pLedOpticalDisks, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
|
---|
398 | this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
|
---|
399 |
|
---|
400 | /* Floppy Disks: */
|
---|
401 | QIStateIndicator *pLedFloppyDisks = indicatorsPool()->indicator(UIIndicatorIndex_FloppyDisks);
|
---|
402 | pIndicatorBoxHLayout->addWidget(pLedFloppyDisks);
|
---|
403 | connect(pLedFloppyDisks, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
|
---|
404 | this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
|
---|
405 |
|
---|
406 | /* USB Devices: */
|
---|
407 | QIStateIndicator *pLedUSBDevices = indicatorsPool()->indicator(UIIndicatorIndex_USBDevices);
|
---|
408 | pIndicatorBoxHLayout->addWidget(pLedUSBDevices);
|
---|
409 | connect(pLedUSBDevices, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
|
---|
410 | this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
|
---|
411 |
|
---|
412 | /* Network Adapters: */
|
---|
413 | QIStateIndicator *pLedNetworkAdapters = indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters);
|
---|
414 | pIndicatorBoxHLayout->addWidget(pLedNetworkAdapters);
|
---|
415 | connect(pLedNetworkAdapters, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
|
---|
416 | this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
|
---|
417 |
|
---|
418 | /* Shared Folders: */
|
---|
419 | QIStateIndicator *pLedSharedFolders = indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders);
|
---|
420 | pIndicatorBoxHLayout->addWidget(pLedSharedFolders);
|
---|
421 | connect(pLedSharedFolders, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
|
---|
422 | this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
|
---|
423 |
|
---|
424 | /* Virtualization: */
|
---|
425 | pIndicatorBoxHLayout->addWidget(indicatorsPool()->indicator(UIIndicatorIndex_Virtualization));
|
---|
426 |
|
---|
427 | /* Separator: */
|
---|
428 | QFrame *pSeparator = new QFrame;
|
---|
429 | pSeparator->setFrameStyle(QFrame::VLine | QFrame::Sunken);
|
---|
430 | pIndicatorBoxHLayout->addWidget(pSeparator);
|
---|
431 |
|
---|
432 | /* Mouse: */
|
---|
433 | QIStateIndicator *pLedMouse = indicatorsPool()->indicator(UIIndicatorIndex_Mouse);
|
---|
434 | pIndicatorBoxHLayout->addWidget(pLedMouse);
|
---|
435 | connect(pLedMouse, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
|
---|
436 | this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
|
---|
437 |
|
---|
438 | /* Host Key: */
|
---|
439 | m_pCntHostkey = new QWidget;
|
---|
440 | QHBoxLayout *pHostkeyLedContainerLayout = new QHBoxLayout(m_pCntHostkey);
|
---|
441 | VBoxGlobal::setLayoutMargin(pHostkeyLedContainerLayout, 0);
|
---|
442 | pHostkeyLedContainerLayout->setSpacing(3);
|
---|
443 | pIndicatorBoxHLayout->addWidget(m_pCntHostkey);
|
---|
444 | pHostkeyLedContainerLayout->addWidget(indicatorsPool()->indicator(UIIndicatorIndex_Hostkey));
|
---|
445 | m_pNameHostkey = new QLabel(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo()));
|
---|
446 | pHostkeyLedContainerLayout->addWidget(m_pNameHostkey);
|
---|
447 |
|
---|
448 | /* Add to statusbar: */
|
---|
449 | statusBar()->addPermanentWidget(pIndicatorBox, 0);
|
---|
450 |
|
---|
451 | /* Add the additions downloader progress bar to the status bar,
|
---|
452 | * if a download is actually running: */
|
---|
453 | sltDownloaderAdditionsEmbed();
|
---|
454 |
|
---|
455 | /* Add the user manual progress bar to the status bar,
|
---|
456 | * if a download is actually running: */
|
---|
457 | sltDownloaderUserManualEmbed();
|
---|
458 |
|
---|
459 | /* Create & start timer to update LEDs: */
|
---|
460 | m_pIdleTimer = new QTimer(this);
|
---|
461 | connect(m_pIdleTimer, SIGNAL(timeout()), this, SLOT(sltUpdateIndicators()));
|
---|
462 | m_pIdleTimer->start(50);
|
---|
463 |
|
---|
464 | #ifdef Q_WS_MAC
|
---|
465 | /* For the status bar on Cocoa: */
|
---|
466 | setUnifiedTitleAndToolBarOnMac(true);
|
---|
467 | #endif
|
---|
468 | }
|
---|
469 |
|
---|
470 | void UIMachineWindowNormal::prepareConnections()
|
---|
471 | {
|
---|
472 | /* Setup global settings change updater: */
|
---|
473 | connect(&vboxGlobal().settings(), SIGNAL(propertyChanged(const char *, const char *)),
|
---|
474 | this, SLOT(sltProcessGlobalSettingChange(const char *, const char *)));
|
---|
475 | /* Setup additions downloader listener: */
|
---|
476 | connect(machineLogic(), SIGNAL(sigDownloaderAdditionsCreated()), this, SLOT(sltDownloaderAdditionsEmbed()));
|
---|
477 | /* Setup user manual downloader listener: */
|
---|
478 | connect(&vboxProblem(), SIGNAL(sigDownloaderUserManualCreated()), this, SLOT(sltDownloaderUserManualEmbed()));
|
---|
479 | }
|
---|
480 |
|
---|
481 | void UIMachineWindowNormal::prepareMachineView()
|
---|
482 | {
|
---|
483 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
484 | /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */
|
---|
485 | bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable();
|
---|
486 | #endif
|
---|
487 |
|
---|
488 | /* Set central widget: */
|
---|
489 | setCentralWidget(new QWidget);
|
---|
490 |
|
---|
491 | /* Set central widget layout: */
|
---|
492 | centralWidget()->setLayout(m_pMachineViewContainer);
|
---|
493 |
|
---|
494 | m_pMachineView = UIMachineView::create( this
|
---|
495 | , m_uScreenId
|
---|
496 | , machineLogic()->visualStateType()
|
---|
497 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
498 | , bAccelerate2DVideo
|
---|
499 | #endif
|
---|
500 | );
|
---|
501 |
|
---|
502 | /* Add machine view into layout: */
|
---|
503 | m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1);
|
---|
504 |
|
---|
505 | /* Setup machine view connections: */
|
---|
506 | if (machineView())
|
---|
507 | {
|
---|
508 | /* Keyboard state-change updater: */
|
---|
509 | connect(machineLogic()->keyboardHandler(), SIGNAL(keyboardStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Hostkey), SLOT(setState(int)));
|
---|
510 |
|
---|
511 | /* Mouse state-change updater: */
|
---|
512 | connect(machineLogic()->mouseHandler(), SIGNAL(mouseStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Mouse), SLOT(setState(int)));
|
---|
513 |
|
---|
514 | /* Early initialize required connections: */
|
---|
515 | indicatorsPool()->indicator(UIIndicatorIndex_Hostkey)->setState(machineLogic()->keyboardHandler()->keyboardState());
|
---|
516 | indicatorsPool()->indicator(UIIndicatorIndex_Mouse)->setState(machineLogic()->mouseHandler()->mouseState());
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 | void UIMachineWindowNormal::loadWindowSettings()
|
---|
521 | {
|
---|
522 | /* Load normal window settings: */
|
---|
523 | CMachine machine = session().GetMachine();
|
---|
524 |
|
---|
525 | /* Load extra-data settings: */
|
---|
526 | {
|
---|
527 | QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastNormalWindowPosition) :
|
---|
528 | QString("%1%2").arg(VBoxDefs::GUI_LastNormalWindowPosition).arg(m_uScreenId);
|
---|
529 | QStringList strPositionSettings = machine.GetExtraDataStringList(strPositionAddress);
|
---|
530 |
|
---|
531 | bool ok = !strPositionSettings.isEmpty(), max = false;
|
---|
532 | int x = 0, y = 0, w = 0, h = 0;
|
---|
533 |
|
---|
534 | if (ok && strPositionSettings.size() > 0)
|
---|
535 | x = strPositionSettings[0].toInt(&ok);
|
---|
536 | else ok = false;
|
---|
537 | if (ok && strPositionSettings.size() > 1)
|
---|
538 | y = strPositionSettings[1].toInt(&ok);
|
---|
539 | else ok = false;
|
---|
540 | if (ok && strPositionSettings.size() > 2)
|
---|
541 | w = strPositionSettings[2].toInt(&ok);
|
---|
542 | else ok = false;
|
---|
543 | if (ok && strPositionSettings.size() > 3)
|
---|
544 | h = strPositionSettings[3].toInt(&ok);
|
---|
545 | else ok = false;
|
---|
546 | if (ok && strPositionSettings.size() > 4)
|
---|
547 | max = strPositionSettings[4] == VBoxDefs::GUI_LastWindowState_Max;
|
---|
548 |
|
---|
549 | QRect ar = ok ? QApplication::desktop()->availableGeometry(QPoint(x, y)) :
|
---|
550 | QApplication::desktop()->availableGeometry(machineWindow());
|
---|
551 |
|
---|
552 | /* If previous parameters were read correctly: */
|
---|
553 | if (ok)
|
---|
554 | {
|
---|
555 | /* If previous machine state is SAVED: */
|
---|
556 | if (machine.GetState() == KMachineState_Saved)
|
---|
557 | {
|
---|
558 | /* Restore window size and position: */
|
---|
559 | m_normalGeometry = QRect(x, y, w, h);
|
---|
560 | setGeometry(m_normalGeometry);
|
---|
561 | }
|
---|
562 | /* If previous machine state is not SAVED: */
|
---|
563 | else
|
---|
564 | {
|
---|
565 | /* Restore only window position: */
|
---|
566 | m_normalGeometry = QRect(x, y, width(), height());
|
---|
567 | setGeometry(m_normalGeometry);
|
---|
568 | if (machineView())
|
---|
569 | machineView()->normalizeGeometry(false /* adjust position? */);
|
---|
570 | }
|
---|
571 | /* Maximize if needed: */
|
---|
572 | if (max)
|
---|
573 | setWindowState(windowState() | Qt::WindowMaximized);
|
---|
574 | }
|
---|
575 | else
|
---|
576 | {
|
---|
577 | /* Normalize view early to the optimal size: */
|
---|
578 | if (machineView())
|
---|
579 | machineView()->normalizeGeometry(true /* adjust position? */);
|
---|
580 | /* Move newly created window to the screen center: */
|
---|
581 | m_normalGeometry = geometry();
|
---|
582 | m_normalGeometry.moveCenter(ar.center());
|
---|
583 | setGeometry(m_normalGeometry);
|
---|
584 | }
|
---|
585 |
|
---|
586 | /* Normalize view to the optimal size:
|
---|
587 | * Note: Cause of the async behavior of X11 (at least GNOME) we have to delay this a little bit.
|
---|
588 | * On Mac OS X and MS Windows this is not necessary and create even wrong resize events.
|
---|
589 | * So there we set the geometry immediately. */
|
---|
590 | if (machineView())
|
---|
591 | #ifdef Q_WS_X11
|
---|
592 | QTimer::singleShot(0, machineView(), SLOT(sltNormalizeGeometry()));
|
---|
593 | #else /* Q_WS_X11 */
|
---|
594 | machineView()->normalizeGeometry(true);
|
---|
595 | #endif /* !Q_WS_X11 */
|
---|
596 | }
|
---|
597 |
|
---|
598 | /* Load availability settings: */
|
---|
599 | {
|
---|
600 | /* USB Stuff: */
|
---|
601 | const CUSBController &usbController = machine.GetUSBController();
|
---|
602 | if ( usbController.isNull()
|
---|
603 | || !usbController.GetEnabled()
|
---|
604 | || !usbController.GetProxyAvailable())
|
---|
605 | {
|
---|
606 | /* Hide USB Menu: */
|
---|
607 | indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->setHidden(true);
|
---|
608 | }
|
---|
609 | else
|
---|
610 | {
|
---|
611 | /* Toggle USB LED: */
|
---|
612 | indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->setState(
|
---|
613 | usbController.GetEnabled() ? KDeviceActivity_Idle : KDeviceActivity_Null);
|
---|
614 | }
|
---|
615 | }
|
---|
616 |
|
---|
617 | /* Load global settings: */
|
---|
618 | {
|
---|
619 | VBoxGlobalSettings settings = vboxGlobal().settings();
|
---|
620 | menuBar()->setHidden(settings.isFeatureActive("noMenuBar"));
|
---|
621 | statusBar()->setHidden(settings.isFeatureActive("noStatusBar"));
|
---|
622 | }
|
---|
623 | }
|
---|
624 |
|
---|
625 | void UIMachineWindowNormal::saveWindowSettings()
|
---|
626 | {
|
---|
627 | CMachine machine = session().GetMachine();
|
---|
628 |
|
---|
629 | /* Save extra-data settings: */
|
---|
630 | {
|
---|
631 | QString strWindowPosition = QString("%1,%2,%3,%4")
|
---|
632 | .arg(m_normalGeometry.x()).arg(m_normalGeometry.y())
|
---|
633 | .arg(m_normalGeometry.width()).arg(m_normalGeometry.height());
|
---|
634 | if (isMaximizedChecked())
|
---|
635 | strWindowPosition += QString(",%1").arg(VBoxDefs::GUI_LastWindowState_Max);
|
---|
636 | QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastNormalWindowPosition) :
|
---|
637 | QString("%1%2").arg(VBoxDefs::GUI_LastNormalWindowPosition).arg(m_uScreenId);
|
---|
638 | machine.SetExtraData(strPositionAddress, strWindowPosition);
|
---|
639 | }
|
---|
640 | }
|
---|
641 |
|
---|
642 | void UIMachineWindowNormal::cleanupMachineView()
|
---|
643 | {
|
---|
644 | /* Do not cleanup machine view if it is not present: */
|
---|
645 | if (!machineView())
|
---|
646 | return;
|
---|
647 |
|
---|
648 | UIMachineView::destroy(m_pMachineView);
|
---|
649 | m_pMachineView = 0;
|
---|
650 | }
|
---|
651 |
|
---|
652 | void UIMachineWindowNormal::cleanupStatusBar()
|
---|
653 | {
|
---|
654 | /* Stop LED-update timer: */
|
---|
655 | m_pIdleTimer->stop();
|
---|
656 | m_pIdleTimer->disconnect(SIGNAL(timeout()), this, SLOT(sltUpdateIndicators()));
|
---|
657 | }
|
---|
658 |
|
---|
659 | void UIMachineWindowNormal::showSimple()
|
---|
660 | {
|
---|
661 | /* Just show window: */
|
---|
662 | show();
|
---|
663 | }
|
---|
664 |
|
---|
665 | bool UIMachineWindowNormal::isMaximizedChecked()
|
---|
666 | {
|
---|
667 | #ifdef Q_WS_MAC
|
---|
668 | /* On the Mac the WindowStateChange signal doesn't seems to be delivered
|
---|
669 | * when the user get out of the maximized state. So check this ourself. */
|
---|
670 | return ::darwinIsWindowMaximized(this);
|
---|
671 | #else /* Q_WS_MAC */
|
---|
672 | return isMaximized();
|
---|
673 | #endif /* !Q_WS_MAC */
|
---|
674 | }
|
---|
675 |
|
---|