VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp@ 43138

Last change on this file since 43138 was 42526, checked in by vboxsync, 12 years ago

FE/Qt: 6234: Support for VM groups: Initial commit. GUI-3 branch reintegrated to trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
  • 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
    /branches/dsen/gui/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp79645-79692
File size: 6.9 KB
Line 
1/* $Id: UINetworkRequestWidget.cpp 42526 2012-08-02 10:31:28Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * UINetworkRequestWidget stuff implementation
6 */
7
8/*
9 * Copyright (C) 2011-2012 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* Global includes: */
21#include <QTimer>
22#include <QGridLayout>
23#include <QProgressBar>
24
25/* Local includes: */
26#include "UINetworkRequestWidget.h"
27#include "UINetworkRequest.h"
28#include "UINetworkManager.h"
29#include "UINetworkManagerDialog.h"
30#include "UIIconPool.h"
31#include "QIToolButton.h"
32#include "QIRichTextLabel.h"
33
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)
168 {
169 links << linkRegExp.cap();
170 strErrorText.replace(linkRegExp.cap(), QString("%%1").arg(i));
171 }
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}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette