Changeset 71350 in vbox
- Timestamp:
- Mar 15, 2018 1:22:58 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileManager.cpp
r71325 r71350 406 406 void UIGuestControlFileManager::sltGuestSessionUnregistered(CGuestSession guestSession) 407 407 { 408 if (!guestSession.isOk()) 409 return; 410 if (guestSession == m_comGuestSession && m_comGuestSession.isOk()) 408 if (guestSession.isNull()) 409 return; 410 if (guestSession == m_comGuestSession && !m_comGuestSession.isNull()) 411 { 411 412 m_comGuestSession.detach(); 412 postSessionClosed(); 413 postSessionClosed(); 414 } 413 415 } 414 416 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileModel.cpp
r71274 r71350 38 38 { 39 39 QList<QVariant> rootData; 40 // rootData << "Title" << "Summary";41 // rootItem = new UIFileTableItem(rootData);42 40 } 43 41 … … 122 120 return QIcon(":/sf_32px.png"); 123 121 } 124 else 125 return QIcon(":/vm_open_filemanager_16px"); 122 else if (item->isFile()) 123 return QIcon(":/vm_open_filemanager_16px.png"); 124 else if (item->isSymLink()) 125 { 126 if (item->isTargetADirectory()) 127 return QIcon(":/sf_read_16px.png"); 128 else 129 return QIcon(":/drag_drop_16px.png"); 130 } 126 131 } 127 132 … … 246 251 QList<QVariant> data; 247 252 data << "New Item" << 0 << QDateTime::currentDateTime(); 248 UIFileTableItem *newItem = new UIFileTableItem(data, true, parentItem);253 UIFileTableItem *newItem = new UIFileTableItem(data, parentItem, FileObjectType_Directory); 249 254 parentItem->appendChild(newItem); 250 255 endInsertRows(); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp
r71330 r71350 230 230 231 231 232 UIFileTableItem::UIFileTableItem(const QList<QVariant> &data, bool isDirectory, UIFileTableItem *parent) 232 UIFileTableItem::UIFileTableItem(const QList<QVariant> &data, 233 UIFileTableItem *parent, FileObjectType type) 233 234 : m_itemData(data) 234 235 , m_parentItem(parent) 235 , m_bIsDirectory(isDirectory)236 236 , m_bIsOpened(false) 237 , m_isTargetADirectory(false) 238 , m_type(type) 237 239 { 238 240 } … … 295 297 if (m_parentItem) 296 298 return m_parentItem->m_childItems.indexOf(const_cast<UIFileTableItem*>(this)); 297 298 299 return 0; 299 300 } … … 301 302 bool UIFileTableItem::isDirectory() const 302 303 { 303 return m_bIsDirectory; 304 return m_type == FileObjectType_Directory; 305 } 306 307 bool UIFileTableItem::isSymLink() const 308 { 309 return m_type == FileObjectType_SymLink; 310 } 311 312 bool UIFileTableItem::isFile() const 313 { 314 return m_type == FileObjectType_File; 304 315 } 305 316 … … 336 347 bool UIFileTableItem::isUpDirectory() const 337 348 { 338 if (! m_bIsDirectory)349 if (!isDirectory()) 339 350 return false; 340 351 if (data(0) == QString("..")) 341 352 return true; 342 353 return false; 354 } 355 356 FileObjectType UIFileTableItem::type() const 357 { 358 return m_type; 359 } 360 361 const QString &UIFileTableItem::targetPath() const 362 { 363 return m_strTargetPath; 364 } 365 366 void UIFileTableItem::setTargetPath(const QString &path) 367 { 368 m_strTargetPath = path; 369 } 370 371 bool UIFileTableItem::isTargetADirectory() const 372 { 373 return m_isTargetADirectory; 374 } 375 376 void UIFileTableItem::setIsTargetADirectory(bool flag) 377 { 378 m_isTargetADirectory = flag; 343 379 } 344 380 … … 500 536 { 501 537 connect(m_pCreateNewDirectory, &QAction::triggered, this, &UIGuestControlFileTable::sltCreateNewDirectory); 502 m_pCreateNewDirectory->setIcon(UIIconPool::iconSet(QString(":/sf_ 32px.png")));538 m_pCreateNewDirectory->setIcon(UIIconPool::iconSet(QString(":/sf_add_16px.png"))); 503 539 m_pToolBar->addAction(m_pCreateNewDirectory); 504 540 } … … 558 594 QList<QVariant> headData; 559 595 headData << "Name" << "Size" << "Change Time"; 560 m_pRootItem = new UIFileTableItem(headData, true, 0); 561 596 m_pRootItem = new UIFileTableItem(headData, 0, FileObjectType_Directory); 562 597 QList<QVariant> startDirData; 563 598 startDirData << "/" << 4096 << QDateTime(); 564 UIFileTableItem* startItem = new UIFileTableItem(startDirData, true, m_pRootItem); 599 UIFileTableItem* startItem = new UIFileTableItem(startDirData, m_pRootItem, FileObjectType_Directory); 600 565 601 startItem->setPath("/"); 566 602 m_pRootItem->appendChild(startItem); … … 578 614 UIFileTableItem *parent, bool isDirectoryMap, bool isStartDir) 579 615 { 580 /* Make sure we have a ".." item within directories, and make sure it does not include for the start dir: */616 /* Make sure we have a ".." item within directories, and make sure it is not there for the start dir: */ 581 617 if (isDirectoryMap) 582 618 { … … 585 621 QList<QVariant> data; 586 622 data << ".." << 4096; 587 UIFileTableItem *item = new UIFileTableItem(data, isDirectoryMap, parent);623 UIFileTableItem *item = new UIFileTableItem(data, parent, FileObjectType_Directory); 588 624 item->setIsOpened(false); 589 625 map.insert("..", item); … … 633 669 void UIGuestControlFileTable::goIntoDirectory(const QModelIndex &itemIndex) 634 670 { 635 UIFileTableItem *item = static_cast<UIFileTableItem*>(itemIndex.internalPointer()); 671 if (!m_pModel) 672 return; 673 674 /* Make sure the colum is 0: */ 675 QModelIndex index = m_pModel->index(itemIndex.row(), 0, itemIndex.parent()); 676 if (!index.isValid()) 677 return; 678 679 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer()); 636 680 if (!item) 637 681 return; … … 640 684 if (item->isUpDirectory()) 641 685 { 642 QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(i temIndex));686 QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(index)); 643 687 if (parentIndex.isValid()) 644 688 changeLocation(parentIndex); … … 650 694 if (!item->isOpened()) 651 695 readDirectory(item->path(),item); 652 changeLocation(i temIndex);696 changeLocation(index); 653 697 } 654 698 … … 989 1033 990 1034 data << fsInfo.GetName() << static_cast<qulonglong>(fsInfo.GetObjectSize()) << changeTime; 991 bool isDirectory = (fsInfo.GetType() == KFsObjType_Directory);992 UIFileTableItem *item = new UIFileTableItem(data, isDirectory, parent);1035 FileObjectType fileType = getFileType(fsInfo); 1036 UIFileTableItem *item = new UIFileTableItem(data, parent, fileType); 993 1037 item->setPath(UIPathOperations::mergePaths(strPath, fsInfo.GetName())); 994 if ( isDirectory)1038 if (fileType == FileObjectType_Directory) 995 1039 { 996 1040 directories.insert(fsInfo.GetName(), item); 997 1041 item->setIsOpened(false); 998 1042 } 999 else 1043 else if(fileType == FileObjectType_File) 1000 1044 { 1001 1045 files.insert(fsInfo.GetName(), item); 1002 1046 item->setIsOpened(false); 1003 1047 } 1048 /** @todo Seems like our API is not able to detect symlinks: */ 1049 else if(fileType == FileObjectType_SymLink) 1050 { 1051 files.insert(fsInfo.GetName(), item); 1052 item->setIsOpened(false); 1053 } 1054 1004 1055 fsInfo = directory.Read(); 1005 1056 } … … 1124 1175 bool UIGuestFileTable::copyHostToGuest(const QString &hostSourcePath, const QString &guestDestinationPath) 1125 1176 { 1126 Q_UNUSED(guestDestinationPath);1127 1177 if (m_comGuestSession.isNull()) 1128 1178 return false; … … 1134 1184 if (hostFileInfo.isFile() || hostFileInfo.isSymLink()) 1135 1185 { 1186 QVector<KFileCopyFlag> flags(KFileCopyFlag_FollowLinks); 1187 /* API expects a full file path as destionation: */ 1188 QString destinationFilePath = UIPathOperations::mergePaths(guestDestinationPath, UIPathOperations::getObjectName(hostSourcePath)); 1189 /** @todo listen to CProgress object to monitor copy operation: */ 1190 /*CProgress comProgress =*/ m_comGuestSession.FileCopyFromGuest(hostSourcePath, destinationFilePath, flags); 1136 1191 } 1137 1192 else if(hostFileInfo.isDir()) 1138 1193 { 1139 } 1140 // { 1141 // QVector<KFileCopyFlag> flags(KFileCopyFlag_FollowLinks); 1142 // /* API expects a full file path as destionation: */ 1143 // QString destinatioFilePath = UIPathOperations::mergePaths(guestDestinationPath, 1144 // UIPathOperations::getObjectName(hostSourcePath)); 1145 // /** @todo listen to CProgress object to monitor copy operation: */ 1146 // /*CProgress comProgress =*/ m_comGuestSession.FileCopyToGuest(hostSourcePath, destinatioFilePath, flags); 1147 1148 // } 1149 // else if (objectType == KFsObjType_Directory) 1150 // { 1151 // QVector<KDirectoryCopyFlag> aFlags(KDirectoryCopyFlag_CopyIntoExisting); 1152 // /** @todo listen to CProgress object to monitor copy operation: */ 1153 // /*CProgress comProgress = */ m_comGuestSession.DirectoryCopyToGuest(hostSourcePath, guestDestinationPath, aFlags); 1154 // } 1155 // if (!m_comGuestSession.isOk()) 1156 // return false; 1194 QVector<KDirectoryCopyFlag> aFlags(KDirectoryCopyFlag_CopyIntoExisting); 1195 /** @todo listen to CProgress object to monitor copy operation: */ 1196 /*CProgress comProgress = */ m_comGuestSession.DirectoryCopyToGuest(hostSourcePath, guestDestinationPath, aFlags); 1197 } 1198 if (!m_comGuestSession.isOk()) 1199 return false; 1157 1200 return true; 1158 1201 } 1159 1202 1203 FileObjectType UIGuestFileTable::getFileType(const CFsObjInfo &fsInfo) 1204 { 1205 if (fsInfo.isNull() || !fsInfo.isOk()) 1206 return FileObjectType_Unknown; 1207 if (fsInfo.GetType() == KFsObjType_Directory) 1208 return FileObjectType_Directory; 1209 else if (fsInfo.GetType() == KFsObjType_File) 1210 return FileObjectType_File; 1211 else if (fsInfo.GetType() == KFsObjType_Symlink) 1212 return FileObjectType_SymLink; 1213 1214 return FileObjectType_Other; 1215 } 1160 1216 1161 1217 /********************************************************************************************************************************* … … 1194 1250 { 1195 1251 const QFileInfo &fileInfo = entries.at(i); 1252 1196 1253 QList<QVariant> data; 1197 1254 data << fileInfo.fileName() << fileInfo.size() << fileInfo.lastModified(); 1198 UIFileTableItem *item = new UIFileTableItem(data, fileInfo.isDir(), parent);1255 UIFileTableItem *item = new UIFileTableItem(data, parent, getFileType(fileInfo)); 1199 1256 item->setPath(fileInfo.absoluteFilePath()); 1257 /* if the item is a symlink set the target path and 1258 check the target if it is a directory: */ 1259 if (fileInfo.isSymLink()) 1260 { 1261 item->setTargetPath(fileInfo.symLinkTarget()); 1262 item->setIsTargetADirectory(QFileInfo(fileInfo.symLinkTarget()).isDir()); 1263 } 1200 1264 if (fileInfo.isDir()) 1201 1265 { … … 1208 1272 item->setIsOpened(false); 1209 1273 } 1210 1211 1274 } 1212 1275 insertItemsToTree(directories, parent, true, isStartDir); … … 1281 1344 } 1282 1345 1346 FileObjectType UIHostFileTable::getFileType(const QFileInfo &fsInfo) 1347 { 1348 if (!fsInfo.exists()) 1349 return FileObjectType_Unknown; 1350 /* first check if it is symlink becacuse for Qt 1351 being smylin and directory/file is not mutually exclusive: */ 1352 if (fsInfo.isSymLink()) 1353 return FileObjectType_SymLink; 1354 else if (fsInfo.isFile()) 1355 return FileObjectType_File; 1356 else if (fsInfo.isDir()) 1357 return FileObjectType_Directory; 1358 1359 return FileObjectType_Other; 1360 } 1361 1283 1362 #include "UIGuestControlFileTable.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h
r71325 r71350 32 32 /* Forward declarations: */ 33 33 class QAction; 34 class QFileInfo; 34 35 class QILabel; 35 36 class QILineEdit; … … 40 41 class UIToolBar; 41 42 43 enum FileObjectType 44 { 45 FileObjectType_File = 0, 46 FileObjectType_Directory, 47 FileObjectType_SymLink, 48 FileObjectType_Other, 49 FileObjectType_Unknown, 50 FileObjectType_Max 51 }; 52 42 53 /********************************************************************************************************************************* 43 54 * UIFileTableItem definition. * … … 47 58 { 48 59 public: 49 explicit UIFileTableItem(const QList<QVariant> &data, bool isDirectory, UIFileTableItem *parentItem); 60 61 explicit UIFileTableItem(const QList<QVariant> &data, 62 UIFileTableItem *parentItem, FileObjectType type); 50 63 ~UIFileTableItem(); 51 64 … … 63 76 64 77 bool isDirectory() const; 78 bool isSymLink() const; 79 bool isFile() const; 80 65 81 bool isOpened() const; 66 82 void setIsOpened(bool flag); … … 72 88 bool isUpDirectory() const; 73 89 void clearChildren(); 90 91 FileObjectType type() const; 92 93 const QString &targetPath() const; 94 void setTargetPath(const QString &path); 95 96 bool isTargetADirectory() const; 97 void setIsTargetADirectory(bool flag); 74 98 75 99 private: … … 79 103 QList<QVariant> m_itemData; 80 104 UIFileTableItem *m_parentItem; 81 bool m_bIsDirectory;82 105 bool m_bIsOpened; 83 106 /** Full absolute path of the item. Without the trailing '/' */ 84 107 QString m_strPath; 108 /** If this is a symlink m_targetPath keeps the absolute path of the target */ 109 QString m_strTargetPath; 110 /** True if this is a symlink and the target is a directory */ 111 bool m_isTargetADirectory; 112 FileObjectType m_type; 85 113 86 114 }; … … 205 233 private: 206 234 235 static FileObjectType getFileType(const CFsObjInfo &fsInfo); 207 236 bool copyGuestToHost(const QString &guestSourcePath, const QString& hostDestinationPath); 208 237 bool copyHostToGuest(const QString& hostSourcePath, const QString &guestDestinationPath); … … 224 253 protected: 225 254 255 static FileObjectType getFileType(const QFileInfo &fsInfo); 226 256 void retranslateUi() /* override */; 227 257 virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;
Note:
See TracChangeset
for help on using the changeset viewer.