VirtualBox

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

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

FE/Qt4: Storage UI could now be invoked at runtime. Console WND source code now feats current coding-style.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 14.9 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 ControllerAddEn = 0,
67 ControllerAddDis = 1,
68 ControllerDelEn = 2,
69 ControllerDelDis = 3,
70
71 AttachmentAddEn = 4,
72 AttachmentAddDis = 5,
73 AttachmentDelEn = 6,
74 AttachmentDelDis = 7,
75
76 IDEControllerNormal = 8,
77 IDEControllerExpand = 9,
78 IDEControllerCollapse = 10,
79 SATAControllerNormal = 11,
80 SATAControllerExpand = 12,
81 SATAControllerCollapse = 13,
82 SCSIControllerNormal = 14,
83 SCSIControllerExpand = 15,
84 SCSIControllerCollapse = 16,
85 FloppyControllerNormal = 17,
86 FloppyControllerExpand = 18,
87 FloppyControllerCollapse = 19,
88
89 IDEControllerAddEn = 20,
90 IDEControllerAddDis = 21,
91 SATAControllerAddEn = 22,
92 SATAControllerAddDis = 23,
93 SCSIControllerAddEn = 24,
94 SCSIControllerAddDis = 25,
95 FloppyControllerAddEn = 26,
96 FloppyControllerAddDis = 27,
97
98 HDAttachmentNormal = 28,
99 CDAttachmentNormal = 29,
100 FDAttachmentNormal = 30,
101
102 HDAttachmentAddEn = 31,
103 HDAttachmentAddDis = 32,
104 CDAttachmentAddEn = 33,
105 CDAttachmentAddDis = 34,
106 FDAttachmentAddEn = 35,
107 FDAttachmentAddDis = 36,
108
109 VMMEn = 37,
110 VMMDis = 38,
111
112 MaxIndex
113 };
114
115 static PixmapPool* pool (QObject *aParent = 0);
116
117 QPixmap pixmap (PixmapType aType) const;
118
119protected:
120
121 PixmapPool (QObject *aParent);
122
123 static QPointer <PixmapPool> mThis;
124
125private:
126
127 QVector <QPixmap> mPool;
128};
129
130/* Abstract Controller Type */
131class AbstractControllerType
132{
133public:
134
135 AbstractControllerType (KStorageBus aBusType, KStorageControllerType aCtrType);
136 virtual ~AbstractControllerType() {}
137
138 KStorageBus busType() const;
139 KStorageControllerType ctrType() const;
140 ControllerTypeList ctrTypes() const;
141 PixmapPool::PixmapType pixmap (ItemState aState) const;
142
143 void setCtrType (KStorageControllerType aCtrType);
144
145 virtual DeviceTypeList deviceTypeList() const = 0;
146
147protected:
148
149 virtual KStorageControllerType first() const = 0;
150 virtual uint size() const = 0;
151
152 KStorageBus mBusType;
153 KStorageControllerType mCtrType;
154 QList <PixmapPool::PixmapType> mPixmaps;
155};
156
157/* IDE Controller Type */
158class IDEControllerType : public AbstractControllerType
159{
160public:
161
162 IDEControllerType (KStorageControllerType aSubType);
163
164private:
165
166 DeviceTypeList deviceTypeList() const;
167
168 KStorageControllerType first() const;
169 uint size() const;
170};
171
172/* SATA Controller Type */
173class SATAControllerType : public AbstractControllerType
174{
175public:
176
177 SATAControllerType (KStorageControllerType aSubType);
178
179private:
180
181 DeviceTypeList deviceTypeList() const;
182
183 KStorageControllerType first() const;
184 uint size() const;
185};
186
187/* SCSI Controller Type */
188class SCSIControllerType : public AbstractControllerType
189{
190public:
191
192 SCSIControllerType (KStorageControllerType aSubType);
193
194private:
195
196 DeviceTypeList deviceTypeList() const;
197
198 KStorageControllerType first() const;
199 uint size() const;
200};
201
202/* Floppy Controller Type */
203class FloppyControllerType : public AbstractControllerType
204{
205public:
206
207 FloppyControllerType (KStorageControllerType aSubType);
208
209private:
210
211 DeviceTypeList deviceTypeList() const;
212
213 KStorageControllerType first() const;
214 uint size() const;
215};
216
217/* Abstract Item */
218class AbstractItem
219{
220public:
221
222 enum ItemType
223 {
224 Type_InvalidItem = 0,
225 Type_RootItem = 1,
226 Type_ControllerItem = 2,
227 Type_AttachmentItem = 3
228 };
229
230 AbstractItem (AbstractItem *aParent = 0);
231 virtual ~AbstractItem();
232
233 AbstractItem* parent() const;
234 QUuid id() const;
235 QString machineId() const;
236
237 void setMachineId (const QString &aMchineId);
238
239 virtual ItemType rtti() const = 0;
240 virtual AbstractItem* childByPos (int aIndex) = 0;
241 virtual AbstractItem* childById (const QUuid &aId) = 0;
242 virtual int posOfChild (AbstractItem *aItem) const = 0;
243 virtual int childCount() const = 0;
244 virtual QString text() const = 0;
245 virtual QString tip() const = 0;
246 virtual QPixmap pixmap (ItemState aState = State_DefaultItem) = 0;
247
248protected:
249
250 virtual void addChild (AbstractItem *aItem) = 0;
251 virtual void delChild (AbstractItem *aItem) = 0;
252
253 AbstractItem *mParent;
254 QUuid mId;
255 QString mMachineId;
256};
257Q_DECLARE_METATYPE (AbstractItem::ItemType);
258
259/* Root Item */
260class RootItem : public AbstractItem
261{
262public:
263
264 RootItem();
265 ~RootItem();
266
267 ULONG childCount (KStorageBus aBus) const;
268
269private:
270
271 ItemType rtti() const;
272 AbstractItem* childByPos (int aIndex);
273 AbstractItem* childById (const QUuid &aId);
274 int posOfChild (AbstractItem *aItem) const;
275 int childCount() const;
276 QString text() const;
277 QString tip() const;
278 QPixmap pixmap (ItemState aState);
279 void addChild (AbstractItem *aItem);
280 void delChild (AbstractItem *aItem);
281
282 QList <AbstractItem*> mControllers;
283};
284
285/* Controller Item */
286class ControllerItem : public AbstractItem
287{
288public:
289
290 ControllerItem (AbstractItem *aParent, const QString &aName, KStorageBus aBusType,
291 KStorageControllerType aControllerType);
292 ~ControllerItem();
293
294 KStorageBus ctrBusType() const;
295 QString ctrName() const;
296 KStorageControllerType ctrType() const;
297 ControllerTypeList ctrTypes() const;
298
299 void setCtrName (const QString &aCtrName);
300 void setCtrType (KStorageControllerType aCtrType);
301
302 SlotsList ctrAllSlots() const;
303 SlotsList ctrUsedSlots() const;
304 DeviceTypeList ctrDeviceTypeList() const;
305 QStringList ctrAllMediumIds (bool aShowDiffs) const;
306 QStringList ctrUsedMediumIds() const;
307
308private:
309
310 ItemType rtti() const;
311 AbstractItem* childByPos (int aIndex);
312 AbstractItem* childById (const QUuid &aId);
313 int posOfChild (AbstractItem *aItem) const;
314 int childCount() const;
315 QString text() const;
316 QString tip() const;
317 QPixmap pixmap (ItemState aState);
318 void addChild (AbstractItem *aItem);
319 void delChild (AbstractItem *aItem);
320
321 QString mCtrName;
322 AbstractControllerType *mCtrType;
323 QList <AbstractItem*> mAttachments;
324};
325
326/* Attachment Item */
327class AttachmentItem : public AbstractItem
328{
329public:
330
331 AttachmentItem (AbstractItem *aParent, KDeviceType aDeviceType);
332
333 StorageSlot attSlot() const;
334 SlotsList attSlots() const;
335 KDeviceType attDeviceType() const;
336 DeviceTypeList attDeviceTypes() const;
337 QString attMediumId() const;
338 QStringList attMediumIds (bool aFilter = true) const;
339 bool attIsShowDiffs() const;
340 bool attIsHostDrive() const;
341 bool attIsPassthrough() const;
342
343 void setAttSlot (const StorageSlot &aAttSlot);
344 void setAttDevice (KDeviceType aAttDeviceType);
345 void setAttMediumId (const QString &aAttMediumId);
346 void setAttIsShowDiffs (bool aAttIsShowDiffs);
347 void setAttIsPassthrough (bool aPassthrough);
348
349 QString attSize() const;
350 QString attLogicalSize() const;
351 QString attLocation() const;
352 QString attFormat() const;
353 QString attUsage() const;
354
355private:
356
357 void cache();
358
359 ItemType rtti() const;
360 AbstractItem* childByPos (int aIndex);
361 AbstractItem* childById (const QUuid &aId);
362 int posOfChild (AbstractItem *aItem) const;
363 int childCount() const;
364 QString text() const;
365 QString tip() const;
366 QPixmap pixmap (ItemState aState);
367 void addChild (AbstractItem *aItem);
368 void delChild (AbstractItem *aItem);
369
370 KDeviceType mAttDeviceType;
371
372 StorageSlot mAttSlot;
373 QString mAttMediumId;
374 bool mAttIsShowDiffs;
375 bool mAttIsHostDrive;
376 bool mAttIsPassthrough;
377
378 QString mAttName;
379 QString mAttTip;
380 QPixmap mAttPixmap;
381
382 QString mAttSize;
383 QString mAttLogicalSize;
384 QString mAttLocation;
385 QString mAttFormat;
386 QString mAttUsage;
387};
388
389/* Storage Model */
390class StorageModel : public QAbstractItemModel
391{
392 Q_OBJECT;
393
394public:
395
396 enum DataRole
397 {
398 R_ItemId = Qt::UserRole + 1,
399 R_ItemPixmap,
400 R_ItemPixmapRect,
401 R_ItemName,
402 R_ItemNamePoint,
403 R_ItemType,
404 R_IsController,
405 R_IsAttachment,
406
407 R_ToolTipType,
408 R_IsMoreIDEControllersPossible,
409 R_IsMoreSATAControllersPossible,
410 R_IsMoreSCSIControllersPossible,
411 R_IsMoreFloppyControllersPossible,
412 R_IsMoreAttachmentsPossible,
413
414 R_CtrName,
415 R_CtrType,
416 R_CtrTypes,
417 R_CtrDevices,
418 R_CtrBusType,
419
420 R_AttSlot,
421 R_AttSlots,
422 R_AttDevice,
423 R_AttDevices,
424 R_AttMediumId,
425 R_AttIsShowDiffs,
426 R_AttIsHostDrive,
427 R_AttIsPassthrough,
428 R_AttSize,
429 R_AttLogicalSize,
430 R_AttLocation,
431 R_AttFormat,
432 R_AttUsage,
433
434 R_Margin,
435 R_Spacing,
436 R_IconSize,
437
438 R_HDPixmapEn,
439 R_CDPixmapEn,
440 R_FDPixmapEn,
441
442 R_HDPixmapAddEn,
443 R_HDPixmapAddDis,
444 R_CDPixmapAddEn,
445 R_CDPixmapAddDis,
446 R_FDPixmapAddEn,
447 R_FDPixmapAddDis,
448 R_HDPixmapRect,
449 R_CDPixmapRect,
450 R_FDPixmapRect
451 };
452
453 enum ToolTipType
454 {
455 DefaultToolTip = 0,
456 ExpanderToolTip = 1,
457 HDAdderToolTip = 2,
458 CDAdderToolTip = 3,
459 FDAdderToolTip = 4
460 };
461
462 StorageModel (QObject *aParent);
463 ~StorageModel();
464
465 int rowCount (const QModelIndex &aParent = QModelIndex()) const;
466 int columnCount (const QModelIndex &aParent = QModelIndex()) const;
467
468 QModelIndex root() const;
469 QModelIndex index (int aRow, int aColumn, const QModelIndex &aParent = QModelIndex()) const;
470 QModelIndex parent (const QModelIndex &aIndex) const;
471
472 QVariant data (const QModelIndex &aIndex, int aRole) const;
473 bool setData (const QModelIndex &aIndex, const QVariant &aValue, int aRole);
474
475 QModelIndex addController (const QString &aCtrName, KStorageBus aBusType, KStorageControllerType aCtrType);
476 void delController (const QUuid &aCtrId);
477
478 QModelIndex addAttachment (const QUuid &aCtrId, KDeviceType aDeviceType);
479 void delAttachment (const QUuid &aCtrId, const QUuid &aAttId);
480
481 void setMachineId (const QString &aMachineId);
482
483private:
484
485 Qt::ItemFlags flags (const QModelIndex &aIndex) const;
486
487 AbstractItem *mRootItem;
488
489 QPixmap mPlusPixmapEn;
490 QPixmap mPlusPixmapDis;
491
492 QPixmap mMinusPixmapEn;
493 QPixmap mMinusPixmapDis;
494
495 ToolTipType mToolTipType;
496};
497Q_DECLARE_METATYPE (StorageModel::ToolTipType);
498
499/* Storage Delegate */
500class StorageDelegate : public QItemDelegate
501{
502 Q_OBJECT;
503
504public:
505
506 StorageDelegate (QObject *aParent, bool aDisableStaticControls);
507
508private:
509
510 void paint (QPainter *aPainter, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
511
512 bool mDisableStaticControls;
513};
514
515/**
516 * QWidget class reimplementation.
517 * Used as HD Settings widget.
518 */
519class VBoxVMSettingsHD : public VBoxSettingsPage,
520 public Ui::VBoxVMSettingsHD
521{
522 Q_OBJECT;
523
524public:
525
526 VBoxVMSettingsHD (bool aDisableStaticControls = false);
527
528signals:
529
530 void storageChanged();
531
532protected:
533
534 void getFrom (const CMachine &aMachine);
535 void putBackTo();
536
537 void setValidator (QIWidgetValidator *aVal);
538 bool revalidate (QString &aWarning, QString &aTitle);
539
540 void retranslateUi();
541
542 void showEvent (QShowEvent *aEvent);
543
544private slots:
545
546 void mediumUpdated (const VBoxMedium &aMedium);
547 void mediumRemoved (VBoxDefs::MediumType aType, const QString &aMediumId);
548
549 void addController();
550 void addIDEController();
551 void addSATAController();
552 void addSCSIController();
553 void addFloppyController();
554 void delController();
555
556 void addAttachment();
557 void addHDAttachment();
558 void addCDAttachment();
559 void addFDAttachment();
560 void delAttachment();
561
562 void getInformation();
563 void setInformation();
564
565 void onVmmInvoked();
566
567 void updateActionsState();
568
569 void onRowInserted (const QModelIndex &aParent, int aIndex);
570 void onRowRemoved();
571
572 void onCurrentItemChanged();
573
574 void onContextMenuRequested (const QPoint &aPosition);
575
576 void onDrawItemBranches (QPainter *aPainter, const QRect &aRect, const QModelIndex &aIndex);
577
578 void onMouseMoved (QMouseEvent *aEvent);
579 void onMouseClicked (QMouseEvent *aEvent);
580
581private:
582
583 void addControllerWrapper (const QString &aName, KStorageBus aBus, KStorageControllerType aType);
584 void addAttachmentWrapper (KDeviceType aDevice);
585
586 QString getWithNewHDWizard();
587 QString getWithMediaManager (VBoxDefs::MediumType aMediumType);
588
589 void updateAdditionalObjects (KDeviceType aType);
590
591 QString generateUniqueName (const QString &aTemplate) const;
592
593 CMachine mMachine;
594 QIWidgetValidator *mValidator;
595
596 StorageModel *mStorageModel;
597
598 QAction *mAddCtrAction;
599 QAction *mAddIDECtrAction;
600 QAction *mAddSATACtrAction;
601 QAction *mAddSCSICtrAction;
602 QAction *mAddFloppyCtrAction;
603 QAction *mDelCtrAction;
604 QAction *mAddAttAction;
605 QAction *mAddHDAttAction;
606 QAction *mAddCDAttAction;
607 QAction *mAddFDAttAction;
608 QAction *mDelAttAction;
609
610 bool mIsLoadingInProgress;
611 bool mIsPolished;
612 bool mDisableStaticControls;
613};
614
615#endif // __VBoxVMSettingsHD_h__
616
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