VirtualBox

Changeset 72038 in vbox


Ignore:
Timestamp:
Apr 26, 2018 12:56:47 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full cleanup for UIAddDiskEncryptionPasswordDialog and move it to VBoxGlobal library.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r72027 r72038  
    453453        src/medium/UIMediumDetailsWidget.h \
    454454        src/medium/UIMediumManager.h \
    455         src/runtime/UIAddDiskEncryptionPasswordDialog.h \
    456455        src/runtime/UIConsoleEventHandler.h \
    457456        src/runtime/UIFrameBuffer.h \
     
    665664        src/selector/UIActionPoolSelector.h \
    666665        src/selector/UIVirtualBoxEventHandler.h \
     666        src/widgets/UIAddDiskEncryptionPasswordDialog.h \
    667667        src/widgets/UIBootTable.h \
    668668        src/widgets/UIFilePathSelector.h \
     
    775775        src/selector/UIActionPoolSelector.h \
    776776        src/selector/UIVirtualBoxEventHandler.h \
     777        src/widgets/UIAddDiskEncryptionPasswordDialog.h \
    777778        src/widgets/UIBootTable.h \
    778779        src/widgets/UIFilePathSelector.h \
     
    836837        src/logviewer/UIVMLogViewerSearchPanel.cpp \
    837838        src/logviewer/UIVMLogViewerTextEdit.cpp \
    838         src/runtime/UIAddDiskEncryptionPasswordDialog.cpp \
    839839        src/runtime/UIConsoleEventHandler.cpp \
    840840        src/runtime/UIFrameBuffer.cpp \
     
    874874        src/selector/UIActionPoolSelector.cpp \
    875875        src/selector/UIVirtualBoxEventHandler.cpp \
     876        src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \
    876877        src/widgets/UIFilmContainer.cpp \
    877878        src/widgets/UIHotKeyEditor.cpp \
     
    916917        src/selector/UIActionPoolSelector.cpp \
    917918        src/selector/UIVirtualBoxEventHandler.cpp \
     919        src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \
    918920        src/widgets/UIFilmContainer.cpp \
    919921        src/widgets/UIHotKeyEditor.cpp \
     
    964966        src/medium/UIMediumManager.cpp \
    965967        src/objects/UIRichTextString.cpp \
    966         src/runtime/UIAddDiskEncryptionPasswordDialog.cpp \
    967968        src/runtime/UIConsoleEventHandler.cpp \
    968969        src/runtime/UIFrameBuffer.cpp \
     
    12151216        src/selector/UIVirtualBoxEventHandler.cpp \
    12161217        src/settings/UISettingsDefs.cpp \
     1218        src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \
    12171219        src/widgets/UIBootTable.cpp \
    12181220        src/widgets/UIFilePathSelector.cpp \
     
    13511353        src/selector/UIVirtualBoxEventHandler.cpp \
    13521354        src/settings/UISettingsDefs.cpp \
     1355        src/widgets/UIAddDiskEncryptionPasswordDialog.cpp \
    13531356        src/widgets/UIBootTable.cpp \
    13541357        src/widgets/UIFilePathSelector.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIAddDiskEncryptionPasswordDialog.cpp

    r72037 r72038  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121
    2222/* Qt includes: */
    23 # include <QVBoxLayout>
     23# include <QAbstractTableModel>
     24# include <QHeaderView>
     25# include <QItemEditorFactory>
    2426# include <QLabel>
    2527# include <QLineEdit>
     28# include <QPushButton>
     29# include <QStandardItemEditorCreator>
    2630# include <QTableView>
    27 # include <QHeaderView>
    28 # include <QPushButton>
    29 # include <QItemEditorFactory>
    30 # include <QAbstractTableModel>
    31 # include <QStandardItemEditorCreator>
     31# include <QVBoxLayout>
    3232
    3333/* GUI includes: */
     34# include "QIDialogButtonBox.h"
     35# include "QIStyledItemDelegate.h"
     36# include "QIWithRetranslateUI.h"
     37# include "VBoxGlobal.h"
     38# include "UIAddDiskEncryptionPasswordDialog.h"
     39# include "UIIconPool.h"
    3440# include "UIMedium.h"
    35 # include "UIIconPool.h"
    36 # include "VBoxGlobal.h"
    3741# include "UIMessageCenter.h"
    38 # include "QIDialogButtonBox.h"
    39 # include "QIWithRetranslateUI.h"
    40 # include "QIStyledItemDelegate.h"
    41 # include "UIAddDiskEncryptionPasswordDialog.h"
    4242
    4343/* Other VBox includes: */
     
    4545
    4646#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     47
    4748
    4849/** UIEncryptionDataTable field indexes. */
     
    5455};
    5556
    56 /** QLineEdit reimplementation used as
     57
     58/** QLineEdit extension used as
    5759  * the embedded password editor for the UIEncryptionDataTable. */
    5860class UIPasswordEditor : public QLineEdit
     
    7375public:
    7476
    75     /** Constructor.
    76       * @param pParent being passed to the base-class. */
     77    /** Constructs password editor passing @a pParent to the base-class. */
    7778    UIPasswordEditor(QWidget *pParent);
     79
     80protected:
     81
     82    /** Handles key-press @a pEvent. */
     83    virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
    7884
    7985private slots:
     
    8490private:
    8591
    86     /** Prepare routine. */
     92    /** Prepares all. */
    8793    void prepare();
    88 
    89     /** Key press @a pEvent handler. */
    90     void keyPressEvent(QKeyEvent *pEvent);
    9194
    9295    /** Property: Returns the current password of the editor. */
     
    9699};
    97100
    98 /** QAbstractTableModel reimplementation used as
     101
     102/** QAbstractTableModel extension used as
    99103  * the data representation model for the UIEncryptionDataTable. */
    100104class UIEncryptionDataModel : public QAbstractTableModel
     
    104108public:
    105109
    106     /** Constructor.
    107       * @param pParent          being passed to the base-class,
    108       * @param encryptedMediums contains the lists of medium ids (values) encrypted with passwords with ids (keys). */
     110    /** Constructs model passing @a pParent to the base-class.
     111      * @param  encryptedMediums  Brings the lists of medium ids (values) encrypted with passwords with ids (keys). */
    109112    UIEncryptionDataModel(QObject *pParent, const EncryptedMediumMap &encryptedMediums);
    110113
     
    130133private:
    131134
    132     /** Prepare routine. */
     135    /** Prepares all. */
    133136    void prepare();
    134137
     
    137140
    138141    /** Holds the encryption password map instance. */
    139     EncryptionPasswordMap m_encryptionPasswords;
     142    EncryptionPasswordMap  m_encryptionPasswords;
    140143};
    141144
    142 /** QTableView reimplementation used to
     145
     146/** QTableView extension used to
    143147  * allow the UIAddDiskEncryptionPasswordDialog to enter
    144148  * disk encryption passwords for particular password ids. */
     
    154158public:
    155159
    156     /** Constructor.
    157       * @param pParent being passed to the base-class. */
     160    /** Constructs table.
     161      * @param  encryptedMediums  Brings the lists of medium ids (values) encrypted with passwords with ids (keys). */
    158162    UIEncryptionDataTable(const EncryptedMediumMap &encryptedMediums);
    159163
     
    167171private:
    168172
    169     /** Prepare routine. */
     173    /** Prepares all. */
    170174    void prepare();
    171175
     
    177181};
    178182
     183
     184/*********************************************************************************************************************************
     185*   Class UIPasswordEditor implementation.                                                                                       *
     186*********************************************************************************************************************************/
     187
    179188UIPasswordEditor::UIPasswordEditor(QWidget *pParent)
    180189    : QLineEdit(pParent)
     
    182191    /* Prepare: */
    183192    prepare();
    184 }
    185 
    186 void UIPasswordEditor::prepare()
    187 {
    188     /* Set echo mode: */
    189     setEchoMode(QLineEdit::Password);
    190     /* Listen for the text changes: */
    191     connect(this, SIGNAL(textChanged(const QString&)),
    192             this, SLOT(sltCommitData()));
    193193}
    194194
     
    210210    }
    211211}
     212
     213void UIPasswordEditor::prepare()
     214{
     215    /* Set echo mode: */
     216    setEchoMode(QLineEdit::Password);
     217    /* Listen for the text changes: */
     218    connect(this, &UIPasswordEditor::textChanged,
     219            this, &UIPasswordEditor::sltCommitData);
     220}
     221
     222
     223/*********************************************************************************************************************************
     224*   Class UIEncryptionDataModel implementation.                                                                                  *
     225*********************************************************************************************************************************/
    212226
    213227UIEncryptionDataModel::UIEncryptionDataModel(QObject *pParent, const EncryptedMediumMap &encryptedMediums)
     
    349363}
    350364
     365
     366/*********************************************************************************************************************************
     367*   Class UIEncryptionDataTable implementation.                                                                                  *
     368*********************************************************************************************************************************/
     369
    351370UIEncryptionDataTable::UIEncryptionDataTable(const EncryptedMediumMap &encryptedMediums)
    352371    : m_encryptedMediums(encryptedMediums)
     
    380399    /* Create encryption-data model: */
    381400    m_pModelEncryptionData = new UIEncryptionDataModel(this, m_encryptedMediums);
    382     AssertPtrReturnVoid(m_pModelEncryptionData);
     401    if (m_pModelEncryptionData)
    383402    {
    384403        /* Assign configured model to table: */
     
    388407    /* Create item delegate: */
    389408    QIStyledItemDelegate *pStyledItemDelegate = new QIStyledItemDelegate(this);
    390     AssertPtrReturnVoid(pStyledItemDelegate);
     409    if (pStyledItemDelegate)
    391410    {
    392411        /* Create item editor factory: */
    393412        QItemEditorFactory *pNewItemEditorFactory = new QItemEditorFactory;
    394         AssertPtrReturnVoid(pNewItemEditorFactory);
     413        if (pNewItemEditorFactory)
    395414        {
    396415            /* Create item editor creator: */
    397416            QStandardItemEditorCreator<UIPasswordEditor> *pQStringItemEditorCreator = new QStandardItemEditorCreator<UIPasswordEditor>();
    398             AssertPtrReturnVoid(pQStringItemEditorCreator);
     417            if (pQStringItemEditorCreator)
    399418            {
    400419                /* Register UIPasswordEditor as the QString editor: */
    401420                pNewItemEditorFactory->registerEditor(QVariant::String, pQStringItemEditorCreator);
    402421            }
     422
    403423            /* Assign configured item editor factory to table delegate: */
    404424            pStyledItemDelegate->setItemEditorFactory(pNewItemEditorFactory);
    405425        }
     426
    406427        /* Assign configured item delegate to table: */
    407428        delete itemDelegate();
    408429        setItemDelegate(pStyledItemDelegate);
     430
    409431        /* Configure item delegate: */
    410432        pStyledItemDelegate->setWatchForEditorDataCommits(true);
    411433        pStyledItemDelegate->setWatchForEditorEnterKeyTriggering(true);
    412         connect(pStyledItemDelegate, SIGNAL(sigEditorEnterKeyTriggered()),
    413                 this, SIGNAL(sigEditorEnterKeyTriggered()));
     434        connect(pStyledItemDelegate, &QIStyledItemDelegate::sigEditorEnterKeyTriggered,
     435                this, &UIEncryptionDataTable::sigEditorEnterKeyTriggered);
    414436    }
    415437
     
    428450    horizontalHeader()->setSectionResizeMode(UIEncryptionDataTableSection_Password, QHeaderView::Stretch);
    429451}
     452
     453
     454/*********************************************************************************************************************************
     455*   Class UIAddDiskEncryptionPasswordDialog implementation.                                                                      *
     456*********************************************************************************************************************************/
    430457
    431458UIAddDiskEncryptionPasswordDialog::UIAddDiskEncryptionPasswordDialog(QWidget *pParent,
     
    441468    /* Prepare: */
    442469    prepare();
    443     /* Translate: */
     470    /* Apply language settings: */
    444471    retranslateUi();
    445472}
     
    449476    AssertPtrReturn(m_pTableEncryptionData, EncryptionPasswordMap());
    450477    return m_pTableEncryptionData->encryptionPasswords();
    451 }
    452 
    453 void UIAddDiskEncryptionPasswordDialog::accept()
    454 {
    455     /* Validate passwords status: */
    456     foreach (const QString &strPasswordId, m_encryptedMediums.uniqueKeys())
    457     {
    458         const QString strMediumId = m_encryptedMediums.values(strPasswordId).first();
    459         const QString strPassword = m_pTableEncryptionData->encryptionPasswords().value(strPasswordId);
    460         if (!isPasswordValid(strMediumId, strPassword))
    461         {
    462             msgCenter().warnAboutInvalidEncryptionPassword(strPasswordId, this);
    463             AssertPtrReturnVoid(m_pTableEncryptionData);
    464             m_pTableEncryptionData->setFocus();
    465             m_pTableEncryptionData->editFirstIndex();
    466             return;
    467         }
    468     }
    469     /* Call to base-class: */
    470     QIWithRetranslateUI<QDialog>::accept();
    471 }
    472 
    473 void UIAddDiskEncryptionPasswordDialog::prepare()
    474 {
    475     /* Configure self: */
    476     setWindowModality(Qt::WindowModal);
    477 
    478     /* Create main-layout: */
    479     QVBoxLayout *pMainLayout = new QVBoxLayout(this);
    480     AssertPtrReturnVoid(pMainLayout);
    481     {
    482         /* Create input-layout: */
    483         QVBoxLayout *pInputLayout = new QVBoxLayout;
    484         AssertPtrReturnVoid(pInputLayout);
    485         {
    486             /* Create description label: */
    487             m_pLabelDescription = new QLabel;
    488             AssertPtrReturnVoid(m_pLabelDescription);
    489             {
    490                 /* Add label into layout: */
    491                 pInputLayout->addWidget(m_pLabelDescription);
    492             }
    493             /* Create encryption-data table: */
    494             m_pTableEncryptionData = new UIEncryptionDataTable(m_encryptedMediums);
    495             AssertPtrReturnVoid(m_pTableEncryptionData);
    496             {
    497                 /* Configure encryption-data table: */
    498                 connect(m_pTableEncryptionData, SIGNAL(sigEditorEnterKeyTriggered()),
    499                         this, SLOT(sltEditorEnterKeyTriggered()));
    500                 m_pTableEncryptionData->setFocus();
    501                 m_pTableEncryptionData->editFirstIndex();
    502                 /* Add label into layout: */
    503                 pInputLayout->addWidget(m_pTableEncryptionData);
    504             }
    505             /* Add layout into parent: */
    506             pMainLayout->addLayout(pInputLayout);
    507         }
    508         /* Create button-box: */
    509         m_pButtonBox = new QIDialogButtonBox;
    510         AssertPtrReturnVoid(m_pButtonBox);
    511         {
    512             /* Configure button-box: */
    513             m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    514             connect(m_pButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
    515             connect(m_pButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
    516             /* Add button-box into layout: */
    517             pMainLayout->addWidget(m_pButtonBox);
    518         }
    519     }
    520478}
    521479
     
    537495}
    538496
     497void UIAddDiskEncryptionPasswordDialog::accept()
     498{
     499    /* Validate passwords status: */
     500    foreach (const QString &strPasswordId, m_encryptedMediums.uniqueKeys())
     501    {
     502        const QString strMediumId = m_encryptedMediums.values(strPasswordId).first();
     503        const QString strPassword = m_pTableEncryptionData->encryptionPasswords().value(strPasswordId);
     504        if (!isPasswordValid(strMediumId, strPassword))
     505        {
     506            msgCenter().warnAboutInvalidEncryptionPassword(strPasswordId, this);
     507            AssertPtrReturnVoid(m_pTableEncryptionData);
     508            m_pTableEncryptionData->setFocus();
     509            m_pTableEncryptionData->editFirstIndex();
     510            return;
     511        }
     512    }
     513    /* Call to base-class: */
     514    QIWithRetranslateUI<QDialog>::accept();
     515}
     516
     517void UIAddDiskEncryptionPasswordDialog::prepare()
     518{
     519    /* Configure self: */
     520    setWindowModality(Qt::WindowModal);
     521
     522    /* Create main-layout: */
     523    QVBoxLayout *pMainLayout = new QVBoxLayout(this);
     524    if (pMainLayout)
     525    {
     526        /* Create input-layout: */
     527        QVBoxLayout *pInputLayout = new QVBoxLayout;
     528        if (pInputLayout)
     529        {
     530            /* Create description label: */
     531            m_pLabelDescription = new QLabel;
     532            if (m_pLabelDescription)
     533            {
     534                /* Add label into layout: */
     535                pInputLayout->addWidget(m_pLabelDescription);
     536            }
     537
     538            /* Create encryption-data table: */
     539            m_pTableEncryptionData = new UIEncryptionDataTable(m_encryptedMediums);
     540            if (m_pTableEncryptionData)
     541            {
     542                /* Configure encryption-data table: */
     543                connect(m_pTableEncryptionData, &UIEncryptionDataTable::sigEditorEnterKeyTriggered,
     544                        this, &UIAddDiskEncryptionPasswordDialog::sltEditorEnterKeyTriggered);
     545                m_pTableEncryptionData->setFocus();
     546                m_pTableEncryptionData->editFirstIndex();
     547                /* Add label into layout: */
     548                pInputLayout->addWidget(m_pTableEncryptionData);
     549            }
     550
     551            /* Add layout into parent: */
     552            pMainLayout->addLayout(pInputLayout);
     553        }
     554
     555        /* Create button-box: */
     556        m_pButtonBox = new QIDialogButtonBox;
     557        if (m_pButtonBox)
     558        {
     559            /* Configure button-box: */
     560            m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
     561            connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIAddDiskEncryptionPasswordDialog::accept);
     562            connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIAddDiskEncryptionPasswordDialog::reject);
     563
     564            /* Add button-box into layout: */
     565            pMainLayout->addWidget(m_pButtonBox);
     566        }
     567    }
     568}
     569
    539570/* static */
    540571bool UIAddDiskEncryptionPasswordDialog::isPasswordValid(const QString strMediumId, const QString strPassword)
     
    557588}
    558589
     590
    559591#include "UIAddDiskEncryptionPasswordDialog.moc"
    560 
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIAddDiskEncryptionPasswordDialog.h

    r72037 r72038  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121/* Qt includes: */
    2222#include <QDialog>
     23#include <QMap>
    2324#include <QMultiMap>
    24 #include <QMap>
    2525
    2626/* GUI includes: */
    2727#include "QIWithRetranslateUI.h"
     28#include "UILibraryDefs.h"
    2829
    2930/* Forward declarations: */
     31class QLabel;
     32class QIDialogButtonBox;
    3033class UIEncryptionDataTable;
    31 class QIDialogButtonBox;
    32 class QLabel;
    3334
    3435/* Type definitions: */
     
    3738typedef QMap<QString, bool> EncryptionPasswordStatusMap;
    3839
    39 /** QDialog reimplementation used to
    40   * allow the user to enter disk encryption passwords for particular password ids. */
    41 class UIAddDiskEncryptionPasswordDialog : public QIWithRetranslateUI<QDialog>
     40/** QDialog subclass used to
     41  * allow the user to enter disk encryption passwords for particular password IDs. */
     42class SHARED_LIBRARY_STUFF UIAddDiskEncryptionPasswordDialog : public QIWithRetranslateUI<QDialog>
    4243{
    4344    Q_OBJECT;
     
    4546public:
    4647
    47     /** Constructor.
    48       * @param pParent          being passed to the base-class,
    49       * @param strMachineName   holds the name of the machine we show this dialog for,
    50       * @param encryptedMediums contains the lists of medium ids (values) encrypted with passwords with ids (keys). */
     48    /** Constructs dialog passing @a pParent to the base-class.
     49      * @param  strMachineName    Brings the name of the machine we show this dialog for.
     50      * @param  encryptedMediums  Brings the lists of medium ids (values) encrypted with passwords with ids (keys). */
    5151    UIAddDiskEncryptionPasswordDialog(QWidget *pParent, const QString &strMachineName, const EncryptedMediumMap &encryptedMediums);
    5252
     
    5454      * acquired from the UIEncryptionDataTable instance. */
    5555    EncryptionPasswordMap encryptionPasswords() const;
     56
     57protected:
     58
     59    /** Translation routine. */
     60    virtual void retranslateUi() /* override */;
    5661
    5762private slots:
     
    6772private:
    6873
    69     /** Prepare routine. */
     74    /** Prepares all. */
    7075    void prepare();
    71 
    72     /** Translation routine. */
    73     void retranslateUi();
    7476
    7577    /** Returns whether passed @a strPassword is valid for medium with passed @a strMediumId. */
     
    7779
    7880    /** Holds the name of the machine we show this dialog for. */
    79     const QString m_strMachineName;
     81    const QString  m_strMachineName;
    8082
    8183    /** Holds the encrypted medium map reference. */
     
    8385
    8486    /** Holds the description label instance. */
    85     QLabel *m_pLabelDescription;
     87    QLabel                *m_pLabelDescription;
    8688    /** Holds the encryption-data table instance. */
    8789    UIEncryptionDataTable *m_pTableEncryptionData;
    8890    /** Holds the button-box instance. */
    89     QIDialogButtonBox *m_pButtonBox;
     91    QIDialogButtonBox     *m_pButtonBox;
    9092};
    9193
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