VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceEditorWidget.cpp@ 100347

Last change on this file since 100347 was 99604, checked in by vboxsync, 17 months ago

bugref:10314. bugref:10278. Reverted VSD RAM unit to bytes and fixed other places where MB unit was used.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 83.5 KB
Line 
1/* $Id: UIApplianceEditorWidget.cpp 99604 2023-05-04 13:53:06Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIApplianceEditorWidget class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QCheckBox>
30#include <QComboBox>
31#include <QDir>
32#include <QHeaderView>
33#include <QLabel>
34#include <QLineEdit>
35#include <QRegExp>
36#include <QSpinBox>
37#include <QTextEdit>
38#include <QVBoxLayout>
39
40/* GUI includes: */
41#include "QITreeView.h"
42#include "UICommon.h"
43#include "UIGuestOSTypeSelectionButton.h"
44#include "UIApplianceEditorWidget.h"
45#include "UIConverter.h"
46#include "UIFilePathSelector.h"
47#include "UIIconPool.h"
48#include "UILineTextEdit.h"
49#include "UIMessageCenter.h"
50#include "UITranslator.h"
51
52/* COM includes: */
53#include "CSystemProperties.h"
54
55
56/** Describes the interface of Appliance item.
57 * Represented as a tree structure with a parent & multiple children. */
58class UIApplianceModelItem : public QITreeViewItem
59{
60 Q_OBJECT;
61
62public:
63
64 /** Constructs root item with specified @a iNumber, @a enmType and @a pParent. */
65 UIApplianceModelItem(int iNumber, ApplianceModelItemType enmType, QITreeView *pParent);
66 /** Constructs non-root item with specified @a iNumber, @a enmType and @a pParentItem. */
67 UIApplianceModelItem(int iNumber, ApplianceModelItemType enmType, UIApplianceModelItem *pParentItem);
68 /** Destructs item. */
69 virtual ~UIApplianceModelItem();
70
71 /** Returns the item type. */
72 ApplianceModelItemType type() const { return m_enmType; }
73
74 /** Returns the parent of the item. */
75 UIApplianceModelItem *parent() const { return m_pParentItem; }
76
77 /** Appends the passed @a pChildItem to the item's list of children. */
78 void appendChild(UIApplianceModelItem *pChildItem);
79 /** Returns the child specified by the @a iIndex. */
80 virtual UIApplianceModelItem *childItem(int iIndex) const RT_OVERRIDE;
81
82 /** Returns the row of the item in the parent. */
83 int row() const;
84
85 /** Returns the number of children. */
86 virtual int childCount() const RT_OVERRIDE;
87 /** Returns the number of columns. */
88 int columnCount() const { return 3; }
89
90 /** Returns the item text. */
91 virtual QString text() const RT_OVERRIDE;
92
93 /** Returns the item flags for the given @a iColumn. */
94 virtual Qt::ItemFlags itemFlags(int /* iColumn */) const { return Qt::ItemFlags(); }
95
96 /** Defines the @a iRole data for the item at @a iColumn to @a value. */
97 virtual bool setData(int /* iColumn */, const QVariant & /* value */, int /* iRole */) { return false; }
98 /** Returns the data stored under the given @a iRole for the item referred to by the @a iColumn. */
99 virtual QVariant data(int /* iColumn */, int /* iRole */) const { return QVariant(); }
100
101 /** Returns the widget used to edit the item specified by @a idx for editing.
102 * @param pParent Brings the parent to be assigned for newly created editor.
103 * @param styleOption Bring the style option set for the newly created editor. */
104 virtual QWidget *createEditor(QWidget * /* pParent */, const QStyleOptionViewItem & /* styleOption */, const QModelIndex & /* idx */) const { return 0; }
105
106 /** Defines the contents of the given @a pEditor to the data for the item at the given @a idx. */
107 virtual bool setEditorData(QWidget * /* pEditor */, const QModelIndex & /* idx */) const { return false; }
108 /** Defines the data for the item at the given @a idx in the @a pModel to the contents of the given @a pEditor. */
109 virtual bool setModelData(QWidget * /* pEditor */, QAbstractItemModel * /* pModel */, const QModelIndex & /* idx */) { return false; }
110
111 /** Restores the default values. */
112 virtual void restoreDefaults() {}
113
114 /** Cache currently stored values, such as @a finalStates, @a finalValues and @a finalExtraValues. */
115 virtual void putBack(QVector<BOOL> &finalStates, QVector<QString> &finalValues, QVector<QString> &finalExtraValues);
116
117protected:
118
119 /** Holds the item number. */
120 int m_iNumber;
121 /** Holds the item type. */
122 ApplianceModelItemType m_enmType;
123
124 /** Holds the parent item reference. */
125 UIApplianceModelItem *m_pParentItem;
126 /** Holds the list of children item instances. */
127 QList<UIApplianceModelItem*> m_childItems;
128};
129
130
131/** UIApplianceModelItem subclass representing Appliance Virtual System item. */
132class UIVirtualSystemItem : public UIApplianceModelItem
133{
134public:
135
136 /** Constructs item passing @a iNumber and @a pParentItem to the base-class.
137 * @param comDescription Brings the Virtual System Description. */
138 UIVirtualSystemItem(int iNumber, CVirtualSystemDescription comDescription, UIApplianceModelItem *pParentItem);
139
140 /** Returns the data stored under the given @a iRole for the item referred to by the @a iColumn. */
141 virtual QVariant data(int iColumn, int iRole) const RT_OVERRIDE;
142
143 /** Cache currently stored values, such as @a finalStates, @a finalValues and @a finalExtraValues. */
144 virtual void putBack(QVector<BOOL> &finalStates, QVector<QString> &finalValues, QVector<QString> &finalExtraValues) RT_OVERRIDE;
145
146private:
147
148 /** Holds the Virtual System Description. */
149 CVirtualSystemDescription m_comDescription;
150};
151
152
153/** UIApplianceModelItem subclass representing Appliance Virtual Hardware item. */
154class UIVirtualHardwareItem : public UIApplianceModelItem
155{
156 friend class UIApplianceSortProxyModel;
157
158 /** Data roles. */
159 enum
160 {
161 TypeRole = Qt::UserRole,
162 ModifiedRole
163 };
164
165public:
166
167 /** Constructs item passing @a iNumber and @a pParentItem to the base-class.
168 * @param pParent Brings the parent reference.
169 * @param enmVSDType Brings the Virtual System Description type.
170 * @param strRef Brings something totally useless.
171 * @param strOrigValue Brings the original value.
172 * @param strConfigValue Brings the configuration value.
173 * @param strExtraConfigValue Brings the extra configuration value. */
174 UIVirtualHardwareItem(UIApplianceModel *pParent,
175 int iNumber,
176 KVirtualSystemDescriptionType enmVSDType,
177 const QString &strRef,
178 const QString &strOrigValue,
179 const QString &strConfigValue,
180 const QString &strExtraConfigValue,
181 UIApplianceModelItem *pParentItem);
182
183 /** Returns the item flags for the given @a iColumn. */
184 virtual Qt::ItemFlags itemFlags(int iColumn) const RT_OVERRIDE;
185
186 /** Defines the @a iRole data for the item at @a iColumn to @a value. */
187 virtual bool setData(int iColumn, const QVariant &value, int iRole) RT_OVERRIDE;
188 /** Returns the data stored under the given @a iRole for the item referred to by the @a iColumn. */
189 virtual QVariant data(int iColumn, int iRole) const RT_OVERRIDE;
190
191 /** Returns the widget used to edit the item specified by @a idx for editing.
192 * @param pParent Brings the parent to be assigned for newly created editor.
193 * @param styleOption Bring the style option set for the newly created editor. */
194 virtual QWidget *createEditor(QWidget *pParent, const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const RT_OVERRIDE;
195
196 /** Defines the contents of the given @a pEditor to the data for the item at the given @a idx. */
197 virtual bool setEditorData(QWidget *pEditor, const QModelIndex &idx) const RT_OVERRIDE;
198 /** Defines the data for the item at the given @a idx in the @a pModel to the contents of the given @a pEditor. */
199 virtual bool setModelData(QWidget *pEditor, QAbstractItemModel *pModel, const QModelIndex &idx) RT_OVERRIDE;
200
201 /** Restores the default values. */
202 virtual void restoreDefaults() RT_OVERRIDE;
203
204 /** Cache currently stored values, such as @a finalStates, @a finalValues and @a finalExtraValues. */
205 virtual void putBack(QVector<BOOL> &finalStates, QVector<QString> &finalValues, QVector<QString> &finalExtraValues) RT_OVERRIDE;
206
207 KVirtualSystemDescriptionType systemDescriptionType() const;
208
209private:
210
211 /** Holds the parent reference. */
212 UIApplianceModel *m_pParent;
213
214 /** Holds the Virtual System Description type. */
215 KVirtualSystemDescriptionType m_enmVSDType;
216 /** Holds something totally useless. */
217 QString m_strRef;
218 /** Holds the original value. */
219 QString m_strOrigValue;
220 /** Holds the configuration value. */
221 QString m_strConfigValue;
222 /** Holds the default configuration value. */
223 QString m_strConfigDefaultValue;
224 /** Holds the extra configuration value. */
225 QString m_strExtraConfigValue;
226 /** Holds the item check state. */
227 Qt::CheckState m_checkState;
228 /** Holds whether item was modified. */
229 bool m_fModified;
230};
231
232
233/*********************************************************************************************************************************
234* Class UIApplianceModelItem implementation. *
235*********************************************************************************************************************************/
236
237UIApplianceModelItem::UIApplianceModelItem(int iNumber, ApplianceModelItemType enmType, QITreeView *pParent)
238 : QITreeViewItem(pParent)
239 , m_iNumber(iNumber)
240 , m_enmType(enmType)
241 , m_pParentItem(0)
242{
243}
244
245UIApplianceModelItem::UIApplianceModelItem(int iNumber, ApplianceModelItemType enmType, UIApplianceModelItem *pParentItem)
246 : QITreeViewItem(pParentItem)
247 , m_iNumber(iNumber)
248 , m_enmType(enmType)
249 , m_pParentItem(pParentItem)
250{
251}
252
253UIApplianceModelItem::~UIApplianceModelItem()
254{
255 qDeleteAll(m_childItems);
256}
257
258void UIApplianceModelItem::appendChild(UIApplianceModelItem *pChildItem)
259{
260 AssertPtr(pChildItem);
261 m_childItems << pChildItem;
262}
263
264UIApplianceModelItem *UIApplianceModelItem::childItem(int iIndex) const
265{
266 return m_childItems.value(iIndex);
267}
268
269int UIApplianceModelItem::row() const
270{
271 if (m_pParentItem)
272 return m_pParentItem->m_childItems.indexOf(const_cast<UIApplianceModelItem*>(this));
273
274 return 0;
275}
276
277int UIApplianceModelItem::childCount() const
278{
279 return m_childItems.count();
280}
281
282QString UIApplianceModelItem::text() const
283{
284 switch (type())
285 {
286 case ApplianceModelItemType_VirtualSystem:
287 return tr("%1", "col.1 text")
288 .arg(data(ApplianceViewSection_Description, Qt::DisplayRole).toString());
289 case ApplianceModelItemType_VirtualHardware:
290 return tr("%1: %2", "col.1 text: col.2 text")
291 .arg(data(ApplianceViewSection_Description, Qt::DisplayRole).toString())
292 .arg(data(ApplianceViewSection_ConfigValue, Qt::DisplayRole).toString());
293 default:
294 break;
295 }
296 return QString();
297}
298
299void UIApplianceModelItem::putBack(QVector<BOOL> &finalStates, QVector<QString> &finalValues, QVector<QString> &finalExtraValues)
300{
301 for (int i = 0; i < childCount(); ++i)
302 childItem(i)->putBack(finalStates, finalValues, finalExtraValues);
303}
304
305
306/*********************************************************************************************************************************
307* Class UIVirtualSystemItem implementation. *
308*********************************************************************************************************************************/
309
310UIVirtualSystemItem::UIVirtualSystemItem(int iNumber, CVirtualSystemDescription comDescription, UIApplianceModelItem *pParentItem)
311 : UIApplianceModelItem(iNumber, ApplianceModelItemType_VirtualSystem, pParentItem)
312 , m_comDescription(comDescription)
313{
314}
315
316QVariant UIVirtualSystemItem::data(int iColumn, int iRole) const
317{
318 QVariant value;
319 if (iColumn == ApplianceViewSection_Description &&
320 iRole == Qt::DisplayRole)
321 value = UIApplianceEditorWidget::tr("Virtual System %1").arg(m_iNumber + 1);
322 return value;
323}
324
325void UIVirtualSystemItem::putBack(QVector<BOOL> &finalStates, QVector<QString> &finalValues, QVector<QString> &finalExtraValues)
326{
327 /* Resize the vectors */
328 unsigned long iCount = m_comDescription.GetCount();
329 AssertReturnVoid(iCount > 0);
330 finalStates.resize(iCount);
331 finalValues.resize(iCount);
332 finalExtraValues.resize(iCount);
333 /* Recursively fill the vectors */
334 UIApplianceModelItem::putBack(finalStates, finalValues, finalExtraValues);
335 /* Set all final values at once */
336 m_comDescription.SetFinalValues(finalStates, finalValues, finalExtraValues);
337}
338
339
340/*********************************************************************************************************************************
341* Class UIVirtualHardwareItem implementation. *
342*********************************************************************************************************************************/
343
344UIVirtualHardwareItem::UIVirtualHardwareItem(UIApplianceModel *pParent,
345 int iNumber,
346 KVirtualSystemDescriptionType enmVSDType,
347 const QString &strRef,
348 const QString &strOrigValue,
349 const QString &strConfigValue,
350 const QString &strExtraConfigValue,
351 UIApplianceModelItem *pParentItem)
352 : UIApplianceModelItem(iNumber, ApplianceModelItemType_VirtualHardware, pParentItem)
353 , m_pParent(pParent)
354 , m_enmVSDType(enmVSDType)
355 , m_strRef(strRef)
356 , m_strOrigValue(enmVSDType == KVirtualSystemDescriptionType_Memory ? UITranslator::byteStringToMegaByteString(strOrigValue) : strOrigValue)
357 , m_strConfigValue(enmVSDType == KVirtualSystemDescriptionType_Memory ? UITranslator::byteStringToMegaByteString(strConfigValue) : strConfigValue)
358 , m_strConfigDefaultValue(strConfigValue)
359 , m_strExtraConfigValue(enmVSDType == KVirtualSystemDescriptionType_Memory ? UITranslator::byteStringToMegaByteString(strExtraConfigValue) : strExtraConfigValue)
360 , m_checkState(Qt::Checked)
361 , m_fModified(false)
362{
363}
364
365Qt::ItemFlags UIVirtualHardwareItem::itemFlags(int iColumn) const
366{
367 Qt::ItemFlags enmFlags = Qt::ItemFlags();
368 if (iColumn == ApplianceViewSection_ConfigValue)
369 {
370 /* Some items are checkable */
371 if (m_enmVSDType == KVirtualSystemDescriptionType_Floppy ||
372 m_enmVSDType == KVirtualSystemDescriptionType_CDROM ||
373 m_enmVSDType == KVirtualSystemDescriptionType_USBController ||
374 m_enmVSDType == KVirtualSystemDescriptionType_SoundCard ||
375 m_enmVSDType == KVirtualSystemDescriptionType_NetworkAdapter ||
376 m_enmVSDType == KVirtualSystemDescriptionType_CloudPublicIP ||
377 m_enmVSDType == KVirtualSystemDescriptionType_CloudKeepObject ||
378 m_enmVSDType == KVirtualSystemDescriptionType_CloudLaunchInstance)
379 enmFlags |= Qt::ItemIsUserCheckable;
380 /* Some items are editable */
381 if ((m_enmVSDType == KVirtualSystemDescriptionType_Name ||
382 m_enmVSDType == KVirtualSystemDescriptionType_Product ||
383 m_enmVSDType == KVirtualSystemDescriptionType_ProductUrl ||
384 m_enmVSDType == KVirtualSystemDescriptionType_Vendor ||
385 m_enmVSDType == KVirtualSystemDescriptionType_VendorUrl ||
386 m_enmVSDType == KVirtualSystemDescriptionType_Version ||
387 m_enmVSDType == KVirtualSystemDescriptionType_Description ||
388 m_enmVSDType == KVirtualSystemDescriptionType_License ||
389 m_enmVSDType == KVirtualSystemDescriptionType_OS ||
390 m_enmVSDType == KVirtualSystemDescriptionType_CPU ||
391 m_enmVSDType == KVirtualSystemDescriptionType_Memory ||
392 m_enmVSDType == KVirtualSystemDescriptionType_SoundCard ||
393 m_enmVSDType == KVirtualSystemDescriptionType_NetworkAdapter ||
394 m_enmVSDType == KVirtualSystemDescriptionType_HardDiskControllerIDE ||
395 m_enmVSDType == KVirtualSystemDescriptionType_HardDiskImage ||
396 m_enmVSDType == KVirtualSystemDescriptionType_SettingsFile ||
397 m_enmVSDType == KVirtualSystemDescriptionType_BaseFolder ||
398 m_enmVSDType == KVirtualSystemDescriptionType_PrimaryGroup ||
399 m_enmVSDType == KVirtualSystemDescriptionType_CloudInstanceShape ||
400 m_enmVSDType == KVirtualSystemDescriptionType_CloudDomain ||
401 m_enmVSDType == KVirtualSystemDescriptionType_CloudBootDiskSize ||
402 m_enmVSDType == KVirtualSystemDescriptionType_CloudBucket ||
403 m_enmVSDType == KVirtualSystemDescriptionType_CloudOCIVCN ||
404 m_enmVSDType == KVirtualSystemDescriptionType_CloudOCISubnet) &&
405 m_checkState == Qt::Checked) /* Item has to be enabled */
406 enmFlags |= Qt::ItemIsEditable;
407 }
408 return enmFlags;
409}
410
411bool UIVirtualHardwareItem::setData(int iColumn, const QVariant &value, int iRole)
412{
413 bool fDone = false;
414 switch (iRole)
415 {
416 case Qt::CheckStateRole:
417 {
418 if (iColumn == ApplianceViewSection_ConfigValue)
419 {
420 switch (m_enmVSDType)
421 {
422 /* These hardware items can be disabled: */
423 case KVirtualSystemDescriptionType_Floppy:
424 case KVirtualSystemDescriptionType_CDROM:
425 case KVirtualSystemDescriptionType_USBController:
426 case KVirtualSystemDescriptionType_SoundCard:
427 case KVirtualSystemDescriptionType_NetworkAdapter:
428 {
429 m_checkState = static_cast<Qt::CheckState>(value.toInt());
430 fDone = true;
431 break;
432 }
433 /* These option items can be enabled: */
434 case KVirtualSystemDescriptionType_CloudPublicIP:
435 case KVirtualSystemDescriptionType_CloudKeepObject:
436 case KVirtualSystemDescriptionType_CloudLaunchInstance:
437 {
438 if (value.toInt() == Qt::Unchecked)
439 m_strConfigValue = "false";
440 else if (value.toInt() == Qt::Checked)
441 m_strConfigValue = "true";
442 fDone = true;
443 break;
444 }
445 default:
446 break;
447 }
448 }
449 break;
450 }
451 case Qt::EditRole:
452 {
453 if (iColumn == ApplianceViewSection_OriginalValue)
454 m_strOrigValue = value.toString();
455 else if (iColumn == ApplianceViewSection_ConfigValue)
456 m_strConfigValue = value.toString();
457 break;
458 }
459 default: break;
460 }
461 return fDone;
462}
463
464QVariant UIVirtualHardwareItem::data(int iColumn, int iRole) const
465{
466 QVariant value;
467 switch (iRole)
468 {
469 case Qt::EditRole:
470 {
471 if (iColumn == ApplianceViewSection_OriginalValue)
472 value = m_strOrigValue;
473 else if (iColumn == ApplianceViewSection_ConfigValue)
474 value = m_strConfigValue;
475 break;
476 }
477 case Qt::DisplayRole:
478 {
479 if (iColumn == ApplianceViewSection_Description)
480 {
481 switch (m_enmVSDType)
482 {
483 case KVirtualSystemDescriptionType_Name: value = UIApplianceEditorWidget::tr("Name"); break;
484 case KVirtualSystemDescriptionType_Product: value = UIApplianceEditorWidget::tr("Product"); break;
485 case KVirtualSystemDescriptionType_ProductUrl: value = UIApplianceEditorWidget::tr("Product-URL"); break;
486 case KVirtualSystemDescriptionType_Vendor: value = UIApplianceEditorWidget::tr("Vendor"); break;
487 case KVirtualSystemDescriptionType_VendorUrl: value = UIApplianceEditorWidget::tr("Vendor-URL"); break;
488 case KVirtualSystemDescriptionType_Version: value = UIApplianceEditorWidget::tr("Version"); break;
489 case KVirtualSystemDescriptionType_Description: value = UIApplianceEditorWidget::tr("Description"); break;
490 case KVirtualSystemDescriptionType_License: value = UIApplianceEditorWidget::tr("License"); break;
491 case KVirtualSystemDescriptionType_OS: value = UIApplianceEditorWidget::tr("Guest OS Type"); break;
492 case KVirtualSystemDescriptionType_CPU: value = UIApplianceEditorWidget::tr("CPU"); break;
493 case KVirtualSystemDescriptionType_Memory: value = UIApplianceEditorWidget::tr("RAM"); break;
494 case KVirtualSystemDescriptionType_HardDiskControllerIDE: value = UIApplianceEditorWidget::tr("Storage Controller (IDE)"); break;
495 case KVirtualSystemDescriptionType_HardDiskControllerSATA: value = UIApplianceEditorWidget::tr("Storage Controller (SATA)"); break;
496 case KVirtualSystemDescriptionType_HardDiskControllerSCSI: value = UIApplianceEditorWidget::tr("Storage Controller (SCSI)"); break;
497 case KVirtualSystemDescriptionType_HardDiskControllerVirtioSCSI: value = UIApplianceEditorWidget::tr("Storage Controller (VirtioSCSI)"); break;
498 case KVirtualSystemDescriptionType_HardDiskControllerSAS: value = UIApplianceEditorWidget::tr("Storage Controller (SAS)"); break;
499 case KVirtualSystemDescriptionType_CDROM: value = UIApplianceEditorWidget::tr("DVD"); break;
500 case KVirtualSystemDescriptionType_Floppy: value = UIApplianceEditorWidget::tr("Floppy"); break;
501 case KVirtualSystemDescriptionType_NetworkAdapter: value = UIApplianceEditorWidget::tr("Network Adapter"); break;
502 case KVirtualSystemDescriptionType_USBController: value = UIApplianceEditorWidget::tr("USB Controller"); break;
503 case KVirtualSystemDescriptionType_SoundCard: value = UIApplianceEditorWidget::tr("Sound Card"); break;
504 case KVirtualSystemDescriptionType_HardDiskImage: value = UIApplianceEditorWidget::tr("Virtual Disk Image"); break;
505 case KVirtualSystemDescriptionType_SettingsFile: value = UIApplianceEditorWidget::tr("Settings File"); break;
506 case KVirtualSystemDescriptionType_BaseFolder: value = UIApplianceEditorWidget::tr("Base Folder"); break;
507 case KVirtualSystemDescriptionType_PrimaryGroup: value = UIApplianceEditorWidget::tr("Primary Group"); break;
508 case KVirtualSystemDescriptionType_CloudProfileName:
509 case KVirtualSystemDescriptionType_CloudInstanceShape:
510 case KVirtualSystemDescriptionType_CloudDomain:
511 case KVirtualSystemDescriptionType_CloudBootDiskSize:
512 case KVirtualSystemDescriptionType_CloudBucket:
513 case KVirtualSystemDescriptionType_CloudOCIVCN:
514 case KVirtualSystemDescriptionType_CloudOCISubnet:
515 case KVirtualSystemDescriptionType_CloudPublicIP:
516 case KVirtualSystemDescriptionType_CloudKeepObject:
517 case KVirtualSystemDescriptionType_CloudLaunchInstance: value = UIApplianceEditorWidget::tr(m_pParent->nameHint(m_enmVSDType).toUtf8().constData()); break;
518 default: value = UIApplianceEditorWidget::tr("Unknown Hardware Item"); break;
519 }
520 }
521 else if (iColumn == ApplianceViewSection_OriginalValue)
522 value = m_strOrigValue;
523 else if (iColumn == ApplianceViewSection_ConfigValue)
524 {
525 switch (m_enmVSDType)
526 {
527 case KVirtualSystemDescriptionType_Description:
528 case KVirtualSystemDescriptionType_License:
529 {
530 /* Shorten the big text if there is more than
531 * one line */
532 QString strTmp(m_strConfigValue);
533 int i = strTmp.indexOf('\n');
534 if (i > -1)
535 strTmp.replace(i, strTmp.length(), "...");
536 value = strTmp; break;
537 }
538 case KVirtualSystemDescriptionType_OS: value = uiCommon().vmGuestOSTypeDescription(m_strConfigValue); break;
539 case KVirtualSystemDescriptionType_Memory: value = m_strConfigValue + " " + UICommon::tr("MB", "size suffix MBytes=1024 KBytes"); break;
540 case KVirtualSystemDescriptionType_SoundCard: value = gpConverter->toString(static_cast<KAudioControllerType>(m_strConfigValue.toInt())); break;
541 case KVirtualSystemDescriptionType_NetworkAdapter: value = gpConverter->toString(static_cast<KNetworkAdapterType>(m_strConfigValue.toInt())); break;
542 case KVirtualSystemDescriptionType_CloudInstanceShape:
543 case KVirtualSystemDescriptionType_CloudDomain:
544 case KVirtualSystemDescriptionType_CloudBootDiskSize:
545 case KVirtualSystemDescriptionType_CloudBucket:
546 case KVirtualSystemDescriptionType_CloudOCIVCN:
547 case KVirtualSystemDescriptionType_CloudOCISubnet:
548 {
549 /* Get VSD type hint and check which kind of data it is.
550 * These VSD types can have masks if represented by arrays. */
551 const QVariant get = m_pParent->getHint(m_enmVSDType);
552 switch (m_pParent->kindHint(m_enmVSDType))
553 {
554 case ParameterKind_Array:
555 {
556 QString strMask;
557 AbstractVSDParameterArray array = get.value<AbstractVSDParameterArray>();
558 /* Every array member is a complex value, - string pair,
559 * "first" is always present while "second" can be null. */
560 foreach (const QIStringPair &pair, array.values)
561 {
562 /* If "second" isn't null & equal to m_strConfigValue => return "first": */
563 if (!pair.second.isNull() && pair.second == m_strConfigValue)
564 {
565 strMask = pair.first;
566 break;
567 }
568 }
569 /* Use mask if found, m_strConfigValue otherwise: */
570 value = strMask.isNull() ? m_strConfigValue : strMask;
571 break;
572 }
573 default:
574 {
575 value = m_strConfigValue;
576 break;
577 }
578 }
579 break;
580 }
581 case KVirtualSystemDescriptionType_CloudPublicIP: break;
582 case KVirtualSystemDescriptionType_CloudKeepObject: break;
583 case KVirtualSystemDescriptionType_CloudLaunchInstance: break;
584 default: value = m_strConfigValue; break;
585 }
586 }
587 break;
588 }
589 case Qt::ToolTipRole:
590 {
591 if (iColumn == ApplianceViewSection_ConfigValue)
592 {
593 if (!m_strOrigValue.isEmpty())
594 {
595 /* Prepare tool-tip pattern/body: */
596 const QString strToolTipPattern = UIApplianceEditorWidget::tr("<b>Original Value:</b> %1");
597 QString strToolTipBody;
598
599 /* Handle certain VSD types separately: */
600 switch (m_enmVSDType)
601 {
602 case KVirtualSystemDescriptionType_CloudInstanceShape:
603 case KVirtualSystemDescriptionType_CloudDomain:
604 case KVirtualSystemDescriptionType_CloudBootDiskSize:
605 case KVirtualSystemDescriptionType_CloudBucket:
606 case KVirtualSystemDescriptionType_CloudOCIVCN:
607 case KVirtualSystemDescriptionType_CloudOCISubnet:
608 {
609 /* Get VSD type hint and check which kind of data it is.
610 * These VSD types can have masks if represented by arrays. */
611 const QVariant get = m_pParent->getHint(m_enmVSDType);
612 switch (m_pParent->kindHint(m_enmVSDType))
613 {
614 case ParameterKind_Array:
615 {
616 QString strMask;
617 AbstractVSDParameterArray array = get.value<AbstractVSDParameterArray>();
618 /* Every array member is a complex value, - string pair,
619 * "first" is always present while "second" can be null. */
620 foreach (const QIStringPair &pair, array.values)
621 {
622 /* If "second" isn't null & equal to m_strOrigValue => return "first": */
623 if (!pair.second.isNull() && pair.second == m_strOrigValue)
624 {
625 strMask = pair.first;
626 break;
627 }
628 }
629 /* Use mask if found: */
630 if (!strMask.isNull())
631 strToolTipBody = strMask;
632 break;
633 }
634 default:
635 break;
636 }
637 break;
638 }
639 default:
640 break;
641 }
642
643 /* Make sure we have at least something: */
644 if (strToolTipBody.isNull())
645 strToolTipBody = m_strOrigValue;
646 /* Compose tool-tip finally: */
647 value = strToolTipPattern.arg(strToolTipBody);
648 }
649 }
650 break;
651 }
652 case Qt::DecorationRole:
653 {
654 if (iColumn == ApplianceViewSection_Description)
655 {
656 switch (m_enmVSDType)
657 {
658 case KVirtualSystemDescriptionType_Name: value = UIIconPool::iconSet(":/name_16px.png"); break;
659 case KVirtualSystemDescriptionType_Product:
660 case KVirtualSystemDescriptionType_ProductUrl:
661 case KVirtualSystemDescriptionType_Vendor:
662 case KVirtualSystemDescriptionType_VendorUrl:
663 case KVirtualSystemDescriptionType_Version:
664 case KVirtualSystemDescriptionType_Description:
665 case KVirtualSystemDescriptionType_License: value = UIIconPool::iconSet(":/description_16px.png"); break;
666 case KVirtualSystemDescriptionType_OS: value = UIIconPool::iconSet(":/system_type_16px.png"); break;
667 case KVirtualSystemDescriptionType_CPU: value = UIIconPool::iconSet(":/cpu_16px.png"); break;
668 case KVirtualSystemDescriptionType_Memory: value = UIIconPool::iconSet(":/ram_16px.png"); break;
669 case KVirtualSystemDescriptionType_HardDiskControllerIDE: value = UIIconPool::iconSet(":/ide_16px.png"); break;
670 case KVirtualSystemDescriptionType_HardDiskControllerSATA: value = UIIconPool::iconSet(":/sata_16px.png"); break;
671 case KVirtualSystemDescriptionType_HardDiskControllerSCSI: value = UIIconPool::iconSet(":/scsi_16px.png"); break;
672 case KVirtualSystemDescriptionType_HardDiskControllerVirtioSCSI: value = UIIconPool::iconSet(":/virtio_scsi_16px.png"); break;
673 case KVirtualSystemDescriptionType_HardDiskControllerSAS: value = UIIconPool::iconSet(":/sas_16px.png"); break;
674 case KVirtualSystemDescriptionType_HardDiskImage: value = UIIconPool::iconSet(":/hd_16px.png"); break;
675 case KVirtualSystemDescriptionType_CDROM: value = UIIconPool::iconSet(":/cd_16px.png"); break;
676 case KVirtualSystemDescriptionType_Floppy: value = UIIconPool::iconSet(":/fd_16px.png"); break;
677 case KVirtualSystemDescriptionType_NetworkAdapter: value = UIIconPool::iconSet(":/nw_16px.png"); break;
678 case KVirtualSystemDescriptionType_USBController: value = UIIconPool::iconSet(":/usb_16px.png"); break;
679 case KVirtualSystemDescriptionType_SoundCard: value = UIIconPool::iconSet(":/sound_16px.png"); break;
680 case KVirtualSystemDescriptionType_BaseFolder: value = generalIconPool().defaultSystemIcon(QFileIconProvider::Folder); break;
681 case KVirtualSystemDescriptionType_PrimaryGroup: value = UIIconPool::iconSet(":/vm_group_name_16px.png"); break;
682 case KVirtualSystemDescriptionType_CloudProfileName:
683 case KVirtualSystemDescriptionType_CloudInstanceShape:
684 case KVirtualSystemDescriptionType_CloudDomain:
685 case KVirtualSystemDescriptionType_CloudBootDiskSize:
686 case KVirtualSystemDescriptionType_CloudBucket:
687 case KVirtualSystemDescriptionType_CloudOCIVCN:
688 case KVirtualSystemDescriptionType_CloudOCISubnet:
689 case KVirtualSystemDescriptionType_CloudPublicIP:
690 case KVirtualSystemDescriptionType_CloudKeepObject:
691 case KVirtualSystemDescriptionType_CloudLaunchInstance: value = UIIconPool::iconSet(":/session_info_16px.png"); break;
692 default: break;
693 }
694 }
695 else if (iColumn == ApplianceViewSection_ConfigValue && m_enmVSDType == KVirtualSystemDescriptionType_OS)
696 value = generalIconPool().guestOSTypeIcon(m_strConfigValue);
697 break;
698 }
699 case Qt::FontRole:
700 {
701 /* If the item is unchecked mark it with italic text. */
702 if (iColumn == ApplianceViewSection_ConfigValue &&
703 m_checkState == Qt::Unchecked)
704 {
705 QFont font = qApp->font();
706 font.setItalic(true);
707 value = font;
708 }
709 break;
710 }
711 case Qt::ForegroundRole:
712 {
713 /* If the item is unchecked mark it with gray text. */
714 if (iColumn == ApplianceViewSection_ConfigValue &&
715 m_checkState == Qt::Unchecked)
716 {
717 QPalette pal = qApp->palette();
718 value = pal.brush(QPalette::Disabled, QPalette::WindowText);
719 }
720 break;
721 }
722 case Qt::CheckStateRole:
723 {
724 if (iColumn == ApplianceViewSection_ConfigValue)
725 {
726 switch (m_enmVSDType)
727 {
728 /* These hardware items can be disabled: */
729 case KVirtualSystemDescriptionType_Floppy:
730 case KVirtualSystemDescriptionType_CDROM:
731 case KVirtualSystemDescriptionType_USBController:
732 case KVirtualSystemDescriptionType_SoundCard:
733 case KVirtualSystemDescriptionType_NetworkAdapter:
734 {
735 value = m_checkState;
736 break;
737 }
738 /* These option items can be enabled: */
739 case KVirtualSystemDescriptionType_CloudPublicIP:
740 case KVirtualSystemDescriptionType_CloudKeepObject:
741 case KVirtualSystemDescriptionType_CloudLaunchInstance:
742 {
743 if (m_strConfigValue == "true")
744 value = Qt::Checked;
745 else
746 value = Qt::Unchecked;
747 break;
748 }
749 default:
750 break;
751 }
752 }
753 break;
754 }
755 case UIVirtualHardwareItem::TypeRole:
756 {
757 value = m_enmVSDType;
758 break;
759 }
760 case UIVirtualHardwareItem::ModifiedRole:
761 {
762 if (iColumn == ApplianceViewSection_ConfigValue)
763 value = m_fModified;
764 break;
765 }
766 }
767 return value;
768}
769
770QWidget *UIVirtualHardwareItem::createEditor(QWidget *pParent, const QStyleOptionViewItem & /* styleOption */, const QModelIndex &idx) const
771{
772 QWidget *pEditor = 0;
773 if (idx.column() == ApplianceViewSection_ConfigValue)
774 {
775 switch (m_enmVSDType)
776 {
777 case KVirtualSystemDescriptionType_OS:
778 {
779 UIGuestOSTypeSelectionButton *pButton = new UIGuestOSTypeSelectionButton(pParent);
780 /* Fill the background with the highlight color in the case
781 * the button hasn't a rectangle shape. This prevents the
782 * display of parts from the current text on the Mac. */
783#ifdef VBOX_WS_MAC
784 /* Use the palette from the tree view, not the one from the
785 * editor. */
786 QPalette p = pButton->palette();
787 p.setBrush(QPalette::Highlight, pParent->palette().brush(QPalette::Highlight));
788 pButton->setPalette(p);
789#endif /* VBOX_WS_MAC */
790 pButton->setAutoFillBackground(true);
791 pButton->setBackgroundRole(QPalette::Highlight);
792 pEditor = pButton;
793 break;
794 }
795 case KVirtualSystemDescriptionType_Name:
796 case KVirtualSystemDescriptionType_Product:
797 case KVirtualSystemDescriptionType_ProductUrl:
798 case KVirtualSystemDescriptionType_Vendor:
799 case KVirtualSystemDescriptionType_VendorUrl:
800 case KVirtualSystemDescriptionType_Version:
801 {
802 QLineEdit *pLineEdit = new QLineEdit(pParent);
803 pEditor = pLineEdit;
804 break;
805 }
806 case KVirtualSystemDescriptionType_Description:
807 case KVirtualSystemDescriptionType_License:
808 {
809 UILineTextEdit *pLineTextEdit = new UILineTextEdit(pParent);
810 pEditor = pLineTextEdit;
811 break;
812 }
813 case KVirtualSystemDescriptionType_CPU:
814 {
815 QSpinBox *pSpinBox = new QSpinBox(pParent);
816 pSpinBox->setRange(UIApplianceEditorWidget::minGuestCPUCount(), UIApplianceEditorWidget::maxGuestCPUCount());
817 pEditor = pSpinBox;
818 break;
819 }
820 case KVirtualSystemDescriptionType_Memory:
821 {
822 QSpinBox *pSpinBox = new QSpinBox(pParent);
823 pSpinBox->setRange(UIApplianceEditorWidget::minGuestRAM(), UIApplianceEditorWidget::maxGuestRAM());
824 pSpinBox->setSuffix(" " + UICommon::tr("MB", "size suffix MBytes=1024 KBytes"));
825 pEditor = pSpinBox;
826 break;
827 }
828 case KVirtualSystemDescriptionType_SoundCard:
829 {
830 QComboBox *pComboBox = new QComboBox(pParent);
831 pComboBox->addItem(gpConverter->toString(KAudioControllerType_AC97), KAudioControllerType_AC97);
832 pComboBox->addItem(gpConverter->toString(KAudioControllerType_SB16), KAudioControllerType_SB16);
833 pComboBox->addItem(gpConverter->toString(KAudioControllerType_HDA), KAudioControllerType_HDA);
834 pEditor = pComboBox;
835 break;
836 }
837 case KVirtualSystemDescriptionType_NetworkAdapter:
838 {
839 /* Create combo editor: */
840 QComboBox *pComboBox = new QComboBox(pParent);
841 /* Load currently supported network adapter types: */
842 CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
843 QVector<KNetworkAdapterType> supportedTypes = comProperties.GetSupportedNetworkAdapterTypes();
844 /* Take currently requested type into account if it's sane: */
845 const KNetworkAdapterType enmAdapterType = static_cast<KNetworkAdapterType>(m_strConfigValue.toInt());
846 if (!supportedTypes.contains(enmAdapterType) && enmAdapterType != KNetworkAdapterType_Null)
847 supportedTypes.prepend(enmAdapterType);
848 /* Populate adapter types: */
849 int iAdapterTypeIndex = 0;
850 foreach (const KNetworkAdapterType &enmType, supportedTypes)
851 {
852 pComboBox->insertItem(iAdapterTypeIndex, gpConverter->toString(enmType));
853 pComboBox->setItemData(iAdapterTypeIndex, QVariant::fromValue((int)enmType));
854 pComboBox->setItemData(iAdapterTypeIndex, pComboBox->itemText(iAdapterTypeIndex), Qt::ToolTipRole);
855 ++iAdapterTypeIndex;
856 }
857 /* Pass editor back: */
858 pEditor = pComboBox;
859 break;
860 }
861 case KVirtualSystemDescriptionType_HardDiskControllerIDE:
862 {
863 QComboBox *pComboBox = new QComboBox(pParent);
864 pComboBox->addItem(gpConverter->toString(KStorageControllerType_PIIX3), "PIIX3");
865 pComboBox->addItem(gpConverter->toString(KStorageControllerType_PIIX4), "PIIX4");
866 pComboBox->addItem(gpConverter->toString(KStorageControllerType_ICH6), "ICH6");
867 pEditor = pComboBox;
868 break;
869 }
870 case KVirtualSystemDescriptionType_HardDiskImage:
871 {
872 UIFilePathSelector *pFileChooser = new UIFilePathSelector(pParent);
873 pFileChooser->setMode(UIFilePathSelector::Mode_File_Save);
874 pFileChooser->setResetEnabled(false);
875 pEditor = pFileChooser;
876 break;
877 }
878 case KVirtualSystemDescriptionType_SettingsFile:
879 {
880 UIFilePathSelector *pFileChooser = new UIFilePathSelector(pParent);
881 pFileChooser->setMode(UIFilePathSelector::Mode_File_Save);
882 pFileChooser->setResetEnabled(false);
883 pEditor = pFileChooser;
884 break;
885 }
886 case KVirtualSystemDescriptionType_BaseFolder:
887 {
888 UIFilePathSelector *pFileChooser = new UIFilePathSelector(pParent);
889 pFileChooser->setMode(UIFilePathSelector::Mode_Folder);
890 pFileChooser->setResetEnabled(false);
891 pEditor = pFileChooser;
892 break;
893 }
894 case KVirtualSystemDescriptionType_PrimaryGroup:
895 {
896 QComboBox *pComboBox = new QComboBox(pParent);
897 pComboBox->setEditable(true);
898 QVector<QString> groupsVector = uiCommon().virtualBox().GetMachineGroups();
899
900 for (int i = 0; i < groupsVector.size(); ++i)
901 pComboBox->addItem(groupsVector.at(i));
902 pEditor = pComboBox;
903 break;
904 }
905 case KVirtualSystemDescriptionType_CloudInstanceShape:
906 case KVirtualSystemDescriptionType_CloudDomain:
907 case KVirtualSystemDescriptionType_CloudBootDiskSize:
908 case KVirtualSystemDescriptionType_CloudBucket:
909 case KVirtualSystemDescriptionType_CloudOCIVCN:
910 case KVirtualSystemDescriptionType_CloudOCISubnet:
911 {
912 const QVariant get = m_pParent->getHint(m_enmVSDType);
913 switch (m_pParent->kindHint(m_enmVSDType))
914 {
915 case ParameterKind_Double:
916 {
917 AbstractVSDParameterDouble value = get.value<AbstractVSDParameterDouble>();
918 QSpinBox *pSpinBox = new QSpinBox(pParent);
919 pSpinBox->setRange(value.minimum, value.maximum);
920 pSpinBox->setSuffix(QString(" %1").arg(UICommon::tr(value.unit.toUtf8().constData())));
921 pEditor = pSpinBox;
922 break;
923 }
924 case ParameterKind_String:
925 {
926 QLineEdit *pLineEdit = new QLineEdit(pParent);
927 pEditor = pLineEdit;
928 break;
929 }
930 case ParameterKind_Array:
931 {
932 AbstractVSDParameterArray value = get.value<AbstractVSDParameterArray>();
933 QComboBox *pComboBox = new QComboBox(pParent);
934 /* Every array member is a complex value, - string pair,
935 * "first" is always present while "second" can be null. */
936 foreach (const QIStringPair &pair, value.values)
937 {
938 /* First always goes to combo item text: */
939 pComboBox->addItem(pair.first);
940 /* If "second" present => it goes to new item data: */
941 if (!pair.second.isNull())
942 pComboBox->setItemData(pComboBox->count() - 1, pair.second);
943 /* Otherwise => "first" goes to new item data as well: */
944 else
945 pComboBox->setItemData(pComboBox->count() - 1, pair.first);
946 }
947 pEditor = pComboBox;
948 break;
949 }
950 default:
951 break;
952 }
953 break;
954 }
955 default: break;
956 }
957 }
958 return pEditor;
959}
960
961bool UIVirtualHardwareItem::setEditorData(QWidget *pEditor, const QModelIndex & /* idx */) const
962{
963 bool fDone = false;
964 switch (m_enmVSDType)
965 {
966 case KVirtualSystemDescriptionType_OS:
967 {
968 if (UIGuestOSTypeSelectionButton *pButton = qobject_cast<UIGuestOSTypeSelectionButton*>(pEditor))
969 {
970 pButton->setOSTypeId(m_strConfigValue);
971 fDone = true;
972 }
973 break;
974 }
975 case KVirtualSystemDescriptionType_HardDiskControllerIDE:
976 {
977 if (QComboBox *pComboBox = qobject_cast<QComboBox*>(pEditor))
978 {
979 int i = pComboBox->findData(m_strConfigValue);
980 if (i != -1)
981 pComboBox->setCurrentIndex(i);
982 fDone = true;
983 }
984 break;
985 }
986 case KVirtualSystemDescriptionType_CPU:
987 case KVirtualSystemDescriptionType_Memory:
988 {
989 if (QSpinBox *pSpinBox = qobject_cast<QSpinBox*>(pEditor))
990 {
991 pSpinBox->setValue(m_strConfigValue.toInt());
992 fDone = true;
993 }
994 break;
995 }
996 case KVirtualSystemDescriptionType_Name:
997 case KVirtualSystemDescriptionType_Product:
998 case KVirtualSystemDescriptionType_ProductUrl:
999 case KVirtualSystemDescriptionType_Vendor:
1000 case KVirtualSystemDescriptionType_VendorUrl:
1001 case KVirtualSystemDescriptionType_Version:
1002 {
1003 if (QLineEdit *pLineEdit = qobject_cast<QLineEdit*>(pEditor))
1004 {
1005 pLineEdit->setText(m_strConfigValue);
1006 fDone = true;
1007 }
1008 break;
1009 }
1010 case KVirtualSystemDescriptionType_Description:
1011 case KVirtualSystemDescriptionType_License:
1012 {
1013 if (UILineTextEdit *pLineTextEdit = qobject_cast<UILineTextEdit*>(pEditor))
1014 {
1015 pLineTextEdit->setText(m_strConfigValue);
1016 fDone = true;
1017 }
1018 break;
1019 }
1020 case KVirtualSystemDescriptionType_SoundCard:
1021 case KVirtualSystemDescriptionType_NetworkAdapter:
1022 {
1023 if (QComboBox *pComboBox = qobject_cast<QComboBox*>(pEditor))
1024 {
1025 int i = pComboBox->findData(m_strConfigValue.toInt());
1026 if (i != -1)
1027 pComboBox->setCurrentIndex(i);
1028 fDone = true;
1029 }
1030 break;
1031 }
1032 case KVirtualSystemDescriptionType_HardDiskImage:
1033 case KVirtualSystemDescriptionType_SettingsFile:
1034 case KVirtualSystemDescriptionType_BaseFolder:
1035 {
1036 if (UIFilePathSelector *pFileChooser = qobject_cast<UIFilePathSelector*>(pEditor))
1037 {
1038 pFileChooser->setPath(m_strConfigValue);
1039 fDone = true;
1040 }
1041 break;
1042 }
1043 case KVirtualSystemDescriptionType_PrimaryGroup:
1044 {
1045 if (QComboBox *pGroupCombo = qobject_cast<QComboBox*>(pEditor))
1046 {
1047 pGroupCombo->setCurrentText(m_strConfigValue);
1048 fDone = true;
1049 }
1050 break;
1051 }
1052 case KVirtualSystemDescriptionType_CloudInstanceShape:
1053 case KVirtualSystemDescriptionType_CloudDomain:
1054 case KVirtualSystemDescriptionType_CloudBootDiskSize:
1055 case KVirtualSystemDescriptionType_CloudBucket:
1056 case KVirtualSystemDescriptionType_CloudOCIVCN:
1057 case KVirtualSystemDescriptionType_CloudOCISubnet:
1058 {
1059 switch (m_pParent->kindHint(m_enmVSDType))
1060 {
1061 case ParameterKind_Double:
1062 {
1063 if (QSpinBox *pSpinBox = qobject_cast<QSpinBox*>(pEditor))
1064 {
1065 pSpinBox->setValue(m_strConfigValue.toInt());
1066 fDone = true;
1067 }
1068 break;
1069 }
1070 case ParameterKind_String:
1071 {
1072 if (QLineEdit *pLineEdit = qobject_cast<QLineEdit*>(pEditor))
1073 {
1074 pLineEdit->setText(m_strConfigValue);
1075 fDone = true;
1076 }
1077 break;
1078 }
1079 case ParameterKind_Array:
1080 {
1081 if (QComboBox *pComboBox = qobject_cast<QComboBox*>(pEditor))
1082 {
1083 /* Every array member is a complex value, - string pair,
1084 * "first" is always present while "second" can be null.
1085 * Actual config value is always stored in item data. */
1086 const int iIndex = pComboBox->findData(m_strConfigValue);
1087 /* If item was found => choose it: */
1088 if (iIndex != -1)
1089 pComboBox->setCurrentIndex(iIndex);
1090 /* Otherwise => just choose the text: */
1091 else
1092 pComboBox->setCurrentText(m_strConfigValue);
1093 fDone = true;
1094 }
1095 break;
1096 }
1097 default:
1098 break;
1099 }
1100 break;
1101 }
1102 default: break;
1103 }
1104 return fDone;
1105}
1106
1107bool UIVirtualHardwareItem::setModelData(QWidget *pEditor, QAbstractItemModel *pModel, const QModelIndex & idx)
1108{
1109 bool fDone = false;
1110 switch (m_enmVSDType)
1111 {
1112 case KVirtualSystemDescriptionType_OS:
1113 {
1114 if (UIGuestOSTypeSelectionButton *pButton = qobject_cast<UIGuestOSTypeSelectionButton*>(pEditor))
1115 {
1116 m_strConfigValue = pButton->osTypeId();
1117 fDone = true;
1118 }
1119 break;
1120 }
1121 case KVirtualSystemDescriptionType_HardDiskControllerIDE:
1122 {
1123 if (QComboBox *pComboBox = qobject_cast<QComboBox*>(pEditor))
1124 {
1125 m_strConfigValue = pComboBox->itemData(pComboBox->currentIndex()).toString();
1126 fDone = true;
1127 }
1128 break;
1129 }
1130 case KVirtualSystemDescriptionType_CPU:
1131 case KVirtualSystemDescriptionType_Memory:
1132 {
1133 if (QSpinBox *pSpinBox = qobject_cast<QSpinBox*>(pEditor))
1134 {
1135 m_strConfigValue = QString::number(pSpinBox->value());
1136 fDone = true;
1137 }
1138 break;
1139 }
1140 case KVirtualSystemDescriptionType_Name:
1141 {
1142 if (QLineEdit *pLineEdit = qobject_cast<QLineEdit*>(pEditor))
1143 {
1144 /* When the VM name is changed the path of the disk images
1145 * should be also changed. So first of all find all disk
1146 * images corresponding to this appliance. Next check if
1147 * they are modified by the user already. If not change the
1148 * path to the new path. */
1149 /* Create an index of this position, but in column 0. */
1150 QModelIndex c0Index = pModel->index(idx.row(), 0, idx.parent());
1151 /* Query all items with the type HardDiskImage and which
1152 * are child's of this item. */
1153 QModelIndexList list = pModel->match(c0Index,
1154 UIVirtualHardwareItem::TypeRole,
1155 KVirtualSystemDescriptionType_HardDiskImage,
1156 -1,
1157 Qt::MatchExactly | Qt::MatchWrap | Qt::MatchRecursive);
1158 for (int i = 0; i < list.count(); ++i)
1159 {
1160 /* Get the index for the config value column. */
1161 QModelIndex hdIndex = pModel->index(list.at(i).row(), ApplianceViewSection_ConfigValue, list.at(i).parent());
1162 /* Ignore it if was already modified by the user. */
1163 if (!hdIndex.data(ModifiedRole).toBool())
1164 /* Replace any occurrence of the old VM name with
1165 * the new VM name. */
1166 {
1167 QStringList splittedOriginalPath = hdIndex.data(Qt::EditRole).toString().split(QDir::separator());
1168 QStringList splittedNewPath;
1169
1170 foreach (QString a, splittedOriginalPath)
1171 {
1172 (a.compare(m_strConfigValue) == 0) ? splittedNewPath << pLineEdit->text() : splittedNewPath << a;
1173 }
1174
1175 QString newPath = splittedNewPath.join(QDir::separator());
1176
1177 pModel->setData(hdIndex,
1178 newPath,
1179 Qt::EditRole);
1180 }
1181 }
1182 m_strConfigValue = pLineEdit->text();
1183 fDone = true;
1184 }
1185 break;
1186 }
1187 case KVirtualSystemDescriptionType_Product:
1188 case KVirtualSystemDescriptionType_ProductUrl:
1189 case KVirtualSystemDescriptionType_Vendor:
1190 case KVirtualSystemDescriptionType_VendorUrl:
1191 case KVirtualSystemDescriptionType_Version:
1192 {
1193 if (QLineEdit *pLineEdit = qobject_cast<QLineEdit*>(pEditor))
1194 {
1195 m_strConfigValue = pLineEdit->text();
1196 fDone = true;
1197 }
1198 break;
1199 }
1200 case KVirtualSystemDescriptionType_Description:
1201 case KVirtualSystemDescriptionType_License:
1202 {
1203 if (UILineTextEdit *pLineTextEdit = qobject_cast<UILineTextEdit*>(pEditor))
1204 {
1205 m_strConfigValue = pLineTextEdit->text();
1206 fDone = true;
1207 }
1208 break;
1209 }
1210 case KVirtualSystemDescriptionType_SoundCard:
1211 case KVirtualSystemDescriptionType_NetworkAdapter:
1212 {
1213 if (QComboBox *pComboBox = qobject_cast<QComboBox*>(pEditor))
1214 {
1215 m_strConfigValue = pComboBox->itemData(pComboBox->currentIndex()).toString();
1216 fDone = true;
1217 }
1218 break;
1219 }
1220 case KVirtualSystemDescriptionType_PrimaryGroup:
1221 {
1222 if (QComboBox *pComboBox = qobject_cast<QComboBox*>(pEditor))
1223 {
1224 m_strConfigValue = pComboBox->currentText();
1225 fDone = true;
1226 }
1227 break;
1228 }
1229 case KVirtualSystemDescriptionType_HardDiskImage:
1230 case KVirtualSystemDescriptionType_BaseFolder:
1231 {
1232 if (UIFilePathSelector *pFileChooser = qobject_cast<UIFilePathSelector*>(pEditor))
1233 {
1234 m_strConfigValue = pFileChooser->path();
1235 fDone = true;
1236 }
1237 break;
1238 }
1239 case KVirtualSystemDescriptionType_CloudInstanceShape:
1240 case KVirtualSystemDescriptionType_CloudDomain:
1241 case KVirtualSystemDescriptionType_CloudBootDiskSize:
1242 case KVirtualSystemDescriptionType_CloudBucket:
1243 case KVirtualSystemDescriptionType_CloudOCIVCN:
1244 case KVirtualSystemDescriptionType_CloudOCISubnet:
1245 {
1246 switch (m_pParent->kindHint(m_enmVSDType))
1247 {
1248 case ParameterKind_Double:
1249 {
1250 if (QSpinBox *pSpinBox = qobject_cast<QSpinBox*>(pEditor))
1251 {
1252 m_strConfigValue = QString::number(pSpinBox->value());
1253 fDone = true;
1254 }
1255 break;
1256 }
1257 case ParameterKind_String:
1258 {
1259 if (QLineEdit *pLineEdit = qobject_cast<QLineEdit*>(pEditor))
1260 {
1261 m_strConfigValue = pLineEdit->text();
1262 fDone = true;
1263 }
1264 break;
1265 }
1266 case ParameterKind_Array:
1267 {
1268 if (QComboBox *pComboBox = qobject_cast<QComboBox*>(pEditor))
1269 {
1270 /* Every array member is a complex value, - string pair,
1271 * "first" is always present while "second" can be null.
1272 * Actual config value is always stored in item data. */
1273 const QString strData = pComboBox->currentData().toString();
1274 /* If item data isn't null => pass it: */
1275 if (!strData.isNull())
1276 m_strConfigValue = strData;
1277 /* Otherwise => just pass the text: */
1278 else
1279 m_strConfigValue = pComboBox->currentText();
1280 fDone = true;
1281 }
1282 break;
1283 }
1284 default:
1285 break;
1286 }
1287 }
1288 default: break;
1289 }
1290 if (fDone)
1291 m_fModified = true;
1292
1293 return fDone;
1294}
1295
1296void UIVirtualHardwareItem::restoreDefaults()
1297{
1298 m_strConfigValue = m_strConfigDefaultValue;
1299 m_checkState = Qt::Checked;
1300}
1301
1302void UIVirtualHardwareItem::putBack(QVector<BOOL> &finalStates, QVector<QString> &finalValues, QVector<QString> &finalExtraValues)
1303{
1304 finalStates[m_iNumber] = m_checkState == Qt::Checked;
1305 /* It's alway stored in bytes in VSD according to the old internal agreement within the team */
1306 finalValues[m_iNumber] = m_enmVSDType == KVirtualSystemDescriptionType_Memory ? UITranslator::megabyteStringToByteString(m_strConfigValue) : m_strConfigValue;
1307 finalExtraValues[m_iNumber] = m_enmVSDType == KVirtualSystemDescriptionType_Memory ? UITranslator::megabyteStringToByteString(m_strExtraConfigValue) : m_strExtraConfigValue;
1308
1309 UIApplianceModelItem::putBack(finalStates, finalValues, finalExtraValues);
1310}
1311
1312
1313KVirtualSystemDescriptionType UIVirtualHardwareItem::systemDescriptionType() const
1314{
1315 return m_enmVSDType;
1316}
1317
1318
1319/*********************************************************************************************************************************
1320* Class UIApplianceModel implementation. *
1321*********************************************************************************************************************************/
1322
1323UIApplianceModel::UIApplianceModel(QVector<CVirtualSystemDescription>& aVSDs, QITreeView *pParent)
1324 : QAbstractItemModel(pParent)
1325 , m_pRootItem(new UIApplianceModelItem(0, ApplianceModelItemType_Root, pParent))
1326{
1327 for (int iVSDIndex = 0; iVSDIndex < aVSDs.size(); ++iVSDIndex)
1328 {
1329 CVirtualSystemDescription vsd = aVSDs[iVSDIndex];
1330
1331 UIVirtualSystemItem *pVirtualSystemItem = new UIVirtualSystemItem(iVSDIndex, vsd, m_pRootItem);
1332 m_pRootItem->appendChild(pVirtualSystemItem);
1333
1334 /** @todo ask Dmitry about include/COMDefs.h:232 */
1335 QVector<KVirtualSystemDescriptionType> types;
1336 QVector<QString> refs;
1337 QVector<QString> origValues;
1338 QVector<QString> configValues;
1339 QVector<QString> extraConfigValues;
1340
1341 QList<int> hdIndexes;
1342 QMap<int, UIVirtualHardwareItem*> controllerMap;
1343 vsd.GetDescription(types, refs, origValues, configValues, extraConfigValues);
1344 for (int i = 0; i < types.size(); ++i)
1345 {
1346 if (types[i] == KVirtualSystemDescriptionType_SettingsFile)
1347 continue;
1348 /* We add the hard disk images in an second step, so save a
1349 reference to them. */
1350 else if (types[i] == KVirtualSystemDescriptionType_HardDiskImage)
1351 hdIndexes << i;
1352 else
1353 {
1354 UIVirtualHardwareItem *pHardwareItem = new UIVirtualHardwareItem(this, i, types[i], refs[i], origValues[i], configValues[i], extraConfigValues[i], pVirtualSystemItem);
1355 pVirtualSystemItem->appendChild(pHardwareItem);
1356 /* Save the hard disk controller types in an extra map */
1357 if (types[i] == KVirtualSystemDescriptionType_HardDiskControllerIDE ||
1358 types[i] == KVirtualSystemDescriptionType_HardDiskControllerSATA ||
1359 types[i] == KVirtualSystemDescriptionType_HardDiskControllerSCSI ||
1360 types[i] == KVirtualSystemDescriptionType_HardDiskControllerVirtioSCSI ||
1361 types[i] == KVirtualSystemDescriptionType_HardDiskControllerSAS)
1362 controllerMap[i] = pHardwareItem;
1363 }
1364 }
1365 QRegExp rx("controller=(\\d+);?");
1366 /* Now process the hard disk images */
1367 for (int iHDIndex = 0; iHDIndex < hdIndexes.size(); ++iHDIndex)
1368 {
1369 int i = hdIndexes[iHDIndex];
1370 QString ecnf = extraConfigValues[i];
1371 if (rx.indexIn(ecnf) != -1)
1372 {
1373 /* Get the controller */
1374 UIVirtualHardwareItem *pControllerItem = controllerMap[rx.cap(1).toInt()];
1375 if (pControllerItem)
1376 {
1377 /* New hardware item as child of the controller */
1378 UIVirtualHardwareItem *pStorageItem = new UIVirtualHardwareItem(this, i, types[i], refs[i], origValues[i], configValues[i], extraConfigValues[i], pControllerItem);
1379 pControllerItem->appendChild(pStorageItem);
1380 }
1381 }
1382 }
1383 }
1384}
1385
1386UIApplianceModel::~UIApplianceModel()
1387{
1388 if (m_pRootItem)
1389 delete m_pRootItem;
1390}
1391
1392QModelIndex UIApplianceModel::root() const
1393{
1394 return index(0, 0);
1395}
1396
1397QModelIndex UIApplianceModel::index(int iRow, int iColumn, const QModelIndex &parentIdx /* = QModelIndex() */) const
1398{
1399 if (!hasIndex(iRow, iColumn, parentIdx))
1400 return QModelIndex();
1401
1402 UIApplianceModelItem *pItem = !parentIdx.isValid() ? m_pRootItem :
1403 static_cast<UIApplianceModelItem*>(parentIdx.internalPointer())->childItem(iRow);
1404
1405 return pItem ? createIndex(iRow, iColumn, pItem) : QModelIndex();
1406}
1407
1408QModelIndex UIApplianceModel::parent(const QModelIndex &idx) const
1409{
1410 if (!idx.isValid())
1411 return QModelIndex();
1412
1413 UIApplianceModelItem *pItem = static_cast<UIApplianceModelItem*>(idx.internalPointer());
1414 UIApplianceModelItem *pParentItem = pItem->parent();
1415
1416 if (pParentItem)
1417 return createIndex(pParentItem->row(), 0, pParentItem);
1418 else
1419 return QModelIndex();
1420}
1421
1422int UIApplianceModel::rowCount(const QModelIndex &parentIdx /* = QModelIndex() */) const
1423{
1424 return !parentIdx.isValid() ? 1 /* only root item has invalid parent */ :
1425 static_cast<UIApplianceModelItem*>(parentIdx.internalPointer())->childCount();
1426}
1427
1428int UIApplianceModel::columnCount(const QModelIndex &parentIdx /* = QModelIndex() */) const
1429{
1430 return !parentIdx.isValid() ? m_pRootItem->columnCount() :
1431 static_cast<UIApplianceModelItem*>(parentIdx.internalPointer())->columnCount();
1432}
1433
1434Qt::ItemFlags UIApplianceModel::flags(const QModelIndex &idx) const
1435{
1436 if (!idx.isValid())
1437 return Qt::ItemFlags();
1438
1439 UIApplianceModelItem *pItem = static_cast<UIApplianceModelItem*>(idx.internalPointer());
1440
1441 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | pItem->itemFlags(idx.column());
1442}
1443
1444QVariant UIApplianceModel::headerData(int iSection, Qt::Orientation enmOrientation, int iRole) const
1445{
1446 if (iRole != Qt::DisplayRole ||
1447 enmOrientation != Qt::Horizontal)
1448 return QVariant();
1449
1450 QString strTitle;
1451 switch (iSection)
1452 {
1453 case ApplianceViewSection_Description: strTitle = UIApplianceEditorWidget::tr("Description"); break;
1454 case ApplianceViewSection_ConfigValue: strTitle = UIApplianceEditorWidget::tr("Configuration"); break;
1455 }
1456 return strTitle;
1457}
1458
1459bool UIApplianceModel::setData(const QModelIndex &idx, const QVariant &value, int iRole)
1460{
1461 if (!idx.isValid())
1462 return false;
1463
1464 UIApplianceModelItem *pTtem = static_cast<UIApplianceModelItem*>(idx.internalPointer());
1465
1466 return pTtem->setData(idx.column(), value, iRole);
1467}
1468
1469QVariant UIApplianceModel::data(const QModelIndex &idx, int iRole /* = Qt::DisplayRole */) const
1470{
1471 if (!idx.isValid())
1472 return QVariant();
1473
1474 UIApplianceModelItem *pTtem = static_cast<UIApplianceModelItem*>(idx.internalPointer());
1475
1476 return pTtem->data(idx.column(), iRole);
1477}
1478
1479QModelIndex UIApplianceModel::buddy(const QModelIndex &idx) const
1480{
1481 if (!idx.isValid())
1482 return QModelIndex();
1483
1484 if (idx.column() == ApplianceViewSection_ConfigValue)
1485 return idx;
1486 else
1487 return index(idx.row(), ApplianceViewSection_ConfigValue, idx.parent());
1488}
1489
1490void UIApplianceModel::restoreDefaults(QModelIndex parentIdx /* = QModelIndex() */)
1491{
1492 /* By default use the root: */
1493 if (!parentIdx.isValid())
1494 parentIdx = root();
1495
1496 /* Get corresponding parent item and enumerate it's children: */
1497 UIApplianceModelItem *pParentItem = static_cast<UIApplianceModelItem*>(parentIdx.internalPointer());
1498 for (int i = 0; i < pParentItem->childCount(); ++i)
1499 {
1500 /* Reset children item data to default: */
1501 pParentItem->childItem(i)->restoreDefaults();
1502 /* Recursively process children item: */
1503 restoreDefaults(index(i, 0, parentIdx));
1504 }
1505 /* Notify the model about the changes: */
1506 emit dataChanged(index(0, 0, parentIdx), index(pParentItem->childCount() - 1, 0, parentIdx));
1507}
1508
1509void UIApplianceModel::putBack()
1510{
1511 QVector<BOOL> v1;
1512 QVector<QString> v2;
1513 QVector<QString> v3;
1514 m_pRootItem->putBack(v1, v2, v3);
1515}
1516
1517
1518void UIApplianceModel::setVirtualSystemBaseFolder(const QString& path)
1519{
1520 if (!m_pRootItem)
1521 return;
1522 /* For each Virtual System: */
1523 for (int i = 0; i < m_pRootItem->childCount(); ++i)
1524 {
1525 UIVirtualSystemItem *pVirtualSystem = dynamic_cast<UIVirtualSystemItem*>(m_pRootItem->childItem(i));
1526 if (!pVirtualSystem)
1527 continue;
1528 int iItemCount = pVirtualSystem->childCount();
1529 for (int j = 0; j < iItemCount; ++j)
1530 {
1531 UIVirtualHardwareItem *pHardwareItem = dynamic_cast<UIVirtualHardwareItem*>(pVirtualSystem->childItem(j));
1532 if (!pHardwareItem)
1533 continue;
1534 if (pHardwareItem->systemDescriptionType() != KVirtualSystemDescriptionType_BaseFolder)
1535 continue;
1536 QVariant data(path);
1537 pHardwareItem->setData(ApplianceViewSection_ConfigValue, data, Qt::EditRole);
1538 QModelIndex index = createIndex(pHardwareItem->row(), 0, pHardwareItem);
1539 emit dataChanged(index, index);
1540 }
1541 }
1542}
1543
1544void UIApplianceModel::setVsdHints(const AbstractVSDParameterList &hints)
1545{
1546 m_listVsdHints = hints;
1547}
1548
1549QString UIApplianceModel::nameHint(KVirtualSystemDescriptionType enmType) const
1550{
1551 foreach (const AbstractVSDParameter &parameter, m_listVsdHints)
1552 if (parameter.type == enmType)
1553 return parameter.name;
1554 return QString();
1555}
1556
1557AbstractVSDParameterKind UIApplianceModel::kindHint(KVirtualSystemDescriptionType enmType) const
1558{
1559 foreach (const AbstractVSDParameter &parameter, m_listVsdHints)
1560 if (parameter.type == enmType)
1561 return parameter.kind;
1562 return ParameterKind_Invalid;
1563}
1564
1565QVariant UIApplianceModel::getHint(KVirtualSystemDescriptionType enmType) const
1566{
1567 foreach (const AbstractVSDParameter &parameter, m_listVsdHints)
1568 if (parameter.type == enmType)
1569 return parameter.get;
1570 return QVariant();
1571}
1572
1573
1574/*********************************************************************************************************************************
1575* Class UIApplianceDelegate implementation. *
1576*********************************************************************************************************************************/
1577
1578UIApplianceDelegate::UIApplianceDelegate(QAbstractProxyModel *pProxy)
1579 : QItemDelegate(pProxy)
1580 , m_pProxy(pProxy)
1581{
1582}
1583
1584QWidget *UIApplianceDelegate::createEditor(QWidget *pParent, const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const
1585{
1586 if (!idx.isValid())
1587 return QItemDelegate::createEditor(pParent, styleOption, idx);
1588
1589 QModelIndex index(idx);
1590 if (m_pProxy)
1591 index = m_pProxy->mapToSource(idx);
1592
1593 UIApplianceModelItem *pItem = static_cast<UIApplianceModelItem*>(index.internalPointer());
1594 QWidget *pEditor = pItem->createEditor(pParent, styleOption, index);
1595
1596 if (!pEditor)
1597 return QItemDelegate::createEditor(pParent, styleOption, index);
1598
1599 /* Allow UILineTextEdit to commit data early: */
1600 if (qobject_cast<UILineTextEdit*>(pEditor))
1601 connect(pEditor, SIGNAL(sigFinished(QWidget*)), this, SIGNAL(commitData(QWidget*)));
1602
1603 return pEditor;
1604}
1605
1606void UIApplianceDelegate::setEditorData(QWidget *pEditor, const QModelIndex &idx) const
1607{
1608 if (!idx.isValid())
1609 return QItemDelegate::setEditorData(pEditor, idx);
1610
1611 QModelIndex index(idx);
1612 if (m_pProxy)
1613 index = m_pProxy->mapToSource(idx);
1614
1615 UIApplianceModelItem *pItem = static_cast<UIApplianceModelItem*>(index.internalPointer());
1616
1617 if (!pItem->setEditorData(pEditor, index))
1618 QItemDelegate::setEditorData(pEditor, index);
1619}
1620
1621void UIApplianceDelegate::setModelData(QWidget *pEditor, QAbstractItemModel *pModel, const QModelIndex &idx) const
1622{
1623 if (!idx.isValid())
1624 return QItemDelegate::setModelData(pEditor, pModel, idx);
1625
1626 QModelIndex index = pModel->index(idx.row(), idx.column());
1627 if (m_pProxy)
1628 index = m_pProxy->mapToSource(idx);
1629
1630 UIApplianceModelItem *pItem = static_cast<UIApplianceModelItem*>(index.internalPointer());
1631 if (!pItem->setModelData(pEditor, pModel, idx))
1632 QItemDelegate::setModelData(pEditor, pModel, idx);
1633}
1634
1635void UIApplianceDelegate::updateEditorGeometry(QWidget *pEditor, const QStyleOptionViewItem &styleOption, const QModelIndex & /* idx */) const
1636{
1637 if (pEditor)
1638 pEditor->setGeometry(styleOption.rect);
1639}
1640
1641QSize UIApplianceDelegate::sizeHint(const QStyleOptionViewItem &styleOption, const QModelIndex &idx) const
1642{
1643 QSize size = QItemDelegate::sizeHint(styleOption, idx);
1644#ifdef VBOX_WS_MAC
1645 int h = 28;
1646#else
1647 int h = 24;
1648#endif
1649 size.setHeight(RT_MAX(h, size.height()));
1650 return size;
1651}
1652
1653#ifdef VBOX_WS_MAC
1654bool UIApplianceDelegate::eventFilter(QObject *pObject, QEvent *pEvent)
1655{
1656 if (pEvent->type() == QEvent::FocusOut)
1657 {
1658 /* On Mac OS X Cocoa the OS type selector widget loses it focus when
1659 * the popup menu is shown. Prevent this here, cause otherwise the new
1660 * selected OS will not be updated. */
1661 UIGuestOSTypeSelectionButton *pButton = qobject_cast<UIGuestOSTypeSelectionButton*>(pObject);
1662 if (pButton && pButton->isMenuShown())
1663 return false;
1664 /* The same counts for the text edit buttons of the license or
1665 * description fields. */
1666 else if (qobject_cast<UILineTextEdit*>(pObject))
1667 return false;
1668 }
1669
1670 return QItemDelegate::eventFilter(pObject, pEvent);
1671}
1672#endif /* VBOX_WS_MAC */
1673
1674
1675/*********************************************************************************************************************************
1676* Class UIApplianceSortProxyModel implementation. *
1677*********************************************************************************************************************************/
1678
1679/* static */
1680KVirtualSystemDescriptionType UIApplianceSortProxyModel::s_aSortList[] =
1681{
1682 KVirtualSystemDescriptionType_Name,
1683 KVirtualSystemDescriptionType_Product,
1684 KVirtualSystemDescriptionType_ProductUrl,
1685 KVirtualSystemDescriptionType_Vendor,
1686 KVirtualSystemDescriptionType_VendorUrl,
1687 KVirtualSystemDescriptionType_Version,
1688 KVirtualSystemDescriptionType_Description,
1689 KVirtualSystemDescriptionType_License,
1690 KVirtualSystemDescriptionType_OS,
1691 KVirtualSystemDescriptionType_CPU,
1692 KVirtualSystemDescriptionType_Memory,
1693 KVirtualSystemDescriptionType_Floppy,
1694 KVirtualSystemDescriptionType_CDROM,
1695 KVirtualSystemDescriptionType_USBController,
1696 KVirtualSystemDescriptionType_SoundCard,
1697 KVirtualSystemDescriptionType_NetworkAdapter,
1698 KVirtualSystemDescriptionType_HardDiskControllerIDE,
1699 KVirtualSystemDescriptionType_HardDiskControllerSATA,
1700 KVirtualSystemDescriptionType_HardDiskControllerSCSI,
1701 KVirtualSystemDescriptionType_HardDiskControllerVirtioSCSI,
1702 KVirtualSystemDescriptionType_HardDiskControllerSAS,
1703 /* OCI */
1704 KVirtualSystemDescriptionType_CloudProfileName,
1705 KVirtualSystemDescriptionType_CloudBucket,
1706 KVirtualSystemDescriptionType_CloudKeepObject,
1707 KVirtualSystemDescriptionType_CloudLaunchInstance,
1708 KVirtualSystemDescriptionType_CloudInstanceShape,
1709 KVirtualSystemDescriptionType_CloudBootDiskSize,
1710 KVirtualSystemDescriptionType_CloudOCIVCN,
1711 KVirtualSystemDescriptionType_CloudOCISubnet,
1712 KVirtualSystemDescriptionType_CloudPublicIP,
1713 KVirtualSystemDescriptionType_CloudDomain
1714};
1715
1716UIApplianceSortProxyModel::UIApplianceSortProxyModel(QObject *pParent)
1717 : QSortFilterProxyModel(pParent)
1718{
1719}
1720
1721bool UIApplianceSortProxyModel::filterAcceptsRow(int iSourceRow, const QModelIndex &srcParenIdx) const
1722{
1723 /* By default enable all, we will explicitly filter out below */
1724 if (srcParenIdx.isValid())
1725 {
1726 QModelIndex i = index(iSourceRow, 0, srcParenIdx);
1727 if (i.isValid())
1728 {
1729 UIApplianceModelItem *pItem = static_cast<UIApplianceModelItem*>(i.internalPointer());
1730 /* We filter hardware types only */
1731 if (pItem->type() == ApplianceModelItemType_VirtualHardware)
1732 {
1733 UIVirtualHardwareItem *hwItem = static_cast<UIVirtualHardwareItem*>(pItem);
1734 /* The license type shouldn't be displayed */
1735 if (m_aFilteredList.contains(hwItem->m_enmVSDType))
1736 return false;
1737 }
1738 }
1739 }
1740 return true;
1741}
1742
1743bool UIApplianceSortProxyModel::lessThan(const QModelIndex &leftIdx, const QModelIndex &rightIdx) const
1744{
1745 if (!leftIdx.isValid() ||
1746 !rightIdx.isValid())
1747 return false;
1748
1749 UIApplianceModelItem *pLeftItem = static_cast<UIApplianceModelItem*>(leftIdx.internalPointer());
1750 UIApplianceModelItem *pRightItem = static_cast<UIApplianceModelItem*>(rightIdx.internalPointer());
1751
1752 /* We sort hardware types only */
1753 if (!(pLeftItem->type() == ApplianceModelItemType_VirtualHardware &&
1754 pRightItem->type() == ApplianceModelItemType_VirtualHardware))
1755 return false;
1756
1757 UIVirtualHardwareItem *pHwLeft = static_cast<UIVirtualHardwareItem*>(pLeftItem);
1758 UIVirtualHardwareItem *pHwRight = static_cast<UIVirtualHardwareItem*>(pRightItem);
1759
1760 for (unsigned int i = 0; i < RT_ELEMENTS(s_aSortList); ++i)
1761 if (pHwLeft->m_enmVSDType == s_aSortList[i])
1762 {
1763 for (unsigned int a = 0; a <= i; ++a)
1764 if (pHwRight->m_enmVSDType == s_aSortList[a])
1765 return true;
1766 return false;
1767 }
1768
1769 return true;
1770}
1771
1772
1773/*********************************************************************************************************************************
1774* Class UIApplianceEditorWidget implementation. *
1775*********************************************************************************************************************************/
1776
1777/* static */
1778int UIApplianceEditorWidget::m_minGuestRAM = -1;
1779int UIApplianceEditorWidget::m_maxGuestRAM = -1;
1780int UIApplianceEditorWidget::m_minGuestCPUCount = -1;
1781int UIApplianceEditorWidget::m_maxGuestCPUCount = -1;
1782
1783UIApplianceEditorWidget::UIApplianceEditorWidget(QWidget *pParent /* = 0 */)
1784 : QIWithRetranslateUI<QWidget>(pParent)
1785 , m_pModel(0)
1786{
1787 /* Make sure all static content is properly initialized */
1788 initSystemSettings();
1789
1790 /* Create layout: */
1791 m_pLayout = new QVBoxLayout(this);
1792 {
1793 /* Configure information layout: */
1794 m_pLayout->setContentsMargins(0, 0, 0, 0);
1795
1796 /* Create information pane: */
1797 m_pPaneInformation = new QWidget;
1798 {
1799 /* Create information layout: */
1800 QVBoxLayout *m_pLayoutInformation = new QVBoxLayout(m_pPaneInformation);
1801 {
1802 /* Configure information layout: */
1803 m_pLayoutInformation->setContentsMargins(0, 0, 0, 0);
1804
1805 /* Create tree-view: */
1806 m_pTreeViewSettings = new QITreeView;
1807 {
1808 /* Configure tree-view: */
1809 m_pTreeViewSettings->setAlternatingRowColors(true);
1810 m_pTreeViewSettings->setAllColumnsShowFocus(true);
1811 m_pTreeViewSettings->header()->setStretchLastSection(true);
1812 m_pTreeViewSettings->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
1813 m_pTreeViewSettings->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
1814
1815 /* Add tree-view into information layout: */
1816 m_pLayoutInformation->addWidget(m_pTreeViewSettings);
1817 }
1818
1819
1820
1821 }
1822
1823 /* Add information pane into layout: */
1824 m_pLayout->addWidget(m_pPaneInformation);
1825 }
1826
1827 /* Create warning pane: */
1828 m_pPaneWarning = new QWidget;
1829 {
1830 /* Configure warning pane: */
1831 m_pPaneWarning->hide();
1832 m_pPaneWarning->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
1833
1834 /* Create warning layout: */
1835 QVBoxLayout *m_pLayoutWarning = new QVBoxLayout(m_pPaneWarning);
1836 {
1837 /* Configure warning layout: */
1838 m_pLayoutWarning->setContentsMargins(0, 0, 0, 0);
1839
1840 /* Create label: */
1841 m_pLabelWarning = new QLabel;
1842 {
1843 /* Add label into warning layout: */
1844 m_pLayoutWarning->addWidget(m_pLabelWarning);
1845 }
1846
1847 /* Create text-edit: */
1848 m_pTextEditWarning = new QTextEdit;
1849 {
1850 /* Configure text-edit: */
1851 m_pTextEditWarning->setReadOnly(true);
1852 m_pTextEditWarning->setMaximumHeight(50);
1853 m_pTextEditWarning->setAutoFormatting(QTextEdit::AutoBulletList);
1854
1855 /* Add text-edit into warning layout: */
1856 m_pLayoutWarning->addWidget(m_pTextEditWarning);
1857 }
1858 }
1859
1860 /* Add warning pane into layout: */
1861 m_pLayout->addWidget(m_pPaneWarning);
1862 }
1863 }
1864
1865 /* Translate finally: */
1866 retranslateUi();
1867}
1868
1869void UIApplianceEditorWidget::clear()
1870{
1871 /* Wipe model: */
1872 delete m_pModel;
1873 m_pModel = 0;
1874
1875 /* And appliance: */
1876 m_comAppliance = CAppliance();
1877}
1878
1879void UIApplianceEditorWidget::setAppliance(const CAppliance &comAppliance)
1880{
1881 m_comAppliance = comAppliance;
1882}
1883
1884void UIApplianceEditorWidget::setVsdHints(const AbstractVSDParameterList &hints)
1885{
1886 /* Save here as well: */
1887 m_listVsdHints = hints;
1888
1889 /* Make sure model exists, it's being created in sub-classes: */
1890 if (m_pModel)
1891 m_pModel->setVsdHints(m_listVsdHints);
1892}
1893
1894void UIApplianceEditorWidget::setVirtualSystemBaseFolder(const QString &strPath)
1895{
1896 /* Make sure model exists, it's being created in sub-classes: */
1897 if (m_pModel)
1898 m_pModel->setVirtualSystemBaseFolder(strPath);
1899}
1900
1901void UIApplianceEditorWidget::restoreDefaults()
1902{
1903 /* Make sure model exists, it's being created in sub-classes: */
1904 if (m_pModel)
1905 m_pModel->restoreDefaults();
1906}
1907
1908void UIApplianceEditorWidget::retranslateUi()
1909{
1910 /* Translate information pane tree-view: */
1911 m_pTreeViewSettings->setWhatsThis(tr("Detailed list of all components of all virtual machines of the current appliance"));
1912
1913 /* Translate warning pane label: */
1914 m_pLabelWarning->setText(tr("Warnings:"));
1915}
1916
1917/* static */
1918void UIApplianceEditorWidget::initSystemSettings()
1919{
1920 if (m_minGuestRAM == -1)
1921 {
1922 /* We need some global defaults from the current VirtualBox
1923 installation */
1924 CSystemProperties sp = uiCommon().virtualBox().GetSystemProperties();
1925 m_minGuestRAM = sp.GetMinGuestRAM();
1926 m_maxGuestRAM = sp.GetMaxGuestRAM();
1927 m_minGuestCPUCount = sp.GetMinGuestCPUCount();
1928 m_maxGuestCPUCount = sp.GetMaxGuestCPUCount();
1929 }
1930}
1931
1932
1933#include "UIApplianceEditorWidget.moc"
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette