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