VirtualBox

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

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

Fe/Qt4: Fixed VM Settings / HD Page => select vdi through vdm.

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