VirtualBox

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

Last change on this file since 52727 was 52727, checked in by vboxsync, 11 years ago

FE/Qt: file header cleanups.

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