VirtualBox

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

Last change on this file since 103977 was 103771, checked in by vboxsync, 9 months ago

FE/Qt: UICommon: Switching dependency from UICommon to UIGlobalSession whenever is possible.

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