Changeset 90938 in vbox
- Timestamp:
- Aug 27, 2021 8:45:54 AM (3 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/globals
- Files:
-
- 2 edited
-
UICommon.cpp (modified) (5 diffs)
-
UICommon.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp
r90937 r90938 233 233 /* static */ 234 234 UICommon *UICommon::s_pInstance = 0; 235 bool UICommon::s_fCleaningUp = false;236 QString UICommon::s_strLoadedLanguageId = vboxBuiltInLanguageName();237 QString UICommon::s_strUserDefinedPortName = QString();235 bool UICommon::s_fCleaningUp = false; 236 QString UICommon::s_strLoadedLanguageId = vboxBuiltInLanguageName(); 237 QString UICommon::s_strUserDefinedPortName = QString(); 238 238 239 239 /* static */ … … 241 241 { 242 242 /* Make sure instance is NOT created yet: */ 243 if (s_pInstance) 244 { 245 AssertMsgFailed(("UICommon instance is already created!")); 246 return; 247 } 243 AssertReturnVoid(!s_pInstance); 248 244 249 245 /* Create instance: */ … … 257 253 { 258 254 /* Make sure instance is NOT destroyed yet: */ 259 if (!s_pInstance) 260 { 261 AssertMsgFailed(("UICommon instance is already destroyed!")); 262 return; 263 } 255 AssertPtrReturnVoid(s_pInstance); 264 256 265 257 /* Cleanup instance: … … 326 318 } 327 319 320 void UICommon::prepare() 321 { 322 /* Make sure QApplication cleanup us on exit: */ 323 qApp->setFallbackSessionManagementEnabled(false); 324 connect(qApp, &QGuiApplication::aboutToQuit, 325 this, &UICommon::sltCleanup); 326 #ifndef VBOX_GUI_WITH_CUSTOMIZATIONS1 327 /* Make sure we handle host OS session shutdown as well: */ 328 connect(qApp, &QGuiApplication::commitDataRequest, 329 this, &UICommon::sltHandleCommitDataRequest); 330 #endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */ 331 332 #ifdef VBOX_WS_MAC 333 /* Determine OS release early: */ 334 m_enmMacOSVersion = determineOsRelease(); 335 #endif /* VBOX_WS_MAC */ 336 337 /* Create converter: */ 338 UIConverter::create(); 339 340 /* Create desktop-widget watchdog: */ 341 UIDesktopWidgetWatchdog::create(); 342 343 /* Create message-center: */ 344 UIMessageCenter::create(); 345 /* Create popup-center: */ 346 UIPopupCenter::create(); 347 348 /* Prepare general icon-pool: */ 349 m_pIconPool = new UIIconPoolGeneral; 350 351 /* Load translation based on the current locale: */ 352 loadLanguage(); 353 354 HRESULT rc = COMBase::InitializeCOM(true); 355 if (FAILED(rc)) 356 { 357 #ifdef VBOX_WITH_XPCOM 358 if (rc == NS_ERROR_FILE_ACCESS_DENIED) 359 { 360 char szHome[RTPATH_MAX] = ""; 361 com::GetVBoxUserHomeDirectory(szHome, sizeof(szHome)); 362 msgCenter().cannotInitUserHome(QString(szHome)); 363 } 364 else 365 #endif 366 msgCenter().cannotInitCOM(rc); 367 return; 368 } 369 370 /* Make sure VirtualBoxClient instance created: */ 371 m_comVBoxClient.createInstance(CLSID_VirtualBoxClient); 372 if (!m_comVBoxClient.isOk()) 373 { 374 msgCenter().cannotCreateVirtualBoxClient(m_comVBoxClient); 375 return; 376 } 377 /* Make sure VirtualBox instance acquired: */ 378 m_comVBox = m_comVBoxClient.GetVirtualBox(); 379 if (!m_comVBoxClient.isOk()) 380 { 381 msgCenter().cannotAcquireVirtualBox(m_comVBoxClient); 382 return; 383 } 384 /* Init wrappers: */ 385 comWrappersReinit(); 386 387 /* Watch for the VBoxSVC availability changes: */ 388 connect(gVBoxClientEvents, &UIVirtualBoxClientEventHandler::sigVBoxSVCAvailabilityChange, 389 this, &UICommon::sltHandleVBoxSVCAvailabilityChange); 390 391 /* Prepare thread-pool instances: */ 392 m_pThreadPool = new UIThreadPool(3 /* worker count */, 5000 /* worker timeout */); 393 m_pThreadPoolCloud = new UIThreadPool(2 /* worker count */, 1000 /* worker timeout */); 394 395 #ifdef VBOX_WS_WIN 396 /* Load color theme: */ 397 loadColorTheme(); 398 #endif 399 400 /* Load translation based on the user settings: */ 401 QString sLanguageId = gEDataManager->languageId(); 402 if (!sLanguageId.isNull()) 403 loadLanguage(sLanguageId); 404 405 retranslateUi(); 406 407 connect(gEDataManager, &UIExtraDataManager::sigLanguageChange, 408 this, &UICommon::sltGUILanguageChange); 409 410 qApp->installEventFilter(this); 411 412 /* process command line */ 413 414 UIVisualStateType visualStateType = UIVisualStateType_Invalid; 415 416 #ifdef VBOX_WS_X11 417 /* Check whether we have compositing manager running: */ 418 m_fCompositingManagerRunning = X11IsCompositingManagerRunning(); 419 420 /* Acquire current Window Manager type: */ 421 m_enmWindowManagerType = X11WindowManagerType(); 422 #endif /* VBOX_WS_X11 */ 423 424 #ifdef VBOX_WITH_DEBUGGER_GUI 425 # ifdef VBOX_WITH_DEBUGGER_GUI_MENU 426 initDebuggerVar(&m_fDbgEnabled, "VBOX_GUI_DBG_ENABLED", GUI_Dbg_Enabled, true); 427 # else 428 initDebuggerVar(&m_fDbgEnabled, "VBOX_GUI_DBG_ENABLED", GUI_Dbg_Enabled, false); 429 # endif 430 initDebuggerVar(&m_fDbgAutoShow, "VBOX_GUI_DBG_AUTO_SHOW", GUI_Dbg_AutoShow, false); 431 m_fDbgAutoShowCommandLine = m_fDbgAutoShowStatistics = m_fDbgAutoShow; 432 #endif 433 434 /* 435 * Parse the command line options. 436 * 437 * This is a little sloppy but we're trying to tighten it up. Unfortuately, 438 * both on X11 and darwin (IIRC) there might be additional arguments aimed 439 * for client libraries with GUI processes. So, using RTGetOpt or similar 440 * is a bit hard since we have to cope with unknown options. 441 */ 442 m_fShowStartVMErrors = true; 443 bool startVM = false; 444 bool fSeparateProcess = false; 445 QString vmNameOrUuid; 446 447 const QStringList &arguments = QCoreApplication::arguments(); 448 const int argc = arguments.size(); 449 int i = 1; 450 while (i < argc) 451 { 452 const QByteArray &argBytes = arguments.at(i).toUtf8(); 453 const char *arg = argBytes.constData(); 454 enum { OptType_Unknown, OptType_VMRunner, OptType_VMSelector, OptType_MaybeBoth } enmOptType = OptType_Unknown; 455 /* NOTE: the check here must match the corresponding check for the 456 * options to start a VM in main.cpp and hardenedmain.cpp exactly, 457 * otherwise there will be weird error messages. */ 458 if ( !::strcmp(arg, "--startvm") 459 || !::strcmp(arg, "-startvm")) 460 { 461 enmOptType = OptType_VMRunner; 462 if (++i < argc) 463 { 464 vmNameOrUuid = arguments.at(i); 465 startVM = true; 466 } 467 } 468 else if (!::strcmp(arg, "-separate") || !::strcmp(arg, "--separate")) 469 { 470 enmOptType = OptType_VMRunner; 471 fSeparateProcess = true; 472 } 473 #ifdef VBOX_GUI_WITH_PIDFILE 474 else if (!::strcmp(arg, "-pidfile") || !::strcmp(arg, "--pidfile")) 475 { 476 enmOptType = OptType_MaybeBoth; 477 if (++i < argc) 478 m_strPidFile = arguments.at(i); 479 } 480 #endif /* VBOX_GUI_WITH_PIDFILE */ 481 /* Visual state type options: */ 482 else if (!::strcmp(arg, "-normal") || !::strcmp(arg, "--normal")) 483 { 484 enmOptType = OptType_MaybeBoth; 485 visualStateType = UIVisualStateType_Normal; 486 } 487 else if (!::strcmp(arg, "-fullscreen") || !::strcmp(arg, "--fullscreen")) 488 { 489 enmOptType = OptType_MaybeBoth; 490 visualStateType = UIVisualStateType_Fullscreen; 491 } 492 else if (!::strcmp(arg, "-seamless") || !::strcmp(arg, "--seamless")) 493 { 494 enmOptType = OptType_MaybeBoth; 495 visualStateType = UIVisualStateType_Seamless; 496 } 497 else if (!::strcmp(arg, "-scale") || !::strcmp(arg, "--scale")) 498 { 499 enmOptType = OptType_MaybeBoth; 500 visualStateType = UIVisualStateType_Scale; 501 } 502 /* Passwords: */ 503 else if (!::strcmp(arg, "--settingspw")) 504 { 505 enmOptType = OptType_MaybeBoth; 506 if (++i < argc) 507 { 508 RTStrCopy(m_astrSettingsPw, sizeof(m_astrSettingsPw), arguments.at(i).toLocal8Bit().constData()); 509 m_fSettingsPwSet = true; 510 } 511 } 512 else if (!::strcmp(arg, "--settingspwfile")) 513 { 514 enmOptType = OptType_MaybeBoth; 515 if (++i < argc) 516 { 517 const QByteArray &argFileBytes = arguments.at(i).toLocal8Bit(); 518 const char *pszFile = argFileBytes.constData(); 519 bool fStdIn = !::strcmp(pszFile, "stdin"); 520 int vrc = VINF_SUCCESS; 521 PRTSTREAM pStrm; 522 if (!fStdIn) 523 vrc = RTStrmOpen(pszFile, "r", &pStrm); 524 else 525 pStrm = g_pStdIn; 526 if (RT_SUCCESS(vrc)) 527 { 528 size_t cbFile; 529 vrc = RTStrmReadEx(pStrm, m_astrSettingsPw, sizeof(m_astrSettingsPw) - 1, &cbFile); 530 if (RT_SUCCESS(vrc)) 531 { 532 if (cbFile >= sizeof(m_astrSettingsPw) - 1) 533 cbFile = sizeof(m_astrSettingsPw) - 1; 534 unsigned i; 535 for (i = 0; i < cbFile && !RT_C_IS_CNTRL(m_astrSettingsPw[i]); i++) 536 ; 537 m_astrSettingsPw[i] = '\0'; 538 m_fSettingsPwSet = true; 539 } 540 if (!fStdIn) 541 RTStrmClose(pStrm); 542 } 543 } 544 } 545 /* Misc options: */ 546 else if (!::strcmp(arg, "-comment") || !::strcmp(arg, "--comment")) 547 { 548 enmOptType = OptType_MaybeBoth; 549 ++i; 550 } 551 else if (!::strcmp(arg, "--no-startvm-errormsgbox")) 552 { 553 enmOptType = OptType_VMRunner; 554 m_fShowStartVMErrors = false; 555 } 556 else if (!::strcmp(arg, "--aggressive-caching")) 557 { 558 enmOptType = OptType_MaybeBoth; 559 m_fAgressiveCaching = true; 560 } 561 else if (!::strcmp(arg, "--no-aggressive-caching")) 562 { 563 enmOptType = OptType_MaybeBoth; 564 m_fAgressiveCaching = false; 565 } 566 else if (!::strcmp(arg, "--restore-current")) 567 { 568 enmOptType = OptType_VMRunner; 569 m_fRestoreCurrentSnapshot = true; 570 } 571 /* Ad hoc VM reconfig options: */ 572 else if (!::strcmp(arg, "--fda")) 573 { 574 enmOptType = OptType_VMRunner; 575 if (++i < argc) 576 m_strFloppyImage = arguments.at(i); 577 } 578 else if (!::strcmp(arg, "--dvd") || !::strcmp(arg, "--cdrom")) 579 { 580 enmOptType = OptType_VMRunner; 581 if (++i < argc) 582 m_strDvdImage = arguments.at(i); 583 } 584 /* VMM Options: */ 585 else if (!::strcmp(arg, "--disable-patm")) 586 { 587 enmOptType = OptType_VMRunner; 588 m_fDisablePatm = true; 589 } 590 else if (!::strcmp(arg, "--disable-csam")) 591 { 592 enmOptType = OptType_VMRunner; 593 m_fDisableCsam = true; 594 } 595 else if (!::strcmp(arg, "--recompile-supervisor")) 596 { 597 enmOptType = OptType_VMRunner; 598 m_fRecompileSupervisor = true; 599 } 600 else if (!::strcmp(arg, "--recompile-user")) 601 { 602 enmOptType = OptType_VMRunner; 603 m_fRecompileUser = true; 604 } 605 else if (!::strcmp(arg, "--recompile-all")) 606 { 607 enmOptType = OptType_VMRunner; 608 m_fDisablePatm = m_fDisableCsam = m_fRecompileSupervisor = m_fRecompileUser = true; 609 } 610 else if (!::strcmp(arg, "--execute-all-in-iem")) 611 { 612 enmOptType = OptType_VMRunner; 613 m_fDisablePatm = m_fDisableCsam = m_fExecuteAllInIem = true; 614 } 615 else if (!::strcmp(arg, "--warp-pct")) 616 { 617 enmOptType = OptType_VMRunner; 618 if (++i < argc) 619 m_uWarpPct = RTStrToUInt32(arguments.at(i).toLocal8Bit().constData()); 620 } 621 #ifdef VBOX_WITH_DEBUGGER_GUI 622 /* Debugger/Debugging options: */ 623 else if (!::strcmp(arg, "-dbg") || !::strcmp(arg, "--dbg")) 624 { 625 enmOptType = OptType_VMRunner; 626 setDebuggerVar(&m_fDbgEnabled, true); 627 } 628 else if (!::strcmp( arg, "-debug") || !::strcmp(arg, "--debug")) 629 { 630 enmOptType = OptType_VMRunner; 631 setDebuggerVar(&m_fDbgEnabled, true); 632 setDebuggerVar(&m_fDbgAutoShow, true); 633 setDebuggerVar(&m_fDbgAutoShowCommandLine, true); 634 setDebuggerVar(&m_fDbgAutoShowStatistics, true); 635 } 636 else if (!::strcmp(arg, "--debug-command-line")) 637 { 638 enmOptType = OptType_VMRunner; 639 setDebuggerVar(&m_fDbgEnabled, true); 640 setDebuggerVar(&m_fDbgAutoShow, true); 641 setDebuggerVar(&m_fDbgAutoShowCommandLine, true); 642 } 643 else if (!::strcmp(arg, "--debug-statistics")) 644 { 645 enmOptType = OptType_VMRunner; 646 setDebuggerVar(&m_fDbgEnabled, true); 647 setDebuggerVar(&m_fDbgAutoShow, true); 648 setDebuggerVar(&m_fDbgAutoShowStatistics, true); 649 } 650 else if (!::strcmp(arg, "--statistics-expand") || !::strcmp(arg, "--stats-expand")) 651 { 652 enmOptType = OptType_VMRunner; 653 if (++i < argc) 654 { 655 if (!m_strDbgStatisticsExpand.isEmpty()) 656 m_strDbgStatisticsExpand.append('|'); 657 m_strDbgStatisticsExpand.append(arguments.at(i)); 658 } 659 } 660 else if (!::strncmp(arg, RT_STR_TUPLE("--statistics-expand=")) || !::strncmp(arg, RT_STR_TUPLE("--stats-expand="))) 661 { 662 enmOptType = OptType_VMRunner; 663 if (!m_strDbgStatisticsExpand.isEmpty()) 664 m_strDbgStatisticsExpand.append('|'); 665 m_strDbgStatisticsExpand.append(arguments.at(i).section('=', 1)); 666 } 667 else if (!::strcmp(arg, "--statistics-filter") || !::strcmp(arg, "--stats-filter")) 668 { 669 enmOptType = OptType_VMRunner; 670 if (++i < argc) 671 m_strDbgStatisticsFilter = arguments.at(i); 672 } 673 else if (!::strncmp(arg, RT_STR_TUPLE("--statistics-filter=")) || !::strncmp(arg, RT_STR_TUPLE("--stats-filter="))) 674 { 675 enmOptType = OptType_VMRunner; 676 m_strDbgStatisticsFilter = arguments.at(i).section('=', 1); 677 } 678 else if (!::strcmp(arg, "-no-debug") || !::strcmp(arg, "--no-debug")) 679 { 680 enmOptType = OptType_VMRunner; 681 setDebuggerVar(&m_fDbgEnabled, false); 682 setDebuggerVar(&m_fDbgAutoShow, false); 683 setDebuggerVar(&m_fDbgAutoShowCommandLine, false); 684 setDebuggerVar(&m_fDbgAutoShowStatistics, false); 685 } 686 /* Not quite debug options, but they're only useful with the debugger bits. */ 687 else if (!::strcmp(arg, "--start-paused")) 688 { 689 enmOptType = OptType_VMRunner; 690 m_enmLaunchRunning = LaunchRunning_No; 691 } 692 else if (!::strcmp(arg, "--start-running")) 693 { 694 enmOptType = OptType_VMRunner; 695 m_enmLaunchRunning = LaunchRunning_Yes; 696 } 697 #endif 698 if (enmOptType == OptType_VMRunner && m_enmType != UIType_RuntimeUI) 699 msgCenter().warnAboutUnrelatedOptionType(arg); 700 701 i++; 702 } 703 704 if (m_enmType == UIType_RuntimeUI && startVM) 705 { 706 /* m_fSeparateProcess makes sense only if a VM is started. */ 707 m_fSeparateProcess = fSeparateProcess; 708 709 /* Search for corresponding VM: */ 710 QUuid uuid = QUuid(vmNameOrUuid); 711 const CMachine machine = m_comVBox.FindMachine(vmNameOrUuid); 712 if (!uuid.isNull()) 713 { 714 if (machine.isNull() && showStartVMErrors()) 715 return msgCenter().cannotFindMachineById(m_comVBox, vmNameOrUuid); 716 } 717 else 718 { 719 if (machine.isNull() && showStartVMErrors()) 720 return msgCenter().cannotFindMachineByName(m_comVBox, vmNameOrUuid); 721 } 722 m_strManagedVMId = machine.GetId(); 723 724 if (m_fSeparateProcess) 725 { 726 /* Create a log file for VirtualBoxVM process. */ 727 QString str = machine.GetLogFolder(); 728 com::Utf8Str logDir(str.toUtf8().constData()); 729 730 /* make sure the Logs folder exists */ 731 if (!RTDirExists(logDir.c_str())) 732 RTDirCreateFullPath(logDir.c_str(), 0700); 733 734 com::Utf8Str logFile = com::Utf8StrFmt("%s%cVBoxUI.log", 735 logDir.c_str(), RTPATH_DELIMITER); 736 737 com::VBoxLogRelCreate("GUI (separate)", logFile.c_str(), 738 RTLOGFLAGS_PREFIX_TIME_PROG | RTLOGFLAGS_RESTRICT_GROUPS, 739 "all all.restrict -default.restrict", 740 "VBOX_RELEASE_LOG", RTLOGDEST_FILE, 741 32768 /* cMaxEntriesPerGroup */, 742 0 /* cHistory */, 0 /* uHistoryFileTime */, 743 0 /* uHistoryFileSize */, NULL); 744 } 745 } 746 747 /* For Selector UI: */ 748 if (uiType() == UIType_SelectorUI) 749 { 750 /* We should create separate logging file for VM selector: */ 751 char szLogFile[RTPATH_MAX]; 752 const char *pszLogFile = NULL; 753 com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile)); 754 RTPathAppend(szLogFile, sizeof(szLogFile), "selectorwindow.log"); 755 pszLogFile = szLogFile; 756 /* Create release logger, to file: */ 757 com::VBoxLogRelCreate("GUI VM Selector Window", 758 pszLogFile, 759 RTLOGFLAGS_PREFIX_TIME_PROG, 760 "all", 761 "VBOX_GUI_SELECTORWINDOW_RELEASE_LOG", 762 RTLOGDEST_FILE | RTLOGDEST_F_NO_DENY, 763 UINT32_MAX, 764 10, 765 60 * 60, 766 _1M, 767 NULL /*pErrInfo*/); 768 769 LogRel(("Qt version: %s\n", qtRTVersionString().toUtf8().constData())); 770 } 771 772 if (m_fSettingsPwSet) 773 m_comVBox.SetSettingsSecret(m_astrSettingsPw); 774 775 if (visualStateType != UIVisualStateType_Invalid && !m_strManagedVMId.isNull()) 776 gEDataManager->setRequestedVisualState(visualStateType, m_strManagedVMId); 777 778 #ifdef VBOX_WITH_DEBUGGER_GUI 779 /* For Runtime UI: */ 780 if (uiType() == UIType_RuntimeUI) 781 { 782 /* Setup the debugger GUI: */ 783 if (RTEnvExist("VBOX_GUI_NO_DEBUGGER")) 784 m_fDbgEnabled = m_fDbgAutoShow = m_fDbgAutoShowCommandLine = m_fDbgAutoShowStatistics = false; 785 if (m_fDbgEnabled) 786 { 787 RTERRINFOSTATIC ErrInfo; 788 RTErrInfoInitStatic(&ErrInfo); 789 int vrc = SUPR3HardenedLdrLoadAppPriv("VBoxDbg", &m_hVBoxDbg, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core); 790 if (RT_FAILURE(vrc)) 791 { 792 m_hVBoxDbg = NIL_RTLDRMOD; 793 m_fDbgAutoShow = m_fDbgAutoShowCommandLine = m_fDbgAutoShowStatistics = false; 794 LogRel(("Failed to load VBoxDbg, rc=%Rrc - %s\n", vrc, ErrInfo.Core.pszMsg)); 795 } 796 } 797 } 798 #endif 799 800 m_fValid = true; 801 802 /* Create medium-enumerator but don't do any immediate caching: */ 803 m_pMediumEnumerator = new UIMediumEnumerator; 804 { 805 /* Prepare medium-enumerator: */ 806 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumCreated, 807 this, &UICommon::sigMediumCreated); 808 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumDeleted, 809 this, &UICommon::sigMediumDeleted); 810 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumEnumerationStarted, 811 this, &UICommon::sigMediumEnumerationStarted); 812 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumEnumerated, 813 this, &UICommon::sigMediumEnumerated); 814 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumEnumerationFinished, 815 this, &UICommon::sigMediumEnumerationFinished); 816 } 817 818 /* Create shortcut pool: */ 819 UIShortcutPool::create(); 820 821 #ifdef VBOX_GUI_WITH_NETWORK_MANAGER 822 /* Create network manager: */ 823 UINetworkRequestManager::create(); 824 825 /* Schedule update manager: */ 826 UIUpdateManager::schedule(); 827 #endif /* VBOX_GUI_WITH_NETWORK_MANAGER */ 828 829 #ifdef RT_OS_LINUX 830 /* Make sure no wrong USB mounted: */ 831 checkForWrongUSBMounted(); 832 #endif /* RT_OS_LINUX */ 833 834 /* Populate the list of medium names to be excluded from the 835 recently used media extra data: */ 836 #if 0 /* bird: This is counter productive as it is _frequently_ necessary to re-insert the 837 viso to refresh the files (like after you rebuilt them on the host). 838 The guest caches ISOs aggressively and files sizes may change. */ 839 m_recentMediaExcludeList << "ad-hoc.viso"; 840 #endif 841 } 842 843 void UICommon::cleanup() 844 { 845 LogRel(("GUI: UICommon: Handling aboutToQuit request..\n")); 846 847 /// @todo Shouldn't that be protected with a mutex or something? 848 /* Remember that the cleanup is in progress preventing any unwanted 849 * stuff which could be called from the other threads: */ 850 s_fCleaningUp = true; 851 852 #ifdef VBOX_WS_WIN 853 /* Ask listeners to commit data if haven't yet: */ 854 if (!m_fDataCommitted) 855 { 856 emit sigAskToCommitData(); 857 m_fDataCommitted = true; 858 } 859 #else 860 /* Ask listeners to commit data: */ 861 emit sigAskToCommitData(); 862 #endif 863 864 #ifdef VBOX_WITH_DEBUGGER_GUI 865 /* For Runtime UI: */ 866 if ( uiType() == UIType_RuntimeUI 867 && m_hVBoxDbg != NIL_RTLDRMOD) 868 { 869 RTLdrClose(m_hVBoxDbg); 870 m_hVBoxDbg = NIL_RTLDRMOD; 871 } 872 #endif 873 874 #ifdef VBOX_GUI_WITH_NETWORK_MANAGER 875 /* Shutdown update manager: */ 876 UIUpdateManager::shutdown(); 877 878 /* Destroy network manager: */ 879 UINetworkRequestManager::destroy(); 880 #endif /* VBOX_GUI_WITH_NETWORK_MANAGER */ 881 882 /* Destroy shortcut pool: */ 883 UIShortcutPool::destroy(); 884 885 #ifdef VBOX_GUI_WITH_PIDFILE 886 deletePidfile(); 887 #endif /* VBOX_GUI_WITH_PIDFILE */ 888 889 /* Starting medium-enumerator cleanup: */ 890 m_meCleanupProtectionToken.lockForWrite(); 891 { 892 /* Destroy medium-enumerator: */ 893 delete m_pMediumEnumerator; 894 m_pMediumEnumerator = 0; 895 } 896 /* Finishing medium-enumerator cleanup: */ 897 m_meCleanupProtectionToken.unlock(); 898 899 /* Destroy the global (VirtualBox and VirtualBoxClient) Main event 900 * handlers which are used in both Manager and Runtime UIs. */ 901 UIVirtualBoxEventHandler::destroy(); 902 UIVirtualBoxClientEventHandler::destroy(); 903 904 /* Destroy the extra-data manager finally after everything 905 * above which could use it already destroyed: */ 906 UIExtraDataManager::destroy(); 907 908 /* Destroy converter: */ 909 UIConverter::destroy(); 910 911 /* Cleanup thread-pools: */ 912 delete m_pThreadPool; 913 m_pThreadPool = 0; 914 delete m_pThreadPoolCloud; 915 m_pThreadPoolCloud = 0; 916 /* Cleanup general icon-pool: */ 917 delete m_pIconPool; 918 m_pIconPool = 0; 919 920 /* Ensure CGuestOSType objects are no longer used: */ 921 m_guestOSFamilyIDs.clear(); 922 m_guestOSTypes.clear(); 923 924 /* Starting COM cleanup: */ 925 m_comCleanupProtectionToken.lockForWrite(); 926 { 927 /* First, make sure we don't use COM any more: */ 928 emit sigAskToDetachCOM(); 929 m_comHost.detach(); 930 m_comVBox.detach(); 931 m_comVBoxClient.detach(); 932 933 /* There may be UIMedium(s)EnumeratedEvent instances still in the message 934 * queue which reference COM objects. Remove them to release those objects 935 * before uninitializing the COM subsystem. */ 936 QApplication::removePostedEvents(this); 937 938 /* Finally cleanup COM itself: */ 939 COMBase::CleanupCOM(); 940 } 941 /* Finishing COM cleanup: */ 942 m_comCleanupProtectionToken.unlock(); 943 944 /* Notify listener it can close UI now: */ 945 emit sigAskToCloseUI(); 946 947 /* Destroy popup-center: */ 948 UIPopupCenter::destroy(); 949 /* Destroy message-center: */ 950 UIMessageCenter::destroy(); 951 952 /* Destroy desktop-widget watchdog: */ 953 UIDesktopWidgetWatchdog::destroy(); 954 955 m_fValid = false; 956 957 LogRel(("GUI: UICommon: aboutToQuit request handled!\n")); 958 } 959 328 960 /* static */ 329 961 QString UICommon::qtRTVersionString() … … 4114 4746 } 4115 4747 4116 void UICommon::prepare()4117 {4118 /* Make sure QApplication cleanup us on exit: */4119 qApp->setFallbackSessionManagementEnabled(false);4120 connect(qApp, &QGuiApplication::aboutToQuit,4121 this, &UICommon::cleanup);4122 #ifndef VBOX_GUI_WITH_CUSTOMIZATIONS14123 /* Make sure we handle host OS session shutdown as well: */4124 connect(qApp, &QGuiApplication::commitDataRequest,4125 this, &UICommon::sltHandleCommitDataRequest);4126 #endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */4127 4128 #ifdef VBOX_WS_MAC4129 /* Determine OS release early: */4130 m_enmMacOSVersion = determineOsRelease();4131 #endif /* VBOX_WS_MAC */4132 4133 /* Create converter: */4134 UIConverter::create();4135 4136 /* Create desktop-widget watchdog: */4137 UIDesktopWidgetWatchdog::create();4138 4139 /* Create message-center: */4140 UIMessageCenter::create();4141 /* Create popup-center: */4142 UIPopupCenter::create();4143 4144 /* Prepare general icon-pool: */4145 m_pIconPool = new UIIconPoolGeneral;4146 4147 /* Load translation based on the current locale: */4148 loadLanguage();4149 4150 HRESULT rc = COMBase::InitializeCOM(true);4151 if (FAILED(rc))4152 {4153 #ifdef VBOX_WITH_XPCOM4154 if (rc == NS_ERROR_FILE_ACCESS_DENIED)4155 {4156 char szHome[RTPATH_MAX] = "";4157 com::GetVBoxUserHomeDirectory(szHome, sizeof(szHome));4158 msgCenter().cannotInitUserHome(QString(szHome));4159 }4160 else4161 #endif4162 msgCenter().cannotInitCOM(rc);4163 return;4164 }4165 4166 /* Make sure VirtualBoxClient instance created: */4167 m_comVBoxClient.createInstance(CLSID_VirtualBoxClient);4168 if (!m_comVBoxClient.isOk())4169 {4170 msgCenter().cannotCreateVirtualBoxClient(m_comVBoxClient);4171 return;4172 }4173 /* Make sure VirtualBox instance acquired: */4174 m_comVBox = m_comVBoxClient.GetVirtualBox();4175 if (!m_comVBoxClient.isOk())4176 {4177 msgCenter().cannotAcquireVirtualBox(m_comVBoxClient);4178 return;4179 }4180 /* Init wrappers: */4181 comWrappersReinit();4182 4183 /* Watch for the VBoxSVC availability changes: */4184 connect(gVBoxClientEvents, &UIVirtualBoxClientEventHandler::sigVBoxSVCAvailabilityChange,4185 this, &UICommon::sltHandleVBoxSVCAvailabilityChange);4186 4187 /* Prepare thread-pool instances: */4188 m_pThreadPool = new UIThreadPool(3 /* worker count */, 5000 /* worker timeout */);4189 m_pThreadPoolCloud = new UIThreadPool(2 /* worker count */, 1000 /* worker timeout */);4190 4191 #ifdef VBOX_WS_WIN4192 /* Load color theme: */4193 loadColorTheme();4194 #endif4195 4196 /* Load translation based on the user settings: */4197 QString sLanguageId = gEDataManager->languageId();4198 if (!sLanguageId.isNull())4199 loadLanguage(sLanguageId);4200 4201 retranslateUi();4202 4203 connect(gEDataManager, &UIExtraDataManager::sigLanguageChange,4204 this, &UICommon::sltGUILanguageChange);4205 4206 qApp->installEventFilter(this);4207 4208 /* process command line */4209 4210 UIVisualStateType visualStateType = UIVisualStateType_Invalid;4211 4212 #ifdef VBOX_WS_X114213 /* Check whether we have compositing manager running: */4214 m_fCompositingManagerRunning = X11IsCompositingManagerRunning();4215 4216 /* Acquire current Window Manager type: */4217 m_enmWindowManagerType = X11WindowManagerType();4218 #endif /* VBOX_WS_X11 */4219 4220 #ifdef VBOX_WITH_DEBUGGER_GUI4221 # ifdef VBOX_WITH_DEBUGGER_GUI_MENU4222 initDebuggerVar(&m_fDbgEnabled, "VBOX_GUI_DBG_ENABLED", GUI_Dbg_Enabled, true);4223 # else4224 initDebuggerVar(&m_fDbgEnabled, "VBOX_GUI_DBG_ENABLED", GUI_Dbg_Enabled, false);4225 # endif4226 initDebuggerVar(&m_fDbgAutoShow, "VBOX_GUI_DBG_AUTO_SHOW", GUI_Dbg_AutoShow, false);4227 m_fDbgAutoShowCommandLine = m_fDbgAutoShowStatistics = m_fDbgAutoShow;4228 #endif4229 4230 /*4231 * Parse the command line options.4232 *4233 * This is a little sloppy but we're trying to tighten it up. Unfortuately,4234 * both on X11 and darwin (IIRC) there might be additional arguments aimed4235 * for client libraries with GUI processes. So, using RTGetOpt or similar4236 * is a bit hard since we have to cope with unknown options.4237 */4238 m_fShowStartVMErrors = true;4239 bool startVM = false;4240 bool fSeparateProcess = false;4241 QString vmNameOrUuid;4242 4243 const QStringList &arguments = QCoreApplication::arguments();4244 const int argc = arguments.size();4245 int i = 1;4246 while (i < argc)4247 {4248 const QByteArray &argBytes = arguments.at(i).toUtf8();4249 const char *arg = argBytes.constData();4250 enum { OptType_Unknown, OptType_VMRunner, OptType_VMSelector, OptType_MaybeBoth } enmOptType = OptType_Unknown;4251 /* NOTE: the check here must match the corresponding check for the4252 * options to start a VM in main.cpp and hardenedmain.cpp exactly,4253 * otherwise there will be weird error messages. */4254 if ( !::strcmp(arg, "--startvm")4255 || !::strcmp(arg, "-startvm"))4256 {4257 enmOptType = OptType_VMRunner;4258 if (++i < argc)4259 {4260 vmNameOrUuid = arguments.at(i);4261 startVM = true;4262 }4263 }4264 else if (!::strcmp(arg, "-separate") || !::strcmp(arg, "--separate"))4265 {4266 enmOptType = OptType_VMRunner;4267 fSeparateProcess = true;4268 }4269 #ifdef VBOX_GUI_WITH_PIDFILE4270 else if (!::strcmp(arg, "-pidfile") || !::strcmp(arg, "--pidfile"))4271 {4272 enmOptType = OptType_MaybeBoth;4273 if (++i < argc)4274 m_strPidFile = arguments.at(i);4275 }4276 #endif /* VBOX_GUI_WITH_PIDFILE */4277 /* Visual state type options: */4278 else if (!::strcmp(arg, "-normal") || !::strcmp(arg, "--normal"))4279 {4280 enmOptType = OptType_MaybeBoth;4281 visualStateType = UIVisualStateType_Normal;4282 }4283 else if (!::strcmp(arg, "-fullscreen") || !::strcmp(arg, "--fullscreen"))4284 {4285 enmOptType = OptType_MaybeBoth;4286 visualStateType = UIVisualStateType_Fullscreen;4287 }4288 else if (!::strcmp(arg, "-seamless") || !::strcmp(arg, "--seamless"))4289 {4290 enmOptType = OptType_MaybeBoth;4291 visualStateType = UIVisualStateType_Seamless;4292 }4293 else if (!::strcmp(arg, "-scale") || !::strcmp(arg, "--scale"))4294 {4295 enmOptType = OptType_MaybeBoth;4296 visualStateType = UIVisualStateType_Scale;4297 }4298 /* Passwords: */4299 else if (!::strcmp(arg, "--settingspw"))4300 {4301 enmOptType = OptType_MaybeBoth;4302 if (++i < argc)4303 {4304 RTStrCopy(m_astrSettingsPw, sizeof(m_astrSettingsPw), arguments.at(i).toLocal8Bit().constData());4305 m_fSettingsPwSet = true;4306 }4307 }4308 else if (!::strcmp(arg, "--settingspwfile"))4309 {4310 enmOptType = OptType_MaybeBoth;4311 if (++i < argc)4312 {4313 const QByteArray &argFileBytes = arguments.at(i).toLocal8Bit();4314 const char *pszFile = argFileBytes.constData();4315 bool fStdIn = !::strcmp(pszFile, "stdin");4316 int vrc = VINF_SUCCESS;4317 PRTSTREAM pStrm;4318 if (!fStdIn)4319 vrc = RTStrmOpen(pszFile, "r", &pStrm);4320 else4321 pStrm = g_pStdIn;4322 if (RT_SUCCESS(vrc))4323 {4324 size_t cbFile;4325 vrc = RTStrmReadEx(pStrm, m_astrSettingsPw, sizeof(m_astrSettingsPw) - 1, &cbFile);4326 if (RT_SUCCESS(vrc))4327 {4328 if (cbFile >= sizeof(m_astrSettingsPw) - 1)4329 cbFile = sizeof(m_astrSettingsPw) - 1;4330 unsigned i;4331 for (i = 0; i < cbFile && !RT_C_IS_CNTRL(m_astrSettingsPw[i]); i++)4332 ;4333 m_astrSettingsPw[i] = '\0';4334 m_fSettingsPwSet = true;4335 }4336 if (!fStdIn)4337 RTStrmClose(pStrm);4338 }4339 }4340 }4341 /* Misc options: */4342 else if (!::strcmp(arg, "-comment") || !::strcmp(arg, "--comment"))4343 {4344 enmOptType = OptType_MaybeBoth;4345 ++i;4346 }4347 else if (!::strcmp(arg, "--no-startvm-errormsgbox"))4348 {4349 enmOptType = OptType_VMRunner;4350 m_fShowStartVMErrors = false;4351 }4352 else if (!::strcmp(arg, "--aggressive-caching"))4353 {4354 enmOptType = OptType_MaybeBoth;4355 m_fAgressiveCaching = true;4356 }4357 else if (!::strcmp(arg, "--no-aggressive-caching"))4358 {4359 enmOptType = OptType_MaybeBoth;4360 m_fAgressiveCaching = false;4361 }4362 else if (!::strcmp(arg, "--restore-current"))4363 {4364 enmOptType = OptType_VMRunner;4365 m_fRestoreCurrentSnapshot = true;4366 }4367 /* Ad hoc VM reconfig options: */4368 else if (!::strcmp(arg, "--fda"))4369 {4370 enmOptType = OptType_VMRunner;4371 if (++i < argc)4372 m_strFloppyImage = arguments.at(i);4373 }4374 else if (!::strcmp(arg, "--dvd") || !::strcmp(arg, "--cdrom"))4375 {4376 enmOptType = OptType_VMRunner;4377 if (++i < argc)4378 m_strDvdImage = arguments.at(i);4379 }4380 /* VMM Options: */4381 else if (!::strcmp(arg, "--disable-patm"))4382 {4383 enmOptType = OptType_VMRunner;4384 m_fDisablePatm = true;4385 }4386 else if (!::strcmp(arg, "--disable-csam"))4387 {4388 enmOptType = OptType_VMRunner;4389 m_fDisableCsam = true;4390 }4391 else if (!::strcmp(arg, "--recompile-supervisor"))4392 {4393 enmOptType = OptType_VMRunner;4394 m_fRecompileSupervisor = true;4395 }4396 else if (!::strcmp(arg, "--recompile-user"))4397 {4398 enmOptType = OptType_VMRunner;4399 m_fRecompileUser = true;4400 }4401 else if (!::strcmp(arg, "--recompile-all"))4402 {4403 enmOptType = OptType_VMRunner;4404 m_fDisablePatm = m_fDisableCsam = m_fRecompileSupervisor = m_fRecompileUser = true;4405 }4406 else if (!::strcmp(arg, "--execute-all-in-iem"))4407 {4408 enmOptType = OptType_VMRunner;4409 m_fDisablePatm = m_fDisableCsam = m_fExecuteAllInIem = true;4410 }4411 else if (!::strcmp(arg, "--warp-pct"))4412 {4413 enmOptType = OptType_VMRunner;4414 if (++i < argc)4415 m_uWarpPct = RTStrToUInt32(arguments.at(i).toLocal8Bit().constData());4416 }4417 #ifdef VBOX_WITH_DEBUGGER_GUI4418 /* Debugger/Debugging options: */4419 else if (!::strcmp(arg, "-dbg") || !::strcmp(arg, "--dbg"))4420 {4421 enmOptType = OptType_VMRunner;4422 setDebuggerVar(&m_fDbgEnabled, true);4423 }4424 else if (!::strcmp( arg, "-debug") || !::strcmp(arg, "--debug"))4425 {4426 enmOptType = OptType_VMRunner;4427 setDebuggerVar(&m_fDbgEnabled, true);4428 setDebuggerVar(&m_fDbgAutoShow, true);4429 setDebuggerVar(&m_fDbgAutoShowCommandLine, true);4430 setDebuggerVar(&m_fDbgAutoShowStatistics, true);4431 }4432 else if (!::strcmp(arg, "--debug-command-line"))4433 {4434 enmOptType = OptType_VMRunner;4435 setDebuggerVar(&m_fDbgEnabled, true);4436 setDebuggerVar(&m_fDbgAutoShow, true);4437 setDebuggerVar(&m_fDbgAutoShowCommandLine, true);4438 }4439 else if (!::strcmp(arg, "--debug-statistics"))4440 {4441 enmOptType = OptType_VMRunner;4442 setDebuggerVar(&m_fDbgEnabled, true);4443 setDebuggerVar(&m_fDbgAutoShow, true);4444 setDebuggerVar(&m_fDbgAutoShowStatistics, true);4445 }4446 else if (!::strcmp(arg, "--statistics-expand") || !::strcmp(arg, "--stats-expand"))4447 {4448 enmOptType = OptType_VMRunner;4449 if (++i < argc)4450 {4451 if (!m_strDbgStatisticsExpand.isEmpty())4452 m_strDbgStatisticsExpand.append('|');4453 m_strDbgStatisticsExpand.append(arguments.at(i));4454 }4455 }4456 else if (!::strncmp(arg, RT_STR_TUPLE("--statistics-expand=")) || !::strncmp(arg, RT_STR_TUPLE("--stats-expand=")))4457 {4458 enmOptType = OptType_VMRunner;4459 if (!m_strDbgStatisticsExpand.isEmpty())4460 m_strDbgStatisticsExpand.append('|');4461 m_strDbgStatisticsExpand.append(arguments.at(i).section('=', 1));4462 }4463 else if (!::strcmp(arg, "--statistics-filter") || !::strcmp(arg, "--stats-filter"))4464 {4465 enmOptType = OptType_VMRunner;4466 if (++i < argc)4467 m_strDbgStatisticsFilter = arguments.at(i);4468 }4469 else if (!::strncmp(arg, RT_STR_TUPLE("--statistics-filter=")) || !::strncmp(arg, RT_STR_TUPLE("--stats-filter=")))4470 {4471 enmOptType = OptType_VMRunner;4472 m_strDbgStatisticsFilter = arguments.at(i).section('=', 1);4473 }4474 else if (!::strcmp(arg, "-no-debug") || !::strcmp(arg, "--no-debug"))4475 {4476 enmOptType = OptType_VMRunner;4477 setDebuggerVar(&m_fDbgEnabled, false);4478 setDebuggerVar(&m_fDbgAutoShow, false);4479 setDebuggerVar(&m_fDbgAutoShowCommandLine, false);4480 setDebuggerVar(&m_fDbgAutoShowStatistics, false);4481 }4482 /* Not quite debug options, but they're only useful with the debugger bits. */4483 else if (!::strcmp(arg, "--start-paused"))4484 {4485 enmOptType = OptType_VMRunner;4486 m_enmLaunchRunning = LaunchRunning_No;4487 }4488 else if (!::strcmp(arg, "--start-running"))4489 {4490 enmOptType = OptType_VMRunner;4491 m_enmLaunchRunning = LaunchRunning_Yes;4492 }4493 #endif4494 if (enmOptType == OptType_VMRunner && m_enmType != UIType_RuntimeUI)4495 msgCenter().warnAboutUnrelatedOptionType(arg);4496 4497 i++;4498 }4499 4500 if (m_enmType == UIType_RuntimeUI && startVM)4501 {4502 /* m_fSeparateProcess makes sense only if a VM is started. */4503 m_fSeparateProcess = fSeparateProcess;4504 4505 /* Search for corresponding VM: */4506 QUuid uuid = QUuid(vmNameOrUuid);4507 const CMachine machine = m_comVBox.FindMachine(vmNameOrUuid);4508 if (!uuid.isNull())4509 {4510 if (machine.isNull() && showStartVMErrors())4511 return msgCenter().cannotFindMachineById(m_comVBox, vmNameOrUuid);4512 }4513 else4514 {4515 if (machine.isNull() && showStartVMErrors())4516 return msgCenter().cannotFindMachineByName(m_comVBox, vmNameOrUuid);4517 }4518 m_strManagedVMId = machine.GetId();4519 4520 if (m_fSeparateProcess)4521 {4522 /* Create a log file for VirtualBoxVM process. */4523 QString str = machine.GetLogFolder();4524 com::Utf8Str logDir(str.toUtf8().constData());4525 4526 /* make sure the Logs folder exists */4527 if (!RTDirExists(logDir.c_str()))4528 RTDirCreateFullPath(logDir.c_str(), 0700);4529 4530 com::Utf8Str logFile = com::Utf8StrFmt("%s%cVBoxUI.log",4531 logDir.c_str(), RTPATH_DELIMITER);4532 4533 com::VBoxLogRelCreate("GUI (separate)", logFile.c_str(),4534 RTLOGFLAGS_PREFIX_TIME_PROG | RTLOGFLAGS_RESTRICT_GROUPS,4535 "all all.restrict -default.restrict",4536 "VBOX_RELEASE_LOG", RTLOGDEST_FILE,4537 32768 /* cMaxEntriesPerGroup */,4538 0 /* cHistory */, 0 /* uHistoryFileTime */,4539 0 /* uHistoryFileSize */, NULL);4540 }4541 }4542 4543 /* For Selector UI: */4544 if (uiType() == UIType_SelectorUI)4545 {4546 /* We should create separate logging file for VM selector: */4547 char szLogFile[RTPATH_MAX];4548 const char *pszLogFile = NULL;4549 com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile));4550 RTPathAppend(szLogFile, sizeof(szLogFile), "selectorwindow.log");4551 pszLogFile = szLogFile;4552 /* Create release logger, to file: */4553 com::VBoxLogRelCreate("GUI VM Selector Window",4554 pszLogFile,4555 RTLOGFLAGS_PREFIX_TIME_PROG,4556 "all",4557 "VBOX_GUI_SELECTORWINDOW_RELEASE_LOG",4558 RTLOGDEST_FILE | RTLOGDEST_F_NO_DENY,4559 UINT32_MAX,4560 10,4561 60 * 60,4562 _1M,4563 NULL /*pErrInfo*/);4564 4565 LogRel(("Qt version: %s\n", qtRTVersionString().toUtf8().constData()));4566 }4567 4568 if (m_fSettingsPwSet)4569 m_comVBox.SetSettingsSecret(m_astrSettingsPw);4570 4571 if (visualStateType != UIVisualStateType_Invalid && !m_strManagedVMId.isNull())4572 gEDataManager->setRequestedVisualState(visualStateType, m_strManagedVMId);4573 4574 #ifdef VBOX_WITH_DEBUGGER_GUI4575 /* For Runtime UI: */4576 if (uiType() == UIType_RuntimeUI)4577 {4578 /* Setup the debugger GUI: */4579 if (RTEnvExist("VBOX_GUI_NO_DEBUGGER"))4580 m_fDbgEnabled = m_fDbgAutoShow = m_fDbgAutoShowCommandLine = m_fDbgAutoShowStatistics = false;4581 if (m_fDbgEnabled)4582 {4583 RTERRINFOSTATIC ErrInfo;4584 RTErrInfoInitStatic(&ErrInfo);4585 int vrc = SUPR3HardenedLdrLoadAppPriv("VBoxDbg", &m_hVBoxDbg, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);4586 if (RT_FAILURE(vrc))4587 {4588 m_hVBoxDbg = NIL_RTLDRMOD;4589 m_fDbgAutoShow = m_fDbgAutoShowCommandLine = m_fDbgAutoShowStatistics = false;4590 LogRel(("Failed to load VBoxDbg, rc=%Rrc - %s\n", vrc, ErrInfo.Core.pszMsg));4591 }4592 }4593 }4594 #endif4595 4596 m_fValid = true;4597 4598 /* Create medium-enumerator but don't do any immediate caching: */4599 m_pMediumEnumerator = new UIMediumEnumerator;4600 {4601 /* Prepare medium-enumerator: */4602 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumCreated,4603 this, &UICommon::sigMediumCreated);4604 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumDeleted,4605 this, &UICommon::sigMediumDeleted);4606 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumEnumerationStarted,4607 this, &UICommon::sigMediumEnumerationStarted);4608 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumEnumerated,4609 this, &UICommon::sigMediumEnumerated);4610 connect(m_pMediumEnumerator, &UIMediumEnumerator::sigMediumEnumerationFinished,4611 this, &UICommon::sigMediumEnumerationFinished);4612 }4613 4614 /* Create shortcut pool: */4615 UIShortcutPool::create();4616 4617 #ifdef VBOX_GUI_WITH_NETWORK_MANAGER4618 /* Create network manager: */4619 UINetworkRequestManager::create();4620 4621 /* Schedule update manager: */4622 UIUpdateManager::schedule();4623 #endif /* VBOX_GUI_WITH_NETWORK_MANAGER */4624 4625 #ifdef RT_OS_LINUX4626 /* Make sure no wrong USB mounted: */4627 checkForWrongUSBMounted();4628 #endif /* RT_OS_LINUX */4629 4630 /* Populate the list of medium names to be excluded from the4631 recently used media extra data: */4632 #if 0 /* bird: This is counter productive as it is _frequently_ necessary to re-insert the4633 viso to refresh the files (like after you rebuilt them on the host).4634 The guest caches ISOs aggressively and files sizes may change. */4635 m_recentMediaExcludeList << "ad-hoc.viso";4636 #endif4637 }4638 4639 void UICommon::cleanup()4640 {4641 LogRel(("GUI: UICommon: Handling aboutToQuit request..\n"));4642 4643 /// @todo Shouldn't that be protected with a mutex or something?4644 /* Remember that the cleanup is in progress preventing any unwanted4645 * stuff which could be called from the other threads: */4646 s_fCleaningUp = true;4647 4648 #ifdef VBOX_WS_WIN4649 /* Ask listeners to commit data if haven't yet: */4650 if (!m_fDataCommitted)4651 {4652 emit sigAskToCommitData();4653 m_fDataCommitted = true;4654 }4655 #else4656 /* Ask listeners to commit data: */4657 emit sigAskToCommitData();4658 #endif4659 4660 #ifdef VBOX_WITH_DEBUGGER_GUI4661 /* For Runtime UI: */4662 if ( uiType() == UIType_RuntimeUI4663 && m_hVBoxDbg != NIL_RTLDRMOD)4664 {4665 RTLdrClose(m_hVBoxDbg);4666 m_hVBoxDbg = NIL_RTLDRMOD;4667 }4668 #endif4669 4670 #ifdef VBOX_GUI_WITH_NETWORK_MANAGER4671 /* Shutdown update manager: */4672 UIUpdateManager::shutdown();4673 4674 /* Destroy network manager: */4675 UINetworkRequestManager::destroy();4676 #endif /* VBOX_GUI_WITH_NETWORK_MANAGER */4677 4678 /* Destroy shortcut pool: */4679 UIShortcutPool::destroy();4680 4681 #ifdef VBOX_GUI_WITH_PIDFILE4682 deletePidfile();4683 #endif /* VBOX_GUI_WITH_PIDFILE */4684 4685 /* Starting medium-enumerator cleanup: */4686 m_meCleanupProtectionToken.lockForWrite();4687 {4688 /* Destroy medium-enumerator: */4689 delete m_pMediumEnumerator;4690 m_pMediumEnumerator = 0;4691 }4692 /* Finishing medium-enumerator cleanup: */4693 m_meCleanupProtectionToken.unlock();4694 4695 /* Destroy the global (VirtualBox and VirtualBoxClient) Main event4696 * handlers which are used in both Manager and Runtime UIs. */4697 UIVirtualBoxEventHandler::destroy();4698 UIVirtualBoxClientEventHandler::destroy();4699 4700 /* Destroy the extra-data manager finally after everything4701 * above which could use it already destroyed: */4702 UIExtraDataManager::destroy();4703 4704 /* Destroy converter: */4705 UIConverter::destroy();4706 4707 /* Cleanup thread-pools: */4708 delete m_pThreadPool;4709 m_pThreadPool = 0;4710 delete m_pThreadPoolCloud;4711 m_pThreadPoolCloud = 0;4712 /* Cleanup general icon-pool: */4713 delete m_pIconPool;4714 m_pIconPool = 0;4715 4716 /* Ensure CGuestOSType objects are no longer used: */4717 m_guestOSFamilyIDs.clear();4718 m_guestOSTypes.clear();4719 4720 /* Starting COM cleanup: */4721 m_comCleanupProtectionToken.lockForWrite();4722 {4723 /* First, make sure we don't use COM any more: */4724 emit sigAskToDetachCOM();4725 m_comHost.detach();4726 m_comVBox.detach();4727 m_comVBoxClient.detach();4728 4729 /* There may be UIMedium(s)EnumeratedEvent instances still in the message4730 * queue which reference COM objects. Remove them to release those objects4731 * before uninitializing the COM subsystem. */4732 QApplication::removePostedEvents(this);4733 4734 /* Finally cleanup COM itself: */4735 COMBase::CleanupCOM();4736 }4737 /* Finishing COM cleanup: */4738 m_comCleanupProtectionToken.unlock();4739 4740 /* Notify listener it can close UI now: */4741 emit sigAskToCloseUI();4742 4743 /* Destroy popup-center: */4744 UIPopupCenter::destroy();4745 /* Destroy message-center: */4746 UIMessageCenter::destroy();4747 4748 /* Destroy desktop-widget watchdog: */4749 UIDesktopWidgetWatchdog::destroy();4750 4751 m_fValid = false;4752 4753 LogRel(("GUI: UICommon: aboutToQuit request handled!\n"));4754 }4755 4756 4748 #ifndef VBOX_GUI_WITH_CUSTOMIZATIONS1 4757 4749 void UICommon::sltHandleCommitDataRequest(QSessionManager &manager) -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h
r90937 r90938 765 765 protected slots: 766 766 767 /** Calls for cleanup() functionality. */ 768 void sltCleanup() { cleanup(); } 769 770 #ifndef VBOX_GUI_WITH_CUSTOMIZATIONS1 771 /** @name Common stuff. 772 * @{ */ 773 /** Handles @a manager request for emergency session shutdown. */ 774 void sltHandleCommitDataRequest(QSessionManager &manager); 775 /** @} */ 776 #endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */ 777 778 /** @name COM stuff. 779 * @{ */ 780 /** Handles the VBoxSVC availability change. */ 781 void sltHandleVBoxSVCAvailabilityChange(bool fAvailable); 782 /** @} */ 783 784 private: 785 786 /** Construcs global VirtualBox object of passed @a enmType. */ 787 UICommon(UIType enmType); 788 /** Destrucs global VirtualBox object. */ 789 virtual ~UICommon() /* override final */; 790 767 791 /** Prepares all. */ 768 792 void prepare(); 769 793 /** Cleanups all. */ 770 794 void cleanup(); 771 772 #ifndef VBOX_GUI_WITH_CUSTOMIZATIONS1773 /** @name Common stuff.774 * @{ */775 /** Handles @a manager request for emergency session shutdown. */776 void sltHandleCommitDataRequest(QSessionManager &manager);777 /** @} */778 #endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */779 780 /** @name COM stuff.781 * @{ */782 /** Handles the VBoxSVC availability change. */783 void sltHandleVBoxSVCAvailabilityChange(bool fAvailable);784 /** @} */785 786 private:787 788 /** Construcs global VirtualBox object of passed @a enmType. */789 UICommon(UIType enmType);790 791 /** Destrucs global VirtualBox object. */792 virtual ~UICommon() /* override */;793 794 795 795 796 /** @name COM: Virtual Media create functions.
Note:
See TracChangeset
for help on using the changeset viewer.

