- Timestamp:
- Nov 25, 2008 3:30:32 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxDefs.h
r14540 r14578 119 119 ChangeGUILanguageEventType, 120 120 #if defined (VBOX_GUI_WITH_SYSTRAY) 121 ChangeGUITrayIconEventType, 121 CanShowTrayIconEventType, 122 ChangeTrayIconEventType, 122 123 #endif 123 124 AddVDMUrlsEventType … … 152 153 static const char* GUI_LastVMSelected; 153 154 static const char* GUI_InfoDlgState; 155 #ifdef VBOX_GUI_WITH_SYSTRAY 156 static const char* GUI_TrayIconWinID; 157 #endif 154 158 }; 155 159 -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h
r14540 r14578 391 391 392 392 #ifdef VBOX_GUI_WITH_SYSTRAY 393 class VBoxChangeGUITrayIconEvent : public QEvent 394 { 395 public: 396 VBoxChangeGUITrayIconEvent (bool aEnabled) 397 : QEvent ((QEvent::Type) VBoxDefs::ChangeGUITrayIconEventType) 393 class VBoxCanShowTrayIconEvent : public QEvent 394 { 395 public: 396 VBoxCanShowTrayIconEvent (bool aCanShow) 397 : QEvent ((QEvent::Type) VBoxDefs::CanShowTrayIconEventType) 398 , mCanShow (aCanShow) 399 {} 400 401 const bool mCanShow; 402 }; 403 404 class VBoxChangeTrayIconEvent : public QEvent 405 { 406 public: 407 VBoxChangeTrayIconEvent (bool aEnabled) 408 : QEvent ((QEvent::Type) VBoxDefs::ChangeTrayIconEventType) 398 409 , mEnabled (aEnabled) 399 410 {} … … 470 481 QWidget *mainWindow() const { return mMainWindow; } 471 482 472 473 483 bool isVMConsoleProcess() const { return !vmUuid.isNull(); } 484 #ifdef VBOX_GUI_WITH_SYSTRAY 485 bool isTrayIcon() const; 486 bool trayIconInstall(); 487 #endif 474 488 QUuid managedVMUuid() const { return vmUuid; } 475 489 … … 938 952 void snapshotChanged (const VBoxSnapshotEvent &e); 939 953 #ifdef VBOX_GUI_WITH_SYSTRAY 940 void systrayIconChanged (const VBoxChangeGUITrayIconEvent &e); 954 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e); 955 void trayIconChanged (const VBoxChangeTrayIconEvent &e); 941 956 #endif 942 957 … … 980 995 QUuid vmUuid; 981 996 997 #ifdef VBOX_GUI_WITH_SYSTRAY 998 bool mIsTrayIcon; /* Is current instance responsible for tray icon? */ 999 #endif 982 1000 QThread *mMediaEnumThread; 983 1001 VBoxMediaList mMediaList; -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h
r14509 r14578 133 133 void snapshotChanged (const VBoxSnapshotEvent &e); 134 134 #ifdef VBOX_GUI_WITH_SYSTRAY 135 void systrayIconChanged (const VBoxChangeGUITrayIconEvent &e); 135 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e); 136 void trayIconChanged (const VBoxChangeTrayIconEvent &e); 136 137 #endif 137 138 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxDefs.cpp
r14046 r14578 45 45 const char* VBoxDefs::GUI_LastVMSelected = "GUI/LastVMSelected"; 46 46 const char* VBoxDefs::GUI_InfoDlgState = "GUI/InfoDlgState"; 47 #ifdef VBOX_GUI_WITH_SYSTRAY 48 const char* VBoxDefs::GUI_TrayIconWinID = "GUI/TrayIconWinID"; 49 #endif -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp
r14540 r14578 654 654 VBoxCallback (VBoxGlobal &aGlobal) 655 655 : mGlobal (aGlobal) 656 , mIsRegDlgOwner (false), mIsUpdDlgOwner (false) 656 , mIsRegDlgOwner (false) 657 , mIsUpdDlgOwner (false) 658 #ifdef VBOX_GUI_WITH_SYSTRAY 659 , mIsTrayIconOwner (false) 660 #endif 657 661 { 658 662 #if defined (Q_OS_WIN32) … … 763 767 return S_OK; 764 768 } 765 769 #ifdef VBOX_GUI_WITH_SYSTRAY 770 if (sKey == VBoxDefs::GUI_TrayIconWinID) 771 { 772 if (mIsTrayIconOwner) 773 { 774 if (sVal.isEmpty() || 775 sVal == QString ("%1") 776 .arg ((qulonglong) vboxGlobal().mainWindow()->winId())) 777 *allowChange = TRUE; 778 else 779 *allowChange = FALSE; 780 } 781 else 782 *allowChange = TRUE; 783 return S_OK; 784 } 785 #endif 766 786 /* try to set the global setting to check its syntax */ 767 787 VBoxGlobalSettings gs (false /* non-null */); … … 831 851 if (sKey == "GUI/LanguageID") 832 852 QApplication::postEvent (&mGlobal, new VBoxChangeGUILanguageEvent (sVal)); 833 #ifdef VBOX_GUI_WITH_SYSTRAY 853 #ifdef VBOX_GUI_WITH_SYSTRAY 854 if (sKey == VBoxDefs::GUI_TrayIconWinID) 855 { 856 if (sVal.isEmpty()) 857 { 858 mIsTrayIconOwner = false; 859 QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (true)); 860 } 861 else if (sVal == QString ("%1") 862 .arg ((qulonglong) vboxGlobal().mainWindow()->winId())) 863 { 864 mIsTrayIconOwner = true; 865 QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (true)); 866 } 867 else 868 QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (false)); 869 } 834 870 if (sKey == "GUI/TrayIcon/Enabled") 835 QApplication::postEvent (&mGlobal, new VBoxChange GUITrayIconEvent ((sVal.toLower() == "true") ? true : false));836 871 QApplication::postEvent (&mGlobal, new VBoxChangeTrayIconEvent ((sVal.toLower() == "true") ? true : false)); 872 #endif 837 873 838 874 mMutex.lock(); … … 920 956 bool mIsRegDlgOwner; 921 957 bool mIsUpdDlgOwner; 958 #ifdef VBOX_GUI_WITH_SYSTRAY 959 bool mIsTrayIconOwner; 960 #endif 922 961 923 962 #if defined (Q_OS_WIN32) … … 1189 1228 , mSelectorWnd (NULL), mConsoleWnd (NULL) 1190 1229 , mMainWindow (NULL) 1230 #ifdef VBOX_GUI_WITH_SYSTRAY 1231 , mIsTrayIcon (false) 1232 #endif 1191 1233 #ifdef VBOX_WITH_REGISTRATION 1192 1234 , mRegDlg (NULL) … … 1357 1399 return *mConsoleWnd; 1358 1400 } 1401 1402 #ifdef VBOX_GUI_WITH_SYSTRAY 1403 1404 /** 1405 * Returns true if the current instance is responsible of showing/handling 1406 * the tray icon. 1407 */ 1408 bool VBoxGlobal::isTrayIcon() const 1409 { 1410 return mIsTrayIcon; 1411 } 1412 1413 /** 1414 * Tries to install the tray icon using the current instance (singleton). 1415 * Returns true on success, false on failure. 1416 */ 1417 bool VBoxGlobal::trayIconInstall() 1418 { 1419 if (false == QSystemTrayIcon::isSystemTrayAvailable()) 1420 return false; 1421 1422 AssertMsg (vboxGlobal().mainWindow(), 1423 ("Main window must not be null for systray!")); 1424 1425 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, 1426 QString ("%1").arg ((qulonglong) vboxGlobal().mainWindow()->winId())); 1427 1428 /* The first process which can grab this "mutex" will win -> 1429 * It will be the tray icon menu then. */ 1430 if (mVBox.isOk()) 1431 { 1432 mIsTrayIcon = true; 1433 emit trayIconChanged (*(new VBoxChangeTrayIconEvent (vboxGlobal().settings().trayIconEnabled()))); 1434 } 1435 1436 return mIsTrayIcon; 1437 } 1438 1439 #endif 1359 1440 1360 1441 /** … … 5048 5129 } 5049 5130 #ifdef VBOX_GUI_WITH_SYSTRAY 5050 case VBoxDefs::C hangeGUITrayIconEventType:5051 { 5052 emit systrayIconChanged (*(VBoxChangeGUITrayIconEvent *) e);5131 case VBoxDefs::CanShowTrayIconEventType: 5132 { 5133 emit trayIconCanShow (*(VBoxCanShowTrayIconEvent *) e); 5053 5134 return true; 5054 5135 } 5136 case VBoxDefs::ChangeTrayIconEventType: 5137 { 5138 emit trayIconChanged (*(VBoxChangeTrayIconEvent *) e); 5139 return true; 5140 } 5055 5141 #endif 5056 5057 5142 default: 5058 5143 break; -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp
r14509 r14578 675 675 this, SLOT (snapshotChanged (const VBoxSnapshotEvent &))); 676 676 #ifdef VBOX_GUI_WITH_SYSTRAY 677 connect (&vboxGlobal(), SIGNAL (systrayIconChanged (const VBoxChangeGUITrayIconEvent &)), 678 this, SLOT (systrayIconChanged (const VBoxChangeGUITrayIconEvent &))); 677 connect (&vboxGlobal(), SIGNAL (trayIconCanShow (const VBoxCanShowTrayIconEvent &)), 678 this, SLOT (trayIconCanShow (const VBoxCanShowTrayIconEvent &))); 679 connect (&vboxGlobal(), SIGNAL (trayIconChanged (const VBoxChangeTrayIconEvent &)), 680 this, SLOT (trayIconChanged (const VBoxChangeTrayIconEvent &))); 679 681 #endif 680 682 681 683 /* bring the VM list to the focus */ 682 684 mVMListView->setFocus(); 683 684 #ifdef VBOX_GUI_WITH_SYSTRAY685 mTrayIcon->trayIconShow (settings.trayIconEnabled());686 #endif687 685 } 688 686 … … 1085 1083 1086 1084 #ifdef VBOX_GUI_WITH_SYSTRAY 1087 mTrayIcon->refresh(); 1085 if (vboxGlobal().isTrayIcon()) 1086 mTrayIcon->refresh(); 1088 1087 #endif 1089 1088 } … … 1319 1318 1320 1319 #ifdef VBOX_GUI_WITH_SYSTRAY 1321 mTrayIcon->retranslateUi(); 1322 mTrayIcon->refresh(); 1320 if (vboxGlobal().isTrayIcon()) 1321 { 1322 mTrayIcon->retranslateUi(); 1323 mTrayIcon->refresh(); 1324 } 1323 1325 #endif 1324 1326 } … … 1613 1615 #ifdef VBOX_GUI_WITH_SYSTRAY 1614 1616 1615 void VBoxSelectorWnd::systrayIconChanged (const VBoxChangeGUITrayIconEvent &aEvent) 1617 void VBoxSelectorWnd::trayIconCanShow (const VBoxCanShowTrayIconEvent &aEvent) 1618 { 1619 emit trayIconChanged (VBoxChangeTrayIconEvent (vboxGlobal().settings().trayIconEnabled())); 1620 } 1621 1622 void VBoxSelectorWnd::trayIconChanged (const VBoxChangeTrayIconEvent &aEvent) 1616 1623 { 1617 1624 mTrayIcon->trayIconShow (aEvent.mEnabled); … … 1672 1679 connect (mShowSelectorAction, SIGNAL (triggered()), mParent, SLOT (showWindow())); 1673 1680 connect (mHideSystrayMenuAction, SIGNAL (triggered()), this, SLOT (trayIconShow())); 1674 1675 VBoxGlobalSettings settings = vboxGlobal().settings();1676 trayIconShow (settings.trayIconEnabled());1677 1681 } 1678 1682 1679 1683 VBoxTrayIcon::~VBoxTrayIcon () 1680 1684 { 1681 hide(); 1685 /* Erase dialog handle in config file. */ 1686 if (vboxGlobal().isTrayIcon()) 1687 { 1688 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_TrayIconWinID, 1689 QString::null); 1690 hide(); 1691 } 1682 1692 } 1683 1693 … … 1715 1725 void VBoxTrayIcon::showSubMenu () 1716 1726 { 1727 if (!mActive) 1728 return; 1729 1717 1730 VBoxVMItem* pItem = NULL; 1718 1731 QMenu *pMenu = NULL; 1719 1732 QVariant vID; 1720 1721 if (!mActive)1722 return;1723 1733 1724 1734 if ((pMenu = qobject_cast<QMenu*>(sender()))) … … 1834 1844 void VBoxTrayIcon::hideSubMenu () 1835 1845 { 1846 if (!mActive) 1847 return; 1848 1836 1849 VBoxVMItem* pItem = NULL; 1837 1850 QVariant vID; 1838 1839 if (!mActive)1840 return;1841 1851 1842 1852 if (QMenu *pMenu = qobject_cast<QMenu*>(sender())) … … 1928 1938 void VBoxTrayIcon::trayIconShow (bool aShow) 1929 1939 { 1930 if (false == QSystemTrayIcon::isSystemTrayAvailable()) 1931 return; 1932 1933 mActive = aShow; 1940 mActive = aShow; 1934 1941 if (mActive) 1935 1942 { -
trunk/src/VBox/Frontends/VirtualBox4/src/main.cpp
r14198 r14578 374 374 vboxGlobal().startEnumeratingMedia(); 375 375 vboxGlobal().setMainWindow (&vboxGlobal().selectorWnd()); 376 #ifdef VBOX_GUI_WITH_SYSTRAY 377 if ( vboxGlobal().trayIconInstall() 378 && vboxGlobal().isTrayIcon()) 379 { 380 /* Nothing to do here yet. */ 381 } 382 #endif 376 383 vboxGlobal().selectorWnd().show(); 377 384 #ifdef VBOX_WITH_REGISTRATION_REQUEST
Note:
See TracChangeset
for help on using the changeset viewer.