VirtualBox

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

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

gcc-4.3 warnings

  • 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 void populate (const HDSltValue &aIncluding);
199
200 QList<HDSltValue> mList;
201};
202
203/** VBoxMediaComboBox class reimplementation used as editor for hd vdi */
204class HDVdiEditor : public VBoxMediaComboBox
205{
206 Q_OBJECT;
207 Q_PROPERTY (QVariant vdi READ vdi WRITE setVdi USER true);
208
209public:
210
211 HDVdiEditor (QWidget *aParent);
212 ~HDVdiEditor();
213
214 QVariant vdi() const;
215 void setVdi (QVariant aVdi);
216
217 void tryToChooseUniqueVdi (QList<HDVdiValue> &aList);
218
219 static HDVdiEditor* activeEditor();
220
221signals:
222
223 void readyToCommit (QWidget *aThis);
224
225private slots:
226
227 void onActivate();
228
229private:
230
231 static HDVdiEditor *mInstance;
232};
233
234/** Singleton QObject class reimplementation to use for making
235 * selected IDE & SATA slots unique */
236class HDSlotUniquizer : public QObject
237{
238 Q_OBJECT;
239
240public:
241
242 static HDSlotUniquizer* instance (QWidget *aParent = 0,
243 HDItemsModel *aWatched = 0,
244 const CMachine &aMachine = CMachine());
245
246 QList<HDSltValue> list (const HDSltValue &aIncluding, bool aFilter = true);
247
248 int sataCount() { return mSataCount; }
249 void setSataCount (int aSataCount)
250 {
251 mSataCount = aSataCount;
252 makeSATAList();
253 }
254
255 const CMachine& machine() const { return mMachine; }
256
257protected:
258
259 HDSlotUniquizer (QWidget *aParent, HDItemsModel *aWatched,
260 const CMachine &aMachine);
261 virtual ~HDSlotUniquizer();
262
263private:
264
265 void makeIDEList();
266 void makeSATAList();
267
268 static HDSlotUniquizer *mInstance;
269
270 int mSataCount;
271 HDItemsModel *mModel;
272 QList<HDSltValue> mIDEList;
273 QList<HDSltValue> mSATAList;
274 const CMachine &mMachine;
275};
276
277/** QWidget class reimplementation used as hard disks settings */
278class VBoxVMSettingsHD : public VBoxSettingsPage,
279 public Ui::VBoxVMSettingsHD
280{
281 Q_OBJECT;
282
283public:
284
285 VBoxVMSettingsHD();
286
287signals:
288
289 void signalToCloseEditor (QWidget *aEditor,
290 QAbstractItemDelegate::EndEditHint aCloseHint);
291 void hdChanged();
292
293protected:
294
295 void getFrom (const CMachine &aMachine);
296 void putBackTo();
297
298 void setValidator (QIWidgetValidator *aVal);
299 bool revalidate (QString &aWarning, QString &aTitle);
300
301 void setOrderAfter (QWidget *aWidget);
302
303 void retranslateUi();
304
305private slots:
306
307 void newClicked();
308 void delClicked();
309 void vdmClicked();
310
311 void onCurrentChanged (const QModelIndex &aIndex);
312 void cbSATAToggled (int);
313 void onMediaRemoved (VBoxDefs::DiskType, const QUuid &);
314
315private:
316
317 bool eventFilter (QObject *aObj, QEvent *aEvent);
318
319 int maxNameLength() const;
320 void showEvent (QShowEvent *aEvent);
321
322 CMachine mMachine;
323 QIWidgetValidator *mValidator;
324 HDItemsModel *mModel;
325 QAction *mNewAction;
326 QAction *mDelAction;
327 QAction *mVdmAction;
328};
329
330#endif // __VBoxVMSettingsHD_h__
331
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