VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

Last change on this file was 106556, checked in by vboxsync, 6 weeks ago

FE/Qt: bugref:10513: Runtime UI / Machine-logic: At VM startup (if selected bridged adapter wasn't found) we should open Network settings dialog the modal way to pause startup for a moment while another adapter being chosen.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.9 KB
Line 
1/* $Id: UIMachineLogic.h 106556 2024-10-21 11:20:06Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMachineLogic class declaration.
4 */
5
6/*
7 * Copyright (C) 2010-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef FEQT_INCLUDED_SRC_runtime_UIMachineLogic_h
29#define FEQT_INCLUDED_SRC_runtime_UIMachineLogic_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* GUI includes: */
35#include "UIExtraDataDefs.h"
36#include "UIAdvancedSettingsDialog.h"
37
38/* COM includes: */
39#include "KGuestMonitorChangedEventType.h"
40
41/* Forward declarations: */
42class QAction;
43class QActionGroup;
44class QIManagerDialog;
45class UIActionPool;
46class UIKeyboardHandler;
47class UIMachine;
48class UIMachineWindow;
49class UIMachineView;
50class UIMouseHandler;
51class UIDockIconPreview;
52class UISoftKeyboard;
53class UIVMInformationDialog;
54class CUSBDevice;
55class CVirtualBoxErrorInfo;
56#if defined(VBOX_WS_NIX)
57 struct DBusScreenSaverInhibitMethod;
58#endif
59
60/* Machine logic interface: */
61class UIMachineLogic : public QObject
62{
63 Q_OBJECT;
64
65 /** Pointer to menu update-handler for this class: */
66 typedef void (UIMachineLogic::*MenuUpdateHandler)(QMenu *pMenu);
67
68public:
69
70 /** Factory function to create a logic of required type.
71 * @param pMachine Brings the machine this logic belongs to.
72 * @param pSession Brings the session this logic is created for.
73 * @param enmVisualStateType Brings the visual state type of logic to be created. */
74 static UIMachineLogic *create(UIMachine *pMachine, UIVisualStateType enmVisualStateType);
75 /** Factory function to destroy passed @a pLogic. */
76 static void destroy(UIMachineLogic *&pLogic);
77
78 /** Returns visual state type. */
79 virtual UIVisualStateType visualStateType() const = 0;
80
81 /* Check if this logic is available: */
82 virtual bool checkAvailability() = 0;
83
84 /** Returns machine-window flags for current machine-logic and passed @a uScreenId. */
85 virtual Qt::WindowFlags windowFlags(ulong uScreenId) const = 0;
86
87 /* Prepare/cleanup the logic: */
88 virtual void prepare();
89 virtual void cleanup();
90
91 /** Returns machine UI reference. */
92 UIMachine *uimachine() const { return m_pMachine; }
93 /** Returns action-pool reference. */
94 UIActionPool *actionPool() const;
95
96 /** Returns the machine name. */
97 QString machineName() const;
98 const QList<UIMachineWindow*>& machineWindows() const { return m_machineWindowsList; }
99 UIKeyboardHandler* keyboardHandler() const { return m_pKeyboardHandler; }
100 UIMouseHandler* mouseHandler() const { return m_pMouseHandler; }
101 UIMachineWindow* mainMachineWindow() const;
102 UIMachineWindow* activeMachineWindow() const;
103
104 /** Adjusts machine-window(s) geometry if necessary. */
105 virtual void adjustMachineWindowsGeometry();
106
107 /** Send machine-window(s) size-hint(s) to the guest. */
108 virtual void sendMachineWindowsSizeHints();
109
110 /** Opens Machine settings / Network page the modal way. */
111 void openNetworkSettingsDialogTheModalWay();
112
113#ifdef VBOX_WS_MAC
114 void updateDockIcon();
115 void updateDockIconSize(int screenId, int width, int height);
116 UIMachineView* dockPreviewView() const;
117 virtual void updateDock();
118#endif /* VBOX_WS_MAC */
119
120 /** An public interface to sltTypeHostKeyComboPressRelease. */
121 void typeHostKeyComboPressRelease(bool fToggleSequence);
122
123protected slots:
124
125 /** Handles the VBoxSVC availability change. */
126 void sltHandleVBoxSVCAvailabilityChange();
127
128 /** Handles Machine UI initialized event. */
129 void sltHandleMachineInitialized();
130
131 /** Checks if some visual-state type was requested. */
132 virtual void sltCheckForRequestedVisualStateType() {}
133
134 /** Requests visual-state change to 'normal' (window). */
135 virtual void sltChangeVisualStateToNormal();
136 /** Requests visual-state change to 'fullscreen'. */
137 virtual void sltChangeVisualStateToFullscreen();
138 /** Requests visual-state change to 'seamless'. */
139 virtual void sltChangeVisualStateToSeamless();
140 /** Requests visual-state change to 'scale'. */
141 virtual void sltChangeVisualStateToScale();
142
143 /* Console callback handlers: */
144 virtual void sltMachineStateChanged();
145 virtual void sltSessionStateChanged(const QUuid &uId, const KSessionState enmState);
146 virtual void sltAdditionsStateChanged();
147 virtual void sltMouseCapabilityChanged();
148 virtual void sltKeyboardLedsChanged();
149 virtual void sltUSBDeviceStateChange(const CUSBDevice &device, bool fIsAttached, const CVirtualBoxErrorInfo &error);
150 virtual void sltRuntimeError(bool fIsFatal, const QString &strErrorId, const QString &strMessage);
151#ifdef RT_OS_DARWIN
152 virtual void sltShowWindows();
153#endif /* RT_OS_DARWIN */
154 /** Handles guest-screen count change. */
155 virtual void sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo);
156
157 /** Handles host-screen count change. */
158 virtual void sltHostScreenCountChange();
159 /** Handles host-screen geometry change. */
160 virtual void sltHostScreenGeometryChange();
161 /** Handles host-screen available-area change. */
162 virtual void sltHostScreenAvailableAreaChange();
163 /* Handles Help Request. */
164 virtual void sltHandleHelpRequest();
165
166protected:
167
168 /** Constructs a logic passing @a pMachine to the base-class.
169 * @param pMachine Brings the machine this logic belongs to. */
170 UIMachineLogic(UIMachine *pMachine);
171 /* Destructs the logic. */
172 virtual ~UIMachineLogic() RT_OVERRIDE;
173
174 /* Protected getters/setters: */
175 bool isMachineWindowsCreated() const { return m_fIsWindowsCreated; }
176 void setMachineWindowsCreated(bool fIsWindowsCreated) { m_fIsWindowsCreated = fIsWindowsCreated; }
177
178 /* Protected members: */
179 void setKeyboardHandler(UIKeyboardHandler *pKeyboardHandler);
180 void setMouseHandler(UIMouseHandler *pMouseHandler);
181 void addMachineWindow(UIMachineWindow *pMachineWindow);
182#ifdef VBOX_WS_MAC
183 bool isDockIconPreviewEnabled() const { return m_fIsDockIconEnabled; }
184 void setDockIconPreviewEnabled(bool fIsDockIconPreviewEnabled) { m_fIsDockIconEnabled = fIsDockIconPreviewEnabled; }
185 void updateDockOverlay();
186#endif /* VBOX_WS_MAC */
187
188 /* Prepare helpers: */
189 virtual void prepareRequiredFeatures() {}
190 virtual void prepareSessionConnections();
191 virtual void prepareActionGroups();
192 virtual void prepareActionConnections();
193 virtual void prepareOtherConnections();
194 virtual void prepareHandlers();
195 virtual void prepareMachineWindows() = 0;
196 virtual void prepareMenu() {}
197#ifdef VBOX_WS_MAC
198 virtual void prepareDock();
199#endif /* VBOX_WS_MAC */
200#ifdef VBOX_WITH_DEBUGGER_GUI
201 virtual void prepareDebugger();
202#endif /* VBOX_WITH_DEBUGGER_GUI */
203 virtual void loadSettings();
204
205 /* Cleanup helpers: */
206#ifdef VBOX_WITH_DEBUGGER_GUI
207 virtual void cleanupDebugger();
208#endif /* VBOX_WITH_DEBUGGER_GUI */
209#ifdef VBOX_WS_MAC
210 virtual void cleanupDock();
211#endif /* VBOX_WS_MAC */
212 virtual void cleanupMenu() {}
213 virtual void cleanupMachineWindows() = 0;
214 virtual void cleanupHandlers();
215 //virtual void cleanupOtherConnections() {}
216 virtual void cleanupActionConnections() {}
217 virtual void cleanupActionGroups() {}
218 virtual void cleanupSessionConnections();
219 //virtual void cleanupRequiredFeatures() {}
220
221 /* Handler: Event-filter stuff: */
222 bool eventFilter(QObject *pWatched, QEvent *pEvent) RT_OVERRIDE;
223
224private slots:
225
226 /** Handle menu prepare. */
227 void sltHandleMenuPrepare(int iIndex, QMenu *pMenu);
228
229 /* "Application" menu functionality: */
230 void sltOpenPreferencesDialogDefault() { openPreferencesDialog(); }
231 void sltClosePreferencesDialog();
232 void sltClose();
233
234 /* "Machine" menu functionality: */
235 void sltOpenSettingsDialogDefault() { openSettingsDialog(); }
236 void sltCloseSettingsDialog();
237 void sltTakeSnapshot();
238 void sltShowInformationDialog();
239 void sltCloseInformationDialog();
240 void sltShowFileManagerDialog();
241 void sltCloseFileManagerDialog();
242 void sltShowLogDialog();
243 void sltCloseLogDialog();
244 void sltPause(bool fOn);
245 void sltReset();
246 void sltDetach();
247 void sltSaveState();
248 void sltShutdown();
249 void sltPowerOff();
250
251 /* "View" menu functionality: */
252 void sltMinimizeActiveMachineWindow();
253 void sltAdjustMachineWindows();
254 void sltToggleGuestAutoresize(bool fEnabled);
255 void sltTakeScreenshot();
256 void sltOpenRecordingOptions();
257 void sltToggleRecording(bool fEnabled);
258 void sltToggleVRDE(bool fEnabled);
259
260 /* "Input" menu functionality: */
261 void sltShowKeyboardSettings();
262 void sltShowSoftKeyboard();
263 void sltCloseSoftKeyboard();
264 void sltTypeCAD();
265#ifdef VBOX_WS_NIX
266 void sltTypeCABS();
267#endif /* VBOX_WS_NIX */
268 void sltTypeCtrlBreak();
269 void sltTypeInsert();
270 void sltTypePrintScreen();
271 void sltTypeAltPrintScreen();
272 void sltTypeHostKeyComboPressRelease(bool fToggleSequence);
273 void sltToggleMouseIntegration(bool fEnabled);
274
275 /* "Device" menu functionality: */
276 void sltOpenSettingsDialogStorage();
277 void sltMountStorageMedium();
278 void sltToggleAudioOutput(bool fEnabled);
279 void sltToggleAudioInput(bool fEnabled);
280 void sltOpenSettingsDialogNetwork();
281 void sltOpenSettingsDialogUSBDevices();
282 void sltOpenSettingsDialogSharedFolders();
283 void sltAttachUSBDevice();
284 void sltAttachWebcamDevice();
285 void sltChangeSharedClipboardType(QAction *pAction);
286 void sltFileTransferToggled(bool fChecked);
287 void sltToggleNetworkAdapterConnection(bool fChecked);
288 void sltChangeDragAndDropType(QAction *pAction);
289 void sltInstallGuestAdditions();
290
291#ifdef VBOX_WITH_DEBUGGER_GUI
292 /* "Debug" menu functionality: */
293 void sltShowDebugStatistics();
294 void sltShowDebugCommandLine();
295 void sltLoggingToggled(bool);
296 void sltShowGuestControlConsoleDialog();
297 void sltCloseGuestControlConsoleDialog();
298#endif /* VBOX_WITH_DEBUGGER_GUI */
299
300#ifdef RT_OS_DARWIN /* Something is *really* broken in regards of the moc here */
301 /* "Window" menu functionality: */
302 void sltSwitchToMachineWindow();
303
304 /* "Dock" menu functionality: */
305 void sltDockPreviewModeChanged(QAction *pAction);
306 void sltDockPreviewMonitorChanged(QAction *pAction);
307 void sltChangeDockIconUpdate(bool fEnabled);
308 /** Handles dock icon overlay change event. */
309 void sltChangeDockIconOverlayAppearance(bool fDisabled);
310 /** Handles dock icon overlay disable action triggering. */
311 void sltDockIconDisableOverlayChanged(bool fDisabled);
312#endif /* RT_OS_DARWIN */
313
314 /* Handlers: Keyboard LEDs sync logic: */
315 void sltSwitchKeyboardLedsToGuestLeds();
316 void sltSwitchKeyboardLedsToPreviousLeds();
317
318 /* Handle disabling/enabling host screen saver. */
319 void sltDisableHostScreenSaverStateChanged(bool fDisabled);
320
321 /** Handles request for visual state change. */
322 void sltHandleVisualStateChange();
323
324 /** Handles request to commit data. */
325 void sltHandleCommitData();
326
327 /** Handles translation event. */
328 void sltRetranslateUI();
329
330private:
331
332 /** Update 'Devices' : 'Optical/Floppy Devices' menu routine. */
333 void updateMenuDevicesStorage(QMenu *pMenu);
334 /** Update 'Devices' : 'Network' menu routine. */
335 void updateMenuDevicesNetwork(QMenu *pMenu);
336 /** Update 'Devices' : 'USB Devices' menu routine. */
337 void updateMenuDevicesUSB(QMenu *pMenu);
338 /** Update 'Devices' : 'Web Cams' menu routine. */
339 void updateMenuDevicesWebcams(QMenu *pMenu);
340 /** Update 'Devices' : 'Shared Clipboard' menu routine. */
341 void updateMenuDevicesSharedClipboard(QMenu *pMenu);
342 /** Update 'Devices' : 'Drag and Drop' menu routine. */
343 void updateMenuDevicesDragAndDrop(QMenu *pMenu);
344#ifdef VBOX_WITH_DEBUGGER_GUI
345 /** Update 'Debug' menu routine. */
346 void updateMenuDebug(QMenu *pMenu);
347#endif /* VBOX_WITH_DEBUGGER_GUI */
348#ifdef VBOX_WS_MAC
349 /** Update 'Window' menu routine. */
350 void updateMenuWindow(QMenu *pMenu);
351#endif /* VBOX_WS_MAC */
352
353 /** Asks user for the disks encryption passwords. */
354 void askUserForTheDiskEncryptionPasswords();
355
356 /** Opens Global preferences dialog.
357 * @param strCategory Brings the category to open.
358 * @param strControl Brings the name of control to choose.
359 * @param fAppModal Brings whether dialog should be app modal. */
360 void openPreferencesDialog(const QString &strCategory = QString(),
361 const QString &strControl = QString(),
362 bool fAppModal = false);
363
364 /** Opens VM settings dialog.
365 * @param strCategory Brings the category to open.
366 * @param strControl Brings the name of control to choose.
367 * @param fAppModal Brings whether dialog should be app modal. */
368 void openSettingsDialog(const QString &strCategory = QString(),
369 const QString &strControl = QString(),
370 bool fAppModal = false);
371
372 /* Helpers: */
373 void takeScreenshot(const QString &strFile, const QString &strFormat /* = "png" */) const;
374
375 /** Reactivates the screen saver. This is possbily called during vm window close and enables host screen
376 * if there are no other vms running at the moment. Note that this seems to be not needed on Linux since
377 * closing vm windows re-activates screen saver automatically. On Windows explicit re-activation is needed. */
378 void activateScreenSaver();
379 /* Shows the boot failure dialog through which user can mount a boot DVD and reset the vm. */
380 void showBootFailureDialog();
381 /** Resets the machine. If @p fShowConfirmation is true then a confirmation messag box is shown first. */
382 void reset(bool fShowConfirmation);
383
384 /* Private variables: */
385 UIMachine *m_pMachine;
386 UIKeyboardHandler *m_pKeyboardHandler;
387 UIMouseHandler *m_pMouseHandler;
388 QList<UIMachineWindow*> m_machineWindowsList;
389
390 QActionGroup *m_pRunningActions;
391 QActionGroup *m_pRunningOrPausedActions;
392 QActionGroup *m_pRunningOrPausedOrStuckActions;
393 QActionGroup *m_pSharedClipboardActions;
394 QAction *m_pFileTransferToggleAction;
395 QActionGroup *m_pDragAndDropActions;
396
397 /** Holds the map of menu update-handlers. */
398 QMap<int, MenuUpdateHandler> m_menuUpdateHandlers;
399
400 bool m_fIsWindowsCreated : 1;
401
402#ifdef VBOX_WS_MAC
403 bool m_fIsDockIconEnabled;
404 UIDockIconPreview *m_pDockIconPreview;
405 QActionGroup *m_pDockPreviewSelectMonitorGroup;
406 QAction *m_pDockSettingsMenuSeparator;
407 int m_DockIconPreviewMonitor;
408 QAction *m_pDockSettingMenuAction;
409 /* Keeps a list of machine menu actions that we add to dock menu. */
410 QList<QAction*> m_dockMachineMenuActions;
411#endif /* VBOX_WS_MAC */
412
413 void *m_pHostLedsState;
414
415 /** Holds the map of settings dialogs. */
416 QMap<UIAdvancedSettingsDialog::DialogType, UIAdvancedSettingsDialog*> m_settings;
417
418 /** Holds the log viewer dialog instance. */
419 QIManagerDialog *m_pLogViewerDialog;
420 QIManagerDialog *m_pFileManagerDialog;
421 QIManagerDialog *m_pProcessControlDialog;
422 UISoftKeyboard *m_pSoftKeyboardDialog;
423 UIVMInformationDialog *m_pVMInformationDialog;
424
425 /* Holds the cookies returnd by QDBus inhibition calls. Map keys are service name. These are required during uninhibition.*/
426 QMap<QString, uint> m_screenSaverInhibitionCookies;
427#if defined(VBOX_WS_NIX)
428 QVector<DBusScreenSaverInhibitMethod*> m_methods;
429#endif
430};
431
432#endif /* !FEQT_INCLUDED_SRC_runtime_UIMachineLogic_h */
Note: See TracBrowser for help on using the repository browser.

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