Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp	(revision 66450)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp	(revision 66451)
@@ -40,7 +40,7 @@
     /** Constructs data. */
     UIDataSettingsSharedFolder()
-        : m_type(MachineType)
+        : m_enmType(MachineType)
         , m_strName(QString())
-        , m_strHostPath(QString())
+        , m_strPath(QString())
         , m_fAutoMount(false)
         , m_fWritable(false)
@@ -51,7 +51,7 @@
     {
         return true
-               && (m_type == other.m_type)
+               && (m_enmType == other.m_enmType)
                && (m_strName == other.m_strName)
-               && (m_strHostPath == other.m_strHostPath)
+               && (m_strPath == other.m_strPath)
                && (m_fAutoMount == other.m_fAutoMount)
                && (m_fWritable == other.m_fWritable)
@@ -65,9 +65,9 @@
 
     /** Holds the shared folder type. */
-    UISharedFolderType  m_type;
+    UISharedFolderType  m_enmType;
     /** Holds the shared folder name. */
     QString             m_strName;
     /** Holds the shared folder path. */
-    QString             m_strHostPath;
+    QString             m_strPath;
     /** Holds whether the shared folder should be auto-mounted at startup. */
     bool                m_fAutoMount;
@@ -90,62 +90,89 @@
 
 
-class SFTreeViewItem : public QITreeWidgetItem
+/** Machine settings: Shared Folder tree-widget item. */
+class SFTreeViewItem : public QITreeWidgetItem, public UIDataSettingsSharedFolder
 {
 public:
 
+    /** Format type. */
     enum FormatType
     {
-        IncorrectFormat = 0,
-        EllipsisStart   = 1,
-        EllipsisMiddle  = 2,
-        EllipsisEnd     = 3,
-        EllipsisFile    = 4
+        FormatType_Invalid,
+        FormatType_EllipsisStart,
+        FormatType_EllipsisMiddle,
+        FormatType_EllipsisEnd,
+        FormatType_EllipsisFile,
     };
 
-    /* Root Item */
-    SFTreeViewItem (QITreeWidget *aParent, const QStringList &aFields, FormatType aFormat)
-        : QITreeWidgetItem (aParent, aFields), mFormat (aFormat)
-    {
-        setFirstColumnSpanned (true);
-        setFlags (flags() ^ Qt::ItemIsSelectable);
-    }
-
-    /* Child Item */
-    SFTreeViewItem (SFTreeViewItem *aParent, const QStringList &aFields, FormatType aFormat)
-        : QITreeWidgetItem (aParent, aFields), mFormat (aFormat)
-    {
-        updateText (aFields);
-    }
-
-    bool operator< (const QTreeWidgetItem &aOther) const
-    {
-        /* Root items should always been sorted by id-field. */
-        return parentItem() ? text (0).toLower() < aOther.text (0).toLower() :
-                              text (1).toLower() < aOther.text (1).toLower();
-    }
-
-    SFTreeViewItem* child (int aIndex) const
-    {
-        QTreeWidgetItem *item = QTreeWidgetItem::child (aIndex);
-        return item ? static_cast <SFTreeViewItem*> (item) : 0;
-    }
-
-    QString getText (int aIndex) const
-    {
-        return aIndex >= 0 && aIndex < (int)mTextList.size() ? mTextList [aIndex] : QString::null;
-    }
-
-    void updateText (const QStringList &aFields)
-    {
-        mTextList.clear();
-        mTextList << aFields;
+    /** Constructs shared folder type (root) item.
+      * @param  pParent    Brings the item parent.
+      * @param  enmFormat  Brings the item format type. */
+    SFTreeViewItem(QITreeWidget *pParent, FormatType enmFormat)
+        : QITreeWidgetItem(pParent)
+        , m_enmFormat(enmFormat)
+    {
+        setFirstColumnSpanned(true);
+        setFlags(flags() ^ Qt::ItemIsSelectable);
+    }
+
+    /** Constructs shared folder (child) item.
+      * @param  pParent    Brings the item parent.
+      * @param  enmFormat  Brings the item format type. */
+    SFTreeViewItem(SFTreeViewItem *pParent, FormatType enmFormat)
+        : QITreeWidgetItem(pParent)
+        , m_enmFormat(enmFormat)
+    {
+    }
+
+    /** Returns whether this item is less than the @a other one. */
+    bool operator<(const QTreeWidgetItem &other) const
+    {
+        /* Root items should always been sorted by type field: */
+        return parentItem() ? text(0) < other.text(0) :
+                              text(1) < other.text(1);
+    }
+
+    /** Returns child item number @a iIndex. */
+    SFTreeViewItem *child(int iIndex) const
+    {
+        QTreeWidgetItem *pItem = QTreeWidgetItem::child(iIndex);
+        return pItem ? static_cast<SFTreeViewItem*>(pItem) : 0;
+    }
+
+    /** Returns text of item number @a iIndex. */
+    QString getText(int iIndex) const
+    {
+        return iIndex >= 0 && iIndex < m_fields.size() ? m_fields.at(iIndex) : QString();
+    }
+
+    /** Updates item fields. */
+    void updateFields()
+    {
+        /* Clear fields: */
+        m_fields.clear();
+
+        /* For root items: */
+        if (!parentItem())
+            m_fields << m_strName
+                     << QString::number((int)m_enmType);
+        /* For child items: */
+        else
+            m_fields << m_strName
+                     << m_strPath
+                     << (m_fAutoMount ? UIMachineSettingsSF::tr("Yes") : "")
+                     << (m_fWritable ? UIMachineSettingsSF::tr("Full") : UIMachineSettingsSF::tr("Read-only"));
+
+        /* Adjust item layout: */
         adjustText();
     }
 
+    /** Adjusts item layout. */
     void adjustText()
     {
-        for (int i = 0; i < treeWidget()->columnCount(); ++ i)
-            processColumn (i);
-    }
+        for (int i = 0; i < treeWidget()->columnCount(); ++i)
+            processColumn(i);
+    }
+
+protected:
 
     /** Returns default text. */
@@ -155,8 +182,8 @@
                tr("%1, %2: %3, %4: %5, %6: %7",
                   "col.1 text, col.2 name: col.2 text, col.3 name: col.3 text, col.4 name: col.4 text")
-                 .arg(text(0))
-                 .arg(parentTree()->headerItem()->text(1)).arg(text(1))
-                 .arg(parentTree()->headerItem()->text(2)).arg(text(2))
-                 .arg(parentTree()->headerItem()->text(3)).arg(text(3)) :
+                  .arg(text(0))
+                  .arg(parentTree()->headerItem()->text(1)).arg(text(1))
+                  .arg(parentTree()->headerItem()->text(2)).arg(text(2))
+                  .arg(parentTree()->headerItem()->text(3)).arg(text(3)) :
                text(0);
     }
@@ -164,74 +191,78 @@
 private:
 
-    void processColumn (int aColumn)
-    {
-        QString oneString = getText (aColumn);
-        if (oneString.isNull())
+    /** Performs item @a iColumn processing. */
+    void processColumn(int iColumn)
+    {
+        QString strOneString = getText(iColumn);
+        if (strOneString.isNull())
             return;
-        QFontMetrics fm = treeWidget()->fontMetrics();
-        int oldSize = fm.width (oneString);
-        int indentSize = fm.width (" ... ");
-        int itemIndent = parentItem() ? treeWidget()->indentation() * 2 : treeWidget()->indentation();
-        if (aColumn == 0)
-            indentSize += itemIndent;
-        int cWidth = treeWidget()->columnWidth (aColumn);
-
-        /* Compress text */
-        int start = 0;
-        int finish = 0;
-        int position = 0;
-        int textWidth = 0;
+        const QFontMetrics fm = treeWidget()->fontMetrics();
+        const int iOldSize = fm.width(strOneString);
+        const int iItemIndent = parentItem() ? treeWidget()->indentation() * 2 : treeWidget()->indentation();
+        int iIndentSize = fm.width(" ... ");
+        if (iColumn == 0)
+            iIndentSize += iItemIndent;
+        const int cWidth = !parentItem() ? treeWidget()->viewport()->width() : treeWidget()->columnWidth(iColumn);
+
+        /* Compress text: */
+        int iStart = 0;
+        int iFinish = 0;
+        int iPosition = 0;
+        int iTextWidth = 0;
         do
         {
-            textWidth = fm.width (oneString);
-            if (textWidth + indentSize > cWidth)
+            iTextWidth = fm.width(strOneString);
+            if (iTextWidth + iIndentSize > cWidth)
             {
-                start  = 0;
-                finish = oneString.length();
-
-                /* Selecting remove position */
-                switch (mFormat)
+                iStart = 0;
+                iFinish = strOneString.length();
+
+                /* Selecting remove position: */
+                switch (m_enmFormat)
                 {
-                    case EllipsisStart:
-                        position = start;
+                    case FormatType_EllipsisStart:
+                        iPosition = iStart;
                         break;
-                    case EllipsisMiddle:
-                        position = (finish - start) / 2;
+                    case FormatType_EllipsisMiddle:
+                        iPosition = (iFinish - iStart) / 2;
                         break;
-                    case EllipsisEnd:
-                        position = finish - 1;
+                    case FormatType_EllipsisEnd:
+                        iPosition = iFinish - 1;
                         break;
-                    case EllipsisFile:
+                    case FormatType_EllipsisFile:
                     {
-                        QRegExp regExp ("([\\\\/][^\\\\^/]+[\\\\/]?$)");
-                        int newFinish = regExp.indexIn (oneString);
-                        if (newFinish != -1)
-                            finish = newFinish;
-                        position = (finish - start) / 2;
+                        const QRegExp regExp("([\\\\/][^\\\\^/]+[\\\\/]?$)");
+                        const int iNewFinish = regExp.indexIn(strOneString);
+                        if (iNewFinish != -1)
+                            iFinish = iNewFinish;
+                        iPosition = (iFinish - iStart) / 2;
                         break;
                     }
                     default:
-                        AssertMsgFailed (("Invalid format type\n"));
+                        AssertMsgFailed(("Invalid format type\n"));
                 }
 
-                if (position == finish)
+                if (iPosition == iFinish)
                    break;
 
-                oneString.remove (position, 1);
+                strOneString.remove(iPosition, 1);
             }
         }
-        while (textWidth + indentSize > cWidth);
-
-        if (position || mFormat == EllipsisFile) oneString.insert (position, "...");
-        int newSize = fm.width (oneString);
-        setText (aColumn, newSize < oldSize ? oneString : mTextList [aColumn]);
-        setToolTip (aColumn, text (aColumn) == getText (aColumn) ? QString::null : getText (aColumn));
-
-        /* Calculate item's size-hint */
-        setSizeHint (aColumn, QSize (fm.width (QString ("  %1  ").arg (getText (aColumn))), 100));
-    }
-
-    FormatType  mFormat;
-    QStringList mTextList;
+        while (iTextWidth + iIndentSize > cWidth);
+
+        if (iPosition || m_enmFormat == FormatType_EllipsisFile)
+            strOneString.insert(iPosition, "...");
+        const int iNewSize = fm.width(strOneString);
+        setText(iColumn, iNewSize < iOldSize ? strOneString : m_fields.at(iColumn));
+        setToolTip(iColumn, text(iColumn) == getText(iColumn) ? QString() : getText(iColumn));
+
+        /* Calculate item's size-hint: */
+        setSizeHint(iColumn, QSize(fm.width(QString("  %1  ").arg(getText(iColumn))), fm.height()));
+    }
+
+    /** Holds the item format type. */
+    FormatType   m_enmFormat;
+    /** Holds the item text fields. */
+    QStringList  m_fields;
 };
 
