VirtualBox

Changeset 90579 in vbox


Ignore:
Timestamp:
Aug 9, 2021 2:49:12 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146185
Message:

FE/Qt: bugref:10067: Large rework in UIUpdateManager; Separating network-customer and update-step definitions, network-customer is using in just one update-step, while update-step and update-queue are now represented as separate UIExecutionQueue and UIExecutionStep interfaces.

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

Legend:

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

    r90569 r90579  
    847847        src/notificationcenter/UINotificationObjects.h \
    848848        src/notificationcenter/UINotificationProgressTask.h \
     849        src/objects/UIExecutionQueue.h \
    849850        src/settings/UISettingsDialog.h \
    850851        src/settings/UISettingsDialogSpecific.h \
     
    13961397        src/notificationcenter/UINotificationObjects.cpp \
    13971398        src/notificationcenter/UINotificationProgressTask.cpp \
     1399        src/objects/UIExecutionQueue.cpp \
    13981400        src/objects/UIRichTextString.cpp \
    13991401        src/settings/UISettingsDefs.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/networking/UINetworkCustomer.cpp

    r90547 r90579  
    2121
    2222
    23 UINetworkCustomer::UINetworkCustomer(QObject *pParent /* = 0 */, bool fForceCall /* = true */)
    24     : QObject(pParent)
    25     , m_fForceCall(fForceCall)
     23UINetworkCustomer::UINetworkCustomer()
    2624{
    2725}
  • trunk/src/VBox/Frontends/VirtualBox/src/networking/UINetworkCustomer.h

    r90547 r90579  
    4646public:
    4747
    48     /** Constructs network customer passing @a pParent to the base-class.
    49       * @param  fForceCall  Brings whether this customer has forced privelegies. */
    50     UINetworkCustomer(QObject *pParent = 0, bool fForceCall = true);
     48    /** Constructs network customer passing @a pParent to the base-class. */
     49    UINetworkCustomer();
    5150    /** Destructs network customer. */
    5251    virtual ~UINetworkCustomer() /* override */;
    53 
    54     /** Returns whether this customer has forced privelegies. */
    55     bool isItForceCall() const { return m_fForceCall; }
    5652
    5753    /** Returns description of the current network operation. */
     
    8480private:
    8581
    86     /** Holds whether this customer has forced privelegies. */
    87     bool  m_fForceCall;
    88 
    8982    /** Holds the network-request ID. */
    9083    QUuid  m_uId;
  • trunk/src/VBox/Frontends/VirtualBox/src/networking/UIUpdateManager.cpp

    r90564 r90579  
    2727#include "UICommon.h"
    2828#include "VBoxUtils.h"
     29#include "UIExecutionQueue.h"
    2930#include "UIExtraDataManager.h"
    3031#include "UIMessageCenter.h"
     
    4344
    4445/* Other VBox includes: */
    45 //# include <iprt/err.h>
    4646#include <iprt/path.h>
    4747#include <iprt/system.h>
     
    5151//#define VBOX_NEW_VERSION_TEST "5.1.12_0 http://unknown.unknown.org/0.0.0/VirtualBox-0.0.0-0-unknown.pkg"
    5252
    53 /* Forward declarations: */
    54 class UIUpdateStep;
    55 
    56 
    57 /** QObject subclass providing GUI with
    58   * an object to manage queue of update-steps. */
    59 class UIUpdateQueue : public QObject
     53
     54/** UINetworkCustomer extension for new version check. */
     55class UINewVersionChecker : public UINetworkCustomer
    6056{
    6157    Q_OBJECT;
     
    6359signals:
    6460
    65     /** Starts the queue. */
    66     void sigStartQueue();
    67 
    68     /** Notifies about queue is finished. */
    69     void sigQueueFinished();
     61    /** Notifies about new version check complete. */
     62    void sigNewVersionChecked();
    7063
    7164public:
    7265
    73     /** Constructs update queue passing @a pParent to the base-class. */
    74     UIUpdateQueue(UIUpdateManager *pParent) : QObject(pParent) {}
    75 
    76     /** Starts the queue. */
    77     void start() { emit sigStartQueue(); }
     66    /** Constructs new version checker.
     67      * @param  fForceCall  Brings whether this customer has forced privelegies. */
     68    UINewVersionChecker(bool fForceCall);
     69
     70    /** Starts new version check. */
     71    void start();
     72
     73protected:
     74
     75    /** Handles network reply progress for @a iReceived amount of bytes among @a iTotal. */
     76    virtual void processNetworkReplyProgress(qint64 iReceived, qint64 iTotal);
     77    /** Handles network reply failed with specified @a strError. */
     78    virtual void processNetworkReplyFailed(const QString &strError);
     79    /** Handles network reply canceling for a passed @a pReply. */
     80    virtual void processNetworkReplyCanceled(UINetworkReply *pReply);
     81    /** Handles network reply finishing for a passed @a pReply. */
     82    virtual void processNetworkReplyFinished(UINetworkReply *pReply);
    7883
    7984private:
    8085
    81     /** Returns whether queue is empty. */
    82     bool isEmpty() const { return m_pLastStep.isNull(); }
    83 
    84     /** Defines the last queued @a pStep. */
    85     void setLastStep(UIUpdateStep *pStep) { m_pLastStep = pStep; }
    86     /** Returns the last queued step. */
    87     UIUpdateStep *lastStep() const { return m_pLastStep; }
    88 
    89     /** Holds the last queued step reference. */
    90     QPointer<UIUpdateStep> m_pLastStep;
    91 
    92     /** Allows step to manage queue. */
    93     friend class UIUpdateStep;
    94 };
    95 
    96 
    97 /** Update step interface.
    98   * UINetworkCustomer extension which allows background network updates. */
    99 class UIUpdateStep : public UINetworkCustomer
    100 {
    101     Q_OBJECT;
    102 
    103 signals:
    104 
    105     /** Notifies about step is finished. */
    106     void sigStepComplete();
    107 
    108 public:
    109 
    110     /** Constructs update step passing @a pQueue and @a fForceCall to the base-class. */
    111     UIUpdateStep(UIUpdateQueue *pQueue, bool fForceCall);
    112 
    113 protected:
    114 
    115     /** Handles network reply progress for @a iReceived amount of bytes among @a iTotal. */
    116     virtual void processNetworkReplyProgress(qint64 iReceived, qint64 iTotal) /* override */;
    117     /** Handles network reply finishing with specified @a strError. */
    118     virtual void processNetworkReplyFailed(const QString &strError) /* override */;
    119     /** Handles network reply canceling for a passed @a pReply. */
    120     virtual void processNetworkReplyCanceled(UINetworkReply *pReply) /* override */;
    121     /** Handles network reply finishing for a passed @a pReply. */
    122     virtual void processNetworkReplyFinished(UINetworkReply *pReply) /* override */;
    123 
    124 protected slots:
    125 
    126     /** Starts the step. */
    127     virtual void sltStartStep() = 0;
    128 };
    129 
    130 
    131 /** Update step subclass to check for the new VirtualBox version. */
    132 class UIUpdateStepVirtualBox : public UIUpdateStep
    133 {
    134     Q_OBJECT;
    135 
    136 public:
    137 
    138     /** Constructs update step passing @a pQueue and @a fForceCall to the base-class. */
    139     UIUpdateStepVirtualBox(UIUpdateQueue *pQueue, bool fForceCall)
    140         : UIUpdateStep(pQueue, fForceCall)
    141         , m_url("https://update.virtualbox.org/query.php")
    142     {}
    143 
    144 protected:
    145 
    146     /** Returns description of the current network operation. */
    147     virtual QString description() const /* override */;
    148 
    149     /** Handles network reply finishing with specified @a strError. */
    150     virtual void processNetworkReplyFailed(const QString &strError) /* override */;
    151     /** Handles network reply canceling for a passed @a pReply. */
    152     virtual void processNetworkReplyCanceled(UINetworkReply *pReply) /* override */;
    153     /** Handles network reply finishing for a passed @a pReply. */
    154     virtual void processNetworkReplyFinished(UINetworkReply *pReply) /* override */;
    155 
    156 protected slots:
    157 
    158     /** Starts the step. */
    159     virtual void sltStartStep() /* override */;
    160 
    161 private:
     86    /** Returns whether this customer has forced privelegies. */
     87    bool isItForceCall() const { return m_fForceCall; }
    16288
    16389    /** Generates platform information. */
    16490    static QString platformInfo();
    16591
    166     /** Holds the update step URL. */
    167     QUrl m_url;
     92    /** Holds whether this customer has forced privelegies. */
     93    bool  m_fForceCall;
     94    /** Holds the new version checker URL. */
     95    QUrl  m_url;
    16896};
    16997
    17098
    171 /** Update step subclass to check for the new VirtualBox Extension Pack version. */
    172 class UIUpdateStepVirtualBoxExtensionPack : public UIUpdateStep
     99/** UIExecutionStep extension to check for the new VirtualBox version. */
     100class UIUpdateStepVirtualBox : public UIExecutionStep
    173101{
    174102    Q_OBJECT;
     
    176104public:
    177105
    178     /** Constructs update step passing @a pQueue and @a fForceCall to the base-class. */
    179     UIUpdateStepVirtualBoxExtensionPack(UIUpdateQueue *pQueue, bool fForceCall)
    180         : UIUpdateStep(pQueue, fForceCall)
    181     {}
    182 
    183 protected slots:
    184 
    185     /** Starts the step. */
    186     virtual void sltStartStep() /* override */;
     106    /** Constructs extension step. */
     107    UIUpdateStepVirtualBox(bool fForceCall);
     108    /** Destructs extension step. */
     109    virtual ~UIUpdateStepVirtualBox() /* override final */;
     110
     111    /** Executes the step. */
     112    virtual void exec() /* override */;
     113
     114private:
     115
     116    /** Holds the new version checker instance. */
     117    UINewVersionChecker *m_pNewVersionChecker;
     118};
     119
     120
     121/** UIExecutionStep extension to check for the new VirtualBox Extension Pack version. */
     122class UIUpdateStepVirtualBoxExtensionPack : public UIExecutionStep
     123{
     124    Q_OBJECT;
     125
     126public:
     127
     128    /** Constructs extension step. */
     129    UIUpdateStepVirtualBoxExtensionPack();
     130
     131    /** Executes the step. */
     132    virtual void exec() /* override */;
    187133
    188134private slots:
     
    199145
    200146/*********************************************************************************************************************************
    201 *   Class UIUpdateStep implementation.                                                                                           *
     147*   Class UINewVersionChecker implementation.                                                                                    *
    202148*********************************************************************************************************************************/
    203149
    204 UIUpdateStep::UIUpdateStep(UIUpdateQueue *pQueue, bool fForceCall)
    205     : UINetworkCustomer(pQueue, fForceCall)
    206 {
    207     /* If queue has no steps yet: */
    208     if (pQueue->isEmpty())
    209     {
    210         /* Connect starting-signal of the queue to starting-slot of this step: */
    211         connect(pQueue, &UIUpdateQueue::sigStartQueue, this, &UIUpdateStep::sltStartStep, Qt::QueuedConnection);
    212     }
    213     /* If queue has at least one step already: */
    214     else
    215     {
    216         /* Reconnect completion-signal of the last-step from completion-signal of the queue to starting-slot of this step: */
    217         disconnect(pQueue->lastStep(), &UIUpdateStep::sigStepComplete, pQueue, &UIUpdateQueue::sigQueueFinished);
    218         connect(pQueue->lastStep(), &UIUpdateStep::sigStepComplete, this, &UIUpdateStep::sltStartStep, Qt::QueuedConnection);
    219     }
    220 
    221     /* Connect completion-signal of this step to the completion-signal of the queue: */
    222     connect(this, &UIUpdateStep::sigStepComplete, pQueue, &UIUpdateQueue::sigQueueFinished, Qt::QueuedConnection);
    223     /* Connect completion-signal of this step to the destruction-slot of this step: */
    224     connect(this, &UIUpdateStep::sigStepComplete, this, &UIUpdateStep::deleteLater, Qt::QueuedConnection);
    225 
    226     /* Remember this step as the last one: */
    227     pQueue->setLastStep(this);
    228 }
    229 
    230 void UIUpdateStep::processNetworkReplyProgress(qint64, qint64)
    231 {
    232 }
    233 
    234 void UIUpdateStep::processNetworkReplyFailed(const QString &)
    235 {
    236 }
    237 
    238 void UIUpdateStep::processNetworkReplyCanceled(UINetworkReply *)
    239 {
    240 }
    241 
    242 void UIUpdateStep::processNetworkReplyFinished(UINetworkReply *)
    243 {
    244 }
    245 
    246 
    247 /*********************************************************************************************************************************
    248 *   Class UIUpdateStepVirtualBox implementation.                                                                                 *
    249 *********************************************************************************************************************************/
    250 
    251 QString UIUpdateStepVirtualBox::description() const
    252 {
    253     return tr("Checking for a new VirtualBox version...");
    254 }
    255 
    256 void UIUpdateStepVirtualBox::processNetworkReplyFailed(const QString &strError)
    257 {
    258     Q_UNUSED(strError);
    259 
    260     /* Notify about step completion: */
    261     emit sigStepComplete();
    262 }
    263 
    264 void UIUpdateStepVirtualBox::processNetworkReplyCanceled(UINetworkReply *pReply)
    265 {
    266     Q_UNUSED(pReply);
    267 
    268     /* Notify about step completion: */
    269     emit sigStepComplete();
    270 }
    271 
    272 void UIUpdateStepVirtualBox::processNetworkReplyFinished(UINetworkReply *pReply)
    273 {
    274     /* Deserialize incoming data: */
    275     QString strResponseData(pReply->readAll());
    276 
    277 #ifdef VBOX_NEW_VERSION_TEST
    278     strResponseData = VBOX_NEW_VERSION_TEST;
    279 #endif
    280     /* Newer version of necessary package found: */
    281     if (strResponseData.indexOf(QRegExp("^\\d+\\.\\d+\\.\\d+(_[0-9A-Z]+)? \\S+$")) == 0)
    282     {
    283         QStringList response = strResponseData.split(" ", QString::SkipEmptyParts);
    284         msgCenter().showUpdateSuccess(response[0], response[1]);
    285     }
    286     /* No newer version of necessary package found: */
    287     else
    288     {
    289         if (isItForceCall())
    290             msgCenter().showUpdateNotFound();
    291     }
    292 
    293     /* Increment update check counter: */
    294     gEDataManager->incrementApplicationUpdateCheckCounter();
    295 
    296     /* Notify about step completion: */
    297     emit sigStepComplete();
    298 }
    299 
    300 void UIUpdateStepVirtualBox::sltStartStep()
     150UINewVersionChecker::UINewVersionChecker(bool fForceCall)
     151    : m_fForceCall(fForceCall)
     152    , m_url("https://update.virtualbox.org/query.php")
     153{
     154}
     155
     156void UINewVersionChecker::start()
    301157{
    302158    /* Compose query: */
     
    320176    url.addQueryItem("count", QString::number(gEDataManager->applicationUpdateCheckCounter()));
    321177    url.addQueryItem("branch", VBoxUpdateData(gEDataManager->applicationUpdateData()).branchName());
    322     QString strUserAgent(QString("VirtualBox %1 <%2>").arg(uiCommon().virtualBox().GetVersion()).arg(platformInfo()));
     178    const QString strUserAgent(QString("VirtualBox %1 <%2>").arg(uiCommon().virtualBox().GetVersion()).arg(platformInfo()));
    323179
    324180    /* Send GET request: */
     
    330186}
    331187
     188void UINewVersionChecker::processNetworkReplyProgress(qint64, qint64)
     189{
     190}
     191
     192void UINewVersionChecker::processNetworkReplyFailed(const QString &)
     193{
     194    emit sigNewVersionChecked();
     195}
     196
     197void UINewVersionChecker::processNetworkReplyCanceled(UINetworkReply *)
     198{
     199    emit sigNewVersionChecked();
     200}
     201
     202void UINewVersionChecker::processNetworkReplyFinished(UINetworkReply *pReply)
     203{
     204    /* Deserialize incoming data: */
     205    const QString strResponseData(pReply->readAll());
     206
     207#ifdef VBOX_NEW_VERSION_TEST
     208    strResponseData = VBOX_NEW_VERSION_TEST;
     209#endif
     210    /* Newer version of necessary package found: */
     211    if (strResponseData.indexOf(QRegExp("^\\d+\\.\\d+\\.\\d+(_[0-9A-Z]+)? \\S+$")) == 0)
     212    {
     213        const QStringList response = strResponseData.split(" ", QString::SkipEmptyParts);
     214        msgCenter().showUpdateSuccess(response[0], response[1]);
     215    }
     216    /* No newer version of necessary package found: */
     217    else
     218    {
     219        if (isItForceCall())
     220            msgCenter().showUpdateNotFound();
     221    }
     222
     223    /* Increment update check counter: */
     224    gEDataManager->incrementApplicationUpdateCheckCounter();
     225
     226    /* Notify about completion: */
     227    emit sigNewVersionChecked();
     228}
     229
    332230/* static */
    333 QString UIUpdateStepVirtualBox::platformInfo()
     231QString UINewVersionChecker::platformInfo()
    334232{
    335233    /* Prepare platform report: */
     
    406304
    407305/*********************************************************************************************************************************
     306*   Class UIUpdateStepVirtualBox implementation.                                                                                 *
     307*********************************************************************************************************************************/
     308
     309UIUpdateStepVirtualBox::UIUpdateStepVirtualBox(bool fForceCall)
     310    : m_pNewVersionChecker(0)
     311{
     312    m_pNewVersionChecker = new UINewVersionChecker(fForceCall);
     313    if (m_pNewVersionChecker)
     314        connect(m_pNewVersionChecker, &UINewVersionChecker::sigNewVersionChecked,
     315                this, &UIUpdateStepVirtualBox::sigStepFinished);
     316}
     317
     318UIUpdateStepVirtualBox::~UIUpdateStepVirtualBox()
     319{
     320    delete m_pNewVersionChecker;
     321    m_pNewVersionChecker = 0;
     322}
     323
     324void UIUpdateStepVirtualBox::exec()
     325{
     326    m_pNewVersionChecker->start();
     327}
     328
     329
     330/*********************************************************************************************************************************
    408331*   Class UIUpdateStepVirtualBoxExtensionPack implementation.                                                                    *
    409332*********************************************************************************************************************************/
    410333
    411 void UIUpdateStepVirtualBoxExtensionPack::sltStartStep()
    412 {
    413     /* Return if Selector UI issued a direct request to install EP: */
     334UIUpdateStepVirtualBoxExtensionPack::UIUpdateStepVirtualBoxExtensionPack()
     335{
     336}
     337
     338void UIUpdateStepVirtualBoxExtensionPack::exec()
     339{
     340    /* Return if VirtualBox Manager issued a direct request to install EP: */
    414341    if (gUpdateManager->isEPInstallationRequested())
    415342    {
    416         emit sigStepComplete();
     343        emit sigStepFinished();
    417344        return;
    418345    }
     
    421348    if (UINotificationDownloaderExtensionPack::exists())
    422349    {
    423         emit sigStepComplete();
     350        emit sigStepFinished();
    424351        return;
    425352    }
     
    430357    if (extPackManager.isNull())
    431358    {
    432         emit sigStepComplete();
     359        emit sigStepFinished();
    433360        return;
    434361    }
     
    439366    if (extPack.isNull())
    440367    {
    441         emit sigStepComplete();
     368        emit sigStepFinished();
    442369        return;
    443370    }
     
    457384        else
    458385        {
    459             emit sigStepComplete();
     386            emit sigStepFinished();
    460387            return;
    461388        }
     
    468395    if (UIVersion(strExtPackVersion) >= vboxVersion)
    469396    {
    470         emit sigStepComplete();
     397        emit sigStepFinished();
    471398        return;
    472399    }
     
    478405        msgCenter().askUserToDownloadExtensionPack(GUI_ExtPackName, strExtPackVersion, strVBoxVersion);
    479406        /* Never try to download for ENTERPRISE version: */
    480         emit sigStepComplete();
     407        emit sigStepFinished();
    481408        return;
    482409    }
     
    485412    if (!msgCenter().warnAboutOutdatedExtensionPack(GUI_ExtPackName, strExtPackVersion))
    486413    {
    487         emit sigStepComplete();
     414        emit sigStepFinished();
    488415        return;
    489416    }
     
    496423    /* Also, destroyed downloader is a signal to finish the step: */
    497424    connect(pNotification, &UINotificationDownloaderExtensionPack::sigDownloaderDestroyed,
    498             this, &UIUpdateStepVirtualBoxExtensionPack::sigStepComplete);
     425            this, &UIUpdateStepVirtualBoxExtensionPack::sigStepFinished);
    499426    /* Append and start notification: */
    500427    gpNotificationCenter->append(pNotification);
     
    515442        /* Get the list of old extension pack files in VirtualBox homefolder: */
    516443        const QStringList oldExtPackFiles = QDir(uiCommon().homeFolder()).entryList(QStringList("*.vbox-extpack"),
    517                                                                                       QDir::Files);
     444                                                                                    QDir::Files);
    518445        /* Propose to delete old extension pack files if there are any: */
    519446        if (oldExtPackFiles.size())
     
    540467
    541468UIUpdateManager::UIUpdateManager()
    542     : m_pQueue(new UIUpdateQueue(this))
     469    : m_pQueue(new UIExecutionQueue(this))
    543470    , m_fIsRunning(false)
    544471    , m_uTime(1 /* day */ * 24 /* hours */ * 60 /* minutes */ * 60 /* seconds */ * 1000 /* ms */)
     
    550477
    551478    /* Configure queue: */
    552     connect(m_pQueue, &UIUpdateQueue::sigQueueFinished, this, &UIUpdateManager::sltHandleUpdateFinishing);
     479    connect(m_pQueue, &UIExecutionQueue::sigQueueFinished, this, &UIUpdateManager::sltHandleUpdateFinishing);
    553480
    554481#ifdef VBOX_WITH_UPDATE_REQUEST
     
    621548    {
    622549        /* Prepare update queue: */
    623         new UIUpdateStepVirtualBox(m_pQueue, fForceCall);
    624         new UIUpdateStepVirtualBoxExtensionPack(m_pQueue, fForceCall);
     550        m_pQueue->enqueue(new UIUpdateStepVirtualBox(fForceCall));
     551        m_pQueue->enqueue(new UIUpdateStepVirtualBoxExtensionPack);
    625552        /* Start update queue: */
    626553        m_pQueue->start();
  • trunk/src/VBox/Frontends/VirtualBox/src/networking/UIUpdateManager.h

    r86996 r90579  
    2929
    3030/* Forward declarations: */
    31 class UIUpdateQueue;
     31class UIExecutionQueue;
    3232
    3333/** Singleton to perform new version checks
     
    7474    static UIUpdateManager *s_pInstance;
    7575
    76     /** Holds the update queue instance. */
    77     UIUpdateQueue *m_pQueue;
     76    /** Holds the execution queue instance. */
     77    UIExecutionQueue *m_pQueue;
    7878    /** Holds whether Update Manager is running. */
    79     bool           m_fIsRunning;
     79    bool              m_fIsRunning;
    8080    /** Holds the refresh period. */
    81     quint64        m_uTime;
     81    quint64           m_uTime;
    8282
    8383    /** Holds whether the Extension Pack installation is requested. */
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