VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxImportApplianceWgt.cpp@ 35740

Last change on this file since 35740 was 34530, checked in by vboxsync, 14 years ago

FE/Qt4: more progress images

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

© 2023 Oracle
ContactPrivacy policyTerms of Use