VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.3 KB
Line 
1/* $Id: UIMachineLogic.h 106061 2024-09-16 14:03:52Z 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 /* Wrapper to open Machine settings / Network page: */
111 void openNetworkSettingsDialog() { sltOpenSettingsDialogNetwork(); }
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 sltOpenPreferencesDialog(const QString &strCategory = QString(), const QString &strControl = QString());
231 void sltOpenPreferencesDialogDefault() { sltOpenPreferencesDialog(); }
232 void sltClosePreferencesDialog();
233 void sltClose();
234
235 /* "Machine" menu functionality: */
236 void sltOpenSettingsDialog(const QString &strCategory = QString(), const QString &strControl = QString());
237 void sltOpenSettingsDialogDefault() { sltOpenSettingsDialog(); }
238 void sltCloseSettingsDialog();
239 void sltTakeSnapshot();
240 void sltShowInformationDialog();
241 void sltCloseInformationDialog();
242 void sltShowFileManagerDialog();
243 void sltCloseFileManagerDialog();
244 void sltShowLogDialog();
245 void sltCloseLogDialog();
246 void sltPause(bool fOn);
247 void sltReset();
248 void sltDetach();
249 void sltSaveState();
250 void sltShutdown();
251 void sltPowerOff();
252
253 /* "View" menu functionality: */
254 void sltMinimizeActiveMachineWindow();
255 void sltAdjustMachineWindows();
256 void sltToggleGuestAutoresize(bool fEnabled);
257 void sltTakeScreenshot();
258 void sltOpenRecordingOptions();
259 void sltToggleRecording(bool fEnabled);
260 void sltToggleVRDE(bool fEnabled);
261
262 /* "Input" menu functionality: */
263 void sltShowKeyboardSettings();
264 void sltShowSoftKeyboard();
265 void sltCloseSoftKeyboard();
266 void sltTypeCAD();
267#ifdef VBOX_WS_NIX
268 void sltTypeCABS();
269#endif /* VBOX_WS_NIX */
270 void sltTypeCtrlBreak();
271 void sltTypeInsert();
272 void sltTypePrintScreen();
273 void sltTypeAltPrintScreen();
274 void sltTypeHostKeyComboPressRelease(bool fToggleSequence);
275 void sltToggleMouseIntegration(bool fEnabled);
276
277 /* "Device" menu functionality: */
278 void sltOpenSettingsDialogStorage();
279 void sltMountStorageMedium();
280 void sltToggleAudioOutput(bool fEnabled);
281 void sltToggleAudioInput(bool fEnabled);
282 void sltOpenSettingsDialogNetwork();
283 void sltOpenSettingsDialogUSBDevices();
284 void sltOpenSettingsDialogSharedFolders();
285 void sltAttachUSBDevice();
286 void sltAttachWebcamDevice();
287 void sltChangeSharedClipboardType(QAction *pAction);
288 void sltFileTransferToggled(bool fChecked);
289 void sltToggleNetworkAdapterConnection(bool fChecked);
290 void sltChangeDragAndDropType(QAction *pAction);
291 void sltInstallGuestAdditions();
292
293#ifdef VBOX_WITH_DEBUGGER_GUI
294 /* "Debug" menu functionality: */
295 void sltShowDebugStatistics();
296 void sltShowDebugCommandLine();
297 void sltLoggingToggled(bool);
298 void sltShowGuestControlConsoleDialog();
299 void sltCloseGuestControlConsoleDialog();
300#endif /* VBOX_WITH_DEBUGGER_GUI */
301
302#ifdef RT_OS_DARWIN /* Something is *really* broken in regards of the moc here */
303 /* "Window" menu functionality: */
304 void sltSwitchToMachineWindow();
305
306 /* "Dock" menu functionality: */
307 void sltDockPreviewModeChanged(QAction *pAction);
308 void sltDockPreviewMonitorChanged(QAction *pAction);
309 void sltChangeDockIconUpdate(bool fEnabled);
310 /** Handles dock icon overlay change event. */
311 void sltChangeDockIconOverlayAppearance(bool fDisabled);
312 /** Handles dock icon overlay disable action triggering. */
313 void sltDockIconDisableOverlayChanged(bool fDisabled);
314#endif /* RT_OS_DARWIN */
315
316 /* Handlers: Keyboard LEDs sync logic: */
317 void sltSwitchKeyboardLedsToGuestLeds();
318 void sltSwitchKeyboardLedsToPreviousLeds();
319
320 /* Handle disabling/enabling host screen saver. */
321 void sltDisableHostScreenSaverStateChanged(bool fDisabled);
322
323 /** Handles request for visual state change. */
324 void sltHandleVisualStateChange();
325
326 /** Handles request to commit data. */
327 void sltHandleCommitData();
328
329 /** Handles translation event. */
330 void sltRetranslateUI();
331
332private:
333
334 /** Update 'Devices' : 'Optical/Floppy Devices' menu routine. */
335 void updateMenuDevicesStorage(QMenu *pMenu);
336 /** Update 'Devices' : 'Network' menu routine. */
337 void updateMenuDevicesNetwork(QMenu *pMenu);
338 /** Update 'Devices' : 'USB Devices' menu routine. */
339 void updateMenuDevicesUSB(QMenu *pMenu);
340 /** Update 'Devices' : 'Web Cams' menu routine. */
341 void updateMenuDevicesWebcams(QMenu *pMenu);
342 /** Update 'Devices' : 'Shared Clipboard' menu routine. */
343 void updateMenuDevicesSharedClipboard(QMenu *pMenu);
344 /** Update 'Devices' : 'Drag and Drop' menu routine. */
345 void updateMenuDevicesDragAndDrop(QMenu *pMenu);
346#ifdef VBOX_WITH_DEBUGGER_GUI
347 /** Update 'Debug' menu routine. */
348 void updateMenuDebug(QMenu *pMenu);
349#endif /* VBOX_WITH_DEBUGGER_GUI */
350#ifdef VBOX_WS_MAC
351 /** Update 'Window' menu routine. */
352 void updateMenuWindow(QMenu *pMenu);
353#endif /* VBOX_WS_MAC */
354
355 /** Asks user for the disks encryption passwords. */
356 void askUserForTheDiskEncryptionPasswords();
357
358 /* Helpers: */
359 void takeScreenshot(const QString &strFile, const QString &strFormat /* = "png" */) const;
360
361 /** Reactivates the screen saver. This is possbily called during vm window close and enables host screen
362 * if there are no other vms running at the moment. Note that this seems to be not needed on Linux since
363 * closing vm windows re-activates screen saver automatically. On Windows explicit re-activation is needed. */
364 void activateScreenSaver();
365 /* Shows the boot failure dialog through which user can mount a boot DVD and reset the vm. */
366 void showBootFailureDialog();
367 /** Resets the machine. If @p fShowConfirmation is true then a confirmation messag box is shown first. */
368 void reset(bool fShowConfirmation);
369
370 /* Private variables: */
371 UIMachine *m_pMachine;
372 UIKeyboardHandler *m_pKeyboardHandler;
373 UIMouseHandler *m_pMouseHandler;
374 QList<UIMachineWindow*> m_machineWindowsList;
375
376 QActionGroup *m_pRunningActions;
377 QActionGroup *m_pRunningOrPausedActions;
378 QActionGroup *m_pRunningOrPausedOrStuckActions;
379 QActionGroup *m_pSharedClipboardActions;
380 QAction *m_pFileTransferToggleAction;
381 QActionGroup *m_pDragAndDropActions;
382
383 /** Holds the map of menu update-handlers. */
384 QMap<int, MenuUpdateHandler> m_menuUpdateHandlers;
385
386 bool m_fIsWindowsCreated : 1;
387
388#ifdef VBOX_WS_MAC
389 bool m_fIsDockIconEnabled;
390 UIDockIconPreview *m_pDockIconPreview;
391 QActionGroup *m_pDockPreviewSelectMonitorGroup;
392 QAction *m_pDockSettingsMenuSeparator;
393 int m_DockIconPreviewMonitor;
394 QAction *m_pDockSettingMenuAction;
395 /* Keeps a list of machine menu actions that we add to dock menu. */
396 QList<QAction*> m_dockMachineMenuActions;
397#endif /* VBOX_WS_MAC */
398
399 void *m_pHostLedsState;
400
401 /** Holds the map of settings dialogs. */
402 QMap<UIAdvancedSettingsDialog::DialogType, UIAdvancedSettingsDialog*> m_settings;
403
404 /** Holds the log viewer dialog instance. */
405 QIManagerDialog *m_pLogViewerDialog;
406 QIManagerDialog *m_pFileManagerDialog;
407 QIManagerDialog *m_pProcessControlDialog;
408 UISoftKeyboard *m_pSoftKeyboardDialog;
409 UIVMInformationDialog *m_pVMInformationDialog;
410
411 /* Holds the cookies returnd by QDBus inhibition calls. Map keys are service name. These are required during uninhibition.*/
412 QMap<QString, uint> m_screenSaverInhibitionCookies;
413#if defined(VBOX_WS_NIX)
414 QVector<DBusScreenSaverInhibitMethod*> m_methods;
415#endif
416};
417
418#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