VirtualBox

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

Last change on this file since 23225 was 23225, checked in by vboxsync, 16 years ago

FE/Qt4: merged New Storage UI: 'Show Diffs' support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 12.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.215389.xyz. 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 attIsShowDiffs() const;
323 bool attIsHostDrive() const;
324 bool attIsPassthrough() const;
325
326 void setAttSlot (const StorageSlot &aAttSlot);
327 void setAttDevice (KDeviceType aAttDeviceType);
328 void setAttMediumId (const QString &aAttMediumId);
329 void setAttIsShowDiffs (bool aAttIsShowDiffs);
330 void setAttIsPassthrough (bool aPassthrough);
331
332 QString attSize() const;
333 QString attLogicalSize() const;
334 QString attLocation() const;
335 QString attFormat() const;
336 QString attUsage() const;
337
338private:
339
340 void cache();
341
342 void addChild (AbstractItem *aItem);
343 void delChild (AbstractItem *aItem);
344
345 KDeviceType mAttDeviceType;
346
347 StorageSlot mAttSlot;
348 QString mAttMediumId;
349 bool mAttIsShowDiffs;
350 bool mAttIsHostDrive;
351 bool mAttIsPassthrough;
352
353 QString mAttName;
354 QString mAttTip;
355 QPixmap mAttPixmap;
356
357 QString mAttSize;
358 QString mAttLogicalSize;
359 QString mAttLocation;
360 QString mAttFormat;
361 QString mAttUsage;
362};
363
364/* Storage Model */
365class StorageModel : public QAbstractItemModel
366{
367 Q_OBJECT;
368
369public:
370
371 enum DataRole
372 {
373 R_ItemId = Qt::UserRole + 1,
374 R_ItemPixmap,
375 R_ItemPixmapRect,
376 R_ItemName,
377 R_ItemNamePoint,
378 R_ItemType,
379 R_IsController,
380 R_IsAttachment,
381
382 R_IsMoreControllersPossible,
383 R_IsMoreAttachmentsPossible,
384
385 R_CtrName,
386 R_CtrType,
387 R_CtrTypes,
388 R_CtrDevices,
389 R_CtrBusType,
390
391 R_AttSlot,
392 R_AttSlots,
393 R_AttDevice,
394 R_AttDevices,
395 R_AttMediumId,
396 R_AttIsShowDiffs,
397 R_AttIsHostDrive,
398 R_AttIsPassthrough,
399 R_AttSize,
400 R_AttLogicalSize,
401 R_AttLocation,
402 R_AttFormat,
403 R_AttUsage,
404
405 R_Margin,
406 R_Spacing,
407 R_IconSize,
408
409 R_HDPixmapEn,
410 R_HDPixmapDis,
411 R_CDPixmapEn,
412 R_CDPixmapDis,
413 R_FDPixmapEn,
414 R_FDPixmapDis,
415 R_HDPixmapRect,
416 R_CDPixmapRect,
417 R_FDPixmapRect,
418
419 R_PlusPixmapEn,
420 R_PlusPixmapDis,
421 R_MinusPixmapEn,
422 R_MinusPixmapDis,
423 R_AdderPoint
424 };
425
426 StorageModel (QObject *aParent);
427 ~StorageModel();
428
429 int rowCount (const QModelIndex &aParent = QModelIndex()) const;
430 int columnCount (const QModelIndex &aParent = QModelIndex()) const;
431
432 QModelIndex root() const;
433 QModelIndex index (int aRow, int aColumn, const QModelIndex &aParent = QModelIndex()) const;
434 QModelIndex parent (const QModelIndex &aIndex) const;
435
436 QVariant data (const QModelIndex &aIndex, int aRole) const;
437 bool setData (const QModelIndex &aIndex, const QVariant &aValue, int aRole);
438
439 QModelIndex addController (const QString &aCtrName, KStorageBus aBusType, KStorageControllerType aCtrType);
440 void delController (const QUuid &aCtrId);
441
442 QModelIndex addAttachment (const QUuid &aCtrId, KDeviceType aDeviceType);
443 void delAttachment (const QUuid &aCtrId, const QUuid &aAttId);
444
445private:
446
447 Qt::ItemFlags flags (const QModelIndex &aIndex) const;
448
449 AbstractItem *mRootItem;
450
451 QPixmap mPlusPixmapEn;
452 QPixmap mPlusPixmapDis;
453
454 QPixmap mMinusPixmapEn;
455 QPixmap mMinusPixmapDis;
456};
457
458/* Storage Delegate */
459class StorageDelegate : public QItemDelegate
460{
461 Q_OBJECT;
462
463public:
464
465 StorageDelegate (QObject *aParent);
466
467private:
468
469 void paint (QPainter *aPainter, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const;
470};
471
472/**
473 * QWidget class reimplementation.
474 * Used as HD Settings widget.
475 */
476class VBoxVMSettingsHD : public VBoxSettingsPage,
477 public Ui::VBoxVMSettingsHD
478{
479 Q_OBJECT;
480
481public:
482
483 VBoxVMSettingsHD();
484
485signals:
486
487 void mediumChanged();
488
489protected:
490
491 void getFrom (const CMachine &aMachine);
492 void putBackTo();
493
494 void setValidator (QIWidgetValidator *aVal);
495 bool revalidate (QString &aWarning, QString &aTitle);
496
497 void retranslateUi();
498
499 void showEvent (QShowEvent *aEvent);
500
501private slots:
502
503 void addController();
504 void addIDEController();
505 void addSATAController();
506 void addSCSIController();
507 void addFloppyController();
508 void delController();
509
510 void addAttachment (KDeviceType aDeviceType = KDeviceType_Null);
511 void delAttachment();
512
513 void getInformation();
514 void setInformation();
515
516 void onVmmInvoked();
517
518 void updateActionsState();
519
520 void onRowInserted (const QModelIndex &aParent, int aIndex);
521 void onRowRemoved();
522
523 void onCurrentItemChanged();
524
525 void onContextMenuRequested (const QPoint &aPosition);
526
527 void onDrawItemBranches (QPainter *aPainter, const QRect &aRect, const QModelIndex &aIndex);
528
529 void onMouseClicked (QMouseEvent *aEvent);
530
531private:
532
533 QString getWithNewHDWizard();
534 QString getWithMediaManager (VBoxDefs::MediumType aMediumType);
535
536 void updateAdditionalObjects (KDeviceType aType);
537
538 CMachine mMachine;
539 QIWidgetValidator *mValidator;
540
541 StorageModel *mStorageModel;
542
543 QAction *mAddCtrAction;
544 QAction *mAddIDECtrAction;
545 QAction *mAddSATACtrAction;
546 QAction *mAddSCSICtrAction;
547 QAction *mAddFloppyCtrAction;
548 QAction *mDelCtrAction;
549 QAction *mAddAttAction;
550 QAction *mDelAttAction;
551
552 bool mIsLoadingInProgress;
553 bool mIsPolished;
554};
555
556#endif // __VBoxVMSettingsHD_h__
557
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