VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMSettingsHD.h@ 23429

Last change on this file since 23429 was 23429, checked in by vboxsync, 15 years ago

FE/Qt4: New Storage UI: Icons partially updated (2nd update); Correct foreground coloring for focused tree-view items.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 13.8 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt4 GUI ("VirtualBox"):
4 * VBoxVMSettingsHD class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#ifndef __VBoxVMSettingsHD_h__
24#define __VBoxVMSettingsHD_h__
25
26/* Global includes */
27#include <QItemDelegate>
28#include <QPointer>
29
30/* Local includes */
31#include "VBoxSettingsPage.h"
32#include "VBoxVMSettingsHD.gen.h"
33#include "COMDefs.h"
34
35/* Local forwardes */
36class AttachmentItem;
37class ControllerItem;
38
39/* Internal Types */
40typedef QList <StorageSlot> SlotsList;
41typedef QList <KDeviceType> DeviceTypeList;
42typedef QList <KStorageControllerType> ControllerTypeList;
43Q_DECLARE_METATYPE (SlotsList);
44Q_DECLARE_METATYPE (DeviceTypeList);
45Q_DECLARE_METATYPE (ControllerTypeList);
46
47enum ItemState
48{
49 State_DefaultItem = 0,
50 State_CollapsedItem = 1,
51 State_ExpandedItem = 2,
52 State_MAX
53};
54
55/* Pixmap Storage Pool */
56class PixmapPool : public QObject
57{
58 Q_OBJECT;
59
60public:
61
62 enum PixmapType
63 {
64 InvalidPixmap = -1,
65
66 AddControllerEn = 0,
67 AddControllerDis = 1,
68 DelControllerEn = 2,
69 DelControllerDis = 3,
70
71 AddAttachmentEn = 4,
72 AddAttachmentDis = 5,
73 DelAttachmentEn = 6,
74 DelAttachmentDis = 7,
75
76 IDEController = 8,
77 IDEExpand = 9,
78 IDECollapse = 10,
79 SATAController = 11,
80 SATAExpand = 12,
81 SATACollapse = 13,
82 SCSIController = 14,
83 SCSIExpand = 15,
84 SCSICollapse = 16,
85 FloppyController = 17,
86 FloppyExpand = 18,
87 FloppyCollapse = 19,
88
89 HDAttachmentEn = 20,
90 CDAttachmentEn = 21,
91 FDAttachmentEn = 22,
92
93 HDAttachmentAddEn = 23,
94 HDAttachmentAddDis = 24,
95 CDAttachmentAddEn = 25,
96 CDAttachmentAddDis = 26,
97 FDAttachmentAddEn = 27,
98 FDAttachmentAddDis = 28,
99
100 VMMEn = 29,
101 VMMDis = 30,
102
103 MaxIndex
104 };
105
106 static PixmapPool* pool (QObject *aParent = 0);
107
108 QPixmap pixmap (PixmapType aType) const;
109
110protected:
111
112 PixmapPool (QObject *aParent);
113
114 static QPointer <PixmapPool> mThis;
115
116private:
117
118 QVector <QPixmap> mPool;
119};
120
121/* Abstract Controller Type */
122class AbstractControllerType
123{
124public:
125
126 AbstractControllerType (KStorageBus aBusType, KStorageControllerType aCtrType);
127 virtual ~AbstractControllerType() {}
128
129 KStorageBus busType() const;
130 KStorageControllerType ctrType() const;
131 ControllerTypeList ctrTypes() const;
132 PixmapPool::PixmapType pixmap (ItemState aState) const;
133
134 void setCtrType (KStorageControllerType aCtrType);
135
136 virtual DeviceTypeList deviceTypeList() const = 0;
137
138protected:
139
140 virtual KStorageControllerType first() const = 0;
141 virtual uint size() const = 0;
142
143 KStorageBus mBusType;
144 KStorageControllerType mCtrType;
145 QList <PixmapPool::PixmapType> mPixmaps;
146};
147
148/* IDE Controller Type */
149class IDEControllerType : public AbstractControllerType
150{
151public:
152
153 IDEControllerType (KStorageControllerType aSubType);
154
155private:
156
157 DeviceTypeList deviceTypeList() const;
158
159 KStorageControllerType first() const;
160 uint size() const;
161};
162
163/* SATA Controller Type */
164class SATAControllerType : public AbstractControllerType
165{
166public:
167
168 SATAControllerType (KStorageControllerType aSubType);
169
170private:
171
172 DeviceTypeList deviceTypeList() const;
173
174 KStorageControllerType first() const;
175 uint size() const;
176};
177
178/* SCSI Controller Type */
179class SCSIControllerType : public AbstractControllerType
180{
181public:
182
183 SCSIControllerType (KStorageControllerType aSubType);
184
185private:
186
187 DeviceTypeList deviceTypeList() const;
188
189 KStorageControllerType first() const;
190 uint size() const;
191};
192
193/* Floppy Controller Type */
194class FloppyControllerType : public AbstractControllerType
195{
196public:
197
198 FloppyControllerType (KStorageControllerType aSubType);
199
200private:
201
202 DeviceTypeList deviceTypeList() const;
203
204 KStorageControllerType first() const;
205 uint size() const;
206};
207
208/* Abstract Item */
209class AbstractItem
210{
211public:
212
213 enum ItemType
214 {
215 Type_InvalidItem = 0,
216 Type_RootItem = 1,
217 Type_ControllerItem = 2,
218 Type_AttachmentItem = 3
219 };
220
221 AbstractItem (AbstractItem *aParent = 0);
222 virtual ~AbstractItem();
223
224 AbstractItem* parent() const;
225 QUuid id() const;
226 QString machineId() const;
227
228 void setMachineId (const QString &aMchineId);
229
230 virtual ItemType rtti() const = 0;
231 virtual AbstractItem* childByPos (int aIndex) = 0;
232 virtual AbstractItem* childById (const QUuid &aId) = 0;
233 virtual int posOfChild (AbstractItem *aItem) const = 0;
234 virtual int childCount() const = 0;
235 virtual QString text() const = 0;
236 virtual QString tip() const = 0;
237 virtual QPixmap pixmap (ItemState aState = State_DefaultItem) = 0;
238
239protected:
240
241 virtual void addChild (AbstractItem *aItem) = 0;
242 virtual void delChild (AbstractItem *aItem) = 0;
243
244 AbstractItem *mParent;
245 QUuid mId;
246 QString mMachineId;
247};
248Q_DECLARE_METATYPE (AbstractItem::ItemType);
249
250/* Root Item */
251class RootItem : public AbstractItem
252{
253public:
254
255 RootItem();
256 ~RootItem();
257
258private:
259
260 ItemType rtti() const;
261 AbstractItem* childByPos (int aIndex);
262 AbstractItem* childById (const QUuid &aId);
263 int posOfChild (AbstractItem *aItem) const;
264 int childCount() const;
265 QString text() const;
266 QString tip() const;
267 QPixmap pixmap (ItemState aState);
268 void addChild (AbstractItem *aItem);
269 void delChild (AbstractItem *aItem);
270
271 QList <AbstractItem*> mControllers;
272};
273
274/* Controller Item */
275class ControllerItem : public AbstractItem
276{
277public:
278
279 ControllerItem (AbstractItem *aParent, const QString &aName, KStorageBus aBusType,
280 KStorageControllerType aControllerType);
281 ~ControllerItem();
282
283 KStorageBus ctrBusType() const;
284 QString ctrName() const;
285 KStorageControllerType ctrType() const;
286 ControllerTypeList ctrTypes() const;
287
288 void setCtrName (const QString &aCtrName);
289 void setCtrType (KStorageControllerType aCtrType);
290
291 SlotsList ctrAllSlots() const;
292 SlotsList ctrUsedSlots() const;
293 DeviceTypeList ctrDeviceTypeList() const;
294 QStringList ctrAllMediumIds (bool aShowDiffs) const;
295 QStringList ctrUsedMediumIds() const;
296
297private:
298
299 ItemType rtti() const;
300 AbstractItem* childByPos (int aIndex);
301 AbstractItem* childById (const QUuid &aId);
302 int posOfChild (AbstractItem *aItem) const;
303 int childCount() const;
304 QString text() const;
305 QString tip() const;
306 QPixmap pixmap (ItemState aState);
307 void addChild (AbstractItem *aItem);
308 void delChild (AbstractItem *aItem);
309
310 QString mCtrName;
311 AbstractControllerType *mCtrType;
312 QList <AbstractItem*> mAttachments;
313};
314
315/* Attachment Item */
316class AttachmentItem : public AbstractItem
317{
318public:
319
320 AttachmentItem (AbstractItem *aParent, KDeviceType aDeviceType);
321
322 StorageSlot attSlot() const;
323 SlotsList attSlots() const;
324 KDeviceType attDeviceType() const;
325 DeviceTypeList attDeviceTypes() const;
326 QString attMediumId() const;
327 QStringList attMediumIds (bool aFilter = true) const;
328 bool attIsShowDiffs() const;
329 bool attIsHostDrive() const;
330 bool attIsPassthrough() const;
331
332 void setAttSlot (const StorageSlot &aAttSlot);
333 void setAttDevice (KDeviceType aAttDeviceType);
334 void setAttMediumId (const QString &aAttMediumId);
335 void setAttIsShowDiffs (bool aAttIsShowDiffs);
336 void setAttIsPassthrough (bool aPassthrough);
337
338 QString attSize() const;
339 QString attLogicalSize() const;
340 QString attLocation() const;
341 QString attFormat() const;
342 QString attUsage() const;
343
344private:
345
346 void cache();
347
348 ItemType rtti() const;
349 AbstractItem* childByPos (int aIndex);
350 AbstractItem* childById (const QUuid &aId);
351 int posOfChild (AbstractItem *aItem) const;
352 int childCount() const;
353 QString text() const;
354 QString tip() const;
355 QPixmap pixmap (ItemState aState);
356 void addChild (AbstractItem *aItem);
357 void delChild (AbstractItem *aItem);
358
359 KDeviceType mAttDeviceType;
360
361 StorageSlot mAttSlot;
362 QString mAttMediumId;
363 bool mAttIsShowDiffs;
364 bool mAttIsHostDrive;
365 bool mAttIsPassthrough;
366
367 QString mAttName;
368 QString mAttTip;
369 QPixmap mAttPixmap;
370
371 QString mAttSize;
372 QString mAttLogicalSize;
373 QString mAttLocation;
374 QString mAttFormat;
375 QString mAttUsage;
376};
377
378/* Storage Model */
379class StorageModel : public QAbstractItemModel
380{
381 Q_OBJECT;
382
383public:
384
385 enum DataRole
386 {
387 R_ItemId = Qt::UserRole + 1,
388 R_ItemPixmap,
389 R_ItemPixmapRect,
390 R_ItemName,
391 R_ItemNamePoint,
392 R_ItemType,
393 R_IsController,
394 R_IsAttachment,
395
396 R_ToolTipType,
397 R_IsMoreControllersPossible,
398 R_IsMoreAttachmentsPossible,
399
400 R_CtrName,
401 R_CtrType,
402 R_CtrTypes,
403 R_CtrDevices,
404 R_CtrBusType,
405
406 R_AttSlot,
407 R_AttSlots,
408 R_AttDevice,
409 R_AttDevices,
410 R_AttMediumId,
411 R_AttIsShowDiffs,
412 R_AttIsHostDrive,
413 R_AttIsPassthrough,
414 R_AttSize,
415 R_AttLogicalSize,
416 R_AttLocation,
417 R_AttFormat,
418 R_AttUsage,
419
420 R_Margin,
421 R_Spacing,
422 R_IconSize,
423
424 R_HDPixmapEn,
425 R_CDPixmapEn,
426 R_FDPixmapEn,
427
428 R_HDPixmapAddEn,
429 R_HDPixmapAddDis,
430 R_CDPixmapAddEn,
431 R_CDPixmapAddDis,
432 R_FDPixmapAddEn,
433 R_FDPixmapAddDis,
434 R_HDPixmapRect,
435 R_CDPixmapRect,
436 R_FDPixmapRect
437 };
438
439 enum ToolTipType
440 {
441 DefaultToolTip = 0,
442 ExpanderToolTip = 1,
443 HDAdderToolTip = 2,
444 CDAdderToolTip = 3,
445 FDAdderToolTip = 4
446 };
447
448 StorageModel (QObject *aParent);
449 ~StorageModel();
450
451 int rowCount (const QModelIndex &aParent = QModelIndex()) const;
452 int columnCount (const QModelIndex &aParent = QModelIndex()) const;
453
454 QModelIndex root() const;
455 QModelIndex index (int aRow, int aColumn, const QModelIndex &aParent = QModelIndex()) const;
456 QModelIndex parent (const QModelIndex &aIndex) const;
457
458 QVariant data (const QModelIndex &aIndex, int aRole) const;
459 bool setData (const QModelIndex &aIndex, const QVariant &aValue, int aRole);
460
461 QModelIndex addController (const QString &aCtrName, KStorageBus aBusType, KStorageControllerType aCtrType);
462 void delController (const QUuid &aCtrId);
463
464 QModelIndex addAttachment (const QUuid &aCtrId, KDeviceType aDeviceType);
465 void delAttachment (const QUuid &aCtrId, const QUuid &aAttId);
466
467 void setMachineId (const QString &aMachineId);
468
469private:
470
471 Qt::ItemFlags flags (const QModelIndex &aIndex) const;
472
473 AbstractItem *mRootItem;
474
475 QPixmap mPlusPixmapEn;
476 QPixmap mPlusPixmapDis;
477
478 QPixmap mMinusPixmapEn;
479 QPixmap mMinusPixmapDis;
480
481 ToolTipType mToolTipType;
482};
483Q_DECLARE_METATYPE (StorageModel::ToolTipType);
484
485/* Storage Delegate */
486class StorageDelegate : public QItemDelegate
487{
488 Q_OBJECT;
489
490public:
491
492 StorageDelegate (QObject *aParent);
493
494private:
495
496 void paint (QPainter *aPainter, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
497};
498
499/**
500 * QWidget class reimplementation.
501 * Used as HD Settings widget.
502 */
503class VBoxVMSettingsHD : public VBoxSettingsPage,
504 public Ui::VBoxVMSettingsHD
505{
506 Q_OBJECT;
507
508public:
509
510 VBoxVMSettingsHD();
511
512signals:
513
514 void storageChanged();
515
516protected:
517
518 void getFrom (const CMachine &aMachine);
519 void putBackTo();
520
521 void setValidator (QIWidgetValidator *aVal);
522 bool revalidate (QString &aWarning, QString &aTitle);
523
524 void retranslateUi();
525
526 void showEvent (QShowEvent *aEvent);
527
528private slots:
529
530 void mediumUpdated (const VBoxMedium &aMedium);
531 void mediumRemoved (VBoxDefs::MediumType aType, const QString &aMediumId);
532
533 void addController();
534 void addIDEController();
535 void addSATAController();
536 void addSCSIController();
537 void addFloppyController();
538 void delController();
539
540 void addAttachment (KDeviceType aDeviceType = KDeviceType_Null);
541 void delAttachment();
542
543 void getInformation();
544 void setInformation();
545
546 void onVmmInvoked();
547
548 void updateActionsState();
549
550 void onRowInserted (const QModelIndex &aParent, int aIndex);
551 void onRowRemoved();
552
553 void onCurrentItemChanged();
554
555 void onContextMenuRequested (const QPoint &aPosition);
556
557 void onDrawItemBranches (QPainter *aPainter, const QRect &aRect, const QModelIndex &aIndex);
558
559 void onMouseMoved (QMouseEvent *aEvent);
560 void onMouseClicked (QMouseEvent *aEvent);
561
562private:
563
564 QString getWithNewHDWizard();
565 QString getWithMediaManager (VBoxDefs::MediumType aMediumType);
566
567 void updateAdditionalObjects (KDeviceType aType);
568
569 QString generateUniqueName (const QString &aTemplate) const;
570
571 CMachine mMachine;
572 QIWidgetValidator *mValidator;
573
574 StorageModel *mStorageModel;
575
576 QAction *mAddCtrAction;
577 QAction *mAddIDECtrAction;
578 QAction *mAddSATACtrAction;
579 QAction *mAddSCSICtrAction;
580 QAction *mAddFloppyCtrAction;
581 QAction *mDelCtrAction;
582 QAction *mAddAttAction;
583 QAction *mDelAttAction;
584
585 bool mIsLoadingInProgress;
586 bool mIsPolished;
587};
588
589#endif // __VBoxVMSettingsHD_h__
590
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette