VirtualBox

Changeset 54928 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 24, 2015 4:35:25 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: Machine settings Serializer: Cleanup rework to prepare to the encryption settings integration (step 7): Settings save progress dialog initial implementation.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp

    r54923 r54928  
    166166    loadOwnData();
    167167
    168     /* Execute dialog and wait for completion: */
    169     if (exec() != QDialog::Accepted)
    170         return;
    171 
     168    /* Execute dialog: */
     169    exec();
     170}
     171
     172void UISettingsDialog::accept()
     173{
    172174    /* Save data: */
    173175    saveOwnData();
     176
     177    /* Call to base-class: */
     178    QIWithRetranslateUI<QIMainDialog>::accept();
    174179}
    175180
     
    245250
    246251    /* Create settings loader: */
    247     UISettingsSerializer *pSettingsLoader = new UISettingsSerializer(this,
    248                                                                      UISettingsSerializer::Load,
    249                                                                      QVariant::fromValue(data),
    250                                                                      m_pSelector->settingPages());
     252    UISettingsSerializer *pSettingsLoader = new UISettingsSerializer(this, UISettingsSerializer::Load,
     253                                                                     data, m_pSelector->settingPages());
    251254    AssertPtrReturnVoid(pSettingsLoader);
    252255    {
     
    271274
    272275    /* Create settings saver: */
    273     UISettingsSerializer *pSettingsSaver = new UISettingsSerializer(this,
    274                                                                     UISettingsSerializer::Save,
    275                                                                     QVariant::fromValue(data),
    276                                                                     m_pSelector->settingPages());
    277     AssertPtrReturnVoid(pSettingsSaver);
    278     {
     276    UISettingsSerializerProgress *pSettingsSaveProgress = new UISettingsSerializerProgress(this, UISettingsSerializer::Save,
     277                                                                                           data, m_pSelector->settingPages());
     278    AssertPtrReturnVoid(pSettingsSaveProgress);
     279    {
     280        /* Configure settings saver: */
     281        connect(pSettingsSaveProgress, SIGNAL(finished(int)), this, SLOT(sltMarkSaved()));
    279282        /* Start settings saver: */
    280         pSettingsSaver->start();
     283        pSettingsSaveProgress->exec();
    281284    }
    282285
    283286    /* Upload data finally: */
    284     data = pSettingsSaver->data();
     287    data = pSettingsSaveProgress->data();
    285288}
    286289
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r54921 r54928  
    5151
    5252protected slots:
     53
     54    /** Hides the modal dialog and sets the result code to Accepted. */
     55    virtual void accept();
    5356
    5457    /* Category-change slot: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

    r54922 r54928  
    235235    else if (!(newSettings == settings))
    236236        vboxGlobal().setSettings(newSettings);
    237 
    238     /* Mark page processed: */
    239     sltMarkSaved();
    240237}
    241238
     
    576573    if (!m_machine.isOk())
    577574        msgCenter().cannotSaveMachineSettings(m_machine, this);
    578 
    579     /* Mark page processed: */
    580     sltMarkSaved();
    581575}
    582576
     
    700694    UISettingsDialog::sltMarkLoaded();
    701695
    702     sltSetFirstRunFlag();
     696    /* No need to reset 'first run' flag: */
     697    m_fResetFirstRunFlag = false;
    703698
    704699    /* Unlock the session if exists: */
     
    794789{
    795790    m_fAllowResetFirstRunFlag = true;
    796 }
    797 
    798 void UISettingsDialogMachine::sltSetFirstRunFlag()
    799 {
    800     m_fResetFirstRunFlag = false;
    801791}
    802792
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h

    r54922 r54928  
    8686    void sltCategoryChanged(int cId);
    8787    void sltAllowResetFirstRunFlag();
    88     void sltSetFirstRunFlag();
    8988    void sltResetFirstRunFlag();
    9089
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSerializer.cpp

    r54923 r54928  
    4040
    4141    /* Copy the page(s) from incoming list to our map: */
    42     for (int iPageIndex = 0; iPageIndex < pages.size(); ++iPageIndex)
    43     {
    44         UISettingsPage *pPage = pages[iPageIndex];
     42    foreach (UISettingsPage *pPage, pages)
    4543        m_pages.insert(pPage->id(), pPage);
    46     }
    4744
    4845    /* Handling internal signals, they are also redirected in their handlers: */
     
    8986    /* Start async serializing thread: */
    9087    QThread::start(priority);
    91 
    92     /* If serializer saves settings: */
    93     if (m_direction == Save)
    94     {
    95         /* We should block calling thread until all pages will be saved: */
    96         while (!m_fSavingComplete)
    97         {
    98             /* Lock mutex initially: */
    99             m_mutex.lock();
    100             /* Perform idle-processing every 100ms,
    101              * and waiting for direct wake up signal: */
    102             m_condition.wait(&m_mutex, 100);
    103             /* Process queued signals posted to GUI thread: */
    104             qApp->processEvents();
    105             /* Unlock mutex finally: */
    106             m_mutex.unlock();
    107         }
    108     }
    10988}
    11089
     
    198177}
    199178
     179UISettingsSerializerProgress::UISettingsSerializerProgress(QWidget *pParent, UISettingsSerializer::SerializationDirection direction,
     180                                                           const QVariant &data, const UISettingsPageList &pages)
     181    : QIWithRetranslateUI<QProgressDialog>(pParent)
     182    , m_pSerializer(0)
     183    , m_direction(direction)
     184    , m_data(data)
     185    , m_pages(pages)
     186{
     187    /* Prepare: */
     188    prepare();
     189
     190    /* Translate: */
     191    retranslateUi();
     192}
     193
     194int UISettingsSerializerProgress::exec()
     195{
     196    /* Start the serializer: */
     197    m_pSerializer->start();
     198
     199    /* Call to base-class: */
     200    return QIWithRetranslateUI<QProgressDialog>::exec();
     201}
     202
     203QVariant& UISettingsSerializerProgress::data()
     204{
     205    AssertPtrReturn(m_pSerializer, m_data);
     206    return m_pSerializer->data();
     207}
     208
     209void UISettingsSerializerProgress::prepare()
     210{
     211    /* Create serializer: */
     212    m_pSerializer = new UISettingsSerializer(this, m_direction, m_data, m_pages);
     213    AssertPtrReturnVoid(m_pSerializer);
     214    {
     215        /* Install progress handler: */
     216        connect(m_pSerializer, SIGNAL(sigNotifyAboutPagePostprocessed(int)),
     217                this, SLOT(sltAdvanceProgressValue()));
     218        connect(m_pSerializer, SIGNAL(sigNotifyAboutPagesPostprocessed()),
     219                this, SLOT(sltAdvanceProgressValue()));
     220    }
     221
     222    /* Set maximum/minimum/current values: */
     223    setMaximum(m_pSerializer->pageCount() + 1);
     224    setMinimum(0);
     225    setValue(0);
     226}
     227
     228void UISettingsSerializerProgress::retranslateUi()
     229{
     230    /* Translate title: */
     231    switch (m_pSerializer->direction())
     232    {
     233        case UISettingsSerializer::Load: setLabelText(tr("Loading Settings...")); break;
     234        case UISettingsSerializer::Save: setLabelText(tr("Saving Settings...")); break;
     235    }
     236}
     237
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSerializer.h

    r54923 r54928  
    2222#include <QVariant>
    2323#include <QWaitCondition>
     24#include <QProgressDialog>
    2425#include <QMutex>
    2526#include <QList>
    2627#include <QMap>
     28
     29/* GUI includes: */
     30#include "QIWithRetranslateUI.h"
    2731
    2832/* Forward declarations: */
     
    7680    ~UISettingsSerializer();
    7781
     82    /** Returns the load/save direction. */
     83    SerializationDirection direction() const { return m_direction; }
     84
    7885    /** Returns the instance of wrapper(s) to load/save the data from/to. */
    7986    QVariant& data() { return m_data; }
     87
     88    /** Returns the count of the page(s) to load/save the data to/from. */
     89    int pageCount() const { return m_pages.size(); }
    8090
    8191    /** Raises the priority of page with @a iPageId. */
     
    103113    static UISettingsSerializer *m_spInstance;
    104114
    105     /** Holds the the load/save direction. */
    106     SerializationDirection m_direction;
     115    /** Holds the load/save direction. */
     116    const SerializationDirection m_direction;
    107117
    108118    /** Holds the wrapper(s) to load/save the data from/to. */
     
    121131};
    122132
     133/** QProgressDialog reimplementation used to
     134  * reflect the settings serialization operation. */
     135class UISettingsSerializerProgress : public QIWithRetranslateUI<QProgressDialog>
     136{
     137    Q_OBJECT;
     138
     139public:
     140
     141    /** Constructor.
     142      * @param pParent   being passed to the base-class,
     143      * @param direction determines the load/save direction,
     144      * @param data      contains the wrapper(s) to load/save the data from/to,
     145      * @param pages     contains the page(s) to load/save the data to/from. */
     146    UISettingsSerializerProgress(QWidget *pParent, UISettingsSerializer::SerializationDirection direction,
     147                                 const QVariant &data, const UISettingsPageList &pages);
     148
     149    /** Executes the dialog. */
     150    int exec();
     151
     152    /** Returns the instance of wrapper(s) to load/save the data from/to. */
     153    QVariant& data();
     154
     155protected:
     156
     157    /** Prepare routine. */
     158    void prepare();
     159
     160    /** Translate routine: */
     161    void retranslateUi();
     162
     163private slots:
     164
     165    /** Advances the current progress value. */
     166    void sltAdvanceProgressValue() { setValue(value() + 1); }
     167
     168private:
     169
     170    /** Holds the load/save direction. */
     171    const UISettingsSerializer::SerializationDirection m_direction;
     172
     173    /** Holds the wrapper(s) to load/save the data from/to. */
     174    QVariant m_data;
     175    /** Holds the page(s) to load/save the data to/from. */
     176    UISettingsPageList m_pages;
     177
     178    /** Holds the pointer to the thread loading/saving settings in async mode. */
     179    UISettingsSerializer *m_pSerializer;
     180};
     181
    123182#endif /* !___UISettingsSerializer_h___ */
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