VirtualBox

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

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

FE/Qt: bugref:10067: Notification signature for user manual downloading which should now go to center instead of network-request center; Moving singleton functionality from UIDownloaderUserManual to UINotificationDownloaderUserManual.

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