VirtualBox

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

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

API: big medium handling change and lots of assorted other cleanups and fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 12.6 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
47/* Pixmap Storage Pool */
48class PixmapPool : public QObject
49{
50 Q_OBJECT;
51
52public:
53
54 enum PixmapType
55 {
56 InvalidPixmap = -1,
57
58 AddControllerEn = 0,
59 AddControllerDis = 1,
60 DelControllerEn = 2,
61 DelControllerDis = 3,
62
63 AddAttachmentEn = 4,
64 AddAttachmentDis = 5,
65 DelAttachmentEn = 6,
66 DelAttachmentDis = 7,
67
68 IDEController = 8,
69 SATAController = 9,
70 SCSIController = 10,
71 FloppyController = 11,
72
73 HDAttachmentEn = 12,
74 HDAttachmentDis = 13,
75 CDAttachmentEn = 14,
76 CDAttachmentDis = 15,
77 FDAttachmentEn = 16,
78 FDAttachmentDis = 17,
79
80 PlusEn = 18,
81 PlusDis = 19,
82 MinusEn = 20,
83 MinusDis = 21,
84
85 UnknownEn = 22,
86
87 VMMEn = 23,
88 VMMDis = 24,
89
90 MaxIndex
91 };
92
93 static PixmapPool* pool (QObject *aParent = 0);
94
95 QPixmap pixmap (PixmapType aType) const;
96
97protected:
98
99 PixmapPool (QObject *aParent);
100
101 static QPointer <PixmapPool> mThis;
102
103private:
104
105 QVector <QPixmap> mPool;
106};
107
108/* Abstract Controller Type */
109class AbstractControllerType
110{
111public:
112
113 AbstractControllerType (KStorageBus aBusType, KStorageControllerType aCtrType);
114 virtual ~AbstractControllerType() {}
115
116 KStorageBus busType() const;
117 KStorageControllerType ctrType() const;
118 ControllerTypeList ctrTypes() const;
119 PixmapPool::PixmapType pixmap() const;
120
121 void setCtrType (KStorageControllerType aCtrType);
122
123 virtual DeviceTypeList deviceTypeList() const = 0;
124
125protected:
126
127 virtual KStorageControllerType first() const = 0;
128 virtual uint size() const = 0;
129
130 KStorageBus mBusType;
131 KStorageControllerType mCtrType;
132 PixmapPool::PixmapType mPixmap;
133};
134
135/* IDE Controller Type */
136class IDEControllerType : public AbstractControllerType
137{
138public:
139
140 IDEControllerType (KStorageControllerType aSubType);
141
142private:
143
144 DeviceTypeList deviceTypeList() const;
145
146 KStorageControllerType first() const;
147 uint size() const;
148};
149
150/* SATA Controller Type */
151class SATAControllerType : public AbstractControllerType
152{
153public:
154
155 SATAControllerType (KStorageControllerType aSubType);
156
157private:
158
159 DeviceTypeList deviceTypeList() const;
160
161 KStorageControllerType first() const;
162 uint size() const;
163};
164
165/* SCSI Controller Type */
166class SCSIControllerType : public AbstractControllerType
167{
168public:
169
170 SCSIControllerType (KStorageControllerType aSubType);
171
172private:
173
174 DeviceTypeList deviceTypeList() const;
175
176 KStorageControllerType first() const;
177 uint size() const;
178};
179
180/* Floppy Controller Type */
181class FloppyControllerType : public AbstractControllerType
182{
183public:
184
185 FloppyControllerType (KStorageControllerType aSubType);
186
187private:
188
189 DeviceTypeList deviceTypeList() const;
190
191 KStorageControllerType first() const;
192 uint size() const;
193};
194
195/* Abstract Item */
196class AbstractItem
197{
198public:
199
200 enum ItemType
201 {
202 Type_InvalidItem = 0,
203 Type_RootItem = 1,
204 Type_ControllerItem = 2,
205 Type_AttachmentItem = 3
206 };
207
208 AbstractItem (AbstractItem *aParent = 0);
209 virtual ~AbstractItem();
210
211 AbstractItem* parent();
212 QUuid id();
213
214 virtual ItemType rtti() const = 0;
215 virtual AbstractItem* childByPos (int aIndex) = 0;
216 virtual AbstractItem* childById (const QUuid &aId) = 0;
217 virtual int posOfChild (AbstractItem *aItem) const = 0;
218 virtual int childCount() const = 0;
219 virtual QString text() const = 0;
220 virtual QString tip() const = 0;
221 virtual QPixmap pixmap() = 0;
222
223protected:
224
225 virtual void addChild (AbstractItem *aItem) = 0;
226 virtual void delChild (AbstractItem *aItem) = 0;
227
228 AbstractItem *mParent;
229 QUuid mId;
230};
231Q_DECLARE_METATYPE (AbstractItem::ItemType);
232
233/* Root Item */
234class RootItem : public AbstractItem
235{
236public:
237
238 RootItem();
239 ~RootItem();
240
241 ItemType rtti() const;
242 AbstractItem* childByPos (int aIndex);
243 AbstractItem* childById (const QUuid &aId);
244 int posOfChild (AbstractItem *aItem) const;
245 int childCount() const;
246 QString text() const;
247 QString tip() const;
248 QPixmap pixmap();
249
250private:
251
252 void addChild (AbstractItem *aItem);
253 void delChild (AbstractItem *aItem);
254
255 QList <AbstractItem*> mControllers;
256};
257
258/* Controller Item */
259class ControllerItem : public AbstractItem
260{
261public:
262
263 ControllerItem (AbstractItem *aParent, const QString &aName, KStorageBus aBusType,
264 KStorageControllerType aControllerType);
265 ~ControllerItem();
266
267 ItemType rtti() const;
268 AbstractItem* childByPos (int aIndex);
269 AbstractItem* childById (const QUuid &aId);
270 int posOfChild (AbstractItem *aItem) const;
271 int childCount() const;
272 QString text() const;
273 QString tip() const;
274 QPixmap pixmap();
275
276 KStorageBus ctrBusType() const;
277 QString ctrName() const;
278 KStorageControllerType ctrType() const;
279 ControllerTypeList ctrTypes() const;
280
281 void setCtrName (const QString &aCtrName);
282 void setCtrType (KStorageControllerType aCtrType);
283
284 SlotsList ctrAllSlots() const;
285 SlotsList ctrUsedSlots() const;
286 DeviceTypeList ctrDeviceTypeList() const;
287 QStringList ctrAllMediumIds() const;
288 QStringList ctrUsedMediumIds() const;
289
290private:
291
292 void addChild (AbstractItem *aItem);
293 void delChild (AbstractItem *aItem);
294
295 QString mCtrName;
296 AbstractControllerType *mCtrType;
297 QList <AbstractItem*> mAttachments;
298};
299
300/* Attachment Item */
301class AttachmentItem : public AbstractItem
302{
303public:
304
305 AttachmentItem (AbstractItem *aParent, KDeviceType aDeviceType);
306
307 ItemType rtti() const;
308 AbstractItem* childByPos (int aIndex);
309 AbstractItem* childById (const QUuid &aId);
310 int posOfChild (AbstractItem *aItem) const;
311 int childCount() const;
312 QString text() const;
313 QString tip() const;
314 QPixmap pixmap();
315
316 StorageSlot attSlot() const;
317 SlotsList attSlots() const;
318 KDeviceType attDeviceType() const;
319 DeviceTypeList attDeviceTypes() const;
320 QString attMediumId() const;
321 QStringList attMediumIds (bool aFilter = true) const;
322 bool attIsHostDrive() const;
323 bool attIsPassthrough() const;
324
325 void setAttSlot (const StorageSlot &aAttSlot);
326 void setAttDevice (KDeviceType aAttDeviceType);
327 void setAttMediumId (const QString &aAttMediumId);
328 void setAttIsPassthrough (bool aPassthrough);
329
330 QString attSize() const;
331 QString attLogicalSize() const;
332 QString attLocation() const;
333 QString attFormat() const;
334 QString attUsage() const;
335
336private:
337
338 void cache (const VBoxMedium &aMedium);
339
340 void addChild (AbstractItem *aItem);
341 void delChild (AbstractItem *aItem);
342
343 KDeviceType mAttDeviceType;
344
345 StorageSlot mAttSlot;
346 QString mAttMediumId;
347 bool mAttIsHostDrive;
348 bool mAttIsPassthrough;
349
350 QString mAttName;
351 QString mAttTip;
352 QPixmap mAttPixmap;
353
354 QString mAttSize;
355 QString mAttLogicalSize;
356 QString mAttLocation;
357 QString mAttFormat;
358 QString mAttUsage;
359};
360
361/* Storage Model */
362class StorageModel : public QAbstractItemModel
363{
364 Q_OBJECT;
365
366public:
367
368 enum DataRole
369 {
370 R_ItemId = Qt::UserRole + 1,
371 R_ItemPixmap,
372 R_ItemPixmapRect,
373 R_ItemName,
374 R_ItemNamePoint,
375 R_ItemType,
376 R_IsController,
377 R_IsAttachment,
378
379 R_IsMoreControllersPossible,
380 R_IsMoreAttachmentsPossible,
381
382 R_CtrName,
383 R_CtrType,
384 R_CtrTypes,
385 R_CtrDevices,
386 R_CtrBusType,
387
388 R_AttSlot,
389 R_AttSlots,
390 R_AttDevice,
391 R_AttDevices,
392 R_AttMediumId,
393 R_AttIsHostDrive,
394 R_AttIsPassthrough,
395 R_AttSize,
396 R_AttLogicalSize,
397 R_AttLocation,
398 R_AttFormat,
399 R_AttUsage,
400
401 R_Margin,
402 R_Spacing,
403 R_IconSize,
404
405 R_HDPixmapEn,
406 R_HDPixmapDis,
407 R_CDPixmapEn,
408 R_CDPixmapDis,
409 R_FDPixmapEn,
410 R_FDPixmapDis,
411 R_HDPixmapRect,
412 R_CDPixmapRect,
413 R_FDPixmapRect,
414
415 R_PlusPixmapEn,
416 R_PlusPixmapDis,
417 R_MinusPixmapEn,
418 R_MinusPixmapDis,
419 R_AdderPoint
420 };
421
422 StorageModel (QObject *aParent);
423 ~StorageModel();
424
425 int rowCount (const QModelIndex &aParent = QModelIndex()) const;
426 int columnCount (const QModelIndex &aParent = QModelIndex()) const;
427
428 QModelIndex root() const;
429 QModelIndex index (int aRow, int aColumn, const QModelIndex &aParent = QModelIndex()) const;
430 QModelIndex parent (const QModelIndex &aIndex) const;
431
432 QVariant data (const QModelIndex &aIndex, int aRole) const;
433 bool setData (const QModelIndex &aIndex, const QVariant &aValue, int aRole);
434
435 QModelIndex addController (const QString &aCtrName, KStorageBus aBusType, KStorageControllerType aCtrType);
436 void delController (const QUuid &aCtrId);
437
438 QModelIndex addAttachment (const QUuid &aCtrId, KDeviceType aDeviceType);
439 void delAttachment (const QUuid &aCtrId, const QUuid &aAttId);
440
441private:
442
443 Qt::ItemFlags flags (const QModelIndex &aIndex) const;
444
445 AbstractItem *mRootItem;
446
447 QPixmap mPlusPixmapEn;
448 QPixmap mPlusPixmapDis;
449
450 QPixmap mMinusPixmapEn;
451 QPixmap mMinusPixmapDis;
452};
453
454/* Storage Delegate */
455class StorageDelegate : public QItemDelegate
456{
457 Q_OBJECT;
458
459public:
460
461 StorageDelegate (QObject *aParent);
462
463private:
464
465 void paint (QPainter *aPainter, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
466};
467
468/**
469 * QWidget class reimplementation.
470 * Used as HD Settings widget.
471 */
472class VBoxVMSettingsHD : public VBoxSettingsPage,
473 public Ui::VBoxVMSettingsHD
474{
475 Q_OBJECT;
476
477public:
478
479 VBoxVMSettingsHD();
480
481signals:
482
483 void mediumChanged();
484
485protected:
486
487 void getFrom (const CMachine &aMachine);
488 void putBackTo();
489
490 void setValidator (QIWidgetValidator *aVal);
491 bool revalidate (QString &aWarning, QString &aTitle);
492
493 void retranslateUi();
494
495 void showEvent (QShowEvent *aEvent);
496
497private slots:
498
499 void addController();
500 void addIDEController();
501 void addSATAController();
502 void addSCSIController();
503 void addFloppyController();
504 void delController();
505
506 void addAttachment (KDeviceType aDeviceType = KDeviceType_Null);
507 void delAttachment();
508
509 void getInformation();
510 void setInformation();
511
512 void onVmmInvoked();
513
514 void updateActionsState();
515
516 void onRowInserted (const QModelIndex &aParent, int aIndex);
517 void onRowRemoved();
518
519 void onCurrentItemChanged();
520
521 void onContextMenuRequested (const QPoint &aPosition);
522
523 void onDrawItemBranches (QPainter *aPainter, const QRect &aRect, const QModelIndex &aIndex);
524
525 void onMouseClicked (QMouseEvent *aEvent);
526
527private:
528
529 QString getWithNewHDWizard();
530 QString getWithMediaManager (VBoxDefs::MediumType aMediumType);
531
532 void updateAdditionalObjects (KDeviceType aType);
533
534 CMachine mMachine;
535 QIWidgetValidator *mValidator;
536
537 StorageModel *mStorageModel;
538
539 QAction *mAddCtrAction;
540 QAction *mAddIDECtrAction;
541 QAction *mAddSATACtrAction;
542 QAction *mAddSCSICtrAction;
543 QAction *mAddFloppyCtrAction;
544 QAction *mDelCtrAction;
545 QAction *mAddAttAction;
546 QAction *mDelAttAction;
547
548 bool mIsLoadingInProgress;
549 bool mIsPolished;
550};
551
552#endif // __VBoxVMSettingsHD_h__
553
Note: See TracBrowser for help on using the repository browser.

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