UIMediumManager.h revision 4cac31995acb30108f8070f160cd9a820b8f50ac
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync/** @file
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync *
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * VBox frontends: Qt4 GUI ("VirtualBox"):
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * UIMediumManager class declaration
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync */
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync/*
cfeb51c88f60cb31c8862f0fa325d7d1c4d22f8avboxsync * Copyright (C) 2006-2013 Oracle Corporation
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync *
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * available from http://www.virtualbox.org. This file is free software;
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * you can redistribute it and/or modify it under the terms of the GNU
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * General Public License (GPL) as published by the Free Software
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync */
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync#ifndef __UIMediumManager_h__
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync#define __UIMediumManager_h__
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync/* GUI includes: */
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync#include "UIMediumManager.gen.h"
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync#include "QIWithRetranslateUI.h"
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync#include "QIMainDialog.h"
79a32911c902685a8fafa06c4b9fd7f277994d93vboxsync#include "UIMediumDefs.h"
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync/* COM includes: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync#include "COMEnums.h"
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync#include "CMachine.h"
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync#include "CVirtualBox.h"
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync/* Forward declarations: */
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsyncclass UIToolBar;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsyncclass UIMediumItem;
65ba0abe3ecfd47b318d49a3c37a9b48d1f6904evboxsyncclass UIEnumerationProgressBar;
79a32911c902685a8fafa06c4b9fd7f277994d93vboxsyncclass UIMedium;
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsync/** Functor interface allowing to check if passed UIMediumItem is suitable. */
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsyncclass CheckIfSuitableBy
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsync{
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsyncpublic:
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsync /** Determines whether passed UIMediumItem is suitable. */
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsync virtual bool isItSuitable(UIMediumItem *pItem) const = 0;
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsync};
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync/* Medium Manager Dialog: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsyncclass UIMediumManager : public QIWithRetranslateUI2<QIMainDialog>, public Ui::UIMediumManager
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync{
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync Q_OBJECT;
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Enumerators: */
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync enum TabIndex { HDTab = 0, CDTab, FDTab };
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync enum ItemAction { ItemAction_Added, ItemAction_Updated, ItemAction_Removed };
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync enum Action { Action_Edit, Action_Copy, Action_Modify, Action_Remove, Action_Release };
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Constructor/destructor: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync UIMediumManager(QWidget *pCenterWidget, bool fRefresh = true);
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync ~UIMediumManager();
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsyncpublic:
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Static API: Singleton stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync static UIMediumManager* instance();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync static void showModeless(QWidget *pCenterWidget, bool fRefresh = true);
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsyncpublic slots:
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Handler: Refresh stuff: */
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync void refreshAll();
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsyncprivate slots:
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Handlers: Medium-processing stuff: */
026a45b961439e27215ecef27f81bc115857609evboxsync void sltHandleMediumCreated(const QString &strMediumID);
b4e89d495c2988c10068923397d31fd27112b9ebvboxsync void sltHandleMediumDeleted(const QString &strMediumID);
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Handlers: Medium-enumeration stuff: */
0623012e80c8f7252d781d1f51cb6836afd4d3eevboxsync void sltHandleMediumEnumerationStart();
026a45b961439e27215ecef27f81bc115857609evboxsync void sltHandleMediumEnumerated(const QString &strMediumID);
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltHandleMediumEnumerationFinish();
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Handlers: Medium-modification stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltCopyMedium();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltModifyMedium();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltRemoveMedium();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltReleaseMedium();
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Handlers: Navigation stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltHandleCurrentTabChanged();
4cac31995acb30108f8070f160cd9a820b8f50acvboxsync void sltHandleCurrentItemChanged(QTreeWidgetItem *pItem);
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltHandleDoubleClick();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltHandleContextMenuCall(const QPoint &position);
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Handlers: Geometry stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltMakeRequestForTableAdjustment();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void sltPerformTablesAdjustment();
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsyncprivate:
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Helpers: Prepare stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepare();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareThis();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareActions();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareMenuBar();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareToolBar();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareContextMenu();
df32f009590cc83917fb1a9c38365de26109411bvboxsync void prepareTabWidget();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareTreeWidgets();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareTreeWidgetHD();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareTreeWidgetCD();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareTreeWidgetFD();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareInformationPanes();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareButtonBox();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareProgressBar();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync#ifdef Q_WS_MAC
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void prepareMacWindowMenu();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync#endif /* Q_WS_MAC */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync
19e4b59d75d82092624cb5440dd5dbe724b61d77vboxsync /** Repopulates tree-widgets content. */
19e4b59d75d82092624cb5440dd5dbe724b61d77vboxsync void repopulateTreeWidgets();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync /** Update actions according currently chosen medium-item. */
fd5860ffe98b17e6cadfc269b2266f95bce04af9vboxsync void updateActions();
e352a9803c8b6a6ffba3440c75acadabf47c8e0evboxsync /** Update tab icons according last @a action happened with @a pItem. */
e352a9803c8b6a6ffba3440c75acadabf47c8e0evboxsync void updateTabIcons(UIMediumItem *pItem, ItemAction action);
a1d5123f3ab0fbe5f030c0fc55a812e0807a566evboxsync /** Update information pane of passed medium @a type. */
a1d5123f3ab0fbe5f030c0fc55a812e0807a566evboxsync void updateInformationPanes(UIMediumType type = UIMediumType_Invalid);
a1d5123f3ab0fbe5f030c0fc55a812e0807a566evboxsync /** Update information pane for hard-drive tab. */
a1d5123f3ab0fbe5f030c0fc55a812e0807a566evboxsync void updateInformationPanesHD();
a1d5123f3ab0fbe5f030c0fc55a812e0807a566evboxsync /** Update information pane for optical-disk tab. */
a1d5123f3ab0fbe5f030c0fc55a812e0807a566evboxsync void updateInformationPanesCD();
a1d5123f3ab0fbe5f030c0fc55a812e0807a566evboxsync /** Update information pane for floppy-disk tab. */
a1d5123f3ab0fbe5f030c0fc55a812e0807a566evboxsync void updateInformationPanesFD();
fd5860ffe98b17e6cadfc269b2266f95bce04af9vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Helpers: Cleanup stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync#ifdef Q_WS_MAC
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void cleanupMacWindowMenu();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync#endif /* Q_WS_MAC */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void cleanup();
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Handler: Translation stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync void retranslateUi();
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
2a3ea815abf6290c6e17e81eb350e5c19a090c64vboxsync /** Creates UIMediumItem for corresponding UIMedium. */
2a3ea815abf6290c6e17e81eb350e5c19a090c64vboxsync void createMediumItem(const UIMedium &medium);
2a3ea815abf6290c6e17e81eb350e5c19a090c64vboxsync /** Updates UIMediumItem for corresponding UIMedium. */
2a3ea815abf6290c6e17e81eb350e5c19a090c64vboxsync void updateMediumItem(const UIMedium &medium);
2a3ea815abf6290c6e17e81eb350e5c19a090c64vboxsync
cfeb51c88f60cb31c8862f0fa325d7d1c4d22f8avboxsync /* Helpers: Medium-modification stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync bool releaseMediumFrom(const UIMedium &medium, const QString &strMachineId);
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync bool releaseHardDiskFrom(const UIMedium &medium, CMachine &machine);
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync bool releaseOpticalDiskFrom(const UIMedium &medium, CMachine &machine);
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync bool releaseFloppyDiskFrom(const UIMedium &medium, CMachine &machine);
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync /** Returns current medium type. */
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync UIMediumType currentMediumType() const;
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync /** Returns tree-widget for passed medium @a type. */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QTreeWidget* treeWidget(UIMediumType type) const;
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync /** Returns current tree-widget. */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QTreeWidget* currentTreeWidget() const;
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync /** Returns medium-item for passed medium @a type. */
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync UIMediumItem* mediumItem(UIMediumType type) const;
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync /** Returns current medium-item. */
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync UIMediumItem* currentMediumItem() const;
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync
4cac31995acb30108f8070f160cd9a820b8f50acvboxsync /** Defines <i>current-item</i> for passed @a pTreeWidget as @a pItem. */
4cac31995acb30108f8070f160cd9a820b8f50acvboxsync void setCurrentItem(QTreeWidget *pTreeWidget, QTreeWidgetItem *pItem);
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsync UIMediumItem* searchItem(QTreeWidget *pTree, const CheckIfSuitableBy &functor) const;
5a062c1c10e75283bed9bd16145610874ec5bacdvboxsync UIMediumItem* searchItem(QTreeWidgetItem *pParentItem, const CheckIfSuitableBy &functor) const;
cfeb51c88f60cb31c8862f0fa325d7d1c4d22f8avboxsync UIMediumItem* createHardDiskItem(QTreeWidget *pTree, const UIMedium &medium) const;
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
19e4b59d75d82092624cb5440dd5dbe724b61d77vboxsync /* Helper: Other stuff: */
cfeb51c88f60cb31c8862f0fa325d7d1c4d22f8avboxsync bool checkMediumFor(UIMediumItem *pItem, Action action);
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync /** Casts passed QTreeWidgetItem @a pItem to UIMediumItem if possible. */
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync static UIMediumItem* toMediumItem(QTreeWidgetItem *pItem);
07a690d662bd122b5e07b2c996990b4ef97f14f2vboxsync
cfeb51c88f60cb31c8862f0fa325d7d1c4d22f8avboxsync /* Static helper: Formatting stuff: */
cfeb51c88f60cb31c8862f0fa325d7d1c4d22f8avboxsync static QString formatPaneText(const QString &strText, bool fCompact = true, const QString &strElipsis = "middle");
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
cfeb51c88f60cb31c8862f0fa325d7d1c4d22f8avboxsync /* Static helper: Enumeration stuff: */
79a32911c902685a8fafa06c4b9fd7f277994d93vboxsync static bool isMediumAttachedToHiddenMachinesOnly(const UIMedium &medium);
cf575292da27c79a7de59f7ced500686a0838b38vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Variable: Singleton instance: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync static UIMediumManager *m_spInstance;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Variables: General stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync CVirtualBox m_vbox;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QWidget *m_pCenterWidget;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync bool m_fRefresh;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Variables: Tab-widget stuff: */
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync bool m_fInaccessibleHD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync bool m_fInaccessibleCD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync bool m_fInaccessibleFD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync const QIcon m_iconHD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync const QIcon m_iconCD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync const QIcon m_iconFD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QString m_strSelectedIdHD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QString m_strSelectedIdCD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QString m_strSelectedIdFD;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Variables: Menu & Toolbar stuff: */
65ba0abe3ecfd47b318d49a3c37a9b48d1f6904evboxsync UIToolBar *m_pToolBar;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QMenu *m_pContextMenu;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QMenu *m_pMenu;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QAction *m_pActionCopy;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QAction *m_pActionModify;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QAction *m_pActionRemove;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QAction *m_pActionRelease;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync QAction *m_pActionRefresh;
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync
26ab5559e05ae622734a4047cee975670da3b0e8vboxsync /* Variable: Progress-bar stuff: */
65ba0abe3ecfd47b318d49a3c37a9b48d1f6904evboxsync UIEnumerationProgressBar *m_pProgressBar;
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync};
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync
8230e6f6671b538d39c7ef6d8484cf516a983ef4vboxsync#endif /* __UIMediumManager_h__ */