VirtualBox

Changeset 56953 in vbox


Ignore:
Timestamp:
Jul 16, 2015 2:04:58 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: 7676: Encryption support: Simplifying UI by moving password validation from 'password editor key-press' to 'Ok button key-press'; Removing stuff which became obsolete after that.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r56180 r56953  
    537537             .arg(strKey, CMachine(machine).GetName(), strValue),
    538538          formatErrorInfo(machine));
     539}
     540
     541void UIMessageCenter::warnAboutInvalidEncryptionPassword(const QString &strPasswordId, QWidget *pParent /* = 0 */)
     542{
     543    alert(pParent, MessageType_Error,
     544          tr("Encryption password for <nobr>ID = '%1'</nobr> is invalid.")
     545             .arg(strPasswordId));
    539546}
    540547
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r55547 r56953  
    174174    void cannotSetExtraData(const CVirtualBox &vbox, const QString &strKey, const QString &strValue);
    175175    void cannotSetExtraData(const CMachine &machine, const QString &strKey, const QString &strValue);
     176    void warnAboutInvalidEncryptionPassword(const QString &strPasswordId, QWidget *pParent = 0);
    176177
    177178    /* API: Selector warnings: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIAddDiskEncryptionPasswordDialog.cpp

    r56213 r56953  
    3535# include "UIIconPool.h"
    3636# include "VBoxGlobal.h"
     37# include "UIMessageCenter.h"
    3738# include "QIDialogButtonBox.h"
    3839# include "QIWithRetranslateUI.h"
     
    4849enum UIEncryptionDataTableSection
    4950{
    50     UIEncryptionDataTableSection_Status,
    5151    UIEncryptionDataTableSection_Id,
    5252    UIEncryptionDataTableSection_Password,
     
    7979private slots:
    8080
    81     /** Handles @s strPassword changes. */
    82     void sltPasswordChanged(const QString &strPassword);
     81    /** Commits data to the listeners. */
     82    void sltCommitData() { emit sigCommitData(this); }
    8383
    8484private:
     
    112112    EncryptionPasswordMap encryptionPasswords() const { return m_encryptionPasswords; }
    113113
    114     /** Returns whether the model is valid. */
    115     bool isValid() const;
    116 
    117114    /** Returns the row count, taking optional @a parent instead of root if necessary. */
    118115    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
     
    136133    void prepare();
    137134
    138     /** Returns whether passed @a strPassword is valid for medium with passed @a strMediumId. */
    139     bool isPasswordValid(const QString strMediumId, const QString strPassword);
    140 
    141135    /** Holds the encrypted medium map reference. */
    142136    const EncryptedMediumMap &m_encryptedMediums;
     
    144138    /** Holds the encryption password map instance. */
    145139    EncryptionPasswordMap m_encryptionPasswords;
    146     /** Holds the encryption password status map instance. */
    147     EncryptionPasswordStatusMap m_encryptionPasswordStatus;
    148140};
    149141
     
    157149signals:
    158150
    159     /** Notifies listeners about data change. */
    160     void sigDataChanged();
    161 
    162151    /** Notifies listeners about editor's Enter/Return key triggering. */
    163152    void sigEditorEnterKeyTriggered();
     
    173162    EncryptionPasswordMap encryptionPasswords() const;
    174163
    175     /** Returns whether the table is valid. */
    176     bool isValid() const;
    177 
    178164    /** Initiates the editor for the first index available. */
    179165    void editFirstIndex();
     
    196182    /* Prepare: */
    197183    prepare();
    198 }
    199 
    200 void UIPasswordEditor::sltPasswordChanged(const QString &strPassword)
    201 {
    202     Q_UNUSED(strPassword);
    203     /* Commit data to the listener: */
    204     emit sigCommitData(this);
    205184}
    206185
     
    211190    /* Listen for the text changes: */
    212191    connect(this, SIGNAL(textChanged(const QString&)),
    213             this, SLOT(sltPasswordChanged(const QString&)));
     192            this, SLOT(sltCommitData()));
    214193}
    215194
     
    237216    /* Prepare: */
    238217    prepare();
    239 }
    240 
    241 bool UIEncryptionDataModel::isValid() const
    242 {
    243     /* Check whether the model contains invalid passwords: */
    244     foreach (const bool &fValue, m_encryptionPasswordStatus.values())
    245         if (!fValue)
    246             return false;
    247     /* Valid by default: */
    248     return true;
    249218}
    250219
     
    269238    switch (index.column())
    270239    {
    271         case UIEncryptionDataTableSection_Status:   return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    272240        case UIEncryptionDataTableSection_Id:       return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    273241        case UIEncryptionDataTableSection_Password: return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
     
    286254    switch (iSection)
    287255    {
    288         case UIEncryptionDataTableSection_Status:   return UIAddDiskEncryptionPasswordDialog::tr("Status", "password table field");
    289256        case UIEncryptionDataTableSection_Id:       return UIAddDiskEncryptionPasswordDialog::tr("ID", "password table field");
    290257        case UIEncryptionDataTableSection_Password: return UIAddDiskEncryptionPasswordDialog::tr("Password", "password table field");
     
    297264QVariant UIEncryptionDataModel::data(const QModelIndex &index, int iRole /* = Qt::DisplayRole */) const
    298265{
    299     /* Check index validness: */
     266    /* Check argument validness: */
    300267    if (!index.isValid())
    301268        return QVariant();
     
    303270    switch (iRole)
    304271    {
    305         case Qt::DecorationRole:
    306         {
    307             /* Depending on column index: */
    308             switch (index.column())
    309             {
    310                 case UIEncryptionDataTableSection_Status:
    311                     return m_encryptionPasswordStatus.value(m_encryptionPasswordStatus.keys().at(index.row())) ?
    312                            UIIconPool::iconSet(":/status_check_16px.png") : UIIconPool::iconSet(":/status_error_16px.png");
    313                 default:
    314                     return QVariant();
    315             }
    316             break;
    317         }
    318272        case Qt::DisplayRole:
    319273        {
     
    365319bool UIEncryptionDataModel::setData(const QModelIndex &index, const QVariant &value, int iRole /* = Qt::EditRole */)
    366320{
    367     /* Check index validness: */
    368     if (!index.isValid())
    369         return false;
    370321    /* Check argument validness: */
    371     if (iRole != Qt::EditRole)
     322    if (!index.isValid() || iRole != Qt::EditRole)
    372323        return false;
    373324    /* Depending on column index: */
     
    381332            const QString strKey = m_encryptionPasswords.keys().at(iRow);
    382333            m_encryptionPasswords[strKey] = strPassword;
    383             /* Update password status: */
    384             const QString strMediumId = m_encryptedMediums.values(strKey).first();
    385             const bool fPasswordStatus = isPasswordValid(strMediumId, strPassword);
    386             m_encryptionPasswordStatus[strKey] = fPasswordStatus;
    387             /* Initiate explicit password status update: */
    388             const QModelIndex statusIndex = createIndex(iRow, UIEncryptionDataTableSection_Status);
    389             emit dataChanged(statusIndex, statusIndex);
    390334            break;
    391335        }
     
    399343void UIEncryptionDataModel::prepare()
    400344{
    401     /* Populate the map of passwords and statuses. */
     345    /* Populate the map of passwords and statuses: */
    402346    foreach (const QString &strPasswordId, m_encryptedMediums.keys())
    403     {
    404347        m_encryptionPasswords.insert(strPasswordId, QString());
    405         m_encryptionPasswordStatus.insert(strPasswordId, false);
    406     }
    407 }
    408 
    409 bool UIEncryptionDataModel::isPasswordValid(const QString strMediumId, const QString strPassword)
    410 {
    411     /* Look for the medium with passed ID: */
    412     const UIMedium uimedium = vboxGlobal().medium(strMediumId);
    413     if (!uimedium.isNull())
    414     {
    415         /* Check wrapped medium for validity: */
    416         const CMedium medium = uimedium.medium();
    417         if (!medium.isNull())
    418         {
    419             /* Check whether the password is suitable for that medium. */
    420             medium.CheckEncryptionPassword(strPassword);
    421             return medium.isOk();
    422         }
    423     }
    424     /* False by default: */
    425     return false;
    426348}
    427349
     
    438360    AssertPtrReturn(m_pModelEncryptionData, EncryptionPasswordMap());
    439361    return m_pModelEncryptionData->encryptionPasswords();
    440 }
    441 
    442 bool UIEncryptionDataTable::isValid() const
    443 {
    444     AssertPtrReturn(m_pModelEncryptionData, false);
    445     return m_pModelEncryptionData->isValid();
    446362}
    447363
     
    467383        /* Assign configured model to table: */
    468384        setModel(m_pModelEncryptionData);
    469         /* Configure encryption-data model: */
    470         connect(m_pModelEncryptionData, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
    471                 this, SIGNAL(sigDataChanged()));
    472385    }
    473386
     
    510423    verticalHeader()->setDefaultSectionSize((int)(verticalHeader()->minimumSectionSize() * 1.33));
    511424    horizontalHeader()->setStretchLastSection(false);
    512     horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Status, QHeaderView::ResizeToContents);
    513425    horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Id, QHeaderView::Interactive);
    514426    horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Password, QHeaderView::Stretch);
     
    529441    /* Translate: */
    530442    retranslateUi();
    531     /* Validate: */
    532     revalidate();
    533443}
    534444
     
    539449}
    540450
    541 void UIAddDiskEncryptionPasswordDialog::sltEditorEnterKeyTriggered()
    542 {
    543     if (m_pButtonBox->button(QDialogButtonBox::Ok)->isEnabled())
    544         accept();
     451void UIAddDiskEncryptionPasswordDialog::accept()
     452{
     453    /* Validate passwords status: */
     454    foreach (const QString &strPasswordId, m_encryptedMediums.uniqueKeys())
     455    {
     456        const QString strMediumId = m_encryptedMediums.values(strPasswordId).first();
     457        const QString strPassword = m_pTableEncryptionData->encryptionPasswords().value(strPasswordId);
     458        if (!isPasswordValid(strMediumId, strPassword))
     459            return msgCenter().warnAboutInvalidEncryptionPassword(strPasswordId, this);
     460    }
     461    /* Call to base-class: */
     462    QIWithRetranslateUI<QDialog>::accept();
    545463}
    546464
     
    570488            {
    571489                /* Configure encryption-data table: */
    572                 connect(m_pTableEncryptionData, SIGNAL(sigDataChanged()),
    573                         this, SLOT(sltDataChanged()));
    574490                connect(m_pTableEncryptionData, SIGNAL(sigEditorEnterKeyTriggered()),
    575491                        this, SLOT(sltEditorEnterKeyTriggered()));
     
    613529}
    614530
    615 void UIAddDiskEncryptionPasswordDialog::revalidate()
    616 {
    617     /* Validate: */
    618     AssertPtrReturnVoid(m_pButtonBox);
    619     m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(m_pTableEncryptionData->isValid());
     531/* static */
     532bool UIAddDiskEncryptionPasswordDialog::isPasswordValid(const QString strMediumId, const QString strPassword)
     533{
     534    /* Look for the medium with passed ID: */
     535    const UIMedium uimedium = vboxGlobal().medium(strMediumId);
     536    if (!uimedium.isNull())
     537    {
     538        /* Check wrapped medium for validity: */
     539        const CMedium medium = uimedium.medium();
     540        if (!medium.isNull())
     541        {
     542            /* Check whether the password is suitable for that medium: */
     543            medium.CheckEncryptionPassword(strPassword);
     544            return medium.isOk();
     545        }
     546    }
     547    /* False by default: */
     548    return false;
    620549}
    621550
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIAddDiskEncryptionPasswordDialog.h

    r55401 r56953  
    5757private slots:
    5858
    59     /** Handles the data change. */
    60     void sltDataChanged() { revalidate(); }
     59    /** Handles editor's Enter/Return key triggering. */
     60    void sltEditorEnterKeyTriggered() { accept(); }
    6161
    62     /** Handles editor's Enter/Return key triggering. */
    63     void sltEditorEnterKeyTriggered();
     62    /** Performs passwords validation.
     63      * If all passwords are valid,
     64      * this slot calls to base-class. */
     65    void accept();
    6466
    6567private:
     
    7173    void retranslateUi();
    7274
    73     /** Validation routine. */
    74     void revalidate();
     75    /** Returns whether passed @a strPassword is valid for medium with passed @a strMediumId. */
     76    static bool isPasswordValid(const QString strMediumId, const QString strPassword);
    7577
    7678    /** Holds the name of the machine we show this dialog for. */
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