VirtualBox

Changeset 13790 in vbox for trunk


Ignore:
Timestamp:
Nov 4, 2008 4:01:42 PM (16 years ago)
Author:
vboxsync
Message:

Fe/Qt4: Added first systray support (under development, compile with VBOX_GUI_WITH_SYSTRAY in VirtualBox4_DEFS).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h

    r13580 r13790  
    3333/* Qt includes */
    3434#include <QMainWindow>
     35#ifdef VBOX_GUI_WITH_SYSTRAY
     36    #include <QSystemTrayIcon>
     37#endif
     38#include <QUuid>
    3539
    3640class VBoxSnapshotsWgt;
     
    6670
    6771    void fileMediaMgr();
     72    VBoxVMItem* getSelectedItem();
     73#ifdef VBOX_GUI_WITH_SYSTRAY
     74    void iconActivated(QSystemTrayIcon::ActivationReason aReason);
     75    void showWindow();
     76#endif
    6877    void fileSettings();
    6978    void fileExit();
     
    7180    void vmNew();
    7281    void vmSettings (const QString &aCategory = QString::null,
    73                      const QString &aControl = QString::null);
    74     void vmDelete();
    75     void vmStart();
    76     void vmDiscard();
    77     void vmPause (bool);
    78     void vmRefresh();
    79     void vmShowLogs();
     82                     const QString &aControl = QString::null,
     83                     const QUuid& = "");
     84    void vmDelete(const QUuid& = "");
     85    void vmStart (const QUuid& = "");
     86    void vmDiscard(const QUuid& = "");
     87    void vmPause (bool, const QUuid& = "");
     88    void vmRefresh(const QUuid& = "");
     89    void vmShowLogs(const QUuid& = "");
    8090
     91#ifdef VBOX_GUI_WITH_SYSTRAY
     92    void refreshSysTray();
     93#endif
    8194    void refreshVMList();
    8295    void refreshVMItem (const QUuid &aID, bool aDetails,
     
    129142    QAction *fileExitAction;
    130143    QAction *vmNewAction;
     144#ifdef VBOX_GUI_WITH_SYSTRAY
     145    QAction *trayShowWindowAction;
     146    QAction *trayExitAction;
     147#endif
    131148    QAction *vmConfigAction;
    132149    QAction *vmDeleteAction;
     
    138155
    139156    VBoxHelpActions mHelpActions;
     157
     158#ifdef VBOX_GUI_WITH_SYSTRAY
     159    /* The systray icon */
     160    QSystemTrayIcon *trayIcon;
     161    QMenu *trayIconMenu;
     162#endif
    140163
    141164    /* The vm list view/model */
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMListView.h

    r9729 r13790  
    3131#include <QDateTime>
    3232
    33 class VBoxVMItem
    34 {
    35 public:
    36     VBoxVMItem (const CMachine &aM);
     33class VBoxVMItem : public QObject
     34{
     35    Q_OBJECT;
     36
     37public:
     38
     39    enum Action
     40    {
     41        Config = 0,
     42        Delete,
     43        Start,
     44        Discard,
     45        Pause,
     46        Refresh,
     47        ShowLogs
     48    };
     49
     50public:
     51
     52    VBoxVMItem (const CMachine &aM, QObject* pParent);
    3753    virtual ~VBoxVMItem();
    3854
     
    4258    QIcon osIcon() const { return mAccessible ? vboxGlobal().vmGuestOSTypeIcon (mOSTypeId) :QPixmap (":/os_unknown.png"); }
    4359    QUuid id() const { return mId; }
    44    
     60
    4561    QString sessionStateName() const;
    4662    QIcon sessionStateIcon() const { return mAccessible ? vboxGlobal().toIcon (mState) : QPixmap (":/state_aborted_16px.png"); }
     
    4965    ULONG snapshotCount() const { return mSnapshotCount; }
    5066
     67    QAction* vmActionConfig() const { return vmConfigAction; }
     68    QAction* vmActionDelete() const { return vmDeleteAction; }
     69    QAction* vmActionStart() const { return vmStartAction; }
     70    QAction* vmActionDiscard() const { return vmDiscardAction; }
     71    QAction* vmActionPause() const { return vmPauseAction; }
     72    QAction* vmActionRefresh() const { return vmRefreshAction; }
     73    QAction* vmActionShowLogs() const { return vmShowLogsAction; }
     74
    5175    QString toolTipText() const;
    5276
    5377    bool accessible() const { return mAccessible; }
     78    bool running() const {  return (sessionState() != KSessionState_Closed); }
    5479    const CVirtualBoxErrorInfo &accessError() const { return mAccessError; }
    5580    KMachineState state() const { return mState; }
     
    6085    bool canSwitchTo() const;
    6186    bool switchTo();
     87   
     88    void updateActions();
    6289
    6390private:
    6491
    6592    /* Private member vars */
     93    QObject* mParent;
    6694    CMachine mMachine;
     95
     96    QAction *vmConfigAction;
     97    QAction *vmDeleteAction;
     98    QAction *vmStartAction;
     99    QAction *vmDiscardAction;
     100    QAction *vmPauseAction;
     101    QAction *vmRefreshAction;
     102    QAction *vmShowLogsAction;
    67103
    68104    /* Cached machine data (to minimize server requests) */
     
    82118
    83119    ULONG mPid;
     120
     121private slots:
     122
     123    void vmSettings();
     124    void vmDelete();
     125    void vmStart();
     126    void vmDiscard();
     127    void vmPause(bool aPause);
     128    void vmRefresh();
     129    void vmShowLogs();
    84130};
    85131
     
    111157
    112158    VBoxVMItem *itemById (const QUuid &aId) const;
     159    VBoxVMItem *itemByRow (int aRow) const;
    113160    QModelIndex indexById (const QUuid &aId) const;
    114161
     
    163210    void mousePressEvent (QMouseEvent *aEvent);
    164211    bool selectCurrent();
    165 }; 
     212};
    166213
    167214class VBoxVMItemPainter: public QIItemDelegate
     
    181228    inline QIcon::Mode iconMode (QStyle::State aState) const
    182229    {
    183         if (!(aState & QStyle::State_Enabled)) 
     230        if (!(aState & QStyle::State_Enabled))
    184231            return QIcon::Disabled;
    185         if (aState & QStyle::State_Selected) 
     232        if (aState & QStyle::State_Selected)
    186233            return QIcon::Selected;
    187234        return QIcon::Normal;
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp

    r13669 r13790  
    412412    fileExitAction->setMenuRole (QAction::QuitRole);
    413413    fileExitAction->setIcon (VBoxGlobal::iconSet (":/exit_16px.png"));
     414
     415#ifdef VBOX_GUI_WITH_SYSTRAY
     416    trayShowWindowAction = new QAction (this);
     417    trayShowWindowAction->setIcon (VBoxGlobal::iconSet (":/VirtualBox_16px.png"));
     418    trayShowWindowAction->setText (tr ("Sun xVM VirtualBox"));
     419   
     420    trayExitAction = new QAction (this);
     421    trayExitAction->setMenuRole (QAction::QuitRole);
     422    trayExitAction->setIcon (VBoxGlobal::iconSet (":/exit_16px.png"));
     423#endif
    414424
    415425    vmNewAction = new QAction (this);
     
    456466    mHelpActions.setup (this);
    457467
    458     /* Subwidgets */
     468#ifdef VBOX_GUI_WITH_SYSTRAY
     469    if (QSystemTrayIcon::isSystemTrayAvailable())
     470    {
     471        /* tray menu */
     472        trayIconMenu = new QMenu(this);
     473
     474        /* tray icon */
     475        trayIcon = new QSystemTrayIcon  (this);
     476        trayIcon->setIcon(QIcon (":/VirtualBox_16px.png"));
     477        trayIcon->setContextMenu (trayIconMenu);
     478
     479        connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
     480                this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
     481    }
     482#endif
    459483
    460484    /* Central widget @ horizontal layout */
     
    640664    connect (fileExitAction, SIGNAL (triggered()), this, SLOT (fileExit()));
    641665    connect (vmNewAction, SIGNAL (triggered()), this, SLOT (vmNew()));
     666
    642667    connect (vmConfigAction, SIGNAL (triggered()), this, SLOT (vmSettings()));
    643668    connect (vmDeleteAction, SIGNAL (triggered()), this, SLOT (vmDelete()));
     
    647672    connect (vmRefreshAction, SIGNAL (triggered()), this, SLOT (vmRefresh()));
    648673    connect (vmShowLogsAction, SIGNAL (triggered()), this, SLOT (vmShowLogs()));
     674
     675#ifdef VBOX_GUI_WITH_SYSTRAY
     676    connect (trayShowWindowAction, SIGNAL (triggered()), this, SLOT(showWindow()));
     677#endif
    649678
    650679    connect (mVMListView, SIGNAL (currentChanged()),
     
    699728    /* Save vm selector position */
    700729    {
    701         VBoxVMItem *item = mVMListView->selectedItem();
     730        VBoxVMItem *item = getSelectedItem();
    702731        QString curVMId = item ?
    703732            QString (item->id()) :
     
    712741// Public slots
    713742/////////////////////////////////////////////////////////////////////////////
     743
     744#ifdef VBOX_GUI_WITH_SYSTRAY
     745void VBoxSelectorWnd::iconActivated(QSystemTrayIcon::ActivationReason aReason)
     746{
     747    switch (aReason)
     748    {
     749
     750    case QSystemTrayIcon::Context:
     751
     752        refreshSysTray();
     753        break;
     754
     755    case QSystemTrayIcon::Trigger:
     756        break;
     757
     758    case QSystemTrayIcon::DoubleClick:
     759
     760        showWindow();
     761        break;
     762
     763    case QSystemTrayIcon::MiddleClick:
     764        break;
     765
     766    default:
     767        break;
     768    }
     769}
     770#endif
     771
     772VBoxVMItem* VBoxSelectorWnd::getSelectedItem()
     773{
     774    VBoxVMItem* pItem = NULL;
     775
     776    if (NULL == pItem)
     777        pItem = mVMListView->selectedItem();
     778
     779    /* pItem can be NULL here, so don't assert. */
     780    return pItem;
     781}
     782
     783#ifdef VBOX_GUI_WITH_SYSTRAY
     784void VBoxSelectorWnd::showWindow()
     785{
     786    showNormal();
     787    setFocus();
     788}
     789#endif
    714790
    715791void VBoxSelectorWnd::fileMediaMgr()
     
    769845 *  Opens the VM settings dialog.
    770846 */
    771 void VBoxSelectorWnd::vmSettings (const QString &aCategory, const QString &aControl)
     847void VBoxSelectorWnd::vmSettings (const QString &aCategory, const QString &aControl, const QUuid& a_Uuid)
    772848{
    773849    if (!aCategory.isEmpty() && aCategory [0] != '#')
     
    778854    }
    779855
    780     VBoxVMItem *item = mVMListView->selectedItem();
     856    VBoxVMItem *item = mVMModel->itemById (a_Uuid);
     857    if (NULL == item)
     858        item = getSelectedItem();
    781859
    782860    AssertMsgReturnVoid (item, ("Item must be always selected here"));
     
    819897}
    820898
    821 void VBoxSelectorWnd::vmDelete()
    822 {
    823     VBoxVMItem *item = mVMListView->selectedItem();
     899void VBoxSelectorWnd::vmDelete(const QUuid& a_Uuid)
     900{
     901    VBoxVMItem *item = mVMModel->itemById (a_Uuid);
     902    if (NULL == item)
     903        item = getSelectedItem();
    824904
    825905    AssertMsgReturnVoid (item, ("Item must be always selected here"));
     
    879959}
    880960
    881 void VBoxSelectorWnd::vmStart()
    882 {
     961void VBoxSelectorWnd::vmStart(const QUuid& a_Uuid)
     962{
     963    VBoxVMItem *item = mVMModel->itemById (a_Uuid);
     964    if (NULL == item)
     965        item = getSelectedItem();
     966
     967    AssertMsgReturn (item, ("Item must be always selected here"), (void) 0);
     968
    883969    /* we always get here when mVMListView emits the activated() signal,
    884970     * so we must explicitly check if the action is enabled or not. */
    885     if (!vmStartAction->isEnabled())
     971    if (!item->vmActionStart()->isEnabled())
    886972        return;
    887 
    888     VBoxVMItem *item = mVMListView->selectedItem();
    889 
    890     AssertMsg (item, ("Item must be always selected here"));
    891973
    892974#if defined (VBOX_GUI_SEPARATE_VM_PROCESS)
     
    9561038}
    9571039
    958 void VBoxSelectorWnd::vmDiscard()
    959 {
    960     VBoxVMItem *item = mVMListView->selectedItem();
     1040void VBoxSelectorWnd::vmDiscard(const QUuid& a_Uuid)
     1041{
     1042    VBoxVMItem *item = mVMModel->itemById (a_Uuid);
     1043    if (NULL == item)
     1044        item = getSelectedItem();
    9611045
    9621046    AssertMsgReturn (item, ("Item must be always selected here"), (void) 0);
     
    9901074}
    9911075
    992 void VBoxSelectorWnd::vmPause (bool aPause)
    993 {
    994     VBoxVMItem *item = mVMListView->selectedItem();
     1076void VBoxSelectorWnd::vmPause (bool aPause, const QUuid& a_Uuid)
     1077{
     1078    VBoxVMItem *item = mVMModel->itemById (a_Uuid);
     1079    if (NULL == item)
     1080        item = getSelectedItem();
    9951081
    9961082    AssertMsgReturn (item, ("Item must be always selected here"), (void) 0);
     
    10211107}
    10221108
    1023 void VBoxSelectorWnd::vmRefresh()
    1024 {
    1025     VBoxVMItem *item = mVMListView->selectedItem();
     1109void VBoxSelectorWnd::vmRefresh(const QUuid& a_Uuid)
     1110{
     1111    VBoxVMItem *item = mVMModel->itemById (a_Uuid);
     1112    if (NULL == item)
     1113        item = getSelectedItem();
    10261114
    10271115    AssertMsgReturn (item, ("Item must be always selected here"), (void) 0);
     
    10331121}
    10341122
    1035 void VBoxSelectorWnd::vmShowLogs()
    1036 {
    1037     VBoxVMItem *item = mVMListView->selectedItem();
     1123void VBoxSelectorWnd::vmShowLogs(const QUuid& a_Uuid)
     1124{
     1125    VBoxVMItem *item = mVMModel->itemById (a_Uuid);
     1126    if (NULL == item)
     1127        item = getSelectedItem();
     1128
    10381129    CMachine machine = item->machine();
    10391130    VBoxVMLogViewer::createLogViewer (this, machine);
    10401131}
     1132
     1133#ifdef VBOX_GUI_WITH_SYSTRAY
     1134void VBoxSelectorWnd::refreshSysTray()
     1135{
     1136    if (false == QSystemTrayIcon::isSystemTrayAvailable())
     1137        return;
     1138
     1139    Assert(trayIcon);
     1140    Assert(trayIconMenu);
     1141
     1142    trayIcon->setVisible (true);
     1143    trayIconMenu->clear();
     1144    trayIconMenu->addAction (trayExitAction);
     1145    trayIconMenu->addSeparator();
     1146
     1147    VBoxVMItem* pItem = NULL;
     1148    QMenu* pSubMenu = NULL;
     1149    for (int i = 0; i < mVMModel->rowCount(); i++)
     1150    {
     1151        pItem = mVMModel->itemByRow(i);
     1152        Assert(pItem);
     1153
     1154        pSubMenu = new QMenu (pItem->name());
     1155        Assert(pSubMenu);
     1156        pSubMenu->setIcon (pItem->osIcon());
     1157        if(pItem->accessible())
     1158        {
     1159            pSubMenu->addAction (pItem->vmActionConfig());
     1160            pSubMenu->addAction (pItem->vmActionDelete());
     1161            pSubMenu->addSeparator();
     1162            pSubMenu->addAction (pItem->vmActionStart());
     1163            pSubMenu->addAction (pItem->vmActionDiscard());
     1164            if (pItem->running())
     1165            {
     1166                pSubMenu->addSeparator();
     1167                pSubMenu->addAction (pItem->vmActionPause());
     1168            }
     1169            pSubMenu->addSeparator();
     1170            pSubMenu->addAction (pItem->vmActionShowLogs());
     1171        }
     1172        else
     1173        {
     1174            pSubMenu->addAction (pItem->vmActionDelete());
     1175            pSubMenu->addAction (pItem->vmActionRefresh());
     1176        }
     1177
     1178        trayIconMenu->addMenu (pSubMenu);
     1179    }
     1180
     1181    trayIconMenu->addSeparator();
     1182    trayIconMenu->addAction (fileExitAction);
     1183
     1184    trayIconMenu->setVisible (true);
     1185}
     1186#endif
    10411187
    10421188void VBoxSelectorWnd::refreshVMList()
     
    10461192    for (CMachineVector::ConstIterator m = vec.begin();
    10471193         m != vec.end(); ++ m)
    1048         mVMModel->addItem (new VBoxVMItem (*m));
     1194        mVMModel->addItem (new VBoxVMItem (*m, this));
    10491195    mVMModel->sort();
    10501196
    10511197    vmListViewCurrentChanged();
     1198
     1199#ifdef VBOX_GUI_WITH_SYSTRAY
     1200    refreshSysTray();
     1201#endif
    10521202}
    10531203
     
    12471397
    12481398void VBoxSelectorWnd::vmListViewCurrentChanged (bool aRefreshDetails,
    1249                                                bool aRefreshSnapshots,
    1250                                                bool aRefreshDescription)
    1251 {
    1252     VBoxVMItem *item = mVMListView->selectedItem();
     1399                                                bool aRefreshSnapshots,
     1400                                                bool aRefreshDescription)
     1401{
     1402    VBoxVMItem *item = getSelectedItem();
    12531403
    12541404    if (item && item->accessible())
     
    14791629        if (!m.isNull())
    14801630        {
    1481             mVMModel->addItem (new VBoxVMItem (m));
     1631            mVMModel->addItem (new VBoxVMItem (m, this));
    14821632            mVMModel->sort();
    14831633            /* Make sure the description, ... pages are properly updated.
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMListView.cpp

    r12058 r13790  
    2323#include "VBoxVMListView.h"
    2424#include "VBoxProblemReporter.h"
     25#include "VBoxSelectorWnd.h"
    2526
    2627/* Qt includes */
     
    134135#endif
    135136
    136 VBoxVMItem::VBoxVMItem (const CMachine &aM)
    137     : mMachine (aM)
    138 {
     137VBoxVMItem::VBoxVMItem (const CMachine &aM, QObject* pParent)
     138    : mMachine (aM), mParent(pParent)
     139{
     140    vmConfigAction = new QAction (this);
     141    vmConfigAction->setIcon (VBoxGlobal::iconSetFull (
     142          QSize (32, 32), QSize (16, 16),
     143          ":/vm_settings_32px.png", ":/settings_16px.png",
     144          ":/vm_settings_disabled_32px.png", ":/settings_dis_16px.png"));
     145    vmDeleteAction = new QAction (this);
     146    vmDeleteAction->setIcon (VBoxGlobal::iconSetFull (
     147          QSize (32, 32), QSize (16, 16),
     148          ":/vm_delete_32px.png", ":/delete_16px.png",
     149          ":/vm_delete_disabled_32px.png", ":/delete_dis_16px.png"));
     150     vmStartAction = new QAction (this);
     151     vmStartAction->setIcon (VBoxGlobal::iconSetFull (
     152          QSize (32, 32), QSize (16, 16),
     153          ":/vm_start_32px.png", ":/start_16px.png",
     154          ":/vm_start_disabled_32px.png", ":/start_dis_16px.png"));
     155    vmDiscardAction = new QAction (this);
     156    vmDiscardAction->setIcon (VBoxGlobal::iconSetFull (
     157          QSize (32, 32), QSize (16, 16),
     158          ":/vm_discard_32px.png", ":/discard_16px.png",
     159          ":/vm_discard_disabled_32px.png", ":/discard_dis_16px.png"));
     160    vmPauseAction = new QAction (this);
     161    vmPauseAction->setCheckable (true);
     162    vmPauseAction->setIcon (VBoxGlobal::iconSetFull (
     163          QSize (32, 32), QSize (16, 16),
     164          ":/vm_pause_32px.png", ":/pause_16px.png",
     165          ":/vm_pause_disabled_32px.png", ":/pause_disabled_16px.png"));
     166    vmRefreshAction = new QAction (this);
     167    vmRefreshAction->setIcon (VBoxGlobal::iconSetFull (
     168          QSize (32, 32), QSize (16, 16),
     169          ":/refresh_32px.png", ":/refresh_16px.png",
     170          ":/refresh_disabled_32px.png", ":/refresh_disabled_16px.png"));
     171    vmShowLogsAction = new QAction (this);
     172    vmShowLogsAction->setIcon (VBoxGlobal::iconSetFull (
     173          QSize (32, 32), QSize (16, 16),
     174          ":/vm_show_logs_32px.png", ":/show_logs_16px.png",
     175          ":/vm_show_logs_disabled_32px.png", ":/show_logs_disabled_16px.png"));
     176
    139177    recache();
     178
     179    connect (vmConfigAction, SIGNAL (triggered()), this, SLOT (vmSettings()));
     180    connect (vmDeleteAction, SIGNAL (triggered()), this, SLOT (vmDelete()));
     181    connect (vmStartAction, SIGNAL (triggered()), this, SLOT (vmStart()));
     182    connect (vmDiscardAction, SIGNAL (triggered()), this, SLOT (vmDiscard()));
     183    connect (vmPauseAction, SIGNAL (toggled (bool)), this, SLOT (vmPause (bool)));
     184    connect (vmRefreshAction, SIGNAL (triggered()), this, SLOT (vmRefresh()));
     185    connect (vmShowLogsAction, SIGNAL (triggered()), this, SLOT (vmShowLogs()));
     186   
     187    updateActions();
    140188}
    141189
     
    150198{
    151199    return mAccessible ? vboxGlobal().toString (mState) : VBoxVMListView::tr ("Inaccessible");
     200}
     201
     202void VBoxVMItem::vmSettings()
     203{
     204    VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent);
     205    Assert (pWnd);
     206    emit pWnd->vmSettings(NULL, NULL, mId);
     207}
     208
     209void VBoxVMItem::vmDelete()
     210{
     211    VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent);
     212    Assert (pWnd);
     213    emit pWnd->vmDelete(mId);
     214}
     215
     216void VBoxVMItem::vmStart()
     217{
     218    VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent);
     219    Assert (pWnd);
     220    emit pWnd->vmStart(mId);
     221}
     222
     223void VBoxVMItem::vmDiscard()
     224{
     225    VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent);
     226    Assert (pWnd);
     227    emit pWnd->vmDiscard(mId);
     228}
     229
     230void VBoxVMItem::vmPause(bool aPause)
     231{
     232    VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent);
     233    Assert (pWnd);
     234    emit pWnd->vmPause(aPause, mId);
     235}
     236
     237void VBoxVMItem::vmRefresh()
     238{
     239    VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent);
     240    Assert (pWnd);
     241    emit pWnd->vmRefresh(mId);
     242}
     243
     244void VBoxVMItem::vmShowLogs()
     245{
     246    VBoxSelectorWnd* pWnd = qobject_cast<VBoxSelectorWnd*>(mParent);
     247    Assert (pWnd);
     248    emit pWnd->vmShowLogs(mId);
    152249}
    153250
     
    199296    {
    200297        QString name = mMachine.GetName();
     298        setObjectName(name);
    201299        CSnapshot snp = mMachine.GetCurrentSnapshot();
    202300        mSnapshotName = snp.isNull() ? QString::null : snp.GetName();
     
    385483}
    386484
     485void VBoxVMItem::updateActions()
     486{
     487    if (accessible())
     488    {
     489        CMachine m = machine();
     490
     491        KMachineState s = state();
     492        bool run = running();
     493        bool modifyEnabled = !run && s != KMachineState_Saved;
     494
     495        /* enable/disable modify actions */
     496        vmConfigAction->setEnabled (modifyEnabled);
     497        vmDeleteAction->setEnabled (modifyEnabled);
     498        vmDiscardAction->setEnabled (s == KMachineState_Saved && !run);
     499        vmPauseAction->setEnabled (s == KMachineState_Running ||
     500                                   s == KMachineState_Paused);
     501
     502        /* change the Start button text accordingly */
     503        if (s >= KMachineState_Running)
     504        {
     505            vmStartAction->setText (tr ("S&how"));
     506            vmStartAction->setStatusTip (
     507                tr ("Switch to the window of the selected virtual machine"));
     508
     509            vmStartAction->setEnabled (canSwitchTo());
     510        }
     511        else
     512        {
     513            vmStartAction->setText (tr ("S&tart"));
     514            vmStartAction->setStatusTip (
     515                tr ("Start the selected virtual machine"));
     516
     517            vmStartAction->setEnabled (!run);
     518        }
     519
     520        /* change the Pause/Resume button text accordingly */
     521        if (s == KMachineState_Paused)
     522        {
     523            vmPauseAction->setText (tr ("R&esume"));
     524            vmPauseAction->setStatusTip (
     525                tr ("Resume the execution of the virtual machine"));
     526            vmPauseAction->blockSignals (true);
     527            vmPauseAction->setChecked (true);
     528            vmPauseAction->blockSignals (false);
     529        }
     530        else
     531        {
     532            vmPauseAction->setText (tr ("&Pause"));
     533            vmPauseAction->setStatusTip (
     534                tr ("Suspend the execution of the virtual machine"));
     535            vmPauseAction->blockSignals (true);
     536            vmPauseAction->setChecked (false);
     537            vmPauseAction->blockSignals (false);
     538        }
     539
     540        /* disable Refresh for accessible machines */
     541        vmRefreshAction->setEnabled (false);
     542
     543        /* enable the show log item for the selected vm */
     544        vmShowLogsAction->setEnabled (true);
     545    }
     546    else
     547    {   
     548        vmRefreshAction->setEnabled (true);   
     549
     550        /* disable modify actions */
     551        vmConfigAction->setEnabled (false);
     552        vmDeleteAction->setEnabled (true);
     553        vmDiscardAction->setEnabled (false);
     554        vmPauseAction->setEnabled (false);
     555
     556        /* change the Start button text accordingly */
     557        vmStartAction->setText (tr ("S&tart"));
     558        vmStartAction->setStatusTip (
     559            tr ("Start the selected virtual machine"));
     560        vmStartAction->setEnabled (false);
     561
     562        /* disable the show log item for the selected vm */
     563        vmShowLogsAction->setEnabled (false);
     564    }
     565     
     566    vmConfigAction->setText (tr ("&Settings..."));
     567    vmConfigAction->setStatusTip (tr ("Configure the selected virtual machine"));
     568   
     569    vmDeleteAction->setText (tr ("&Delete"));
     570    vmDeleteAction->setStatusTip (tr ("Delete the selected virtual machine"));
     571   
     572    vmDiscardAction->setText (tr ("D&iscard"));
     573    vmDiscardAction->setStatusTip (
     574        tr ("Discard the saved state of the selected virtual machine"));
     575   
     576    vmRefreshAction->setText (tr ("&Refresh"));
     577    vmRefreshAction->setStatusTip (
     578        tr ("Refresh the accessibility state of the selected virtual machine"));
     579   
     580    vmShowLogsAction->setText (tr ("Show &Log..."));
     581    vmShowLogsAction->setIconText (tr ("Log", "icon text"));
     582    vmShowLogsAction->setStatusTip (
     583        tr ("Show the log files of the selected virtual machine"));
     584}
     585
    387586/* VBoxVMModel class */
    388587
     
    421620{
    422621    Assert (aItem);
     622    aItem->updateActions();
    423623    if (aItem->recache())
    424624        sort();
     
    455655            return item;
    456656    return NULL;
     657}
     658
     659VBoxVMItem *VBoxVMModel::itemByRow (int aRow) const
     660{
     661    return mVMItemList.at (aRow);
    457662}
    458663
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