VirtualBox

Changeset 71234 in vbox for trunk


Ignore:
Timestamp:
Mar 6, 2018 10:52:27 AM (7 years ago)
Author:
vboxsync
Message:

FT/Qt bugref:6699 Adding 'rename' and 'go to home' actions to file views

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileManager.cpp

    r71208 r71234  
    323323            m_pGuestFileTable->setEnabled(false);
    324324            if (m_pGuestFileTable)
     325            {
     326                connect(m_pGuestFileTable, &UIGuestFileTable::sigLogOutput,
     327                        this, &UIGuestControlFileManager::sltReceieveLogOutput);
    325328                containerLayout->addWidget(m_pGuestFileTable);
    326 
     329            }
    327330            m_pToolBar = new UIToolBar;
    328331            if (m_pToolBar)
     
    356359            m_pHostFileTable = new UIHostFileTable;
    357360            if (m_pHostFileTable)
     361            {
     362                connect(m_pHostFileTable, &UIHostFileTable::sigLogOutput,
     363                        this, &UIGuestControlFileManager::sltReceieveLogOutput);
    358364                containerLayout->addWidget(m_pHostFileTable);
     365            }
    359366        }
    360367        m_pVerticalSplitter->addWidget(fileTableContainer);
     
    457464        m_pLogOutput->appendPlainText("Session status has changed");
    458465    }
     466}
     467
     468void UIGuestControlFileManager::sltReceieveLogOutput(QString strOutput)
     469{
     470    if (m_pLogOutput)
     471        m_pLogOutput->appendPlainText(strOutput);
    459472}
    460473
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileManager.h

    r71195 r71234  
    6464    void sltCloseSession();
    6565    void sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent);
     66    void sltReceieveLogOutput(QString strOutput);
    6667
    6768private:
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.cpp

    r71209 r71234  
    8080    void setPath(const QString &path);
    8181
     82    const QString  &name() const;
     83    void setName(const QString &name);
     84
    8285    /** True if this is directory and name is ".." */
    8386    bool isUpDirectory() const;
     
    9194    bool             m_bIsOpened;
    9295    QString          m_strPath;
     96    QString          m_strName;
    9397};
    9498
     
    181185{
    182186    m_strPath = path;
     187}
     188
     189const QString  &UIFileTableItem::name() const
     190{
     191    return m_strName;
     192}
     193
     194void UIFileTableItem::setName(const QString &name)
     195{
     196    m_strName = name;
    183197}
    184198
     
    371385    , m_pCurrentLocationEdit(0)
    372386    , m_pToolBar(0)
     387    , m_pGoUp(0)
     388    , m_pGoHome(0)
    373389    , m_pRefresh(0)
    374390    , m_pDelete(0)
     391    , m_pRename(0)
    375392    , m_pNewFolder(0)
    376     , m_pGoUp(0)
    377393    , m_pCopy(0)
    378394    , m_pCut(0)
     
    468484    }
    469485
     486    m_pGoHome = new QAction(this);
     487    if (m_pGoHome)
     488    {
     489        connect(m_pGoHome, &QAction::triggered, this, &UIGuestControlFileTable::sltGoHome);
     490        m_pGoHome->setIcon(UIIconPool::iconSet(QString(":/nw_24px.png")));
     491        m_pToolBar->addAction(m_pGoHome);
     492    }
     493
    470494    m_pRefresh = new QAction(this);
    471495    if (m_pRefresh)
     
    476500    }
    477501
     502    m_pToolBar->addSeparator();
    478503
    479504    m_pDelete = new QAction(this);
     
    483508        m_pDelete->setIcon(UIIconPool::iconSet(QString(":/vm_delete_32px.png")));
    484509        m_pToolBar->addAction(m_pDelete);
     510    }
     511
     512    m_pRename = new QAction(this);
     513    if (m_pRename)
     514    {
     515        connect(m_pRename, &QAction::triggered, this, &UIGuestControlFileTable::sltRename);
     516        m_pRename->setIcon(UIIconPool::iconSet(QString(":/name_16px_x2.png")));
     517        m_pToolBar->addAction(m_pRename);
    485518    }
    486519
     
    538571    UIFileTableItem* startItem = new UIFileTableItem(startDirData, m_pRootItem);
    539572    startItem->setPath("/");
     573    startItem->setName("/");
    540574    m_pRootItem->appendChild(startItem);
    541575
     
    583617    if (!index.isValid() ||  !m_pModel || !m_pView)
    584618        return;
    585 
    586     UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     619    goIntoDirectory(index);
     620}
     621
     622void UIGuestControlFileTable::sltGoUp()
     623{
     624    if (!m_pView || !m_pModel)
     625        return;
     626    QModelIndex currentRoot = m_pView->rootIndex();
     627    if (!currentRoot.isValid())
     628        return;
     629    if (currentRoot != m_pModel->rootIndex())
     630        m_pView->setRootIndex(currentRoot.parent());
     631}
     632
     633void UIGuestControlFileTable::sltGoHome()
     634{
     635}
     636
     637void UIGuestControlFileTable::sltRefresh()
     638{
     639    refresh();
     640}
     641
     642void UIGuestControlFileTable::goIntoDirectory(const QModelIndex &itemIndex)
     643{
     644    UIFileTableItem *item = static_cast<UIFileTableItem*>(itemIndex.internalPointer());
    587645    if (!item)
    588646        return;
     
    590648    if (item->isUpDirectory())
    591649    {
    592         QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(index));
     650        QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(itemIndex));
    593651        if (parentIndex.isValid())
    594652            changeLocation(parentIndex);
     
    601659       readDirectory(item->path(),item);
    602660
    603     changeLocation(index);
    604 }
    605 
    606 void UIGuestControlFileTable::sltGoUp()
    607 {
    608     if (!m_pView || !m_pModel)
    609         return;
    610     QModelIndex currentRoot = m_pView->rootIndex();
    611     if (!currentRoot.isValid())
    612         return;
    613     if (currentRoot != m_pModel->rootIndex())
    614         m_pView->setRootIndex(currentRoot.parent());
    615 }
    616 
    617 void UIGuestControlFileTable::sltRefresh()
    618 {
    619     refresh();
     661    changeLocation(itemIndex);
    620662}
    621663
     
    648690        return;
    649691
    650     QModelIndexList selectedItemIndices = selectionModel->selectedIndexes();
     692    QModelIndexList selectedItemIndices = selectionModel->selectedRows();
    651693    for(int i = 0; i < selectedItemIndices.size(); ++i)
    652694    {
     
    654696    }
    655697    refresh();
     698}
     699
     700void UIGuestControlFileTable::sltRename()
     701{
    656702}
    657703
     
    668714void UIGuestControlFileTable::retranslateUi()
    669715{
     716    if (m_pGoUp)
     717    {
     718        m_pGoUp->setText(UIVMInformationDialog::tr("Move one level up"));
     719        m_pGoUp->setToolTip(UIVMInformationDialog::tr("Move one level up"));
     720        m_pGoUp->setStatusTip(UIVMInformationDialog::tr("Move one level up"));
     721    }
     722
     723    if (m_pGoHome)
     724    {
     725        m_pGoHome->setText(UIVMInformationDialog::tr("Goto home folder"));
     726        m_pGoHome->setToolTip(UIVMInformationDialog::tr("Goto home folder"));
     727        m_pGoHome->setStatusTip(UIVMInformationDialog::tr("Goto home folder"));
     728    }
     729
     730    if (m_pRename)
     731    {
     732        m_pRename->setText(UIVMInformationDialog::tr("Rename the selected item"));
     733        m_pRename->setToolTip(UIVMInformationDialog::tr("Rename the selected item"));
     734        m_pRename->setStatusTip(UIVMInformationDialog::tr("Rename the selected item"));
     735    }
     736
    670737    if (m_pRefresh)
    671738    {
     
    688755
    689756    }
    690     if (m_pGoUp)
    691     {
    692         m_pGoUp->setText(UIVMInformationDialog::tr("Move one level up"));
    693         m_pGoUp->setToolTip(UIVMInformationDialog::tr("Move one level up"));
    694         m_pGoUp->setStatusTip(UIVMInformationDialog::tr("Move one level up"));
    695 
    696     }
    697757
    698758    if (m_pCopy)
     
    718778        m_pPaste->setStatusTip(UIVMInformationDialog::tr("Paste the copied item(s)"));
    719779    }
    720 
     780}
     781
     782
     783void UIGuestControlFileTable::keyPressEvent(QKeyEvent * pEvent)
     784{
     785    /* Browse into directory with enter: */
     786    if (pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return)
     787    {
     788        if (m_pView && m_pModel)
     789        {
     790            /* Get the selected item. If there are 0 or more than 1 selection do nothing: */
     791            QItemSelectionModel *selectionModel =  m_pView->selectionModel();
     792            if (selectionModel)
     793            {
     794                QModelIndexList selectedItemIndices = selectionModel->selectedRows();
     795                if (selectedItemIndices.size() == 1)
     796                    goIntoDirectory(selectedItemIndices.at(0));
     797            }
     798        }
     799    }
     800    else if(pEvent->key() == Qt::Key_Delete)
     801    {
     802        sltDelete();
     803    }
     804    QWidget::keyPressEvent(pEvent);
    721805}
    722806
     
    813897    else
    814898    {
     899        /** @todo this is not working: */
    815900        m_comGuestSession.FsObjRemove(item->path());
    816901    }
    817902}
     903
    818904
    819905/*********************************************************************************************************************************
     
    841927
    842928    QDir directory(strPath);
     929    //directory.setFilter(QDir::NoDotAndDotDot);
    843930    parent->setIsOpened(true);
    844931    if (!directory.exists())
     
    848935    QMap<QString, UIFileTableItem*> files;
    849936
    850 
    851937    for (int i = 0; i < entries.size(); ++i)
    852938    {
    853939        const QFileInfo &fileInfo = entries.at(i);
    854 
    855940        QList<QVariant> data;
    856941        data << fileInfo.baseName() << fileInfo.size();
     
    878963void UIHostFileTable::deleteByItem(UIFileTableItem *item)
    879964{
    880     Q_UNUSED(item);
     965    if (!item->isDirectory())
     966    {
     967        QDir itemToDelete;//(item->path());
     968        itemToDelete.remove(item->path());
     969    }
     970    QDir itemToDelete(item->path());
     971    itemToDelete.setFilter(QDir::NoDotAndDotDot);
     972    /* Try to delete item recursively (in case of directories).
     973       note that this is no good way of deleting big directory
     974       trees. We need a better error reporting and a kind of progress
     975       indicator: */
     976    /** @todo replace this recursive delete by a better implementation: */
     977    bool deleteSuccess = itemToDelete.removeRecursively();
     978
     979     if (!deleteSuccess)
     980         emit sigLogOutput(QString(item->path()).append(" could not be deleted"));
    881981}
    882982
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.h

    r71208 r71234  
    4343/** UIGuestControlFileModel serves as the model for a file structure.
    4444    it supports a tree level hierarchy which can be displayed with
    45     QTableView and/or QTreeView */
     45    QTableView and/or QTreeView. Note the file structure data is not
     46    kept by the model but rather by the containing widget which also servers
     47    as the interface to functionality this model provides.*/
    4648class UIGuestControlFileModel : public QAbstractItemModel
    4749{
     
    7981    and a host version are derived from this base. Each of these children
    8082    populates the UIGuestControlFileModel by scanning the file system
    81     differently. */
     83    differently. The file structre kept in this class as a tree and all
     84    the interfacing is done thru this class.*/
    8285class UIGuestControlFileTable : public QIWithRetranslateUI<QWidget>
    8386{
    8487    Q_OBJECT;
     88
     89signals:
     90
     91    void sigLogOutput(QString);
    8592
    8693public:
     
    102109    virtual void refresh();
    103110    virtual void deleteByItem(UIFileTableItem *item) = 0;
     111    void keyPressEvent(QKeyEvent * pEvent);
    104112    UIFileTableItem         *m_pRootItem;
    105113
     
    116124    void sltItemDoubleClicked(const QModelIndex &index);
    117125    void sltGoUp();
     126    void sltGoHome();
    118127    void sltRefresh();
    119128    void sltDelete();
     129    void sltRename();
    120130
    121131private:
     
    124134    void            prepareActions();
    125135    void            deleteByIndex(const QModelIndex &itemIndex);
     136    void            goIntoDirectory(const QModelIndex &itemIndex);
    126137    QGridLayout    *m_pMainLayout;
    127138    QILineEdit     *m_pCurrentLocationEdit;
    128139    UIToolBar      *m_pToolBar;
     140    QAction        *m_pGoUp;
     141    QAction        *m_pGoHome;
    129142    QAction        *m_pRefresh;
    130143    QAction        *m_pDelete;
     144    QAction        *m_pRename;
    131145    QAction        *m_pNewFolder;
    132     QAction        *m_pGoUp;
     146
    133147    QAction        *m_pCopy;
    134148    QAction        *m_pCut;
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