VirtualBox

Changeset 66451 in vbox


Ignore:
Timestamp:
Apr 6, 2017 8:45:04 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114431
Message:

FE/Qt: Machine settings: Shared Folders page: Reworking shared folder tree-widget item to inherit data structure as done for USB filter tree-widget item.

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  
    4040    /** Constructs data. */
    4141    UIDataSettingsSharedFolder()
    42         : m_type(MachineType)
     42        : m_enmType(MachineType)
    4343        , m_strName(QString())
    44         , m_strHostPath(QString())
     44        , m_strPath(QString())
    4545        , m_fAutoMount(false)
    4646        , m_fWritable(false)
     
    5151    {
    5252        return true
    53                && (m_type == other.m_type)
     53               && (m_enmType == other.m_enmType)
    5454               && (m_strName == other.m_strName)
    55                && (m_strHostPath == other.m_strHostPath)
     55               && (m_strPath == other.m_strPath)
    5656               && (m_fAutoMount == other.m_fAutoMount)
    5757               && (m_fWritable == other.m_fWritable)
     
    6565
    6666    /** Holds the shared folder type. */
    67     UISharedFolderType  m_type;
     67    UISharedFolderType  m_enmType;
    6868    /** Holds the shared folder name. */
    6969    QString             m_strName;
    7070    /** Holds the shared folder path. */
    71     QString             m_strHostPath;
     71    QString             m_strPath;
    7272    /** Holds whether the shared folder should be auto-mounted at startup. */
    7373    bool                m_fAutoMount;
     
    9090
    9191
    92 class SFTreeViewItem : public QITreeWidgetItem
     92/** Machine settings: Shared Folder tree-widget item. */
     93class SFTreeViewItem : public QITreeWidgetItem, public UIDataSettingsSharedFolder
    9394{
    9495public:
    9596
     97    /** Format type. */
    9698    enum FormatType
    9799    {
    98         IncorrectFormat = 0,
    99         EllipsisStart   = 1,
    100         EllipsisMiddle  = 2,
    101         EllipsisEnd     = 3,
    102         EllipsisFile    = 4
     100        FormatType_Invalid,
     101        FormatType_EllipsisStart,
     102        FormatType_EllipsisMiddle,
     103        FormatType_EllipsisEnd,
     104        FormatType_EllipsisFile,
    103105    };
    104106
    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: */
    142166        adjustText();
    143167    }
    144168
     169    /** Adjusts item layout. */
    145170    void adjustText()
    146171    {
    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
     176protected:
    150177
    151178    /** Returns default text. */
     
    155182               tr("%1, %2: %3, %4: %5, %6: %7",
    156183                  "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)) :
    161188               text(0);
    162189    }
     
    164191private:
    165192
    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())
    170198            return;
    171         QFontMetrics fm = treeWidget()->fontMetrics();
    172         int oldSize = fm.width (oneString);
    173         int indentSize = fm.width (" ... ");
    174         int itemIndent = parentItem() ? treeWidget()->indentation() * 2 : treeWidget()->indentation();
    175         if (aColumn == 0)
    176             indentSize += 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;
    184212        do
    185213        {
    186             textWidth = fm.width (oneString);
    187             if (textWidth + indentSize > cWidth)
     214            iTextWidth = fm.width(strOneString);
     215            if (iTextWidth + iIndentSize > cWidth)
    188216            {
    189                 start = 0;
    190                 finish = oneString.length();
    191 
    192                 /* Selecting remove position */
    193                 switch (mFormat)
     217                iStart = 0;
     218                iFinish = strOneString.length();
     219
     220                /* Selecting remove position: */
     221                switch (m_enmFormat)
    194222                {
    195                     case EllipsisStart:
    196                         position = start;
     223                    case FormatType_EllipsisStart:
     224                        iPosition = iStart;
    197225                        break;
    198                     case EllipsisMiddle:
    199                         position = (finish - start) / 2;
     226                    case FormatType_EllipsisMiddle:
     227                        iPosition = (iFinish - iStart) / 2;
    200228                        break;
    201                     case EllipsisEnd:
    202                         position = finish - 1;
     229                    case FormatType_EllipsisEnd:
     230                        iPosition = iFinish - 1;
    203231                        break;
    204                     case EllipsisFile:
     232                    case FormatType_EllipsisFile:
    205233                    {
    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;
    211239                        break;
    212240                    }
    213241                    default:
    214                         AssertMsgFailed (("Invalid format type\n"));
     242                        AssertMsgFailed(("Invalid format type\n"));
    215243                }
    216244
    217                 if (position == finish)
     245                if (iPosition == iFinish)
    218246                   break;
    219247
    220                 oneString.remove (position, 1);
     248                strOneString.remove(iPosition, 1);
    221249            }
    222250        }
    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;
    236267};
    237268
     
    291322            {
    292323                /* Gather shared folder values: */
    293                 initialFolderData.m_type = enmFolderType;
     324                initialFolderData.m_enmType = enmFolderType;
    294325                initialFolderData.m_strName = folder.GetName();
    295                 initialFolderData.m_strHostPath = folder.GetHostPath();
     326                initialFolderData.m_strPath = folder.GetHostPath();
    296327                initialFolderData.m_fAutoMount = folder.GetAutoMount();
    297328                initialFolderData.m_fWritable = folder.GetWritable();
     
    319350    /* For each shared folder: */
    320351    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? */);
    335353
    336354    /* Ensure current item fetched: */
     
    350368        /* Get shared folder root item: */
    351369        const SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex));
    352         const UISharedFolderType enmSharedFolderType = (UISharedFolderType)pFolderTypeRoot->text(1).toInt();
    353370
    354371        /* For each shared folder of current type: */
     
    357374            /* Get shared folder item: */
    358375            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);
    370377        }
    371378    }
     
    425432    m_pActionEdit->setToolTip(m_pActionEdit->whatsThis());
    426433    m_pActionRemove->setToolTip(m_pActionRemove->whatsThis());
    427 
    428     m_strTrFull = tr("Full");
    429     m_strTrReadOnly = tr("Read-only");
    430     m_strTrYes = tr("Yes");
    431434}
    432435
     
    459462}
    460463
    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();
     464void 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;
    470478        /* Shared folder's name & path could not be empty: */
    471479        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: */
    479493        mTwFolders->sortItems(0, Qt::AscendingOrder);
    480         mTwFolders->scrollToItem(pItem);
    481         mTwFolders->setCurrentItem(pItem);
    482         sltHandleCurrentItemChange(pItem);
    483         mTwFolders->setFocus();
     494        /* Adjust tree-widget finally: */
    484495        sltAdjustTree();
    485496    }
    486497}
    487498
    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();
     499void 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;
    508523        /* Shared folder's name & path could not be empty: */
    509524        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);
    519536        if (pItem->parentItem() != pRoot)
    520537        {
    521             /* Move the selected item into new location: */
     538            /* Move the tree-widget item to a new location: */
    522539            pItem->parentItem()->takeChild(pItem->parentItem()->indexOfChild(pItem));
    523540            pRoot->insertChild(pRoot->childCount(), pItem);
     541
     542            /* Update tree-widget: */
    524543            mTwFolders->scrollToItem(pItem);
    525544            mTwFolders->setCurrentItem(pItem);
    526545            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: */
    529551        sltAdjustTree();
    530552    }
    531553}
    532554
    533 void UIMachineSettingsSF::sltRemoveSharedFolder()
    534 {
    535     QTreeWidgetItem *pSelectedItem = mTwFolders->selectedItems().size() == 1 ? mTwFolders->selectedItems()[0] : 0;
    536     Assert(pSelectedItem);
    537     delete pSelectedItem;
     555void 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: */
    538565    sltAdjustTree();
    539566}
     
    554581    const bool fEditEnabled = pItem && pItem->parent();
    555582    if (fEditEnabled)
    556         sltEditSharedFolder();
     583        sltEditFolder();
    557584}
    558585
     
    610637    for (int i = 0; i < pMainRoot->childCount(); ++i)
    611638    {
    612         QTreeWidgetItem *pSubRoot = pMainRoot->child(i);
     639        SFTreeViewItem *pSubRoot = static_cast<SFTreeViewItem*>(pMainRoot->child(i));
     640        pSubRoot->adjustText();
    613641        for (int j = 0; j < pSubRoot->childCount(); ++j)
    614642        {
    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();
    618645        }
    619646    }
     
    666693        m_pActionAdd = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_add_16px.png",
    667694                                                                        ":/sf_add_disabled_16px.png"),
    668                                                     QString(), this, SLOT(sltAddSharedFolder()));
     695                                                    QString(), this, SLOT(sltAddFolder()));
    669696        AssertPtrReturnVoid(m_pActionAdd);
    670697        {
     
    676703        m_pActionEdit = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_edit_16px.png",
    677704                                                                         ":/sf_edit_disabled_16px.png"),
    678                                                      QString(), this, SLOT(sltEditSharedFolder()));
     705                                                     QString(), this, SLOT(sltEditFolder()));
    679706        AssertPtrReturnVoid(m_pActionEdit);
    680707        {
     
    686713        m_pActionRemove = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_remove_16px.png",
    687714                                                                           ":/sf_remove_disabled_16px.png"),
    688                                                        QString(), this, SLOT(sltRemoveSharedFolder()));
     715                                                       QString(), this, SLOT(sltRemoveFolder()));
    689716        AssertPtrReturnVoid(m_pActionRemove);
    690717        {
     
    721748    {
    722749        /* Get iterated item: */
    723         QTreeWidgetItem *pIteratedItem = pMainRootItem->child(iFolderTypeIndex);
     750        SFTreeViewItem *pIteratedItem = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex));
    724751        /* If iterated item type is what we are looking for: */
    725         if (pIteratedItem->text(1).toInt() == enmSharedFolderType)
     752        if (pIteratedItem->m_enmType == enmSharedFolderType)
    726753        {
    727754            /* Remember the item: */
     
    781808    if (!pRootItem)
    782809    {
    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        }
    799824    }
    800825    /* Expand/collaps it if necessary: */
     
    830855}
    831856
     857void 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
    832881bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache)
    833882{
     
    835884    const UIDataSettingsSharedFolder &folderData = folderCache.data();
    836885    const QString strName = folderData.m_strName;
    837     const QString strPath = folderData.m_strHostPath;
     886    const QString strPath = folderData.m_strPath;
    838887    const bool fIsWritable = folderData.m_fWritable;
    839888    const bool fIsAutoMount = folderData.m_fAutoMount;
    840     const UISharedFolderType enmSharedFoldersType = folderData.m_type;
     889    const UISharedFolderType enmSharedFoldersType = folderData.m_enmType;
    841890
    842891    /* Get current shared folders: */
     
    894943    const UIDataSettingsSharedFolder &folderData = folderCache.base();
    895944    const QString strName = folderData.m_strName;
    896     const QString strPath = folderData.m_strHostPath;
    897     const UISharedFolderType enmSharedFoldersType = folderData.m_type;
     945    const QString strPath = folderData.m_strPath;
     946    const UISharedFolderType enmSharedFoldersType = folderData.m_enmType;
    898947
    899948    /* Get current shared folders: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h

    r66383 r66451  
    8282
    8383    /** Handles command to add shared folder. */
    84     void sltAddSharedFolder();
     84    void sltAddFolder();
    8585    /** Handles command to edit shared folder. */
    86     void sltEditSharedFolder();
     86    void sltEditFolder();
    8787    /** Handles command to remove shared folder. */
    88     void sltRemoveSharedFolder();
     88    void sltRemoveFolder();
    8989
    9090    /** Handles @a pCurrentItem change. */
     
    128128    CSharedFolderVector getSharedFolders(UISharedFolderType enmSharedFoldersType);
    129129
     130    /** Creates shared folder item based on passed @a data. */
     131    void addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose);
     132
    130133    /** Creates shared folder defined by a @a folderCache. */
    131134    bool createSharedFolder(const UISettingsCacheSharedFolder &folderCache);
     
    140143    QAction *m_pActionRemove;
    141144
    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 
    149145    /** Holds the page data cache instance. */
    150146    UISettingsCacheSharedFolders *m_pCache;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette