VirtualBox

Changeset 24395 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 5, 2009 3:52:25 PM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: VM Settings / Storage Page: Using ISystemProperties::GetDeviceTypesForStorageBus() as device types getters instead of hard-coded values.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMSettingsHD.h

    r24161 r24395  
    143143    void setCtrType (KStorageControllerType aCtrType);
    144144
    145     virtual DeviceTypeList deviceTypeList() const = 0;
     145    DeviceTypeList deviceTypeList() const;
    146146
    147147protected:
     
    164164private:
    165165
    166     DeviceTypeList deviceTypeList() const;
    167 
    168166    KStorageControllerType first() const;
    169167    uint size() const;
     
    179177private:
    180178
    181     DeviceTypeList deviceTypeList() const;
    182 
    183179    KStorageControllerType first() const;
    184180    uint size() const;
     
    194190private:
    195191
    196     DeviceTypeList deviceTypeList() const;
    197 
    198192    KStorageControllerType first() const;
    199193    uint size() const;
     
    208202
    209203private:
    210 
    211     DeviceTypeList deviceTypeList() const;
    212204
    213205    KStorageControllerType first() const;
     
    421413        R_AttSlots,
    422414        R_AttDevice,
    423         R_AttDevices,
    424415        R_AttMediumId,
    425416        R_AttIsShowDiffs,
     
    504495public:
    505496
    506     StorageDelegate (QObject *aParent, bool aDisableStaticControls);
     497    StorageDelegate (QObject *aParent);
    507498
    508499private:
     
    524515public:
    525516
    526     VBoxVMSettingsHD (bool aDisableStaticControls = false);
     517    VBoxVMSettingsHD();
    527518
    528519signals:
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r24304 r24395  
    5454#include "VBoxTakeSnapshotDlg.h"
    5555#include "VBoxVMFirstRunWzd.h"
    56 #include "VBoxVMSettingsHD.h"
    5756#include "VBoxVMSettingsNetwork.h"
    5857#include "VBoxVMSettingsSF.h"
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsHD.cpp

    r24175 r24395  
    226226}
    227227
     228DeviceTypeList AbstractControllerType::deviceTypeList() const
     229{
     230    return vboxGlobal().virtualBox().GetSystemProperties().GetDeviceTypesForStorageBus (mBusType).toList();
     231}
     232
    228233/* IDE Controller Type */
    229234IDEControllerType::IDEControllerType (KStorageControllerType aSubType)
     
    232237}
    233238
    234 DeviceTypeList IDEControllerType::deviceTypeList() const
    235 {
    236     return DeviceTypeList() << KDeviceType_HardDisk << KDeviceType_DVD;
    237 }
    238 
    239239KStorageControllerType IDEControllerType::first() const
    240240{
     
    253253}
    254254
    255 DeviceTypeList SATAControllerType::deviceTypeList() const
    256 {
    257     return DeviceTypeList() << KDeviceType_HardDisk << KDeviceType_DVD;
    258 }
    259 
    260255KStorageControllerType SATAControllerType::first() const
    261256{
     
    274269}
    275270
    276 DeviceTypeList SCSIControllerType::deviceTypeList() const
    277 {
    278     return DeviceTypeList() << KDeviceType_HardDisk << KDeviceType_DVD;
    279 }
    280 
    281271KStorageControllerType SCSIControllerType::first() const
    282272{
     
    293283    : AbstractControllerType (KStorageBus_Floppy, aSubType)
    294284{
    295 }
    296 
    297 DeviceTypeList FloppyControllerType::deviceTypeList() const
    298 {
    299     return DeviceTypeList() << KDeviceType_Floppy;
    300285}
    301286
     
    11321117            return result;
    11331118        }
    1134         case R_AttDevices:
    1135         {
    1136             QVariant result (QVariant::fromValue (DeviceTypeList()));
    1137             if (AbstractItem *item = static_cast <AbstractItem*> (aIndex.internalPointer()))
    1138                 if (item->rtti() == AbstractItem::Type_AttachmentItem)
    1139                     result.setValue (static_cast <AttachmentItem*> (item)->attDeviceTypes());
    1140             return result;
    1141         }
    11421119        case R_AttMediumId:
    11431120        {
     
    12541231        }
    12551232        case R_HDPixmapRect:
     1233        {
     1234            int margin = data (aIndex, R_Margin).toInt();
     1235            int width = data (aIndex, R_IconSize).toInt();
     1236            return QRect (0 - width - margin, margin, width, width);
     1237        }
     1238        case R_CDPixmapRect:
    12561239        {
    12571240            int margin = data (aIndex, R_Margin).toInt();
     
    12591242            int width = data (aIndex, R_IconSize).toInt();
    12601243            return QRect (0 - width - spacing - width - margin, margin, width, width);
    1261         }
    1262         case R_CDPixmapRect:
    1263         {
    1264             int margin = data (aIndex, R_Margin).toInt();
    1265             int width = data (aIndex, R_IconSize).toInt();
    1266             return QRect (0 - width - margin, margin, width, width);
    12671244        }
    12681245        case R_FDPixmapRect:
     
    14361413
    14371414/* Storage Delegate */
    1438 StorageDelegate::StorageDelegate (QObject *aParent, bool aDisableStaticControls)
     1415StorageDelegate::StorageDelegate (QObject *aParent)
    14391416    : QItemDelegate (aParent)
    1440     , mDisableStaticControls (aDisableStaticControls)
    14411417{
    14421418}
     
    14951471
    14961472    /* Draw Controller Additions */
    1497     if (!mDisableStaticControls && model->data (aIndex, StorageModel::R_IsController).toBool() && state & QStyle::State_Selected)
     1473    if (model->data (aIndex, StorageModel::R_IsController).toBool() && state & QStyle::State_Selected)
    14981474    {
    14991475        DeviceTypeList devicesList (model->data (aIndex, StorageModel::R_CtrDevices).value <DeviceTypeList>());
     
    15471523 * Used as HD Settings widget.
    15481524 */
    1549 VBoxVMSettingsHD::VBoxVMSettingsHD (bool aDisableStaticControls /* = false */)
     1525VBoxVMSettingsHD::VBoxVMSettingsHD()
    15501526    : mValidator (0)
    15511527    , mIsPolished (false)
    1552     , mDisableStaticControls (aDisableStaticControls)
    15531528{
    15541529    /* Apply UI decorations */
     
    16091584    /* Storage Model/View */
    16101585    mStorageModel = new StorageModel (mTwStorageTree);
    1611     StorageDelegate *storageDelegate = new StorageDelegate (mTwStorageTree, mDisableStaticControls);
     1586    StorageDelegate *storageDelegate = new StorageDelegate (mTwStorageTree);
    16121587    mTwStorageTree->setMouseTracking (true);
    16131588    mTwStorageTree->setContextMenuPolicy (Qt::CustomContextMenu);
     
    16231598    mTbStorageBar->addAction (mAddCtrAction);
    16241599    mTbStorageBar->addAction (mDelCtrAction);
    1625     mTbStorageBar->setHidden (mDisableStaticControls);
    16261600
    16271601#ifdef Q_WS_MAC
     
    17361710void VBoxVMSettingsHD::putBackTo()
    17371711{
    1738     if (mDisableStaticControls)
    1739     {
    1740         /* Just search for the currently present CD/DVD & Floppy devices to update */
    1741         QModelIndex rootIndex = mStorageModel->root();
    1742         for (int i = 0; i < mStorageModel->rowCount (rootIndex); ++ i)
    1743         {
    1744             QModelIndex ctrIndex = rootIndex.child (i, 0);
    1745             QString ctrName = mStorageModel->data (ctrIndex, StorageModel::R_CtrName).toString();
    1746             for (int j = 0; j < mStorageModel->rowCount (ctrIndex); ++ j)
    1747             {
    1748                 QModelIndex attIndex = ctrIndex.child (j, 0);
    1749                 KDeviceType attDeviceType = mStorageModel->data (attIndex, StorageModel::R_AttDevice).value <KDeviceType>();
    1750                 if (attDeviceType != KDeviceType_DVD && attDeviceType != KDeviceType_Floppy) continue;
    1751                 StorageSlot attStorageSlot = mStorageModel->data (attIndex, StorageModel::R_AttSlot).value <StorageSlot>();
    1752                 QString attMediumId = mStorageModel->data (attIndex, StorageModel::R_AttMediumId).toString();
    1753                 const CMedium &medium = mMachine.GetMedium (ctrName, attStorageSlot.port, attStorageSlot.device);
    1754                 if ((medium.isNull() && !QUuid (attMediumId).isNull()) ||
    1755                     (!medium.isNull() && medium.GetId() != attMediumId))
    1756                     mMachine.MountMedium (ctrName, attStorageSlot.port, attStorageSlot.device, attMediumId);
    1757             }
    1758         }
    1759     }
    1760     else
    1761     {
    1762         /* Remove currently present controllers & attachments */
    1763         CStorageControllerVector controllers = mMachine.GetStorageControllers();
    1764         foreach (const CStorageController &controller, controllers)
    1765         {
    1766             QString controllerName (controller.GetName());
    1767             CMediumAttachmentVector attachments = mMachine.GetMediumAttachmentsOfController (controllerName);
    1768             foreach (const CMediumAttachment &attachment, attachments)
    1769                 mMachine.DetachDevice (controllerName, attachment.GetPort(), attachment.GetDevice());
    1770             mMachine.RemoveStorageController (controllerName);
    1771         }
    1772 
    1773         /* Save created controllers & attachments */
    1774         QModelIndex rootIndex = mStorageModel->root();
    1775         for (int i = 0; i < mStorageModel->rowCount (rootIndex); ++ i)
    1776         {
    1777             QModelIndex ctrIndex = rootIndex.child (i, 0);
    1778             QString ctrName = mStorageModel->data (ctrIndex, StorageModel::R_CtrName).toString();
    1779             KStorageBus ctrBusType = mStorageModel->data (ctrIndex, StorageModel::R_CtrBusType).value <KStorageBus>();
    1780             KStorageControllerType ctrType = mStorageModel->data (ctrIndex, StorageModel::R_CtrType).value <KStorageControllerType>();
    1781             CStorageController ctr = mMachine.AddStorageController (ctrName, ctrBusType);
    1782             ctr.SetControllerType (ctrType);
    1783             int maxUsedPort = -1;
    1784             for (int j = 0; j < mStorageModel->rowCount (ctrIndex); ++ j)
    1785             {
    1786                 QModelIndex attIndex = ctrIndex.child (j, 0);
    1787                 StorageSlot attStorageSlot = mStorageModel->data (attIndex, StorageModel::R_AttSlot).value <StorageSlot>();
    1788                 KDeviceType attDeviceType = mStorageModel->data (attIndex, StorageModel::R_AttDevice).value <KDeviceType>();
    1789                 QString attMediumId = mStorageModel->data (attIndex, StorageModel::R_AttMediumId).toString();
    1790                 mMachine.AttachDevice (ctrName, attStorageSlot.port, attStorageSlot.device, attDeviceType, attMediumId);
    1791                 if (attDeviceType == KDeviceType_DVD)
    1792                     mMachine.PassthroughDevice (ctrName, attStorageSlot.port, attStorageSlot.device,
    1793                                                 mStorageModel->data (attIndex, StorageModel::R_AttIsPassthrough).toBool());
    1794                 maxUsedPort = attStorageSlot.port > maxUsedPort ? attStorageSlot.port : maxUsedPort;
    1795             }
    1796             if (ctrBusType == KStorageBus_SATA)
    1797             {
    1798                 ULONG sataPortsCount = maxUsedPort + 1;
    1799                 sataPortsCount = qMax (sataPortsCount, ctr.GetMinPortCount());
    1800                 sataPortsCount = qMin (sataPortsCount, ctr.GetMaxPortCount());
    1801                 ctr.SetPortCount (sataPortsCount);
    1802             }
     1712    /* Remove currently present controllers & attachments */
     1713    CStorageControllerVector controllers = mMachine.GetStorageControllers();
     1714    foreach (const CStorageController &controller, controllers)
     1715    {
     1716        QString controllerName (controller.GetName());
     1717        CMediumAttachmentVector attachments = mMachine.GetMediumAttachmentsOfController (controllerName);
     1718        foreach (const CMediumAttachment &attachment, attachments)
     1719            mMachine.DetachDevice (controllerName, attachment.GetPort(), attachment.GetDevice());
     1720        mMachine.RemoveStorageController (controllerName);
     1721    }
     1722
     1723    /* Save created controllers & attachments */
     1724    QModelIndex rootIndex = mStorageModel->root();
     1725    for (int i = 0; i < mStorageModel->rowCount (rootIndex); ++ i)
     1726    {
     1727        QModelIndex ctrIndex = rootIndex.child (i, 0);
     1728        QString ctrName = mStorageModel->data (ctrIndex, StorageModel::R_CtrName).toString();
     1729        KStorageBus ctrBusType = mStorageModel->data (ctrIndex, StorageModel::R_CtrBusType).value <KStorageBus>();
     1730        KStorageControllerType ctrType = mStorageModel->data (ctrIndex, StorageModel::R_CtrType).value <KStorageControllerType>();
     1731        CStorageController ctr = mMachine.AddStorageController (ctrName, ctrBusType);
     1732        ctr.SetControllerType (ctrType);
     1733        int maxUsedPort = -1;
     1734        for (int j = 0; j < mStorageModel->rowCount (ctrIndex); ++ j)
     1735        {
     1736            QModelIndex attIndex = ctrIndex.child (j, 0);
     1737            StorageSlot attStorageSlot = mStorageModel->data (attIndex, StorageModel::R_AttSlot).value <StorageSlot>();
     1738            KDeviceType attDeviceType = mStorageModel->data (attIndex, StorageModel::R_AttDevice).value <KDeviceType>();
     1739            QString attMediumId = mStorageModel->data (attIndex, StorageModel::R_AttMediumId).toString();
     1740            mMachine.AttachDevice (ctrName, attStorageSlot.port, attStorageSlot.device, attDeviceType, attMediumId);
     1741            if (attDeviceType == KDeviceType_DVD)
     1742                mMachine.PassthroughDevice (ctrName, attStorageSlot.port, attStorageSlot.device,
     1743                                            mStorageModel->data (attIndex, StorageModel::R_AttIsPassthrough).toBool());
     1744            maxUsedPort = attStorageSlot.port > maxUsedPort ? attStorageSlot.port : maxUsedPort;
     1745        }
     1746        if (ctrBusType == KStorageBus_SATA)
     1747        {
     1748            ULONG sataPortsCount = maxUsedPort + 1;
     1749            sataPortsCount = qMax (sataPortsCount, ctr.GetMinPortCount());
     1750            sataPortsCount = qMin (sataPortsCount, ctr.GetMaxPortCount());
     1751            ctr.SetPortCount (sataPortsCount);
    18031752        }
    18041753    }
     
    19981947    Assert (mStorageModel->data (index, StorageModel::R_IsController).toBool());
    19991948
    2000     if (mStorageModel->data (index, StorageModel::R_CtrBusType).value <KStorageBus>() == KStorageBus_Floppy)
    2001     {
    2002         Assert (mAddFDAttAction->isEnabled());
    2003         mAddFDAttAction->trigger();
    2004     }
    2005     else
    2006     {
    2007         QMenu menu;
    2008         menu.addAction (mAddHDAttAction);
    2009         menu.addAction (mAddCDAttAction);
     1949    DeviceTypeList deviceTypeList (mStorageModel->data (index, StorageModel::R_CtrDevices).value <DeviceTypeList>());
     1950    bool justTrigger = deviceTypeList.size() == 1;
     1951    bool showMenu = deviceTypeList.size() > 1;
     1952    QMenu menu;
     1953    foreach (const KDeviceType &deviceType, deviceTypeList)
     1954    {
     1955        switch (deviceType)
     1956        {
     1957            case KDeviceType_HardDisk:
     1958                if (justTrigger)
     1959                    mAddHDAttAction->trigger();
     1960                if (showMenu)
     1961                    menu.addAction (mAddHDAttAction);
     1962                break;
     1963            case KDeviceType_DVD:
     1964                if (justTrigger)
     1965                    mAddCDAttAction->trigger();
     1966                if (showMenu)
     1967                    menu.addAction (mAddCDAttAction);
     1968                break;
     1969            case KDeviceType_Floppy:
     1970                if (justTrigger)
     1971                    mAddFDAttAction->trigger();
     1972                if (showMenu)
     1973                    menu.addAction (mAddFDAttAction);
     1974                break;
     1975            default:
     1976                break;
     1977        }
     1978    }
     1979    if (showMenu)
    20101980        menu.exec (QCursor::pos());
    2011     }
    20121981}
    20131982
     
    20602029                /* Getting Controller Name */
    20612030                mLeName->setText (mStorageModel->data (index, StorageModel::R_CtrName).toString());
    2062                 mLbName->setEnabled (!mDisableStaticControls);
    2063                 mLeName->setEnabled (!mDisableStaticControls);
    20642031
    20652032                /* Getting Controller Sub type */
     
    20712038                int ctrPos = mCbType->findText (vboxGlobal().toString (type));
    20722039                mCbType->setCurrentIndex (ctrPos == -1 ? 0 : ctrPos);
    2073                 mLbType->setEnabled (!mDisableStaticControls);
    2074                 mCbType->setEnabled (!mDisableStaticControls);
    20752040
    20762041                /* Showing Controller Page */
     
    20892054                mCbSlot->setCurrentIndex (attSlotPos == -1 ? 0 : attSlotPos);
    20902055                mCbSlot->setToolTip (mCbSlot->itemText (mCbSlot->currentIndex()));
    2091                 mLbSlot->setEnabled (!mDisableStaticControls);
    2092                 mCbSlot->setEnabled (!mDisableStaticControls);
    20932056
    20942057                /* Getting Show Diffs state */
    20952058                bool isShowDiffs = mStorageModel->data (index, StorageModel::R_AttIsShowDiffs).toBool();
    20962059                mCbShowDiffs->setChecked (isShowDiffs);
    2097                 mCbShowDiffs->setEnabled (!mDisableStaticControls);
    20982060
    20992061                /* Getting Attachment Medium */
     
    21032065                    case KDeviceType_HardDisk:
    21042066                        mLbVdi->setText (tr ("Hard &Disk:"));
    2105                         mLbVdi->setEnabled (!mDisableStaticControls);
    2106                         mCbVdi->setEnabled (!mDisableStaticControls);
    2107                         mTbVmm->setEnabled (!mDisableStaticControls);
    21082067                        break;
    21092068                    case KDeviceType_DVD:
    21102069                        mLbVdi->setText (tr ("&CD/DVD Device:"));
    2111                         mLbVdi->setEnabled (true);
    2112                         mCbVdi->setEnabled (true);
    2113                         mTbVmm->setEnabled (true);
    21142070                        break;
    21152071                    case KDeviceType_Floppy:
    21162072                        mLbVdi->setText (tr ("&Floppy Device:"));
    2117                         mLbVdi->setEnabled (true);
    2118                         mCbVdi->setEnabled (true);
    2119                         mTbVmm->setEnabled (true);
    21202073                        break;
    21212074                    default:
     
    21292082                /* Getting Passthrough state */
    21302083                bool isHostDrive = mStorageModel->data (index, StorageModel::R_AttIsHostDrive).toBool();
    2131                 mCbPassthrough->setEnabled (!mDisableStaticControls && isHostDrive);
     2084                mCbPassthrough->setEnabled (isHostDrive);
    21322085                mCbPassthrough->setChecked (isHostDrive && mStorageModel->data (index, StorageModel::R_AttIsPassthrough).toBool());
    21332086
     
    22222175    bool isAttachmentsPossible = mStorageModel->data (index, StorageModel::R_IsMoreAttachmentsPossible).toBool();
    22232176
    2224     mAddCtrAction->setEnabled (!mDisableStaticControls && (isIDEPossible || isSATAPossible || isSCSIPossible || isFloppyPossible));
    2225     mAddIDECtrAction->setEnabled (!mDisableStaticControls && isIDEPossible);
    2226     mAddSATACtrAction->setEnabled (!mDisableStaticControls && isSATAPossible);
    2227     mAddSCSICtrAction->setEnabled (!mDisableStaticControls && isSCSIPossible);
    2228     mAddFloppyCtrAction->setEnabled (!mDisableStaticControls && isFloppyPossible);
    2229 
    2230     mAddAttAction->setEnabled (!mDisableStaticControls && isController && isAttachmentsPossible);
    2231     mAddHDAttAction->setEnabled (!mDisableStaticControls && isController && isAttachmentsPossible);
    2232     mAddCDAttAction->setEnabled (!mDisableStaticControls && isController && isAttachmentsPossible);
    2233     mAddFDAttAction->setEnabled (!mDisableStaticControls && isController && isAttachmentsPossible);
    2234 
    2235     mDelCtrAction->setEnabled (!mDisableStaticControls && isController);
    2236     mDelAttAction->setEnabled (!mDisableStaticControls && isAttachment);
     2177    mAddCtrAction->setEnabled (isIDEPossible || isSATAPossible || isSCSIPossible || isFloppyPossible);
     2178    mAddIDECtrAction->setEnabled (isIDEPossible);
     2179    mAddSATACtrAction->setEnabled (isSATAPossible);
     2180    mAddSCSICtrAction->setEnabled (isSCSIPossible);
     2181    mAddFloppyCtrAction->setEnabled (isFloppyPossible);
     2182
     2183    mAddAttAction->setEnabled (isController && isAttachmentsPossible);
     2184    mAddHDAttAction->setEnabled (isController && isAttachmentsPossible);
     2185    mAddCDAttAction->setEnabled (isController && isAttachmentsPossible);
     2186    mAddFDAttAction->setEnabled (isController && isAttachmentsPossible);
     2187
     2188    mDelCtrAction->setEnabled (isController);
     2189    mDelAttAction->setEnabled (isAttachment);
    22372190}
    22382191
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette