VirtualBox

Changeset 41440 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 24, 2012 4:37:17 PM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: Network Manager stuff: Moving classes into separate files.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited
6 copied

Legend:

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

    r41387 r41440  
    272272        src/globals/VBoxGlobal.h \
    273273        src/globals/VBoxUtils.h \
     274        src/net/UINetworkManager.h \
     275        src/net/UINetworkManagerDialog.h \
     276        src/net/UINetworkRequest.h \
     277        src/net/UINetworkRequestWidget.h \
     278        src/net/UINetworkCustomer.h \
     279        src/net/UIUpdateManager.h \
    274280        src/net/UIDownloader.h \
    275281        src/net/UIDownloaderAdditions.h \
    276282        src/net/UIDownloaderExtensionPack.h \
    277283        src/net/UIDownloaderUserManual.h \
    278         src/net/UINetworkManager.h \
    279         src/net/UIUpdateManager.h \
    280         src/net/UINetworkCustomer.h \
    281284        src/runtime/UIActionPoolRuntime.h \
    282285        src/runtime/UIConsoleEventHandler.h \
     
    404407        src/globals/UIActionPool.cpp \
    405408        src/globals/UIExtraDataEventHandler.cpp \
    406         src/net/UINetworkManager.cpp \
    407409        src/net/UIUpdateManager.cpp \
    408410        src/runtime/UIActionPoolRuntime.cpp \
     
    471473        src/globals/VBoxGlobal.cpp \
    472474        src/main.cpp \
     475        src/net/UINetworkManager.cpp \
     476        src/net/UINetworkManagerDialog.cpp \
     477        src/net/UINetworkRequest.cpp \
     478        src/net/UINetworkRequestWidget.cpp \
     479        src/net/UINetworkCustomer.cpp \
    473480        src/net/UIDownloader.cpp \
    474481        src/net/UIDownloaderAdditions.cpp \
    475482        src/net/UIDownloaderExtensionPack.cpp \
    476483        src/net/UIDownloaderUserManual.cpp \
    477         src/net/UINetworkManager.cpp \
    478484        src/net/UIUpdateDefs.cpp \
    479485        src/net/UIUpdateManager.cpp \
    480         src/net/UINetworkCustomer.cpp \
    481486        src/runtime/UIActionPoolRuntime.cpp \
    482487        src/runtime/UIConsoleEventHandler.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp

    r41433 r41440  
    2020/* Global includes: */
    2121#include <QWidget>
    22 #include <QTimer>
    23 #include <QGridLayout>
    24 #include <QProgressBar>
    25 #include <QMainWindow>
    26 #include <QVBoxLayout>
    27 #include <QLabel>
    28 #include <QPushButton>
    29 #include <QStatusBar>
    30 #include <QKeyEvent>
    31 #include <QNetworkReply>
    3222
    3323/* Local includes: */
    3424#include "UINetworkManager.h"
     25#include "UINetworkManagerDialog.h"
     26#include "UINetworkRequest.h"
    3527#include "UINetworkCustomer.h"
    36 #include "QIWithRetranslateUI.h"
    3728#include "VBoxGlobal.h"
    38 #include "UIMessageCenter.h"
    39 #include "UIIconPool.h"
    40 #include "QIDialogButtonBox.h"
    41 #include "UIPopupBox.h"
    42 #include "QIToolButton.h"
    43 #include "QIRichTextLabel.h"
    44 
    45 /* Network-request widget: */
    46 class UINetworkRequestWidget : public QIWithRetranslateUI<UIPopupBox>
    47 {
    48     Q_OBJECT;
    49 
    50 signals:
    51 
    52     /* Signal to retry network-request: */
    53     void sigRetry();
    54     /* Signal to cancel network-request: */
    55     void sigCancel();
    56 
    57 public:
    58 
    59     /* Constructor: */
    60     UINetworkRequestWidget(QMainWindow *pParent, UINetworkRequest *pNetworkRequest)
    61         : QIWithRetranslateUI<UIPopupBox>(pParent)
    62         , m_pNetworkRequest(pNetworkRequest)
    63         , m_pTimer(new QTimer(this))
    64         , m_pContentWidget(new QWidget(this))
    65         , m_pMainLayout(new QGridLayout(m_pContentWidget))
    66         , m_pProgressBar(new QProgressBar(m_pContentWidget))
    67         , m_pRetryButton(new QIToolButton(m_pContentWidget))
    68         , m_pCancelButton(new QIToolButton(m_pContentWidget))
    69         , m_pErrorPane(new QIRichTextLabel(m_pContentWidget))
    70     {
    71         /* Setup self: */
    72         setTitleIcon(UIIconPool::iconSet(":/nw_16px.png"));
    73         setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    74         setContentWidget(m_pContentWidget);
    75         setOpen(true);
    76 
    77         /* Prepare listeners for m_pNetworkRequest: */
    78         connect(m_pNetworkRequest, SIGNAL(sigProgress(qint64, qint64)), this, SLOT(sltSetProgress(qint64, qint64)));
    79         connect(m_pNetworkRequest, SIGNAL(sigStarted()), this, SLOT(sltSetProgressToStarted()));
    80         connect(m_pNetworkRequest, SIGNAL(sigFinished()), this, SLOT(sltSetProgressToFinished()));
    81         connect(m_pNetworkRequest, SIGNAL(sigFailed(const QString&)), this, SLOT(sltSetProgressToFailed(const QString&)));
    82 
    83         /* Setup timer: */
    84         m_pTimer->setInterval(5000);
    85         connect(m_pTimer, SIGNAL(timeout()), this, SLOT(sltTimeIsOut()));
    86 
    87         /* Setup main-layout: */
    88         m_pMainLayout->setContentsMargins(6, 6, 6, 6);
    89 
    90         /* Setup progress-bar: */
    91         m_pProgressBar->setRange(0, 0);
    92         m_pProgressBar->setMaximumHeight(16);
    93 
    94         /* Setup retry-button: */
    95         m_pRetryButton->setHidden(true);
    96         m_pRetryButton->removeBorder();
    97         m_pRetryButton->setFocusPolicy(Qt::NoFocus);
    98         m_pRetryButton->setIcon(UIIconPool::iconSet(":/refresh_16px.png"));
    99         connect(m_pRetryButton, SIGNAL(clicked(bool)), this, SIGNAL(sigRetry()));
    100 
    101         /* Setup cancel-button: */
    102         m_pCancelButton->removeBorder();
    103         m_pCancelButton->setFocusPolicy(Qt::NoFocus);
    104         m_pCancelButton->setIcon(UIIconPool::iconSet(":/delete_16px.png"));
    105         connect(m_pCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(sigCancel()));
    106 
    107         /* Setup error-label: */
    108         m_pErrorPane->setHidden(true);
    109         m_pErrorPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    110         /* Calculate required width: */
    111         int iMinimumWidth = pParent->minimumWidth();
    112         int iLeft, iTop, iRight, iBottom;
    113         /* Take into account content-widget layout margins: */
    114         m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    115         iMinimumWidth -= iLeft;
    116         iMinimumWidth -= iRight;
    117         /* Take into account this layout margins: */
    118         layout()->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    119         iMinimumWidth -= iLeft;
    120         iMinimumWidth -= iRight;
    121         /* Take into account parent layout margins: */
    122         QLayout *pParentLayout = qobject_cast<QMainWindow*>(parent())->centralWidget()->layout();
    123         pParentLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    124         iMinimumWidth -= iLeft;
    125         iMinimumWidth -= iRight;
    126         /* Set minimum text width: */
    127         m_pErrorPane->setMinimumTextWidth(iMinimumWidth);
    128 
    129         /* Layout content: */
    130         m_pMainLayout->addWidget(m_pProgressBar, 0, 0);
    131         m_pMainLayout->addWidget(m_pRetryButton, 0, 1);
    132         m_pMainLayout->addWidget(m_pCancelButton, 0, 2);
    133         m_pMainLayout->addWidget(m_pErrorPane, 1, 0, 1, 3);
    134 
    135         /* Retranslate UI: */
    136         retranslateUi();
    137     }
    138 
    139 private slots:
    140 
    141     /* Retranslate UI: */
    142     void retranslateUi()
    143     {
    144         /* Get corresponding title: */
    145         const QString &strTitle = m_pNetworkRequest->description();
    146 
    147         /* Set popup title (default if missed): */
    148         setTitle(strTitle.isEmpty() ? UINetworkManager::tr("Network Operation") : strTitle);
    149 
    150         /* Translate retry button: */
    151         m_pRetryButton->setStatusTip(UINetworkManager::tr("Restart network operation"));
    152 
    153         /* Translate cancel button: */
    154         m_pCancelButton->setStatusTip(UINetworkManager::tr("Cancel network operation"));
    155     }
    156 
    157     /* Updates current network-request progess: */
    158     void sltSetProgress(qint64 iReceived, qint64 iTotal)
    159     {
    160         /* Restart timer: */
    161         m_pTimer->start();
    162 
    163         /* Set current progress to passed: */
    164         m_pProgressBar->setRange(0, iTotal);
    165         m_pProgressBar->setValue(iReceived);
    166     }
    167 
    168     /* Set current network-request progress to 'started': */
    169     void sltSetProgressToStarted()
    170     {
    171         /* Start timer: */
    172         m_pTimer->start();
    173 
    174         /* Set current progress to 'started': */
    175         m_pProgressBar->setRange(0, 1);
    176         m_pProgressBar->setValue(0);
    177 
    178         /* Hide 'retry' button: */
    179         m_pRetryButton->setHidden(true);
    180 
    181         /* Hide error label: */
    182         m_pErrorPane->setHidden(true);
    183         m_pErrorPane->setText(QString());
    184     }
    185 
    186     /* Set current network-request progress to 'finished': */
    187     void sltSetProgressToFinished()
    188     {
    189         /* Stop timer: */
    190         m_pTimer->stop();
    191 
    192         /* Set current progress to 'started': */
    193         m_pProgressBar->setRange(0, 1);
    194         m_pProgressBar->setValue(1);
    195     }
    196 
    197     /* Set current network-request progress to 'failed': */
    198     void sltSetProgressToFailed(const QString &strError)
    199     {
    200         /* Stop timer: */
    201         m_pTimer->stop();
    202 
    203         /* Set current progress to 'failed': */
    204         m_pProgressBar->setRange(0, 1);
    205         m_pProgressBar->setValue(1);
    206 
    207         /* Show 'retry' button: */
    208         m_pRetryButton->setHidden(false);
    209 
    210         /* Try to find all the links in the error-message,
    211          * replace them with %increment if present: */
    212         QString strErrorText(strError);
    213         QRegExp linkRegExp("[\\S]+[\\./][\\S]+");
    214         QStringList links;
    215         for (int i = 1; linkRegExp.indexIn(strErrorText) != -1; ++i)
    216         {
    217             links << linkRegExp.cap();
    218             strErrorText.replace(linkRegExp.cap(), QString("%%1").arg(i));
    219         }
    220         /* Return back all the links, just in bold: */
    221         if (!links.isEmpty())
    222             for (int i = 0; i < links.size(); ++i)
    223                 strErrorText = strErrorText.arg(QString("<b>%1</b>").arg(links[i]));
    224 
    225         /* Show error label: */
    226         m_pErrorPane->setHidden(false);
    227         m_pErrorPane->setText(UINetworkManager::tr("Error: %1.").arg(strErrorText));
    228     }
    229 
    230     /* Handle frozen progress: */
    231     void sltTimeIsOut()
    232     {
    233         /* Stop timer: */
    234         m_pTimer->stop();
    235 
    236         /* Set current progress to unknown: */
    237         m_pProgressBar->setRange(0, 0);
    238     }
    239 
    240 private:
    241 
    242     /* Objects: */
    243     UINetworkRequest *m_pNetworkRequest;
    244     QTimer *m_pTimer;
    245 
    246     /* Widgets: */
    247     QWidget *m_pContentWidget;
    248     QGridLayout *m_pMainLayout;
    249     QProgressBar *m_pProgressBar;
    250     QIToolButton *m_pRetryButton;
    251     QIToolButton *m_pCancelButton;
    252     QIRichTextLabel *m_pErrorPane;
    253 };
    254 
    255 /* Network requests dialog: */
    256 class UINetworkManagerDialog : public QIWithRetranslateUI<QMainWindow>
    257 {
    258     Q_OBJECT;
    259 
    260 signals:
    261 
    262     /* Signal to cancel all network-requests: */
    263     void sigCancelNetworkRequests();
    264 
    265 public slots:
    266 
    267     /* Show the dialog, make sure its visible: */
    268     void showNormal()
    269     {
    270         /* Show (restore if neessary): */
    271         QMainWindow::showNormal();
    272 
    273         /* Raise above the others: */
    274         raise();
    275 
    276         /* Activate: */
    277         activateWindow();
    278     }
    279 
    280 public:
    281 
    282     /* Constructor: */
    283     UINetworkManagerDialog()
    284     {
    285         /* Do not count that window as important for application,
    286          * it will NOT be taken into account when other top-level windows will be closed: */
    287         setAttribute(Qt::WA_QuitOnClose, false);
    288 
    289         /* Set minimum width: */
    290         setMinimumWidth(500);
    291 
    292         /* Prepare central-widget: */
    293         setCentralWidget(new QWidget);
    294 
    295         /* Create main-layout: */
    296         m_pMainLayout = new QVBoxLayout(centralWidget());
    297         m_pMainLayout->setContentsMargins(6, 6, 6, 6);
    298 
    299         /* Create description-label: */
    300         m_pLabel = new QLabel(centralWidget());
    301         m_pLabel->setAlignment(Qt::AlignCenter);
    302         m_pLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    303 
    304         /* Create button-box: */
    305         m_pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, centralWidget());
    306         connect(m_pButtonBox, SIGNAL(rejected()), this, SLOT(sltHandleCancelAllButtonPress()));
    307         m_pButtonBox->setHidden(true);
    308 
    309         /* Layout content: */
    310         m_pMainLayout->addWidget(m_pLabel);
    311         m_pMainLayout->addStretch();
    312         m_pMainLayout->addWidget(m_pButtonBox);
    313 
    314         /* Create status-bar: */
    315         setStatusBar(new QStatusBar);
    316 
    317         /* Translate dialog: */
    318         retranslateUi();
    319     }
    320 
    321     /* Add network-request widget: */
    322     UINetworkRequestWidget* addNetworkRequestWidget(UINetworkRequest *pNetworkRequest)
    323     {
    324         /* Make sure network-request is really exists: */
    325         AssertMsg(pNetworkRequest, ("Network-request doesn't exists!\n"));
    326 
    327         /* Create new network-request widget: */
    328         UINetworkRequestWidget *pNetworkRequestWidget = new UINetworkRequestWidget(this, pNetworkRequest);
    329         m_pMainLayout->insertWidget(m_pMainLayout->count() - 2 /* before button-box and stretch */, pNetworkRequestWidget);
    330         m_widgets.insert(pNetworkRequest->uuid(), pNetworkRequestWidget);
    331 
    332         /* Hide label: */
    333         m_pLabel->setHidden(true);
    334         /* Show button-box: */
    335         m_pButtonBox->setHidden(false);
    336         /* If customer made a force-call: */
    337         if (pNetworkRequest->customer()->isItForceCall())
    338         {
    339             /* Show dialog: */
    340             showNormal();
    341         }
    342 
    343         /* Return network-request widget: */
    344         return pNetworkRequestWidget;
    345     }
    346 
    347     /* Remove network-request widget: */
    348     void removeNetworkRequestWidget(const QUuid &uuid)
    349     {
    350         /* Make sure network-request widget still present: */
    351         AssertMsg(m_widgets.contains(uuid), ("Network-request widget already removed!\n"));
    352 
    353         /* Delete corresponding network-request widget: */
    354         delete m_widgets.value(uuid);
    355         m_widgets.remove(uuid);
    356 
    357         /* Check if dialog is empty: */
    358         if (m_widgets.isEmpty())
    359         {
    360             /* Show label: */
    361             m_pLabel->setHidden(false);
    362             /* Hide button-box: */
    363             m_pButtonBox->setHidden(true);
    364             /* Let central-widget update its layout before being hidden: */
    365             QCoreApplication::sendPostedEvents(centralWidget(), QEvent::LayoutRequest);
    366             /* Hide dialog: */
    367             hide();
    368         }
    369     }
    370 
    371 private slots:
    372 
    373     /* Handler for 'Cancel All' button press: */
    374     void sltHandleCancelAllButtonPress()
    375     {
    376         /* Ask if user wants to cancel all current network-requests: */
    377         if (msgCenter().askAboutCancelAllNetworkRequest(this))
    378             emit sigCancelNetworkRequests();
    379     }
    380 
    381 private:
    382 
    383     /* Translate whole dialog: */
    384     void retranslateUi()
    385     {
    386         /* Set window caption: */
    387         setWindowTitle(UINetworkManager::tr("Network Operations Manager"));
    388 
    389         /* Set description-label text: */
    390         m_pLabel->setText(UINetworkManager::tr("There are no active network operations."));
    391 
    392         /* Set buttons-box text: */
    393         m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("&Cancel All"));
    394         m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Cancel all active network operations"));
    395     }
    396 
    397     /* Overloaded show-event: */
    398     void showEvent(QShowEvent *pShowEvent)
    399     {
    400         /* Resize to minimum size-hint: */
    401         resize(minimumSizeHint());
    402 
    403         /* Center according current main application window: */
    404         vboxGlobal().centerWidget(this, vboxGlobal().mainWindow(), false);
    405 
    406         /* Pass event to the base-class: */
    407         QMainWindow::showEvent(pShowEvent);
    408     }
    409 
    410     /* Overloaded keypress-event: */
    411     void keyPressEvent(QKeyEvent *pKeyPressEvent)
    412     {
    413         /* 'Escape' key used to close the dialog: */
    414         if (pKeyPressEvent->key() == Qt::Key_Escape)
    415         {
    416             close();
    417             return;
    418         }
    419 
    420         /* Pass event to the base-class: */
    421         QMainWindow::keyPressEvent(pKeyPressEvent);
    422     }
    423 
    424     /* Main layout: */
    425     QVBoxLayout *m_pMainLayout;
    426     QLabel *m_pLabel;
    427     QIDialogButtonBox *m_pButtonBox;
    428 
    429     /* Popup-widget map: */
    430     QMap<QUuid, UINetworkRequestWidget*> m_widgets;
    431 };
    432 
    433 /* Constructor: */
    434 UINetworkRequest::UINetworkRequest(UINetworkManager *pNetworkManager,
    435                                    UINetworkManagerDialog *pNetworkManagerDialog,
    436                                    const QNetworkRequest &request, UINetworkRequestType type,
    437                                    const QString &strDescription, UINetworkCustomer *pCustomer)
    438     : QObject(pNetworkManager)
    439     , m_pNetworkManagerDialog(pNetworkManagerDialog)
    440     , m_pNetworkRequestWidget(0)
    441     , m_uuid(QUuid::createUuid())
    442     , m_requests(QList<QNetworkRequest>() << request)
    443     , m_iCurrentRequestIndex(0)
    444     , m_type(type)
    445     , m_strDescription(strDescription)
    446     , m_pCustomer(pCustomer)
    447     , m_fRunning(false)
    448 {
    449     /* Initialize: */
    450     initialize();
    451 }
    452 
    453 UINetworkRequest::UINetworkRequest(UINetworkManager *pNetworkManager,
    454                                    UINetworkManagerDialog *pNetworkManagerDialog,
    455                                    const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    456                                    const QString &strDescription, UINetworkCustomer *pCustomer)
    457     : QObject(pNetworkManager)
    458     , m_pNetworkManagerDialog(pNetworkManagerDialog)
    459     , m_pNetworkRequestWidget(0)
    460     , m_uuid(QUuid::createUuid())
    461     , m_requests(requests)
    462     , m_iCurrentRequestIndex(0)
    463     , m_type(type)
    464     , m_strDescription(strDescription)
    465     , m_pCustomer(pCustomer)
    466     , m_fRunning(false)
    467 {
    468     /* Initialize: */
    469     initialize();
    470 }
    471 
    472 /* Destructor: */
    473 UINetworkRequest::~UINetworkRequest()
    474 {
    475     /* Destroy network-reply: */
    476     cleanupNetworkReply();
    477 
    478     /* Destroy network-request widget: */
    479     m_pNetworkManagerDialog->removeNetworkRequestWidget(m_uuid);
    480 }
    481 
    482 /* Network-reply progress handler: */
    483 void UINetworkRequest::sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal)
    484 {
    485     /* Notify UINetworkManager: */
    486     emit sigProgress(m_uuid, iReceived, iTotal);
    487     /* Notify UINetworkRequestWidget: */
    488     emit sigProgress(iReceived, iTotal);
    489 }
    490 
    491 /* Network-reply finish handler: */
    492 void UINetworkRequest::sltHandleNetworkReplyFinish()
    493 {
    494     /* Set as non-running: */
    495     m_fRunning = false;
    496 
    497     /* Get sender network reply: */
    498     QNetworkReply *pNetworkReply = static_cast<QNetworkReply*>(sender());
    499 
    500     /* If network-request was canceled: */
    501     if (pNetworkReply->error() == QNetworkReply::OperationCanceledError)
    502     {
    503         /* Notify UINetworkManager: */
    504         emit sigCanceled(m_uuid);
    505     }
    506     /* If network-reply has no errors: */
    507     else if (pNetworkReply->error() == QNetworkReply::NoError)
    508     {
    509         /* Check if redirection required: */
    510         QUrl redirect = pNetworkReply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
    511         if (redirect.isValid())
    512         {
    513             /* Cleanup current network-reply first: */
    514             cleanupNetworkReply();
    515 
    516             /* Choose redirect-source as current: */
    517             m_request.setUrl(redirect);
    518 
    519             /* Create new network-reply finally: */
    520             prepareNetworkReply();
    521         }
    522         else
    523         {
    524             /* Notify UINetworkRequestWidget: */
    525             emit sigFinished();
    526             /* Notify UINetworkManager: */
    527             emit sigFinished(m_uuid);
    528         }
    529     }
    530     /* If some error occured: */
    531     else
    532     {
    533         /* Check if we have other requests in set: */
    534         if (m_iCurrentRequestIndex < m_requests.size() - 1)
    535         {
    536             /* Cleanup current network-reply first: */
    537             cleanupNetworkReply();
    538 
    539             /* Choose next network-request as current: */
    540             ++m_iCurrentRequestIndex;
    541             m_request = m_requests[m_iCurrentRequestIndex];
    542 
    543             /* Create new network-reply finally: */
    544             prepareNetworkReply();
    545         }
    546         else
    547         {
    548             /* Notify UINetworkRequestWidget: */
    549             emit sigFailed(pNetworkReply->errorString());
    550             /* Notify UINetworkManager: */
    551             emit sigFailed(m_uuid, pNetworkReply->errorString());
    552         }
    553     }
    554 }
    555 
    556 /* Slot to retry network-request: */
    557 void UINetworkRequest::sltRetry()
    558 {
    559     /* Cleanup current network-reply first: */
    560     cleanupNetworkReply();
    561 
    562     /* Choose first network-request as current: */
    563     m_iCurrentRequestIndex = 0;
    564     m_request = m_requests[m_iCurrentRequestIndex];
    565 
    566     /* Create new network-reply finally: */
    567     prepareNetworkReply();
    568 }
    569 
    570 /* Slot to cancel network-request: */
    571 void UINetworkRequest::sltCancel()
    572 {
    573     /* Abort network-reply if present: */
    574     abortNetworkReply();
    575 }
    576 
    577 /* Initialize: */
    578 void UINetworkRequest::initialize()
    579 {
    580     /* Prepare listeners for parent(): */
    581     connect(parent(), SIGNAL(sigCancelNetworkRequests()), this, SLOT(sltCancel()));
    582 
    583     /* Create network-request widget: */
    584     m_pNetworkRequestWidget = m_pNetworkManagerDialog->addNetworkRequestWidget(this);
    585 
    586     /* Prepare listeners for m_pNetworkRequestWidget: */
    587     connect(m_pNetworkRequestWidget, SIGNAL(sigRetry()), this, SLOT(sltRetry()));
    588     connect(m_pNetworkRequestWidget, SIGNAL(sigCancel()), this, SLOT(sltCancel()));
    589 
    590     /* Choose first network-request as current: */
    591     m_iCurrentRequestIndex = 0;
    592     m_request = m_requests[m_iCurrentRequestIndex];
    593 
    594     /* Create network-reply: */
    595     prepareNetworkReply();
    596 }
    597 
    598 /* Prepare network-reply: */
    599 void UINetworkRequest::prepareNetworkReply()
    600 {
    601     /* Make network-request: */
    602     switch (m_type)
    603     {
    604         case UINetworkRequestType_HEAD:
    605         {
    606             m_pReply = gNetworkManager->head(m_request);
    607             break;
    608         }
    609         case UINetworkRequestType_GET:
    610         {
    611             m_pReply = gNetworkManager->get(m_request);
    612             break;
    613         }
    614         default:
    615             break;
    616     }
    617 
    618     /* Prepare listeners for m_pReply: */
    619     AssertMsg(m_pReply, ("Unable to make network-request!\n"));
    620     connect(m_pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(sltHandleNetworkReplyProgress(qint64, qint64)));
    621     connect(m_pReply, SIGNAL(finished()), this, SLOT(sltHandleNetworkReplyFinish()));
    622 
    623     /* Set as running: */
    624     m_fRunning = true;
    625 
    626     /* Notify UINetworkRequestWidget: */
    627     emit sigStarted();
    628 }
    629 
    630 /* Cleanup network-reply: */
    631 void UINetworkRequest::cleanupNetworkReply()
    632 {
    633     /* Destroy current reply: */
    634     AssertMsg(m_pReply, ("Network-reply already destroyed!\n"));
    635     m_pReply->disconnect();
    636     m_pReply->deleteLater();
    637     m_pReply = 0;
    638 }
    639 
    640 /* Abort network-reply: */
    641 void UINetworkRequest::abortNetworkReply()
    642 {
    643     /* Abort network-reply if present: */
    644     if (m_pReply)
    645     {
    646         if (m_fRunning)
    647             m_pReply->abort();
    648         else
    649             emit sigCanceled(m_uuid);
    650     }
    651 }
    652 
    653 /* Instance: */
     29
    65430UINetworkManager* UINetworkManager::m_pInstance = 0;
    65531
    656 /* Create singleton: */
    65732void UINetworkManager::create()
    65833{
     
    66338    /* Create instance: */
    66439    new UINetworkManager;
    665 }
    666 
    667 /* Destroy singleton: */
     40
     41    /* Prepare instance: */
     42    m_pInstance->prepare();
     43}
     44
    66845void UINetworkManager::destroy()
    66946{
     
    67249        return;
    67350
     51    /* Cleanup instance: */
     52    m_pInstance->cleanup();
     53
    67454    /* Destroy instance: */
    67555    delete m_pInstance;
    67656}
    67757
    678 /* Network Access Manager GUI window: */
    67958QWidget* UINetworkManager::window() const
    68059{
    681     return m_pNetworkProgressDialog;
    682 }
    683 
    684 /* Show Network Access Manager GUI: */
     60    return m_pNetworkManagerDialog;
     61}
     62
    68563void UINetworkManager::show()
    68664{
    687     /* Just show the dialog: */
    688     m_pNetworkProgressDialog->showNormal();
    689 }
    690 
    691 /* Network-request creation wrapper for UINetworkCustomer: */
    692 void UINetworkManager::createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type,
    693                                             const QString &strDescription, UINetworkCustomer *pCustomer)
    694 {
    695     /* Create new network-request: */
    696     UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkProgressDialog,
    697                                                              request, type, strDescription, pCustomer);
     65    /* Show network-manager dialog: */
     66    m_pNetworkManagerDialog->showNormal();
     67}
     68
     69void UINetworkManager::createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type, const QString &strDescription,
     70                                            UINetworkCustomer *pCustomer)
     71{
     72    /* Create network-request: */
     73    UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkManagerDialog, request, type, strDescription, pCustomer);
    69874    /* Prepare created network-request: */
    69975    prepareNetworkRequest(pNetworkRequest);
    70076}
    70177
    702 /* Network request (set) creation wrapper for UINetworkCustomer: */
    703 void UINetworkManager::createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    704                                             const QString &strDescription, UINetworkCustomer *pCustomer)
    705 {
    706     /* Create new network-request: */
    707     UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkProgressDialog,
    708                                                              requests, type, strDescription, pCustomer);
     78void UINetworkManager::createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type, const QString &strDescription,
     79                                            UINetworkCustomer *pCustomer)
     80{
     81    /* Create network-request: */
     82    UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkManagerDialog, requests, type, strDescription, pCustomer);
    70983    /* Prepare created network-request: */
    71084    prepareNetworkRequest(pNetworkRequest);
    71185}
    71286
    713 /* Constructor: */
    71487UINetworkManager::UINetworkManager()
    71588{
    71689    /* Prepare instance: */
    71790    m_pInstance = this;
    718 
    719     /* Prepare finally: */
    720     prepare();
    721 }
    722 
    723 /* Destructor: */
     91}
     92
    72493UINetworkManager::~UINetworkManager()
    72594{
    726     /* Cleanup first: */
    727     cleanup();
    728 
    72995    /* Cleanup instance: */
    73096    m_pInstance = 0;
    73197}
    73298
    733 /* Prepare: */
    73499void UINetworkManager::prepare()
    735100{
    736     /* Prepare network manager GUI: */
    737     m_pNetworkProgressDialog = new UINetworkManagerDialog;
    738 
    739     /* Prepare listeners for m_pNetworkProgressDialog: */
    740     connect(m_pNetworkProgressDialog, SIGNAL(sigCancelNetworkRequests()), this, SIGNAL(sigCancelNetworkRequests()));
    741 }
    742 
    743 /* Cleanup: */
     101    /* Prepare network-manager dialog: */
     102    m_pNetworkManagerDialog = new UINetworkManagerDialog;
     103    connect(m_pNetworkManagerDialog, SIGNAL(sigCancelNetworkRequests()), this, SIGNAL(sigCancelNetworkRequests()));
     104}
     105
    744106void UINetworkManager::cleanup()
    745107{
     
    747109    cleanupNetworkRequests();
    748110
    749     /* Cleanup network manager GUI: */
    750     delete m_pNetworkProgressDialog;
    751 }
    752 
    753 /* Prepare network-request: */
     111    /* Cleanup network-manager dialog: */
     112    delete m_pNetworkManagerDialog;
     113}
     114
    754115void UINetworkManager::prepareNetworkRequest(UINetworkRequest *pNetworkRequest)
    755116{
    756     /* Prepare listeners for pNetworkRequest: */
    757     connect(pNetworkRequest, SIGNAL(sigProgress(const QUuid&, qint64, qint64)), this, SLOT(sltHandleNetworkRequestProgress(const QUuid&, qint64, qint64)));
    758     connect(pNetworkRequest, SIGNAL(sigCanceled(const QUuid&)), this, SLOT(sltHandleNetworkRequestCancel(const QUuid&)));
    759     connect(pNetworkRequest, SIGNAL(sigFinished(const QUuid&)), this, SLOT(sltHandleNetworkRequestFinish(const QUuid&)));
    760     connect(pNetworkRequest, SIGNAL(sigFailed(const QUuid&, const QString&)), this, SLOT(sltHandleNetworkRequestFailure(const QUuid&, const QString&)));
    761 
    762     /* Add this request into internal map: */
     117    /* Prepare listeners for network-request: */
     118    connect(pNetworkRequest, SIGNAL(sigProgress(const QUuid&, qint64, qint64)),
     119            this, SLOT(sltHandleNetworkRequestProgress(const QUuid&, qint64, qint64)));
     120    connect(pNetworkRequest, SIGNAL(sigCanceled(const QUuid&)),
     121            this, SLOT(sltHandleNetworkRequestCancel(const QUuid&)));
     122    connect(pNetworkRequest, SIGNAL(sigFinished(const QUuid&)),
     123            this, SLOT(sltHandleNetworkRequestFinish(const QUuid&)));
     124    connect(pNetworkRequest, SIGNAL(sigFailed(const QUuid&, const QString&)),
     125            this, SLOT(sltHandleNetworkRequestFailure(const QUuid&, const QString&)));
     126
     127    /* Add network-request into map: */
    763128    m_requests.insert(pNetworkRequest->uuid(), pNetworkRequest);
    764129}
    765130
    766 /* Cleanup network-request: */
    767131void UINetworkManager::cleanupNetworkRequest(QUuid uuid)
    768132{
    769     /* Cleanup network-request map: */
     133    /* Delete network-request from map: */
    770134    delete m_requests[uuid];
    771135    m_requests.remove(uuid);
    772136}
    773137
    774 /* Cleanup all network-requests: */
    775138void UINetworkManager::cleanupNetworkRequests()
    776139{
     
    782145}
    783146
    784 /* Slot to handle network-request progress: */
    785147void UINetworkManager::sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
    786148{
     
    798160}
    799161
    800 /* Slot to handle network-request cancel: */
    801162void UINetworkManager::sltHandleNetworkRequestCancel(const QUuid &uuid)
    802163{
     
    817178}
    818179
    819 /* Slot to handle network-request finish: */
    820180void UINetworkManager::sltHandleNetworkRequestFinish(const QUuid &uuid)
    821181{
     
    836196}
    837197
    838 /* Slot to handle network-request failure: */
    839198void UINetworkManager::sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &)
    840199{
     
    856215}
    857216
    858 #include "UINetworkManager.moc"
    859 
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h

    r41433 r41440  
    2525#include <QMap>
    2626#include <QNetworkRequest>
    27 #include <QNetworkReply>
    28 #include <QPointer>
    2927
    3028/* Local inludes: */
     
    3230
    3331/* Forward declarations: */
    34 class UINetworkManager;
     32class QWidget;
     33class UINetworkRequest;
    3534class UINetworkCustomer;
    36 class UINetworkRequestWidget;
    3735class UINetworkManagerDialog;
    3836
    39 /* Network request contianer: */
    40 class UINetworkRequest : public QObject
    41 {
    42     Q_OBJECT;
    43 
    44 signals:
    45 
    46     /* Notifications to UINetworkManager: */
    47     void sigProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
    48     void sigCanceled(const QUuid &uuid);
    49     void sigFinished(const QUuid &uuid);
    50     void sigFailed(const QUuid &uuid, const QString &strError);
    51 
    52     /* Notifications to UINetworkRequestWidget: */
    53     void sigProgress(qint64 iReceived, qint64 iTotal);
    54     void sigStarted();
    55     void sigFinished();
    56     void sigFailed(const QString &strError);
    57 
    58 public:
    59 
    60     /* Constructor/destructor: */
    61     UINetworkRequest(UINetworkManager *pNetworkManager,
    62                      UINetworkManagerDialog *pNetworkManagerDialog,
    63                      const QNetworkRequest &request, UINetworkRequestType type,
    64                      const QString &strDescription, UINetworkCustomer *pCustomer);
    65     UINetworkRequest(UINetworkManager *pNetworkManager,
    66                      UINetworkManagerDialog *pNetworkManagerDialog,
    67                      const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    68                      const QString &strDescription, UINetworkCustomer *pCustomer);
    69     ~UINetworkRequest();
    70 
    71     /* Getters: */
    72     const QUuid& uuid() const { return m_uuid; }
    73     const QString& description() const { return m_strDescription; }
    74     UINetworkCustomer* customer() { return m_pCustomer; }
    75     QNetworkReply* reply() { return m_pReply; }
    76 
    77 private slots:
    78 
    79     /* Network-reply progress handler: */
    80     void sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal);
    81     /* Network-reply finish handler: */
    82     void sltHandleNetworkReplyFinish();
    83 
    84     /* Slot to retry network-request: */
    85     void sltRetry();
    86     /* Slot to cancel network-request: */
    87     void sltCancel();
    88 
    89 private:
    90 
    91     /* Initialize: */
    92     void initialize();
    93 
    94     /* Prepare network-reply: */
    95     void prepareNetworkReply();
    96     /* Cleanup network-reply: */
    97     void cleanupNetworkReply();
    98     /* Abort network-reply: */
    99     void abortNetworkReply();
    100 
    101     /* Widgets: */
    102     UINetworkManagerDialog *m_pNetworkManagerDialog;
    103     UINetworkRequestWidget *m_pNetworkRequestWidget;
    104 
    105     /* Variables: */
    106     QUuid m_uuid;
    107     QList<QNetworkRequest> m_requests;
    108     QNetworkRequest m_request;
    109     int m_iCurrentRequestIndex;
    110     UINetworkRequestType m_type;
    111     QString m_strDescription;
    112     UINetworkCustomer *m_pCustomer;
    113     QPointer<QNetworkReply> m_pReply;
    114     bool m_fRunning;
    115 };
    116 
    117 /* QNetworkAccessManager class reimplementation providing
    118  * network access for the VirtualBox application purposes. */
     37/* QNetworkAccessManager class reimplementation.
     38 * Providing network access for VirtualBox application purposes. */
    11939class UINetworkManager : public QNetworkAccessManager
    12040{
     
    12343signals:
    12444
    125     /* Notification to UINetworkRequest: */
     45    /* Ask listeners (network-requests) to cancel: */
    12646    void sigCancelNetworkRequests();
    12747
     
    13555    static void destroy();
    13656
    137     /* Network Access Manager GUI window: */
     57    /* Pointer to network-manager dialog: */
    13858    QWidget* window() const;
    13959
    14060public slots:
    14161
    142     /* Show Network Access Manager GUI: */
     62    /* Show network-manager dialog: */
    14363    void show();
    14464
    14565protected:
    14666
    147     /* Allow UINetworkCustomer to implicitly use next mothods: */
     67    /* Allow UINetworkCustomer to create network-request: */
    14868    friend class UINetworkCustomer;
    149     /* Network-request creation wrapper for UINetworkCustomer: */
    150     void createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type,
    151                               const QString &strDescription, UINetworkCustomer *pCustomer);
    152     /* Network request (set) creation wrapper for UINetworkCustomer: */
    153     void createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    154                               const QString &strDescription, UINetworkCustomer *pCustomer);
     69    /* Network-request creation wrappers for UINetworkCustomer: */
     70    void createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type, const QString &strDescription,
     71                              UINetworkCustomer *pCustomer);
     72    void createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type, const QString &strDescription,
     73                              UINetworkCustomer *pCustomer);
    15574
    15675private:
     
    190109    QMap<QUuid, UINetworkRequest*> m_requests;
    191110
    192     /* Network manager UI: */
    193     UINetworkManagerDialog *m_pNetworkProgressDialog;
     111    /* Network-manager dialog: */
     112    UINetworkManagerDialog *m_pNetworkManagerDialog;
    194113};
    195114#define gNetworkManager UINetworkManager::instance()
    196115
    197116#endif // __UINetworkManager_h__
     117
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.cpp

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp58652,​70973
      /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp66309,​66318
      /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp70873
      /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp74233
    r41434 r41440  
    33 *
    44 * VBox frontends: Qt GUI ("VirtualBox"):
    5  * UINetworkManager stuff implementation
     5 * UINetworkManagerDialog stuff implementation
    66 */
    77
     
    1919
    2020/* Global includes: */
    21 #include <QWidget>
    22 #include <QTimer>
    23 #include <QGridLayout>
    24 #include <QProgressBar>
    25 #include <QMainWindow>
    2621#include <QVBoxLayout>
    2722#include <QLabel>
     
    2924#include <QStatusBar>
    3025#include <QKeyEvent>
    31 #include <QNetworkReply>
    3226
    3327/* Local includes: */
     28#include "UINetworkManagerDialog.h"
    3429#include "UINetworkManager.h"
     30#include "UINetworkRequest.h"
     31#include "UINetworkRequestWidget.h"
    3532#include "UINetworkCustomer.h"
    36 #include "QIWithRetranslateUI.h"
     33#include "UIIconPool.h"
    3734#include "VBoxGlobal.h"
    3835#include "UIMessageCenter.h"
    39 #include "UIIconPool.h"
    4036#include "QIDialogButtonBox.h"
    41 #include "UIPopupBox.h"
    42 #include "QIToolButton.h"
    43 #include "QIRichTextLabel.h"
    4437
    45 /* Network-request widget: */
    46 class UINetworkRequestWidget : public QIWithRetranslateUI<UIPopupBox>
     38void UINetworkManagerDialog::showNormal()
    4739{
    48     Q_OBJECT;
     40    /* Show (restore if necessary): */
     41    QMainWindow::showNormal();
    4942
    50 signals:
     43    /* Raise above the others: */
     44    raise();
    5145
    52     /* Signal to retry network-request: */
    53     void sigRetry();
    54     /* Signal to cancel network-request: */
    55     void sigCancel();
     46    /* Activate: */
     47    activateWindow();
     48}
    5649
    57 public:
     50UINetworkManagerDialog::UINetworkManagerDialog()
     51{
     52    /* Apply window icons: */
     53    setWindowIcon(UIIconPool::iconSetFull(QSize (32, 32), QSize (16, 16), ":/nw_32px.png", ":/nw_16px.png"));
    5854
    59     /* Constructor: */
    60     UINetworkRequestWidget(QMainWindow *pParent, UINetworkRequest *pNetworkRequest)
    61         : QIWithRetranslateUI<UIPopupBox>(pParent)
    62         , m_pNetworkRequest(pNetworkRequest)
    63         , m_pTimer(new QTimer(this))
    64         , m_pContentWidget(new QWidget(this))
    65         , m_pMainLayout(new QGridLayout(m_pContentWidget))
    66         , m_pProgressBar(new QProgressBar(m_pContentWidget))
    67         , m_pRetryButton(new QIToolButton(m_pContentWidget))
    68         , m_pCancelButton(new QIToolButton(m_pContentWidget))
    69         , m_pErrorPane(new QIRichTextLabel(m_pContentWidget))
     55    /* Do not count that window as important for application,
     56     * it will NOT be taken into account when other top-level windows will be closed: */
     57    setAttribute(Qt::WA_QuitOnClose, false);
     58
     59    /* Set minimum width: */
     60    setMinimumWidth(500);
     61
     62    /* Prepare central-widget: */
     63    setCentralWidget(new QWidget);
     64
     65    /* Create main-layout: */
     66    QVBoxLayout *pMainLayout = new QVBoxLayout(centralWidget());
     67    pMainLayout->setContentsMargins(6, 6, 6, 6);
     68
     69    /* Create description-label: */
     70    m_pLabel = new QLabel(centralWidget());
     71    m_pLabel->setAlignment(Qt::AlignCenter);
     72    m_pLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     73
     74    /* Create layout for network-request widgets: */
     75    m_pWidgetsLayout = new QVBoxLayout;
     76
     77    /* Create button-box: */
     78    m_pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, centralWidget());
     79    connect(m_pButtonBox, SIGNAL(rejected()), this, SLOT(sltHandleCancelAllButtonPress()));
     80    m_pButtonBox->setHidden(true);
     81
     82    /* Layout content: */
     83    pMainLayout->addWidget(m_pLabel);
     84    pMainLayout->addLayout(m_pWidgetsLayout);
     85    pMainLayout->addStretch();
     86    pMainLayout->addWidget(m_pButtonBox);
     87
     88    /* Create status-bar: */
     89    setStatusBar(new QStatusBar);
     90
     91    /* Translate dialog: */
     92    retranslateUi();
     93}
     94
     95UINetworkRequestWidget* UINetworkManagerDialog::addNetworkRequestWidget(UINetworkRequest *pNetworkRequest)
     96{
     97    /* Make sure network-request is really exists: */
     98    AssertMsg(pNetworkRequest, ("Network-request doesn't exists!\n"));
     99
     100    /* Create new network-request widget: */
     101    UINetworkRequestWidget *pNetworkRequestWidget = new UINetworkRequestWidget(this, pNetworkRequest);
     102    m_pWidgetsLayout->addWidget(pNetworkRequestWidget);
     103    m_widgets.insert(pNetworkRequest->uuid(), pNetworkRequestWidget);
     104
     105    /* Hide label: */
     106    m_pLabel->hide();
     107    /* Show button-box: */
     108    m_pButtonBox->show();
     109    /* If customer made a force-call: */
     110    if (pNetworkRequest->customer()->isItForceCall())
    70111    {
    71         /* Setup self: */
    72         setTitleIcon(UIIconPool::iconSet(":/nw_16px.png"));
    73         setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    74         setContentWidget(m_pContentWidget);
    75         setOpen(true);
    76 
    77         /* Prepare listeners for m_pNetworkRequest: */
    78         connect(m_pNetworkRequest, SIGNAL(sigProgress(qint64, qint64)), this, SLOT(sltSetProgress(qint64, qint64)));
    79         connect(m_pNetworkRequest, SIGNAL(sigStarted()), this, SLOT(sltSetProgressToStarted()));
    80         connect(m_pNetworkRequest, SIGNAL(sigFinished()), this, SLOT(sltSetProgressToFinished()));
    81         connect(m_pNetworkRequest, SIGNAL(sigFailed(const QString&)), this, SLOT(sltSetProgressToFailed(const QString&)));
    82 
    83         /* Setup timer: */
    84         m_pTimer->setInterval(5000);
    85         connect(m_pTimer, SIGNAL(timeout()), this, SLOT(sltTimeIsOut()));
    86 
    87         /* Setup main-layout: */
    88         m_pMainLayout->setContentsMargins(6, 6, 6, 6);
    89 
    90         /* Setup progress-bar: */
    91         m_pProgressBar->setRange(0, 0);
    92         m_pProgressBar->setMaximumHeight(16);
    93 
    94         /* Setup retry-button: */
    95         m_pRetryButton->setHidden(true);
    96         m_pRetryButton->removeBorder();
    97         m_pRetryButton->setFocusPolicy(Qt::NoFocus);
    98         m_pRetryButton->setIcon(UIIconPool::iconSet(":/refresh_16px.png"));
    99         connect(m_pRetryButton, SIGNAL(clicked(bool)), this, SIGNAL(sigRetry()));
    100 
    101         /* Setup cancel-button: */
    102         m_pCancelButton->removeBorder();
    103         m_pCancelButton->setFocusPolicy(Qt::NoFocus);
    104         m_pCancelButton->setIcon(UIIconPool::iconSet(":/delete_16px.png"));
    105         connect(m_pCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(sigCancel()));
    106 
    107         /* Setup error-label: */
    108         m_pErrorPane->setHidden(true);
    109         m_pErrorPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    110         /* Calculate required width: */
    111         int iMinimumWidth = pParent->minimumWidth();
    112         int iLeft, iTop, iRight, iBottom;
    113         /* Take into account content-widget layout margins: */
    114         m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    115         iMinimumWidth -= iLeft;
    116         iMinimumWidth -= iRight;
    117         /* Take into account this layout margins: */
    118         layout()->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    119         iMinimumWidth -= iLeft;
    120         iMinimumWidth -= iRight;
    121         /* Take into account parent layout margins: */
    122         QLayout *pParentLayout = qobject_cast<QMainWindow*>(parent())->centralWidget()->layout();
    123         pParentLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    124         iMinimumWidth -= iLeft;
    125         iMinimumWidth -= iRight;
    126         /* Set minimum text width: */
    127         m_pErrorPane->setMinimumTextWidth(iMinimumWidth);
    128 
    129         /* Layout content: */
    130         m_pMainLayout->addWidget(m_pProgressBar, 0, 0);
    131         m_pMainLayout->addWidget(m_pRetryButton, 0, 1);
    132         m_pMainLayout->addWidget(m_pCancelButton, 0, 2);
    133         m_pMainLayout->addWidget(m_pErrorPane, 1, 0, 1, 3);
    134 
    135         /* Retranslate UI: */
    136         retranslateUi();
     112        /* Show dialog: */
     113        showNormal();
    137114    }
    138115
    139 private slots:
    140 
    141     /* Retranslate UI: */
    142     void retranslateUi()
    143     {
    144         /* Get corresponding title: */
    145         const QString &strTitle = m_pNetworkRequest->description();
    146 
    147         /* Set popup title (default if missed): */
    148         setTitle(strTitle.isEmpty() ? UINetworkManager::tr("Network Operation") : strTitle);
    149 
    150         /* Translate retry button: */
    151         m_pRetryButton->setStatusTip(UINetworkManager::tr("Restart network operation"));
    152 
    153         /* Translate cancel button: */
    154         m_pCancelButton->setStatusTip(UINetworkManager::tr("Cancel network operation"));
    155     }
    156 
    157     /* Updates current network-request progess: */
    158     void sltSetProgress(qint64 iReceived, qint64 iTotal)
    159     {
    160         /* Restart timer: */
    161         m_pTimer->start();
    162 
    163         /* Set current progress to passed: */
    164         m_pProgressBar->setRange(0, iTotal);
    165         m_pProgressBar->setValue(iReceived);
    166     }
    167 
    168     /* Set current network-request progress to 'started': */
    169     void sltSetProgressToStarted()
    170     {
    171         /* Start timer: */
    172         m_pTimer->start();
    173 
    174         /* Set current progress to 'started': */
    175         m_pProgressBar->setRange(0, 1);
    176         m_pProgressBar->setValue(0);
    177 
    178         /* Hide 'retry' button: */
    179         m_pRetryButton->setHidden(true);
    180 
    181         /* Hide error label: */
    182         m_pErrorPane->setHidden(true);
    183         m_pErrorPane->setText(QString());
    184     }
    185 
    186     /* Set current network-request progress to 'finished': */
    187     void sltSetProgressToFinished()
    188     {
    189         /* Stop timer: */
    190         m_pTimer->stop();
    191 
    192         /* Set current progress to 'started': */
    193         m_pProgressBar->setRange(0, 1);
    194         m_pProgressBar->setValue(1);
    195     }
    196 
    197     /* Set current network-request progress to 'failed': */
    198     void sltSetProgressToFailed(const QString &strError)
    199     {
    200         /* Stop timer: */
    201         m_pTimer->stop();
    202 
    203         /* Set current progress to 'failed': */
    204         m_pProgressBar->setRange(0, 1);
    205         m_pProgressBar->setValue(1);
    206 
    207         /* Show 'retry' button: */
    208         m_pRetryButton->setHidden(false);
    209 
    210         /* Try to find all the links in the error-message,
    211          * replace them with %increment if present: */
    212         QString strErrorText(strError);
    213         QRegExp linkRegExp("[\\S]+[\\./][\\S]+");
    214         QStringList links;
    215         for (int i = 1; linkRegExp.indexIn(strErrorText) != -1; ++i)
    216         {
    217             links << linkRegExp.cap();
    218             strErrorText.replace(linkRegExp.cap(), QString("%%1").arg(i));
    219         }
    220         /* Return back all the links, just in bold: */
    221         if (!links.isEmpty())
    222             for (int i = 0; i < links.size(); ++i)
    223                 strErrorText = strErrorText.arg(QString("<b>%1</b>").arg(links[i]));
    224 
    225         /* Show error label: */
    226         m_pErrorPane->setHidden(false);
    227         m_pErrorPane->setText(UINetworkManager::tr("Error: %1.").arg(strErrorText));
    228     }
    229 
    230     /* Handle frozen progress: */
    231     void sltTimeIsOut()
    232     {
    233         /* Stop timer: */
    234         m_pTimer->stop();
    235 
    236         /* Set current progress to unknown: */
    237         m_pProgressBar->setRange(0, 0);
    238     }
    239 
    240 private:
    241 
    242     /* Objects: */
    243     UINetworkRequest *m_pNetworkRequest;
    244     QTimer *m_pTimer;
    245 
    246     /* Widgets: */
    247     QWidget *m_pContentWidget;
    248     QGridLayout *m_pMainLayout;
    249     QProgressBar *m_pProgressBar;
    250     QIToolButton *m_pRetryButton;
    251     QIToolButton *m_pCancelButton;
    252     QIRichTextLabel *m_pErrorPane;
    253 };
    254 
    255 /* Network requests dialog: */
    256 class UINetworkManagerDialog : public QIWithRetranslateUI<QMainWindow>
    257 {
    258     Q_OBJECT;
    259 
    260 signals:
    261 
    262     /* Signal to cancel all network-requests: */
    263     void sigCancelNetworkRequests();
    264 
    265 public slots:
    266 
    267     /* Show the dialog, make sure its visible: */
    268     void showNormal()
    269     {
    270         /* Show (restore if neessary): */
    271         QMainWindow::showNormal();
    272 
    273         /* Raise above the others: */
    274         raise();
    275 
    276         /* Activate: */
    277         activateWindow();
    278     }
    279 
    280 public:
    281 
    282     /* Constructor: */
    283     UINetworkManagerDialog()
    284     {
    285         /* Do not count that window as important for application,
    286          * it will NOT be taken into account when other top-level windows will be closed: */
    287         setAttribute(Qt::WA_QuitOnClose, false);
    288 
    289         /* Set minimum width: */
    290         setMinimumWidth(500);
    291 
    292         /* Prepare central-widget: */
    293         setCentralWidget(new QWidget);
    294 
    295         /* Create main-layout: */
    296         m_pMainLayout = new QVBoxLayout(centralWidget());
    297         m_pMainLayout->setContentsMargins(6, 6, 6, 6);
    298 
    299         /* Create description-label: */
    300         m_pLabel = new QLabel(centralWidget());
    301         m_pLabel->setAlignment(Qt::AlignCenter);
    302         m_pLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    303 
    304         /* Create button-box: */
    305         m_pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, centralWidget());
    306         connect(m_pButtonBox, SIGNAL(rejected()), this, SLOT(sltHandleCancelAllButtonPress()));
    307         m_pButtonBox->setHidden(true);
    308 
    309         /* Layout content: */
    310         m_pMainLayout->addWidget(m_pLabel);
    311         m_pMainLayout->addStretch();
    312         m_pMainLayout->addWidget(m_pButtonBox);
    313 
    314         /* Create status-bar: */
    315         setStatusBar(new QStatusBar);
    316 
    317         /* Translate dialog: */
    318         retranslateUi();
    319     }
    320 
    321     /* Add network-request widget: */
    322     UINetworkRequestWidget* addNetworkRequestWidget(UINetworkRequest *pNetworkRequest)
    323     {
    324         /* Make sure network-request is really exists: */
    325         AssertMsg(pNetworkRequest, ("Network-request doesn't exists!\n"));
    326 
    327         /* Create new network-request widget: */
    328         UINetworkRequestWidget *pNetworkRequestWidget = new UINetworkRequestWidget(this, pNetworkRequest);
    329         m_pMainLayout->insertWidget(m_pMainLayout->count() - 2 /* before button-box and stretch */, pNetworkRequestWidget);
    330         m_widgets.insert(pNetworkRequest->uuid(), pNetworkRequestWidget);
    331 
    332         /* Hide label: */
    333         m_pLabel->setHidden(true);
    334         /* Show button-box: */
    335         m_pButtonBox->setHidden(false);
    336         /* If customer made a force-call: */
    337         if (pNetworkRequest->customer()->isItForceCall())
    338         {
    339             /* Show dialog: */
    340             showNormal();
    341         }
    342 
    343         /* Return network-request widget: */
    344         return pNetworkRequestWidget;
    345     }
    346 
    347     /* Remove network-request widget: */
    348     void removeNetworkRequestWidget(const QUuid &uuid)
    349     {
    350         /* Make sure network-request widget still present: */
    351         AssertMsg(m_widgets.contains(uuid), ("Network-request widget already removed!\n"));
    352 
    353         /* Delete corresponding network-request widget: */
    354         delete m_widgets.value(uuid);
    355         m_widgets.remove(uuid);
    356 
    357         /* Check if dialog is empty: */
    358         if (m_widgets.isEmpty())
    359         {
    360             /* Show label: */
    361             m_pLabel->setHidden(false);
    362             /* Hide button-box: */
    363             m_pButtonBox->setHidden(true);
    364             /* Let central-widget update its layout before being hidden: */
    365             QCoreApplication::sendPostedEvents(centralWidget(), QEvent::LayoutRequest);
    366             /* Hide dialog: */
    367             hide();
    368         }
    369     }
    370 
    371 private slots:
    372 
    373     /* Handler for 'Cancel All' button press: */
    374     void sltHandleCancelAllButtonPress()
    375     {
    376         /* Ask if user wants to cancel all current network-requests: */
    377         if (msgCenter().askAboutCancelAllNetworkRequest(this))
    378             emit sigCancelNetworkRequests();
    379     }
    380 
    381 private:
    382 
    383     /* Translate whole dialog: */
    384     void retranslateUi()
    385     {
    386         /* Set window caption: */
    387         setWindowTitle(UINetworkManager::tr("Network Operations Manager"));
    388 
    389         /* Set description-label text: */
    390         m_pLabel->setText(UINetworkManager::tr("There are no active network operations."));
    391 
    392         /* Set buttons-box text: */
    393         m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("&Cancel All"));
    394         m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Cancel all active network operations"));
    395     }
    396 
    397     /* Overloaded show-event: */
    398     void showEvent(QShowEvent *pShowEvent)
    399     {
    400         /* Resize to minimum size-hint: */
    401         resize(minimumSizeHint());
    402 
    403         /* Center according current main application window: */
    404         vboxGlobal().centerWidget(this, vboxGlobal().mainWindow(), false);
    405 
    406         /* Pass event to the base-class: */
    407         QMainWindow::showEvent(pShowEvent);
    408     }
    409 
    410     /* Overloaded keypress-event: */
    411     void keyPressEvent(QKeyEvent *pKeyPressEvent)
    412     {
    413         /* 'Escape' key used to close the dialog: */
    414         if (pKeyPressEvent->key() == Qt::Key_Escape)
    415         {
    416             close();
    417             return;
    418         }
    419 
    420         /* Pass event to the base-class: */
    421         QMainWindow::keyPressEvent(pKeyPressEvent);
    422     }
    423 
    424     /* Main layout: */
    425     QVBoxLayout *m_pMainLayout;
    426     QLabel *m_pLabel;
    427     QIDialogButtonBox *m_pButtonBox;
    428 
    429     /* Popup-widget map: */
    430     QMap<QUuid, UINetworkRequestWidget*> m_widgets;
    431 };
    432 
    433 /* Constructor: */
    434 UINetworkRequest::UINetworkRequest(UINetworkManager *pNetworkManager,
    435                                    UINetworkManagerDialog *pNetworkManagerDialog,
    436                                    const QNetworkRequest &request, UINetworkRequestType type,
    437                                    const QString &strDescription, UINetworkCustomer *pCustomer)
    438     : QObject(pNetworkManager)
    439     , m_pNetworkManagerDialog(pNetworkManagerDialog)
    440     , m_pNetworkRequestWidget(0)
    441     , m_uuid(QUuid::createUuid())
    442     , m_requests(QList<QNetworkRequest>() << request)
    443     , m_iCurrentRequestIndex(0)
    444     , m_type(type)
    445     , m_strDescription(strDescription)
    446     , m_pCustomer(pCustomer)
    447     , m_fRunning(false)
    448 {
    449     /* Initialize: */
    450     initialize();
     116    /* Return network-request widget: */
     117    return pNetworkRequestWidget;
    451118}
    452119
    453 UINetworkRequest::UINetworkRequest(UINetworkManager *pNetworkManager,
    454                                    UINetworkManagerDialog *pNetworkManagerDialog,
    455                                    const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    456                                    const QString &strDescription, UINetworkCustomer *pCustomer)
    457     : QObject(pNetworkManager)
    458     , m_pNetworkManagerDialog(pNetworkManagerDialog)
    459     , m_pNetworkRequestWidget(0)
    460     , m_uuid(QUuid::createUuid())
    461     , m_requests(requests)
    462     , m_iCurrentRequestIndex(0)
    463     , m_type(type)
    464     , m_strDescription(strDescription)
    465     , m_pCustomer(pCustomer)
    466     , m_fRunning(false)
     120void UINetworkManagerDialog::removeNetworkRequestWidget(const QUuid &uuid)
    467121{
    468     /* Initialize: */
    469     initialize();
    470 }
     122    /* Make sure network-request widget still present: */
     123    AssertMsg(m_widgets.contains(uuid), ("Network-request widget already removed!\n"));
    471124
    472 /* Destructor: */
    473 UINetworkRequest::~UINetworkRequest()
    474 {
    475     /* Destroy network-reply: */
    476     cleanupNetworkReply();
     125    /* Delete corresponding network-request widget: */
     126    delete m_widgets.value(uuid);
     127    m_widgets.remove(uuid);
    477128
    478     /* Destroy network-request widget: */
    479     m_pNetworkManagerDialog->removeNetworkRequestWidget(m_uuid);
    480 }
    481 
    482 /* Network-reply progress handler: */
    483 void UINetworkRequest::sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal)
    484 {
    485     /* Notify UINetworkManager: */
    486     emit sigProgress(m_uuid, iReceived, iTotal);
    487     /* Notify UINetworkRequestWidget: */
    488     emit sigProgress(iReceived, iTotal);
    489 }
    490 
    491 /* Network-reply finish handler: */
    492 void UINetworkRequest::sltHandleNetworkReplyFinish()
    493 {
    494     /* Set as non-running: */
    495     m_fRunning = false;
    496 
    497     /* Get sender network reply: */
    498     QNetworkReply *pNetworkReply = static_cast<QNetworkReply*>(sender());
    499 
    500     /* If network-request was canceled: */
    501     if (pNetworkReply->error() == QNetworkReply::OperationCanceledError)
     129    /* Check if dialog is empty: */
     130    if (m_widgets.isEmpty())
    502131    {
    503         /* Notify UINetworkManager: */
    504         emit sigCanceled(m_uuid);
    505     }
    506     /* If network-reply has no errors: */
    507     else if (pNetworkReply->error() == QNetworkReply::NoError)
    508     {
    509         /* Check if redirection required: */
    510         QUrl redirect = pNetworkReply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
    511         if (redirect.isValid())
    512         {
    513             /* Cleanup current network-reply first: */
    514             cleanupNetworkReply();
    515 
    516             /* Choose redirect-source as current: */
    517             m_request.setUrl(redirect);
    518 
    519             /* Create new network-reply finally: */
    520             prepareNetworkReply();
    521         }
    522         else
    523         {
    524             /* Notify UINetworkRequestWidget: */
    525             emit sigFinished();
    526             /* Notify UINetworkManager: */
    527             emit sigFinished(m_uuid);
    528         }
    529     }
    530     /* If some error occured: */
    531     else
    532     {
    533         /* Check if we have other requests in set: */
    534         if (m_iCurrentRequestIndex < m_requests.size() - 1)
    535         {
    536             /* Cleanup current network-reply first: */
    537             cleanupNetworkReply();
    538 
    539             /* Choose next network-request as current: */
    540             ++m_iCurrentRequestIndex;
    541             m_request = m_requests[m_iCurrentRequestIndex];
    542 
    543             /* Create new network-reply finally: */
    544             prepareNetworkReply();
    545         }
    546         else
    547         {
    548             /* Notify UINetworkRequestWidget: */
    549             emit sigFailed(pNetworkReply->errorString());
    550             /* Notify UINetworkManager: */
    551             emit sigFailed(m_uuid, pNetworkReply->errorString());
    552         }
     132        /* Show label: */
     133        m_pLabel->show();
     134        /* Hide button-box: */
     135        m_pButtonBox->hide();
     136        /* Let central-widget update its layout before being hidden: */
     137        QCoreApplication::sendPostedEvents(centralWidget(), QEvent::LayoutRequest);
     138        /* Hide dialog: */
     139        hide();
    553140    }
    554141}
    555142
    556 /* Slot to retry network-request: */
    557 void UINetworkRequest::sltRetry()
     143void UINetworkManagerDialog::sltHandleCancelAllButtonPress()
    558144{
    559     /* Cleanup current network-reply first: */
    560     cleanupNetworkReply();
    561 
    562     /* Choose first network-request as current: */
    563     m_iCurrentRequestIndex = 0;
    564     m_request = m_requests[m_iCurrentRequestIndex];
    565 
    566     /* Create new network-reply finally: */
    567     prepareNetworkReply();
     145    /* Ask if user wants to cancel all current network-requests: */
     146    if (msgCenter().askAboutCancelAllNetworkRequest(this))
     147        emit sigCancelNetworkRequests();
    568148}
    569149
    570 /* Slot to cancel network-request: */
    571 void UINetworkRequest::sltCancel()
     150void UINetworkManagerDialog::retranslateUi()
    572151{
    573     /* Abort network-reply if present: */
    574     abortNetworkReply();
     152    /* Set window caption: */
     153    setWindowTitle(tr("Network Operations Manager"));
     154
     155    /* Set description-label text: */
     156    m_pLabel->setText(tr("There are no active network operations."));
     157
     158    /* Set buttons-box text: */
     159    m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(tr("&Cancel All"));
     160    m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Cancel all active network operations"));
    575161}
    576162
    577 /* Initialize: */
    578 void UINetworkRequest::initialize()
     163void UINetworkManagerDialog::showEvent(QShowEvent *pShowEvent)
    579164{
    580     /* Prepare listeners for parent(): */
    581     connect(parent(), SIGNAL(sigCancelNetworkRequests()), this, SLOT(sltCancel()));
     165    /* Resize to minimum size-hint: */
     166    resize(minimumSizeHint());
    582167
    583     /* Create network-request widget: */
    584     m_pNetworkRequestWidget = m_pNetworkManagerDialog->addNetworkRequestWidget(this);
     168    /* Center according current main application window: */
     169    vboxGlobal().centerWidget(this, vboxGlobal().mainWindow(), false);
    585170
    586     /* Prepare listeners for m_pNetworkRequestWidget: */
    587     connect(m_pNetworkRequestWidget, SIGNAL(sigRetry()), this, SLOT(sltRetry()));
    588     connect(m_pNetworkRequestWidget, SIGNAL(sigCancel()), this, SLOT(sltCancel()));
    589 
    590     /* Choose first network-request as current: */
    591     m_iCurrentRequestIndex = 0;
    592     m_request = m_requests[m_iCurrentRequestIndex];
    593 
    594     /* Create network-reply: */
    595     prepareNetworkReply();
     171    /* Pass event to the base-class: */
     172    QMainWindow::showEvent(pShowEvent);
    596173}
    597174
    598 /* Prepare network-reply: */
    599 void UINetworkRequest::prepareNetworkReply()
     175void UINetworkManagerDialog::keyPressEvent(QKeyEvent *pKeyPressEvent)
    600176{
    601     /* Make network-request: */
    602     switch (m_type)
     177    /* 'Escape' key used to close the dialog: */
     178    if (pKeyPressEvent->key() == Qt::Key_Escape)
    603179    {
    604         case UINetworkRequestType_HEAD:
    605         {
    606             m_pReply = gNetworkManager->head(m_request);
    607             break;
    608         }
    609         case UINetworkRequestType_GET:
    610         {
    611             m_pReply = gNetworkManager->get(m_request);
    612             break;
    613         }
    614         default:
    615             break;
     180        close();
     181        return;
    616182    }
    617183
    618     /* Prepare listeners for m_pReply: */
    619     AssertMsg(m_pReply, ("Unable to make network-request!\n"));
    620     connect(m_pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(sltHandleNetworkReplyProgress(qint64, qint64)));
    621     connect(m_pReply, SIGNAL(finished()), this, SLOT(sltHandleNetworkReplyFinish()));
    622 
    623     /* Set as running: */
    624     m_fRunning = true;
    625 
    626     /* Notify UINetworkRequestWidget: */
    627     emit sigStarted();
     184    /* Pass event to the base-class: */
     185    QMainWindow::keyPressEvent(pKeyPressEvent);
    628186}
    629187
    630 /* Cleanup network-reply: */
    631 void UINetworkRequest::cleanupNetworkReply()
    632 {
    633     /* Destroy current reply: */
    634     AssertMsg(m_pReply, ("Network-reply already destroyed!\n"));
    635     m_pReply->disconnect();
    636     m_pReply->deleteLater();
    637     m_pReply = 0;
    638 }
    639 
    640 /* Abort network-reply: */
    641 void UINetworkRequest::abortNetworkReply()
    642 {
    643     /* Abort network-reply if present: */
    644     if (m_pReply)
    645     {
    646         if (m_fRunning)
    647             m_pReply->abort();
    648         else
    649             emit sigCanceled(m_uuid);
    650     }
    651 }
    652 
    653 /* Instance: */
    654 UINetworkManager* UINetworkManager::m_pInstance = 0;
    655 
    656 /* Create singleton: */
    657 void UINetworkManager::create()
    658 {
    659     /* Check that instance do NOT exist: */
    660     if (m_pInstance)
    661         return;
    662 
    663     /* Create instance: */
    664     new UINetworkManager;
    665 }
    666 
    667 /* Destroy singleton: */
    668 void UINetworkManager::destroy()
    669 {
    670     /* Check that instance exists: */
    671     if (!m_pInstance)
    672         return;
    673 
    674     /* Destroy instance: */
    675     delete m_pInstance;
    676 }
    677 
    678 /* Network Access Manager GUI window: */
    679 QWidget* UINetworkManager::window() const
    680 {
    681     return m_pNetworkProgressDialog;
    682 }
    683 
    684 /* Show Network Access Manager GUI: */
    685 void UINetworkManager::show()
    686 {
    687     /* Just show the dialog: */
    688     m_pNetworkProgressDialog->showNormal();
    689 }
    690 
    691 /* Network-request creation wrapper for UINetworkCustomer: */
    692 void UINetworkManager::createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type,
    693                                             const QString &strDescription, UINetworkCustomer *pCustomer)
    694 {
    695     /* Create new network-request: */
    696     UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkProgressDialog,
    697                                                              request, type, strDescription, pCustomer);
    698     /* Prepare created network-request: */
    699     prepareNetworkRequest(pNetworkRequest);
    700 }
    701 
    702 /* Network request (set) creation wrapper for UINetworkCustomer: */
    703 void UINetworkManager::createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    704                                             const QString &strDescription, UINetworkCustomer *pCustomer)
    705 {
    706     /* Create new network-request: */
    707     UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkProgressDialog,
    708                                                              requests, type, strDescription, pCustomer);
    709     /* Prepare created network-request: */
    710     prepareNetworkRequest(pNetworkRequest);
    711 }
    712 
    713 /* Constructor: */
    714 UINetworkManager::UINetworkManager()
    715 {
    716     /* Prepare instance: */
    717     m_pInstance = this;
    718 
    719     /* Prepare finally: */
    720     prepare();
    721 }
    722 
    723 /* Destructor: */
    724 UINetworkManager::~UINetworkManager()
    725 {
    726     /* Cleanup first: */
    727     cleanup();
    728 
    729     /* Cleanup instance: */
    730     m_pInstance = 0;
    731 }
    732 
    733 /* Prepare: */
    734 void UINetworkManager::prepare()
    735 {
    736     /* Prepare network manager GUI: */
    737     m_pNetworkProgressDialog = new UINetworkManagerDialog;
    738 
    739     /* Prepare listeners for m_pNetworkProgressDialog: */
    740     connect(m_pNetworkProgressDialog, SIGNAL(sigCancelNetworkRequests()), this, SIGNAL(sigCancelNetworkRequests()));
    741 }
    742 
    743 /* Cleanup: */
    744 void UINetworkManager::cleanup()
    745 {
    746     /* Cleanup network-requests first: */
    747     cleanupNetworkRequests();
    748 
    749     /* Cleanup network manager GUI: */
    750     delete m_pNetworkProgressDialog;
    751 }
    752 
    753 /* Prepare network-request: */
    754 void UINetworkManager::prepareNetworkRequest(UINetworkRequest *pNetworkRequest)
    755 {
    756     /* Prepare listeners for pNetworkRequest: */
    757     connect(pNetworkRequest, SIGNAL(sigProgress(const QUuid&, qint64, qint64)), this, SLOT(sltHandleNetworkRequestProgress(const QUuid&, qint64, qint64)));
    758     connect(pNetworkRequest, SIGNAL(sigCanceled(const QUuid&)), this, SLOT(sltHandleNetworkRequestCancel(const QUuid&)));
    759     connect(pNetworkRequest, SIGNAL(sigFinished(const QUuid&)), this, SLOT(sltHandleNetworkRequestFinish(const QUuid&)));
    760     connect(pNetworkRequest, SIGNAL(sigFailed(const QUuid&, const QString&)), this, SLOT(sltHandleNetworkRequestFailure(const QUuid&, const QString&)));
    761 
    762     /* Add this request into internal map: */
    763     m_requests.insert(pNetworkRequest->uuid(), pNetworkRequest);
    764 }
    765 
    766 /* Cleanup network-request: */
    767 void UINetworkManager::cleanupNetworkRequest(QUuid uuid)
    768 {
    769     /* Cleanup network-request map: */
    770     delete m_requests[uuid];
    771     m_requests.remove(uuid);
    772 }
    773 
    774 /* Cleanup all network-requests: */
    775 void UINetworkManager::cleanupNetworkRequests()
    776 {
    777     /* Get all the request IDs: */
    778     const QList<QUuid> &uuids = m_requests.keys();
    779     /* Cleanup corresponding requests: */
    780     for (int i = 0; i < uuids.size(); ++i)
    781         cleanupNetworkRequest(uuids[i]);
    782 }
    783 
    784 /* Slot to handle network-request progress: */
    785 void UINetworkManager::sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
    786 {
    787     /* Make sure corresponding map contains received ID: */
    788     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    789 
    790     /* Get corresponding network-request: */
    791     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    792 
    793     /* Get corresponding customer: */
    794     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    795 
    796     /* Send to customer to process: */
    797     pNetworkCustomer->processNetworkReplyProgress(iReceived, iTotal);
    798 }
    799 
    800 /* Slot to handle network-request cancel: */
    801 void UINetworkManager::sltHandleNetworkRequestCancel(const QUuid &uuid)
    802 {
    803     /* Make sure corresponding map contains received ID: */
    804     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    805 
    806     /* Get corresponding network-request: */
    807     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    808 
    809     /* Get corresponding customer: */
    810     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    811 
    812     /* Send to customer to process: */
    813     pNetworkCustomer->processNetworkReplyCanceled(pNetworkRequest->reply());
    814 
    815     /* Cleanup network-request: */
    816     cleanupNetworkRequest(uuid);
    817 }
    818 
    819 /* Slot to handle network-request finish: */
    820 void UINetworkManager::sltHandleNetworkRequestFinish(const QUuid &uuid)
    821 {
    822     /* Make sure corresponding map contains received ID: */
    823     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    824 
    825     /* Get corresponding network-request: */
    826     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    827 
    828     /* Get corresponding customer: */
    829     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    830 
    831     /* Send to customer to process: */
    832     pNetworkCustomer->processNetworkReplyFinished(pNetworkRequest->reply());
    833 
    834     /* Cleanup network-request: */
    835     cleanupNetworkRequest(uuid);
    836 }
    837 
    838 /* Slot to handle network-request failure: */
    839 void UINetworkManager::sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &)
    840 {
    841     /* Make sure corresponding map contains received ID: */
    842     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    843 
    844     /* Get corresponding network-request: */
    845     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    846 
    847     /* Get corresponding customer: */
    848     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    849 
    850     /* If customer made a force-call: */
    851     if (pNetworkCustomer->isItForceCall())
    852     {
    853         /* Just show the dialog: */
    854         show();
    855     }
    856 }
    857 
    858 #include "UINetworkManager.moc"
    859 
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.h

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h58652,​70973
      /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h66309,​66318
      /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h70873
      /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h74233
    r41434 r41440  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * UINetworkManager stuff declaration
     4 * UINetworkManagerDialog stuff declaration
    55 */
    66
     
    1717 */
    1818
    19 #ifndef __UINetworkManager_h__
    20 #define __UINetworkManager_h__
     19#ifndef __UINetworkManagerDialog_h__
     20#define __UINetworkManagerDialog_h__
    2121
    2222/* Global includes: */
    23 #include <QNetworkAccessManager>
     23#include <QMainWindow>
     24#include <QMap>
    2425#include <QUuid>
    25 #include <QMap>
    26 #include <QNetworkRequest>
    27 #include <QNetworkReply>
    28 #include <QPointer>
    2926
    30 /* Local inludes: */
    31 #include "UINetworkDefs.h"
     27/* Local includes: */
     28#include "QIWithRetranslateUI.h"
    3229
    3330/* Forward declarations: */
    34 class UINetworkManager;
    35 class UINetworkCustomer;
     31class UINetworkRequest;
     32class QVBoxLayout;
     33class QLabel;
     34class QIDialogButtonBox;
    3635class UINetworkRequestWidget;
    37 class UINetworkManagerDialog;
    3836
    39 /* Network request contianer: */
    40 class UINetworkRequest : public QObject
     37/* QMainWindow reimplementation to reflect network-requests: */
     38class UINetworkManagerDialog : public QIWithRetranslateUI<QMainWindow>
    4139{
    4240    Q_OBJECT;
     
    4442signals:
    4543
    46     /* Notifications to UINetworkManager: */
    47     void sigProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
    48     void sigCanceled(const QUuid &uuid);
    49     void sigFinished(const QUuid &uuid);
    50     void sigFailed(const QUuid &uuid, const QString &strError);
     44    /* Ask listener (network-manager) to cancel all network-requests: */
     45    void sigCancelNetworkRequests();
    5146
    52     /* Notifications to UINetworkRequestWidget: */
    53     void sigProgress(qint64 iReceived, qint64 iTotal);
    54     void sigStarted();
    55     void sigFinished();
    56     void sigFailed(const QString &strError);
     47public slots:
    5748
    58 public:
     49    /* Show the dialog, make sure its visible: */
     50    void showNormal();
    5951
    60     /* Constructor/destructor: */
    61     UINetworkRequest(UINetworkManager *pNetworkManager,
    62                      UINetworkManagerDialog *pNetworkManagerDialog,
    63                      const QNetworkRequest &request, UINetworkRequestType type,
    64                      const QString &strDescription, UINetworkCustomer *pCustomer);
    65     UINetworkRequest(UINetworkManager *pNetworkManager,
    66                      UINetworkManagerDialog *pNetworkManagerDialog,
    67                      const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    68                      const QString &strDescription, UINetworkCustomer *pCustomer);
    69     ~UINetworkRequest();
     52protected:
    7053
    71     /* Getters: */
    72     const QUuid& uuid() const { return m_uuid; }
    73     const QString& description() const { return m_strDescription; }
    74     UINetworkCustomer* customer() { return m_pCustomer; }
    75     QNetworkReply* reply() { return m_pReply; }
     54    /* Allow creation of UINetworkManagerDialog to UINetworkManager: */
     55    friend class UINetworkManager;
     56    /* Constructor: */
     57    UINetworkManagerDialog();
     58
     59    /* Allow adding/removing network-request widgets to UINetworkRequest: */
     60    friend class UINetworkRequest;
     61    /* Add network-request widget: */
     62    UINetworkRequestWidget* addNetworkRequestWidget(UINetworkRequest *pNetworkRequest);
     63    /* Remove network-request widget: */
     64    void removeNetworkRequestWidget(const QUuid &uuid);
    7665
    7766private slots:
    7867
    79     /* Network-reply progress handler: */
    80     void sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal);
    81     /* Network-reply finish handler: */
    82     void sltHandleNetworkReplyFinish();
    83 
    84     /* Slot to retry network-request: */
    85     void sltRetry();
    86     /* Slot to cancel network-request: */
    87     void sltCancel();
     68    /* Handler for 'Cancel All' button-press: */
     69    void sltHandleCancelAllButtonPress();
    8870
    8971private:
    9072
    91     /* Initialize: */
    92     void initialize();
     73    /* Translation stuff: */
     74    void retranslateUi();
    9375
    94     /* Prepare network-reply: */
    95     void prepareNetworkReply();
    96     /* Cleanup network-reply: */
    97     void cleanupNetworkReply();
    98     /* Abort network-reply: */
    99     void abortNetworkReply();
     76    /* Overloaded event-handlers: */
     77    void showEvent(QShowEvent *pShowEvent);
     78    void keyPressEvent(QKeyEvent *pKeyPressEvent);
    10079
    10180    /* Widgets: */
    102     UINetworkManagerDialog *m_pNetworkManagerDialog;
    103     UINetworkRequestWidget *m_pNetworkRequestWidget;
    104 
    105     /* Variables: */
    106     QUuid m_uuid;
    107     QList<QNetworkRequest> m_requests;
    108     QNetworkRequest m_request;
    109     int m_iCurrentRequestIndex;
    110     UINetworkRequestType m_type;
    111     QString m_strDescription;
    112     UINetworkCustomer *m_pCustomer;
    113     QPointer<QNetworkReply> m_pReply;
    114     bool m_fRunning;
     81    QLabel *m_pLabel;
     82    QVBoxLayout *m_pWidgetsLayout;
     83    QIDialogButtonBox *m_pButtonBox;
     84    QMap<QUuid, UINetworkRequestWidget*> m_widgets;
    11585};
    11686
    117 /* QNetworkAccessManager class reimplementation providing
    118  * network access for the VirtualBox application purposes. */
    119 class UINetworkManager : public QNetworkAccessManager
    120 {
    121     Q_OBJECT;
     87#endif // __UINetworkManagerDialog_h__
    12288
    123 signals:
    124 
    125     /* Notification to UINetworkRequest: */
    126     void sigCancelNetworkRequests();
    127 
    128 public:
    129 
    130     /* Instance: */
    131     static UINetworkManager* instance() { return m_pInstance; }
    132 
    133     /* Create/destroy singleton: */
    134     static void create();
    135     static void destroy();
    136 
    137     /* Network Access Manager GUI window: */
    138     QWidget* window() const;
    139 
    140 public slots:
    141 
    142     /* Show Network Access Manager GUI: */
    143     void show();
    144 
    145 protected:
    146 
    147     /* Allow UINetworkCustomer to implicitly use next mothods: */
    148     friend class UINetworkCustomer;
    149     /* Network-request creation wrapper for UINetworkCustomer: */
    150     void createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type,
    151                               const QString &strDescription, UINetworkCustomer *pCustomer);
    152     /* Network request (set) creation wrapper for UINetworkCustomer: */
    153     void createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    154                               const QString &strDescription, UINetworkCustomer *pCustomer);
    155 
    156 private:
    157 
    158     /* Constructor/destructor: */
    159     UINetworkManager();
    160     ~UINetworkManager();
    161 
    162     /* Prepare/cleanup: */
    163     void prepare();
    164     void cleanup();
    165 
    166     /* Network-request prepare helper: */
    167     void prepareNetworkRequest(UINetworkRequest *pNetworkRequest);
    168     /* Network-request cleanup helper: */
    169     void cleanupNetworkRequest(QUuid uuid);
    170     /* Network-requests cleanup helper: */
    171     void cleanupNetworkRequests();
    172 
    173 private slots:
    174 
    175     /* Slot to handle network-request progress: */
    176     void sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
    177     /* Slot to handle network-request cancel: */
    178     void sltHandleNetworkRequestCancel(const QUuid &uuid);
    179     /* Slot to handle network-request finish: */
    180     void sltHandleNetworkRequestFinish(const QUuid &uuid);
    181     /* Slot to handle network-request failure: */
    182     void sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &strError);
    183 
    184 private:
    185 
    186     /* Instance: */
    187     static UINetworkManager *m_pInstance;
    188 
    189     /* Network-request map: */
    190     QMap<QUuid, UINetworkRequest*> m_requests;
    191 
    192     /* Network manager UI: */
    193     UINetworkManagerDialog *m_pNetworkProgressDialog;
    194 };
    195 #define gNetworkManager UINetworkManager::instance()
    196 
    197 #endif // __UINetworkManager_h__
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp58652,​70973
      /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp66309,​66318
      /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp70873
      /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp74233
    r41433 r41440  
    33 *
    44 * VBox frontends: Qt GUI ("VirtualBox"):
    5  * UINetworkManager stuff implementation
     5 * UINetworkRequest stuff implementation
    66 */
    77
     
    1919
    2020/* Global includes: */
    21 #include <QWidget>
    22 #include <QTimer>
    23 #include <QGridLayout>
    24 #include <QProgressBar>
    25 #include <QMainWindow>
    26 #include <QVBoxLayout>
    27 #include <QLabel>
    28 #include <QPushButton>
    29 #include <QStatusBar>
    30 #include <QKeyEvent>
    3121#include <QNetworkReply>
    3222
    3323/* Local includes: */
     24#include "UINetworkRequest.h"
     25#include "UINetworkRequestWidget.h"
    3426#include "UINetworkManager.h"
     27#include "UINetworkManagerDialog.h"
    3528#include "UINetworkCustomer.h"
    36 #include "QIWithRetranslateUI.h"
    3729#include "VBoxGlobal.h"
    38 #include "UIMessageCenter.h"
    39 #include "UIIconPool.h"
    40 #include "QIDialogButtonBox.h"
    41 #include "UIPopupBox.h"
    42 #include "QIToolButton.h"
    43 #include "QIRichTextLabel.h"
    44 
    45 /* Network-request widget: */
    46 class UINetworkRequestWidget : public QIWithRetranslateUI<UIPopupBox>
    47 {
    48     Q_OBJECT;
    49 
    50 signals:
    51 
    52     /* Signal to retry network-request: */
    53     void sigRetry();
    54     /* Signal to cancel network-request: */
    55     void sigCancel();
    56 
    57 public:
    58 
    59     /* Constructor: */
    60     UINetworkRequestWidget(QMainWindow *pParent, UINetworkRequest *pNetworkRequest)
    61         : QIWithRetranslateUI<UIPopupBox>(pParent)
    62         , m_pNetworkRequest(pNetworkRequest)
    63         , m_pTimer(new QTimer(this))
    64         , m_pContentWidget(new QWidget(this))
    65         , m_pMainLayout(new QGridLayout(m_pContentWidget))
    66         , m_pProgressBar(new QProgressBar(m_pContentWidget))
    67         , m_pRetryButton(new QIToolButton(m_pContentWidget))
    68         , m_pCancelButton(new QIToolButton(m_pContentWidget))
    69         , m_pErrorPane(new QIRichTextLabel(m_pContentWidget))
    70     {
    71         /* Setup self: */
    72         setTitleIcon(UIIconPool::iconSet(":/nw_16px.png"));
    73         setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    74         setContentWidget(m_pContentWidget);
    75         setOpen(true);
    76 
    77         /* Prepare listeners for m_pNetworkRequest: */
    78         connect(m_pNetworkRequest, SIGNAL(sigProgress(qint64, qint64)), this, SLOT(sltSetProgress(qint64, qint64)));
    79         connect(m_pNetworkRequest, SIGNAL(sigStarted()), this, SLOT(sltSetProgressToStarted()));
    80         connect(m_pNetworkRequest, SIGNAL(sigFinished()), this, SLOT(sltSetProgressToFinished()));
    81         connect(m_pNetworkRequest, SIGNAL(sigFailed(const QString&)), this, SLOT(sltSetProgressToFailed(const QString&)));
    82 
    83         /* Setup timer: */
    84         m_pTimer->setInterval(5000);
    85         connect(m_pTimer, SIGNAL(timeout()), this, SLOT(sltTimeIsOut()));
    86 
    87         /* Setup main-layout: */
    88         m_pMainLayout->setContentsMargins(6, 6, 6, 6);
    89 
    90         /* Setup progress-bar: */
    91         m_pProgressBar->setRange(0, 0);
    92         m_pProgressBar->setMaximumHeight(16);
    93 
    94         /* Setup retry-button: */
    95         m_pRetryButton->setHidden(true);
    96         m_pRetryButton->removeBorder();
    97         m_pRetryButton->setFocusPolicy(Qt::NoFocus);
    98         m_pRetryButton->setIcon(UIIconPool::iconSet(":/refresh_16px.png"));
    99         connect(m_pRetryButton, SIGNAL(clicked(bool)), this, SIGNAL(sigRetry()));
    100 
    101         /* Setup cancel-button: */
    102         m_pCancelButton->removeBorder();
    103         m_pCancelButton->setFocusPolicy(Qt::NoFocus);
    104         m_pCancelButton->setIcon(UIIconPool::iconSet(":/delete_16px.png"));
    105         connect(m_pCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(sigCancel()));
    106 
    107         /* Setup error-label: */
    108         m_pErrorPane->setHidden(true);
    109         m_pErrorPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    110         /* Calculate required width: */
    111         int iMinimumWidth = pParent->minimumWidth();
    112         int iLeft, iTop, iRight, iBottom;
    113         /* Take into account content-widget layout margins: */
    114         m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    115         iMinimumWidth -= iLeft;
    116         iMinimumWidth -= iRight;
    117         /* Take into account this layout margins: */
    118         layout()->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    119         iMinimumWidth -= iLeft;
    120         iMinimumWidth -= iRight;
    121         /* Take into account parent layout margins: */
    122         QLayout *pParentLayout = qobject_cast<QMainWindow*>(parent())->centralWidget()->layout();
    123         pParentLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    124         iMinimumWidth -= iLeft;
    125         iMinimumWidth -= iRight;
    126         /* Set minimum text width: */
    127         m_pErrorPane->setMinimumTextWidth(iMinimumWidth);
    128 
    129         /* Layout content: */
    130         m_pMainLayout->addWidget(m_pProgressBar, 0, 0);
    131         m_pMainLayout->addWidget(m_pRetryButton, 0, 1);
    132         m_pMainLayout->addWidget(m_pCancelButton, 0, 2);
    133         m_pMainLayout->addWidget(m_pErrorPane, 1, 0, 1, 3);
    134 
    135         /* Retranslate UI: */
    136         retranslateUi();
    137     }
    138 
    139 private slots:
    140 
    141     /* Retranslate UI: */
    142     void retranslateUi()
    143     {
    144         /* Get corresponding title: */
    145         const QString &strTitle = m_pNetworkRequest->description();
    146 
    147         /* Set popup title (default if missed): */
    148         setTitle(strTitle.isEmpty() ? UINetworkManager::tr("Network Operation") : strTitle);
    149 
    150         /* Translate retry button: */
    151         m_pRetryButton->setStatusTip(UINetworkManager::tr("Restart network operation"));
    152 
    153         /* Translate cancel button: */
    154         m_pCancelButton->setStatusTip(UINetworkManager::tr("Cancel network operation"));
    155     }
    156 
    157     /* Updates current network-request progess: */
    158     void sltSetProgress(qint64 iReceived, qint64 iTotal)
    159     {
    160         /* Restart timer: */
    161         m_pTimer->start();
    162 
    163         /* Set current progress to passed: */
    164         m_pProgressBar->setRange(0, iTotal);
    165         m_pProgressBar->setValue(iReceived);
    166     }
    167 
    168     /* Set current network-request progress to 'started': */
    169     void sltSetProgressToStarted()
    170     {
    171         /* Start timer: */
    172         m_pTimer->start();
    173 
    174         /* Set current progress to 'started': */
    175         m_pProgressBar->setRange(0, 1);
    176         m_pProgressBar->setValue(0);
    177 
    178         /* Hide 'retry' button: */
    179         m_pRetryButton->setHidden(true);
    180 
    181         /* Hide error label: */
    182         m_pErrorPane->setHidden(true);
    183         m_pErrorPane->setText(QString());
    184     }
    185 
    186     /* Set current network-request progress to 'finished': */
    187     void sltSetProgressToFinished()
    188     {
    189         /* Stop timer: */
    190         m_pTimer->stop();
    191 
    192         /* Set current progress to 'started': */
    193         m_pProgressBar->setRange(0, 1);
    194         m_pProgressBar->setValue(1);
    195     }
    196 
    197     /* Set current network-request progress to 'failed': */
    198     void sltSetProgressToFailed(const QString &strError)
    199     {
    200         /* Stop timer: */
    201         m_pTimer->stop();
    202 
    203         /* Set current progress to 'failed': */
    204         m_pProgressBar->setRange(0, 1);
    205         m_pProgressBar->setValue(1);
    206 
    207         /* Show 'retry' button: */
    208         m_pRetryButton->setHidden(false);
    209 
    210         /* Try to find all the links in the error-message,
    211          * replace them with %increment if present: */
    212         QString strErrorText(strError);
    213         QRegExp linkRegExp("[\\S]+[\\./][\\S]+");
    214         QStringList links;
    215         for (int i = 1; linkRegExp.indexIn(strErrorText) != -1; ++i)
    216         {
    217             links << linkRegExp.cap();
    218             strErrorText.replace(linkRegExp.cap(), QString("%%1").arg(i));
    219         }
    220         /* Return back all the links, just in bold: */
    221         if (!links.isEmpty())
    222             for (int i = 0; i < links.size(); ++i)
    223                 strErrorText = strErrorText.arg(QString("<b>%1</b>").arg(links[i]));
    224 
    225         /* Show error label: */
    226         m_pErrorPane->setHidden(false);
    227         m_pErrorPane->setText(UINetworkManager::tr("Error: %1.").arg(strErrorText));
    228     }
    229 
    230     /* Handle frozen progress: */
    231     void sltTimeIsOut()
    232     {
    233         /* Stop timer: */
    234         m_pTimer->stop();
    235 
    236         /* Set current progress to unknown: */
    237         m_pProgressBar->setRange(0, 0);
    238     }
    239 
    240 private:
    241 
    242     /* Objects: */
    243     UINetworkRequest *m_pNetworkRequest;
    244     QTimer *m_pTimer;
    245 
    246     /* Widgets: */
    247     QWidget *m_pContentWidget;
    248     QGridLayout *m_pMainLayout;
    249     QProgressBar *m_pProgressBar;
    250     QIToolButton *m_pRetryButton;
    251     QIToolButton *m_pCancelButton;
    252     QIRichTextLabel *m_pErrorPane;
    253 };
    254 
    255 /* Network requests dialog: */
    256 class UINetworkManagerDialog : public QIWithRetranslateUI<QMainWindow>
    257 {
    258     Q_OBJECT;
    259 
    260 signals:
    261 
    262     /* Signal to cancel all network-requests: */
    263     void sigCancelNetworkRequests();
    264 
    265 public slots:
    266 
    267     /* Show the dialog, make sure its visible: */
    268     void showNormal()
    269     {
    270         /* Show (restore if neessary): */
    271         QMainWindow::showNormal();
    272 
    273         /* Raise above the others: */
    274         raise();
    275 
    276         /* Activate: */
    277         activateWindow();
    278     }
    279 
    280 public:
    281 
    282     /* Constructor: */
    283     UINetworkManagerDialog()
    284     {
    285         /* Do not count that window as important for application,
    286          * it will NOT be taken into account when other top-level windows will be closed: */
    287         setAttribute(Qt::WA_QuitOnClose, false);
    288 
    289         /* Set minimum width: */
    290         setMinimumWidth(500);
    291 
    292         /* Prepare central-widget: */
    293         setCentralWidget(new QWidget);
    294 
    295         /* Create main-layout: */
    296         m_pMainLayout = new QVBoxLayout(centralWidget());
    297         m_pMainLayout->setContentsMargins(6, 6, 6, 6);
    298 
    299         /* Create description-label: */
    300         m_pLabel = new QLabel(centralWidget());
    301         m_pLabel->setAlignment(Qt::AlignCenter);
    302         m_pLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    303 
    304         /* Create button-box: */
    305         m_pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, centralWidget());
    306         connect(m_pButtonBox, SIGNAL(rejected()), this, SLOT(sltHandleCancelAllButtonPress()));
    307         m_pButtonBox->setHidden(true);
    308 
    309         /* Layout content: */
    310         m_pMainLayout->addWidget(m_pLabel);
    311         m_pMainLayout->addStretch();
    312         m_pMainLayout->addWidget(m_pButtonBox);
    313 
    314         /* Create status-bar: */
    315         setStatusBar(new QStatusBar);
    316 
    317         /* Translate dialog: */
    318         retranslateUi();
    319     }
    320 
    321     /* Add network-request widget: */
    322     UINetworkRequestWidget* addNetworkRequestWidget(UINetworkRequest *pNetworkRequest)
    323     {
    324         /* Make sure network-request is really exists: */
    325         AssertMsg(pNetworkRequest, ("Network-request doesn't exists!\n"));
    326 
    327         /* Create new network-request widget: */
    328         UINetworkRequestWidget *pNetworkRequestWidget = new UINetworkRequestWidget(this, pNetworkRequest);
    329         m_pMainLayout->insertWidget(m_pMainLayout->count() - 2 /* before button-box and stretch */, pNetworkRequestWidget);
    330         m_widgets.insert(pNetworkRequest->uuid(), pNetworkRequestWidget);
    331 
    332         /* Hide label: */
    333         m_pLabel->setHidden(true);
    334         /* Show button-box: */
    335         m_pButtonBox->setHidden(false);
    336         /* If customer made a force-call: */
    337         if (pNetworkRequest->customer()->isItForceCall())
    338         {
    339             /* Show dialog: */
    340             showNormal();
    341         }
    342 
    343         /* Return network-request widget: */
    344         return pNetworkRequestWidget;
    345     }
    346 
    347     /* Remove network-request widget: */
    348     void removeNetworkRequestWidget(const QUuid &uuid)
    349     {
    350         /* Make sure network-request widget still present: */
    351         AssertMsg(m_widgets.contains(uuid), ("Network-request widget already removed!\n"));
    352 
    353         /* Delete corresponding network-request widget: */
    354         delete m_widgets.value(uuid);
    355         m_widgets.remove(uuid);
    356 
    357         /* Check if dialog is empty: */
    358         if (m_widgets.isEmpty())
    359         {
    360             /* Show label: */
    361             m_pLabel->setHidden(false);
    362             /* Hide button-box: */
    363             m_pButtonBox->setHidden(true);
    364             /* Let central-widget update its layout before being hidden: */
    365             QCoreApplication::sendPostedEvents(centralWidget(), QEvent::LayoutRequest);
    366             /* Hide dialog: */
    367             hide();
    368         }
    369     }
    370 
    371 private slots:
    372 
    373     /* Handler for 'Cancel All' button press: */
    374     void sltHandleCancelAllButtonPress()
    375     {
    376         /* Ask if user wants to cancel all current network-requests: */
    377         if (msgCenter().askAboutCancelAllNetworkRequest(this))
    378             emit sigCancelNetworkRequests();
    379     }
    380 
    381 private:
    382 
    383     /* Translate whole dialog: */
    384     void retranslateUi()
    385     {
    386         /* Set window caption: */
    387         setWindowTitle(UINetworkManager::tr("Network Operations Manager"));
    388 
    389         /* Set description-label text: */
    390         m_pLabel->setText(UINetworkManager::tr("There are no active network operations."));
    391 
    392         /* Set buttons-box text: */
    393         m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("&Cancel All"));
    394         m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Cancel all active network operations"));
    395     }
    396 
    397     /* Overloaded show-event: */
    398     void showEvent(QShowEvent *pShowEvent)
    399     {
    400         /* Resize to minimum size-hint: */
    401         resize(minimumSizeHint());
    402 
    403         /* Center according current main application window: */
    404         vboxGlobal().centerWidget(this, vboxGlobal().mainWindow(), false);
    405 
    406         /* Pass event to the base-class: */
    407         QMainWindow::showEvent(pShowEvent);
    408     }
    409 
    410     /* Overloaded keypress-event: */
    411     void keyPressEvent(QKeyEvent *pKeyPressEvent)
    412     {
    413         /* 'Escape' key used to close the dialog: */
    414         if (pKeyPressEvent->key() == Qt::Key_Escape)
    415         {
    416             close();
    417             return;
    418         }
    419 
    420         /* Pass event to the base-class: */
    421         QMainWindow::keyPressEvent(pKeyPressEvent);
    422     }
    423 
    424     /* Main layout: */
    425     QVBoxLayout *m_pMainLayout;
    426     QLabel *m_pLabel;
    427     QIDialogButtonBox *m_pButtonBox;
    428 
    429     /* Popup-widget map: */
    430     QMap<QUuid, UINetworkRequestWidget*> m_widgets;
    431 };
    43230
    43331/* Constructor: */
     
    48381void UINetworkRequest::sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal)
    48482{
    485     /* Notify UINetworkManager: */
     83    /* Notify network-manager: */
    48684    emit sigProgress(m_uuid, iReceived, iTotal);
    487     /* Notify UINetworkRequestWidget: */
     85    /* Notify network-request widget: */
    48886    emit sigProgress(iReceived, iTotal);
    48987}
     
    49593    m_fRunning = false;
    49694
    497     /* Get sender network reply: */
     95    /* Get sender network-reply: */
    49896    QNetworkReply *pNetworkReply = static_cast<QNetworkReply*>(sender());
    49997
     
    50199    if (pNetworkReply->error() == QNetworkReply::OperationCanceledError)
    502100    {
    503         /* Notify UINetworkManager: */
     101        /* Notify network-manager: */
    504102        emit sigCanceled(m_uuid);
    505103    }
     
    651249}
    652250
    653 /* Instance: */
    654 UINetworkManager* UINetworkManager::m_pInstance = 0;
    655 
    656 /* Create singleton: */
    657 void UINetworkManager::create()
    658 {
    659     /* Check that instance do NOT exist: */
    660     if (m_pInstance)
    661         return;
    662 
    663     /* Create instance: */
    664     new UINetworkManager;
    665 }
    666 
    667 /* Destroy singleton: */
    668 void UINetworkManager::destroy()
    669 {
    670     /* Check that instance exists: */
    671     if (!m_pInstance)
    672         return;
    673 
    674     /* Destroy instance: */
    675     delete m_pInstance;
    676 }
    677 
    678 /* Network Access Manager GUI window: */
    679 QWidget* UINetworkManager::window() const
    680 {
    681     return m_pNetworkProgressDialog;
    682 }
    683 
    684 /* Show Network Access Manager GUI: */
    685 void UINetworkManager::show()
    686 {
    687     /* Just show the dialog: */
    688     m_pNetworkProgressDialog->showNormal();
    689 }
    690 
    691 /* Network-request creation wrapper for UINetworkCustomer: */
    692 void UINetworkManager::createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type,
    693                                             const QString &strDescription, UINetworkCustomer *pCustomer)
    694 {
    695     /* Create new network-request: */
    696     UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkProgressDialog,
    697                                                              request, type, strDescription, pCustomer);
    698     /* Prepare created network-request: */
    699     prepareNetworkRequest(pNetworkRequest);
    700 }
    701 
    702 /* Network request (set) creation wrapper for UINetworkCustomer: */
    703 void UINetworkManager::createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    704                                             const QString &strDescription, UINetworkCustomer *pCustomer)
    705 {
    706     /* Create new network-request: */
    707     UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkProgressDialog,
    708                                                              requests, type, strDescription, pCustomer);
    709     /* Prepare created network-request: */
    710     prepareNetworkRequest(pNetworkRequest);
    711 }
    712 
    713 /* Constructor: */
    714 UINetworkManager::UINetworkManager()
    715 {
    716     /* Prepare instance: */
    717     m_pInstance = this;
    718 
    719     /* Prepare finally: */
    720     prepare();
    721 }
    722 
    723 /* Destructor: */
    724 UINetworkManager::~UINetworkManager()
    725 {
    726     /* Cleanup first: */
    727     cleanup();
    728 
    729     /* Cleanup instance: */
    730     m_pInstance = 0;
    731 }
    732 
    733 /* Prepare: */
    734 void UINetworkManager::prepare()
    735 {
    736     /* Prepare network manager GUI: */
    737     m_pNetworkProgressDialog = new UINetworkManagerDialog;
    738 
    739     /* Prepare listeners for m_pNetworkProgressDialog: */
    740     connect(m_pNetworkProgressDialog, SIGNAL(sigCancelNetworkRequests()), this, SIGNAL(sigCancelNetworkRequests()));
    741 }
    742 
    743 /* Cleanup: */
    744 void UINetworkManager::cleanup()
    745 {
    746     /* Cleanup network-requests first: */
    747     cleanupNetworkRequests();
    748 
    749     /* Cleanup network manager GUI: */
    750     delete m_pNetworkProgressDialog;
    751 }
    752 
    753 /* Prepare network-request: */
    754 void UINetworkManager::prepareNetworkRequest(UINetworkRequest *pNetworkRequest)
    755 {
    756     /* Prepare listeners for pNetworkRequest: */
    757     connect(pNetworkRequest, SIGNAL(sigProgress(const QUuid&, qint64, qint64)), this, SLOT(sltHandleNetworkRequestProgress(const QUuid&, qint64, qint64)));
    758     connect(pNetworkRequest, SIGNAL(sigCanceled(const QUuid&)), this, SLOT(sltHandleNetworkRequestCancel(const QUuid&)));
    759     connect(pNetworkRequest, SIGNAL(sigFinished(const QUuid&)), this, SLOT(sltHandleNetworkRequestFinish(const QUuid&)));
    760     connect(pNetworkRequest, SIGNAL(sigFailed(const QUuid&, const QString&)), this, SLOT(sltHandleNetworkRequestFailure(const QUuid&, const QString&)));
    761 
    762     /* Add this request into internal map: */
    763     m_requests.insert(pNetworkRequest->uuid(), pNetworkRequest);
    764 }
    765 
    766 /* Cleanup network-request: */
    767 void UINetworkManager::cleanupNetworkRequest(QUuid uuid)
    768 {
    769     /* Cleanup network-request map: */
    770     delete m_requests[uuid];
    771     m_requests.remove(uuid);
    772 }
    773 
    774 /* Cleanup all network-requests: */
    775 void UINetworkManager::cleanupNetworkRequests()
    776 {
    777     /* Get all the request IDs: */
    778     const QList<QUuid> &uuids = m_requests.keys();
    779     /* Cleanup corresponding requests: */
    780     for (int i = 0; i < uuids.size(); ++i)
    781         cleanupNetworkRequest(uuids[i]);
    782 }
    783 
    784 /* Slot to handle network-request progress: */
    785 void UINetworkManager::sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
    786 {
    787     /* Make sure corresponding map contains received ID: */
    788     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    789 
    790     /* Get corresponding network-request: */
    791     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    792 
    793     /* Get corresponding customer: */
    794     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    795 
    796     /* Send to customer to process: */
    797     pNetworkCustomer->processNetworkReplyProgress(iReceived, iTotal);
    798 }
    799 
    800 /* Slot to handle network-request cancel: */
    801 void UINetworkManager::sltHandleNetworkRequestCancel(const QUuid &uuid)
    802 {
    803     /* Make sure corresponding map contains received ID: */
    804     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    805 
    806     /* Get corresponding network-request: */
    807     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    808 
    809     /* Get corresponding customer: */
    810     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    811 
    812     /* Send to customer to process: */
    813     pNetworkCustomer->processNetworkReplyCanceled(pNetworkRequest->reply());
    814 
    815     /* Cleanup network-request: */
    816     cleanupNetworkRequest(uuid);
    817 }
    818 
    819 /* Slot to handle network-request finish: */
    820 void UINetworkManager::sltHandleNetworkRequestFinish(const QUuid &uuid)
    821 {
    822     /* Make sure corresponding map contains received ID: */
    823     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    824 
    825     /* Get corresponding network-request: */
    826     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    827 
    828     /* Get corresponding customer: */
    829     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    830 
    831     /* Send to customer to process: */
    832     pNetworkCustomer->processNetworkReplyFinished(pNetworkRequest->reply());
    833 
    834     /* Cleanup network-request: */
    835     cleanupNetworkRequest(uuid);
    836 }
    837 
    838 /* Slot to handle network-request failure: */
    839 void UINetworkManager::sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &)
    840 {
    841     /* Make sure corresponding map contains received ID: */
    842     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    843 
    844     /* Get corresponding network-request: */
    845     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    846 
    847     /* Get corresponding customer: */
    848     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    849 
    850     /* If customer made a force-call: */
    851     if (pNetworkCustomer->isItForceCall())
    852     {
    853         /* Just show the dialog: */
    854         show();
    855     }
    856 }
    857 
    858 #include "UINetworkManager.moc"
    859 
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.h

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h58652,​70973
      /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h66309,​66318
      /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h70873
      /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h74233
    r41433 r41440  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * UINetworkManager stuff declaration
     4 * UINetworkRequest stuff declaration
    55 */
    66
     
    1717 */
    1818
    19 #ifndef __UINetworkManager_h__
    20 #define __UINetworkManager_h__
     19#ifndef __UINetworkRequest_h__
     20#define __UINetworkRequest_h__
    2121
    2222/* Global includes: */
    23 #include <QNetworkAccessManager>
    2423#include <QUuid>
    25 #include <QMap>
    2624#include <QNetworkRequest>
    2725#include <QNetworkReply>
     
    3331/* Forward declarations: */
    3432class UINetworkManager;
     33class UINetworkManagerDialog;
     34class UINetworkRequestWidget;
    3535class UINetworkCustomer;
    36 class UINetworkRequestWidget;
    37 class UINetworkManagerDialog;
    3836
    39 /* Network request contianer: */
     37/* Network-request contianer: */
    4038class UINetworkRequest : public QObject
    4139{
     
    115113};
    116114
    117 /* QNetworkAccessManager class reimplementation providing
    118  * network access for the VirtualBox application purposes. */
    119 class UINetworkManager : public QNetworkAccessManager
    120 {
    121     Q_OBJECT;
    122 
    123 signals:
    124 
    125     /* Notification to UINetworkRequest: */
    126     void sigCancelNetworkRequests();
    127 
    128 public:
    129 
    130     /* Instance: */
    131     static UINetworkManager* instance() { return m_pInstance; }
    132 
    133     /* Create/destroy singleton: */
    134     static void create();
    135     static void destroy();
    136 
    137     /* Network Access Manager GUI window: */
    138     QWidget* window() const;
    139 
    140 public slots:
    141 
    142     /* Show Network Access Manager GUI: */
    143     void show();
    144 
    145 protected:
    146 
    147     /* Allow UINetworkCustomer to implicitly use next mothods: */
    148     friend class UINetworkCustomer;
    149     /* Network-request creation wrapper for UINetworkCustomer: */
    150     void createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type,
    151                               const QString &strDescription, UINetworkCustomer *pCustomer);
    152     /* Network request (set) creation wrapper for UINetworkCustomer: */
    153     void createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    154                               const QString &strDescription, UINetworkCustomer *pCustomer);
    155 
    156 private:
    157 
    158     /* Constructor/destructor: */
    159     UINetworkManager();
    160     ~UINetworkManager();
    161 
    162     /* Prepare/cleanup: */
    163     void prepare();
    164     void cleanup();
    165 
    166     /* Network-request prepare helper: */
    167     void prepareNetworkRequest(UINetworkRequest *pNetworkRequest);
    168     /* Network-request cleanup helper: */
    169     void cleanupNetworkRequest(QUuid uuid);
    170     /* Network-requests cleanup helper: */
    171     void cleanupNetworkRequests();
    172 
    173 private slots:
    174 
    175     /* Slot to handle network-request progress: */
    176     void sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
    177     /* Slot to handle network-request cancel: */
    178     void sltHandleNetworkRequestCancel(const QUuid &uuid);
    179     /* Slot to handle network-request finish: */
    180     void sltHandleNetworkRequestFinish(const QUuid &uuid);
    181     /* Slot to handle network-request failure: */
    182     void sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &strError);
    183 
    184 private:
    185 
    186     /* Instance: */
    187     static UINetworkManager *m_pInstance;
    188 
    189     /* Network-request map: */
    190     QMap<QUuid, UINetworkRequest*> m_requests;
    191 
    192     /* Network manager UI: */
    193     UINetworkManagerDialog *m_pNetworkProgressDialog;
    194 };
    195 #define gNetworkManager UINetworkManager::instance()
    196 
    197 #endif // __UINetworkManager_h__
     115#endif // __UINetworkRequest_h__
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp58652,​70973
      /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp66309,​66318
      /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp70873
      /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp74233
    r41435 r41440  
    33 *
    44 * VBox frontends: Qt GUI ("VirtualBox"):
    5  * UINetworkManager stuff implementation
     5 * UINetworkRequestWidget stuff implementation
    66 */
    77
     
    1919
    2020/* Global includes: */
    21 #include <QWidget>
    2221#include <QTimer>
    2322#include <QGridLayout>
    2423#include <QProgressBar>
    25 #include <QMainWindow>
    26 #include <QVBoxLayout>
    27 #include <QLabel>
    28 #include <QPushButton>
    29 #include <QStatusBar>
    30 #include <QKeyEvent>
    31 #include <QNetworkReply>
    3224
    3325/* Local includes: */
     26#include "UINetworkRequestWidget.h"
     27#include "UINetworkRequest.h"
    3428#include "UINetworkManager.h"
    35 #include "UINetworkCustomer.h"
    36 #include "QIWithRetranslateUI.h"
    37 #include "VBoxGlobal.h"
    38 #include "UIMessageCenter.h"
     29#include "UINetworkManagerDialog.h"
    3930#include "UIIconPool.h"
    40 #include "QIDialogButtonBox.h"
    41 #include "UIPopupBox.h"
    4231#include "QIToolButton.h"
    4332#include "QIRichTextLabel.h"
    4433
    45 /* Network-request widget: */
    46 class UINetworkRequestWidget : public QIWithRetranslateUI<UIPopupBox>
    47 {
    48     Q_OBJECT;
    49 
    50 signals:
    51 
    52     /* Signal to retry network-request: */
    53     void sigRetry();
    54     /* Signal to cancel network-request: */
    55     void sigCancel();
    56 
    57 public:
    58 
    59     /* Constructor: */
    60     UINetworkRequestWidget(QMainWindow *pParent, UINetworkRequest *pNetworkRequest)
    61         : QIWithRetranslateUI<UIPopupBox>(pParent)
    62         , m_pNetworkRequest(pNetworkRequest)
    63         , m_pTimer(new QTimer(this))
    64         , m_pContentWidget(new QWidget(this))
    65         , m_pMainLayout(new QGridLayout(m_pContentWidget))
    66         , m_pProgressBar(new QProgressBar(m_pContentWidget))
    67         , m_pRetryButton(new QIToolButton(m_pContentWidget))
    68         , m_pCancelButton(new QIToolButton(m_pContentWidget))
    69         , m_pErrorPane(new QIRichTextLabel(m_pContentWidget))
     34UINetworkRequestWidget::UINetworkRequestWidget(UINetworkManagerDialog *pParent, UINetworkRequest *pNetworkRequest)
     35    : QIWithRetranslateUI<UIPopupBox>(pParent)
     36    , m_pContentWidget(new QWidget(this))
     37    , m_pMainLayout(new QGridLayout(m_pContentWidget))
     38    , m_pProgressBar(new QProgressBar(m_pContentWidget))
     39    , m_pRetryButton(new QIToolButton(m_pContentWidget))
     40    , m_pCancelButton(new QIToolButton(m_pContentWidget))
     41    , m_pErrorPane(new QIRichTextLabel(m_pContentWidget))
     42    , m_pNetworkRequest(pNetworkRequest)
     43    , m_pTimer(new QTimer(this))
     44{
     45    /* Setup self: */
     46    setTitleIcon(UIIconPool::iconSet(":/nw_16px.png"));
     47    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
     48    setContentWidget(m_pContentWidget);
     49    setOpen(true);
     50
     51    /* Prepare listeners for m_pNetworkRequest: */
     52    connect(m_pNetworkRequest, SIGNAL(sigProgress(qint64, qint64)), this, SLOT(sltSetProgress(qint64, qint64)));
     53    connect(m_pNetworkRequest, SIGNAL(sigStarted()), this, SLOT(sltSetProgressToStarted()));
     54    connect(m_pNetworkRequest, SIGNAL(sigFinished()), this, SLOT(sltSetProgressToFinished()));
     55    connect(m_pNetworkRequest, SIGNAL(sigFailed(const QString&)), this, SLOT(sltSetProgressToFailed(const QString&)));
     56
     57    /* Setup timer: */
     58    m_pTimer->setInterval(5000);
     59    connect(m_pTimer, SIGNAL(timeout()), this, SLOT(sltTimeIsOut()));
     60
     61    /* Setup main-layout: */
     62    m_pMainLayout->setContentsMargins(6, 6, 6, 6);
     63
     64    /* Setup progress-bar: */
     65    m_pProgressBar->setRange(0, 0);
     66    m_pProgressBar->setMaximumHeight(16);
     67
     68    /* Setup retry-button: */
     69    m_pRetryButton->setHidden(true);
     70    m_pRetryButton->removeBorder();
     71    m_pRetryButton->setFocusPolicy(Qt::NoFocus);
     72    m_pRetryButton->setIcon(UIIconPool::iconSet(":/refresh_16px.png"));
     73    connect(m_pRetryButton, SIGNAL(clicked(bool)), this, SIGNAL(sigRetry()));
     74
     75    /* Setup cancel-button: */
     76    m_pCancelButton->removeBorder();
     77    m_pCancelButton->setFocusPolicy(Qt::NoFocus);
     78    m_pCancelButton->setIcon(UIIconPool::iconSet(":/delete_16px.png"));
     79    connect(m_pCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(sigCancel()));
     80
     81    /* Setup error-label: */
     82    m_pErrorPane->setHidden(true);
     83    m_pErrorPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
     84    /* Calculate required width: */
     85    int iMinimumWidth = pParent->minimumWidth();
     86    int iLeft, iTop, iRight, iBottom;
     87    /* Take into account content-widget layout margins: */
     88    m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
     89    iMinimumWidth -= iLeft;
     90    iMinimumWidth -= iRight;
     91    /* Take into account this layout margins: */
     92    layout()->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
     93    iMinimumWidth -= iLeft;
     94    iMinimumWidth -= iRight;
     95    /* Take into account parent layout margins: */
     96    QLayout *pParentLayout = qobject_cast<QMainWindow*>(parent())->centralWidget()->layout();
     97    pParentLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
     98    iMinimumWidth -= iLeft;
     99    iMinimumWidth -= iRight;
     100    /* Set minimum text width: */
     101    m_pErrorPane->setMinimumTextWidth(iMinimumWidth);
     102
     103    /* Layout content: */
     104    m_pMainLayout->addWidget(m_pProgressBar, 0, 0);
     105    m_pMainLayout->addWidget(m_pRetryButton, 0, 1);
     106    m_pMainLayout->addWidget(m_pCancelButton, 0, 2);
     107    m_pMainLayout->addWidget(m_pErrorPane, 1, 0, 1, 3);
     108
     109    /* Retranslate UI: */
     110    retranslateUi();
     111}
     112
     113void UINetworkRequestWidget::sltSetProgress(qint64 iReceived, qint64 iTotal)
     114{
     115    /* Restart timer: */
     116    m_pTimer->start();
     117
     118    /* Set current progress to passed: */
     119    m_pProgressBar->setRange(0, iTotal);
     120    m_pProgressBar->setValue(iReceived);
     121}
     122
     123void UINetworkRequestWidget::sltSetProgressToStarted()
     124{
     125    /* Start timer: */
     126    m_pTimer->start();
     127
     128    /* Set current progress to 'started': */
     129    m_pProgressBar->setRange(0, 1);
     130    m_pProgressBar->setValue(0);
     131
     132    /* Hide 'retry' button: */
     133    m_pRetryButton->setHidden(true);
     134
     135    /* Hide error label: */
     136    m_pErrorPane->setHidden(true);
     137    m_pErrorPane->setText(QString());
     138}
     139
     140void UINetworkRequestWidget::sltSetProgressToFinished()
     141{
     142    /* Stop timer: */
     143    m_pTimer->stop();
     144
     145    /* Set current progress to 'started': */
     146    m_pProgressBar->setRange(0, 1);
     147    m_pProgressBar->setValue(1);
     148}
     149
     150void UINetworkRequestWidget::sltSetProgressToFailed(const QString &strError)
     151{
     152    /* Stop timer: */
     153    m_pTimer->stop();
     154
     155    /* Set current progress to 'failed': */
     156    m_pProgressBar->setRange(0, 1);
     157    m_pProgressBar->setValue(1);
     158
     159    /* Show 'retry' button: */
     160    m_pRetryButton->setHidden(false);
     161
     162    /* Try to find all the links in the error-message,
     163     * replace them with %increment if present: */
     164    QString strErrorText(strError);
     165    QRegExp linkRegExp("[\\S]+[\\./][\\S]+");
     166    QStringList links;
     167    for (int i = 1; linkRegExp.indexIn(strErrorText) != -1; ++i)
    70168    {
    71         /* Setup self: */
    72         setTitleIcon(UIIconPool::iconSet(":/nw_16px.png"));
    73         setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    74         setContentWidget(m_pContentWidget);
    75         setOpen(true);
    76 
    77         /* Prepare listeners for m_pNetworkRequest: */
    78         connect(m_pNetworkRequest, SIGNAL(sigProgress(qint64, qint64)), this, SLOT(sltSetProgress(qint64, qint64)));
    79         connect(m_pNetworkRequest, SIGNAL(sigStarted()), this, SLOT(sltSetProgressToStarted()));
    80         connect(m_pNetworkRequest, SIGNAL(sigFinished()), this, SLOT(sltSetProgressToFinished()));
    81         connect(m_pNetworkRequest, SIGNAL(sigFailed(const QString&)), this, SLOT(sltSetProgressToFailed(const QString&)));
    82 
    83         /* Setup timer: */
    84         m_pTimer->setInterval(5000);
    85         connect(m_pTimer, SIGNAL(timeout()), this, SLOT(sltTimeIsOut()));
    86 
    87         /* Setup main-layout: */
    88         m_pMainLayout->setContentsMargins(6, 6, 6, 6);
    89 
    90         /* Setup progress-bar: */
    91         m_pProgressBar->setRange(0, 0);
    92         m_pProgressBar->setMaximumHeight(16);
    93 
    94         /* Setup retry-button: */
    95         m_pRetryButton->setHidden(true);
    96         m_pRetryButton->removeBorder();
    97         m_pRetryButton->setFocusPolicy(Qt::NoFocus);
    98         m_pRetryButton->setIcon(UIIconPool::iconSet(":/refresh_16px.png"));
    99         connect(m_pRetryButton, SIGNAL(clicked(bool)), this, SIGNAL(sigRetry()));
    100 
    101         /* Setup cancel-button: */
    102         m_pCancelButton->removeBorder();
    103         m_pCancelButton->setFocusPolicy(Qt::NoFocus);
    104         m_pCancelButton->setIcon(UIIconPool::iconSet(":/delete_16px.png"));
    105         connect(m_pCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(sigCancel()));
    106 
    107         /* Setup error-label: */
    108         m_pErrorPane->setHidden(true);
    109         m_pErrorPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    110         /* Calculate required width: */
    111         int iMinimumWidth = pParent->minimumWidth();
    112         int iLeft, iTop, iRight, iBottom;
    113         /* Take into account content-widget layout margins: */
    114         m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    115         iMinimumWidth -= iLeft;
    116         iMinimumWidth -= iRight;
    117         /* Take into account this layout margins: */
    118         layout()->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    119         iMinimumWidth -= iLeft;
    120         iMinimumWidth -= iRight;
    121         /* Take into account parent layout margins: */
    122         QLayout *pParentLayout = qobject_cast<QMainWindow*>(parent())->centralWidget()->layout();
    123         pParentLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    124         iMinimumWidth -= iLeft;
    125         iMinimumWidth -= iRight;
    126         /* Set minimum text width: */
    127         m_pErrorPane->setMinimumTextWidth(iMinimumWidth);
    128 
    129         /* Layout content: */
    130         m_pMainLayout->addWidget(m_pProgressBar, 0, 0);
    131         m_pMainLayout->addWidget(m_pRetryButton, 0, 1);
    132         m_pMainLayout->addWidget(m_pCancelButton, 0, 2);
    133         m_pMainLayout->addWidget(m_pErrorPane, 1, 0, 1, 3);
    134 
    135         /* Retranslate UI: */
    136         retranslateUi();
     169        links << linkRegExp.cap();
     170        strErrorText.replace(linkRegExp.cap(), QString("%%1").arg(i));
    137171    }
    138 
    139 private slots:
    140 
    141     /* Retranslate UI: */
    142     void retranslateUi()
    143     {
    144         /* Get corresponding title: */
    145         const QString &strTitle = m_pNetworkRequest->description();
    146 
    147         /* Set popup title (default if missed): */
    148         setTitle(strTitle.isEmpty() ? UINetworkManager::tr("Network Operation") : strTitle);
    149 
    150         /* Translate retry button: */
    151         m_pRetryButton->setStatusTip(UINetworkManager::tr("Restart network operation"));
    152 
    153         /* Translate cancel button: */
    154         m_pCancelButton->setStatusTip(UINetworkManager::tr("Cancel network operation"));
    155     }
    156 
    157     /* Updates current network-request progess: */
    158     void sltSetProgress(qint64 iReceived, qint64 iTotal)
    159     {
    160         /* Restart timer: */
    161         m_pTimer->start();
    162 
    163         /* Set current progress to passed: */
    164         m_pProgressBar->setRange(0, iTotal);
    165         m_pProgressBar->setValue(iReceived);
    166     }
    167 
    168     /* Set current network-request progress to 'started': */
    169     void sltSetProgressToStarted()
    170     {
    171         /* Start timer: */
    172         m_pTimer->start();
    173 
    174         /* Set current progress to 'started': */
    175         m_pProgressBar->setRange(0, 1);
    176         m_pProgressBar->setValue(0);
    177 
    178         /* Hide 'retry' button: */
    179         m_pRetryButton->setHidden(true);
    180 
    181         /* Hide error label: */
    182         m_pErrorPane->setHidden(true);
    183         m_pErrorPane->setText(QString());
    184     }
    185 
    186     /* Set current network-request progress to 'finished': */
    187     void sltSetProgressToFinished()
    188     {
    189         /* Stop timer: */
    190         m_pTimer->stop();
    191 
    192         /* Set current progress to 'started': */
    193         m_pProgressBar->setRange(0, 1);
    194         m_pProgressBar->setValue(1);
    195     }
    196 
    197     /* Set current network-request progress to 'failed': */
    198     void sltSetProgressToFailed(const QString &strError)
    199     {
    200         /* Stop timer: */
    201         m_pTimer->stop();
    202 
    203         /* Set current progress to 'failed': */
    204         m_pProgressBar->setRange(0, 1);
    205         m_pProgressBar->setValue(1);
    206 
    207         /* Show 'retry' button: */
    208         m_pRetryButton->setHidden(false);
    209 
    210         /* Try to find all the links in the error-message,
    211          * replace them with %increment if present: */
    212         QString strErrorText(strError);
    213         QRegExp linkRegExp("[\\S]+[\\./][\\S]+");
    214         QStringList links;
    215         for (int i = 1; linkRegExp.indexIn(strErrorText) != -1; ++i)
    216         {
    217             links << linkRegExp.cap();
    218             strErrorText.replace(linkRegExp.cap(), QString("%%1").arg(i));
    219         }
    220         /* Return back all the links, just in bold: */
    221         if (!links.isEmpty())
    222             for (int i = 0; i < links.size(); ++i)
    223                 strErrorText = strErrorText.arg(QString("<b>%1</b>").arg(links[i]));
    224 
    225         /* Show error label: */
    226         m_pErrorPane->setHidden(false);
    227         m_pErrorPane->setText(UINetworkManager::tr("Error: %1.").arg(strErrorText));
    228     }
    229 
    230     /* Handle frozen progress: */
    231     void sltTimeIsOut()
    232     {
    233         /* Stop timer: */
    234         m_pTimer->stop();
    235 
    236         /* Set current progress to unknown: */
    237         m_pProgressBar->setRange(0, 0);
    238     }
    239 
    240 private:
    241 
    242     /* Objects: */
    243     UINetworkRequest *m_pNetworkRequest;
    244     QTimer *m_pTimer;
    245 
    246     /* Widgets: */
    247     QWidget *m_pContentWidget;
    248     QGridLayout *m_pMainLayout;
    249     QProgressBar *m_pProgressBar;
    250     QIToolButton *m_pRetryButton;
    251     QIToolButton *m_pCancelButton;
    252     QIRichTextLabel *m_pErrorPane;
    253 };
    254 
    255 /* Network requests dialog: */
    256 class UINetworkManagerDialog : public QIWithRetranslateUI<QMainWindow>
    257 {
    258     Q_OBJECT;
    259 
    260 signals:
    261 
    262     /* Signal to cancel all network-requests: */
    263     void sigCancelNetworkRequests();
    264 
    265 public slots:
    266 
    267     /* Show the dialog, make sure its visible: */
    268     void showNormal()
    269     {
    270         /* Show (restore if neessary): */
    271         QMainWindow::showNormal();
    272 
    273         /* Raise above the others: */
    274         raise();
    275 
    276         /* Activate: */
    277         activateWindow();
    278     }
    279 
    280 public:
    281 
    282     /* Constructor: */
    283     UINetworkManagerDialog()
    284     {
    285         /* Do not count that window as important for application,
    286          * it will NOT be taken into account when other top-level windows will be closed: */
    287         setAttribute(Qt::WA_QuitOnClose, false);
    288 
    289         /* Set minimum width: */
    290         setMinimumWidth(500);
    291 
    292         /* Prepare central-widget: */
    293         setCentralWidget(new QWidget);
    294 
    295         /* Create main-layout: */
    296         m_pMainLayout = new QVBoxLayout(centralWidget());
    297         m_pMainLayout->setContentsMargins(6, 6, 6, 6);
    298 
    299         /* Create description-label: */
    300         m_pLabel = new QLabel(centralWidget());
    301         m_pLabel->setAlignment(Qt::AlignCenter);
    302         m_pLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    303 
    304         /* Create button-box: */
    305         m_pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, centralWidget());
    306         connect(m_pButtonBox, SIGNAL(rejected()), this, SLOT(sltHandleCancelAllButtonPress()));
    307         m_pButtonBox->setHidden(true);
    308 
    309         /* Layout content: */
    310         m_pMainLayout->addWidget(m_pLabel);
    311         m_pMainLayout->addStretch();
    312         m_pMainLayout->addWidget(m_pButtonBox);
    313 
    314         /* Create status-bar: */
    315         setStatusBar(new QStatusBar);
    316 
    317         /* Translate dialog: */
    318         retranslateUi();
    319     }
    320 
    321     /* Add network-request widget: */
    322     UINetworkRequestWidget* addNetworkRequestWidget(UINetworkRequest *pNetworkRequest)
    323     {
    324         /* Make sure network-request is really exists: */
    325         AssertMsg(pNetworkRequest, ("Network-request doesn't exists!\n"));
    326 
    327         /* Create new network-request widget: */
    328         UINetworkRequestWidget *pNetworkRequestWidget = new UINetworkRequestWidget(this, pNetworkRequest);
    329         m_pMainLayout->insertWidget(m_pMainLayout->count() - 2 /* before button-box and stretch */, pNetworkRequestWidget);
    330         m_widgets.insert(pNetworkRequest->uuid(), pNetworkRequestWidget);
    331 
    332         /* Hide label: */
    333         m_pLabel->setHidden(true);
    334         /* Show button-box: */
    335         m_pButtonBox->setHidden(false);
    336         /* If customer made a force-call: */
    337         if (pNetworkRequest->customer()->isItForceCall())
    338         {
    339             /* Show dialog: */
    340             showNormal();
    341         }
    342 
    343         /* Return network-request widget: */
    344         return pNetworkRequestWidget;
    345     }
    346 
    347     /* Remove network-request widget: */
    348     void removeNetworkRequestWidget(const QUuid &uuid)
    349     {
    350         /* Make sure network-request widget still present: */
    351         AssertMsg(m_widgets.contains(uuid), ("Network-request widget already removed!\n"));
    352 
    353         /* Delete corresponding network-request widget: */
    354         delete m_widgets.value(uuid);
    355         m_widgets.remove(uuid);
    356 
    357         /* Check if dialog is empty: */
    358         if (m_widgets.isEmpty())
    359         {
    360             /* Show label: */
    361             m_pLabel->setHidden(false);
    362             /* Hide button-box: */
    363             m_pButtonBox->setHidden(true);
    364             /* Let central-widget update its layout before being hidden: */
    365             QCoreApplication::sendPostedEvents(centralWidget(), QEvent::LayoutRequest);
    366             /* Hide dialog: */
    367             hide();
    368         }
    369     }
    370 
    371 private slots:
    372 
    373     /* Handler for 'Cancel All' button press: */
    374     void sltHandleCancelAllButtonPress()
    375     {
    376         /* Ask if user wants to cancel all current network-requests: */
    377         if (msgCenter().askAboutCancelAllNetworkRequest(this))
    378             emit sigCancelNetworkRequests();
    379     }
    380 
    381 private:
    382 
    383     /* Translate whole dialog: */
    384     void retranslateUi()
    385     {
    386         /* Set window caption: */
    387         setWindowTitle(UINetworkManager::tr("Network Operations Manager"));
    388 
    389         /* Set description-label text: */
    390         m_pLabel->setText(UINetworkManager::tr("There are no active network operations."));
    391 
    392         /* Set buttons-box text: */
    393         m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("&Cancel All"));
    394         m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Cancel all active network operations"));
    395     }
    396 
    397     /* Overloaded show-event: */
    398     void showEvent(QShowEvent *pShowEvent)
    399     {
    400         /* Resize to minimum size-hint: */
    401         resize(minimumSizeHint());
    402 
    403         /* Center according current main application window: */
    404         vboxGlobal().centerWidget(this, vboxGlobal().mainWindow(), false);
    405 
    406         /* Pass event to the base-class: */
    407         QMainWindow::showEvent(pShowEvent);
    408     }
    409 
    410     /* Overloaded keypress-event: */
    411     void keyPressEvent(QKeyEvent *pKeyPressEvent)
    412     {
    413         /* 'Escape' key used to close the dialog: */
    414         if (pKeyPressEvent->key() == Qt::Key_Escape)
    415         {
    416             close();
    417             return;
    418         }
    419 
    420         /* Pass event to the base-class: */
    421         QMainWindow::keyPressEvent(pKeyPressEvent);
    422     }
    423 
    424     /* Main layout: */
    425     QVBoxLayout *m_pMainLayout;
    426     QLabel *m_pLabel;
    427     QIDialogButtonBox *m_pButtonBox;
    428 
    429     /* Popup-widget map: */
    430     QMap<QUuid, UINetworkRequestWidget*> m_widgets;
    431 };
    432 
    433 /* Constructor: */
    434 UINetworkRequest::UINetworkRequest(UINetworkManager *pNetworkManager,
    435                                    UINetworkManagerDialog *pNetworkManagerDialog,
    436                                    const QNetworkRequest &request, UINetworkRequestType type,
    437                                    const QString &strDescription, UINetworkCustomer *pCustomer)
    438     : QObject(pNetworkManager)
    439     , m_pNetworkManagerDialog(pNetworkManagerDialog)
    440     , m_pNetworkRequestWidget(0)
    441     , m_uuid(QUuid::createUuid())
    442     , m_requests(QList<QNetworkRequest>() << request)
    443     , m_iCurrentRequestIndex(0)
    444     , m_type(type)
    445     , m_strDescription(strDescription)
    446     , m_pCustomer(pCustomer)
    447     , m_fRunning(false)
    448 {
    449     /* Initialize: */
    450     initialize();
    451 }
    452 
    453 UINetworkRequest::UINetworkRequest(UINetworkManager *pNetworkManager,
    454                                    UINetworkManagerDialog *pNetworkManagerDialog,
    455                                    const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    456                                    const QString &strDescription, UINetworkCustomer *pCustomer)
    457     : QObject(pNetworkManager)
    458     , m_pNetworkManagerDialog(pNetworkManagerDialog)
    459     , m_pNetworkRequestWidget(0)
    460     , m_uuid(QUuid::createUuid())
    461     , m_requests(requests)
    462     , m_iCurrentRequestIndex(0)
    463     , m_type(type)
    464     , m_strDescription(strDescription)
    465     , m_pCustomer(pCustomer)
    466     , m_fRunning(false)
    467 {
    468     /* Initialize: */
    469     initialize();
    470 }
    471 
    472 /* Destructor: */
    473 UINetworkRequest::~UINetworkRequest()
    474 {
    475     /* Destroy network-reply: */
    476     cleanupNetworkReply();
    477 
    478     /* Destroy network-request widget: */
    479     m_pNetworkManagerDialog->removeNetworkRequestWidget(m_uuid);
    480 }
    481 
    482 /* Network-reply progress handler: */
    483 void UINetworkRequest::sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal)
    484 {
    485     /* Notify UINetworkManager: */
    486     emit sigProgress(m_uuid, iReceived, iTotal);
    487     /* Notify UINetworkRequestWidget: */
    488     emit sigProgress(iReceived, iTotal);
    489 }
    490 
    491 /* Network-reply finish handler: */
    492 void UINetworkRequest::sltHandleNetworkReplyFinish()
    493 {
    494     /* Set as non-running: */
    495     m_fRunning = false;
    496 
    497     /* Get sender network reply: */
    498     QNetworkReply *pNetworkReply = static_cast<QNetworkReply*>(sender());
    499 
    500     /* If network-request was canceled: */
    501     if (pNetworkReply->error() == QNetworkReply::OperationCanceledError)
    502     {
    503         /* Notify UINetworkManager: */
    504         emit sigCanceled(m_uuid);
    505     }
    506     /* If network-reply has no errors: */
    507     else if (pNetworkReply->error() == QNetworkReply::NoError)
    508     {
    509         /* Check if redirection required: */
    510         QUrl redirect = pNetworkReply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
    511         if (redirect.isValid())
    512         {
    513             /* Cleanup current network-reply first: */
    514             cleanupNetworkReply();
    515 
    516             /* Choose redirect-source as current: */
    517             m_request.setUrl(redirect);
    518 
    519             /* Create new network-reply finally: */
    520             prepareNetworkReply();
    521         }
    522         else
    523         {
    524             /* Notify UINetworkRequestWidget: */
    525             emit sigFinished();
    526             /* Notify UINetworkManager: */
    527             emit sigFinished(m_uuid);
    528         }
    529     }
    530     /* If some error occured: */
    531     else
    532     {
    533         /* Check if we have other requests in set: */
    534         if (m_iCurrentRequestIndex < m_requests.size() - 1)
    535         {
    536             /* Cleanup current network-reply first: */
    537             cleanupNetworkReply();
    538 
    539             /* Choose next network-request as current: */
    540             ++m_iCurrentRequestIndex;
    541             m_request = m_requests[m_iCurrentRequestIndex];
    542 
    543             /* Create new network-reply finally: */
    544             prepareNetworkReply();
    545         }
    546         else
    547         {
    548             /* Notify UINetworkRequestWidget: */
    549             emit sigFailed(pNetworkReply->errorString());
    550             /* Notify UINetworkManager: */
    551             emit sigFailed(m_uuid, pNetworkReply->errorString());
    552         }
    553     }
    554 }
    555 
    556 /* Slot to retry network-request: */
    557 void UINetworkRequest::sltRetry()
    558 {
    559     /* Cleanup current network-reply first: */
    560     cleanupNetworkReply();
    561 
    562     /* Choose first network-request as current: */
    563     m_iCurrentRequestIndex = 0;
    564     m_request = m_requests[m_iCurrentRequestIndex];
    565 
    566     /* Create new network-reply finally: */
    567     prepareNetworkReply();
    568 }
    569 
    570 /* Slot to cancel network-request: */
    571 void UINetworkRequest::sltCancel()
    572 {
    573     /* Abort network-reply if present: */
    574     abortNetworkReply();
    575 }
    576 
    577 /* Initialize: */
    578 void UINetworkRequest::initialize()
    579 {
    580     /* Prepare listeners for parent(): */
    581     connect(parent(), SIGNAL(sigCancelNetworkRequests()), this, SLOT(sltCancel()));
    582 
    583     /* Create network-request widget: */
    584     m_pNetworkRequestWidget = m_pNetworkManagerDialog->addNetworkRequestWidget(this);
    585 
    586     /* Prepare listeners for m_pNetworkRequestWidget: */
    587     connect(m_pNetworkRequestWidget, SIGNAL(sigRetry()), this, SLOT(sltRetry()));
    588     connect(m_pNetworkRequestWidget, SIGNAL(sigCancel()), this, SLOT(sltCancel()));
    589 
    590     /* Choose first network-request as current: */
    591     m_iCurrentRequestIndex = 0;
    592     m_request = m_requests[m_iCurrentRequestIndex];
    593 
    594     /* Create network-reply: */
    595     prepareNetworkReply();
    596 }
    597 
    598 /* Prepare network-reply: */
    599 void UINetworkRequest::prepareNetworkReply()
    600 {
    601     /* Make network-request: */
    602     switch (m_type)
    603     {
    604         case UINetworkRequestType_HEAD:
    605         {
    606             m_pReply = gNetworkManager->head(m_request);
    607             break;
    608         }
    609         case UINetworkRequestType_GET:
    610         {
    611             m_pReply = gNetworkManager->get(m_request);
    612             break;
    613         }
    614         default:
    615             break;
    616     }
    617 
    618     /* Prepare listeners for m_pReply: */
    619     AssertMsg(m_pReply, ("Unable to make network-request!\n"));
    620     connect(m_pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(sltHandleNetworkReplyProgress(qint64, qint64)));
    621     connect(m_pReply, SIGNAL(finished()), this, SLOT(sltHandleNetworkReplyFinish()));
    622 
    623     /* Set as running: */
    624     m_fRunning = true;
    625 
    626     /* Notify UINetworkRequestWidget: */
    627     emit sigStarted();
    628 }
    629 
    630 /* Cleanup network-reply: */
    631 void UINetworkRequest::cleanupNetworkReply()
    632 {
    633     /* Destroy current reply: */
    634     AssertMsg(m_pReply, ("Network-reply already destroyed!\n"));
    635     m_pReply->disconnect();
    636     m_pReply->deleteLater();
    637     m_pReply = 0;
    638 }
    639 
    640 /* Abort network-reply: */
    641 void UINetworkRequest::abortNetworkReply()
    642 {
    643     /* Abort network-reply if present: */
    644     if (m_pReply)
    645     {
    646         if (m_fRunning)
    647             m_pReply->abort();
    648         else
    649             emit sigCanceled(m_uuid);
    650     }
    651 }
    652 
    653 /* Instance: */
    654 UINetworkManager* UINetworkManager::m_pInstance = 0;
    655 
    656 /* Create singleton: */
    657 void UINetworkManager::create()
    658 {
    659     /* Check that instance do NOT exist: */
    660     if (m_pInstance)
    661         return;
    662 
    663     /* Create instance: */
    664     new UINetworkManager;
    665 }
    666 
    667 /* Destroy singleton: */
    668 void UINetworkManager::destroy()
    669 {
    670     /* Check that instance exists: */
    671     if (!m_pInstance)
    672         return;
    673 
    674     /* Destroy instance: */
    675     delete m_pInstance;
    676 }
    677 
    678 /* Network Access Manager GUI window: */
    679 QWidget* UINetworkManager::window() const
    680 {
    681     return m_pNetworkProgressDialog;
    682 }
    683 
    684 /* Show Network Access Manager GUI: */
    685 void UINetworkManager::show()
    686 {
    687     /* Just show the dialog: */
    688     m_pNetworkProgressDialog->showNormal();
    689 }
    690 
    691 /* Network-request creation wrapper for UINetworkCustomer: */
    692 void UINetworkManager::createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type,
    693                                             const QString &strDescription, UINetworkCustomer *pCustomer)
    694 {
    695     /* Create new network-request: */
    696     UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkProgressDialog,
    697                                                              request, type, strDescription, pCustomer);
    698     /* Prepare created network-request: */
    699     prepareNetworkRequest(pNetworkRequest);
    700 }
    701 
    702 /* Network request (set) creation wrapper for UINetworkCustomer: */
    703 void UINetworkManager::createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    704                                             const QString &strDescription, UINetworkCustomer *pCustomer)
    705 {
    706     /* Create new network-request: */
    707     UINetworkRequest *pNetworkRequest = new UINetworkRequest(this, m_pNetworkProgressDialog,
    708                                                              requests, type, strDescription, pCustomer);
    709     /* Prepare created network-request: */
    710     prepareNetworkRequest(pNetworkRequest);
    711 }
    712 
    713 /* Constructor: */
    714 UINetworkManager::UINetworkManager()
    715 {
    716     /* Prepare instance: */
    717     m_pInstance = this;
    718 
    719     /* Prepare finally: */
    720     prepare();
    721 }
    722 
    723 /* Destructor: */
    724 UINetworkManager::~UINetworkManager()
    725 {
    726     /* Cleanup first: */
    727     cleanup();
    728 
    729     /* Cleanup instance: */
    730     m_pInstance = 0;
    731 }
    732 
    733 /* Prepare: */
    734 void UINetworkManager::prepare()
    735 {
    736     /* Prepare network manager GUI: */
    737     m_pNetworkProgressDialog = new UINetworkManagerDialog;
    738 
    739     /* Prepare listeners for m_pNetworkProgressDialog: */
    740     connect(m_pNetworkProgressDialog, SIGNAL(sigCancelNetworkRequests()), this, SIGNAL(sigCancelNetworkRequests()));
    741 }
    742 
    743 /* Cleanup: */
    744 void UINetworkManager::cleanup()
    745 {
    746     /* Cleanup network-requests first: */
    747     cleanupNetworkRequests();
    748 
    749     /* Cleanup network manager GUI: */
    750     delete m_pNetworkProgressDialog;
    751 }
    752 
    753 /* Prepare network-request: */
    754 void UINetworkManager::prepareNetworkRequest(UINetworkRequest *pNetworkRequest)
    755 {
    756     /* Prepare listeners for pNetworkRequest: */
    757     connect(pNetworkRequest, SIGNAL(sigProgress(const QUuid&, qint64, qint64)), this, SLOT(sltHandleNetworkRequestProgress(const QUuid&, qint64, qint64)));
    758     connect(pNetworkRequest, SIGNAL(sigCanceled(const QUuid&)), this, SLOT(sltHandleNetworkRequestCancel(const QUuid&)));
    759     connect(pNetworkRequest, SIGNAL(sigFinished(const QUuid&)), this, SLOT(sltHandleNetworkRequestFinish(const QUuid&)));
    760     connect(pNetworkRequest, SIGNAL(sigFailed(const QUuid&, const QString&)), this, SLOT(sltHandleNetworkRequestFailure(const QUuid&, const QString&)));
    761 
    762     /* Add this request into internal map: */
    763     m_requests.insert(pNetworkRequest->uuid(), pNetworkRequest);
    764 }
    765 
    766 /* Cleanup network-request: */
    767 void UINetworkManager::cleanupNetworkRequest(QUuid uuid)
    768 {
    769     /* Cleanup network-request map: */
    770     delete m_requests[uuid];
    771     m_requests.remove(uuid);
    772 }
    773 
    774 /* Cleanup all network-requests: */
    775 void UINetworkManager::cleanupNetworkRequests()
    776 {
    777     /* Get all the request IDs: */
    778     const QList<QUuid> &uuids = m_requests.keys();
    779     /* Cleanup corresponding requests: */
    780     for (int i = 0; i < uuids.size(); ++i)
    781         cleanupNetworkRequest(uuids[i]);
    782 }
    783 
    784 /* Slot to handle network-request progress: */
    785 void UINetworkManager::sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
    786 {
    787     /* Make sure corresponding map contains received ID: */
    788     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    789 
    790     /* Get corresponding network-request: */
    791     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    792 
    793     /* Get corresponding customer: */
    794     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    795 
    796     /* Send to customer to process: */
    797     pNetworkCustomer->processNetworkReplyProgress(iReceived, iTotal);
    798 }
    799 
    800 /* Slot to handle network-request cancel: */
    801 void UINetworkManager::sltHandleNetworkRequestCancel(const QUuid &uuid)
    802 {
    803     /* Make sure corresponding map contains received ID: */
    804     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    805 
    806     /* Get corresponding network-request: */
    807     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    808 
    809     /* Get corresponding customer: */
    810     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    811 
    812     /* Send to customer to process: */
    813     pNetworkCustomer->processNetworkReplyCanceled(pNetworkRequest->reply());
    814 
    815     /* Cleanup network-request: */
    816     cleanupNetworkRequest(uuid);
    817 }
    818 
    819 /* Slot to handle network-request finish: */
    820 void UINetworkManager::sltHandleNetworkRequestFinish(const QUuid &uuid)
    821 {
    822     /* Make sure corresponding map contains received ID: */
    823     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    824 
    825     /* Get corresponding network-request: */
    826     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    827 
    828     /* Get corresponding customer: */
    829     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    830 
    831     /* Send to customer to process: */
    832     pNetworkCustomer->processNetworkReplyFinished(pNetworkRequest->reply());
    833 
    834     /* Cleanup network-request: */
    835     cleanupNetworkRequest(uuid);
    836 }
    837 
    838 /* Slot to handle network-request failure: */
    839 void UINetworkManager::sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &)
    840 {
    841     /* Make sure corresponding map contains received ID: */
    842     AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
    843 
    844     /* Get corresponding network-request: */
    845     UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
    846 
    847     /* Get corresponding customer: */
    848     UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
    849 
    850     /* If customer made a force-call: */
    851     if (pNetworkCustomer->isItForceCall())
    852     {
    853         /* Just show the dialog: */
    854         show();
    855     }
    856 }
    857 
    858 #include "UINetworkManager.moc"
    859 
     172    /* Return back all the links, just in bold: */
     173    if (!links.isEmpty())
     174        for (int i = 0; i < links.size(); ++i)
     175            strErrorText = strErrorText.arg(QString("<b>%1</b>").arg(links[i]));
     176
     177    /* Show error label: */
     178    m_pErrorPane->setHidden(false);
     179    m_pErrorPane->setText(UINetworkManagerDialog::tr("Error: %1.").arg(strErrorText));
     180}
     181
     182void UINetworkRequestWidget::sltTimeIsOut()
     183{
     184    /* Stop timer: */
     185    m_pTimer->stop();
     186
     187    /* Set current progress to unknown: */
     188    m_pProgressBar->setRange(0, 0);
     189}
     190
     191void UINetworkRequestWidget::retranslateUi()
     192{
     193    /* Get corresponding title: */
     194    const QString &strTitle = m_pNetworkRequest->description();
     195
     196    /* Set popup title (default if missed): */
     197    setTitle(strTitle.isEmpty() ? UINetworkManagerDialog::tr("Network Operation") : strTitle);
     198
     199    /* Translate retry button: */
     200    m_pRetryButton->setStatusTip(UINetworkManagerDialog::tr("Restart network operation"));
     201
     202    /* Translate cancel button: */
     203    m_pCancelButton->setStatusTip(UINetworkManagerDialog::tr("Cancel network operation"));
     204}
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.h

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h58652,​70973
      /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h66309,​66318
      /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h70873
      /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h74233
    r41435 r41440  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * UINetworkManager stuff declaration
     4 * UINetworkRequestWidget stuff declaration
    55 */
    66
     
    1717 */
    1818
    19 #ifndef __UINetworkManager_h__
    20 #define __UINetworkManager_h__
    21 
    22 /* Global includes: */
    23 #include <QNetworkAccessManager>
    24 #include <QUuid>
    25 #include <QMap>
    26 #include <QNetworkRequest>
    27 #include <QNetworkReply>
    28 #include <QPointer>
     19#ifndef __UINetworkRequestWidget_h__
     20#define __UINetworkRequestWidget_h__
    2921
    3022/* Local inludes: */
    31 #include "UINetworkDefs.h"
     23#include "QIWithRetranslateUI.h"
     24#include "UIPopupBox.h"
    3225
    3326/* Forward declarations: */
    34 class UINetworkManager;
    35 class UINetworkCustomer;
    36 class UINetworkRequestWidget;
    3727class UINetworkManagerDialog;
     28class QWidget;
     29class QGridLayout;
     30class QProgressBar;
     31class QIToolButton;
     32class QIRichTextLabel;
     33class UINetworkRequest;
     34class QTimer;
    3835
    39 /* Network request contianer: */
    40 class UINetworkRequest : public QObject
     36/* UIPopupBox reimplementation to reflect network-request status: */
     37class UINetworkRequestWidget : public QIWithRetranslateUI<UIPopupBox>
    4138{
    4239    Q_OBJECT;
     
    4441signals:
    4542
    46     /* Notifications to UINetworkManager: */
    47     void sigProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
    48     void sigCanceled(const QUuid &uuid);
    49     void sigFinished(const QUuid &uuid);
    50     void sigFailed(const QUuid &uuid, const QString &strError);
     43    /* Signal to retry network-request: */
     44    void sigRetry();
     45    /* Signal to cancel network-request: */
     46    void sigCancel();
    5147
    52     /* Notifications to UINetworkRequestWidget: */
    53     void sigProgress(qint64 iReceived, qint64 iTotal);
    54     void sigStarted();
    55     void sigFinished();
    56     void sigFailed(const QString &strError);
     48protected:
    5749
    58 public:
    59 
    60     /* Constructor/destructor: */
    61     UINetworkRequest(UINetworkManager *pNetworkManager,
    62                      UINetworkManagerDialog *pNetworkManagerDialog,
    63                      const QNetworkRequest &request, UINetworkRequestType type,
    64                      const QString &strDescription, UINetworkCustomer *pCustomer);
    65     UINetworkRequest(UINetworkManager *pNetworkManager,
    66                      UINetworkManagerDialog *pNetworkManagerDialog,
    67                      const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    68                      const QString &strDescription, UINetworkCustomer *pCustomer);
    69     ~UINetworkRequest();
    70 
    71     /* Getters: */
    72     const QUuid& uuid() const { return m_uuid; }
    73     const QString& description() const { return m_strDescription; }
    74     UINetworkCustomer* customer() { return m_pCustomer; }
    75     QNetworkReply* reply() { return m_pReply; }
     50    /* Allow creation of UINetworkRequestWidget to UINetworkManagerDialog only: */
     51    friend class UINetworkManagerDialog;
     52    /* Constructor: */
     53    UINetworkRequestWidget(UINetworkManagerDialog *pParent, UINetworkRequest *pNetworkRequest);
    7654
    7755private slots:
    7856
    79     /* Network-reply progress handler: */
    80     void sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal);
    81     /* Network-reply finish handler: */
    82     void sltHandleNetworkReplyFinish();
     57    /* Updates current network-request progess: */
     58    void sltSetProgress(qint64 iReceived, qint64 iTotal);
    8359
    84     /* Slot to retry network-request: */
    85     void sltRetry();
    86     /* Slot to cancel network-request: */
    87     void sltCancel();
     60    /* Set current network-request progress to 'started': */
     61    void sltSetProgressToStarted();
     62    /* Set current network-request progress to 'finished': */
     63    void sltSetProgressToFinished();
     64    /* Set current network-request progress to 'failed': */
     65    void sltSetProgressToFailed(const QString &strError);
     66
     67    /* Handle frozen progress: */
     68    void sltTimeIsOut();
    8869
    8970private:
    9071
    91     /* Initialize: */
    92     void initialize();
    93 
    94     /* Prepare network-reply: */
    95     void prepareNetworkReply();
    96     /* Cleanup network-reply: */
    97     void cleanupNetworkReply();
    98     /* Abort network-reply: */
    99     void abortNetworkReply();
     72    /* Translation stuff: */
     73    void retranslateUi();
    10074
    10175    /* Widgets: */
    102     UINetworkManagerDialog *m_pNetworkManagerDialog;
    103     UINetworkRequestWidget *m_pNetworkRequestWidget;
     76    QWidget *m_pContentWidget;
     77    QGridLayout *m_pMainLayout;
     78    QProgressBar *m_pProgressBar;
     79    QIToolButton *m_pRetryButton;
     80    QIToolButton *m_pCancelButton;
     81    QIRichTextLabel *m_pErrorPane;
    10482
    105     /* Variables: */
    106     QUuid m_uuid;
    107     QList<QNetworkRequest> m_requests;
    108     QNetworkRequest m_request;
    109     int m_iCurrentRequestIndex;
    110     UINetworkRequestType m_type;
    111     QString m_strDescription;
    112     UINetworkCustomer *m_pCustomer;
    113     QPointer<QNetworkReply> m_pReply;
    114     bool m_fRunning;
     83    /* Objects: */
     84    UINetworkRequest *m_pNetworkRequest;
     85    QTimer *m_pTimer;
    11586};
    11687
    117 /* QNetworkAccessManager class reimplementation providing
    118  * network access for the VirtualBox application purposes. */
    119 class UINetworkManager : public QNetworkAccessManager
    120 {
    121     Q_OBJECT;
     88#endif // __UINetworkRequestWidget_h__
    12289
    123 signals:
    124 
    125     /* Notification to UINetworkRequest: */
    126     void sigCancelNetworkRequests();
    127 
    128 public:
    129 
    130     /* Instance: */
    131     static UINetworkManager* instance() { return m_pInstance; }
    132 
    133     /* Create/destroy singleton: */
    134     static void create();
    135     static void destroy();
    136 
    137     /* Network Access Manager GUI window: */
    138     QWidget* window() const;
    139 
    140 public slots:
    141 
    142     /* Show Network Access Manager GUI: */
    143     void show();
    144 
    145 protected:
    146 
    147     /* Allow UINetworkCustomer to implicitly use next mothods: */
    148     friend class UINetworkCustomer;
    149     /* Network-request creation wrapper for UINetworkCustomer: */
    150     void createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type,
    151                               const QString &strDescription, UINetworkCustomer *pCustomer);
    152     /* Network request (set) creation wrapper for UINetworkCustomer: */
    153     void createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type,
    154                               const QString &strDescription, UINetworkCustomer *pCustomer);
    155 
    156 private:
    157 
    158     /* Constructor/destructor: */
    159     UINetworkManager();
    160     ~UINetworkManager();
    161 
    162     /* Prepare/cleanup: */
    163     void prepare();
    164     void cleanup();
    165 
    166     /* Network-request prepare helper: */
    167     void prepareNetworkRequest(UINetworkRequest *pNetworkRequest);
    168     /* Network-request cleanup helper: */
    169     void cleanupNetworkRequest(QUuid uuid);
    170     /* Network-requests cleanup helper: */
    171     void cleanupNetworkRequests();
    172 
    173 private slots:
    174 
    175     /* Slot to handle network-request progress: */
    176     void sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal);
    177     /* Slot to handle network-request cancel: */
    178     void sltHandleNetworkRequestCancel(const QUuid &uuid);
    179     /* Slot to handle network-request finish: */
    180     void sltHandleNetworkRequestFinish(const QUuid &uuid);
    181     /* Slot to handle network-request failure: */
    182     void sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &strError);
    183 
    184 private:
    185 
    186     /* Instance: */
    187     static UINetworkManager *m_pInstance;
    188 
    189     /* Network-request map: */
    190     QMap<QUuid, UINetworkRequest*> m_requests;
    191 
    192     /* Network manager UI: */
    193     UINetworkManagerDialog *m_pNetworkProgressDialog;
    194 };
    195 #define gNetworkManager UINetworkManager::instance()
    196 
    197 #endif // __UINetworkManager_h__
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