VirtualBox

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

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

FE/Qt4: GUI support for the SCSI controllers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 10.2 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt4 GUI ("VirtualBox"):
4 * VBoxVMSettingsHD class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2008 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#include "VBoxSettingsPage.h"
27#include "VBoxVMSettingsHD.gen.h"
28#include "COMDefs.h"
29#include "VBoxMediaComboBox.h"
30
31/* Qt includes */
32#include <QComboBox>
33
34/** Register type to store slot data */
35class SlotValue
36{
37public:
38 SlotValue()
39 : bus (KStorageBus_Null), channel (0), device (0)
40 , name (QString::null) {}
41 SlotValue (KStorageBus aBus, LONG aChannel, LONG aDevice)
42 : bus (aBus), channel (aChannel), device (aDevice)
43 , name (vboxGlobal().toFullString (aBus, aChannel, aDevice)) {}
44 SlotValue (const SlotValue &aOther)
45 : bus (aOther.bus), channel (aOther.channel), device (aOther.device)
46 , name (aOther.name) {}
47
48 SlotValue& operator= (const SlotValue &aOther)
49 {
50 bus = aOther.bus;
51 channel = aOther.channel;
52 device = aOther.device;
53 name = aOther.name;
54 return *this;
55 }
56
57 bool operator== (const SlotValue &aOther)
58 {
59 return bus == aOther.bus &&
60 channel == aOther.channel &&
61 device == aOther.device;
62 }
63
64 bool operator!= (const SlotValue &aOther)
65 {
66 return ! (*this == aOther);
67 }
68
69 KStorageBus bus;
70 LONG channel;
71 LONG device;
72 QString name;
73};
74Q_DECLARE_METATYPE (SlotValue);
75
76/** Register type to store disk data */
77class DiskValue
78{
79public:
80 DiskValue()
81 : id (QUuid())
82 , name (QString::null), tip (QString::null), pix (QPixmap()) {}
83 DiskValue (const QUuid &aId);
84 DiskValue (const DiskValue &aOther)
85 : id (aOther.id)
86 , name (aOther.name), tip (aOther.tip), pix (aOther.pix) {}
87
88 DiskValue& operator= (const DiskValue &aOther)
89 {
90 id = aOther.id;
91 name = aOther.name;
92 tip = aOther.tip;
93 pix = aOther.pix;
94 return *this;
95 }
96
97 bool operator== (const DiskValue &aOther)
98 {
99 return id == aOther.id;
100 }
101
102 bool operator!= (const DiskValue &aOther)
103 {
104 return ! (*this == aOther);
105 }
106
107 QUuid id;
108 QString name;
109 QString tip;
110 QPixmap pix;
111};
112Q_DECLARE_METATYPE (DiskValue);
113
114/** Declare type to store both slot&disk data */
115class Attachment
116{
117public:
118 Attachment (SlotValue aSlot, DiskValue aDisk)
119 : slot (aSlot), disk (aDisk) {}
120
121 /* Define sorting rules */
122 bool operator< (const Attachment &aOther) const
123 {
124 return (slot.bus < aOther.slot.bus) ||
125 (slot.bus == aOther.slot.bus && slot.channel < aOther.slot.channel) ||
126 (slot.bus == aOther.slot.bus && slot.channel == aOther.slot.channel && slot.device < aOther.slot.device);
127 }
128
129 SlotValue slot;
130 DiskValue disk;
131};
132
133/**
134 * QAbstractTableModel class reimplementation.
135 * Used to feat slot/disk selection mechanism.
136 */
137class AttachmentsModel : public QAbstractTableModel
138{
139 Q_OBJECT;
140
141public:
142
143 AttachmentsModel (QITableView *aParent, int aSlotId, int aDiskId)
144 : QAbstractTableModel (aParent), mParent (aParent)
145 , mSlotId (aSlotId), mDiskId (aDiskId) {}
146
147 Qt::ItemFlags flags (const QModelIndex &aIndex) const;
148
149 int columnCount (const QModelIndex &aParent = QModelIndex()) const
150 { NOREF (aParent); return 2; }
151 int rowCount (const QModelIndex &aParent = QModelIndex()) const
152 { NOREF (aParent); return mUsedSlotsList.count() + 1; }
153
154 QVariant data (const QModelIndex &aIndex,
155 int aRole = Qt::DisplayRole) const;
156 bool setData (const QModelIndex &aIndex,
157 const QVariant &aValue,
158 int aRole = Qt::EditRole);
159 QVariant headerData (int aSection,
160 Qt::Orientation aOrientation,
161 int aRole = Qt::DisplayRole) const;
162
163 void addItem (const SlotValue &aSlot = SlotValue(),
164 const DiskValue &aDisk = DiskValue());
165 void delItem (int aIndex);
166
167 const QList<SlotValue>& usedSlotsList() { return mUsedSlotsList; }
168 const QList<DiskValue>& usedDisksList() { return mUsedDisksList; }
169 QList<Attachment> fullUsedList();
170
171 void removeAddController();
172 void updateDisks();
173
174private:
175
176 QITableView *mParent;
177 QList<SlotValue> mUsedSlotsList;
178 QList<DiskValue> mUsedDisksList;
179 int mSlotId;
180 int mDiskId;
181};
182
183/**
184 * QComboBox class reimplementation.
185 * Used as editor for HD Attachment SLOT field.
186 */
187class SlotEditor : public QComboBox
188{
189 Q_OBJECT;
190 Q_PROPERTY (QVariant slot READ slot WRITE setSlot USER true);
191
192public:
193
194 SlotEditor (QWidget *aParent);
195
196 QVariant slot() const;
197 void setSlot (QVariant aSlot);
198
199signals:
200
201 void readyToCommit (QWidget *aThis);
202
203private slots:
204
205 void onActivate();
206
207private:
208
209#if 0 /* F2 key binding left for future releases... */
210 void keyPressEvent (QKeyEvent *aEvent);
211#endif
212
213 void populate (const SlotValue &aIncluding);
214
215 QList<SlotValue> mList;
216};
217
218/**
219 * VBoxMediaComboBox class reimplementation.
220 * Used as editor for HD Attachment DISK field.
221 */
222class DiskEditor : public VBoxMediaComboBox
223{
224 Q_OBJECT;
225 Q_PROPERTY (QVariant disk READ disk WRITE setDisk USER true);
226
227public:
228
229 static DiskEditor* activeEditor();
230
231 DiskEditor (QWidget *aParent);
232 ~DiskEditor();
233
234 QVariant disk() const;
235 void setDisk (QVariant aDisk);
236
237signals:
238
239 void readyToCommit (QWidget *aThis);
240
241protected:
242
243 void paintEvent (QPaintEvent *aEvent);
244 void initStyleOption (QStyleOptionComboBox *aOption) const;
245
246private slots:
247
248 void onActivate();
249
250private:
251
252#if 0 /* F2 key binding left for future releases... */
253 void keyPressEvent (QKeyEvent *aEvent);
254#endif
255
256 static DiskEditor *mInstance;
257};
258
259/**
260 * Singleton QObject class reimplementation.
261 * Used to make selected HD Attachments slots unique &
262 * stores some specific data used for HD Settings.
263 */
264class HDSettings : public QObject
265{
266 Q_OBJECT;
267
268public:
269
270 static HDSettings* instance (QWidget *aParent = 0,
271 AttachmentsModel *aWatched = 0);
272
273 QList<SlotValue> slotsList (const SlotValue &aIncluding = SlotValue(),
274 bool aFilter = false) const;
275 QList<DiskValue> disksList() const;
276
277 bool tryToChooseUniqueDisk (DiskValue &aResult) const;
278
279 const CMachine& machine() const { return mMachine; }
280 void setMachine (const CMachine &aMachine) { mMachine = aMachine; }
281
282 int addCount() const { return mAddCount; }
283 void setAddCount (int aAddCount, KStorageBus aAddBus)
284 {
285 if (mAddCount != aAddCount ||
286 aAddBus != mAddBus)
287 {
288 mAddCount = aAddCount;
289 mAddBus = aAddBus;
290 makeAddControllerList();
291 }
292 }
293
294 bool showDiffs() const { return mShowDiffs; }
295 void setShowDiffs (bool aShowDiffs)
296 {
297 mShowDiffs = aShowDiffs;
298 update();
299 }
300
301protected:
302
303 HDSettings (QWidget *aParent, AttachmentsModel *aWatched);
304 virtual ~HDSettings();
305
306private slots:
307
308 void update()
309 {
310 makeMediumList();
311 mModel->updateDisks();
312 }
313
314private:
315
316 void makeIDEList();
317 void makeAddControllerList();
318 void makeMediumList();
319
320
321 static HDSettings *mInstance;
322
323 AttachmentsModel *mModel;
324 CMachine mMachine;
325
326 QList<SlotValue> mIDEList;
327 QList<SlotValue> mAddControllerList;
328 QList<DiskValue> mDisksList;
329
330 int mAddCount;
331 KStorageBus mAddBus;
332 bool mShowDiffs;
333};
334
335/**
336 * QWidget class reimplementation.
337 * Used as HD Settings widget.
338 */
339class VBoxVMSettingsHD : public VBoxSettingsPage,
340 public Ui::VBoxVMSettingsHD
341{
342 Q_OBJECT;
343
344public:
345
346 VBoxVMSettingsHD();
347
348signals:
349
350 void hdChanged();
351
352protected:
353
354 void getFrom (const CMachine &aMachine);
355 void putBackTo();
356
357 void setValidator (QIWidgetValidator *aVal);
358 bool revalidate (QString &aWarning, QString &aTitle);
359
360 void setOrderAfter (QWidget *aWidget);
361
362 void retranslateUi();
363
364private slots:
365
366 void addAttachment();
367 void delAttachment();
368 void showMediaManager();
369
370 void onAddControllerCheckToggled (int);
371 void onAddControllerTypeChanged (int aIndex);
372 bool checkAddControllers (int aWhat);
373 void onShowDiffsCheckToggled (int);
374
375 void updateActions (const QModelIndex &aIndex);
376
377private:
378
379 /* events */
380 bool eventFilter (QObject *aObj, QEvent *aEvent);
381 void showEvent (QShowEvent *aEvent);
382
383 /* private functions */
384 QUuid getWithMediaManager (const QUuid &aInitialId = QUuid());
385 QUuid getWithNewHDWizard();
386 int maxNameLength() const;
387 void prepareComboboxes();
388 void removeFocus();
389 KStorageControllerType currentControllerType() const
390 {
391 return static_cast<KStorageControllerType> (mCbControllerType->itemData (mCbControllerType->currentIndex()).toInt());
392 }
393 KStorageBus currentBusType() const
394 {
395 return vboxGlobal().toStorageBusType (currentControllerType());
396 }
397 int currentMaxPortCount() const
398 {
399 int c = 0;
400 switch (currentBusType())
401 {
402 case KStorageBus_IDE: c = 2; break;
403 case KStorageBus_SATA: c = 30; break;
404 case KStorageBus_SCSI: c = 16; break;
405 default: break;
406 }
407 return c;
408 }
409
410 /* variables */
411 CMachine mMachine;
412 AttachmentsModel *mModel;
413 QIWidgetValidator *mValidator;
414
415 QAction *mNewAction;
416 QAction *mDelAction;
417 QAction *mVdmAction;
418
419 bool mWasTableSelected;
420 bool mPolished;
421
422 int mLastSelAddControllerIndex;
423};
424
425#endif // __VBoxVMSettingsHD_h__
426
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