Changeset 14296 in vbox for trunk/src/VBox
- Timestamp:
- Nov 18, 2008 12:36:47 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h
r14046 r14296 44 44 class VBoxVMModel; 45 45 class VBoxVMItem; 46 class VBoxTrayIcon; 46 47 47 48 class QTabWidget; … … 49 50 class QEvent; 50 51 51 class VBoxSelectorWnd : public QIWithRetranslateUI2 <QMainWindow>52 class VBoxSelectorWnd : public QIWithRetranslateUI2 <QMainWindow> 52 53 { 53 54 Q_OBJECT; … … 82 83 void vmRefresh (const QUuid & = QUuid_null); 83 84 void vmShowLogs (const QUuid & = QUuid_null); 84 85 #ifdef VBOX_GUI_WITH_SYSTRAY86 void refreshSysTray (bool aRetranslate = false);87 #endif88 85 89 86 void refreshVMList(); … … 159 156 #ifdef VBOX_GUI_WITH_SYSTRAY 160 157 /* The systray icon */ 161 QSystemTrayIcon *mTrayIcon; 162 QMenu *mTrayIconMenu; 158 VBoxTrayIcon *mTrayIcon; 163 159 #endif 164 160 … … 179 175 }; 180 176 177 #ifdef VBOX_GUI_WITH_SYSTRAY 178 179 Q_DECLARE_METATYPE(QUuid); 180 181 class VBoxTrayIcon : public QSystemTrayIcon 182 { 183 Q_OBJECT; 184 185 public: 186 187 VBoxTrayIcon (VBoxSelectorWnd* aParent, VBoxVMModel* aVMModel); 188 virtual ~VBoxTrayIcon (); 189 190 void refresh (); 191 void retranslateUi (); 192 193 protected: 194 195 VBoxVMItem* GetItem (QObject* aObject); 196 197 signals: 198 199 public slots: 200 201 202 private slots: 203 204 void showSubMenu(); 205 void hideSubMenu (); 206 207 void vmSettings(); 208 void vmDelete(); 209 void vmStart(); 210 void vmDiscard(); 211 void vmPause(bool aPause); 212 void vmRefresh(); 213 void vmShowLogs(); 214 215 private: 216 217 /* The vm list model */ 218 VBoxVMModel *mVMModel; 219 220 VBoxSelectorWnd* mParent; 221 QMenu *mTrayIconMenu; 222 QAction *mVmConfigAction; 223 QAction *mVmDeleteAction; 224 QAction *mVmStartAction; 225 QAction *mVmDiscardAction; 226 QAction *mVmPauseAction; 227 QAction *mVmRefreshAction; 228 QAction *mVmShowLogsAction; 229 }; 230 231 #endif // VBOX_GUI_WITH_SYSTRAY 232 181 233 #endif // __VBoxSelectorWnd_h__ -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMListView.h
r14022 r14296 67 67 ULONG snapshotCount() const { return mSnapshotCount; } 68 68 69 QAction* vmActionConfig() const { return vmConfigAction; }70 QAction* vmActionDelete() const { return vmDeleteAction; }71 QAction* vmActionStart() const { return vmStartAction; }72 QAction* vmActionDiscard() const { return vmDiscardAction; }73 QAction* vmActionPause() const { return vmPauseAction; }74 QAction* vmActionRefresh() const { return vmRefreshAction; }75 QAction* vmActionShowLogs() const { return vmShowLogsAction; }76 77 69 QString toolTipText() const; 78 70 … … 88 80 bool switchTo(); 89 81 90 /* Updates all internal actions depending on the VM's state. */91 void updateActions();92 void retranslateUi();93 94 82 private: 95 83 … … 97 85 VBoxSelectorWnd *mParent; 98 86 CMachine mMachine; 99 100 QAction *vmConfigAction;101 QAction *vmDeleteAction;102 QAction *vmStartAction;103 QAction *vmDiscardAction;104 QAction *vmPauseAction;105 QAction *vmRefreshAction;106 QAction *vmShowLogsAction;107 87 108 88 /* Cached machine data (to minimize server requests) */ … … 122 102 123 103 ULONG mPid; 124 125 private slots:126 127 void vmSettings();128 void vmDelete();129 void vmStart();130 void vmDiscard();131 void vmPause(bool aPause);132 void vmRefresh();133 void vmShowLogs();134 104 }; 135 105 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp
r14053 r14296 450 450 ":/vm_show_logs_disabled_32px.png", ":/show_logs_disabled_16px.png")); 451 451 452 #ifdef VBOX_GUI_WITH_SYSTRAY453 mTrayShowWindowAction = new QAction (this);454 mTrayShowWindowAction->setIcon (VBoxGlobal::iconSet (":/VirtualBox_16px.png"));455 mTrayShowWindowAction->setText (tr ("Sun xVM VirtualBox"));456 457 mTrayExitAction = new QAction (this);458 mTrayExitAction->setMenuRole (QAction::QuitRole);459 mTrayExitAction->setIcon (VBoxGlobal::iconSet (":/exit_16px.png"));460 #endif461 462 452 mHelpActions.setup (this); 463 464 #ifdef VBOX_GUI_WITH_SYSTRAY465 if (QSystemTrayIcon::isSystemTrayAvailable())466 {467 /* tray menu */468 mTrayIconMenu = new QMenu (this);469 470 /* tray icon */471 mTrayIcon = new QSystemTrayIcon (this);472 mTrayIcon->setIcon (QIcon (":/VirtualBox_16px.png"));473 mTrayIcon->setContextMenu (mTrayIconMenu);474 475 connect (mTrayIcon, SIGNAL (activated (QSystemTrayIcon::ActivationReason)),476 this, SLOT (trayIconActivated (QSystemTrayIcon::ActivationReason)));477 }478 #endif479 453 480 454 /* Central widget @ horizontal layout */ … … 589 563 mHelpMenu = menuBar()->addMenu (QString::null); 590 564 mHelpActions.addTo (mHelpMenu); 565 566 #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 mTrayExitAction = new QAction (this); 573 Assert (mTrayExitAction); 574 mTrayExitAction->setMenuRole (QAction::QuitRole); 575 mTrayExitAction->setIcon (VBoxGlobal::iconSet (":/exit_16px.png")); 576 577 if (QSystemTrayIcon::isSystemTrayAvailable()) 578 { 579 mTrayIcon = new VBoxTrayIcon (this, mVMModel); 580 Assert (mTrayIcon); 581 connect (mTrayIcon, SIGNAL (activated (QSystemTrayIcon::ActivationReason)), 582 this, SLOT (trayIconActivated (QSystemTrayIcon::ActivationReason))); 583 } 584 #endif 591 585 592 586 retranslateUi(); … … 909 903 AssertMsgReturnVoid (item, ("Item must be always selected here")); 910 904 911 /* we always get here when mVMListView emits the activated() signal,905 /* We always get here when mVMListView emits the activated() signal, 912 906 * so we must explicitly check if the action is enabled or not. */ 913 if (!item->vmActionStart()->isEnabled()) 914 return; 907 if (aUuid.isNull()) /* If Uuid is NULL, this function is called from the mVMListView activated() signal. */ 908 { 909 if (!vmStartAction->isEnabled()) 910 return; 911 } 915 912 916 913 #if defined (VBOX_GUI_SEPARATE_VM_PROCESS) … … 1071 1068 } 1072 1069 1073 #ifdef VBOX_GUI_WITH_SYSTRAY1074 1075 void VBoxSelectorWnd::refreshSysTray (bool aRetranslate)1076 {1077 if (false == QSystemTrayIcon::isSystemTrayAvailable())1078 return;1079 1080 AssertReturnVoid (mTrayIcon);1081 AssertReturnVoid (mTrayIconMenu);1082 1083 if (!aRetranslate)1084 {1085 mTrayIcon->setVisible (true);1086 mTrayIconMenu->clear();1087 mTrayIconMenu->addAction (mTrayExitAction);1088 mTrayIconMenu->addSeparator();1089 }1090 1091 VBoxVMItem* pItem = NULL;1092 QMenu* pCurMenu = mTrayIconMenu;1093 QMenu* pSubMenu = NULL;1094 1095 int iCurItemCount = 0;1096 1097 for (int i = 0; i < mVMModel->rowCount(); i++, iCurItemCount++)1098 {1099 pItem = mVMModel->itemByRow(i);1100 Assert(pItem);1101 1102 if (aRetranslate)1103 {1104 pItem->retranslateUi();1105 continue;1106 }1107 else1108 {1109 if (iCurItemCount > 10) /* 10 machines per sub menu. */1110 {1111 pSubMenu = new QMenu (tr ("&Other Machines...", "tray menu"));1112 Assert(pSubMenu);1113 pCurMenu->addMenu (pSubMenu);1114 pCurMenu = pSubMenu;1115 iCurItemCount = 0;1116 }1117 1118 pSubMenu = new QMenu (QString ("&%1. %2")1119 .arg ((iCurItemCount + 1) % 10).arg (pItem->name()));1120 Assert(pSubMenu);1121 pSubMenu->setIcon (pItem->osIcon());1122 if(pItem->accessible())1123 {1124 pSubMenu->addAction (pItem->vmActionConfig());1125 pSubMenu->addAction (pItem->vmActionDelete());1126 pSubMenu->addSeparator();1127 pSubMenu->addAction (pItem->vmActionStart());1128 pSubMenu->addAction (pItem->vmActionDiscard());1129 if (pItem->running())1130 {1131 pSubMenu->addSeparator();1132 pSubMenu->addAction (pItem->vmActionPause());1133 }1134 pSubMenu->addSeparator();1135 pSubMenu->addAction (pItem->vmActionShowLogs());1136 }1137 else1138 {1139 pSubMenu->addAction (pItem->vmActionDelete());1140 pSubMenu->addAction (pItem->vmActionRefresh());1141 }1142 1143 pCurMenu->addMenu (pSubMenu);1144 }1145 }1146 1147 if (!aRetranslate)1148 {1149 mTrayIconMenu->addSeparator();1150 mTrayIconMenu->addAction (fileExitAction);1151 }1152 }1153 1154 #endif /* #ifdef VBOX_GUI_WITH_SYSTRAY */1155 1156 1070 void VBoxSelectorWnd::refreshVMList() 1157 1071 { … … 1164 1078 1165 1079 vmListViewCurrentChanged(); 1166 1167 1080 #ifdef VBOX_GUI_WITH_SYSTRAY 1168 refreshSysTray();1081 mTrayIcon->refresh(); 1169 1082 #endif 1170 1083 } … … 1201 1114 case QSystemTrayIcon::Context: 1202 1115 1203 refreshSysTray();1116 mTrayIcon->refresh(); 1204 1117 break; 1205 1118 … … 1226 1139 } 1227 1140 1228 #endif / * #ifdef VBOX_GUI_WITH_SYSTRAY */1141 #endif // VBOX_GUI_WITH_SYSTRAY 1229 1142 1230 1143 // Protected members … … 1395 1308 1396 1309 #ifdef VBOX_GUI_WITH_SYSTRAY 1397 refreshSysTray (true); /* true = re-translate the UI. */ 1310 mTrayIcon->retranslateUi(); 1311 mTrayIcon->refresh(); 1398 1312 #endif 1399 1313 } … … 1418 1332 1419 1333 KMachineState state = item->state(); 1420 bool running = item->running();1421 bool modifyEnabled = !running && state != KMachineState_Saved;1334 bool bRunning = item->running(); 1335 bool bModifyEnabled = !bRunning && state != KMachineState_Saved; 1422 1336 1423 1337 if (aRefreshDetails) … … 1425 1339 vmDetailsView->setDetailsText ( 1426 1340 vboxGlobal().detailsReport (m, false /* isNewVM */, 1427 modifyEnabled /* withLinks */));1341 bModifyEnabled /* withLinks */)); 1428 1342 } 1429 1343 if (aRefreshSnapshots) … … 1451 1365 vmTabWidget->setTabEnabled (vmTabWidget->indexOf (vmDescriptionPage), true); 1452 1366 } 1367 1368 /* enable/disable modify actions */ 1369 vmConfigAction->setEnabled (bModifyEnabled); 1370 vmDeleteAction->setEnabled (bModifyEnabled); 1371 vmDiscardAction->setEnabled (state == KMachineState_Saved && !bRunning); 1372 vmPauseAction->setEnabled (state == KMachineState_Running || 1373 state == KMachineState_Paused); 1374 1375 /* change the Start button text accordingly */ 1376 if (state >= KMachineState_Running) 1377 { 1378 vmStartAction->setText (tr ("S&how")); 1379 vmStartAction->setStatusTip ( 1380 tr ("Switch to the window of the selected virtual machine")); 1381 1382 vmStartAction->setEnabled (item->canSwitchTo()); 1383 } 1384 else 1385 { 1386 vmStartAction->setText (tr ("S&tart")); 1387 vmStartAction->setStatusTip ( 1388 tr ("Start the selected virtual machine")); 1389 1390 vmStartAction->setEnabled (!bRunning); 1391 } 1392 1393 /* change the Pause/Resume button text accordingly */ 1394 if (state == KMachineState_Paused) 1395 { 1396 vmPauseAction->setText (tr ("R&esume")); 1397 vmPauseAction->setShortcut (QKeySequence ("Ctrl+P")); 1398 vmPauseAction->setStatusTip ( 1399 tr ("Resume the execution of the virtual machine")); 1400 vmPauseAction->blockSignals (true); 1401 vmPauseAction->setChecked (true); 1402 vmPauseAction->blockSignals (false); 1403 } 1404 else 1405 { 1406 vmPauseAction->setText (tr ("&Pause")); 1407 vmPauseAction->setShortcut (QKeySequence ("Ctrl+P")); 1408 vmPauseAction->setStatusTip ( 1409 tr ("Suspend the execution of the virtual machine")); 1410 vmPauseAction->blockSignals (true); 1411 vmPauseAction->setChecked (false); 1412 vmPauseAction->blockSignals (false); 1413 } 1414 1415 /* disable Refresh for accessible machines */ 1416 vmRefreshAction->setEnabled (false); 1417 1418 /* enable the show log item for the selected vm */ 1419 vmShowLogsAction->setEnabled (true); 1453 1420 } 1454 1421 else … … 1463 1430 vmDetailsView->setErrorText ( 1464 1431 VBoxProblemReporter::formatErrorInfo (item->accessError())); 1432 vmRefreshAction->setEnabled (true); 1465 1433 } 1466 1434 else … … 1495 1463 vmTabWidget->setTabText (vmTabWidget->indexOf (vmDescriptionPage), tr ("D&escription")); 1496 1464 vmTabWidget->setTabEnabled (vmTabWidget->indexOf (vmDescriptionPage), false); 1497 } 1498 1499 if (item) 1500 { 1501 item->updateActions(); 1502 1503 /* enable/disable modify actions */ 1504 vmConfigAction->setEnabled (item->vmActionConfig()->isEnabled()); 1505 vmDeleteAction->setEnabled (item->vmActionDelete()->isEnabled()); 1506 vmDiscardAction->setEnabled (item->vmActionDiscard()->isEnabled()); 1507 1508 vmStartAction->setEnabled (item->vmActionStart()->isEnabled()); 1509 vmStartAction->setText (item->vmActionStart()->text()); 1510 vmStartAction->setStatusTip (item->vmActionStart()->statusTip()); 1511 1512 vmPauseAction->setEnabled (item->vmActionPause()->isEnabled()); 1513 vmPauseAction->setText (item->vmActionPause()->text()); 1514 vmPauseAction->setStatusTip (item->vmActionPause()->statusTip()); 1515 vmPauseAction->blockSignals (true); 1516 vmPauseAction->setChecked (item->vmActionPause()->isChecked()); 1517 vmPauseAction->blockSignals (false); 1518 1519 vmRefreshAction->setEnabled (item->vmActionRefresh()->isEnabled()); 1520 1521 vmShowLogsAction->setEnabled (item->vmActionShowLogs()->isEnabled()); 1465 1466 /* disable modify actions */ 1467 vmConfigAction->setEnabled (false); 1468 vmDeleteAction->setEnabled (item != NULL); 1469 vmDiscardAction->setEnabled (false); 1470 vmPauseAction->setEnabled (false); 1471 1472 /* change the Start button text accordingly */ 1473 vmStartAction->setText (tr ("S&tart")); 1474 vmStartAction->setStatusTip ( 1475 tr ("Start the selected virtual machine")); 1476 vmStartAction->setEnabled (false); 1477 1478 /* disable the show log item for the selected vm */ 1479 vmShowLogsAction->setEnabled (false); 1522 1480 } 1523 1481 } … … 1642 1600 } 1643 1601 1602 #ifdef VBOX_GUI_WITH_SYSTRAY 1603 1604 VBoxTrayIcon::VBoxTrayIcon (VBoxSelectorWnd* aParent, VBoxVMModel* aVMModel) 1605 { 1606 mVmConfigAction = new QAction (this); 1607 Assert (mVmConfigAction); 1608 mVmConfigAction->setIcon (VBoxGlobal::iconSetFull ( 1609 QSize (32, 32), QSize (16, 16), 1610 ":/vm_settings_32px.png", ":/settings_16px.png", 1611 ":/vm_settings_disabled_32px.png", ":/settings_dis_16px.png")); 1612 mVmDeleteAction = new QAction (this); 1613 Assert (mVmDeleteAction); 1614 mVmDeleteAction->setIcon (VBoxGlobal::iconSetFull ( 1615 QSize (32, 32), QSize (16, 16), 1616 ":/vm_delete_32px.png", ":/delete_16px.png", 1617 ":/vm_delete_disabled_32px.png", ":/delete_dis_16px.png")); 1618 mVmStartAction = new QAction (this); 1619 Assert (mVmStartAction); 1620 mVmStartAction->setIcon (VBoxGlobal::iconSetFull ( 1621 QSize (32, 32), QSize (16, 16), 1622 ":/vm_start_32px.png", ":/start_16px.png", 1623 ":/vm_start_disabled_32px.png", ":/start_dis_16px.png")); 1624 mVmDiscardAction = new QAction (this); 1625 Assert (mVmDiscardAction); 1626 mVmDiscardAction->setIcon (VBoxGlobal::iconSetFull ( 1627 QSize (32, 32), QSize (16, 16), 1628 ":/vm_discard_32px.png", ":/discard_16px.png", 1629 ":/vm_discard_disabled_32px.png", ":/discard_dis_16px.png")); 1630 mVmPauseAction = new QAction (this); 1631 Assert (mVmPauseAction); 1632 mVmPauseAction->setCheckable (true); 1633 mVmPauseAction->setIcon (VBoxGlobal::iconSetFull ( 1634 QSize (32, 32), QSize (16, 16), 1635 ":/vm_pause_32px.png", ":/pause_16px.png", 1636 ":/vm_pause_disabled_32px.png", ":/pause_disabled_16px.png")); 1637 mVmRefreshAction = new QAction (this); 1638 Assert (mVmRefreshAction); 1639 mVmRefreshAction->setIcon (VBoxGlobal::iconSetFull ( 1640 QSize (32, 32), QSize (16, 16), 1641 ":/refresh_32px.png", ":/refresh_16px.png", 1642 ":/refresh_disabled_32px.png", ":/refresh_disabled_16px.png")); 1643 mVmShowLogsAction = new QAction (this); 1644 Assert (mVmConfigAction); 1645 mVmShowLogsAction->setIcon (VBoxGlobal::iconSetFull ( 1646 QSize (32, 32), QSize (16, 16), 1647 ":/vm_show_logs_32px.png", ":/show_logs_16px.png", 1648 ":/vm_show_logs_disabled_32px.png", ":/show_logs_disabled_16px.png")); 1649 1650 mTrayIconMenu = new QMenu (aParent); 1651 Assert (mTrayIconMenu); 1652 1653 mParent = aParent; 1654 mVMModel = aVMModel; 1655 1656 setIcon (QIcon (":/VirtualBox_16px.png")); 1657 setContextMenu (mTrayIconMenu); 1658 1659 retranslateUi(); 1660 } 1661 1662 VBoxTrayIcon::~VBoxTrayIcon () 1663 { 1664 1665 } 1666 1667 void VBoxTrayIcon::showSubMenu () 1668 { 1669 VBoxVMItem* pItem = NULL; 1670 QMenu *pMenu = NULL; 1671 QVariant vID; 1672 if (pMenu = qobject_cast<QMenu*>(sender())) 1673 { 1674 vID = pMenu->menuAction()->data(); 1675 if (vID.canConvert<QUuid>() && mVMModel) 1676 pItem = mVMModel->itemById (qvariant_cast<QUuid>(vID)); 1677 } 1678 1679 mVmConfigAction->setData (vID); 1680 mVmDeleteAction->setData (vID); 1681 mVmDiscardAction->setData (vID); 1682 mVmStartAction->setData (vID); 1683 mVmPauseAction->setData (vID); 1684 mVmShowLogsAction->setData (vID); 1685 1686 if (pItem && pItem->accessible()) 1687 { 1688 CMachine m = pItem->machine(); 1689 KMachineState s = pItem->state(); 1690 bool bRunning = pItem->running(); 1691 bool bModifyEnabled = !bRunning && s != KMachineState_Saved; 1692 1693 /* Settings */ 1694 mVmConfigAction->setEnabled (bModifyEnabled); 1695 1696 /* Delete */ 1697 mVmDeleteAction->setEnabled (bModifyEnabled); 1698 1699 /* Discard */ 1700 mVmDiscardAction->setEnabled (s == KMachineState_Saved && !bRunning); 1701 1702 /* Change the Start button text accordingly */ 1703 if (s >= KMachineState_Running) 1704 { 1705 mVmStartAction->setText (VBoxVMListView::tr ("S&how")); 1706 mVmStartAction->setStatusTip ( 1707 VBoxVMListView::tr ("Switch to the window of the selected virtual machine")); 1708 mVmStartAction->setEnabled (pItem->canSwitchTo()); 1709 } 1710 else 1711 { 1712 mVmStartAction->setText (VBoxVMListView::tr ("S&tart")); 1713 mVmStartAction->setStatusTip ( 1714 VBoxVMListView::tr ("Start the selected virtual machine")); 1715 mVmStartAction->setEnabled (!bRunning); 1716 } 1717 1718 /* Change the Pause/Resume button text accordingly */ 1719 mVmPauseAction->setEnabled (s == KMachineState_Running || 1720 s == KMachineState_Paused); 1721 1722 if (s == KMachineState_Paused) 1723 { 1724 mVmPauseAction->setText (VBoxVMListView::tr ("R&esume")); 1725 mVmPauseAction->setStatusTip ( 1726 VBoxVMListView::tr ("Resume the execution of the virtual machine")); 1727 mVmPauseAction->blockSignals (true); 1728 mVmPauseAction->setChecked (true); 1729 mVmPauseAction->blockSignals (false); 1730 } 1731 else 1732 { 1733 mVmPauseAction->setText (VBoxVMListView::tr ("&Pause")); 1734 mVmPauseAction->setStatusTip ( 1735 VBoxVMListView::tr ("Suspend the execution of the virtual machine")); 1736 mVmPauseAction->blockSignals (true); 1737 mVmPauseAction->setChecked (false); 1738 mVmPauseAction->blockSignals (false); 1739 } 1740 1741 mVmShowLogsAction->setEnabled (true); 1742 1743 /* Disconnect old slot which maybe was connected from another selected sub menu. */ 1744 disconnect (mVmConfigAction, SIGNAL (triggered()), this, SLOT (vmSettings())); 1745 disconnect (mVmDeleteAction, SIGNAL (triggered()), this, SLOT (vmDelete())); 1746 disconnect (mVmDiscardAction, SIGNAL (triggered()), this, SLOT (vmDiscard())); 1747 disconnect (mVmStartAction, SIGNAL (triggered()), this, SLOT (vmStart())); 1748 disconnect (mVmPauseAction, SIGNAL (toggled (bool)), this, SLOT (vmPause (bool))); 1749 disconnect (mVmShowLogsAction, SIGNAL (triggered()), this, SLOT (vmShowLogs())); 1750 1751 /* Connect new sub menu with slots. */ 1752 connect (mVmConfigAction, SIGNAL (triggered()), this, SLOT (vmSettings())); 1753 connect (mVmDeleteAction, SIGNAL (triggered()), this, SLOT (vmDelete())); 1754 connect (mVmDiscardAction, SIGNAL (triggered()), this, SLOT (vmDiscard())); 1755 connect (mVmStartAction, SIGNAL (triggered()), this, SLOT (vmStart())); 1756 connect (mVmPauseAction, SIGNAL (toggled (bool)), this, SLOT (vmPause (bool))); 1757 connect (mVmShowLogsAction, SIGNAL (triggered()), this, SLOT (vmShowLogs())); 1758 } 1759 else /* Item is not accessible. */ 1760 { 1761 mVmConfigAction->setEnabled (false); 1762 mVmDeleteAction->setEnabled (pItem != NULL); 1763 mVmDiscardAction->setEnabled (false); 1764 mVmPauseAction->setEnabled (false); 1765 1766 /* Set the Start button text accordingly. */ 1767 mVmStartAction->setText (VBoxVMListView::tr ("S&tart")); 1768 mVmStartAction->setStatusTip ( 1769 VBoxVMListView::tr ("Start the selected virtual machine")); 1770 mVmStartAction->setEnabled (false); 1771 1772 /* Disable the show log item for the selected vm. */ 1773 mVmShowLogsAction->setEnabled (false); 1774 } 1775 1776 /* Build sub menu entries. */ 1777 pMenu->addAction (mVmConfigAction); 1778 pMenu->addAction (mVmDeleteAction); 1779 pMenu->addSeparator(); 1780 pMenu->addAction (mVmStartAction); 1781 pMenu->addAction (mVmDiscardAction); 1782 pMenu->addAction (mVmPauseAction); 1783 pMenu->addSeparator(); 1784 pMenu->addAction (mVmShowLogsAction); 1785 } 1786 1787 void VBoxTrayIcon::retranslateUi () 1788 { 1789 mVmConfigAction->setText (VBoxVMListView::tr ("&Settings...")); 1790 mVmConfigAction->setStatusTip (VBoxVMListView::tr ("Configure the selected virtual machine")); 1791 1792 mVmDeleteAction->setText (VBoxVMListView::tr ("&Delete")); 1793 mVmDeleteAction->setStatusTip (VBoxVMListView::tr ("Delete the selected virtual machine")); 1794 1795 mVmDiscardAction->setText (VBoxVMListView::tr ("D&iscard")); 1796 mVmDiscardAction->setStatusTip (VBoxVMListView::tr ("Discard the saved state of the selected virtual machine")); 1797 1798 mVmShowLogsAction->setText (VBoxVMListView::tr ("Show &Log...")); 1799 mVmShowLogsAction->setStatusTip (VBoxVMListView::tr ("Show the log files of the selected virtual machine")); 1800 } 1801 1802 void VBoxTrayIcon::hideSubMenu () 1803 { 1804 VBoxVMItem* pItem = NULL; 1805 QMenu *pMenu = NULL; 1806 QVariant vID; 1807 if (pMenu = qobject_cast<QMenu*>(sender())) 1808 { 1809 vID = pMenu->menuAction()->data(); 1810 if (vID.canConvert<QUuid>() && mVMModel) 1811 pItem = mVMModel->itemById (qvariant_cast<QUuid>(vID)); 1812 } 1813 1814 /* Nothing to do here yet. */ 1815 1816 Assert (pItem); 1817 } 1818 1819 void VBoxTrayIcon::refresh () 1820 { 1821 if (false == QSystemTrayIcon::isSystemTrayAvailable()) 1822 return; 1823 1824 AssertReturnVoid (mVMModel); 1825 AssertReturnVoid (mTrayIconMenu); 1826 1827 setVisible (true); 1828 mTrayIconMenu->clear(); 1829 1830 VBoxVMItem* pItem = NULL; 1831 QMenu* pCurMenu = mTrayIconMenu; 1832 QMenu* pSubMenu = NULL; 1833 1834 int iCurItemCount = 0; 1835 1836 for (int i = 0; i < mVMModel->rowCount(); i++, iCurItemCount++) 1837 { 1838 pItem = mVMModel->itemByRow(i); 1839 Assert(pItem); 1840 1841 if (iCurItemCount > 10) /* 10 machines per sub menu. */ 1842 { 1843 pSubMenu = new QMenu (tr ("&Other Machines...", "tray menu")); 1844 Assert (pSubMenu); 1845 pCurMenu->addMenu (pSubMenu); 1846 pCurMenu = pSubMenu; 1847 iCurItemCount = 0; 1848 } 1849 1850 QString strStatus; 1851 if (pItem->state() >= KMachineState_Running) 1852 strStatus = "(R)"; 1853 1854 pSubMenu = new QMenu (QString ("&%1. %2 %3") 1855 .arg ((iCurItemCount + 1) % 100).arg (pItem->name()).arg (strStatus)); 1856 Assert (pSubMenu); 1857 pSubMenu->setIcon (pItem->osIcon()); 1858 1859 QAction *pAction = NULL; 1860 QVariant vID; 1861 vID.setValue (pItem->id()); 1862 1863 pSubMenu->menuAction()->setData (vID); 1864 connect (pSubMenu, SIGNAL (aboutToShow()), this, SLOT (showSubMenu())); 1865 connect (pSubMenu, SIGNAL (aboutToHide()), this, SLOT (hideSubMenu())); 1866 pCurMenu->addMenu (pSubMenu); 1867 } 1868 } 1869 1870 VBoxVMItem* VBoxTrayIcon::GetItem (QObject* aObject) 1871 { 1872 QAction *pAction = NULL; 1873 VBoxVMItem* pItem = NULL; 1874 if (pAction = qobject_cast<QAction*>(sender())) 1875 { 1876 QVariant v = pAction->data(); 1877 if (v.canConvert<QUuid>() && mVMModel) 1878 pItem = mVMModel->itemById (qvariant_cast<QUuid>(v)); 1879 } 1880 1881 Assert (pItem); 1882 return pItem; 1883 } 1884 1885 void VBoxTrayIcon::vmSettings() 1886 { 1887 VBoxVMItem* pItem = GetItem (sender()); 1888 mParent->vmSettings (NULL, NULL, pItem->id()); 1889 } 1890 1891 void VBoxTrayIcon::vmDelete() 1892 { 1893 VBoxVMItem* pItem = GetItem (sender()); 1894 mParent->vmDelete (pItem->id()); 1895 } 1896 1897 void VBoxTrayIcon::vmStart() 1898 { 1899 VBoxVMItem* pItem = GetItem (sender()); 1900 mParent->vmStart (pItem->id()); 1901 } 1902 1903 void VBoxTrayIcon::vmDiscard() 1904 { 1905 VBoxVMItem* pItem = GetItem (sender()); 1906 mParent->vmDiscard (pItem->id()); 1907 } 1908 1909 void VBoxTrayIcon::vmPause(bool aPause) 1910 { 1911 VBoxVMItem* pItem = GetItem (sender()); 1912 mParent->vmPause (aPause, pItem->id()); 1913 } 1914 1915 void VBoxTrayIcon::vmRefresh() 1916 { 1917 VBoxVMItem* pItem = GetItem (sender()); 1918 mParent->vmRefresh (pItem->id()); 1919 } 1920 1921 void VBoxTrayIcon::vmShowLogs() 1922 { 1923 VBoxVMItem* pItem = GetItem (sender()); 1924 mParent->vmShowLogs (pItem->id()); 1925 } 1926 1927 #endif // VBOX_GUI_WITH_SYSTRAY 1928 1644 1929 #include "VBoxSelectorWnd.moc" -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMListView.cpp
r14022 r14296 138 138 : mParent (pParent), mMachine (aMachine) 139 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 177 140 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();188 retranslateUi();189 141 } 190 142 … … 200 152 return mAccessible ? vboxGlobal().toString (mState) : 201 153 VBoxVMListView::tr ("Inaccessible"); 202 }203 204 void VBoxVMItem::vmSettings()205 {206 mParent->vmSettings (NULL, NULL, mId);207 }208 209 void VBoxVMItem::vmDelete()210 {211 mParent->vmDelete (mId);212 }213 214 void VBoxVMItem::vmStart()215 {216 mParent->vmStart (mId);217 }218 219 void VBoxVMItem::vmDiscard()220 {221 mParent->vmDiscard (mId);222 }223 224 void VBoxVMItem::vmPause (bool aPause)225 {226 mParent->vmPause (aPause, mId);227 }228 229 void VBoxVMItem::vmRefresh()230 {231 mParent->vmRefresh (mId);232 }233 234 void VBoxVMItem::vmShowLogs()235 {236 mParent->vmShowLogs (mId);237 154 } 238 155 … … 471 388 } 472 389 473 void VBoxVMItem::updateActions()474 {475 if (accessible())476 {477 CMachine m = machine();478 479 KMachineState s = state();480 bool run = running();481 bool modifyEnabled = !run && s != KMachineState_Saved;482 483 /* enable/disable modify actions */484 vmConfigAction->setEnabled (modifyEnabled);485 vmDeleteAction->setEnabled (modifyEnabled);486 vmDiscardAction->setEnabled (s == KMachineState_Saved && !run);487 vmPauseAction->setEnabled (s == KMachineState_Running ||488 s == KMachineState_Paused);489 490 /* change the Start button text accordingly */491 if (s >= KMachineState_Running)492 {493 vmStartAction->setText (VBoxVMListView::tr ("S&how"));494 vmStartAction->setStatusTip (495 VBoxVMListView::tr ("Switch to the window of the selected virtual machine"));496 497 vmStartAction->setEnabled (canSwitchTo());498 }499 else500 {501 vmStartAction->setText (VBoxVMListView::tr ("S&tart"));502 vmStartAction->setStatusTip (503 VBoxVMListView::tr ("Start the selected virtual machine"));504 505 vmStartAction->setEnabled (!run);506 }507 508 /* change the Pause/Resume button text accordingly */509 if (s == KMachineState_Paused)510 {511 vmPauseAction->setText (VBoxVMListView::tr ("R&esume"));512 vmPauseAction->setStatusTip (513 VBoxVMListView::tr ("Resume the execution of the virtual machine"));514 vmPauseAction->blockSignals (true);515 vmPauseAction->setChecked (true);516 vmPauseAction->blockSignals (false);517 }518 else519 {520 vmPauseAction->setText (VBoxVMListView::tr ("&Pause"));521 vmPauseAction->setStatusTip (522 VBoxVMListView::tr ("Suspend the execution of the virtual machine"));523 vmPauseAction->blockSignals (true);524 vmPauseAction->setChecked (false);525 vmPauseAction->blockSignals (false);526 }527 528 /* disable Refresh for accessible machines */529 vmRefreshAction->setEnabled (false);530 531 /* enable the show log item for the selected vm */532 vmShowLogsAction->setEnabled (true);533 }534 else535 {536 vmRefreshAction->setEnabled (true);537 538 /* disable modify actions */539 vmConfigAction->setEnabled (false);540 vmDeleteAction->setEnabled (true);541 vmDiscardAction->setEnabled (false);542 vmPauseAction->setEnabled (false);543 544 /* change the Start button text accordingly */545 vmStartAction->setText (VBoxVMListView::tr ("S&tart"));546 vmStartAction->setStatusTip (547 VBoxVMListView::tr ("Start the selected virtual machine"));548 vmStartAction->setEnabled (false);549 550 /* disable the show log item for the selected vm */551 vmShowLogsAction->setEnabled (false);552 }553 }554 555 void VBoxVMItem::retranslateUi ()556 {557 vmConfigAction->setText (VBoxVMListView::tr ("&Settings..."));558 vmConfigAction->setStatusTip (VBoxVMListView::tr ("Configure the selected virtual machine"));559 560 vmDeleteAction->setText (VBoxVMListView::tr ("&Delete"));561 vmDeleteAction->setStatusTip (VBoxVMListView::tr ("Delete the selected virtual machine"));562 563 vmDiscardAction->setText (VBoxVMListView::tr ("D&iscard"));564 vmDiscardAction->setStatusTip (565 VBoxVMListView::tr ("Discard the saved state of the selected virtual machine"));566 567 vmRefreshAction->setText (VBoxVMListView::tr ("&Refresh"));568 vmRefreshAction->setStatusTip (569 VBoxVMListView::tr ("Refresh the accessibility state of the selected virtual machine"));570 571 vmShowLogsAction->setText (VBoxVMListView::tr ("Show &Log..."));572 vmShowLogsAction->setIconText (VBoxVMListView::tr ("Log", "icon text"));573 vmShowLogsAction->setStatusTip (574 VBoxVMListView::tr ("Show the log files of the selected virtual machine"));575 576 /* Update other actions which changes behavior depending the machine's state. */577 updateActions();578 }579 580 390 /* VBoxVMModel class */ 581 391 … … 614 424 { 615 425 Assert (aItem); 616 aItem->updateActions();617 426 if (aItem->recache()) 618 427 sort();
Note:
See TracChangeset
for help on using the changeset viewer.