Changeset 66508 in vbox
- Timestamp:
- Apr 11, 2017 11:18:01 AM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
r66502 r66508 60 60 # include "CParallelPort.h" 61 61 # include "CSerialPort.h" 62 # include "CSharedFolder.h" 62 63 # include "CConsole.h" 63 64 # include "CMachine.h" … … 1253 1254 } 1254 1255 1256 void UIMessageCenter::cannotLoadFoldersSettings(const CMachine &comMachine, QWidget *pParent /* = 0 */) 1257 { 1258 error(pParent, MessageType_Error, 1259 tr("Cannot load shared folders settings."), 1260 formatErrorInfo(comMachine)); 1261 } 1262 1263 void UIMessageCenter::cannotSaveFoldersSettings(const CMachine &comMachine, QWidget *pParent /* = 0 */) 1264 { 1265 error(pParent, MessageType_Error, 1266 tr("Cannot save shared folders settings."), 1267 formatErrorInfo(comMachine)); 1268 } 1269 1270 void UIMessageCenter::cannotLoadFoldersSettings(const CConsole &comConsole, QWidget *pParent /* = 0 */) 1271 { 1272 error(pParent, MessageType_Error, 1273 tr("Cannot load shared folders settings."), 1274 formatErrorInfo(comConsole)); 1275 } 1276 1277 void UIMessageCenter::cannotSaveFoldersSettings(const CConsole &comConsole, QWidget *pParent /* = 0 */) 1278 { 1279 error(pParent, MessageType_Error, 1280 tr("Cannot save shared folders settings."), 1281 formatErrorInfo(comConsole)); 1282 } 1283 1284 void UIMessageCenter::cannotLoadFolderSettings(const CSharedFolder &comFolder, QWidget *pParent /* = 0 */) 1285 { 1286 error(pParent, MessageType_Error, 1287 tr("Cannot load shared folder settings."), 1288 formatErrorInfo(comFolder)); 1289 } 1290 1291 void UIMessageCenter::cannotSaveFolderSettings(const CSharedFolder &comFolder, QWidget *pParent /* = 0 */) 1292 { 1293 error(pParent, MessageType_Error, 1294 tr("Cannot save shared folder settings."), 1295 formatErrorInfo(comFolder)); 1296 } 1297 1255 1298 void UIMessageCenter::cannotAttachDevice(const CMachine &machine, UIMediumType type, 1256 1299 const QString &strLocation, const StorageSlot &storageSlot, … … 1334 1377 QString() /* cancel button text */, 1335 1378 false /* ok button by default? */); 1336 }1337 1338 void UIMessageCenter::cannotCreateSharedFolder(const CMachine &machine, const QString &strName, const QString &strPath, QWidget *pParent /* = 0*/)1339 {1340 error(pParent, MessageType_Error,1341 tr("Failed to create the shared folder <b>%1</b> (pointing to "1342 "<nobr><b>%2</b></nobr>) for the virtual machine <b>%3</b>.")1343 .arg(strName, strPath, CMachine(machine).GetName()),1344 formatErrorInfo(machine));1345 }1346 1347 void UIMessageCenter::cannotCreateSharedFolder(const CConsole &console, const QString &strName, const QString &strPath, QWidget *pParent /* = 0*/)1348 {1349 error(pParent, MessageType_Error,1350 tr("Failed to create the shared folder <b>%1</b> (pointing to "1351 "<nobr><b>%2</b></nobr>) for the virtual machine <b>%3</b>.")1352 .arg(strName, strPath, CConsole(console).GetMachine().GetName()),1353 formatErrorInfo(console));1354 }1355 1356 void UIMessageCenter::cannotRemoveSharedFolder(const CMachine &machine, const QString &strName, const QString &strPath, QWidget *pParent /* = 0*/)1357 {1358 error(pParent, MessageType_Error,1359 tr("<p>Failed to remove the shared folder <b>%1</b> (pointing to "1360 "<nobr><b>%2</b></nobr>) from the virtual machine <b>%3</b>.</p>"1361 "<p>Please close all programs in the guest OS that "1362 "may be using this shared folder and try again.</p>")1363 .arg(strName, strPath, CMachine(machine).GetName()),1364 formatErrorInfo(machine));1365 }1366 1367 void UIMessageCenter::cannotRemoveSharedFolder(const CConsole &console, const QString &strName, const QString &strPath, QWidget *pParent /* = 0*/)1368 {1369 error(pParent, MessageType_Error,1370 tr("<p>Failed to remove the shared folder <b>%1</b> (pointing to "1371 "<nobr><b>%2</b></nobr>) from the virtual machine <b>%3</b>.</p>"1372 "<p>Please close all programs in the guest OS that "1373 "may be using this shared folder and try again.</p>")1374 .arg(strName, strPath, CConsole(console).GetMachine().GetName()),1375 formatErrorInfo(console));1376 1379 } 1377 1380 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
r66502 r66508 253 253 void cannotSaveSerialSettings(const CMachine &comMachine, QWidget *pParent = 0); 254 254 void cannotSaveSerialPortSettings(const CSerialPort &comPort, QWidget *pParent = 0); 255 void cannotLoadFoldersSettings(const CMachine &comMachine, QWidget *pParent = 0); 256 void cannotSaveFoldersSettings(const CMachine &comMachine, QWidget *pParent = 0); 257 void cannotLoadFoldersSettings(const CConsole &comConsole, QWidget *pParent = 0); 258 void cannotSaveFoldersSettings(const CConsole &comConsole, QWidget *pParent = 0); 259 void cannotLoadFolderSettings(const CSharedFolder &comFolder, QWidget *pParent = 0); 260 void cannotSaveFolderSettings(const CSharedFolder &comFolder, QWidget *pParent = 0); 255 261 void cannotAttachDevice(const CMachine &machine, UIMediumType type, const QString &strLocation, const StorageSlot &storageSlot, QWidget *pParent = 0); 256 262 bool warnAboutIncorrectPort(QWidget *pParent = 0) const; … … 260 266 bool warnAboutRulesConflict(QWidget *pParent = 0) const; 261 267 bool confirmCancelingPortForwardingDialog(QWidget *pParent = 0) const; 262 void cannotCreateSharedFolder(const CMachine &machine, const QString &strName, const QString &strPath, QWidget *pParent = 0);263 void cannotCreateSharedFolder(const CConsole &console, const QString &strName, const QString &strPath, QWidget *pParent = 0);264 void cannotRemoveSharedFolder(const CMachine &machine, const QString &strName, const QString &strPath, QWidget *pParent = 0);265 void cannotRemoveSharedFolder(const CConsole &console, const QString &strName, const QString &strPath, QWidget *pParent = 0);266 268 void cannotSaveMachineSettings(const CMachine &machine, QWidget *pParent = 0) const; 267 269 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp
r66460 r66508 396 396 UISettingsPageMachine::fetchData(data); 397 397 398 /* Make sure machine is in valid mode & folders data was changed: */ 399 if (isMachineInValidMode() && m_pCache->wasChanged()) 400 { 401 /* For each folder record: */ 402 for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex) 403 { 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()) 409 { 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()) 424 { 425 removeSharedFolder(folderCache); 426 createSharedFolder(folderCache); 427 } 428 } 429 } 430 } 398 /* Update folders data and failing state: */ 399 setFailed(!saveFoldersData()); 431 400 432 401 /* Upload machine to data: */ … … 847 816 } 848 817 849 CSharedFolderVector UIMachineSettingsSF::getSharedFolders(UISharedFolderType enmSharedFoldersType)850 {851 CSharedFolderVector sharedFolders;852 if (isSharedFolderTypeSupported(enmSharedFoldersType))853 {854 switch (enmSharedFoldersType)855 {856 case MachineType:857 {858 AssertMsg(!m_machine.isNull(), ("Machine is NOT set!\n"));859 sharedFolders = m_machine.GetSharedFolders();860 break;861 }862 case ConsoleType:863 {864 AssertMsg(!m_console.isNull(), ("Console is NOT set!\n"));865 sharedFolders = m_console.GetSharedFolders();866 break;867 }868 default:869 break;870 }871 }872 return sharedFolders;873 }874 875 818 void UIMachineSettingsSF::addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose) 876 819 { … … 897 840 } 898 841 899 bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache) 900 { 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: */ 910 const CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType); 911 /* Make sure such folder doesn't exist: */ 912 CSharedFolder sharedFolder; 913 for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex) 914 if (sharedFolders.at(iFolderIndex).GetName() == strName) 915 sharedFolder = sharedFolders.at(iFolderIndex); 916 if (sharedFolder.isNull()) 917 { 918 /* Create new folder: */ 919 switch(enmSharedFoldersType) 842 CSharedFolderVector UIMachineSettingsSF::getSharedFolders(UISharedFolderType enmFoldersType) 843 { 844 /* Wrap up the getter below: */ 845 CSharedFolderVector folders; 846 getSharedFolders(enmFoldersType, folders); 847 return folders; 848 } 849 850 bool UIMachineSettingsSF::getSharedFolders(UISharedFolderType enmFoldersType, CSharedFolderVector &folders) 851 { 852 /* Prepare result: */ 853 bool fSuccess = true; 854 /* Load folders of passed type: */ 855 if (fSuccess) 856 { 857 /* Make sure folder type is supported: */ 858 AssertReturn(isSharedFolderTypeSupported(enmFoldersType), false); 859 switch (enmFoldersType) 920 860 { 921 861 case MachineType: 922 862 { 923 /* Create new folder: */ 924 m_machine.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount); 925 if (!m_machine.isOk()) 926 { 927 /* Mark the page as failed: */ 928 setFailed(true); 929 /* Show error message: */ 930 msgCenter().cannotCreateSharedFolder(m_machine, strName, strPath, this); 931 /* Finish early: */ 932 return false; 933 } 863 /* Make sure machine was specified: */ 864 AssertReturn(!m_machine.isNull(), false); 865 /* Load machine folders: */ 866 folders = m_machine.GetSharedFolders(); 867 fSuccess = m_machine.isOk(); 868 /* Show error message if necessary: */ 869 if (!fSuccess) 870 msgCenter().cannotLoadFoldersSettings(m_machine, this); 934 871 break; 935 872 } 936 873 case ConsoleType: 937 874 { 938 /* Create new folder: */ 939 m_console.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount); 940 if (!m_console.isOk()) 941 { 942 /* Mark the page as failed: */ 943 setFailed(true); 944 /* Show error message: */ 945 msgCenter().cannotCreateSharedFolder(m_console, strName, strPath, this); 946 /* Finish early: */ 947 return false; 948 } 875 /* Make sure console was specified: */ 876 AssertReturn(!m_console.isNull(), false); 877 /* Load console folders: */ 878 folders = m_console.GetSharedFolders(); 879 fSuccess = m_console.isOk(); 880 /* Show error message if necessary: */ 881 if (!fSuccess) 882 msgCenter().cannotLoadFoldersSettings(m_console, this); 949 883 break; 950 884 } 951 885 default: 952 break; 953 } 954 } 955 return true; 886 AssertFailedReturn(false); 887 } 888 } 889 /* Return result: */ 890 return fSuccess; 891 } 892 893 bool UIMachineSettingsSF::getSharedFolder(const QString &strFolderName, const CSharedFolderVector &folders, CSharedFolder &comFolder) 894 { 895 /* Prepare result: */ 896 bool fSuccess = true; 897 /* Look for a folder with passed name: */ 898 for (int iFolderIndex = 0; fSuccess && iFolderIndex < folders.size(); ++iFolderIndex) 899 { 900 /* Get current folder: */ 901 const CSharedFolder &comCurrentFolder = folders.at(iFolderIndex); 902 903 /* Get current folder name for further activities: */ 904 QString strCurrentFolderName; 905 if (fSuccess) 906 { 907 strCurrentFolderName = comCurrentFolder.GetName(); 908 fSuccess = comCurrentFolder.isOk(); 909 } 910 /* Show error message if necessary: */ 911 if (!fSuccess) 912 msgCenter().cannotLoadFolderSettings(comCurrentFolder, this); 913 914 /* If that's the folder we are looking for => take it: */ 915 if (fSuccess && strCurrentFolderName == strFolderName) 916 comFolder = folders[iFolderIndex]; 917 } 918 /* Return result: */ 919 return fSuccess; 920 } 921 922 bool UIMachineSettingsSF::saveFoldersData() 923 { 924 /* Prepare result: */ 925 bool fSuccess = true; 926 /* Save folders settings from the cache: */ 927 if (fSuccess && isMachineInValidMode() && m_pCache->wasChanged()) 928 { 929 /* For each folder: */ 930 for (int iFolderIndex = 0; fSuccess && iFolderIndex < m_pCache->childCount(); ++iFolderIndex) 931 { 932 /* Get folder cache: */ 933 const UISettingsCacheSharedFolder &folderCache = m_pCache->child(iFolderIndex); 934 935 /* Check if this folder data was changed: */ 936 if (folderCache.wasChanged()) 937 { 938 /* If folder was removed or updated: */ 939 if (folderCache.wasRemoved() || folderCache.wasUpdated()) 940 fSuccess = removeSharedFolder(folderCache); 941 942 /* If folder was created or updated: */ 943 if (folderCache.wasCreated() || folderCache.wasUpdated()) 944 fSuccess = createSharedFolder(folderCache); 945 } 946 } 947 } 948 /* Return result: */ 949 return fSuccess; 956 950 } 957 951 958 952 bool UIMachineSettingsSF::removeSharedFolder(const UISettingsCacheSharedFolder &folderCache) 959 953 { 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: */ 967 const CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType); 968 /* Make sure such folder really exists: */ 969 CSharedFolder sharedFolder; 970 for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex) 971 if (sharedFolders.at(iFolderIndex).GetName() == strName) 972 sharedFolder = sharedFolders.at(iFolderIndex); 973 if (!sharedFolder.isNull()) 974 { 975 /* Remove existing folder: */ 976 switch(enmSharedFoldersType) 977 { 978 case MachineType: 954 /* Prepare result: */ 955 bool fSuccess = true; 956 /* Remove folder: */ 957 if (fSuccess) 958 { 959 /* Get folder data: */ 960 const UIDataSettingsSharedFolder &newFolderData = folderCache.base(); 961 const UISharedFolderType enmFoldersType = newFolderData.m_enmType; 962 const QString strFolderName = newFolderData.m_strName; 963 964 /* Get current folders: */ 965 CSharedFolderVector folders; 966 if (fSuccess) 967 fSuccess = getSharedFolders(enmFoldersType, folders); 968 969 /* Search for a folder with the same name: */ 970 CSharedFolder comFolder; 971 if (fSuccess) 972 /* fSuccess = */ getSharedFolder(strFolderName, folders, comFolder); 973 974 /* Make sure such folder really exists: */ 975 if (!comFolder.isNull()) 976 { 977 /* Remove existing folder: */ 978 switch (enmFoldersType) 979 979 { 980 /* Remove existing folder: */ 981 m_machine.RemoveSharedFolder(strName); 982 if (!m_machine.isOk()) 980 case MachineType: 983 981 { 984 /* Mark the page as failed: */ 985 setFailed(true); 986 /* Show error message: */ 987 msgCenter().cannotRemoveSharedFolder(m_machine, strName, strPath, this); 988 /* Finish early: */ 989 return false; 982 /* Remove existing folder: */ 983 m_machine.RemoveSharedFolder(strFolderName); 984 /* Check that machine is OK: */ 985 fSuccess = m_machine.isOk(); 986 if (!fSuccess) 987 { 988 /* Show error message: */ 989 msgCenter().cannotSaveFoldersSettings(m_machine, this); 990 } 991 break; 990 992 } 991 break; 993 case ConsoleType: 994 { 995 /* Remove existing folder: */ 996 m_console.RemoveSharedFolder(strFolderName); 997 /* Check that console is OK: */ 998 fSuccess = m_console.isOk(); 999 if (!fSuccess) 1000 { 1001 /* Show error message: */ 1002 msgCenter().cannotSaveFoldersSettings(m_console, this); 1003 } 1004 break; 1005 } 1006 default: 1007 break; 992 1008 } 993 case ConsoleType: 1009 } 1010 } 1011 /* Return result: */ 1012 return fSuccess; 1013 } 1014 1015 bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache) 1016 { 1017 /* Prepare result: */ 1018 bool fSuccess = true; 1019 /* Remove folder: */ 1020 if (fSuccess) 1021 { 1022 /* Get folder data: */ 1023 const UIDataSettingsSharedFolder &newFolderData = folderCache.data(); 1024 const UISharedFolderType enmFoldersType = newFolderData.m_enmType; 1025 const QString strFolderName = newFolderData.m_strName; 1026 const QString strFolderPath = newFolderData.m_strPath; 1027 const bool fIsAutoMount = newFolderData.m_fAutoMount; 1028 const bool fIsWritable = newFolderData.m_fWritable; 1029 1030 /* Get current folders: */ 1031 CSharedFolderVector folders; 1032 if (fSuccess) 1033 fSuccess = getSharedFolders(enmFoldersType, folders); 1034 1035 /* Search for a folder with the same name: */ 1036 CSharedFolder comFolder; 1037 if (fSuccess) 1038 /* fSuccess = */ getSharedFolder(strFolderName, folders, comFolder); 1039 1040 /* Make sure such folder doesn't exist: */ 1041 if (comFolder.isNull()) 1042 { 1043 /* Create new folder: */ 1044 switch (enmFoldersType) 994 1045 { 995 /* Remove existing folder: */ 996 m_console.RemoveSharedFolder(strName); 997 if (!m_console.isOk()) 1046 case MachineType: 998 1047 { 999 /* Mark the page as failed: */ 1000 setFailed(true); 1001 /* Show error message: */ 1002 msgCenter().cannotRemoveSharedFolder(m_console, strName, strPath, this); 1003 /* Finish early: */ 1004 return false; 1048 /* Create new folder: */ 1049 m_machine.CreateSharedFolder(strFolderName, strFolderPath, fIsWritable, fIsAutoMount); 1050 /* Check that machine is OK: */ 1051 fSuccess = m_machine.isOk(); 1052 if (!fSuccess) 1053 { 1054 /* Show error message: */ 1055 msgCenter().cannotSaveFoldersSettings(m_machine, this); 1056 } 1057 break; 1005 1058 } 1006 break; 1059 case ConsoleType: 1060 { 1061 /* Create new folder: */ 1062 m_console.CreateSharedFolder(strFolderName, strFolderPath, fIsWritable, fIsAutoMount); 1063 /* Check that console is OK: */ 1064 fSuccess = m_console.isOk(); 1065 if (!fSuccess) 1066 { 1067 /* Show error message: */ 1068 msgCenter().cannotSaveFoldersSettings(m_console, this); 1069 } 1070 break; 1071 } 1072 default: 1073 break; 1007 1074 } 1008 default: 1009 break; 1010 } 1011 } 1012 return true; 1013 } 1014 1075 } 1076 } 1077 /* Return result: */ 1078 return fSuccess; 1079 } 1080 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h
r66451 r66508 118 118 QStringList usedList(bool fIncludeSelected); 119 119 120 /** Returns whether the corresponding @a enm SharedFoldersType supported. */121 bool isSharedFolderTypeSupported(UISharedFolderType enm SharedFoldersType) const;120 /** Returns whether the corresponding @a enmFoldersType supported. */ 121 bool isSharedFolderTypeSupported(UISharedFolderType enmFoldersType) const; 122 122 /** Updates root item visibility. */ 123 123 void updateRootItemsVisibility(); 124 /** Defines whether the root item of @a enmSharedFoldersType is @a fVisible. */ 125 void setRootItemVisible(UISharedFolderType enmSharedFoldersType, bool fVisible); 126 127 /** Gathers a vector of shared folders of the passed @a enmSharedFoldersType. */ 128 CSharedFolderVector getSharedFolders(UISharedFolderType enmSharedFoldersType); 124 /** Defines whether the root item of @a enmFoldersType is @a fVisible. */ 125 void setRootItemVisible(UISharedFolderType enmFoldersType, bool fVisible); 129 126 130 127 /** Creates shared folder item based on passed @a data. */ 131 128 void addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose); 132 129 130 /** Gathers a vector of shared folders of the passed @a enmFoldersType. */ 131 CSharedFolderVector getSharedFolders(UISharedFolderType enmFoldersType); 132 /** Gathers a vector of shared folders of the passed @a enmFoldersType. */ 133 bool getSharedFolders(UISharedFolderType enmFoldersType, CSharedFolderVector &folders); 134 /** Look for a folder with the the passed @a strFolderName. */ 135 bool getSharedFolder(const QString &strFolderName, const CSharedFolderVector &folders, CSharedFolder &comFolder); 136 137 /** Saves existing folder data from the cache. */ 138 bool saveFoldersData(); 139 /** Removes shared folder defined by a @a folderCache. */ 140 bool removeSharedFolder(const UISettingsCacheSharedFolder &folderCache); 133 141 /** Creates shared folder defined by a @a folderCache. */ 134 142 bool createSharedFolder(const UISettingsCacheSharedFolder &folderCache); 135 /** Removes shared folder defined by a @a folderCache. */136 bool removeSharedFolder(const UISettingsCacheSharedFolder &folderCache);137 143 138 144 /** Holds the Add action instance. */
Note:
See TracChangeset
for help on using the changeset viewer.