VirtualBox

Changeset 76495 in vbox for trunk/src


Ignore:
Timestamp:
Dec 27, 2018 12:20:17 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. Some changes on UICustomFileSystemItem.

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

Legend:

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

    r76429 r76495  
    2121
    2222/* Qt includes: */
     23# include <QApplication>
    2324# include <QDateTime>
    2425# include <QHeaderView>
     
    3940*********************************************************************************************************************************/
    4041
    41 UICustomFileSystemItem::UICustomFileSystemItem(const QVector<QVariant> &data,
    42                                  UICustomFileSystemItem *parent, KFsObjType type)
    43     : m_itemData(data)
    44     , m_parentItem(parent)
     42UICustomFileSystemItem::UICustomFileSystemItem(const QString &strName, UICustomFileSystemItem *parent, KFsObjType type)
     43    : m_parentItem(parent)
    4544    , m_bIsOpened(false)
    4645    , m_isTargetADirectory(false)
     
    4847    , m_isDriveItem(false)
    4948{
     49    for (int i = static_cast<int>(UICustomFileSystemModelColumn_Name);
     50         i < static_cast<int>(UICustomFileSystemModelColumn_Max); ++i)
     51        m_itemData[static_cast<UICustomFileSystemModelColumn>(i)] = QVariant();
     52    m_itemData[UICustomFileSystemModelColumn_Name] = strName;
    5053    if (parent)
    5154        parent->appendChild(this);
     
    9598{
    9699    return m_itemData.count();
     100
    97101}
    98102
    99103QVariant UICustomFileSystemItem::data(int column) const
    100104{
    101     return m_itemData.value(column);
     105    return m_itemData.value(static_cast<UICustomFileSystemModelColumn>(column), QVariant());
    102106}
    103107
    104108QString UICustomFileSystemItem::name() const
    105109{
    106     if (m_itemData.isEmpty() || !m_itemData[0].canConvert(QMetaType::QString))
     110    QVariant data = m_itemData.value(UICustomFileSystemModelColumn_Name, QVariant());
     111    if (!data.canConvert(QMetaType::QString))
    107112        return QString();
    108     return m_itemData[0].toString();
     113    return data.toString();
    109114}
    110115
    111116void UICustomFileSystemItem::setData(const QVariant &data, int index)
    112117{
    113     if (index >= m_itemData.length())
    114         return;
    115     m_itemData[index] = data;
     118    m_itemData[static_cast<UICustomFileSystemModelColumn>(index)] = data;
     119}
     120
     121void UICustomFileSystemItem::setData(const QVariant &data, UICustomFileSystemModelColumn enmColumn)
     122{
     123    m_itemData[enmColumn] = data;
    116124}
    117125
     
    220228{
    221229    return m_isDriveItem;
    222 }
    223 
    224 /* static */QVector<QVariant> UICustomFileSystemItem::createTreeItemData(const QString &strName, unsigned long long size,
    225                                                                          const QDateTime &changeTime,
    226                                                                          const QString &strOwner, const QString &strPermissions)
    227 {
    228     QVector<QVariant> data;
    229     data.resize(UICustomFileSystemModelColumn_Max);
    230     data[UICustomFileSystemModelColumn_Name]        = strName;
    231     data[UICustomFileSystemModelColumn_Size]        = (qulonglong)size;
    232     data[UICustomFileSystemModelColumn_ChangeTime]  = changeTime;
    233     data[UICustomFileSystemModelColumn_Owner]       = strOwner;
    234     data[UICustomFileSystemModelColumn_Permissions] = strPermissions;
    235     return data;
    236230}
    237231
     
    479473    UICustomFileSystemItem *parentItem = childItem->parentItem();
    480474
    481     if (parentItem == rootItem())
     475    if (!parentItem || parentItem == rootItem())
    482476        return QModelIndex();
    483477
     
    539533void UICustomFileSystemModel::initializeTree()
    540534{
    541     QVector<QVariant> headData;
    542     headData.resize(UICustomFileSystemModelColumn_Max);
    543     m_pRootItem = new UICustomFileSystemItem(headData, 0, KFsObjType_Directory);
    544 }
     535    m_pRootItem = new UICustomFileSystemItem(QApplication::tr("UIFileManager", "Name"), 0, KFsObjType_Directory);
     536    m_pRootItem->setData(QApplication::tr("UIFileManager", "Size"), UICustomFileSystemModelColumn_Size);
     537    m_pRootItem->setData(QApplication::tr("UIFileManager", "Change Time"), UICustomFileSystemModelColumn_ChangeTime);
     538    m_pRootItem->setData(QApplication::tr("UIFileManager", "Owner"), UICustomFileSystemModelColumn_Owner);
     539    m_pRootItem->setData(QApplication::tr("UIFileManager", "Permissions"), UICustomFileSystemModelColumn_Permissions);
     540}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICustomFileSystemModel.h

    r76333 r76495  
    4242public:
    4343
    44     /** @p data contains values to be shown in table view's colums. data[0] is assumed to be
    45      *  the name of the file object which is the file name including extension or name of the
    46      *  directory */
    47     explicit UICustomFileSystemItem(const QVector<QVariant> &data,
    48                              UICustomFileSystemItem *parentItem, KFsObjType type);
     44    /** @p strName contains file object name which is assumed to be unique among a parent object's children. */
     45    explicit UICustomFileSystemItem(const QString &strName, UICustomFileSystemItem *parentItem, KFsObjType type);
    4946    ~UICustomFileSystemItem();
    5047
    51     void appendChild(UICustomFileSystemItem *child);
    5248    void reset();
    5349    UICustomFileSystemItem *child(int row) const;
     
    5854    QVariant data(int column) const;
    5955    void setData(const QVariant &data, int index);
     56    void setData(const QVariant &data, UICustomFileSystemModelColumn enmColumn);
    6057    int row() const;
    6158    UICustomFileSystemItem *parentItem();
     
    9390    bool isDriveItem() const;
    9491
    95     static QVector<QVariant> createTreeItemData(const QString &strName, unsigned long long size, const QDateTime &changeTime,
    96                                                 const QString &strOwner, const QString &strPermissions);
    97 
    9892private:
     93    void appendChild(UICustomFileSystemItem *child);
    9994
    10095    QList<UICustomFileSystemItem*>         m_childItems;
    10196    /** Used to find children by name */
    10297    QMap<QString, UICustomFileSystemItem*> m_childMap;
    103     /** It is required that m_itemData[0] is name (QString) of the file object */
    104     QVector<QVariant>  m_itemData;
     98    QMap<UICustomFileSystemModelColumn, QVariant>  m_itemData;
    10599    UICustomFileSystemItem *m_parentItem;
    106100    bool             m_bIsOpened;
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp

    r76429 r76495  
    205205                QDateTime changeTime = QDateTime::fromMSecsSinceEpoch(fsInfo.GetChangeTime()/RT_NS_1MS);
    206206
    207                 data << fsInfo.GetName() << static_cast<qulonglong>(fsInfo.GetObjectSize())
    208                      << changeTime << fsInfo.GetUserName() << permissionString(fsInfo);
    209 
    210207                KFsObjType fsObjectType = fileType(fsInfo);
    211                 UICustomFileSystemItem *item = new UICustomFileSystemItem(data, parent, fsObjectType);
     208                UICustomFileSystemItem *item = new UICustomFileSystemItem(fsInfo.GetName(), parent, fsObjectType);
    212209
    213210                if (!item)
    214211                    continue;
     212
     213                item->setData(static_cast<qulonglong>(fsInfo.GetObjectSize()), UICustomFileSystemModelColumn_Size);
     214                item->setData(changeTime, UICustomFileSystemModelColumn_ChangeTime);
     215                item->setData(fsInfo.GetUserName(), UICustomFileSystemModelColumn_Owner);
     216                item->setData(permissionString(fsInfo), UICustomFileSystemModelColumn_Permissions);
    215217                item->setPath(UIPathOperations::mergePaths(strPath, fsInfo.GetName()));
     218                item->setIsOpened(false);
    216219                fileObjects.insert(fsInfo.GetName(), item);
    217                 item->setIsOpened(false);
    218220                /* @todo. We will need to wait a fully implemented SymlinkRead function
    219221                 * to be able to handle sym links properly: */
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp

    r76429 r76495  
    148148        return;
    149149    QFileInfoList entries = directory.entryInfoList();
    150 
    151 
    152150    for (int i = 0; i < entries.size(); ++i)
    153151    {
    154 
    155 
    156152        const QFileInfo &fileInfo = entries.at(i);
    157         QVector<QVariant> itemData = UICustomFileSystemItem::createTreeItemData(fileInfo.fileName(), fileInfo.size(),
    158                                                                                 fileInfo.lastModified(), fileInfo.owner(),
    159                                                                                 permissionString(fileInfo.permissions()));
     153
    160154        if (fileInfo.fileName() == ".")
    161155            continue;
     
    163157            continue;
    164158
    165         UICustomFileSystemItem *item = new UICustomFileSystemItem(itemData, parent, fileType(fileInfo));
     159        UICustomFileSystemItem *item = new UICustomFileSystemItem(fileInfo.fileName(), parent, fileType(fileInfo));
    166160        if (!item)
    167161            continue;
     162
     163        item->setData(fileInfo.size(),         UICustomFileSystemModelColumn_Size);
     164        item->setData(fileInfo.lastModified(), UICustomFileSystemModelColumn_ChangeTime);
     165        item->setData(fileInfo.owner(),        UICustomFileSystemModelColumn_Owner);
     166        item->setData(permissionString(fileInfo.permissions()),  UICustomFileSystemModelColumn_Permissions);
    168167        item->setPath(fileInfo.absoluteFilePath());
    169168        /* if the item is a symlink set the target path and
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r76429 r76495  
    551551
    552552    const QString startPath("/");
    553     QVector<QVariant> itemData = UICustomFileSystemItem::createTreeItemData(startPath, 4096, QDateTime(),
    554                                                                             "" /* owner */, "" /* permissions */);
    555     UICustomFileSystemItem* startItem = new UICustomFileSystemItem(itemData, rootItem(), KFsObjType_Directory);
     553    UICustomFileSystemItem* startItem = new UICustomFileSystemItem(startPath, rootItem(), KFsObjType_Directory);
    556554    startItem->setPath(startPath);
    557     rootItem()->appendChild(startItem);
    558555    startItem->setIsOpened(false);
    559556    populateStartDirectory(startItem);
     
    576573        for (int i = 0; i < m_driveLetterList.size(); ++i)
    577574        {
    578             QVector<QVariant> itemData = UICustomFileSystemItem::createTreeItemData(m_driveLetterList[i], 4096,
    579                                                                                     QDateTime(), QString(), QString());
    580             UICustomFileSystemItem* driveItem = new UICustomFileSystemItem(itemData, startItem, KFsObjType_Directory);
     575            UICustomFileSystemItem* driveItem = new UICustomFileSystemItem(m_driveLetterList[i], startItem, KFsObjType_Directory);
    581576            driveItem->setPath(m_driveLetterList[i]);
    582             startItem->appendChild(driveItem);
    583577            driveItem->setIsOpened(false);
    584578            driveItem->setIsDriveItem(true);
     
    596590    if (!map.contains(UICustomFileSystemModel::strUpDirectoryString)  && !isStartDir)
    597591    {
    598         QVector<QVariant> data = UICustomFileSystemItem::createTreeItemData(UICustomFileSystemModel::strUpDirectoryString,
    599                                                                             4096, QDateTime(), QString(), QString());
    600 
    601         UICustomFileSystemItem *item = new UICustomFileSystemItem(data, parent, KFsObjType_Directory);
     592        UICustomFileSystemItem *item = new UICustomFileSystemItem(UICustomFileSystemModel::strUpDirectoryString,
     593                                                                  parent, KFsObjType_Directory);
    602594        item->setIsOpened(false);
    603595        map.insert(UICustomFileSystemModel::strUpDirectoryString, item);
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