Changeset 54875 in vbox
- Timestamp:
- Mar 20, 2015 3:31:09 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 99090
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp
r54228 r54875 76 76 typedef QMap<int, UISettingsPage*> UISettingsPageMap; 77 77 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! */ 86 81 class UISettingsSerializer : public QThread 87 82 { … … 90 85 signals: 91 86 92 /* Signal to notify main GUI thread about process has been started:*/87 /** Notifies GUI thread about process has been started. */ 93 88 void sigNotifyAboutProcessStarted(); 94 89 95 /* Signal to notify main GUI thread about some page was processed:*/90 /** Notifies GUI thread about some page was processed. */ 96 91 void sigNotifyAboutPageProcessed(int iPageId); 97 92 98 /* Signal to notify main GUI thread about all pages were processed:*/93 /** Notifies GUI thread about all pages were processed. */ 99 94 void sigNotifyAboutPagesProcessed(); 100 95 101 96 public: 102 97 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) 108 111 : QThread(pParent) 109 112 , m_direction(direction) 110 113 , 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) 113 116 , m_iIdOfHighPriorityPage(-1) 114 117 { 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 } 117 127 118 128 /* Connecting this signals: */ … … 125 135 } 126 136 127 /* Settings serializer destructor:*/137 /** Destructor. */ 128 138 ~UISettingsSerializer() 129 139 { … … 134 144 wait(); 135 145 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. */ 151 154 void raisePriorityOfPage(int iPageId) 152 155 { 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())) 162 159 m_iIdOfHighPriorityPage = iPageId; 163 } 164 } 165 166 /* Return current m_data content: */ 167 QVariant& data() { return m_data; } 160 } 168 161 169 162 public slots: 170 163 164 /** Starts the process of data loading with passed @a priority. */ 171 165 void start(Priority priority = InheritPriority) 172 166 { … … 175 169 176 170 /* If serializer saves settings: */ 177 if (m_direction == UISettingsSerializeDirection_Save)171 if (m_direction == Save) 178 172 { 179 173 /* 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(); 182 176 } 183 177 … … 186 180 187 181 /* If serializer saves settings: */ 188 if (m_direction == UISettingsSerializeDirection_Save)182 if (m_direction == Save) 189 183 { 190 184 /* We should block calling thread until all pages will be saved: */ … … 201 195 m_mutex.unlock(); 202 196 } 197 /* Allow to destroy serializer finally: */ 203 198 m_fAllowToDestroySerializer = true; 204 199 } … … 207 202 protected slots: 208 203 209 /* Slot to handle the fact of some page was processed:*/204 /** Handles the fact of some page was processed. */ 210 205 void sltHandleProcessedPage(int iPageId) 211 206 { 212 207 /* 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: */ 216 211 if (m_pages.contains(iPageId)) 217 212 { 213 /* We should fetch internal page cache: */ 218 214 UISettingsPage *pSettingsPage = m_pages[iPageId]; 219 215 pSettingsPage->setValidatorBlocked(true); … … 224 220 } 225 221 226 /* Slot to handle the fact of all pages were processed:*/222 /** Handles the fact of all pages were processed. */ 227 223 void sltHandleProcessedPages() 228 224 { 229 225 /* If serializer saves settings: */ 230 if (m_direction == UISettingsSerializeDirection_Save)226 if (m_direction == Save) 231 227 { 232 228 /* We should flag GUI thread to unlock itself: */ … … 243 239 } 244 240 245 /* Slot to destroy serializer:*/241 /** Killing serializer, softly :) */ 246 242 void sltDestroySerializer() 247 243 { … … 256 252 protected: 257 253 258 /* Settings processor:*/254 /** Settings serializer. */ 259 255 void run() 260 256 { … … 263 259 264 260 /* 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); 268 263 269 264 /* Iterate over the all left settings pages: */ … … 273 268 /* Get required page pointer, protect map by mutex while getting pointer: */ 274 269 UISettingsPage *pPage = m_iIdOfHighPriorityPage != -1 && pages.contains(m_iIdOfHighPriorityPage) ? 275 pages [m_iIdOfHighPriorityPage]: *pages.begin();270 pages.value(m_iIdOfHighPriorityPage) : *pages.begin(); 276 271 /* Reset request of high priority: */ 277 272 if (m_iIdOfHighPriorityPage != -1) … … 280 275 if (pPage->isEnabled()) 281 276 { 282 if (m_direction == UISettingsSerializeDirection_Load)277 if (m_direction == Load) 283 278 pPage->loadToCacheFrom(m_data); 284 if (m_direction == UISettingsSerializeDirection_Save)279 if (m_direction == Save) 285 280 pPage->saveFromCacheTo(m_data); 286 281 } … … 292 287 emit sigNotifyAboutPageProcessed(pPage->id()); 293 288 /* If serializer saves settings => wake up GUI thread: */ 294 if (m_direction == UISettingsSerializeDirection_Save)289 if (m_direction == Save) 295 290 m_condition.wakeAll(); 296 291 /* Break further processing if page had failed: */ … … 301 296 emit sigNotifyAboutPagesProcessed(); 302 297 /* If serializer saves settings => wake up GUI thread: */ 303 if (m_direction == UISettingsSerializeDirection_Save)298 if (m_direction == Save) 304 299 m_condition.wakeAll(); 305 300 … … 308 303 } 309 304 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. */ 312 312 QVariant m_data; 313 /** Holds the page(s) to load/save the data to/from. */ 313 314 UISettingsPageMap m_pages; 315 316 /** Holds whether the save was complete. */ 314 317 bool m_fSavingComplete; 318 /** Holds whether it is allowed to destroy the serializer. */ 315 319 bool m_fAllowToDestroySerializer; 320 /** Holds the ID of the high priority page. */ 316 321 int m_iIdOfHighPriorityPage; 322 /** Holds the synchronization mutex. */ 317 323 QMutex m_mutex; 324 /** Holds the synchronization condition. */ 318 325 QWaitCondition m_condition; 319 static UISettingsSerializer *m_pInstance;320 326 }; 321 327 322 UISettingsSerializer* UISettingsSerializer::m_ pInstance = 0;328 UISettingsSerializer* UISettingsSerializer::m_spInstance = 0; 323 329 324 330 UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent, … … 477 483 /* Create global settings loader, 478 484 * 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()); 480 489 connect(pGlobalSettingsLoader, SIGNAL(destroyed(QObject*)), this, SLOT(sltMarkLoaded())); 481 /* Set pages to be loaded: */482 pGlobalSettingsLoader->setPageList(m_pSelector->settingPages());483 490 /* Start loader: */ 484 491 pGlobalSettingsLoader->start(); … … 498 505 /* Create global settings saver, 499 506 * 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()); 503 511 /* Start saver: */ 504 512 pGlobalSettingsSaver->start(); … … 792 800 /* Create machine settings loader, 793 801 * 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()); 795 806 connect(pMachineSettingsLoader, SIGNAL(destroyed(QObject*)), this, SLOT(sltMarkLoaded())); 796 807 connect(pMachineSettingsLoader, SIGNAL(sigNotifyAboutPagesProcessed()), this, SLOT(sltSetFirstRunFlag())); 797 /* Set pages to be loaded: */798 pMachineSettingsLoader->setPageList(m_pSelector->settingPages());799 808 /* Ask to raise required page priority: */ 800 809 pMachineSettingsLoader->raisePriorityOfPage(m_pSelector->currentId()); … … 836 845 /* Create machine settings saver, 837 846 * 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()); 841 851 /* Start saver: */ 842 852 pMachineSettingsSaver->start();
Note:
See TracChangeset
for help on using the changeset viewer.