Changeset 71466 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 22, 2018 4:39:35 PM (7 years ago)
- 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 5 5 6 6 /* 7 * Copyright (C) 2012-201 7Oracle Corporation7 * Copyright (C) 2012-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 30 30 31 31 32 UINetworkCustomer::UINetworkCustomer() 33 : QObject(0) 34 , m_fForceCall(true) 35 { 36 } 37 38 UINetworkCustomer::UINetworkCustomer(QObject *pParent, bool fForceCall) 32 UINetworkCustomer::UINetworkCustomer(QObject *pParent /* = 0 */, bool fForceCall /* = true */) 39 33 : QObject(pParent) 40 34 , m_fForceCall(fForceCall) … … 42 36 } 43 37 44 void UINetworkCustomer::createNetworkRequest(UINetworkRequestType type, const QList<QUrl> urls,38 void UINetworkCustomer::createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> urls, 45 39 const UserDictionary requestHeaders /* = UserDictionary() */) 46 40 { 47 gNetworkManager->createNetworkRequest( type, urls, requestHeaders, this);41 gNetworkManager->createNetworkRequest(enmType, urls, requestHeaders, this); 48 42 } 49 43 -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkCustomer.h
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2012-201 7Oracle Corporation7 * Copyright (C) 2012-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ UINetworkCustomer_h__19 #define __ UINetworkCustomer_h__18 #ifndef ___UINetworkCustomer_h___ 19 #define ___UINetworkCustomer_h___ 20 20 21 /* Globalincludes: */21 /* Qt includes: */ 22 22 #include <QObject> 23 23 24 /* Localincludes: */24 /* GUI includes: */ 25 25 #include "UINetworkDefs.h" 26 26 … … 29 29 class QUrl; 30 30 31 /* Interface to access UINetworkManager protected functionality:*/31 /** Interface to access UINetworkManager protected functionality. */ 32 32 class UINetworkCustomer : public QObject 33 33 { … … 36 36 public: 37 37 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); 41 41 42 /* Getters:*/42 /** Returns whether this customer has forced privelegies. */ 43 43 bool isItForceCall() const { return m_fForceCall; } 44 44 45 /* Network-reply progress handler:*/45 /** Handles network reply progress for @a iReceived amount of bytes among @a iTotal. */ 46 46 virtual void processNetworkReplyProgress(qint64 iReceived, qint64 iTotal) = 0; 47 /* Network-reply cancel handler:*/47 /** Handles network reply canceling for a passed @a pReply. */ 48 48 virtual void processNetworkReplyCanceled(UINetworkReply *pReply) = 0; 49 /* Network-reply finish handler:*/49 /** Handles network reply finishing for a passed @a pReply. */ 50 50 virtual void processNetworkReplyFinished(UINetworkReply *pReply) = 0; 51 51 … … 56 56 57 57 /** 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, 59 59 const UserDictionary requestHeaders = UserDictionary()); 60 60 61 61 private: 62 62 63 /* Variables:*/63 /** Holds whether this customer has forced privelegies. */ 64 64 bool m_fForceCall; 65 65 }; 66 66 67 #endif / / __UINetworkCustomer_h__67 #endif /* !___UINetworkCustomer_h___ */ 68 68 -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 21 21 22 /* Globalincludes: */22 /* Qt includes: */ 23 23 # include <QWidget> 24 24 # include <QUrl> 25 25 26 /* Local includes: */ 26 /* GUI includes: */ 27 # include "VBoxGlobal.h" 28 # include "UINetworkCustomer.h" 27 29 # include "UINetworkManager.h" 28 30 # include "UINetworkManagerDialog.h" 29 31 # include "UINetworkManagerIndicator.h" 30 32 # include "UINetworkRequest.h" 31 # include "UINetworkCustomer.h"32 # include "VBoxGlobal.h"33 33 34 34 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 35 35 36 36 37 UINetworkManager* UINetworkManager:: m_pInstance = 0;37 UINetworkManager* UINetworkManager::s_pInstance = 0; 38 38 39 39 void UINetworkManager::create() 40 40 { 41 41 /* Check that instance do NOT exist: */ 42 if ( m_pInstance)42 if (s_pInstance) 43 43 return; 44 44 … … 47 47 48 48 /* Prepare instance: */ 49 m_pInstance->prepare();49 s_pInstance->prepare(); 50 50 } 51 51 … … 53 53 { 54 54 /* Check that instance exists: */ 55 if (! m_pInstance)55 if (!s_pInstance) 56 56 return; 57 57 58 58 /* Cleanup instance: */ 59 m_pInstance->cleanup();59 s_pInstance->cleanup(); 60 60 61 61 /* Destroy instance: */ 62 delete m_pInstance;63 } 64 65 UINetworkManagerDialog *UINetworkManager::window() const62 delete s_pInstance; 63 } 64 65 UINetworkManagerDialog *UINetworkManager::window() const 66 66 { 67 67 return m_pNetworkManagerDialog; 68 68 } 69 69 70 UINetworkManagerIndicator *UINetworkManager::createIndicator() const70 UINetworkManagerIndicator *UINetworkManager::createIndicator() const 71 71 { 72 72 /* For Selector UI only: */ … … 108 108 } 109 109 110 void UINetworkManager::createNetworkRequest(UINetworkRequestType type, const QList<QUrl> &urls,110 void UINetworkManager::createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> &urls, 111 111 const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer) 112 112 { 113 113 /* Create network-request: */ 114 UINetworkRequest *pNetworkRequest = new UINetworkRequest( type, urls, requestHeaders, pCustomer, this);114 UINetworkRequest *pNetworkRequest = new UINetworkRequest(enmType, urls, requestHeaders, pCustomer, this); 115 115 /* Prepare created network-request: */ 116 116 prepareNetworkRequest(pNetworkRequest); … … 121 121 { 122 122 /* Prepare instance: */ 123 m_pInstance = this;123 s_pInstance = this; 124 124 } 125 125 … … 127 127 { 128 128 /* Cleanup instance: */ 129 m_pInstance = 0;129 s_pInstance = 0; 130 130 } 131 131 -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ UINetworkManager_h__19 #define __ UINetworkManager_h__18 #ifndef ___UINetworkManager_h___ 19 #define ___UINetworkManager_h___ 20 20 21 21 /* Qt includes: */ … … 23 23 #include <QUuid> 24 24 25 /* Localinludes: */25 /* GUI inludes: */ 26 26 #include "UINetworkDefs.h" 27 27 … … 29 29 class QUrl; 30 30 class QWidget; 31 class UINetworkRequest;32 31 class UINetworkCustomer; 33 32 class UINetworkManagerDialog; 34 33 class UINetworkManagerIndicator; 34 class UINetworkRequest; 35 35 36 /* QObject class reimplementation.37 * Providing network access for VirtualBox application purposes. */36 /** QObject class extension. 37 * Providing network access for VirtualBox application purposes. */ 38 38 class UINetworkManager : public QObject 39 39 { … … 42 42 signals: 43 43 44 /* Ask listeners (network-requests) to cancel:*/44 /** Asks listeners (network-requests) to cancel. */ 45 45 void sigCancelNetworkRequests(); 46 46 … … 52 52 public: 53 53 54 /* Instance: */ 55 static UINetworkManager* instance() { return m_pInstance; } 56 57 /* Create/destroy singleton: */ 54 /** Creates singleton instance. */ 58 55 static void create(); 56 /** Destroys singleton instance. */ 59 57 static void destroy(); 60 58 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; 63 64 64 65 /** Creates network-manager state-indicator. 65 66 * @remarks To be cleaned up by the caller. */ 66 UINetworkManagerIndicator *createIndicator() const;67 UINetworkManagerIndicator *createIndicator() const; 67 68 68 69 /** Registers @a pNetworkRequest in network-manager. */ … … 73 74 public slots: 74 75 75 /* Show network-manager dialog:*/76 /** Shows network-manager dialog. */ 76 77 void show(); 77 78 78 79 protected: 79 80 80 /* Allow UINetworkCustomer to create network-request:*/81 /** Allows UINetworkCustomer to create network-request. */ 81 82 friend class UINetworkCustomer; 83 82 84 /** Creates network-request of the passed @a type 83 85 * 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, 85 87 const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer); 86 88 87 89 private: 88 90 89 /* Constructor/destructor:*/91 /** Constructs network manager. */ 90 92 UINetworkManager(); 93 /** Destructs network manager. */ 91 94 ~UINetworkManager(); 92 95 93 /* Prepare/cleanup:*/96 /** Prepares all. */ 94 97 void prepare(); 98 /** Cleanups all. */ 95 99 void cleanup(); 96 100 97 /* Network-request prepare helper:*/101 /** Prepares @a pNetworkRequest. */ 98 102 void prepareNetworkRequest(UINetworkRequest *pNetworkRequest); 99 /* Network-request cleanup helper:*/103 /** Cleanups network-request with passed @a uuid. */ 100 104 void cleanupNetworkRequest(QUuid uuid); 101 /* Network-requests cleanup helper:*/105 /** Cleanups all network-requests. */ 102 106 void cleanupNetworkRequests(); 103 107 104 108 private slots: 105 109 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. */ 107 111 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. */ 109 113 void sltHandleNetworkRequestCancel(const QUuid &uuid); 110 /* Slot to handle network-request finish:*/114 /** Handles finishing of request specified by @a uuid. */ 111 115 void sltHandleNetworkRequestFinish(const QUuid &uuid); 112 /* Slot to handle network-request failure:*/116 /** Handles @a strError of request specified by @a uuid. */ 113 117 void sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &strError); 114 118 115 119 private: 116 120 117 /* Instance:*/118 static UINetworkManager * m_pInstance;121 /** Holds the singleton instance. */ 122 static UINetworkManager *s_pInstance; 119 123 120 /* Network-request map:*/124 /** Holds the map of current requests. */ 121 125 QMap<QUuid, UINetworkRequest*> m_requests; 122 126 123 /* Network-manager dialog:*/127 /** Holds the network manager dialog instance. */ 124 128 UINetworkManagerDialog *m_pNetworkManagerDialog; 125 129 }; 130 131 /** Singleton Network Manager 'official' name. */ 126 132 #define gNetworkManager UINetworkManager::instance() 127 133 128 #endif / / __UINetworkManager_h__134 #endif /* !___UINetworkManager_h___ */ 129 135 -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.cpp
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 21 21 22 /* Globalincludes: */22 /* Qt includes: */ 23 23 # include <QVBoxLayout> 24 24 # include <QLabel> … … 27 27 # include <QKeyEvent> 28 28 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" 30 37 # include "UINetworkManagerDialog.h" 31 # include "UINetworkManager.h"32 38 # include "UINetworkRequest.h" 33 39 # 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"40 40 41 41 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.h
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ UINetworkManagerDialog_h__19 #define __ UINetworkManagerDialog_h__18 #ifndef ___UINetworkManagerDialog_h___ 19 #define ___UINetworkManagerDialog_h___ 20 20 21 /* Globalincludes: */21 /* Qt includes: */ 22 22 #include <QMainWindow> 23 23 #include <QMap> 24 24 #include <QUuid> 25 25 26 /* Localincludes: */26 /* GUI includes: */ 27 27 #include "QIWithRetranslateUI.h" 28 28 29 29 /* Forward declarations: */ 30 class QLabel; 31 class QUuid; 32 class QVBoxLayout; 33 class QIDialogButtonBox; 30 34 class UINetworkRequest; 31 class QVBoxLayout;32 class QLabel;33 class QIDialogButtonBox;34 35 class UINetworkRequestWidget; 35 36 36 /* QMainWindow reimplementation to reflect network-requests:*/37 /** QMainWindow reimplementation to reflect network-requests. */ 37 38 class UINetworkManagerDialog : public QIWithRetranslateUI<QMainWindow> 38 39 { … … 41 42 signals: 42 43 43 /* Ask listener (network-manager) to cancel all network-requests:*/44 /** Asks listener (network-manager) to cancel all network-requests. */ 44 45 void sigCancelNetworkRequests(); 45 46 46 47 public slots: 47 48 48 /* Show the dialog, make sure its visible:*/49 /** Shows the dialog, make sure its visible. */ 49 50 void showNormal(); 50 51 51 52 protected: 52 53 53 /* Allow creation of UINetworkManagerDialog to UINetworkManager:*/54 /** Allows creation of UINetworkManagerDialog to UINetworkManager. */ 54 55 friend class UINetworkManager; 55 /* Constructor:*/56 /** Constructs Network Manager Dialog. */ 56 57 UINetworkManagerDialog(); 57 58 58 /* Allow adding/removing network-request widgets to UINetworkRequest:*/59 /** Allows adding/removing network-request widgets to UINetworkRequest. */ 59 60 friend class UINetworkRequest; 60 /* Add network-request widget:*/61 /** Adds network-request widget. */ 61 62 void addNetworkRequestWidget(UINetworkRequest *pNetworkRequest); 62 /* Remove network-request widget:*/63 /** Removes network-request widget. */ 63 64 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 */; 64 74 65 75 private slots: 66 76 67 /* Handler for 'Cancel All' button-press:*/77 /** Handles 'Cancel All' button-press. */ 68 78 void sltHandleCancelAllButtonPress(); 69 79 70 80 private: 71 81 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; 84 90 }; 85 91 86 #endif / / __UINetworkManagerDialog_h__92 #endif /* !___UINetworkManagerDialog_h___ */ 87 93 -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerIndicator.cpp
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2012-201 7Oracle Corporation7 * Copyright (C) 2012-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 22 22 /* GUI includes: */ 23 # include "VBoxGlobal.h" 24 # include "UIIconPool.h" 23 25 # include "UINetworkManagerIndicator.h" 24 26 # include "UINetworkRequest.h" 25 # include "UIIconPool.h"26 # include "VBoxGlobal.h"27 27 28 28 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 38 38 /* Translate content: */ 39 39 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 else168 {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 else187 {188 /* Set state to 'loading': */189 setState(UINetworkManagerIndicatorState_Loading);190 }191 }192 193 /* Update appearance finally: */194 updateAppearance();195 40 } 196 41 … … 242 87 } 243 88 89 void 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 116 void 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 132 void UINetworkManagerIndicator::retranslateUi() 133 { 134 /* Update appearance: */ 135 updateAppearance(); 136 } 137 138 void 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 155 void 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 165 void 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 180 void 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 190 void 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 206 void 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 5 5 6 6 /* 7 * Copyright (C) 2012-201 7Oracle Corporation7 * Copyright (C) 2012-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ UINetworkManagerIndicator_h__19 #define __ UINetworkManagerIndicator_h__18 #ifndef ___UINetworkManagerIndicator_h___ 19 #define ___UINetworkManagerIndicator_h___ 20 20 21 /* Globalincludes: */21 /* Qt includes: */ 22 22 #include <QVector> 23 23 #include <QUuid> 24 24 25 /* Localincludes: */25 /* GUI includes: */ 26 26 #include "QIStatusBarIndicator.h" 27 #include "QIWithRetranslateUI.h" 27 28 28 29 /* Forward declarations: */ 29 30 class UINetworkRequest; 30 31 31 /* Network-manager status-bar indicator states: */ 32 33 /** Network-manager status-bar indicator states. */ 32 34 enum UINetworkManagerIndicatorState 33 35 { … … 37 39 }; 38 40 39 /* Network-manager status-bar indicator: */ 40 class UINetworkManagerIndicator : public QIStateStatusBarIndicator 41 42 /** QIStateStatusBarIndicator extension for network-manager indicator. */ 43 class UINetworkManagerIndicator : public QIWithRetranslateUI<QIStateStatusBarIndicator> 41 44 { 42 45 Q_OBJECT; … … 44 47 public: 45 48 46 /* Constructor:*/49 /** Constructs network manager indicator. */ 47 50 UINetworkManagerIndicator(); 48 51 49 /** Update routine. */52 /** Updates appearance. */ 50 53 void updateAppearance(); 51 54 … … 57 60 void sldRemoveNetworkManagerIndicatorDescription(const QUuid &uuid); 58 61 62 protected: 63 64 /** Handles translation event. */ 65 virtual void retranslateUi() /* override */; 66 59 67 private slots: 60 68 61 /* Set particular network-request progress to 'started':*/69 /** Sets particular network-request @a uuid progress to 'started'. */ 62 70 void sltSetProgressToStarted(const QUuid &uuid); 63 /* Set particular network-request progress to 'canceled':*/71 /** Sets particular network-request @a uuid progress to 'canceled'. */ 64 72 void sltSetProgressToCanceled(const QUuid &uuid); 65 /* Set particular network-request progress to 'failed':*/73 /** Sets particular network-request @a uuid progress to 'failed'. */ 66 74 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'. */ 68 76 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. */ 70 78 void sltSetProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal); 71 79 72 80 private: 73 81 82 /** Network request data. */ 74 83 struct UINetworkRequestData 75 84 { 85 /** Constructs network request data. */ 76 86 UINetworkRequestData() 77 87 : bytesReceived(0), bytesTotal(0), failed(false) {} 88 /** Constructs network request data with @a strDescription, @a iBytesReceived and @a iBytesTotal. */ 78 89 UINetworkRequestData(const QString &strDescription, int iBytesReceived, int iBytesTotal) 79 90 : description(strDescription), bytesReceived(iBytesReceived), bytesTotal(iBytesTotal), failed(false) {} 91 /** Holds the description. */ 80 92 QString description; 93 /** Holds the amount of bytes received. */ 81 94 int bytesReceived; 95 /** Holds the amount of total bytes. */ 82 96 int bytesTotal; 97 /** Holds whether request is failed. */ 83 98 bool failed; 84 99 }; 85 100 86 /* Translate stuff: */ 87 void retranslateUi(); 88 89 /* Update stuff: */ 101 /** Update stuff. */ 90 102 void recalculateIndicatorState(); 91 103 92 /* Variables:*/104 /** Holds the vector of network request IDs. */ 93 105 QVector<QUuid> m_ids; 106 /** Holds the vector of network request data. */ 94 107 QVector<UINetworkRequestData> m_data; 95 108 }; 96 109 97 #endif // __UINetworkManagerIndicator_h__98 110 111 #endif /* !___UINetworkManagerIndicator_h___ */ 112 -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2012-201 7Oracle Corporation7 * Copyright (C) 2012-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.h
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2012-201 7Oracle Corporation7 * Copyright (C) 2012-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 31 31 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 32 32 33 UINetworkRequest::UINetworkRequest(UINetworkRequestType type,33 UINetworkRequest::UINetworkRequest(UINetworkRequestType enmType, 34 34 const QList<QUrl> &urls, 35 35 const UserDictionary &requestHeaders, … … 37 37 UINetworkManager *pNetworkManager) 38 38 : QObject(pNetworkManager) 39 , m_ type(type)39 , m_enmType(enmType) 40 40 , m_urls(urls) 41 41 , m_requestHeaders(requestHeaders) … … 197 197 { 198 198 /* 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); 200 200 AssertPtrReturnVoid(m_pReply.data()); 201 201 { -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.h
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 67 67 public: 68 68 69 /** Constructs network-request of the passed @a type69 /** Constructs network-request of the passed @a enmType 70 70 * on the basis of the passed @a urls and the @a requestHeaders 71 71 * for the @a pCustomer and @a pNetworkManager specified. */ 72 UINetworkRequest(UINetworkRequestType type,72 UINetworkRequest(UINetworkRequestType enmType, 73 73 const QList<QUrl> &urls, 74 74 const UserDictionary &requestHeaders, … … 118 118 119 119 /** Holds the request type. */ 120 const UINetworkRequestType m_ type;120 const UINetworkRequestType m_enmType; 121 121 /** Holds the request urls. */ 122 122 const QList<QUrl> m_urls; -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 21 21 22 /* Global includes: */ 23 # include <QTimer> 24 # include <QStyle> 22 /* Qt includes: */ 25 23 # include <QGridLayout> 26 24 # 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" 31 32 # include "UINetworkManager.h" 32 33 # include "UINetworkManagerDialog.h" 33 # include "UIIconPool.h" 34 # include "QIToolButton.h" 35 # include "QIRichTextLabel.h" 34 # include "UINetworkRequest.h" 35 # include "UINetworkRequestWidget.h" 36 36 37 37 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 125 125 } 126 126 127 void 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 127 146 void UINetworkRequestWidget::sltSetProgress(qint64 iReceived, qint64 iTotal) 128 147 { … … 186 205 /* Set current progress to unknown: */ 187 206 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()));207 207 } 208 208 -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.h
r71027 r71466 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ UINetworkRequestWidget_h__19 #define __ UINetworkRequestWidget_h__18 #ifndef ___UINetworkRequestWidget_h___ 19 #define ___UINetworkRequestWidget_h___ 20 20 21 /* Localinludes: */21 /* GUI inludes: */ 22 22 #include "QIWithRetranslateUI.h" 23 23 #include "UIPopupBox.h" … … 33 33 class QTimer; 34 34 35 /* UIPopupBox reimplementation to reflect network-request status:*/35 /** UIPopupBox reimplementation to reflect network-request status. */ 36 36 class UINetworkRequestWidget : public QIWithRetranslateUI<UIPopupBox> 37 37 { … … 40 40 signals: 41 41 42 /* Signal to retry network-request:*/42 /** Asks to retry network-request. */ 43 43 void sigRetry(); 44 /* Signal to cancel network-request:*/44 /** Asks to cancel network-request. */ 45 45 void sigCancel(); 46 46 47 47 protected: 48 48 49 /* Allow creation of UINetworkRequestWidget to UINetworkManagerDialog only:*/49 /** Allows creation of UINetworkRequestWidget to UINetworkManagerDialog only. */ 50 50 friend class UINetworkManagerDialog; 51 /* Constructor:*/51 /** Constructs @a pNetworkRequest widget passing @a pParent to the base-class. */ 52 52 UINetworkRequestWidget(UINetworkManagerDialog *pParent, UINetworkRequest *pNetworkRequest); 53 54 /** Handles translation event. */ 55 virtual void retranslateUi() /* override */; 53 56 54 57 private slots: 55 58 56 /* Updates current network-request progess:*/59 /** Updates current network-request progess as @a iReceived of @a iTotal. */ 57 60 void sltSetProgress(qint64 iReceived, qint64 iTotal); 58 61 59 /* Set current network-request progress to 'started':*/62 /** Sets current network-request progress to 'started'. */ 60 63 void sltSetProgressToStarted(); 61 /* Set current network-request progress to 'finished':*/64 /** Sets current network-request progress to 'finished'. */ 62 65 void sltSetProgressToFinished(); 63 /* Set current network-request progress to 'failed':*/66 /** Sets current network-request progress to 'failed' because of @a strError. */ 64 67 void sltSetProgressToFailed(const QString &strError); 65 68 66 /* Handle frozen progress:*/69 /** Handles frozen progress. */ 67 70 void sltTimeIsOut(); 68 71 69 72 private: 70 73 71 /* Translation stuff: */72 void retranslateUi();73 74 74 /** Composes error text on the basis of the passed @a strErrorText. */ 75 75 static const QString composeErrorText(QString strErrorText); 76 76 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. */ 83 88 QIRichTextLabel *m_pErrorPane; 84 89 85 /* Objects:*/90 /** Holds the network request reference. */ 86 91 UINetworkRequest *m_pNetworkRequest; 92 93 /** Holds the timeout timer instance. */ 87 94 QTimer *m_pTimer; 88 95 }; 89 96 90 #endif / / __UINetworkRequestWidget_h__97 #endif /* !___UINetworkRequestWidget_h___ */ 91 98
Note:
See TracChangeset
for help on using the changeset viewer.