Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp	(revision 54874)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp	(revision 54875)
@@ -76,12 +76,7 @@
 typedef QMap<int, UISettingsPage*> UISettingsPageMap;
 
-/* Serializer direction: */
-enum UISettingsSerializeDirection
-{
-    UISettingsSerializeDirection_Load,
-    UISettingsSerializeDirection_Save
-};
-
-/* QThread reimplementation for loading/saving settings in async mode: */
+/** QThread reimplementation used for
+  * loading/saving settings in async mode.
+  * @todo To be moved into the separate files! */
 class UISettingsSerializer : public QThread
 {
@@ -90,29 +85,44 @@
 signals:
 
-    /* Signal to notify main GUI thread about process has been started: */
+    /** Notifies GUI thread about process has been started. */
     void sigNotifyAboutProcessStarted();
 
-    /* Signal to notify main GUI thread about some page was processed: */
+    /** Notifies GUI thread about some page was processed. */
     void sigNotifyAboutPageProcessed(int iPageId);
 
-    /* Signal to notify main GUI thread about all pages were processed: */
+    /** Notifies GUI thread about all pages were processed. */
     void sigNotifyAboutPagesProcessed();
 
 public:
 
-    /* Settings serializer instance: */
-    static UISettingsSerializer* instance() { return m_pInstance; }
-
-    /* Settings serializer constructor: */
-    UISettingsSerializer(QObject *pParent, const QVariant &data, UISettingsSerializeDirection direction)
+    /** Serialization directions. */
+    enum SerializationDirection { Load, Save };
+
+    /** Returns the singleton instance. */
+    static UISettingsSerializer* instance() { return m_spInstance; }
+
+    /** Constructor.
+      * @param pParent   being passed to the base-class,
+      * @param direction determines the load/save direction,
+      * @param data      contains the wrapper(s) to load/save the data from/to,
+      * @param pages     contains the page(s) to load/save the data to/from. */
+    UISettingsSerializer(QObject *pParent, SerializationDirection direction,
+                         const QVariant &data, const UISettingsPageList &pages)
         : QThread(pParent)
         , m_direction(direction)
         , m_data(data)
-        , m_fSavingComplete(m_direction == UISettingsSerializeDirection_Load)
-        , m_fAllowToDestroySerializer(m_direction == UISettingsSerializeDirection_Load)
+        , m_fSavingComplete(m_direction == Load)
+        , m_fAllowToDestroySerializer(m_direction == Load)
         , m_iIdOfHighPriorityPage(-1)
     {
-        /* Set instance: */
-        m_pInstance = this;
+        /* Prepare instance: */
+        m_spInstance = this;
+
+        /* Copy the page(s) from incoming list to our map: */
+        for (int iPageIndex = 0; iPageIndex < pages.size(); ++iPageIndex)
+        {
+            UISettingsPage *pPage = pages[iPageIndex];
+            m_pages.insert(pPage->id(), pPage);
+        }
 
         /* Connecting this signals: */
@@ -125,5 +135,5 @@
     }
 
-    /* Settings serializer destructor: */
+    /** Destructor. */
     ~UISettingsSerializer()
     {
@@ -134,39 +144,23 @@
             wait();
 
-        /* Clear instance: */
-        m_pInstance = 0;
-    }
-
-    /* Set pages list: */
-    void setPageList(const UISettingsPageList &pageList)
-    {
-        for (int iPageIndex = 0; iPageIndex < pageList.size(); ++iPageIndex)
-        {
-            UISettingsPage *pPage = pageList[iPageIndex];
-            m_pages.insert(pPage->id(), pPage);
-        }
-    }
-
-    /* Raise priority of page: */
+        /* Cleanup instance: */
+        m_spInstance = 0;
+    }
+
+    /** Returns the instance of wrapper(s) to load/save the data from/to. */
+    QVariant& data() { return m_data; }
+
+    /** Raises the priority of page with @a iPageId. */
     void raisePriorityOfPage(int iPageId)
     {
-        /* If that page is not present or was processed already: */
-        if (!m_pages.contains(iPageId) || m_pages[iPageId]->processed())
-        {
-            /* We just ignoring that request: */
-            return;
-        }
-        else
-        {
-            /* Else remember which page we should be processed next: */
+        /* If that page is present and was not processed already =>
+         * we should remember which page should be processed next: */
+        if (m_pages.contains(iPageId) && !(m_pages[iPageId]->processed()))
             m_iIdOfHighPriorityPage = iPageId;
-        }
-    }
-
-    /* Return current m_data content: */
-    QVariant& data() { return m_data; }
+    }
 
 public slots:
 
