VirtualBox

Changeset 14449 in vbox for trunk


Ignore:
Timestamp:
Nov 21, 2008 11:10:23 AM (16 years ago)
Author:
vboxsync
Message:

Fe/Qt4: Systray:

  • Added ability to disable systray menu using the "guiFeatures" -> "noSystrayMenu" property (GUI entry not implemented yet).
  • Added state icons to VM sub menu entries (instead of OS icons).
  • Changed VM sub menus only having basic commands for now (start/show, pause/resume, delete).
  • Fixed showing the selector window using the systray menu (force to front).
  • Misc small bugfixes / code cleanup.
Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
2 edited

Legend:

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

    r14355 r14449  
    147147    QAction *vmShowLogsAction;
    148148
    149 #ifdef VBOX_GUI_WITH_SYSTRAY
    150     QAction *mTrayShowWindowAction;
    151 #endif
    152 
    153149    VBoxHelpActions mHelpActions;
    154150
     
    214210private:
    215211
     212    bool mActive;           /* Is systray menu active/available? */
     213
    216214    /* The vm list model */
    217215    VBoxVMModel *mVMModel;
     
    219217    VBoxSelectorWnd* mParent;
    220218    QMenu *mTrayIconMenu;
     219
     220    QAction *mShowSelectorAction;
     221    QAction *mExitSelectorAction;
    221222    QAction *mVmConfigAction;
    222223    QAction *mVmDeleteAction;
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp

    r14441 r14449  
    383383    , doneInaccessibleWarningOnce (false)
    384384{
     385    VBoxGlobalSettings settings = vboxGlobal().settings();
     386
    385387    if (aSelf)
    386388        *aSelf = this;
     
    565567
    566568#ifdef VBOX_GUI_WITH_SYSTRAY
    567     mTrayShowWindowAction = new QAction (this);
    568     Assert (mTrayShowWindowAction);
    569     mTrayShowWindowAction->setIcon (VBoxGlobal::iconSet (":/VirtualBox_16px.png"));
    570     mTrayShowWindowAction->setText (tr ("Sun xVM VirtualBox"));
    571 
    572     if (QSystemTrayIcon::isSystemTrayAvailable())
    573     {
    574         mTrayIcon = new VBoxTrayIcon (this, mVMModel);
    575         Assert (mTrayIcon);
    576         connect (mTrayIcon, SIGNAL (activated (QSystemTrayIcon::ActivationReason)),
    577                 this, SLOT (trayIconActivated (QSystemTrayIcon::ActivationReason)));
    578     }
     569    mTrayIcon = new VBoxTrayIcon (this, mVMModel);
     570    Assert (mTrayIcon);
     571    connect (mTrayIcon, SIGNAL (activated (QSystemTrayIcon::ActivationReason)),
     572             this, SLOT (trayIconActivated (QSystemTrayIcon::ActivationReason)));
    579573#endif
    580574
     
    653647    connect (vmShowLogsAction, SIGNAL (triggered()), this, SLOT (vmShowLogs()));
    654648
    655 #ifdef VBOX_GUI_WITH_SYSTRAY
    656     connect (mTrayShowWindowAction, SIGNAL (triggered()), this, SLOT (showWindow()));
    657 #endif
    658 
    659649    connect (mVMListView, SIGNAL (currentChanged()),
    660650             this, SLOT (vmListViewCurrentChanged()));
     
    714704        vbox.SetExtraData (VBoxDefs::GUI_LastVMSelected, curVMId);
    715705    }
     706
     707#ifdef VBOX_GUI_WITH_SYSTRAY
     708    /* Delete systray menu object */
     709    delete mTrayIcon;
     710#endif
     711
    716712    /* Delete the items from our model */
    717713    mVMModel->clear();
     
    11381134{
    11391135    showNormal();
    1140     setFocus();
     1136    raise();
     1137    activateWindow();
    11411138}
    11421139
     
    16061603VBoxTrayIcon::VBoxTrayIcon (VBoxSelectorWnd* aParent, VBoxVMModel* aVMModel)
    16071604{
     1605    mShowSelectorAction = new QAction (this);
     1606    Assert (mShowSelectorAction);
     1607    mShowSelectorAction->setIcon (VBoxGlobal::iconSet (
     1608        ":/VirtualBox_16px.png"));
     1609    mShowSelectorAction->setText (VBoxVMListView::tr ("Show Selector Window"));
     1610    mShowSelectorAction->setStatusTip (VBoxVMListView::tr ("Shows the selector window assigned to this menu"));
     1611    mExitSelectorAction = new QAction (this);
     1612    Assert (mExitSelectorAction);
     1613    mExitSelectorAction->setIcon (VBoxGlobal::iconSet (
     1614        ":/exit_16px.png"));
     1615    mExitSelectorAction->setText (VBoxVMListView::tr ("Exit Selector Window"));
     1616    mExitSelectorAction->setStatusTip (VBoxVMListView::tr ("Exits the selector window assigned to this menu"));
     1617
    16081618    mVmConfigAction = new QAction (this);
    16091619    Assert (mVmConfigAction);
     
    16591669    setContextMenu (mTrayIconMenu);
    16601670
     1671    VBoxGlobalSettings settings = vboxGlobal().settings();
     1672    mActive = QSystemTrayIcon::isSystemTrayAvailable() &&
     1673              !settings.isFeatureActive ("noSystrayMenu");
     1674
     1675    connect (mShowSelectorAction, SIGNAL (triggered()), mParent, SLOT (showWindow()));
     1676    connect (mExitSelectorAction, SIGNAL (triggered()), mParent, SLOT (fileExit()));
     1677
    16611678    retranslateUi();
    16621679}
     
    16641681VBoxTrayIcon::~VBoxTrayIcon ()
    16651682{
    1666 
     1683    hide();
    16671684}
    16681685
     
    16721689    QMenu *pMenu = NULL;
    16731690    QVariant vID;
     1691
     1692    if (!mActive)
     1693        return;
     1694
    16741695    if ((pMenu = qobject_cast<QMenu*>(sender())))
    16751696    {
     
    16911712        CMachine m = pItem->machine();
    16921713        KMachineState s = pItem->state();
    1693         bool bRunning = pItem->sessionState() != KSessionState_Closed;
    1694         bool bModifyEnabled = !bRunning && s != KMachineState_Saved;
     1714        bool running = pItem->sessionState() != KSessionState_Closed;
     1715        bool modifyEnabled = !running && s != KMachineState_Saved;
    16951716
    16961717        /* Settings */
    1697         mVmConfigAction->setEnabled (bModifyEnabled);
     1718        mVmConfigAction->setEnabled (modifyEnabled);
    16981719
    16991720        /* Delete */
    1700         mVmDeleteAction->setEnabled (bModifyEnabled);
     1721        mVmDeleteAction->setEnabled (modifyEnabled);
    17011722
    17021723        /* Discard */
    1703         mVmDiscardAction->setEnabled (s == KMachineState_Saved && !bRunning);
     1724        mVmDiscardAction->setEnabled (s == KMachineState_Saved && !running);
    17041725
    17051726        /* Change the Start button text accordingly */
     
    17161737            mVmStartAction->setStatusTip (
    17171738                  VBoxVMListView::tr ("Start the selected virtual machine"));
    1718             mVmStartAction->setEnabled (!bRunning);
     1739            mVmStartAction->setEnabled (!running);
    17191740        }
    17201741
     
    17771798    }
    17781799
    1779     /* Build sub menu entries. */
    1780     pMenu->addAction (mVmConfigAction);
     1800    /* Build sub menu entries (add rest of sub menu entries later here). */
     1801    pMenu->addAction (mVmStartAction);
     1802    pMenu->addAction (mVmPauseAction);
    17811803    pMenu->addAction (mVmDeleteAction);
    1782     pMenu->addSeparator();
    1783     pMenu->addAction (mVmStartAction);
    1784     pMenu->addAction (mVmDiscardAction);
    1785     pMenu->addAction (mVmPauseAction);
    1786     pMenu->addSeparator();
    1787     pMenu->addAction (mVmShowLogsAction);
    17881804}
    17891805
    17901806void VBoxTrayIcon::retranslateUi ()
    17911807{
     1808    if (!mActive)
     1809        return;
     1810
    17921811    mVmConfigAction->setText (VBoxVMListView::tr ("&Settings..."));
    17931812    mVmConfigAction->setStatusTip (VBoxVMListView::tr ("Configure the selected virtual machine"));
     
    17961815    mVmDeleteAction->setStatusTip (VBoxVMListView::tr ("Delete the selected virtual machine"));
    17971816
     1817    mVmPauseAction->setText (VBoxVMListView::tr ("&Pause"));
     1818    mVmPauseAction->setStatusTip (VBoxVMListView::tr ("Suspend the execution of the virtual machine"));
     1819
    17981820    mVmDiscardAction->setText (VBoxVMListView::tr ("D&iscard"));
    17991821    mVmDiscardAction->setStatusTip (VBoxVMListView::tr ("Discard the saved state of the selected virtual machine"));
     
    18071829    VBoxVMItem* pItem = NULL;
    18081830    QVariant vID;
     1831
     1832    if (!mActive)
     1833        return;
     1834
    18091835    if (QMenu *pMenu = qobject_cast<QMenu*>(sender()))
    18101836    {
     
    18211847void VBoxTrayIcon::refresh ()
    18221848{
    1823     if (false == QSystemTrayIcon::isSystemTrayAvailable())
     1849    if (!mActive)
    18241850        return;
    18251851
     
    18271853    AssertReturnVoid (mTrayIconMenu);
    18281854
    1829     setVisible (true);
    18301855    mTrayIconMenu->clear();
    18311856
     
    18351860
    18361861    int iCurItemCount = 0;
     1862
     1863    mTrayIconMenu->addAction (mShowSelectorAction);
    18371864
    18381865    for (int i = 0; i < mVMModel->rowCount(); i++, iCurItemCount++)
     
    18501877        }
    18511878
    1852         QString strStatus;
    1853         if (pItem->state() >= KMachineState_Running)
    1854             strStatus = "(R)";
    1855 
    1856         pSubMenu = new QMenu (QString ("&%1. %2 %3")
    1857                               .arg ((iCurItemCount + 1) % 100).arg (pItem->name()).arg (strStatus));
     1879        pSubMenu = new QMenu (QString ("&%1. %2")
     1880                              .arg ((iCurItemCount + 1) % 100).arg (pItem->name()));
    18581881        Assert (pSubMenu);
    1859         pSubMenu->setIcon (pItem->osIcon());
     1882        pSubMenu->setIcon (pItem->sessionStateIcon());
    18601883
    18611884        QAction *pAction = NULL;
     
    18681891        pCurMenu->addMenu (pSubMenu);
    18691892    }
     1893
     1894    mTrayIconMenu->addAction (mExitSelectorAction);
     1895
     1896    /* We're done constructing the menu, show it */
     1897    setVisible (true);
    18701898}
    18711899
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