VirtualBox

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

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

FE/Qt. bugref:10622. Using new UITranslationEventListener in the manager UI classes.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use