VirtualBox

Changeset 75633 in vbox


Ignore:
Timestamp:
Nov 21, 2018 10:03:40 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126811
Message:

FE/Qt: bugref:6699. Implement a 'delete confirmation' dialog

Location:
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIGuestControlFileTable.cpp

    r75619 r75633  
    2323# include <QAction>
    2424# include <QComboBox>
     25# include <QCheckBox>
    2526# include <QDateTime>
    2627# include <QDir>
     
    4445# include "UIIconPool.h"
    4546# include "UIGuestControlFileTable.h"
     47# include "UIGuestControlFileManager.h"
    4648# include "UIGuestControlFileModel.h"
    4749# include "UIToolBar.h"
     
    99101
    100102protected:
    101         virtual void drawFocus ( QPainter * /*painter*/, const QStyleOptionViewItem & /*option*/, const QRect & /*rect*/ ) const {}
     103
     104    virtual void drawFocus ( QPainter * /*painter*/, const QStyleOptionViewItem & /*option*/, const QRect & /*rect*/ ) const {}
     105
    102106};
    103107
    104108
    105109/*********************************************************************************************************************************
    106 *   UIFileStringInputDialog definition.                                                                                          *
     110*   UStringInputDialog definition.                                                                                          *
    107111*********************************************************************************************************************************/
    108112
     
    121125
    122126    QILineEdit      *m_pLineEdit;
     127
     128};
     129
     130
     131/*********************************************************************************************************************************
     132*   UIFileDeleteConfirmationDialog definition.                                                                                   *
     133*********************************************************************************************************************************/
     134
     135/** A QIDialog child including a line edit whose text exposed when the dialog is accepted */
     136class UIFileDeleteConfirmationDialog : public QIDialog
     137{
     138
     139    Q_OBJECT;
     140
     141public:
     142
     143    UIFileDeleteConfirmationDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
     144    /** Returns whether m_pAskNextTimeCheckBox is checked or not. */
     145    bool askDeleteConfirmationNextTime() const;
     146
     147private:
     148
     149    QCheckBox *m_pAskNextTimeCheckBox;
     150    QLabel    *m_pQuestionLabel;
    123151
    124152};
     
    341369        new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
    342370    layout->addWidget(pButtonBox);
    343         // {
    344         //     /* Configure button-box: */
    345371    connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
    346372    connect(pButtonBox, &QIDialogButtonBox::rejected, this, &UIStringInputDialog::reject);
    347 
    348373}
    349374
     
    598623{
    599624    return m_isDriveItem;
     625}
     626
     627/*********************************************************************************************************************************
     628+*   UIFileDeleteConfirmationDialog implementation.                                                                                *
     629+*********************************************************************************************************************************/
     630
     631UIFileDeleteConfirmationDialog::UIFileDeleteConfirmationDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags flags /* = 0 */)
     632    :QIDialog(pParent, flags)
     633    , m_pAskNextTimeCheckBox(0)
     634    , m_pQuestionLabel(0)
     635{
     636    QVBoxLayout *pLayout = new QVBoxLayout(this);
     637
     638    m_pQuestionLabel = new QLabel;
     639    if (m_pQuestionLabel)
     640    {
     641        pLayout->addWidget(m_pQuestionLabel);
     642        m_pQuestionLabel->setText(UIGuestControlFileManager::tr("Delete the selected file(s) and/or folder(s)"));
     643    }
     644
     645    QIDialogButtonBox *pButtonBox =
     646        new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
     647    if (pButtonBox)
     648    {
     649        pLayout->addWidget(pButtonBox, 0, Qt::AlignCenter);
     650        connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
     651        connect(pButtonBox, &QIDialogButtonBox::rejected, this, &UIStringInputDialog::reject);
     652    }
     653
     654    QCheckBox *m_pAskNextTimeCheckBox = new QCheckBox;
     655
     656    if (m_pAskNextTimeCheckBox)
     657    {
     658        pLayout->addWidget(m_pAskNextTimeCheckBox);
     659        m_pAskNextTimeCheckBox->setText(UIGuestControlFileManager::tr("Ask for this confirmation next time"));
     660    }
     661}
     662
     663bool UIFileDeleteConfirmationDialog::askDeleteConfirmationNextTime() const
     664{
     665    if (!m_pAskNextTimeCheckBox)
     666        return true;
     667    return m_pAskNextTimeCheckBox->isChecked();
    600668}
    601669
     
    9741042void UIGuestControlFileTable::sltDelete()
    9751043{
     1044    if (!checkIfDeleteOK())
     1045        return;
     1046
     1047    if (!m_pView || !m_pModel)
     1048        return;
     1049
    9761050    if (!m_pView || !m_pModel)
    9771051        return;
     
    14191493}
    14201494
     1495bool UIGuestControlFileTable::checkIfDeleteOK()
     1496{
     1497    UIGuestControlFileManagerSettings *pFileManagerSettings = UIGuestControlFileManagerSettings::instance();
     1498    if (!pFileManagerSettings)
     1499        return true;
     1500    if (!pFileManagerSettings->bAskDeleteConfirmation)
     1501        return true;
     1502    UIFileDeleteConfirmationDialog *pDialog =
     1503        new UIFileDeleteConfirmationDialog(this);
     1504
     1505
     1506    bool fContinueWithDelete = (pDialog->execute() == QDialog::Accepted);
     1507
     1508    bool bAskNextTime = pDialog->askDeleteConfirmationNextTime();
     1509
     1510    /* Update the file manager settings only if it is necessary: */
     1511    if (pFileManagerSettings->bAskDeleteConfirmation != bAskNextTime)
     1512    {
     1513        pFileManagerSettings->bAskDeleteConfirmation = bAskNextTime;
     1514        /* Notify file manager settings panel so that the check box there is updated: */
     1515        emit sigDeleteConfirmationSettingChanged();
     1516    }
     1517
     1518    delete pDialog;
     1519
     1520    return fContinueWithDelete;
     1521
     1522}
     1523
    14211524#include "UIGuestControlFileTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIGuestControlFileTable.h

    r75610 r75633  
    246246
    247247    void sigLogOutput(QString strLog, FileManagerLogType eLogType);
     248    void sigDeleteConfirmationSettingChanged();
    248249
    249250public:
     
    363364    /** Clears the m_pSearchLineEdit and hides it. */
    364365    void            disableSelectionSearch();
     366    /** Checks if delete confirmation dialog is shown and users choice. Returns true
     367     *  if deletion can continue */
     368    bool            checkIfDeleteOK();
     369
    365370    UIGuestControlFileModel      *m_pModel;
    366371    UIGuestControlFileView       *m_pView;
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