Changeset 14652 in vbox
- Timestamp:
- Nov 26, 2008 4:05:08 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h
r14578 r14652 483 483 bool isVMConsoleProcess() const { return !vmUuid.isNull(); } 484 484 #ifdef VBOX_GUI_WITH_SYSTRAY 485 bool isTrayIcon() const; 485 bool hasTrayIcon() const; 486 bool isTrayMenu() const; 486 487 bool trayIconInstall(); 487 488 #endif … … 996 997 997 998 #ifdef VBOX_GUI_WITH_SYSTRAY 998 bool mIsTrayIcon; /* Is current instance responsible for tray icon? */ 999 bool mHasTrayIcon; /* Is current instance responsible for tray icon? */ 1000 bool mIsTrayMenu; /* Tray icon active/desired? */ 999 1001 #endif 1000 1002 QThread *mMediaEnumThread; -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h
r14578 r14652 61 61 virtual ~VBoxSelectorWnd(); 62 62 63 bool startMachine (const QUuid &aId);64 65 63 signals: 66 64 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp
r14629 r14652 88 88 #include <iprt/file.h> 89 89 #include <iprt/ldr.h> 90 91 #ifdef VBOX_GUI_WITH_SYSTRAY 92 #include <iprt/process.h> 93 94 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) 95 #define HOSTSUFF_EXE ".exe" 96 #else /* !RT_OS_WINDOWS */ 97 #define HOSTSUFF_EXE "" 98 #endif /* !RT_OS_WINDOWS */ 99 #endif 90 100 91 101 #if defined (Q_WS_X11) … … 941 951 void postEvent (QEvent *e) 942 952 { 943 #ifndef VBOX_GUI_WITH_SYSTRAY 944 // If not using a systray menu, we don't post events if we are in the VM 945 // execution console mode, to save some CPU ticks (so far, there was no 946 // need to handle VirtualBox callback events in the execution console 947 // mode 953 // currently, we don't post events if we are in the VM execution 954 // console mode, to save some CPU ticks (so far, there was no need 955 // to handle VirtualBox callback events in the execution console mode) 948 956 if (!mGlobal.isVMConsoleProcess()) 949 #endif950 957 QApplication::postEvent (&mGlobal, e); 951 958 } … … 1235 1242 , mUpdDlg (NULL) 1236 1243 #ifdef VBOX_GUI_WITH_SYSTRAY 1237 , mIsTrayIcon (false) 1244 , mHasTrayIcon (false) 1245 , mIsTrayMenu (false) 1238 1246 #endif 1239 1247 , mMediaEnumThread (NULL) … … 1348 1356 VBoxSelectorWnd &VBoxGlobal::selectorWnd() 1349 1357 { 1358 #if defined (VBOX_GUI_SEPARATE_VM_PROCESS) 1359 AssertMsg (!vboxGlobal().isVMConsoleProcess(), 1360 ("Must NOT be a VM console process")); 1361 #endif 1362 1350 1363 Assert (mValid); 1351 1364 … … 1403 1416 * the tray icon. 1404 1417 */ 1405 bool VBoxGlobal::isTrayIcon() const 1406 { 1407 return mIsTrayIcon; 1418 bool VBoxGlobal::hasTrayIcon() const 1419 { 1420 return mHasTrayIcon; 1421 } 1422 1423 /** 1424 * Returns true if the current instance a systray menu only (started with 1425 * "-systray" parameter). 1426 */ 1427 bool VBoxGlobal::isTrayMenu() const 1428 { 1429 return (mHasTrayIcon && mIsTrayMenu); 1408 1430 } 1409 1431 … … 1414 1436 bool VBoxGlobal::trayIconInstall() 1415 1437 { 1416 if (false == QSystemTrayIcon::isSystemTrayAvailable()) 1438 bool bActive = mIsTrayMenu; 1439 if (false == bActive) 1440 bActive = vboxGlobal().settings().trayIconEnabled(); 1441 1442 if ( bActive 1443 && (false == QSystemTrayIcon::isSystemTrayAvailable()) 1444 && (false == mVBox.GetExtraData (VBoxDefs::GUI_TrayIconWinID).isEmpty())) 1445 { 1417 1446 return false; 1418 1419 AssertMsg (&vboxGlobal().selectorWnd(), 1420 ("Selector window must not be null for systray!")); 1421 1422 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, 1423 QString ("%1").arg ((qulonglong) vboxGlobal().selectorWnd().winId())); 1424 1425 /* The first process which can grab this "mutex" will win -> 1426 * It will be the tray icon menu then. */ 1427 if (mVBox.isOk()) 1428 { 1429 mIsTrayIcon = true; 1430 emit trayIconChanged (*(new VBoxChangeTrayIconEvent (vboxGlobal().settings().trayIconEnabled()))); 1431 } 1432 1433 return mIsTrayIcon; 1447 } 1448 1449 int rc = 0; 1450 if (isVMConsoleProcess()) 1451 { 1452 // Spawn new selector window instance 1453 1454 // Get the path to the executable 1455 char path [RTPATH_MAX]; 1456 RTPathAppPrivateArch (path, RTPATH_MAX); 1457 size_t sz = strlen (path); 1458 path [sz++] = RTPATH_DELIMITER; 1459 path [sz] = 0; 1460 char *cmd = path + sz; 1461 sz = RTPATH_MAX - sz; 1462 1463 RTPROCESS pid = NIL_RTPROCESS; 1464 RTENV env = RTENV_DEFAULT; 1465 1466 const char VirtualBox_exe[] = "VirtualBox" HOSTSUFF_EXE; 1467 Assert (sz >= sizeof (VirtualBox_exe)); 1468 strcpy (cmd, VirtualBox_exe); 1469 # ifdef RT_OS_WINDOWS /** @todo drop this once the RTProcCreate bug has been fixed */ 1470 const char * args[] = {path, "-systray", 0 }; 1471 # else 1472 const char * args[] = {path, "-systray", 0 }; 1473 # endif 1474 rc = RTProcCreate (path, args, env, 0, &pid); 1475 if (RT_FAILURE (rc)) 1476 { 1477 LogRel(("Failed to start systray window! rc=%Rrc\n", rc)); 1478 return false; 1479 } 1480 } 1481 else 1482 { 1483 // Use this selector for displaying the tray icon 1484 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, 1485 QString ("%1").arg ((qulonglong) vboxGlobal().mainWindow()->winId())); 1486 1487 /* The first process which can grab this "mutex" will win -> 1488 * It will be the tray icon menu then. */ 1489 if (mVBox.isOk()) 1490 { 1491 mHasTrayIcon = true; 1492 emit trayIconChanged (*(new VBoxChangeTrayIconEvent (vboxGlobal().settings().trayIconEnabled()))); 1493 } 1494 } 1495 1496 return mHasTrayIcon; 1434 1497 } 1435 1498 … … 5386 5449 } 5387 5450 } 5451 #ifdef VBOX_GUI_WITH_SYSTRAY 5452 else if (!::strcmp (arg, "-systray")) 5453 { 5454 mIsTrayMenu = true; 5455 } 5456 #endif 5388 5457 else if (!::strcmp (arg, "-comment")) 5389 5458 { -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp
r14629 r14652 714 714 /* Delete systray menu object */ 715 715 delete mTrayIcon; 716 mTrayIcon = NULL; 716 717 #endif 717 718 … … 911 912 #if defined (VBOX_GUI_SEPARATE_VM_PROCESS) 912 913 914 AssertMsg (!vboxGlobal().isVMConsoleProcess(), 915 ("Must NOT be a VM console process")); 916 913 917 /* just switch to the VM window if it already exists */ 914 918 if (item->canSwitchTo()) … … 1080 1084 1081 1085 #ifdef VBOX_GUI_WITH_SYSTRAY 1082 if (vboxGlobal(). isTrayIcon())1086 if (vboxGlobal().hasTrayIcon()) 1083 1087 mTrayIcon->refresh(); 1084 1088 #endif … … 1191 1195 void VBoxSelectorWnd::closeEvent (QCloseEvent *aEvent) 1192 1196 { 1193 emit closing(); 1194 return QMainWindow::closeEvent (aEvent); 1197 #ifdef VBOX_GUI_WITH_SYSTRAY 1198 if (vboxGlobal().isTrayMenu()) 1199 { 1200 hide(); 1201 } 1202 else 1203 { 1204 #endif 1205 emit closing(); 1206 QMainWindow::closeEvent (aEvent); 1207 #ifdef VBOX_GUI_WITH_SYSTRAY 1208 } 1209 #endif 1195 1210 } 1196 1211 … … 1315 1330 1316 1331 #ifdef VBOX_GUI_WITH_SYSTRAY 1317 if (vboxGlobal(). isTrayIcon())1332 if (vboxGlobal().hasTrayIcon()) 1318 1333 { 1319 1334 mTrayIcon->retranslateUi(); … … 1619 1634 void VBoxSelectorWnd::trayIconChanged (const VBoxChangeTrayIconEvent &aEvent) 1620 1635 { 1621 mTrayIcon->trayIconShow (aEvent.mEnabled); 1636 if (mTrayIcon) 1637 mTrayIcon->trayIconShow (aEvent.mEnabled); 1622 1638 } 1623 1639 … … 1935 1951 void VBoxTrayIcon::trayIconShow (bool aShow) 1936 1952 { 1953 if (!vboxGlobal().hasTrayIcon()) 1954 return; 1955 1937 1956 mActive = aShow; 1938 1957 if (mActive) … … 1942 1961 } 1943 1962 setVisible (mActive); 1963 1964 if (!mActive && vboxGlobal().isTrayMenu()) 1965 mParent->fileExit(); 1944 1966 } 1945 1967 -
trunk/src/VBox/Frontends/VirtualBox4/src/main.cpp
r14629 r14652 361 361 if (vboxGlobal().isVMConsoleProcess()) 362 362 { 363 vboxGlobal().setMainWindow (&vboxGlobal().consoleWnd()); 363 364 #ifdef VBOX_GUI_WITH_SYSTRAY 364 /* Keep selector window in memory (hidden) because we need it for365 * the systray menu. */366 vboxGlobal().startEnumeratingMedia();367 vboxGlobal().selectorWnd();368 vboxGlobal().setMainWindow (&vboxGlobal().consoleWnd());369 365 if ( vboxGlobal().trayIconInstall() 370 && vboxGlobal(). isTrayIcon())366 && vboxGlobal().hasTrayIcon()) 371 367 { 372 368 /* Nothing to do here yet. */ 373 369 } 374 #else375 vboxGlobal().setMainWindow (&vboxGlobal().consoleWnd());376 370 #endif 377 371 if (vboxGlobal().startMachine (vboxGlobal().managedVMUuid())) … … 389 383 #ifdef VBOX_GUI_WITH_SYSTRAY 390 384 if ( vboxGlobal().trayIconInstall() 391 && vboxGlobal(). isTrayIcon())385 && vboxGlobal().hasTrayIcon()) 392 386 { 393 387 /* Nothing to do here yet. */ 394 388 } 395 #endif 396 vboxGlobal().selectorWnd().show(); 389 390 if (false == vboxGlobal().isTrayMenu()) 391 #endif 392 vboxGlobal().selectorWnd().show(); 397 393 #ifdef VBOX_WITH_REGISTRATION_REQUEST 398 394 vboxGlobal().showRegistrationDialog (false /* aForce */);
Note:
See TracChangeset
for help on using the changeset viewer.