1 | /* $Id: UIApplianceImportEditorWidget.cpp 45424 2013-04-09 08:21:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt4 GUI ("VirtualBox"):
|
---|
5 | * UIApplianceImportEditorWidget class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2009-2012 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* GUI includes: */
|
---|
21 | #include "UIApplianceImportEditorWidget.h"
|
---|
22 | #include "VBoxGlobal.h"
|
---|
23 | #include "UIMessageCenter.h"
|
---|
24 |
|
---|
25 | /* COM includes: */
|
---|
26 | #include "CAppliance.h"
|
---|
27 |
|
---|
28 | ////////////////////////////////////////////////////////////////////////////////
|
---|
29 | // ImportSortProxyModel
|
---|
30 |
|
---|
31 | class ImportSortProxyModel: public VirtualSystemSortProxyModel
|
---|
32 | {
|
---|
33 | public:
|
---|
34 | ImportSortProxyModel(QObject *pParent = NULL)
|
---|
35 | : VirtualSystemSortProxyModel(pParent)
|
---|
36 | {
|
---|
37 | m_filterList << KVirtualSystemDescriptionType_License;
|
---|
38 | }
|
---|
39 | };
|
---|
40 |
|
---|
41 | ////////////////////////////////////////////////////////////////////////////////
|
---|
42 | // UIApplianceImportEditorWidget
|
---|
43 |
|
---|
44 | UIApplianceImportEditorWidget::UIApplianceImportEditorWidget(QWidget *pParent)
|
---|
45 | : UIApplianceEditorWidget(pParent)
|
---|
46 | {
|
---|
47 | /* Show the MAC check box */
|
---|
48 | m_pReinitMACsCheckBox->setHidden(false);
|
---|
49 | }
|
---|
50 |
|
---|
51 | bool UIApplianceImportEditorWidget::setFile(const QString& strFile)
|
---|
52 | {
|
---|
53 | bool fResult = false;
|
---|
54 | if (!strFile.isEmpty())
|
---|
55 | {
|
---|
56 | CProgress progress;
|
---|
57 | CVirtualBox vbox = vboxGlobal().virtualBox();
|
---|
58 | /* Create a appliance object */
|
---|
59 | m_pAppliance = new CAppliance(vbox.CreateAppliance());
|
---|
60 | fResult = m_pAppliance->isOk();
|
---|
61 | if (fResult)
|
---|
62 | {
|
---|
63 | /* Read the appliance */
|
---|
64 | progress = m_pAppliance->Read(strFile);
|
---|
65 | fResult = m_pAppliance->isOk();
|
---|
66 | if (fResult)
|
---|
67 | {
|
---|
68 | /* Show some progress, so the user know whats going on */
|
---|
69 | msgCenter().showModalProgressDialog(progress, tr("Reading Appliance ..."), ":/shared_folder_32px.png", this);
|
---|
70 | if (!progress.isOk() || progress.GetResultCode() != 0)
|
---|
71 | fResult = false;
|
---|
72 | else
|
---|
73 | {
|
---|
74 | /* Now we have to interpret that stuff */
|
---|
75 | m_pAppliance->Interpret();
|
---|
76 | fResult = m_pAppliance->isOk();
|
---|
77 | if (fResult)
|
---|
78 | {
|
---|
79 | if (m_pModel)
|
---|
80 | delete m_pModel;
|
---|
81 |
|
---|
82 | QVector<CVirtualSystemDescription> vsds = m_pAppliance->GetVirtualSystemDescriptions();
|
---|
83 |
|
---|
84 | m_pModel = new VirtualSystemModel(vsds, this);
|
---|
85 |
|
---|
86 | ImportSortProxyModel *pProxy = new ImportSortProxyModel(this);
|
---|
87 | pProxy->setSourceModel(m_pModel);
|
---|
88 | pProxy->sort(DescriptionSection, Qt::DescendingOrder);
|
---|
89 |
|
---|
90 | VirtualSystemDelegate *pDelegate = new VirtualSystemDelegate(pProxy, this);
|
---|
91 |
|
---|
92 | /* Set our own model */
|
---|
93 | m_pTvSettings->setModel(pProxy);
|
---|
94 | /* Set our own delegate */
|
---|
95 | m_pTvSettings->setItemDelegate(pDelegate);
|
---|
96 | /* For now we hide the original column. This data is displayed as tooltip
|
---|
97 | also. */
|
---|
98 | m_pTvSettings->setColumnHidden(OriginalValueSection, true);
|
---|
99 | m_pTvSettings->expandAll();
|
---|
100 |
|
---|
101 | /* Check for warnings & if there are one display them. */
|
---|
102 | bool fWarningsEnabled = false;
|
---|
103 | QVector<QString> warnings = m_pAppliance->GetWarnings();
|
---|
104 | if (warnings.size() > 0)
|
---|
105 | {
|
---|
106 | foreach (const QString& text, warnings)
|
---|
107 | mWarningTextEdit->append("- " + text);
|
---|
108 | fWarningsEnabled = true;
|
---|
109 | }
|
---|
110 | m_pWarningWidget->setShown(fWarningsEnabled);
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 | }
|
---|
115 | if (!fResult)
|
---|
116 | {
|
---|
117 | if (progress.isNull())
|
---|
118 | msgCenter().cannotImportAppliance(*m_pAppliance, this);
|
---|
119 | else
|
---|
120 | msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
|
---|
121 | /* Delete the appliance in a case of an error */
|
---|
122 | delete m_pAppliance;
|
---|
123 | m_pAppliance = NULL;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | return fResult;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void UIApplianceImportEditorWidget::prepareImport()
|
---|
130 | {
|
---|
131 | if (m_pAppliance)
|
---|
132 | m_pModel->putBack();
|
---|
133 | }
|
---|
134 |
|
---|
135 | bool UIApplianceImportEditorWidget::import()
|
---|
136 | {
|
---|
137 | if (m_pAppliance)
|
---|
138 | {
|
---|
139 | /* Start the import asynchronously */
|
---|
140 | CProgress progress;
|
---|
141 | QVector<KImportOptions> options;
|
---|
142 | if (!m_pReinitMACsCheckBox->isChecked())
|
---|
143 | options.append(KImportOptions_KeepAllMACs);
|
---|
144 | progress = m_pAppliance->ImportMachines(options);
|
---|
145 | bool fResult = m_pAppliance->isOk();
|
---|
146 | if (fResult)
|
---|
147 | {
|
---|
148 | /* Show some progress, so the user know whats going on */
|
---|
149 | msgCenter().showModalProgressDialog(progress, tr("Importing Appliance ..."), ":/progress_import_90px.png", this);
|
---|
150 | if (progress.GetCanceled())
|
---|
151 | return false;
|
---|
152 | if (!progress.isOk() || progress.GetResultCode() != 0)
|
---|
153 | {
|
---|
154 | msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
|
---|
155 | return false;
|
---|
156 | }
|
---|
157 | else
|
---|
158 | return true;
|
---|
159 | }
|
---|
160 | if (!fResult)
|
---|
161 | msgCenter().cannotImportAppliance(*m_pAppliance, this);
|
---|
162 | }
|
---|
163 | return false;
|
---|
164 | }
|
---|
165 |
|
---|
166 | QList<QPair<QString, QString> > UIApplianceImportEditorWidget::licenseAgreements() const
|
---|
167 | {
|
---|
168 | QList<QPair<QString, QString> > list;
|
---|
169 |
|
---|
170 | CVirtualSystemDescriptionVector vsds = m_pAppliance->GetVirtualSystemDescriptions();
|
---|
171 | for (int i = 0; i < vsds.size(); ++i)
|
---|
172 | {
|
---|
173 | QVector<QString> strLicense;
|
---|
174 | strLicense = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_License,
|
---|
175 | KVirtualSystemDescriptionValueType_Original);
|
---|
176 | if (!strLicense.isEmpty())
|
---|
177 | {
|
---|
178 | QVector<QString> strName;
|
---|
179 | strName = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_Name,
|
---|
180 | KVirtualSystemDescriptionValueType_Auto);
|
---|
181 | list << QPair<QString, QString>(strName.first(), strLicense.first());
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | return list;
|
---|
186 | }
|
---|
187 |
|
---|