VirtualBox

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

Last change on this file since 52730 was 52730, checked in by vboxsync, 11 years ago

FE/Qt: Precompiled header hacking (work in progress).

  • 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/VBox-4.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp91223
    /branches/VBox-4.3/trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequestWidget.cpp91223
    /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: 7.0 KB
Line 
1/* $Id: UINetworkRequestWidget.cpp 52730 2014-09-12 16:19:53Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UINetworkRequestWidget stuff implementation.
4 */
5
6/*
7 * Copyright (C) 2011-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifdef VBOX_WITH_PRECOMPILED_HEADERS
19# include <precomp.h>
20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
21
22/* Global includes: */
23# include <QTimer>
24# include <QGridLayout>
25# include <QProgressBar>
26
27/* Local includes: */
28# include "UINetworkRequestWidget.h"
29# include "UINetworkRequest.h"
30# include "UINetworkManager.h"
31# include "UINetworkManagerDialog.h"
32# include "UIIconPool.h"
33# include "QIToolButton.h"
34# include "QIRichTextLabel.h"
35
36#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
37
38
39UINetworkRequestWidget::UINetworkRequestWidget(UINetworkManagerDialog *pParent, UINetworkRequest *pNetworkRequest)
40 : QIWithRetranslateUI<UIPopupBox>(pParent)
41 , m_pContentWidget(new QWidget(this))
42 , m_pMainLayout(new QGridLayout(m_pContentWidget))
43 , m_pProgressBar(new QProgressBar(m_pContentWidget))
44 , m_pRetryButton(new QIToolButton(m_pContentWidget))
45 , m_pCancelButton(new QIToolButton(m_pContentWidget))
46 , m_pErrorPane(new QIRichTextLabel(m_pContentWidget))
47 , m_pNetworkRequest(pNetworkRequest)
48 , m_pTimer(new QTimer(this))
49{
50 /* Setup self: */
51 setTitleIcon(UIIconPool::iconSet(":/nw_16px.png"));
52 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
53 setContentWidget(m_pContentWidget);
54 setOpen(true);
55
56 /* Prepare listeners for m_pNetworkRequest: */
57 connect(m_pNetworkRequest, SIGNAL(sigProgress(qint64, qint64)), this, SLOT(sltSetProgress(qint64, qint64)));
58 connect(m_pNetworkRequest, SIGNAL(sigStarted()), this, SLOT(sltSetProgressToStarted()));
59 connect(m_pNetworkRequest, SIGNAL(sigFinished()), this, SLOT(sltSetProgressToFinished()));
60 connect(m_pNetworkRequest, SIGNAL(sigFailed(const QString&)), this, SLOT(sltSetProgressToFailed(const QString&)));
61
62 /* Setup timer: */
63 m_pTimer->setInterval(5000);
64 connect(m_pTimer, SIGNAL(timeout()), this, SLOT(sltTimeIsOut()));
65
66 /* Setup main-layout: */
67 m_pMainLayout->setContentsMargins(6, 6, 6, 6);
68
69 /* Setup progress-bar: */
70 m_pProgressBar->setRange(0, 0);
71 m_pProgressBar->setMaximumHeight(16);
72
73 /* Setup retry-button: */
74 m_pRetryButton->setHidden(true);
75 m_pRetryButton->removeBorder();
76 m_pRetryButton->setFocusPolicy(Qt::NoFocus);
77 m_pRetryButton->setIcon(UIIconPool::iconSet(":/refresh_16px.png"));
78 connect(m_pRetryButton, SIGNAL(clicked(bool)), this, SIGNAL(sigRetry()));
79
80 /* Setup cancel-button: */
81 m_pCancelButton->removeBorder();
82 m_pCancelButton->setFocusPolicy(Qt::NoFocus);
83 m_pCancelButton->setIcon(UIIconPool::iconSet(":/cancel_16px.png"));
84 connect(m_pCancelButton, SIGNAL(clicked(bool)), this, SIGNAL(sigCancel()));
85
86 /* Setup error-label: */
87 m_pErrorPane->setHidden(true);
88 m_pErrorPane->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
89 /* Calculate required width: */
90 int iMinimumWidth = pParent->minimumWidth();
91 int iLeft, iTop, iRight, iBottom;
92 /* Take into account content-widget layout margins: */
93 m_pMainLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
94 iMinimumWidth -= iLeft;
95 iMinimumWidth -= iRight;
96 /* Take into account this layout margins: */
97 layout()->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
98 iMinimumWidth -= iLeft;
99 iMinimumWidth -= iRight;
100 /* Take into account parent layout margins: */
101 QLayout *pParentLayout = qobject_cast<QMainWindow*>(parent())->centralWidget()->layout();
102 pParentLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
103 iMinimumWidth -= iLeft;
104 iMinimumWidth -= iRight;
105 /* Set minimum text width: */
106 m_pErrorPane->setMinimumTextWidth(iMinimumWidth);
107
108 /* Layout content: */
109 m_pMainLayout->addWidget(m_pProgressBar, 0, 0);
110 m_pMainLayout->addWidget(m_pRetryButton, 0, 1);
111 m_pMainLayout->addWidget(m_pCancelButton, 0, 2);
112 m_pMainLayout->addWidget(m_pErrorPane, 1, 0, 1, 3);
113
114 /* Retranslate UI: */
115 retranslateUi();
116}
117
118void UINetworkRequestWidget::sltSetProgress(qint64 iReceived, qint64 iTotal)
119{
120 /* Restart timer: */
121 m_pTimer->start();
122
123 /* Set current progress to passed: */
124 m_pProgressBar->setRange(0, iTotal);
125 m_pProgressBar->setValue(iReceived);
126}
127
128void UINetworkRequestWidget::sltSetProgressToStarted()
129{
130 /* Start timer: */
131 m_pTimer->start();
132
133 /* Set current progress to 'started': */
134 m_pProgressBar->setRange(0, 1);
135 m_pProgressBar->setValue(0);
136
137 /* Hide 'retry' button: */
138 m_pRetryButton->setHidden(true);
139
140 /* Hide error label: */
141 m_pErrorPane->setHidden(true);
142 m_pErrorPane->setText(QString());
143}
144
145void UINetworkRequestWidget::sltSetProgressToFinished()
146{
147 /* Stop timer: */
148 m_pTimer->stop();
149
150 /* Set current progress to 'started': */
151 m_pProgressBar->setRange(0, 1);
152 m_pProgressBar->setValue(1);
153}
154
155void UINetworkRequestWidget::sltSetProgressToFailed(const QString &strError)
156{
157 /* Stop timer: */
158 m_pTimer->stop();
159
160 /* Set current progress to 'failed': */
161 m_pProgressBar->setRange(0, 1);
162 m_pProgressBar->setValue(1);
163
164 /* Show 'retry' button: */
165 m_pRetryButton->setHidden(false);
166
167 /* Try to find all the links in the error-message,
168 * replace them with %increment if present: */
169 QString strErrorText(strError);
170 QRegExp linkRegExp("[\\S]+[\\./][\\S]+");
171 QStringList links;
172 for (int i = 1; linkRegExp.indexIn(strErrorText) != -1; ++i)
173 {
174 links << linkRegExp.cap();
175 strErrorText.replace(linkRegExp.cap(), QString("%%1").arg(i));
176 }
177 /* Return back all the links, just in bold: */
178 if (!links.isEmpty())
179 for (int i = 0; i < links.size(); ++i)
180 strErrorText = strErrorText.arg(QString("<b>%1</b>").arg(links[i]));
181
182 /* Show error label: */
183 m_pErrorPane->setHidden(false);
184 m_pErrorPane->setText(UINetworkManagerDialog::tr("The network operation failed with the following error: %1.").arg(strErrorText));
185}
186
187void UINetworkRequestWidget::sltTimeIsOut()
188{
189 /* Stop timer: */
190 m_pTimer->stop();
191
192 /* Set current progress to unknown: */
193 m_pProgressBar->setRange(0, 0);
194}
195
196void UINetworkRequestWidget::retranslateUi()
197{
198 /* Get corresponding title: */
199 const QString &strTitle = m_pNetworkRequest->description();
200
201 /* Set popup title (default if missed): */
202 setTitle(strTitle.isEmpty() ? UINetworkManagerDialog::tr("Network Operation") : strTitle);
203
204 /* Translate retry button: */
205 m_pRetryButton->setStatusTip(UINetworkManagerDialog::tr("Restart network operation"));
206
207 /* Translate cancel button: */
208 m_pCancelButton->setStatusTip(UINetworkManagerDialog::tr("Cancel network operation"));
209}
Note: See TracBrowser for help on using the repository browser.

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