VirtualBox

Changeset 90290 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 22, 2021 2:40:08 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10067: Extend notification-center with progress handling stuff.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 added
5 edited

Legend:

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

    r90288 r90290  
    846846        src/notificationcenter/UINotificationObject.h \
    847847        src/notificationcenter/UINotificationObjectItem.h \
     848        src/notificationcenter/UINotificationProgressTask.h \
    848849        src/settings/UISettingsDialog.h \
    849850        src/settings/UISettingsDialogSpecific.h \
     
    13951396        src/notificationcenter/UINotificationObject.cpp \
    13961397        src/notificationcenter/UINotificationObjectItem.cpp \
     1398        src/notificationcenter/UINotificationProgressTask.cpp \
    13971399        src/objects/UIRichTextString.cpp \
    13981400        src/settings/UISettingsDefs.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObject.cpp

    r90288 r90290  
    1818/* GUI includes: */
    1919#include "UINotificationObject.h"
     20#include "UINotificationProgressTask.h"
    2021
     22
     23/*********************************************************************************************************************************
     24*   Class UINotificationObject implementation.                                                                                   *
     25*********************************************************************************************************************************/
    2126
    2227UINotificationObject::UINotificationObject()
     
    2833    emit sigAboutToClose();
    2934}
     35
     36
     37/*********************************************************************************************************************************
     38*   Class UINotificationProgress implementation.                                                                                 *
     39*********************************************************************************************************************************/
     40
     41UINotificationProgress::UINotificationProgress()
     42    : m_pTask(0)
     43    , m_uPercent(0)
     44{
     45}
     46
     47UINotificationProgress::~UINotificationProgress()
     48{
     49    delete m_pTask;
     50    m_pTask = 0;
     51}
     52
     53ulong UINotificationProgress::percent() const
     54{
     55    return m_uPercent;
     56}
     57
     58bool UINotificationProgress::isCancelable() const
     59{
     60    return m_pTask->isCancelable();
     61}
     62
     63QString UINotificationProgress::error() const
     64{
     65    return m_pTask->errorMessage();
     66}
     67
     68void UINotificationProgress::handle()
     69{
     70    /* Prepare task: */
     71    m_pTask = new UINotificationProgressTask(this);
     72    if (m_pTask)
     73    {
     74        connect(m_pTask, &UIProgressTask::sigProgressStarted,
     75                this, &UINotificationProgress::sigProgressStarted);
     76        connect(m_pTask, &UIProgressTask::sigProgressChange,
     77                this, &UINotificationProgress::sltHandleProgressChange);
     78        connect(m_pTask, &UIProgressTask::sigProgressFinished,
     79                this, &UINotificationProgress::sltHandleProgressFinished);
     80    }
     81
     82    /* And start it finally: */
     83    m_pTask->start();
     84}
     85
     86void UINotificationProgress::close()
     87{
     88    /* Cancel task: */
     89    m_pTask->cancel();
     90    /* Call to base-class: */
     91    UINotificationObject::close();
     92}
     93
     94void UINotificationProgress::sltHandleProgressChange(ulong uPercent)
     95{
     96    m_uPercent = uPercent;
     97    emit sigProgressChange(uPercent);
     98}
     99
     100void UINotificationProgress::sltHandleProgressFinished()
     101{
     102    m_uPercent = 100;
     103    emit sigProgressFinished();
     104}
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObject.h

    r90288 r90290  
    2828#include "UILibraryDefs.h"
    2929
     30/* COM includes: */
     31#include "CProgress.h"
     32
     33/* Forward declarations: */
     34class UINotificationProgressTask;
     35
    3036/** QObject-based notification-object. */
    3137class SHARED_LIBRARY_STUFF UINotificationObject : public QObject
     
    5662};
    5763
     64/** UINotificationObject extension for notification-progress. */
     65class SHARED_LIBRARY_STUFF UINotificationProgress : public UINotificationObject
     66{
     67    Q_OBJECT;
     68
     69signals:
     70
     71    /** Notifies listeners about progress started. */
     72    void sigProgressStarted();
     73    /** Notifies listeners about progress changed.
     74      * @param  uPercent  Brings new progress percentage value. */
     75    void sigProgressChange(ulong uPercent);
     76    /** Notifies listeners about progress finished. */
     77    void sigProgressFinished();
     78
     79public:
     80
     81    /** Constructs notification-progress. */
     82    UINotificationProgress();
     83    /** Destructs notification-progress. */
     84    virtual ~UINotificationProgress() /* override final */;
     85
     86    /** Creates and returns started progress-wrapper. */
     87    virtual CProgress createProgress(COMResult &comResult) = 0;
     88
     89    /** Returns current progress percentage value. */
     90    ulong percent() const;
     91    /** Returns whether progress is cancelable. */
     92    bool isCancelable() const;
     93    /** Returns error-message if any. */
     94    QString error() const;
     95
     96    /** Handles notification-object being added. */
     97    virtual void handle() /* override final */;
     98
     99public slots:
     100
     101    /** Stops the progress and notifies model about closing. */
     102    virtual void close() /* override final */;
     103
     104private slots:
     105
     106    /** Handles signal about progress changed.
     107      * @param  uPercent  Brings new progress percentage value. */
     108    void sltHandleProgressChange(ulong uPercent);
     109    /** Handles signal about progress finished. */
     110    void sltHandleProgressFinished();
     111
     112private:
     113
     114    /** Holds the instance of progress-task being wrapped by this notification-progress. */
     115    UINotificationProgressTask *m_pTask;
     116
     117    /** Holds the last cached progress percentage value. */
     118    ulong  m_uPercent;
     119};
     120
    58121#endif /* !FEQT_INCLUDED_SRC_notificationcenter_UINotificationObject_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjectItem.cpp

    r90288 r90290  
    2323#include <QPainter>
    2424#include <QPaintEvent>
     25#include <QProgressBar>
    2526#include <QVBoxLayout>
    2627
     
    161162
    162163/*********************************************************************************************************************************
    163 *   Namespace UINotificationItem implementation.                                                                                 *
     164*   Class UINotificationProgressItem implementation.                                                                             *
    164165*********************************************************************************************************************************/
    165166
     167UINotificationProgressItem::UINotificationProgressItem(QWidget *pParent, UINotificationProgress *pProgress /* = 0 */)
     168    : UINotificationObjectItem(pParent, pProgress)
     169    , m_pProgressBar(0)
     170{
     171    /* Main layout was prepared in base-class: */
     172    if (m_pLayoutMain)
     173    {
     174        /* Name label was prepared in base-class: */
     175        if (m_pLabelName)
     176            m_pLabelName->setText(progress()->name());
     177        /* Details label was prepared in base-class: */
     178        if (m_pLabelDetails)
     179        {
     180            m_pLabelDetails->setText(progress()->details());
     181            int iHint = m_pLabelName->minimumSizeHint().width()
     182                      + m_pLayoutUpper->spacing()
     183                      + m_pButtonClose->minimumSizeHint().width();
     184            m_pLabelDetails->setMinimumTextWidth(iHint);
     185        }
     186
     187        /* Prepare progress-bar: */
     188        m_pProgressBar = new QProgressBar(this);
     189        if (m_pProgressBar)
     190        {
     191            m_pProgressBar->setMinimum(0);
     192            m_pProgressBar->setMaximum(100);
     193            m_pProgressBar->setValue(progress()->percent());
     194
     195            m_pLayoutMain->addWidget(m_pProgressBar);
     196        }
     197    }
     198
     199    /* Prepare progress connections: */
     200    connect(progress(), &UINotificationProgress::sigProgressStarted,
     201            this, &UINotificationProgressItem::sltHandleProgressStarted);
     202    connect(progress(), &UINotificationProgress::sigProgressChange,
     203            this, &UINotificationProgressItem::sltHandleProgressChange);
     204    connect(progress(), &UINotificationProgress::sigProgressFinished,
     205            this, &UINotificationProgressItem::sltHandleProgressFinished);
     206}
     207
     208void UINotificationProgressItem::sltHandleProgressStarted()
     209{
     210    /* Init close-button and progress-bar states: */
     211    if (m_pButtonClose)
     212        m_pButtonClose->setEnabled(progress()->isCancelable());
     213    if (m_pProgressBar)
     214        m_pProgressBar->setValue(0);
     215}
     216
     217void UINotificationProgressItem::sltHandleProgressChange(ulong uPercent)
     218{
     219    /* Update close-button and progress-bar states: */
     220    if (m_pButtonClose)
     221        m_pButtonClose->setEnabled(progress()->isCancelable());
     222    if (m_pProgressBar)
     223        m_pProgressBar->setValue(uPercent);
     224}
     225
     226void UINotificationProgressItem::sltHandleProgressFinished()
     227{
     228    /* Finalize close-button and progress-bar states: */
     229    if (m_pButtonClose)
     230        m_pButtonClose->setEnabled(true);
     231    if (m_pProgressBar)
     232        m_pProgressBar->setValue(100);
     233    /* Update details with error text if any: */
     234    if (m_pLabelDetails)
     235    {
     236        const QString strDetails = progress()->details();
     237        const QString strError = progress()->error();
     238        const QString strFullDetails = strError.isNull()
     239                                     ? strDetails
     240                                     : QString("%1<br>%2").arg(strDetails, strError);
     241        m_pLabelDetails->setText(strFullDetails);
     242    }
     243}
     244
     245UINotificationProgress *UINotificationProgressItem::progress() const
     246{
     247    return qobject_cast<UINotificationProgress*>(m_pObject);
     248}
     249
     250
     251/*********************************************************************************************************************************
     252*   Namespace UINotificationProgressItem implementation.                                                                         *
     253*********************************************************************************************************************************/
     254
    166255UINotificationObjectItem *UINotificationItem::create(QWidget *pParent, UINotificationObject *pObject)
    167256{
     257    /* Handle known types: */
     258    if (pObject->inherits("UINotificationProgress"))
     259        return new UINotificationProgressItem(pParent, static_cast<UINotificationProgress*>(pObject));
    168260    /* Handle defaults: */
    169261    return new UINotificationObjectItem(pParent, pObject);
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjectItem.h

    r90288 r90290  
    2828class QHBoxLayout;
    2929class QLabel;
     30class QProgressBar;
    3031class QVBoxLayout;
    3132class QIRichTextLabel;
    3233class QIToolButton;
    3334class UINotificationObject;
     35class UINotificationProgress;
    3436
    3537/** QWidget-based notification-object item. */
     
    7274};
    7375
     76/** UINotificationObjectItem extension for notification-progress. */
     77class UINotificationProgressItem : public UINotificationObjectItem
     78{
     79    Q_OBJECT;
     80
     81public:
     82
     83    /** Constructs notification-progress item, passing @a pParent to the base-class.
     84      * @param  pProgress  Brings the notification-progress this item created for. */
     85    UINotificationProgressItem(QWidget *pParent, UINotificationProgress *pProgress = 0);
     86
     87protected:
     88
     89    /** Holds the progress-bar instance. */
     90    QProgressBar *m_pProgressBar;
     91
     92private slots:
     93
     94    /** Handles signal about progress started. */
     95    void sltHandleProgressStarted();
     96    /** Handles signal about progress changed.
     97      * @param  uPercent  Brings new progress percentage value. */
     98    void sltHandleProgressChange(ulong uPercent);
     99    /** Handles signal about progress finished. */
     100    void sltHandleProgressFinished();
     101
     102private:
     103
     104    /** Holds the notification-progress this item created for. */
     105    UINotificationProgress *progress() const;
     106};
     107
    74108/** Notification-object factory. */
    75109namespace UINotificationItem
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