@@ -291,7 +322,7 @@
             {
                 /* Gather shared folder values: */
-                initialFolderData.m_type = enmFolderType;
+                initialFolderData.m_enmType = enmFolderType;
                 initialFolderData.m_strName = folder.GetName();
-                initialFolderData.m_strHostPath = folder.GetHostPath();
+                initialFolderData.m_strPath = folder.GetHostPath();
                 initialFolderData.m_fAutoMount = folder.GetAutoMount();
                 initialFolderData.m_fWritable = folder.GetWritable();
@@ -319,18 +350,5 @@
     /* For each shared folder: */
     for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex)
-    {
-        /* Acquire corresponding folder data: */
-        const UIDataSettingsSharedFolder &folderData = m_pCache->child(iFolderIndex).base();
-
-        /* Prepare shared folder item fields: */
-        QStringList fields;
-        fields << folderData.m_strName
-               << folderData.m_strHostPath
-               << (folderData.m_fAutoMount ? m_strTrYes : "")
-               << (folderData.m_fWritable ? m_strTrFull : m_strTrReadOnly);
-
-        /* Create new shared folder item: */
-        new SFTreeViewItem(root(folderData.m_type), fields, SFTreeViewItem::EllipsisFile);
-    }
+        addSharedFolderItem(m_pCache->child(iFolderIndex).base(), false /* its new? */);
 
     /* Ensure current item fetched: */
