VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp@ 35740

Last change on this file since 35740 was 35133, checked in by vboxsync, 13 years ago

FE/Qt: Enable remember-last-folder property for open-medium-window by default.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 67.6 KB
Line 
1/* $Id: UIMachineLogic.cpp 35133 2010-12-15 13:32:39Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * UIMachineLogic 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 "QIFileDialog.h"
23#include "UIActionsPool.h"
24#include "UIDownloaderAdditions.h"
25#include "UIIconPool.h"
26#include "UIKeyboardHandler.h"
27#include "UIMouseHandler.h"
28#include "UIMachineLogic.h"
29#include "UIMachineLogicFullscreen.h"
30#include "UIMachineLogicNormal.h"
31#include "UIMachineLogicSeamless.h"
32#include "UIMachineLogicScale.h"
33#include "UIMachineView.h"
34#include "UIMachineWindow.h"
35#include "UISession.h"
36#include "VBoxGlobal.h"
37#include "VBoxProblemReporter.h"
38#include "VBoxTakeSnapshotDlg.h"
39#include "VBoxVMInformationDlg.h"
40#include "UIMachineSettingsNetwork.h"
41#include "UIMachineSettingsSF.h"
42#ifdef Q_WS_MAC
43# include "DockIconPreview.h"
44# include "UIExtraDataEventHandler.h"
45#endif /* Q_WS_MAC */
46
47/* Global includes */
48#include <iprt/path.h>
49#include <VBox/VMMDev.h>
50
51#ifdef VBOX_WITH_DEBUGGER_GUI
52# include <iprt/ldr.h>
53#endif /* VBOX_WITH_DEBUGGER_GUI */
54
55#ifdef Q_WS_X11
56# include <XKeyboard.h>
57# include <QX11Info>
58#endif /* Q_WS_X11 */
59
60#include <QDir>
61#include <QFileInfo>
62#include <QDesktopWidget>
63#include <QTimer>
64
65struct MediumTarget
66{
67 MediumTarget() : name(QString("")), port(0), device(0), id(QString()), type(VBoxDefs::MediumType_Invalid) {}
68 MediumTarget(const QString &strName, LONG iPort, LONG iDevice)
69 : name(strName), port(iPort), device(iDevice), id(QString()), type(VBoxDefs::MediumType_Invalid) {}
70 MediumTarget(const QString &strName, LONG iPort, LONG iDevice, const QString &strId)
71 : name(strName), port(iPort), device(iDevice), id(strId), type(VBoxDefs::MediumType_Invalid) {}
72 MediumTarget(const QString &strName, LONG iPort, LONG iDevice, VBoxDefs::MediumType eType)
73 : name(strName), port(iPort), device(iDevice), id(QString()), type(eType) {}
74 QString name;
75 LONG port;
76 LONG device;
77 QString id;
78 VBoxDefs::MediumType type;
79};
80Q_DECLARE_METATYPE(MediumTarget);
81
82struct RecentMediumTarget
83{
84 RecentMediumTarget() : name(QString("")), port(0), device(0), location(QString()), type(VBoxDefs::MediumType_Invalid) {}
85 RecentMediumTarget(const QString &strName, LONG iPort, LONG iDevice, const QString &strLocation, VBoxDefs::MediumType eType)
86 : name(strName), port(iPort), device(iDevice), location(strLocation), type(eType) {}
87 QString name;
88 LONG port;
89 LONG device;
90 QString location;
91 VBoxDefs::MediumType type;
92};
93Q_DECLARE_METATYPE(RecentMediumTarget);
94
95struct USBTarget
96{
97 USBTarget() : attach(false), id(QString()) {}
98 USBTarget(bool fAttach, const QString &strId)
99 : attach(fAttach), id(strId) {}
100 bool attach;
101 QString id;
102};
103Q_DECLARE_METATYPE(USBTarget);
104
105class UINetworkAdaptersDialog : public QIWithRetranslateUI<QDialog>
106{
107 Q_OBJECT;
108
109public:
110
111 UINetworkAdaptersDialog(QWidget *pParent, CSession &session)
112 : QIWithRetranslateUI<QDialog>(pParent)
113 , m_pSettings(0)
114 , m_session(session)
115 {
116 /* Setup Dialog's options */
117 setModal(true);
118 setWindowIcon(QIcon(":/nw_16px.png"));
119 setSizeGripEnabled(true);
120
121 /* Setup main dialog's layout */
122 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
123 VBoxGlobal::setLayoutMargin(pMainLayout, 10);
124 pMainLayout->setSpacing(10);
125
126 /* Setup settings layout */
127 m_pSettings = new UIMachineSettingsNetworkPage(true);
128 m_pSettings->setOrderAfter(this);
129 VBoxGlobal::setLayoutMargin(m_pSettings->layout(), 0);
130 m_pSettings->loadDirectlyFrom(m_session.GetMachine());
131 pMainLayout->addWidget(m_pSettings);
132
133 /* Setup button's layout */
134 QIDialogButtonBox *pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
135
136 connect(pButtonBox, SIGNAL(helpRequested()), &vboxProblem(), SLOT(showHelpHelpDialog()));
137 connect(pButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
138 connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
139 pMainLayout->addWidget(pButtonBox);
140
141 retranslateUi();
142 }
143
144protected:
145
146 void retranslateUi()
147 {
148 setWindowTitle(QApplication::translate("VBoxNetworkDialog", "Network Adapters"));
149 }
150
151protected slots:
152
153 virtual void accept()
154 {
155 CMachine machine = m_session.GetMachine();
156 m_pSettings->saveDirectlyTo(machine);
157 machine.SaveSettings();
158 if (!machine.isOk())
159 vboxProblem().cannotSaveMachineSettings(machine);
160 QDialog::accept();
161 }
162
163protected:
164
165 void showEvent(QShowEvent *pEvent)
166 {
167 resize(450, 300);
168 VBoxGlobal::centerWidget(this, parentWidget());
169 setMinimumWidth(400);
170 QDialog::showEvent(pEvent);
171 }
172
173private:
174
175 UIMachineSettingsNetworkPage *m_pSettings;
176 CSession &m_session;
177};
178
179class UISharedFoldersDialog : public QIWithRetranslateUI<QDialog>
180{
181 Q_OBJECT;
182
183public:
184
185 UISharedFoldersDialog(QWidget *pParent, CSession &session)
186 : QIWithRetranslateUI<QDialog>(pParent)
187 , m_pSettings(0)
188 , m_session(session)
189 {
190 /* Setup Dialog's options */
191 setModal(true);
192 setWindowIcon(QIcon(":/select_file_16px.png"));
193 setSizeGripEnabled(true);
194
195 /* Setup main dialog's layout */
196 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
197 VBoxGlobal::setLayoutMargin(pMainLayout, 10);
198 pMainLayout->setSpacing(10);
199
200 /* Setup settings layout */
201 m_pSettings = new UIMachineSettingsSF;
202 VBoxGlobal::setLayoutMargin(m_pSettings->layout(), 0);
203 m_pSettings->loadDirectlyFrom(m_session.GetConsole());
204 pMainLayout->addWidget(m_pSettings);
205
206 /* Setup button's layout */
207 QIDialogButtonBox *pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
208
209 connect(pButtonBox, SIGNAL(helpRequested()), &vboxProblem(), SLOT(showHelpHelpDialog()));
210 connect(pButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
211 connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
212 pMainLayout->addWidget(pButtonBox);
213
214 retranslateUi();
215 }
216
217protected:
218
219 void retranslateUi()
220 {
221 setWindowTitle(QApplication::translate("VBoxSFDialog", "Shared Folders"));
222 }
223
224protected slots:
225
226 virtual void accept()
227 {
228 CMachine machine = m_session.GetMachine();
229 CConsole console = m_session.GetConsole();
230 m_pSettings->saveDirectlyTo(console);
231 machine.SaveSettings();
232 if (!machine.isOk())
233 vboxProblem().cannotSaveMachineSettings(machine);
234 QDialog::accept();
235 }
236
237protected:
238
239 void showEvent (QShowEvent *aEvent)
240 {
241 resize(450, 300);
242 VBoxGlobal::centerWidget(this, parentWidget());
243 setMinimumWidth(400);
244 QDialog::showEvent(aEvent);
245 }
246
247private:
248
249 UIMachineSettingsSF *m_pSettings;
250 CSession &m_session;
251};
252
253UIMachineLogic* UIMachineLogic::create(QObject *pParent,
254 UISession *pSession,
255 UIActionsPool *pActionsPool,
256 UIVisualStateType visualStateType)
257{
258 UIMachineLogic *logic = 0;
259 switch (visualStateType)
260 {
261 case UIVisualStateType_Normal:
262 logic = new UIMachineLogicNormal(pParent, pSession, pActionsPool);
263 break;
264 case UIVisualStateType_Fullscreen:
265 logic = new UIMachineLogicFullscreen(pParent, pSession, pActionsPool);
266 break;
267 case UIVisualStateType_Seamless:
268 logic = new UIMachineLogicSeamless(pParent, pSession, pActionsPool);
269 break;
270 case UIVisualStateType_Scale:
271 logic = new UIMachineLogicScale(pParent, pSession, pActionsPool);
272 break;
273 }
274 return logic;
275}
276
277bool UIMachineLogic::checkAvailability()
278{
279 return true;
280}
281
282UIMachineWindow* UIMachineLogic::mainMachineWindow() const
283{
284 /* Return null if windows are not created yet: */
285 if (!isMachineWindowsCreated())
286 return 0;
287
288 return machineWindows()[0];
289}
290
291UIMachineWindow* UIMachineLogic::defaultMachineWindow() const
292{
293 /* Return null if windows are not created yet: */
294 if (!isMachineWindowsCreated())
295 return 0;
296
297 /* Select main machine window by default: */
298 UIMachineWindow *pWindowToPropose = mainMachineWindow();
299
300 /* Check if there is active window present: */
301 foreach (UIMachineWindow *pWindowToCheck, machineWindows())
302 {
303 if (pWindowToCheck->machineWindow()->isActiveWindow())
304 {
305 pWindowToPropose = pWindowToCheck;
306 break;
307 }
308 }
309
310 /* Return default machine window: */
311 return pWindowToPropose;
312}
313
314#ifdef Q_WS_MAC
315void UIMachineLogic::updateDockIcon()
316{
317 if (!isMachineWindowsCreated())
318 return;
319
320 if ( m_fIsDockIconEnabled
321 && m_pDockIconPreview)
322 if(UIMachineView *pView = machineWindows().at(m_DockIconPreviewMonitor)->machineView())
323 if (CGImageRef image = pView->vmContentImage())
324 {
325 m_pDockIconPreview->updateDockPreview(image);
326 CGImageRelease(image);
327 }
328}
329
330void UIMachineLogic::updateDockIconSize(int screenId, int width, int height)
331{
332 if (!isMachineWindowsCreated())
333 return;
334
335 if ( m_fIsDockIconEnabled
336 && m_pDockIconPreview
337 && m_DockIconPreviewMonitor == screenId)
338 m_pDockIconPreview->setOriginalSize(width, height);
339}
340
341UIMachineView* UIMachineLogic::dockPreviewView() const
342{
343 if ( m_fIsDockIconEnabled
344 && m_pDockIconPreview)
345 return machineWindows().at(m_DockIconPreviewMonitor)->machineView();
346 return 0;
347}
348#endif /* Q_WS_MAC */
349
350UIMachineLogic::UIMachineLogic(QObject *pParent,
351 UISession *pSession,
352 UIActionsPool *pActionsPool,
353 UIVisualStateType visualStateType)
354 : QIWithRetranslateUI3<QObject>(pParent)
355 , m_pSession(pSession)
356 , m_pActionsPool(pActionsPool)
357 , m_visualStateType(visualStateType)
358 , m_pKeyboardHandler(0)
359 , m_pMouseHandler(0)
360 , m_pRunningActions(0)
361 , m_pRunningOrPausedActions(0)
362 , m_fIsWindowsCreated(false)
363 , m_fIsPreventAutoClose(false)
364#ifdef VBOX_WITH_DEBUGGER_GUI
365 , m_pDbgGui(0)
366 , m_pDbgGuiVT(0)
367#endif /* VBOX_WITH_DEBUGGER_GUI */
368#ifdef Q_WS_MAC
369 , m_fIsDockIconEnabled(true)
370 , m_pDockIconPreview(0)
371 , m_pDockPreviewSelectMonitorGroup(0)
372 , m_DockIconPreviewMonitor(0)
373#endif /* Q_WS_MAC */
374{
375}
376
377UIMachineLogic::~UIMachineLogic()
378{
379#ifdef VBOX_WITH_DEBUGGER_GUI
380 /* Close debugger: */
381 dbgDestroy();
382#endif /* VBOX_WITH_DEBUGGER_GUI */
383}
384
385CSession& UIMachineLogic::session()
386{
387 return uisession()->session();
388}
389
390void UIMachineLogic::addMachineWindow(UIMachineWindow *pMachineWindow)
391{
392 m_machineWindowsList << pMachineWindow;
393}
394
395void UIMachineLogic::setKeyboardHandler(UIKeyboardHandler *pKeyboardHandler)
396{
397 m_pKeyboardHandler = pKeyboardHandler;
398}
399
400void UIMachineLogic::setMouseHandler(UIMouseHandler *pMouseHandler)
401{
402 m_pMouseHandler = pMouseHandler;
403}
404
405void UIMachineLogic::retranslateUi()
406{
407#ifdef Q_WS_MAC
408 if (m_pDockPreviewSelectMonitorGroup)
409 {
410 const QList<QAction*> &actions = m_pDockPreviewSelectMonitorGroup->actions();
411 for (int i = 0; i < actions.size(); ++i)
412 {
413 QAction *pAction = actions.at(i);
414 pAction->setText(QApplication::translate("UIMachineLogic", "Preview Monitor %1").arg(pAction->data().toInt() + 1));
415 }
416 }
417#endif /* Q_WS_MAC */
418}
419
420#ifdef Q_WS_MAC
421void UIMachineLogic::updateDockOverlay()
422{
423 /* Only to an update to the realtime preview if this is enabled by the user
424 * & we are in an state where the framebuffer is likely valid. Otherwise to
425 * the overlay stuff only. */
426 KMachineState state = uisession()->machineState();
427 if (m_fIsDockIconEnabled &&
428 (state == KMachineState_Running ||
429 state == KMachineState_Paused ||
430 state == KMachineState_Teleporting ||
431 state == KMachineState_LiveSnapshotting ||
432 state == KMachineState_Restoring ||
433 state == KMachineState_TeleportingPausedVM ||
434 state == KMachineState_TeleportingIn ||
435 state == KMachineState_Saving ||
436 state == KMachineState_DeletingSnapshotOnline ||
437 state == KMachineState_DeletingSnapshotPaused))
438 updateDockIcon();
439 else if (m_pDockIconPreview)
440 m_pDockIconPreview->updateDockOverlay();
441}
442#endif /* Q_WS_MAC */
443
444void UIMachineLogic::prepareSessionConnections()
445{
446 /* Machine power-up notifier: */
447 connect(uisession(), SIGNAL(sigMachineStarted()), this, SLOT(sltCheckRequestedModes()));
448
449 /* Machine state-change updater: */
450 connect(uisession(), SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged()));
451
452 /* Guest additions state-change updater: */
453 connect(uisession(), SIGNAL(sigAdditionsStateChange()), this, SLOT(sltAdditionsStateChanged()));
454
455 /* Mouse capability state-change updater: */
456 connect(uisession(), SIGNAL(sigMouseCapabilityChange()), this, SLOT(sltMouseCapabilityChanged()));
457
458 /* USB devices state-change updater: */
459 connect(uisession(), SIGNAL(sigUSBDeviceStateChange(const CUSBDevice &, bool, const CVirtualBoxErrorInfo &)),
460 this, SLOT(sltUSBDeviceStateChange(const CUSBDevice &, bool, const CVirtualBoxErrorInfo &)));
461
462 /* Runtime errors notifier: */
463 connect(uisession(), SIGNAL(sigRuntimeError(bool, const QString &, const QString &)),
464 this, SLOT(sltRuntimeError(bool, const QString &, const QString &)));
465
466#ifdef Q_WS_MAC
467 /* Show windows: */
468 connect(uisession(), SIGNAL(sigShowWindows()),
469 this, SLOT(sltShowWindows()));
470#endif /* Q_WS_MAC */
471}
472
473void UIMachineLogic::prepareActionConnections()
474{
475 /* "Machine" actions connections: */
476 connect(actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize), SIGNAL(toggled(bool)),
477 this, SLOT(sltToggleGuestAutoresize(bool)));
478 connect(actionsPool()->action(UIActionIndex_Simple_AdjustWindow), SIGNAL(triggered()),
479 this, SLOT(sltAdjustWindow()));
480 connect(actionsPool()->action(UIActionIndex_Toggle_MouseIntegration), SIGNAL(toggled(bool)),
481 this, SLOT(sltToggleMouseIntegration(bool)));
482 connect(actionsPool()->action(UIActionIndex_Simple_TypeCAD), SIGNAL(triggered()),
483 this, SLOT(sltTypeCAD()));
484#ifdef Q_WS_X11
485 connect(actionsPool()->action(UIActionIndex_Simple_TypeCABS), SIGNAL(triggered()),
486 this, SLOT(sltTypeCABS()));
487#endif
488 connect(actionsPool()->action(UIActionIndex_Simple_TakeSnapshot), SIGNAL(triggered()),
489 this, SLOT(sltTakeSnapshot()));
490 connect(actionsPool()->action(UIActionIndex_Simple_InformationDialog), SIGNAL(triggered()),
491 this, SLOT(sltShowInformationDialog()));
492 connect(actionsPool()->action(UIActionIndex_Toggle_Pause), SIGNAL(toggled(bool)),
493 this, SLOT(sltPause(bool)));
494 connect(actionsPool()->action(UIActionIndex_Simple_Reset), SIGNAL(triggered()),
495 this, SLOT(sltReset()));
496 connect(actionsPool()->action(UIActionIndex_Simple_Shutdown), SIGNAL(triggered()),
497 this, SLOT(sltACPIShutdown()));
498 connect(actionsPool()->action(UIActionIndex_Simple_Close), SIGNAL(triggered()),
499 this, SLOT(sltClose()));
500
501 /* "Devices" actions connections: */
502 connect(actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu(), SIGNAL(aboutToShow()),
503 this, SLOT(sltPrepareStorageMenu()));
504 connect(actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu(), SIGNAL(aboutToShow()),
505 this, SLOT(sltPrepareStorageMenu()));
506 connect(actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu(), SIGNAL(aboutToShow()),
507 this, SLOT(sltPrepareUSBMenu()));
508 connect(actionsPool()->action(UIActionIndex_Simple_NetworkAdaptersDialog), SIGNAL(triggered()),
509 this, SLOT(sltOpenNetworkAdaptersDialog()));
510 connect(actionsPool()->action(UIActionIndex_Simple_SharedFoldersDialog), SIGNAL(triggered()),
511 this, SLOT(sltOpenSharedFoldersDialog()));
512 connect(actionsPool()->action(UIActionIndex_Toggle_VRDEServer), SIGNAL(toggled(bool)),
513 this, SLOT(sltSwitchVrde(bool)));
514 connect(actionsPool()->action(UIActionIndex_Simple_InstallGuestTools), SIGNAL(triggered()),
515 this, SLOT(sltInstallGuestAdditions()));
516
517#ifdef VBOX_WITH_DEBUGGER_GUI
518 /* "Debug" actions connections: */
519 connect(actionsPool()->action(UIActionIndex_Menu_Debug)->menu(), SIGNAL(aboutToShow()),
520 this, SLOT(sltPrepareDebugMenu()));
521 connect(actionsPool()->action(UIActionIndex_Simple_Statistics), SIGNAL(triggered()),
522 this, SLOT(sltShowDebugStatistics()));
523 connect(actionsPool()->action(UIActionIndex_Simple_CommandLine), SIGNAL(triggered()),
524 this, SLOT(sltShowDebugCommandLine()));
525 connect(actionsPool()->action(UIActionIndex_Toggle_Logging), SIGNAL(toggled(bool)),
526 this, SLOT(sltLoggingToggled(bool)));
527#endif
528}
529
530void UIMachineLogic::prepareActionGroups()
531{
532#ifdef Q_WS_MAC
533 /* On Mac OS X, all QMenu's are consumed by Qt after they are added to
534 * another QMenu or a QMenuBar. This means we have to recreate all QMenus
535 * when creating a new QMenuBar. */
536 uisession()->actionsPool()->createMenus();
537#endif /* Q_WS_MAC */
538
539 /* Create group for all actions that are enabled only when the VM is running.
540 * Note that only actions whose enabled state depends exclusively on the
541 * execution state of the VM are added to this group. */
542 m_pRunningActions = new QActionGroup(this);
543 m_pRunningActions->setExclusive(false);
544
545 /* Create group for all actions that are enabled when the VM is running or paused.
546 * Note that only actions whose enabled state depends exclusively on the
547 * execution state of the VM are added to this group. */
548 m_pRunningOrPausedActions = new QActionGroup(this);
549 m_pRunningOrPausedActions->setExclusive(false);
550
551 /* Move actions into running actions group: */
552 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Toggle_Fullscreen));
553 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Toggle_Seamless));
554 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Toggle_Scale));
555 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize));
556 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_AdjustWindow));
557 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_TypeCAD));
558#ifdef Q_WS_X11
559 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_TypeCABS));
560#endif
561 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_Reset));
562 m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_Shutdown));
563
564 /* Move actions into running-n-paused actions group: */
565 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_MouseIntegration));
566 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Toggle_MouseIntegration));
567 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_TakeSnapshot));
568 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_InformationDialog));
569 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Toggle_Pause));
570 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_OpticalDevices));
571 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_FloppyDevices));
572 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_USBDevices));
573 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_NetworkAdapters));
574 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_NetworkAdaptersDialog));
575 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_SharedFolders));
576 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_SharedFoldersDialog));
577 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Toggle_VRDEServer));
578 m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_InstallGuestTools));
579}
580
581void UIMachineLogic::prepareHandlers()
582{
583 /* Create keyboard-handler: */
584 setKeyboardHandler(UIKeyboardHandler::create(this, visualStateType()));
585
586 /* Create mouse-handler: */
587 setMouseHandler(UIMouseHandler::create(this, visualStateType()));
588}
589
590#ifdef Q_WS_MAC
591void UIMachineLogic::prepareDock()
592{
593 QMenu *pDockMenu = actionsPool()->action(UIActionIndex_Menu_Dock)->menu();
594
595 /* Add all VM menu entries to the dock menu. Leave out close and stuff like
596 * this. */
597 QList<QAction*> actions = actionsPool()->action(UIActionIndex_Menu_Machine)->menu()->actions();
598 for (int i=0; i < actions.size(); ++i)
599 if (actions.at(i)->menuRole() == QAction::NoRole)
600 pDockMenu->addAction(actions.at(i));
601 pDockMenu->addSeparator();
602
603 QMenu *pDockSettingsMenu = actionsPool()->action(UIActionIndex_Menu_DockSettings)->menu();
604 QActionGroup *pDockPreviewModeGroup = new QActionGroup(this);
605 QAction *pDockDisablePreview = actionsPool()->action(UIActionIndex_Toggle_DockDisableMonitor);
606 pDockPreviewModeGroup->addAction(pDockDisablePreview);
607 QAction *pDockEnablePreviewMonitor = actionsPool()->action(UIActionIndex_Toggle_DockPreviewMonitor);
608 pDockPreviewModeGroup->addAction(pDockEnablePreviewMonitor);
609 pDockSettingsMenu->addActions(pDockPreviewModeGroup->actions());
610
611 connect(pDockPreviewModeGroup, SIGNAL(triggered(QAction*)),
612 this, SLOT(sltDockPreviewModeChanged(QAction*)));
613 connect(gEDataEvents, SIGNAL(sigDockIconAppearanceChange(bool)),
614 this, SLOT(sltChangeDockIconUpdate(bool)));
615
616 /* Monitor selection if there are more than one monitor */
617 int cGuestScreens = uisession()->session().GetMachine().GetMonitorCount();
618 if (cGuestScreens > 1)
619 {
620 pDockSettingsMenu->addSeparator();
621 m_DockIconPreviewMonitor = qMin(session().GetMachine().GetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateMonitor).toInt(), cGuestScreens - 1);
622 m_pDockPreviewSelectMonitorGroup = new QActionGroup(this);
623 for (int i = 0; i < cGuestScreens; ++i)
624 {
625 QAction *pAction = new QAction(m_pDockPreviewSelectMonitorGroup);
626 pAction->setCheckable(true);
627 pAction->setData(i);
628 if (m_DockIconPreviewMonitor == i)
629 pAction->setChecked(true);
630 }
631 pDockSettingsMenu->addActions(m_pDockPreviewSelectMonitorGroup->actions());
632 connect(m_pDockPreviewSelectMonitorGroup, SIGNAL(triggered(QAction*)),
633 this, SLOT(sltDockPreviewMonitorChanged(QAction*)));
634 }
635
636 pDockMenu->addMenu(pDockSettingsMenu);
637
638 /* Add it to the dock. */
639 ::darwinSetDockIconMenu(pDockMenu);
640
641 /* Now the dock icon preview */
642 QString osTypeId = session().GetConsole().GetGuest().GetOSTypeId();
643 m_pDockIconPreview = new UIDockIconPreview(m_pSession, vboxGlobal().vmGuestOSTypeIcon(osTypeId));
644
645 QString strTest = session().GetMachine().GetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled).toLower();
646 /* Default to true if it is an empty value */
647 bool f = (strTest.isEmpty() || strTest == "true");
648 if (f)
649 pDockEnablePreviewMonitor->setChecked(true);
650 else
651 {
652 pDockDisablePreview->setChecked(true);
653 if(m_pDockPreviewSelectMonitorGroup)
654 m_pDockPreviewSelectMonitorGroup->setEnabled(false);
655 }
656
657 /* Default to true if it is an empty value */
658 setDockIconPreviewEnabled(f);
659 updateDockOverlay();
660}
661#endif /* Q_WS_MAC */
662
663void UIMachineLogic::prepareRequiredFeatures()
664{
665#ifdef Q_WS_MAC
666# ifdef VBOX_WITH_ICHAT_THEATER
667 /* Init shared AV manager: */
668 initSharedAVManager();
669# endif
670#endif
671}
672
673#ifdef VBOX_WITH_DEBUGGER_GUI
674void UIMachineLogic::prepareDebugger()
675{
676 CMachine machine = uisession()->session().GetMachine();
677 if (!machine.isNull() && vboxGlobal().isDebuggerAutoShowEnabled(machine))
678 {
679 /* console in upper left corner of the desktop. */
680// QRect rct (0, 0, 0, 0);
681// QDesktopWidget *desktop = QApplication::desktop();
682// if (desktop)
683// rct = desktop->availableGeometry(pos());
684// move (QPoint (rct.x(), rct.y()));
685
686 if (vboxGlobal().isDebuggerAutoShowStatisticsEnabled(machine))
687 sltShowDebugStatistics();
688 if (vboxGlobal().isDebuggerAutoShowCommandLineEnabled(machine))
689 sltShowDebugCommandLine();
690
691 if (!vboxGlobal().isStartPausedEnabled())
692 sltPause(false);
693 }
694}
695#endif /* VBOX_WITH_DEBUGGER_GUI */
696
697#ifdef Q_WS_MAC
698void UIMachineLogic::cleanupDock()
699{
700 if (m_pDockIconPreview)
701 {
702 delete m_pDockIconPreview;
703 m_pDockIconPreview = 0;
704 }
705}
706#endif /* Q_WS_MAC */
707
708void UIMachineLogic::cleanupHandlers()
709{
710 /* Cleanup mouse-handler: */
711 UIMouseHandler::destroy(mouseHandler());
712
713 /* Cleanup keyboard-handler: */
714 UIKeyboardHandler::destroy(keyboardHandler());
715}
716
717void UIMachineLogic::sltMachineStateChanged()
718{
719 /* Get machine state: */
720 KMachineState state = uisession()->machineState();
721
722 /* Update action groups: */
723 m_pRunningActions->setEnabled(uisession()->isRunning());
724 m_pRunningOrPausedActions->setEnabled(uisession()->isRunning() || uisession()->isPaused());
725
726 switch (state)
727 {
728 case KMachineState_Stuck: // TODO: Test it!
729 {
730 /* Prevent machine view from resizing: */
731 uisession()->setGuestResizeIgnored(true);
732
733 /* Get console: */
734 CConsole console = session().GetConsole();
735
736 /* Take the screenshot for debugging purposes and save it. */
737 QString strLogFolder = console.GetMachine().GetLogFolder();
738 CDisplay display = console.GetDisplay();
739 int cGuestScreens = uisession()->session().GetMachine().GetMonitorCount();
740 for (int i=0; i < cGuestScreens; ++i)
741 {
742 QString strFileName;
743 if (i == 0)
744 strFileName = strLogFolder + "/VBox.png";
745 else
746 strFileName = QString("%1/VBox.%2.png").arg(strLogFolder).arg(i);
747 ULONG width = 0;
748 ULONG height = 0;
749 ULONG bpp = 0;
750 display.GetScreenResolution(i, width, height, bpp);
751 QImage shot = QImage(width, height, QImage::Format_RGB32);
752 display.TakeScreenShot(i, shot.bits(), shot.width(), shot.height());
753 shot.save(QFile::encodeName(strFileName), "PNG");
754 }
755
756 /* Warn the user about GURU: */
757 if (vboxProblem().remindAboutGuruMeditation(console, QDir::toNativeSeparators(strLogFolder)))
758 {
759 console.PowerDown();
760 if (!console.isOk())
761 vboxProblem().cannotStopMachine(console);
762 }
763 break;
764 }
765 case KMachineState_Paused:
766 case KMachineState_TeleportingPausedVM:
767 {
768 QAction *pPauseAction = actionsPool()->action(UIActionIndex_Toggle_Pause);
769 if (!pPauseAction->isChecked())
770 {
771 /* Was paused from CSession side: */
772 pPauseAction->blockSignals(true);
773 pPauseAction->setChecked(true);
774 pPauseAction->blockSignals(false);
775 }
776 break;
777 }
778 case KMachineState_Running:
779 case KMachineState_Teleporting:
780 case KMachineState_LiveSnapshotting:
781 {
782 QAction *pPauseAction = actionsPool()->action(UIActionIndex_Toggle_Pause);
783 if (pPauseAction->isChecked())
784 {
785 /* Was resumed from CSession side: */
786 pPauseAction->blockSignals(true);
787 pPauseAction->setChecked(false);
788 pPauseAction->blockSignals(false);
789 }
790 break;
791 }
792 case KMachineState_PoweredOff:
793 case KMachineState_Saved:
794 case KMachineState_Teleported:
795 case KMachineState_Aborted:
796 {
797 /* Close VM if it was turned off and closure allowed: */
798 if (!isPreventAutoClose())
799 {
800 /* VM has been powered off, saved or aborted, no matter
801 * internally or externally. We must *safely* close VM window(s): */
802 QTimer::singleShot(0, uisession(), SLOT(sltCloseVirtualSession()));
803 }
804 break;
805 }
806#ifdef Q_WS_X11
807 case KMachineState_Starting:
808 case KMachineState_Restoring:
809 case KMachineState_TeleportingIn:
810 {
811 /* The keyboard handler may wish to do some release logging on startup.
812 * Tell it that the logger is now active. */
813 doXKeyboardLogging(QX11Info::display());
814 break;
815 }
816#endif
817 default:
818 break;
819 }
820
821#ifdef Q_WS_MAC
822 /* Update Dock Overlay: */
823 updateDockOverlay();
824#endif /* Q_WS_MAC */
825}
826
827void UIMachineLogic::sltAdditionsStateChanged()
828{
829 /* Variable flags: */
830 bool fIsSupportsGraphics = uisession()->isGuestSupportsGraphics();
831 bool fIsSupportsSeamless = uisession()->isGuestSupportsSeamless();
832
833 /* Update action states: */
834 actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setEnabled(fIsSupportsGraphics);
835 actionsPool()->action(UIActionIndex_Toggle_Seamless)->setEnabled(fIsSupportsSeamless);
836
837 /* Check if we should enter some extended mode: */
838 sltCheckRequestedModes();
839}
840
841void UIMachineLogic::sltMouseCapabilityChanged()
842{
843 /* Variable falgs: */
844 bool fIsMouseSupportsAbsolute = uisession()->isMouseSupportsAbsolute();
845 bool fIsMouseSupportsRelative = uisession()->isMouseSupportsRelative();
846 bool fIsMouseHostCursorNeeded = uisession()->isMouseHostCursorNeeded();
847
848 /* Update action state: */
849 QAction *pAction = actionsPool()->action(UIActionIndex_Toggle_MouseIntegration);
850 pAction->setEnabled(fIsMouseSupportsAbsolute && fIsMouseSupportsRelative && !fIsMouseHostCursorNeeded);
851 if (fIsMouseHostCursorNeeded)
852 pAction->setChecked(false);
853}
854
855void UIMachineLogic::sltUSBDeviceStateChange(const CUSBDevice &device, bool fIsAttached, const CVirtualBoxErrorInfo &error)
856{
857 bool fSuccess = error.isNull();
858
859 if (!fSuccess)
860 {
861 if (fIsAttached)
862 vboxProblem().cannotAttachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
863 else
864 vboxProblem().cannotDetachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
865 }
866}
867
868void UIMachineLogic::sltRuntimeError(bool fIsFatal, const QString &strErrorId, const QString &strMessage)
869{
870 vboxProblem().showRuntimeError(session().GetConsole(), fIsFatal, strErrorId, strMessage);
871}
872
873#ifdef Q_WS_MAC
874void UIMachineLogic::sltShowWindows()
875{
876 for (int i=0; i < m_machineWindowsList.size(); ++i)
877 {
878 UIMachineWindow *pMachineWindow = m_machineWindowsList.at(i);
879 /* Dunno what Qt thinks a window that has minimized to the dock
880 * should be - it is not hidden, neither is it minimized. OTOH it is
881 * marked shown and visible, but not activated. This latter isn't of
882 * much help though, since at this point nothing is marked activated.
883 * I might have overlooked something, but I'm buggered what if I know
884 * what. So, I'll just always show & activate the stupid window to
885 * make it get out of the dock when the user wishes to show a VM. */
886 pMachineWindow->machineWindow()->raise();
887 pMachineWindow->machineWindow()->activateWindow();
888 }
889}
890#endif /* Q_WS_MAC */
891
892void UIMachineLogic::sltCheckRequestedModes()
893{
894 /* Do not try to enter extended mode if machine was not started yet: */
895 if (!uisession()->isRunning() && !uisession()->isPaused())
896 return;
897
898 /* If seamless mode is requested, supported and we are NOT currently in seamless mode: */
899 if (uisession()->isSeamlessModeRequested() &&
900 uisession()->isGuestSupportsSeamless() &&
901 visualStateType() != UIVisualStateType_Seamless)
902 {
903 uisession()->setSeamlessModeRequested(false);
904 QAction *pSeamlessModeAction = actionsPool()->action(UIActionIndex_Toggle_Seamless);
905 AssertMsg(!pSeamlessModeAction->isChecked(), ("Seamless action should not be triggered before us!\n"));
906 QTimer::singleShot(0, pSeamlessModeAction, SLOT(trigger()));
907 }
908 /* If seamless mode is NOT requested, NOT supported and we are currently in seamless mode: */
909 else if (!uisession()->isSeamlessModeRequested() &&
910 !uisession()->isGuestSupportsSeamless() &&
911 visualStateType() == UIVisualStateType_Seamless)
912 {
913 uisession()->setSeamlessModeRequested(true);
914 QAction *pSeamlessModeAction = actionsPool()->action(UIActionIndex_Toggle_Seamless);
915 AssertMsg(pSeamlessModeAction->isChecked(), ("Seamless action should not be triggered before us!\n"));
916 QTimer::singleShot(0, pSeamlessModeAction, SLOT(trigger()));
917 }
918}
919
920void UIMachineLogic::sltToggleGuestAutoresize(bool fEnabled)
921{
922 /* Do not process if window(s) missed! */
923 if (!isMachineWindowsCreated())
924 return;
925
926 /* Toggle guest-autoresize feature for all view(s)! */
927 foreach(UIMachineWindow *pMachineWindow, machineWindows())
928 pMachineWindow->machineView()->setGuestAutoresizeEnabled(fEnabled);
929}
930
931void UIMachineLogic::sltAdjustWindow()
932{
933 /* Do not process if window(s) missed! */
934 if (!isMachineWindowsCreated())
935 return;
936
937 /* Adjust all window(s)! */
938 foreach(UIMachineWindow *pMachineWindow, machineWindows())
939 {
940 /* Exit maximized window state if actual: */
941 if (pMachineWindow->machineWindow()->isMaximized())
942 pMachineWindow->machineWindow()->showNormal();
943
944 /* Normalize view's geometry: */
945 pMachineWindow->machineView()->normalizeGeometry(true);
946 }
947}
948
949void UIMachineLogic::sltToggleMouseIntegration(bool fOff)
950{
951 /* Do not process if window(s) missed! */
952 if (!isMachineWindowsCreated())
953 return;
954
955 /* Disable/Enable mouse-integration for all view(s): */
956 m_pMouseHandler->setMouseIntegrationEnabled(!fOff);
957}
958
959void UIMachineLogic::sltTypeCAD()
960{
961 CKeyboard keyboard = session().GetConsole().GetKeyboard();
962 Assert(!keyboard.isNull());
963 keyboard.PutCAD();
964 AssertWrapperOk(keyboard);
965}
966
967#ifdef Q_WS_X11
968void UIMachineLogic::sltTypeCABS()
969{
970 CKeyboard keyboard = session().GetConsole().GetKeyboard();
971 Assert(!keyboard.isNull());
972 static QVector<LONG> aSequence(6);
973 aSequence[0] = 0x1d; /* Ctrl down */
974 aSequence[1] = 0x38; /* Alt down */
975 aSequence[2] = 0x0E; /* Backspace down */
976 aSequence[3] = 0x8E; /* Backspace up */
977 aSequence[4] = 0xb8; /* Alt up */
978 aSequence[5] = 0x9d; /* Ctrl up */
979 keyboard.PutScancodes(aSequence);
980 AssertWrapperOk(keyboard);
981}
982#endif
983
984void UIMachineLogic::sltTakeSnapshot()
985{
986 /* Do not process if window(s) missed! */
987 if (!isMachineWindowsCreated())
988 return;
989
990 /* Remember the paused state. */
991 bool fWasPaused = uisession()->isPaused();
992 if (!fWasPaused)
993 {
994 /* Suspend the VM and ignore the close event if failed to do so.
995 * pause() will show the error message to the user. */
996 if (!uisession()->pause())
997 return;
998 }
999
1000 CMachine machine = session().GetMachine();
1001
1002 VBoxTakeSnapshotDlg dlg(defaultMachineWindow()->machineWindow(), machine);
1003
1004 QString strTypeId = machine.GetOSTypeId();
1005 dlg.mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(strTypeId));
1006
1007 /* Search for the max available filter index. */
1008 QString strNameTemplate = QApplication::translate("UIMachineLogic", "Snapshot %1");
1009 int iMaxSnapshotIndex = searchMaxSnapshotIndex(machine, machine.FindSnapshot(QString()), strNameTemplate);
1010 dlg.mLeName->setText(strNameTemplate.arg(++ iMaxSnapshotIndex));
1011
1012 if (dlg.exec() == QDialog::Accepted)
1013 {
1014 CConsole console = session().GetConsole();
1015
1016 CProgress progress = console.TakeSnapshot(dlg.mLeName->text().trimmed(), dlg.mTeDescription->toPlainText());
1017
1018 if (console.isOk())
1019 {
1020 /* Show the "Taking Snapshot" progress dialog */
1021 vboxProblem().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_create_90px.png", 0, true);
1022
1023 if (progress.GetResultCode() != 0)
1024 vboxProblem().cannotTakeSnapshot(progress);
1025 }
1026 else
1027 vboxProblem().cannotTakeSnapshot(console);
1028 }
1029
1030 /* Restore the running state if needed. */
1031 if (!fWasPaused)
1032 {
1033 /* Make sure machine-state-change callback is processed: */
1034 QApplication::sendPostedEvents(uisession(), UIConsoleEventType_StateChange);
1035 /* Unpause VM: */
1036 uisession()->unpause();
1037 }
1038}
1039
1040void UIMachineLogic::sltShowInformationDialog()
1041{
1042 /* Do not process if window(s) missed! */
1043 if (!isMachineWindowsCreated())
1044 return;
1045
1046 VBoxVMInformationDlg::createInformationDlg(mainMachineWindow());
1047}
1048
1049void UIMachineLogic::sltReset()
1050{
1051 /* Confirm/Reset current console: */
1052 if (vboxProblem().confirmVMReset(0))
1053 session().GetConsole().Reset();
1054
1055 /* TODO_NEW_CORE: On reset the additional screens didn't get a display
1056 update. Emulate this for now until it get fixed. */
1057 ulong uMonitorCount = session().GetMachine().GetMonitorCount();
1058 for (ulong uScreenId = 1; uScreenId < uMonitorCount; ++uScreenId)
1059 machineWindows().at(uScreenId)->machineWindow()->update();
1060}
1061
1062void UIMachineLogic::sltPause(bool fOn)
1063{
1064 uisession()->setPause(fOn);
1065}
1066
1067void UIMachineLogic::sltACPIShutdown()
1068{
1069 /* Get console: */
1070 CConsole console = session().GetConsole();
1071
1072 /* Warn the user about ACPI is not available if so: */
1073 if (!console.GetGuestEnteredACPIMode())
1074 return vboxProblem().cannotSendACPIToMachine();
1075
1076 /* Send ACPI shutdown signal, warn if failed: */
1077 console.PowerButton();
1078 if (!console.isOk())
1079 vboxProblem().cannotACPIShutdownMachine(console);
1080}
1081
1082void UIMachineLogic::sltClose()
1083{
1084 /* Do not process if window(s) missed! */
1085 if (!isMachineWindowsCreated())
1086 return;
1087
1088 /* Propose to close default machine window: */
1089 defaultMachineWindow()->sltTryClose();
1090}
1091
1092void UIMachineLogic::sltPrepareStorageMenu()
1093{
1094 /* Get the sender() menu: */
1095 QMenu *pMenu = qobject_cast<QMenu*>(sender());
1096 AssertMsg(pMenu, ("This slot should only be called on hovering storage menu!\n"));
1097 pMenu->clear();
1098
1099 /* Short way to common storage menus: */
1100 QMenu *pOpticalDevicesMenu = actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu();
1101 QMenu *pFloppyDevicesMenu = actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu();
1102
1103 /* Determine medium & device types: */
1104 VBoxDefs::MediumType mediumType = pMenu == pOpticalDevicesMenu ? VBoxDefs::MediumType_DVD :
1105 pMenu == pFloppyDevicesMenu ? VBoxDefs::MediumType_Floppy :
1106 VBoxDefs::MediumType_Invalid;
1107 KDeviceType deviceType = vboxGlobal().mediumTypeToGlobal(mediumType);
1108 AssertMsg(mediumType != VBoxDefs::MediumType_Invalid, ("Incorrect storage medium type!\n"));
1109 AssertMsg(deviceType != KDeviceType_Null, ("Incorrect storage device type!\n"));
1110
1111 /* Fill attachments menu: */
1112 const CMachine &machine = session().GetMachine();
1113 const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
1114 for (int iAttachmentIndex = 0; iAttachmentIndex < attachments.size(); ++iAttachmentIndex)
1115 {
1116 /* Current attachment: */
1117 const CMediumAttachment &attachment = attachments[iAttachmentIndex];
1118 /* Current controller: */
1119 const CStorageController &controller = machine.GetStorageControllerByName(attachment.GetController());
1120 /* If controller present and device type correct: */
1121 if (!controller.isNull() && (attachment.GetType() == deviceType))
1122 {
1123 /* Current attachment attributes: */
1124 const CMedium &currentMedium = attachment.GetMedium();
1125 QString strCurrentId = currentMedium.isNull() ? QString::null : currentMedium.GetId();
1126 QString strCurrentLocation = currentMedium.isNull() ? QString::null : currentMedium.GetLocation();
1127
1128 /* Attachment menu item: */
1129 QMenu *pAttachmentMenu = 0;
1130 if (pMenu->menuAction()->data().toInt() > 1)
1131 {
1132 pAttachmentMenu = new QMenu(pMenu);
1133 pAttachmentMenu->setTitle(QString("%1 (%2)").arg(controller.GetName())
1134 .arg(vboxGlobal().toString(StorageSlot(controller.GetBus(),
1135 attachment.GetPort(),
1136 attachment.GetDevice()))));
1137 switch (controller.GetBus())
1138 {
1139 case KStorageBus_IDE:
1140 pAttachmentMenu->setIcon(QIcon(":/ide_16px.png")); break;
1141 case KStorageBus_SATA:
1142 pAttachmentMenu->setIcon(QIcon(":/sata_16px.png")); break;
1143 case KStorageBus_SCSI:
1144 pAttachmentMenu->setIcon(QIcon(":/scsi_16px.png")); break;
1145 case KStorageBus_Floppy:
1146 pAttachmentMenu->setIcon(QIcon(":/floppy_16px.png")); break;
1147 default:
1148 break;
1149 }
1150 pMenu->addMenu(pAttachmentMenu);
1151 }
1152 else pAttachmentMenu = pMenu;
1153
1154 /* Prepare choose-existing-medium action: */
1155 QAction *pChooseExistingMediumAction = pAttachmentMenu->addAction(QIcon(":/select_file_16px.png"), QString(),
1156 this, SLOT(sltMountStorageMedium()));
1157 pChooseExistingMediumAction->setData(QVariant::fromValue(MediumTarget(controller.GetName(), attachment.GetPort(),
1158 attachment.GetDevice(), mediumType)));
1159
1160 /* Prepare choose-particular-medium actions: */
1161 CMediumVector mediums;
1162 QString strRecentMediumAddress;
1163 switch (mediumType)
1164 {
1165 case VBoxDefs::MediumType_DVD:
1166 mediums = vboxGlobal().virtualBox().GetHost().GetDVDDrives();
1167 strRecentMediumAddress = VBoxDefs::GUI_RecentListCD;
1168 break;
1169 case VBoxDefs::MediumType_Floppy:
1170 mediums = vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
1171 strRecentMediumAddress = VBoxDefs::GUI_RecentListFD;
1172 break;
1173 default:
1174 break;
1175 }
1176
1177 /* Prepare choose-host-drive actions: */
1178 for (int iHostDriveIndex = 0; iHostDriveIndex < mediums.size(); ++iHostDriveIndex)
1179 {
1180 const CMedium &medium = mediums[iHostDriveIndex];
1181 bool fIsHostDriveUsed = false;
1182 for (int iOtherAttachmentIndex = 0; iOtherAttachmentIndex < attachments.size(); ++iOtherAttachmentIndex)
1183 {
1184 const CMediumAttachment &otherAttachment = attachments[iOtherAttachmentIndex];
1185 if (otherAttachment != attachment)
1186 {
1187 const CMedium &otherMedium = otherAttachment.GetMedium();
1188 if (!otherMedium.isNull() && otherMedium.GetId() == medium.GetId())
1189 {
1190 fIsHostDriveUsed = true;
1191 break;
1192 }
1193 }
1194 }
1195 if (!fIsHostDriveUsed)
1196 {
1197 QAction *pChooseHostDriveAction = pAttachmentMenu->addAction(VBoxMedium(medium, mediumType).name(),
1198 this, SLOT(sltMountStorageMedium()));
1199 pChooseHostDriveAction->setCheckable(true);
1200 pChooseHostDriveAction->setChecked(!currentMedium.isNull() && medium.GetId() == strCurrentId);
1201 pChooseHostDriveAction->setData(QVariant::fromValue(MediumTarget(controller.GetName(), attachment.GetPort(),
1202 attachment.GetDevice(), medium.GetId())));
1203 }
1204 }
1205
1206 /* Prepare choose-recent-medium actions: */
1207 QStringList recentMediumList = vboxGlobal().virtualBox().GetExtraData(strRecentMediumAddress).split(';');
1208 /* For every list-item: */
1209 for (int i = 0; i < recentMediumList.size(); ++i)
1210 {
1211 QString strRecentMediumLocation = QDir::toNativeSeparators(recentMediumList[i]);
1212 if (QFile::exists(strRecentMediumLocation))
1213 {
1214 bool fIsRecentMediumUsed = false;
1215 for (int iOtherAttachmentIndex = 0; iOtherAttachmentIndex < attachments.size(); ++iOtherAttachmentIndex)
1216 {
1217 const CMediumAttachment &otherAttachment = attachments[iOtherAttachmentIndex];
1218 if (otherAttachment != attachment)
1219 {
1220 const CMedium &otherMedium = otherAttachment.GetMedium();
1221 if (!otherMedium.isNull() && otherMedium.GetLocation() == strRecentMediumLocation)
1222 {
1223 fIsRecentMediumUsed = true;
1224 break;
1225 }
1226 }
1227 }
1228 if (!fIsRecentMediumUsed)
1229 {
1230 QAction *pChooseRecentMediumAction = pAttachmentMenu->addAction(QFileInfo(strRecentMediumLocation).fileName(),
1231 this, SLOT(sltMountRecentStorageMedium()));
1232 pChooseRecentMediumAction->setCheckable(true);
1233 pChooseRecentMediumAction->setChecked(!currentMedium.isNull() && strRecentMediumLocation == strCurrentLocation);
1234 pChooseRecentMediumAction->setData(QVariant::fromValue(RecentMediumTarget(controller.GetName(), attachment.GetPort(),
1235 attachment.GetDevice(), strRecentMediumLocation, mediumType)));
1236 }
1237 }
1238 }
1239
1240 /* Insert separator: */
1241 pAttachmentMenu->addSeparator();
1242
1243 /* Unmount Medium action: */
1244 QAction *unmountMediumAction = new QAction(pAttachmentMenu);
1245 unmountMediumAction->setEnabled(!currentMedium.isNull());
1246 unmountMediumAction->setData(QVariant::fromValue(MediumTarget(controller.GetName(),
1247 attachment.GetPort(),
1248 attachment.GetDevice())));
1249 connect(unmountMediumAction, SIGNAL(triggered(bool)), this, SLOT(sltMountStorageMedium()));
1250 pAttachmentMenu->addAction(unmountMediumAction);
1251
1252 /* Switch CD/FD naming */
1253 switch (mediumType)
1254 {
1255 case VBoxDefs::MediumType_DVD:
1256 pChooseExistingMediumAction->setText(QApplication::translate("UIMachineSettingsStorage", "Choose a virtual CD/DVD disk file..."));
1257 unmountMediumAction->setText(QApplication::translate("UIMachineSettingsStorage", "Remove disk from virtual drive"));
1258 unmountMediumAction->setIcon(UIIconPool::iconSet(":/cd_unmount_16px.png",
1259 ":/cd_unmount_dis_16px.png"));
1260 break;
1261 case VBoxDefs::MediumType_Floppy:
1262 pChooseExistingMediumAction->setText(QApplication::translate("UIMachineSettingsStorage", "Choose a virtual floppy disk file..."));
1263 unmountMediumAction->setText(QApplication::translate("UIMachineSettingsStorage", "Remove disk from virtual drive"));
1264 unmountMediumAction->setIcon(UIIconPool::iconSet(":/fd_unmount_16px.png",
1265 ":/fd_unmount_dis_16px.png"));
1266 break;
1267 default:
1268 break;
1269 }
1270 }
1271 }
1272
1273 if (pMenu->menuAction()->data().toInt() == 0)
1274 {
1275 /* Empty menu item */
1276 Assert(pMenu->isEmpty());
1277 QAction *pEmptyMenuAction = new QAction(pMenu);
1278 pEmptyMenuAction->setEnabled(false);
1279 switch (mediumType)
1280 {
1281 case VBoxDefs::MediumType_DVD:
1282 pEmptyMenuAction->setText(QApplication::translate("UIMachineLogic", "No CD/DVD Devices Attached"));
1283 pEmptyMenuAction->setToolTip(QApplication::translate("UIMachineLogic", "No CD/DVD devices attached to that VM"));
1284 break;
1285 case VBoxDefs::MediumType_Floppy:
1286 pEmptyMenuAction->setText(QApplication::translate("UIMachineLogic", "No Floppy Devices Attached"));
1287 pEmptyMenuAction->setToolTip(QApplication::translate("UIMachineLogic", "No floppy devices attached to that VM"));
1288 break;
1289 default:
1290 break;
1291 }
1292 pEmptyMenuAction->setIcon(UIIconPool::iconSet(":/delete_16px.png", ":/delete_dis_16px.png"));
1293 pMenu->addAction(pEmptyMenuAction);
1294 }
1295}
1296
1297void UIMachineLogic::sltMountStorageMedium()
1298{
1299 /* Get sender action: */
1300 QAction *action = qobject_cast<QAction*>(sender());
1301 AssertMsg(action, ("This slot should only be called on selecting storage menu item!\n"));
1302
1303 /* Get current machine: */
1304 CMachine machine = session().GetMachine();
1305
1306 /* Get mount-target: */
1307 MediumTarget target = action->data().value<MediumTarget>();
1308
1309 /* Current mount-target attributes: */
1310 CMediumAttachment currentAttachment = machine.GetMediumAttachment(target.name, target.port, target.device);
1311 CMedium currentMedium = currentAttachment.GetMedium();
1312 QString currentId = currentMedium.isNull() ? QString("") : currentMedium.GetId();
1313
1314 /* New mount-target attributes: */
1315 QString newId = QString("");
1316 bool fSelectWithMediaManager = target.type != VBoxDefs::MediumType_Invalid;
1317
1318 /* Open Virtual Media Manager to select image id: */
1319 if (fSelectWithMediaManager)
1320 {
1321 /* Search for already used images: */
1322 QStringList usedImages;
1323 foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments())
1324 {
1325 CMedium medium = attachment.GetMedium();
1326 if (attachment != currentAttachment && !medium.isNull() && !medium.GetHostDrive())
1327 usedImages << medium.GetId();
1328 }
1329 /* Call for file-open window: */
1330 QString strMachineFolder(QFileInfo(machine.GetSettingsFilePath()).absolutePath());
1331 QString strMediumId = vboxGlobal().openMediumWithFileOpenDialog(target.type, defaultMachineWindow()->machineWindow(),
1332 strMachineFolder);
1333 defaultMachineWindow()->machineView()->setFocus();
1334 if (!strMediumId.isNull())
1335 newId = strMediumId;
1336 else return;
1337 }
1338 /* Use medium which was sent: */
1339 else if (!target.id.isNull() && target.id != currentId)
1340 newId = target.id;
1341
1342 bool fMount = !newId.isEmpty();
1343
1344 VBoxMedium vmedium = vboxGlobal().findMedium(newId);
1345 CMedium medium = vmedium.medium(); // @todo r=dj can this be cached somewhere?
1346
1347 /* Remount medium to the predefined port/device: */
1348 bool fWasMounted = false;
1349 machine.MountMedium(target.name, target.port, target.device, medium, false /* force */);
1350 if (machine.isOk())
1351 fWasMounted = true;
1352 else
1353 {
1354 /* Ask for force remounting: */
1355 if (vboxProblem().cannotRemountMedium(0, machine, vboxGlobal().findMedium (fMount ? newId : currentId), fMount, true /* retry? */) == QIMessageBox::Ok)
1356 {
1357 /* Force remount medium to the predefined port/device: */
1358 machine.MountMedium(target.name, target.port, target.device, medium, true /* force */);
1359 if (machine.isOk())
1360 fWasMounted = true;
1361 else
1362 vboxProblem().cannotRemountMedium(0, machine, vboxGlobal().findMedium (fMount ? newId : currentId), fMount, false /* retry? */);
1363 }
1364 }
1365
1366 /* Save medium mounted at runtime */
1367 if (fWasMounted && !uisession()->isIgnoreRuntimeMediumsChanging())
1368 {
1369 machine.SaveSettings();
1370 if (!machine.isOk())
1371 vboxProblem().cannotSaveMachineSettings(machine);
1372 }
1373}
1374
1375void UIMachineLogic::sltMountRecentStorageMedium()
1376{
1377 /* Get sender action: */
1378 QAction *pSender = qobject_cast<QAction*>(sender());
1379 AssertMsg(pSender, ("This slot should only be called on selecting storage menu item!\n"));
1380
1381 /* Get mount-target: */
1382 RecentMediumTarget target = pSender->data().value<RecentMediumTarget>();
1383
1384 /* Get new medium id: */
1385 QString strNewId = vboxGlobal().openMedium(target.type, target.location);
1386
1387 if (!strNewId.isEmpty())
1388 {
1389 /* Get current machine: */
1390 CMachine machine = session().GetMachine();
1391
1392 /* Get current medium id: */
1393 const CMediumAttachment &currentAttachment = machine.GetMediumAttachment(target.name, target.port, target.device);
1394 CMedium currentMedium = currentAttachment.GetMedium();
1395 QString strCurrentId = currentMedium.isNull() ? QString("") : currentMedium.GetId();
1396
1397 /* Should we mount or unmount? */
1398 bool fMount = strNewId != strCurrentId;
1399
1400 /* Prepare target medium: */
1401 const VBoxMedium &vboxMedium = fMount ? vboxGlobal().findMedium(strNewId) : VBoxMedium();
1402 const CMedium &comMedium = fMount ? vboxMedium.medium() : CMedium();
1403
1404 /* 'Mounted' flag: */
1405 bool fWasMounted = false;
1406
1407 /* Try to mount medium to the predefined port/device: */
1408 machine.MountMedium(target.name, target.port, target.device, comMedium, false /* force? */);
1409 if (machine.isOk())
1410 fWasMounted = true;
1411 else
1412 {
1413 /* Ask for force remounting: */
1414 if (vboxProblem().cannotRemountMedium(0, machine, vboxGlobal().findMedium(fMount ? strNewId : strCurrentId), fMount, true /* retry? */) == QIMessageBox::Ok)
1415 {
1416 /* Force remount medium to the predefined port/device: */
1417 machine.MountMedium(target.name, target.port, target.device, comMedium, true /* force? */);
1418 if (machine.isOk())
1419 fWasMounted = true;
1420 else
1421 vboxProblem().cannotRemountMedium(0, machine, vboxGlobal().findMedium(fMount ? strNewId : strCurrentId), fMount, false /* retry? */);
1422 }
1423 }
1424
1425 /* Save medium mounted at runtime if necessary: */
1426 if (fWasMounted && !uisession()->isIgnoreRuntimeMediumsChanging())
1427 {
1428 machine.SaveSettings();
1429 if (!machine.isOk())
1430 vboxProblem().cannotSaveMachineSettings(machine);
1431 }
1432 }
1433}
1434
1435void UIMachineLogic::sltPrepareUSBMenu()
1436{
1437 /* Get the sender() menu: */
1438 QMenu *pMenu = qobject_cast<QMenu*>(sender());
1439#ifdef RT_STRICT
1440 QMenu *pUSBDevicesMenu = actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu();
1441#endif
1442 AssertMsg(pMenu == pUSBDevicesMenu, ("This slot should only be called on hovering USB menu!\n"));
1443 pMenu->clear();
1444
1445 /* Get HOST: */
1446 CHost host = vboxGlobal().virtualBox().GetHost();
1447
1448 /* Get USB devices list: */
1449 CHostUSBDeviceVector devices = host.GetUSBDevices();
1450
1451 /* Fill USB devices menu: */
1452 bool fIsUSBListEmpty = devices.size() == 0;
1453 if (fIsUSBListEmpty)
1454 {
1455 /* Fill USB devices menu: */
1456 QAction *pEmptyMenuAction = new QAction(pMenu);
1457 pEmptyMenuAction->setEnabled(false);
1458 pEmptyMenuAction->setText(QApplication::translate("UIMachineLogic", "No USB Devices Connected"));
1459 pEmptyMenuAction->setIcon(UIIconPool::iconSet(":/delete_16px.png", ":/delete_dis_16px.png"));
1460 pEmptyMenuAction->setToolTip(QApplication::translate("UIMachineLogic", "No supported devices connected to the host PC"));
1461 }
1462 else
1463 {
1464 foreach (const CHostUSBDevice hostDevice, devices)
1465 {
1466 /* Get common USB device: */
1467 CUSBDevice device(hostDevice);
1468
1469 /* Create USB device action: */
1470 QAction *attachUSBAction = new QAction(vboxGlobal().details(device), pMenu);
1471 attachUSBAction->setCheckable(true);
1472 connect(attachUSBAction, SIGNAL(triggered(bool)), this, SLOT(sltAttachUSBDevice()));
1473 pMenu->addAction(attachUSBAction);
1474
1475 /* Check if that USB device was already attached to this session: */
1476 CConsole console = session().GetConsole();
1477 CUSBDevice attachedDevice = console.FindUSBDeviceById(device.GetId());
1478 attachUSBAction->setChecked(!attachedDevice.isNull());
1479 attachUSBAction->setEnabled(hostDevice.GetState() != KUSBDeviceState_Unavailable);
1480
1481 /* Set USB attach data: */
1482 attachUSBAction->setData(QVariant::fromValue(USBTarget(!attachUSBAction->isChecked(), device.GetId())));
1483 attachUSBAction->setToolTip(vboxGlobal().toolTip(device));
1484 }
1485 }
1486}
1487
1488void UIMachineLogic::sltAttachUSBDevice()
1489{
1490 /* Get sender action: */
1491 QAction *action = qobject_cast<QAction*>(sender());
1492 AssertMsg(action, ("This slot should only be called on selecting USB menu item!\n"));
1493
1494 /* Get current console: */
1495 CConsole console = session().GetConsole();
1496
1497 /* Get USB target: */
1498 USBTarget target = action->data().value<USBTarget>();
1499 CUSBDevice device = console.FindUSBDeviceById(target.id);
1500
1501 /* Attach USB device: */
1502 if (target.attach)
1503 {
1504 console.AttachUSBDevice(target.id);
1505 if (!console.isOk())
1506 vboxProblem().cannotAttachUSBDevice(console, vboxGlobal().details(device));
1507 }
1508 else
1509 {
1510 console.DetachUSBDevice(target.id);
1511 if (!console.isOk())
1512 vboxProblem().cannotDetachUSBDevice(console, vboxGlobal().details(device));
1513 }
1514}
1515
1516void UIMachineLogic::sltOpenNetworkAdaptersDialog()
1517{
1518 /* Do not process if window(s) missed! */
1519 if (!isMachineWindowsCreated())
1520 return;
1521
1522 /* Show network settings dialog: */
1523 UINetworkAdaptersDialog dlg(defaultMachineWindow()->machineWindow(), session());
1524 dlg.exec();
1525}
1526
1527void UIMachineLogic::sltOpenSharedFoldersDialog()
1528{
1529 /* Do not process if window(s) missed! */
1530 if (!isMachineWindowsCreated())
1531 return;
1532
1533 /* Show shared folders settings dialog: */
1534 UISharedFoldersDialog dlg(defaultMachineWindow()->machineWindow(), session());
1535 if (!uisession()->isGuestAdditionsActive())
1536 vboxProblem().remindAboutGuestAdditionsAreNotActive(defaultMachineWindow()->machineWindow());
1537 dlg.exec();
1538}
1539
1540void UIMachineLogic::sltSwitchVrde(bool fOn)
1541{
1542 /* Enable VRDE server if possible: */
1543 CVRDEServer server = session().GetMachine().GetVRDEServer();
1544 AssertMsg(!server.isNull(), ("VRDE server should not be null!\n"));
1545 server.SetEnabled(fOn);
1546}
1547
1548void UIMachineLogic::sltInstallGuestAdditions()
1549{
1550 /* Do not process if window(s) missed! */
1551 if (!isMachineWindowsCreated())
1552 return;
1553
1554 char strAppPrivPath[RTPATH_MAX];
1555 int rc = RTPathAppPrivateNoArch(strAppPrivPath, sizeof(strAppPrivPath));
1556 AssertRC (rc);
1557
1558 QString strSrc1 = QString(strAppPrivPath) + "/VBoxGuestAdditions.iso";
1559 QString strSrc2 = qApp->applicationDirPath() + "/additions/VBoxGuestAdditions.iso";
1560
1561 /* Check the standard image locations */
1562 if (QFile::exists(strSrc1))
1563 return uisession()->sltInstallGuestAdditionsFrom(strSrc1);
1564 else if (QFile::exists(strSrc2))
1565 return uisession()->sltInstallGuestAdditionsFrom(strSrc2);
1566
1567 /* Check for the already registered image */
1568 CVirtualBox vbox = vboxGlobal().virtualBox();
1569 QString name = QString("VBoxGuestAdditions_%1.iso").arg(vbox.GetVersion().remove("_OSE"));
1570
1571 CMediumVector vec = vbox.GetDVDImages();
1572 for (CMediumVector::ConstIterator it = vec.begin(); it != vec.end(); ++ it)
1573 {
1574 QString path = it->GetLocation();
1575 /* Compare the name part ignoring the file case */
1576 QString fn = QFileInfo(path).fileName();
1577 if (RTPathCompare(name.toUtf8().constData(), fn.toUtf8().constData()) == 0)
1578 return uisession()->sltInstallGuestAdditionsFrom(path);
1579 }
1580
1581 /* Download the required image */
1582 int result = vboxProblem().cannotFindGuestAdditions(QDir::toNativeSeparators(strSrc1), QDir::toNativeSeparators(strSrc2));
1583 if (result == QIMessageBox::Yes)
1584 {
1585 QString source = QString("http://download.virtualbox.org/virtualbox/%1/").arg(vbox.GetVersion().remove("_OSE")) + name;
1586 QString target = QDir(vboxGlobal().virtualBox().GetHomeFolder()).absoluteFilePath(name);
1587
1588 UIDownloaderAdditions *pDl = UIDownloaderAdditions::create();
1589 /* Configure the additions downloader. */
1590 pDl->setSource(source);
1591 pDl->setTarget(target);
1592 pDl->setAction(actionsPool()->action(UIActionIndex_Simple_InstallGuestTools));
1593 pDl->setParentWidget(mainMachineWindow()->machineWindow());
1594 /* After the download is finished the user may like to install the
1595 * additions.*/
1596 connect(pDl, SIGNAL(downloadFinished(const QString&)),
1597 uisession(), SLOT(sltInstallGuestAdditionsFrom(const QString&)));
1598 /* Some of the modes may show additional info of the download progress: */
1599 emit sigDownloaderAdditionsCreated();
1600 /* Start the download: */
1601 pDl->startDownload();
1602 }
1603}
1604
1605#ifdef VBOX_WITH_DEBUGGER_GUI
1606void UIMachineLogic::sltPrepareDebugMenu()
1607{
1608 /* The "Logging" item. */
1609 bool fEnabled = false;
1610 bool fChecked = false;
1611 CConsole console = session().GetConsole();
1612 if (console.isOk())
1613 {
1614 CMachineDebugger cdebugger = console.GetDebugger();
1615 if (console.isOk())
1616 {
1617 fEnabled = true;
1618 fChecked = cdebugger.GetLogEnabled() != FALSE;
1619 }
1620 }
1621 if (fEnabled != actionsPool()->action(UIActionIndex_Toggle_Logging)->isEnabled())
1622 actionsPool()->action(UIActionIndex_Toggle_Logging)->setEnabled(fEnabled);
1623 if (fChecked != actionsPool()->action(UIActionIndex_Toggle_Logging)->isChecked())
1624 actionsPool()->action(UIActionIndex_Toggle_Logging)->setChecked(fChecked);
1625}
1626
1627void UIMachineLogic::sltShowDebugStatistics()
1628{
1629 if (dbgCreated())
1630 m_pDbgGuiVT->pfnShowStatistics(m_pDbgGui);
1631}
1632
1633void UIMachineLogic::sltShowDebugCommandLine()
1634{
1635 if (dbgCreated())
1636 m_pDbgGuiVT->pfnShowCommandLine(m_pDbgGui);
1637}
1638
1639void UIMachineLogic::sltLoggingToggled(bool fState)
1640{
1641 NOREF(fState);
1642 CConsole console = session().GetConsole();
1643 if (console.isOk())
1644 {
1645 CMachineDebugger cdebugger = console.GetDebugger();
1646 if (console.isOk())
1647 cdebugger.SetLogEnabled(fState);
1648 }
1649}
1650#endif
1651
1652#ifdef Q_WS_MAC
1653void UIMachineLogic::sltDockPreviewModeChanged(QAction *pAction)
1654{
1655 CMachine machine = m_pSession->session().GetMachine();
1656 if (!machine.isNull())
1657 {
1658 bool fEnabled = true;
1659 if (pAction == actionsPool()->action(UIActionIndex_Toggle_DockDisableMonitor))
1660 fEnabled = false;
1661
1662 machine.SetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled, fEnabled ? "true" : "false");
1663 updateDockOverlay();
1664 }
1665}
1666
1667void UIMachineLogic::sltDockPreviewMonitorChanged(QAction *pAction)
1668{
1669 CMachine machine = m_pSession->session().GetMachine();
1670 if (!machine.isNull())
1671 {
1672 int monitor = pAction->data().toInt();
1673 machine.SetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateMonitor, QString::number(monitor));
1674 updateDockOverlay();
1675 }
1676}
1677
1678void UIMachineLogic::sltChangeDockIconUpdate(bool fEnabled)
1679{
1680 if (isMachineWindowsCreated())
1681 {
1682 setDockIconPreviewEnabled(fEnabled);
1683 if (m_pDockPreviewSelectMonitorGroup)
1684 {
1685 m_pDockPreviewSelectMonitorGroup->setEnabled(fEnabled);
1686 CMachine machine = session().GetMachine();
1687 m_DockIconPreviewMonitor = qMin(machine.GetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateMonitor).toInt(), (int)machine.GetMonitorCount() - 1);
1688 }
1689 /* Resize the dock icon in the case the preview monitor has changed. */
1690 QSize size = machineWindows().at(m_DockIconPreviewMonitor)->machineView()->size();
1691 updateDockIconSize(m_DockIconPreviewMonitor, size.width(), size.height());
1692 updateDockOverlay();
1693 }
1694}
1695#endif /* Q_WS_MAC */
1696
1697int UIMachineLogic::searchMaxSnapshotIndex(const CMachine &machine,
1698 const CSnapshot &snapshot,
1699 const QString &strNameTemplate)
1700{
1701 int iMaxIndex = 0;
1702 QRegExp regExp(QString("^") + strNameTemplate.arg("([0-9]+)") + QString("$"));
1703 if (!snapshot.isNull())
1704 {
1705 /* Check the current snapshot name */
1706 QString strName = snapshot.GetName();
1707 int iPos = regExp.indexIn(strName);
1708 if (iPos != -1)
1709 iMaxIndex = regExp.cap(1).toInt() > iMaxIndex ? regExp.cap(1).toInt() : iMaxIndex;
1710 /* Traversing all the snapshot children */
1711 foreach (const CSnapshot &child, snapshot.GetChildren())
1712 {
1713 int iMaxIndexOfChildren = searchMaxSnapshotIndex(machine, child, strNameTemplate);
1714 iMaxIndex = iMaxIndexOfChildren > iMaxIndex ? iMaxIndexOfChildren : iMaxIndex;
1715 }
1716 }
1717 return iMaxIndex;
1718}
1719
1720#ifdef VBOX_WITH_DEBUGGER_GUI
1721bool UIMachineLogic::dbgCreated()
1722{
1723 if (m_pDbgGui)
1724 return true;
1725
1726 RTLDRMOD hLdrMod = vboxGlobal().getDebuggerModule();
1727 if (hLdrMod == NIL_RTLDRMOD)
1728 return false;
1729
1730 PFNDBGGUICREATE pfnGuiCreate;
1731 int rc = RTLdrGetSymbol(hLdrMod, "DBGGuiCreate", (void**)&pfnGuiCreate);
1732 if (RT_SUCCESS(rc))
1733 {
1734 ISession *pISession = session().raw();
1735 rc = pfnGuiCreate(pISession, &m_pDbgGui, &m_pDbgGuiVT);
1736 if (RT_SUCCESS(rc))
1737 {
1738 if (DBGGUIVT_ARE_VERSIONS_COMPATIBLE(m_pDbgGuiVT->u32Version, DBGGUIVT_VERSION) ||
1739 m_pDbgGuiVT->u32EndVersion == m_pDbgGuiVT->u32Version)
1740 {
1741 m_pDbgGuiVT->pfnSetParent(m_pDbgGui, defaultMachineWindow()->machineWindow());
1742 m_pDbgGuiVT->pfnSetMenu(m_pDbgGui, actionsPool()->action(UIActionIndex_Menu_Debug));
1743 dbgAdjustRelativePos();
1744 return true;
1745 }
1746
1747 LogRel(("DBGGuiCreate failed, incompatible versions (loaded %#x/%#x, expected %#x)\n",
1748 m_pDbgGuiVT->u32Version, m_pDbgGuiVT->u32EndVersion, DBGGUIVT_VERSION));
1749 }
1750 else
1751 LogRel(("DBGGuiCreate failed, rc=%Rrc\n", rc));
1752 }
1753 else
1754 LogRel(("RTLdrGetSymbol(,\"DBGGuiCreate\",) -> %Rrc\n", rc));
1755
1756 m_pDbgGui = 0;
1757 m_pDbgGuiVT = 0;
1758 return false;
1759}
1760
1761void UIMachineLogic::dbgDestroy()
1762{
1763 if (m_pDbgGui)
1764 {
1765 m_pDbgGuiVT->pfnDestroy(m_pDbgGui);
1766 m_pDbgGui = 0;
1767 m_pDbgGuiVT = 0;
1768 }
1769}
1770
1771void UIMachineLogic::dbgAdjustRelativePos()
1772{
1773 if (m_pDbgGui)
1774 {
1775 QRect rct = defaultMachineWindow()->machineWindow()->frameGeometry();
1776 m_pDbgGuiVT->pfnAdjustRelativePos(m_pDbgGui, rct.x(), rct.y(), rct.width(), rct.height());
1777 }
1778}
1779#endif
1780
1781#include "UIMachineLogic.moc"
1782
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use