VirtualBox

Changeset 41145 in vbox


Ignore:
Timestamp:
May 3, 2012 4:40:59 PM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: Update Manager stuff: Refactoring/Cleanup.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp

    r39932 r41145  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIUpdateManager class implementation.
     3 *
     4 * VBox frontends: Qt4 GUI ("VirtualBox"):
     5 * UIUpdateManager class implementation
    46 */
    57
    68/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     9 * Copyright (C) 2006-2012 Oracle Corporation
    810 *
    911 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1719
    1820/* Global includes: */
    19 #include <QEventLoop>
    2021#include <QNetworkReply>
    2122#include <QTimer>
     
    3637#include "VBoxDefs.h"
    3738
     39/* Forward declarations: */
     40class UIUpdateStep;
     41
    3842/* Using declarations: */
    3943using namespace VBoxGlobalDefs;
    4044
    41 /* Interface representing update step: */
     45/* Queue for processing update-steps: */
     46class UIUpdateQueue : public QObject
     47{
     48    Q_OBJECT;
     49
     50signals:
     51
     52    /* Starting-signal of the queue: */
     53    void sigStartQueue();
     54
     55    /* Completion-signal of the queue: */
     56    void sigQueueFinished();
     57
     58public:
     59
     60    /* Constructor: */
     61    UIUpdateQueue(UIUpdateManager *pParent) : QObject(pParent) {}
     62
     63    /* Starts a queue: */
     64    void start() { emit sigStartQueue(); }
     65
     66private:
     67
     68    /* Helpers: */
     69    bool isEmpty() const { return m_pLastStep.isNull(); }
     70    UIUpdateStep* lastStep() const { return m_pLastStep; }
     71    void setLastStep(UIUpdateStep *pStep) { m_pLastStep = pStep; }
     72
     73    /* Variables: */
     74    QPointer<UIUpdateStep> m_pLastStep;
     75
     76    /* Friend classes: */
     77    friend class UIUpdateStep;
     78};
     79
     80/* Interface representing update-step: */
    4281class UIUpdateStep : public UINetworkCustomer
    4382{
     
    5291
    5392    /* Constructor: */
    54     UIUpdateStep()
    55     {
    56         /* Connect completion-signal of the step to the destruction-slot of the step: */
     93    UIUpdateStep(UIUpdateQueue *pQueue) : UINetworkCustomer(pQueue)
     94    {
     95        /* If queue has no steps yet: */
     96        if (pQueue->isEmpty())
     97        {
     98            /* Connect starting-signal of the queue to starting-slot of this step: */
     99            connect(pQueue, SIGNAL(sigStartQueue()), this, SLOT(sltStartStep()), Qt::QueuedConnection);
     100        }
     101        /* If queue has at least one step already: */
     102        else
     103        {
     104            /* Reconnect completion-signal of the last-step from completion-signal of the queue to starting-slot of this step: */
     105            disconnect(pQueue->lastStep(), SIGNAL(sigStepComplete()), pQueue, SIGNAL(sigQueueFinished()));
     106            connect(pQueue->lastStep(), SIGNAL(sigStepComplete()), this, SLOT(sltStartStep()), Qt::QueuedConnection);
     107        }
     108
     109        /* Connect completion-signal of this step to the completion-signal of the queue: */
     110        connect(this, SIGNAL(sigStepComplete()), pQueue, SIGNAL(sigQueueFinished()), Qt::QueuedConnection);
     111        /* Connect completion-signal of this step to the destruction-slot of this step: */
    57112        connect(this, SIGNAL(sigStepComplete()), this, SLOT(deleteLater()), Qt::QueuedConnection);
     113
     114        /* Remember this step as the last one: */
     115        pQueue->setLastStep(this);
    58116    }
    59117
     
    73131};
    74132
    75 /* Queue for processing update steps: */
    76 class UIUpdateQueue : public QObject
     133/* Update-step to check for the new VirtualBox version: */
     134class UIUpdateStepVirtualBox : public UIUpdateStep
    77135{
    78136    Q_OBJECT;
    79137
    80 signals:
    81 
    82     /* Starting-signal of the queue: */
    83     void sigStartQueue();
    84 
    85     /* Completion-signal of the queue: */
    86     void sigQueueFinished();
    87 
    88138public:
    89139
    90140    /* Constructor: */
    91     UIUpdateQueue(UIUpdateManager *pParent) : QObject(pParent) {}
    92 
    93     /* Enqueue passed-step with previously queued (if any) passed-steps: */
    94     void add(UIUpdateStep *pStep)
    95     {
    96         /* Set 'this' as parent for passed step,
    97          * that way passed-step could be cleaned-up in case of queue destruction: */
    98         pStep->setParent(this);
    99 
    100         /* If queue had no passed-steps yet: */
    101         if (!m_pLastStep)
    102         {
    103             /* Connect starting-signal of the queue to starting-slot of the passed-step: */
    104             connect(this, SIGNAL(sigStartQueue()), pStep, SLOT(sltStartStep()), Qt::QueuedConnection);
    105         }
    106         /* If queue already had at least one passed-step: */
    107         else
    108         {
    109             /* Reconnect completion-signal of the last-step from completion-signal of the queue to starting-slot of the passed-step: */
    110             disconnect(m_pLastStep, SIGNAL(sigStepComplete()), this, SIGNAL(sigQueueFinished()));
    111             connect(m_pLastStep, SIGNAL(sigStepComplete()), pStep, SLOT(sltStartStep()), Qt::QueuedConnection);
    112         }
    113 
    114         /* Connect completion-signal of the passed-step to the completion-signal of the queue: */
    115         connect(pStep, SIGNAL(sigStepComplete()), this, SIGNAL(sigQueueFinished()), Qt::QueuedConnection);
    116 
    117         /* Remember last-step: */
    118         m_pLastStep = pStep;
    119     }
    120 
    121     /* Starts a queue: */
    122     void start()
    123     {
    124         /* Emit signal which starts queue: */
    125         emit sigStartQueue();
    126     }
    127 
    128 private:
    129 
    130     /* Guarded pointer to the last passed-step: */
    131     QPointer<UIUpdateStep> m_pLastStep;
    132 };
    133 
    134 /* Update step to check for the new VirtualBox version: */
    135 class UIUpdateStepVirtualBox : public UIUpdateStep
    136 {
    137     Q_OBJECT;
    138 
    139 public:
    140 
    141     /* Constructor: */
    142     UIUpdateStepVirtualBox(bool fForceCall)
    143         : m_url("http://update.virtualbox.org/query.php")
     141    UIUpdateStepVirtualBox(UIUpdateQueue *pQueue, bool fForceCall)
     142        : UIUpdateStep(pQueue)
     143        , m_url("http://update.virtualbox.org/query.php")
    144144        , m_fForceCall(fForceCall)
    145145    {
     
    243243};
    244244
    245 /* Update step to check for the new VirtualBox Extension Pack version: */
     245/* Update-step to check for the new VirtualBox Extension Pack version: */
    246246class UIUpdateStepVirtualBoxExtensionPack : public UIUpdateStep
    247247{
     
    251251
    252252    /* Constructor: */
    253     UIUpdateStepVirtualBoxExtensionPack() {}
     253    UIUpdateStepVirtualBoxExtensionPack(UIUpdateQueue *pQueue)
     254        : UIUpdateStep(pQueue)
     255    {
     256    }
    254257
    255258private slots:
     
    409412    {
    410413        /* Prepare update queue: */
    411         m_pQueue->add(new UIUpdateStepVirtualBox(fForceCall));
    412         m_pQueue->add(new UIUpdateStepVirtualBoxExtensionPack);
     414        new UIUpdateStepVirtualBox(m_pQueue, fForceCall);
     415        new UIUpdateStepVirtualBoxExtensionPack(m_pQueue);
    413416        /* Start update queue: */
    414417        m_pQueue->start();
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.h

    r39932 r41145  
    66
    77/*
    8  * Copyright (C) 2006-2011 Oracle Corporation
     8 * Copyright (C) 2006-2012 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2626class UIUpdateQueue;
    2727
    28 /* Singleton to perform new version checks and
    29  * updates of various VirtualBox parts. */
     28/* Singleton to perform new version checks
     29 * and update of various VirtualBox parts. */
    3030class UIUpdateManager : public QObject
    3131{
     
    6969
    7070#endif // __UIUpdateManager_h__
     71
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