VirtualBox

Changeset 71208 in vbox


Ignore:
Timestamp:
Mar 5, 2018 5:39:39 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:6699 Implement guest 'delete' actions for file table widget

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

Legend:

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

    r71201 r71208  
    424424    {
    425425        m_pLogOutput->appendPlainText("Guest session is not valid");
     426        postSessionClosed();
    426427        return;
    427428    }
     
    439440void UIGuestControlFileManager::sltGuestSessionStateChanged(const CGuestSessionStateChangedEvent &cEvent)
    440441{
    441     if (cEvent.isOk() && m_comGuestSession.isOk())// && m_comGuestProcess.GetStatus() == KProcessStatus_Error)
     442    if (cEvent.isOk() && m_comGuestSession.isOk())
    442443    {
    443444        CVirtualBoxErrorInfo cErrorInfo = cEvent.GetError();
    444         if (cErrorInfo.isOk())// && cErrorInfo.GetResultCode() != S_OK)
     445        if (cErrorInfo.isOk())
    445446        {
    446447            m_pLogOutput->appendPlainText(cErrorInfo.GetText());
     
    520521    connect(m_pQtSessionListener->getWrapped(), &UIMainEventListener::sigGuestSessionStatedChanged,
    521522            this, &UIGuestControlFileManager::sltGuestSessionStateChanged);
    522     // /* Wait session to start: */
    523     // const ULONG waitTimeout = 2000;
    524     // KGuestSessionWaitResult waitResult = guestSession.WaitFor(KGuestSessionWaitForFlag_Start, waitTimeout);
    525     // if (waitResult != KGuestSessionWaitResult_Start)
    526     //     return false;
    527 
    528     // outSession = guestSession;
     523     /* Wait session to start. For some reason we cannot get GuestSessionStatusChanged event
     524        consistently. So we wait: */
     525    m_pLogOutput->appendPlainText("Waiting the session to start");
     526    const ULONG waitTimeout = 2000;
     527    KGuestSessionWaitResult waitResult = m_comGuestSession.WaitFor(KGuestSessionWaitForFlag_Start, waitTimeout);
     528    if (waitResult != KGuestSessionWaitResult_Start)
     529    {
     530        m_pLogOutput->appendPlainText("The session did not start");
     531        sltCloseSession();
     532        return false;
     533    }
    529534
    530535    return true;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.cpp

    r71201 r71208  
    3838# include "CFsObjInfo.h"
    3939# include "CGuestDirectory.h"
     40# include "CProgress.h"
    4041
    4142#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    477478
    478479    m_pDelete = new QAction(this);
    479     m_pDelete->setIcon(UIIconPool::iconSet(QString(":/vm_delete_32px.png")));
    480     m_pToolBar->addAction(m_pDelete);
     480    if (m_pDelete)
     481    {
     482        connect(m_pDelete, &QAction::triggered, this, &UIGuestControlFileTable::sltDelete);
     483        m_pDelete->setIcon(UIIconPool::iconSet(QString(":/vm_delete_32px.png")));
     484        m_pToolBar->addAction(m_pDelete);
     485    }
    481486
    482487    m_pNewFolder = new QAction(this);
     
    612617void UIGuestControlFileTable::sltRefresh()
    613618{
     619    refresh();
     620}
     621
     622void UIGuestControlFileTable::refresh()
     623{
    614624    if (!m_pView || !m_pModel)
    615625        return;
     
    621631    if (!treeItem)
    622632        return;
     633    bool isRootDir = (m_pModel->rootIndex() == currentIndex);
    623634    m_pModel->beginReset();
    624635    /* For now we clear the whole subtree (that isrecursively) which is an overkill: */
    625636    treeItem->clearChildren();
    626     readDirectory(treeItem->path(), treeItem, false);
     637    readDirectory(treeItem->path(), treeItem, isRootDir);
    627638    m_pModel->endReset();
    628639    m_pView->setRootIndex(currentIndex);
    629640}
    630641
     642void UIGuestControlFileTable::sltDelete()
     643{
     644    if (!m_pView || !m_pModel)
     645        return;
     646    QItemSelectionModel *selectionModel =  m_pView->selectionModel();
     647    if (!selectionModel)
     648        return;
     649
     650    QModelIndexList selectedItemIndices = selectionModel->selectedIndexes();
     651    for(int i = 0; i < selectedItemIndices.size(); ++i)
     652    {
     653        deleteByIndex(selectedItemIndices.at(i));
     654    }
     655    refresh();
     656}
     657
     658void UIGuestControlFileTable::deleteByIndex(const QModelIndex &itemIndex)
     659{
     660    if (!itemIndex.isValid())
     661        return;
     662    UIFileTableItem *treeItem = static_cast<UIFileTableItem*>(itemIndex.internalPointer());
     663    if (!treeItem)
     664        return;
     665    deleteByItem(treeItem);
     666}
    631667
    632668void UIGuestControlFileTable::retranslateUi()
     
    641677    {
    642678        m_pDelete->setText(UIVMInformationDialog::tr("Delete"));
    643         m_pDelete->setToolTip(UIVMInformationDialog::tr("Delete the selected item"));
    644         m_pDelete->setStatusTip(UIVMInformationDialog::tr("Delete the selected item"));
     679        m_pDelete->setToolTip(UIVMInformationDialog::tr("Delete the selected item(s)"));
     680        m_pDelete->setStatusTip(UIVMInformationDialog::tr("Delete the selected item(s)"));
    645681    }
    646682
     
    663699    {
    664700        m_pCopy->setText(UIVMInformationDialog::tr("Copy the selected item"));
    665         m_pCopy->setToolTip(UIVMInformationDialog::tr("Copy the selected item"));
    666         m_pCopy->setStatusTip(UIVMInformationDialog::tr("Copy the selected item"));
     701        m_pCopy->setToolTip(UIVMInformationDialog::tr("Copy the selected item(s)"));
     702        m_pCopy->setStatusTip(UIVMInformationDialog::tr("Copy the selected item(s)"));
    667703
    668704    }
     
    670706    if (m_pCut)
    671707    {
    672         m_pCut->setText(UIVMInformationDialog::tr("Cut the selected item"));
    673         m_pCut->setToolTip(UIVMInformationDialog::tr("Cut the selected item"));
    674         m_pCut->setStatusTip(UIVMInformationDialog::tr("Cut the selected item"));
     708        m_pCut->setText(UIVMInformationDialog::tr("Cut the selected item(s)"));
     709        m_pCut->setToolTip(UIVMInformationDialog::tr("Cut the selected item(s)"));
     710        m_pCut->setStatusTip(UIVMInformationDialog::tr("Cut the selected item(s)"));
    675711
    676712    }
     
    678714    if ( m_pPaste)
    679715    {
    680         m_pPaste->setText(UIVMInformationDialog::tr("Paste the copied item"));
    681         m_pPaste->setToolTip(UIVMInformationDialog::tr("Paste the copied item"));
    682         m_pPaste->setStatusTip(UIVMInformationDialog::tr("Paste the copied item"));
     716        m_pPaste->setText(UIVMInformationDialog::tr("Paste the copied item(s)"));
     717        m_pPaste->setToolTip(UIVMInformationDialog::tr("Paste the copied item(s)"));
     718        m_pPaste->setStatusTip(UIVMInformationDialog::tr("Paste the copied item(s)"));
    683719    }
    684720
     
    761797}
    762798
    763 void UIGuestFileTable::refresh()
    764 {
    765 }
    766 
     799void UIGuestFileTable::deleteByItem(UIFileTableItem *item)
     800{
     801    if (!item)
     802        return;
     803    if (!m_comGuestSession.isOk())
     804        return;
     805    if (item->isUpDirectory())
     806        return;
     807    QVector<KDirectoryRemoveRecFlag> flags(KDirectoryRemoveRecFlag_ContentAndDir);
     808
     809    if (item->isDirectory())
     810    {
     811        m_comGuestSession.DirectoryRemoveRecursive(item->path(), flags);
     812    }
     813    else
     814    {
     815        m_comGuestSession.FsObjRemove(item->path());
     816    }
     817}
    767818
    768819/*********************************************************************************************************************************
     
    825876}
    826877
    827 void UIHostFileTable::refresh()
    828 {
     878void UIHostFileTable::deleteByItem(UIFileTableItem */*item */)
     879{
     880
    829881}
    830882
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/guestctrl/UIGuestControlFileTable.h

    r71201 r71208  
    100100                           bool isDirectoryMap, bool isStartDir);
    101101    virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) = 0;
    102     virtual void refresh() = 0;
     102    virtual void refresh();
     103    virtual void deleteByItem(UIFileTableItem *item) = 0;
    103104    UIFileTableItem         *m_pRootItem;
    104105
     
    116117    void sltGoUp();
    117118    void sltRefresh();
     119    void sltDelete();
    118120
    119121private:
     
    121123    void            prepareObjects();
    122124    void            prepareActions();
     125    void            deleteByIndex(const QModelIndex &itemIndex);
    123126    QGridLayout    *m_pMainLayout;
    124127    QILineEdit     *m_pCurrentLocationEdit;
     
    150153    void retranslateUi() /* override */;
    151154    virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;
    152     virtual void refresh() /* override */;
     155    virtual void deleteByItem(UIFileTableItem *item) /* override */;
    153156
    154157private:
     
    171174    void retranslateUi() /* override */;
    172175    virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;
    173     virtual void refresh() /* override */;
    174 
     176    virtual void deleteByItem(UIFileTableItem *item) /* override */;
    175177};
    176178
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