- Timestamp:
- Mar 12, 2018 9:23:17 AM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileManager.cpp
r71276 r71298 261 261 if (m_pCopyGuestToHost) 262 262 { 263 m_pCopyGuestToHost->setText(UIVMInformationDialog::tr("Copy the selected object from guest to host"));264 m_pCopyGuestToHost->setToolTip(UIVMInformationDialog::tr("Copy the selected object from guest to host"));265 m_pCopyGuestToHost->setStatusTip(UIVMInformationDialog::tr("Copy the selected object from guest to host"));263 m_pCopyGuestToHost->setText(UIVMInformationDialog::tr("Copy the selected object(s) from guest to host")); 264 m_pCopyGuestToHost->setToolTip(UIVMInformationDialog::tr("Copy the selected object(s) from guest to host")); 265 m_pCopyGuestToHost->setStatusTip(UIVMInformationDialog::tr("Copy the selected object(s) from guest to host")); 266 266 } 267 267 268 268 if (m_pCopyHostToGuest) 269 269 { 270 m_pCopyHostToGuest->setText(UIVMInformationDialog::tr("Copy the selected object from host to guest"));271 m_pCopyHostToGuest->setToolTip(UIVMInformationDialog::tr("Copy the selected object from host to guest"));272 m_pCopyHostToGuest->setStatusTip(UIVMInformationDialog::tr("Copy the selected object from host to guest"));270 m_pCopyHostToGuest->setText(UIVMInformationDialog::tr("Copy the selected object(s) from host to guest")); 271 m_pCopyHostToGuest->setToolTip(UIVMInformationDialog::tr("Copy the selected object(s) from host to guest")); 272 m_pCopyHostToGuest->setStatusTip(UIVMInformationDialog::tr("Copy the selected object(s) from host to guest")); 273 273 } 274 274 … … 485 485 if (!m_pGuestFileTable || !m_pHostFileTable) 486 486 return; 487 QString hostDestinationPath = m_pHostFileTable->current Path();487 QString hostDestinationPath = m_pHostFileTable->currentDirectoryPath(); 488 488 printf("current host path %s\n", hostDestinationPath.toStdString().c_str()); 489 489 m_pGuestFileTable->copyGuestToHost(hostDestinationPath); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp
r71285 r71298 43 43 /* COM includes: */ 44 44 # include "CFsObjInfo.h" 45 # include "CGuestFsObjInfo.h" 45 46 # include "CGuestDirectory.h" 46 47 # include "CProgress.h" 47 48 48 49 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 50 51 /** A collection of utility functions for some path string manipulations */ 52 class UIPathOperations 53 { 54 public: 55 static QString removeMultipleDelimiters(const QString &path); 56 static QString removeTrailingDelimiters(const QString &path); 57 static QString addStartDelimiter(const QString &path); 58 static QString removeAllDelimiters(const QString &path); 59 60 // static QString removeTrailingDelimiters(const QString &path); 61 static QString sanitize(const QString &path); 62 /** Merge prefix and suffix by making sure they have a single '/' in between */ 63 static QString mergePaths(const QString &path, const QString &baseName); 64 /** Returns the last part of the @p path. That is the filename or directory name without the path */ 65 static QString getObjectName(const QString &path); 66 /** Remove the object name and return the path */ 67 static QString getPathExceptObjectName(const QString &path); 68 /** Replace the last part of the @p previusPath with newBaseName */ 69 static QString constructNewItemPath(const QString &previousPath, const QString &newBaseName); 70 71 static const QChar delimiter; 72 }; 73 74 const QChar UIPathOperations::delimiter = QChar('/'); 75 76 QString UIPathOperations::removeMultipleDelimiters(const QString &path) 77 { 78 QString newPath(path); 79 QString doubleDelimiter(2, delimiter); 80 81 while (newPath.contains(doubleDelimiter) && !newPath.isEmpty()) 82 newPath = newPath.replace(doubleDelimiter, delimiter); 83 return newPath; 84 } 85 86 QString UIPathOperations::removeTrailingDelimiters(const QString &path) 87 { 88 if (path.isNull() || path.isEmpty()) 89 return QString(); 90 QString newPath(path); 91 /* Make sure for we dont have any trailing slashes: */ 92 while (newPath.length() > 1 && newPath.at(newPath.length() - 1) == UIPathOperations::delimiter) 93 newPath.chop(1); 94 return newPath; 95 } 96 97 QString UIPathOperations::addStartDelimiter(const QString &path) 98 { 99 if (path.isEmpty()) 100 return QString(path); 101 QString newPath(path); 102 if (newPath.at(0) != delimiter) 103 newPath.insert(0, delimiter); 104 return newPath; 105 } 106 107 QString UIPathOperations::sanitize(const QString &path) 108 { 109 return addStartDelimiter(removeTrailingDelimiters(removeMultipleDelimiters(path))); 110 } 111 112 QString UIPathOperations::mergePaths(const QString &path, const QString &baseName) 113 { 114 QString newBase(baseName); 115 newBase = newBase.remove(delimiter); 116 117 /* make sure we have one and only one trailing '/': */ 118 QString newPath(sanitize(path)); 119 if(newPath.isEmpty()) 120 newPath = delimiter; 121 if(newPath.at(newPath.length() - 1) != delimiter) 122 newPath += UIPathOperations::delimiter; 123 newPath += newBase; 124 return sanitize(newPath); 125 } 126 127 QString UIPathOperations::getObjectName(const QString &path) 128 { 129 if (path.length() <= 1) 130 return QString(path); 131 132 QString strTemp(sanitize(path)); 133 if (strTemp.length() < 2) 134 return strTemp; 135 int lastSlashPosition = strTemp.lastIndexOf(UIPathOperations::delimiter); 136 if (lastSlashPosition == -1) 137 return QString(); 138 return strTemp.right(strTemp.length() - lastSlashPosition - 1); 139 } 140 141 QString UIPathOperations::getPathExceptObjectName(const QString &path) 142 { 143 if (path.length() <= 1) 144 return QString(path); 145 146 QString strTemp(sanitize(path)); 147 int lastSlashPosition = strTemp.lastIndexOf(UIPathOperations::delimiter); 148 if (lastSlashPosition == -1) 149 return QString(); 150 return strTemp.left(lastSlashPosition + 1); 151 } 152 153 QString UIPathOperations::constructNewItemPath(const QString &previousPath, const QString &newBaseName) 154 { 155 if (previousPath.length() <= 1) 156 return QString(previousPath); 157 return sanitize(mergePaths(getPathExceptObjectName(previousPath), newBaseName)); 158 } 49 159 50 160 … … 128 238 , m_bIsOpened(false) 129 239 { 130 131 240 } 132 241 … … 224 333 return; 225 334 m_strPath = path; 226 /* Make sure for we dont have any trailing slashes: */ 227 if (m_strPath.length() > 1 && m_strPath.at(m_strPath.length() - 1) == QChar('/')) 228 m_strPath.chop(1); 229 } 230 231 void UIFileTableItem::setPath(const QString &prefix, const QString &suffix) 232 { 233 if (prefix.isEmpty()) 234 return; 235 QString newPath(prefix); 236 /* Make sure we have a trailing '/' in @p prefix: */ 237 if (prefix.at(newPath.length() - 1) != QChar('/')) 238 newPath += "/"; 239 newPath += suffix; 240 setPath(newPath); 335 UIPathOperations::removeTrailingDelimiters(m_strPath); 241 336 } 242 337 … … 785 880 } 786 881 787 QString UIGuestControlFileTable::constructNewItemPath(const QString &previousPath, const QString &newBaseName)788 {789 if (newBaseName.isEmpty() || previousPath.length() <= 1)790 return QString();791 792 QStringList pathList = previousPath.split('/', QString::SkipEmptyParts);793 QString newPath("/");794 for(int i = 0; i < pathList.size() - 1; ++i)795 {796 newPath += (pathList.at(i) + "/");797 }798 newPath += newBaseName;799 return newPath;800 }801 802 QString UIGuestControlFileTable::mergePaths(const QString &path, const QString &baseName)803 {804 QString newPath(path);805 /* make sure we have a trailing '/': */806 if (newPath.at(newPath.length() - 1) != QChar('/'))807 newPath += QChar('/');808 newPath += baseName;809 return newPath;810 }811 882 812 883 QString UIGuestControlFileTable::getNewDirectoryName() … … 823 894 } 824 895 825 QString UIGuestControlFileTable::current Path() const896 QString UIGuestControlFileTable::currentDirectoryPath() const 826 897 { 827 898 if (!m_pView) … … 833 904 if (!item) 834 905 return QString(); 906 /* be paranoid: */ 907 if (!item->isDirectory()) 908 return QString(); 835 909 return item->path(); 836 910 } … … 898 972 directory = m_comGuestSession.DirectoryOpen(strPath, /*aFilter*/ "", flag); 899 973 parent->setIsOpened(true); 900 901 974 if (directory.isOk()) 902 975 { … … 913 986 bool isDirectory = (fsInfo.GetType() == KFsObjType_Directory); 914 987 UIFileTableItem *item = new UIFileTableItem(data, isDirectory, parent); 915 item->setPath( strPath, fsInfo.GetName());988 item->setPath(UIPathOperations::mergePaths(strPath, fsInfo.GetName())); 916 989 if (isDirectory) 917 990 { … … 930 1003 updateCurrentLocationEdit(strPath); 931 1004 } 1005 directory.Close(); 932 1006 } 933 1007 … … 963 1037 if (!item || item->isUpDirectory() || newBaseName.isEmpty() || !m_comGuestSession.isOk()) 964 1038 return false; 965 QString newPath = constructNewItemPath(item->path(), newBaseName);1039 QString newPath = UIPathOperations::constructNewItemPath(item->path(), newBaseName); 966 1040 QVector<KFsObjRenameFlag> aFlags(KFsObjRenameFlag_Replace); 967 1041 … … 984 1058 return false; 985 1059 986 QString newDirectoryPath = mergePaths(path, directoryName);1060 QString newDirectoryPath = UIPathOperations::mergePaths(path, directoryName); 987 1061 QVector<KDirectoryCreateFlag> flags(KDirectoryCreateFlag_None); 988 1062 … … 999 1073 void UIGuestFileTable::copyGuestToHost(const QString& hostDestinationPath) 1000 1074 { 1001 Q_UNUSED(hostDestinationPath); 1075 QStringList selectedPathList = selectedItemPathList(); 1076 for (int i = 0; i < selectedPathList.size(); ++i) 1077 copyGuestToHost(selectedPathList.at(i), hostDestinationPath); 1002 1078 } 1003 1079 1004 1080 void UIGuestFileTable::copyHostToGuest(const QStringList &hostSourcePathList) 1005 1081 { 1006 Q_UNUSED(hostSourcePathList); 1082 for (int i = 0; i < hostSourcePathList.size(); ++i) 1083 copyHostToGuest(hostSourcePathList.at(i), currentDirectoryPath()); 1084 } 1085 1086 bool UIGuestFileTable::copyGuestToHost(const QString &guestSourcePath, const QString& hostDestinationPath) 1087 { 1088 if (m_comGuestSession.isNull()) 1089 return false; 1090 1091 /* Currently API expects a path including a file name for file copy*/ 1092 KFsObjType objectType = fsObjectType(guestSourcePath); 1093 if (objectType == KFsObjType_File) 1094 { 1095 // QString destinatioFilePath = mergePaths(hostDestinationPath, const QString &Path, const QString &baseName); 1096 1097 } 1098 1099 QVector<KDirectoryCopyFlag> aFlags(KDirectoryCopyFlag_CopyIntoExisting); 1100 /** @todo listen to CProgress object to monitor copy operation: */ 1101 /*CProgress comProgress = */m_comGuestSession.DirectoryCopyFromGuest(guestSourcePath, hostDestinationPath, aFlags); 1102 if (!m_comGuestSession.isOk()) 1103 return false; 1104 return true; 1105 } 1106 1107 bool UIGuestFileTable::copyHostToGuest(const QString &hostSourcePath, const QString &guestDestinationPath) 1108 { 1109 if (m_comGuestSession.isNull()) 1110 return false; 1111 QVector<KDirectoryCopyFlag> aFlags(KDirectoryCopyFlag_CopyIntoExisting); 1112 /** @todo listen to CProgress object to monitor copy operation: */ 1113 /*CProgress comProgress = */m_comGuestSession.DirectoryCopyToGuest(hostSourcePath, guestDestinationPath, aFlags); 1114 return true; 1115 } 1116 1117 KFsObjType UIGuestFileTable::fsObjectType(const QString& path) 1118 { 1119 if (m_comGuestSession.isNull()) 1120 return KFsObjType_Unknown; 1121 CGuestFsObjInfo comFsObjInfo = m_comGuestSession.FsObjQueryInfo(path, false /*aFollowSymlinks*/); 1122 if (!comFsObjInfo.isOk() || m_comGuestSession.isOk()) 1123 return KFsObjType_Unknown; 1124 return comFsObjInfo.GetType(); 1007 1125 } 1008 1126 … … 1108 1226 if (!item || item->isUpDirectory() || newBaseName.isEmpty()) 1109 1227 return false; 1110 QString newPath = constructNewItemPath(item->path(), newBaseName);1228 QString newPath = UIPathOperations::constructNewItemPath(item->path(), newBaseName); 1111 1229 QDir tempDir; 1112 1230 if (tempDir.rename(item->path(), newPath)) … … 1123 1241 if (!parentDir.mkdir(directoryName)) 1124 1242 { 1125 emit sigLogOutput( mergePaths(path, directoryName).append(" could not be created"));1243 emit sigLogOutput(UIPathOperations::mergePaths(path, directoryName).append(" could not be created")); 1126 1244 return false; 1127 1245 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h
r71276 r71298 68 68 const QString &path() const; 69 69 void setPath(const QString &path); 70 /** Merge prefix and suffix by making sure they have a single '/' in between */71 void setPath(const QString &prexix, const QString &suffix);72 70 73 71 /** True if this is directory and name is ".." */ … … 85 83 /** Full absolute path of the item. Without the trailing '/' */ 86 84 QString m_strPath; 87 /** For directories base name is the name of the lowest level directory 88 in strPath. eg. for 'm_strPath = /opt/qt5.6/examples' 'm_strBaseName = examples' 89 for files it is the name of the file */ 90 QString m_strBaseName; 85 91 86 }; 92 87 … … 112 107 void emitLogOutput(const QString& strOutput); 113 108 /** Returns the path of the rootIndex */ 114 QString current Path() const;109 QString currentDirectoryPath() const; 115 110 /** Returns the paths of the selected items (if any) as a list */ 116 111 QStringList selectedItemPathList(); … … 138 133 void keyPressEvent(QKeyEvent * pEvent); 139 134 140 /** Replace the last part of the @p previusPath with newBaseName */ 141 QString constructNewItemPath(const QString &previousPath, const QString &newBaseName); 142 QString mergePaths(const QString &Path, const QString &baseName); 135 143 136 144 137 UIFileTableItem *m_pRootItem; … … 212 205 private: 213 206 207 KFsObjType fsObjectType(const QString& path); 208 bool copyGuestToHost(const QString &guestSourcePath, const QString& hostDestinationPath); 209 bool copyHostToGuest(const QString& hostSourcePath, const QString &guestDestinationPath); 210 214 211 void configureObjects(); 215 212 CGuestSession m_comGuestSession;
Note:
See TracChangeset
for help on using the changeset viewer.