1 | /* $Id: UIMachineMenuBar.cpp 27141 2010-03-07 16:30:12Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIMachineMenuBar class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | /* Local includes */
|
---|
25 | #include "UIMachineMenuBar.h"
|
---|
26 | #include "UISession.h"
|
---|
27 | #include "UIActionsPool.h"
|
---|
28 | #include "VBoxGlobal.h"
|
---|
29 | #include "VBoxProblemReporter.h"
|
---|
30 |
|
---|
31 | /* Global includes */
|
---|
32 | #include <QMenuBar>
|
---|
33 |
|
---|
34 | UIMachineMenuBar::UIMachineMenuBar()
|
---|
35 | /* On the Mac we add some items only the first time, cause otherwise they
|
---|
36 | * will be merged more than once to the application menu by Qt. */
|
---|
37 | : m_fIsFirstTime(true)
|
---|
38 | {
|
---|
39 | }
|
---|
40 |
|
---|
41 | QMenu* UIMachineMenuBar::createMenu(UIActionsPool *pActionsPool)
|
---|
42 | {
|
---|
43 | /* Create empty menu: */
|
---|
44 | QMenu *pMenu = new QMenu;
|
---|
45 |
|
---|
46 | /* Fill menu with prepared items: */
|
---|
47 | foreach (QMenu *pSubMenu, prepareSubMenus(pActionsPool))
|
---|
48 | pMenu->addMenu(pSubMenu);
|
---|
49 |
|
---|
50 | /* Return filled menu: */
|
---|
51 | return pMenu;
|
---|
52 | }
|
---|
53 |
|
---|
54 | QMenuBar* UIMachineMenuBar::createMenuBar(UIActionsPool *pActionsPool)
|
---|
55 | {
|
---|
56 | /* Create empty menubar: */
|
---|
57 | QMenuBar *pMenuBar = new QMenuBar;
|
---|
58 |
|
---|
59 | /* Fill menubar with prepared items: */
|
---|
60 | foreach (QMenu *pSubMenu, prepareSubMenus(pActionsPool))
|
---|
61 | pMenuBar->addMenu(pSubMenu);
|
---|
62 |
|
---|
63 | /* Return filled menubar: */
|
---|
64 | return pMenuBar;
|
---|
65 | }
|
---|
66 |
|
---|
67 | QList<QMenu*> UIMachineMenuBar::prepareSubMenus(UIActionsPool *pActionsPool)
|
---|
68 | {
|
---|
69 | /* Create empty submenu list: */
|
---|
70 | QList<QMenu*> preparedSubMenus;
|
---|
71 |
|
---|
72 | /* Machine submenu: */
|
---|
73 | QMenu *pMenuMachine = pActionsPool->action(UIActionIndex_Menu_Machine)->menu();
|
---|
74 | prepareMenuMachine(pMenuMachine, pActionsPool);
|
---|
75 | preparedSubMenus << pMenuMachine;
|
---|
76 |
|
---|
77 | /* Devices submenu: */
|
---|
78 | QMenu *pMenuDevices = pActionsPool->action(UIActionIndex_Menu_Devices)->menu();
|
---|
79 | prepareMenuDevices(pMenuDevices, pActionsPool);
|
---|
80 | preparedSubMenus << pMenuDevices;
|
---|
81 |
|
---|
82 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
83 | /* Debug submenu: */
|
---|
84 | if (vboxGlobal().isDebuggerEnabled())
|
---|
85 | {
|
---|
86 | QMenu *pMenuDebug = pActionsPool->action(UIActionIndex_Menu_Debug)->menu();
|
---|
87 | prepareMenuDebug(pMenuDebug, pActionsPool);
|
---|
88 | preparedSubMenus << pMenuDebug;
|
---|
89 | }
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | /* Help submenu: */
|
---|
93 | QMenu *pMenuHelp = pActionsPool->action(UIActionIndex_Menu_Help)->menu();
|
---|
94 | prepareMenuHelp(pMenuHelp, pActionsPool);
|
---|
95 | preparedSubMenus << pMenuHelp;
|
---|
96 |
|
---|
97 | /* Return a list of prepared submenus: */
|
---|
98 | return preparedSubMenus;
|
---|
99 | }
|
---|
100 |
|
---|
101 | void UIMachineMenuBar::prepareMenuMachine(QMenu *pMenu, UIActionsPool *pActionsPool)
|
---|
102 | {
|
---|
103 | /* Do not prepare if ready: */
|
---|
104 | if (!pMenu->isEmpty())
|
---|
105 | return;
|
---|
106 |
|
---|
107 | /* Machine submenu: */
|
---|
108 | pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Fullscreen));
|
---|
109 | pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Seamless));
|
---|
110 | pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_GuestAutoresize));
|
---|
111 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_AdjustWindow));
|
---|
112 | pMenu->addSeparator();
|
---|
113 | pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_MouseIntegration));
|
---|
114 | pMenu->addSeparator();
|
---|
115 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TypeCAD));
|
---|
116 | #ifdef Q_WS_X11
|
---|
117 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TypeCABS));
|
---|
118 | #endif
|
---|
119 | pMenu->addSeparator();
|
---|
120 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_TakeSnapshot));
|
---|
121 | pMenu->addSeparator();
|
---|
122 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_InformationDialog));
|
---|
123 | pMenu->addSeparator();
|
---|
124 | pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Pause));
|
---|
125 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Reset));
|
---|
126 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Shutdown));
|
---|
127 | #ifndef Q_WS_MAC
|
---|
128 | pMenu->addSeparator();
|
---|
129 | #else /* Q_WS_MAC */
|
---|
130 | if (m_fIsFirstTime)
|
---|
131 | #endif /* !Q_WS_MAC */
|
---|
132 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Close));
|
---|
133 | }
|
---|
134 |
|
---|
135 | void UIMachineMenuBar::prepareMenuDevices(QMenu *pMenu, UIActionsPool *pActionsPool)
|
---|
136 | {
|
---|
137 | /* Do not prepare if ready: */
|
---|
138 | if (!pMenu->isEmpty())
|
---|
139 | return;
|
---|
140 |
|
---|
141 | /* Devices submenu: */
|
---|
142 | pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_OpticalDevices)->menu());
|
---|
143 | pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_FloppyDevices)->menu());
|
---|
144 | pMenu->addMenu(pActionsPool->action(UIActionIndex_Menu_USBDevices)->menu());
|
---|
145 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_NetworkAdaptersDialog));
|
---|
146 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_SharedFoldersDialog));
|
---|
147 | pMenu->addSeparator();
|
---|
148 | pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_VRDP));
|
---|
149 | pMenu->addSeparator();
|
---|
150 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_InstallGuestTools));
|
---|
151 | }
|
---|
152 |
|
---|
153 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
154 | void UIMachineMenuBar::prepareMenuDebug(QMenu *pMenu, UIActionsPool *pActionsPool)
|
---|
155 | {
|
---|
156 | /* Do not prepare if ready: */
|
---|
157 | if (!pMenu->isEmpty())
|
---|
158 | return;
|
---|
159 |
|
---|
160 | /* Debug submenu: */
|
---|
161 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Statistics));
|
---|
162 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_CommandLine));
|
---|
163 | pMenu->addAction(pActionsPool->action(UIActionIndex_Toggle_Logging));
|
---|
164 | }
|
---|
165 | #endif /* VBOX_WITH_DEBUGGER_GUI */
|
---|
166 |
|
---|
167 | void UIMachineMenuBar::prepareMenuHelp(QMenu *pMenu, UIActionsPool *pActionsPool)
|
---|
168 | {
|
---|
169 | /* Do not prepare if ready: */
|
---|
170 | if (!pMenu->isEmpty())
|
---|
171 | return;
|
---|
172 |
|
---|
173 | /* Help submenu: */
|
---|
174 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Help));
|
---|
175 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Web));
|
---|
176 | pMenu->addSeparator();
|
---|
177 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_ResetWarnings));
|
---|
178 | pMenu->addSeparator();
|
---|
179 |
|
---|
180 | #ifdef VBOX_WITH_REGISTRATION
|
---|
181 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Register));
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | #ifdef Q_WS_MAC
|
---|
185 | if (m_fIsFirstTime)
|
---|
186 | #endif /* Q_WS_MAC */
|
---|
187 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_Update));
|
---|
188 |
|
---|
189 | #ifndef Q_WS_MAC
|
---|
190 | pMenu->addSeparator();
|
---|
191 | #else /* Q_WS_MAC */
|
---|
192 | if (m_fIsFirstTime)
|
---|
193 | #endif /* !Q_WS_MAC */
|
---|
194 | pMenu->addAction(pActionsPool->action(UIActionIndex_Simple_About));
|
---|
195 |
|
---|
196 | /* Because this connections are done to VBoxGlobal, they are needed once only.
|
---|
197 | * Otherwise we will get the slots called more than once. */
|
---|
198 | if (m_fIsFirstTime)
|
---|
199 | {
|
---|
200 | VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Help), SIGNAL(triggered()),
|
---|
201 | &vboxProblem(), SLOT(showHelpHelpDialog()));
|
---|
202 | VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Web), SIGNAL(triggered()),
|
---|
203 | &vboxProblem(), SLOT(showHelpWebDialog()));
|
---|
204 | VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_ResetWarnings), SIGNAL(triggered()),
|
---|
205 | &vboxProblem(), SLOT(resetSuppressedMessages()));
|
---|
206 | VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Register), SIGNAL(triggered()),
|
---|
207 | &vboxGlobal(), SLOT(showRegistrationDialog()));
|
---|
208 | VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_Update), SIGNAL(triggered()),
|
---|
209 | &vboxGlobal(), SLOT(showUpdateDialog()));
|
---|
210 | VBoxGlobal::connect(pActionsPool->action(UIActionIndex_Simple_About), SIGNAL(triggered()),
|
---|
211 | &vboxProblem(), SLOT(showHelpAboutDialog()));
|
---|
212 |
|
---|
213 | VBoxGlobal::connect(&vboxGlobal(), SIGNAL (canShowRegDlg (bool)),
|
---|
214 | pActionsPool->action(UIActionIndex_Simple_Register), SLOT(setEnabled(bool)));
|
---|
215 | VBoxGlobal::connect(&vboxGlobal(), SIGNAL (canShowUpdDlg (bool)),
|
---|
216 | pActionsPool->action(UIActionIndex_Simple_Update), SLOT(setEnabled(bool)));
|
---|
217 |
|
---|
218 | m_fIsFirstTime = false;
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|