VirtualBox

Changeset 71832 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 12, 2018 6:56:48 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699 Handle drive letters in 'guest' file manager

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

Legend:

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

    r71639 r71832  
    116116            if (item->isUpDirectory())
    117117                return QIcon(":/arrow_up_10px_x2.png");
     118            else if(item->isDriveItem())
     119                return QIcon(":/hd_32px.png");
    118120            else
    119121                return QIcon(":/sf_32px.png");
     
    256258    return true;
    257259}
    258 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp

    r71794 r71832  
    171171
    172172const QChar UIPathOperations::delimiter = QChar('/');
     173const QChar UIPathOperations::dosDelimiter = QChar('\\');
    173174
    174175/* static */ QString UIPathOperations::removeMultipleDelimiters(const QString &path)
     
    193194}
    194195
    195 /* static */ QString UIPathOperations::addTrailingDelimiters
    196 (const QString &path)
     196/* static */ QString UIPathOperations::addTrailingDelimiters(const QString &path)
    197197{
    198198    if (path.isNull() || path.isEmpty())
     
    209209        return QString(path);
    210210    QString newPath(path);
     211
     212    if (doesPathStartWithDriveLetter(newPath))
     213    {
     214        if (newPath.at(newPath.length() - 1) != delimiter)
     215            newPath += delimiter;
     216        return newPath;
     217    }
    211218    if (newPath.at(0) != delimiter)
    212219        newPath.insert(0, delimiter);
     
    216223/* static */ QString UIPathOperations::sanitize(const QString &path)
    217224{
    218     return addStartDelimiter(removeTrailingDelimiters(removeMultipleDelimiters(path)));
     225    //return addStartDelimiter(removeTrailingDelimiters(removeMultipleDelimiters(path)));
     226    QString newPath = addStartDelimiter(removeTrailingDelimiters(removeMultipleDelimiters(path))).replace(dosDelimiter, delimiter);
     227    return newPath;
    219228}
    220229
     
    270279{
    271280    QStringList pathList = path.split(UIPathOperations::delimiter, QString::SkipEmptyParts);
     281    if (!pathList.isEmpty() && doesPathStartWithDriveLetter(pathList[0]))
     282    {
     283        pathList[0] = addTrailingDelimiters(pathList[0]);
     284    }
    272285    return pathList;
     286}
     287
     288/* static */ bool UIPathOperations::doesPathStartWithDriveLetter(const QString &path)
     289{
     290    if (path.length() < 2)
     291        return false;
     292    /* search for ':' with the path: */
     293    if (!path[0].isLetter())
     294        return false;
     295    if (path[1] != ':')
     296        return false;
     297    return true;
    273298}
    274299
     
    545570    , m_isTargetADirectory(false)
    546571    , m_type(type)
     572    , m_isDriveItem(false)
    547573{
    548574}
     
    693719{
    694720    m_isTargetADirectory = flag;
     721}
     722
     723void UIFileTableItem::setIsDriveItem(bool flag)
     724{
     725    m_isDriveItem = flag;
     726}
     727
     728bool UIFileTableItem::isDriveItem() const
     729{
     730    return m_isDriveItem;
    695731}
    696732
     
    9721008    if (m_pRootItem)
    9731009        reset();
    974 
     1010    determineDriveLetters();
     1011    /* Root item: */
    9751012    const QString startPath("/");
    9761013    QList<QVariant> headData;
     
    9831020    startItem->setPath(startPath);
    9841021    m_pRootItem->appendChild(startItem);
    985 
    9861022    startItem->setIsOpened(false);
    987     /* Read the root directory and get the list: */
    988     readDirectory(startPath, startItem, true);
     1023    if (m_driveLetterList.isEmpty())
     1024    {
     1025        /* Read the root directory and get the list: */
     1026        readDirectory(startPath, startItem, true);
     1027    }
     1028    else
     1029    {
     1030        for (int i = 0; i < m_driveLetterList.size(); ++i)
     1031        {
     1032            QList<QVariant> data;
     1033
     1034            data << m_driveLetterList[i] << 4096 << QDateTime() << "";
     1035            UIFileTableItem* driveItem = new UIFileTableItem(data, startItem, FileObjectType_Directory);
     1036            driveItem->setPath(m_driveLetterList[i]);
     1037            startItem->appendChild(driveItem);
     1038            driveItem->setIsOpened(false);
     1039            driveItem->setIsDriveItem(true);
     1040            startItem->setIsOpened(true);
     1041        }
     1042    }
    9891043    m_pView->setRootIndex(m_pModel->rootIndex());
    9901044    m_pModel->signalUpdate();
     
    9951049                                                UIFileTableItem *parent, bool isDirectoryMap, bool isStartDir)
    9961050{
     1051    if (parent)
     1052
    9971053    /* Make sure we have a ".." item within directories, and make sure it is not there for the start dir: */
    9981054    if (isDirectoryMap)
     
    12441300    if (comboLocation == currentDirectoryPath())
    12451301        return;
    1246 
    1247     QStringList pathList = comboLocation.split(UIPathOperations::delimiter, QString::SkipEmptyParts);
    1248     goIntoDirectory(pathList);
     1302    goIntoDirectory(UIPathOperations::pathTrail(comboLocation));
    12491303}
    12501304
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h

    r71792 r71832  
    147147    static QString constructNewItemPath(const QString &previousPath, const QString &newBaseName);
    148148    /** Split the path and return it as a QStringList, top most being the 0th element. No delimiters */
    149     QStringList pathTrail(const QString &path);
     149    static QStringList pathTrail(const QString &path);
    150150    static const QChar delimiter;
     151    static const QChar dosDelimiter;
     152
     153    /** Try to guess if the path starts with DOS style drive letters */
     154    static bool doesPathStartWithDriveLetter(const QString &path);
     155
    151156};
    152157
     
    203208    QString name() const;
    204209
     210    void setIsDriveItem(bool flag);
     211    bool isDriveItem() const;
     212
    205213private:
    206214
    207215    QList<UIFileTableItem*>         m_childItems;
    208     /** Used to find children by path */
     216    /** Used to find children by name */
    209217    QMap<QString, UIFileTableItem*> m_childMap;
    210218    /** It is required that m_itemData[0] is name (QString) of the file object */
     
    219227    bool             m_isTargetADirectory;
    220228    FileObjectType   m_type;
    221 
     229    /** True if only this item represents a DOS style drive letter item */
     230    bool             m_isDriveItem;
    222231};
    223232
     
    267276    virtual QString  fsObjectPropertyString() = 0;
    268277    virtual void     showProperties() = 0;
     278    /** For non-windows system does nothing and for windows systems populates m_driveLetterList with
     279     *  drive letters */
     280    virtual void     determineDriveLetters() = 0;
    269281    static QString   fileTypeString(FileObjectType type);
    270282    void             goIntoDirectory(const QModelIndex &itemIndex);
     
    285297    QAction                 *m_pPaste;
    286298    UIPropertiesDialog      *m_pPropertiesDialog;
     299    /** Stores the drive letters the file system has (for windows system). For non-windows
     300     *  systems this is empty and for windows system it should at least contain C:/ */
     301    QStringList m_driveLetterList;
    287302
    288303protected slots:
     
    336351    QVector<QAction*> m_selectionDependentActions;
    337352    /** The absolue path list of the file objects which user has chosen to cut/copy. this
    338       * list will be cleaned after a paste operation or overwritten by a subsequent cut/copy */
     353     * list will be cleaned after a paste operation or overwritten by a subsequent cut/copy */
    339354    QStringList       m_copyCutBuffer;
    340355    friend class UIGuestControlFileModel;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.cpp

    r71693 r71832  
    178178    flag.push_back(KDirectoryOpenFlag_None);
    179179
    180     directory = m_comGuestSession.DirectoryOpen(strPath, /*aFilter*/ "", flag);
     180    directory = m_comGuestSession.DirectoryOpen(UIPathOperations::sanitize(strPath), /*aFilter*/ "", flag);
    181181    if (!m_comGuestSession.isOk())
    182182    {
     
    204204                continue;
    205205            item->setPath(UIPathOperations::mergePaths(strPath, fsInfo.GetName()));
    206 
    207206            if (fsObjectType == FileObjectType_Directory)
    208207            {
     
    269268    }
    270269    QStringList pathList = userHome.split(UIPathOperations::delimiter, QString::SkipEmptyParts);
    271     goIntoDirectory(pathList);
     270    goIntoDirectory(UIPathOperations::pathTrail(userHome));
    272271}
    273272
     
    555554}
    556555
     556void UIGuestFileTable::determineDriveLetters()
     557{
     558    if (m_comGuestSession.isNull())
     559        return;
     560    KPathStyle pathStyle = m_comGuestSession.GetPathStyle();
     561    if (pathStyle != KPathStyle_DOS)
     562        return;
     563
     564    /** @todo Currently API lacks a way to query windows drive letters.
     565     *  so we enumarate them by using CGuestSession::DirectoryExists() */
     566    for (int i = 'A'; i <= 'Z'; ++i)
     567    {
     568        QString path((char)i);
     569        path += ":/";
     570        bool exists = m_comGuestSession.DirectoryExists(path, false /* aFollowSymlinks */);
     571        if (exists)
     572            m_driveLetterList.push_back(path);
     573    }
     574}
     575
    557576#include "UIGuestFileTable.moc"
    558 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.h

    r71654 r71832  
    4949    virtual QString fsObjectPropertyString() /* override */;
    5050    virtual void  showProperties() /* override */;
     51    virtual void determineDriveLetters() /* override */;
    5152
    5253private:
     
    6364
    6465#endif /* !___UIGuestControlFileTable_h___ */
    65 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.cpp

    r71693 r71832  
    227227
    228228    QString userHome = UIPathOperations::sanitize(QDir::homePath());
    229     QStringList pathList = userHome.split(UIPathOperations::delimiter, QString::SkipEmptyParts);
    230     goIntoDirectory(pathList);
     229    goIntoDirectory(UIPathOperations::pathTrail(userHome));
    231230}
    232231
     
    382381}
    383382
     383void UIHostFileTable::determineDriveLetters()
     384{
     385}
     386
    384387#include "UIHostFileTable.moc"
    385 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.h

    r71639 r71832  
    4343    virtual QString fsObjectPropertyString() /* override */;
    4444    virtual void  showProperties() /* override */;
     45    virtual void determineDriveLetters() /* override */;
    4546
    4647private:
     
    5051
    5152#endif /* !___UIGuestControlFileTable_h___ */
    52 
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