VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIExtension.cpp@ 96430

Last change on this file since 96430 was 96407, checked in by vboxsync, 21 months ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: UIExtension.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIExtension namespace implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2022 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/* GUI includes: */
29#include "UICommon.h"
30#include "UIExtension.h"
31#include "UINotificationCenter.h"
32#include "UIMessageCenter.h"
33#include "VBoxLicenseViewer.h"
34
35/* COM includes: */
36#include "CExtPack.h"
37
38
39void UIExtension::install(QString const &strFilePath,
40 QString const &strDigest,
41 QWidget *pParent,
42 QString *pstrExtPackName)
43{
44 /* If the extension pack manager isn't available, skip any attempts to install: */
45 CExtPackManager comExtPackManager = uiCommon().virtualBox().GetExtensionPackManager();
46 if (comExtPackManager.isNull())
47 return;
48 /* Open the extpack tarball via IExtPackManager: */
49 CExtPackFile comExtPackFile;
50 if (strDigest.isEmpty())
51 comExtPackFile = comExtPackManager.OpenExtPackFile(strFilePath);
52 else
53 {
54 QString strFileAndHash = QString("%1::SHA-256=%2").arg(strFilePath).arg(strDigest);
55 comExtPackFile = comExtPackManager.OpenExtPackFile(strFileAndHash);
56 }
57 if (!comExtPackManager.isOk())
58 {
59 UINotificationMessage::cannotOpenExtPack(comExtPackManager, strFilePath);
60 return;
61 }
62
63 if (!comExtPackFile.GetUsable())
64 {
65 UINotificationMessage::cannotOpenExtPackFile(comExtPackFile, strFilePath);
66 return;
67 }
68
69 const QString strPackName = comExtPackFile.GetName();
70 const QString strPackDescription = comExtPackFile.GetDescription();
71 const QString strPackVersion = QString("%1r%2%3").arg(comExtPackFile.GetVersion()).arg(comExtPackFile.GetRevision()).arg(comExtPackFile.GetEdition());
72
73 /* Check if there is a version of the extension pack already
74 * installed on the system and let the user decide what to do about it. */
75 CExtPack comExtPackCur = comExtPackManager.Find(strPackName);
76 bool fReplaceIt = comExtPackCur.isOk();
77 if (fReplaceIt)
78 {
79 QString strPackVersionCur = QString("%1r%2%3").arg(comExtPackCur.GetVersion()).arg(comExtPackCur.GetRevision()).arg(comExtPackCur.GetEdition());
80 if (!msgCenter().confirmReplaceExtensionPack(strPackName, strPackVersion, strPackVersionCur, strPackDescription, pParent))
81 return;
82 }
83 /* If it's a new package just ask for general confirmation. */
84 else
85 {
86 if (!msgCenter().confirmInstallExtensionPack(strPackName, strPackVersion, strPackDescription, pParent))
87 return;
88 }
89
90 /* Display the license dialog if required by the extension pack. */
91 if (comExtPackFile.GetShowLicense())
92 {
93 QString strLicense = comExtPackFile.GetLicense();
94 VBoxLicenseViewer licenseViewer(pParent);
95 if (licenseViewer.showLicenseFromString(strLicense) != QDialog::Accepted)
96 return;
97 }
98
99 /* Install the selected package.
100 * Set the package name return value before doing
101 * this as the caller should do a refresh even on failure. */
102 QString strDisplayInfo;
103#ifdef VBOX_WS_WIN
104 if (pParent)
105 strDisplayInfo.sprintf("hwnd=%#llx", (uint64_t)(uintptr_t)pParent->winId());
106#endif
107
108 /* Install extension pack: */
109 UINotificationProgressExtensionPackInstall *pNotification =
110 new UINotificationProgressExtensionPackInstall(comExtPackFile,
111 fReplaceIt,
112 strPackName,
113 strDisplayInfo);
114 QObject::connect(pNotification, &UINotificationProgressExtensionPackInstall::sigExtensionPackInstalled,
115 &uiCommon(), &UICommon::sigExtensionPackInstalled);
116 gpNotificationCenter->append(pNotification);
117
118 /* Store the name: */
119 if (pstrExtPackName)
120 *pstrExtPackName = strPackName;
121}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use