VirtualBox

Changeset 55015 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Mar 30, 2015 5:56:27 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: 7676: Runtime UI: Disk Encryption (DE) support: Add Password dialog: Reflect status of the currently entered passwords.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIAddDiskEncryptionPasswordDialog.cpp

    r54936 r55015  
    3131
    3232/* GUI includes: */
     33# include "UIMedium.h"
     34# include "UIIconPool.h"
     35# include "VBoxGlobal.h"
    3336# include "QIDialogButtonBox.h"
    3437# include "QIWithRetranslateUI.h"
     
    4447enum UIEncryptionDataTableSection
    4548{
     49    UIEncryptionDataTableSection_Status,
    4650    UIEncryptionDataTableSection_Id,
    4751    UIEncryptionDataTableSection_Password,
     
    99103
    100104    /** Returns the shallow copy of the encryption password map instance. */
    101     EncryptionPasswordsMap encryptionPasswords() const { return m_encryptionPasswords; }
     105    EncryptionPasswordMap encryptionPasswords() const { return m_encryptionPasswords; }
    102106
    103107    /** Returns the row count, taking optional @a parent instead of root if necessary. */
     
    122126    void prepare();
    123127
     128    /** Returns whether passed @a strPassword is valid for medium with passed @a strMediumId. */
     129    bool isPasswordValid(const QString strMediumId, const QString strPassword);
     130
    124131    /** Holds the encrypted medium map reference. */
    125132    const EncryptedMediumMap &m_encryptedMediums;
    126133
    127134    /** Holds the encryption password map instance. */
    128     EncryptionPasswordsMap m_encryptionPasswords;
     135    EncryptionPasswordMap m_encryptionPasswords;
     136    /** Holds the encryption password status map instance. */
     137    EncryptionPasswordStatusMap m_encryptionPasswordStatus;
    129138};
    130139
     
    144153    /** Returns the shallow copy of the encryption password map
    145154      * acquired from the UIEncryptionDataModel instance. */
    146     EncryptionPasswordsMap encryptionPasswords() const;
     155    EncryptionPasswordMap encryptionPasswords() const;
    147156
    148157private:
     
    211220    switch (index.column())
    212221    {
     222        case UIEncryptionDataTableSection_Status:   return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    213223        case UIEncryptionDataTableSection_Id:       return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    214224        case UIEncryptionDataTableSection_Password: return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
     
    227237    switch (iSection)
    228238    {
    229         case UIEncryptionDataTableSection_Id:       return tr("Password ID");
    230         case UIEncryptionDataTableSection_Password: return tr("Password");
     239        case UIEncryptionDataTableSection_Status:   return tr("Status", "password table field");
     240        case UIEncryptionDataTableSection_Id:       return tr("ID", "password table field");
     241        case UIEncryptionDataTableSection_Password: return tr("Password", "password table field");
    231242        default: break;
    232243    }
     
    243254    switch (iRole)
    244255    {
     256        case Qt::DecorationRole:
     257        {
     258            /* Depending on column index: */
     259            switch (index.column())
     260            {
     261                case UIEncryptionDataTableSection_Status:
     262                    return m_encryptionPasswordStatus.value(m_encryptionPasswordStatus.keys().at(index.row())) ?
     263                           UIIconPool::iconSet(":/status_check_16px.png") : UIIconPool::iconSet(":/status_error_16px.png");
     264                default:
     265                    return QVariant();
     266            }
     267            break;
     268        }
    245269        case Qt::DisplayRole:
    246270        {
     
    312336    switch (index.column())
    313337    {
    314         case UIEncryptionDataTableSection_Password: m_encryptionPasswords[m_encryptionPasswords.keys().at(index.row())] = value.toString(); break;
    315         default: break;
     338        case UIEncryptionDataTableSection_Password:
     339        {
     340            /* Update password: */
     341            const int iRow = index.row();
     342            const QString strPassword = value.toString();
     343            const QString strKey = m_encryptionPasswords.keys().at(iRow);
     344            m_encryptionPasswords[strKey] = strPassword;
     345            /* Update password status: */
     346            const QString strMediumId = m_encryptedMediums.values(strKey).first();
     347            const bool fPasswordStatus = isPasswordValid(strMediumId, strPassword);
     348            m_encryptionPasswordStatus[strKey] = fPasswordStatus;
     349            /* Initiate explicit password status update: */
     350            const QModelIndex statusIndex = createIndex(iRow, UIEncryptionDataTableSection_Status);
     351            emit dataChanged(statusIndex, statusIndex);
     352            break;
     353        }
     354        default:
     355            break;
    316356    }
    317357    /* Nothing to set by default: */
     
    321361void UIEncryptionDataModel::prepare()
    322362{
    323     /* Populate the map of passwords. */
     363    /* Populate the map of passwords and statuses. */
    324364    foreach (const QString &strPasswordId, m_encryptedMediums.keys())
     365    {
    325366        m_encryptionPasswords.insert(strPasswordId, QString());
     367        m_encryptionPasswordStatus.insert(strPasswordId, false);
     368    }
     369}
     370
     371bool UIEncryptionDataModel::isPasswordValid(const QString strMediumId, const QString strPassword)
     372{
     373    /* Look for the medium with passed ID: */
     374    const UIMedium uimedium = vboxGlobal().medium(strMediumId);
     375    if (!uimedium.isNull())
     376    {
     377        /* Check wrapped medium for validity: */
     378        const CMedium medium = uimedium.medium();
     379        if (!medium.isNull())
     380        {
     381            /* Check whether the password is suitable for that medium. */
     382            medium.CheckEncryptionPassword(strPassword);
     383            return medium.isOk();
     384        }
     385    }
     386    /* False by default: */
     387    return false;
    326388}
    327389
     
    334396}
    335397
    336 EncryptionPasswordsMap UIEncryptionDataTable::encryptionPasswords() const
    337 {
    338     AssertPtrReturn(m_pModelEncryptionData, EncryptionPasswordsMap());
     398EncryptionPasswordMap UIEncryptionDataTable::encryptionPasswords() const
     399{
     400    AssertPtrReturn(m_pModelEncryptionData, EncryptionPasswordMap());
    339401    return m_pModelEncryptionData->encryptionPasswords();
    340402}
     
    384446    verticalHeader()->setDefaultSectionSize((int)(verticalHeader()->minimumSectionSize() * 1.33));
    385447    horizontalHeader()->setStretchLastSection(false);
     448    horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Status, QHeaderView::ResizeToContents);
    386449    horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Id, QHeaderView::Interactive);
    387450    horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Password, QHeaderView::Stretch);
     
    403466}
    404467
    405 EncryptionPasswordsMap UIAddDiskEncryptionPasswordDialog::encryptionPasswords() const
    406 {
    407     AssertPtrReturn(m_pTableEncryptionData, EncryptionPasswordsMap());
     468EncryptionPasswordMap UIAddDiskEncryptionPasswordDialog::encryptionPasswords() const
     469{
     470    AssertPtrReturn(m_pTableEncryptionData, EncryptionPasswordMap());
    408471    return m_pTableEncryptionData->encryptionPasswords();
    409472}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIAddDiskEncryptionPasswordDialog.h

    r54754 r55015  
    3232/* Type definitions: */
    3333typedef QMultiMap<QString, QString> EncryptedMediumMap;
    34 typedef QMap<QString, QString> EncryptionPasswordsMap;
     34typedef QMap<QString, QString> EncryptionPasswordMap;
     35typedef QMap<QString, bool> EncryptionPasswordStatusMap;
    3536
    3637/** QDialog reimplementation used to
     
    5051    /** Returns the shallow copy of the encryption password map
    5152      * acquired from the UIEncryptionDataTable instance. */
    52     EncryptionPasswordsMap encryptionPasswords() const;
     53    EncryptionPasswordMap encryptionPasswords() const;
    5354
    5455private:
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r55006 r55015  
    24372437
    24382438    /* Ask for the disk encryption passwords if necessary: */
    2439     EncryptionPasswordsMap encryptionPasswords;
     2439    EncryptionPasswordMap encryptionPasswords;
    24402440    if (!encryptedMediums.isEmpty())
    24412441    {
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsGeneral.cpp

    r54956 r55015  
    314314                /* Get the maps of encrypted mediums and their passwords: */
    315315                const EncryptedMediumMap &encryptedMedium = generalData.m_encryptedMediums;
    316                 const EncryptionPasswordsMap &encryptionPasswords = generalData.m_encryptionPasswords;
     316                const EncryptionPasswordMap &encryptionPasswords = generalData.m_encryptionPasswords;
    317317                /* Enumerate attachments: */
    318318                foreach (const CMediumAttachment &attachment, m_machine.GetMediumAttachments())
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsGeneral.h

    r54953 r55015  
    9292    EncryptedMediumMap m_encryptedMediums;
    9393    /** Holds the encryption passwords. */
    94     EncryptionPasswordsMap m_encryptionPasswords;
     94    EncryptionPasswordMap m_encryptionPasswords;
    9595};
    9696typedef UISettingsCache<UIDataSettingsMachineGeneral> UICacheSettingsMachineGeneral;
Note: See TracChangeset for help on using the changeset viewer.

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