Changeset 75000 in vbox
- Timestamp:
- Oct 23, 2018 2:01:46 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 126028
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileManager.cpp
r74947 r75000 79 79 UIGuestControlFileManagerSettings::UIGuestControlFileManagerSettings() 80 80 : bListDirectoriesOnTop(true) 81 , bAskDeleteConfirmation(false) 81 82 { 82 83 } … … 390 391 m_pFileTableContainerLayout->setSpacing(0); 391 392 m_pFileTableContainerLayout->setContentsMargins(0, 0, 0, 0); 392 m_pGuestFileTable = new 393 m_pGuestFileTable = new UIGuestFileTable; 393 394 m_pGuestFileTable->setEnabled(false); 394 395 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileManager.h
r74947 r75000 56 56 57 57 bool bListDirectoriesOnTop; 58 bool bAskDeleteConfirmation; 58 59 private: 59 60 UIGuestControlFileManagerSettings(); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp
r74811 r75000 81 81 void sigPaste(); 82 82 void sigShowProperties(); 83 84 83 void sigSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected); 85 84 … … 93 92 virtual void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) /*override */; 94 93 void contextMenuEvent(QContextMenuEvent *pEvent); 94 //void keyPressEvent(QKeyEvent * pEvent); 95 95 96 96 private: 97 97 98 98 void configure(); 99 99 QWidget *m_pParent; 100 100 }; 101 101 … … 304 304 *********************************************************************************************************************************/ 305 305 306 UIGuestControlFileView::UIGuestControlFileView(QWidget * 306 UIGuestControlFileView::UIGuestControlFileView(QWidget *parent) 307 307 :QTableView(parent) 308 , m_pParent(parent) 308 309 { 309 310 configure(); … … 319 320 verticalHeader()->setDefaultSectionSize(verticalHeader()->minimumSectionSize()); 320 321 setAlternatingRowColors(true); 322 installEventFilter(m_pParent); 321 323 } 322 324 … … 347 349 if (pActionRefresh) 348 350 { 349 pActionRefresh->setIcon(UIIconPool::iconSet(QString(":/refresh_24 .png")));351 pActionRefresh->setIcon(UIIconPool::iconSet(QString(":/refresh_24px.png"))); 350 352 connect(pActionRefresh, &QAction::triggered, this, &UIGuestControlFileView::sigRefresh); 351 353 } … … 834 836 m_pProxyModel->setSourceModel(m_pModel); 835 837 836 m_pView = new UIGuestControlFileView ;838 m_pView = new UIGuestControlFileView(this); 837 839 if (m_pView) 838 840 { 839 841 m_pMainLayout->addWidget(m_pView, 2, 0, 5, 5); 840 842 m_pView->setModel(m_pProxyModel); 841 //m_pView->setModel(m_pModel);842 843 m_pView->setItemDelegate(new UIFileDelegate); 843 844 m_pView->setSortingEnabled(true); … … 846 847 connect(m_pView, &UIGuestControlFileView::doubleClicked, 847 848 this, &UIGuestControlFileTable::sltItemDoubleClicked); 849 connect(m_pView, &UIGuestControlFileView::clicked, 850 this, &UIGuestControlFileTable::sltItemClicked); 848 851 connect(m_pView, &UIGuestControlFileView::sigGoUp, 849 852 this, &UIGuestControlFileTable::sltGoUp); … … 870 873 871 874 } 875 m_pSearchLineEdit = new QILineEdit; 876 if (m_pSearchLineEdit) 877 { 878 m_pMainLayout->addWidget(m_pSearchLineEdit, 8, 0, 1, 5); 879 m_pSearchLineEdit->hide(); 880 m_pSearchLineEdit->setClearButtonEnabled(true); 881 connect(m_pSearchLineEdit, &QLineEdit::textChanged, 882 this, &UIGuestControlFileTable::sltSearchTextChanged); 883 } 872 884 } 873 885 … … 897 909 { 898 910 connect(m_pRefresh, &QAction::triggered, this, &UIGuestControlFileTable::sltRefresh); 899 m_pRefresh->setIcon(UIIconPool::iconSet(QString(":/refresh_24 .png")));911 m_pRefresh->setIcon(UIIconPool::iconSet(QString(":/refresh_24px.png"))); 900 912 m_pToolBar->addAction(m_pRefresh); 901 913 } … … 1100 1112 } 1101 1113 1114 void UIGuestControlFileTable::sltItemClicked(const QModelIndex &index) 1115 { 1116 Q_UNUSED(index); 1117 disableSelectionSearch(); 1118 } 1119 1102 1120 void UIGuestControlFileTable::sltGoUp() 1103 1121 { … … 1342 1360 } 1343 1361 1362 void UIGuestControlFileTable::sltSearchTextChanged(const QString &strText) 1363 { 1364 performSelectionSearch(strText); 1365 } 1366 1344 1367 void UIGuestControlFileTable::deSelectUpDirectoryItem() 1345 1368 { … … 1390 1413 } 1391 1414 1415 void UIGuestControlFileTable::setSelection(const QModelIndex &indexInProxyModel) 1416 { 1417 if (!m_pView) 1418 return; 1419 QItemSelectionModel *selectionModel = m_pView->selectionModel(); 1420 if (!selectionModel) 1421 return; 1422 selectionModel->select(indexInProxyModel, QItemSelectionModel::Current | QItemSelectionModel::Rows | QItemSelectionModel::Select); 1423 m_pView->scrollTo(indexInProxyModel, QAbstractItemView::EnsureVisible); 1424 } 1425 1392 1426 void UIGuestControlFileTable::deleteByIndex(const QModelIndex &itemIndex) 1393 1427 { … … 1486 1520 } 1487 1521 1488 1489 void UIGuestControlFileTable::keyPressEvent(QKeyEvent * pEvent) 1490 { 1491 /* Browse into directory with enter: */ 1492 if (pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return) 1493 { 1494 if (m_pView && m_pModel) 1522 bool UIGuestControlFileTable::eventFilter(QObject *pObject, QEvent *pEvent) /* override */ 1523 { 1524 if (pEvent->type() == QEvent::KeyPress) 1525 { 1526 QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent); 1527 if (pKeyEvent) 1495 1528 { 1496 /* Get the selected item. If there are 0 or more than 1 selection do nothing: */ 1497 QItemSelectionModel *selectionModel = m_pView->selectionModel(); 1498 if (selectionModel) 1529 if (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return) 1499 1530 { 1500 QModelIndexList selectedItemIndices = selectionModel->selectedRows(); 1501 if (selectedItemIndices.size() == 1) 1502 goIntoDirectory(selectedItemIndices.at(0)); 1531 if (m_pView && m_pModel) 1532 { 1533 /* Get the selected item. If there are 0 or more than 1 selection do nothing: */ 1534 QItemSelectionModel *selectionModel = m_pView->selectionModel(); 1535 if (selectionModel) 1536 { 1537 QModelIndexList selectedItemIndices = selectionModel->selectedRows(); 1538 if (selectedItemIndices.size() == 1 && m_pModel) 1539 goIntoDirectory( m_pProxyModel->mapToSource(selectedItemIndices.at(0))); 1540 } 1541 } 1542 return true; 1543 } 1544 else if (pKeyEvent->key() == Qt::Key_Delete) 1545 { 1546 sltDelete(); 1547 return true; 1548 } 1549 else if (pKeyEvent->key() == Qt::Key_Backspace) 1550 { 1551 sltGoUp(); 1552 return true; 1553 } 1554 else if (pKeyEvent->text().length() == 1 && pKeyEvent->text().at(0).unicode() <= 127) 1555 { 1556 if (m_pSearchLineEdit) 1557 { 1558 m_pSearchLineEdit->show(); 1559 QString strText = m_pSearchLineEdit->text(); 1560 strText.append(pKeyEvent->text()); 1561 m_pSearchLineEdit->setText(strText); 1562 } 1503 1563 } 1504 1564 } 1505 1565 } 1506 else if (pEvent->key() == Qt::Key_Delete) 1507 { 1508 sltDelete(); 1509 } 1510 else if (pEvent->key() == Qt::Key_Backspace) 1511 { 1512 sltGoUp(); 1513 } 1514 1515 QWidget::keyPressEvent(pEvent); 1566 1567 return false; 1516 1568 } 1517 1569 … … 1543 1595 if (!m_pView) 1544 1596 return QString(); 1545 QModelIndex currentRoot = m_pView->rootIndex();1597 QModelIndex currentRoot = currentRootIndex(); 1546 1598 if (!currentRoot.isValid()) 1547 1599 return QString(); … … 1663 1715 } 1664 1716 1717 void UIGuestControlFileTable::performSelectionSearch(const QString &strSearchText) 1718 { 1719 if (!m_pProxyModel | !m_pView || strSearchText.isEmpty()) 1720 return; 1721 1722 int rowCount = m_pProxyModel->rowCount(m_pView->rootIndex()); 1723 UIFileTableItem *pFoundItem = 0; 1724 QModelIndex index; 1725 for (int i = 0; i < rowCount && !pFoundItem; ++i) 1726 { 1727 index = m_pProxyModel->index(i, 0, m_pView->rootIndex()); 1728 if (!index.isValid()) 1729 continue; 1730 pFoundItem = static_cast<UIFileTableItem*>(m_pProxyModel->mapToSource(index).internalPointer()); 1731 if (!pFoundItem) 1732 continue; 1733 const QString &strName = pFoundItem->name(); 1734 if (!strName.startsWith(m_pSearchLineEdit->text(), Qt::CaseInsensitive)) 1735 pFoundItem = 0; 1736 } 1737 if (pFoundItem) 1738 { 1739 /* Deselect anything that is already selected: */ 1740 m_pView->clearSelection(); 1741 setSelection(index); 1742 } 1743 } 1744 1745 void UIGuestControlFileTable::disableSelectionSearch() 1746 { 1747 if (!m_pSearchLineEdit) 1748 return; 1749 m_pSearchLineEdit->blockSignals(true); 1750 m_pSearchLineEdit->clear(); 1751 m_pSearchLineEdit->hide(); 1752 m_pSearchLineEdit->blockSignals(false); 1753 } 1665 1754 #include "UIGuestControlFileTable.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h
r72151 r75000 290 290 void goIntoDirectory(UIFileTableItem *item); 291 291 UIFileTableItem* indexData(const QModelIndex &index) const; 292 void keyPressEvent(QKeyEvent * pEvent);292 bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */; 293 293 CGuestFsObjInfo guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const; 294 294 … … 311 311 /* index is passed by the item view and represents the double clicked object's 'proxy' model index */ 312 312 void sltItemDoubleClicked(const QModelIndex &index); 313 void sltItemClicked(const QModelIndex &index); 313 314 void sltGoUp(); 314 315 void sltGoHome(); … … 325 326 void sltSelectAll(); 326 327 void sltInvertSelection(); 328 void sltSearchTextChanged(const QString &strText); 327 329 328 330 private: … … 340 342 void deSelectUpDirectoryItem(); 341 343 void setSelectionForAll(QItemSelectionModel::SelectionFlags flags); 344 void setSelection(const QModelIndex &indexInProxyModel); 342 345 /** The start directory requires a special attention since on file systems with drive letters 343 346 * drive letter are direct children of the start directory. On other systems start directory is '/' */ 344 347 void populateStartDirectory(UIFileTableItem *startItem); 345 348 QModelIndex currentRootIndex() const; 349 /* Searches the content of m_pSearchLineEdit within the current items' names and selects the item if found. */ 350 void performSelectionSearch(const QString &strSearchText); 351 /* Clears the m_pSearchLineEdit and hides it. */ 352 void disableSelectionSearch(); 353 346 354 UIGuestControlFileModel *m_pModel; 347 355 UIGuestControlFileView *m_pView; … … 364 372 /** The absolue path list of the file objects which user has chosen to cut/copy. this 365 373 * list will be cleaned after a paste operation or overwritten by a subsequent cut/copy */ 366 QStringList m_copyCutBuffer; 367 friend class UIGuestControlFileModel; 374 QStringList m_copyCutBuffer; 375 QILineEdit *m_pSearchLineEdit; 376 friend class UIGuestControlFileModel; 368 377 }; 369 378 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.cpp
r74947 r75000 316 316 void UIGuestFileTable::copyHostToGuest(const QStringList &hostSourcePathList) 317 317 { 318 for (int i = 0; i < hostSourcePathList.size(); ++i) 319 copyHostToGuest(hostSourcePathList.at(i), currentDirectoryPath()); 318 QVector<QString> sourcePaths = hostSourcePathList.toVector(); 319 QVector<QString> aFilters; 320 QVector<QString> aFlags; 321 m_comGuestSession.CopyToGuest(sourcePaths, aFilters, aFlags, currentDirectoryPath()); 322 if (!m_comGuestSession.isOk()) 323 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession)); 324 else 325 refresh(); 320 326 } 321 327 … … 344 350 345 351 /** @todo listen to CProgress object to monitor copy operation: */ 346 /*CProgress comProgress = */ m_comGuestSession.DirectoryCopyFromGuest(guestSourcePath, hostDestinationPath/*destinatioFilePath*/ , aFlags); 347 m_comGuestSession.DirectoryCopyFromGuest(guestSourcePath, destinatioFilePath , aFlags); 348 m_comGuestSession.DirectoryCopyFromGuest(sourceWithDelimiter, destinatioFilePath , aFlags); 349 m_comGuestSession.DirectoryCopyFromGuest(sourceWithDelimiter, hostDestinationPath , aFlags); 352 /*CProgress comProgress = */ 353 // m_comGuestSession.DirectoryCopyFromGuest(guestSourcePath, hostDestinationPath/*destinatioFilePath*/ , aFlags); 354 // m_comGuestSession.DirectoryCopyFromGuest(guestSourcePath, destinatioFilePath , aFlags); 355 // m_comGuestSession.DirectoryCopyFromGuest(sourceWithDelimiter, destinatioFilePath , aFlags); 356 // m_comGuestSession.DirectoryCopyFromGuest(sourceWithDelimiter, hostDestinationPath , aFlags); 350 357 351 358 } … … 359 366 } 360 367 361 bool UIGuestFileTable::copyHostToGuest(const QString &hostSourcePath, const QString &guestDestinationPath)362 {363 if (m_comGuestSession.isNull())364 return false;365 QFileInfo hostFileInfo(hostSourcePath);366 if (!hostFileInfo.exists())367 return false;368 CProgress comProgress;369 /* Currently API expects a path including a file name for file copy*/370 if (hostFileInfo.isFile() || hostFileInfo.isSymLink())371 {372 QVector<KFileCopyFlag> flags(KFileCopyFlag_FollowLinks);373 QString destinationFilePath = UIPathOperations::addTrailingDelimiters(guestDestinationPath);374 /** @todo listen to CProgress object to monitor copy operation: */375 comProgress = m_comGuestSession.FileCopyToGuest(hostSourcePath, destinationFilePath, flags);376 }377 else if(hostFileInfo.isDir())378 {379 380 QVector<KDirectoryCopyFlag> aFlags(KDirectoryCopyFlag_CopyIntoExisting);381 QString destinationFilePath = UIPathOperations::addTrailingDelimiters(guestDestinationPath);382 /** @todo listen to CProgress object to monitor copy operation: */383 comProgress = m_comGuestSession.DirectoryCopyToGuest(hostSourcePath, destinationFilePath, aFlags);384 }385 /** @todo currently I cannot get an errorfrom CProgress: */386 if (m_comGuestSession.isOk())387 {388 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)389 {390 emit sigLogOutput(UIErrorString::formatErrorInfo(comProgress));391 return false;392 }393 }394 else395 {396 emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession));397 return false;398 }399 /** @todo we have to until CProgress finishes to refresh: */400 refresh();401 return true;402 }368 // bool UIGuestFileTable::copyHostToGuest(const QString &hostSourcePath, const QString &guestDestinationPath) 369 // { 370 // if (m_comGuestSession.isNull()) 371 // return false; 372 // QFileInfo hostFileInfo(hostSourcePath); 373 // if (!hostFileInfo.exists()) 374 // return false; 375 // CProgress comProgress; 376 // /* Currently API expects a path including a file name for file copy*/ 377 // if (hostFileInfo.isFile() || hostFileInfo.isSymLink()) 378 // { 379 // QVector<KFileCopyFlag> flags(KFileCopyFlag_FollowLinks); 380 // QString destinationFilePath = UIPathOperations::addTrailingDelimiters(guestDestinationPath); 381 // /** @todo listen to CProgress object to monitor copy operation: */ 382 // comProgress = m_comGuestSession.FileCopyToGuest(hostSourcePath, destinationFilePath, flags); 383 // } 384 // else if(hostFileInfo.isDir()) 385 // { 386 387 // QVector<KDirectoryCopyFlag> aFlags(KDirectoryCopyFlag_CopyIntoExisting); 388 // QString destinationFilePath = UIPathOperations::addTrailingDelimiters(guestDestinationPath); 389 // /** @todo listen to CProgress object to monitor copy operation: */ 390 // comProgress = m_comGuestSession.DirectoryCopyToGuest(hostSourcePath, destinationFilePath, aFlags); 391 // } 392 // /** @todo currently I cannot get an errorfrom CProgress: */ 393 // if (m_comGuestSession.isOk()) 394 // { 395 // if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 396 // { 397 // emit sigLogOutput(UIErrorString::formatErrorInfo(comProgress)); 398 // return false; 399 // } 400 // } 401 // else 402 // { 403 // emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession)); 404 // return false; 405 // } 406 // /** @todo we have to until CProgress finishes to refresh: */ 407 // refresh(); 408 // return true; 409 // } 403 410 404 411 FileObjectType UIGuestFileTable::fileType(const CFsObjInfo &fsInfo)
Note:
See TracChangeset
for help on using the changeset viewer.