VirtualBox

Changeset 71350 in vbox


Ignore:
Timestamp:
Mar 15, 2018 1:22:58 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699: Solving an update problem in the file table

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  
    406406void UIGuestControlFileManager::sltGuestSessionUnregistered(CGuestSession guestSession)
    407407{
    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    {
    411412        m_comGuestSession.detach();
    412     postSessionClosed();
     413        postSessionClosed();
     414    }
    413415}
    414416
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileModel.cpp

    r71274 r71350  
    3838{
    3939    QList<QVariant> rootData;
    40     // rootData << "Title" << "Summary";
    41     // rootItem = new UIFileTableItem(rootData);
    4240}
    4341
     
    122120                return QIcon(":/sf_32px.png");
    123121        }
    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        }
    126131    }
    127132
     
    246251    QList<QVariant> data;
    247252    data << "New Item" << 0 << QDateTime::currentDateTime();
    248     UIFileTableItem *newItem = new UIFileTableItem(data, true, parentItem);
     253    UIFileTableItem *newItem = new UIFileTableItem(data, parentItem, FileObjectType_Directory);
    249254    parentItem->appendChild(newItem);
    250255    endInsertRows();
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp

    r71330 r71350  
    230230
    231231
    232 UIFileTableItem::UIFileTableItem(const QList<QVariant> &data, bool isDirectory, UIFileTableItem *parent)
     232UIFileTableItem::UIFileTableItem(const QList<QVariant> &data,
     233                                 UIFileTableItem *parent, FileObjectType type)
    233234    : m_itemData(data)
    234235    , m_parentItem(parent)
    235     , m_bIsDirectory(isDirectory)
    236236    , m_bIsOpened(false)
     237    , m_isTargetADirectory(false)
     238    , m_type(type)
    237239{
    238240}
     
    295297    if (m_parentItem)
    296298        return m_parentItem->m_childItems.indexOf(const_cast<UIFileTableItem*>(this));
    297 
    298299    return 0;
    299300}
     
    301302bool UIFileTableItem::isDirectory() const
    302303{
    303     return m_bIsDirectory;
     304    return m_type == FileObjectType_Directory;
     305}
     306
     307bool UIFileTableItem::isSymLink() const
     308{
     309    return m_type == FileObjectType_SymLink;
     310}
     311
     312bool UIFileTableItem::isFile() const
     313{
     314    return m_type == FileObjectType_File;
    304315}
    305316
     
    336347bool UIFileTableItem::isUpDirectory() const
    337348{
    338     if (!m_bIsDirectory)
     349    if (!isDirectory())
    339350        return false;
    340351    if (data(0) == QString(".."))
    341352        return true;
    342353    return false;
     354}
     355
     356FileObjectType UIFileTableItem::type() const
     357{
     358    return m_type;
     359}
     360
     361const QString &UIFileTableItem::targetPath() const
     362{
     363    return m_strTargetPath;
     364}
     365
     366void UIFileTableItem::setTargetPath(const QString &path)
     367{
     368    m_strTargetPath = path;
     369}
     370
     371bool UIFileTableItem::isTargetADirectory() const
     372{
     373    return m_isTargetADirectory;
     374}
     375
     376void UIFileTableItem::setIsTargetADirectory(bool flag)
     377{
     378    m_isTargetADirectory = flag;
    343379}
    344380
     
    500536    {
    501537        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")));
    503539        m_pToolBar->addAction(m_pCreateNewDirectory);
    504540    }
     
    558594    QList<QVariant> headData;
    559595    headData << "Name" << "Size" << "Change Time";
    560     m_pRootItem = new UIFileTableItem(headData, true, 0);
    561 
     596    m_pRootItem = new UIFileTableItem(headData, 0, FileObjectType_Directory);
    562597    QList<QVariant> startDirData;
    563598    startDirData << "/" << 4096 << QDateTime();
    564     UIFileTableItem* startItem = new UIFileTableItem(startDirData, true, m_pRootItem);
     599    UIFileTableItem* startItem = new UIFileTableItem(startDirData, m_pRootItem, FileObjectType_Directory);
     600
    565601    startItem->setPath("/");
    566602    m_pRootItem->appendChild(startItem);
     
    578614                                                UIFileTableItem *parent, bool isDirectoryMap, bool isStartDir)
    579615{
    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: */
    581617    if (isDirectoryMap)
    582618    {
     
    585621            QList<QVariant> data;
    586622            data << ".." << 4096;
    587             UIFileTableItem *item = new UIFileTableItem(data, isDirectoryMap, parent);
     623            UIFileTableItem *item = new UIFileTableItem(data, parent, FileObjectType_Directory);
    588624            item->setIsOpened(false);
    589625            map.insert("..", item);
     
    633669void UIGuestControlFileTable::goIntoDirectory(const QModelIndex &itemIndex)
    634670{
    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());
    636680    if (!item)
    637681        return;
     
    640684    if (item->isUpDirectory())
    641685    {
    642         QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(itemIndex));
     686        QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(index));
    643687        if (parentIndex.isValid())
    644688            changeLocation(parentIndex);
     
    650694    if (!item->isOpened())
    651695       readDirectory(item->path(),item);
    652     changeLocation(itemIndex);
     696    changeLocation(index);
    653697}
    654698
     
    9891033
    9901034            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);
    9931037            item->setPath(UIPathOperations::mergePaths(strPath, fsInfo.GetName()));
    994             if (isDirectory)
     1038            if (fileType == FileObjectType_Directory)
    9951039            {
    9961040                directories.insert(fsInfo.GetName(), item);
    9971041                item->setIsOpened(false);
    9981042            }
    999             else
     1043            else if(fileType == FileObjectType_File)
    10001044            {
    10011045                files.insert(fsInfo.GetName(), item);
    10021046                item->setIsOpened(false);
    10031047            }
     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
    10041055            fsInfo = directory.Read();
    10051056        }
     
    11241175bool UIGuestFileTable::copyHostToGuest(const QString &hostSourcePath, const QString &guestDestinationPath)
    11251176{
    1126     Q_UNUSED(guestDestinationPath);
    11271177    if (m_comGuestSession.isNull())
    11281178        return false;
     
    11341184    if (hostFileInfo.isFile() || hostFileInfo.isSymLink())
    11351185    {
     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);
    11361191    }
    11371192    else if(hostFileInfo.isDir())
    11381193    {
    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;
    11571200    return true;
    11581201}
    11591202
     1203FileObjectType 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}
    11601216
    11611217/*********************************************************************************************************************************
     
    11941250    {
    11951251        const QFileInfo &fileInfo = entries.at(i);
     1252
    11961253        QList<QVariant> data;
    11971254        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));
    11991256        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        }
    12001264        if (fileInfo.isDir())
    12011265        {
     
    12081272            item->setIsOpened(false);
    12091273        }
    1210 
    12111274    }
    12121275    insertItemsToTree(directories, parent, true, isStartDir);
     
    12811344}
    12821345
     1346FileObjectType 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
    12831362#include "UIGuestControlFileTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h

    r71325 r71350  
    3232/* Forward declarations: */
    3333class QAction;
     34class QFileInfo;
    3435class QILabel;
    3536class QILineEdit;
     
    4041class UIToolBar;
    4142
     43enum FileObjectType
     44{
     45    FileObjectType_File = 0,
     46    FileObjectType_Directory,
     47    FileObjectType_SymLink,
     48    FileObjectType_Other,
     49    FileObjectType_Unknown,
     50    FileObjectType_Max
     51};
     52
    4253/*********************************************************************************************************************************
    4354*   UIFileTableItem definition.                                                                                                  *
     
    4758{
    4859public:
    49     explicit UIFileTableItem(const QList<QVariant> &data, bool isDirectory, UIFileTableItem *parentItem);
     60
     61    explicit UIFileTableItem(const QList<QVariant> &data,
     62                             UIFileTableItem *parentItem, FileObjectType type);
    5063    ~UIFileTableItem();
    5164
     
    6376
    6477    bool isDirectory() const;
     78    bool isSymLink() const;
     79    bool isFile() const;
     80
    6581    bool isOpened() const;
    6682    void setIsOpened(bool flag);
     
    7288    bool isUpDirectory() const;
    7389    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);
    7498
    7599private:
     
    79103    QList<QVariant>  m_itemData;
    80104    UIFileTableItem *m_parentItem;
    81     bool             m_bIsDirectory;
    82105    bool             m_bIsOpened;
    83106    /** Full absolute path of the item. Without the trailing '/' */
    84107    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;
    85113
    86114};
     
    205233private:
    206234
     235    static FileObjectType getFileType(const CFsObjInfo &fsInfo);
    207236    bool copyGuestToHost(const QString &guestSourcePath, const QString& hostDestinationPath);
    208237    bool copyHostToGuest(const QString& hostSourcePath, const QString &guestDestinationPath);
     
    224253protected:
    225254
     255    static FileObjectType getFileType(const QFileInfo &fsInfo);
    226256    void retranslateUi() /* override */;
    227257    virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;
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