VirtualBox

Ignore:
Timestamp:
Oct 27, 2008 2:04:18 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
38479
Message:

Ported s2 branch (r37120:38456).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsHD.h

    r12036 r13580  
    2929#include "VBoxMediaComboBox.h"
    3030
     31/* Qt includes */
    3132#include <QComboBox>
    3233
    3334/** 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;
     35class SlotValue
     36{
     37public:
     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    {
    5150        bus     = aOther.bus;
    5251        channel = aOther.channel;
    5352        device  = aOther.device;
     53        name    = aOther.name;
    5454        return *this;
    5555    }
    5656
    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 &&
    6160               channel == aOther.channel &&
    6261               device  == aOther.device;
    6362    }
    6463
    65     bool operator!= (const HDSltValue &aOther)
     64    bool operator!= (const SlotValue &aOther)
    6665    {
    6766        return ! (*this == aOther);
    6867    }
    6968
    70     QString     name;
    7169    KStorageBus bus;
    7270    LONG        channel;
    7371    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};
     74Q_DECLARE_METATYPE (SlotValue);
     75
     76/** Register type to store disk data */
     77class DiskValue
     78{
     79public:
     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;
    9091        name = aOther.name;
    91         id   = aOther.id;
     92        tip  = aOther.tip;
     93        pix  = aOther.pix;
    9294        return *this;
    9395    }
    9496
    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)
    102103    {
    103104        return ! (*this == aOther);
    104105    }
    105106
     107    QUuid   id;
    106108    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};
     112Q_DECLARE_METATYPE (DiskValue);
     113
     114/** Declare type to store both slot&disk data */
     115class Attachment
     116{
     117public:
     118    Attachment (SlotValue aSlot, DiskValue aDisk)
     119        : slot (aSlot), disk (aDisk) {}
    117120
    118121    /* 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 */
     137class AttachmentsModel : public QAbstractTableModel
     138{
     139    Q_OBJECT;
     140
     141public:
     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;
    141148
    142149    int columnCount (const QModelIndex &aParent = QModelIndex()) const
    143150        { NOREF (aParent); return 2; }
    144151    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; }
    147153
    148154    QVariant data (const QModelIndex &aIndex,
     
    155161                         int aRole = Qt::DisplayRole) const;
    156162
    157     void addItem (const HDSltValue &aSlt = HDSltValue(),
    158                   const HDVdiValue &aVdi = HDVdiValue());
     163    void addItem (const SlotValue &aSlot = SlotValue(),
     164                  const DiskValue &aDisk = DiskValue());
    159165    void delItem (int aIndex);
    160166
    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();
    164170
    165171    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
     174private:
     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 */
     187class SlotEditor : public QComboBox
    177188{
    178189    Q_OBJECT;
     
    181192public:
    182193
    183     HDSltEditor (QWidget *aParent);
     194    SlotEditor (QWidget *aParent);
    184195
    185196    QVariant slot() const;
     
    196207private:
    197208
    198 #if 0
     209#if 0 /* F2 key binding left for future releases... */
    199210    void keyPressEvent (QKeyEvent *aEvent);
    200211#endif
    201212
    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 */
     222class DiskEditor : public VBoxMediaComboBox
     223{
     224    Q_OBJECT;
     225    Q_PROPERTY (QVariant disk READ disk WRITE setDisk USER true);
     226
     227public:
     228
     229    static DiskEditor* activeEditor();
     230
     231    DiskEditor (QWidget *aParent);
     232   ~DiskEditor();
     233
     234    QVariant disk() const;
     235    void setDisk (QVariant aDisk);
    224236
    225237signals:
     
    227239    void readyToCommit (QWidget *aThis);
    228240
     241protected:
     242
     243    void paintEvent (QPaintEvent *aEvent);
     244    void initStyleOption (QStyleOptionComboBox *aOption) const;
     245
    229246private slots:
    230247
     
    233250private:
    234251
    235 #if 0
     252#if 0 /* F2 key binding left for future releases... */
    236253    void keyPressEvent (QKeyEvent *aEvent);
    237254#endif
    238255
    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 */
     264class HDSettings : public QObject
     265{
     266    Q_OBJECT;
     267
     268public:
     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; }
    257283    void setSataCount (int aSataCount)
    258284    {
    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    }
    264298
    265299protected:
    266300
    267     HDSlotUniquizer (QWidget *aParent, HDItemsModel *aWatched,
    268                      const CMachine &aMachine);
    269     virtual ~HDSlotUniquizer();
     301    HDSettings (QWidget *aParent, AttachmentsModel *aWatched);
     302    virtual ~HDSettings();
     303
     304private slots:
     305
     306    void update()
     307    {
     308        makeMediumList();
     309        mModel->updateDisks();
     310    }
    270311
    271312private:
     
    273314    void makeIDEList();
    274315    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;
    277326
    278327    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 */
    286335class VBoxVMSettingsHD : public VBoxSettingsPage,
    287336                         public Ui::VBoxVMSettingsHD
     
    311360private slots:
    312361
    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
     371private:
     372
     373    /* events */
    323374    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();
    325380    int maxNameLength() const;
    326     void showEvent (QShowEvent *aEvent);
    327 
     381
     382    /* variables */
    328383    CMachine mMachine;
     384    AttachmentsModel *mModel;
    329385    QIWidgetValidator *mValidator;
    330     HDItemsModel *mModel;
     386
    331387    QAction *mNewAction;
    332388    QAction *mDelAction;
    333389    QAction *mVdmAction;
     390
    334391    bool mWasTableSelected;
     392    bool mPolished;
    335393};
    336394
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette