VirtualBox

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

Last change on this file since 103131 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: UIDownloaderUserManual.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIDownloaderUserManual class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QDir>
30#include <QFile>
31#include <QVariant>
32
33/* GUI includes: */
34#include "QIFileDialog.h"
35#include "UICommon.h"
36#include "UIDownloaderUserManual.h"
37#include "UIMessageCenter.h"
38#include "UIModalWindowManager.h"
39#include "UINetworkReply.h"
40#include "UINotificationCenter.h"
41#include "UIVersion.h"
42
43
44UIDownloaderUserManual::UIDownloaderUserManual()
45{
46 /* Get version number and adjust it for test and trunk builds. The server only has official releases. */
47 const QString strVersion = UIVersion(uiCommon().vboxVersionStringNormalized()).effectiveReleasedVersion().toString();
48
49 /* Compose User Manual filename: */
50 QString strUserManualFullFileName = uiCommon().helpFile();
51 QString strUserManualShortFileName = QFileInfo(strUserManualFullFileName).fileName();
52
53 /* Add sources: */
54 QString strSource1 = QString("https://download.virtualbox.org/virtualbox/%1/").arg(strVersion) + strUserManualShortFileName;
55 QString strSource2 = QString("https://download.virtualbox.org/virtualbox/") + strUserManualShortFileName;
56 addSource(strSource1);
57 addSource(strSource2);
58
59 /* Set target: */
60 QString strUserManualDestination = QDir(uiCommon().homeFolder()).absoluteFilePath(strUserManualShortFileName);
61 setTarget(strUserManualDestination);
62}
63
64QString UIDownloaderUserManual::description() const
65{
66 return UIDownloader::description().arg(tr("VirtualBox User Manual"));
67}
68
69bool UIDownloaderUserManual::askForDownloadingConfirmation(UINetworkReply *pReply)
70{
71 return msgCenter().confirmDownloadUserManual(source().toString(), pReply->header(UINetworkReply::ContentLengthHeader).toInt());
72}
73
74void UIDownloaderUserManual::handleDownloadedObject(UINetworkReply *pReply)
75{
76 /* Read received data into the buffer: */
77 QByteArray receivedData(pReply->readAll());
78 /* Serialize that buffer into the file: */
79 while (true)
80 {
81 /* Make sure the file already exists. If we reached
82 * this place, it's already written and checked. */
83 QFile file(target());
84 bool fSuccess = false;
85 /* Check step. Try to open file for reading first. */
86 if (file.open(QIODevice::ReadOnly))
87 fSuccess = true;
88 /* Failsafe step. Try to open file for writing otherwise. */
89 if (!fSuccess && file.open(QIODevice::WriteOnly))
90 {
91 /* Write buffer into the file: */
92 file.write(receivedData);
93 file.close();
94 fSuccess = true;
95 }
96 /* If the file already exists or was just written: */
97 if (fSuccess)
98 {
99 /* Warn the user about user-manual loaded and saved: */
100 UINotificationMessage::warnAboutUserManualDownloaded(source().toString(), QDir::toNativeSeparators(target()));
101 /* Warn the listener about user-manual was downloaded: */
102 emit sigDownloadFinished(target());
103 break;
104 }
105
106 /* Warn user about user-manual was downloaded but was NOT saved: */
107 msgCenter().cannotSaveUserManual(source().toString(), QDir::toNativeSeparators(target()));
108
109 /* Ask the user for another location for the user-manual file: */
110 QString strTarget = QIFileDialog::getExistingDirectory(QFileInfo(target()).absolutePath(),
111 windowManager().mainWindowShown(),
112 tr("Select folder to save User Manual to"), true);
113
114 /* Check if user had really set a new target: */
115 if (!strTarget.isNull())
116 setTarget(QDir(strTarget).absoluteFilePath(QFileInfo(target()).fileName()));
117 else
118 break;
119 }
120}
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