UIMediumManager.cpp revision 47d888c3986ffa5364798290b450b78e5a621e90
/* $Id$ */
/** @file
* VBox Qt GUI - UIMediumManager class implementation.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
# include "precomp.h"
#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
/* Qt includes: */
#include <QLabel>
#include <QProgressBar>
#include <QMenuBar>
#include <QHeaderView>
#include <QPushButton>
/* GUI includes: */
#include "VBoxGlobal.h"
#include "UIMediumManager.h"
#include "UIWizardCloneVD.h"
#include "UIMessageCenter.h"
#include "UIToolBar.h"
#include "QILabel.h"
#include "UIIconPool.h"
#include "UIMediumTypeChangeDialog.h"
#include "UIMedium.h"
/* COM includes: */
#include "COMEnums.h"
#include "CMachine.h"
#include "CMediumFormat.h"
#include "CStorageController.h"
#include "CMediumAttachment.h"
# ifdef Q_WS_MAC
# include "UIWindowMenuManager.h"
# endif /* Q_WS_MAC */
#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
/** QTreeWidgetItem extension representing Medium Manager item. */
class UIMediumItem : public QTreeWidgetItem
{
public:
/** UIMediumItem type for rtti needs. */
/** Constructor for top-level item. */
{ refresh(); }
/** Constructor for child item. */
{ refresh(); }
/** Copy UIMedium wrapped by <i>this</i> item. */
virtual bool copy() = 0;
/** Modify UIMedium wrapped by <i>this</i> item. */
virtual bool modify() = 0;
/** Remove UIMedium wrapped by <i>this</i> item. */
virtual bool remove() = 0;
/** Release UIMedium wrapped by <i>this</i> item. */
virtual bool release()
{
/* Refresh: */
refreshAll();
/* Make sure medium was not released yet: */
return true;
/* Confirm release: */
return false;
/* Release: */
if (!releaseFrom(strMachineID))
return false;
/* True by default: */
return true;
}
/** Refresh item fully. */
void refreshAll()
{
refresh();
}
/** Returns UIMedium wrapped by <i>this</i> item. */
/** Defines UIMedium wrapped by <i>this</i> item. */
{
refresh();
}
/** Returns UIMediumType of the wrapped UIMedium. */
/** Returns KMediumState of the wrapped UIMedium. */
/** Returns QString <i>ID</i> of the wrapped UIMedium. */
/** Returns QString <i>location</i> of the wrapped UIMedium. */
/** Returns QString <i>hard-disk format</i> of the wrapped UIMedium. */
/** Returns QString <i>hard-disk type</i> of the wrapped UIMedium. */
/** Returns QString <i>storage details</i> of the wrapped UIMedium. */
/** Returns QString <i>tool-tip</i> of the wrapped UIMedium. */
/** Returns QString <i>usage</i> of the wrapped UIMedium. */
/** Returns whether wrapped UIMedium is used or not. */
/** Returns whether wrapped UIMedium is used in snapshots or not. */
/** Operator< reimplementation used for sorting purposes. */
bool operator<(const QTreeWidgetItem &other) const
{
}
protected:
/** Release UIMedium wrapped by <i>this</i> item from virtual @a machine. */
private:
/** Refresh item information such as icon, text and tool-tip. */
void refresh()
{
/* Fill-in columns: */
/* All columns get the same tooltip: */
for (int i = 0; i < treeWidget()->columnCount(); ++i)
setToolTip(i, strToolTip);
}
/** Release UIMedium wrapped by <i>this</i> item from virtual machine with @a strMachineID. */
{
/* Open session: */
return false;
/* Get machine: */
/* Prepare result: */
bool fSuccess = false;
/* Release medium from machine: */
if (releaseFrom(machine))
{
/* Save machine settings: */
else
fSuccess = true;
}
/* Close session: */
/* Return result: */
return fSuccess;
}
/** UIMedium wrapped by <i>this</i> item. */
};
/** UIMediumItem extension representing hard-disk item. */
class UIMediumItemHD : public UIMediumItem
{
public:
/** Constructor for top-level item. */
{}
/** Constructor for child item. */
{}
protected:
/** Copy UIMedium wrapped by <i>this</i> item. */
bool copy()
{
/* Show Clone VD wizard: */
/* Delete if still exists: */
if (pWizard)
delete pWizard;
/* True by default: */
return true;
}
/** Modify UIMedium wrapped by <i>this</i> item. */
bool modify()
{
/* False by default: */
bool fResult = false;
/* Show Modify VD dialog: */
{
/* Update medium-item: */
refreshAll();
/* Change to passed: */
fResult = true;
}
/* Delete if still exists: */
if (pDialog)
delete pDialog;
/* Return result: */
return fResult;
}
/** Remove UIMedium wrapped by <i>this</i> item. */
bool remove()
{
/* Confirm medium removal: */
return false;
/* Remember some of hard-disk attributes: */
/* Propose to remove medium storage: */
if (!maybeRemoveStorage())
return false;
/* Close hard-disk: */
{
return false;
}
/* Remove UIMedium finally: */
/* True by default: */
return true;
}
/** Release UIMedium wrapped by <i>this</i> item from virtual @a machine. */
{
/* Enumerate attachments: */
{
/* Skip non-hard-disks: */
continue;
/* Skip unrelated hard-disks: */
continue;
/* Remember controller: */
/* Try to detach device: */
{
/* Return failure: */
treeWidget());
return false;
}
/* Return success: */
return true;
}
/* False by default: */
return false;
}
private:
/** Proposes user to remove CMedium storage wrapped by <i>this</i> item. */
bool maybeRemoveStorage()
{
/* Remember some of hard-disk attributes: */
/* We don't want to try to delete inaccessible storage as it will most likely fail.
* Note that UIMessageCenter::confirmMediumRemoval() is aware of that and
* will give a corresponding hint. Therefore, once the code is changed below,
* the hint should be re-checked for validity. */
bool fDeleteStorage = false;
qulonglong uCapability = 0;
{
if (rc == AlertButton_Cancel)
return false;
}
/* If user wish to delete storage: */
if (fDeleteStorage)
{
/* Prepare delete storage progress: */
{
return false;
}
/* Show delete storage progress: */
":/progress_media_delete_90px.png", treeWidget());
{
return false;
}
}
/* True by default: */
return true;
}
};
/** UIMediumItem extension representing optical-disk item. */
class UIMediumItemCD : public UIMediumItem
{
public:
/** Constructor for top-level item. */
{}
protected:
/** Copy UIMedium wrapped by <i>this</i> item. */
bool copy()
{
AssertMsgFailedReturn(("That functionality in not supported!\n"), false);
}
/** Modify UIMedium wrapped by <i>this</i> item. */
bool modify()
{
AssertMsgFailedReturn(("That functionality in not supported!\n"), false);
}
/** Remove UIMedium wrapped by <i>this</i> item. */
bool remove()
{
/* Confirm medium removal: */
return false;
/* Remember some of optical-disk attributes: */
/* Close optical-disk: */
{
return false;
}
/* Remove UIMedium finally: */
/* True by default: */
return true;
}
/** Release UIMedium wrapped by <i>this</i> item from virtual @a machine. */
{
/* Enumerate attachments: */
{
/* Skip non-optical-disks: */
continue;
/* Skip unrelated optical-disks: */
continue;
/* Try to unmount device: */
machine.MountMedium(attachment.GetController(), attachment.GetPort(), attachment.GetDevice(), CMedium(), false /* force */);
{
/* Return failure: */
msgCenter().cannotRemountMedium(machine, medium(), false /* mount? */, false /* retry? */, treeWidget());
return false;
}
/* Return success: */
return true;
}
/* Return failure: */
return false;
}
};
/** UIMediumItem extension representing floppy-disk item. */
class UIMediumItemFD : public UIMediumItem
{
public:
/** Constructor for top-level item. */
{}
protected:
/** Copy UIMedium wrapped by <i>this</i> item. */
bool copy()
{
AssertMsgFailedReturn(("That functionality in not supported!\n"), false);
}
/** Modify UIMedium wrapped by <i>this</i> item. */
bool modify()
{
AssertMsgFailedReturn(("That functionality in not supported!\n"), false);
}
/** Remove UIMedium wrapped by <i>this</i> item. */
bool remove()
{
/* Confirm medium removal: */
return false;
/* Remember some of floppy-disk attributes: */
/* Close floppy-disk: */
{
return false;
}
/* Remove UIMedium finally: */
/* True by default: */
return true;
}
/** Release UIMedium wrapped by <i>this</i> item from virtual @a machine. */
{
/* Enumerate attachments: */
{
/* Skip non-floppy-disks: */
continue;
/* Skip unrelated floppy-disks: */
continue;
/* Try to unmount device: */
machine.MountMedium(attachment.GetController(), attachment.GetPort(), attachment.GetDevice(), CMedium(), false /* force */);
{
/* Return failure: */
msgCenter().cannotRemountMedium(machine, medium(), false /* mount? */, false /* retry? */, treeWidget());
return false;
}
/* Return success: */
return true;
}
/* Return failure: */
return false;
}
};
/** Functor allowing to check if passed UIMediumItem is suitable by @a strID. */
class CheckIfSuitableByID : public CheckIfSuitableBy
{
public:
/** Constructor accepting @a strID to compare with. */
private:
/** Determines whether passed UIMediumItem is suitable by @a strID. */
/** Holds the @a strID to compare to. */
};
/** Functor allowing to check if passed UIMediumItem is suitable by @a state. */
class CheckIfSuitableByState : public CheckIfSuitableBy
{
public:
/** Constructor accepting @a state to compare with. */
private:
/** Determines whether passed UIMediumItem is suitable by @a state. */
/** Holds the @a state to compare to. */
};
/** Medium manager progress-bar.
* Reflects medium-enumeration progress, stays hidden otherwise. */
class UIEnumerationProgressBar : public QWidget
{
public:
/** Constructor on the basis of passed @a pParent. */
{
/* Prepare: */
prepare();
}
/** Defines progress-bar label-text. */
/** Returns progress-bar current-value. */
/** Defines progress-bar current-value. */
/** Defines progress-bar maximum-value. */
private:
/** Prepares progress-bar content. */
void prepare()
{
/* Create layout: */
{
/* Configure layout: */
pLayout->setContentsMargins(0, 0, 0, 0);
/* Create label: */
/* Create progress-bar: */
m_pProgressBar = new QProgressBar;
{
/* Configure progress-bar: */
m_pProgressBar->setTextVisible(false);
}
/* Add widgets into layout: */
}
}
/** Progress-bar label. */
/** Progress-bar itself. */
};
/* static */
, m_fPreventChangeCurrentItem(false)
, m_fInaccessibleHD(false)
, m_fInaccessibleCD(false)
, m_fInaccessibleFD(false)
{
/* Prepare: */
prepare();
}
{
/* Cleanup: */
cleanup();
/* Cleanup instance: */
m_spInstance = 0;
}
/* static */
{
/* Create instance if not yet created: */
if (!m_spInstance)
/* Show instance: */
m_spInstance->show();
}
{
/* Search for corresponding medium: */
/* Ignore non-interesting mediums: */
return;
/* Ignore mediums (and their children) which are
* marked as hidden or attached to hidden machines only: */
return;
/* Create medium-item for corresponding medium: */
/* If medium-item change allowed and
* 1. medium-enumeration is not currently in progress or
* 2. if there is no currently medium-item selected
* we have to choose newly added medium-item as current one: */
&& ( !vboxGlobal().isMediumEnumerationInProgress()
}
{
/* Make sure corresponding medium-item deleted: */
}
{
/* Disable 'refresh' action: */
m_pActionRefresh->setEnabled(false);
/* Reset and show progress-bar: */
m_pProgressBar->setValue(0);
m_pProgressBar->show();
/* Reset inaccessibility flags: */
m_fInaccessibleFD = false;
/* Reset tab-widget icons: */
/* Repopulate tree-widgets content: */
/* Re-fetch all current medium-items: */
}
{
/* Search for corresponding medium: */
/* Ignore non-interesting mediums: */
return;
/* Ignore mediums (and their children) which are
* marked as hidden or attached to hidden machines only: */
return;
/* Update medium-item for corresponding medium: */
/* Advance progress-bar: */
}
{
/* Hide progress-bar: */
m_pProgressBar->hide();
/* Enable 'refresh' action: */
m_pActionRefresh->setEnabled(true);
/* Re-fetch all current medium-items: */
}
void UIMediumManager::sltCopyMedium()
{
/* Get current medium-item: */
/* Copy current medium-item: */
pMediumItem->copy();
}
void UIMediumManager::sltModifyMedium()
{
/* Get current medium-item: */
/* Modify current medium-item: */
/* Update HD information-panes: */
if (fResult)
}
void UIMediumManager::sltRemoveMedium()
{
/* Get current medium-item: */
/* Remove current medium-item: */
pMediumItem->remove();
}
void UIMediumManager::sltReleaseMedium()
{
/* Get current medium-item: */
/* Remove current medium-item: */
/* Refetch currently chosen medium-item: */
if (fResult)
}
void UIMediumManager::sltRefreshAll()
{
/* Start medium-enumeration: */
}
{
/* Get current tree-widget: */
/* If another tree-widget was focused before,
* move focus to current tree-widget: */
pTreeWidget->setFocus();
/* Re-fetch currently chosen medium-item: */
}
{
/* Get sender() tree-widget: */
/* Re-fetch current medium-item of required type: */
}
void UIMediumManager::sltHandleDoubleClick()
{
/* Skip for non-hard-drives: */
if (currentMediumType() != UIMediumType_HardDisk)
return;
/* Call for modify-action: */
}
{
/* Get current tree-widget / item: */
/* Skip further actions if item was not found: */
if (!pItem)
return;
/* Make sure that item is current one: */
/* Show item context menu: */
}
{
/* Get all the tree-widgets: */
/* Calculate deduction for every header: */
{
int iDeduction = 0;
deductions << iDeduction;
}
/* Adjust the table's first column: */
{
}
}
void UIMediumManager::prepare()
{
/* Prepare this: */
prepareThis();
/* Prepare actions: */
/* Prepare menu-bar: */
/* Prepare tool-bar: */
/* Prepare context-menu: */
/* Prepare tab-widget: */
/* Prepare tree-widgets: */
/* Prepare information-panes: */
/* Prepare button-box: */
/* Prepare progress-bar: */
/* Translate dialog: */
#ifdef Q_WS_MAC
/* Prepare Mac window-menu.
* Should go *after* translation! */
#endif /* Q_WS_MAC */
/* Center according pseudo-parent widget: */
/* Initialize information-panes: */
/* Start medium-enumeration (if necessary): */
/* Emulate medium-enumeration otherwise: */
else
{
/* Start medium-enumeration: */
/* Finish medium-enumeration (if necessary): */
if (!vboxGlobal().isMediumEnumerationInProgress())
}
}
void UIMediumManager::prepareThis()
{
/* Dialog should delete itself on 'close': */
/* And no need to count it as important for application.
* This way it will NOT be taken into account
* when other top-level windows will be closed: */
/* Apply window icons: */
":/diskimage_32px.png", ":/diskimage_16px.png"));
/* Apply UI decorations: */
/* Configure medium-processing connections: */
/* Configure medium-enumeration connections: */
this, SLOT(sltHandleMediumEnumerationStart()));
this, SLOT(sltHandleMediumEnumerationFinish()));
}
void UIMediumManager::prepareActions()
{
/* Create copy-action: */
m_pActionCopy = new QAction(this);
{
/* Configure copy-action: */
":/hd_copy_22px.png", ":/hd_copy_16px.png",
":/hd_copy_disabled_22px.png", ":/hd_copy_disabled_16px.png"));
}
/* Create modify-action: */
m_pActionModify = new QAction(this);
{
/* Configure modify-action: */
":/hd_modify_22px.png", ":/hd_modify_16px.png",
":/hd_modify_disabled_22px.png", ":/hd_modify_disabled_16px.png"));
}
/* Create remove-action: */
m_pActionRemove = new QAction(this);
{
/* Configure remove-action: */
":/hd_remove_22px.png", ":/hd_remove_16px.png",
":/hd_remove_disabled_22px.png", ":/hd_remove_disabled_16px.png"));
}
/* Create release-action: */
m_pActionRelease = new QAction(this);
{
/* Configure release-action: */
":/hd_release_22px.png", ":/hd_release_16px.png",
":/hd_release_disabled_22px.png", ":/hd_release_disabled_16px.png"));
}
/* Create refresh-action: */
m_pActionRefresh = new QAction(this);
{
/* Configure refresh-action: */
":/refresh_22px.png", ":/refresh_16px.png",
":/refresh_disabled_22px.png", ":/refresh_disabled_16px.png"));
}
}
void UIMediumManager::prepareMenuBar()
{
/* Create actions-menu for menu-bar: */
{
/* Configure menu-bar menu: */
}
}
void UIMediumManager::prepareToolBar()
{
/* Create tool-bar: */
m_pToolBar = new UIToolBar(this);
{
/* Configure tool-bar: */
/* Add tool-bar actions: */
/* Integrate tool-bar into dialog: */
/* Enable unified tool-bars on Mac OS X. Available on Qt >= 4.3: */
pMainLayout->setContentsMargins(0, 0, 0, 0);
#else /* MAC_LEOPARD_STYLE */
/* Add the tool-bar: */
#endif /* MAC_LEOPARD_STYLE */
}
}
void UIMediumManager::prepareContextMenu()
{
/* Create context-menu: */
m_pContextMenu = new QMenu(this);
{
/* Configure contex-menu: */
}
}
void UIMediumManager::prepareTabWidget()
{
/* Tab-widget created in .ui file. */
{
/* Configure tab-widget: */
}
}
void UIMediumManager::prepareTreeWidgets()
{
/* Prepare tree-widget HD: */
/* Prepare tree-widget CD: */
/* Prepare tree-widget FD: */
/* Focus current tree-widget: */
currentTreeWidget()->setFocus();
}
void UIMediumManager::prepareTreeWidgetHD()
{
/* HD tree-widget created in .ui file. */
{
/* Configure HD tree-widget: */
pTreeWidget->setSortingEnabled(true);
this, SLOT(sltHandleCurrentItemChanged()));
this, SLOT(sltHandleDoubleClick()));
}
}
void UIMediumManager::prepareTreeWidgetCD()
{
/* CD tree-widget created in .ui file. */
{
/* Configure CD tree-widget: */
pTreeWidget->setSortingEnabled(true);
this, SLOT(sltHandleCurrentItemChanged()));
this, SLOT(sltHandleDoubleClick()));
}
}
void UIMediumManager::prepareTreeWidgetFD()
{
/* FD tree-widget created in .ui file. */
{
/* Configure FD tree-widget: */
pTreeWidget->setSortingEnabled(true);
this, SLOT(sltHandleCurrentItemChanged()));
this, SLOT(sltHandleDoubleClick()));
}
}
{
/* Information-panes created in .ui file. */
{
/* Configure information-panes: */
pPane->setFullSizeSelection(true);
}
}
void UIMediumManager::prepareButtonBox()
{
/* Button-box created in .ui file. */
{
/* Configure button-box: */
}
}
void UIMediumManager::prepareProgressBar()
{
/* Create progress-bar: */
m_pProgressBar = new UIEnumerationProgressBar(this);
{
/* Configure progress-bar: */
m_pProgressBar->hide();
}
}
#ifdef Q_WS_MAC
void UIMediumManager::prepareMacWindowMenu()
{
/* Create window-menu for menu-bar: */
}
#endif /* Q_WS_MAC */
void UIMediumManager::repopulateTreeWidgets()
{
/* Remember current medium-items: */
/* Clear tree-widgets: */
pTreeWidgetHD->clear();
pTreeWidgetCD->clear();
pTreeWidgetFD->clear();
/* Create medium-items (do not change current one): */
m_fPreventChangeCurrentItem = true;
m_fPreventChangeCurrentItem = false;
/* Select first item as current one if nothing selected: */
if (!mediumItem(UIMediumType_HardDisk))
if (!mediumItem(UIMediumType_DVD))
if (!mediumItem(UIMediumType_Floppy))
}
{
/* Get corresponding medium-item: */
/* If medium-item set: */
if (pMediumItem)
{
/* Set the file for the proxy icon: */
/* Make sure current medium-item visible: */
}
/* Update actions: */
/* Update corresponding information-panes: */
}
{
}
{
}
void UIMediumManager::updateActions()
{
/* Get current medium-item: */
/* Calculate actions accessibility: */
bool fActionEnabledRemove = fNotInEnumeration && pMediumItem && checkMediumFor(pMediumItem, Action_Remove);
bool fActionEnabledRelease = fNotInEnumeration && pMediumItem && checkMediumFor(pMediumItem, Action_Release);
/* Apply actions accessibility: */
}
{
/* Make sure medium-item is valid: */
/* Prepare data for tab: */
int iTab = -1;
bool *pfInaccessible = 0;
switch (pMediumItem->mediumType())
{
case UIMediumType_HardDisk:
iTab = TabIndex_HD;
break;
case UIMediumType_DVD:
iTab = TabIndex_CD;
break;
case UIMediumType_Floppy:
iTab = TabIndex_FD;
break;
default:
AssertFailed();
}
switch (action)
{
case Action_Add:
{
/* Does it change the overall state? */
break; /* no */
*pfInaccessible = true;
break;
}
case Action_Edit:
case Action_Remove:
{
bool fCheckRest = false;
if (action == Action_Edit)
{
/* Does it change the overall state? */
break; /* no */
/* Is the given item in charge? */
*pfInaccessible = true; /* yes */
else
fCheckRest = true; /* no */
}
else
fCheckRest = true;
if (fCheckRest)
{
/* Find the first KMediumState_Inaccessible item to be in charge: */
UIMediumItem *pInaccessibleMediumItem = searchItem(pMediumItem->treeWidget(), lookForState, &ignoreID);
}
if (*pfInaccessible)
else
break;
}
}
}
{
/* Make sure type is valid: */
if (type == UIMediumType_Invalid)
type = currentMediumType();
/* Depending on required type: */
switch (type)
{
case UIMediumType_HardDisk: updateInformationPanesHD(); break;
case UIMediumType_DVD: updateInformationPanesCD(); break;
case UIMediumType_Floppy: updateInformationPanesFD(); break;
case UIMediumType_All:
break;
default: break;
}
}
{
/* Get current hard-drive medium-item: */
/* If current item is not set: */
if (!pCurrentItem)
{
/* Just clear information panes: */
m_pTypePane->clear();
m_pLocationPane->clear();
m_pFormatPane->clear();
m_pDetailsPane->clear();
m_pUsagePane->clear();
}
/* If current item is set: */
else
{
/* Acquire required details: */
}
}
{
/* Get current optical medium-item: */
/* If current item is not set: */
if (!pCurrentItem)
{
/* Just clear information panes: */
}
/* If current item is set: */
else
{
/* Update required details: */
}
}
{
/* Get current floppy medium-item: */
/* If current item is not set: */
if (!pCurrentItem)
{
/* Just clear information panes: */
}
/* If current item is set: */
else
{
/* Update required details: */
}
}
#ifdef Q_WS_MAC
void UIMediumManager::cleanupMacWindowMenu()
{
/* Destroy window-menu of menu-bar: */
}
#endif /* Q_WS_MAC */
void UIMediumManager::cleanup()
{
#ifdef Q_WS_MAC
/* Cleanup Mac window-menu: */
#endif /* Q_WS_MAC */
}
void UIMediumManager::retranslateUi()
{
/* Translate uic generated strings: */
/* Menu: */
/* Action names: */
/* Action tool-tips: */
m_pActionCopy->setToolTip(m_pActionCopy->text().remove('&') + QString(" (%1)").arg(m_pActionCopy->shortcut().toString()));
m_pActionModify->setToolTip(m_pActionModify->text().remove('&') + QString(" (%1)").arg(m_pActionModify->shortcut().toString()));
m_pActionRemove->setToolTip(m_pActionRemove->text().remove('&') + QString(" (%1)").arg(m_pActionRemove->shortcut().toString()));
m_pActionRelease->setToolTip(m_pActionRelease->text().remove('&') + QString(" (%1)").arg(m_pActionRelease->shortcut().toString()));
m_pActionRefresh->setToolTip(m_pActionRefresh->text().remove('&') + QString(" (%1)").arg(m_pActionRefresh->shortcut().toString()));
/* Action status-tips: */
m_pActionCopy->setStatusTip(QApplication::translate("VBoxMediaManagerDlg", "Copy an existing disk image file"));
m_pActionModify->setStatusTip(QApplication::translate("VBoxMediaManagerDlg", "Modify the attributes of the selected disk image file"));
m_pActionRemove->setStatusTip(QApplication::translate("VBoxMediaManagerDlg", "Remove the selected disk image file"));
m_pActionRelease->setStatusTip(QApplication::translate("VBoxMediaManagerDlg", "Release the selected disk image file by detaching it from the machines"));
m_pActionRefresh->setStatusTip(QApplication::translate("VBoxMediaManagerDlg", "Refresh the list of disk image files"));
/* Tool-bar: */
#ifdef Q_WS_MAC
# ifdef QT_MAC_USE_COCOA
/* There is a bug in Qt Cocoa which result in showing a "more arrow" when
the necessary size of the toolbar is increased. Also for some languages
the with doesn't match if the text increase. So manually adjust the size
after changing the text. */
# endif /* QT_MAC_USE_COCOA */
#endif /* Q_WS_MAC */
// TODO: Just rename translation context in .nls files!
/* Translations moved from VBoxMediaManagerDlg.ui file to keep old translation context: */
pTreeWidgetHD->headerItem()->setText(1, QApplication::translate("VBoxMediaManagerDlg", "Virtual Size"));
pTreeWidgetHD->headerItem()->setText(2, QApplication::translate("VBoxMediaManagerDlg", "Actual Size"));
/* Progress-bar: */
#ifdef Q_WS_MAC
/* Make sure that the widgets aren't jumping around
* while the progress-bar get visible. */
int h = m_pProgressBar->height();
#endif /* Q_WS_MAC */
/* Button-box: */
/* Full refresh if there is at least one item present: */
if (pTreeWidgetHD->topLevelItemCount() || pTreeWidgetCD->topLevelItemCount() || pTreeWidgetFD->topLevelItemCount())
}
{
/* Get medium type: */
/* Create medium-item: */
UIMediumItem *pMediumItem = 0;
switch (type)
{
/* Of hard-drive type: */
case UIMediumType_HardDisk:
{
{
m_strCurrentIdHD = QString();
}
break;
}
/* Of optical-image type: */
case UIMediumType_DVD:
{
LogRel2(("UIMediumManager: Optical medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
{
m_strCurrentIdCD = QString();
}
break;
}
/* Of floppy-image type: */
case UIMediumType_Floppy:
{
LogRel2(("UIMediumManager: Floppy medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
{
m_strCurrentIdFD = QString();
}
break;
}
}
/* Update tab-icons: */
/* Re-fetch medium-item if it is current one created: */
/* Return created medium-item: */
return pMediumItem;
}
{
/* Make sure passed medium is valid: */
/* Get corresponding tree-widget: */
/* Search for existing medium-item: */
/* If medium-item do not exists: */
if (!pMediumItem)
{
/* If medium have a parent: */
{
/* Try to find parent medium-item: */
/* If parent medium-item was not found: */
if (!pParentMediumItem)
{
/* Make sure corresponding parent medium is already cached! */
if (parentMedium.isNull())
AssertMsgFailed(("Parent medium with ID={%s} was not found!\n", medium.parentID().toAscii().constData()));
/* Try to create parent medium-item: */
else
}
/* If parent medium-item was found: */
if (pParentMediumItem)
{
LogRel2(("UIMediumManager: Child hard-drive medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
}
}
/* Else just create item as top-level one: */
if (!pMediumItem)
{
LogRel2(("UIMediumManager: Root hard-drive medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
}
}
/* Return created medium-item: */
return pMediumItem;
}
{
/* Get medium type: */
/* Search for existing medium-item, create if was not found: */
/* Update medium-item: */
LogRel2(("UIMediumManager: Medium-item with ID={%s} updated.\n", medium.id().toAscii().constData()));
/* Update tab-icons: */
/* Re-fetch medium-item if it is current one updated: */
}
{
/* Search for corresponding tree-widget: */
QTreeWidget *pTreeWidget = 0;
UIMediumItem *pMediumItem = 0;
{
/* Get iterated tree-widget: */
/* Search for existing medium-item: */
if (pMediumItem)
break;
}
/* Ignore medium-item (if it was not found): */
if (!pMediumItem)
return;
/* Update tab-icons: */
/* Delete medium-item: */
delete pMediumItem;
LogRel2(("UIMediumManager: Medium-item with ID={%s} deleted.\n", strMediumID.toAscii().constData()));
/* If there is no current medium-item now selected
* we have to choose first-available medium-item as current one: */
if (!pTreeWidget->currentItem())
}
{
/* Hard-drive tree-widget: */
/* Optical-image tree-widget: */
/* Floppy-image tree-widget: */
/* Invalid by default: */
}
{
/* Return current medium type: */
switch (mTabWidget->currentIndex())
{
case TabIndex_HD: return UIMediumType_HardDisk;
case TabIndex_CD: return UIMediumType_DVD;
case TabIndex_FD: return UIMediumType_Floppy;
}
/* Invalid by default: */
return UIMediumType_Invalid;
}
{
/* Return corresponding tree-widget for known medium types: */
switch (type)
{
case UIMediumType_HardDisk: return mTwHD;
case UIMediumType_DVD: return mTwCD;
case UIMediumType_Floppy: return mTwFD;
}
/* Null by default: */
return 0;
}
{
/* Return current tree-widget: */
return treeWidget(currentMediumType());
}
{
/* Get corresponding tree-widget: */
/* Return corresponding medium-item: */
}
{
/* Return current medium-item: */
return mediumItem(currentMediumType());
}
{
/* Make sure passed tree-widget is valid: */
/* Make passed item current for passed tree-widget: */
/* If non NULL item was passed: */
if (pItem)
{
/* Make sure it's also selected, and visible: */
pItem->setSelected(true);
}
/* Re-fetch currently chosen medium-item: */
}
/* static */
UIMediumItem* UIMediumManager::searchItem(QTreeWidget *pTreeWidget, const CheckIfSuitableBy &condition, CheckIfSuitableBy *pException)
{
/* Make sure argument is valid: */
if (!pTreeWidget)
return 0;
/* Return wrapper: */
}
/* static */
UIMediumItem* UIMediumManager::searchItem(QTreeWidgetItem *pParentItem, const CheckIfSuitableBy &condition, CheckIfSuitableBy *pException)
{
/* Make sure argument is valid: */
if (!pParentItem)
return 0;
/* Verify passed item if it is of 'medium' type too: */
return pMediumParentItem;
/* Iterate other all the children: */
return pRequiredMediumChildItem;
/* Null by default: */
return 0;
}
/* static */
{
/* Make sure passed ID is valid: */
AssertReturn(pItem, false);
switch (action)
{
case Action_Edit:
{
/* Edit means changing the description and alike; any media that is
* not being read to or written from can be altered in these terms. */
{
case KMediumState_NotCreated:
case KMediumState_LockedRead:
case KMediumState_LockedWrite:
return false;
default:
break;
}
return true;
}
case Action_Copy:
{
/* False for children: */
}
case Action_Modify:
{
/* False for children: */
}
case Action_Remove:
{
/* Removable if not attached to anything: */
}
case Action_Release:
{
/* Releasable if attached but not in snapshots: */
}
}
AssertFailedReturn(false);
}
/* static */
{
/* Cast passed QTreeWidgetItem to UIMediumItem if possible: */
}
/* static */
{
return strInfo;
}
/* static */
{
/* Iterate till the root: */
do
{
/* Ignore medium if its hidden
* or attached to hidden machines only: */
if (mediumIterator.isHidden())
return true;
/* Move iterator to parent: */
}
while (!mediumIterator.isNull());
/* False by default: */
return false;
}
#include "UIMediumManager.moc"