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