VirtualBox

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

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

FE/Qt4: Use QIWidthRetranslateUI at all places.

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