VirtualBox

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

Last change on this file since 69500 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1/* $Id: UIApplianceImportEditorWidget.cpp 69500 2017-10-28 15:14:05Z 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
26/* GUI includes: */
27# include "QITreeView.h"
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
41class ImportSortProxyModel: public UIApplianceSortProxyModel
42{
43public:
44 ImportSortProxyModel(QObject *pParent = NULL)
45 : UIApplianceSortProxyModel(pParent)
46 {
47 m_aFilteredList << KVirtualSystemDescriptionType_License;
48 }
49};
50
51////////////////////////////////////////////////////////////////////////////////
52// UIApplianceImportEditorWidget
53
54UIApplianceImportEditorWidget::UIApplianceImportEditorWidget(QWidget *pParent)
55 : UIApplianceEditorWidget(pParent)
56{
57 /* Show the MAC check box */
58 m_pCheckBoxReinitMACs->setHidden(false);
59}
60
61bool 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 UIApplianceModel(vsds, m_pTreeViewSettings);
95
96 ImportSortProxyModel *pProxy = new ImportSortProxyModel(this);
97 pProxy->setSourceModel(m_pModel);
98 pProxy->sort(ApplianceViewSection_Description, Qt::DescendingOrder);
99
100 UIApplianceDelegate *pDelegate = new UIApplianceDelegate(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 /* Set model root index and make it current: */
111 m_pTreeViewSettings->setRootIndex(pProxy->mapFromSource(m_pModel->root()));
112 m_pTreeViewSettings->setCurrentIndex(pProxy->mapFromSource(m_pModel->root()));
113
114 /* Check for warnings & if there are one display them. */
115 bool fWarningsEnabled = false;
116 QVector<QString> warnings = m_pAppliance->GetWarnings();
117 if (warnings.size() > 0)
118 {
119 foreach (const QString& text, warnings)
120 m_pTextEditWarning->append("- " + text);
121 fWarningsEnabled = true;
122 }
123 m_pPaneWarning->setVisible(fWarningsEnabled);
124 }
125 }
126 }
127 }
128 if (!fResult)
129 {
130 if (!m_pAppliance->isOk())
131 msgCenter().cannotImportAppliance(*m_pAppliance, this);
132 else if (!progress.isNull() && (!progress.isOk() || progress.GetResultCode() != 0))
133 msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
134 /* Delete the appliance in a case of an error */
135 delete m_pAppliance;
136 m_pAppliance = NULL;
137 }
138 }
139 return fResult;
140}
141
142void UIApplianceImportEditorWidget::prepareImport()
143{
144 if (m_pAppliance)
145 m_pModel->putBack();
146}
147
148bool UIApplianceImportEditorWidget::import()
149{
150 if (m_pAppliance)
151 {
152 /* Start the import asynchronously */
153 CProgress progress;
154 QVector<KImportOptions> options;
155 if (!m_pCheckBoxReinitMACs->isChecked())
156 options.append(KImportOptions_KeepAllMACs);
157 progress = m_pAppliance->ImportMachines(options);
158 bool fResult = m_pAppliance->isOk();
159 if (fResult)
160 {
161 /* Show some progress, so the user know whats going on */
162 msgCenter().showModalProgressDialog(progress, tr("Importing Appliance ..."), ":/progress_import_90px.png", this);
163 if (progress.GetCanceled())
164 return false;
165 if (!progress.isOk() || progress.GetResultCode() != 0)
166 {
167 msgCenter().cannotImportAppliance(progress, m_pAppliance->GetPath(), this);
168 return false;
169 }
170 else
171 return true;
172 }
173 if (!fResult)
174 msgCenter().cannotImportAppliance(*m_pAppliance, this);
175 }
176 return false;
177}
178
179QList<QPair<QString, QString> > UIApplianceImportEditorWidget::licenseAgreements() const
180{
181 QList<QPair<QString, QString> > list;
182
183 CVirtualSystemDescriptionVector vsds = m_pAppliance->GetVirtualSystemDescriptions();
184 for (int i = 0; i < vsds.size(); ++i)
185 {
186 QVector<QString> strLicense;
187 strLicense = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_License,
188 KVirtualSystemDescriptionValueType_Original);
189 if (!strLicense.isEmpty())
190 {
191 QVector<QString> strName;
192 strName = vsds[i].GetValuesByType(KVirtualSystemDescriptionType_Name,
193 KVirtualSystemDescriptionValueType_Auto);
194 list << QPair<QString, QString>(strName.first(), strLicense.first());
195 }
196 }
197
198 return list;
199}
200
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