VirtualBox

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

Last change on this file since 62493 was 62493, checked in by vboxsync, 9 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/* $Id: UIApplianceImportEditorWidget.cpp 62493 2016-07-22 18:44:18Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIApplianceImportEditorWidget class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2016 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/* GUI includes: */
23# include "UIApplianceImportEditorWidget.h"
24# include "VBoxGlobal.h"
25# include "UIMessageCenter.h"
26
27/* COM includes: */
28# include "CAppliance.h"
29
30#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
31
32
33////////////////////////////////////////////////////////////////////////////////
34// ImportSortProxyModel
35
36class ImportSortProxyModel: public VirtualSystemSortProxyModel
37{
38public:
39 ImportSortProxyModel(QObject *pParent = NULL)
40 : VirtualSystemSortProxyModel(pParent)
41 {
42 m_filterList << KVirtualSystemDescriptionType_License;
43 }
44};
45
46////////////////////////////////////////////////////////////////////////////////
47// UIApplianceImportEditorWidget
48
49UIApplianceImportEditorWidget::UIApplianceImportEditorWidget(QWidget *pParent)
50 : UIApplianceEditorWidget(pParent)
51{
52 /* Show the MAC check box */
53 m_pReinitMACsCheckBox->setHidden(false);
54}
55
56bool UIApplianceImportEditorWidget::setFile(const QString& strFile)
57{
58 bool fResult = false;
59 if (!strFile.isEmpty())
60 {
61 CProgress progress;
62 CVirtualBox vbox = vboxGlobal().virtualBox();
63 /* Create a appliance object */
64 m_pAppliance = new CAppliance(vbox.CreateAppliance());
65 fResult = m_pAppliance->isOk();
66 if (fResult)
67 {
68 /* Read the appliance */
69 progress = m_pAppliance->Read(strFile);
70 fResult = m_pAppliance->isOk();
71 if (fResult)
72 {
73 /* Show some progress, so the user know whats going on */
74 msgCenter().showModalProgressDialog(progress, tr("Reading Appliance ..."), ":/progress_reading_appliance_90px.png", this);
75 if (!progress.isOk() || progress.GetResultCode() != 0)
76 fResult = false;
77 else
78 {
79 /* Now we have to interpret that stuff */
80 m_pAppliance->Interpret();
81 fResult = m_pAppliance->isOk();
82 if (fResult)
83 {
84 if (m_pModel)
85 delete m_pModel;
86
87 QVector<CVirtualSystemDescription> vsds = m_pAppliance->GetVirtualSystemDescriptions();
88
89 m_pModel = new VirtualSystemModel(vsds, this);
90
91 ImportSortProxyModel *pProxy = new ImportSortProxyModel(this);
92 pProxy->setSourceModel(m_pModel);
93 pProxy->sort(DescriptionSection, Qt::DescendingOrder);
94
95 VirtualSystemDelegate *pDelegate = new VirtualSystemDelegate(pProxy, this);
96
97 /* Set our own model */
98 m_pTvSettings->setModel(pProxy);
99 /* Set our own delegate */
100 m_pTvSettings->setItemDelegate(pDelegate);
101 /* For now we hide the original column. This data is displayed as tooltip
102 also. */
103 m_pTvSettings->setColumnHidden(OriginalValueSection, true);
104 m_pTvSettings->expandAll();
105
106 /* Check for warnings & if there are one display them. */
107 bool fWarningsEnabled = false;
108 QVector<QString> warnings = m_pAppliance->GetWarnings();
109 if (warnings.size() > 0)
110 {
111 foreach (const QString& text, warnings)
112 mWarningTextEdit->append("- " + text);
113 fWarningsEnabled = true;
114 }
115 m_pWarningWidget->setVisible(fWarningsEnabled);
116 }
117 }
118 }
119 }
120 if (!fResult)
121 {
122 if (!m_pAppliance->isOk())
123 msgCenter().cannotImportAppliance(*m_pAppliance, this);
124 else if (!progress.isNull() && (!progress.isOk() || progress.GetResultCode() != 0))
125 msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
126 /* Delete the appliance in a case of an error */
127 delete m_pAppliance;
128 m_pAppliance = NULL;
129 }
130 }
131 return fResult;
132}
133
134void UIApplianceImportEditorWidget::prepareImport()
135{
136 if (m_pAppliance)
137 m_pModel->putBack();
138}
139
140bool UIApplianceImportEditorWidget::import()
141{
142 if (m_pAppliance)
143 {
144 /* Start the import asynchronously */
145 CProgress progress;
146 QVector<KImportOptions> options;
147 if (!m_pReinitMACsCheckBox->isChecked())
148 options.append(KImportOptions_KeepAllMACs);
149 progress = m_pAppliance->ImportMachines(options);
150 bool fResult = m_pAppliance->isOk();
151 if (fResult)
152 {
153 /* Show some progress, so the user know whats going on */
154 msgCenter().showModalProgressDialog(progress, tr("Importing Appliance ..."), ":/progress_import_90px.png", this);
155 if (progress.GetCanceled())
156 return false;
157 if (!progress.isOk() || progress.GetResultCode() != 0)
158 {
159 msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
160 return false;
161 }
162 else
163 return true;
164 }
165 if (!fResult)
166 msgCenter().cannotImportAppliance(*m_pAppliance, this);
167 }
168 return false;
169}
170
171QList<QPair<QString, QString> > UIApplianceImportEditorWidget::licenseAgreements() const
172{
173 QList<QPair<QString, QString> > list;
174
175 CVirtualSystemDescriptionVector vsds = m_pAppliance->GetVirtualSystemDescriptions();
176 for (int i = 0; i < vsds.size(); ++i)
177 {
178 QVector<QString> strLicense;
179 strLicense = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_License,
180 KVirtualSystemDescriptionValueType_Original);
181 if (!strLicense.isEmpty())
182 {
183 QVector<QString> strName;
184 strName = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_Name,
185 KVirtualSystemDescriptionValueType_Auto);
186 list << QPair<QString, QString>(strName.first(), strLicense.first());
187 }
188 }
189
190 return list;
191}
192
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette