VirtualBox

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

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

FE/Qt. bugref:10622. Using new UITranslationEventListener in medium manager related classes.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use