VirtualBox

Changeset 102378 in vbox for trunk/src


Ignore:
Timestamp:
Nov 29, 2023 12:06:14 PM (18 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160514
Message:

FE/Qt: bugref:10561. Several fixes in file system model related code to make them work correctly with Windows file system.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICustomFileSystemModel.cpp

    r102363 r102378  
    6262
    6363    if (parent)
     64    {
    6465        parent->appendChild(this);
     66        setParentModel(parent->parentModel());
     67    }
    6568}
    6669
     
    207210QString UICustomFileSystemItem::path(bool fRemoveTrailingDelimiters /* = false */) const
    208211{
     212    const QChar delimiter('/');
    209213    Q_UNUSED(fRemoveTrailingDelimiters);
    210214    const UICustomFileSystemItem *pParent = this;
    211215    QStringList path;
    212 
    213216    while(pParent && pParent->parentItem())
    214217    {
    215         printf("ffff %s %d\n", qPrintable(pParent->fileObjectName()), isDriveItem());
    216218        path.prepend(pParent->fileObjectName());
    217219        pParent = pParent->parentItem();
    218220    }
    219 
    220     return UIPathOperations::removeMultipleDelimiters(path.join("/"));
     221    QString strPath = UIPathOperations::removeMultipleDelimiters(path.join(delimiter));
     222    if (m_pParentModel && m_pParentModel->isWindowsFileSystem())
     223    {
     224        if (!strPath.isEmpty() && strPath.at(0) == delimiter)
     225            strPath.remove(0, 1);
     226    }
     227    return UIPathOperations::addTrailingDelimiters(strPath);
    221228}
    222229
     
    300307}
    301308
     309void UICustomFileSystemItem::setParentModel(UICustomFileSystemModel *pModel)
     310{
     311    m_pParentModel = pModel;
     312}
     313
     314UICustomFileSystemModel *UICustomFileSystemItem::parentModel()
     315{
     316    return m_pParentModel;
     317}
    302318
    303319/*********************************************************************************************************************************
     
    401417    : QAbstractItemModel(parent)
    402418    , m_fShowHumanReadableSizes(false)
     419    , m_fIsWindowFileSystemModel(false)
    403420{
    404421    m_pRootItem = new UICustomFileSystemItem(QString(), 0, KFsObjType_Directory);
     422    m_pRootItem->setParentModel(this);
    405423}
    406424
     
    666684        pParent->removeChild(pItem);
    667685}
     686
     687void UICustomFileSystemModel::setIsWindowsFileSystem(bool fIsWindowsFileSystem)
     688{
     689    m_fIsWindowFileSystemModel = fIsWindowsFileSystem;
     690}
     691
     692bool UICustomFileSystemModel::isWindowsFileSystem() const
     693{
     694    return m_fIsWindowFileSystemModel;
     695}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICustomFileSystemModel.h

    r102363 r102378  
    4040/* COM includes: */
    4141#include "COMEnums.h"
     42
     43class UICustomFileSystemModel;
    4244
    4345enum UICustomFileSystemModelData
     
    127129
    128130    void appendChild(UICustomFileSystemItem *child);
     131    void setParentModel(UICustomFileSystemModel *pModel);
     132    UICustomFileSystemModel *parentModel();
     133
    129134    QList<UICustomFileSystemItem*>               m_childItems;
    130135    QMap<UICustomFileSystemModelData, QVariant>  m_itemData;
     
    135140    /** True if this is a symlink and the target is a directory */
    136141    bool             m_fIsTargetADirectory;
    137     KFsObjType  m_type;
     142    KFsObjType       m_type;
    138143    /** True if only this item represents a DOS style drive letter item */
    139144    bool             m_fIsDriveItem;
     
    141146    bool             m_fIsHidden;
    142147    QString          m_strToolTip;
     148    /** Pointer to the parent model. */
     149    UICustomFileSystemModel *m_pParentModel;
     150    friend UICustomFileSystemModel;
    143151};
    144152
     
    214222    const UICustomFileSystemItem* rootItem() const;
    215223
     224    void setIsWindowsFileSystem(bool fIsWindowsFileSystem);
     225    bool isWindowsFileSystem() const;
     226
    216227    static const char* strUpDirectoryString;
    217228
     
    220231    UICustomFileSystemItem    *m_pRootItem;
    221232    void setupModelData(const QStringList &lines, UICustomFileSystemItem *parent);
    222     bool                m_fShowHumanReadableSizes;
     233    bool m_fShowHumanReadableSizes;
     234    bool m_fIsWindowFileSystemModel;
    223235};
    224236
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPathOperations.cpp

    r98103 r102378  
    162162    return true;
    163163}
     164
     165/* static */ const QString UIPathOperations::replaceDosDelimeter(const QString &path)
     166{
     167    QString newPath(path);
     168    return newPath.replace(dosDelimiter, delimiter);
     169}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPathOperations.h

    r98103 r102378  
    6161    /** Tries to determine if the path starts with DOS style drive letters. */
    6262    static bool doesPathStartWithDriveLetter(const QString &path);
    63 
     63    static const QString replaceDosDelimeter(const QString &path);
    6464};
    6565
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp

    r102363 r102378  
    427427    , pszMinimumGuestAdditionVersion("6.1")
    428428{
     429    setModelFileSystem(isWindowsFileSystem());
    429430    if (!m_comMachine.isNull())
    430431        m_strTableName = m_comMachine.GetName();
     
    432433    prepareGuestSessionPanel();
    433434    prepareActionConnections();
    434 
    435435    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
    436436            this, &UIFileManagerGuestTable::sltMachineStateChange);
     
    15901590}
    15911591
    1592 bool UIFileManagerGuestTable::isFileSystemWindows() const
    1593 {
    1594     if (!m_comGuest.isOk())
     1592bool UIFileManagerGuestTable::isWindowsFileSystem() const
     1593{
     1594    if (!m_comMachine.isOk())
    15951595        return false;
    1596     return m_comGuest.GetOSTypeId().contains("windows", Qt::CaseInsensitive);
     1596    return m_comMachine.GetOSTypeId().contains("windows", Qt::CaseInsensitive);
    15971597}
    15981598
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.h

    r102363 r102378  
    102102    virtual void  setState();
    103103    virtual void  setSessionDependentWidgetsEnabled();
    104     virtual bool  isFileSystemWindows() const override final;
     104    virtual bool  isWindowsFileSystem() const override final;
    105105
    106106private slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp

    r102363 r102378  
    136136    :UIFileManagerTable(pActionPool, pParent)
    137137{
     138    setModelFileSystem(isWindowsFileSystem());
    138139    initializeFileTree();
    139140    prepareToolbar();
     
    261262}
    262263
    263 bool UIFileManagerHostTable::isFileSystemWindows() const
     264bool UIFileManagerHostTable::isWindowsFileSystem() const
    264265{
    265266    return uiCommon().hostOperatingSystem().contains("windows", Qt::CaseInsensitive);
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.h

    r102363 r102378  
    7474    virtual void    createFileViewContextMenu(const QWidget *pWidget, const QPoint &point) override final;
    7575    virtual void    toggleForwardBackwardActions() override final;
    76     virtual bool    isFileSystemWindows() const override final;
     76    virtual bool    isWindowsFileSystem() const override final;
    7777    /** @name Copy/Cut host-to-host stuff. Currently not implemented.
    7878     * @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r102363 r102378  
    461461    if (!m_pModel)
    462462        return;
     463
    463464    connect(m_pModel, &UICustomFileSystemModel::sigItemRenamed,
    464465            this, &UIFileManagerTable::sltHandleItemRenameAttempt);
     
    552553        return;
    553554
    554     const QString startPath("/");
     555    QString startPath("/");
    555556    /* On Unix-like systems startItem represents the root directory. On Windows it is like "my computer" under which
    556557     * drives are listed: */
     
    561562
    562563    m_pModel->signalUpdate();
    563     updateCurrentLocationEdit(startPath);
    564564    m_pView->setRootIndex(m_pProxyModel->mapFromSource(m_pModel->rootIndex()));
     565    updateCurrentLocationEdit(currentDirectoryPath());
    565566}
    566567
     
    13451346}
    13461347
     1348void UIFileManagerTable::setModelFileSystem(bool fIsWindowsFileSystem)
     1349{
     1350    if (m_pModel)
     1351        m_pModel->setIsWindowsFileSystem(fIsWindowsFileSystem);
     1352}
     1353
    13471354#include "UIFileManagerTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r102363 r102378  
    227227    virtual void     toggleForwardBackwardActions() = 0;
    228228    virtual bool     event(QEvent *pEvent) RT_OVERRIDE;
    229     virtual bool     isFileSystemWindows() const = 0;
     229    virtual bool     isWindowsFileSystem() const = 0;
    230230    /** @name Copy/Cut guest-to-guest (host-to-host) stuff.
    231231     * @{ */
     
    252252    QHBoxLayout*     toolBarLayout();
    253253    void             setSessionWidgetsEnabled(bool fEnabled);
     254    void             setModelFileSystem(bool fIsWindowsFileSystem);
    254255
    255256    QILabel                 *m_pLocationLabel;
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.h

    r100955 r102378  
    5151class QIToolBar;
    5252class UIActionPool;
     53class UIFileManagerHostTable;
    5354class UIVisoHostBrowser;
    5455class UIVisoContentBrowser;
     
    152153    /** @} */
    153154
    154     QVBoxLayout          *m_pMainLayout;
    155     UIVisoHostBrowser    *m_pHostBrowser;
    156     UIVisoContentBrowser *m_pVISOContentBrowser;
     155    QVBoxLayout            *m_pMainLayout;
     156    UIVisoHostBrowser      *m_pHostBrowser;
     157    UIVisoContentBrowser   *m_pVISOContentBrowser;
     158    UIFileManagerHostTable *m_pHostFileBrowser;
    157159
    158160    QIToolBar             *m_pToolBar;
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFileTableNavigationWidget.cpp

    r100324 r102378  
    115115UIFileManagerBreadCrumbs::UIFileManagerBreadCrumbs(QWidget *pParent /* = 0 */)
    116116    :QLabel(pParent)
    117     , m_pathSeparator('/')
     117    , m_pathSeparator(UIPathOperations::delimiter)
    118118{
    119119    float fFontMult = 1.f;
     
    139139    m_strPath = strPath;
    140140
    141     const QChar separator('/');
     141    const QChar separator(UIPathOperations::delimiter);
    142142    clear();
    143143
     
    146146
    147147    QStringList folderList = UIPathOperations::pathTrail(strPath);
    148     folderList.push_front(separator);
     148    if (!strPath.isEmpty() && strPath.at(0) == UIPathOperations::delimiter)
     149        folderList.push_front(separator);
    149150
    150151    QString strLabelText;
     
    154155    for (int i = 0; i < folderList.size(); ++i)
    155156    {
    156         QString strFolder = UIPathOperations::removeTrailingDelimiters(folderList.at(i));
     157        QString strFolder = folderList.at(i);
    157158        if (i != 0)
    158159            strPathUpto[i] = strPathUpto[i - 1];
    159         if (i == 0 || i == folderList.size() - 1)
    160             strPathUpto[i].append(QString("%1").arg(strFolder));
    161         else
    162             strPathUpto[i].append(QString("%1%2").arg(strFolder).arg(separator));
     160        strPathUpto[i].append(QString("%1%2").arg(strFolder).arg(separator));
    163161    }
    164162
     
    166164    for (int i = folderList.size() - 1; i >= 0; --i)
    167165    {
    168         QString strFolder = UIPathOperations::removeTrailingDelimiters(folderList.at(i)).replace('/', m_pathSeparator);
     166        QString strFolder = UIPathOperations::removeTrailingDelimiters(folderList.at(i)).replace(UIPathOperations::delimiter, m_pathSeparator);
    169167        QString strWord = QString("<a href=\"%1\" style=\"color:black;text-decoration:none;\">%2</a>").arg(strPathUpto[i]).arg(strFolder);
    170168
     
    214212    , m_pAddressLineEdit(0)
    215213    , m_pSwitchButton(0)
    216     , m_pathSeparator('/')
     214    , m_pathSeparator(UIPathOperations::delimiter)
    217215{
    218216    prepare();
     
    232230    {
    233231        QString strNativeLocation(strLocation);
    234         strNativeLocation.replace('/', m_pathSeparator);
     232        strNativeLocation.replace(UIPathOperations::delimiter, m_pathSeparator);
    235233        int itemIndex = m_pHistoryComboBox->findText(strNativeLocation,
    236234                                                      Qt::MatchExactly | Qt::MatchCaseSensitive);
     
    369367void UIFileTableNavigationWidget::sltHandlePathChange(const QString &strPath)
    370368{
    371     emit sigPathChanged(QDir::fromNativeSeparators(strPath));
     369    emit sigPathChanged(UIPathOperations::replaceDosDelimeter(strPath));
    372370}
    373371
Note: See TracChangeset for help on using the changeset viewer.

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