VirtualBox

Changeset 71466 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Mar 22, 2018 4:39:35 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Heavy cleanup for all networking stuff.

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

Legend:

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

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3030
    3131
    32 UINetworkCustomer::UINetworkCustomer()
    33     : QObject(0)
    34     , m_fForceCall(true)
    35 {
    36 }
    37 
    38 UINetworkCustomer::UINetworkCustomer(QObject *pParent, bool fForceCall)
     32UINetworkCustomer::UINetworkCustomer(QObject *pParent /* = 0 */, bool fForceCall /* = true */)
    3933    : QObject(pParent)
    4034    , m_fForceCall(fForceCall)
     
    4236}
    4337
    44 void UINetworkCustomer::createNetworkRequest(UINetworkRequestType type, const QList<QUrl> urls,
     38void UINetworkCustomer::createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> urls,
    4539                                             const UserDictionary requestHeaders /* = UserDictionary() */)
    4640{
    47     gNetworkManager->createNetworkRequest(type, urls, requestHeaders, this);
     41    gNetworkManager->createNetworkRequest(enmType, urls, requestHeaders, this);
    4842}
    4943
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkCustomer.h

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UINetworkCustomer_h__
    19 #define __UINetworkCustomer_h__
     18#ifndef ___UINetworkCustomer_h___
     19#define ___UINetworkCustomer_h___
    2020
    21 /* Global includes: */
     21/* Qt includes: */
    2222#include <QObject>
    2323
    24 /* Local includes: */
     24/* GUI includes: */
    2525#include "UINetworkDefs.h"
    2626
     
    2929class QUrl;
    3030
    31 /* Interface to access UINetworkManager protected functionality: */
     31/** Interface to access UINetworkManager protected functionality. */
    3232class UINetworkCustomer : public QObject
    3333{
     
    3636public:
    3737
    38     /* Constructors: */
    39     UINetworkCustomer();
    40     UINetworkCustomer(QObject *pParent, bool fForceCall);
     38    /** Constructs network customer passing @a pParent to the base-class.
     39      * @param  fForceCall  Brings whether this customer has forced privelegies. */
     40    UINetworkCustomer(QObject *pParent = 0, bool fForceCall = true);
    4141
    42     /* Getters: */
     42    /** Returns whether this customer has forced privelegies. */
    4343    bool isItForceCall() const { return m_fForceCall; }
    4444
    45     /* Network-reply progress handler: */
     45    /** Handles network reply progress for @a iReceived amount of bytes among @a iTotal. */
    4646    virtual void processNetworkReplyProgress(qint64 iReceived, qint64 iTotal) = 0;
    47     /* Network-reply cancel handler: */
     47    /** Handles network reply canceling for a passed @a pReply. */
    4848    virtual void processNetworkReplyCanceled(UINetworkReply *pReply) = 0;
    49     /* Network-reply finish handler: */
     49    /** Handles network reply finishing for a passed @a pReply. */
    5050    virtual void processNetworkReplyFinished(UINetworkReply *pReply) = 0;
    5151
     
    5656
    5757    /** Creates network-request of the passed @a type on the basis of the passed @a urls and the @a requestHeaders. */
    58     void createNetworkRequest(UINetworkRequestType type, const QList<QUrl> urls,
     58    void createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> urls,
    5959                              const UserDictionary requestHeaders = UserDictionary());
    6060
    6161private:
    6262
    63     /* Variables: */
     63    /** Holds whether this customer has forced privelegies. */
    6464    bool m_fForceCall;
    6565};
    6666
    67 #endif // __UINetworkCustomer_h__
     67#endif /* !___UINetworkCustomer_h___ */
    6868
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    22 /* Global includes: */
     22/* Qt includes: */
    2323# include <QWidget>
    2424# include <QUrl>
    2525
    26 /* Local includes: */
     26/* GUI includes: */
     27# include "VBoxGlobal.h"
     28# include "UINetworkCustomer.h"
    2729# include "UINetworkManager.h"
    2830# include "UINetworkManagerDialog.h"
    2931# include "UINetworkManagerIndicator.h"
    3032# include "UINetworkRequest.h"
    31 # include "UINetworkCustomer.h"
    32 # include "VBoxGlobal.h"
    3333
    3434#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3535
    3636
    37 UINetworkManager* UINetworkManager::m_pInstance = 0;
     37UINetworkManager* UINetworkManager::s_pInstance = 0;
    3838
    3939void UINetworkManager::create()
    4040{
    4141    /* Check that instance do NOT exist: */
    42     if (m_pInstance)
     42    if (s_pInstance)
    4343        return;
    4444
     
    4747
    4848    /* Prepare instance: */
    49     m_pInstance->prepare();
     49    s_pInstance->prepare();
    5050}
    5151
     
    5353{
    5454    /* Check that instance exists: */
    55     if (!m_pInstance)
     55    if (!s_pInstance)
    5656        return;
    5757
    5858    /* Cleanup instance: */
    59     m_pInstance->cleanup();
     59    s_pInstance->cleanup();
    6060
    6161    /* Destroy instance: */
    62     delete m_pInstance;
    63 }
    64 
    65 UINetworkManagerDialog* UINetworkManager::window() const
     62    delete s_pInstance;
     63}
     64
     65UINetworkManagerDialog *UINetworkManager::window() const
    6666{
    6767    return m_pNetworkManagerDialog;
    6868}
    6969
    70 UINetworkManagerIndicator* UINetworkManager::createIndicator() const
     70UINetworkManagerIndicator *UINetworkManager::createIndicator() const
    7171{
    7272    /* For Selector UI only: */
     
    108108}
    109109
    110 void UINetworkManager::createNetworkRequest(UINetworkRequestType type, const QList<QUrl> &urls,
     110void UINetworkManager::createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> &urls,
    111111                                            const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer)
    112112{
    113113    /* Create network-request: */
    114     UINetworkRequest *pNetworkRequest = new UINetworkRequest(type, urls, requestHeaders, pCustomer, this);
     114    UINetworkRequest *pNetworkRequest = new UINetworkRequest(enmType, urls, requestHeaders, pCustomer, this);
    115115    /* Prepare created network-request: */
    116116    prepareNetworkRequest(pNetworkRequest);
     
    121121{
    122122    /* Prepare instance: */
    123     m_pInstance = this;
     123    s_pInstance = this;
    124124}
    125125
     
    127127{
    128128    /* Cleanup instance: */
    129     m_pInstance = 0;
     129    s_pInstance = 0;
    130130}
    131131
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UINetworkManager_h__
    19 #define __UINetworkManager_h__
     18#ifndef ___UINetworkManager_h___
     19#define ___UINetworkManager_h___
    2020
    2121/* Qt includes: */
     
    2323#include <QUuid>
    2424
    25 /* Local inludes: */
     25/* GUI inludes: */
    2626#include "UINetworkDefs.h"
    2727
     
    2929class QUrl;
    3030class QWidget;
    31 class UINetworkRequest;
    3231class UINetworkCustomer;
    3332class UINetworkManagerDialog;
    3433class UINetworkManagerIndicator;
     34class UINetworkRequest;
    3535
    36 /* QObject class reimplementation.
    37  * Providing network access for VirtualBox application purposes. */
     36/** QObject class extension.
     37  * Providing network access for VirtualBox application purposes. */
    3838class UINetworkManager : public QObject
    3939{
     
    4242signals:
    4343
    44     /* Ask listeners (network-requests) to cancel: */
     44    /** Asks listeners (network-requests) to cancel. */
    4545    void sigCancelNetworkRequests();
    4646
     
    5252public:
    5353
    54     /* Instance: */
    55     static UINetworkManager* instance() { return m_pInstance; }
    56 
    57     /* Create/destroy singleton: */
     54    /** Creates singleton instance. */
    5855    static void create();
     56    /** Destroys singleton instance. */
    5957    static void destroy();
    6058
    61     /* Pointer to network-manager dialog: */
    62     UINetworkManagerDialog* window() const;
     59    /** Returns the singleton instance. */
     60    static UINetworkManager *instance() { return s_pInstance; }
     61
     62    /** Returns pointer to network-manager dialog. */
     63    UINetworkManagerDialog *window() const;
    6364
    6465    /** Creates network-manager state-indicator.
    6566      * @remarks To be cleaned up by the caller. */
    66     UINetworkManagerIndicator* createIndicator() const;
     67    UINetworkManagerIndicator *createIndicator() const;
    6768
    6869    /** Registers @a pNetworkRequest in network-manager. */
     
    7374public slots:
    7475
    75     /* Show network-manager dialog: */
     76    /** Shows network-manager dialog. */
    7677    void show();
    7778
    7879protected:
    7980
    80     /* Allow UINetworkCustomer to create network-request: */
     81    /** Allows UINetworkCustomer to create network-request. */
    8182    friend class UINetworkCustomer;
     83
    8284    /** Creates network-request of the passed @a type
    8385      * on the basis of the passed @a urls and the @a requestHeaders for the @a pCustomer specified. */
    84     void createNetworkRequest(UINetworkRequestType type, const QList<QUrl> &urls,
     86    void createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> &urls,
    8587                              const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer);
    8688
    8789private:
    8890
    89     /* Constructor/destructor: */
     91    /** Constructs network manager. */
    9092    UINetworkManager();
     93    /** Destructs network manager. */
    9194    ~UINetworkManager();
    9295
    93     /* Prepare/cleanup: */
     96    /** Prepares all. */
    9497    void prepare();
     98    /** Cleanups all. */
    9599    void cleanup();
    96100
    97     /* Network-request prepare helper: */
     101    /** Prepares @a pNetworkRequest. */
    98102    void prepareNetworkRequest(UINetworkRequest *pNetworkRequest);
    99     /* Network-request cleanup helper: */
     103    /** Cleanups network-request with passed @a uuid. */
    100104    void cleanupNetworkRequest(QUuid uuid);
    101     /* Network-requests cleanup helper: */
     105    /** Cleanups all network-requests. */
    102106    void cleanupNetworkRequests();
    103107
    104108private slots:
    105109
    106     /* Slot to handle network-request progress: */
     110    /** Handles progress for @a iReceived amount of bytes among @a iTotal for request specified by @a uuid. */
    107111    void sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
    108     /* Slot to handle network-request cancel: */
     112    /** Handles canceling of request specified by @a uuid. */
    109113    void sltHandleNetworkRequestCancel(const QUuid &uuid);
    110     /* Slot to handle network-request finish: */
     114    /** Handles finishing of request specified by @a uuid. */
    111115    void sltHandleNetworkRequestFinish(const QUuid &uuid);
    112     /* Slot to handle network-request failure: */
     116    /** Handles @a strError of request specified by @a uuid. */
    113117    void sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &strError);
    114118
    115119private:
    116120
    117     /* Instance: */
    118     static UINetworkManager *m_pInstance;
     121    /** Holds the singleton instance. */
     122    static UINetworkManager *s_pInstance;
    119123
    120     /* Network-request map: */
     124    /** Holds the map of current requests. */
    121125    QMap<QUuid, UINetworkRequest*> m_requests;
    122126
    123     /* Network-manager dialog: */
     127    /** Holds the network manager dialog instance. */
    124128    UINetworkManagerDialog *m_pNetworkManagerDialog;
    125129};
     130
     131/** Singleton Network Manager 'official' name. */
    126132#define gNetworkManager UINetworkManager::instance()
    127133
    128 #endif // __UINetworkManager_h__
     134#endif /* !___UINetworkManager_h___ */
    129135
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.cpp

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    22 /* Global includes: */
     22/* Qt includes: */
    2323# include <QVBoxLayout>
    2424# include <QLabel>
     
    2727# include <QKeyEvent>
    2828
    29 /* Local includes: */
     29/* GUI includes: */
     30# include "QIDialogButtonBox.h"
     31# include "VBoxGlobal.h"
     32# include "UIIconPool.h"
     33# include "UIMessageCenter.h"
     34# include "UIModalWindowManager.h"
     35# include "UINetworkCustomer.h"
     36# include "UINetworkManager.h"
    3037# include "UINetworkManagerDialog.h"
    31 # include "UINetworkManager.h"
    3238# include "UINetworkRequest.h"
    3339# include "UINetworkRequestWidget.h"
    34 # include "UINetworkCustomer.h"
    35 # include "UIIconPool.h"
    36 # include "VBoxGlobal.h"
    37 # include "UIMessageCenter.h"
    38 # include "UIModalWindowManager.h"
    39 # include "QIDialogButtonBox.h"
    4040
    4141#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.h

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UINetworkManagerDialog_h__
    19 #define __UINetworkManagerDialog_h__
     18#ifndef ___UINetworkManagerDialog_h___
     19#define ___UINetworkManagerDialog_h___
    2020
    21 /* Global includes: */
     21/* Qt includes: */
    2222#include <QMainWindow>
    2323#include <QMap>
    2424#include <QUuid>
    2525
    26 /* Local includes: */
     26/* GUI includes: */
    2727#include "QIWithRetranslateUI.h"
    2828
    2929/* Forward declarations: */
     30class QLabel;
     31class QUuid;
     32class QVBoxLayout;
     33class QIDialogButtonBox;
    3034class UINetworkRequest;
    31 class QVBoxLayout;
    32 class QLabel;
    33 class QIDialogButtonBox;
    3435class UINetworkRequestWidget;
    3536
    36 /* QMainWindow reimplementation to reflect network-requests: */
     37/** QMainWindow reimplementation to reflect network-requests. */
    3738class UINetworkManagerDialog : public QIWithRetranslateUI<QMainWindow>
    3839{
     
    4142signals:
    4243
    43     /* Ask listener (network-manager) to cancel all network-requests: */
     44    /** Asks listener (network-manager) to cancel all network-requests. */
    4445    void sigCancelNetworkRequests();
    4546
    4647public slots:
    4748
    48     /* Show the dialog, make sure its visible: */
     49    /** Shows the dialog, make sure its visible. */
    4950    void showNormal();
    5051
    5152protected:
    5253
    53     /* Allow creation of UINetworkManagerDialog to UINetworkManager: */
     54    /** Allows creation of UINetworkManagerDialog to UINetworkManager. */
    5455    friend class UINetworkManager;
    55     /* Constructor: */
     56    /** Constructs Network Manager Dialog. */
    5657    UINetworkManagerDialog();
    5758
    58     /* Allow adding/removing network-request widgets to UINetworkRequest: */
     59    /** Allows adding/removing network-request widgets to UINetworkRequest. */
    5960    friend class UINetworkRequest;
    60     /* Add network-request widget: */
     61    /** Adds network-request widget. */
    6162    void addNetworkRequestWidget(UINetworkRequest *pNetworkRequest);
    62     /* Remove network-request widget: */
     63    /** Removes network-request widget. */
    6364    void removeNetworkRequestWidget(const QUuid &uuid);
     65
     66    /** Handles translation event. */
     67    virtual void retranslateUi() /* override */;
     68
     69    /** Handles show @a pEvent. */
     70    virtual void showEvent(QShowEvent *pEvent) /* override */;
     71
     72    /** Handles key-press @a pEvent. */
     73    virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
    6474
    6575private slots:
    6676
    67     /* Handler for 'Cancel All' button-press: */
     77    /** Handles 'Cancel All' button-press. */
    6878    void sltHandleCancelAllButtonPress();
    6979
    7080private:
    7181
    72     /* Translation stuff: */
    73     void retranslateUi();
    74 
    75     /* Overloaded event-handlers: */
    76     void showEvent(QShowEvent *pShowEvent);
    77     void keyPressEvent(QKeyEvent *pKeyPressEvent);
    78 
    79     /* Widgets: */
    80     QLabel *m_pLabel;
    81     QVBoxLayout *m_pWidgetsLayout;
    82     QIDialogButtonBox *m_pButtonBox;
    83     QMap<QUuid, UINetworkRequestWidget*> m_widgets;
     82    /** Holds the label instance. */
     83    QLabel                               *m_pLabel;
     84    /** Holds the widget layout instance. */
     85    QVBoxLayout                          *m_pWidgetsLayout;
     86    /** Holds the dialog-button-box instance. */
     87    QIDialogButtonBox                    *m_pButtonBox;
     88    /** Holds the map of the network request widget instances. */
     89    QMap<QUuid, UINetworkRequestWidget*>  m_widgets;
    8490};
    8591
    86 #endif // __UINetworkManagerDialog_h__
     92#endif /* !___UINetworkManagerDialog_h___ */
    8793
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerIndicator.cpp

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121
    2222/* GUI includes: */
     23# include "VBoxGlobal.h"
     24# include "UIIconPool.h"
    2325# include "UINetworkManagerIndicator.h"
    2426# include "UINetworkRequest.h"
    25 # include "UIIconPool.h"
    26 # include "VBoxGlobal.h"
    2727
    2828#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    3838    /* Translate content: */
    3939    retranslateUi();
    40 }
    41 
    42 void UINetworkManagerIndicator::sltAddNetworkManagerIndicatorDescription(UINetworkRequest *pNetworkRequest)
    43 {
    44     /* Make sure network-request is really exists: */
    45     AssertMsg(pNetworkRequest, ("Invalid network-request passed!"));
    46     /* Make sure network-request was NOT registered yet: */
    47     AssertMsg(!m_ids.contains(pNetworkRequest->uuid()), ("Network-request already registered!"));
    48 
    49     /* Append network-request data: */
    50     m_ids.append(pNetworkRequest->uuid());
    51     m_data.append(UINetworkRequestData(pNetworkRequest->description(), 0, 0));
    52 
    53     /* Prepare network-request listeners: */
    54     connect(pNetworkRequest, static_cast<void(UINetworkRequest::*)(const QUuid&)>(&UINetworkRequest::sigStarted),
    55             this, &UINetworkManagerIndicator::sltSetProgressToStarted);
    56     connect(pNetworkRequest, &UINetworkRequest::sigCanceled,
    57             this, &UINetworkManagerIndicator::sltSetProgressToCanceled);
    58     connect(pNetworkRequest, static_cast<void(UINetworkRequest::*)(const QUuid&)>(&UINetworkRequest::sigFinished),
    59             this, &UINetworkManagerIndicator::sltSetProgressToFinished);
    60     connect(pNetworkRequest, static_cast<void(UINetworkRequest::*)(const QUuid&, const QString &)>(&UINetworkRequest::sigFailed),
    61             this, &UINetworkManagerIndicator::sltSetProgressToFailed);
    62     connect(pNetworkRequest, static_cast<void(UINetworkRequest::*)(const QUuid&, qint64, qint64)>(&UINetworkRequest::sigProgress),
    63             this, &UINetworkManagerIndicator::sltSetProgress);
    64 
    65     /* Update appearance: */
    66     recalculateIndicatorState();
    67 }
    68 
    69 void UINetworkManagerIndicator::sldRemoveNetworkManagerIndicatorDescription(const QUuid &uuid)
    70 {
    71     /* Make sure network-request still registered: */
    72     AssertMsg(m_ids.contains(uuid), ("Network-request already unregistered!"));
    73 
    74     /* Search for network-request index: */
    75     int iIndexOfRequiredElement = m_ids.indexOf(uuid);
    76 
    77     /* Delete corresponding network-request: */
    78     m_ids.remove(iIndexOfRequiredElement);
    79     m_data.remove(iIndexOfRequiredElement);
    80 
    81     /* Update appearance: */
    82     recalculateIndicatorState();
    83 }
    84 
    85 void UINetworkManagerIndicator::sltSetProgressToStarted(const QUuid &uuid)
    86 {
    87     /* Make sure that network-request still registered: */
    88     AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
    89 
    90     /* Search for network-request index: */
    91     int iIndexOfNetworkRequest = m_ids.indexOf(uuid);
    92     /* Update corresponding network-request data: */
    93     UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
    94     data.bytesReceived = 0;
    95     data.bytesTotal = 0;
    96     data.failed = false;
    97 
    98     /* Update appearance: */
    99     recalculateIndicatorState();
    100 }
    101 
    102 void UINetworkManagerIndicator::sltSetProgressToCanceled(const QUuid &uuid)
    103 {
    104     /* Make sure that network-request still registered: */
    105     AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
    106     Q_UNUSED(uuid);
    107 
    108     /* Update appearance: */
    109     recalculateIndicatorState();
    110 }
    111 
    112 void UINetworkManagerIndicator::sltSetProgressToFailed(const QUuid &uuid, const QString &)
    113 {
    114     /* Make sure that network-request still registered: */
    115     AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
    116 
    117     /* Search for network-request index: */
    118     int iIndexOfNetworkRequest = m_ids.indexOf(uuid);
    119     /* Update corresponding data: */
    120     UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
    121     data.failed = true;
    122 
    123     /* Update appearance: */
    124     recalculateIndicatorState();
    125 }
    126 
    127 void UINetworkManagerIndicator::sltSetProgressToFinished(const QUuid &uuid)
    128 {
    129     /* Make sure that network-request still registered: */
    130     AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
    131     Q_UNUSED(uuid);
    132 
    133     /* Update appearance: */
    134     recalculateIndicatorState();
    135 }
    136 
    137 void UINetworkManagerIndicator::sltSetProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
    138 {
    139     /* Make sure that network-request still registered: */
    140     AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
    141 
    142     /* Search for network-request index: */
    143     int iIndexOfNetworkRequest = m_ids.indexOf(uuid);
    144     /* Update corresponding network-request data: */
    145     UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
    146     data.bytesReceived = iReceived;
    147     data.bytesTotal = iTotal;
    148 
    149     /* Update appearance: */
    150     updateAppearance();
    151 }
    152 
    153 void UINetworkManagerIndicator::retranslateUi()
    154 {
    155     /* Update appearance: */
    156     updateAppearance();
    157 }
    158 
    159 void UINetworkManagerIndicator::recalculateIndicatorState()
    160 {
    161     /* Check if there are network-requests at all: */
    162     if (m_ids.isEmpty())
    163     {
    164         /* Set state to 'idle': */
    165         setState(UINetworkManagerIndicatorState_Idle);
    166     }
    167     else
    168     {
    169         /* Check if there is at least one failed network-request: */
    170         bool fIsThereAtLeastOneFailedNetworkRequest = false;
    171         for (int i = 0; i < m_data.size(); ++i)
    172         {
    173             if (m_data[i].failed)
    174             {
    175                 fIsThereAtLeastOneFailedNetworkRequest = true;
    176                 break;
    177             }
    178         }
    179 
    180         /* If there it least one failed network-request: */
    181         if (fIsThereAtLeastOneFailedNetworkRequest)
    182         {
    183             /* Set state to 'error': */
    184             setState(UINetworkManagerIndicatorState_Error);
    185         }
    186         else
    187         {
    188             /* Set state to 'loading': */
    189             setState(UINetworkManagerIndicatorState_Loading);
    190         }
    191     }
    192 
    193     /* Update appearance finally: */
    194     updateAppearance();
    19540}
    19641
     
    24287}
    24388
     89void UINetworkManagerIndicator::sltAddNetworkManagerIndicatorDescription(UINetworkRequest *pNetworkRequest)
     90{
     91    /* Make sure network-request is really exists: */
     92    AssertMsg(pNetworkRequest, ("Invalid network-request passed!"));
     93    /* Make sure network-request was NOT registered yet: */
     94    AssertMsg(!m_ids.contains(pNetworkRequest->uuid()), ("Network-request already registered!"));
     95
     96    /* Append network-request data: */
     97    m_ids.append(pNetworkRequest->uuid());
     98    m_data.append(UINetworkRequestData(pNetworkRequest->description(), 0, 0));
     99
     100    /* Prepare network-request listeners: */
     101    connect(pNetworkRequest, static_cast<void(UINetworkRequest::*)(const QUuid&)>(&UINetworkRequest::sigStarted),
     102            this, &UINetworkManagerIndicator::sltSetProgressToStarted);
     103    connect(pNetworkRequest, &UINetworkRequest::sigCanceled,
     104            this, &UINetworkManagerIndicator::sltSetProgressToCanceled);
     105    connect(pNetworkRequest, static_cast<void(UINetworkRequest::*)(const QUuid&)>(&UINetworkRequest::sigFinished),
     106            this, &UINetworkManagerIndicator::sltSetProgressToFinished);
     107    connect(pNetworkRequest, static_cast<void(UINetworkRequest::*)(const QUuid&, const QString &)>(&UINetworkRequest::sigFailed),
     108            this, &UINetworkManagerIndicator::sltSetProgressToFailed);
     109    connect(pNetworkRequest, static_cast<void(UINetworkRequest::*)(const QUuid&, qint64, qint64)>(&UINetworkRequest::sigProgress),
     110            this, &UINetworkManagerIndicator::sltSetProgress);
     111
     112    /* Update appearance: */
     113    recalculateIndicatorState();
     114}
     115
     116void UINetworkManagerIndicator::sldRemoveNetworkManagerIndicatorDescription(const QUuid &uuid)
     117{
     118    /* Make sure network-request still registered: */
     119    AssertMsg(m_ids.contains(uuid), ("Network-request already unregistered!"));
     120
     121    /* Search for network-request index: */
     122    int iIndexOfRequiredElement = m_ids.indexOf(uuid);
     123
     124    /* Delete corresponding network-request: */
     125    m_ids.remove(iIndexOfRequiredElement);
     126    m_data.remove(iIndexOfRequiredElement);
     127
     128    /* Update appearance: */
     129    recalculateIndicatorState();
     130}
     131
     132void UINetworkManagerIndicator::retranslateUi()
     133{
     134    /* Update appearance: */
     135    updateAppearance();
     136}
     137
     138void UINetworkManagerIndicator::sltSetProgressToStarted(const QUuid &uuid)
     139{
     140    /* Make sure that network-request still registered: */
     141    AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
     142
     143    /* Search for network-request index: */
     144    int iIndexOfNetworkRequest = m_ids.indexOf(uuid);
     145    /* Update corresponding network-request data: */
     146    UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
     147    data.bytesReceived = 0;
     148    data.bytesTotal = 0;
     149    data.failed = false;
     150
     151    /* Update appearance: */
     152    recalculateIndicatorState();
     153}
     154
     155void UINetworkManagerIndicator::sltSetProgressToCanceled(const QUuid &uuid)
     156{
     157    /* Make sure that network-request still registered: */
     158    AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
     159    Q_UNUSED(uuid);
     160
     161    /* Update appearance: */
     162    recalculateIndicatorState();
     163}
     164
     165void UINetworkManagerIndicator::sltSetProgressToFailed(const QUuid &uuid, const QString &)
     166{
     167    /* Make sure that network-request still registered: */
     168    AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
     169
     170    /* Search for network-request index: */
     171    int iIndexOfNetworkRequest = m_ids.indexOf(uuid);
     172    /* Update corresponding data: */
     173    UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
     174    data.failed = true;
     175
     176    /* Update appearance: */
     177    recalculateIndicatorState();
     178}
     179
     180void UINetworkManagerIndicator::sltSetProgressToFinished(const QUuid &uuid)
     181{
     182    /* Make sure that network-request still registered: */
     183    AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
     184    Q_UNUSED(uuid);
     185
     186    /* Update appearance: */
     187    recalculateIndicatorState();
     188}
     189
     190void UINetworkManagerIndicator::sltSetProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
     191{
     192    /* Make sure that network-request still registered: */
     193    AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
     194
     195    /* Search for network-request index: */
     196    int iIndexOfNetworkRequest = m_ids.indexOf(uuid);
     197    /* Update corresponding network-request data: */
     198    UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
     199    data.bytesReceived = iReceived;
     200    data.bytesTotal = iTotal;
     201
     202    /* Update appearance: */
     203    updateAppearance();
     204}
     205
     206void UINetworkManagerIndicator::recalculateIndicatorState()
     207{
     208    /* Check if there are network-requests at all: */
     209    if (m_ids.isEmpty())
     210    {
     211        /* Set state to 'idle': */
     212        setState(UINetworkManagerIndicatorState_Idle);
     213    }
     214    else
     215    {
     216        /* Check if there is at least one failed network-request: */
     217        bool fIsThereAtLeastOneFailedNetworkRequest = false;
     218        for (int i = 0; i < m_data.size(); ++i)
     219        {
     220            if (m_data[i].failed)
     221            {
     222                fIsThereAtLeastOneFailedNetworkRequest = true;
     223                break;
     224            }
     225        }
     226
     227        /* If there it least one failed network-request: */
     228        if (fIsThereAtLeastOneFailedNetworkRequest)
     229        {
     230            /* Set state to 'error': */
     231            setState(UINetworkManagerIndicatorState_Error);
     232        }
     233        else
     234        {
     235            /* Set state to 'loading': */
     236            setState(UINetworkManagerIndicatorState_Loading);
     237        }
     238    }
     239
     240    /* Update appearance finally: */
     241    updateAppearance();
     242}
     243
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerIndicator.h

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UINetworkManagerIndicator_h__
    19 #define __UINetworkManagerIndicator_h__
     18#ifndef ___UINetworkManagerIndicator_h___
     19#define ___UINetworkManagerIndicator_h___
    2020
    21 /* Global includes: */
     21/* Qt includes: */
    2222#include <QVector>
    2323#include <QUuid>
    2424
    25 /* Local includes: */
     25/* GUI includes: */
    2626#include "QIStatusBarIndicator.h"
     27#include "QIWithRetranslateUI.h"
    2728
    2829/* Forward declarations: */
    2930class UINetworkRequest;
    3031
    31 /* Network-manager status-bar indicator states: */
     32
     33/** Network-manager status-bar indicator states. */
    3234enum UINetworkManagerIndicatorState
    3335{
     
    3739};
    3840
    39 /* Network-manager status-bar indicator: */
    40 class UINetworkManagerIndicator : public QIStateStatusBarIndicator
     41
     42/** QIStateStatusBarIndicator extension for network-manager indicator. */
     43class UINetworkManagerIndicator : public QIWithRetranslateUI<QIStateStatusBarIndicator>
    4144{
    4245    Q_OBJECT;
     
    4447public:
    4548
    46     /* Constructor: */
     49    /** Constructs network manager indicator. */
    4750    UINetworkManagerIndicator();
    4851
    49     /** Update routine. */
     52    /** Updates appearance. */
    5053    void updateAppearance();
    5154
     
    5760    void sldRemoveNetworkManagerIndicatorDescription(const QUuid &uuid);
    5861
     62protected:
     63
     64    /** Handles translation event. */
     65    virtual void retranslateUi() /* override */;
     66
    5967private slots:
    6068
    61     /* Set particular network-request progress to 'started': */
     69    /** Sets particular network-request @a uuid progress to 'started'. */
    6270    void sltSetProgressToStarted(const QUuid &uuid);
    63     /* Set particular network-request progress to 'canceled': */
     71    /** Sets particular network-request @a uuid progress to 'canceled'. */
    6472    void sltSetProgressToCanceled(const QUuid &uuid);
    65     /* Set particular network-request progress to 'failed': */
     73    /** Sets particular network-request @a uuid progress to 'failed'. */
    6674    void sltSetProgressToFailed(const QUuid &uuid, const QString &strError);
    67     /* Set particular network-request progress to 'finished': */
     75    /** Sets particular network-request @a uuid progress to 'finished'. */
    6876    void sltSetProgressToFinished(const QUuid &uuid);
    69     /* Update particular network-request progress: */
     77    /** Updates particular network-request @a uuid progress for @a iReceived amount of bytes among @a iTotal. */
    7078    void sltSetProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
    7179
    7280private:
    7381
     82    /** Network request data. */
    7483    struct UINetworkRequestData
    7584    {
     85        /** Constructs network request data. */
    7686        UINetworkRequestData()
    7787            : bytesReceived(0), bytesTotal(0), failed(false) {}
     88        /** Constructs network request data with @a strDescription, @a iBytesReceived and @a iBytesTotal. */
    7889        UINetworkRequestData(const QString &strDescription, int iBytesReceived, int iBytesTotal)
    7990            : description(strDescription), bytesReceived(iBytesReceived), bytesTotal(iBytesTotal), failed(false) {}
     91        /** Holds the description. */
    8092        QString description;
     93        /** Holds the amount of bytes received. */
    8194        int bytesReceived;
     95        /** Holds the amount of total bytes. */
    8296        int bytesTotal;
     97        /** Holds whether request is failed. */
    8398        bool failed;
    8499    };
    85100
    86     /* Translate stuff: */
    87     void retranslateUi();
    88 
    89     /* Update stuff: */
     101    /** Update stuff. */
    90102    void recalculateIndicatorState();
    91103
    92     /* Variables: */
     104    /** Holds the vector of network request IDs. */
    93105    QVector<QUuid> m_ids;
     106    /** Holds the vector of network request data. */
    94107    QVector<UINetworkRequestData> m_data;
    95108};
    96109
    97 #endif // __UINetworkManagerIndicator_h__
    98110
     111#endif /* !___UINetworkManagerIndicator_h___ */
     112
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.h

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3131#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3232
    33 UINetworkRequest::UINetworkRequest(UINetworkRequestType type,
     33UINetworkRequest::UINetworkRequest(UINetworkRequestType enmType,
    3434                                   const QList<QUrl> &urls,
    3535                                   const UserDictionary &requestHeaders,
     
    3737                                   UINetworkManager *pNetworkManager)
    3838    : QObject(pNetworkManager)
    39     , m_type(type)
     39    , m_enmType(enmType)
    4040    , m_urls(urls)
    4141    , m_requestHeaders(requestHeaders)
     
    197197{
    198198    /* Create network-reply: */
    199     m_pReply = new UINetworkReply(m_type, m_url, m_requestHeaders);
     199    m_pReply = new UINetworkReply(m_enmType, m_url, m_requestHeaders);
    200200    AssertPtrReturnVoid(m_pReply.data());
    201201    {
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.h

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    6767public:
    6868
    69     /** Constructs network-request of the passed @a type
     69    /** Constructs network-request of the passed @a enmType
    7070      * on the basis of the passed @a urls and the @a requestHeaders
    7171      * for the @a pCustomer and @a pNetworkManager specified. */
    72     UINetworkRequest(UINetworkRequestType type,
     72    UINetworkRequest(UINetworkRequestType enmType,
    7373                     const QList<QUrl> &urls,
    7474                     const UserDictionary &requestHeaders,
     
    118118
    119119    /** Holds the request type. */
    120     const UINetworkRequestType m_type;
     120    const UINetworkRequestType m_enmType;
    121121    /** Holds the request urls. */
    122122    const QList<QUrl> m_urls;
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    22 /* Global includes: */
    23 # include <QTimer>
    24 # include <QStyle>
     22/* Qt includes: */
    2523# include <QGridLayout>
    2624# include <QProgressBar>
    27 
    28 /* Local includes: */
    29 # include "UINetworkRequestWidget.h"
    30 # include "UINetworkRequest.h"
     25# include <QStyle>
     26# include <QTimer>
     27
     28/* GUI includes: */
     29# include "QIRichTextLabel.h"
     30# include "QIToolButton.h"
     31# include "UIIconPool.h"
    3132# include "UINetworkManager.h"
    3233# include "UINetworkManagerDialog.h"
    33 # include "UIIconPool.h"
    34 # include "QIToolButton.h"
    35 # include "QIRichTextLabel.h"
     34# include "UINetworkRequest.h"
     35# include "UINetworkRequestWidget.h"
    3636
    3737#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    125125}
    126126
     127void UINetworkRequestWidget::retranslateUi()
     128{
     129    /* Get corresponding title: */
     130    const QString &strTitle = m_pNetworkRequest->description();
     131
     132    /* Set popup title (default if missed): */
     133    setTitle(strTitle.isEmpty() ? UINetworkManagerDialog::tr("Network Operation") : strTitle);
     134
     135    /* Translate retry button: */
     136    m_pRetryButton->setStatusTip(UINetworkManagerDialog::tr("Restart network operation"));
     137
     138    /* Translate cancel button: */
     139    m_pCancelButton->setStatusTip(UINetworkManagerDialog::tr("Cancel network operation"));
     140
     141    /* Translate error label: */
     142    if (m_pNetworkRequest->reply())
     143        m_pErrorPane->setText(composeErrorText(m_pNetworkRequest->reply()->errorString()));
     144}
     145
    127146void UINetworkRequestWidget::sltSetProgress(qint64 iReceived, qint64 iTotal)
    128147{
     
    186205    /* Set current progress to unknown: */
    187206    m_pProgressBar->setRange(0, 0);
    188 }
    189 
    190 void UINetworkRequestWidget::retranslateUi()
    191 {
    192     /* Get corresponding title: */
    193     const QString &strTitle = m_pNetworkRequest->description();
    194 
    195     /* Set popup title (default if missed): */
    196     setTitle(strTitle.isEmpty() ? UINetworkManagerDialog::tr("Network Operation") : strTitle);
    197 
    198     /* Translate retry button: */
    199     m_pRetryButton->setStatusTip(UINetworkManagerDialog::tr("Restart network operation"));
    200 
    201     /* Translate cancel button: */
    202     m_pCancelButton->setStatusTip(UINetworkManagerDialog::tr("Cancel network operation"));
    203 
    204     /* Translate error label: */
    205     if (m_pNetworkRequest->reply())
    206         m_pErrorPane->setText(composeErrorText(m_pNetworkRequest->reply()->errorString()));
    207207}
    208208
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.h

    r71027 r71466  
    55
    66/*
    7  * Copyright (C) 2011-2017 Oracle Corporation
     7 * Copyright (C) 2011-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UINetworkRequestWidget_h__
    19 #define __UINetworkRequestWidget_h__
     18#ifndef ___UINetworkRequestWidget_h___
     19#define ___UINetworkRequestWidget_h___
    2020
    21 /* Local inludes: */
     21/* GUI inludes: */
    2222#include "QIWithRetranslateUI.h"
    2323#include "UIPopupBox.h"
     
    3333class QTimer;
    3434
    35 /* UIPopupBox reimplementation to reflect network-request status: */
     35/** UIPopupBox reimplementation to reflect network-request status. */
    3636class UINetworkRequestWidget : public QIWithRetranslateUI<UIPopupBox>
    3737{
     
    4040signals:
    4141
    42     /* Signal to retry network-request: */
     42    /** Asks to retry network-request. */
    4343    void sigRetry();
    44     /* Signal to cancel network-request: */
     44    /** Asks to cancel network-request. */
    4545    void sigCancel();
    4646
    4747protected:
    4848
    49     /* Allow creation of UINetworkRequestWidget to UINetworkManagerDialog only: */
     49    /** Allows creation of UINetworkRequestWidget to UINetworkManagerDialog only. */
    5050    friend class UINetworkManagerDialog;
    51     /* Constructor: */
     51    /** Constructs @a pNetworkRequest widget passing @a pParent to the base-class. */
    5252    UINetworkRequestWidget(UINetworkManagerDialog *pParent, UINetworkRequest *pNetworkRequest);
     53
     54    /** Handles translation event. */
     55    virtual void retranslateUi() /* override */;
    5356
    5457private slots:
    5558
    56     /* Updates current network-request progess: */
     59    /** Updates current network-request progess as @a iReceived of @a iTotal. */
    5760    void sltSetProgress(qint64 iReceived, qint64 iTotal);
    5861
    59     /* Set current network-request progress to 'started': */
     62    /** Sets current network-request progress to 'started'. */
    6063    void sltSetProgressToStarted();
    61     /* Set current network-request progress to 'finished': */
     64    /** Sets current network-request progress to 'finished'. */
    6265    void sltSetProgressToFinished();
    63     /* Set current network-request progress to 'failed': */
     66    /** Sets current network-request progress to 'failed' because of @a strError. */
    6467    void sltSetProgressToFailed(const QString &strError);
    6568
    66     /* Handle frozen progress: */
     69    /** Handles frozen progress. */
    6770    void sltTimeIsOut();
    6871
    6972private:
    7073
    71     /* Translation stuff: */
    72     void retranslateUi();
    73 
    7474    /** Composes error text on the basis of the passed @a strErrorText. */
    7575    static const QString composeErrorText(QString strErrorText);
    7676
    77     /* Widgets: */
    78     QWidget *m_pContentWidget;
    79     QGridLayout *m_pMainLayout;
    80     QProgressBar *m_pProgressBar;
    81     QIToolButton *m_pRetryButton;
    82     QIToolButton *m_pCancelButton;
     77    /** Holds the contents widget instance. */
     78    QWidget         *m_pContentWidget;
     79    /** Holds the main layout instance. */
     80    QGridLayout     *m_pMainLayout;
     81    /** Holds the progress-bar instance. */
     82    QProgressBar    *m_pProgressBar;
     83    /** Holds the Retry button instance. */
     84    QIToolButton    *m_pRetryButton;
     85    /** Holds the Cancel button instance. */
     86    QIToolButton    *m_pCancelButton;
     87    /** Holds the error-pane instance. */
    8388    QIRichTextLabel *m_pErrorPane;
    8489
    85     /* Objects: */
     90    /** Holds the network request reference. */
    8691    UINetworkRequest *m_pNetworkRequest;
     92
     93    /** Holds the timeout timer instance. */
    8794    QTimer *m_pTimer;
    8895};
    8996
    90 #endif // __UINetworkRequestWidget_h__
     97#endif /* !___UINetworkRequestWidget_h___ */
    9198
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