Changeset 66451 in vbox
- Timestamp:
- Apr 6, 2017 8:45:04 AM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 114431
- 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
r66406 r66451 40 40 /** Constructs data. */ 41 41 UIDataSettingsSharedFolder() 42 : m_ type(MachineType)42 : m_enmType(MachineType) 43 43 , m_strName(QString()) 44 , m_str HostPath(QString())44 , m_strPath(QString()) 45 45 , m_fAutoMount(false) 46 46 , m_fWritable(false) … … 51 51 { 52 52 return true 53 && (m_ type == other.m_type)53 && (m_enmType == other.m_enmType) 54 54 && (m_strName == other.m_strName) 55 && (m_str HostPath == other.m_strHostPath)55 && (m_strPath == other.m_strPath) 56 56 && (m_fAutoMount == other.m_fAutoMount) 57 57 && (m_fWritable == other.m_fWritable) … … 65 65 66 66 /** Holds the shared folder type. */ 67 UISharedFolderType m_ type;67 UISharedFolderType m_enmType; 68 68 /** Holds the shared folder name. */ 69 69 QString m_strName; 70 70 /** Holds the shared folder path. */ 71 QString m_str HostPath;71 QString m_strPath; 72 72 /** Holds whether the shared folder should be auto-mounted at startup. */ 73 73 bool m_fAutoMount; … … 90 90 91 91 92 class SFTreeViewItem : public QITreeWidgetItem 92 /** Machine settings: Shared Folder tree-widget item. */ 93 class SFTreeViewItem : public QITreeWidgetItem, public UIDataSettingsSharedFolder 93 94 { 94 95 public: 95 96 97 /** Format type. */ 96 98 enum FormatType 97 99 { 98 IncorrectFormat = 0,99 EllipsisStart = 1,100 EllipsisMiddle = 2,101 EllipsisEnd = 3,102 EllipsisFile = 4100 FormatType_Invalid, 101 FormatType_EllipsisStart, 102 FormatType_EllipsisMiddle, 103 FormatType_EllipsisEnd, 104 FormatType_EllipsisFile, 103 105 }; 104 106 105 /* Root Item */ 106 SFTreeViewItem (QITreeWidget *aParent, const QStringList &aFields, FormatType aFormat) 107 : QITreeWidgetItem (aParent, aFields), mFormat (aFormat) 108 { 109 setFirstColumnSpanned (true); 110 setFlags (flags() ^ Qt::ItemIsSelectable); 111 } 112 113 /* Child Item */ 114 SFTreeViewItem (SFTreeViewItem *aParent, const QStringList &aFields, FormatType aFormat) 115 : QITreeWidgetItem (aParent, aFields), mFormat (aFormat) 116 { 117 updateText (aFields); 118 } 119 120 bool operator< (const QTreeWidgetItem &aOther) const 121 { 122 /* Root items should always been sorted by id-field. */ 123 return parentItem() ? text (0).toLower() < aOther.text (0).toLower() : 124 text (1).toLower() < aOther.text (1).toLower(); 125 } 126 127 SFTreeViewItem* child (int aIndex) const 128 { 129 QTreeWidgetItem *item = QTreeWidgetItem::child (aIndex); 130 return item ? static_cast <SFTreeViewItem*> (item) : 0; 131 } 132 133 QString getText (int aIndex) const 134 { 135 return aIndex >= 0 && aIndex < (int)mTextList.size() ? mTextList [aIndex] : QString::null; 136 } 137 138 void updateText (const QStringList &aFields) 139 { 140 mTextList.clear(); 141 mTextList << aFields; 107 /** Constructs shared folder type (root) item. 108 * @param pParent Brings the item parent. 109 * @param enmFormat Brings the item format type. */ 110 SFTreeViewItem(QITreeWidget *pParent, FormatType enmFormat) 111 : QITreeWidgetItem(pParent) 112 , m_enmFormat(enmFormat) 113 { 114 setFirstColumnSpanned(true); 115 setFlags(flags() ^ Qt::ItemIsSelectable); 116 } 117 118 /** Constructs shared folder (child) item. 119 * @param pParent Brings the item parent. 120 * @param enmFormat Brings the item format type. */ 121 SFTreeViewItem(SFTreeViewItem *pParent, FormatType enmFormat) 122 : QITreeWidgetItem(pParent) 123 , m_enmFormat(enmFormat) 124 { 125 } 126 127 /** Returns whether this item is less than the @a other one. */ 128 bool operator<(const QTreeWidgetItem &other) const 129 { 130 /* Root items should always been sorted by type field: */ 131 return parentItem() ? text(0) < other.text(0) : 132 text(1) < other.text(1); 133 } 134 135 /** Returns child item number @a iIndex. */ 136 SFTreeViewItem *child(int iIndex) const 137 { 138 QTreeWidgetItem *pItem = QTreeWidgetItem::child(iIndex); 139 return pItem ? static_cast<SFTreeViewItem*>(pItem) : 0; 140 } 141 142 /** Returns text of item number @a iIndex. */ 143 QString getText(int iIndex) const 144 { 145 return iIndex >= 0 && iIndex < m_fields.size() ? m_fields.at(iIndex) : QString(); 146 } 147 148 /** Updates item fields. */ 149 void updateFields() 150 { 151 /* Clear fields: */ 152 m_fields.clear(); 153 154 /* For root items: */ 155 if (!parentItem()) 156 m_fields << m_strName 157 << QString::number((int)m_enmType); 158 /* For child items: */ 159 else 160 m_fields << m_strName 161 << m_strPath 162 << (m_fAutoMount ? UIMachineSettingsSF::tr("Yes") : "") 163 << (m_fWritable ? UIMachineSettingsSF::tr("Full") : UIMachineSettingsSF::tr("Read-only")); 164 165 /* Adjust item layout: */ 142 166 adjustText(); 143 167 } 144 168 169 /** Adjusts item layout. */ 145 170 void adjustText() 146 171 { 147 for (int i = 0; i < treeWidget()->columnCount(); ++ i) 148 processColumn (i); 149 } 172 for (int i = 0; i < treeWidget()->columnCount(); ++i) 173 processColumn(i); 174 } 175 176 protected: 150 177 151 178 /** Returns default text. */ … … 155 182 tr("%1, %2: %3, %4: %5, %6: %7", 156 183 "col.1 text, col.2 name: col.2 text, col.3 name: col.3 text, col.4 name: col.4 text") 157 .arg(text(0))158 .arg(parentTree()->headerItem()->text(1)).arg(text(1))159 .arg(parentTree()->headerItem()->text(2)).arg(text(2))160 .arg(parentTree()->headerItem()->text(3)).arg(text(3)) :184 .arg(text(0)) 185 .arg(parentTree()->headerItem()->text(1)).arg(text(1)) 186 .arg(parentTree()->headerItem()->text(2)).arg(text(2)) 187 .arg(parentTree()->headerItem()->text(3)).arg(text(3)) : 161 188 text(0); 162 189 } … … 164 191 private: 165 192 166 void processColumn (int aColumn) 167 { 168 QString oneString = getText (aColumn); 169 if (oneString.isNull()) 193 /** Performs item @a iColumn processing. */ 194 void processColumn(int iColumn) 195 { 196 QString strOneString = getText(iColumn); 197 if (strOneString.isNull()) 170 198 return; 171 QFontMetrics fm = treeWidget()->fontMetrics();172 int oldSize = fm.width (oneString);173 int indentSize = fm.width (" ... ");174 int i temIndent = parentItem() ? treeWidget()->indentation() * 2 : treeWidget()->indentation();175 if ( aColumn == 0)176 i ndentSize += itemIndent;177 int cWidth = treeWidget()->columnWidth (aColumn);178 179 /* Compress text */180 int start = 0;181 int finish = 0;182 int position = 0;183 int textWidth = 0;199 const QFontMetrics fm = treeWidget()->fontMetrics(); 200 const int iOldSize = fm.width(strOneString); 201 const int iItemIndent = parentItem() ? treeWidget()->indentation() * 2 : treeWidget()->indentation(); 202 int iIndentSize = fm.width(" ... "); 203 if (iColumn == 0) 204 iIndentSize += iItemIndent; 205 const int cWidth = !parentItem() ? treeWidget()->viewport()->width() : treeWidget()->columnWidth(iColumn); 206 207 /* Compress text: */ 208 int iStart = 0; 209 int iFinish = 0; 210 int iPosition = 0; 211 int iTextWidth = 0; 184 212 do 185 213 { 186 textWidth = fm.width (oneString);187 if ( textWidth + indentSize > cWidth)214 iTextWidth = fm.width(strOneString); 215 if (iTextWidth + iIndentSize > cWidth) 188 216 { 189 start= 0;190 finish = oneString.length();191 192 /* Selecting remove position */193 switch (m Format)217 iStart = 0; 218 iFinish = strOneString.length(); 219 220 /* Selecting remove position: */ 221 switch (m_enmFormat) 194 222 { 195 case EllipsisStart:196 position = start;223 case FormatType_EllipsisStart: 224 iPosition = iStart; 197 225 break; 198 case EllipsisMiddle:199 position = (finish - start) / 2;226 case FormatType_EllipsisMiddle: 227 iPosition = (iFinish - iStart) / 2; 200 228 break; 201 case EllipsisEnd:202 position = finish - 1;229 case FormatType_EllipsisEnd: 230 iPosition = iFinish - 1; 203 231 break; 204 case EllipsisFile:232 case FormatType_EllipsisFile: 205 233 { 206 QRegExp regExp("([\\\\/][^\\\\^/]+[\\\\/]?$)");207 int newFinish = regExp.indexIn (oneString);208 if ( newFinish != -1)209 finish = newFinish;210 position = (finish - start) / 2;234 const QRegExp regExp("([\\\\/][^\\\\^/]+[\\\\/]?$)"); 235 const int iNewFinish = regExp.indexIn(strOneString); 236 if (iNewFinish != -1) 237 iFinish = iNewFinish; 238 iPosition = (iFinish - iStart) / 2; 211 239 break; 212 240 } 213 241 default: 214 AssertMsgFailed 242 AssertMsgFailed(("Invalid format type\n")); 215 243 } 216 244 217 if ( position == finish)245 if (iPosition == iFinish) 218 246 break; 219 247 220 oneString.remove (position, 1);248 strOneString.remove(iPosition, 1); 221 249 } 222 250 } 223 while (textWidth + indentSize > cWidth); 224 225 if (position || mFormat == EllipsisFile) oneString.insert (position, "..."); 226 int newSize = fm.width (oneString); 227 setText (aColumn, newSize < oldSize ? oneString : mTextList [aColumn]); 228 setToolTip (aColumn, text (aColumn) == getText (aColumn) ? QString::null : getText (aColumn)); 229 230 /* Calculate item's size-hint */ 231 setSizeHint (aColumn, QSize (fm.width (QString (" %1 ").arg (getText (aColumn))), 100)); 232 } 233 234 FormatType mFormat; 235 QStringList mTextList; 251 while (iTextWidth + iIndentSize > cWidth); 252 253 if (iPosition || m_enmFormat == FormatType_EllipsisFile) 254 strOneString.insert(iPosition, "..."); 255 const int iNewSize = fm.width(strOneString); 256 setText(iColumn, iNewSize < iOldSize ? strOneString : m_fields.at(iColumn)); 257 setToolTip(iColumn, text(iColumn) == getText(iColumn) ? QString() : getText(iColumn)); 258 259 /* Calculate item's size-hint: */ 260 setSizeHint(iColumn, QSize(fm.width(QString(" %1 ").arg(getText(iColumn))), fm.height())); 261 } 262 263 /** Holds the item format type. */ 264 FormatType m_enmFormat; 265 /** Holds the item text fields. */ 266 QStringList m_fields; 236 267 }; 237 268 … … 291 322 { 292 323 /* Gather shared folder values: */ 293 initialFolderData.m_ type = enmFolderType;324 initialFolderData.m_enmType = enmFolderType; 294 325 initialFolderData.m_strName = folder.GetName(); 295 initialFolderData.m_str HostPath = folder.GetHostPath();326 initialFolderData.m_strPath = folder.GetHostPath(); 296 327 initialFolderData.m_fAutoMount = folder.GetAutoMount(); 297 328 initialFolderData.m_fWritable = folder.GetWritable(); … … 319 350 /* For each shared folder: */ 320 351 for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex) 321 { 322 /* Acquire corresponding folder data: */ 323 const UIDataSettingsSharedFolder &folderData = m_pCache->child(iFolderIndex).base(); 324 325 /* Prepare shared folder item fields: */ 326 QStringList fields; 327 fields << folderData.m_strName 328 << folderData.m_strHostPath 329 << (folderData.m_fAutoMount ? m_strTrYes : "") 330 << (folderData.m_fWritable ? m_strTrFull : m_strTrReadOnly); 331 332 /* Create new shared folder item: */ 333 new SFTreeViewItem(root(folderData.m_type), fields, SFTreeViewItem::EllipsisFile); 334 } 352 addSharedFolderItem(m_pCache->child(iFolderIndex).base(), false /* its new? */); 335 353 336 354 /* Ensure current item fetched: */ … … 350 368 /* Get shared folder root item: */ 351 369 const SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex)); 352 const UISharedFolderType enmSharedFolderType = (UISharedFolderType)pFolderTypeRoot->text(1).toInt();353 370 354 371 /* For each shared folder of current type: */ … … 357 374 /* Get shared folder item: */ 358 375 SFTreeViewItem *pFolderItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFolderIndex)); 359 360 /* Prepare current shared folder data: */ 361 UIDataSettingsSharedFolder currentFolderData; 362 currentFolderData.m_type = enmSharedFolderType; 363 currentFolderData.m_strName = pFolderItem->getText(0); 364 currentFolderData.m_strHostPath = pFolderItem->getText(1); 365 currentFolderData.m_fAutoMount = pFolderItem->getText(2) == m_strTrYes ? true : false; 366 currentFolderData.m_fWritable = pFolderItem->getText(3) == m_strTrFull ? true : false; 367 368 /* Cache current shared folder data: */ 369 m_pCache->child(currentFolderData.m_strName).cacheCurrentData(currentFolderData); 376 m_pCache->child(pFolderItem->m_strName).cacheCurrentData(*pFolderItem); 370 377 } 371 378 } … … 425 432 m_pActionEdit->setToolTip(m_pActionEdit->whatsThis()); 426 433 m_pActionRemove->setToolTip(m_pActionRemove->whatsThis()); 427 428 m_strTrFull = tr("Full");429 m_strTrReadOnly = tr("Read-only");430 m_strTrYes = tr("Yes");431 434 } 432 435 … … 459 462 } 460 463 461 void UIMachineSettingsSF::sltAddSharedFolder() 462 { 463 /* Invoke Add-Box Dialog: */ 464 UIMachineSettingsSFDetails dlg(UIMachineSettingsSFDetails::AddType, isSharedFolderTypeSupported(ConsoleType), usedList(true), this); 465 if (dlg.exec() == QDialog::Accepted) 466 { 467 const QString strName = dlg.name(); 468 const QString strPath = dlg.path(); 469 const bool fPermanent = dlg.isPermanent(); 464 void UIMachineSettingsSF::sltAddFolder() 465 { 466 /* Configure folder details dialog: */ 467 UIMachineSettingsSFDetails dlgFolderDetails(UIMachineSettingsSFDetails::AddType, 468 isSharedFolderTypeSupported(ConsoleType), 469 usedList(true), 470 this); 471 472 /* Run folder details dialog: */ 473 if (dlgFolderDetails.exec() == QDialog::Accepted) 474 { 475 const QString strName = dlgFolderDetails.name(); 476 const QString strPath = dlgFolderDetails.path(); 477 const UISharedFolderType enmType = dlgFolderDetails.isPermanent() ? MachineType : ConsoleType; 470 478 /* Shared folder's name & path could not be empty: */ 471 479 Assert(!strName.isEmpty() && !strPath.isEmpty()); 472 /* Appending a new listview item to the root: */ 473 QStringList fields; 474 fields << strName /* name */ << strPath /* path */ 475 << (dlg.isAutoMounted() ? m_strTrYes : "" /* auto mount? */) 476 << (dlg.isWriteable() ? m_strTrFull : m_strTrReadOnly /* writable? */); 477 SFTreeViewItem *pItem = new SFTreeViewItem(root(fPermanent ? MachineType : ConsoleType), 478 fields, SFTreeViewItem::EllipsisFile); 480 481 /* Prepare new folder data: */ 482 UIDataSettingsSharedFolder newFolderData; 483 newFolderData.m_enmType = enmType; 484 newFolderData.m_strName = strName; 485 newFolderData.m_strPath = strPath; 486 newFolderData.m_fAutoMount = dlgFolderDetails.isAutoMounted(); 487 newFolderData.m_fWritable = dlgFolderDetails.isWriteable(); 488 489 /* Add new folder item: */ 490 addSharedFolderItem(newFolderData, true /* its new? */); 491 492 /* Sort tree-widget before adjusting: */ 479 493 mTwFolders->sortItems(0, Qt::AscendingOrder); 480 mTwFolders->scrollToItem(pItem); 481 mTwFolders->setCurrentItem(pItem); 482 sltHandleCurrentItemChange(pItem); 483 mTwFolders->setFocus(); 494 /* Adjust tree-widget finally: */ 484 495 sltAdjustTree(); 485 496 } 486 497 } 487 498 488 void UIMachineSettingsSF::sltEditSharedFolder() 489 { 490 /* Check selected item: */ 491 QTreeWidgetItem *pSelectedItem = mTwFolders->selectedItems().size() == 1 ? mTwFolders->selectedItems()[0] : 0; 492 SFTreeViewItem *pItem = pSelectedItem ? static_cast<SFTreeViewItem*>(pSelectedItem) : 0; 493 Assert(pItem); 494 Assert(pItem->parentItem()); 495 496 /* Invoke Edit-Box Dialog: */ 497 UIMachineSettingsSFDetails dlg(UIMachineSettingsSFDetails::EditType, isSharedFolderTypeSupported(ConsoleType), usedList(false), this); 498 dlg.setPath(pItem->getText(1)); 499 dlg.setName(pItem->getText(0)); 500 dlg.setPermanent((UISharedFolderType)pItem->parentItem()->text(1).toInt() != ConsoleType); 501 dlg.setAutoMount(pItem->getText(2) == m_strTrYes); 502 dlg.setWriteable(pItem->getText(3) == m_strTrFull); 503 if (dlg.exec() == QDialog::Accepted) 504 { 505 const QString strName = dlg.name(); 506 const QString strPath = dlg.path(); 507 const bool fPermanent = dlg.isPermanent(); 499 void UIMachineSettingsSF::sltEditFolder() 500 { 501 /* Check current folder item: */ 502 SFTreeViewItem *pItem = static_cast<SFTreeViewItem*>(mTwFolders->currentItem()); 503 AssertPtrReturnVoid(pItem); 504 AssertPtrReturnVoid(pItem->parentItem()); 505 506 /* Configure folder details dialog: */ 507 UIMachineSettingsSFDetails dlgFolderDetails(UIMachineSettingsSFDetails::EditType, 508 isSharedFolderTypeSupported(ConsoleType), 509 usedList(false), 510 this); 511 dlgFolderDetails.setPath(pItem->m_strPath); 512 dlgFolderDetails.setName(pItem->m_strName); 513 dlgFolderDetails.setPermanent(pItem->m_enmType == MachineType); 514 dlgFolderDetails.setAutoMount(pItem->m_fAutoMount); 515 dlgFolderDetails.setWriteable(pItem->m_fWritable); 516 517 /* Run folder details dialog: */ 518 if (dlgFolderDetails.exec() == QDialog::Accepted) 519 { 520 const QString strName = dlgFolderDetails.name(); 521 const QString strPath = dlgFolderDetails.path(); 522 const UISharedFolderType enmType = dlgFolderDetails.isPermanent() ? MachineType : ConsoleType; 508 523 /* Shared folder's name & path could not be empty: */ 509 524 Assert(!strName.isEmpty() && !strPath.isEmpty()); 510 /* Searching new root for the selected listview item: */ 511 SFTreeViewItem *pRoot = root(fPermanent ? MachineType : ConsoleType); 512 /* Updating an edited listview item: */ 513 QStringList fields; 514 fields << strName /* name */ << strPath /* path */ 515 << (dlg.isAutoMounted() ? m_strTrYes : "" /* auto mount? */) 516 << (dlg.isWriteable() ? m_strTrFull : m_strTrReadOnly /* writable? */); 517 pItem->updateText(fields); 518 mTwFolders->sortItems(0, Qt::AscendingOrder); 525 526 /* Update edited tree-widget item: */ 527 pItem->m_enmType = enmType; 528 pItem->m_strName = strName; 529 pItem->m_strPath = strPath; 530 pItem->m_fAutoMount = dlgFolderDetails.isAutoMounted(); 531 pItem->m_fWritable = dlgFolderDetails.isWriteable(); 532 pItem->updateFields(); 533 534 /* Searching for a root of the edited tree-widget item: */ 535 SFTreeViewItem *pRoot = root(enmType); 519 536 if (pItem->parentItem() != pRoot) 520 537 { 521 /* Move the selected item intonew location: */538 /* Move the tree-widget item to a new location: */ 522 539 pItem->parentItem()->takeChild(pItem->parentItem()->indexOfChild(pItem)); 523 540 pRoot->insertChild(pRoot->childCount(), pItem); 541 542 /* Update tree-widget: */ 524 543 mTwFolders->scrollToItem(pItem); 525 544 mTwFolders->setCurrentItem(pItem); 526 545 sltHandleCurrentItemChange(pItem); 527 mTwFolders->setFocus(); 528 } 546 } 547 548 /* Sort tree-widget before adjusting: */ 549 mTwFolders->sortItems(0, Qt::AscendingOrder); 550 /* Adjust tree-widget finally: */ 529 551 sltAdjustTree(); 530 552 } 531 553 } 532 554 533 void UIMachineSettingsSF::sltRemoveSharedFolder() 534 { 535 QTreeWidgetItem *pSelectedItem = mTwFolders->selectedItems().size() == 1 ? mTwFolders->selectedItems()[0] : 0; 536 Assert(pSelectedItem); 537 delete pSelectedItem; 555 void UIMachineSettingsSF::sltRemoveFolder() 556 { 557 /* Check current folder item: */ 558 QTreeWidgetItem *pItem = mTwFolders->currentItem(); 559 AssertPtrReturnVoid(pItem); 560 561 /* Delete corresponding item: */ 562 delete pItem; 563 564 /* Adjust tree-widget finally: */ 538 565 sltAdjustTree(); 539 566 } … … 554 581 const bool fEditEnabled = pItem && pItem->parent(); 555 582 if (fEditEnabled) 556 sltEdit SharedFolder();583 sltEditFolder(); 557 584 } 558 585 … … 610 637 for (int i = 0; i < pMainRoot->childCount(); ++i) 611 638 { 612 QTreeWidgetItem *pSubRoot = pMainRoot->child(i); 639 SFTreeViewItem *pSubRoot = static_cast<SFTreeViewItem*>(pMainRoot->child(i)); 640 pSubRoot->adjustText(); 613 641 for (int j = 0; j < pSubRoot->childCount(); ++j) 614 642 { 615 SFTreeViewItem *pItem = pSubRoot->child(j) ? static_cast <SFTreeViewItem*>(pSubRoot->child(j)) : 0; 616 if (pItem) 617 pItem->adjustText(); 643 SFTreeViewItem *pItem = static_cast<SFTreeViewItem*>(pSubRoot->child(j)); 644 pItem->adjustText(); 618 645 } 619 646 } … … 666 693 m_pActionAdd = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_add_16px.png", 667 694 ":/sf_add_disabled_16px.png"), 668 QString(), this, SLOT(sltAdd SharedFolder()));695 QString(), this, SLOT(sltAddFolder())); 669 696 AssertPtrReturnVoid(m_pActionAdd); 670 697 { … … 676 703 m_pActionEdit = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_edit_16px.png", 677 704 ":/sf_edit_disabled_16px.png"), 678 QString(), this, SLOT(sltEdit SharedFolder()));705 QString(), this, SLOT(sltEditFolder())); 679 706 AssertPtrReturnVoid(m_pActionEdit); 680 707 { … … 686 713 m_pActionRemove = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_remove_16px.png", 687 714 ":/sf_remove_disabled_16px.png"), 688 QString(), this, SLOT(sltRemove SharedFolder()));715 QString(), this, SLOT(sltRemoveFolder())); 689 716 AssertPtrReturnVoid(m_pActionRemove); 690 717 { … … 721 748 { 722 749 /* Get iterated item: */ 723 QTreeWidgetItem *pIteratedItem = pMainRootItem->child(iFolderTypeIndex);750 SFTreeViewItem *pIteratedItem = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex)); 724 751 /* If iterated item type is what we are looking for: */ 725 if (pIteratedItem-> text(1).toInt()== enmSharedFolderType)752 if (pIteratedItem->m_enmType == enmSharedFolderType) 726 753 { 727 754 /* Remember the item: */ … … 781 808 if (!pRootItem) 782 809 { 783 /* Prepare fields for the new root item: */ 784 QStringList fields; 785 /* Depending on folder type: */ 786 switch (enmSharedFolderType) 787 { 788 case MachineType: 789 fields << tr(" Machine Folders") << QString::number(MachineType); 790 break; 791 case ConsoleType: 792 fields << tr(" Transient Folders") << QString::number(ConsoleType); 793 break; 794 default: 795 break; 796 } 797 /* And create the new root item: */ 798 pRootItem = new SFTreeViewItem(mTwFolders, fields, SFTreeViewItem::EllipsisEnd); 810 /* Create new shared folder type item: */ 811 pRootItem = new SFTreeViewItem(mTwFolders, SFTreeViewItem::FormatType_EllipsisEnd); 812 AssertPtrReturnVoid(pRootItem); 813 { 814 /* Configure item: */ 815 pRootItem->m_enmType = enmSharedFolderType; 816 switch (enmSharedFolderType) 817 { 818 case MachineType: pRootItem->m_strName = tr(" Machine Folders"); break; 819 case ConsoleType: pRootItem->m_strName = tr(" Transient Folders"); break; 820 default: break; 821 } 822 pRootItem->updateFields(); 823 } 799 824 } 800 825 /* Expand/collaps it if necessary: */ … … 830 855 } 831 856 857 void UIMachineSettingsSF::addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose) 858 { 859 /* Create shared folder item: */ 860 SFTreeViewItem *pItem = new SFTreeViewItem(root(sharedFolderData.m_enmType), SFTreeViewItem::FormatType_EllipsisFile); 861 AssertPtrReturnVoid(pItem); 862 { 863 /* Configure item: */ 864 pItem->m_enmType = sharedFolderData.m_enmType; 865 pItem->m_strName = sharedFolderData.m_strName; 866 pItem->m_strPath = sharedFolderData.m_strPath; 867 pItem->m_fAutoMount = sharedFolderData.m_fAutoMount; 868 pItem->m_fWritable = sharedFolderData.m_fWritable; 869 pItem->updateFields(); 870 871 /* Select this item if it's new: */ 872 if (fChoose) 873 { 874 mTwFolders->scrollToItem(pItem); 875 mTwFolders->setCurrentItem(pItem); 876 sltHandleCurrentItemChange(pItem); 877 } 878 } 879 } 880 832 881 bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache) 833 882 { … … 835 884 const UIDataSettingsSharedFolder &folderData = folderCache.data(); 836 885 const QString strName = folderData.m_strName; 837 const QString strPath = folderData.m_str HostPath;886 const QString strPath = folderData.m_strPath; 838 887 const bool fIsWritable = folderData.m_fWritable; 839 888 const bool fIsAutoMount = folderData.m_fAutoMount; 840 const UISharedFolderType enmSharedFoldersType = folderData.m_ type;889 const UISharedFolderType enmSharedFoldersType = folderData.m_enmType; 841 890 842 891 /* Get current shared folders: */ … … 894 943 const UIDataSettingsSharedFolder &folderData = folderCache.base(); 895 944 const QString strName = folderData.m_strName; 896 const QString strPath = folderData.m_str HostPath;897 const UISharedFolderType enmSharedFoldersType = folderData.m_ type;945 const QString strPath = folderData.m_strPath; 946 const UISharedFolderType enmSharedFoldersType = folderData.m_enmType; 898 947 899 948 /* Get current shared folders: */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h
r66383 r66451 82 82 83 83 /** Handles command to add shared folder. */ 84 void sltAdd SharedFolder();84 void sltAddFolder(); 85 85 /** Handles command to edit shared folder. */ 86 void sltEdit SharedFolder();86 void sltEditFolder(); 87 87 /** Handles command to remove shared folder. */ 88 void sltRemove SharedFolder();88 void sltRemoveFolder(); 89 89 90 90 /** Handles @a pCurrentItem change. */ … … 128 128 CSharedFolderVector getSharedFolders(UISharedFolderType enmSharedFoldersType); 129 129 130 /** Creates shared folder item based on passed @a data. */ 131 void addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose); 132 130 133 /** Creates shared folder defined by a @a folderCache. */ 131 134 bool createSharedFolder(const UISettingsCacheSharedFolder &folderCache); … … 140 143 QAction *m_pActionRemove; 141 144 142 /** Holds the "Full" access translation tag. */143 QString m_strTrFull;144 /** Holds the "Read-only" access translation tag. */145 QString m_strTrReadOnly;146 /** Holds the "Yes" for auto-mount translation tag. */147 QString m_strTrYes;148 149 145 /** Holds the page data cache instance. */ 150 146 UISettingsCacheSharedFolders *m_pCache;
Note:
See TracChangeset
for help on using the changeset viewer.