VirtualBox

Changeset 76333 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 21, 2018 12:56:44 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699: More refactoring in file manager classes

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

Legend:

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

    r76332 r76333  
    3636
    3737/*********************************************************************************************************************************
    38 *   UIFileTableItem implementation.                                                                                              *
     38*   UICustomFileSystemItem implementation.                                                                                       *
    3939*********************************************************************************************************************************/
    4040
    41 UIFileTableItem::UIFileTableItem(const QVector<QVariant> &data,
    42                                  UIFileTableItem *parent, KFsObjType type)
     41UICustomFileSystemItem::UICustomFileSystemItem(const QVector<QVariant> &data,
     42                                 UICustomFileSystemItem *parent, KFsObjType type)
    4343    : m_itemData(data)
    4444    , m_parentItem(parent)
     
    5050}
    5151
    52 UIFileTableItem::~UIFileTableItem()
     52UICustomFileSystemItem::~UICustomFileSystemItem()
    5353{
    5454    reset();
    5555}
    5656
    57 void UIFileTableItem::appendChild(UIFileTableItem *item)
     57void UICustomFileSystemItem::appendChild(UICustomFileSystemItem *item)
    5858{
    5959    if (!item)
     
    6363}
    6464
    65 void UIFileTableItem::reset()
     65void UICustomFileSystemItem::reset()
    6666{
    6767    qDeleteAll(m_childItems);
     
    7171}
    7272
    73 UIFileTableItem *UIFileTableItem::child(int row) const
     73UICustomFileSystemItem *UICustomFileSystemItem::child(int row) const
    7474{
    7575    return m_childItems.value(row);
    7676}
    7777
    78 UIFileTableItem *UIFileTableItem::child(const QString &path) const
     78UICustomFileSystemItem *UICustomFileSystemItem::child(const QString &path) const
    7979{
    8080    if (!m_childMap.contains(path))
     
    8383}
    8484
    85 int UIFileTableItem::childCount() const
     85int UICustomFileSystemItem::childCount() const
    8686{
    8787    return m_childItems.count();
    8888}
    8989
    90 int UIFileTableItem::columnCount() const
     90int UICustomFileSystemItem::columnCount() const
    9191{
    9292    return m_itemData.count();
    9393}
    9494
    95 QVariant UIFileTableItem::data(int column) const
     95QVariant UICustomFileSystemItem::data(int column) const
    9696{
    9797    return m_itemData.value(column);
    9898}
    9999
    100 QString UIFileTableItem::name() const
     100QString UICustomFileSystemItem::name() const
    101101{
    102102    if (m_itemData.isEmpty() || !m_itemData[0].canConvert(QMetaType::QString))
     
    105105}
    106106
    107 void UIFileTableItem::setData(const QVariant &data, int index)
     107void UICustomFileSystemItem::setData(const QVariant &data, int index)
    108108{
    109109    if (index >= m_itemData.length())
     
    112112}
    113113
    114 UIFileTableItem *UIFileTableItem::parentItem()
     114UICustomFileSystemItem *UICustomFileSystemItem::parentItem()
    115115{
    116116    return m_parentItem;
    117117}
    118118
    119 int UIFileTableItem::row() const
     119int UICustomFileSystemItem::row() const
    120120{
    121121    if (m_parentItem)
    122         return m_parentItem->m_childItems.indexOf(const_cast<UIFileTableItem*>(this));
     122        return m_parentItem->m_childItems.indexOf(const_cast<UICustomFileSystemItem*>(this));
    123123    return 0;
    124124}
    125125
    126 bool UIFileTableItem::isDirectory() const
     126bool UICustomFileSystemItem::isDirectory() const
    127127{
    128128    return m_type == KFsObjType_Directory;
    129129}
    130130
    131 bool UIFileTableItem::isSymLink() const
     131bool UICustomFileSystemItem::isSymLink() const
    132132{
    133133    return m_type == KFsObjType_Symlink;
    134134}
    135135
    136 bool UIFileTableItem::isFile() const
     136bool UICustomFileSystemItem::isFile() const
    137137{
    138138    return m_type == KFsObjType_File;
    139139}
    140140
    141 void UIFileTableItem::clearChildren()
     141void UICustomFileSystemItem::clearChildren()
    142142{
    143143    qDeleteAll(m_childItems);
     
    146146}
    147147
    148 bool UIFileTableItem::isOpened() const
     148bool UICustomFileSystemItem::isOpened() const
    149149{
    150150    return m_bIsOpened;
    151151}
    152152
    153 void UIFileTableItem::setIsOpened(bool flag)
     153void UICustomFileSystemItem::setIsOpened(bool flag)
    154154{
    155155    m_bIsOpened = flag;
    156156}
    157157
    158 const QString  &UIFileTableItem::path() const
     158const QString  &UICustomFileSystemItem::path() const
    159159{
    160160    return m_strPath;
    161161}
    162162
    163 void UIFileTableItem::setPath(const QString &path)
     163void UICustomFileSystemItem::setPath(const QString &path)
    164164{
    165165    if (path.isNull() || path.isEmpty())
     
    169169}
    170170
    171 bool UIFileTableItem::isUpDirectory() const
     171bool UICustomFileSystemItem::isUpDirectory() const
    172172{
    173173    if (!isDirectory())
     
    178178}
    179179
    180 KFsObjType UIFileTableItem::type() const
     180KFsObjType UICustomFileSystemItem::type() const
    181181{
    182182    return m_type;
    183183}
    184184
    185 const QString &UIFileTableItem::targetPath() const
     185const QString &UICustomFileSystemItem::targetPath() const
    186186{
    187187    return m_strTargetPath;
    188188}
    189189
    190 void UIFileTableItem::setTargetPath(const QString &path)
     190void UICustomFileSystemItem::setTargetPath(const QString &path)
    191191{
    192192    m_strTargetPath = path;
    193193}
    194194
    195 bool UIFileTableItem::isSymLinkToADirectory() const
     195bool UICustomFileSystemItem::isSymLinkToADirectory() const
    196196{
    197197    return m_isTargetADirectory;
    198198}
    199199
    200 void UIFileTableItem::setIsSymLinkToADirectory(bool flag)
     200void UICustomFileSystemItem::setIsSymLinkToADirectory(bool flag)
    201201{
    202202    m_isTargetADirectory = flag;
    203203}
    204204
    205 bool UIFileTableItem::isSymLinkToAFile() const
     205bool UICustomFileSystemItem::isSymLinkToAFile() const
    206206{
    207207    return isSymLink() && !m_isTargetADirectory;
    208208}
    209209
    210 void UIFileTableItem::setIsDriveItem(bool flag)
     210void UICustomFileSystemItem::setIsDriveItem(bool flag)
    211211{
    212212    m_isDriveItem = flag;
    213213}
    214214
    215 bool UIFileTableItem::isDriveItem() const
     215bool UICustomFileSystemItem::isDriveItem() const
    216216{
    217217    return m_isDriveItem;
    218218}
    219219
    220 UICustomFileSystemProxyModel::UICustomFileSystemProxyModel(QObject *parent /* = 0 */)
    221     :QSortFilterProxyModel(parent)
    222     , m_fListDirectoriesOnTop(false)
    223 {
    224 }
    225 
    226 void UICustomFileSystemProxyModel::setListDirectoriesOnTop(bool fListDirectoriesOnTop)
    227 {
    228     m_fListDirectoriesOnTop = fListDirectoriesOnTop;
     220/* static */QVector<QVariant> UICustomFileSystemItem::createTreeItemData(const QString &strName, unsigned long long size,
     221                                                                         const QDateTime &changeTime,
     222                                                                         const QString &strOwner, const QString &strPermissions)
     223{
     224    QVector<QVariant> data;
     225    data.resize(UICustomFileSystemModelColumn_Max);
     226    data[UICustomFileSystemModelColumn_Name]        = strName;
     227    data[UICustomFileSystemModelColumn_Size]        = (qulonglong)size;
     228    data[UICustomFileSystemModelColumn_ChangeTime]  = changeTime;
     229    data[UICustomFileSystemModelColumn_Owner]       = strOwner;
     230    data[UICustomFileSystemModelColumn_Permissions] = strPermissions;
     231    return data;
    229232}
    230233
     
    241244bool UICustomFileSystemProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
    242245{
    243     UIFileTableItem *pLeftItem = static_cast<UIFileTableItem*>(left.internalPointer());
    244     UIFileTableItem *pRightItem = static_cast<UIFileTableItem*>(right.internalPointer());
     246    UICustomFileSystemItem *pLeftItem = static_cast<UICustomFileSystemItem*>(left.internalPointer());
     247    UICustomFileSystemItem *pRightItem = static_cast<UICustomFileSystemItem*>(right.internalPointer());
    245248
    246249    if (pLeftItem && pRightItem)
     
    281284}
    282285
     286UICustomFileSystemProxyModel::UICustomFileSystemProxyModel(QObject *parent /* = 0 */)
     287    :QSortFilterProxyModel(parent)
     288    , m_fListDirectoriesOnTop(false)
     289{
     290}
     291
     292void UICustomFileSystemProxyModel::setListDirectoriesOnTop(bool fListDirectoriesOnTop)
     293{
     294    m_fListDirectoriesOnTop = fListDirectoriesOnTop;
     295}
     296
     297
     298/*********************************************************************************************************************************
     299*   UICustomFileSystemModel implementation.                                                                                      *
     300*********************************************************************************************************************************/
     301
    283302UICustomFileSystemModel::UICustomFileSystemModel(QObject *parent)
    284303    : QAbstractItemModel(parent)
     
    288307}
    289308
    290 UIFileTableItem* UICustomFileSystemModel::rootItem()
     309UICustomFileSystemItem* UICustomFileSystemModel::rootItem()
    291310{
    292311    return m_pRootItem;
    293312}
    294313
    295 const UIFileTableItem* UICustomFileSystemModel::rootItem() const
     314const UICustomFileSystemItem* UICustomFileSystemModel::rootItem() const
    296315{
    297316    return m_pRootItem;
     
    306325{
    307326    if (parent.isValid())
    308         return static_cast<UIFileTableItem*>(parent.internalPointer())->columnCount();
     327        return static_cast<UICustomFileSystemItem*>(parent.internalPointer())->columnCount();
    309328    else
    310329    {
     
    322341        if (index.column() == 0 && value.canConvert(QMetaType::QString))
    323342        {
    324             UIFileTableItem *pItem = static_cast<UIFileTableItem*>(index.internalPointer());
     343            UICustomFileSystemItem *pItem = static_cast<UICustomFileSystemItem*>(index.internalPointer());
    325344            if (!pItem)
    326345                return false;
     
    339358    if (!index.isValid())
    340359        return QVariant();
    341     UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     360    UICustomFileSystemItem *item = static_cast<UICustomFileSystemItem*>(index.internalPointer());
    342361    if (!item)
    343362        return QVariant();
     
    398417    if (!index.isValid())
    399418        return 0;
    400     UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     419    UICustomFileSystemItem *item = static_cast<UICustomFileSystemItem*>(index.internalPointer());
    401420    if (!item)
    402421        return QAbstractItemModel::flags(index);
     
    420439}
    421440
    422 QModelIndex UICustomFileSystemModel::index(UIFileTableItem* item)
     441QModelIndex UICustomFileSystemModel::index(UICustomFileSystemItem* item)
    423442{
    424443    if (!item)
     
    432451        return QModelIndex();
    433452
    434     const UIFileTableItem* parentItem = rootItem();
     453    const UICustomFileSystemItem* parentItem = rootItem();
    435454
    436455    if (parent.isValid())
    437         parentItem = static_cast<UIFileTableItem*>(parent.internalPointer());
     456        parentItem = static_cast<UICustomFileSystemItem*>(parent.internalPointer());
    438457
    439458    if (!parentItem)
    440459        return QModelIndex();
    441460
    442     UIFileTableItem *childItem = parentItem->child(row);
     461    UICustomFileSystemItem *childItem = parentItem->child(row);
    443462    if (childItem)
    444463        return createIndex(row, column, childItem);
     
    453472        return QModelIndex();
    454473
    455     UIFileTableItem *childItem = static_cast<UIFileTableItem*>(index.internalPointer());
    456     UIFileTableItem *parentItem = childItem->parentItem();
     474    UICustomFileSystemItem *childItem = static_cast<UICustomFileSystemItem*>(index.internalPointer());
     475    UICustomFileSystemItem *parentItem = childItem->parentItem();
    457476
    458477    if (parentItem == rootItem())
     
    466485    if (parent.column() > 0)
    467486        return 0;
    468     const UIFileTableItem *parentItem = rootItem();
     487    const UICustomFileSystemItem *parentItem = rootItem();
    469488    if (parent.isValid())
    470         parentItem = static_cast<UIFileTableItem*>(parent.internalPointer());
     489        parentItem = static_cast<UICustomFileSystemItem*>(parent.internalPointer());
    471490    if (!parentItem)
    472491        return 0;
     
    518537    QVector<QVariant> headData;
    519538    headData.resize(UICustomFileSystemModelColumn_Max);
    520     m_pRootItem = new UIFileTableItem(headData, 0, KFsObjType_Directory);
    521 }
     539    m_pRootItem = new UICustomFileSystemItem(headData, 0, KFsObjType_Directory);
     540}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICustomFileSystemModel.h

    r76332 r76333  
    3636};
    3737
    38 /** A UIFileTableItem instance is a tree node representing a file object (file, directory, etc). The tree contructed
     38/** A UICustomFileSystemItem instance is a tree node representing a file object (file, directory, etc). The tree contructed
    3939    by these instances is the data source for the UICustomFileSystemModel. */
    40 class UIFileTableItem
     40class UICustomFileSystemItem
    4141{
    4242public:
     
    4545     *  the name of the file object which is the file name including extension or name of the
    4646     *  directory */
    47     explicit UIFileTableItem(const QVector<QVariant> &data,
    48                              UIFileTableItem *parentItem, KFsObjType type);
    49     ~UIFileTableItem();
     47    explicit UICustomFileSystemItem(const QVector<QVariant> &data,
     48                             UICustomFileSystemItem *parentItem, KFsObjType type);
     49    ~UICustomFileSystemItem();
    5050
    51     void appendChild(UIFileTableItem *child);
     51    void appendChild(UICustomFileSystemItem *child);
    5252    void reset();
    53     UIFileTableItem *child(int row) const;
     53    UICustomFileSystemItem *child(int row) const;
    5454    /** Searches for the child by path and returns it if found. */
    55     UIFileTableItem *child(const QString &path) const;
     55    UICustomFileSystemItem *child(const QString &path) const;
    5656    int childCount() const;
    5757    int columnCount() const;
     
    5959    void setData(const QVariant &data, int index);
    6060    int row() const;
    61     UIFileTableItem *parentItem();
     61    UICustomFileSystemItem *parentItem();
    6262
    6363    bool isDirectory() const;
     
    9393    bool isDriveItem() const;
    9494
     95    static QVector<QVariant> createTreeItemData(const QString &strName, unsigned long long size, const QDateTime &changeTime,
     96                                                const QString &strOwner, const QString &strPermissions);
     97
    9598private:
    9699
    97     QList<UIFileTableItem*>         m_childItems;
     100    QList<UICustomFileSystemItem*>         m_childItems;
    98101    /** Used to find children by name */
    99     QMap<QString, UIFileTableItem*> m_childMap;
     102    QMap<QString, UICustomFileSystemItem*> m_childMap;
    100103    /** It is required that m_itemData[0] is name (QString) of the file object */
    101104    QVector<QVariant>  m_itemData;
    102     UIFileTableItem *m_parentItem;
     105    UICustomFileSystemItem *m_parentItem;
    103106    bool             m_bIsOpened;
    104107    /** Full absolute path of the item. Without the trailing '/' */
     
    145148signals:
    146149
    147     void sigItemRenamed(UIFileTableItem *pItem, QString strOldName, QString strNewName);
     150    void sigItemRenamed(UICustomFileSystemItem *pItem, QString strOldName, QString strNewName);
    148151
    149152public:
     
    160163    QModelIndex    index(int row, int column,
    161164                      const QModelIndex &parent = QModelIndex()) const /* override */;
    162     QModelIndex    index(UIFileTableItem* item);
     165    QModelIndex    index(UICustomFileSystemItem* item);
    163166    QModelIndex    parent(const QModelIndex &index) const /* override */;
    164167    int            rowCount(const QModelIndex &parent = QModelIndex()) const /* override */;
     
    172175    void           setShowHumanReadableSizes(bool fShowHumanReadableSizes);
    173176    bool           showHumanReadableSizes() const;
    174     UIFileTableItem* rootItem();
    175     const UIFileTableItem* rootItem() const;
     177    UICustomFileSystemItem* rootItem();
     178    const UICustomFileSystemItem* rootItem() const;
    176179
    177180    static const char* strUpDirectoryString;
     
    179182private:
    180183    void                initializeTree();
    181     UIFileTableItem    *m_pRootItem;
    182     void setupModelData(const QStringList &lines, UIFileTableItem *parent);
     184    UICustomFileSystemItem    *m_pRootItem;
     185    void setupModelData(const QStringList &lines, UICustomFileSystemItem *parent);
    183186    bool                m_fShowHumanReadableSizes;
    184187};
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp

    r76329 r76333  
    175175
    176176void UIFileManagerGuestTable::readDirectory(const QString& strPath,
    177                                      UIFileTableItem *parent, bool isStartDir /*= false*/)
     177                                     UICustomFileSystemItem *parent, bool isStartDir /*= false*/)
    178178
    179179{
     
    196196    {
    197197        CFsObjInfo fsInfo = directory.Read();
    198         QMap<QString, UIFileTableItem*> directories;
    199         QMap<QString, UIFileTableItem*> files;
     198        QMap<QString, UICustomFileSystemItem*> directories;
     199        QMap<QString, UICustomFileSystemItem*> files;
    200200
    201201        while (fsInfo.isOk())
     
    208208
    209209            KFsObjType fsObjectType = fileType(fsInfo);
    210             UIFileTableItem *item = new UIFileTableItem(data, parent, fsObjectType);
     210            UICustomFileSystemItem *item = new UICustomFileSystemItem(data, parent, fsObjectType);
    211211
    212212            if (!item)
     
    243243}
    244244
    245 void UIFileManagerGuestTable::deleteByItem(UIFileTableItem *item)
     245void UIFileManagerGuestTable::deleteByItem(UICustomFileSystemItem *item)
    246246{
    247247    if (!item)
     
    289289    if (!rootItem() || rootItem()->childCount() <= 0)
    290290        return;
    291     UIFileTableItem *startDirItem = rootItem()->child(0);
     291    UICustomFileSystemItem *startDirItem = rootItem()->child(0);
    292292    if (!startDirItem)
    293293        return;
     
    303303}
    304304
    305 bool UIFileManagerGuestTable::renameItem(UIFileTableItem *item, QString newBaseName)
     305bool UIFileManagerGuestTable::renameItem(UICustomFileSystemItem *item, QString newBaseName)
    306306{
    307307
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.h

    r76300 r76333  
    3131/* Forward declarations: */
    3232class UIActionPool;
     33class UICustomFileSystemItem;
    3334
    3435/** This class scans the guest file system by using the VBox Guest Control API
     
    5354
    5455    void            retranslateUi() /* override */;
    55     virtual void    readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;
    56     virtual void    deleteByItem(UIFileTableItem *item) /* override */;
     56    virtual void    readDirectory(const QString& strPath, UICustomFileSystemItem *parent, bool isStartDir = false) /* override */;
     57    virtual void    deleteByItem(UICustomFileSystemItem *item) /* override */;
    5758    virtual void    deleteByPath(const QStringList &pathList) /* override */;
    5859    virtual void    goToHomeDirectory() /* override */;
    59     virtual bool    renameItem(UIFileTableItem *item, QString newBaseName);
     60    virtual bool    renameItem(UICustomFileSystemItem *item, QString newBaseName);
    6061    virtual bool    createDirectory(const QString &path, const QString &directoryName);
    6162    virtual QString fsObjectPropertyString() /* override */;
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp

    r76329 r76333  
    202202}
    203203
    204 void UIFileManagerHostTable::readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir /*= false*/)
     204void UIFileManagerHostTable::readDirectory(const QString& strPath, UICustomFileSystemItem *parent, bool isStartDir /*= false*/)
    205205{
    206206    if (!parent)
     
    213213        return;
    214214    QFileInfoList entries = directory.entryInfoList();
    215     QMap<QString, UIFileTableItem*> directories;
    216     QMap<QString, UIFileTableItem*> files;
     215    QMap<QString, UICustomFileSystemItem*> directories;
     216    QMap<QString, UICustomFileSystemItem*> files;
    217217
    218218    for (int i = 0; i < entries.size(); ++i)
     
    220220
    221221        const QFileInfo &fileInfo = entries.at(i);
    222         UIFileTableItem *item = new UIFileTableItem(createTreeItemData(fileInfo.fileName(), fileInfo.size(),
    223                                                                        fileInfo.lastModified(), fileInfo.owner(),
    224                                                                        permissionString(fileInfo.permissions())),
    225                                                     parent, fileType(fileInfo));
     222        QVector<QVariant> itemData = UICustomFileSystemItem::createTreeItemData(fileInfo.fileName(), fileInfo.size(),
     223                                                                                fileInfo.lastModified(), fileInfo.owner(),
     224                                                                                permissionString(fileInfo.permissions()));
     225        UICustomFileSystemItem *item = new UICustomFileSystemItem(itemData, parent, fileType(fileInfo));
    226226        if (!item)
    227227            continue;
     
    250250}
    251251
    252 void UIFileManagerHostTable::deleteByItem(UIFileTableItem *item)
     252void UIFileManagerHostTable::deleteByItem(UICustomFileSystemItem *item)
    253253{
    254254    if (item->isUpDirectory())
     
    297297    if (!rootItem() || rootItem()->childCount() <= 0)
    298298        return;
    299     UIFileTableItem *startDirItem = rootItem()->child(0);
     299    UICustomFileSystemItem *startDirItem = rootItem()->child(0);
    300300    if (!startDirItem)
    301301        return;
     
    305305}
    306306
    307 bool UIFileManagerHostTable::renameItem(UIFileTableItem *item, QString newBaseName)
     307bool UIFileManagerHostTable::renameItem(UICustomFileSystemItem *item, QString newBaseName)
    308308{
    309309    if (!item || item->isUpDirectory() || newBaseName.isEmpty())
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.h

    r76300 r76333  
    2424/* Forward declarations: */
    2525class UIActionPool;
     26class UICustomFileSystemItem;
    2627
    2728/** This class scans the host file system by using the Qt API
     
    3940    KFsObjType  fileType(const QFileInfo &fsInfo);
    4041    void            retranslateUi() /* override */;
    41     virtual void    readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;
    42     virtual void    deleteByItem(UIFileTableItem *item) /* override */;
     42    virtual void    readDirectory(const QString& strPath, UICustomFileSystemItem *parent, bool isStartDir = false) /* override */;
     43    virtual void    deleteByItem(UICustomFileSystemItem *item) /* override */;
    4344    virtual void    deleteByPath(const QStringList &pathList) /* override */;
    4445    virtual void    goToHomeDirectory() /* override */;
    45     virtual bool    renameItem(UIFileTableItem *item, QString newBaseName);
     46    virtual bool    renameItem(UICustomFileSystemItem *item, QString newBaseName);
    4647    virtual bool    createDirectory(const QString &path, const QString &directoryName);
    4748    virtual QString fsObjectPropertyString() /* override */;
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r76329 r76333  
    534534    m_pView->clearSelection();
    535535
    536     UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     536    UICustomFileSystemItem *item = static_cast<UICustomFileSystemItem*>(index.internalPointer());
    537537    if (item)
    538538    {
     
    551551
    552552    const QString startPath("/");
    553     UIFileTableItem* startItem = new UIFileTableItem(createTreeItemData(startPath, 4096, QDateTime(),
    554                                                                         "" /* owner */, "" /* permissions */),
    555                                                     rootItem(), KFsObjType_Directory);
     553    QVector<QVariant> itemData = UICustomFileSystemItem::createTreeItemData(startPath, 4096, QDateTime(),
     554                                                                            "" /* owner */, "" /* permissions */);
     555    UICustomFileSystemItem* startItem = new UICustomFileSystemItem(itemData, rootItem(), KFsObjType_Directory);
    556556    startItem->setPath(startPath);
    557557    rootItem()->appendChild(startItem);
     
    564564}
    565565
    566 void UIFileManagerTable::populateStartDirectory(UIFileTableItem *startItem)
     566void UIFileManagerTable::populateStartDirectory(UICustomFileSystemItem *startItem)
    567567{
    568568    determineDriveLetters();
     
    576576        for (int i = 0; i < m_driveLetterList.size(); ++i)
    577577        {
    578             UIFileTableItem* driveItem = new UIFileTableItem(createTreeItemData(m_driveLetterList[i], 4096,
    579                                                                                 QDateTime(), QString(), QString()),
    580                                                             startItem, KFsObjType_Directory);
     578            QVector<QVariant> itemData = UICustomFileSystemItem::createTreeItemData(m_driveLetterList[i], 4096,
     579                                                                                    QDateTime(), QString(), QString());
     580            UICustomFileSystemItem* driveItem = new UICustomFileSystemItem(itemData, startItem, KFsObjType_Directory);
    581581            driveItem->setPath(m_driveLetterList[i]);
    582582            startItem->appendChild(driveItem);
     
    588588}
    589589
    590 void UIFileManagerTable::insertItemsToTree(QMap<QString,UIFileTableItem*> &map,
    591                                                 UIFileTableItem *parent, bool isDirectoryMap, bool isStartDir)
    592 {
    593     if (parent)
    594 
     590void UIFileManagerTable::insertItemsToTree(QMap<QString,UICustomFileSystemItem*> &map,
     591                                                UICustomFileSystemItem *parent, bool isDirectoryMap, bool isStartDir)
     592{
     593    if (!parent)
     594        return;
    595595    /* Make sure we have an item representing up directory, and make sure it is not there for the start dir: */
    596596    if (isDirectoryMap)
     
    598598        if (!map.contains(UICustomFileSystemModel::strUpDirectoryString)  && !isStartDir)
    599599        {
    600             QVector<QVariant> data;
    601             UIFileTableItem *item = new UIFileTableItem(createTreeItemData(UICustomFileSystemModel::strUpDirectoryString, 4096,
    602                                                                            QDateTime(), QString(), QString())
    603                                                         , parent, KFsObjType_Directory);
     600            QVector<QVariant> data = UICustomFileSystemItem::createTreeItemData(UICustomFileSystemModel::strUpDirectoryString,
     601                                                                                4096, QDateTime(), QString(), QString());
     602
     603            UICustomFileSystemItem *item = new UICustomFileSystemItem(data, parent, KFsObjType_Directory);
    604604            item->setIsOpened(false);
    605605            map.insert(UICustomFileSystemModel::strUpDirectoryString, item);
     
    610610        }
    611611    }
    612     for (QMap<QString,UIFileTableItem*>::const_iterator iterator = map.begin();
     612    for (QMap<QString,UICustomFileSystemItem*>::const_iterator iterator = map.begin();
    613613        iterator != map.end(); ++iterator)
    614614    {
     
    672672        return;
    673673
    674     UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     674    UICustomFileSystemItem *item = static_cast<UICustomFileSystemItem*>(index.internalPointer());
    675675    if (!item)
    676676        return;
     
    695695void UIFileManagerTable::goIntoDirectory(const QStringList &pathTrail)
    696696{
    697     UIFileTableItem *parent = getStartDirectoryItem();
     697    UICustomFileSystemItem *parent = getStartDirectoryItem();
    698698
    699699    for(int i = 0; i < pathTrail.size(); ++i)
     
    705705            readDirectory(parent->path(), parent, parent == getStartDirectoryItem());
    706706        /* search the current path item among the parent's children: */
    707         UIFileTableItem *item = parent->child(pathTrail.at(i));
     707        UICustomFileSystemItem *item = parent->child(pathTrail.at(i));
    708708        if (!item)
    709709            return;
     
    717717}
    718718
    719 void UIFileManagerTable::goIntoDirectory(UIFileTableItem *item)
     719void UIFileManagerTable::goIntoDirectory(UICustomFileSystemItem *item)
    720720{
    721721    if (!item || !m_pModel)
     
    724724}
    725725
    726 UIFileTableItem* UIFileManagerTable::indexData(const QModelIndex &index) const
     726UICustomFileSystemItem* UIFileManagerTable::indexData(const QModelIndex &index) const
    727727{
    728728    if (!index.isValid())
    729729        return 0;
    730     return static_cast<UIFileTableItem*>(index.internalPointer());
     730    return static_cast<UICustomFileSystemItem*>(index.internalPointer());
    731731}
    732732
     
    737737    QModelIndex currentIndex = currentRootIndex();
    738738
    739     UIFileTableItem *treeItem = indexData(currentIndex);
     739    UICustomFileSystemItem *treeItem = indexData(currentIndex);
    740740    if (!treeItem)
    741741        return;
     
    798798    QModelIndex modelIndex =
    799799        m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(0)) : selectedItemIndices.at(0);
    800     UIFileTableItem *item = indexData(modelIndex);
     800    UICustomFileSystemItem *item = indexData(modelIndex);
    801801    if (!item || item->isUpDirectory())
    802802        return;
     
    811811    if (!currentIndex.isValid())
    812812        return;
    813     UIFileTableItem *item = static_cast<UIFileTableItem*>(currentIndex.internalPointer());
     813    UICustomFileSystemItem *item = static_cast<UICustomFileSystemItem*>(currentIndex.internalPointer());
    814814    if (!item)
    815815        return;
     
    888888}
    889889
    890 void UIFileManagerTable::sltHandleItemRenameAttempt(UIFileTableItem *pItem, QString strOldName, QString strNewName)
     890void UIFileManagerTable::sltHandleItemRenameAttempt(UICustomFileSystemItem *pItem, QString strOldName, QString strNewName)
    891891{
    892892    if (!pItem)
     
    929929            continue;
    930930
    931         UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     931        UICustomFileSystemItem *item = static_cast<UICustomFileSystemItem*>(index.internalPointer());
    932932        if (item && item->isUpDirectory())
    933933        {
     
    972972void UIFileManagerTable::deleteByIndex(const QModelIndex &itemIndex)
    973973{
    974     UIFileTableItem *treeItem = indexData(itemIndex);
     974    UICustomFileSystemItem *treeItem = indexData(itemIndex);
    975975    if (!treeItem)
    976976        return;
     
    980980void UIFileManagerTable::retranslateUi()
    981981{
    982     UIFileTableItem *pRootItem = rootItem();
     982    UICustomFileSystemItem *pRootItem = rootItem();
    983983    if (pRootItem)
    984984    {
     
    10521052}
    10531053
    1054 UIFileTableItem *UIFileManagerTable::getStartDirectoryItem()
    1055 {
    1056     UIFileTableItem* pRootItem = rootItem();
     1054UICustomFileSystemItem *UIFileManagerTable::getStartDirectoryItem()
     1055{
     1056    UICustomFileSystemItem* pRootItem = rootItem();
    10571057    if (!pRootItem)
    10581058        return 0;
     
    10831083    if (!currentRoot.isValid())
    10841084        return QString();
    1085     UIFileTableItem *item = static_cast<UIFileTableItem*>(currentRoot.internalPointer());
     1085    UICustomFileSystemItem *item = static_cast<UICustomFileSystemItem*>(currentRoot.internalPointer());
    10861086    if (!item)
    10871087        return QString();
     
    11041104        QModelIndex index =
    11051105            m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
    1106         UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
     1106        UICustomFileSystemItem *item = static_cast<UICustomFileSystemItem*>(index.internalPointer());
    11071107        if (!item)
    11081108            continue;
     
    11301130}
    11311131
    1132 QVector<QVariant> UIFileManagerTable::createTreeItemData(const QString &strName, ULONG64 size, const QDateTime &changeTime,
    1133                                                             const QString &strOwner, const QString &strPermissions)
    1134 {
    1135     QVector<QVariant> data;
    1136     data.resize(UICustomFileSystemModelColumn_Max);
    1137     data[UICustomFileSystemModelColumn_Name]        = strName;
    1138     data[UICustomFileSystemModelColumn_Size]        = (qulonglong)size;
    1139     data[UICustomFileSystemModelColumn_ChangeTime]  = changeTime;
    1140     data[UICustomFileSystemModelColumn_Owner]       = strOwner;
    1141     data[UICustomFileSystemModelColumn_Permissions] = strPermissions;
    1142     return data;
    1143 }
    1144 
    1145 UIFileTableItem* UIFileManagerTable::rootItem()
     1132UICustomFileSystemItem* UIFileManagerTable::rootItem()
    11461133{
    11471134    if (!m_pModel)
     
    12241211
    12251212    int rowCount = m_pProxyModel->rowCount(m_pView->rootIndex());
    1226     UIFileTableItem *pFoundItem = 0;
     1213    UICustomFileSystemItem *pFoundItem = 0;
    12271214    QModelIndex index;
    12281215    for (int i = 0; i < rowCount && !pFoundItem; ++i)
     
    12311218        if (!index.isValid())
    12321219            continue;
    1233         pFoundItem = static_cast<UIFileTableItem*>(m_pProxyModel->mapToSource(index).internalPointer());
     1220        pFoundItem = static_cast<UICustomFileSystemItem*>(m_pProxyModel->mapToSource(index).internalPointer());
    12341221        if (!pFoundItem)
    12351222            continue;
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r76329 r76333  
    4646class QVBoxLayout;
    4747class UIActionPool;
    48 class UIFileTableItem;
     48class UICustomFileSystemItem;
    4949class UICustomFileSystemModel;
    5050class UICustomFileSystemProxyModel;
     
    193193    void changeLocation(const QModelIndex &index);
    194194    void initializeFileTree();
    195     void insertItemsToTree(QMap<QString,UIFileTableItem*> &map, UIFileTableItem *parent,
     195    void insertItemsToTree(QMap<QString,UICustomFileSystemItem*> &map, UICustomFileSystemItem *parent,
    196196                           bool isDirectoryMap, bool isStartDir);
    197     virtual void     readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) = 0;
    198     virtual void     deleteByItem(UIFileTableItem *item) = 0;
     197    virtual void     readDirectory(const QString& strPath, UICustomFileSystemItem *parent, bool isStartDir = false) = 0;
     198    virtual void     deleteByItem(UICustomFileSystemItem *item) = 0;
    199199    virtual void     deleteByPath(const QStringList &pathList) = 0;
    200200    virtual void     goToHomeDirectory() = 0;
    201     virtual bool     renameItem(UIFileTableItem *item, QString newBaseName) = 0;
     201    virtual bool     renameItem(UICustomFileSystemItem *item, QString newBaseName) = 0;
    202202    virtual bool     createDirectory(const QString &path, const QString &directoryName) = 0;
    203203    virtual QString  fsObjectPropertyString() = 0;
     
    225225    void             goIntoDirectory(const QStringList &pathTrail);
    226226    /** Goes into directory pointed by the @p item */
    227     void             goIntoDirectory(UIFileTableItem *item);
    228     UIFileTableItem* indexData(const QModelIndex &index) const;
     227    void             goIntoDirectory(UICustomFileSystemItem *item);
     228    UICustomFileSystemItem* indexData(const QModelIndex &index) const;
    229229    bool             eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
    230230    CGuestFsObjInfo  guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const;
    231231    void             setSelectionDependentActionsEnabled(bool fIsEnabled);
    232     /** Creates a QList out of the parameters wrt. UICustomFileSystemModelColumn enum */
    233     QVector<QVariant>  createTreeItemData(const QString &strName, ULONG64 size, const QDateTime &changeTime,
    234                                         const QString &strOwner, const QString &strPermissions);
    235     UIFileTableItem*   rootItem();
    236 
     232    UICustomFileSystemItem*   rootItem();
    237233
    238234    QILabel                 *m_pLocationLabel;
     
    260256     *  if the file system rename fails we restore the old name of the item. See the comment of
    261257     *  sltRename() for more details. */
    262     void sltHandleItemRenameAttempt(UIFileTableItem *pItem, QString strOldName, QString strNewName);
     258    void sltHandleItemRenameAttempt(UICustomFileSystemItem *pItem, QString strOldName, QString strNewName);
    263259
    264260private:
     
    268264    /** @p itemIndex is assumed to be 'model' index not 'proxy model' index */
    269265    void             deleteByIndex(const QModelIndex &itemIndex);
    270     /** Returns the UIFileTableItem for path / which is a direct (and single) child of m_pRootItem */
    271     UIFileTableItem *getStartDirectoryItem();
     266    /** Returns the UICustomFileSystemItem for path / which is a direct (and single) child of m_pRootItem */
     267    UICustomFileSystemItem *getStartDirectoryItem();
    272268    /** Shows a modal dialog with a line edit for user to enter a new directory name and return the entered string*/
    273269    QString         getNewDirectoryName();
     
    277273    /** The start directory requires a special attention since on file systems with drive letters
    278274     *  drive letter are direct children of the start directory. On other systems start directory is '/' */
    279     void            populateStartDirectory(UIFileTableItem *startItem);
     275    void            populateStartDirectory(UICustomFileSystemItem *startItem);
    280276    /** Root index of the m_pModel */
    281277    QModelIndex     currentRootIndex() const;
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