VBoxApplianceEditorWgt.cpp revision 8d4665a316d78d6587fd1c9da948f7aa37d0bfdd
/** @file
*
* VBox frontends: Qt4 GUI ("VirtualBox"):
* VBoxApplianceEditorWgt class implementation
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/* VBox includes */
#include "VBoxApplianceEditorWgt.h"
#include "VBoxGlobal.h"
#include "VBoxProblemReporter.h"
#include "VBoxOSTypeSelectorButton.h"
#include "VBoxLineTextEdit.h"
/* Qt includes */
#include <QItemDelegate>
#include <QSortFilterProxyModel>
#include <QHeaderView>
#include <QLineEdit>
#include <QTextEdit>
#include <QSpinBox>
#include <QComboBox>
////////////////////////////////////////////////////////////////////////////////
// ModelItem
/* This & the following derived classes represent the data items of a Virtual
System. All access/manipulation is done with the help of virtual functions
to keep the interface clean. ModelItem is able to handle tree structures
with a parent & several children's. */
, mParentItem (aParent)
{}
{
}
{
mChildItems << aChild;
}
{
}
{
if (mParentItem)
return 0;
}
int ModelItem::childCount() const
{
return mChildItems.count();
}
void ModelItem::putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues)
{
for (int i = 0; i < childCount(); ++i)
}
////////////////////////////////////////////////////////////////////////////////
// VirtualSystemItem
VirtualSystemItem::VirtualSystemItem (int aNumber, CVirtualSystemDescription aDesc, ModelItem *aParent)
{}
{
QVariant v;
if (aColumn == DescriptionSection &&
return v;
}
void VirtualSystemItem::putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues)
{
/* Resize the vectors */
/* Recursively fill the vectors */
/* Set all final values at once */
}
////////////////////////////////////////////////////////////////////////////////
// HardwareItem
const QString &aOrigValue,
const QString &aConfigValue,
const QString &aExtraConfigValue,
, mOrigValue (aOrigValue)
{}
void HardwareItem::putBack (QVector<BOOL>& aFinalStates, QVector<QString>& aFinalValues, QVector<QString>& aFinalExtraValues)
{
}
{
bool fDone = false;
switch (aRole)
{
case Qt::CheckStateRole:
{
if (aColumn == ConfigValueSection &&
{
fDone = true;
}
break;
}
default: break;
}
return fDone;
}
{
QVariant v;
switch (aRole)
{
case Qt::DisplayRole:
{
if (aColumn == DescriptionSection)
{
switch (mType)
{
case KVirtualSystemDescriptionType_ProductUrl: v = VBoxApplianceEditorWgt::tr ("Product-URL"); break;
case KVirtualSystemDescriptionType_Description: v = VBoxApplianceEditorWgt::tr ("Description"); break;
case KVirtualSystemDescriptionType_HardDiskControllerIDE: v = VBoxApplianceEditorWgt::tr ("Hard Disk Controller (IDE)"); break;
case KVirtualSystemDescriptionType_HardDiskControllerSATA: v = VBoxApplianceEditorWgt::tr ("Hard Disk Controller (SATA)"); break;
case KVirtualSystemDescriptionType_HardDiskControllerSCSI: v = VBoxApplianceEditorWgt::tr ("Hard Disk Controller (SCSI)"); break;
case KVirtualSystemDescriptionType_NetworkAdapter: v = VBoxApplianceEditorWgt::tr ("Network Adapter"); break;
case KVirtualSystemDescriptionType_USBController: v = VBoxApplianceEditorWgt::tr ("USB Controller"); break;
case KVirtualSystemDescriptionType_HardDiskImage: v = VBoxApplianceEditorWgt::tr ("Virtual Disk Image"); break;
}
}
else if (aColumn == OriginalValueSection)
v = mOrigValue;
else if (aColumn == ConfigValueSection)
{
switch (mType)
{
{
/* Shorten the big text if there is more than
* one line */
if (i > -1)
v = tmp; break;
}
case KVirtualSystemDescriptionType_OS: v = vboxGlobal().vmGuestOSTypeDescription (mConfigValue); break;
case KVirtualSystemDescriptionType_Memory: v = mConfigValue + " " + VBoxApplianceEditorWgt::tr ("MB"); break;
case KVirtualSystemDescriptionType_SoundCard: v = vboxGlobal().toString (static_cast<KAudioControllerType> (mConfigValue.toInt())); break;
case KVirtualSystemDescriptionType_NetworkAdapter: v = vboxGlobal().toString (static_cast<KNetworkAdapterType> (mConfigValue.toInt())); break;
default: v = mConfigValue; break;
}
}
break;
}
case Qt::ToolTipRole:
{
if (aColumn == ConfigValueSection)
{
if (!mOrigValue.isEmpty())
}
break;
}
case Qt::DecorationRole:
{
if (aColumn == DescriptionSection)
{
switch (mType)
{
default: break;
}
}
else if (aColumn == ConfigValueSection &&
{
}
break;
}
{
/* If the item is unchecked mark it with italic text. */
if (aColumn == ConfigValueSection &&
{
v = font;
}
break;
}
case Qt::ForegroundRole:
{
/* If the item is unchecked mark it with gray text. */
if (aColumn == ConfigValueSection &&
{
}
break;
}
case Qt::CheckStateRole:
{
if (aColumn == ConfigValueSection &&
v = mCheckState;
break;
}
}
return v;
}
{
if (aColumn == ConfigValueSection)
{
/* Some items are checkable */
if (mType == KVirtualSystemDescriptionType_Floppy ||
/* Some items are editable */
if ((mType == KVirtualSystemDescriptionType_Name ||
}
return flags;
}
QWidget * HardwareItem::createEditor (QWidget *aParent, const QStyleOptionViewItem & /* aOption */, const QModelIndex &aIndex) const
{
{
switch (mType)
{
{
/* Fill the background with the highlight color in the case
* the button hasn't a rectangle shape. This prevents the
* display of parts from the current text on the Mac. */
e->setAutoFillBackground (true);
editor = e;
break;
}
{
editor = e;
break;
}
{
editor = e;
break;
}
{
e->setRange (VBoxApplianceEditorWgt::minGuestCPUCount(), VBoxApplianceEditorWgt::maxGuestCPUCount());
editor = e;
break;
}
{
editor = e;
break;
}
{
editor = e;
break;
}
{
#ifdef VBOX_WITH_E1000
#endif /* VBOX_WITH_E1000 */
#ifdef VBOX_WITH_VIRTIO
#endif /* VBOX_WITH_VIRTIO */
editor = e;
break;
}
{
editor = e;
break;
}
{
/* disabled for now
VBoxFilePathSelectorWidget *e = new VBoxFilePathSelectorWidget (aParent);
e->setMode (VBoxFilePathSelectorWidget::Mode_File);
e->setResetEnabled (false);
*/
editor = e;
break;
}
default: break;
}
}
return editor;
}
{
bool fDone = false;
switch (mType)
{
{
{
e->setOSTypeId (mConfigValue);
fDone = true;
}
break;
}
{
{
int i = e->findData (mConfigValue);
if (i != -1)
e->setCurrentIndex (i);
fDone = true;
}
break;
}
{
{
fDone = true;
}
break;
}
{
{
e->setText (mConfigValue);
fDone = true;
}
break;
}
{
{
e->setText (mConfigValue);
fDone = true;
}
break;
}
{
{
if (i != -1)
e->setCurrentIndex (i);
fDone = true;
}
break;
}
{
/* disabled for now
if (VBoxFilePathSelectorWidget *e = qobject_cast<VBoxFilePathSelectorWidget*> (aEditor))
{
e->setPath (mConfigValue);
}
*/
{
e->setText (mConfigValue);
fDone = true;
}
break;
}
default: break;
}
return fDone;
}
bool HardwareItem::setModelData (QWidget *aEditor, QAbstractItemModel * /* aModel */, const QModelIndex & /* aIndex */)
{
bool fDone = false;
switch (mType)
{
{
{
mConfigValue = e->osTypeId();
fDone = true;
}
break;
}
{
{
fDone = true;
}
break;
}
{
{
fDone = true;
}
break;
}
{
{
mConfigValue = e->text();
fDone = true;
}
break;
}
{
{
mConfigValue = e->text();
fDone = true;
}
break;
}
{
{
fDone = true;
}
break;
}
{
/* disabled for now
if (VBoxFilePathSelectorWidget *e = qobject_cast<VBoxFilePathSelectorWidget*> (aEditor))
{
mConfigValue = e->path();
}
*/
{
mConfigValue = e->text();
fDone = true;
}
break;
}
default: break;
}
return fDone;
}
////////////////////////////////////////////////////////////////////////////////
// VirtualSystemModel
/* This class is a wrapper model for our ModelItem. It could be used with any
TreeView & forward mostly all calls to the methods of ModelItem. The
ModelItems itself are stored as internal pointers in the QModelIndex class. */
VirtualSystemModel::VirtualSystemModel (QVector<CVirtualSystemDescription>& aVSDs, QObject *aParent /* = NULL */)
{
{
{
/* We add the hard disk images in an second step, so save a
reference to them. */
if (types[i] == KVirtualSystemDescriptionType_HardDiskImage)
hdIndizies << i;
else
{
HardwareItem *hi = new HardwareItem (i, types[i], refs[i], origValues[i], configValues[i], extraConfigValues[i], vi);
/* Save the hard disk controller types in an extra map */
if (types[i] == KVirtualSystemDescriptionType_HardDiskControllerIDE ||
controllerMap[i] = hi;
}
}
/* Now process the hard disk images */
for (int a = 0; a < hdIndizies.size(); ++a)
{
int i = hdIndizies[a];
{
/* Get the controller */
if (ci)
{
/* New hardware item as child of the controller */
HardwareItem *hi = new HardwareItem (i, types[i], refs[i], origValues[i], configValues[i], extraConfigValues[i], ci);
}
}
}
}
}
QModelIndex VirtualSystemModel::index (int aRow, int aColumn, const QModelIndex &aParent /* = QModelIndex() */) const
{
return QModelIndex();
else
if (childItem)
else
return QModelIndex();
}
{
return QModelIndex();
if (parentItem == mRootItem)
return QModelIndex();
}
{
return 0;
else
return parentItem->childCount();
}
{
else
return mRootItem->columnCount();
}
{
return false;
}
QVariant VirtualSystemModel::data (const QModelIndex &aIndex, int aRole /* = Qt::DisplayRole */) const
{
return QVariant();
}
{
return 0;
}
QVariant VirtualSystemModel::headerData (int aSection, Qt::Orientation aOrientation, int aRole) const
{
return QVariant();
switch (aSection)
{
}
return title;
}
{
return QModelIndex();
return aIndex;
else
}
{
else
for (int i = 0; i < parentItem->childCount(); ++i)
{
}
}
void VirtualSystemModel::putBack()
{
}
////////////////////////////////////////////////////////////////////////////////
// VirtualSystemDelegate
various types we support. This class forward the requests to the virtual
methods of our different ModelItems. If this is not possible the default
methods of QItemDelegate are used to get some standard behavior. Note: We
have to handle the proxy model ourself. I really don't understand why Qt is
not doing this for us. */
VirtualSystemDelegate::VirtualSystemDelegate (QAbstractProxyModel *aProxy, QObject *aParent /* = NULL */)
: QItemDelegate (aParent)
{}
QWidget * VirtualSystemDelegate::createEditor (QWidget *aParent, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const
{
if (mProxy)
else
return editor;
}
{
if (mProxy)
}
void VirtualSystemDelegate::setModelData (QWidget *aEditor, QAbstractItemModel *aModel, const QModelIndex &aIndex) const
{
if (mProxy)
}
void VirtualSystemDelegate::updateEditorGeometry (QWidget *aEditor, const QStyleOptionViewItem &aOption, const QModelIndex & /* aIndex */) const
{
if (aEditor)
}
////////////////////////////////////////////////////////////////////////////////
// VirtualSystemSortProxyModel
/* How to sort the items in the tree view */
{
};
{}
bool VirtualSystemSortProxyModel::filterAcceptsRow (int aSourceRow, const QModelIndex & aSourceParent) const
{
/* By default enable all, we will explicitly filter out below */
if (aSourceParent.isValid())
{
if (i.isValid())
{
/* We filter hardware types only */
{
/* The license type shouldn't be displayed */
return false;
}
}
}
return true;
}
bool VirtualSystemSortProxyModel::lessThan (const QModelIndex &aLeft, const QModelIndex &aRight) const
{
return false;
/* We sort hardware types only */
return false;
for (unsigned int i = 0; i < RT_ELEMENTS (mSortList); ++i)
{
for (unsigned int a = 0; a <= i; ++a)
return true;
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
// VBoxApplianceEditorWgt
, mAppliance (NULL)
{
/* Make sure all static content is properly initialized */
/* Apply UI decorations */
/* Make the tree looking nicer */
mTvSettings->setRootIsDecorated (false);
mTvSettings->setAlternatingRowColors (true);
mTvSettings->setAllColumnsShowFocus (true);
/* Applying language settings */
}
{
}
void VBoxApplianceEditorWgt::retranslateUi()
{
/* Translate uic generated strings */
}
/* static */
{
if (mMinGuestRAM == -1)
{
/* We need some global defaults from the current VirtualBox
installation */
}
}