@@ -350,5 +368,4 @@
         /* Get shared folder root item: */
         const SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex));
-        const UISharedFolderType enmSharedFolderType = (UISharedFolderType)pFolderTypeRoot->text(1).toInt();
 
         /* For each shared folder of current type: */
@@ -357,15 +374,5 @@
             /* Get shared folder item: */
             SFTreeViewItem *pFolderItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFolderIndex));
-
-            /* Prepare current shared folder data: */
-            UIDataSettingsSharedFolder currentFolderData;
-            currentFolderData.m_type = enmSharedFolderType;
-            currentFolderData.m_strName = pFolderItem->getText(0);
-            currentFolderData.m_strHostPath = pFolderItem->getText(1);
-            currentFolderData.m_fAutoMount = pFolderItem->getText(2) == m_strTrYes ? true : false;
-            currentFolderData.m_fWritable = pFolderItem->getText(3) == m_strTrFull ? true : false;
-
-            /* Cache current shared folder data: */
-            m_pCache->child(currentFolderData.m_strName).cacheCurrentData(currentFolderData);
+            m_pCache->child(pFolderItem->m_strName).cacheCurrentData(*pFolderItem);
         }
     }
@@ -425,8 +432,4 @@
     m_pActionEdit->setToolTip(m_pActionEdit->whatsThis());
     m_pActionRemove->setToolTip(m_pActionRemove->whatsThis());
