VirtualBox

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

Last change on this file since 74626 was 74626, checked in by vboxsync, 6 years ago

FE/Qt: bugref:9260. Adding a label to import wizard(s) for additional option checkboxes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.1 KB
Line 
1/* $Id: UIApplianceImportEditorWidget.cpp 74626 2018-10-05 11:57:03Z 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 <QGridLayout>
25# include <QLabel>
26# include <QTextEdit>
27# include <QVBoxLayout>
28
29/* GUI includes: */
30# include "QIRichTextLabel.h"
31# include "QITreeView.h"
32# include "UIApplianceImportEditorWidget.h"
33# include "UIFilePathSelector.h"
34# include "UIMessageCenter.h"
35# include "UIWizardImportApp.h"
36# include "VBoxGlobal.h"
37
38/* COM includes: */
39# include "CAppliance.h"
40# include "CSystemProperties.h"
41
42#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
43
44
45////////////////////////////////////////////////////////////////////////////////
46// ImportSortProxyModel
47
48class ImportSortProxyModel: public UIApplianceSortProxyModel
49{
50public:
51 ImportSortProxyModel(QObject *pParent = NULL)
52 : UIApplianceSortProxyModel(pParent)
53 {
54 m_aFilteredList << KVirtualSystemDescriptionType_License;
55 }
56};
57
58////////////////////////////////////////////////////////////////////////////////
59// UIApplianceImportEditorWidget
60
61UIApplianceImportEditorWidget::UIApplianceImportEditorWidget(QWidget *pParent)
62 : UIApplianceEditorWidget(pParent)
63 , m_pPathSelectorLabel(0)
64 , m_pPathSelector(0)
65 , m_pImportHDsAsVDI(0)
66 , m_pMACComboBoxLabel(0)
67 , m_pMACComboBox(0)
68 , m_pOptionsLayout(0)
69 , m_pAdditionalOptionsLabel(0)
70{
71 prepareWidgets();
72}
73
74void UIApplianceImportEditorWidget::prepareWidgets()
75{
76 m_pPathSelectorLabel = new QIRichTextLabel(this);
77 if (m_pPathSelectorLabel)
78 {
79 m_pLayout->addWidget(m_pPathSelectorLabel);
80 }
81 m_pPathSelector = new UIFilePathSelector(this);
82 if (m_pPathSelector)
83 {
84 m_pPathSelector->setResetEnabled(true);
85 m_pPathSelector->setDefaultPath(vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder());
86 m_pPathSelector->setPath(vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder());
87 connect(m_pPathSelector, &UIFilePathSelector::pathChanged, this, &UIApplianceImportEditorWidget::sltHandlePathChanged);
88 m_pLayout->addWidget(m_pPathSelector);
89 }
90
91 m_pOptionsLayout = new QGridLayout;
92
93 m_pMACComboBox = new QComboBox;
94 if (m_pMACComboBox)
95 {
96 m_pMACComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
97 /* Add into layout: */
98 m_pOptionsLayout->addWidget(m_pMACComboBox, 0, 1);
99 }
100
101 /* Create format combo-box label: */
102 m_pMACComboBoxLabel = new QLabel;
103 if (m_pMACComboBoxLabel)
104 {
105 m_pMACComboBoxLabel->setAlignment(Qt::AlignLeft | Qt::AlignTrailing | Qt::AlignVCenter);
106 /* Add into layout: */
107 m_pOptionsLayout->addWidget(m_pMACComboBoxLabel, 0, 0);
108 }
109
110 if (m_pMACComboBoxLabel)
111 m_pMACComboBoxLabel->setBuddy(m_pMACComboBox);
112
113 m_pAdditionalOptionsLabel = new QLabel;
114 if (m_pAdditionalOptionsLabel)
115 {
116 m_pAdditionalOptionsLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
117 m_pOptionsLayout->addWidget(m_pAdditionalOptionsLabel, 2, 0, 1, 1);
118 }
119
120 m_pImportHDsAsVDI = new QCheckBox;
121 {
122 m_pOptionsLayout->addWidget(m_pImportHDsAsVDI, 2, 1);
123 m_pImportHDsAsVDI->setCheckState(Qt::Checked);
124 }
125
126
127 m_pLayout->addLayout(m_pOptionsLayout);
128 populateMACAddressImportPolicies();
129 connect(m_pMACComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
130 this, &UIApplianceImportEditorWidget::sltHandleMACAddressImportPolicyComboChange);
131 retranslateUi();
132}
133
134bool UIApplianceImportEditorWidget::setFile(const QString& strFile)
135{
136 bool fResult = false;
137 if (!strFile.isEmpty())
138 {
139 CProgress progress;
140 CVirtualBox vbox = vboxGlobal().virtualBox();
141 /* Create a appliance object */
142 m_pAppliance = new CAppliance(vbox.CreateAppliance());
143 fResult = m_pAppliance->isOk();
144 if (fResult)
145 {
146 /* Read the appliance */
147 progress = m_pAppliance->Read(strFile);
148 fResult = m_pAppliance->isOk();
149 if (fResult)
150 {
151 /* Show some progress, so the user know whats going on */
152 msgCenter().showModalProgressDialog(progress, tr("Reading Appliance ..."), ":/progress_reading_appliance_90px.png", this);
153 if (!progress.isOk() || progress.GetResultCode() != 0)
154 fResult = false;
155 else
156 {
157 /* Now we have to interpret that stuff */
158 m_pAppliance->Interpret();
159 fResult = m_pAppliance->isOk();
160 if (fResult)
161 {
162 if (m_pModel)
163 delete m_pModel;
164
165 QVector<CVirtualSystemDescription> vsds = m_pAppliance->GetVirtualSystemDescriptions();
166
167 m_pModel = new UIApplianceModel(vsds, m_pTreeViewSettings);
168
169 ImportSortProxyModel *pProxy = new ImportSortProxyModel(this);
170 pProxy->setSourceModel(m_pModel);
171 pProxy->sort(ApplianceViewSection_Description, Qt::DescendingOrder);
172
173 UIApplianceDelegate *pDelegate = new UIApplianceDelegate(pProxy, this);
174
175 /* Set our own model */
176 m_pTreeViewSettings->setModel(pProxy);
177 /* Set our own delegate */
178 m_pTreeViewSettings->setItemDelegate(pDelegate);
179 /* For now we hide the original column. This data is displayed as tooltip
180 also. */
181 m_pTreeViewSettings->setColumnHidden(ApplianceViewSection_OriginalValue, true);
182 m_pTreeViewSettings->expandAll();
183 /* Set model root index and make it current: */
184 m_pTreeViewSettings->setRootIndex(pProxy->mapFromSource(m_pModel->root()));
185 m_pTreeViewSettings->setCurrentIndex(pProxy->mapFromSource(m_pModel->root()));
186
187 /* Check for warnings & if there are one display them. */
188 bool fWarningsEnabled = false;
189 QVector<QString> warnings = m_pAppliance->GetWarnings();
190 if (warnings.size() > 0)
191 {
192 foreach (const QString& text, warnings)
193 m_pTextEditWarning->append("- " + text);
194 fWarningsEnabled = true;
195 }
196 m_pPaneWarning->setVisible(fWarningsEnabled);
197 }
198 }
199 }
200 }
201 if (!fResult)
202 {
203 if (!m_pAppliance->isOk())
204 msgCenter().cannotImportAppliance(*m_pAppliance, this);
205 else if (!progress.isNull() && (!progress.isOk() || progress.GetResultCode() != 0))
206 msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
207 /* Delete the appliance in a case of an error */
208 delete m_pAppliance;
209 m_pAppliance = NULL;
210 }
211 }
212 /* Make sure we initialize model items with correct base folder path: */
213 if (m_pPathSelector)
214 sltHandlePathChanged(m_pPathSelector->path());
215
216 return fResult;
217}
218
219void UIApplianceImportEditorWidget::prepareImport()
220{
221 if (m_pAppliance)
222 m_pModel->putBack();
223}
224
225bool UIApplianceImportEditorWidget::import()
226{
227 if (m_pAppliance)
228 {
229 /* Start the import asynchronously */
230 CProgress progress;
231 QVector<KImportOptions> options;
232 if (m_pMACComboBox)
233 {
234 MACAddressImportPolicy macPolicy = static_cast<MACAddressImportPolicy>(m_pMACComboBox->currentIndex());
235 switch (macPolicy)
236 {
237 case MACAddressImportPolicy_KeepAllMACs:
238 options.append(KImportOptions_KeepAllMACs);
239 break;
240 case MACAddressImportPolicy_KeepNATMACs:
241 options.append(KImportOptions_KeepNATMACs);
242 break;
243 default:
244 break;
245 }
246 }
247
248 if (m_pImportHDsAsVDI->isChecked())
249 options.append(KImportOptions_ImportToVDI);
250 progress = m_pAppliance->ImportMachines(options);
251 bool fResult = m_pAppliance->isOk();
252 if (fResult)
253 {
254 /* Show some progress, so the user know whats going on */
255 msgCenter().showModalProgressDialog(progress, tr("Importing Appliance ..."), ":/progress_import_90px.png", this);
256 if (progress.GetCanceled())
257 return false;
258 if (!progress.isOk() || progress.GetResultCode() != 0)
259 {
260 msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
261 return false;
262 }
263 else
264 return true;
265 }
266 if (!fResult)
267 msgCenter().cannotImportAppliance(*m_pAppliance, this);
268 }
269 return false;
270}
271
272QList<QPair<QString, QString> > UIApplianceImportEditorWidget::licenseAgreements() const
273{
274 QList<QPair<QString, QString> > list;
275
276 CVirtualSystemDescriptionVector vsds = m_pAppliance->GetVirtualSystemDescriptions();
277 for (int i = 0; i < vsds.size(); ++i)
278 {
279 QVector<QString> strLicense;
280 strLicense = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_License,
281 KVirtualSystemDescriptionValueType_Original);
282 if (!strLicense.isEmpty())
283 {
284 QVector<QString> strName;
285 strName = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_Name,
286 KVirtualSystemDescriptionValueType_Auto);
287 list << QPair<QString, QString>(strName.first(), strLicense.first());
288 }
289 }
290
291 return list;
292}
293
294void UIApplianceImportEditorWidget::retranslateUi()
295{
296 UIApplianceEditorWidget::retranslateUi();
297 if (m_pPathSelectorLabel)
298 m_pPathSelectorLabel->setText(UIWizardImportApp::tr("You can modify the base folder which will host all the virtual machines.\n"
299 "Home folders can also be individually (per virtual machine) modified."));
300 if (m_pImportHDsAsVDI)
301 {
302 m_pImportHDsAsVDI->setText(tr("&Import hard drives as VDI"));
303 m_pImportHDsAsVDI->setToolTip(tr("When checked a all the hard drives that belong to this appliance will be imported in VDI format"));
304 }
305
306 /* Translate MAC address policy combo-box: */
307 m_pMACComboBoxLabel->setText(tr("MAC Address &Policy:"));
308 m_pMACComboBox->setItemText(MACAddressImportPolicy_KeepAllMACs,
309 tr("Include all network adapter MAC addresses"));
310 m_pMACComboBox->setItemText(MACAddressImportPolicy_KeepNATMACs,
311 tr("Include only NAT network adapter MAC addresses"));
312 m_pMACComboBox->setItemText(MACAddressImportPolicy_StripAllMACs,
313 tr("Generate new MAC addresses for all network adapters"));
314 m_pMACComboBox->setItemData(MACAddressImportPolicy_KeepAllMACs,
315 tr("Include all network adapter MAC addresses in exported "
316 "during cloning."), Qt::ToolTipRole);
317 m_pMACComboBox->setItemData(MACAddressImportPolicy_KeepNATMACs,
318 tr("Include only NAT network adapter MAC addresses "
319 "during cloning."), Qt::ToolTipRole);
320 m_pMACComboBox->setItemData(MACAddressImportPolicy_StripAllMACs,
321 tr("Generate new MAC addresses for all network adapters "
322 "during cloning."), Qt::ToolTipRole);
323
324 m_pAdditionalOptionsLabel->setText(tr("Additional Options:"));
325
326 QList<QWidget*> labels;
327 labels << m_pMACComboBoxLabel;
328 labels << m_pAdditionalOptionsLabel;
329
330 int iMaxWidth = 0;
331 foreach (QWidget *pLabel, labels)
332 iMaxWidth = qMax(iMaxWidth, pLabel->minimumSizeHint().width());
333 m_pOptionsLayout->setColumnMinimumWidth(0, iMaxWidth);
334}
335
336void UIApplianceImportEditorWidget::sltHandlePathChanged(const QString &newPath)
337{
338 setVirtualSystemBaseFolder(newPath);
339}
340
341void UIApplianceImportEditorWidget::populateMACAddressImportPolicies()
342{
343 AssertReturnVoid(m_pMACComboBox->count() == 0);
344
345 /* Apply hardcoded policies list: */
346 for (int i = 0; i < (int)MACAddressImportPolicy_MAX; ++i)
347 {
348 m_pMACComboBox->addItem(QString::number(i));
349 m_pMACComboBox->setItemData(i, i);
350 }
351
352 /* Set default: */
353 setMACAddressImportPolicy(MACAddressImportPolicy_KeepNATMACs);
354}
355
356void UIApplianceImportEditorWidget::setMACAddressImportPolicy(MACAddressImportPolicy enmMACAddressImportPolicy)
357{
358 const int iIndex = m_pMACComboBox->findData((int)enmMACAddressImportPolicy);
359 AssertMsg(iIndex != -1, ("Data not found!"));
360 m_pMACComboBox->setCurrentIndex(iIndex);
361}
362
363void UIApplianceImportEditorWidget::sltHandleMACAddressImportPolicyComboChange()
364{
365 /* Update tool-tip: */
366 updateMACAddressImportPolicyComboToolTip();
367}
368
369void UIApplianceImportEditorWidget::updateMACAddressImportPolicyComboToolTip()
370{
371 const int iCurrentIndex = m_pMACComboBox->currentIndex();
372 const QString strCurrentToolTip = m_pMACComboBox->itemData(iCurrentIndex, Qt::ToolTipRole).toString();
373 AssertMsg(!strCurrentToolTip.isEmpty(), ("Data not found!"));
374 m_pMACComboBox->setToolTip(strCurrentToolTip);
375}
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