VirtualBox

Changeset 86242 in vbox


Ignore:
Timestamp:
Sep 23, 2020 2:55:37 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: UICloudProfileManager: Make sure closeEvent handler checks for an unsaved changes.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/cloud/profilemanager/UICloudProfileManager.cpp

    r86233 r86242  
    2424#include "QIDialogButtonBox.h"
    2525#include "QIInputDialog.h"
     26#include "QIMessageBox.h"
    2627#include "QITreeWidget.h"
    2728#include "UICommon.h"
     
    184185                                   << tr("Source")
    185186                                   << tr("List VMs"));
     187}
     188
     189bool UICloudProfileManagerWidget::makeSureChangesResolved()
     190{
     191    /* Check if currently selected item is of profile type: */
     192    QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
     193    UIItemCloudProfile *pProfileItem = qobject_cast<UIItemCloudProfile*>(pItem);
     194    if (!pProfileItem)
     195        return true;
     196
     197    /* Get item data: */
     198    UIDataCloudProfile oldData = *pProfileItem;
     199    UIDataCloudProfile newData = m_pDetailsWidget->data();
     200
     201    /* Check if data has changed: */
     202    if (newData == oldData)
     203        return true;
     204
     205    /* Ask whether user wants to Accept/Reset changes or still not sure: */
     206    const int iResult = msgCenter().confirmCloudProfileManagerClosing(window());
     207    switch (iResult)
     208    {
     209        case AlertButton_Choice1:
     210        {
     211            sltApplyCloudProfileDetailsChanges();
     212            return true;
     213        }
     214        case AlertButton_Choice2:
     215        {
     216            sltResetCloudProfileDetailsChanges();
     217            return true;
     218        }
     219        default:
     220            break;
     221    }
     222
     223    /* False by default: */
     224    return false;
    186225}
    187226
     
    10721111}
    10731112
     1113void UICloudProfileManager::closeEvent(QCloseEvent *pEvent)
     1114{
     1115    /* Make sure all changes resolved: */
     1116    if (widget()->makeSureChangesResolved())
     1117    {
     1118        /* Call to base class: */
     1119        QIWithRetranslateUI<QIManagerDialog>::closeEvent(pEvent);
     1120    }
     1121    else
     1122    {
     1123        /* Just ignore the event otherwise: */
     1124        pEvent->ignore();
     1125    }
     1126}
     1127
    10741128
    10751129#include "UICloudProfileManager.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/cloud/profilemanager/UICloudProfileManager.h

    r86233 r86242  
    7272    QIToolBar *toolbar() const { return m_pToolBar; }
    7373#endif
     74
     75    /** Check for changes committed.
     76      * @returns Whether changes were resolved (accepted or discarded) or still a problem otherwise. */
     77    bool makeSureChangesResolved();
    7478
    7579protected:
     
    274278    /** @} */
    275279
     280    /** @name Event-handling stuff.
     281      * @{ */
     282        /** Handles close @a pEvent. */
     283        virtual void closeEvent(QCloseEvent *pEvent) /* override */;
     284    /** @} */
     285
    276286    /** @name Action related variables.
    277287      * @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r85389 r86242  
    20222022}
    20232023
     2024int UIMessageCenter::confirmCloudProfileManagerClosing(QWidget *pParent /* = 0 */) const
     2025{
     2026    return question(pParent, MessageType_Question,
     2027                    tr("<p>Do you want to close the Cloud Profile Manager?</p>"
     2028                       "<p>There seems to be an unsaved changes. "
     2029                       "You can choose to <b>Accept</b> or <b>Reject</b> them automatically "
     2030                       "or cancel to keep the dialog opened.</p>"),
     2031                    0 /* auto-confirm id */,
     2032                    AlertButton_Choice1,
     2033                    AlertButton_Choice2,
     2034                    AlertButton_Cancel | AlertButtonOption_Default | AlertButtonOption_Escape,
     2035                    tr("Accept", "cloud profile manager changes"),
     2036                    tr("Reject", "cloud profile manager changes"));
     2037}
     2038
    20242039bool UIMessageCenter::confirmCloudConsoleApplicationRemoval(const QString &strName, QWidget *pParent /* = 0 */) const
    20252040{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r85389 r86242  
    416416    void cannotAssignFormValue(const CRangedIntegerFormValue &comValue, QWidget *pParent = 0) const;
    417417    void cannotAssignFormValue(const CProgress &comProgress, QWidget *pParent = 0) const;
     418    int confirmCloudProfileManagerClosing(QWidget *pParent = 0) const;
    418419
    419420    /* API: Cloud Console Manager warnings: */
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