-
-    m_strTrFull = tr("Full");
-    m_strTrReadOnly = tr("Read-only");
-    m_strTrYes = tr("Yes");
 }
 
@@ -459,81 +462,105 @@
 }
 
-void UIMachineSettingsSF::sltAddSharedFolder()
-{
-    /* Invoke Add-Box Dialog: */
-    UIMachineSettingsSFDetails dlg(UIMachineSettingsSFDetails::AddType, isSharedFolderTypeSupported(ConsoleType), usedList(true), this);
-    if (dlg.exec() == QDialog::Accepted)
-    {
-        const QString strName = dlg.name();
-        const QString strPath = dlg.path();
-        const bool fPermanent = dlg.isPermanent();
+void UIMachineSettingsSF::sltAddFolder()
+{
+    /* Configure folder details dialog: */
+    UIMachineSettingsSFDetails dlgFolderDetails(UIMachineSettingsSFDetails::AddType,
+                                                isSharedFolderTypeSupported(ConsoleType),
+                                                usedList(true),
+                                                this);
+
+    /* Run folder details dialog: */
+    if (dlgFolderDetails.exec() == QDialog::Accepted)
+    {
+        const QString strName = dlgFolderDetails.name();
+        const QString strPath = dlgFolderDetails.path();
+        const UISharedFolderType enmType = dlgFolderDetails.isPermanent() ? MachineType : ConsoleType;
         /* Shared folder's name & path could not be empty: */
         Assert(!strName.isEmpty() && !strPath.isEmpty());
-        /* Appending a new listview item to the root: */
-        QStringList fields;
-        fields << strName /* name */ << strPath /* path */
-               << (dlg.isAutoMounted() ? m_strTrYes : "" /* auto mount? */)
-               << (dlg.isWriteable() ? m_strTrFull : m_strTrReadOnly /* writable? */);
-        SFTreeViewItem *pItem = new SFTreeViewItem(root(fPermanent ? MachineType : ConsoleType),
-                                                   fields, SFTreeViewItem::EllipsisFile);
+
+        /* Prepare new folder data: */
+        UIDataSettingsSharedFolder newFolderData;
+        newFolderData.m_enmType = enmType;
+        newFolderData.m_strName = strName;
+        newFolderData.m_strPath = strPath;
+        newFolderData.m_fAutoMount = dlgFolderDetails.isAutoMounted();
+        newFolderData.m_fWritable = dlgFolderDetails.isWriteable();
+
+        /* Add new folder item: */
+        addSharedFolderItem(newFolderData, true /* its new? */);
+
+        /* Sort tree-widget before adjusting: */
         mTwFolders->sortItems(0, Qt::AscendingOrder);
-        mTwFolders->scrollToItem(pItem);
-        mTwFolders->setCurrentItem(pItem);
-        sltHandleCurrentItemChange(pItem);
-        mTwFolders->setFocus();
+        /* Adjust tree-widget finally: */
         sltAdjustTree();
     }
 }
 
-void UIMachineSettingsSF::sltEditSharedFolder()
-{
-    /* Check selected item: */
-    QTreeWidgetItem *pSelectedItem = mTwFolders->selectedItems().size() == 1 ? mTwFolders->selectedItems()[0] : 0;
-    SFTreeViewItem *pItem = pSelectedItem ? static_cast<SFTreeViewItem*>(pSelectedItem) : 0;
-    Assert(pItem);
-    Assert(pItem->parentItem());
-
-    /* Invoke Edit-Box Dialog: */
-    UIMachineSettingsSFDetails dlg(UIMachineSettingsSFDetails::EditType, isSharedFolderTypeSupported(ConsoleType), usedList(false), this);
-    dlg.setPath(pItem->getText(1));
-    dlg.setName(pItem->getText(0));
-    dlg.setPermanent((UISharedFolderType)pItem->parentItem()->text(1).toInt() != ConsoleType);
-    dlg.setAutoMount(pItem->getText(2) == m_strTrYes);
-    dlg.setWriteable(pItem->getText(3) == m_strTrFull);
-    if (dlg.exec() == QDialog::Accepted)
-    {
-        const QString strName = dlg.name();
-        const QString strPath = dlg.path();
-        const bool fPermanent = dlg.isPermanent();
+void UIMachineSettingsSF::sltEditFolder()
+{
+    /* Check current folder item: */
+    SFTreeViewItem *pItem = static_cast<SFTreeViewItem*>(mTwFolders->currentItem());
+    AssertPtrReturnVoid(pItem);
+    AssertPtrReturnVoid(pItem->parentItem());
+
+    /* Configure folder details dialog: */
+    UIMachineSettingsSFDetails dlgFolderDetails(UIMachineSettingsSFDetails::EditType,
+                                                isSharedFolderTypeSupported(ConsoleType),
+                                                usedList(false),
+                                                this);
+    dlgFolderDetails.setPath(pItem->m_strPath);
+    dlgFolderDetails.setName(pItem->m_strName);
+    dlgFolderDetails.setPermanent(pItem->m_enmType == MachineType);
+    dlgFolderDetails.setAutoMount(pItem->m_fAutoMount);
+    dlgFolderDetails.setWriteable(pItem->m_fWritable);
+
+    /* Run folder details dialog: */
+    if (dlgFolderDetails.exec() == QDialog::Accepted)
+    {
+        const QString strName = dlgFolderDetails.name();
+        const QString strPath = dlgFolderDetails.path();
+        const UISharedFolderType enmType = dlgFolderDetails.isPermanent() ? MachineType : ConsoleType;
         /* Shared folder's name & path could not be empty: */
         Assert(!strName.isEmpty() && !strPath.isEmpty());
-        /* Searching new root for the selected listview item: */
-        SFTreeViewItem *pRoot = root(fPermanent ? MachineType : ConsoleType);
-        /* Updating an edited listview item: */
-        QStringList fields;
-        fields << strName /* name */ << strPath /* path */
-               << (dlg.isAutoMounted() ? m_strTrYes : "" /* auto mount? */)
-               << (dlg.isWriteable() ? m_strTrFull : m_strTrReadOnly /* writable? */);
-        pItem->updateText(fields);
-        mTwFolders->sortItems(0, Qt::AscendingOrder);
+
+        /* Update edited tree-widget item: */
+        pItem->m_enmType = enmType;
+        pItem->m_strName = strName;
+        pItem->m_strPath = strPath;
+        pItem->m_fAutoMount = dlgFolderDetails.isAutoMounted();
+        pItem->m_fWritable = dlgFolderDetails.isWriteable();
+        pItem->updateFields();
+
+        /* Searching for a root of the edited tree-widget item: */
+        SFTreeViewItem *pRoot = root(enmType);
         if (pItem->parentItem() != pRoot)
         {
-            /* Move the selected item into new location: */
+            /* Move the tree-widget item to a new location: */
             pItem->parentItem()->takeChild(pItem->parentItem()->indexOfChild(pItem));
             pRoot->insertChild(pRoot->childCount(), pItem);
+
+            /* Update tree-widget: */
             mTwFolders->scrollToItem(pItem);
             mTwFolders->setCurrentItem(pItem);
             sltHandleCurrentItemChange(pItem);
-            mTwFolders->setFocus();
-        }
+        }
+
+        /* Sort tree-widget before adjusting: */
+        mTwFolders->sortItems(0, Qt::AscendingOrder);
+        /* Adjust tree-widget finally: */
         sltAdjustTree();
     }
 }
 
-void UIMachineSettingsSF::sltRemoveSharedFolder()
-{
-    QTreeWidgetItem *pSelectedItem = mTwFolders->selectedItems().size() == 1 ? mTwFolders->selectedItems()[0] : 0;
-    Assert(pSelectedItem);
-    delete pSelectedItem;
+void UIMachineSettingsSF::sltRemoveFolder()
+{
+    /* Check current folder item: */
+    QTreeWidgetItem *pItem = mTwFolders->currentItem();
+    AssertPtrReturnVoid(pItem);
+
+    /* Delete corresponding item: */
+    delete pItem;
+
+    /* Adjust tree-widget finally: */
     sltAdjustTree();
 }
@@ -554,5 +581,5 @@
     const bool fEditEnabled = pItem && pItem->parent();
     if (fEditEnabled)
-        sltEditSharedFolder();
+        sltEditFolder();
 }
 
@@ -610,10 +637,10 @@
     for (int i = 0; i < pMainRoot->childCount(); ++i)
     {
-        QTreeWidgetItem *pSubRoot = pMainRoot->child(i);
+        SFTreeViewItem *pSubRoot = static_cast<SFTreeViewItem*>(pMainRoot->child(i));
+        pSubRoot->adjustText();
         for (int j = 0; j < pSubRoot->childCount(); ++j)
         {
-            SFTreeViewItem *pItem = pSubRoot->child(j) ? static_cast <SFTreeViewItem*>(pSubRoot->child(j)) : 0;
-            if (pItem)
-                pItem->adjustText();
+            SFTreeViewItem *pItem = static_cast<SFTreeViewItem*>(pSubRoot->child(j));
+            pItem->adjustText();
         }
     }
@@ -666,5 +693,5 @@
         m_pActionAdd = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_add_16px.png",
                                                                         ":/sf_add_disabled_16px.png"),
-                                                    QString(), this, SLOT(sltAddSharedFolder()));
+                                                    QString(), this, SLOT(sltAddFolder()));
         AssertPtrReturnVoid(m_pActionAdd);
         {
@@ -676,5 +703,5 @@
         m_pActionEdit = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_edit_16px.png",
                                                                          ":/sf_edit_disabled_16px.png"),
