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