VirtualBox

Ignore:
Timestamp:
Oct 28, 2009 7:19:25 PM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: VBoxConsoleWND: Device dropdown & popup menus for CD & FD reworked using nested menus.

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

Legend:

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

    r23734 r24147  
    147147
    148148    void devicesSwitchVrdp (bool aOn);
    149     void devicesOpenStorageDialog();
    150149    void devicesOpenNetworkDialog();
    151150    void devicesOpenSFDialog();
     
    156155    void prepareSFMenu();
    157156
     157    void mountMedium();
    158158    void switchUSB (QAction *aAction);
    159159
     
    237237    QMenu *mVMMenuMini;
    238238    QMenu *mDevicesMenu;
    239     QMenu *mDevicesStorageMenu;
     239    QMenu *mDevicesCDMenu;
     240    QMenu *mDevicesFDMenu;
    240241    QMenu *mDevicesNetworkMenu;
    241242    QMenu *mDevicesSFMenu;
     
    272273
    273274    /* Devices actions */
    274     QAction *mDevicesStorageDialogAction;
    275275    QAction *mDevicesNetworkDialogAction;
    276276    QAction *mDevicesSFDialogAction;
     
    379379
    380380class VBoxSettingsPage;
    381 class VBoxStorageDialog : public QIWithRetranslateUI <QDialog>
    382 {
    383     Q_OBJECT;
    384 
    385 public:
    386 
    387     VBoxStorageDialog (QWidget *aParent, CSession &aSession);
    388 
    389 protected:
    390 
    391     void retranslateUi();
    392 
    393 protected slots:
    394 
    395     virtual void accept();
    396 
    397     void revalidate (QIWidgetValidator *aValidator);
    398     void enableOk (const QIWidgetValidator *aValidator);
    399 
    400 protected:
    401 
    402     void showEvent (QShowEvent *aEvent);
    403 
    404 private:
    405 
    406     VBoxSettingsPage *mSettings;
    407     QIDialogButtonBox *mButtonBox;
    408     CSession &mSession;
    409 };
    410 
    411381class VBoxNetworkDialog : public QIWithRetranslateUI <QDialog>
    412382{
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxMediaManagerDlg.h

    r23953 r24147  
    5656                const CMachine &aSessionMachine = CMachine(),
    5757                const QString &aSelectId = QString::null,
    58                 bool aShowDiffs = true);
     58                bool aShowDiffs = true,
     59                const QStringList &aUsedMediaIds = QStringList());
    5960
    6061    static void showModeless (QWidget *aParent = NULL, bool aRefresh = true);
     
    171172    QString mCDSelectedId;
    172173    QString mFDSelectedId;
     174    QStringList mUsedMediaIds;
    173175};
    174176
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r24080 r24147  
    197197};
    198198
     199struct MountTarget
     200{
     201    MountTarget() : name (QString ("")), port (0), device (0), id (QString ("")), type (VBoxDefs::MediumType_Invalid) {}
     202    MountTarget (const QString &aName, LONG aPort, LONG aDevice)
     203        : name (aName), port (aPort), device (aDevice), id (QString ("")), type (VBoxDefs::MediumType_Invalid) {}
     204    MountTarget (const QString &aName, LONG aPort, LONG aDevice, const QString &aId)
     205        : name (aName), port (aPort), device (aDevice), id (aId), type (VBoxDefs::MediumType_Invalid) {}
     206    MountTarget (const QString &aName, LONG aPort, LONG aDevice, const QString &aId, VBoxDefs::MediumType aType)
     207        : name (aName), port (aPort), device (aDevice), id (aId), type (aType) {}
     208    QString name;
     209    LONG port;
     210    LONG device;
     211    QString id;
     212    VBoxDefs::MediumType type;
     213};
     214Q_DECLARE_METATYPE (MountTarget);
     215
    199216/** \class VBoxConsoleWnd
    200217 *
     
    225242    , mVMMenuMini (0)
    226243    , mDevicesMenu (0)
    227     , mDevicesStorageMenu (0)
     244    , mDevicesCDMenu (0)
     245    , mDevicesFDMenu (0)
    228246    , mDevicesNetworkMenu (0)
    229247    , mDevicesSFMenu (0)
     
    258276    , mVmCloseAction (0)
    259277    /* Device Menu Actions */
    260     , mDevicesStorageDialogAction (0)
    261278    , mDevicesNetworkDialogAction (0)
    262279    , mDevicesSFDialogAction (0)
     
    402419
    403420    /* Devices menu actions */
    404     mDevicesStorageDialogAction = new QAction (mRunningOrPausedActions);
    405     mDevicesStorageDialogAction->setIcon (VBoxGlobal::iconSet (
    406         ":/attachment_16px.png", ":/attachment_disabled_16px.png"));
    407 
    408421    mDevicesNetworkDialogAction = new QAction (mRunningOrPausedActions);
    409422    mDevicesNetworkDialogAction->setIcon (VBoxGlobal::iconSet (
     
    451464    /* Menu Items */
    452465    mMainMenu = new QIMenu (this);
    453     mDevicesStorageMenu = new QMenu (this);
     466    mDevicesCDMenu = new QMenu (this);
     467    mDevicesFDMenu = new QMenu (this);
    454468    mDevicesNetworkMenu = new QMenu (this);
    455469    mDevicesSFMenu = new QMenu (this);
     470    mDevicesUSBMenu = new VBoxUSBMenu (this);
    456471
    457472    /* Machine submenu */
     
    491506    mMainMenu->addMenu (mDevicesMenu);
    492507
    493     mDevicesUSBMenu = new VBoxUSBMenu (mDevicesMenu);
    494     mDevicesUSBMenu->setIcon (VBoxGlobal::iconSet (
    495         ":/usb_16px.png", ":/usb_disabled_16px.png"));
    496 
    497     mDevicesMenu->addAction (mDevicesStorageDialogAction);
     508    mDevicesCDMenu->setIcon (VBoxGlobal::iconSet (":/cd_16px.png", ":/cd_disabled_16px.png"));
     509    mDevicesFDMenu->setIcon (VBoxGlobal::iconSet (":/fd_16px.png", ":/fd_disabled_16px.png"));
     510    mDevicesUSBMenu->setIcon (VBoxGlobal::iconSet (":/usb_16px.png", ":/usb_disabled_16px.png"));
     511
     512    mDevicesMenu->addMenu (mDevicesCDMenu);
     513    mDevicesMenu->addMenu (mDevicesFDMenu);
    498514    mDevicesMenu->addAction (mDevicesNetworkDialogAction);
    499515    mDevicesMenu->addAction (mDevicesSFDialogAction);
     
    508524    mDevicesMenu->addSeparator();
    509525    mDevicesMenu->addAction (mDevicesInstallGuestToolsAction);
    510 
    511     /* Reset the "context menu" flag */
    512     mDevicesUSBMenu->menuAction()->setData (false);
    513526
    514527#ifdef VBOX_WITH_DEBUGGER_GUI
     
    665678    connect (mVmCloseAction, SIGNAL (triggered()), this, SLOT (vmClose()));
    666679
    667     connect (mDevicesStorageMenu, SIGNAL (aboutToShow()), this, SLOT (prepareStorageMenu()));
     680    connect (mDevicesCDMenu, SIGNAL (aboutToShow()), this, SLOT (prepareStorageMenu()));
     681    connect (mDevicesFDMenu, SIGNAL (aboutToShow()), this, SLOT (prepareStorageMenu()));
    668682    connect (mDevicesNetworkMenu, SIGNAL (aboutToShow()), this, SLOT (prepareNetworkMenu()));
    669683    connect (mDevicesSFMenu, SIGNAL (aboutToShow()), this, SLOT (prepareSFMenu()));
    670684    connect (mDevicesUSBMenu, SIGNAL(triggered (QAction *)), this, SLOT(switchUSB (QAction *)));
    671685
    672     connect (mDevicesStorageDialogAction, SIGNAL (triggered()), this, SLOT (devicesOpenStorageDialog()));
    673686    connect (mDevicesNetworkDialogAction, SIGNAL (triggered()), this, SLOT (devicesOpenNetworkDialog()));
    674687    connect (mDevicesSFDialogAction, SIGNAL (triggered()), this, SLOT (devicesOpenSFDialog()));
     
    676689    connect (mDevicesInstallGuestToolsAction, SIGNAL (triggered()), this, SLOT (devicesInstallGuestAdditions()));
    677690
    678     connect (mHDLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    679              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    680691    connect (mCDLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    681692             this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
     
    901912            mConsole->requestToResize (QSize (w, h - menuBar()->height() - statusBar()->height()));
    902913    }
     914
     915    /* initialize storage stuff */
     916    int cdDevicesCount = 0;
     917    int fdDevicesCount = 0;
     918    const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
     919    foreach (const CMediumAttachment &attachment, attachments)
     920    {
     921        if (attachment.GetType() == KDeviceType_DVD)
     922            ++ cdDevicesCount;
     923        if (attachment.GetType() == KDeviceType_Floppy)
     924            ++ fdDevicesCount;
     925    }
     926    mDevicesCDMenu->menuAction()->setData (cdDevicesCount);
     927    mDevicesFDMenu->menuAction()->setData (fdDevicesCount);
     928    mDevicesCDMenu->menuAction()->setVisible (cdDevicesCount);
     929    mDevicesFDMenu->menuAction()->setVisible (fdDevicesCount);
    903930
    904931    /* initialize usb stuff */
     
    16051632
    16061633    /* Devices actions */
    1607     mDevicesStorageDialogAction->setText (tr ("&Storage Devices..."));
    1608     mDevicesStorageDialogAction->setStatusTip (tr ("Open the dialog to change settings of the storage devices"));
     1634    mDevicesCDMenu->setTitle (tr ("&CD/DVD Devices"));
     1635    mDevicesFDMenu->setTitle (tr ("&Floppy Devices"));
    16091636
    16101637    mDevicesNetworkDialogAction->setText (tr ("&Network Adapters..."));
     
    16141641    mDevicesSFDialogAction->setStatusTip (tr ("Open the dialog to operate on shared folders"));
    16151642
    1616     mDevicesSwitchVrdpAction->setText (tr ("Remote Dis&play"));
     1643    mDevicesSwitchVrdpAction->setText (tr ("&Remote Display"));
    16171644    mDevicesSwitchVrdpAction->setStatusTip (tr ("Enable or disable remote desktop (RDP) connections to this machine"));
    16181645#if 0 /* TODO: Allow to setup status-bar! */
     
    20472074}
    20482075
    2049 void VBoxConsoleWnd::devicesOpenStorageDialog()
    2050 {
    2051     if (!mConsole) return;
    2052 
    2053     VBoxStorageDialog dlg (mConsole, mSession);
    2054     dlg.exec();
    2055 }
    2056 
    20572076void VBoxConsoleWnd::devicesOpenNetworkDialog()
    20582077{
     
    21192138void VBoxConsoleWnd::prepareStorageMenu()
    21202139{
    2121     mDevicesStorageMenu->clear();
    2122     mDevicesStorageMenu->addAction (mDevicesStorageDialogAction);
     2140    QMenu *menu = qobject_cast <QMenu*> (sender());
     2141    Assert (menu);
     2142    menu->clear();
     2143
     2144    KDeviceType deviceType = menu == mDevicesCDMenu ? KDeviceType_DVD :
     2145                             menu == mDevicesFDMenu ? KDeviceType_Floppy :
     2146                                                      KDeviceType_Null;
     2147    Assert (deviceType != KDeviceType_Null);
     2148
     2149    VBoxDefs::MediumType mediumType = menu == mDevicesCDMenu ? VBoxDefs::MediumType_DVD :
     2150                                      menu == mDevicesFDMenu ? VBoxDefs::MediumType_Floppy :
     2151                                                               VBoxDefs::MediumType_Invalid;
     2152    Assert (mediumType != VBoxDefs::MediumType_Invalid);
     2153
     2154    const CMediumAttachmentVector &attachments = mSession.GetMachine().GetMediumAttachments();
     2155    foreach (const CMediumAttachment &attachment, attachments)
     2156    {
     2157        if (attachment.GetType() == deviceType)
     2158        {
     2159            /* Attachment menu item */
     2160            QMenu *attachmentMenu = 0;
     2161            if (menu->menuAction()->data().toInt() > 1)
     2162            {
     2163                attachmentMenu = new QMenu (menu);
     2164                attachmentMenu->setTitle (QString ("%1 (%2)").arg (attachment.GetController().GetName())
     2165                                          .arg (vboxGlobal().toString (StorageSlot (attachment.GetController().GetBus(),
     2166                                                                                    attachment.GetPort(),
     2167                                                                                    attachment.GetDevice()))));
     2168                switch (attachment.GetController().GetBus())
     2169                {
     2170                    case KStorageBus_IDE:
     2171                        attachmentMenu->setIcon (QIcon (":/ide_16px.png")); break;
     2172                    case KStorageBus_SATA:
     2173                        attachmentMenu->setIcon (QIcon (":/sata_16px.png")); break;
     2174                    case KStorageBus_SCSI:
     2175                        attachmentMenu->setIcon (QIcon (":/scsi_16px.png")); break;
     2176                    case KStorageBus_Floppy:
     2177                        attachmentMenu->setIcon (QIcon (":/floppy_16px.png")); break;
     2178                    default:
     2179                        break;
     2180                }
     2181                menu->addMenu (attachmentMenu);
     2182            }
     2183            else attachmentMenu = menu;
     2184
     2185            /* Related VBoxMedium item */
     2186            VBoxMedium vboxMediumCurrent;
     2187            vboxGlobal().findMedium (attachment.GetMedium(), vboxMediumCurrent);
     2188
     2189            /* Mount Medium actions */
     2190            int addedIntoList = 0;
     2191            const VBoxMediaList &vboxMediums = vboxGlobal().currentMediaList();
     2192            foreach (const VBoxMedium &vboxMedium, vboxMediums)
     2193            {
     2194                if (vboxMedium.type() == mediumType)
     2195                {
     2196                    bool isMediumUsed = false;
     2197                    foreach (const CMediumAttachment &otherAttachment, attachments)
     2198                    {
     2199                        if (otherAttachment != attachment)
     2200                        {
     2201                            CMedium otherMedium = otherAttachment.GetMedium();
     2202                            if (!otherMedium.isNull() && otherMedium.GetId() == vboxMedium.id())
     2203                            {
     2204                                isMediumUsed = true;
     2205                                break;
     2206                            }
     2207                        }
     2208                    }
     2209                    if (!isMediumUsed)
     2210                    {
     2211                        QAction *mountMediumAction = new QAction (vboxMedium.name(), attachmentMenu);
     2212                        mountMediumAction->setCheckable (true);
     2213                        mountMediumAction->setChecked (vboxMedium.id() == vboxMediumCurrent.id());
     2214                        mountMediumAction->setData (QVariant::fromValue (MountTarget (attachment.GetController().GetName(),
     2215                                                                                      attachment.GetPort(),
     2216                                                                                      attachment.GetDevice(),
     2217                                                                                      vboxMedium.id())));
     2218                        connect (mountMediumAction, SIGNAL (triggered (bool)), this, SLOT (mountMedium()));
     2219                        attachmentMenu->addAction (mountMediumAction);
     2220                        ++ addedIntoList;
     2221                        if (addedIntoList == 5)
     2222                            break;
     2223                    }
     2224                }
     2225            }
     2226
     2227            /* Virtual Media Manager action */
     2228            QAction *callVMMAction = new QAction (attachmentMenu);
     2229            callVMMAction->setIcon (QIcon (":/diskimage_16px.png"));
     2230            callVMMAction->setData (QVariant::fromValue (MountTarget (attachment.GetController().GetName(),
     2231                                                                      attachment.GetPort(),
     2232                                                                      attachment.GetDevice(),
     2233                                                                      QString (""),
     2234                                                                      mediumType)));
     2235            connect (callVMMAction, SIGNAL (triggered (bool)), this, SLOT (mountMedium()));
     2236            attachmentMenu->addAction (callVMMAction);
     2237
     2238            /* Separator */
     2239            attachmentMenu->addSeparator();
     2240
     2241            /* Unmount Medium action */
     2242            QAction *unmountMediumAction = new QAction (attachmentMenu);
     2243            unmountMediumAction->setEnabled (!vboxMediumCurrent.isNull());
     2244            unmountMediumAction->setData (QVariant::fromValue (MountTarget (attachment.GetController().GetName(),
     2245                                                                            attachment.GetPort(),
     2246                                                                            attachment.GetDevice())));
     2247            connect (unmountMediumAction, SIGNAL (triggered (bool)), this, SLOT (mountMedium()));
     2248            attachmentMenu->addAction (unmountMediumAction);
     2249
     2250            /* Switch CD/FD naming */
     2251            switch (deviceType)
     2252            {
     2253                case KDeviceType_DVD:
     2254                    callVMMAction->setText (tr ("More CD/DVD Images..."));
     2255                    unmountMediumAction->setText (tr ("Unmount CD/DVD Device"));
     2256                    unmountMediumAction->setIcon (VBoxGlobal::iconSet (":/cd_unmount_16px.png",
     2257                                                                       ":/cd_unmount_disabled_16px.png"));
     2258                    break;
     2259                case KDeviceType_Floppy:
     2260                    callVMMAction->setText (tr ("More Floppy Images..."));
     2261                    unmountMediumAction->setText (tr ("Unmount Floppy Device"));
     2262                    unmountMediumAction->setIcon (VBoxGlobal::iconSet (":/fd_unmount_16px.png",
     2263                                                                       ":/fd_unmount_disabled_16px.png"));
     2264                    break;
     2265                default:
     2266                    break;
     2267            }
     2268        }
     2269    }
     2270
     2271    if (menu->menuAction()->data().toInt() == 0)
     2272    {
     2273        /* Empty menu item */
     2274        Assert (menu->isEmpty());
     2275        QAction *emptyMenuAction = new QAction (menu);
     2276        emptyMenuAction->setEnabled (false);
     2277        switch (deviceType)
     2278        {
     2279            case KDeviceType_DVD:
     2280                emptyMenuAction->setText (tr ("No CD/DVD Devices Attached"));
     2281                break;
     2282            case KDeviceType_Floppy:
     2283                emptyMenuAction->setText (tr ("No Floppy Devices Attached"));
     2284                break;
     2285            default:
     2286                break;
     2287        }
     2288        emptyMenuAction->setIcon (VBoxGlobal::iconSet (":/delete_16px.png", ":/delete_disabled_16px.png"));
     2289        menu->addAction (emptyMenuAction);
     2290    }
    21232291}
    21242292
     
    21332301    mDevicesSFMenu->clear();
    21342302    mDevicesSFMenu->addAction (mDevicesSFDialogAction);
     2303}
     2304
     2305void VBoxConsoleWnd::mountMedium()
     2306{
     2307    QAction *action = qobject_cast <QAction*> (sender());
     2308    Assert (action);
     2309
     2310    MountTarget target = action->data().value <MountTarget>();
     2311    CMachine machine = mSession.GetMachine();
     2312    CMediumAttachment attachment = machine.GetMediumAttachment (target.name, target.port, target.device);
     2313    CMedium medium = attachment.GetMedium();
     2314
     2315    if (target.type != VBoxDefs::MediumType_Invalid)
     2316    {
     2317        /* Search for already used images */
     2318        QStringList usedImages;
     2319        const CMediumAttachmentVector &attachments = mSession.GetMachine().GetMediumAttachments();
     2320        foreach (const CMediumAttachment &index, attachments)
     2321        {
     2322            if (index != attachment && !index.GetMedium().isNull() && !index.GetMedium().GetHostDrive())
     2323                usedImages << index.GetMedium().GetId();
     2324        }
     2325        /* Open VMM Dialog */
     2326        VBoxMediaManagerDlg dlg (this);
     2327        dlg.setup (target.type, true /* do select? */, false /* do refresh? */,
     2328                   mSession.GetMachine(), QString(), true, usedImages);
     2329        if (dlg.exec() == QDialog::Accepted)
     2330            target.id = dlg.selectedId();
     2331        else return;
     2332    }
     2333
     2334    machine.MountMedium (target.name, target.port, target.device,
     2335                         target.id.isEmpty() || medium.isNull() || medium.GetId() != target.id ||
     2336                         target.type != VBoxDefs::MediumType_Invalid ? target.id : QString (""));
    21352337}
    21362338
     
    21742376void VBoxConsoleWnd::showIndicatorContextMenu (QIStateIndicator *aInd, QContextMenuEvent *aEvent)
    21752377{
    2176     if (aInd == mHDLed)
    2177     {
    2178         if (mDevicesStorageMenu->isEnabled())
    2179         {
    2180             /* set "this is a context menu" flag */
    2181             mDevicesStorageMenu->menuAction()->setData (true);
    2182             mDevicesStorageMenu->exec (aEvent->globalPos());
    2183             mDevicesStorageMenu->menuAction()->setData (false);
    2184         }
    2185     }
    2186     else if (aInd == mCDLed)
    2187     {
    2188         if (mDevicesStorageMenu->isEnabled())
    2189         {
    2190             /* set "this is a context menu" flag */
    2191             mDevicesStorageMenu->menuAction()->setData (true);
    2192             mDevicesStorageMenu->exec (aEvent->globalPos());
    2193             mDevicesStorageMenu->menuAction()->setData (false);
    2194         }
     2378    if (aInd == mCDLed)
     2379    {
     2380        mDevicesCDMenu->exec (aEvent->globalPos());
    21952381    }
    21962382#if 0 /* TODO: Allow to setup status-bar! */
    21972383    else if (aInd == mFDLed)
    21982384    {
    2199         if (mDevicesStorageMenu->isEnabled())
    2200         {
    2201             /* set "this is a context menu" flag */
    2202             mDevicesStorageMenu->menuAction()->setData (true);
    2203             mDevicesStorageMenu->exec (aEvent->globalPos());
    2204             mDevicesStorageMenu->menuAction()->setData (false);
    2205         }
     2385        mDevicesFDMenu->exec (aEvent->globalPos());
    22062386    }
    22072387#endif
     
    22092389    {
    22102390        if (mDevicesNetworkMenu->isEnabled())
    2211         {
    2212             mDevicesNetworkMenu->menuAction()->setData (true);
    22132391            mDevicesNetworkMenu->exec (aEvent->globalPos());
    2214             mDevicesNetworkMenu->menuAction()->setData (false);
    2215         }
    22162392    }
    22172393    else if (aInd == mUSBLed)
    22182394    {
    22192395        if (mDevicesUSBMenu->isEnabled())
    2220         {
    2221             /* set "this is a context menu" flag */
    2222             mDevicesUSBMenu->menuAction()->setData (true);
    22232396            mDevicesUSBMenu->exec (aEvent->globalPos());
    2224             mDevicesUSBMenu->menuAction()->setData (false);
    2225         }
    22262397    }
    22272398    else if (aInd == mSFLed)
    22282399    {
    22292400        if (mDevicesSFMenu->isEnabled())
    2230         {
    2231             mDevicesSFMenu->menuAction()->setData (true);
    22322401            mDevicesSFMenu->exec (aEvent->globalPos());
    2233             mDevicesSFMenu->menuAction()->setData (false);
    2234         }
    22352402    }
    22362403    else if (aInd == mMouseLed)
     
    34143581#endif /* VBOX_WITH_DEBUGGER_GUI */
    34153582
    3416 VBoxStorageDialog::VBoxStorageDialog (QWidget *aParent, CSession &aSession)
    3417     : QIWithRetranslateUI <QDialog> (aParent)
    3418     , mSettings (0)
    3419     , mButtonBox (0)
    3420     , mSession (aSession)
    3421 {
    3422     setModal (true);
    3423     /* Setup Dialog's options */
    3424     setWindowIcon (QIcon (":/attachment_16px.png"));
    3425     setSizeGripEnabled (true);
    3426 
    3427     /* Setup main dialog's layout */
    3428     QVBoxLayout *mainLayout = new QVBoxLayout (this);
    3429     VBoxGlobal::setLayoutMargin (mainLayout, 10);
    3430     mainLayout->setSpacing (10);
    3431 
    3432     /* Setup settings layout */
    3433     mSettings = new VBoxVMSettingsHD (true);
    3434     VBoxGlobal::setLayoutMargin (mSettings->layout(), 0);
    3435     mainLayout->addWidget (mSettings);
    3436     mSettings->getFrom (aSession.GetMachine());
    3437 
    3438     /* Setup validation */
    3439     QIWidgetValidator *validator = new QIWidgetValidator (mSettings, this);
    3440     mSettings->setValidator (validator);
    3441 
    3442     /* Setup button's layout */
    3443     mButtonBox = new QIDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
    3444     mainLayout->addWidget (mButtonBox);
    3445 
    3446     connect (mButtonBox, SIGNAL (helpRequested()), &vboxProblem(), SLOT (showHelpHelpDialog()));
    3447     connect (mButtonBox, SIGNAL (accepted()), this, SLOT (accept()));
    3448     connect (mButtonBox, SIGNAL (rejected()), this, SLOT (reject()));
    3449     connect (validator, SIGNAL (isValidRequested (QIWidgetValidator*)),
    3450              this, SLOT (revalidate (QIWidgetValidator*)));
    3451     connect (validator, SIGNAL (validityChanged (const QIWidgetValidator*)),
    3452              this, SLOT (enableOk (const QIWidgetValidator*)));
    3453 
    3454     retranslateUi();
    3455 }
    3456 
    3457 void VBoxStorageDialog::retranslateUi()
    3458 {
    3459     setWindowTitle (tr ("Storage Devices"));
    3460 }
    3461 
    3462 void VBoxStorageDialog::accept()
    3463 {
    3464     mSettings->putBackTo();
    3465     CMachine machine = mSession.GetMachine();
    3466     machine.SaveSettings();
    3467     if (!machine.isOk())
    3468         vboxProblem().cannotSaveMachineSettings (machine);
    3469     QDialog::accept();
    3470 }
    3471 
    3472 void VBoxStorageDialog::revalidate (QIWidgetValidator *aValidator)
    3473 {
    3474     QString warning, title;
    3475     bool valid = mSettings->revalidate (warning, title);
    3476     aValidator->setOtherValid (valid);
    3477 }
    3478 
    3479 void VBoxStorageDialog::enableOk (const QIWidgetValidator *aValidator)
    3480 {
    3481     mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (aValidator->isValid());
    3482 }
    3483 
    3484 void VBoxStorageDialog::showEvent (QShowEvent *aEvent)
    3485 {
    3486     resize (450, 300);
    3487     VBoxGlobal::centerWidget (this, parentWidget());
    3488     setMinimumWidth (400);
    3489     QDialog::showEvent (aEvent);
    3490 }
    3491 
    34923583VBoxNetworkDialog::VBoxNetworkDialog (QWidget *aParent, CSession &aSession)
    34933584    : QIWithRetranslateUI <QDialog> (aParent)
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp

    r24054 r24147  
    394394 *                          (ignored if @a aSessionMachine is null assuming
    395395 *                          @c true).
     396 * @param aUsedMediaIds     List containing IDs of mediums used in other
     397 *                          attachments to restrict selection.
    396398 */
    397399void VBoxMediaManagerDlg::setup (VBoxDefs::MediumType aType, bool aDoSelect,
     
    399401                                 const CMachine &aSessionMachine /* = CMachine() */,
    400402                                 const QString &aSelectId /* = QString() */,
    401                                  bool aShowDiffs /* = true */)
     403                                 bool aShowDiffs /* = true */,
     404                                 const QStringList &aUsedMediaIds /* = QStringList() */)
    402405{
    403406    mSetupMode = true;
     
    432435
    433436    mDoSelect = aDoSelect;
     437    mUsedMediaIds = aUsedMediaIds;
    434438
    435439    mButtonBox->button (QDialogButtonBox::Cancel)->setVisible (mDoSelect);
     
    16661670        case Action_Select:
    16671671        {
    1668             /* In the current implementation, any known media can be attached
    1669              * (either directly, or indirectly), so always return true */
    1670             return true;
     1672            /* Restrict selecting mediums
     1673             * already used by other attachments */
     1674            return !mUsedMediaIds.contains (aItem->id());
    16711675        }
    16721676        case Action_Edit:
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