VirtualBox

Changeset 90556 in vbox


Ignore:
Timestamp:
Aug 6, 2021 4:08:18 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146162
Message:

FE/Qt: bugref:10067: New notification interfaces for downloader object and item.

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

Legend:

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

    r90387 r90556  
    1717
    1818/* GUI includes: */
     19#include "UIDownloader.h"
    1920#include "UINotificationObject.h"
    2021#include "UINotificationProgressTask.h"
     
    7879        connect(m_pTask, &UIProgressTask::sigProgressFinished,
    7980                this, &UINotificationProgress::sltHandleProgressFinished);
     81
     82        /* And start it finally: */
     83        m_pTask->start();
    8084    }
    81 
    82     /* And start it finally: */
    83     m_pTask->start();
    8485}
    8586
     
    104105    emit sigProgressFinished();
    105106}
     107
     108
     109/*********************************************************************************************************************************
     110*   Class UINotificationDownloader implementation.                                                                               *
     111*********************************************************************************************************************************/
     112
     113UINotificationDownloader::UINotificationDownloader()
     114{
     115}
     116
     117UINotificationDownloader::~UINotificationDownloader()
     118{
     119    delete m_pDownloader;
     120}
     121
     122ulong UINotificationDownloader::percent() const
     123{
     124    return m_uPercent;
     125}
     126
     127QString UINotificationDownloader::error() const
     128{
     129    return m_strError;
     130}
     131
     132void UINotificationDownloader::handle()
     133{
     134    /* Prepare downloader: */
     135    m_pDownloader = createDownloader();
     136    if (m_pDownloader)
     137    {
     138        connect(m_pDownloader, &UIDownloader::sigToStartAcknowledging,
     139                this, &UINotificationDownloader::sigProgressStarted);
     140        connect(m_pDownloader, &UIDownloader::sigToStartDownloading,
     141                this, &UINotificationDownloader::sigProgressStarted);
     142        connect(m_pDownloader, &UIDownloader::sigToStartVerifying,
     143                this, &UINotificationDownloader::sigProgressStarted);
     144        connect(m_pDownloader, &UIDownloader::sigProgressChange,
     145                this, &UINotificationDownloader::sltHandleProgressChange);
     146        connect(m_pDownloader, &UIDownloader::sigProgressFailed,
     147                this, &UINotificationDownloader::sltHandleProgressFailed);
     148        connect(m_pDownloader, &UIDownloader::sigProgressCanceled,
     149                this, &UINotificationDownloader::sigProgressCanceled);
     150        connect(m_pDownloader, &UIDownloader::sigProgressFinished,
     151                this, &UINotificationDownloader::sigProgressFinished);
     152        connect(m_pDownloader, &UIDownloader::destroyed,
     153                this, &UINotificationDownloader::sigDownloaderDestroyed);
     154
     155        /* And start it finally: */
     156        m_pDownloader->start();
     157    }
     158}
     159
     160void UINotificationDownloader::close()
     161{
     162    /* Cancel downloader: */
     163    if (m_pDownloader)
     164        m_pDownloader->cancel();
     165    /* Call to base-class: */
     166    UINotificationObject::close();
     167}
     168
     169void UINotificationDownloader::sltHandleProgressChange(ulong uPercent)
     170{
     171    m_uPercent = uPercent;
     172    emit sigProgressChange(uPercent);
     173}
     174
     175void UINotificationDownloader::sltHandleProgressFailed(const QString &strError)
     176{
     177    m_strError = strError;
     178    emit sigProgressFailed();
     179}
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObject.h

    r90290 r90556  
    2424/* Qt includes: */
    2525#include <QObject>
     26#include <QPointer>
    2627
    2728/* GUI includes: */
     
    3233
    3334/* Forward declarations: */
     35class UIDownloader;
    3436class UINotificationProgressTask;
    3537
     
    119121};
    120122
     123/** UINotificationObject extension for notification-downloader. */
     124class SHARED_LIBRARY_STUFF UINotificationDownloader : public UINotificationObject
     125{
     126    Q_OBJECT;
     127
     128signals:
     129
     130    /** Notifies listeners about progress started. */
     131    void sigProgressStarted();
     132    /** Notifies listeners about progress changed.
     133      * @param  uPercent  Brings new progress percentage value. */
     134    void sigProgressChange(ulong uPercent);
     135    /** Notifies listeners about progress failed. */
     136    void sigProgressFailed();
     137    /** Notifies listeners about progress canceled. */
     138    void sigProgressCanceled();
     139    /** Notifies listeners about progress finished. */
     140    void sigProgressFinished();
     141
     142    /** Notifies listeners about downloader destroyed. */
     143    void sigDownloaderDestroyed();
     144
     145public:
     146
     147    /** Constructs notification-downloader. */
     148    UINotificationDownloader();
     149    /** Destructs notification-downloader. */
     150    virtual ~UINotificationDownloader() /* override final */;
     151
     152    /** Creates and returns started downloader-wrapper. */
     153    virtual UIDownloader *createDownloader() = 0;
     154
     155    /** Returns current progress percentage value. */
     156    ulong percent() const;
     157    /** Returns error-message if any. */
     158    QString error() const;
     159
     160    /** Handles notification-object being added. */
     161    virtual void handle() /* override final */;
     162
     163public slots:
     164
     165    /** Stops the downloader and notifies model about closing. */
     166    virtual void close() /* override final */;
     167
     168private slots:
     169
     170    /** Handles signal about progress changed.
     171      * @param  uPercent  Brings new progress percentage value. */
     172    void sltHandleProgressChange(ulong uPercent);
     173    /** Handles signal about progress failed.
     174      * @param  strError  Brings error message if any. */
     175    void sltHandleProgressFailed(const QString &strError);
     176
     177private:
     178
     179    /** Holds the instance of downloader being wrapped by this notification-downloader. */
     180    QPointer<UIDownloader>  m_pDownloader;
     181
     182    /** Holds the last cached progress percentage value. */
     183    ulong    m_uPercent;
     184    /** Holds the error message is any. */
     185    QString  m_strError;
     186};
     187
    121188#endif /* !FEQT_INCLUDED_SRC_notificationcenter_UINotificationObject_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjectItem.cpp

    r90391 r90556  
    273273
    274274/*********************************************************************************************************************************
     275*   Class UINotificationDownloaderItem implementation.                                                                           *
     276*********************************************************************************************************************************/
     277
     278UINotificationDownloaderItem::UINotificationDownloaderItem(QWidget *pParent, UINotificationDownloader *pDownloader /* = 0 */)
     279    : UINotificationObjectItem(pParent, pDownloader)
     280    , m_pProgressBar(0)
     281{
     282    /* Main layout was prepared in base-class: */
     283    if (m_pLayoutMain)
     284    {
     285        /* Name label was prepared in base-class: */
     286        if (m_pLabelName)
     287            m_pLabelName->setText(downloader()->name());
     288        /* Details label was prepared in base-class: */
     289        if (m_pLabelDetails)
     290        {
     291            int iHint = m_pLabelName->minimumSizeHint().width()
     292                      + m_pLayoutUpper->spacing()
     293                      + m_pButtonClose->minimumSizeHint().width();
     294            m_pLabelDetails->setMinimumTextWidth(iHint);
     295            updateDetails();
     296        }
     297
     298        /* Prepare progress-bar: */
     299        m_pProgressBar = new QProgressBar(this);
     300        if (m_pProgressBar)
     301        {
     302            m_pProgressBar->setMinimum(0);
     303            m_pProgressBar->setMaximum(100);
     304            m_pProgressBar->setValue(downloader()->percent());
     305
     306            m_pLayoutMain->addWidget(m_pProgressBar);
     307        }
     308    }
     309
     310    /* Prepare downloader connections: */
     311    connect(downloader(), &UINotificationDownloader::sigProgressStarted,
     312            this, &UINotificationDownloaderItem::sltHandleProgressStarted);
     313    connect(downloader(), &UINotificationDownloader::sigProgressChange,
     314            this, &UINotificationDownloaderItem::sltHandleProgressChange);
     315    connect(downloader(), &UINotificationDownloader::sigProgressFailed,
     316            this, &UINotificationDownloaderItem::sltHandleProgressFinished);
     317    connect(downloader(), &UINotificationDownloader::sigProgressCanceled,
     318            this, &UINotificationDownloaderItem::sltHandleProgressFinished);
     319    connect(downloader(), &UINotificationDownloader::sigProgressFinished,
     320            this, &UINotificationDownloaderItem::sltHandleProgressFinished);
     321}
     322
     323void UINotificationDownloaderItem::sltHandleProgressStarted()
     324{
     325    /* Init progress-bar state: */
     326    if (m_pProgressBar)
     327        m_pProgressBar->setValue(0);
     328    /* Update details with fetched stuff if any: */
     329    if (m_pLabelDetails)
     330        updateDetails();
     331}
     332
     333void UINotificationDownloaderItem::sltHandleProgressChange(ulong uPercent)
     334{
     335    /* Update progress-bar state: */
     336    if (m_pProgressBar)
     337        m_pProgressBar->setValue(uPercent);
     338}
     339
     340void UINotificationDownloaderItem::sltHandleProgressFinished()
     341{
     342    /* Finalize progress-bar state: */
     343    if (m_pProgressBar)
     344        m_pProgressBar->setValue(100);
     345    /* Update details with error text if any: */
     346    if (m_pLabelDetails)
     347        updateDetails();
     348}
     349
     350UINotificationDownloader *UINotificationDownloaderItem::downloader() const
     351{
     352    return qobject_cast<UINotificationDownloader*>(m_pObject);
     353}
     354
     355void UINotificationDownloaderItem::updateDetails()
     356{
     357    AssertPtrReturnVoid(m_pLabelDetails);
     358    const QString strDetails = downloader()->details();
     359    const QString strError = downloader()->error();
     360    const QString strFullDetails = strError.isNull()
     361                                 ? strDetails
     362                                 : QString("%1<br>%2").arg(strDetails, strError);
     363    m_pLabelDetails->setText(strFullDetails);
     364    if (!strError.isEmpty())
     365    {
     366        m_fToggled = true;
     367        m_pLabelDetails->setVisible(m_fToggled);
     368    }
     369}
     370
     371
     372/*********************************************************************************************************************************
    275373*   Namespace UINotificationProgressItem implementation.                                                                         *
    276374*********************************************************************************************************************************/
     
    281379    if (pObject->inherits("UINotificationProgress"))
    282380        return new UINotificationProgressItem(pParent, static_cast<UINotificationProgress*>(pObject));
     381    if (pObject->inherits("UINotificationDownloader"))
     382        return new UINotificationDownloaderItem(pParent, static_cast<UINotificationDownloader*>(pObject));
    283383    /* Handle defaults: */
    284384    return new UINotificationObjectItem(pParent, pObject);
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjectItem.h

    r90388 r90556  
    3232class QIRichTextLabel;
    3333class QIToolButton;
     34class UINotificationDownloader;
    3435class UINotificationObject;
    3536class UINotificationProgress;
     
    109110};
    110111
     112/** UINotificationObjectItem extension for notification-downloader. */
     113class UINotificationDownloaderItem : public UINotificationObjectItem
     114{
     115    Q_OBJECT;
     116
     117public:
     118
     119    /** Constructs notification-downloader item, passing @a pParent to the base-class.
     120      * @param  pDownloader  Brings the notification-downloader this item created for. */
     121    UINotificationDownloaderItem(QWidget *pParent, UINotificationDownloader *pDownloader = 0);
     122
     123protected:
     124
     125    /** Holds the progress-bar instance. */
     126    QProgressBar *m_pProgressBar;
     127
     128private slots:
     129
     130    /** Handles signal about progress started. */
     131    void sltHandleProgressStarted();
     132    /** Handles signal about progress changed.
     133      * @param  uPercent  Brings new progress percentage value. */
     134    void sltHandleProgressChange(ulong uPercent);
     135    /** Handles signal about progress finished. */
     136    void sltHandleProgressFinished();
     137
     138private:
     139
     140    /** Holds the notification-downloader this item created for. */
     141    UINotificationDownloader *downloader() const;
     142
     143    /** Updates details. */
     144    void updateDetails();
     145};
     146
    111147/** Notification-object factory. */
    112148namespace UINotificationItem
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