Changeset 14908 in vbox for trunk/src/VBox
- Timestamp:
- Dec 2, 2008 3:03:52 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
r14706 r14908 120 120 #if defined (VBOX_GUI_WITH_SYSTRAY) 121 121 CanShowTrayIconEventType, 122 ChangeTrayIconEventType, 122 ShowTrayIconEventType, 123 TrayIconChangeEventType, 124 MainWindowCountChangeEventType, 123 125 #endif 124 126 AddVDMUrlsEventType -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h
r14706 r14908 391 391 392 392 #ifdef VBOX_GUI_WITH_SYSTRAY 393 class VBoxMainWindowCountChangeEvent : public QEvent 394 { 395 public: 396 VBoxMainWindowCountChangeEvent (int aCount) 397 : QEvent ((QEvent::Type) VBoxDefs::MainWindowCountChangeEventType) 398 , mCount (aCount) 399 {} 400 401 const int mCount; 402 }; 403 393 404 class VBoxCanShowTrayIconEvent : public QEvent 394 405 { … … 402 413 }; 403 414 415 class VBoxShowTrayIconEvent : public QEvent 416 { 417 public: 418 VBoxShowTrayIconEvent (bool aShow) 419 : QEvent ((QEvent::Type) VBoxDefs::ShowTrayIconEventType) 420 , mShow (aShow) 421 {} 422 423 const bool mShow; 424 }; 425 404 426 class VBoxChangeTrayIconEvent : public QEvent 405 427 { 406 428 public: 407 VBoxChangeTrayIconEvent (bool a Enabled)408 : QEvent ((QEvent::Type) VBoxDefs:: ChangeTrayIconEventType)409 , m Enabled (aEnabled)429 VBoxChangeTrayIconEvent (bool aChanged) 430 : QEvent ((QEvent::Type) VBoxDefs::TrayIconChangeEventType) 431 , mChanged (aChanged) 410 432 {} 411 433 412 const bool m Enabled;434 const bool mChanged; 413 435 }; 414 436 #endif … … 483 505 bool isVMConsoleProcess() const { return !vmUuid.isNull(); } 484 506 #ifdef VBOX_GUI_WITH_SYSTRAY 485 bool hasTrayIcon() const;486 507 bool isTrayMenu() const; 508 void setTrayMenu(bool aIsTrayMenu); 509 void trayIconShowSelector(); 487 510 bool trayIconInstall(); 488 511 #endif … … 956 979 void snapshotChanged (const VBoxSnapshotEvent &e); 957 980 #ifdef VBOX_GUI_WITH_SYSTRAY 981 void mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &e); 958 982 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e); 983 void trayIconShow (const VBoxShowTrayIconEvent &e); 959 984 void trayIconChanged (const VBoxChangeTrayIconEvent &e); 960 985 #endif … … 1000 1025 1001 1026 #ifdef VBOX_GUI_WITH_SYSTRAY 1002 bool mHasTrayIcon; /* Is current instance responsible for tray icon? */1003 1027 bool mIsTrayMenu; /* Tray icon active/desired? */ 1004 1028 #endif -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h
r14907 r14908 131 131 void snapshotChanged (const VBoxSnapshotEvent &e); 132 132 #ifdef VBOX_GUI_WITH_SYSTRAY 133 void mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &aEvent); 133 134 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e); 135 void trayIconShow (const VBoxShowTrayIconEvent &e); 134 136 void trayIconChanged (const VBoxChangeTrayIconEvent &e); 135 137 #endif -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp
r14818 r14908 864 864 QApplication::postEvent (&mGlobal, new VBoxChangeGUILanguageEvent (sVal)); 865 865 #ifdef VBOX_GUI_WITH_SYSTRAY 866 if (sKey == "GUI/MainWindowCount") 867 QApplication::postEvent (&mGlobal, new VBoxMainWindowCountChangeEvent (sVal.toInt())); 866 868 if (sKey == VBoxDefs::GUI_TrayIconWinID) 867 869 { … … 1244 1246 , mUpdDlg (NULL) 1245 1247 #ifdef VBOX_GUI_WITH_SYSTRAY 1246 , mHasTrayIcon (false)1247 1248 , mIsTrayMenu (false) 1248 1249 #endif … … 1415 1416 1416 1417 /** 1417 * Returns true if the current instance is responsible of showing/handling1418 * the tray icon.1419 */1420 bool VBoxGlobal::hasTrayIcon() const1421 {1422 return mHasTrayIcon;1423 }1424 1425 /**1426 1418 * Returns true if the current instance a systray menu only (started with 1427 1419 * "-systray" parameter). … … 1429 1421 bool VBoxGlobal::isTrayMenu() const 1430 1422 { 1431 return (mHasTrayIcon && mIsTrayMenu); 1423 return mIsTrayMenu; 1424 } 1425 1426 void VBoxGlobal::setTrayMenu(bool aIsTrayMenu) 1427 { 1428 mIsTrayMenu = aIsTrayMenu; 1429 } 1430 1431 /** 1432 * Spawns a new selector window (process). 1433 */ 1434 void VBoxGlobal::trayIconShowSelector() 1435 { 1436 /* Get the path to the executable. */ 1437 char path [RTPATH_MAX]; 1438 RTPathAppPrivateArch (path, RTPATH_MAX); 1439 size_t sz = strlen (path); 1440 path [sz++] = RTPATH_DELIMITER; 1441 path [sz] = 0; 1442 char *cmd = path + sz; 1443 sz = RTPATH_MAX - sz; 1444 1445 int rc = 0; 1446 RTPROCESS pid = NIL_RTPROCESS; 1447 RTENV env = RTENV_DEFAULT; 1448 1449 const char VirtualBox_exe[] = "VirtualBox" HOSTSUFF_EXE; 1450 Assert (sz >= sizeof (VirtualBox_exe)); 1451 strcpy (cmd, VirtualBox_exe); 1452 # ifdef RT_OS_WINDOWS /** @todo drop this once the RTProcCreate bug has been fixed */ 1453 const char * args[] = {path, 0 }; 1454 # else 1455 const char * args[] = {path, 0 }; 1456 # endif 1457 rc = RTProcCreate (path, args, env, 0, &pid); 1458 if (RT_FAILURE (rc)) 1459 LogRel(("Systray: Failed to start new selector window! Path=%s, rc=%Rrc\n", path, rc)); 1432 1460 } 1433 1461 1434 1462 /** 1435 1463 * Tries to install the tray icon using the current instance (singleton). 1436 * Returns true on success, false on failure.1464 * Returns true if this instance is the tray icon, false if not. 1437 1465 */ 1438 1466 bool VBoxGlobal::trayIconInstall() 1439 1467 { 1440 bool bActive = mIsTrayMenu; 1441 if (false == bActive) 1442 bActive = vboxGlobal().settings().trayIconEnabled(); 1468 int rc = 0; 1469 QString strTrayWinID = mVBox.GetExtraData (VBoxDefs::GUI_TrayIconWinID); 1470 if (false == strTrayWinID.isEmpty()) 1471 { 1472 /* Check if current tray icon is alive by writing some bogus value. */ 1473 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, "0"); 1474 if (mVBox.isOk()) 1475 { 1476 /* Current tray icon died - clean up. */ 1477 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, NULL); 1478 strTrayWinID.clear(); 1479 } 1480 } 1443 1481 1444 1482 /* Is there already a tray icon or is tray icon not active? */ 1445 QString strTrayWinID = mVBox.GetExtraData (VBoxDefs::GUI_TrayIconWinID); 1446 if ( (bActive == false) 1447 || (QSystemTrayIcon::isSystemTrayAvailable() == false) 1448 || (strTrayWinID.isEmpty() == false)) 1449 { 1450 return false; 1451 } 1452 1453 int rc = 0; 1454 if (isVMConsoleProcess()) 1455 { 1456 // Spawn new selector window instance 1457 1458 // Get the path to the executable 1483 if ( (mIsTrayMenu == false) 1484 && (vboxGlobal().settings().trayIconEnabled()) 1485 && (QSystemTrayIcon::isSystemTrayAvailable()) 1486 && (strTrayWinID.isEmpty())) 1487 { 1488 /* Get the path to the executable. */ 1459 1489 char path [RTPATH_MAX]; 1460 1490 RTPathAppPrivateArch (path, RTPATH_MAX); … … 1471 1501 Assert (sz >= sizeof (VirtualBox_exe)); 1472 1502 strcpy (cmd, VirtualBox_exe); 1473 # ifdef RT_OS_WINDOWS /** @todo drop this once the RTProcCreate bug has been fixed */1503 # ifdef RT_OS_WINDOWS /** @todo drop this once the RTProcCreate bug has been fixed */ 1474 1504 const char * args[] = {path, "-systray", 0 }; 1475 # else1505 # else 1476 1506 const char * args[] = {path, "-systray", 0 }; 1477 # endif1507 # endif 1478 1508 rc = RTProcCreate (path, args, env, 0, &pid); 1479 1509 if (RT_FAILURE (rc)) 1480 1510 { 1481 LogRel((" Failed to start systray window! Path=%s, rc=%Rrc\n", path, rc));1511 LogRel(("Systray: Failed to start systray window! Path=%s, rc=%Rrc\n", path, rc)); 1482 1512 return false; 1483 1513 } 1484 1514 } 1485 else 1515 1516 if (mIsTrayMenu) 1486 1517 { 1487 1518 // Use this selector for displaying the tray icon … … 1493 1524 if (mVBox.isOk()) 1494 1525 { 1495 mHasTrayIcon = true;1496 emit trayIconChanged (*(new VBoxChangeTrayIconEvent (vboxGlobal().settings().trayIconEnabled())));1497 } 1498 } 1499 1500 return mHasTrayIcon;1526 emit trayIconShow (*(new VBoxShowTrayIconEvent (true))); 1527 return true; 1528 } 1529 } 1530 1531 return false; 1501 1532 } 1502 1533 … … 5204 5235 } 5205 5236 #ifdef VBOX_GUI_WITH_SYSTRAY 5237 case VBoxDefs::MainWindowCountChangeEventType: 5238 5239 emit mainWindowCountChanged (*(VBoxMainWindowCountChangeEvent *) e); 5240 return true; 5241 5206 5242 case VBoxDefs::CanShowTrayIconEventType: 5207 5243 { … … 5209 5245 return true; 5210 5246 } 5211 case VBoxDefs::ChangeTrayIconEventType: 5247 case VBoxDefs::ShowTrayIconEventType: 5248 { 5249 emit trayIconShow (*(VBoxShowTrayIconEvent *) e); 5250 return true; 5251 } 5252 case VBoxDefs::TrayIconChangeEventType: 5212 5253 { 5213 5254 emit trayIconChanged (*(VBoxChangeTrayIconEvent *) e); -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobalSettings.cpp
r14455 r14908 60 60 languageId = QString::null; 61 61 maxGuestRes = "auto"; 62 trayIconEnabled = true;62 trayIconEnabled = false; 63 63 } 64 64 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp
r14907 r14908 680 680 this, SLOT (snapshotChanged (const VBoxSnapshotEvent &))); 681 681 #ifdef VBOX_GUI_WITH_SYSTRAY 682 connect (&vboxGlobal(), SIGNAL (mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &)), 683 this, SLOT (mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &))); 682 684 connect (&vboxGlobal(), SIGNAL (trayIconCanShow (const VBoxCanShowTrayIconEvent &)), 683 685 this, SLOT (trayIconCanShow (const VBoxCanShowTrayIconEvent &))); 686 connect (&vboxGlobal(), SIGNAL (trayIconShow (const VBoxShowTrayIconEvent &)), 687 this, SLOT (trayIconShow (const VBoxShowTrayIconEvent &))); 684 688 connect (&vboxGlobal(), SIGNAL (trayIconChanged (const VBoxChangeTrayIconEvent &)), 685 689 this, SLOT (trayIconChanged (const VBoxChangeTrayIconEvent &))); … … 1087 1091 1088 1092 #ifdef VBOX_GUI_WITH_SYSTRAY 1089 if (vboxGlobal(). hasTrayIcon())1093 if (vboxGlobal().isTrayMenu()) 1090 1094 mTrayIcon->refresh(); 1091 1095 #endif … … 1131 1135 case QSystemTrayIcon::DoubleClick: 1132 1136 1133 showWindow();1137 vboxGlobal().trayIconShowSelector(); 1134 1138 break; 1135 1139 … … 1188 1192 { 1189 1193 #ifdef VBOX_GUI_WITH_SYSTRAY 1194 /* Needed for breaking out of the while() loop in main(). */ 1190 1195 if (vboxGlobal().isTrayMenu()) 1191 { 1192 hide(); 1193 if (vboxGlobal().mainWindowCount() == 0) 1194 { 1195 emit closing(); 1196 QMainWindow::closeEvent (aEvent); 1197 } 1198 else aEvent->ignore(); 1199 } 1200 else 1201 { 1196 vboxGlobal().setTrayMenu (false); 1202 1197 #endif 1203 emit closing(); 1204 QMainWindow::closeEvent (aEvent); 1205 #ifdef VBOX_GUI_WITH_SYSTRAY 1206 } 1207 #endif 1198 1199 emit closing(); 1200 QMainWindow::closeEvent (aEvent); 1208 1201 } 1209 1202 … … 1328 1321 1329 1322 #ifdef VBOX_GUI_WITH_SYSTRAY 1330 if (vboxGlobal(). hasTrayIcon())1323 if (vboxGlobal().isTrayMenu()) 1331 1324 { 1332 1325 mTrayIcon->retranslateUi(); … … 1638 1631 #ifdef VBOX_GUI_WITH_SYSTRAY 1639 1632 1633 void VBoxSelectorWnd::mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &aEvent) 1634 { 1635 if (vboxGlobal().isTrayMenu() && aEvent.mCount <= 1) 1636 fileExit(); 1637 } 1638 1640 1639 void VBoxSelectorWnd::trayIconCanShow (const VBoxCanShowTrayIconEvent &aEvent) 1641 1640 { … … 1643 1642 } 1644 1643 1644 void VBoxSelectorWnd::trayIconShow (const VBoxShowTrayIconEvent &aEvent) 1645 { 1646 if (vboxGlobal().isTrayMenu() && mTrayIcon) 1647 mTrayIcon->trayIconShow (aEvent.mShow); 1648 } 1649 1645 1650 void VBoxSelectorWnd::trayIconChanged (const VBoxChangeTrayIconEvent &aEvent) 1646 1651 { 1647 if (mTrayIcon) 1648 mTrayIcon->trayIconShow (aEvent.mEnabled); 1652 /* Not used yet. */ 1649 1653 } 1650 1654 … … 1962 1966 void VBoxTrayIcon::trayIconShow (bool aShow) 1963 1967 { 1964 if (!vboxGlobal(). hasTrayIcon())1968 if (!vboxGlobal().isTrayMenu()) 1965 1969 return; 1966 1970 … … 1973 1977 setVisible (mActive); 1974 1978 1975 if (!mActive && vboxGlobal().isTrayMenu()) 1979 if (!mActive) 1980 { 1981 VBoxGlobalSettings s = vboxGlobal().settings(); 1982 s.setTrayIconEnabled (false); 1983 s.save(vboxGlobal().virtualBox()); 1976 1984 mParent->fileExit(); 1985 } 1977 1986 } 1978 1987 -
trunk/src/VBox/Frontends/VirtualBox4/src/main.cpp
r14831 r14908 363 363 vboxGlobal().setMainWindow (&vboxGlobal().consoleWnd()); 364 364 #ifdef VBOX_GUI_WITH_SYSTRAY 365 if ( vboxGlobal().trayIconInstall() 366 && vboxGlobal().hasTrayIcon()) 365 if (vboxGlobal().trayIconInstall()) 367 366 { 368 367 /* Nothing to do here yet. */ … … 380 379 vboxGlobal().setMainWindow (&vboxGlobal().selectorWnd()); 381 380 #ifdef VBOX_GUI_WITH_SYSTRAY 382 if ( vboxGlobal().trayIconInstall() 383 && vboxGlobal().hasTrayIcon()) 381 if (vboxGlobal().trayIconInstall()) 384 382 { 385 383 /* Nothing to do here yet. */ … … 395 393 vboxGlobal().showUpdateDialog (false /* aForce */); 396 394 #endif 397 rc = a.exec(); 395 #ifdef VBOX_GUI_WITH_SYSTRAY 396 do 397 { 398 #endif 399 rc = a.exec(); 400 #ifdef VBOX_GUI_WITH_SYSTRAY 401 } while (vboxGlobal().isTrayMenu()); 402 #endif 398 403 } 399 404 }
Note:
See TracChangeset
for help on using the changeset viewer.