Changeset 13580 in vbox for trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsHD.h
- Timestamp:
- Oct 27, 2008 2:04:18 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 38479
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsHD.h
r12036 r13580 29 29 #include "VBoxMediaComboBox.h" 30 30 31 /* Qt includes */ 31 32 #include <QComboBox> 32 33 33 34 /** Register type to store slot data */ 34 class HDSltValue 35 { 36 public: 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; 35 class SlotValue 36 { 37 public: 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 { 51 50 bus = aOther.bus; 52 51 channel = aOther.channel; 53 52 device = aOther.device; 53 name = aOther.name; 54 54 return *this; 55 55 } 56 56 57 bool operator== (const HDSltValue &aOther) 58 { 59 return name == aOther.name && 60 bus == aOther.bus && 57 bool operator== (const SlotValue &aOther) 58 { 59 return bus == aOther.bus && 61 60 channel == aOther.channel && 62 61 device == aOther.device; 63 62 } 64 63 65 bool operator!= (const HDSltValue &aOther)64 bool operator!= (const SlotValue &aOther) 66 65 { 67 66 return ! (*this == aOther); 68 67 } 69 68 70 QString name;71 69 KStorageBus bus; 72 70 LONG channel; 73 71 LONG device; 74 }; 75 Q_DECLARE_METATYPE (HDSltValue); 76 77 /** Register type to store vdi data */ 78 class HDVdiValue 79 { 80 public: 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 { 72 QString name; 73 }; 74 Q_DECLARE_METATYPE (SlotValue); 75 76 /** Register type to store disk data */ 77 class DiskValue 78 { 79 public: 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; 90 91 name = aOther.name; 91 id = aOther.id; 92 tip = aOther.tip; 93 pix = aOther.pix; 92 94 return *this; 93 95 } 94 96 95 bool operator== (const HDVdiValue &aOther) 96 { 97 return name == aOther.name && 98 id == aOther.id; 99 } 100 101 bool operator!= (const HDVdiValue &aOther) 97 bool operator== (const DiskValue &aOther) 98 { 99 return id == aOther.id; 100 } 101 102 bool operator!= (const DiskValue &aOther) 102 103 { 103 104 return ! (*this == aOther); 104 105 } 105 106 107 QUuid id; 106 108 QString name; 107 QUuid id; 108 }; 109 Q_DECLARE_METATYPE (HDVdiValue); 110 111 /** Declare type to store both slt&vdi data */ 112 class HDValue 113 { 114 public: 115 HDValue (HDSltValue aSlt, HDVdiValue aVdi) 116 : slt (aSlt), vdi (aVdi) {} 109 QString tip; 110 QPixmap pix; 111 }; 112 Q_DECLARE_METATYPE (DiskValue); 113 114 /** Declare type to store both slot&disk data */ 115 class Attachment 116 { 117 public: 118 Attachment (SlotValue aSlot, DiskValue aDisk) 119 : slot (aSlot), disk (aDisk) {} 117 120 118 121 /* 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 */ 132 class HDItemsModel : public QAbstractTableModel 133 { 134 Q_OBJECT; 135 136 public: 137 138 HDItemsModel (QObject *aParent, int aSltId, int aVdiId) 139 : QAbstractTableModel (aParent) 140 , mSltId (aSltId), mVdiId (aVdiId) {} 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 */ 137 class AttachmentsModel : public QAbstractTableModel 138 { 139 Q_OBJECT; 140 141 public: 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; 141 148 142 149 int columnCount (const QModelIndex &aParent = QModelIndex()) const 143 150 { NOREF (aParent); return 2; } 144 151 int rowCount (const QModelIndex &aParent = QModelIndex()) const 145 { NOREF (aParent); return mSltList.count() + 1; } 146 Qt::ItemFlags flags (const QModelIndex &aIndex) const; 152 { NOREF (aParent); return mUsedSlotsList.count() + 1; } 147 153 148 154 QVariant data (const QModelIndex &aIndex, … … 155 161 int aRole = Qt::DisplayRole) const; 156 162 157 void addItem (const HDSltValue &aSlt = HDSltValue(),158 const HDVdiValue &aVdi = HDVdiValue());163 void addItem (const SlotValue &aSlot = SlotValue(), 164 const DiskValue &aDisk = DiskValue()); 159 165 void delItem (int aIndex); 160 166 161 const QList< HDSltValue>& slotsList() { return mSltList; }162 const QList< HDVdiValue>& vdiList() { return mVdiList; }163 QList< HDValue> fullList (bool aSorted = true);167 const QList<SlotValue>& usedSlotsList() { return mUsedSlotsList; } 168 const QList<DiskValue>& usedDisksList() { return mUsedDisksList; } 169 QList<Attachment> fullUsedList(); 164 170 165 171 void removeSata(); 166 167 private: 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 */ 176 class HDSltEditor : public QComboBox 172 void updateDisks(); 173 174 private: 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 */ 187 class SlotEditor : public QComboBox 177 188 { 178 189 Q_OBJECT; … … 181 192 public: 182 193 183 HDSltEditor (QWidget *aParent);194 SlotEditor (QWidget *aParent); 184 195 185 196 QVariant slot() const; … … 196 207 private: 197 208 198 #if 0 209 #if 0 /* F2 key binding left for future releases... */ 199 210 void keyPressEvent (QKeyEvent *aEvent); 200 211 #endif 201 212 202 void populate (const HDSltValue &aIncluding); 203 204 QList<HDSltValue> mList; 205 }; 206 207 /** VBoxMediaComboBox class reimplementation used as editor for hd vdi */ 208 class HDVdiEditor : public VBoxMediaComboBox 209 { 210 Q_OBJECT; 211 Q_PROPERTY (QVariant vdi READ vdi WRITE setVdi USER true); 212 213 public: 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(); 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 */ 222 class DiskEditor : public VBoxMediaComboBox 223 { 224 Q_OBJECT; 225 Q_PROPERTY (QVariant disk READ disk WRITE setDisk USER true); 226 227 public: 228 229 static DiskEditor* activeEditor(); 230 231 DiskEditor (QWidget *aParent); 232 ~DiskEditor(); 233 234 QVariant disk() const; 235 void setDisk (QVariant aDisk); 224 236 225 237 signals: … … 227 239 void readyToCommit (QWidget *aThis); 228 240 241 protected: 242 243 void paintEvent (QPaintEvent *aEvent); 244 void initStyleOption (QStyleOptionComboBox *aOption) const; 245 229 246 private slots: 230 247 … … 233 250 private: 234 251 235 #if 0 252 #if 0 /* F2 key binding left for future releases... */ 236 253 void keyPressEvent (QKeyEvent *aEvent); 237 254 #endif 238 255 239 static HDVdiEditor *mInstance; 240 }; 241 242 /** Singleton QObject class reimplementation to use for making 243 * selected IDE & SATA slots unique */ 244 class HDSlotUniquizer : public QObject 245 { 246 Q_OBJECT; 247 248 public: 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; } 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 */ 264 class HDSettings : public QObject 265 { 266 Q_OBJECT; 267 268 public: 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 sataCount() const { return mSataCount; } 257 283 void setSataCount (int aSataCount) 258 284 { 259 mSataCount = aSataCount; 260 makeSATAList(); 261 } 262 263 const CMachine& machine() const { return mMachine; } 285 if (mSataCount != aSataCount) 286 { 287 mSataCount = aSataCount; 288 makeSATAList(); 289 } 290 } 291 292 bool showDiffs() const { return mShowDiffs; } 293 void setShowDiffs (bool aShowDiffs) 294 { 295 mShowDiffs = aShowDiffs; 296 update(); 297 } 264 298 265 299 protected: 266 300 267 HDSlotUniquizer (QWidget *aParent, HDItemsModel *aWatched, 268 const CMachine &aMachine); 269 virtual ~HDSlotUniquizer(); 301 HDSettings (QWidget *aParent, AttachmentsModel *aWatched); 302 virtual ~HDSettings(); 303 304 private slots: 305 306 void update() 307 { 308 makeMediumList(); 309 mModel->updateDisks(); 310 } 270 311 271 312 private: … … 273 314 void makeIDEList(); 274 315 void makeSATAList(); 275 276 static HDSlotUniquizer *mInstance; 316 void makeMediumList(); 317 318 static HDSettings *mInstance; 319 320 AttachmentsModel *mModel; 321 CMachine mMachine; 322 323 QList<SlotValue> mIDEList; 324 QList<SlotValue> mSATAList; 325 QList<DiskValue> mDisksList; 277 326 278 327 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*/328 bool mShowDiffs; 329 }; 330 331 /** 332 * QWidget class reimplementation. 333 * Used as HD Settings widget. 334 */ 286 335 class VBoxVMSettingsHD : public VBoxSettingsPage, 287 336 public Ui::VBoxVMSettingsHD … … 311 360 private slots: 312 361 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 321 private: 322 362 void addAttachment(); 363 void delAttachment(); 364 void showMediaManager(); 365 366 void onSATACheckToggled (int); 367 void onShowDiffsCheckToggled (int); 368 369 void updateActions (const QModelIndex &aIndex); 370 371 private: 372 373 /* events */ 323 374 bool eventFilter (QObject *aObj, QEvent *aEvent); 324 375 void showEvent (QShowEvent *aEvent); 376 377 /* private functions */ 378 QUuid getWithMediaManager (const QUuid &aInitialId = QUuid()); 379 QUuid getWithNewHDWizard(); 325 380 int maxNameLength() const; 326 void showEvent (QShowEvent *aEvent); 327 381 382 /* variables */ 328 383 CMachine mMachine; 384 AttachmentsModel *mModel; 329 385 QIWidgetValidator *mValidator; 330 HDItemsModel *mModel; 386 331 387 QAction *mNewAction; 332 388 QAction *mDelAction; 333 389 QAction *mVdmAction; 390 334 391 bool mWasTableSelected; 392 bool mPolished; 335 393 }; 336 394
Note:
See TracChangeset
for help on using the changeset viewer.