VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h@ 103977

Last change on this file since 103977 was 103549, checked in by vboxsync, 10 months ago

FE/Qt: UIVirtualBoxManager & UINotificationObjects: Get rid of UICommon include in the header.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.0 KB
Line 
1/* $Id: UIVirtualBoxManager.h 103549 2024-02-23 15:42:38Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVirtualBoxManager class declaration.
4 */
5
6/*
7 * Copyright (C) 2006-2023 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_manager_UIVirtualBoxManager_h
29#define FEQT_INCLUDED_SRC_manager_UIVirtualBoxManager_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QMainWindow>
36#include <QUrl>
37#include <QUuid>
38
39/* GUI includes: */
40#include "QIWithRestorableGeometry.h"
41#include "QIWithRetranslateUI.h"
42#include "UIAdvancedSettingsDialog.h"
43#include "UICloudMachineSettingsDialog.h"
44#include "UIDefs.h"
45#include "UIExtraDataDefs.h"
46#include "UIAdvancedSettingsDialog.h"
47
48/* Forward declarations: */
49class QMenu;
50class QIManagerDialog;
51class UIAction;
52class UIActionPool;
53class UINativeWizard;
54struct UIUnattendedInstallData;
55class UIVirtualBoxManagerWidget;
56class UIVirtualMachineItem;
57class CCloudMachine;
58class CUnattended;
59
60/* Type definitions: */
61typedef QIWithRestorableGeometry<QMainWindow> QMainWindowWithRestorableGeometry;
62typedef QIWithRetranslateUI<QMainWindowWithRestorableGeometry> QMainWindowWithRestorableGeometryAndRetranslateUi;
63
64/** Singleton QMainWindow extension used as VirtualBox Manager instance. */
65class UIVirtualBoxManager : public QMainWindowWithRestorableGeometryAndRetranslateUi
66{
67 Q_OBJECT;
68
69 /** Pointer to menu update-handler for this class: */
70 typedef void (UIVirtualBoxManager::*MenuUpdateHandler)(QMenu *pMenu);
71
72signals:
73
74 /** Notifies listeners about this window remapped to another screen. */
75 void sigWindowRemapped();
76
77public:
78
79 /** Singleton constructor. */
80 static void create();
81 /** Singleton destructor. */
82 static void destroy();
83 /** Singleton instance provider. */
84 static UIVirtualBoxManager *instance() { return s_pInstance; }
85
86 /** Returns the action-pool instance. */
87 UIActionPool *actionPool() const { return m_pActionPool; }
88
89 /** Opens Cloud Profile Manager. */
90 void openCloudProfileManager() { sltOpenManagerWindow(UIToolType_Cloud); }
91
92protected:
93
94 /** Constructs VirtualBox Manager. */
95 UIVirtualBoxManager();
96 /** Destructs VirtualBox Manager. */
97 virtual ~UIVirtualBoxManager() RT_OVERRIDE;
98
99 /** Returns whether the window should be maximized when geometry being restored. */
100 virtual bool shouldBeMaximized() const RT_OVERRIDE;
101
102 /** @name Event handling stuff.
103 * @{ */
104#ifdef VBOX_WS_MAC
105 /** Mac OS X: Preprocesses any @a pEvent for passed @a pObject. */
106 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
107#endif
108
109 /** Handles translation event. */
110 virtual void retranslateUi() RT_OVERRIDE;
111
112 /** Handles any Qt @a pEvent. */
113 virtual bool event(QEvent *pEvent) RT_OVERRIDE;
114 /** Handles show @a pEvent. */
115 virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
116 /** Handles first show @a pEvent. */
117 virtual void polishEvent(QShowEvent *pEvent);
118 /** Handles close @a pEvent. */
119 virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;
120 /** Handles drag enter @a pEvent. */
121 virtual void dragEnterEvent(QDragEnterEvent *event) RT_OVERRIDE;
122 /** Handles drop @a pEvent. */
123 virtual void dropEvent(QDropEvent *event) RT_OVERRIDE;
124 /** @} */
125
126private slots:
127
128 /** @name Common stuff.
129 * @{ */
130#ifdef VBOX_WS_NIX
131 /** Handles host-screen available-area change. */
132 void sltHandleHostScreenAvailableAreaChange();
133#endif
134
135 /** Handles request to update actions. */
136 void sltHandleUpdateActionAppearanceRequest() { updateActionsAppearance(); }
137
138 /** Handles request to commit data. */
139 void sltHandleCommitData();
140
141 /** Handles signal about medium-enumeration finished. */
142 void sltHandleMediumEnumerationFinish();
143
144 /** Handles call to open a @a list of URLs. */
145 void sltHandleOpenUrlCall(QList<QUrl> list = QList<QUrl>());
146
147 /** Checks if USB device list can be enumerated and host produces any warning during enumeration. */
148 void sltCheckUSBAccesibility();
149
150 /** Handles signal about Chooser-pane index change. */
151 void sltHandleChooserPaneIndexChange();
152 /** Handles signal about group saving progress change. */
153 void sltHandleGroupSavingProgressChange();
154 /** Handles signal about cloud update progress change. */
155 void sltHandleCloudUpdateProgressChange();
156
157 /** Handles signal about Global Tool type change. */
158 void sltHandleGlobalToolTypeChange();
159 /** Handles signal about Machine Tool type change. */
160 void sltHandleMachineToolTypeChange();
161
162 /** Handles create medium request. */
163 void sltCreateMedium();
164 /** Handles copy medium request. */
165 void sltCopyMedium(const QUuid &uMediumId);
166
167 /** Handles current snapshot item change. */
168 void sltCurrentSnapshotItemChange();
169
170 /** Handles request to detach Log Viewer pane. */
171 void sltDetachToolPane(UIToolType enmToolType);
172
173 /** Handles state change for cloud machine with certain @a uId. */
174 void sltHandleCloudMachineStateChange(const QUuid &uId);
175 /** @} */
176
177 /** @name CVirtualBox event handling stuff.
178 * @{ */
179 /** Handles CVirtualBox event about state change for machine with @a uID. */
180 void sltHandleStateChange(const QUuid &uID);
181 /** @} */
182
183 /** @name Action-pool stuff.
184 * @{ */
185 /** Handle menu prepare. */
186 void sltHandleMenuPrepare(int iIndex, QMenu *pMenu);
187 /** @} */
188
189 /** @name File menu stuff.
190 * @{ */
191 /** Handles call to open Manager window of certain @a enmType. */
192 void sltOpenManagerWindow(UIToolType enmType = UIToolType_Invalid);
193 /** Handles call to open Manager window by default. */
194 void sltOpenManagerWindowDefault() { sltOpenManagerWindow(); }
195 /** Handles call to embed Manager window of certain @a enmType. */
196 void sltEmbedManagerWindow(UIToolType enmType = UIToolType_Invalid);
197 /** Handles call to close Manager window of certain @a enmType. */
198 void sltCloseManagerWindow(UIToolType enmType = UIToolType_Invalid);
199 /** Handles call to embed Manager window by default. */
200 void sltEmbedManagerWindowDefault() { sltEmbedManagerWindow(); }
201 /** Handles call to close Manager window by default. */
202 void sltCloseManagerWindowDefault() { sltCloseManagerWindow(); }
203
204 /** Handles call to open Import Appliance wizard. */
205 void sltOpenImportApplianceWizard() { openImportApplianceWizard(); }
206 /** Handles call to open Export Appliance wizard. */
207 void sltOpenExportApplianceWizard();
208
209#ifdef VBOX_GUI_WITH_EXTRADATA_MANAGER_UI
210 /** Handles call to open Extra-data Manager window. */
211 void sltOpenExtraDataManagerWindow();
212#endif
213
214 /** Handles call to open Preferences dialog. */
215 void sltOpenPreferencesDialog();
216 /** Handles call to close Preferences dialog. */
217 void sltClosePreferencesDialog();
218
219 /** Handles call to switch to global tool corresponding to passed @a pAction. */
220 void sltPerformSwitchToGlobalTool(QAction *pAction);
221
222 /** Handles call to exit application. */
223 void sltPerformExit();
224 /** @} */
225
226 /** @name Machine menu stuff.
227 * @{ */
228 /** Handles call to open wizard of specified @a enmType. */
229 void sltOpenWizard(WizardType enmType);
230 /** Handles call to close wizard of specified @a enmType. */
231 void sltCloseWizard(WizardType enmType);
232
233 /** Handles call to open new machine wizard. */
234 void sltOpenNewMachineWizard();
235 /** Handles call to open add machine dialog. */
236 void sltOpenAddMachineDialog();
237
238 /** Handles call to open group name editor. */
239 void sltOpenGroupNameEditor();
240 /** Handles call to disband group. */
241 void sltDisbandGroup();
242
243 /** Handles call to open Settings dialog.
244 * @param strCategory can bring the settings category to start from.
245 * @param strControl can bring the widget of the page to focus.
246 * @param uID can bring the ID of machine to manage. */
247 void sltOpenSettingsDialog(QString strCategory = QString(),
248 QString strControl = QString(),
249 const QUuid &uID = QUuid());
250 /** Handles call to open Settings dialog the default way. */
251 void sltOpenSettingsDialogDefault() { sltOpenSettingsDialog(); }
252 /** Handles call to close Settings dialog. */
253 void sltCloseSettingsDialog();
254
255 /** Handles call to open Clone Machine wizard. */
256 void sltOpenCloneMachineWizard();
257
258 /** Handles call to move machine. */
259 void sltPerformMachineMove();
260
261 /** Handles call to remove machine. */
262 void sltPerformMachineRemove();
263
264 /** Handles call to move machine to a new group. */
265 void sltPerformMachineMoveToNewGroup();
266 /** Handles call to move machine to a specific group. */
267 void sltPerformMachineMoveToSpecificGroup();
268
269 /** Handles call to start or show machine. */
270 void sltPerformStartOrShowMachine();
271 /** Handles call to start machine in normal mode. */
272 void sltPerformStartMachineNormal();
273 /** Handles call to start machine in headless mode. */
274 void sltPerformStartMachineHeadless();
275 /** Handles call to start machine in detachable mode. */
276 void sltPerformStartMachineDetachable();
277
278 /** Handles call to create console connection for group. */
279 void sltPerformCreateConsoleConnectionForGroup();
280 /** Handles call to create console connection for machine. */
281 void sltPerformCreateConsoleConnectionForMachine();
282 /** Handles call to delete console connection for group. */
283 void sltPerformDeleteConsoleConnectionForGroup();
284 /** Handles call to delete console connection for machine. */
285 void sltPerformDeleteConsoleConnectionForMachine();
286 /** Handles call to copy console connection key fingerprint. */
287 void sltCopyConsoleConnectionFingerprint();
288 /** Handles call to copy serial console command for Unix. */
289 void sltPerformCopyCommandSerialUnix();
290 /** Handles call to copy serial console command for Windows. */
291 void sltPerformCopyCommandSerialWindows();
292 /** Handles call to copy VNC console command for Unix. */
293 void sltPerformCopyCommandVNCUnix();
294 /** Handles call to copy VNC console command for Windows. */
295 void sltPerformCopyCommandVNCWindows();
296 /** Handles call to show console log. */
297 void sltPerformShowLog();
298 /** Handles call about console @a strLog for cloud VM with @a strName read. */
299 void sltHandleConsoleLogRead(const QString &strName, const QString &strLog);
300 /** Handles call to execute external application. */
301 void sltExecuteExternalApplication();
302
303 /** Handles call to discard machine state. */
304 void sltPerformDiscardMachineState();
305
306 /** Handles call to @a fPause or resume machine otherwise. */
307 void sltPerformPauseOrResumeMachine(bool fPause);
308
309 /** Handles call to reset machine. */
310 void sltPerformResetMachine();
311
312 /** Handles call to detach machine UI. */
313 void sltPerformDetachMachineUI();
314 /** Handles call to save machine state. */
315 void sltPerformSaveMachineState();
316 /** Handles call to terminate machine. */
317 void sltPerformTerminateMachine();
318 /** Handles call to ask machine for shutdown. */
319 void sltPerformShutdownMachine();
320 /** Handles call to power machine off. */
321 void sltPerformPowerOffMachine();
322 /** Handles signal about machine powered off.
323 * @param fSuccess Brings whether machine was powered off successfully.
324 * @param fIncludingDiscard Brings whether machine state should be discarded. */
325 void sltHandlePoweredOffMachine(bool fSuccess, bool fIncludingDiscard);
326
327 /** Handles call to switch to machine tool corresponding to passed @a pAction. */
328 void sltPerformSwitchToMachineTool(QAction *pAction);
329
330 /** Handles call to refresh machine. */
331 void sltPerformRefreshMachine();
332
333 /** Handles call to show machine in File Manager. */
334 void sltShowMachineInFileManager();
335
336 /** Handles call to create machine shortcut. */
337 void sltPerformCreateMachineShortcut();
338
339 /** Handles call to sort group. */
340 void sltPerformGroupSorting();
341
342 /** Handles call to toggle machine search widget visibility to be @a fVisible. */
343 void sltPerformMachineSearchWidgetVisibilityToggling(bool fVisible);
344
345 /** Handles call to show help viewer. */
346 void sltPerformShowHelpBrowser();
347
348 /** Handles signals that are emitted when an ext. pack un/installed. */
349 void sltExtensionPackInstalledUninstalled(const QString &strName);
350 /** @} */
351
352private:
353
354 /** @name Prepare/Cleanup cascade.
355 * @{ */
356 /** Prepares window. */
357 void prepare();
358 /** Prepares icon. */
359 void prepareIcon();
360 /** Prepares menu-bar. */
361 void prepareMenuBar();
362 /** Prepares status-bar. */
363 void prepareStatusBar();
364 /** Prepares toolbar. */
365 void prepareToolbar();
366 /** Prepares widgets. */
367 void prepareWidgets();
368 /** Prepares connections. */
369 void prepareConnections();
370 /** Loads settings. */
371 void loadSettings();
372
373 /** Cleanups connections. */
374 void cleanupConnections();
375 /** Cleanups widgets. */
376 void cleanupWidgets();
377 /** Cleanups menu-bar. */
378 void cleanupMenuBar();
379 /** Cleanups window. */
380 void cleanup();
381 /** @} */
382
383 /** @name Common stuff.
384 * @{ */
385 /** Returns current-item. */
386 UIVirtualMachineItem *currentItem() const;
387 /** Returns a list of current-items. */
388 QList<UIVirtualMachineItem*> currentItems() const;
389
390 /** Returns whether group saving is in progress. */
391 bool isGroupSavingInProgress() const;
392 /** Returns whether all items of one group is selected. */
393 bool isAllItemsOfOneGroupSelected() const;
394 /** Returns whether single group is selected. */
395 bool isSingleGroupSelected() const;
396 /** Returns whether single local group is selected. */
397 bool isSingleLocalGroupSelected() const;
398 /** Returns whether single cloud provider group is selected. */
399 bool isSingleCloudProviderGroupSelected() const;
400 /** Returns whether single cloud profile group is selected. */
401 bool isSingleCloudProfileGroupSelected() const;
402
403 /** Returns whether at least one cloud profile currently being updated. */
404 bool isCloudProfileUpdateInProgress() const;
405
406 /** Checks if @a comUnattended has any errors.
407 * If so shows an error notification and returns false, else returns true. */
408 bool checkUnattendedInstallError(const CUnattended &comUnattended) const;
409 /** @} */
410
411 /** @name Various VM helpers.
412 * @{ */
413 /** Opens add machine dialog specifying initial name with @a strFileName. */
414 void openAddMachineDialog(const QString &strFileName = QString());
415 /** Opens new machine dialog specifying initial name with @a strFileName. */
416 void openNewMachineWizard(const QString &strISOFilePath = QString());
417
418 /** Opens Import Appliance wizard.
419 * @param strFileName can bring the name of file to import appliance from. */
420 void openImportApplianceWizard(const QString &strFileName = QString());
421
422 /** Launches certain @a comMachine in specified @a enmLaunchMode. */
423 static void launchMachine(CMachine &comMachine, UILaunchMode enmLaunchMode = UILaunchMode_Default);
424 /** Launches certain @a comMachine. */
425 static void launchMachine(CCloudMachine &comMachine);
426
427 /** Creates an unattended installer and uses it to install guest os to newly created vm. */
428 void startUnattendedInstall(const CUnattended &comUnattended, bool fStartHeadless, const QString &strMachineId);
429
430 /** Launches or shows virtual machines represented by passed @a items in corresponding @a enmLaunchMode (for launch). */
431 void performStartOrShowVirtualMachines(const QList<UIVirtualMachineItem*> &items, UILaunchMode enmLaunchMode);
432
433#ifndef VBOX_WS_WIN
434 /** Parses serialized @a strArguments string according to shell rules. */
435 QStringList parseShellArguments(const QString &strArguments);
436#endif
437 /** @} */
438
439 /** @name Action update stuff.
440 * @{ */
441 /** Updates 'Group' menu. */
442 void updateMenuGroup(QMenu *pMenu);
443 /** Updates 'Machine' menu. */
444 void updateMenuMachine(QMenu *pMenu);
445 /** Updates 'Group' : 'Move to Group' menu. */
446 void updateMenuGroupMoveToGroup(QMenu *pMenu);
447 /** Updates 'Group' : 'Console' menu. */
448 void updateMenuGroupConsole(QMenu *pMenu);
449 /** Updates 'Group' : 'Close' menu. */
450 void updateMenuGroupClose(QMenu *pMenu);
451 /** Updates 'Machine' : 'Move to Group' menu. */
452 void updateMenuMachineMoveToGroup(QMenu *pMenu);
453 /** Updates 'Machine' : 'Console' menu. */
454 void updateMenuMachineConsole(QMenu *pMenu);
455 /** Updates 'Machine' : 'Close' menu. */
456 void updateMenuMachineClose(QMenu *pMenu);
457
458 /** Performs update of actions visibility. */
459 void updateActionsVisibility();
460 /** Performs update of actions appearance. */
461 void updateActionsAppearance();
462
463 /** Returns whether the action with @a iActionIndex is enabled.
464 * @param items used to calculate verdict about should the action be enabled. */
465 bool isActionEnabled(int iActionIndex, const QList<UIVirtualMachineItem*> &items);
466
467 /** Returns whether all passed @a items are local. */
468 static bool isItemsLocal(const QList<UIVirtualMachineItem*> &items);
469 /** Returns whether all passed @a items are cloud. */
470 static bool isItemsCloud(const QList<UIVirtualMachineItem*> &items);
471 /** Returns whether all passed @a items are powered off. */
472 static bool isItemsPoweredOff(const QList<UIVirtualMachineItem*> &items);
473 /** Returns whether at least one of passed @a items is able to shutdown. */
474 static bool isAtLeastOneItemAbleToShutdown(const QList<UIVirtualMachineItem*> &items);
475 /** Returns whether at least one of passed @a items supports shortcut creation. */
476 static bool isAtLeastOneItemSupportsShortcuts(const QList<UIVirtualMachineItem*> &items);
477 /** Returns whether at least one of passed @a items is accessible. */
478 static bool isAtLeastOneItemAccessible(const QList<UIVirtualMachineItem*> &items);
479 /** Returns whether at least one of passed @a items is inaccessible. */
480 static bool isAtLeastOneItemInaccessible(const QList<UIVirtualMachineItem*> &items);
481 /** Returns whether at least one of passed @a items is removable. */
482 static bool isAtLeastOneItemRemovable(const QList<UIVirtualMachineItem*> &items);
483 /** Returns whether at least one of passed @a items can be started. */
484 static bool isAtLeastOneItemCanBeStarted(const QList<UIVirtualMachineItem*> &items);
485 /** Returns whether at least one of passed @a items can be shown. */
486 static bool isAtLeastOneItemCanBeShown(const QList<UIVirtualMachineItem*> &items);
487 /** Returns whether at least one of passed @a items can be started or shown. */
488 static bool isAtLeastOneItemCanBeStartedOrShown(const QList<UIVirtualMachineItem*> &items);
489 /** Returns whether at least one of passed @a items can be discarded. */
490 static bool isAtLeastOneItemDiscardable(const QList<UIVirtualMachineItem*> &items);
491 /** Returns whether at least one of passed @a items is started. */
492 static bool isAtLeastOneItemStarted(const QList<UIVirtualMachineItem*> &items);
493 /** Returns whether at least one of passed @a items is running. */
494 static bool isAtLeastOneItemRunning(const QList<UIVirtualMachineItem*> &items);
495 /** Returns whether at least one of passed @a items is detachable. */
496 static bool isAtLeastOneItemDetachable(const QList<UIVirtualMachineItem*> &items);
497
498#ifdef VBOX_WS_NIX
499 /** Tries to guess default X11 terminal emulator.
500 * @returns Data packed into Qt pair of QString(s),
501 * which is `name` and `--execute argument`. */
502 static QPair<QString, QString> defaultTerminalData();
503#endif
504 /** @} */
505
506 /** Holds the static instance. */
507 static UIVirtualBoxManager *s_pInstance;
508
509 /** Holds whether the dialog is polished. */
510 bool m_fPolished : 1;
511 /** Holds whether first medium-enumeration handled. */
512 bool m_fFirstMediumEnumerationHandled : 1;
513
514 /** Holds the action-pool instance. */
515 UIActionPool *m_pActionPool;
516 /** Holds the map of menu update-handlers. */
517 QMap<int, MenuUpdateHandler> m_menuUpdateHandlers;
518
519 /** Holds the map of various global managers. */
520 QMap<UIToolType, QIManagerDialog*> m_managers;
521
522 /** Holds the map of various settings dialogs. */
523 QMap<UIAdvancedSettingsDialog::DialogType, UIAdvancedSettingsDialog*> m_settings;
524
525 /** Holds the cloud settings dialog instance. */
526 UISafePointerCloudMachineSettingsDialog m_pCloudSettings;
527
528 /** Holds the map of various wizards. */
529 QMap<WizardType, UINativeWizard*> m_wizards;
530
531 /** Holds the central-widget instance. */
532 UIVirtualBoxManagerWidget *m_pWidget;
533
534 /** Holds the geometry save timer ID. */
535 int m_iGeometrySaveTimerId;
536
537 /** Holds the ISO file path used by new VM wizard. */
538 QString m_strISOFilePath;
539
540 /** Holds whether snapshot clone should be done by clone VM wizard. */
541 bool m_fSnapshotCloneByDefault;
542
543 /** Holds whether OCI importing should be started by default. */
544 bool m_fImportFromOCI;
545 /** Holds the file-name used by import wizard. */
546 QString m_strFileName;
547
548 /** Holds whether OCI exporting should be started by default. */
549 bool m_fExportToOCI;
550 /** Holds the list of VMs used by export wizard. */
551 QStringList m_names;
552
553 /** Holds the ID of medium used by clone VD wizard. */
554 QUuid m_uMediumId;
555};
556
557#define gpManager UIVirtualBoxManager::instance()
558
559#endif /* !FEQT_INCLUDED_SRC_manager_UIVirtualBoxManager_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