VirtualBox

Changeset 66453 in vbox


Ignore:
Timestamp:
Apr 6, 2017 9:10:34 AM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Machine settings: Shared Folders page: Proper loading, caching, saving (2nd iteration, s.a. r114330).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp

    r66451 r66453  
    295295    m_pCache->clear();
    296296
    297     /* Get actual shared folders: */
     297    /* Prepare old folders data: */
     298    UIDataSettingsSharedFolders oldFoldersData;
     299
     300    /* Get actual folders: */
    298301    QMap<UISharedFolderType, CSharedFolder> folders;
    299     /* Load machine (permanent) shared folders if allowed: */
     302    /* Load machine (permanent) folders if allowed: */
    300303    if (isSharedFolderTypeSupported(MachineType))
    301304        foreach (const CSharedFolder &folder, getSharedFolders(MachineType))
    302305            folders.insertMulti(MachineType, folder);
    303     /* Load console (temporary) shared folders if allowed: */
     306    /* Load console (temporary) folders if allowed: */
    304307    if (isSharedFolderTypeSupported(ConsoleType))
    305308        foreach (const CSharedFolder &folder, getSharedFolders(ConsoleType))
    306309            folders.insertMulti(ConsoleType, folder);
    307310
    308     /* For each shared folder type: */
     311    /* For each folder type: */
    309312    foreach (const UISharedFolderType &enmFolderType, folders.keys())
    310313    {
    311         /* For each shared folder of current type: */
     314        /* For each folder of current type: */
    312315        const QList<CSharedFolder> &currentTypeFolders = folders.values(enmFolderType);
    313316        for (int iFolderIndex = 0; iFolderIndex < currentTypeFolders.size(); ++iFolderIndex)
    314317        {
    315             /* Prepare cache key & data: */
     318            /* Prepare old folder data & cache key: */
    316319            QString strFolderKey = QString::number(iFolderIndex);
    317             UIDataSettingsSharedFolder initialFolderData;
    318 
    319             /* Check if shared folder exists:  */
    320             const CSharedFolder &folder = currentTypeFolders.at(iFolderIndex);
    321             if (!folder.isNull())
     320            UIDataSettingsSharedFolder oldFolderData;
     321
     322            /* Check whether folder is valid:  */
     323            const CSharedFolder &comFolder = currentTypeFolders.at(iFolderIndex);
     324            if (!comFolder.isNull())
    322325            {
    323                 /* Gather shared folder values: */
    324                 initialFolderData.m_enmType = enmFolderType;
    325                 initialFolderData.m_strName = folder.GetName();
    326                 initialFolderData.m_strPath = folder.GetHostPath();
    327                 initialFolderData.m_fAutoMount = folder.GetAutoMount();
    328                 initialFolderData.m_fWritable = folder.GetWritable();
    329                 /* Override shared folder cache key: */
    330                 strFolderKey = initialFolderData.m_strName;
     326                /* Gather old folder data: */
     327                oldFolderData.m_enmType = enmFolderType;
     328                oldFolderData.m_strName = comFolder.GetName();
     329                oldFolderData.m_strPath = comFolder.GetHostPath();
     330                oldFolderData.m_fAutoMount = comFolder.GetAutoMount();
     331                oldFolderData.m_fWritable = comFolder.GetWritable();
     332                /* Override folder cache key: */
     333                strFolderKey = oldFolderData.m_strName;
    331334            }
    332335
    333             /* Cache initial shared folder data: */
    334             m_pCache->child(strFolderKey).cacheInitialData(initialFolderData);
    335         }
    336     }
     336            /* Cache old folder data: */
     337            m_pCache->child(strFolderKey).cacheInitialData(oldFolderData);
     338        }
     339    }
     340
     341    /* Cache old folders data: */
     342    m_pCache->cacheInitialData(oldFoldersData);
    337343
    338344    /* Upload machine to data: */
     
    348354    updateRootItemsVisibility();
    349355
    350     /* For each shared folder: */
     356    /* For each folder => load it to the page: */
    351357    for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex)
    352358        addSharedFolderItem(m_pCache->child(iFolderIndex).base(), false /* its new? */);
    353359
    354     /* Ensure current item fetched: */
     360    /* Choose first folder as current: */
    355361    mTwFolders->setCurrentItem(mTwFolders->topLevelItem(0));
    356362    sltHandleCurrentItemChange(mTwFolders->currentItem());
     
    362368void UIMachineSettingsSF::putToCache()
    363369{
    364     /* For each shared folder type: */
     370    /* Prepare new folders data: */
     371    UIDataSettingsSharedFolders newFoldersData;
     372
     373    /* For each folder type: */
    365374    QTreeWidgetItem *pMainRootItem = mTwFolders->invisibleRootItem();
    366375    for (int iFolderTypeIndex = 0; iFolderTypeIndex < pMainRootItem->childCount(); ++iFolderTypeIndex)
    367376    {
    368         /* Get shared folder root item: */
     377        /* Get folder root item: */
    369378        const SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex));
    370379
    371         /* For each shared folder of current type: */
     380        /* For each folder of current type: */
    372381        for (int iFolderIndex = 0; iFolderIndex < pFolderTypeRoot->childCount(); ++iFolderIndex)
    373382        {
    374             /* Get shared folder item: */
    375             SFTreeViewItem *pFolderItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFolderIndex));
    376             m_pCache->child(pFolderItem->m_strName).cacheCurrentData(*pFolderItem);
    377         }
    378     }
     383            /* Get and cache new folder item: */
     384            const SFTreeViewItem *pItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFolderIndex));
     385            m_pCache->child(pItem->m_strName).cacheCurrentData(*pItem);
     386        }
     387    }
     388
     389    /* Cache new folders data: */
     390    m_pCache->cacheCurrentData(newFoldersData);
    379391}
    380392
     
    384396    UISettingsPageMachine::fetchData(data);
    385397
    386     /* Check if shared folders data was changed: */
     398    /* Check if folders data was changed: */
    387399    if (m_pCache->wasChanged())
    388400    {
    389         /* For each shared folder record: */
     401        /* For each folder record: */
    390402        for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex)
    391403        {
    392             /* Check if this shared folder data was changed: */
    393             const UISettingsCacheSharedFolder &currentFolderCache = m_pCache->child(iFolderIndex);
    394             if (currentFolderCache.wasChanged())
     404            /* Get folder cache: */
     405            const UISettingsCacheSharedFolder &folderCache = m_pCache->child(iFolderIndex);
     406
     407            /* Check if this folder data was changed: */
     408            if (folderCache.wasChanged())
    395409            {
    396                 /* If shared folder was removed: */
    397                 if (currentFolderCache.wasRemoved())
    398                     removeSharedFolder(currentFolderCache);
    399 
    400                 /* If shared folder was created: */
    401                 if (currentFolderCache.wasCreated())
    402                     createSharedFolder(currentFolderCache);
    403 
    404                 /* If shared folder was changed: */
    405                 if (currentFolderCache.wasUpdated())
     410                /* If folder was removed: */
     411                if (folderCache.wasRemoved())
     412                    removeSharedFolder(folderCache);
     413
     414                else
     415
     416                /* If folder was created: */
     417                if (folderCache.wasCreated())
     418                    createSharedFolder(folderCache);
     419
     420                else
     421
     422                /* If folder was updated: */
     423                if (folderCache.wasUpdated())
    406424                {
    407                     removeSharedFolder(currentFolderCache);
    408                     createSharedFolder(currentFolderCache);
     425                    removeSharedFolder(folderCache);
     426                    createSharedFolder(folderCache);
    409427                }
    410428            }
     
    881899bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache)
    882900{
    883     /* Get shared folder data: */
    884     const UIDataSettingsSharedFolder &folderData = folderCache.data();
    885     const QString strName = folderData.m_strName;
    886     const QString strPath = folderData.m_strPath;
    887     const bool fIsWritable = folderData.m_fWritable;
    888     const bool fIsAutoMount = folderData.m_fAutoMount;
    889     const UISharedFolderType enmSharedFoldersType = folderData.m_enmType;
    890 
    891     /* Get current shared folders: */
     901    /* Get new folder data: */
     902    const UIDataSettingsSharedFolder &newFolderData = folderCache.data();
     903    const UISharedFolderType enmSharedFoldersType = newFolderData.m_enmType;
     904    const QString strName = newFolderData.m_strName;
     905    const QString strPath = newFolderData.m_strPath;
     906    const bool fIsAutoMount = newFolderData.m_fAutoMount;
     907    const bool fIsWritable = newFolderData.m_fWritable;
     908
     909    /* Get current folders: */
    892910    const CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType);
    893     /* Check if such shared folder do not exists: */
     911    /* Make sure such folder doesn't exist: */
    894912    CSharedFolder sharedFolder;
    895913    for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex)
    896         if (sharedFolders[iFolderIndex].GetName() == strName)
    897             sharedFolder = sharedFolders[iFolderIndex];
     914        if (sharedFolders.at(iFolderIndex).GetName() == strName)
     915            sharedFolder = sharedFolders.at(iFolderIndex);
    898916    if (sharedFolder.isNull())
    899917    {
    900         /* Create new shared folder: */
     918        /* Create new folder: */
    901919        switch(enmSharedFoldersType)
    902920        {
    903921            case MachineType:
    904922            {
    905                 /* Create new shared folder: */
     923                /* Create new folder: */
    906924                m_machine.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount);
    907925                if (!m_machine.isOk())
     
    918936            case ConsoleType:
    919937            {
    920                 /* Create new shared folder: */
     938                /* Create new folder: */
    921939                m_console.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount);
    922940                if (!m_console.isOk())
     
    940958bool UIMachineSettingsSF::removeSharedFolder(const UISettingsCacheSharedFolder &folderCache)
    941959{
    942     /* Get shared folder data: */
    943     const UIDataSettingsSharedFolder &folderData = folderCache.base();
    944     const QString strName = folderData.m_strName;
    945     const QString strPath = folderData.m_strPath;
    946     const UISharedFolderType enmSharedFoldersType = folderData.m_enmType;
    947 
    948     /* Get current shared folders: */
     960    /* Get old folder data: */
     961    const UIDataSettingsSharedFolder &oldFolderData = folderCache.base();
     962    const UISharedFolderType enmSharedFoldersType = oldFolderData.m_enmType;
     963    const QString strName = oldFolderData.m_strName;
     964    const QString strPath = oldFolderData.m_strPath;
     965
     966    /* Get current folders: */
    949967    const CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType);
    950     /* Check that such shared folder really exists: */
     968    /* Make sure such folder really exists: */
    951969    CSharedFolder sharedFolder;
    952970    for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex)
    953         if (sharedFolders[iFolderIndex].GetName() == strName)
    954             sharedFolder = sharedFolders[iFolderIndex];
     971        if (sharedFolders.at(iFolderIndex).GetName() == strName)
     972            sharedFolder = sharedFolders.at(iFolderIndex);
    955973    if (!sharedFolder.isNull())
    956974    {
    957         /* Remove existing shared folder: */
     975        /* Remove existing folder: */
    958976        switch(enmSharedFoldersType)
    959977        {
    960978            case MachineType:
    961979            {
    962                 /* Remove existing shared folder: */
     980                /* Remove existing folder: */
    963981                m_machine.RemoveSharedFolder(strName);
    964982                if (!m_machine.isOk())
     
    975993            case ConsoleType:
    976994            {
    977                 /* Remove existing shared folder: */
     995                /* Remove existing folder: */
    978996                m_console.RemoveSharedFolder(strName);
    979997                if (!m_console.isOk())
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