VirtualBox

Changeset 2458 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 3, 2007 9:34:13 AM (18 years ago)
Author:
vboxsync
Message:

1906: Add context menu over network icon

Feature implemented as designed:
Network Adapters context menu was added into dropped down menu and to Network LED popup menu.
It allows network cable to be temporary connected/disconnected for the selected enabled Network Adapter.

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

Legend:

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

    r2412 r2458  
    4040# undef PAGE_SHIFT
    4141# include <Carbon/Carbon.h>
    42 #endif 
     42#endif
    4343
    4444class QAction;
     
    5353class VBoxSwitchMenu;
    5454class VBoxUSBLedTip;
     55class VBoxNetworkLedTip;
    5556
    5657class VBoxConsoleWnd : public QMainWindow
     
    140141    void prepareDVDMenu();
    141142
     143    void prepareNetworkMenu();
     144    void activateNetworkMenu (int);
     145
    142146    void captureFloppy (int id);
    143147    void captureDVD (int id);
     
    207211    QPopupMenu *devicesMountDVDMenu;
    208212    QPopupMenu *devicesSharedFolders;
     213    QPopupMenu *devicesNetworkMenu;
    209214    VBoxUSBMenu *devicesUSBMenu;
    210215    VBoxSwitchMenu *devicesVRDPMenu;
     
    226231        devicesMountDVDMenuId,
    227232        devicesUSBMenuId,
     233        devicesNetworkMenuId,
    228234#ifdef VBOX_WITH_DEBUGGER_GUI
    229235        dbgMenuId,
     
    245251
    246252    VBoxUSBLedTip *mUsbLedTip;
     253    VBoxNetworkLedTip *mNetworkLedTip;
    247254
    248255    QTimer *idle_timer;
     
    280287    CGImageRef dockImgBack100x75;
    281288    CGImageRef dockImgOS;
    282 #endif 
     289#endif
    283290};
    284291
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r2423 r2458  
    119119};
    120120
     121/** class VBoxNetworkLedTip
     122 *
     123 *  The VBoxNetworkLedTip class is an auxiliary ToolTip class
     124 *  for the Network LED indicator.
     125 */
     126class VBoxNetworkLedTip : public QToolTip
     127{
     128public:
     129
     130    VBoxNetworkLedTip (QWidget *aWidget, const CMachine &aMachine) :
     131        QToolTip (aWidget), mMachine (aMachine) {}
     132
     133    ~VBoxNetworkLedTip() { remove (parentWidget()); }
     134
     135protected:
     136
     137    void maybeTip (const QPoint &/* aPoint */)
     138    {
     139        QString toolTip = VBoxConsoleWnd::tr (
     140            "<qt>Indicates&nbsp;the&nbsp;activity&nbsp;of&nbsp;the&nbsp;network&nbsp;interfaces",
     141            "Network adapters indicator"
     142        );
     143
     144        QString devices;
     145
     146        ulong count = vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount();
     147        for (ulong slot = 0; slot < count; ++ slot)
     148        {
     149            CNetworkAdapter adapter = mMachine.GetNetworkAdapter (slot);
     150            if (adapter.GetEnabled())
     151                devices += VBoxConsoleWnd::tr ("<br><nobr>[Adapter %1 (%2): cable %3]</nobr>",
     152                                               "Network adapters indicator")
     153                    .arg (slot)
     154                    .arg (vboxGlobal().toString (adapter.GetAttachmentType()))
     155                    .arg (adapter.GetCableConnected() ?
     156                          VBoxConsoleWnd::tr ("connected", "Network adapters indicator") :
     157                          VBoxConsoleWnd::tr ("disconnected", "Network adapters indicator"));
     158        }
     159
     160        if (devices.isNull())
     161            devices = VBoxConsoleWnd::tr ("<br><nobr>[<b>All Network adapters are disabled</b>]</nobr>",
     162                                          "Network adapters indicator");
     163
     164        tip (parentWidget()->rect(), toolTip + devices);
     165    }
     166
     167private:
     168
     169    CMachine mMachine;
     170};
     171
    121172/** \class VBoxConsoleWnd
    122173 *
     
    147198    , console (0)
    148199    , mUsbLedTip (0)
     200    , mNetworkLedTip (0)
    149201    , machine_state (CEnums::InvalidMachineState)
    150202    , no_auto_close (false)
     
    164216    , dockImgBack100x75 (NULL)
    165217    , dockImgOS (NULL)
    166 #endif 
     218#endif
    167219{
    168220    if (aSelf)
     
    325377
    326378    devicesSharedFolders = new QPopupMenu (devicesMenu, "devicesSharedFolders");
     379    devicesNetworkMenu = new QPopupMenu (devicesMenu, "devicesNetworkMenu");
    327380    devicesUSBMenu = new VBoxUSBMenu (devicesMenu);
    328381    devicesVRDPMenu = new VBoxSwitchMenu (devicesMenu, devicesSwitchVrdpAction);
     
    341394    devicesSFDialogAction->addTo (devicesMenu);
    342395    devicesSFMenuSeparatorId = devicesMenu->insertSeparator();
     396    devicesMenu->insertItem (VBoxGlobal::iconSet ("nw_16px.png", "nw_disabled_16px.png"),
     397        QString::null, devicesNetworkMenu, devicesNetworkMenuId);
     398    devicesMenu->insertSeparator();
    343399    devicesSwitchVrdpAction->addTo (devicesMenu);
    344400    devicesVRDPMenuSeparatorId = devicesMenu->insertSeparator();
     
    483539    connect (devicesMountFloppyMenu, SIGNAL(aboutToShow()), this, SLOT(prepareFloppyMenu()));
    484540    connect (devicesMountDVDMenu, SIGNAL(aboutToShow()), this, SLOT(prepareDVDMenu()));
     541    connect (devicesNetworkMenu, SIGNAL(aboutToShow()), this, SLOT(prepareNetworkMenu()));
    485542
    486543    connect (devicesMountFloppyMenu, SIGNAL(activated(int)), this, SLOT(captureFloppy(int)));
     
    488545    connect (devicesUSBMenu, SIGNAL(activated(int)), this, SLOT(switchUSB(int)));
    489546    connect (devicesSharedFolders, SIGNAL(activated(int)), this, SLOT(activateSFMenu()));
     547    connect (devicesNetworkMenu, SIGNAL(activated(int)), this, SLOT(activateNetworkMenu(int)));
    490548
    491549    connect (helpWebAction, SIGNAL (activated()),
     
    503561             this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    504562    connect (sf_state, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
     563             this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
     564    connect (net_light, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    505565             this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    506566
     
    537597    SetApplicationDockTileImage (dockImgOS);
    538598    OverlayApplicationDockTileImage (dockImgStateRunning);
    539 #endif 
     599#endif
    540600}
    541601
     
    544604    if (mUsbLedTip)
    545605        delete mUsbLedTip;
     606    if (mNetworkLedTip)
     607        delete mNetworkLedTip;
    546608#ifdef Q_WS_MAC
    547609    /* release the dock images */
     
    560622    if (dockImgOS)
    561623        CGImageRelease (dockImgOS);
    562 #endif 
     624#endif
    563625}
    564626
     
    694756    }
    695757
     758    /* initialize network stuff */
     759    mNetworkLedTip = new VBoxNetworkLedTip (net_light, cmachine);
     760
    696761    /* initialize vrdp stuff */
    697762    CVRDPServer vrdpsrv = cmachine.GetVRDPServer();
     
    732797    QImage osImg75x75 = vboxGlobal().vmGuestOSTypeIcon (osType).convertToImage().smoothScale (75, 75);
    733798    QImage osImg = QImage::fromMimeSource ("dock_0.png");
    734     bitBlt (&osImg, 25, 22, 
     799    bitBlt (&osImg, 25, 22,
    735800            &osImg75x75, 0, 0,
    736801            75, 75, /* conversion_flags */ 0);
     
    738803    QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osType).convertToImage().smoothScale (100, 75);
    739804    QImage osImg = QImage::fromMimeSource ("dock_1.png");
    740     bitBlt (&osImg, 14, 22, 
     805    bitBlt (&osImg, 14, 22,
    741806            &osImg100x75, 0, 0,
    742807            100, 75, /* conversion_flags */ 0);
    743 # endif 
     808# endif
    744809    if (dockImgOS)
    745810        CGImageRelease (dockImgOS);
     
    13071372    devicesMenu->changeItem (devicesMountFloppyMenuId, tr ("Mount &Floppy"));
    13081373    devicesMenu->changeItem (devicesMountDVDMenuId, tr ("Mount &CD/DVD-ROM"));
     1374    devicesMenu->changeItem (devicesNetworkMenuId, tr ("&Network Adapters"));
    13091375    devicesMenu->changeItem (devicesUSBMenuId, tr ("&USB Devices"));
    13101376
     
    14791545        net_light->setState (count > 0 ? CEnums::DeviceIdle
    14801546                                         : CEnums::InvalidActivity);
    1481         QString tip = tr (
    1482             "<qt>Indicates&nbsp;the&nbsp;activity&nbsp;of&nbsp;the&nbsp;network&nbsp;interfaces"
    1483             "<br>[<b>%1 adapter(s)</b>]</qt>"
    1484         );
    1485         QToolTip::add (net_light, tip.arg (count));
    14861547    }
    14871548    if (element & USBStuff)
     
    20672128
    20682129/**
     2130 *  Prepares the "Network adapter" menu by populating the existent adaptors.
     2131 */
     2132void VBoxConsoleWnd::prepareNetworkMenu()
     2133{
     2134    devicesNetworkMenu->clear();
     2135    ulong count = vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount();
     2136    for (ulong slot = 0; slot < count; ++ slot)
     2137    {
     2138        CNetworkAdapter adapter = csession.GetMachine().GetNetworkAdapter (slot);
     2139        int id = devicesNetworkMenu->insertItem (tr ("Adapter %1").arg (slot));
     2140        devicesNetworkMenu->setItemEnabled (id, adapter.GetEnabled());
     2141        devicesNetworkMenu->setItemChecked (id, adapter.GetEnabled() && adapter.GetCableConnected());
     2142    }
     2143}
     2144
     2145/**
     2146 *  Switch the cable connected/disconnected for the selected network adapter
     2147 */
     2148void VBoxConsoleWnd::activateNetworkMenu (int aId)
     2149{
     2150    ulong count = vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount();
     2151    for (ulong slot = 0; slot < count; ++ slot)
     2152    {
     2153        if (aId == devicesNetworkMenu->idAt (slot))
     2154        {
     2155            CNetworkAdapter adapter = csession.GetMachine().GetNetworkAdapter (slot);
     2156            bool connected = adapter.GetCableConnected();
     2157            if (adapter.GetEnabled())
     2158                adapter.SetCableConnected (!connected);
     2159            break;
     2160        }
     2161    }
     2162}
     2163
     2164/**
    20692165 *  Captures a floppy device corresponding to a given menu id.
    20702166 */
     
    22072303    {
    22082304        devicesSharedFolders->exec (e->globalPos());
     2305    }
     2306    else
     2307    if (ind == net_light)
     2308    {
     2309        devicesNetworkMenu->exec (e->globalPos());
    22092310    }
    22102311}
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