1
/* $Id: UIDownloaderUserManual.cpp 33540 2010-10-28 09:27:05Z vboxsync $ */
4
* VBox frontends: Qt GUI ("VirtualBox"):
5
* UIDownloaderUserManual class implementation
9
* Copyright (C) 2006-2010 Oracle Corporation
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.
26
#include "UIDownloaderUserManual.h"
27
#include "QIFileDialog.h"
29
#include "VBoxProblemReporter.h"
31
UIDownloaderUserManual *UIDownloaderUserManual::m_pInstance = 0;
33
UIDownloaderUserManual *UIDownloaderUserManual::create()
36
m_pInstance = new UIDownloaderUserManual;
40
UIDownloaderUserManual *UIDownloaderUserManual::current()
45
void UIDownloaderUserManual::destroy()
52
void UIDownloaderUserManual::setSource(const QString &strSource)
54
/* Erase the list first: */
55
m_sourcesList.clear();
56
/* And add there passed value: */
60
void UIDownloaderUserManual::addSource(const QString &strSource)
62
/* Append passed value: */
63
m_sourcesList << strSource;
66
void UIDownloaderUserManual::setParentWidget(QWidget *pParent)
71
QWidget* UIDownloaderUserManual::parentWidget() const
76
UIMiniProcessWidgetUserManual* UIDownloaderUserManual::processWidget(QWidget *pParent /* = 0 */) const
78
UIMiniProcessWidgetUserManual *pWidget = new UIMiniProcessWidgetUserManual(pParent);
80
/* Connect the cancel signal: */
81
connect(pWidget, SIGNAL(sigCancel()), this, SLOT(cancelDownloading()));
82
/* Connect the signal to notify about source changed: */
83
connect(this, SIGNAL(sigSourceChanged(const QString&)), pWidget, SLOT(sltSetSource(const QString&)));
84
/* Connect the signal to notify about the download process: */
85
connect(this, SIGNAL(sigDownloadProcess(int, int)), pWidget, SLOT(sltProcess(int, int)));
86
/* Make sure the widget is destroyed when this class is deleted: */
87
connect(this, SIGNAL(destroyed(QObject*)), pWidget, SLOT(close()));
92
void UIDownloaderUserManual::startDownload()
94
/* If at least one source to try left: */
95
if (!m_sourcesList.isEmpty())
97
/* Set the first of left sources as current one: */
98
UIDownloader::setSource(m_sourcesList.takeFirst());
99
/* Warn process-bar(s) about source was changed: */
100
emit sigSourceChanged(source());
101
/* Try to download: */
106
void UIDownloaderUserManual::acknowledgeFinished(bool fError)
108
/* If current source was wrong but other is present
109
* we will try other source else we should finish: */
110
if (m_pHttp->errorCode() != QIHttp::Aborted && m_pHttp->errorCode() != QIHttp::NoError && !m_sourcesList.isEmpty())
113
UIDownloader::acknowledgeFinished(fError);
116
void UIDownloaderUserManual::downloadFinished(bool fError)
119
UIDownloader::downloadFinished(fError);
122
/* Read all received data: */
123
QByteArray receivedData(m_pHttp->readAll());
125
/* Serialize the incoming buffer into the User Manual file: */
128
/* Try to open file to save document: */
129
QFile file(m_strTarget);
130
if (file.open(QIODevice::WriteOnly))
132
/* Write received data into file: */
133
file.write(receivedData);
135
/* Warn user about User Manual document loaded and saved: */
136
vboxProblem().warnAboutUserManualDownloaded(m_source.toString(), QDir::toNativeSeparators(m_strTarget));
137
/* Warn listener about User Manual was downloaded: */
138
emit sigDownloadFinished(m_strTarget);
139
/* Close the downloader: */
140
QTimer::singleShot(0, this, SLOT(suicide()));
145
/* Warn user about User Manual document loaded but was not saved: */
146
vboxProblem().warnAboutUserManualCantBeSaved(m_source.toString(), QDir::toNativeSeparators(m_strTarget));
149
/* Ask the user about User Manual file save location: */
150
QString target = QIFileDialog::getExistingDirectory(QFileInfo(m_strTarget).absolutePath(), m_pParent,
151
tr("Select folder to save User Manual to"), true);
152
/* If user reject to set save point: */
154
/* Just close the downloader: */
155
QTimer::singleShot(0, this, SLOT(suicide()));
156
/* If user set correct save point: */
158
/* Store it and try to save User Manual document there: */
159
m_strTarget = QDir(target).absoluteFilePath(QFileInfo(m_strTarget).fileName());
164
void UIDownloaderUserManual::suicide()
166
UIDownloaderUserManual::destroy();
169
UIDownloaderUserManual::UIDownloaderUserManual()
175
bool UIDownloaderUserManual::confirmDownload()
177
return vboxProblem().confirmUserManualDownload(m_source.toString(), m_pHttp->lastResponse().contentLength());
180
void UIDownloaderUserManual::warnAboutError(const QString &strError)
182
return vboxProblem().warnAboutUserManualCantBeDownloaded(m_source.toString(), strError);