+    /** Starts the process of data loading with passed @a priority. */
     void start(Priority priority = InheritPriority)
     {
@@ -175,9 +169,9 @@
 
         /* If serializer saves settings: */
-        if (m_direction == UISettingsSerializeDirection_Save)
+        if (m_direction == Save)
         {
             /* We should update internal page cache first: */
-            for (int iPageIndex = 0; iPageIndex < m_pages.values().size(); ++iPageIndex)
-                m_pages.values()[iPageIndex]->putToCache();
+            foreach (UISettingsPage *pPage, m_pages.values())
+                pPage->putToCache();
         }
 
@@ -186,5 +180,5 @@
 
         /* If serializer saves settings: */
-        if (m_direction == UISettingsSerializeDirection_Save)
+        if (m_direction == Save)
         {
             /* We should block calling thread until all pages will be saved: */
@@ -201,4 +195,5 @@
                 m_mutex.unlock();
             }
+            /* Allow to destroy serializer finally: */
             m_fAllowToDestroySerializer = true;
         }
@@ -207,13 +202,14 @@
 protected slots:
 
-    /* Slot to handle the fact of some page was processed: */
+    /** Handles the fact of some page was processed. */
     void sltHandleProcessedPage(int iPageId)
     {
         /* If serializer loads settings: */
-        if (m_direction == UISettingsSerializeDirection_Load)
-        {
-            /* If such page present we should fetch internal page cache: */
+        if (m_direction == Load)
+        {
+            /* If such page present: */
             if (m_pages.contains(iPageId))
             {
+                /* We should fetch internal page cache: */
                 UISettingsPage *pSettingsPage = m_pages[iPageId];
                 pSettingsPage->setValidatorBlocked(true);
@@ -224,9 +220,9 @@
     }
 
-    /* Slot to handle the fact of all pages were processed: */
+    /** Handles the fact of all pages were processed. */
     void sltHandleProcessedPages()
     {
         /* If serializer saves settings: */
-        if (m_direction == UISettingsSerializeDirection_Save)
+        if (m_direction == Save)
         {
             /* We should flag GUI thread to unlock itself: */
@@ -243,5 +239,5 @@
     }
 
-    /* Slot to destroy serializer: */
+    /** Killing serializer, softly :) */
     void sltDestroySerializer()
     {
@@ -256,5 +252,5 @@
 protected:
 
-    /* Settings processor: */
+    /** Settings serializer. */
     void run()
     {
@@ -263,7 +259,6 @@
 
         /* Mark all the pages initially as NOT processed: */
-        QList<UISettingsPage*> pageList = m_pages.values();
-        for (int iPageNumber = 0; iPageNumber < pageList.size(); ++iPageNumber)
-            pageList[iPageNumber]->setProcessed(false);
+        foreach (UISettingsPage *pPage, m_pages.values())
+            pPage->setProcessed(false);
 
         /* Iterate over the all left settings pages: */
@@ -273,5 +268,5 @@
             /* Get required page pointer, protect map by mutex while getting pointer: */
             UISettingsPage *pPage = m_iIdOfHighPriorityPage != -1 && pages.contains(m_iIdOfHighPriorityPage) ?
-                                    pages[m_iIdOfHighPriorityPage] : *pages.begin();
+                                    pages.value(m_iIdOfHighPriorityPage) : *pages.begin();
             /* Reset request of high priority: */
             if (m_iIdOfHighPriorityPage != -1)
@@ -280,7 +275,7 @@
             if (pPage->isEnabled())
             {
-                if (m_direction == UISettingsSerializeDirection_Load)
+                if (m_direction == Load)
                     pPage->loadToCacheFrom(m_data);
-                if (m_direction == UISettingsSerializeDirection_Save)
+                if (m_direction == Save)
                     pPage->saveFromCacheTo(m_data);
             }
@@ -292,5 +287,5 @@
             emit sigNotifyAboutPageProcessed(pPage->id());
             /* If serializer saves settings => wake up GUI thread: */
-            if (m_direction == UISettingsSerializeDirection_Save)
+            if (m_direction == Save)
                 m_condition.wakeAll();
             /* Break further processing if page had failed: */
@@ -301,5 +296,5 @@
         emit sigNotifyAboutPagesProcessed();
         /* If serializer saves settings => wake up GUI thread: */
-        if (m_direction == UISettingsSerializeDirection_Save)
+        if (m_direction == Save)
             m_condition.wakeAll();
 
@@ -308,17 +303,28 @@
     }
 
-    /* Variables: */
-    UISettingsSerializeDirection m_direction;
+    /** Holds the singleton instance. */
+    static UISettingsSerializer *m_spInstance;
+
+    /** Holds the the load/save direction. */
+    SerializationDirection m_direction;
+
+    /** Holds the wrapper(s) to load/save the data from/to. */
     QVariant m_data;
+    /** Holds the page(s) to load/save the data to/from. */
     UISettingsPageMap m_pages;
+
+    /** Holds whether the save was complete. */
     bool m_fSavingComplete;
+    /** Holds whether it is allowed to destroy the serializer. */
     bool m_fAllowToDestroySerializer;
+    /** Holds the ID of the high priority page. */
     int m_iIdOfHighPriorityPage;
+    /** Holds the synchronization mutex. */
     QMutex m_mutex;
+    /** Holds the synchronization condition. */
     QWaitCondition m_condition;
-    static UISettingsSerializer *m_pInstance;
 };
 
-UISettingsSerializer* UISettingsSerializer::m_pInstance = 0;
+UISettingsSerializer* UISettingsSerializer::m_spInstance = 0;
 
 UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent,
@@ -477,8 +483,9 @@
     /* Create global settings loader,
      * it will load global settings & delete itself in the appropriate time: */
-    UISettingsSerializer *pGlobalSettingsLoader = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Load);
+    UISettingsSerializer *pGlobalSettingsLoader = new UISettingsSerializer(this,
+                                                                           UISettingsSerializer::Load,
+                                                                           QVariant::fromValue(data),
+                                                                           m_pSelector->settingPages());
     connect(pGlobalSettingsLoader, SIGNAL(destroyed(QObject*)), this, SLOT(sltMarkLoaded()));
-    /* Set pages to be loaded: */
-    pGlobalSettingsLoader->setPageList(m_pSelector->settingPages());
     /* Start loader: */
     pGlobalSettingsLoader->start();
@@ -498,7 +505,8 @@
     /* Create global settings saver,
      * it will save global settings & delete itself in the appropriate time: */
-    UISettingsSerializer *pGlobalSettingsSaver = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Save);
-    /* Set pages to be saved: */
-    pGlobalSettingsSaver->setPageList(m_pSelector->settingPages());
+    UISettingsSerializer *pGlobalSettingsSaver = new UISettingsSerializer(this,
+                                                                          UISettingsSerializer::Save,
+                                                                          QVariant::fromValue(data),
+                                                                          m_pSelector->settingPages());
     /* Start saver: */
     pGlobalSettingsSaver->start();
@@ -792,9 +800,10 @@
     /* Create machine settings loader,
      * it will load machine settings & delete itself in the appropriate time: */
-    UISettingsSerializer *pMachineSettingsLoader = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Load);
+    UISettingsSerializer *pMachineSettingsLoader = new UISettingsSerializer(this,
+                                                                            UISettingsSerializer::Load,
+                                                                            QVariant::fromValue(data),
+                                                                            m_pSelector->settingPages());
     connect(pMachineSettingsLoader, SIGNAL(destroyed(QObject*)), this, SLOT(sltMarkLoaded()));
     connect(pMachineSettingsLoader, SIGNAL(sigNotifyAboutPagesProcessed()), this, SLOT(sltSetFirstRunFlag()));
-    /* Set pages to be loaded: */
-    pMachineSettingsLoader->setPageList(m_pSelector->settingPages());
     /* Ask to raise required page priority: */
     pMachineSettingsLoader->raisePriorityOfPage(m_pSelector->currentId());
@@ -836,7 +845,8 @@
     /* Create machine settings saver,
      * it will save machine settings & delete itself in the appropriate time: */
-    UISettingsSerializer *pMachineSettingsSaver = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Save);
-    /* Set pages to be saved: */
-    pMachineSettingsSaver->setPageList(m_pSelector->settingPages());
+    UISettingsSerializer *pMachineSettingsSaver = new UISettingsSerializer(this,
+                                                                           UISettingsSerializer::Save,
+                                                                           QVariant::fromValue(data),
+                                                                           m_pSelector->settingPages());
     /* Start saver: */
     pMachineSettingsSaver->start();