-                                                     QString(), this, SLOT(sltEditSharedFolder()));
+                                                     QString(), this, SLOT(sltEditFolder()));
         AssertPtrReturnVoid(m_pActionEdit);
         {
@@ -686,5 +713,5 @@
         m_pActionRemove = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_remove_16px.png",
                                                                            ":/sf_remove_disabled_16px.png"),
-                                                       QString(), this, SLOT(sltRemoveSharedFolder()));
+                                                       QString(), this, SLOT(sltRemoveFolder()));
         AssertPtrReturnVoid(m_pActionRemove);
         {
@@ -721,7 +748,7 @@
     {
         /* Get iterated item: */
-        QTreeWidgetItem *pIteratedItem = pMainRootItem->child(iFolderTypeIndex);
+        SFTreeViewItem *pIteratedItem = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex));
         /* If iterated item type is what we are looking for: */
-        if (pIteratedItem->text(1).toInt() == enmSharedFolderType)
+        if (pIteratedItem->m_enmType == enmSharedFolderType)
         {
             /* Remember the item: */
@@ -781,20 +808,18 @@
     if (!pRootItem)
     {
-        /* Prepare fields for the new root item: */
-        QStringList fields;
-        /* Depending on folder type: */
-        switch (enmSharedFolderType)
-        {
-            case MachineType:
-                fields << tr(" Machine Folders") << QString::number(MachineType);
-                break;
-            case ConsoleType:
-                fields << tr(" Transient Folders") << QString::number(ConsoleType);
-                break;
-            default:
-                break;
-        }
-        /* And create the new root item: */
-        pRootItem = new SFTreeViewItem(mTwFolders, fields, SFTreeViewItem::EllipsisEnd);
+        /* Create new shared folder type item: */
+        pRootItem = new SFTreeViewItem(mTwFolders, SFTreeViewItem::FormatType_EllipsisEnd);
+        AssertPtrReturnVoid(pRootItem);
+        {
+            /* Configure item: */
+            pRootItem->m_enmType = enmSharedFolderType;
+            switch (enmSharedFolderType)
+            {
+                case MachineType: pRootItem->m_strName = tr(" Machine Folders"); break;
+                case ConsoleType: pRootItem->m_strName = tr(" Transient Folders"); break;
+                default: break;
+            }
+            pRootItem->updateFields();
+        }
     }
     /* Expand/collaps it if necessary: */
@@ -830,4 +855,28 @@
 }
 
