VirtualBox

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

Last change on this file was 103793, checked in by vboxsync, 2 months ago

FE/Qt: UICommon: Move versioning related functionality to UIVersion / UIVersionInfo; Rework user cases accordingly.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: UIDownloaderUserManual.cpp 103793 2024-03-11 19:17:31Z 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 "UIGlobalSession.h"
38#include "UIMessageCenter.h"
39#include "UIModalWindowManager.h"
40#include "UINetworkReply.h"
41#include "UINotificationCenter.h"
42#include "UIVersion.h"
43
44
45UIDownloaderUserManual::UIDownloaderUserManual()
46{
47 /* Get version number and adjust it for test and trunk builds. The server only has official releases. */
48 const QString strVersion = UIVersion(UIVersionInfo::vboxVersionStringNormalized()).effectiveReleasedVersion().toString();
49
50 /* Compose User Manual filename: */
51 QString strUserManualFullFileName = uiCommon().helpFile();
52 QString strUserManualShortFileName = QFileInfo(strUserManualFullFileName).fileName();
53
54 /* Add sources: */
55 QString strSource1 = QString("https://download.virtualbox.org/virtualbox/%1/").arg(strVersion) + strUserManualShortFileName;
56 QString strSource2 = QString("https://download.virtualbox.org/virtualbox/") + strUserManualShortFileName;
57 addSource(strSource1);
58 addSource(strSource2);
59
60 /* Set target: */
61 QString strUserManualDestination = QDir(gpGlobalSession->homeFolder()).absoluteFilePath(strUserManualShortFileName);
62 setTarget(strUserManualDestination);
63}
64
65QString UIDownloaderUserManual::description() const
66{
67 return UIDownloader::description().arg(tr("VirtualBox User Manual"));
68}
69
70bool UIDownloaderUserManual::askForDownloadingConfirmation(UINetworkReply *pReply)
71{
72 return msgCenter().confirmDownloadUserManual(source().toString(), pReply->header(UINetworkReply::ContentLengthHeader).toInt());
73}
74
75void UIDownloaderUserManual::handleDownloadedObject(UINetworkReply *pReply)
76{
77 /* Read received data into the buffer: */
78 QByteArray receivedData(pReply->readAll());
79 /* Serialize that buffer into the file: */
80 while (true)
81 {
82 /* Make sure the file already exists. If we reached
83 * this place, it's already written and checked. */
84 QFile file(target());
85 bool fSuccess = false;
86 /* Check step. Try to open file for reading first. */
87 if (file.open(QIODevice::ReadOnly))
88 fSuccess = true;
89 /* Failsafe step. Try to open file for writing otherwise. */
90 if (!fSuccess && file.open(QIODevice::WriteOnly))
91 {
92 /* Write buffer into the file: */
93 file.write(receivedData);
94 file.close();
95 fSuccess = true;
96 }
97 /* If the file already exists or was just written: */
98 if (fSuccess)
99 {
100 /* Warn the user about user-manual loaded and saved: */
101 UINotificationMessage::warnAboutUserManualDownloaded(source().toString(), QDir::toNativeSeparators(target()));
102 /* Warn the listener about user-manual was downloaded: */
103 emit sigDownloadFinished(target());
104 break;
105 }
106
107 /* Warn user about user-manual was downloaded but was NOT saved: */
108 msgCenter().cannotSaveUserManual(source().toString(), QDir::toNativeSeparators(target()));
109
110 /* Ask the user for another location for the user-manual file: */
111 QString strTarget = QIFileDialog::getExistingDirectory(QFileInfo(target()).absolutePath(),
112 windowManager().mainWindowShown(),
113 tr("Select folder to save User Manual to"), true);
114
115 /* Check if user had really set a new target: */
116 if (!strTarget.isNull())
117 setTarget(QDir(strTarget).absoluteFilePath(QFileInfo(target()).fileName()));
118 else
119 break;
120 }
121}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use