Changeset 66453 in vbox
- Timestamp:
- Apr 6, 2017 9:10:34 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp
r66451 r66453 295 295 m_pCache->clear(); 296 296 297 /* Get actual shared folders: */ 297 /* Prepare old folders data: */ 298 UIDataSettingsSharedFolders oldFoldersData; 299 300 /* Get actual folders: */ 298 301 QMap<UISharedFolderType, CSharedFolder> folders; 299 /* Load machine (permanent) sharedfolders if allowed: */302 /* Load machine (permanent) folders if allowed: */ 300 303 if (isSharedFolderTypeSupported(MachineType)) 301 304 foreach (const CSharedFolder &folder, getSharedFolders(MachineType)) 302 305 folders.insertMulti(MachineType, folder); 303 /* Load console (temporary) sharedfolders if allowed: */306 /* Load console (temporary) folders if allowed: */ 304 307 if (isSharedFolderTypeSupported(ConsoleType)) 305 308 foreach (const CSharedFolder &folder, getSharedFolders(ConsoleType)) 306 309 folders.insertMulti(ConsoleType, folder); 307 310 308 /* For each sharedfolder type: */311 /* For each folder type: */ 309 312 foreach (const UISharedFolderType &enmFolderType, folders.keys()) 310 313 { 311 /* For each sharedfolder of current type: */314 /* For each folder of current type: */ 312 315 const QList<CSharedFolder> ¤tTypeFolders = folders.values(enmFolderType); 313 316 for (int iFolderIndex = 0; iFolderIndex < currentTypeFolders.size(); ++iFolderIndex) 314 317 { 315 /* Prepare cache key & data: */318 /* Prepare old folder data & cache key: */ 316 319 QString strFolderKey = QString::number(iFolderIndex); 317 UIDataSettingsSharedFolder initialFolderData;318 319 /* Check if shared folder exists: */320 const CSharedFolder & folder = currentTypeFolders.at(iFolderIndex);321 if (! folder.isNull())320 UIDataSettingsSharedFolder oldFolderData; 321 322 /* Check whether folder is valid: */ 323 const CSharedFolder &comFolder = currentTypeFolders.at(iFolderIndex); 324 if (!comFolder.isNull()) 322 325 { 323 /* Gather shared folder values: */324 initialFolderData.m_enmType = enmFolderType;325 initialFolderData.m_strName = folder.GetName();326 initialFolderData.m_strPath = folder.GetHostPath();327 initialFolderData.m_fAutoMount = folder.GetAutoMount();328 initialFolderData.m_fWritable = folder.GetWritable();329 /* Override sharedfolder cache key: */330 strFolderKey = initialFolderData.m_strName;326 /* Gather old folder data: */ 327 oldFolderData.m_enmType = enmFolderType; 328 oldFolderData.m_strName = comFolder.GetName(); 329 oldFolderData.m_strPath = comFolder.GetHostPath(); 330 oldFolderData.m_fAutoMount = comFolder.GetAutoMount(); 331 oldFolderData.m_fWritable = comFolder.GetWritable(); 332 /* Override folder cache key: */ 333 strFolderKey = oldFolderData.m_strName; 331 334 } 332 335 333 /* Cache initial shared folder data: */ 334 m_pCache->child(strFolderKey).cacheInitialData(initialFolderData); 335 } 336 } 336 /* Cache old folder data: */ 337 m_pCache->child(strFolderKey).cacheInitialData(oldFolderData); 338 } 339 } 340 341 /* Cache old folders data: */ 342 m_pCache->cacheInitialData(oldFoldersData); 337 343 338 344 /* Upload machine to data: */ … … 348 354 updateRootItemsVisibility(); 349 355 350 /* For each shared folder: */356 /* For each folder => load it to the page: */ 351 357 for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex) 352 358 addSharedFolderItem(m_pCache->child(iFolderIndex).base(), false /* its new? */); 353 359 354 /* Ensure current item fetched: */360 /* Choose first folder as current: */ 355 361 mTwFolders->setCurrentItem(mTwFolders->topLevelItem(0)); 356 362 sltHandleCurrentItemChange(mTwFolders->currentItem()); … … 362 368 void UIMachineSettingsSF::putToCache() 363 369 { 364 /* For each shared folder type: */ 370 /* Prepare new folders data: */ 371 UIDataSettingsSharedFolders newFoldersData; 372 373 /* For each folder type: */ 365 374 QTreeWidgetItem *pMainRootItem = mTwFolders->invisibleRootItem(); 366 375 for (int iFolderTypeIndex = 0; iFolderTypeIndex < pMainRootItem->childCount(); ++iFolderTypeIndex) 367 376 { 368 /* Get sharedfolder root item: */377 /* Get folder root item: */ 369 378 const SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex)); 370 379 371 /* For each sharedfolder of current type: */380 /* For each folder of current type: */ 372 381 for (int iFolderIndex = 0; iFolderIndex < pFolderTypeRoot->childCount(); ++iFolderIndex) 373 382 { 374 /* Get shared folder item: */ 375 SFTreeViewItem *pFolderItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFolderIndex)); 376 m_pCache->child(pFolderItem->m_strName).cacheCurrentData(*pFolderItem); 377 } 378 } 383 /* Get and cache new folder item: */ 384 const SFTreeViewItem *pItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFolderIndex)); 385 m_pCache->child(pItem->m_strName).cacheCurrentData(*pItem); 386 } 387 } 388 389 /* Cache new folders data: */ 390 m_pCache->cacheCurrentData(newFoldersData); 379 391 } 380 392 … … 384 396 UISettingsPageMachine::fetchData(data); 385 397 386 /* Check if sharedfolders data was changed: */398 /* Check if folders data was changed: */ 387 399 if (m_pCache->wasChanged()) 388 400 { 389 /* For each sharedfolder record: */401 /* For each folder record: */ 390 402 for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex) 391 403 { 392 /* Check if this shared folder data was changed: */ 393 const UISettingsCacheSharedFolder ¤tFolderCache = m_pCache->child(iFolderIndex); 394 if (currentFolderCache.wasChanged()) 404 /* Get folder cache: */ 405 const UISettingsCacheSharedFolder &folderCache = m_pCache->child(iFolderIndex); 406 407 /* Check if this folder data was changed: */ 408 if (folderCache.wasChanged()) 395 409 { 396 /* If shared folder was removed: */ 397 if (currentFolderCache.wasRemoved()) 398 removeSharedFolder(currentFolderCache); 399 400 /* If shared folder was created: */ 401 if (currentFolderCache.wasCreated()) 402 createSharedFolder(currentFolderCache); 403 404 /* If shared folder was changed: */ 405 if (currentFolderCache.wasUpdated()) 410 /* If folder was removed: */ 411 if (folderCache.wasRemoved()) 412 removeSharedFolder(folderCache); 413 414 else 415 416 /* If folder was created: */ 417 if (folderCache.wasCreated()) 418 createSharedFolder(folderCache); 419 420 else 421 422 /* If folder was updated: */ 423 if (folderCache.wasUpdated()) 406 424 { 407 removeSharedFolder( currentFolderCache);408 createSharedFolder( currentFolderCache);425 removeSharedFolder(folderCache); 426 createSharedFolder(folderCache); 409 427 } 410 428 } … … 881 899 bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache) 882 900 { 883 /* Get sharedfolder data: */884 const UIDataSettingsSharedFolder & folderData = folderCache.data();885 const QString strName = folderData.m_strName;886 const QString str Path = folderData.m_strPath;887 const bool fIsWritable = folderData.m_fWritable;888 const bool fIsAutoMount = folderData.m_fAutoMount;889 const UISharedFolderType enmSharedFoldersType = folderData.m_enmType;890 891 /* Get current sharedfolders: */901 /* Get new folder data: */ 902 const UIDataSettingsSharedFolder &newFolderData = folderCache.data(); 903 const UISharedFolderType enmSharedFoldersType = newFolderData.m_enmType; 904 const QString strName = newFolderData.m_strName; 905 const QString strPath = newFolderData.m_strPath; 906 const bool fIsAutoMount = newFolderData.m_fAutoMount; 907 const bool fIsWritable = newFolderData.m_fWritable; 908 909 /* Get current folders: */ 892 910 const CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType); 893 /* Check if such shared folder do not exists: */911 /* Make sure such folder doesn't exist: */ 894 912 CSharedFolder sharedFolder; 895 913 for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex) 896 if (sharedFolders [iFolderIndex].GetName() == strName)897 sharedFolder = sharedFolders [iFolderIndex];914 if (sharedFolders.at(iFolderIndex).GetName() == strName) 915 sharedFolder = sharedFolders.at(iFolderIndex); 898 916 if (sharedFolder.isNull()) 899 917 { 900 /* Create new sharedfolder: */918 /* Create new folder: */ 901 919 switch(enmSharedFoldersType) 902 920 { 903 921 case MachineType: 904 922 { 905 /* Create new sharedfolder: */923 /* Create new folder: */ 906 924 m_machine.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount); 907 925 if (!m_machine.isOk()) … … 918 936 case ConsoleType: 919 937 { 920 /* Create new sharedfolder: */938 /* Create new folder: */ 921 939 m_console.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount); 922 940 if (!m_console.isOk()) … … 940 958 bool UIMachineSettingsSF::removeSharedFolder(const UISettingsCacheSharedFolder &folderCache) 941 959 { 942 /* Get shared folder data: */943 const UIDataSettingsSharedFolder & folderData = folderCache.base();944 const QString strName = folderData.m_strName;945 const QString str Path = folderData.m_strPath;946 const UISharedFolderType enmSharedFoldersType = folderData.m_enmType;947 948 /* Get current sharedfolders: */960 /* Get old folder data: */ 961 const UIDataSettingsSharedFolder &oldFolderData = folderCache.base(); 962 const UISharedFolderType enmSharedFoldersType = oldFolderData.m_enmType; 963 const QString strName = oldFolderData.m_strName; 964 const QString strPath = oldFolderData.m_strPath; 965 966 /* Get current folders: */ 949 967 const CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType); 950 /* Check that such sharedfolder really exists: */968 /* Make sure such folder really exists: */ 951 969 CSharedFolder sharedFolder; 952 970 for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex) 953 if (sharedFolders [iFolderIndex].GetName() == strName)954 sharedFolder = sharedFolders [iFolderIndex];971 if (sharedFolders.at(iFolderIndex).GetName() == strName) 972 sharedFolder = sharedFolders.at(iFolderIndex); 955 973 if (!sharedFolder.isNull()) 956 974 { 957 /* Remove existing sharedfolder: */975 /* Remove existing folder: */ 958 976 switch(enmSharedFoldersType) 959 977 { 960 978 case MachineType: 961 979 { 962 /* Remove existing sharedfolder: */980 /* Remove existing folder: */ 963 981 m_machine.RemoveSharedFolder(strName); 964 982 if (!m_machine.isOk()) … … 975 993 case ConsoleType: 976 994 { 977 /* Remove existing sharedfolder: */995 /* Remove existing folder: */ 978 996 m_console.RemoveSharedFolder(strName); 979 997 if (!m_console.isOk())
Note:
See TracChangeset
for help on using the changeset viewer.