+void UIMachineSettingsSF::addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose)
+{
+    /* Create shared folder item: */
+    SFTreeViewItem *pItem = new SFTreeViewItem(root(sharedFolderData.m_enmType), SFTreeViewItem::FormatType_EllipsisFile);
+    AssertPtrReturnVoid(pItem);
+    {
+        /* Configure item: */
+        pItem->m_enmType = sharedFolderData.m_enmType;
+        pItem->m_strName = sharedFolderData.m_strName;
+        pItem->m_strPath = sharedFolderData.m_strPath;
+        pItem->m_fAutoMount = sharedFolderData.m_fAutoMount;
+        pItem->m_fWritable = sharedFolderData.m_fWritable;
+        pItem->updateFields();
+
+        /* Select this item if it's new: */
+        if (fChoose)
+        {
+            mTwFolders->scrollToItem(pItem);
+            mTwFolders->setCurrentItem(pItem);
+            sltHandleCurrentItemChange(pItem);
+        }
+    }
+}
+
 bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache)
 {
@@ -835,8 +884,8 @@
     const UIDataSettingsSharedFolder &folderData = folderCache.data();
     const QString strName = folderData.m_strName;
-    const QString strPath = folderData.m_strHostPath;
+    const QString strPath = folderData.m_strPath;
     const bool fIsWritable = folderData.m_fWritable;
     const bool fIsAutoMount = folderData.m_fAutoMount;
-    const UISharedFolderType enmSharedFoldersType = folderData.m_type;
+    const UISharedFolderType enmSharedFoldersType = folderData.m_enmType;
 
     /* Get current shared folders: */
@@ -894,6 +943,6 @@
     const UIDataSettingsSharedFolder &folderData = folderCache.base();
     const QString strName = folderData.m_strName;
-    const QString strPath = folderData.m_strHostPath;
-    const UISharedFolderType enmSharedFoldersType = folderData.m_type;
+    const QString strPath = folderData.m_strPath;
+    const UISharedFolderType enmSharedFoldersType = folderData.m_enmType;
 
     /* Get current shared folders: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h	(revision 66450)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h	(revision 66451)
@@ -82,9 +82,9 @@
 
     /** Handles command to add shared folder. */
-    void sltAddSharedFolder();
+    void sltAddFolder();
     /** Handles command to edit shared folder. */
-    void sltEditSharedFolder();
+    void sltEditFolder();
     /** Handles command to remove shared folder. */
-    void sltRemoveSharedFolder();
+    void sltRemoveFolder();
 
     /** Handles @a pCurrentItem change. */
@@ -128,4 +128,7 @@
     CSharedFolderVector getSharedFolders(UISharedFolderType enmSharedFoldersType);
 
+    /** Creates shared folder item based on passed @a data. */
+    void addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose);
+
     /** Creates shared folder defined by a @a folderCache. */
     bool createSharedFolder(const UISettingsCacheSharedFolder &folderCache);
@@ -140,11 +143,4 @@
     QAction *m_pActionRemove;
 
-    /** Holds the "Full" access translation tag. */
-    QString  m_strTrFull;
-    /** Holds the "Read-only" access translation tag. */
-    QString  m_strTrReadOnly;
-    /** Holds the "Yes" for auto-mount translation tag. */
-    QString  m_strTrYes;
-
     /** Holds the page data cache instance. */
     UISettingsCacheSharedFolders *m_pCache;
