VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/networking/UIDownloaderUserManual.cpp@ 90491

Last change on this file since 90491 was 90491, checked in by vboxsync, 4 years ago

FE/Qt: bugref:10067: Remove Network Access Manager references from Modal Window Manager as well.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: UIDownloaderUserManual.cpp 90491 2021-08-03 09:56:48Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIDownloaderUserManual class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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/* Qt includes: */
19#include <QDir>
20#include <QFile>
21#include <QVariant>
22
23/* GUI includes: */
24#include "QIFileDialog.h"
25#include "UICommon.h"
26#include "UIDownloaderUserManual.h"
27#include "UIMessageCenter.h"
28#include "UIModalWindowManager.h"
29#include "UINetworkReply.h"
30#include "UIVersion.h"
31
32
33/* static */
34UIDownloaderUserManual* UIDownloaderUserManual::s_pInstance = 0;
35
36/* static */
37UIDownloaderUserManual* UIDownloaderUserManual::create()
38{
39 if (!s_pInstance)
40 s_pInstance = new UIDownloaderUserManual;
41 return s_pInstance;
42}
43
44UIDownloaderUserManual::UIDownloaderUserManual()
45{
46 /* Prepare instance: */
47 if (!s_pInstance)
48 s_pInstance = this;
49
50 /* Get version number and adjust it for test and trunk builds. The server only has official releases. */
51 const QString strVersion = UIVersion(uiCommon().vboxVersionStringNormalized()).effectiveReleasedVersion().toString();
52
53 /* Compose User Manual filename: */
54 QString strUserManualFullFileName = uiCommon().helpFile();
55 QString strUserManualShortFileName = QFileInfo(strUserManualFullFileName).fileName();
56
57 /* Add sources: */
58 QString strSource1 = QString("https://download.virtualbox.org/virtualbox/%1/").arg(strVersion) + strUserManualShortFileName;
59 QString strSource2 = QString("https://download.virtualbox.org/virtualbox/") + strUserManualShortFileName;
60 addSource(strSource1);
61 addSource(strSource2);
62
63 /* Set target: */
64 QString strUserManualDestination = QDir(uiCommon().homeFolder()).absoluteFilePath(strUserManualShortFileName);
65 setTarget(strUserManualDestination);
66}
67
68UIDownloaderUserManual::~UIDownloaderUserManual()
69{
70 /* Cleanup instance: */
71 if (s_pInstance == this)
72 s_pInstance = 0;
73}
74
75const QString UIDownloaderUserManual::description() const
76{
77 return UIDownloader::description().arg(tr("VirtualBox User Manual"));
78}
79
80bool UIDownloaderUserManual::askForDownloadingConfirmation(UINetworkReply *pReply)
81{
82 return msgCenter().confirmDownloadUserManual(source().toString(), pReply->header(UINetworkReply::ContentLengthHeader).toInt());
83}
84
85void UIDownloaderUserManual::handleDownloadedObject(UINetworkReply *pReply)
86{
87 /* Read received data into the buffer: */
88 QByteArray receivedData(pReply->readAll());
89 /* Serialize that buffer into the file: */
90 while (true)
91 {
92 /* Make sure the file already exists. If we reached
93 * this place, it's already written and checked. */
94 QFile file(target());
95 bool fSuccess = false;
96 /* Check step. Try to open file for reading first. */
97 if (file.open(QIODevice::ReadOnly))
98 fSuccess = true;
99 /* Failsafe step. Try to open file for writing otherwise. */
100 if (!fSuccess && file.open(QIODevice::WriteOnly))
101 {
102 /* Write buffer into the file: */
103 file.write(receivedData);
104 file.close();
105 fSuccess = true;
106 }
107 /* If the file already exists or was just written: */
108 if (fSuccess)
109 {
110 /* Warn the user about user-manual loaded and saved: */
111 msgCenter().warnAboutUserManualDownloaded(source().toString(), QDir::toNativeSeparators(target()));
112 /* Warn the listener about user-manual was downloaded: */
113 emit sigDownloadFinished(target());
114 break;
115 }
116
117 /* Warn user about user-manual was downloaded but was NOT saved: */
118 msgCenter().cannotSaveUserManual(source().toString(), QDir::toNativeSeparators(target()));
119
120 /* Ask the user for another location for the user-manual file: */
121 QString strTarget = QIFileDialog::getExistingDirectory(QFileInfo(target()).absolutePath(),
122 windowManager().mainWindowShown(),
123 tr("Select folder to save User Manual to"), true);
124
125 /* Check if user had really set a new target: */
126 if (!strTarget.isNull())
127 setTarget(QDir(strTarget).absoluteFilePath(QFileInfo(target()).fileName()));
128 else
129 break;
130 }
131}
132
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