VirtualBox

Changeset 6904 in vbox for trunk


Ignore:
Timestamp:
Feb 11, 2008 5:11:29 PM (17 years ago)
Author:
vboxsync
Message:

2669: Create VM context menu in the Selector window:

Feature implemented (context menu + pause/resume action).
Waiting for pause_dis_16.png icon.

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

Legend:

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

    r6784 r6904  
    415415#endif
    416416
    417     CSession openSession (const QUuid &id);
     417    CSession openSession (const QUuid &id, bool aExisting = false);
    418418
    419419    bool startMachine (const QUuid &id);
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxSelectorWnd.h

    r5999 r6904  
    2626#include <qapplication.h>
    2727#include <qmainwindow.h>
     28#include <qlistbox.h>
    2829#include <qgroupbox.h>
    2930#include <qaction.h>
     
    6768    void vmStart();
    6869    void vmDiscard();
     70    void vmPause (bool);
    6971    void vmRefresh();
    7072    void vmShowLogs();
     
    7476                                          bool aSnapshots,
    7577                                          bool aDescription);
     78
     79    void showContextMenu (QListBoxItem *, const QPoint &);
    7680
    7781protected:
     
    105109private:
    106110
     111    /* context menu */
     112    QPopupMenu *mVmMenu;
     113
    107114    /* actions */
    108115    QAction *fileDiskMgrAction;
     
    114121    QAction *vmStartAction;
    115122    QAction *vmDiscardAction;
     123    QAction *vmPauseAction;
    116124    QAction *vmRefreshAction;
    117125    QAction *vmShowLogsAction;
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r6851 r6904  
    18281828 *  it is no more necessary.
    18291829 */
    1830 CSession VBoxGlobal::openSession (const QUuid &id)
     1830CSession VBoxGlobal::openSession (const QUuid &id, bool aExisting)
    18311831{
    18321832    CSession session;
     
    18381838    }
    18391839
    1840     mVBox.OpenSession (session, id);
     1840    aExisting ? mVBox.OpenExistingSession (session, id) :
     1841                        mVBox.OpenSession (session, id);
    18411842    if (!mVBox.isOk())
    18421843    {
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSelectorWnd.cpp

    r5999 r6904  
    418418        "vm_discard.png", "discard_16px.png",
    419419        "vm_discard_dis.png", "discard_dis_16px.png"));
     420    vmPauseAction = new QAction (this, "vmPauseAction");
     421    vmPauseAction->setToggleAction (true);
     422    vmPauseAction->setIconSet (VBoxGlobal::iconSet (
     423        "pause_16px.png", "pause_16px.png"));
    420424    vmRefreshAction = new QAction (this, "vmRefreshAction");
    421425    vmRefreshAction->setIconSet (VBoxGlobal::iconSet (
     
    511515    menuBar()->insertItem( QString::null, fileMenu, 1);
    512516
    513     QPopupMenu *vmMenu = new QPopupMenu (this, "vmMenu");
    514     vmNewAction->addTo (vmMenu);
    515     vmConfigAction->addTo (vmMenu);
    516     vmDeleteAction->addTo (vmMenu);
    517     vmMenu->insertSeparator();
    518     vmStartAction->addTo (vmMenu);
    519     vmDiscardAction->addTo (vmMenu);
    520     vmMenu->insertSeparator();
    521     vmRefreshAction->addTo (vmMenu);
    522     vmMenu->insertSeparator();
    523     vmShowLogsAction->addTo (vmMenu);
    524 
    525     menuBar()->insertItem (QString::null, vmMenu, 2);
     517    mVmMenu = new QPopupMenu (this, "mVmMenu");
     518    vmNewAction->addTo (mVmMenu);
     519    vmConfigAction->addTo (mVmMenu);
     520    vmDeleteAction->addTo (mVmMenu);
     521    mVmMenu->insertSeparator();
     522    vmStartAction->addTo (mVmMenu);
     523    vmDiscardAction->addTo (mVmMenu);
     524    mVmMenu->insertSeparator();
     525    vmPauseAction->addTo (mVmMenu);
     526    mVmMenu->insertSeparator();
     527    vmRefreshAction->addTo (mVmMenu);
     528    mVmMenu->insertSeparator();
     529    vmShowLogsAction->addTo (mVmMenu);
     530
     531    menuBar()->insertItem (QString::null, mVmMenu, 2);
    526532
    527533    QPopupMenu *helpMenu = new QPopupMenu( this, "helpMenu" );
     
    596602    connect (vmStartAction, SIGNAL (activated()), this, SLOT (vmStart()));
    597603    connect (vmDiscardAction, SIGNAL (activated()), this, SLOT (vmDiscard()));
     604    connect (vmPauseAction, SIGNAL (toggled (bool)), this, SLOT (vmPause (bool)));
    598605    connect (vmRefreshAction, SIGNAL (activated()), this, SLOT (vmRefresh()));
    599606    connect (vmShowLogsAction, SIGNAL (activated()), this, SLOT (vmShowLogs()));
     
    616623    connect (vmListBox, SIGNAL (selected (QListBoxItem *)),
    617624             this, SLOT (vmStart()));
     625    connect (vmListBox, SIGNAL (contextMenuRequested (QListBoxItem *, const QPoint &)),
     626             this, SLOT (showContextMenu (QListBoxItem *, const QPoint &)));
    618627
    619628    connect (vmDetailsView, SIGNAL (linkClicked (const QString &)),
     
    662671        QString curVMId = item ?
    663672            QString (static_cast<VBoxVMListBoxItem*> (item)->id()) :
    664                     QString::null;
     673            QString::null;
    665674        vbox.SetExtraData (VBoxDefs::GUI_LastVMSelected, curVMId);
    666675    }
     
    960969}
    961970
     971void VBoxSelectorWnd::vmPause (bool aPause)
     972{
     973    VBoxVMListBoxItem *item = (VBoxVMListBoxItem *) vmListBox->selectedItem();
     974
     975    AssertMsgReturn (item, ("Item must be always selected here"), (void) 0);
     976
     977    CSession session = vboxGlobal().openSession (item->id(), true);
     978    if (session.isNull())
     979        return;
     980
     981    CConsole console = session.GetConsole();
     982    if (console.isNull())
     983        return;
     984
     985    if (aPause)
     986        console.Pause();
     987    else
     988        console.Resume();
     989
     990    bool ok = console.isOk();
     991    if (!ok)
     992    {
     993        if (aPause)
     994            vboxProblem().cannotPauseMachine (console);
     995        else
     996            vboxProblem().cannotResumeMachine (console);
     997    }
     998
     999    session.Close();
     1000}
     1001
    9621002void VBoxSelectorWnd::vmRefresh()
    9631003{
     
    9931033    if (item && item->id() == aID)
    9941034        vmListBoxCurrentChanged (aDetails, aSnapshots, aDescription);
     1035}
     1036
     1037void VBoxSelectorWnd::showContextMenu (QListBoxItem *aItem, const QPoint &aPoint)
     1038{
     1039    if (aItem)
     1040        mVmMenu->exec (aPoint);
    9951041}
    9961042
     
    12101256        vmDeleteAction->setEnabled (modifyEnabled);
    12111257        vmDiscardAction->setEnabled (state == CEnums::Saved && !running);
     1258        vmPauseAction->setEnabled (state == CEnums::Running ||
     1259                                   state == CEnums::Paused);
    12121260
    12131261        /* change the Start button text accordingly */
     
    12291277
    12301278            vmStartAction->setEnabled (!running);
     1279        }
     1280
     1281        /* change the Pause/Resume button text accordingly */
     1282        if (state == CEnums::Paused)
     1283        {
     1284            vmPauseAction->setMenuText (tr ("R&esume"));
     1285            vmPauseAction->setText (tr ("Resume"));
     1286            vmPauseAction->setAccel (tr ("Ctrl+P"));
     1287            vmPauseAction->setStatusTip (
     1288                tr ("Resume the execution of the virtual machine"));
     1289            vmPauseAction->blockSignals (true);
     1290            vmPauseAction->setOn (true);
     1291            vmPauseAction->blockSignals (false);
     1292        }
     1293        else
     1294        {
     1295            vmPauseAction->setMenuText (tr ("&Pause"));
     1296            vmPauseAction->setText (tr ("Pause"));
     1297            vmPauseAction->setAccel (tr ("Ctrl+P"));
     1298            vmPauseAction->setStatusTip (
     1299                tr ("Suspend the execution of the virtual machine"));
     1300            vmPauseAction->blockSignals (true);
     1301            vmPauseAction->setOn (false);
     1302            vmPauseAction->blockSignals (false);
    12311303        }
    12321304
     
    12861358        vmDeleteAction->setEnabled (item != NULL);
    12871359        vmDiscardAction->setEnabled (false);
     1360        vmPauseAction->setEnabled (false);
    12881361
    12891362        /* change the Start button text accordingly */
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