VirtualBox

Changeset 91753 in vbox for trunk


Ignore:
Timestamp:
Oct 15, 2021 9:25:35 AM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10067: A possibility to create local UINotificationCenter objects additionally to main singleton.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationCenter.cpp

    r91501 r91753  
    128128{
    129129    AssertReturnVoid(!s_pInstance);
    130     new UINotificationCenter(pParent);
     130    s_pInstance = new UINotificationCenter(pParent);
    131131}
    132132
     
    136136    AssertPtrReturnVoid(s_pInstance);
    137137    delete s_pInstance;
     138    s_pInstance = 0;
    138139}
    139140
     
    142143{
    143144    return s_pInstance;
    144 }
    145 
    146 void UINotificationCenter::setParent(QWidget *pParent)
    147 {
    148     /* Additionally hide if parent unset: */
    149     if (!pParent)
    150         setHidden(true);
    151 
    152     /* Uninstall filter from previous parent: */
    153     if (parent())
    154         parent()->removeEventFilter(this);
    155 
    156     /* Reparent: */
    157     QIWithRetranslateUI<QWidget>::setParent(pParent);
    158 
    159     /* Install filter to new parent: */
    160     if (parent())
    161         parent()->installEventFilter(this);
    162 
    163     /* Show only if there is something to show: */
    164     if (parent())
    165         setHidden(m_pModel->ids().isEmpty());
    166 }
    167 
    168 void UINotificationCenter::invoke()
    169 {
    170     /* Open if center isn't opened yet: */
    171     if (!m_pOpenButton->isChecked())
    172         m_pOpenButton->animateClick();
    173 }
    174 
    175 QUuid UINotificationCenter::append(UINotificationObject *pObject)
    176 {
    177     /* Sanity check: */
    178     AssertPtrReturn(m_pModel, QUuid());
    179     AssertPtrReturn(pObject, QUuid());
    180 
    181     /* Is object critical? */
    182     const bool fCritical = pObject->isCritical();
    183     /* Is object progress? */
    184     const bool fProgress = pObject->inherits("UINotificationProgress");
    185 
    186     /* Handle object. Be aware it can be deleted during handling! */
    187     const QUuid uId = m_pModel->appendObject(pObject);
    188 
    189     /* If object is critical and center isn't opened yet: */
    190     if (!m_pOpenButton->isChecked() && fCritical)
    191     {
    192         /* We should delay progresses for a bit: */
    193         const int iDelay = fProgress ? 2000 : 0;
    194         /* We should issue an open request: */
    195         AssertPtrReturn(m_pTimerOpen, uId);
    196         m_uOpenObjectId = uId;
    197         m_pTimerOpen->start(iDelay);
    198     }
    199 
    200     return uId;
    201 }
    202 
    203 void UINotificationCenter::revoke(const QUuid &uId)
    204 {
    205     AssertReturnVoid(!uId.isNull());
    206     return m_pModel->revokeObject(uId);
    207145}
    208146
     
    219157    , m_pTimerOpen(0)
    220158{
    221     s_pInstance = this;
    222159    prepare();
    223160}
     
    225162UINotificationCenter::~UINotificationCenter()
    226163{
    227     s_pInstance = 0;
     164}
     165
     166void UINotificationCenter::setParent(QWidget *pParent)
     167{
     168    /* Additionally hide if parent unset: */
     169    if (!pParent)
     170        setHidden(true);
     171
     172    /* Uninstall filter from previous parent: */
     173    if (parent())
     174        parent()->removeEventFilter(this);
     175
     176    /* Reparent: */
     177    QIWithRetranslateUI<QWidget>::setParent(pParent);
     178
     179    /* Install filter to new parent: */
     180    if (parent())
     181        parent()->installEventFilter(this);
     182
     183    /* Show only if there is something to show: */
     184    if (parent())
     185        setHidden(m_pModel->ids().isEmpty());
     186}
     187
     188void UINotificationCenter::invoke()
     189{
     190    /* Open if center isn't opened yet: */
     191    if (!m_pOpenButton->isChecked())
     192        m_pOpenButton->animateClick();
     193}
     194
     195QUuid UINotificationCenter::append(UINotificationObject *pObject)
     196{
     197    /* Sanity check: */
     198    AssertPtrReturn(m_pModel, QUuid());
     199    AssertPtrReturn(pObject, QUuid());
     200
     201    /* Is object critical? */
     202    const bool fCritical = pObject->isCritical();
     203    /* Is object progress? */
     204    const bool fProgress = pObject->inherits("UINotificationProgress");
     205
     206    /* Handle object. Be aware it can be deleted during handling! */
     207    const QUuid uId = m_pModel->appendObject(pObject);
     208
     209    /* If object is critical and center isn't opened yet: */
     210    if (!m_pOpenButton->isChecked() && fCritical)
     211    {
     212        /* We should delay progresses for a bit: */
     213        const int iDelay = fProgress ? 2000 : 0;
     214        /* We should issue an open request: */
     215        AssertPtrReturn(m_pTimerOpen, uId);
     216        m_uOpenObjectId = uId;
     217        m_pTimerOpen->start(iDelay);
     218    }
     219
     220    return uId;
     221}
     222
     223void UINotificationCenter::revoke(const QUuid &uId)
     224{
     225    AssertReturnVoid(!uId.isNull());
     226    return m_pModel->revokeObject(uId);
    228227}
    229228
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationCenter.h

    r91236 r91753  
    6363    static UINotificationCenter *instance();
    6464
     65    /** Constructs notification-center passing @a pParent to the base-class. */
     66    UINotificationCenter(QWidget *pParent);
     67    /** Destructs notification-center. */
     68    virtual ~UINotificationCenter() /* override final */;
     69
    6570    /** Defines notification-center @a pParent. */
    6671    void setParent(QWidget *pParent);
     
    7580
    7681protected:
    77 
    78     /** Constructs notification-center passing @a pParent to the base-class. */
    79     UINotificationCenter(QWidget *pParent);
    80     /** Destructs notification-center. */
    81     virtual ~UINotificationCenter() /* override final */;
    8282
    8383    /** Handles translation event. */
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