VirtualBox

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

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

FE/Qt4: Ask for confirmation when the user try to delete the last CD/DVD device.

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