VirtualBox

Changeset 54875 in vbox


Ignore:
Timestamp:
Mar 20, 2015 3:31:09 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99090
Message:

FE/Qt: Machine settings Serializer: Cleanup rework to prepare to the encryption settings integration (step 1).

File:
1 edited

Legend:

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

    r54228 r54875  
    7676typedef QMap<int, UISettingsPage*> UISettingsPageMap;
    7777
    78 /* Serializer direction: */
    79 enum UISettingsSerializeDirection
    80 {
    81     UISettingsSerializeDirection_Load,
    82     UISettingsSerializeDirection_Save
    83 };
    84 
    85 /* QThread reimplementation for loading/saving settings in async mode: */
     78/** QThread reimplementation used for
     79  * loading/saving settings in async mode.
     80  * @todo To be moved into the separate files! */
    8681class UISettingsSerializer : public QThread
    8782{
     
    9085signals:
    9186
    92     /* Signal to notify main GUI thread about process has been started: */
     87    /** Notifies GUI thread about process has been started. */
    9388    void sigNotifyAboutProcessStarted();
    9489
    95     /* Signal to notify main GUI thread about some page was processed: */
     90    /** Notifies GUI thread about some page was processed. */
    9691    void sigNotifyAboutPageProcessed(int iPageId);
    9792
    98     /* Signal to notify main GUI thread about all pages were processed: */
     93    /** Notifies GUI thread about all pages were processed. */
    9994    void sigNotifyAboutPagesProcessed();
    10095
    10196public:
    10297
    103     /* Settings serializer instance: */
    104     static UISettingsSerializer* instance() { return m_pInstance; }
    105 
    106     /* Settings serializer constructor: */
    107     UISettingsSerializer(QObject *pParent, const QVariant &data, UISettingsSerializeDirection direction)
     98    /** Serialization directions. */
     99    enum SerializationDirection { Load, Save };
     100
     101    /** Returns the singleton instance. */
     102    static UISettingsSerializer* instance() { return m_spInstance; }
     103
     104    /** Constructor.
     105      * @param pParent   being passed to the base-class,
     106      * @param direction determines the load/save direction,
     107      * @param data      contains the wrapper(s) to load/save the data from/to,
     108      * @param pages     contains the page(s) to load/save the data to/from. */
     109    UISettingsSerializer(QObject *pParent, SerializationDirection direction,
     110                         const QVariant &data, const UISettingsPageList &pages)
    108111        : QThread(pParent)
    109112        , m_direction(direction)
    110113        , m_data(data)
    111         , m_fSavingComplete(m_direction == UISettingsSerializeDirection_Load)
    112         , m_fAllowToDestroySerializer(m_direction == UISettingsSerializeDirection_Load)
     114        , m_fSavingComplete(m_direction == Load)
     115        , m_fAllowToDestroySerializer(m_direction == Load)
    113116        , m_iIdOfHighPriorityPage(-1)
    114117    {
    115         /* Set instance: */
    116         m_pInstance = this;
     118        /* Prepare instance: */
     119        m_spInstance = this;
     120
     121        /* Copy the page(s) from incoming list to our map: */
     122        for (int iPageIndex = 0; iPageIndex < pages.size(); ++iPageIndex)
     123        {
     124            UISettingsPage *pPage = pages[iPageIndex];
     125            m_pages.insert(pPage->id(), pPage);
     126        }
    117127
    118128        /* Connecting this signals: */
     
    125135    }
    126136
    127     /* Settings serializer destructor: */
     137    /** Destructor. */
    128138    ~UISettingsSerializer()
    129139    {
     
    134144            wait();
    135145
    136         /* Clear instance: */
    137         m_pInstance = 0;
    138     }
    139 
    140     /* Set pages list: */
    141     void setPageList(const UISettingsPageList &pageList)
    142     {
    143         for (int iPageIndex = 0; iPageIndex < pageList.size(); ++iPageIndex)
    144         {
    145             UISettingsPage *pPage = pageList[iPageIndex];
    146             m_pages.insert(pPage->id(), pPage);
    147         }
    148     }
    149 
    150     /* Raise priority of page: */
     146        /* Cleanup instance: */
     147        m_spInstance = 0;
     148    }
     149
     150    /** Returns the instance of wrapper(s) to load/save the data from/to. */
     151    QVariant& data() { return m_data; }
     152
     153    /** Raises the priority of page with @a iPageId. */
    151154    void raisePriorityOfPage(int iPageId)
    152155    {
    153         /* If that page is not present or was processed already: */
    154         if (!m_pages.contains(iPageId) || m_pages[iPageId]->processed())
    155         {
    156             /* We just ignoring that request: */
    157             return;
    158         }
    159         else
    160         {
    161             /* Else remember which page we should be processed next: */
     156        /* If that page is present and was not processed already =>
     157         * we should remember which page should be processed next: */
     158        if (m_pages.contains(iPageId) && !(m_pages[iPageId]->processed()))
    162159            m_iIdOfHighPriorityPage = iPageId;
    163         }
    164     }
    165 
    166     /* Return current m_data content: */
    167     QVariant& data() { return m_data; }
     160    }
    168161
    169162public slots:
    170163
     164    /** Starts the process of data loading with passed @a priority. */
    171165    void start(Priority priority = InheritPriority)
    172166    {
     
    175169
    176170        /* If serializer saves settings: */
    177         if (m_direction == UISettingsSerializeDirection_Save)
     171        if (m_direction == Save)
    178172        {
    179173            /* We should update internal page cache first: */
    180             for (int iPageIndex = 0; iPageIndex < m_pages.values().size(); ++iPageIndex)
    181                 m_pages.values()[iPageIndex]->putToCache();
     174            foreach (UISettingsPage *pPage, m_pages.values())
     175                pPage->putToCache();
    182176        }
    183177
     
    186180
    187181        /* If serializer saves settings: */
    188         if (m_direction == UISettingsSerializeDirection_Save)
     182        if (m_direction == Save)
    189183        {
    190184            /* We should block calling thread until all pages will be saved: */
     
    201195                m_mutex.unlock();
    202196            }
     197            /* Allow to destroy serializer finally: */
    203198            m_fAllowToDestroySerializer = true;
    204199        }
     
    207202protected slots:
    208203
    209     /* Slot to handle the fact of some page was processed: */
     204    /** Handles the fact of some page was processed. */
    210205    void sltHandleProcessedPage(int iPageId)
    211206    {
    212207        /* If serializer loads settings: */
    213         if (m_direction == UISettingsSerializeDirection_Load)
    214         {
    215             /* If such page present we should fetch internal page cache: */
     208        if (m_direction == Load)
     209        {
     210            /* If such page present: */
    216211            if (m_pages.contains(iPageId))
    217212            {
     213                /* We should fetch internal page cache: */
    218214                UISettingsPage *pSettingsPage = m_pages[iPageId];
    219215                pSettingsPage->setValidatorBlocked(true);
     
    224220    }
    225221
    226     /* Slot to handle the fact of all pages were processed: */
     222    /** Handles the fact of all pages were processed. */
    227223    void sltHandleProcessedPages()
    228224    {
    229225        /* If serializer saves settings: */
    230         if (m_direction == UISettingsSerializeDirection_Save)
     226        if (m_direction == Save)
    231227        {
    232228            /* We should flag GUI thread to unlock itself: */
     
    243239    }
    244240
    245     /* Slot to destroy serializer: */
     241    /** Killing serializer, softly :) */
    246242    void sltDestroySerializer()
    247243    {
     
    256252protected:
    257253
    258     /* Settings processor: */
     254    /** Settings serializer. */
    259255    void run()
    260256    {
     
    263259
    264260        /* Mark all the pages initially as NOT processed: */
    265         QList<UISettingsPage*> pageList = m_pages.values();
    266         for (int iPageNumber = 0; iPageNumber < pageList.size(); ++iPageNumber)
    267             pageList[iPageNumber]->setProcessed(false);
     261        foreach (UISettingsPage *pPage, m_pages.values())
     262            pPage->setProcessed(false);
    268263
    269264        /* Iterate over the all left settings pages: */
     
    273268            /* Get required page pointer, protect map by mutex while getting pointer: */
    274269            UISettingsPage *pPage = m_iIdOfHighPriorityPage != -1 && pages.contains(m_iIdOfHighPriorityPage) ?
    275                                     pages[m_iIdOfHighPriorityPage] : *pages.begin();
     270                                    pages.value(m_iIdOfHighPriorityPage) : *pages.begin();
    276271            /* Reset request of high priority: */
    277272            if (m_iIdOfHighPriorityPage != -1)
     
    280275            if (pPage->isEnabled())
    281276            {
    282                 if (m_direction == UISettingsSerializeDirection_Load)
     277                if (m_direction == Load)
    283278                    pPage->loadToCacheFrom(m_data);
    284                 if (m_direction == UISettingsSerializeDirection_Save)
     279                if (m_direction == Save)
    285280                    pPage->saveFromCacheTo(m_data);
    286281            }
     
    292287            emit sigNotifyAboutPageProcessed(pPage->id());
    293288            /* If serializer saves settings => wake up GUI thread: */
    294             if (m_direction == UISettingsSerializeDirection_Save)
     289            if (m_direction == Save)
    295290                m_condition.wakeAll();
    296291            /* Break further processing if page had failed: */
     
    301296        emit sigNotifyAboutPagesProcessed();
    302297        /* If serializer saves settings => wake up GUI thread: */
    303         if (m_direction == UISettingsSerializeDirection_Save)
     298        if (m_direction == Save)
    304299            m_condition.wakeAll();
    305300
     
    308303    }
    309304
    310     /* Variables: */
    311     UISettingsSerializeDirection m_direction;
     305    /** Holds the singleton instance. */
     306    static UISettingsSerializer *m_spInstance;
     307
     308    /** Holds the the load/save direction. */
     309    SerializationDirection m_direction;
     310
     311    /** Holds the wrapper(s) to load/save the data from/to. */
    312312    QVariant m_data;
     313    /** Holds the page(s) to load/save the data to/from. */
    313314    UISettingsPageMap m_pages;
     315
     316    /** Holds whether the save was complete. */
    314317    bool m_fSavingComplete;
     318    /** Holds whether it is allowed to destroy the serializer. */
    315319    bool m_fAllowToDestroySerializer;
     320    /** Holds the ID of the high priority page. */
    316321    int m_iIdOfHighPriorityPage;
     322    /** Holds the synchronization mutex. */
    317323    QMutex m_mutex;
     324    /** Holds the synchronization condition. */
    318325    QWaitCondition m_condition;
    319     static UISettingsSerializer *m_pInstance;
    320326};
    321327
    322 UISettingsSerializer* UISettingsSerializer::m_pInstance = 0;
     328UISettingsSerializer* UISettingsSerializer::m_spInstance = 0;
    323329
    324330UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent,
     
    477483    /* Create global settings loader,
    478484     * it will load global settings & delete itself in the appropriate time: */
    479     UISettingsSerializer *pGlobalSettingsLoader = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Load);
     485    UISettingsSerializer *pGlobalSettingsLoader = new UISettingsSerializer(this,
     486                                                                           UISettingsSerializer::Load,
     487                                                                           QVariant::fromValue(data),
     488                                                                           m_pSelector->settingPages());
    480489    connect(pGlobalSettingsLoader, SIGNAL(destroyed(QObject*)), this, SLOT(sltMarkLoaded()));
    481     /* Set pages to be loaded: */
    482     pGlobalSettingsLoader->setPageList(m_pSelector->settingPages());
    483490    /* Start loader: */
    484491    pGlobalSettingsLoader->start();
     
    498505    /* Create global settings saver,
    499506     * it will save global settings & delete itself in the appropriate time: */
    500     UISettingsSerializer *pGlobalSettingsSaver = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Save);
    501     /* Set pages to be saved: */
    502     pGlobalSettingsSaver->setPageList(m_pSelector->settingPages());
     507    UISettingsSerializer *pGlobalSettingsSaver = new UISettingsSerializer(this,
     508                                                                          UISettingsSerializer::Save,
     509                                                                          QVariant::fromValue(data),
     510                                                                          m_pSelector->settingPages());
    503511    /* Start saver: */
    504512    pGlobalSettingsSaver->start();
     
    792800    /* Create machine settings loader,
    793801     * it will load machine settings & delete itself in the appropriate time: */
    794     UISettingsSerializer *pMachineSettingsLoader = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Load);
     802    UISettingsSerializer *pMachineSettingsLoader = new UISettingsSerializer(this,
     803                                                                            UISettingsSerializer::Load,
     804                                                                            QVariant::fromValue(data),
     805                                                                            m_pSelector->settingPages());
    795806    connect(pMachineSettingsLoader, SIGNAL(destroyed(QObject*)), this, SLOT(sltMarkLoaded()));
    796807    connect(pMachineSettingsLoader, SIGNAL(sigNotifyAboutPagesProcessed()), this, SLOT(sltSetFirstRunFlag()));
    797     /* Set pages to be loaded: */
    798     pMachineSettingsLoader->setPageList(m_pSelector->settingPages());
    799808    /* Ask to raise required page priority: */
    800809    pMachineSettingsLoader->raisePriorityOfPage(m_pSelector->currentId());
     
    836845    /* Create machine settings saver,
    837846     * it will save machine settings & delete itself in the appropriate time: */
    838     UISettingsSerializer *pMachineSettingsSaver = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Save);
    839     /* Set pages to be saved: */
    840     pMachineSettingsSaver->setPageList(m_pSelector->settingPages());
     847    UISettingsSerializer *pMachineSettingsSaver = new UISettingsSerializer(this,
     848                                                                           UISettingsSerializer::Save,
     849                                                                           QVariant::fromValue(data),
     850                                                                           m_pSelector->settingPages());
    841851    /* Start saver: */
    842852    pMachineSettingsSaver->start();
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