VirtualBox

Changeset 70899 in vbox


Ignore:
Timestamp:
Feb 8, 2018 9:03:30 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120727
Message:

FE/Qt: bugref:6699 Refactoring the event handler

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
6 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r70882 r70899  
    504504        src/wizards/firstrun/UIWizardFirstRun.h \
    505505        src/wizards/firstrun/UIWizardFirstRunPageBasic.h \
     506        src/runtime/information/UIGuestSessionsEventHandler.h \
    506507        src/runtime/information/UIInformationConfiguration.h \
    507508        src/runtime/information/UIInformationDataItem.h \
     
    551552        src/globals/UIMainEventListener.cpp \
    552553        src/globals/UIThreadPool.cpp \
    553     src/runtime/information/UIInformationGuestSession.cpp \
     554    src/runtime/information/UIGuestSessionsEventHandler.cpp \
    554555        src/logviewer/UIVMLogViewerFilterPanel.cpp \
    555556        src/logviewer/UIVMLogViewerSearchPanel.cpp \
     
    833834        src/wizards/firstrun/UIWizardFirstRun.cpp \
    834835        src/wizards/firstrun/UIWizardFirstRunPageBasic.cpp \
     836        src/runtime/information/UIGuestSessionsEventHandler.cpp \
    835837        src/runtime/information/UIInformationConfiguration.cpp \
    836838        src/runtime/information/UIInformationDataItem.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMainEventListener.cpp

    r70887 r70899  
    3030/* COM includes: */
    3131# include "COMEnums.h"
     32# include "CCanShowWindowEvent.h"
     33# include "CCursorPositionChangedEvent.h"
    3234# include "CEvent.h"
    3335# include "CEventSource.h"
    3436# include "CEventListener.h"
     37# include "CExtraDataCanChangeEvent.h"
     38# include "CExtraDataChangedEvent.h"
     39# include "CGuestMonitorChangedEvent.h"
     40#include  "CGuestProcessRegisteredEvent.h"
    3541# include "CGuestSessionRegisteredEvent.h"
    36 
    37 # include "CVBoxSVCAvailabilityChangedEvent.h"
    38 # include "CVirtualBoxErrorInfo.h"
     42# include "CKeyboardLedsChangedEvent.h"
    3943# include "CMachineStateChangedEvent.h"
    4044# include "CMachineDataChangedEvent.h"
    4145# include "CMachineRegisteredEvent.h"
     46# include "CMousePointerShapeChangedEvent.h"
     47# include "CMouseCapabilityChangedEvent.h"
     48# include "CMediumChangedEvent.h"
     49# include "CNetworkAdapterChangedEvent.h"
     50# include "CProgressPercentageChangedEvent.h"
     51# include "CProgressTaskCompletedEvent.h"
     52# include "CRuntimeErrorEvent.h"
    4253# include "CSessionStateChangedEvent.h"
     54# include "CShowWindowEvent.h"
    4355# include "CSnapshotTakenEvent.h"
    4456# include "CSnapshotDeletedEvent.h"
    4557# include "CSnapshotChangedEvent.h"
    4658# include "CSnapshotRestoredEvent.h"
    47 # include "CExtraDataCanChangeEvent.h"
    48 # include "CExtraDataChangedEvent.h"
    49 # include "CMousePointerShapeChangedEvent.h"
    50 # include "CMouseCapabilityChangedEvent.h"
    51 # include "CKeyboardLedsChangedEvent.h"
    5259# include "CStateChangedEvent.h"
    53 # include "CNetworkAdapterChangedEvent.h"
    5460# include "CStorageDeviceChangedEvent.h"
    55 # include "CMediumChangedEvent.h"
    5661# include "CUSBDevice.h"
    5762# include "CUSBDeviceStateChangedEvent.h"
    58 # include "CGuestMonitorChangedEvent.h"
    59 # include "CRuntimeErrorEvent.h"
    60 # include "CCanShowWindowEvent.h"
    61 # include "CShowWindowEvent.h"
    62 # include "CProgressPercentageChangedEvent.h"
    63 # include "CProgressTaskCompletedEvent.h"
    64 # include "CCursorPositionChangedEvent.h"
     63# include "CVBoxSVCAvailabilityChangedEvent.h"
     64# include "CVirtualBoxErrorInfo.h"
     65
    6566#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    6667
     
    430431        case KVBoxEventType_OnGuestSessionRegistered:
    431432        {
     433
    432434            CGuestSessionRegisteredEvent cEvent(pEvent);
    433             CGuestSession guestSession = cEvent.GetSession();
    434             emit sigGuestSessionRegistered(guestSession);
     435            if(cEvent.GetRegistered())
     436                emit sigGuestSessionRegistered(cEvent.GetSession());
     437            else
     438                emit sigGuestSessionUnregistered(cEvent.GetSession());
     439            break;
     440        }
     441        case KVBoxEventType_OnGuestProcessRegistered:
     442        {
     443            CGuestProcessRegisteredEvent cEvent(pEvent);
     444            if(cEvent.GetRegistered())
     445                emit sigGuestProcessRegistered(cEvent.GetProcess());
     446            else
     447                emit sigGuestProcessUnregistered(cEvent.GetProcess());
    435448            break;
    436449        }
    437450        case KVBoxEventType_OnGuestSessionStateChanged:
    438         case KVBoxEventType_OnGuestProcessRegistered:
     451        {
     452            emit sigGuestSessionStatedChanged();
     453            break;
     454        }
    439455        case KVBoxEventType_OnGuestProcessStateChanged:
    440456        case KVBoxEventType_OnGuestProcessInputNotify:
    441457        case KVBoxEventType_OnGuestProcessOutput:
     458        {
     459            emit sigGuestProcessStateChanged();
     460            break;
     461        }
    442462        case KVBoxEventType_OnGuestFileRegistered:
    443463        case KVBoxEventType_OnGuestFileStateChanged:
     
    446466        case KVBoxEventType_OnGuestFileWrite:
    447467        {
    448             //CGuestSessionRegisteredEvent ceve(pEvent);
     468            break;
    449469        }
    450470
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMainEventListener.h

    r70887 r70899  
    2525/* COM includes: */
    2626#include "COMEnums.h"
    27 #include "CVirtualBoxErrorInfo.h"
     27#include "CGuestProcess.h"
     28#include "CGuestSession.h"
    2829#include "CMediumAttachment.h"
    2930#include "CNetworkAdapter.h"
    3031#include "CUSBDevice.h"
    31 #include "CGuestSession.h"
     32#include "CVirtualBoxErrorInfo.h"
    3233
    3334/* Other VBox includes: */
     
    132133    void sigProgressTaskComplete(QString strProgressId);
    133134
    134     /** Notifies about guest session registered event @a is the registed guest session. */
    135     void sigGuestSessionRegistered(CGuestSession guestSession);
     135    /** @name Guest Session related signals
     136      * @{ */
     137        /** Notifies about guest session (un)registered event @a is the (un)registed guest session. */
     138        void sigGuestSessionRegistered(CGuestSession guestSession);
     139        void sigGuestSessionUnregistered(CGuestSession guestSession);
     140
     141        /** Notifies about guest process (un)registered event @a is the (un)registed guest process. */
     142        void sigGuestProcessRegistered(CGuestProcess guestProcess);
     143        void sigGuestProcessUnregistered(CGuestProcess guestProcess);
     144        void sigGuestSessionStatedChanged();
     145        void sigGuestProcessStateChanged();
     146    /** @} */
    136147
    137148public:
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIGuestSessionsEventHandler.cpp

    r70883 r70899  
    2121
    2222/* GUI includes: */
    23 # include "UIConsoleEventHandler.h"
     23# include "UIExtraDataManager.h"
     24# include "UIGuestSessionsEventHandler.h"
    2425# include "UIMainEventListener.h"
    25 # include "UIExtraDataManager.h"
    2626# include "VBoxGlobal.h"
    27 # include "UISession.h"
    28 # ifdef VBOX_WS_MAC
    29 #  include "VBoxUtils.h"
    30 # endif /* VBOX_WS_MAC */
     27
    3128
    3229/* COM includes: */
     30# include "COMEnums.h"
    3331# include "CEventListener.h"
    3432# include "CEventSource.h"
    35 # include "CConsole.h"
     33# include "CGuest.h"
    3634
    3735#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3836
    39 
    40 /** Private QObject extension
    41   * providing UIConsoleEventHandler with the CConsole event-source. */
    42 class UIConsoleEventHandlerProxy : public QObject
    43 {
     37class UIGuestSession;
     38class UIGuestProcess;
     39
     40/** Key is CGuestSession::GetId() */
     41typedef QMap<ULONG, UIGuestSession*> GuestSessionMap;
     42/** Key is PID */
     43typedef QMap<ULONG, UIGuestProcess*> GuestProcessMap;
     44
     45
     46/******************************************************************************************************
     47*   UIGuestProcess definition.                                                            *
     48******************************************************************************************************/
     49
     50class UIGuestProcess : public QObject
     51{
     52
    4453    Q_OBJECT;
    4554
    4655signals:
    4756
    48     /** Notifies about mouse pointer become @a fVisible and his shape changed to @a fAlpha, @a hotCorner, @a size and @a shape. */
    49     void sigMousePointerShapeChange(bool fVisible, bool fAlpha, QPoint hotCorner, QSize size, QVector<uint8_t> shape);
    50     /** Notifies about mouse capability change to @a fSupportsAbsolute, @a fSupportsRelative, @a fSupportsMultiTouch and @a fNeedsHostCursor. */
    51     void sigMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative, bool fSupportsMultiTouch, bool fNeedsHostCursor);
    52     /** Notifies about keyboard LEDs change for @a fNumLock, @a fCapsLock and @a fScrollLock. */
    53     void sigKeyboardLedsChangeEvent(bool fNumLock, bool fCapsLock, bool fScrollLock);
    54     /** Notifies about machine @a state change. */
    55     void sigStateChange(KMachineState state);
    56     /** Notifies about guest additions state change. */
    57     void sigAdditionsChange();
    58     /** Notifies about network @a adapter state change. */
    59     void sigNetworkAdapterChange(CNetworkAdapter adapter);
    60     /** Notifies about storage device change for @a attachment, which was @a fRemoved and it was @a fSilent for guest. */
    61     void sigStorageDeviceChange(CMediumAttachment attachment, bool fRemoved, bool fSilent);
    62     /** Notifies about storage medium @a attachment state change. */
    63     void sigMediumChange(CMediumAttachment attachment);
    64     /** Notifies about VRDE device state change. */
    65     void sigVRDEChange();
    66     /** Notifies about Video Capture device state change. */
    67     void sigVideoCaptureChange();
    68     /** Notifies about USB controller state change. */
    69     void sigUSBControllerChange();
    70     /** Notifies about USB @a device state change to @a fAttached, holding additional @a error information. */
    71     void sigUSBDeviceStateChange(CUSBDevice device, bool fAttached, CVirtualBoxErrorInfo error);
    72     /** Notifies about shared folder state change. */
    73     void sigSharedFolderChange();
    74     /** Notifies about CPU execution-cap change. */
    75     void sigCPUExecutionCapChange();
    76     /** Notifies about guest-screen configuration change of @a type for @a uScreenId with @a screenGeo. */
    77     void sigGuestMonitorChange(KGuestMonitorChangedEventType type, ulong uScreenId, QRect screenGeo);
    78     /** Notifies about Runtime error with @a strErrorId which is @a fFatal and have @a strMessage. */
    79     void sigRuntimeError(bool fFatal, QString strErrorId, QString strMessage);
    80 #ifdef RT_OS_DARWIN
    81     /** Notifies about VM window should be shown. */
    82     void sigShowWindow();
    83 #endif /* RT_OS_DARWIN */
    84     /** Notifies about audio adapter state change. */
    85     void sigAudioAdapterChange();
     57    void sigGuestProcessUpdated();
    8658
    8759public:
    8860
    89     /** Constructs event proxy object on the basis of passed @a pParent and @a pSession. */
    90     UIConsoleEventHandlerProxy(QObject *pParent, UISession *pSession);
    91     /** Destructs event proxy object. */
    92     ~UIConsoleEventHandlerProxy();
    93 
    94 protected:
    95 
    96     /** @name Prepare/Cleanup cascade.
    97       * @{ */
    98         /** Prepares all. */
    99         void prepare();
    100         /** Prepares listener. */
    101         void prepareListener();
    102         /** Prepares connections. */
    103         void prepareConnections();
    104 
    105         /** Cleanups connections. */
    106         void cleanupConnections();
    107         /** Cleanups listener. */
    108         void cleanupListener();
    109         /** Cleanups all. */
    110         void cleanup();
    111     /** @} */
    112 
     61    UIGuestProcess(QObject *parent, const CGuestProcess &guestProcess);
     62    ~UIGuestProcess();
     63    QString guestProcessName() const;
     64    ULONG   guestPID() const;
     65    QString guestProcessStatus() const;
    11366private slots:
    11467
    115     /** @name Slots for waitable signals.
    116       * @{ */
    117         /** Returns whether VM window can be shown. */
    118         void sltCanShowWindow(bool &fVeto, QString &strReason);
    119         /** Shows VM window if possible. */
    120         void sltShowWindow(qint64 &winId);
    121     /** @} */
     68    // void sltGuestProcessRegistered(CGuestProcess guestProcess);
     69    // void sltGuestProcessUnregistered(CGuestProcess guestProcess);
    12270
    12371private:
    12472
    125     /** Holds the UI session reference. */
    126     UISession *m_pSession;
    127 
    128     /** Holds the Qt event listener instance. */
     73    void  prepareListener();
     74    void  cleanupListener();
     75
     76    CGuestProcess  m_comGuestProcess;
    12977    ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
    130     /** Holds the COM event listener instance. */
    13178    CEventListener m_comEventListener;
    13279};
    13380
    134 
    135 /*********************************************************************************************************************************
    136 *   Class UIConsoleEventHandlerProxy implementation.                                                                             *
    137 *********************************************************************************************************************************/
    138 
    139 UIConsoleEventHandlerProxy::UIConsoleEventHandlerProxy(QObject *pParent, UISession *pSession)
    140     : QObject(pParent)
    141     , m_pSession(pSession)
    142 {
    143     /* Prepare: */
    144     prepare();
    145 }
    146 
    147 UIConsoleEventHandlerProxy::~UIConsoleEventHandlerProxy()
    148 {
    149     /* Cleanup: */
    150     cleanup();
    151 }
    152 
    153 void UIConsoleEventHandlerProxy::prepare()
    154 {
    155     /* Prepare: */
     81/******************************************************************************************************
     82*   UIGuestSession definition.                                                            *
     83******************************************************************************************************/
     84
     85class UIGuestSession : public QObject
     86{
     87
     88    Q_OBJECT;
     89
     90signals:
     91
     92    void sigGuestSessionUpdated();
     93
     94public:
     95
     96    UIGuestSession(QObject *parent, const CGuestSession &guestSession);
     97    ~UIGuestSession();
     98    QString guestSessionName() const;
     99    QString guestSessionStatus() const;
     100    const GuestProcessMap& guestProcessMap() const;
     101
     102private slots:
     103
     104    void sltGuestProcessRegistered(CGuestProcess guestProcess);
     105    void sltGuestProcessUnregistered(CGuestProcess guestProcess);
     106
     107private:
     108
     109    void  prepareListener();
     110    void  cleanupListener();
     111    void  initialize();
     112    void  addGuestProcess(const CGuestProcess &guestProcess);
     113    void  removeGuestProcess(const CGuestProcess &guestProcess);
     114
     115    CGuestSession  m_comGuestSession;
     116    ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
     117    CEventListener m_comEventListener;
     118    GuestProcessMap m_guestProcessMap;
     119};
     120
     121/******************************************************************************************************
     122*   UIGuestSessionsEventHandlerImp definition.                                                     *
     123******************************************************************************************************/
     124
     125class UIGuestSessionsEventHandlerImp : public QObject
     126{
     127    Q_OBJECT;
     128
     129signals:
     130
     131    void sigGuestSessionUpdated();
     132
     133public:
     134
     135    UIGuestSessionsEventHandlerImp(QObject *parent, const CGuest &comGuest);
     136    ~UIGuestSessionsEventHandlerImp();
     137    const GuestSessionMap& getGuestSessionMap() const;
     138
     139private slots:
     140
     141    void sltGuestSessionRegistered(CGuestSession guestSession);
     142    void sltGuestSessionUnregistered(CGuestSession guestSession);
     143
     144private:
     145
     146    void  prepareListener();
     147    void  cleanupListener();
     148    void  initialize();
     149
     150    void addGuestSession(const CGuestSession &guestSession);
     151    void removeGuestSession(const CGuestSession &guestSession);
     152
     153
     154    CGuest  m_comGuest;
     155    ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
     156    CEventListener m_comEventListener;
     157    GuestSessionMap m_guestSessionMap;
     158};
     159
     160
     161/******************************************************************************************************
     162*   UIGuestProcess definition.                                                            *
     163******************************************************************************************************/
     164UIGuestProcess::UIGuestProcess(QObject *parent, const CGuestProcess &guestProcess)
     165    :QObject(parent)
     166    , m_comGuestProcess(guestProcess)
     167{
     168    qRegisterMetaType<CGuestProcess>("CGuestProcess");
    156169    prepareListener();
    157     prepareConnections();
    158 }
    159 
    160 void UIConsoleEventHandlerProxy::prepareListener()
    161 {
    162     /* Make sure session is passed: */
    163     AssertPtrReturnVoid(m_pSession);
    164 
     170}
     171
     172UIGuestProcess::~UIGuestProcess()
     173{
     174    cleanupListener();
     175}
     176
     177void  UIGuestProcess::prepareListener()
     178{
     179    if (!m_comGuestProcess.isOk())
     180        return;
     181
     182    m_pQtListener.createObject();
     183    m_pQtListener->init(new UIMainEventListener, this);
     184    m_comEventListener = CEventListener(m_pQtListener);
     185    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestProcessStateChanged,
     186            this, &UIGuestProcess::sigGuestProcessUpdated);
     187
     188    CEventSource comEventSourceGuestProcess = m_comGuestProcess.GetEventSource();
     189    AssertWrapperOk(comEventSourceGuestProcess);
     190
     191    QVector<KVBoxEventType> eventTypes;
     192    eventTypes  << KVBoxEventType_OnGuestProcessStateChanged
     193                << KVBoxEventType_OnGuestProcessInputNotify
     194                << KVBoxEventType_OnGuestProcessOutput;
     195
     196    comEventSourceGuestProcess.RegisterListener(m_comEventListener, eventTypes,
     197        gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
     198    AssertWrapperOk(comEventSourceGuestProcess);
     199
     200    if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
     201    {
     202         m_pQtListener->getWrapped()->registerSource(comEventSourceGuestProcess, m_comEventListener);
     203    }
     204}
     205
     206
     207void  UIGuestProcess::cleanupListener()
     208{
     209    if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
     210        m_pQtListener->getWrapped()->unregisterSources();
     211
     212    if (!vboxGlobal().isVBoxSVCAvailable())
     213        return;
     214
     215    CEventSource comEventSourceGuestProcess = m_comGuestProcess.GetEventSource();
     216    AssertWrapperOk(comEventSourceGuestProcess);
     217    comEventSourceGuestProcess.UnregisterListener(m_comEventListener);
     218}
     219
     220QString UIGuestProcess::guestProcessName() const
     221{
     222    if (!m_comGuestProcess.isOk())
     223        return QString();
     224    return m_comGuestProcess.GetExecutablePath();
     225}
     226
     227ULONG UIGuestProcess::guestPID() const
     228{
     229    if (!m_comGuestProcess.isOk())
     230        return 0;
     231    return m_comGuestProcess.GetPID();
     232}
     233
     234QString UIGuestProcess::guestProcessStatus() const
     235{
     236    if (!m_comGuestProcess.isOk())
     237        return QString("InvalidProcess");
     238    QString statusString;
     239    switch (m_comGuestProcess.GetStatus())
     240    {
     241        case KProcessStatus_Undefined:
     242            statusString = "Undefined";
     243            break;
     244        case KProcessStatus_Starting:
     245            statusString = "Starting";
     246            break;
     247        case KProcessStatus_Started:
     248            statusString = "Started";
     249            break;
     250        case KProcessStatus_Paused:
     251            statusString = "Paused";
     252            break;
     253        case KProcessStatus_Terminating:
     254            statusString = "Terminating";
     255            break;
     256        case KProcessStatus_TerminatedNormally:
     257            statusString = "TerminatedNormally";
     258            break;
     259        case KProcessStatus_TerminatedSignal:
     260            statusString = "TerminatedSignal";
     261            break;
     262        case KProcessStatus_TerminatedAbnormally:
     263            statusString = "TerminatedAbnormally";
     264            break;
     265        case KProcessStatus_TimedOutKilled:
     266            statusString = "TimedOutKilled";
     267            break;
     268        case KProcessStatus_TimedOutAbnormally:
     269            statusString = "TimedOutAbnormally";
     270            break;
     271        case KProcessStatus_Down:
     272            statusString = "Down";
     273            break;
     274        case KProcessStatus_Error:
     275        default:
     276            statusString = "Error";
     277            break;
     278    }
     279    return statusString;
     280}
     281
     282/******************************************************************************************************
     283*   UIGuestSession implementation.                                                            *
     284******************************************************************************************************/
     285
     286UIGuestSession::UIGuestSession(QObject *parent, const CGuestSession &guestSession)
     287    : QObject(parent)
     288    , m_comGuestSession(guestSession)
     289{
     290    qRegisterMetaType<CGuestProcess>("CGuestProcess");
     291    prepareListener();
     292    initialize();
     293}
     294
     295UIGuestSession::~UIGuestSession()
     296{
     297    cleanupListener();
     298}
     299
     300void  UIGuestSession::prepareListener()
     301{
     302    if (!m_comGuestSession.isOk())
     303        return;
    165304    /* Create event listener instance: */
    166305    m_pQtListener.createObject();
     
    168307    m_comEventListener = CEventListener(m_pQtListener);
    169308
    170     /* Get console: */
    171     const CConsole comConsole = m_pSession->session().GetConsole();
    172     AssertReturnVoid(!comConsole.isNull() && comConsole.isOk());
    173     /* Get console event source: */
    174     CEventSource comEventSourceConsole = comConsole.GetEventSource();
    175     AssertReturnVoid(!comEventSourceConsole.isNull() && comEventSourceConsole.isOk());
     309    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestSessionStatedChanged,
     310            this, &UIGuestSession::sigGuestSessionUpdated);
     311    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestProcessRegistered,
     312            this, &UIGuestSession::sltGuestProcessRegistered);
     313    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestProcessUnregistered,
     314            this, &UIGuestSession::sltGuestProcessUnregistered);
     315
     316    /* Get CGuest event source: */
     317    CEventSource comEventSourceGuestSession = m_comGuestSession.GetEventSource();
     318    AssertWrapperOk(comEventSourceGuestSession);
    176319
    177320    /* Enumerate all the required event-types: */
    178321    QVector<KVBoxEventType> eventTypes;
    179     eventTypes
    180         << KVBoxEventType_OnMousePointerShapeChanged
    181         << KVBoxEventType_OnMouseCapabilityChanged
    182         << KVBoxEventType_OnKeyboardLedsChanged
    183         << KVBoxEventType_OnStateChanged
    184         << KVBoxEventType_OnAdditionsStateChanged
    185         << KVBoxEventType_OnNetworkAdapterChanged
    186         << KVBoxEventType_OnStorageDeviceChanged
    187         << KVBoxEventType_OnMediumChanged
    188         << KVBoxEventType_OnVRDEServerChanged
    189         << KVBoxEventType_OnVRDEServerInfoChanged
    190         << KVBoxEventType_OnVideoCaptureChanged
    191         << KVBoxEventType_OnUSBControllerChanged
    192         << KVBoxEventType_OnUSBDeviceStateChanged
    193         << KVBoxEventType_OnSharedFolderChanged
    194         << KVBoxEventType_OnCPUExecutionCapChanged
    195         << KVBoxEventType_OnGuestMonitorChanged
    196         << KVBoxEventType_OnRuntimeError
    197         << KVBoxEventType_OnCanShowWindow
    198         << KVBoxEventType_OnShowWindow
    199         << KVBoxEventType_OnAudioAdapterChanged
    200         << KVBoxEventType_OnCursorPositionChanged;
    201 
    202     /* Register event listener for console event source: */
    203     comEventSourceConsole.RegisterListener(m_comEventListener, eventTypes,
     322    eventTypes << KVBoxEventType_OnGuestSessionStateChanged
     323               << KVBoxEventType_OnGuestProcessRegistered;
     324               // << KVBoxEventType_OnGuestProcessStateChanged
     325               // << KVBoxEventType_OnGuestProcessInputNotify
     326               // << KVBoxEventType_OnGuestProcessOutput
     327               // << KVBoxEventType_OnGuestFileRegistered
     328               // << KVBoxEventType_OnGuestFileStateChanged
     329               // << KVBoxEventType_OnGuestFileOffsetChanged
     330               // << KVBoxEventType_OnGuestFileRead
     331               // << KVBoxEventType_OnGuestFileWrite;
     332
     333    /* Register event listener for CGuestSession event source: */
     334    comEventSourceGuestSession.RegisterListener(m_comEventListener, eventTypes,
    204335        gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
    205     AssertWrapperOk(comEventSourceConsole);
     336    AssertWrapperOk(comEventSourceGuestSession);
    206337
    207338    /* If event listener registered as passive one: */
     
    209340    {
    210341        /* Register event sources in their listeners as well: */
    211         m_pQtListener->getWrapped()->registerSource(comEventSourceConsole, m_comEventListener);
    212     }
    213 }
    214 
    215 void UIConsoleEventHandlerProxy::prepareConnections()
    216 {
    217     /* Create direct (sync) connections for signals of main listener: */
    218     connect(m_pQtListener->getWrapped(), SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
    219             this, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
    220             Qt::DirectConnection);
    221     connect(m_pQtListener->getWrapped(), SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
    222             this, SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
    223             Qt::DirectConnection);
    224     connect(m_pQtListener->getWrapped(), SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
    225             this, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
    226             Qt::DirectConnection);
    227     connect(m_pQtListener->getWrapped(), SIGNAL(sigStateChange(KMachineState)),
    228             this, SIGNAL(sigStateChange(KMachineState)),
    229             Qt::DirectConnection);
    230     connect(m_pQtListener->getWrapped(), SIGNAL(sigAdditionsChange()),
    231             this, SIGNAL(sigAdditionsChange()),
    232             Qt::DirectConnection);
    233     connect(m_pQtListener->getWrapped(), SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
    234             this, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
    235             Qt::DirectConnection);
    236     connect(m_pQtListener->getWrapped(), SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
    237             this, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
    238             Qt::DirectConnection);
    239     connect(m_pQtListener->getWrapped(), SIGNAL(sigMediumChange(CMediumAttachment)),
    240             this, SIGNAL(sigMediumChange(CMediumAttachment)),
    241             Qt::DirectConnection);
    242     connect(m_pQtListener->getWrapped(), SIGNAL(sigVRDEChange()),
    243             this, SIGNAL(sigVRDEChange()),
    244             Qt::DirectConnection);
    245     connect(m_pQtListener->getWrapped(), SIGNAL(sigVideoCaptureChange()),
    246             this, SIGNAL(sigVideoCaptureChange()),
    247             Qt::DirectConnection);
    248     connect(m_pQtListener->getWrapped(), SIGNAL(sigUSBControllerChange()),
    249             this, SIGNAL(sigUSBControllerChange()),
    250             Qt::DirectConnection);
    251     connect(m_pQtListener->getWrapped(), SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
    252             this, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
    253             Qt::DirectConnection);
    254     connect(m_pQtListener->getWrapped(), SIGNAL(sigSharedFolderChange()),
    255             this, SIGNAL(sigSharedFolderChange()),
    256             Qt::DirectConnection);
    257     connect(m_pQtListener->getWrapped(), SIGNAL(sigCPUExecutionCapChange()),
    258             this, SIGNAL(sigCPUExecutionCapChange()),
    259             Qt::DirectConnection);
    260     connect(m_pQtListener->getWrapped(), SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
    261             this, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
    262             Qt::DirectConnection);
    263     connect(m_pQtListener->getWrapped(), SIGNAL(sigRuntimeError(bool, QString, QString)),
    264             this, SIGNAL(sigRuntimeError(bool, QString, QString)),
    265             Qt::DirectConnection);
    266     connect(m_pQtListener->getWrapped(), SIGNAL(sigCanShowWindow(bool &, QString &)),
    267             this, SLOT(sltCanShowWindow(bool &, QString &)),
    268             Qt::DirectConnection);
    269     connect(m_pQtListener->getWrapped(), SIGNAL(sigShowWindow(qint64 &)),
    270             this, SLOT(sltShowWindow(qint64 &)),
    271             Qt::DirectConnection);
    272     connect(m_pQtListener->getWrapped(), SIGNAL(sigAudioAdapterChange()),
    273             this, SIGNAL(sigAudioAdapterChange()),
    274             Qt::DirectConnection);
    275 }
    276 
    277 void UIConsoleEventHandlerProxy::cleanupConnections()
    278 {
    279     /* Nothing for now. */
    280 }
    281 
    282 void UIConsoleEventHandlerProxy::cleanupListener()
    283 {
    284     /* Make sure session is passed: */
    285     AssertPtrReturnVoid(m_pSession);
    286 
     342        m_pQtListener->getWrapped()->registerSource(comEventSourceGuestSession, m_comEventListener);
     343    }
     344}
     345
     346void  UIGuestSession::cleanupListener()
     347{
    287348    /* If event listener registered as passive one: */
    288349    if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
     
    292353    }
    293354
    294     /* Get console: */
    295     const CConsole comConsole = m_pSession->session().GetConsole();
    296     if (comConsole.isNull() || !comConsole.isOk())
    297         return;
    298     /* Get console event source: */
    299     CEventSource comEventSourceConsole = comConsole.GetEventSource();
    300     AssertWrapperOk(comEventSourceConsole);
    301 
    302     /* Unregister event listener for console event source: */
    303     comEventSourceConsole.UnregisterListener(m_comEventListener);
    304 }
    305 
    306 void UIConsoleEventHandlerProxy::cleanup()
    307 {
    308     /* Cleanup: */
    309     cleanupConnections();
     355    /* Make sure VBoxSVC is available: */
     356    if (!vboxGlobal().isVBoxSVCAvailable())
     357        return;
     358
     359    /* Get CGuestSession event source: */
     360    CEventSource comEventSourceGuestSession = m_comGuestSession.GetEventSource();
     361    AssertWrapperOk(comEventSourceGuestSession);
     362
     363    /* Unregister event listener for CProgress event source: */
     364    comEventSourceGuestSession.UnregisterListener(m_comEventListener);
     365}
     366
     367QString UIGuestSession::guestSessionName() const
     368{
     369    if (!m_comGuestSession.isOk())
     370        return QString();
     371    return m_comGuestSession.GetName();
     372}
     373
     374QString UIGuestSession::guestSessionStatus() const
     375{
     376    if (!m_comGuestSession.isOk())
     377        return QString("InvalidSession");
     378    QString statusString;
     379    switch (m_comGuestSession.GetStatus())
     380    {
     381        case KGuestSessionStatus_Undefined:
     382            statusString = "Undefined";
     383            break;
     384        case KGuestSessionStatus_Starting:
     385            statusString = "Starting";
     386            break;
     387        case KGuestSessionStatus_Started:
     388            statusString = "Started";
     389            break;
     390
     391        case KGuestSessionStatus_Terminating:
     392            statusString = "Terminating";
     393            break;
     394
     395        case KGuestSessionStatus_Terminated:
     396            statusString = "Terminated";
     397            break;
     398
     399        case KGuestSessionStatus_TimedOutKilled:
     400            statusString = "TimedOutKilled";
     401            break;
     402
     403        case KGuestSessionStatus_TimedOutAbnormally:
     404            statusString = "TimedOutAbnormally";
     405            break;
     406
     407        case KGuestSessionStatus_Down:
     408            statusString = "Down";
     409            break;
     410
     411        case KGuestSessionStatus_Error:
     412            statusString = "Error";
     413            break;
     414        default:
     415            statusString = "Undefined";
     416            break;
     417     }
     418    return statusString;
     419}
     420
     421void UIGuestSession::sltGuestProcessRegistered(CGuestProcess guestProcess)
     422{
     423    addGuestProcess(guestProcess);
     424    emit sigGuestSessionUpdated();
     425}
     426
     427void UIGuestSession::sltGuestProcessUnregistered(CGuestProcess guestProcess)
     428{
     429    removeGuestProcess(guestProcess);
     430    emit sigGuestSessionUpdated();
     431}
     432
     433
     434void  UIGuestSession::initialize()
     435{
     436    QVector<CGuestProcess> processVector = m_comGuestSession.GetProcesses();
     437    for (int i = 0; i < processVector.size(); ++i)
     438        addGuestProcess(processVector.at(i));
     439    emit sigGuestSessionUpdated();
     440}
     441
     442void  UIGuestSession::addGuestProcess(const CGuestProcess &guestProcess)
     443{
     444    if (m_guestProcessMap.contains(guestProcess.GetPID()))
     445       return;
     446    UIGuestProcess *newGuestProcess = new UIGuestProcess(this, guestProcess);
     447    connect(newGuestProcess, &UIGuestProcess::sigGuestProcessUpdated,
     448            this, &UIGuestSession::sigGuestSessionUpdated);
     449    m_guestProcessMap.insert(guestProcess.GetPID(), newGuestProcess);
     450}
     451
     452void  UIGuestSession::removeGuestProcess(const CGuestProcess &guestProcess)
     453{
     454    if (!m_guestProcessMap.contains(guestProcess.GetPID()))
     455       return;
     456    m_guestProcessMap.remove(guestProcess.GetPID());
     457}
     458
     459const GuestProcessMap& UIGuestSession::guestProcessMap() const
     460{
     461    return m_guestProcessMap;
     462}
     463
     464/******************************************************************************************************
     465*   UIGuestSessionsEventHandlerImp implementation.                                                      *
     466******************************************************************************************************/
     467
     468UIGuestSessionsEventHandlerImp::UIGuestSessionsEventHandlerImp(QObject *parent, const CGuest &comGuest)
     469    : QObject(parent)
     470    , m_comGuest(comGuest)
     471{
     472    prepareListener();
     473    initialize();
     474}
     475
     476UIGuestSessionsEventHandlerImp::~UIGuestSessionsEventHandlerImp()
     477{
    310478    cleanupListener();
    311479}
    312480
    313 void UIConsoleEventHandlerProxy::sltCanShowWindow(bool & /* fVeto */, QString & /* strReason */)
    314 {
    315     /* Nothing for now. */
    316 }
    317 
    318 void UIConsoleEventHandlerProxy::sltShowWindow(qint64 &winId)
    319 {
    320 #ifdef VBOX_WS_MAC
    321     /* First of all, just ask the GUI thread to show the machine-window: */
    322     winId = 0;
    323     if (::darwinSetFrontMostProcess())
    324         emit sigShowWindow();
    325     else
    326     {
    327         /* If it's failed for some reason, send the other process our PSN so it can try: */
    328         winId = ::darwinGetCurrentProcessId();
    329     }
    330 #else /* !VBOX_WS_MAC */
    331     /* Return the ID of the top-level machine-window. */
    332     winId = (ULONG64)m_pSession->mainMachineWindowId();
    333 #endif /* !VBOX_WS_MAC */
    334 }
    335 
    336 
    337 /*********************************************************************************************************************************
    338 *   Class UIConsoleEventHandler implementation.                                                                                  *
    339 *********************************************************************************************************************************/
    340 
    341 /* static */
    342 UIConsoleEventHandler *UIConsoleEventHandler::m_spInstance = 0;
    343 
    344 /* static */
    345 void UIConsoleEventHandler::create(UISession *pSession)
    346 {
    347     if (!m_spInstance)
    348         m_spInstance = new UIConsoleEventHandler(pSession);
    349 }
    350 
    351 /* static */
    352 void UIConsoleEventHandler::destroy()
    353 {
    354     if (m_spInstance)
    355     {
    356         delete m_spInstance;
    357         m_spInstance = 0;
    358     }
    359 }
    360 
    361 UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession)
    362     : m_pProxy(new UIConsoleEventHandlerProxy(this, pSession))
    363 {
    364     /* Prepare: */
    365     prepare();
    366 }
    367 
    368 void UIConsoleEventHandler::prepare()
    369 {
    370     /* Prepare: */
    371     prepareConnections();
    372 }
    373 
    374 void UIConsoleEventHandler::prepareConnections()
    375 {
    376     /* Create queued (async) connections for signals of event proxy object: */
    377     connect(m_pProxy, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
    378             this, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
    379             Qt::QueuedConnection);
    380     connect(m_pProxy, SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
    381             this, SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
    382             Qt::QueuedConnection);
    383     connect(m_pProxy, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
    384             this, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
    385             Qt::QueuedConnection);
    386     connect(m_pProxy, SIGNAL(sigStateChange(KMachineState)),
    387             this, SIGNAL(sigStateChange(KMachineState)),
    388             Qt::QueuedConnection);
    389     connect(m_pProxy, SIGNAL(sigAdditionsChange()),
    390             this, SIGNAL(sigAdditionsChange()),
    391             Qt::QueuedConnection);
    392     connect(m_pProxy, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
    393             this, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
    394             Qt::QueuedConnection);
    395     connect(m_pProxy, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
    396             this, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
    397             Qt::QueuedConnection);
    398     connect(m_pProxy, SIGNAL(sigMediumChange(CMediumAttachment)),
    399             this, SIGNAL(sigMediumChange(CMediumAttachment)),
    400             Qt::QueuedConnection);
    401     connect(m_pProxy, SIGNAL(sigVRDEChange()),
    402             this, SIGNAL(sigVRDEChange()),
    403             Qt::QueuedConnection);
    404     connect(m_pProxy, SIGNAL(sigVideoCaptureChange()),
    405             this, SIGNAL(sigVideoCaptureChange()),
    406             Qt::QueuedConnection);
    407     connect(m_pProxy, SIGNAL(sigUSBControllerChange()),
    408             this, SIGNAL(sigUSBControllerChange()),
    409             Qt::QueuedConnection);
    410     connect(m_pProxy, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
    411             this, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
    412             Qt::QueuedConnection);
    413     connect(m_pProxy, SIGNAL(sigSharedFolderChange()),
    414             this, SIGNAL(sigSharedFolderChange()),
    415             Qt::QueuedConnection);
    416     connect(m_pProxy, SIGNAL(sigCPUExecutionCapChange()),
    417             this, SIGNAL(sigCPUExecutionCapChange()),
    418             Qt::QueuedConnection);
    419     connect(m_pProxy, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
    420             this, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
    421             Qt::QueuedConnection);
    422     connect(m_pProxy, SIGNAL(sigRuntimeError(bool, QString, QString)),
    423             this, SIGNAL(sigRuntimeError(bool, QString, QString)),
    424             Qt::QueuedConnection);
    425 #ifdef RT_OS_DARWIN
    426     connect(m_pProxy, SIGNAL(sigShowWindow(qint64 &)),
    427             this, SIGNAL(sigShowWindow(qint64 &)),
    428             Qt::QueuedConnection);
    429 #endif /* RT_OS_DARWIN */
    430     connect(m_pProxy, SIGNAL(sigAudioAdapterChange()),
    431             this, SIGNAL(sigAudioAdapterChange()),
    432             Qt::QueuedConnection);
    433 }
    434 
    435 #include "UIConsoleEventHandler.moc"
    436 
     481void UIGuestSessionsEventHandlerImp::prepareListener()
     482{
     483    if (!m_comGuest.isOk())
     484        return;
     485    /* Create event listener instance: */
     486    m_pQtListener.createObject();
     487    m_pQtListener->init(new UIMainEventListener, this);
     488    m_comEventListener = CEventListener(m_pQtListener);
     489    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestSessionRegistered,
     490            this, &UIGuestSessionsEventHandlerImp::sltGuestSessionRegistered);
     491    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestSessionUnregistered,
     492            this, &UIGuestSessionsEventHandlerImp::sltGuestSessionUnregistered);
     493
     494    /* Get CGuest event source: */
     495    CEventSource comEventSourceGuest = m_comGuest.GetEventSource();
     496    AssertWrapperOk(comEventSourceGuest);
     497
     498    /* Enumerate all the required event-types: */
     499    QVector<KVBoxEventType> eventTypes;
     500    eventTypes << KVBoxEventType_OnGuestSessionRegistered;
     501
     502    /* Register event listener for CGuest event source: */
     503    comEventSourceGuest.RegisterListener(m_comEventListener, eventTypes,
     504        gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
     505    AssertWrapperOk(comEventSourceGuest);
     506
     507    /* If event listener registered as passive one: */
     508    if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
     509    {
     510        /* Register event sources in their listeners as well: */
     511        m_pQtListener->getWrapped()->registerSource(comEventSourceGuest, m_comEventListener);
     512    }
     513}
     514
     515void UIGuestSessionsEventHandlerImp::cleanupListener()
     516{
     517    if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
     518    {
     519        m_pQtListener->getWrapped()->unregisterSources();
     520    }
     521
     522    if (!vboxGlobal().isVBoxSVCAvailable())
     523        return;
     524
     525    CEventSource comEventSourceGuest = m_comGuest.GetEventSource();
     526    AssertWrapperOk(comEventSourceGuest);
     527
     528    comEventSourceGuest.UnregisterListener(m_comEventListener);
     529}
     530
     531
     532void UIGuestSessionsEventHandlerImp::initialize()
     533{
     534    if (!m_comGuest.isOk())
     535        return;
     536    const QVector<CGuestSession>& sessionVector = m_comGuest.GetSessions();
     537    for (int i = 0; i < sessionVector.size(); ++i)
     538    {
     539        addGuestSession(sessionVector.at(i));
     540    }
     541    emit sigGuestSessionUpdated();
     542}
     543
     544
     545void UIGuestSessionsEventHandlerImp::addGuestSession(const CGuestSession &guestSession)
     546{
     547    if (m_guestSessionMap.contains(guestSession.GetId()))
     548        return;
     549    UIGuestSession* newGuestSession = new UIGuestSession(this, guestSession);
     550    connect(newGuestSession, &UIGuestSession::sigGuestSessionUpdated,
     551            this, &UIGuestSessionsEventHandlerImp::sigGuestSessionUpdated);
     552
     553    m_guestSessionMap.insert(guestSession.GetId(), newGuestSession);
     554}
     555
     556void UIGuestSessionsEventHandlerImp::removeGuestSession(const CGuestSession &guestSession)
     557{
     558    if (!m_guestSessionMap.contains(guestSession.GetId()))
     559        return;
     560    m_guestSessionMap.remove(guestSession.GetId());
     561}
     562
     563
     564void UIGuestSessionsEventHandlerImp::sltGuestSessionRegistered(CGuestSession guestSession)
     565{
     566    if (!guestSession.isOk())
     567        return;
     568    addGuestSession(guestSession);
     569    emit sigGuestSessionUpdated();
     570}
     571
     572void UIGuestSessionsEventHandlerImp::sltGuestSessionUnregistered(CGuestSession guestSession)
     573{
     574    if (!guestSession.isOk())
     575        return;
     576    removeGuestSession(guestSession);
     577    emit sigGuestSessionUpdated();
     578}
     579
     580const GuestSessionMap& UIGuestSessionsEventHandlerImp::getGuestSessionMap() const
     581{
     582    return m_guestSessionMap;
     583}
     584
     585UIGuestSessionsEventHandler::UIGuestSessionsEventHandler(QObject *parent, const CGuest &comGuest)
     586    :QObject(parent)
     587    , m_pPrivateImp(new UIGuestSessionsEventHandlerImp(this, comGuest))
     588{
     589    connect(m_pPrivateImp, &UIGuestSessionsEventHandlerImp::sigGuestSessionUpdated,
     590            this, &UIGuestSessionsEventHandler::sigGuestSessionsUpdated);
     591
     592}
     593
     594UIGuestSessionsEventHandler::~UIGuestSessionsEventHandler()
     595{
     596    delete m_pPrivateImp;
     597}
     598
     599void UIGuestSessionsEventHandler::populateGuestSessionsTree(QITreeWidget *pTreeWidget)
     600{
     601    if (!m_pPrivateImp || !pTreeWidget)
     602        return;
     603    pTreeWidget->setColumnCount(3);
     604    QStringList headerStrings;
     605    headerStrings << "Session Id/PID"
     606                  << "Session Name / EXE Path" << "Status";
     607    pTreeWidget->setHeaderLabels(headerStrings);
     608    const GuestSessionMap& guestSessionMap = m_pPrivateImp->getGuestSessionMap();
     609    QStringList itemStringList;
     610    for (GuestSessionMap::const_iterator iterator = guestSessionMap.begin();
     611        iterator != guestSessionMap.end(); ++iterator)
     612    {
     613        itemStringList << QString("Session Id %1").arg(iterator.key())
     614                       << iterator.value()->guestSessionName()
     615                       << iterator.value()->guestSessionStatus();
     616        const GuestProcessMap& processMap = iterator.value()->guestProcessMap();
     617        QITreeWidgetItem *treeItem = new QITreeWidgetItem(pTreeWidget, itemStringList);
     618        pTreeWidget->insertTopLevelItem(iterator.key(), treeItem);
     619        for (GuestProcessMap::const_iterator processIterator = processMap.begin();
     620            processIterator != processMap.end(); ++processIterator)
     621        {
     622            QStringList processStringList;
     623            processStringList << QString("%1").arg(processIterator.value()->guestPID())
     624                              << processIterator.value()->guestProcessName()
     625                              << processIterator.value()->guestProcessStatus();
     626            new QTreeWidgetItem(treeItem, processStringList);
     627        }
     628
     629        itemStringList.clear();
     630    }
     631}
     632
     633#include "UIGuestSessionsEventHandler.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIGuestSessionsEventHandler.h

    r70883 r70899  
    1616 */
    1717
    18 #ifndef ___UIConsoleEventHandler_h___
    19 #define ___UIConsoleEventHandler_h___
     18#ifndef ___UIGuestSessionsEventHandler_h___
     19#define ___UIGuestSessionsEventHandler_h___
    2020
    2121/* Qt includes: */
    2222#include <QObject>
     23#include "QITreeWidget.h"
    2324
    24 /* COM includes: */
    25 #include "COMEnums.h"
    26 #include "CVirtualBoxErrorInfo.h"
    27 #include "CMediumAttachment.h"
    28 #include "CNetworkAdapter.h"
    29 #include "CUSBDevice.h"
    3025
    3126/* Forward declarations: */
    32 class UIConsoleEventHandlerProxy;
    33 class UISession;
     27class CGuest;
     28class UIGuestSessionsEventHandlerImp;
    3429
    35 
    36 /** Singleton QObject extension
    37   * providing GUI with the CConsole event-source. */
    38 class UIConsoleEventHandler : public QObject
     30class UIGuestSessionsEventHandler : public QObject
    3931{
    4032    Q_OBJECT;
     
    4234signals:
    4335
    44     /** Notifies about mouse pointer become @a fVisible and his shape changed to @a fAlpha, @a hotCorner, @a size and @a shape. */
    45     void sigMousePointerShapeChange(bool fVisible, bool fAlpha, QPoint hotCorner, QSize size, QVector<uint8_t> shape);
    46     /** Notifies about mouse capability change to @a fSupportsAbsolute, @a fSupportsRelative, @a fSupportsMultiTouch and @a fNeedsHostCursor. */
    47     void sigMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative, bool fSupportsMultiTouch, bool fNeedsHostCursor);
    48     /** Notifies about keyboard LEDs change for @a fNumLock, @a fCapsLock and @a fScrollLock. */
    49     void sigKeyboardLedsChangeEvent(bool fNumLock, bool fCapsLock, bool fScrollLock);
    50     /** Notifies about machine @a state change. */
    51     void sigStateChange(KMachineState state);
    52     /** Notifies about guest additions state change. */
    53     void sigAdditionsChange();
    54     /** Notifies about network @a adapter state change. */
    55     void sigNetworkAdapterChange(CNetworkAdapter adapter);
    56     /** Notifies about storage device change for @a attachment, which was @a fRemoved and it was @a fSilent for guest. */
    57     void sigStorageDeviceChange(CMediumAttachment attachment, bool fRemoved, bool fSilent);
    58     /** Notifies about storage medium @a attachment state change. */
    59     void sigMediumChange(CMediumAttachment attachment);
    60     /** Notifies about VRDE device state change. */
    61     void sigVRDEChange();
    62     /** Notifies about Video Capture device state change. */
    63     void sigVideoCaptureChange();
    64     /** Notifies about USB controller state change. */
    65     void sigUSBControllerChange();
    66     /** Notifies about USB @a device state change to @a fAttached, holding additional @a error information. */
    67     void sigUSBDeviceStateChange(CUSBDevice device, bool fAttached, CVirtualBoxErrorInfo error);
    68     /** Notifies about shared folder state change. */
    69     void sigSharedFolderChange();
    70     /** Notifies about CPU execution-cap change. */
    71     void sigCPUExecutionCapChange();
    72     /** Notifies about guest-screen configuration change of @a type for @a uScreenId with @a screenGeo. */
    73     void sigGuestMonitorChange(KGuestMonitorChangedEventType type, ulong uScreenId, QRect screenGeo);
    74     /** Notifies about Runtime error with @a strErrorId which is @a fFatal and have @a strMessage. */
    75     void sigRuntimeError(bool fFatal, QString strErrorId, QString strMessage);
    76 #ifdef RT_OS_DARWIN
    77     /** Notifies about VM window should be shown. */
    78     void sigShowWindow();
    79 #endif /* RT_OS_DARWIN */
    80     /** Notifies about audio adapter state change. */
    81     void sigAudioAdapterChange();
     36    void sigGuestSessionsUpdated();
    8237
    8338public:
    8439
    85     /** Returns singleton instance created by the factory. */
    86     static UIConsoleEventHandler* instance() { return m_spInstance; }
    87     /** Creates singleton instance created by the factory. */
    88     static void create(UISession *pSession);
    89     /** Destroys singleton instance created by the factory. */
    90     static void destroy();
     40    UIGuestSessionsEventHandler(QObject *parent, const CGuest &comGuest);
     41    ~UIGuestSessionsEventHandler();
     42
     43    /** Returns the guest session (and processes) hierarchy as a vector of QTreeWidgetItem */
     44    void populateGuestSessionsTree(QITreeWidget *pTreeWidget);
    9145
    9246protected:
    9347
    94     /** Constructs console event handler for passed @a pSession. */
    95     UIConsoleEventHandler(UISession *pSession);
    96 
    97     /** @name Prepare cascade.
    98       * @{ */
    99         /** Prepares all. */
    100         void prepare();
    101         /** Prepares connections. */
    102         void prepareConnections();
    103     /** @} */
    104 
    10548private:
    10649
    107     /** Holds the singleton static console event handler instance. */
    108     static UIConsoleEventHandler *m_spInstance;
    109 
    110     /** Holds the console event proxy instance. */
    111     UIConsoleEventHandlerProxy *m_pProxy;
     50    UIGuestSessionsEventHandlerImp *m_pPrivateImp;
    11251};
    11352
    114 /** Defines the globally known name for the console event handler instance. */
    115 #define gConsoleEvents UIConsoleEventHandler::instance()
    116 
    11753#endif /* !___UIConsoleEventHandler_h___ */
    118 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationGuestSession.cpp

    r70887 r70899  
    2727# include "QITreeWidget.h"
    2828# include "UIInformationGuestSession.h"
    29 # include "UIInformationDataItem.h"
    30 # include "UIInformationItem.h"
    31 # include "UIInformationView.h"
    32 # include "UIExtraDataManager.h"
    33 # include "UIInformationModel.h"
    34 # include "UIMainEventListener.h"
     29# include "UIGuestSessionsEventHandler.h"
    3530# include "VBoxGlobal.h"
    3631
    3732/* COM includes: */
    38 # include "CEventListener.h"
    39 # include "CEventSource.h"
    4033# include "CGuest.h"
    41 # include "CGuestSession.h"
    4234
    4335#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4436
    45 /******************************************************************************************************
    46 *   Class UIGuestEventHandler definition.                                                             *
    47 ******************************************************************************************************/
    48 
    49 class UIGuestEventHandler : public QObject
     37UIInformationGuestSession::UIInformationGuestSession(QWidget *pParent, const CConsole &console)
     38    : QWidget(pParent)
     39    , m_comConsole(console)
     40    , m_pMainLayout(0)
     41    , m_pGuestSessionsEventHandler(0)
     42    , m_pTreeWidget(0)
    5043{
    51 
    52     Q_OBJECT;
    53 
    54 signals:
    55 
    56     void sigGuestSessionRegistered(CGuestSession guestSession);
    57 
    58 public:
    59 
    60     UIGuestEventHandler(QObject *parent, const CGuest &guest);
    61 
    62 private:
    63 
    64     void  prepareListener();
    65     void  cleanupListener();
    66 
    67     CGuest  m_comGuest;
    68     ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
    69     CEventListener m_comEventListener;
    70 
    71 };
    72 
    73 /******************************************************************************************************
    74 *   Class UIGuestEventHandler implementation.                                                         *
    75 *****************************************************************************************************/
    76 
    77 UIGuestEventHandler::UIGuestEventHandler(QObject *parent, const CGuest &guest)
    78     :QObject(parent),
    79      m_comGuest(guest)
    80 {
    81     prepareListener();
    82 }
    83 
    84 void UIGuestEventHandler::prepareListener()
    85 {
    86     if(!m_comGuest.isOk())
    87         return;
    88     /* Create event listener instance: */
    89     m_pQtListener.createObject();
    90     m_pQtListener->init(new UIMainEventListener, this);
    91     m_comEventListener = CEventListener(m_pQtListener);
    92     connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestSessionRegistered,
    93             this, &UIGuestEventHandler::sigGuestSessionRegistered);
    94 
    95     /* Get CGuest event source: */
    96     CEventSource comEventSourceGuest = m_comGuest.GetEventSource();
    97     AssertWrapperOk(comEventSourceGuest);
    98 
    99     /* Enumerate all the required event-types: */
    100     QVector<KVBoxEventType> eventTypes;
    101     eventTypes << KVBoxEventType_OnGuestSessionRegistered;
    102 
    103         /*<< KVBoxEventType_OnGuestSessionStateChanged
    104                << KVBoxEventType_OnGuestProcessRegistered
    105                << KVBoxEventType_OnGuestProcessStateChanged
    106                << KVBoxEventType_OnGuestProcessInputNotify
    107                << KVBoxEventType_OnGuestProcessOutput
    108                << KVBoxEventType_OnGuestFileRegistered
    109                << KVBoxEventType_OnGuestFileStateChanged
    110                << KVBoxEventType_OnGuestFileOffsetChanged
    111                << KVBoxEventType_OnGuestFileRead
    112                << KVBoxEventType_OnGuestFileWrite;*/
    113 
    114 
    115     /* Register event listener for CGuest event source: */
    116     comEventSourceGuest.RegisterListener(m_comEventListener, eventTypes,
    117         gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
    118     AssertWrapperOk(comEventSourceGuest);
    119 
    120     /* If event listener registered as passive one: */
    121     if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
    122     {
    123         /* Register event sources in their listeners as well: */
    124         m_pQtListener->getWrapped()->registerSource(comEventSourceGuest, m_comEventListener);
    125     }
    126 }
    127 
    128 void  UIGuestEventHandler::cleanupListener()
    129 {
    130     /* If event listener registered as passive one: */
    131     if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
    132     {
    133         /* Unregister everything: */
    134         m_pQtListener->getWrapped()->unregisterSources();
    135     }
    136 
    137     /* Make sure VBoxSVC is available: */
    138     if (!vboxGlobal().isVBoxSVCAvailable())
    139         return;
    140 
    141     /* Get CGuestSession event source: */
    142     CEventSource comEventSourceGuest = m_comGuest.GetEventSource();
    143     AssertWrapperOk(comEventSourceGuest);
    144 
    145     /* Unregister event listener for CProgress event source: */
    146     comEventSourceGuest.UnregisterListener(m_comEventListener);
    147 }
    148 
    149 /******************************************************************************************************
    150 *   Class UIGuestSessionEventHandler definition.                                                      *
    151 ******************************************************************************************************/
    152 
    153 class UIGuestSessionEventHandler : public QObject
    154 {
    155 
    156     Q_OBJECT;
    157 
    158 public:
    159 
    160     UIGuestSessionEventHandler(QObject *parent, const CGuestSession &guestSession);
    161 
    162 private slots:
    163 
    164 
    165 private:
    166 
    167     void  prepareListener();
    168     void  cleanupListener();
    169 
    170     CGuestSession  m_comGuestSession;
    171     ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
    172     CEventListener m_comEventListener;
    173 
    174 };
    175 
    176 /******************************************************************************************************
    177 *   Class UIGuestSessionEventHandler implemetation.                                                   *
    178 ******************************************************************************************************/
    179 
    180 UIGuestSessionEventHandler::UIGuestSessionEventHandler(QObject *parent, const CGuestSession &guestSession)
    181     :QObject(parent),
    182      m_comGuestSession(guestSession)
    183 {
    184     prepareListener();
    185 }
    186 
    187 void UIGuestSessionEventHandler::prepareListener()
    188 {
    189     if(!m_comGuestSession.isOk())
    190         return;
    191     /* Create event listener instance: */
    192     m_pQtListener.createObject();
    193     m_pQtListener->init(new UIMainEventListener, this);
    194     m_comEventListener = CEventListener(m_pQtListener);
    195 
    196     /* Get CGuest event source: */
    197     CEventSource comEventSourceGuestSession = m_comGuestSession.GetEventSource();
    198     AssertWrapperOk(comEventSourceGuestSession);
    199 
    200     /* Enumerate all the required event-types: */
    201     QVector<KVBoxEventType> eventTypes;
    202     eventTypes << KVBoxEventType_OnGuestSessionStateChanged
    203                << KVBoxEventType_OnGuestProcessRegistered
    204                << KVBoxEventType_OnGuestProcessStateChanged
    205                << KVBoxEventType_OnGuestProcessInputNotify
    206                << KVBoxEventType_OnGuestProcessOutput
    207                << KVBoxEventType_OnGuestFileRegistered
    208                << KVBoxEventType_OnGuestFileStateChanged
    209                << KVBoxEventType_OnGuestFileOffsetChanged
    210                << KVBoxEventType_OnGuestFileRead
    211                << KVBoxEventType_OnGuestFileWrite;
    212 
    213 
    214     /* Register event listener for CGuestSession event source: */
    215     comEventSourceGuestSession.RegisterListener(m_comEventListener, eventTypes,
    216         gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
    217     AssertWrapperOk(comEventSourceGuestSession);
    218 
    219     /* If event listener registered as passive one: */
    220     if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
    221     {
    222         /* Register event sources in their listeners as well: */
    223         m_pQtListener->getWrapped()->registerSource(comEventSourceGuestSession, m_comEventListener);
    224     }
    225 }
    226 
    227 
    228 void UIGuestSessionEventHandler::cleanupListener()
    229 {
    230 }
    231 
    232 UIInformationGuestSession::UIInformationGuestSession(QWidget *pParent, const CMachine &machine,
    233                                                      const CConsole &console)
    234     : QWidget(pParent)
    235     , m_machine(machine)
    236     , m_console(console)
    237     , m_pMainLayout(0)
    238     , m_pGuestEventHandler(0)
    239 {
     44    prepareEventHandler();
    24045    prepareLayout();
    24146    prepareWidgets();
    242     prepareEventHandler();
    24347}
    24448
     
    25660void UIInformationGuestSession::prepareWidgets()
    25761{
    258     CGuest guest = m_console.GetGuest();
    259     QVector<CGuestSession> guestSessionVector = guest.GetSessions();
     62    m_pTreeWidget = new QITreeWidget();
     63    m_pMainLayout->addWidget(m_pTreeWidget);
     64    updateTreeWidget();
     65}
    26066
    261     QITreeWidget *treeWidget = new QITreeWidget();
    262     treeWidget->setColumnCount(2);
    263     QList<QITreeWidgetItem *> items;
    264     for (int i = 0; i < 10; ++i)
    265     {
    266         QStringList strList;
    267         strList << QString("item %1").arg(i) << "dataa";
    268         QITreeWidgetItem* item = new QITreeWidgetItem(treeWidget, strList);
    269         //items.append(new QITreeWidgetItem((QITreeWidget*)0, QStringList(QString("item: %1").arg(i))));
    270         treeWidget->insertTopLevelItem(i, item);
     67void UIInformationGuestSession::updateTreeWidget()
     68{
     69    if (!m_pTreeWidget)
     70        return;
     71    if (!m_pGuestSessionsEventHandler)
     72        return;
    27173
    272         if(i == 3)
    273         {
    274             QStringList strList;
    275             strList << "child" << "dataa";
    276             new QITreeWidgetItem(item, strList);
    277 
    278         }
    279     }
    280     m_pMainLayout->addWidget(treeWidget);
     74    m_pTreeWidget->clear();
     75    QVector<QITreeWidgetItem> treeItemVector;
     76    m_pGuestSessionsEventHandler->populateGuestSessionsTree(m_pTreeWidget);
     77    update();
    28178}
    28279
    28380void UIInformationGuestSession::prepareEventHandler()
    28481{
    285     CGuest guest = m_console.GetGuest();
    286     m_pGuestEventHandler = new UIGuestEventHandler(this, m_console.GetGuest());
    287     connect(m_pGuestEventHandler, &UIGuestEventHandler::sigGuestSessionRegistered,
    288             this, &UIInformationGuestSession::sltGuestSessionRegistered);
     82    m_pGuestSessionsEventHandler = new UIGuestSessionsEventHandler(this, m_comConsole.GetGuest());
     83    connect(m_pGuestSessionsEventHandler, &UIGuestSessionsEventHandler::sigGuestSessionsUpdated,
     84            this, &UIInformationGuestSession::sltGuestSessionsUpdated);
    28985}
    29086
    291 void UIInformationGuestSession::sltGuestSessionRegistered(CGuestSession guestSession)
     87void UIInformationGuestSession::sltGuestSessionsUpdated()
    29288{
    293     if(!guestSession.isOk())
    294         return;
    295     m_pGuestSessionHandleVector.push_back(new UIGuestSessionEventHandler(this, guestSession));
    296 
     89    updateTreeWidget();
    29790}
    298 
    299 #include "UIInformationGuestSession.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationGuestSession.h

    r70887 r70899  
    2424/* COM includes: */
    2525#include "COMEnums.h"
    26 #include "CMachine.h"
    27 #include "CGuestSession.h"
    2826#include "CConsole.h"
    2927
    3028/* Forward declarations: */
     29class QITreeWidget;
    3130class QVBoxLayout;
    32 class UIGuestEventHandler;
    33 class UIGuestSessionEventHandler;
    34 class UIInformationView;
    35 class UIInformationModel;
     31class UIGuestSessionsEventHandler;
    3632
    3733/** QWidget extension
     
    4541public:
    4642
    47     UIInformationGuestSession(QWidget *pParent, const CMachine &machine, const CConsole &console);
     43    UIInformationGuestSession(QWidget *pParent, const CConsole &console);
    4844
    4945private slots:
    5046
    51     void sltGuestSessionRegistered(CGuestSession guestSession);
     47    void sltGuestSessionsUpdated();
    5248
    5349private:
     
    5652    void prepareWidgets();
    5753    void prepareEventHandler();
     54    void updateTreeWidget();
    5855
    59     CMachine             m_machine;
    60     CConsole             m_console;
     56    CConsole             m_comConsole;
    6157    QVBoxLayout         *m_pMainLayout;
    62     UIGuestEventHandler *m_pGuestEventHandler;
    63     QVector<UIGuestSessionEventHandler*> m_pGuestSessionHandleVector;
     58    UIGuestSessionsEventHandler *m_pGuestSessionsEventHandler;
     59    QITreeWidget        *m_pTreeWidget;
     60
    6461};
    6562
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.cpp

    r70882 r70899  
    244244
    245245        UIInformationGuestSession *pGuestSessionWidget =
    246             new UIInformationGuestSession(this, m_pMachineWindow->machine(), m_pMachineWindow->console());
     246            new UIInformationGuestSession(this, m_pMachineWindow->console());
    247247        if (pGuestSessionWidget)
    248248        {
Note: See TracChangeset for help on using the changeset viewer.

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