VirtualBox

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

Last change on this file since 82781 was 82694, checked in by vboxsync, 4 years ago

FE/Qt: bugref:8651: A bit of GUI related fixes for r135597.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use