Changeset 36932 in vbox
- Timestamp:
- May 3, 2011 1:40:33 PM (14 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp
r36589 r36932 166 166 167 167 UIMachineSettingsSF::UIMachineSettingsSF() 168 : m_type(MachineType) 169 , mNewAction(0), mEdtAction(0), mDelAction(0) 170 , mIsListViewChanged(false) 168 : mNewAction(0), mEdtAction(0), mDelAction(0) 171 169 { 172 170 /* Apply UI decorations */ … … 225 223 UISettingsPageMachine::fetchData(data); 226 224 227 /* Fill internal variables with corresponding values: */ 228 if (!m_machine.isNull()) 229 loadToCacheFromMachine(); 230 if (!m_console.isNull()) 231 loadToCacheFromConsole(); 225 /* Load machine (permanent) shared folders into shared folders cache if possible: */ 226 if (isSharedFolderTypeSupported(MachineType)) 227 loadToCacheFrom(MachineType); 228 /* Load console (temporary) shared folders into shared folders cache if possible: */ 229 if (isSharedFolderTypeSupported(ConsoleType)) 230 loadToCacheFrom(ConsoleType); 232 231 233 232 /* Upload machine to data: */ … … 235 234 } 236 235 237 void UIMachineSettingsSF::loadToCacheFromMachine() 238 { 239 /* Load machine items into internal cache: */ 240 loadToCacheFromVector(m_machine.GetSharedFolders(), MachineType); 241 } 242 243 void UIMachineSettingsSF::loadToCacheFromConsole() 244 { 245 /* Load console items into internal cache: */ 246 loadToCacheFromVector(m_console.GetSharedFolders(), ConsoleType); 247 } 248 249 void UIMachineSettingsSF::loadToCacheFromVector(const CSharedFolderVector &vector, UISharedFolderType type) 250 { 251 /* Cache shared folders in internal variables: */ 252 for (int iFolderIndex = 0; iFolderIndex < vector.size(); ++iFolderIndex) 253 { 254 const CSharedFolder &folder = vector[iFolderIndex]; 255 UISharedFolderData data; 256 data.m_type = type; 257 data.m_strName = folder.GetName(); 258 data.m_strHostPath = folder.GetHostPath(); 259 data.m_fAutoMount = folder.GetAutoMount(); 260 data.m_fWritable = folder.GetWritable(); 261 m_cache.m_items << data; 236 void UIMachineSettingsSF::loadToCacheFrom(UISharedFolderType sharedFoldersType) 237 { 238 /* Get current shared folders: */ 239 CSharedFolderVector sharedFolders = getSharedFolders(sharedFoldersType); 240 241 /* For each shared folder: */ 242 for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex) 243 { 244 /* Prepare cache key & data: */ 245 QString strSharedFolderKey = QString::number(iFolderIndex); 246 UIDataSettingsSharedFolder sharedFolderData; 247 248 /* Check if shared folder exists: */ 249 const CSharedFolder &folder = sharedFolders[iFolderIndex]; 250 if (!folder.isNull()) 251 { 252 /* Gather shared folder values: */ 253 sharedFolderData.m_type = sharedFoldersType; 254 sharedFolderData.m_strName = folder.GetName(); 255 sharedFolderData.m_strHostPath = folder.GetHostPath(); 256 sharedFolderData.m_fAutoMount = folder.GetAutoMount(); 257 sharedFolderData.m_fWritable = folder.GetWritable(); 258 /* Override shared folder cache key: */ 259 strSharedFolderKey = sharedFolderData.m_strName; 260 } 261 262 /* Cache shared folder data: */ 263 m_cache.child(strSharedFolderKey).cacheInitialData(sharedFolderData); 262 264 } 263 265 } … … 267 269 void UIMachineSettingsSF::getFromCache() 268 270 { 269 /* Apply internal variables data to QWidget(s): */ 270 if (m_type == MachineType || m_type == ConsoleType) 271 root(MachineType); 272 if (m_type == ConsoleType) 273 root(ConsoleType); 274 for (int iFolderIndex = 0; iFolderIndex < m_cache.m_items.size(); ++iFolderIndex) 275 { 276 /* Get iterated folder's data: */ 277 const UISharedFolderData &data = m_cache.m_items[iFolderIndex]; 278 /* Prepare list item's fields: */ 271 /* Update root items visibility: */ 272 updateRootItemsVisibility(); 273 274 /* Load shared folders data: */ 275 for (int iFolderIndex = 0; iFolderIndex < m_cache.childCount(); ++iFolderIndex) 276 { 277 /* Get shared folder data: */ 278 const UIDataSettingsSharedFolder &sharedFolderData = m_cache.child(iFolderIndex).base(); 279 /* Prepare item fields: */ 279 280 QStringList fields; 280 fields << data.m_strName << data.m_strHostPath 281 << (data.m_fAutoMount ? mTrYes : "") 282 << (data.m_fWritable ? mTrFull : mTrReadOnly); 283 /* Searching for item's root: */ 284 SFTreeViewItem *pItemsRoot = root(data.m_type); 285 /* Create new folder list item: */ 286 new SFTreeViewItem(pItemsRoot, fields, SFTreeViewItem::EllipsisFile); 287 } 288 /* Sort populated item's list: */ 289 mTwFolders->sortItems(0, Qt::AscendingOrder); 281 fields << sharedFolderData.m_strName 282 << sharedFolderData.m_strHostPath 283 << (sharedFolderData.m_fAutoMount ? mTrYes : "") 284 << (sharedFolderData.m_fWritable ? mTrFull : mTrReadOnly); 285 /* Create new shared folders item: */ 286 new SFTreeViewItem(root(sharedFolderData.m_type), fields, SFTreeViewItem::EllipsisFile); 287 } 290 288 /* Ensure current item fetched: */ 291 289 mTwFolders->setCurrentItem(mTwFolders->topLevelItem(0)); … … 297 295 void UIMachineSettingsSF::putToCache() 298 296 { 299 /* Reset cache: */ 300 m_cache.m_items.clear(); 301 /* Gather internal variables data from QWidget(s): */ 297 /* For each shared folder type: */ 302 298 QTreeWidgetItem *pMainRootItem = mTwFolders->invisibleRootItem(); 303 /* Iterate other all the list top-level items: */304 299 for (int iFodlersTypeIndex = 0; iFodlersTypeIndex < pMainRootItem->childCount(); ++iFodlersTypeIndex) 305 300 { 301 /* Get shared folder root item: */ 306 302 SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFodlersTypeIndex)); 307 UISharedFolderType type = (UISharedFolderType)pFolderTypeRoot->text(1).toInt();308 /* Iterate other all the folder items: */303 UISharedFolderType sharedFolderType = (UISharedFolderType)pFolderTypeRoot->text(1).toInt(); 304 /* For each shared folder of current type: */ 309 305 for (int iFoldersIndex = 0; iFoldersIndex < pFolderTypeRoot->childCount(); ++iFoldersIndex) 310 306 { 311 307 SFTreeViewItem *pFolderItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFoldersIndex)); 312 UI SharedFolderData data;313 data.m_type = type;314 data.m_strName = pFolderItem->getText(0);315 data.m_strHostPath = pFolderItem->getText(1);316 data.m_fAutoMount = pFolderItem->getText(2) == mTrYes ? true : false;317 data.m_fWritable = pFolderItem->getText(3) == mTrFull ? true : false;318 m_cache. m_items << data;308 UIDataSettingsSharedFolder sharedFolderData; 309 sharedFolderData.m_type = sharedFolderType; 310 sharedFolderData.m_strName = pFolderItem->getText(0); 311 sharedFolderData.m_strHostPath = pFolderItem->getText(1); 312 sharedFolderData.m_fAutoMount = pFolderItem->getText(2) == mTrYes ? true : false; 313 sharedFolderData.m_fWritable = pFolderItem->getText(3) == mTrFull ? true : false; 314 m_cache.child(sharedFolderData.m_strName).cacheCurrentData(sharedFolderData); 319 315 } 320 316 } … … 328 324 UISettingsPageMachine::fetchData(data); 329 325 330 /* Gather corresponding values from internal variables: */ 331 if (!m_machine.isNull()) 332 saveFromCacheToMachine(); 333 if (!m_console.isNull()) 334 saveFromCacheToConsole(); 326 /* Check if shared folders data was changed at all: */ 327 if (m_cache.wasChanged()) 328 { 329 /* Save machine (permanent) shared folders if possible: */ 330 if (isSharedFolderTypeSupported(MachineType)) 331 saveFromCacheTo(MachineType); 332 /* Save console (temporary) shared folders if possible: */ 333 if (isSharedFolderTypeSupported(ConsoleType)) 334 saveFromCacheTo(ConsoleType); 335 } 335 336 336 337 /* Upload machine to data: */ … … 338 339 } 339 340 340 void UIMachineSettingsSF::saveFromCacheToMachine() 341 { 342 /* Check if items were NOT changed: */ 343 if (!mIsListViewChanged) 344 return; 345 346 /* Delete all machine folders first: */ 347 const CSharedFolderVector &folders = m_machine.GetSharedFolders(); 348 for (int iFolderIndex = 0; iFolderIndex < folders.size() && !failed(); ++iFolderIndex) 349 { 350 const CSharedFolder &folder = folders[iFolderIndex]; 351 QString strFolderName = folder.GetName(); 352 QString strFolderPath = folder.GetHostPath(); 353 m_machine.RemoveSharedFolder(strFolderName); 354 if (!m_machine.isOk()) 355 { 356 /* Mark the page as failed: */ 357 setFailed(true); 358 /* Show error message: */ 359 vboxProblem().cannotRemoveSharedFolder(m_machine, strFolderName, strFolderPath); 360 } 361 } 362 363 /* Save all new machine folders: */ 364 for (int iFolderIndex = 0; iFolderIndex < m_cache.m_items.size() && !failed(); ++iFolderIndex) 365 { 366 const UISharedFolderData &data = m_cache.m_items[iFolderIndex]; 367 if (data.m_type == MachineType) 368 { 369 m_machine.CreateSharedFolder(data.m_strName, data.m_strHostPath, data.m_fWritable, data.m_fAutoMount); 370 if (!m_machine.isOk()) 371 { 372 /* Mark the page as failed: */ 373 setFailed(true); 374 /* Show error message: */ 375 vboxProblem().cannotCreateSharedFolder(m_machine, data.m_strName, data.m_strHostPath); 376 } 377 } 378 } 379 } 380 381 void UIMachineSettingsSF::saveFromCacheToConsole() 382 { 383 /* Check if items were NOT changed: */ 384 if (!mIsListViewChanged) 385 return; 386 387 /* Delete all console folders first: */ 388 const CSharedFolderVector &folders = m_console.GetSharedFolders(); 389 for (int iFolderIndex = 0; iFolderIndex < folders.size() && !failed(); ++iFolderIndex) 390 { 391 const CSharedFolder &folder = folders[iFolderIndex]; 392 QString strFolderName = folder.GetName(); 393 QString strFolderPath = folder.GetHostPath(); 394 m_console.RemoveSharedFolder(strFolderName); 395 if (!m_console.isOk()) 396 { 397 /* Mark the page as failed: */ 398 setFailed(true); 399 /* Show error message: */ 400 vboxProblem().cannotRemoveSharedFolder(m_console, strFolderName, strFolderPath); 401 } 402 } 403 404 /* Save all new console folders: */ 405 for (int iFolderIndex = 0; iFolderIndex < m_cache.m_items.size() && !failed(); ++iFolderIndex) 406 { 407 const UISharedFolderData &data = m_cache.m_items[iFolderIndex]; 408 if (data.m_type == ConsoleType) 409 { 410 m_console.CreateSharedFolder(data.m_strName, data.m_strHostPath, data.m_fWritable, data.m_fAutoMount); 411 if (!m_console.isOk()) 412 { 413 /* Mark the page as failed: */ 414 setFailed(true); 415 /* Show error message: */ 416 vboxProblem().cannotCreateSharedFolder(m_console, data.m_strName, data.m_strHostPath); 341 void UIMachineSettingsSF::saveFromCacheTo(UISharedFolderType sharedFoldersType) 342 { 343 /* For each shared folder data set: */ 344 for (int iSharedFolderIndex = 0; iSharedFolderIndex < m_cache.childCount(); ++iSharedFolderIndex) 345 { 346 /* Check if this shared folder data was actually changed: */ 347 const UICacheSettingsSharedFolder &sharedFolderCache = m_cache.child(iSharedFolderIndex); 348 if (sharedFolderCache.wasChanged()) 349 { 350 /* If shared folder was removed: */ 351 if (sharedFolderCache.wasRemoved()) 352 { 353 /* Get shared folder data: */ 354 const UIDataSettingsSharedFolder &sharedFolderData = sharedFolderCache.base(); 355 /* Check if thats shared folder of required type before removing: */ 356 if (sharedFolderData.m_type == sharedFoldersType) 357 removeSharedFolder(sharedFolderCache); 358 } 359 360 /* If shared folder was created: */ 361 if (sharedFolderCache.wasCreated()) 362 { 363 /* Get shared folder data: */ 364 const UIDataSettingsSharedFolder &sharedFolderData = sharedFolderCache.data(); 365 /* Check if thats shared folder of required type before creating: */ 366 if (sharedFolderData.m_type == sharedFoldersType) 367 createSharedFolder(sharedFolderCache); 368 } 369 370 /* If shared folder was changed: */ 371 if (sharedFolderCache.wasUpdated()) 372 { 373 /* Get shared folder data: */ 374 const UIDataSettingsSharedFolder &sharedFolderData = sharedFolderCache.data(); 375 /* Check if thats shared folder of required type before recreating: */ 376 if (sharedFolderData.m_type == sharedFoldersType) 377 { 378 removeSharedFolder(sharedFolderCache); 379 createSharedFolder(sharedFolderCache); 380 } 417 381 } 418 382 } … … 453 417 { 454 418 /* Invoke Add-Box Dialog */ 455 UIMachineSettingsSFDetails dlg (UIMachineSettingsSFDetails::AddType, m_type == ConsoleType, usedList (true), this);419 UIMachineSettingsSFDetails dlg (UIMachineSettingsSFDetails::AddType, isSharedFolderTypeSupported(ConsoleType), usedList (true), this); 456 420 if (dlg.exec() == QDialog::Accepted) 457 421 { … … 461 425 /* Shared folder's name & path could not be empty */ 462 426 Assert (!name.isEmpty() && !path.isEmpty()); 463 /* Searching root for the new listview item */464 SFTreeViewItem *pRoot = root(isPermanent ? MachineType : ConsoleType);465 Assert (pRoot);466 427 /* Appending a new listview item to the root */ 467 428 QStringList fields; … … 469 430 << (dlg.isAutoMounted() ? mTrYes : "" /* auto mount? */) 470 431 << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */); 471 SFTreeViewItem *item = new SFTreeViewItem (pRoot, fields, SFTreeViewItem::EllipsisFile); 432 SFTreeViewItem *item = new SFTreeViewItem (root(isPermanent ? MachineType : ConsoleType), 433 fields, SFTreeViewItem::EllipsisFile); 472 434 mTwFolders->sortItems (0, Qt::AscendingOrder); 473 435 mTwFolders->scrollToItem (item); … … 476 438 mTwFolders->setFocus(); 477 439 adjustList(); 478 479 mIsListViewChanged = true;480 440 } 481 441 } … … 491 451 492 452 /* Invoke Edit-Box Dialog */ 493 UIMachineSettingsSFDetails dlg (UIMachineSettingsSFDetails::EditType, m_type == ConsoleType, usedList (false), this);453 UIMachineSettingsSFDetails dlg (UIMachineSettingsSFDetails::EditType, isSharedFolderTypeSupported(ConsoleType), usedList (false), this); 494 454 dlg.setPath (item->getText (1)); 495 455 dlg.setName (item->getText (0)); … … 506 466 /* Searching new root for the selected listview item */ 507 467 SFTreeViewItem *pRoot = root(isPermanent ? MachineType : ConsoleType); 508 Assert (pRoot);509 468 /* Updating an edited listview item */ 510 469 QStringList fields; … … 525 484 } 526 485 adjustList(); 527 528 mIsListViewChanged = true;529 486 } 530 487 } … … 536 493 delete selectedItem; 537 494 adjustList(); 538 mIsListViewChanged = true;539 495 } 540 496 … … 634 590 } 635 591 636 SFTreeViewItem* UIMachineSettingsSF::root(UISharedFolderType type)637 { 638 /* Prepare empty item: */592 SFTreeViewItem* UIMachineSettingsSF::root(UISharedFolderType sharedFolderType) 593 { 594 /* Search for the corresponding root item among all the top-level items: */ 639 595 SFTreeViewItem *pRootItem = 0; 640 /* Get top-level root item: */641 596 QTreeWidgetItem *pMainRootItem = mTwFolders->invisibleRootItem(); 642 /* Iterate other the all root items: */643 597 for (int iFolderTypeIndex = 0; iFolderTypeIndex < pMainRootItem->childCount(); ++iFolderTypeIndex) 644 598 { 645 599 /* Get iterated item: */ 646 600 QTreeWidgetItem *pIteratedItem = pMainRootItem->child(iFolderTypeIndex); 647 /* If iterated item 'stype is what we are looking for: */648 if (pIteratedItem->text(1).toInt() == type)601 /* If iterated item type is what we are looking for: */ 602 if (pIteratedItem->text(1).toInt() == sharedFolderType) 649 603 { 650 604 /* Remember the item: */ … … 654 608 } 655 609 } 656 /* If root item we are looking for still not found: */657 if (!pRootItem)658 {659 /* Preparing fields: */660 QStringList fields;661 /* Depending on folder type: */662 switch (type)663 {664 case MachineType:665 fields << tr(" Machine Folders") << QString::number(MachineType);666 break;667 case ConsoleType:668 fields << tr(" Transient Folders") << QString::number(ConsoleType);669 break;670 default:671 break;672 }673 /* Creating root: */674 pRootItem = new SFTreeViewItem(mTwFolders, fields, SFTreeViewItem::EllipsisEnd);675 /* We should show it (its not?): */676 pRootItem->setHidden(false);677 /* Expand it: */678 pRootItem->setExpanded(true);679 }680 610 /* Return root item: */ 681 611 return pRootItem; … … 701 631 } 702 632 703 void UIMachineSettingsSF::setDialogType(SettingsDialogType settingsDialogType) 704 { 705 UISettingsPageMachine::setDialogType(settingsDialogType); 706 m_type = isMachineSaved() || isMachineOnline() ? ConsoleType : MachineType; 707 } 708 633 bool UIMachineSettingsSF::isSharedFolderTypeSupported(UISharedFolderType sharedFolderType) const 634 { 635 bool fIsSharedFolderTypeSupported = false; 636 switch (sharedFolderType) 637 { 638 case MachineType: 639 fIsSharedFolderTypeSupported = isMachineInValidMode(); 640 break; 641 case ConsoleType: 642 fIsSharedFolderTypeSupported = isMachineSaved() || isMachineOnline(); 643 break; 644 default: 645 break; 646 } 647 return fIsSharedFolderTypeSupported; 648 } 649 650 void UIMachineSettingsSF::updateRootItemsVisibility() 651 { 652 /* Update (show/hide) machine (permanent) root item: */ 653 setRootItemVisible(MachineType, isSharedFolderTypeSupported(MachineType)); 654 /* Update (show/hide) console (temporary) root item: */ 655 setRootItemVisible(ConsoleType, isSharedFolderTypeSupported(ConsoleType)); 656 } 657 658 void UIMachineSettingsSF::setRootItemVisible(UISharedFolderType sharedFolderType, bool fVisible) 659 { 660 /* Search for the corresponding root item among all the top-level items: */ 661 SFTreeViewItem *pRootItem = root(sharedFolderType); 662 /* If root item, we are looking for, still not found: */ 663 if (!pRootItem) 664 { 665 /* Prepare fields for the new root item: */ 666 QStringList fields; 667 /* Depending on folder type: */ 668 switch (sharedFolderType) 669 { 670 case MachineType: 671 fields << tr(" Machine Folders") << QString::number(MachineType); 672 break; 673 case ConsoleType: 674 fields << tr(" Transient Folders") << QString::number(ConsoleType); 675 break; 676 default: 677 break; 678 } 679 /* And create the new root item: */ 680 pRootItem = new SFTreeViewItem(mTwFolders, fields, SFTreeViewItem::EllipsisEnd); 681 } 682 /* Expand/collaps it if necessary: */ 683 pRootItem->setExpanded(fVisible); 684 /* And hide/show it if necessary: */ 685 pRootItem->setHidden(!fVisible); 686 } 687 688 CSharedFolderVector UIMachineSettingsSF::getSharedFolders(UISharedFolderType sharedFoldersType) 689 { 690 CSharedFolderVector sharedFolders; 691 if (isSharedFolderTypeSupported(sharedFoldersType)) 692 { 693 switch (sharedFoldersType) 694 { 695 case MachineType: 696 { 697 AssertMsg(!m_machine.isNull(), ("Machine is NOT set!\n")); 698 sharedFolders = m_machine.GetSharedFolders(); 699 break; 700 } 701 case ConsoleType: 702 { 703 AssertMsg(!m_console.isNull(), ("Console is NOT set!\n")); 704 sharedFolders = m_console.GetSharedFolders(); 705 break; 706 } 707 default: 708 break; 709 } 710 } 711 return sharedFolders; 712 } 713 714 bool UIMachineSettingsSF::removeSharedFolder(const UICacheSettingsSharedFolder &folderCache) 715 { 716 /* Get shared folder data: */ 717 const UIDataSettingsSharedFolder &folderData = folderCache.base(); 718 QString strName = folderData.m_strName; 719 QString strPath = folderData.m_strHostPath; 720 UISharedFolderType sharedFoldersType = folderData.m_type; 721 722 /* Get current shared folders: */ 723 CSharedFolderVector sharedFolders = getSharedFolders(sharedFoldersType); 724 /* Check that such shared folder really exists: */ 725 CSharedFolder sharedFolder; 726 for (int iSharedFolderIndex = 0; iSharedFolderIndex < sharedFolders.size(); ++iSharedFolderIndex) 727 if (sharedFolders[iSharedFolderIndex].GetName() == strName) 728 sharedFolder = sharedFolders[iSharedFolderIndex]; 729 if (!sharedFolder.isNull()) 730 { 731 /* Remove existing shared folder: */ 732 switch(sharedFoldersType) 733 { 734 case MachineType: 735 { 736 m_machine.RemoveSharedFolder(strName); 737 if (!m_machine.isOk()) 738 { 739 /* Mark the page as failed: */ 740 setFailed(true); 741 /* Show error message: */ 742 vboxProblem().cannotRemoveSharedFolder(m_machine, strName, strPath); 743 /* Finish early: */ 744 return false; 745 } 746 break; 747 } 748 case ConsoleType: 749 { 750 m_console.RemoveSharedFolder(strName); 751 if (!m_console.isOk()) 752 { 753 /* Mark the page as failed: */ 754 setFailed(true); 755 /* Show error message: */ 756 vboxProblem().cannotRemoveSharedFolder(m_console, strName, strPath); 757 /* Finish early: */ 758 return false; 759 } 760 break; 761 } 762 default: 763 break; 764 } 765 } 766 return true; 767 } 768 769 bool UIMachineSettingsSF::createSharedFolder(const UICacheSettingsSharedFolder &folderCache) 770 { 771 /* Get shared folder data: */ 772 const UIDataSettingsSharedFolder &folderData = folderCache.data(); 773 QString strName = folderData.m_strName; 774 QString strPath = folderData.m_strHostPath; 775 bool fIsWritable = folderData.m_fWritable; 776 bool fIsAutoMount = folderData.m_fAutoMount; 777 UISharedFolderType sharedFoldersType = folderData.m_type; 778 779 /* Get current shared folders: */ 780 CSharedFolderVector sharedFolders = getSharedFolders(sharedFoldersType); 781 /* Check if such shared folder do not exists: */ 782 CSharedFolder sharedFolder; 783 for (int iSharedFolderIndex = 0; iSharedFolderIndex < sharedFolders.size(); ++iSharedFolderIndex) 784 if (sharedFolders[iSharedFolderIndex].GetName() == strName) 785 sharedFolder = sharedFolders[iSharedFolderIndex]; 786 if (sharedFolder.isNull()) 787 { 788 /* Create new shared folder: */ 789 switch(sharedFoldersType) 790 { 791 case MachineType: 792 { 793 m_machine.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount); 794 if (!m_machine.isOk()) 795 { 796 /* Mark the page as failed: */ 797 setFailed(true); 798 /* Show error message: */ 799 vboxProblem().cannotCreateSharedFolder(m_machine, strName, strPath); 800 /* Finish early: */ 801 return false; 802 } 803 break; 804 } 805 case ConsoleType: 806 { 807 /* Create new shared folder: */ 808 m_console.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount); 809 if (!m_console.isOk()) 810 { 811 /* Mark the page as failed: */ 812 setFailed(true); 813 /* Show error message: */ 814 vboxProblem().cannotCreateSharedFolder(m_console, strName, strPath); 815 /* Finish early: */ 816 return false; 817 } 818 break; 819 } 820 default: 821 break; 822 } 823 } 824 return true; 825 } -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h
r36589 r36932 31 31 typedef QList <SFolderName> SFoldersNameList; 32 32 33 /* Machine settings / Shared Folders page / Folder data: */34 struct UI SharedFolderData33 /* Machine settings / Shared Folders page / Shared Folder data: */ 34 struct UIDataSettingsSharedFolder 35 35 { 36 /* Default constructor: */ 37 UIDataSettingsSharedFolder() 38 : m_type(MachineType) 39 , m_strName(QString()) 40 , m_strHostPath(QString()) 41 , m_fAutoMount(false) 42 , m_fWritable(false) {} 43 /* Functions: */ 44 bool equal(const UIDataSettingsSharedFolder &other) const 45 { 46 return (m_type == other.m_type) && 47 (m_strName == other.m_strName) && 48 (m_strHostPath == other.m_strHostPath) && 49 (m_fAutoMount == other.m_fAutoMount) && 50 (m_fWritable == other.m_fWritable); 51 } 52 /* Operators: */ 53 bool operator==(const UIDataSettingsSharedFolder &other) const { return equal(other); } 54 bool operator!=(const UIDataSettingsSharedFolder &other) const { return !equal(other); } 55 /* Variables: */ 36 56 UISharedFolderType m_type; 37 57 QString m_strName; … … 39 59 bool m_fAutoMount; 40 60 bool m_fWritable; 41 bool m_fEdited;42 61 }; 62 typedef UISettingsCache<UIDataSettingsSharedFolder> UICacheSettingsSharedFolder; 43 63 44 /* Machine settings / Shared Folders page / Cache: */45 struct UI SettingsCacheMachineSFolders64 /* Machine settings / Shared Folders page / Shared Folders data: */ 65 struct UIDataSettingsSharedFolders 46 66 { 47 QList<UISharedFolderData> m_items; 67 /* Default constructor: */ 68 UIDataSettingsSharedFolders() {} 69 /* Operators: */ 70 bool operator==(const UIDataSettingsSharedFolders& /* other */) const { return true; } 71 bool operator!=(const UIDataSettingsSharedFolders& /* other */) const { return false; } 48 72 }; 73 typedef UISettingsCachePool<UIDataSettingsSharedFolders, UICacheSettingsSharedFolder> UICacheSettingsSharedFolders; 49 74 50 75 class UIMachineSettingsSF : public UISettingsPageMachine, … … 62 87 * this task COULD be performed in other than GUI thread: */ 63 88 void loadToCacheFrom(QVariant &data); 64 void loadToCacheFromMachine(); 65 void loadToCacheFromConsole(); 66 void loadToCacheFromVector(const CSharedFolderVector &vector, UISharedFolderType type); 89 void loadToCacheFrom(UISharedFolderType sharedFoldersType); 67 90 /* Load data to corresponding widgets from cache, 68 91 * this task SHOULD be performed in GUI thread only: */ … … 75 98 * this task COULD be performed in other than GUI thread: */ 76 99 void saveFromCacheTo(QVariant &data); 77 void saveFromCacheToMachine(); 78 void saveFromCacheToConsole(); 100 void saveFromCacheTo(UISharedFolderType sharedFoldersType); 79 101 80 102 void setOrderAfter (QWidget *aWidget); … … 104 126 SFoldersNameList usedList (bool aIncludeSelected); 105 127 106 void setDialogType(SettingsDialogType settingsDialogType); 128 bool isSharedFolderTypeSupported(UISharedFolderType sharedFolderType) const; 129 void updateRootItemsVisibility(); 130 void setRootItemVisible(UISharedFolderType sharedFolderType, bool fVisible); 107 131 108 UISharedFolderType m_type; 132 CSharedFolderVector getSharedFolders(UISharedFolderType sharedFoldersType); 133 134 bool removeSharedFolder(const UICacheSettingsSharedFolder &folderCache); 135 bool createSharedFolder(const UICacheSettingsSharedFolder &folderCache); 109 136 110 137 QAction *mNewAction; 111 138 QAction *mEdtAction; 112 139 QAction *mDelAction; 113 bool mIsListViewChanged;114 140 QString mTrFull; 115 141 QString mTrReadOnly; … … 117 143 118 144 /* Cache: */ 119 UI SettingsCacheMachineSFolders m_cache;145 UICacheSettingsSharedFolders m_cache; 120 146 }; 121 147
Note:
See TracChangeset
for help on using the changeset viewer.