VirtualBox

Changeset 66383 in vbox


Ignore:
Timestamp:
Mar 31, 2017 2:09:43 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114330
Message:

FE/Qt: Machine settings: Shared Folders page: Proper loading, caching, saving.

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

    r66377 r66383  
    264264    m_pCache->clear();
    265265
    266     /* Load machine (permanent) shared folders into shared folders cache if possible: */
     266    /* Get actual shared folders: */
     267    QMap<UISharedFolderType, CSharedFolder> folders;
     268    /* Load machine (permanent) shared folders if allowed: */
    267269    if (isSharedFolderTypeSupported(MachineType))
    268         loadToCacheFrom(MachineType);
    269     /* Load console (temporary) shared folders into shared folders cache if possible: */
     270        foreach (const CSharedFolder &folder, getSharedFolders(MachineType))
     271            folders.insertMulti(MachineType, folder);
     272    /* Load console (temporary) shared folders if allowed: */
    270273    if (isSharedFolderTypeSupported(ConsoleType))
    271         loadToCacheFrom(ConsoleType);
     274        foreach (const CSharedFolder &folder, getSharedFolders(ConsoleType))
     275            folders.insertMulti(ConsoleType, folder);
     276
     277    /* For each shared folder type: */
     278    foreach (const UISharedFolderType &enmFolderType, folders.keys())
     279    {
     280        /* For each shared folder of current type: */
     281        const QList<CSharedFolder> &currentTypeFolders = folders.values(enmFolderType);
     282        for (int iFolderIndex = 0; iFolderIndex < currentTypeFolders.size(); ++iFolderIndex)
     283        {
     284            /* Prepare cache key & data: */
     285            QString strFolderKey = QString::number(iFolderIndex);
     286            UIDataSettingsSharedFolder initialFolderData;
     287
     288            /* Check if shared folder exists:  */
     289            const CSharedFolder &folder = currentTypeFolders.at(iFolderIndex);
     290            if (!folder.isNull())
     291            {
     292                /* Gather shared folder values: */
     293                initialFolderData.m_type = enmFolderType;
     294                initialFolderData.m_strName = folder.GetName();
     295                initialFolderData.m_strHostPath = folder.GetHostPath();
     296                initialFolderData.m_fAutoMount = folder.GetAutoMount();
     297                initialFolderData.m_fWritable = folder.GetWritable();
     298                /* Override shared folder cache key: */
     299                strFolderKey = initialFolderData.m_strName;
     300            }
     301
     302            /* Cache initial data: */
     303            m_pCache->child(strFolderKey).cacheInitialData(initialFolderData);
     304        }
     305    }
    272306
    273307    /* Upload machine to data: */
     
    275309}
    276310
    277 void UIMachineSettingsSF::loadToCacheFrom(UISharedFolderType enmSharedFoldersType)
    278 {
    279     /* Get current shared folders: */
    280     CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType);
    281 
    282     /* For each shared folder: */
    283     for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex)
    284     {
    285         /* Prepare cache key & data: */
    286         QString strSharedFolderKey = QString::number(iFolderIndex);
    287         UIDataSettingsSharedFolder sharedFolderData;
    288 
    289         /* Check if shared folder exists:  */
    290         const CSharedFolder &folder = sharedFolders[iFolderIndex];
    291         if (!folder.isNull())
    292         {
    293             /* Gather shared folder values: */
    294             sharedFolderData.m_type = enmSharedFoldersType;
    295             sharedFolderData.m_strName = folder.GetName();
    296             sharedFolderData.m_strHostPath = folder.GetHostPath();
    297             sharedFolderData.m_fAutoMount = folder.GetAutoMount();
    298             sharedFolderData.m_fWritable = folder.GetWritable();
    299             /* Override shared folder cache key: */
    300             strSharedFolderKey = sharedFolderData.m_strName;
    301         }
    302 
    303         /* Cache shared folder data: */
    304         m_pCache->child(strSharedFolderKey).cacheInitialData(sharedFolderData);
    305     }
    306 }
    307 
    308311void UIMachineSettingsSF::getFromCache()
    309312{
     
    314317    updateRootItemsVisibility();
    315318
    316     /* Load shared folders data: */
     319    /* For each shared folder: */
    317320    for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex)
    318321    {
    319         /* Get shared folder data: */
    320         const UIDataSettingsSharedFolder &sharedFolderData = m_pCache->child(iFolderIndex).base();
    321         /* Prepare item fields: */
     322        /* Acquire corresponding folder data: */
     323        const UIDataSettingsSharedFolder &folderData = m_pCache->child(iFolderIndex).base();
     324
     325        /* Prepare shared folder item fields: */
    322326        QStringList fields;
    323         fields << sharedFolderData.m_strName
    324                << sharedFolderData.m_strHostPath
    325                << (sharedFolderData.m_fAutoMount ? m_strTrYes : "")
    326                << (sharedFolderData.m_fWritable ? m_strTrFull : m_strTrReadOnly);
    327         /* Create new shared folders item: */
    328         new SFTreeViewItem(root(sharedFolderData.m_type), fields, SFTreeViewItem::EllipsisFile);
    329     }
     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    }
     335
    330336    /* Ensure current item fetched: */
    331337    mTwFolders->setCurrentItem(mTwFolders->topLevelItem(0));
     
    340346    /* For each shared folder type: */
    341347    QTreeWidgetItem *pMainRootItem = mTwFolders->invisibleRootItem();
    342     for (int iFodlersTypeIndex = 0; iFodlersTypeIndex < pMainRootItem->childCount(); ++iFodlersTypeIndex)
     348    for (int iFolderTypeIndex = 0; iFolderTypeIndex < pMainRootItem->childCount(); ++iFolderTypeIndex)
    343349    {
    344350        /* Get shared folder root item: */
    345         SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFodlersTypeIndex));
    346         UISharedFolderType sharedFolderType = (UISharedFolderType)pFolderTypeRoot->text(1).toInt();
     351        const SFTreeViewItem *pFolderTypeRoot = static_cast<SFTreeViewItem*>(pMainRootItem->child(iFolderTypeIndex));
     352        const UISharedFolderType enmSharedFolderType = (UISharedFolderType)pFolderTypeRoot->text(1).toInt();
     353
    347354        /* For each shared folder of current type: */
    348         for (int iFoldersIndex = 0; iFoldersIndex < pFolderTypeRoot->childCount(); ++iFoldersIndex)
    349         {
    350             SFTreeViewItem *pFolderItem = static_cast<SFTreeViewItem*>(pFolderTypeRoot->child(iFoldersIndex));
    351             UIDataSettingsSharedFolder sharedFolderData;
    352             sharedFolderData.m_type = sharedFolderType;
    353             sharedFolderData.m_strName = pFolderItem->getText(0);
    354             sharedFolderData.m_strHostPath = pFolderItem->getText(1);
    355             sharedFolderData.m_fAutoMount = pFolderItem->getText(2) == m_strTrYes ? true : false;
    356             sharedFolderData.m_fWritable = pFolderItem->getText(3) == m_strTrFull ? true : false;
    357             m_pCache->child(sharedFolderData.m_strName).cacheCurrentData(sharedFolderData);
     355        for (int iFolderIndex = 0; iFolderIndex < pFolderTypeRoot->childCount(); ++iFolderIndex)
     356        {
     357            /* Get shared folder item: */
     358            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);
    358370        }
    359371    }
     
    368380    if (m_pCache->wasChanged())
    369381    {
    370         /* Save machine (permanent) shared folders if possible: */
    371         if (isSharedFolderTypeSupported(MachineType))
    372             saveFromCacheTo(MachineType);
    373         /* Save console (temporary) shared folders if possible: */
    374         if (isSharedFolderTypeSupported(ConsoleType))
    375             saveFromCacheTo(ConsoleType);
     382        /* For each shared folder record: */
     383        for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex)
     384        {
     385            /* Check if this shared folder data was actually changed: */
     386            const UISettingsCacheSharedFolder &currentFolderCache = m_pCache->child(iFolderIndex);
     387            if (currentFolderCache.wasChanged())
     388            {
     389                /* If shared folder was removed: */
     390                if (currentFolderCache.wasRemoved())
     391                    removeSharedFolder(currentFolderCache);
     392
     393                /* If shared folder was created: */
     394                if (currentFolderCache.wasCreated())
     395                    createSharedFolder(currentFolderCache);
     396
     397                /* If shared folder was changed: */
     398                if (currentFolderCache.wasUpdated())
     399                {
     400                    removeSharedFolder(currentFolderCache);
     401                    createSharedFolder(currentFolderCache);
     402                }
     403            }
     404        }
    376405    }
    377406
    378407    /* Upload machine to data: */
    379408    UISettingsPageMachine::uploadData(data);
    380 }
    381 
    382 void UIMachineSettingsSF::saveFromCacheTo(UISharedFolderType enmSharedFoldersType)
    383 {
    384     /* For each shared folder data set: */
    385     for (int iSharedFolderIndex = 0; iSharedFolderIndex < m_pCache->childCount(); ++iSharedFolderIndex)
    386     {
    387         /* Check if this shared folder data was actually changed: */
    388         const UISettingsCacheSharedFolder &sharedFolderCache = m_pCache->child(iSharedFolderIndex);
    389         if (sharedFolderCache.wasChanged())
    390         {
    391             /* If shared folder was removed: */
    392             if (sharedFolderCache.wasRemoved())
    393             {
    394                 /* Get shared folder data: */
    395                 const UIDataSettingsSharedFolder &sharedFolderData = sharedFolderCache.base();
    396                 /* Check if thats shared folder of required type before removing: */
    397                 if (sharedFolderData.m_type == enmSharedFoldersType)
    398                     removeSharedFolder(sharedFolderCache);
    399             }
    400 
    401             /* If shared folder was created: */
    402             if (sharedFolderCache.wasCreated())
    403             {
    404                 /* Get shared folder data: */
    405                 const UIDataSettingsSharedFolder &sharedFolderData = sharedFolderCache.data();
    406                 /* Check if thats shared folder of required type before creating: */
    407                 if (sharedFolderData.m_type == enmSharedFoldersType)
    408                     createSharedFolder(sharedFolderCache);
    409             }
    410 
    411             /* If shared folder was changed: */
    412             if (sharedFolderCache.wasUpdated())
    413             {
    414                 /* Get shared folder data: */
    415                 const UIDataSettingsSharedFolder &sharedFolderData = sharedFolderCache.data();
    416                 /* Check if thats shared folder of required type before recreating: */
    417                 if (sharedFolderData.m_type == enmSharedFoldersType)
    418                 {
    419                     removeSharedFolder(sharedFolderCache);
    420                     createSharedFolder(sharedFolderCache);
    421                 }
    422             }
    423         }
    424     }
    425409}
    426410
     
    860844    /* Check if such shared folder do not exists: */
    861845    CSharedFolder sharedFolder;
    862     for (int iSharedFolderIndex = 0; iSharedFolderIndex < sharedFolders.size(); ++iSharedFolderIndex)
    863         if (sharedFolders[iSharedFolderIndex].GetName() == strName)
    864             sharedFolder = sharedFolders[iSharedFolderIndex];
     846    for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex)
     847        if (sharedFolders[iFolderIndex].GetName() == strName)
     848            sharedFolder = sharedFolders[iFolderIndex];
    865849    if (sharedFolder.isNull())
    866850    {
     
    917901    /* Check that such shared folder really exists: */
    918902    CSharedFolder sharedFolder;
    919     for (int iSharedFolderIndex = 0; iSharedFolderIndex < sharedFolders.size(); ++iSharedFolderIndex)
    920         if (sharedFolders[iSharedFolderIndex].GetName() == strName)
    921             sharedFolder = sharedFolders[iSharedFolderIndex];
     903    for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex)
     904        if (sharedFolders[iFolderIndex].GetName() == strName)
     905            sharedFolder = sharedFolders[iFolderIndex];
    922906    if (!sharedFolder.isNull())
    923907    {
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h

    r66377 r66383  
    5656      * this task COULD be performed in other than the GUI thread. */
    5757    virtual void loadToCacheFrom(QVariant &data) /* override */;
    58     void loadToCacheFrom(UISharedFolderType sharedFoldersType);
    5958    /** Loads data into corresponding widgets from the cache,
    6059      * this task SHOULD be performed in the GUI thread only. */
     
    6766      * this task COULD be performed in other than the GUI thread. */
    6867    virtual void saveFromCacheTo(QVariant &data) /* overrride */;
    69     /** Saves data of @a sharedFoldersType from the cache to corresponding external object(s),
    70       * this task COULD be performed in other than the GUI thread. */
    71     void saveFromCacheTo(UISharedFolderType sharedFoldersType);
    7268
    7369    /** Handles translation event. */
     
    122118    QStringList usedList(bool fIncludeSelected);
    123119
    124     /** Returns whether the corresponding @a sharedFolderType supported. */
    125     bool isSharedFolderTypeSupported(UISharedFolderType sharedFolderType) const;
     120    /** Returns whether the corresponding @a enmSharedFoldersType supported. */
     121    bool isSharedFolderTypeSupported(UISharedFolderType enmSharedFoldersType) const;
    126122    /** Updates root item visibility. */
    127123    void updateRootItemsVisibility();
    128     /** Defines whether the root item of @a sharedFolderType is @a fVisible. */
    129     void setRootItemVisible(UISharedFolderType sharedFolderType, bool fVisible);
     124    /** Defines whether the root item of @a enmSharedFoldersType is @a fVisible. */
     125    void setRootItemVisible(UISharedFolderType enmSharedFoldersType, bool fVisible);
    130126
    131     /** Gathers a vector of shared folders of the passed @a sharedFoldersType. */
    132     CSharedFolderVector getSharedFolders(UISharedFolderType sharedFoldersType);
     127    /** Gathers a vector of shared folders of the passed @a enmSharedFoldersType. */
     128    CSharedFolderVector getSharedFolders(UISharedFolderType enmSharedFoldersType);
    133129
    134130    /** Creates shared folder defined by a @a folderCache. */
Note: See TracChangeset for help on using the changeset viewer.

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