VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsHD.h@ 9677

Last change on this file since 9677 was 9654, checked in by vboxsync, 17 years ago

FE/Qt4: Exported to OSE. Some code style updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 8.1 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 "VBoxVMSettingsHD.gen.h"
27#include "COMDefs.h"
28#include "VBoxMediaComboBox.h"
29
30/* Qt includes */
31#include <QComboBox>
32
33class VBoxVMSettingsDlg;
34class QIWidgetValidator;
35
36/** Register type to store slot data */
37class HDSltValue
38{
39public:
40 HDSltValue()
41 : name (QString::null), bus (KStorageBus_Null)
42 , channel (0), device (0) {}
43 HDSltValue (const QString &aName, KStorageBus aBus,
44 LONG aChannel, LONG aDevice)
45 : name (aName), bus (aBus)
46 , channel (aChannel), device (aDevice) {}
47 HDSltValue (const HDSltValue &aOther)
48 : name (aOther.name), bus (aOther.bus)
49 , channel (aOther.channel), device (aOther.device) {}
50
51 HDSltValue& operator= (const HDSltValue &aOther)
52 {
53 name = aOther.name;
54 bus = aOther.bus;
55 channel = aOther.channel;
56 device = aOther.device;
57 return *this;
58 }
59
60 bool operator== (const HDSltValue &aOther)
61 {
62 return name == aOther.name &&
63 bus == aOther.bus &&
64 channel == aOther.channel &&
65 device == aOther.device;
66 }
67
68 bool operator!= (const HDSltValue &aOther)
69 {
70 return ! (*this == aOther);
71 }
72
73 QString name;
74 KStorageBus bus;
75 LONG channel;
76 LONG device;
77};
78Q_DECLARE_METATYPE (HDSltValue);
79
80/** Register type to store vdi data */
81class HDVdiValue
82{
83public:
84 HDVdiValue()
85 : name (QString::null), id (QUuid()) {}
86 HDVdiValue (const QString &aName, const QUuid &aId)
87 : name (aName), id (aId) {}
88 HDVdiValue (const HDVdiValue &aOther)
89 : name (aOther.name), id (aOther.id) {}
90
91 HDVdiValue& operator= (const HDVdiValue &aOther)
92 {
93 name = aOther.name;
94 id = aOther.id;
95 return *this;
96 }
97
98 bool operator== (const HDVdiValue &aOther)
99 {
100 return name == aOther.name &&
101 id == aOther.id;
102 }
103
104 bool operator!= (const HDVdiValue &aOther)
105 {
106 return ! (*this == aOther);
107 }
108
109 QString name;
110 QUuid id;
111};
112Q_DECLARE_METATYPE (HDVdiValue);
113
114/** Declare type to store both slt&vdi data */
115class HDValue
116{
117public:
118 HDValue (HDSltValue aSlt, HDVdiValue aVdi)
119 : slt (aSlt), vdi (aVdi) {}
120
121 /* Define sorting rules */
122 bool operator< (const HDValue &aOther) const
123 {
124 return slt.bus < aOther.slt.bus ||
125 slt.bus == aOther.slt.bus && slt.channel < aOther.slt.channel ||
126 slt.bus == aOther.slt.bus && slt.channel == aOther.slt.channel && slt.device < aOther.slt.device;
127 }
128
129 HDSltValue slt;
130 HDVdiValue vdi;
131};
132
133/** QAbstractTableModel class reimplementation to feat slot/vdi
134 * selection mechanism */
135class HDItemsModel : public QAbstractTableModel
136{
137 Q_OBJECT;
138
139public:
140
141 HDItemsModel (QObject *aParent, int aSltId, int aVdiId)
142 : QAbstractTableModel (aParent)
143 , mSltId (aSltId), mVdiId (aVdiId) {}
144
145 int columnCount (const QModelIndex &aParent = QModelIndex()) const
146 { NOREF (aParent); return 2; }
147 int rowCount (const QModelIndex &aParent = QModelIndex()) const
148 { NOREF (aParent); return mSltList.count() + 1; }
149 Qt::ItemFlags flags (const QModelIndex &aIndex) const;
150
151 QVariant data (const QModelIndex &aIndex,
152 int aRole = Qt::DisplayRole) const;
153 bool setData (const QModelIndex &aIndex,
154 const QVariant &aValue,
155 int aRole = Qt::EditRole);
156 QVariant headerData (int aSection,
157 Qt::Orientation aOrientation,
158 int aRole = Qt::DisplayRole) const;
159
160 void addItem (const HDSltValue &aSlt = HDSltValue(),
161 const HDVdiValue &aVdi = HDVdiValue());
162 void delItem (int aIndex);
163
164 const QList<HDSltValue>& slotsList() { return mSltList; }
165 const QList<HDVdiValue>& vdiList() { return mVdiList; }
166 QList<HDValue> fullList (bool aSorted = true);
167
168 void removeSata();
169
170private:
171
172 QList<HDSltValue> mSltList;
173 QList<HDVdiValue> mVdiList;
174 int mSltId;
175 int mVdiId;
176};
177
178/** QComboBox class reimplementation used as editor for hd slot */
179class HDSltEditor : public QComboBox
180{
181 Q_OBJECT;
182 Q_PROPERTY (QVariant slot READ slot WRITE setSlot USER true);
183
184public:
185
186 HDSltEditor (QWidget *aParent);
187
188 QVariant slot() const;
189 void setSlot (QVariant aSlot);
190
191signals:
192
193 void readyToCommit (QWidget *aThis);
194
195private slots:
196
197 void onActivate();
198
199private:
200
201 void populate (const HDSltValue &aIncluding);
202
203 QList<HDSltValue> mList;
204};
205
206/** VBoxMediaComboBox class reimplementation used as editor for hd vdi */
207class HDVdiEditor : public VBoxMediaComboBox
208{
209 Q_OBJECT;
210 Q_PROPERTY (QVariant vdi READ vdi WRITE setVdi USER true);
211
212public:
213
214 HDVdiEditor (QWidget *aParent);
215 ~HDVdiEditor();
216
217 QVariant vdi() const;
218 void setVdi (QVariant aVdi);
219
220 void tryToChooseUniqueVdi (QList<HDVdiValue> &aList);
221
222 static HDVdiEditor* activeEditor();
223
224signals:
225
226 void readyToCommit (QWidget *aThis);
227
228private slots:
229
230 void onActivate();
231
232private:
233
234 static HDVdiEditor *mInstance;
235};
236
237/** Singleton QObject class reimplementation to use for making
238 * selected IDE & SATA slots unique */
239class HDSlotUniquizer : public QObject
240{
241 Q_OBJECT;
242
243public:
244
245 static HDSlotUniquizer* instance (QWidget *aParent = 0,
246 HDItemsModel *aWatched = 0);
247
248 QList<HDSltValue> list (const HDSltValue &aIncluding, bool aFilter = true);
249
250 int sataCount() { return mSataCount; }
251 void setSataCount (int aSataCount)
252 {
253 mSataCount = aSataCount;
254 makeSATAList();
255 }
256
257protected:
258
259 HDSlotUniquizer (QWidget *aParent, HDItemsModel *aWatched);
260 virtual ~HDSlotUniquizer();
261
262private:
263
264 void makeIDEList();
265 void makeSATAList();
266
267 static HDSlotUniquizer *mInstance;
268
269 int mSataCount;
270 HDItemsModel *mModel;
271 QList<HDSltValue> mIDEList;
272 QList<HDSltValue> mSATAList;
273};
274
275/** QWidget class reimplementation used as hard disks settings */
276class VBoxVMSettingsHD : public QWidget,
277 public Ui::VBoxVMSettingsHD
278{
279 Q_OBJECT;
280
281public:
282
283 VBoxVMSettingsHD (QWidget *aParent, VBoxVMSettingsDlg *aDlg,
284 const QString &aPath);
285 ~VBoxVMSettingsHD();
286
287 static void getFromMachine (const CMachine &aMachine,
288 QWidget *aPage,
289 VBoxVMSettingsDlg *aDlg,
290 const QString &aPath);
291 static void putBackToMachine();
292 static bool revalidate (QString &aWarning);
293
294 bool eventFilter (QObject *aObj, QEvent *aEvent);
295
296 static CMachine mMachine;
297
298signals:
299
300 void hdChanged();
301
302protected:
303
304 void getFrom();
305 void putBackTo();
306 bool validate (QString &aWarning);
307
308private slots:
309
310 void newClicked();
311 void delClicked();
312 void vdmClicked();
313
314 void onCurrentChanged (const QModelIndex &aIndex);
315 void cbSATAToggled (int);
316 void onMediaRemoved (VBoxDefs::DiskType, const QUuid &);
317
318private:
319
320 int maxNameLength() const;
321 void showEvent (QShowEvent *aEvent);
322
323 static VBoxVMSettingsHD *mSettings;
324
325 QIWidgetValidator *mValidator;
326 HDItemsModel *mModel;
327 QAction *mNewAction;
328 QAction *mDelAction;
329 QAction *mVdmAction;
330};
331
332#endif // __VBoxVMSettingsHD_h__
333
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