VirtualBox

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


Ignore:
Timestamp:
Oct 6, 2017 3:08:33 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8674: Reworking UIProgressDialog to handle IProgress events instead of acquiring details by timer (both modes supported, old can be enabled via GUI/Progress/LegacyMode edata flag).

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

Legend:

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

    r68540 r69006  
    566566        src/widgets/UIMiniToolBar.cpp \
    567567        src/widgets/UIPortForwardingTable.cpp \
     568        src/widgets/UIProgressDialog.cpp \
    568569        src/widgets/UITabBar.cpp \
    569570        src/wizards/importappliance/UIWizardImportApp.cpp
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.cpp

    r68962 r69006  
    4242const char* UIExtraDataDefs::GUI_UpdateCheckCount = "GUI/UpdateCheckCount";
    4343#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
     44
     45/* Progress: */
     46const char* UIExtraDataDefs::GUI_Progress_LegacyMode = "GUI/Progress/LegacyMode";
    4447
    4548/* Settings: */
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h

    r68962 r69006  
    5959    /** @} */
    6060#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
     61
     62    /** @name Progress
     63      * @{ */
     64        /** Holds whether legacy progress handling method is requested. */
     65        extern const char* GUI_Progress_LegacyMode;
     66    /** @} */
    6167
    6268    /** @name Settings
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r68962 r69006  
    19401940           << GUI_PreventApplicationUpdate << GUI_UpdateDate << GUI_UpdateCheckCount
    19411941#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
     1942           << GUI_Progress_LegacyMode
    19421943           << GUI_RestrictedGlobalSettingsPages << GUI_RestrictedMachineSettingsPages
    19431944           << GUI_LanguageID
     
    22912292#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
    22922293
     2294bool UIExtraDataManager::legacyProgressHandlingRequested()
     2295{
     2296    /* 'False' unless feature allowed: */
     2297    return isFeatureAllowed(GUI_Progress_LegacyMode);
     2298}
     2299
    22932300bool UIExtraDataManager::guiFeatureEnabled(GUIFeatureType enmFeature)
    22942301{
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r68962 r69006  
    177177    /** @} */
    178178#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
     179
     180    /** @name Progress
     181      * @{ */
     182        /** Returns whether legacy progress handling method is requested. */
     183        bool legacyProgressHandlingRequested();
     184    /** @} */
    179185
    180186    /** @name Settings
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMainEventListener.cpp

    r68508 r69006  
    5858# include "CCanShowWindowEvent.h"
    5959# include "CShowWindowEvent.h"
     60# include "CProgressPercentageChangedEvent.h"
     61# include "CProgressTaskCompletedEvent.h"
    6062#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    6163
     
    404406            break;
    405407        }
     408        case KVBoxEventType_OnProgressPercentageChanged:
     409        {
     410            CProgressPercentageChangedEvent es(pEvent);
     411            emit sigProgressPercentageChange(es.GetProgressId(), (int)es.GetPercent());
     412            break;
     413        }
     414        case KVBoxEventType_OnProgressTaskCompleted:
     415        {
     416            CProgressTaskCompletedEvent es(pEvent);
     417            emit sigProgressTaskComplete(es.GetProgressId());
     418            break;
     419        }
    406420
    407421        default: break;
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMainEventListener.h

    r68508 r69006  
    122122    void sigAudioAdapterChange();
    123123
     124    /** Notifies about @a iPercent change for progress with @a strProgressId. */
     125    void sigProgressPercentageChange(QString strProgressId, int iPercent);
     126    /** Notifies about task complete for progress with @a strProgressId. */
     127    void sigProgressTaskComplete(QString strProgressId);
     128
    124129public:
    125130
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.cpp

    r69005 r69006  
    3232# include "QILabel.h"
    3333# include "UIErrorString.h"
     34# include "UIExtraDataManager.h"
     35# include "UIMainEventListener.h"
    3436# include "UIModalWindowManager.h"
    3537# include "UIProgressDialog.h"
     
    4143
    4244/* COM includes: */
     45# include "CEventListener.h"
     46# include "CEventSource.h"
    4347# include "CProgress.h"
    4448
    4549#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     50
     51
     52/** Private QObject extension
     53  * providing UIExtraDataManager with the CVirtualBox event-source. */
     54class UIProgressEventHandler : public QObject
     55{
     56    Q_OBJECT;
     57
     58signals:
     59
     60    /** Notifies about @a iPercent change for progress with @a strProgressId. */
     61    void sigProgressPercentageChange(QString strProgressId, int iPercent);
     62    /** Notifies about task complete for progress with @a strProgressId. */
     63    void sigProgressTaskComplete(QString strProgressId);
     64
     65public:
     66
     67    /** Constructs event proxy object on the basis of passed @a pParent. */
     68    UIProgressEventHandler(QObject *pParent, const CProgress &comProgress);
     69    /** Destructs event proxy object. */
     70    ~UIProgressEventHandler();
     71
     72protected:
     73
     74    /** @name Prepare/Cleanup cascade.
     75      * @{ */
     76        /** Prepares all. */
     77        void prepare();
     78        /** Prepares listener. */
     79        void prepareListener();
     80        /** Prepares connections. */
     81        void prepareConnections();
     82
     83        /** Cleanups connections. */
     84        void cleanupConnections();
     85        /** Cleanups listener. */
     86        void cleanupListener();
     87        /** Cleanups all. */
     88        void cleanup();
     89    /** @} */
     90
     91private:
     92
     93    /** Holds the progress wrapper. */
     94    CProgress m_comProgress;
     95
     96    /** Holds the Qt event listener instance. */
     97    ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
     98    /** Holds the COM event listener instance. */
     99    CEventListener m_comEventListener;
     100};
     101
     102
     103/*********************************************************************************************************************************
     104*   Class UIProgressEventHandler implementation.                                                                                 *
     105*********************************************************************************************************************************/
     106
     107UIProgressEventHandler::UIProgressEventHandler(QObject *pParent, const CProgress &comProgress)
     108    : QObject(pParent)
     109    , m_comProgress(comProgress)
     110{
     111    /* Prepare: */
     112    prepare();
     113}
     114
     115UIProgressEventHandler::~UIProgressEventHandler()
     116{
     117    /* Cleanup: */
     118    cleanup();
     119}
     120
     121void UIProgressEventHandler::prepare()
     122{
     123    /* Prepare: */
     124    prepareListener();
     125    prepareConnections();
     126}
     127
     128void UIProgressEventHandler::prepareListener()
     129{
     130    /* Create event listener instance: */
     131    m_pQtListener.createObject();
     132    m_pQtListener->init(new UIMainEventListener, this);
     133    m_comEventListener = CEventListener(m_pQtListener);
     134
     135    /* Get CProgress event source: */
     136    CEventSource comEventSourceProgress = m_comProgress.GetEventSource();
     137    AssertWrapperOk(comEventSourceProgress);
     138
     139    /* Enumerate all the required event-types: */
     140    QVector<KVBoxEventType> eventTypes;
     141    eventTypes
     142        << KVBoxEventType_OnProgressPercentageChanged
     143        << KVBoxEventType_OnProgressTaskCompleted;
     144
     145    /* Register event listener for CProgress event source: */
     146    comEventSourceProgress.RegisterListener(m_comEventListener, eventTypes,
     147        gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
     148    AssertWrapperOk(comEventSourceProgress);
     149
     150    /* If event listener registered as passive one: */
     151    if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
     152    {
     153        /* Register event sources in their listeners as well: */
     154        m_pQtListener->getWrapped()->registerSource(comEventSourceProgress, m_comEventListener);
     155    }
     156}
     157
     158void UIProgressEventHandler::prepareConnections()
     159{
     160    /* Create direct (sync) connections for signals of main listener: */
     161    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigProgressPercentageChange,
     162            this, &UIProgressEventHandler::sigProgressPercentageChange,
     163            Qt::DirectConnection);
     164    connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigProgressTaskComplete,
     165            this, &UIProgressEventHandler::sigProgressTaskComplete,
     166            Qt::DirectConnection);
     167}
     168
     169void UIProgressEventHandler::cleanupConnections()
     170{
     171    /* Nothing for now. */
     172}
     173
     174void UIProgressEventHandler::cleanupListener()
     175{
     176    /* If event listener registered as passive one: */
     177    if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
     178    {
     179        /* Unregister everything: */
     180        m_pQtListener->getWrapped()->unregisterSources();
     181    }
     182
     183    /* Make sure VBoxSVC is available: */
     184    if (!vboxGlobal().isVBoxSVCAvailable())
     185        return;
     186
     187    /* Get CProgress event source: */
     188    CEventSource comEventSourceProgress = m_comProgress.GetEventSource();
     189    AssertWrapperOk(comEventSourceProgress);
     190
     191    /* Unregister event listener for CProgress event source: */
     192    comEventSourceProgress.UnregisterListener(m_comEventListener);
     193}
     194
     195void UIProgressEventHandler::cleanup()
     196{
     197    /* Cleanup: */
     198    cleanupConnections();
     199    cleanupListener();
     200}
    46201
    47202
     
    62217    , m_pImage(pImage)
    63218    , m_cMinDuration(cMinDuration)
     219    , m_fLegacyHandling(gEDataManager->legacyProgressHandlingRequested())
    64220    , m_pLabelImage(0)
    65221    , m_pLabelDescription(0)
     
    71227    , m_fCancelEnabled(false)
    72228    , m_fEnded(false)
     229    , m_pEventHandler(0)
    73230{
    74231    /* Prepare: */
     
    101258    }
    102259
    103     /* Start refresh timer: */
    104     int id = startTimer(cRefreshInterval);
     260    /* Start refresh timer (if necessary): */
     261    int id = 0;
     262    if (m_fLegacyHandling)
     263        id = startTimer(cRefreshInterval);
    105264
    106265    /* Set busy cursor.
     
    129288    }
    130289
    131     /* Kill refresh timer: */
    132     killTimer(id);
     290    /* Kill refresh timer (if necessary): */
     291    if (m_fLegacyHandling)
     292        killTimer(id);
    133293
    134294#ifndef VBOX_WS_MAC
     
    171331}
    172332
     333void UIProgressDialog::sltHandleProgressPercentageChange(QString /* strProgressId */, int iPercent)
     334{
     335    /* New mode only: */
     336    AssertReturnVoid(!m_fLegacyHandling);
     337
     338    /* Update progress: */
     339    updateProgressState();
     340    updateProgressPercentage(iPercent);
     341}
     342
     343void UIProgressDialog::sltHandleProgressTaskComplete(QString /* strProgressId */)
     344{
     345    /* New mode only: */
     346    AssertReturnVoid(!m_fLegacyHandling);
     347
     348    /* If progress-dialog is not yet ended but progress is aborted or completed: */
     349    if (!m_fEnded && (!m_comProgress.isOk() || m_comProgress.GetCompleted()))
     350    {
     351        /* Set progress to 100%: */
     352        updateProgressPercentage(100);
     353
     354        /* Try to close the dialog: */
     355        closeProgressDialog();
     356    }
     357}
     358
     359void UIProgressDialog::sltHandleWindowStackChange()
     360{
     361    /* If progress-dialog is not yet ended but progress is aborted or completed: */
     362    if (!m_fEnded && (!m_comProgress.isOk() || m_comProgress.GetCompleted()))
     363    {
     364        /* Try to close the dialog: */
     365        closeProgressDialog();
     366    }
     367}
     368
    173369void UIProgressDialog::sltCancelOperation()
    174370{
     
    186382#endif
    187383
     384    /* Make sure dialog is handling window stack changes: */
     385    connect(&windowManager(), &UIModalWindowManager::sigStackChanged,
     386            this, &UIProgressDialog::sltHandleWindowStackChange);
     387
    188388    /* Prepare: */
     389    prepareEventHandler();
    189390    prepareWidgets();
     391}
     392
     393void UIProgressDialog::prepareEventHandler()
     394{
     395    if (!m_fLegacyHandling)
     396    {
     397        /* Create CProgress event handler: */
     398        m_pEventHandler = new UIProgressEventHandler(this, m_comProgress);
     399        connect(m_pEventHandler, &UIProgressEventHandler::sigProgressPercentageChange,
     400                this, &UIProgressDialog::sltHandleProgressPercentageChange);
     401        connect(m_pEventHandler, &UIProgressEventHandler::sigProgressTaskComplete,
     402                this, &UIProgressDialog::sltHandleProgressTaskComplete);
     403    }
    190404}
    191405
     
    311525}
    312526
     527void UIProgressDialog::cleanupEventHandler()
     528{
     529    if (!m_fLegacyHandling)
     530    {
     531        /* Destroy CProgress event handler: */
     532        delete m_pEventHandler;
     533        m_pEventHandler = 0;
     534    }
     535}
     536
    313537void UIProgressDialog::cleanup()
    314538{
     
    317541
    318542    /* Call the timer event handling delegate: */
    319     handleTimerEvent();
     543    if (m_fLegacyHandling)
     544        handleTimerEvent();
    320545
    321546    /* Cleanup: */
     547    cleanupEventHandler();
    322548    cleanupWidgets();
    323549}
     
    430656void UIProgressDialog::handleTimerEvent()
    431657{
     658    /* Old mode only: */
     659    AssertReturnVoid(m_fLegacyHandling);
     660
    432661    /* If progress-dialog is ended: */
    433662    if (m_fEnded)
     
    536765}
    537766
     767#include "UIProgressDialog.moc"
     768
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h

    r69004 r69006  
    2828class QILabel;
    2929class UIMiniCancelButton;
     30class UIProgressEventHandler;
    3031class CProgress;
    3132
     
    8687private slots:
    8788
     89    /** Handles percentage changed event for progress with @a strProgressId to @a iPercent. */
     90    void sltHandleProgressPercentageChange(QString strProgressId, int iPercent);
     91    /** Handles task completed event for progress with @a strProgressId. */
     92    void sltHandleProgressTaskComplete(QString strProgressId);
     93
     94    /** Handles window stack changed signal. */
     95    void sltHandleWindowStackChange();
     96
    8897    /** Handles request to cancel operation. */
    8998    void sltCancelOperation();
     
    93102    /** Prepares all. */
    94103    void prepare();
     104    /** Prepares event handler. */
     105    void prepareEventHandler();
    95106    /** Prepares widgets. */
    96107    void prepareWidgets();
    97108    /** Cleanups widgets. */
    98109    void cleanupWidgets();
     110    /** Cleanups event handler. */
     111    void cleanupEventHandler();
    99112    /** Cleanups all. */
    100113    void cleanup();
     
    119132    /** Holds the minimum duration before the progress-dialog is shown. */
    120133    int        m_cMinDuration;
     134
     135    /** Holds whether legacy handling is requested for this progress. */
     136    bool  m_fLegacyHandling;
    121137
    122138    /** Holds the image label instance. */
     
    140156    bool         m_fEnded;
    141157
     158    /** Holds the progress event handler instance. */
     159    UIProgressEventHandler *m_pEventHandler;
     160
    142161    /** Holds the operation description template. */
    143162    static const char *m_spcszOpDescTpl;
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