VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceImportEditorWidget.cpp@ 72545

Last change on this file since 72545 was 72545, checked in by vboxsync, 7 years ago

FE/Qt: ​bugref:6769 Adding a way to provide an appliance wide home folder

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1/* $Id: UIApplianceImportEditorWidget.cpp 72545 2018-06-13 14:24:53Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIApplianceImportEditorWidget class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2017 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#ifdef VBOX_WITH_PRECOMPILED_HEADERS
19# include <precomp.h>
20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
21
22/* Qt includes: */
23# include <QCheckBox>
24# include <QTextEdit>
25# include <QVBoxLayout>
26
27/* GUI includes: */
28# include "QIRichTextLabel.h"
29# include "QITreeView.h"
30# include "UIApplianceImportEditorWidget.h"
31# include "UIFilePathSelector.h"
32# include "UIMessageCenter.h"
33# include "UIWizardImportApp.h"
34# include "VBoxGlobal.h"
35
36/* COM includes: */
37# include "CAppliance.h"
38# include "CSystemProperties.h"
39
40#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
41
42
43////////////////////////////////////////////////////////////////////////////////
44// ImportSortProxyModel
45
46class ImportSortProxyModel: public UIApplianceSortProxyModel
47{
48public:
49 ImportSortProxyModel(QObject *pParent = NULL)
50 : UIApplianceSortProxyModel(pParent)
51 {
52 m_aFilteredList << KVirtualSystemDescriptionType_License;
53 }
54};
55
56////////////////////////////////////////////////////////////////////////////////
57// UIApplianceImportEditorWidget
58
59UIApplianceImportEditorWidget::UIApplianceImportEditorWidget(QWidget *pParent)
60 : UIApplianceEditorWidget(pParent)
61{
62 /* Show the MAC check box */
63 m_pCheckBoxReinitMACs->setHidden(false);
64
65 m_pPathSelectorLabel = new QIRichTextLabel(this);
66 if (m_pPathSelectorLabel)
67 {
68 m_pLayout->addWidget(m_pPathSelectorLabel);
69 }
70 m_pPathSelector = new UIFilePathSelector(this);
71 if (m_pPathSelector)
72 {
73 m_pPathSelector->setResetEnabled(true);
74 m_pPathSelector->setDefaultPath(vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder());
75 m_pPathSelector->setPath(vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder());
76 connect(m_pPathSelector, &UIFilePathSelector::pathChanged, this, &UIApplianceImportEditorWidget::sltHandlePathChanged);
77 m_pLayout->addWidget(m_pPathSelector);
78 }
79 m_pLayout->addStretch();
80 retranslateUi();
81}
82
83bool UIApplianceImportEditorWidget::setFile(const QString& strFile)
84{
85 bool fResult = false;
86 if (!strFile.isEmpty())
87 {
88 CProgress progress;
89 CVirtualBox vbox = vboxGlobal().virtualBox();
90 /* Create a appliance object */
91 m_pAppliance = new CAppliance(vbox.CreateAppliance());
92 fResult = m_pAppliance->isOk();
93 if (fResult)
94 {
95 /* Read the appliance */
96 progress = m_pAppliance->Read(strFile);
97 fResult = m_pAppliance->isOk();
98 if (fResult)
99 {
100 /* Show some progress, so the user know whats going on */
101 msgCenter().showModalProgressDialog(progress, tr("Reading Appliance ..."), ":/progress_reading_appliance_90px.png", this);
102 if (!progress.isOk() || progress.GetResultCode() != 0)
103 fResult = false;
104 else
105 {
106 /* Now we have to interpret that stuff */
107 m_pAppliance->Interpret();
108 fResult = m_pAppliance->isOk();
109 if (fResult)
110 {
111 if (m_pModel)
112 delete m_pModel;
113
114 QVector<CVirtualSystemDescription> vsds = m_pAppliance->GetVirtualSystemDescriptions();
115
116 m_pModel = new UIApplianceModel(vsds, m_pTreeViewSettings);
117
118 ImportSortProxyModel *pProxy = new ImportSortProxyModel(this);
119 pProxy->setSourceModel(m_pModel);
120 pProxy->sort(ApplianceViewSection_Description, Qt::DescendingOrder);
121
122 UIApplianceDelegate *pDelegate = new UIApplianceDelegate(pProxy, this);
123
124 /* Set our own model */
125 m_pTreeViewSettings->setModel(pProxy);
126 /* Set our own delegate */
127 m_pTreeViewSettings->setItemDelegate(pDelegate);
128 /* For now we hide the original column. This data is displayed as tooltip
129 also. */
130 m_pTreeViewSettings->setColumnHidden(ApplianceViewSection_OriginalValue, true);
131 m_pTreeViewSettings->expandAll();
132 /* Set model root index and make it current: */
133 m_pTreeViewSettings->setRootIndex(pProxy->mapFromSource(m_pModel->root()));
134 m_pTreeViewSettings->setCurrentIndex(pProxy->mapFromSource(m_pModel->root()));
135
136 /* Check for warnings & if there are one display them. */
137 bool fWarningsEnabled = false;
138 QVector<QString> warnings = m_pAppliance->GetWarnings();
139 if (warnings.size() > 0)
140 {
141 foreach (const QString& text, warnings)
142 m_pTextEditWarning->append("- " + text);
143 fWarningsEnabled = true;
144 }
145 m_pPaneWarning->setVisible(fWarningsEnabled);
146 }
147 }
148 }
149 }
150 if (!fResult)
151 {
152 if (!m_pAppliance->isOk())
153 msgCenter().cannotImportAppliance(*m_pAppliance, this);
154 else if (!progress.isNull() && (!progress.isOk() || progress.GetResultCode() != 0))
155 msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
156 /* Delete the appliance in a case of an error */
157 delete m_pAppliance;
158 m_pAppliance = NULL;
159 }
160 }
161 /* Make sure we initialize model items with correct base folder path: */
162 if (m_pPathSelector)
163 sltHandlePathChanged(m_pPathSelector->path());
164
165 return fResult;
166}
167
168void UIApplianceImportEditorWidget::prepareImport()
169{
170 if (m_pAppliance)
171 m_pModel->putBack();
172}
173
174bool UIApplianceImportEditorWidget::import()
175{
176 if (m_pAppliance)
177 {
178 /* Start the import asynchronously */
179 CProgress progress;
180 QVector<KImportOptions> options;
181 if (!m_pCheckBoxReinitMACs->isChecked())
182 options.append(KImportOptions_KeepAllMACs);
183 progress = m_pAppliance->ImportMachines(options);
184 bool fResult = m_pAppliance->isOk();
185 if (fResult)
186 {
187 /* Show some progress, so the user know whats going on */
188 msgCenter().showModalProgressDialog(progress, tr("Importing Appliance ..."), ":/progress_import_90px.png", this);
189 if (progress.GetCanceled())
190 return false;
191 if (!progress.isOk() || progress.GetResultCode() != 0)
192 {
193 msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
194 return false;
195 }
196 else
197 return true;
198 }
199 if (!fResult)
200 msgCenter().cannotImportAppliance(*m_pAppliance, this);
201 }
202 return false;
203}
204
205QList<QPair<QString, QString> > UIApplianceImportEditorWidget::licenseAgreements() const
206{
207 QList<QPair<QString, QString> > list;
208
209 CVirtualSystemDescriptionVector vsds = m_pAppliance->GetVirtualSystemDescriptions();
210 for (int i = 0; i < vsds.size(); ++i)
211 {
212 QVector<QString> strLicense;
213 strLicense = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_License,
214 KVirtualSystemDescriptionValueType_Original);
215 if (!strLicense.isEmpty())
216 {
217 QVector<QString> strName;
218 strName = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_Name,
219 KVirtualSystemDescriptionValueType_Auto);
220 list << QPair<QString, QString>(strName.first(), strLicense.first());
221 }
222 }
223
224 return list;
225}
226
227void UIApplianceImportEditorWidget::retranslateUi()
228{
229 UIApplianceEditorWidget::retranslateUi();
230 m_pPathSelectorLabel->setText(UIWizardImportApp::tr("You can modify the base folder which will host "
231 "all the virtual machines. Virtual home folders "
232 "can also be individually modified."));
233
234}
235
236void UIApplianceImportEditorWidget::sltHandlePathChanged(const QString &newPath)
237{
238 setVirtualSystemBaseFolder(newPath);
239}
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