VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use