VirtualBox

Changeset 23054 in vbox for trunk/src


Ignore:
Timestamp:
Sep 16, 2009 9:13:01 AM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: Changing Network Attachment Type during runtime.

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

Legend:

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

    r22737 r23054  
    3030#include "VBoxProblemReporter.h"
    3131#include "VBoxHelpActions.h"
     32#include "VBoxVMSettingsNetwork.h"
    3233
    3334/* Qt includes */
     
    6364
    6465class VBoxMiniToolBar;
     66
     67class VBoxVMSettingsNetworkPage;
    6568
    6669/* We want to make the first action highlighted but not
     
    213216    void devicesUnmountDVD();
    214217    void devicesSwitchVrdp (bool);
     218    void devicesOpenNetworkDialog();
    215219    void devicesOpenSFDialog();
    216220    void devicesInstallGuestAdditions();
     
    218222    void prepareFloppyMenu();
    219223    void prepareDVDMenu();
    220     void prepareNetworkMenu();
    221 
    222     void setDynamicMenuItemStatusTip (QAction *aAction);
    223224
    224225    void captureFloppy (QAction *aAction);
    225226    void captureDVD (QAction *aAction);
    226     void activateNetworkMenu (QAction *aAction);
    227227    void switchUSB (QAction *aAction);
    228228
     
    236236    void updateMouseState (int state);
    237237    void updateAdditionsState (const QString&, bool, bool, bool);
    238     void updateNetworkAdarptersState();
     238    void updateNetworkAdaptersState();
    239239    void updateUsbState();
    240240    void updateMediaDriveState (VBoxDefs::MediaType aType);
     
    291291    QAction *mDevicesUnmountDVDAction;
    292292    QAction *mDevicesSwitchVrdpAction;
     293    QAction *mDevicesNetworkDialogAction;
    293294    QAction *mDevicesSFDialogAction;
    294295    QAction *mDevicesInstallGuestToolsAction;
     
    323324    /* see showIndicatorContextMenu for a description of mDevicesSFMenu */
    324325    /* QMenu *mDevicesSFMenu; */
    325     QMenu *mDevicesNetworkMenu;
    326326    VBoxUSBMenu *mDevicesUSBMenu;
    327327    /* VBoxSwitchMenu *mDevicesVRDPMenu; */
     
    436436
    437437
     438class VBoxVMSettingsNetworkDialogPage : public VBoxVMSettingsNetworkPage
     439{
     440    Q_OBJECT;
     441
     442public:
     443
     444    VBoxVMSettingsNetworkDialogPage() : VBoxVMSettingsNetworkPage(true) {}
     445
     446    void getFrom (const CMachine &aMachine) { VBoxVMSettingsNetworkPage::getFrom(aMachine); }
     447    void putBackTo() { VBoxVMSettingsNetworkPage::putBackTo(); }
     448
     449};
     450
     451class VBoxNetworkDialog : public QIWithRetranslateUI<QDialog>
     452{
     453    Q_OBJECT;
     454
     455public:
     456
     457    VBoxNetworkDialog (QWidget*, CSession&);
     458
     459protected:
     460
     461    void retranslateUi();
     462
     463protected slots:
     464
     465    virtual void accept();
     466
     467protected:
     468
     469    void showEvent (QShowEvent*);
     470
     471private:
     472
     473    VBoxVMSettingsNetworkDialogPage *mSettings;
     474    CSession &mSession;
     475};
     476
     477
    438478#endif // __VBoxConsoleWnd_h__
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMSettingsNetwork.h

    r22992 r23054  
    3939public:
    4040
    41     VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent);
     41    VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent, bool aDisableStaticControls = false);
    4242
    4343    void getFromAdapter (const CNetworkAdapter &aAdapter);
     
    7979
    8080    bool mPolished;
     81    bool mDisableStaticControls;
    8182};
    8283
     
    8788public:
    8889
    89     VBoxVMSettingsNetworkPage();
     90    VBoxVMSettingsNetworkPage(bool aDisableStaticControls = false);
    9091
    9192    QStringList brgList (bool aRefresh = false);
     
    115116    QStringList mIntList;
    116117    QStringList mHoiList;
     118
     119    bool mDisableStaticControls;
    117120};
    118121
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r23027 r23054  
    366366                             ":/cd_unmount_dis_16px.png"));
    367367
     368    mDevicesNetworkDialogAction = new QAction (mRunningOrPausedActions);
     369    mDevicesNetworkDialogAction->setIcon (
     370        VBoxGlobal::iconSet (":/nw_16px.png",
     371                             ":/nw_disabled_16px.png"));
     372
    368373    mDevicesSFDialogAction = new QAction (mRunningOrPausedActions);
    369374    mDevicesSFDialogAction->setIcon (
     
    461466    mDevicesMenu->addSeparator();
    462467
    463     mDevicesNetworkMenu = mDevicesMenu->addMenu (VBoxGlobal::iconSet (":/nw_16px.png", ":/nw_disabled_16px.png"), QString::null);
     468    mDevicesMenu->addAction (mDevicesNetworkDialogAction);
    464469    mDevicesMenu->addSeparator();
    465470
     
    652657    connect (mDevicesUnmountDVDAction, SIGNAL(triggered()), this, SLOT(devicesUnmountDVD()));
    653658    connect (mDevicesSwitchVrdpAction, SIGNAL(toggled (bool)), this, SLOT(devicesSwitchVrdp (bool)));
     659    connect (mDevicesNetworkDialogAction, SIGNAL(triggered()), this, SLOT(devicesOpenNetworkDialog()));
    654660    connect (mDevicesSFDialogAction, SIGNAL(triggered()), this, SLOT(devicesOpenSFDialog()));
    655661    connect (mDevicesInstallGuestToolsAction, SIGNAL(triggered()), this, SLOT(devicesInstallGuestAdditions()));
     
    658664    connect (mDevicesMountFloppyMenu, SIGNAL(aboutToShow()), this, SLOT(prepareFloppyMenu()));
    659665    connect (mDevicesMountDVDMenu, SIGNAL(aboutToShow()), this, SLOT(prepareDVDMenu()));
    660     connect (mDevicesNetworkMenu, SIGNAL(aboutToShow()), this, SLOT(prepareNetworkMenu()));
    661666
    662667    connect (statusBar(), SIGNAL(messageChanged (const QString &)), this, SLOT(statusTipChanged (const QString &)));
     
    665670    connect (mDevicesMountDVDMenu, SIGNAL(triggered(QAction *)), this, SLOT(captureDVD(QAction *)));
    666671    connect (mDevicesUSBMenu, SIGNAL(triggered(QAction *)), this, SLOT(switchUSB(QAction *)));
    667     connect (mDevicesNetworkMenu, SIGNAL(triggered(QAction *)), this, SLOT(activateNetworkMenu(QAction *)));
    668 
    669     connect (mDevicesMountFloppyMenu, SIGNAL (hovered (QAction *)),
    670              this, SLOT (setDynamicMenuItemStatusTip (QAction *)));
    671     connect (mDevicesMountDVDMenu, SIGNAL (hovered (QAction *)),
    672              this, SLOT (setDynamicMenuItemStatusTip (QAction *)));
    673     connect (mDevicesNetworkMenu, SIGNAL (hovered (QAction *)),
    674              this, SLOT (setDynamicMenuItemStatusTip (QAction *)));
    675672
    676673    /* Cleanup the status bar tip when a menu with dynamic items is
     
    681678             statusBar(), SLOT (clearMessage()));
    682679    connect (mDevicesMountDVDMenu, SIGNAL (aboutToHide()),
    683              statusBar(), SLOT (clearMessage()));
    684     connect (mDevicesNetworkMenu, SIGNAL (aboutToHide()),
    685680             statusBar(), SLOT (clearMessage()));
    686681
     
    970965             this, SLOT (updateUsbState()));
    971966    connect (console, SIGNAL (networkStateChange()),
    972              this, SLOT (updateNetworkAdarptersState()));
     967             this, SLOT (updateNetworkAdaptersState()));
    973968    connect (console, SIGNAL (sharedFoldersChanged()),
    974969             this, SLOT (updateSharedFoldersState()));
     
    17491744        tr ("Enable or disable remote desktop (RDP) connections to this machine"));
    17501745
     1746    mDevicesNetworkDialogAction->setText (tr ("&Network Adapters..."));
     1747    mDevicesNetworkDialogAction->setStatusTip (
     1748        tr ("Open the dialog to change settings of the Network Adapters"));
     1749
    17511750    mDevicesSFDialogAction->setText (tr ("&Shared Folders..."));
    17521751    mDevicesSFDialogAction->setStatusTip (
     
    17771776    mDevicesMountFloppyMenu->setTitle (tr ("Mount &Floppy"));
    17781777    mDevicesMountDVDMenu->setTitle (tr ("Mount &CD/DVD-ROM"));
    1779     mDevicesNetworkMenu->setTitle (tr ("&Network Adapters"));
    17801778    mDevicesUSBMenu->setTitle (tr ("&USB Devices"));
    17811779
     
    19841982                                       : KDeviceActivity_Null);
    19851983
    1986         mDevicesNetworkMenu->setEnabled (isRunningOrPaused && count > 0);
     1984        mDevicesNetworkDialogAction->setEnabled (isRunningOrPaused && count > 0);
    19871985
    19881986        /* update tooltip */
     
    29552953}
    29562954
     2955void VBoxConsoleWnd::devicesOpenNetworkDialog()
     2956{
     2957    if (!console) return;
     2958
     2959    VBoxNetworkDialog dlg (console, csession);
     2960    dlg.exec();
     2961}
     2962
    29572963void VBoxConsoleWnd::devicesOpenSFDialog()
    29582964{
     
    32383244}
    32393245
    3240 /**
    3241  *  Prepares the "Network adapter" menu by populating the existent adapters.
    3242  */
    3243 void VBoxConsoleWnd::prepareNetworkMenu()
    3244 {
    3245     mDevicesNetworkMenu->clear();
    3246     ulong count = qMin ((ULONG) 4,
    3247         vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount());
    3248     for (ulong slot = 0; slot < count; ++ slot)
    3249     {
    3250         CNetworkAdapter adapter = csession.GetMachine().GetNetworkAdapter (slot);
    3251         QAction *action = mDevicesNetworkMenu->addAction (tr ("Adapter %1", "network").arg (slot+1));
    3252         action->setEnabled (adapter.GetEnabled());
    3253         action->setCheckable (true);
    3254         action->setChecked (adapter.GetEnabled() && adapter.GetCableConnected());
    3255         action->setData (static_cast<qulonglong> (slot));
    3256     }
    3257 }
    3258 
    3259 void VBoxConsoleWnd::setDynamicMenuItemStatusTip (QAction *aAction)
    3260 {
    3261     QString tip;
    3262 
    3263     if (sender() == mDevicesNetworkMenu)
    3264     {
    3265         tip = aAction->isChecked() ?
    3266             tr ("Disconnect the cable from the selected virtual network adapter") :
    3267             tr ("Connect the cable to the selected virtual network adapter");
    3268     }
    3269 
    3270     if (!tip.isNull())
    3271     {
    3272         StatusTipEvent *ev = new StatusTipEvent (tip);
    3273         QApplication::postEvent (this, ev);
    3274         mWaitForStatusBarChange = true;
    3275     }
    3276 }
    3277 
    32783246void VBoxConsoleWnd::statusTipChanged (const QString & /*aMes*/)
    32793247{
     
    33403308        }
    33413309    }
    3342 }
    3343 
    3344 /**
    3345  *  Switch the cable connected/disconnected for the selected network adapter
    3346  */
    3347 void VBoxConsoleWnd::activateNetworkMenu (QAction *aAction)
    3348 {
    3349     ulong slot = aAction->data().toULongLong();
    3350     CNetworkAdapter adapter = csession.GetMachine().GetNetworkAdapter (slot);
    3351     bool connected = adapter.GetCableConnected();
    3352     if (adapter.GetEnabled())
    3353         adapter.SetCableConnected (!connected);
    33543310}
    33553311
     
    34503406    if (ind == net_light)
    34513407    {
    3452         if (mDevicesNetworkMenu->isEnabled())
    3453         {
    3454             /* set "this is a context menu" flag */
    3455             mDevicesNetworkMenu->menuAction()->setData (true);
    3456             mDevicesNetworkMenu->exec (e->globalPos());
    3457             mDevicesNetworkMenu->menuAction()->setData (false);
    3458         }
     3408        if (mDevicesNetworkDialogAction->isEnabled())
     3409            mDevicesNetworkDialogAction->trigger();
    34593410    }
    34603411}
     
    36853636}
    36863637
    3687 void VBoxConsoleWnd::updateNetworkAdarptersState()
     3638void VBoxConsoleWnd::updateNetworkAdaptersState()
    36883639{
    36893640    updateAppearanceOf (NetworkStuff);
     
    39343885}
    39353886
     3887
     3888VBoxNetworkDialog::VBoxNetworkDialog (QWidget *aParent, CSession &aSession)
     3889    : QIWithRetranslateUI<QDialog> (aParent)
     3890    , mSettings (0)
     3891    , mSession (aSession)
     3892{
     3893    setModal (true);
     3894    /* Setup Dialog's options */
     3895    setWindowIcon (QIcon (":/nw_16px.png"));
     3896    setSizeGripEnabled (true);
     3897
     3898    /* Setup main dialog's layout */
     3899    QVBoxLayout *mainLayout = new QVBoxLayout (this);
     3900    VBoxGlobal::setLayoutMargin (mainLayout, 10);
     3901    mainLayout->setSpacing (10);
     3902
     3903    /* Setup settings layout */
     3904    mSettings = new VBoxVMSettingsNetworkDialogPage();
     3905    mSettings->setOrderAfter (this);
     3906    VBoxGlobal::setLayoutMargin (mSettings->layout(), 0);
     3907    mSettings->getFrom (aSession.GetMachine());
     3908    mainLayout->addWidget (mSettings);
     3909
     3910    /* Setup button's layout */
     3911    QIDialogButtonBox *buttonBox = new QIDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
     3912
     3913    connect (buttonBox, SIGNAL (helpRequested()), &vboxProblem(), SLOT (showHelpHelpDialog()));
     3914    connect (buttonBox, SIGNAL (accepted()), this, SLOT (accept()));
     3915    connect (buttonBox, SIGNAL (rejected()), this, SLOT (reject()));
     3916    mainLayout->addWidget (buttonBox);
     3917
     3918    retranslateUi();
     3919}
     3920
     3921void VBoxNetworkDialog::retranslateUi()
     3922{
     3923    setWindowTitle (tr ("Network Adapter Settings"));
     3924}
     3925
     3926void VBoxNetworkDialog::accept()
     3927{
     3928    mSettings->putBackTo();
     3929    CMachine machine = mSession.GetMachine();
     3930    machine.SaveSettings();
     3931    if (!machine.isOk())
     3932        vboxProblem().cannotSaveMachineSettings (machine);
     3933    QDialog::accept();
     3934}
     3935
     3936void VBoxNetworkDialog::showEvent (QShowEvent *aEvent)
     3937{
     3938    resize (450, 300);
     3939    VBoxGlobal::centerWidget (this, parentWidget());
     3940    setMinimumWidth (400);
     3941    QDialog::showEvent (aEvent);
     3942}
     3943
     3944
    39363945#include "VBoxConsoleWnd.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsNetwork.cpp

    r22992 r23054  
    3535
    3636/* VBoxVMSettingsNetwork Stuff */
    37 VBoxVMSettingsNetwork::VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent)
     37VBoxVMSettingsNetwork::VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent, bool aDisableStaticControls)
    3838    : QIWithRetranslateUI <QWidget> (0)
    3939    , mParent (aParent)
    4040    , mValidator (0)
    4141    , mPolished (false)
     42    , mDisableStaticControls (false)
    4243{
    4344    /* Apply UI decorations */
     
    6970    /* Applying language settings */
    7071    retranslateUi();
     72
     73    /* If some controls should be disabled or not when the
     74     * same tab widgets are shown during runtime
     75     */
     76    mDisableStaticControls = aDisableStaticControls;
    7177}
    7278
     
    153159    mValidator = aValidator;
    154160
    155     connect (mCbEnableAdapter, SIGNAL (toggled (bool)),
    156              mValidator, SLOT (revalidate()));
     161    if (!mDisableStaticControls)
     162        connect (mCbEnableAdapter, SIGNAL (toggled (bool)),
     163                 mValidator, SLOT (revalidate()));
    157164    connect (mCbAttachmentType, SIGNAL (activated (const QString&)),
    158165             this, SLOT (updateAttachmentAlternative()));
     
    162169             this, SLOT (updateAlternativeName()));
    163170
    164     mValidator->revalidate();
     171    if (!mDisableStaticControls)
     172        mValidator->revalidate();
    165173}
    166174
     
    267275        mNetworkChildGridLayout->setColumnMinimumWidth (0, mLbAttachmentType->width());
    268276
    269         /* Hide advanced items initially */
    270         toggleAdvanced();
     277        if (mDisableStaticControls)
     278        {
     279            /* Disable controls for dynamically displayed page */
     280            mCbEnableAdapter->setEnabled (false);
     281            mCbAdapterType->setEnabled (false);
     282            mLeMAC->setEnabled (false);
     283            mTbMAC->setEnabled (false);
     284            mLbAdapterType->setEnabled (false);
     285            mLbMAC->setEnabled (false);
     286            mAbsAdvanced->animateClick();
     287        }
     288        else
     289        {
     290            /* Hide advanced items initially */
     291            toggleAdvanced();
     292        }
    271293    }
    272294    QWidget::showEvent (aEvent);
     
    526548
    527549/* VBoxVMSettingsNetworkPage Stuff */
    528 VBoxVMSettingsNetworkPage::VBoxVMSettingsNetworkPage()
     550VBoxVMSettingsNetworkPage::VBoxVMSettingsNetworkPage(bool aDisableStaticControls)
    529551    : mValidator (0)
     552    , mDisableStaticControls (false)
    530553{
    531554    /* Setup Main Layout */
     
    536559    mTwAdapters = new QTabWidget (this);
    537560    mainLayout->addWidget (mTwAdapters);
     561
     562    /* If some controls should be disabled or not when the
     563     * same tab widgets are shown during runtime
     564     */
     565    mDisableStaticControls = aDisableStaticControls;
    538566}
    539567
     
    637665
    638666        /* Creating Adapter's page */
    639         VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork (this);
     667        VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork (this, mDisableStaticControls);
    640668
    641669        /* Loading Adapter's data into page */
     
    644672        /* Attach Adapter's page to Tab Widget */
    645673        mTwAdapters->addTab (page, page->pageTitle());
     674
     675        /* Disable tab page if adapter is being configured dynamically */
     676        if (mDisableStaticControls && !adapter.GetEnabled())
     677            mTwAdapters->setTabEnabled(slot, false);
    646678
    647679        /* Setup validation */
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