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