VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h@ 104158

Last change on this file since 104158 was 103803, checked in by vboxsync, 9 months ago

FE/Qt. bugref:10618. Splitting COMEnums.h file into individual enum header files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.1 KB
Line 
1/* $Id: UIMediumManager.h 103803 2024-03-12 11:15:18Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMediumManager 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_medium_UIMediumManager_h
29#define FEQT_INCLUDED_SRC_medium_UIMediumManager_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QUuid>
36
37/* GUI includes: */
38#include "QIManagerDialog.h"
39#include "QIWithRetranslateUI.h"
40#include "UIMediumDefs.h"
41
42/* COM includes: */
43#include "KMachineState.h"
44
45/* Forward declarations: */
46class QAbstractButton;
47class QLabel;
48class QProgressBar;
49class QTabWidget;
50class QTreeWidgetItem;
51class QIDialogButtonBox;
52class QILabel;
53class QITreeWidget;
54class UIActionPool;
55class UIMedium;
56class UIMediumDetailsWidget;
57class UIMediumItem;
58class UIMediumSearchWidget;
59class QIToolBar;
60
61
62/** Functor interface allowing to check if passed UIMediumItem is suitable. */
63class CheckIfSuitableBy
64{
65public:
66
67 /** Destructs functor. */
68 virtual ~CheckIfSuitableBy() { /* Makes MSC happy. */ }
69
70 /** Determines whether passed @a pItem is suitable. */
71 virtual bool isItSuitable(UIMediumItem *pItem) const = 0;
72};
73
74
75/** Medium manager progress-bar.
76 * Reflects medium-enumeration progress, stays hidden otherwise. */
77class UIEnumerationProgressBar : public QWidget
78{
79 Q_OBJECT;
80
81public:
82
83 /** Constructor on the basis of passed @a pParent. */
84 UIEnumerationProgressBar(QWidget *pParent = 0);
85
86 /** Defines progress-bar label-text. */
87 void setText(const QString &strText);
88
89 /** Returns progress-bar current-value. */
90 int value() const;
91 /** Defines progress-bar current-value. */
92 void setValue(int iValue);
93 /** Defines progress-bar maximum-value. */
94 void setMaximum(int iValue);
95
96private:
97
98 /** Prepares progress-bar content. */
99 void prepare();
100
101 /** Progress-bar label. */
102 QLabel *m_pLabel;
103 /** Progress-bar itself. */
104 QProgressBar *m_pProgressBar;
105};
106
107
108/** QWidget extension providing GUI with the pane to control media related functionality. */
109class UIMediumManagerWidget : public QIWithRetranslateUI<QWidget>
110{
111 Q_OBJECT;
112
113 /** Item action types. */
114 enum Action { Action_Add, Action_Edit, Action_Copy, Action_Remove, Action_Release };
115
116signals:
117
118 /** Notifies listeners about creation procedure was requested. */
119 void sigCreateMedium();
120 /** Notifies listeners about copy procedure was requested for medium with specified @a uMediumId. */
121 void sigCopyMedium(const QUuid &uMediumId);
122
123 /** Notifies listeners about medium details-widget @a fVisible. */
124 void sigMediumDetailsVisibilityChanged(bool fVisible);
125 /** Notifies listeners about accept is @a fAllowed. */
126 void sigAcceptAllowed(bool fAllowed);
127 /** Notifies listeners about reject is @a fAllowed. */
128 void sigRejectAllowed(bool fAllowed);
129
130public:
131
132 /** Constructs Virtual Media Manager widget.
133 * @param enmEmbedding Brings the type of widget embedding.
134 * @param pActionPool Brings the action-pool reference.
135 * @param fShowToolbar Brings whether we should create/show toolbar. */
136 UIMediumManagerWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool, bool fShowToolbar = true, QWidget *pParent = 0);
137
138 /** Returns the menu. */
139 QMenu *menu() const;
140
141#ifdef VBOX_WS_MAC
142 /** Returns the toolbar. */
143 QIToolBar *toolbar() const { return m_pToolBar; }
144#endif
145
146 /** Defines @a pProgressBar reference. */
147 void setProgressBar(UIEnumerationProgressBar *pProgressBar);
148
149protected:
150
151 /** @name Event-handling stuff.
152 * @{ */
153 /** Handles translation event. */
154 virtual void retranslateUi() RT_OVERRIDE;
155 /** @} */
156
157public slots:
158
159 /** @name Details-widget stuff.
160 * @{ */
161 /** Handles command to reset medium details changes. */
162 void sltResetMediumDetailsChanges();
163 /** Handles command to apply medium details changes. */
164 void sltApplyMediumDetailsChanges();
165 /** @} */
166
167private slots:
168
169 /** @name Medium operation stuff.
170 * @{ */
171 /** Handles UICommon::sigMediumCreated signal. */
172 void sltHandleMediumCreated(const QUuid &uMediumID);
173 /** Handles UICommon::sigMediumDeleted signal. */
174 void sltHandleMediumDeleted(const QUuid &uMediumID);
175 /** @} */
176
177 /** @name Medium enumeration stuff.
178 * @{ */
179 /** Handles UICommon::sigMediumEnumerationStarted signal. */
180 void sltHandleMediumEnumerationStart();
181 /** Handles UICommon::sigMediumEnumerated signal. */
182 void sltHandleMediumEnumerated(const QUuid &uMediumID);
183 /** Handles UICommon::sigMediumEnumerationFinished signal. */
184 void sltHandleMediumEnumerationFinish();
185 void sltHandleMachineStateChange(const QUuid &uId, const KMachineState state);
186 /** @} */
187
188 /** @name Menu/action stuff.
189 * @{ */
190 /** Handles command to add medium. */
191 void sltAddMedium();
192 /** Handles command to create medium. */
193 void sltCreateMedium();
194 /** Handles command to copy medium. */
195 void sltCopyMedium();
196 /** Handles command to move medium. */
197 void sltMoveMedium();
198 /** Handles command to remove medium. */
199 void sltRemoveMedium();
200 /** Handles command to release medium. */
201 void sltReleaseMedium();
202 /** Removes all inaccessible media. */
203 void sltClear();
204 /** Handles command to make medium details @a fVisible. */
205 void sltToggleMediumDetailsVisibility(bool fVisible);
206 /** Handles command to make medium search pane @a fVisible. */
207 void sltToggleMediumSearchVisibility(bool fVisible);
208 /** Handles command to refresh medium. */
209 void sltRefreshAll();
210 /** @} */
211
212 /** @name Menu/action handler stuff.
213 * @{ */
214 /** Handles medium move progress finished signal. */
215 void sltHandleMoveProgressFinished();
216 /** Handles medium resize progress finished signal. */
217 void sltHandleResizeProgressFinished();
218 /** @} */
219
220 /** @name Tab-widget stuff.
221 * @{ */
222 /** Handles tab change case. */
223 void sltHandleCurrentTabChanged();
224 /** Handles item change case. */
225 void sltHandleCurrentItemChanged();
226 /** Handles item context-menu-call case. */
227 void sltHandleContextMenuRequest(const QPoint &position);
228 /** @} */
229
230 /** @name Tree-widget stuff.
231 * @{ */
232 /** Adjusts tree-widgets according content. */
233 void sltPerformTablesAdjustment();
234 /** @} */
235
236 /** @name Medium search stuff.
237 * @{ */
238 /** Adjusts tree-widgets according content. */
239 void sltHandlePerformSearch();
240 /** @} */
241
242 /** @name Medium search stuff.
243 * @{ */
244 /** Handles command to detach COM stuff. */
245 void sltDetachCOM();
246 /** @} */
247
248private:
249
250 /** @name Prepare/cleanup cascade.
251 * @{ */
252 /** Prepares all. */
253 void prepare();
254 /** Prepares connections. */
255 void prepareConnections();
256 /** Prepares actions. */
257 void prepareActions();
258 /** Prepares widgets. */
259 void prepareWidgets();
260 /** Prepares toolbar. */
261 void prepareToolBar();
262 /** Prepares tab-widget. */
263 void prepareTabWidget();
264 /** Prepares tab-widget's tab. */
265 void prepareTab(UIMediumDeviceType type);
266 /** Prepares tab-widget's tree-widget. */
267 void prepareTreeWidget(UIMediumDeviceType type, int iColumns);
268 /** Prepares details-widget. */
269 void prepareDetailsWidget();
270 /** Prepares search-widget. */
271 void prepareSearchWidget();
272 /** Load settings: */
273 void loadSettings();
274
275 /** Repopulates tree-widgets content. */
276 void repopulateTreeWidgets();
277
278 /** Updates details according latest changes in current item of passed @a type. */
279 void refetchCurrentMediumItem(UIMediumDeviceType type);
280 /** Updates details according latest changes in current item of chosen type. */
281 void refetchCurrentChosenMediumItem();
282 /** Updates details according latest changes in all current items. */
283 void refetchCurrentMediumItems();
284
285 /** Updates actions according currently chosen item. */
286 void updateActions();
287 /** Updates action icons according currently chosen tab. */
288 void updateActionIcons();
289 /** Updates tab icons according last @a action happened with @a pItem. */
290 void updateTabIcons(UIMediumItem *pItem, Action action);
291 /** @} */
292
293 /** @name Widget operation stuff.
294 * @{ */
295 /** Creates UIMediumItem for corresponding @a medium. */
296 UIMediumItem *createMediumItem(const UIMedium &medium);
297 /** Creates UIMediumItemHD for corresponding @a medium. */
298 UIMediumItem *createHardDiskItem(const UIMedium &medium);
299 /** Updates UIMediumItem for corresponding @a medium. */
300 void updateMediumItem(const UIMedium &medium);
301 /** Deletes UIMediumItem for corresponding @a uMediumID. */
302 void deleteMediumItem(const QUuid &uMediumID);
303
304 /** Returns tab for passed medium @a type. */
305 QWidget *tab(UIMediumDeviceType type) const;
306 /** Returns tree-widget for passed medium @a type. */
307 QITreeWidget *treeWidget(UIMediumDeviceType type) const;
308 /** Returns item for passed medium @a type. */
309 UIMediumItem *mediumItem(UIMediumDeviceType type) const;
310
311 /** Returns medium type for passed @a pTreeWidget. */
312 UIMediumDeviceType mediumType(QITreeWidget *pTreeWidget) const;
313
314 /** Returns current medium type. */
315 UIMediumDeviceType currentMediumType() const;
316 /** Returns current tree-widget. */
317 QITreeWidget *currentTreeWidget() const;
318 /** Returns current item. */
319 UIMediumItem *currentMediumItem() const;
320
321 /** Defines current item for passed @a pTreeWidget as @a pItem. */
322 void setCurrentItem(QITreeWidget *pTreeWidget, QTreeWidgetItem *pItem);
323
324 void enableClearAction();
325 /** @} */
326
327 /** @name Search stuff.
328 * @{ */
329 /** Calls the UIMediumSearchWidget::search(..). */
330 void performSearch(bool fSelectNext);
331 /** @} */
332
333 /** @name Helper stuff.
334 * @{ */
335 /** Returns tab index for passed UIMediumDeviceType. */
336 static int tabIndex(UIMediumDeviceType type);
337
338 /** Performs search for the @a pTree child which corresponds to the @a condition but not @a pException. */
339 static UIMediumItem *searchItem(QITreeWidget *pTree,
340 const CheckIfSuitableBy &condition,
341 CheckIfSuitableBy *pException = 0);
342 /** Performs search for the @a pParentItem child which corresponds to the @a condition but not @a pException. */
343 static UIMediumItem *searchItem(QTreeWidgetItem *pParentItem,
344 const CheckIfSuitableBy &condition,
345 CheckIfSuitableBy *pException = 0);
346
347
348 /** Checks if @a action can be used for @a pItem. */
349 static bool checkMediumFor(UIMediumItem *pItem, Action action);
350
351 /** Casts passed QTreeWidgetItem @a pItem to UIMediumItem if possible. */
352 static UIMediumItem *toMediumItem(QTreeWidgetItem *pItem);
353 /** @} */
354
355 /** @name General variables.
356 * @{ */
357 /** Holds the widget embedding type. */
358 const EmbedTo m_enmEmbedding;
359 /** Holds the action-pool reference. */
360 UIActionPool *m_pActionPool;
361 /** Holds whether we should create/show toolbar. */
362 const bool m_fShowToolbar;
363
364 /** Holds whether Virtual Media Manager should preserve current item change. */
365 bool m_fPreventChangeCurrentItem;
366 /** @} */
367
368 /** @name Tab-widget variables.
369 * @{ */
370 /** Holds the tab-widget instance. */
371 QTabWidget *m_pTabWidget;
372 /** Holds the tab-widget tab-count. */
373 const int m_iTabCount;
374 /** Holds the map of tree-widget instances. */
375 QMap<int, QITreeWidget*> m_trees;
376 /** Holds whether hard-drive tab-widget have inaccessible item. */
377 bool m_fInaccessibleHD;
378 /** Holds whether optical-disk tab-widget have inaccessible item. */
379 bool m_fInaccessibleCD;
380 /** Holds whether floppy-disk tab-widget have inaccessible item. */
381 bool m_fInaccessibleFD;
382 /** Holds cached hard-drive tab-widget icon. */
383 const QIcon m_iconHD;
384 /** Holds cached optical-disk tab-widget icon. */
385 const QIcon m_iconCD;
386 /** Holds cached floppy-disk tab-widget icon. */
387 const QIcon m_iconFD;
388 /** Holds current hard-drive tree-view item ID. */
389 QUuid m_uCurrentIdHD;
390 /** Holds current optical-disk tree-view item ID. */
391 QUuid m_uCurrentIdCD;
392 /** Holds current floppy-disk tree-view item ID. */
393 QUuid m_uCurrentIdFD;
394 /** @} */
395
396 /** @name Details-widget variables.
397 * @{ */
398 /** Holds the medium details-widget instance. */
399 UIMediumDetailsWidget *m_pDetailsWidget;
400 /** @} */
401
402 /** @name Toolbar and menu variables.
403 * @{ */
404 /** Holds the toolbar widget instance. */
405 QIToolBar *m_pToolBar;
406 /** @} */
407
408 /** @name Progress-bar variables.
409 * @{ */
410 /** Holds the progress-bar widget reference. */
411 UIEnumerationProgressBar *m_pProgressBar;
412 /** @} */
413
414 /** @name Search-widget variables.
415 * @{ */
416 /** Holds the medium details-widget instance. */
417 UIMediumSearchWidget *m_pSearchWidget;
418 /** @} */
419
420};
421
422
423/** QIManagerDialogFactory extension used as a factory for Virtual Media Manager dialog. */
424class UIMediumManagerFactory : public QIManagerDialogFactory
425{
426public:
427
428 /** Constructs Media Manager factory acquiring additional arguments.
429 * @param pActionPool Brings the action-pool reference. */
430 UIMediumManagerFactory(UIActionPool *pActionPool = 0);
431
432protected:
433
434 /** Creates derived @a pDialog instance.
435 * @param pCenterWidget Brings the widget reference to center according to. */
436 virtual void create(QIManagerDialog *&pDialog, QWidget *pCenterWidget) RT_OVERRIDE;
437
438 /** Holds the action-pool reference. */
439 UIActionPool *m_pActionPool;
440};
441
442
443/** QIManagerDialog extension providing GUI with the dialog to control media related functionality. */
444class UIMediumManager : public QIWithRetranslateUI<QIManagerDialog>
445{
446 Q_OBJECT;
447
448signals:
449
450 /** Notifies listeners about data change rejected and should be reseted. */
451 void sigDataChangeRejected();
452 /** Notifies listeners about data change accepted and should be applied. */
453 void sigDataChangeAccepted();
454
455private slots:
456
457 /** @name Button-box stuff.
458 * @{ */
459 /** Handles button-box button click. */
460 void sltHandleButtonBoxClick(QAbstractButton *pButton);
461 /** @} */
462
463private:
464
465 /** Constructs Medium Manager dialog.
466 * @param pCenterWidget Brings the widget reference to center according to.
467 * @param pActionPool Brings the action-pool reference. */
468 UIMediumManager(QWidget *pCenterWidget, UIActionPool *pActionPool);
469
470 /** @name Event-handling stuff.
471 * @{ */
472 /** Handles translation event. */
473 virtual void retranslateUi() RT_OVERRIDE;
474 /** @} */
475
476 /** @name Prepare/cleanup cascade.
477 * @{ */
478 /** Configures all. */
479 virtual void configure() RT_OVERRIDE;
480 /** Configures central-widget. */
481 virtual void configureCentralWidget() RT_OVERRIDE;
482 /** Configures button-box. */
483 virtual void configureButtonBox() RT_OVERRIDE;
484 /** Perform final preparations. */
485 virtual void finalize() RT_OVERRIDE;
486 /** @} */
487
488 /** @name Widget stuff.
489 * @{ */
490 /** Returns the widget. */
491 virtual UIMediumManagerWidget *widget() RT_OVERRIDE;
492 /** @} */
493
494 /** @name Action related variables.
495 * @{ */
496 /** Holds the action-pool reference. */
497 UIActionPool *m_pActionPool;
498 /** @} */
499
500 /** @name Progress-bar variables.
501 * @{ */
502 /** Holds the progress-bar widget instance. */
503 UIEnumerationProgressBar *m_pProgressBar;
504 /** @} */
505
506 /** Allow factory access to private/protected members: */
507 friend class UIMediumManagerFactory;
508};
509
510#endif /* !FEQT_INCLUDED_SRC_medium_UIMediumManager_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