VirtualBox

Changeset 88680 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 23, 2021 2:53:29 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8161: A bit of cleanup for UISession; Mostly prepare/cleanup cascade.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r88678 r88680  
    256256
    257257    /* Warn listeners about we are initialized: */
     258    m_fInitialized = true;
    258259    emit sigInitialized();
    259260
     
    594595{
    595596    /* Cleanup everything COM related: */
     597    cleanupFramebuffers();
    596598    cleanupConsoleEventHandlers();
    597     cleanupFramebuffers();
    598599    cleanupSession();
    599600}
     
    960961    , m_machineState(KMachineState_Null)
    961962    , m_pMachineWindowIcon(0)
    962 #ifdef VBOX_WS_WIN
    963     , m_alphaCursor(0)
    964 #endif /* VBOX_WS_WIN */
    965963#ifdef VBOX_WS_MAC
    966964    , m_pWatchdogDisplayChange(0)
     
    10091007bool UISession::prepare()
    10101008{
    1011     /* Prepare session: */
     1009    /* Prepare COM stuff: */
    10121010    if (!prepareSession())
    10131011        return false;
    1014 
    1015     /* Prepare actions: */
     1012    prepareConsoleEventHandlers();
     1013    prepareFramebuffers();
     1014
     1015    /* Prepare GUI stuff: */
    10161016    prepareActions();
    1017 
    1018     /* Prepare connections: */
    10191017    prepareConnections();
    1020 
    1021     /* Prepare console event-handlers: */
    1022     prepareConsoleEventHandlers();
    1023 
    1024     /* Prepare screens: */
     1018    prepareMachineWindowIcon();
    10251019    prepareScreens();
    1026 
    1027     /* Prepare framebuffers: */
    1028     prepareFramebuffers();
     1020    prepareSignalHandling();
    10291021
    10301022    /* Load settings: */
    10311023    loadSessionSettings();
    1032 
    1033 #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
    1034     struct sigaction sa;
    1035     sa.sa_sigaction = &signalHandlerSIGUSR1;
    1036     sigemptyset(&sa.sa_mask);
    1037     sa.sa_flags = SA_RESTART | SA_SIGINFO;
    1038     sigaction(SIGUSR1, &sa, NULL);
    1039 #endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
    10401024
    10411025    /* True by default: */
     
    10481032    m_session = uiCommon().openSession(uiCommon().managedVMUuid(),
    10491033                                         uiCommon().isSeparateProcess()
    1050                                          ? KLockType_Shared : KLockType_VM);
     1034                                       ? KLockType_Shared
     1035                                       : KLockType_VM);
    10511036    if (m_session.isNull())
    10521037        return false;
     
    10971082}
    10981083
     1084void UISession::prepareConsoleEventHandlers()
     1085{
     1086    /* Create console event-handler: */
     1087    UIConsoleEventHandler::create(this);
     1088
     1089    /* Add console event connections: */
     1090    connect(gConsoleEvents, &UIConsoleEventHandler::sigMousePointerShapeChange,
     1091            this, &UISession::sltMousePointerShapeChange);
     1092    connect(gConsoleEvents, &UIConsoleEventHandler::sigMouseCapabilityChange,
     1093            this, &UISession::sltMouseCapabilityChange);
     1094    connect(gConsoleEvents, &UIConsoleEventHandler::sigCursorPositionChange,
     1095            this, &UISession::sltCursorPositionChange);
     1096    connect(gConsoleEvents, &UIConsoleEventHandler::sigKeyboardLedsChangeEvent,
     1097            this, &UISession::sltKeyboardLedsChangeEvent);
     1098    connect(gConsoleEvents, &UIConsoleEventHandler::sigStateChange,
     1099            this, &UISession::sltStateChange);
     1100    connect(gConsoleEvents, &UIConsoleEventHandler::sigAdditionsChange,
     1101            this, &UISession::sltAdditionsChange);
     1102    connect(gConsoleEvents, &UIConsoleEventHandler::sigVRDEChange,
     1103            this, &UISession::sltVRDEChange);
     1104    connect(gConsoleEvents, &UIConsoleEventHandler::sigRecordingChange,
     1105            this, &UISession::sltRecordingChange);
     1106    connect(gConsoleEvents, &UIConsoleEventHandler::sigNetworkAdapterChange,
     1107            this, &UISession::sigNetworkAdapterChange);
     1108    connect(gConsoleEvents, &UIConsoleEventHandler::sigStorageDeviceChange,
     1109            this, &UISession::sltHandleStorageDeviceChange);
     1110    connect(gConsoleEvents, &UIConsoleEventHandler::sigMediumChange,
     1111            this, &UISession::sigMediumChange);
     1112    connect(gConsoleEvents, &UIConsoleEventHandler::sigUSBControllerChange,
     1113            this, &UISession::sigUSBControllerChange);
     1114    connect(gConsoleEvents, &UIConsoleEventHandler::sigUSBDeviceStateChange,
     1115            this, &UISession::sigUSBDeviceStateChange);
     1116    connect(gConsoleEvents, &UIConsoleEventHandler::sigSharedFolderChange,
     1117            this, &UISession::sigSharedFolderChange);
     1118    connect(gConsoleEvents, &UIConsoleEventHandler::sigRuntimeError,
     1119            this, &UISession::sigRuntimeError);
     1120#ifdef VBOX_WS_MAC
     1121    connect(gConsoleEvents, &UIConsoleEventHandler::sigShowWindow,
     1122            this, &UISession::sigShowWindows, Qt::QueuedConnection);
     1123#endif /* VBOX_WS_MAC */
     1124    connect(gConsoleEvents, &UIConsoleEventHandler::sigCPUExecutionCapChange,
     1125            this, &UISession::sigCPUExecutionCapChange);
     1126    connect(gConsoleEvents, &UIConsoleEventHandler::sigGuestMonitorChange,
     1127            this, &UISession::sltGuestMonitorChange);
     1128    connect(gConsoleEvents, &UIConsoleEventHandler::sigAudioAdapterChange,
     1129            this, &UISession::sltAudioAdapterChange);
     1130    connect(gConsoleEvents, &UIConsoleEventHandler::sigClipboardModeChange,
     1131            this, &UISession::sltClipboardModeChange);
     1132    connect(gConsoleEvents, &UIConsoleEventHandler::sigDnDModeChange,
     1133            this, &UISession::sltDnDModeChange);
     1134}
     1135
     1136void UISession::prepareFramebuffers()
     1137{
     1138    /* Each framebuffer will be really prepared on first UIMachineView creation: */
     1139    m_frameBufferVector.resize(machine().GetGraphicsAdapter().GetMonitorCount());
     1140}
     1141
    10991142void UISession::prepareActions()
    11001143{
    11011144    /* Create action-pool: */
    11021145    m_pActionPool = UIActionPool::create(UIActionPoolType_Runtime);
    1103     AssertPtrReturnVoid(actionPool());
    1104     {
     1146    if (actionPool())
     1147    {
     1148        /* Make sure action-pool knows guest-screen count: */
     1149        actionPool()->toRuntime()->setGuestScreenCount(m_frameBufferVector.size());
    11051150        /* Update action restrictions: */
    11061151        updateActionRestrictions();
     
    11091154        /* Create Mac OS X menu-bar: */
    11101155        m_pMenuBar = new QMenuBar;
    1111         AssertPtrReturnVoid(m_pMenuBar);
     1156        if (m_pMenuBar)
    11121157        {
    11131158            /* Configure Mac OS X menu-bar: */
     
    11231168void UISession::prepareConnections()
    11241169{
    1125     connect(this, &UISession::sigInitialized, this, &UISession::sltMarkInitialized);
     1170    /* UICommon connections: */
    11261171    connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UISession::sltDetachCOM);
    11271172
     
    11451190}
    11461191
    1147 void UISession::prepareConsoleEventHandlers()
    1148 {
    1149     /* Create console event-handler: */
    1150     UIConsoleEventHandler::create(this);
    1151 
    1152     /* Add console event connections: */
    1153     connect(gConsoleEvents, &UIConsoleEventHandler::sigMousePointerShapeChange,
    1154         this, &UISession::sltMousePointerShapeChange);
    1155 
    1156     connect(gConsoleEvents, &UIConsoleEventHandler::sigMouseCapabilityChange,
    1157             this, &UISession::sltMouseCapabilityChange);
    1158 
    1159     connect(gConsoleEvents, &UIConsoleEventHandler::sigCursorPositionChange,
    1160             this, &UISession::sltCursorPositionChange);
    1161 
    1162     connect(gConsoleEvents, &UIConsoleEventHandler::sigKeyboardLedsChangeEvent,
    1163             this, &UISession::sltKeyboardLedsChangeEvent);
    1164 
    1165     connect(gConsoleEvents, &UIConsoleEventHandler::sigStateChange,
    1166             this, &UISession::sltStateChange);
    1167 
    1168     connect(gConsoleEvents, &UIConsoleEventHandler::sigAdditionsChange,
    1169             this, &UISession::sltAdditionsChange);
    1170 
    1171     connect(gConsoleEvents, &UIConsoleEventHandler::sigVRDEChange,
    1172             this, &UISession::sltVRDEChange);
    1173 
    1174     connect(gConsoleEvents, &UIConsoleEventHandler::sigRecordingChange,
    1175             this, &UISession::sltRecordingChange);
    1176 
    1177     connect(gConsoleEvents, &UIConsoleEventHandler::sigNetworkAdapterChange,
    1178             this, &UISession::sigNetworkAdapterChange);
    1179 
    1180     connect(gConsoleEvents, &UIConsoleEventHandler::sigStorageDeviceChange,
    1181             this, &UISession::sltHandleStorageDeviceChange);
    1182 
    1183     connect(gConsoleEvents, &UIConsoleEventHandler::sigMediumChange,
    1184             this, &UISession::sigMediumChange);
    1185 
    1186     connect(gConsoleEvents, &UIConsoleEventHandler::sigUSBControllerChange,
    1187             this, &UISession::sigUSBControllerChange);
    1188 
    1189     connect(gConsoleEvents, &UIConsoleEventHandler::sigUSBDeviceStateChange,
    1190             this, &UISession::sigUSBDeviceStateChange);
    1191 
    1192     connect(gConsoleEvents, &UIConsoleEventHandler::sigSharedFolderChange,
    1193             this, &UISession::sigSharedFolderChange);
    1194 
    1195     connect(gConsoleEvents, &UIConsoleEventHandler::sigRuntimeError,
    1196             this, &UISession::sigRuntimeError);
    1197 
    1198 #ifdef VBOX_WS_MAC
    1199     connect(gConsoleEvents, &UIConsoleEventHandler::sigShowWindow,
    1200             this, &UISession::sigShowWindows, Qt::QueuedConnection);
    1201 #endif /* VBOX_WS_MAC */
    1202 
    1203     connect(gConsoleEvents, &UIConsoleEventHandler::sigCPUExecutionCapChange,
    1204             this, &UISession::sigCPUExecutionCapChange);
    1205 
    1206     connect(gConsoleEvents, &UIConsoleEventHandler::sigGuestMonitorChange,
    1207             this, &UISession::sltGuestMonitorChange);
    1208 
    1209     connect(gConsoleEvents, &UIConsoleEventHandler::sigAudioAdapterChange,
    1210             this, &UISession::sltAudioAdapterChange);
    1211 
    1212     connect(gConsoleEvents, &UIConsoleEventHandler::sigClipboardModeChange,
    1213         this, &UISession::sltClipboardModeChange);
    1214 
    1215     connect(gConsoleEvents, &UIConsoleEventHandler::sigDnDModeChange,
    1216             this, &UISession::sltDnDModeChange);
     1192void UISession::prepareMachineWindowIcon()
     1193{
     1194    /* Acquire user machine-window icon: */
     1195    QIcon icon = uiCommon().vmUserIcon(machine());
     1196    /* Use the OS type icon if user one was not set: */
     1197    if (icon.isNull())
     1198        icon = uiCommon().vmGuestOSTypeIcon(machine().GetOSTypeId());
     1199    /* Use the default icon if nothing else works: */
     1200    if (icon.isNull())
     1201        icon = QIcon(":/VirtualBox_48px.png");
     1202    /* Store the icon dynamically: */
     1203    m_pMachineWindowIcon = new QIcon(icon);
    12171204}
    12181205
     
    12881275}
    12891276
    1290 void UISession::prepareFramebuffers()
    1291 {
    1292     /* Each framebuffer will be really prepared on first UIMachineView creation: */
    1293     m_frameBufferVector.resize(machine().GetGraphicsAdapter().GetMonitorCount());
    1294 
    1295     /* Make sure action-pool knows guest-screen count: */
    1296     actionPool()->toRuntime()->setGuestScreenCount(m_frameBufferVector.size());
     1277void UISession::prepareSignalHandling()
     1278{
     1279#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
     1280    struct sigaction sa;
     1281    sa.sa_sigaction = &signalHandlerSIGUSR1;
     1282    sigemptyset(&sa.sa_mask);
     1283    sa.sa_flags = SA_RESTART | SA_SIGINFO;
     1284    sigaction(SIGUSR1, &sa, NULL);
     1285#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
    12971286}
    12981287
     
    13031292        /* Get machine ID: */
    13041293        const QUuid uMachineID = uiCommon().managedVMUuid();
    1305 
    1306         /* Prepare machine-window icon: */
    1307         {
    1308             /* Acquire user machine-window icon: */
    1309             QIcon icon = uiCommon().vmUserIcon(machine());
    1310             /* Use the OS type icon if user one was not set: */
    1311             if (icon.isNull())
    1312                 icon = uiCommon().vmGuestOSTypeIcon(machine().GetOSTypeId());
    1313             /* Use the default icon if nothing else works: */
    1314             if (icon.isNull())
    1315                 icon = QIcon(":/VirtualBox_48px.png");
    1316             /* Store the icon dynamically: */
    1317             m_pMachineWindowIcon = new QIcon(icon);
    1318         }
    13191294
    13201295#ifndef VBOX_WS_MAC
     
    13941369}
    13951370
    1396 void UISession::saveSessionSettings()
    1397 {
    1398     /* Save extra-data settings: */
    1399     {
    1400         /* Cleanup machine-window icon: */
    1401         delete m_pMachineWindowIcon;
    1402         m_pMachineWindowIcon = 0;
    1403     }
     1371void UISession::cleanupMachineWindowIcon()
     1372{
     1373    /* Cleanup machine-window icon: */
     1374    delete m_pMachineWindowIcon;
     1375    m_pMachineWindowIcon = 0;
     1376}
     1377
     1378void UISession::cleanupConnections()
     1379{
     1380#ifdef VBOX_WS_MAC
     1381    /* Remove display reconfiguration callback: */
     1382    CGDisplayRemoveReconfigurationCallback(cgDisplayReconfigurationCallback, this);
     1383#endif /* VBOX_WS_MAC */
     1384}
     1385
     1386void UISession::cleanupActions()
     1387{
     1388#ifdef VBOX_WS_MAC
     1389    /* Destroy Mac OS X menu-bar: */
     1390    delete m_pMenuBar;
     1391    m_pMenuBar = 0;
     1392#endif /* VBOX_WS_MAC */
     1393
     1394    /* Destroy action-pool if necessary: */
     1395    if (actionPool())
     1396        UIActionPool::destroy(actionPool());
    14041397}
    14051398
     
    14341427}
    14351428
    1436 void UISession::cleanupConnections()
    1437 {
    1438 #ifdef VBOX_WS_MAC
    1439     /* Remove display reconfiguration callback: */
    1440     CGDisplayRemoveReconfigurationCallback(cgDisplayReconfigurationCallback, this);
    1441 #endif /* VBOX_WS_MAC */
    1442 }
    1443 
    1444 void UISession::cleanupActions()
    1445 {
    1446 #ifdef VBOX_WS_MAC
    1447     /* Destroy Mac OS X menu-bar: */
    1448     delete m_pMenuBar;
    1449     m_pMenuBar = 0;
    1450 #endif /* VBOX_WS_MAC */
    1451 
    1452     /* Destroy action-pool if necessary: */
    1453     if (actionPool())
    1454         UIActionPool::destroy(actionPool());
    1455 }
    1456 
    14571429void UISession::cleanupSession()
    14581430{
     
    14951467void UISession::cleanup()
    14961468{
    1497 #ifdef VBOX_WS_WIN
    1498     /* Destroy alpha cursor: */
    1499     if (m_alphaCursor)
    1500         DestroyIcon(m_alphaCursor);
    1501 #endif /* VBOX_WS_WIN */
    1502 
    1503     /* Save settings: */
    1504     saveSessionSettings();
    1505 
    1506     /* Cleanup connections: */
     1469    /* Cleanup GUI stuff: */
     1470    //cleanupSignalHandling();
     1471    //cleanupScreens();
     1472    cleanupMachineWindowIcon();
    15071473    cleanupConnections();
    1508 
    1509     /* Cleanup actions: */
    15101474    cleanupActions();
    15111475}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r88678 r88680  
    362362private slots:
    363363
    364     /** Marks machine started. */
    365     void sltMarkInitialized() { m_fInitialized = true; }
    366 
    367364    /** Detaches COM. */
    368365    void sltDetachCOM();
     
    424421    bool prepare();
    425422    bool prepareSession();
     423    void prepareConsoleEventHandlers();
     424    void prepareFramebuffers();
    426425    void prepareActions();
    427426    void prepareConnections();
    428     void prepareConsoleEventHandlers();
     427    void prepareMachineWindowIcon();
    429428    void prepareScreens();
    430     void prepareFramebuffers();
     429    void prepareSignalHandling();
     430
     431    /* Settings stuff: */
    431432    void loadSessionSettings();
    432433
    433434    /* Cleanup helpers: */
    434     void saveSessionSettings();
    435     void cleanupFramebuffers();
     435    //void cleanupSignalHandling();
    436436    //void cleanupScreens() {}
    437     void cleanupConsoleEventHandlers();
     437    void cleanupMachineWindowIcon();
    438438    void cleanupConnections();
    439439    void cleanupActions();
     440    void cleanupFramebuffers();
     441    void cleanupConsoleEventHandlers();
    440442    void cleanupSession();
    441443    void cleanup();
     
    531533    /** @} */
    532534
    533 #if defined(VBOX_WS_WIN)
    534     HCURSOR m_alphaCursor;
    535 #endif
    536 
    537535    /** @name Host-screen configuration variables.
    538536     * @{ */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette