VirtualBox

Changeset 75000 in vbox


Ignore:
Timestamp:
Oct 23, 2018 2:01:46 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126028
Message:

FE/Qt: bugref:6699. Adding a 'search to select' functionality to file manager

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  
    7979UIGuestControlFileManagerSettings::UIGuestControlFileManagerSettings()
    8080    : bListDirectoriesOnTop(true)
     81    , bAskDeleteConfirmation(false)
    8182{
    8283}
     
    390391            m_pFileTableContainerLayout->setSpacing(0);
    391392            m_pFileTableContainerLayout->setContentsMargins(0, 0, 0, 0);
    392             m_pGuestFileTable = new  UIGuestFileTable;
     393            m_pGuestFileTable = new UIGuestFileTable;
    393394            m_pGuestFileTable->setEnabled(false);
    394395
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileManager.h

    r74947 r75000  
    5656
    5757    bool bListDirectoriesOnTop;
     58    bool bAskDeleteConfirmation;
    5859private:
    5960    UIGuestControlFileManagerSettings();
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp

    r74811 r75000  
    8181    void sigPaste();
    8282    void sigShowProperties();
    83 
    8483    void sigSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
    8584
     
    9392    virtual void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) /*override */;
    9493    void contextMenuEvent(QContextMenuEvent *pEvent);
     94    //void keyPressEvent(QKeyEvent * pEvent);
    9595
    9696private:
    9797
    9898    void configure();
    99 
     99    QWidget *m_pParent;
    100100};
    101101
     
    304304*********************************************************************************************************************************/
    305305
    306 UIGuestControlFileView::UIGuestControlFileView(QWidget * parent)
     306UIGuestControlFileView::UIGuestControlFileView(QWidget *parent)
    307307    :QTableView(parent)
     308    , m_pParent(parent)
    308309{
    309310    configure();
     
    319320    verticalHeader()->setDefaultSectionSize(verticalHeader()->minimumSectionSize());
    320321    setAlternatingRowColors(true);
     322    installEventFilter(m_pParent);
    321323}
    322324
     
    347349    if (pActionRefresh)
    348350    {
    349         pActionRefresh->setIcon(UIIconPool::iconSet(QString(":/refresh_24.png")));
     351        pActionRefresh->setIcon(UIIconPool::iconSet(QString(":/refresh_24px.png")));
    350352        connect(pActionRefresh, &QAction::triggered, this, &UIGuestControlFileView::sigRefresh);
    351353    }
     
    834836    m_pProxyModel->setSourceModel(m_pModel);
    835837
    836     m_pView = new UIGuestControlFileView;
     838    m_pView = new UIGuestControlFileView(this);
    837839    if (m_pView)
    838840    {
    839841        m_pMainLayout->addWidget(m_pView, 2, 0, 5, 5);
    840842        m_pView->setModel(m_pProxyModel);
    841         //m_pView->setModel(m_pModel);
    842843        m_pView->setItemDelegate(new UIFileDelegate);
    843844        m_pView->setSortingEnabled(true);
     
    846847        connect(m_pView, &UIGuestControlFileView::doubleClicked,
    847848                this, &UIGuestControlFileTable::sltItemDoubleClicked);
     849        connect(m_pView, &UIGuestControlFileView::clicked,
     850                this, &UIGuestControlFileTable::sltItemClicked);
    848851        connect(m_pView, &UIGuestControlFileView::sigGoUp,
    849852                this, &UIGuestControlFileTable::sltGoUp);
     
    870873
    871874    }
     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    }
    872884}
    873885
     
    897909    {
    898910        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")));
    900912        m_pToolBar->addAction(m_pRefresh);
    901913    }
     
    11001112}
    11011113
     1114void UIGuestControlFileTable::sltItemClicked(const QModelIndex &index)
     1115{
     1116    Q_UNUSED(index);
     1117    disableSelectionSearch();
     1118}
     1119
    11021120void UIGuestControlFileTable::sltGoUp()
    11031121{
     
    13421360}
    13431361
     1362void UIGuestControlFileTable::sltSearchTextChanged(const QString &strText)
     1363{
     1364    performSelectionSearch(strText);
     1365}
     1366
    13441367void UIGuestControlFileTable::deSelectUpDirectoryItem()
    13451368{
     
    13901413}
    13911414
     1415void 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
    13921426void UIGuestControlFileTable::deleteByIndex(const QModelIndex &itemIndex)
    13931427{
     
    14861520}
    14871521
    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)
     1522bool 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)
    14951528        {
    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)
    14991530            {
    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                }
    15031563            }
    15041564        }
    15051565    }
    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;
    15161568}
    15171569
     
    15431595    if (!m_pView)
    15441596        return QString();
    1545     QModelIndex currentRoot = m_pView->rootIndex();
     1597    QModelIndex currentRoot = currentRootIndex();
    15461598    if (!currentRoot.isValid())
    15471599        return QString();
     
    16631715}
    16641716
     1717void 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
     1745void 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}
    16651754#include "UIGuestControlFileTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h

    r72151 r75000  
    290290    void             goIntoDirectory(UIFileTableItem *item);
    291291    UIFileTableItem* indexData(const QModelIndex &index) const;
    292     void             keyPressEvent(QKeyEvent * pEvent);
     292    bool             eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
    293293    CGuestFsObjInfo  guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const;
    294294
     
    311311    /* index is passed by the item view and represents the double clicked object's 'proxy' model index */
    312312    void sltItemDoubleClicked(const QModelIndex &index);
     313    void sltItemClicked(const QModelIndex &index);
    313314    void sltGoUp();
    314315    void sltGoHome();
     
    325326    void sltSelectAll();
    326327    void sltInvertSelection();
     328    void sltSearchTextChanged(const QString &strText);
    327329
    328330private:
     
    340342    void            deSelectUpDirectoryItem();
    341343    void            setSelectionForAll(QItemSelectionModel::SelectionFlags flags);
     344    void            setSelection(const QModelIndex &indexInProxyModel);
    342345    /** The start directory requires a special attention since on file systems with drive letters
    343346     *  drive letter are direct children of the start directory. On other systems start directory is '/' */
    344347    void            populateStartDirectory(UIFileTableItem *startItem);
    345348    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
    346354    UIGuestControlFileModel      *m_pModel;
    347355    UIGuestControlFileView       *m_pView;
     
    364372    /** The absolue path list of the file objects which user has chosen to cut/copy. this
    365373     *  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;
    368377};
    369378
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.cpp

    r74947 r75000  
    316316void UIGuestFileTable::copyHostToGuest(const QStringList &hostSourcePathList)
    317317{
    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();
    320326}
    321327
     
    344350
    345351        /** @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);
    350357
    351358    }
     
    359366}
    360367
    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     else
    395     {
    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// }
    403410
    404411FileObjectType UIGuestFileTable::fileType(const CFsObjInfo &fsInfo)
Note: See TracChangeset for help on using the changeset viewer.

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