- Timestamp:
- Dec 27, 2018 12:20:17 PM (6 years ago)
- 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 21 21 22 22 /* Qt includes: */ 23 # include <QApplication> 23 24 # include <QDateTime> 24 25 # include <QHeaderView> … … 39 40 *********************************************************************************************************************************/ 40 41 41 UICustomFileSystemItem::UICustomFileSystemItem(const QVector<QVariant> &data, 42 UICustomFileSystemItem *parent, KFsObjType type) 43 : m_itemData(data) 44 , m_parentItem(parent) 42 UICustomFileSystemItem::UICustomFileSystemItem(const QString &strName, UICustomFileSystemItem *parent, KFsObjType type) 43 : m_parentItem(parent) 45 44 , m_bIsOpened(false) 46 45 , m_isTargetADirectory(false) … … 48 47 , m_isDriveItem(false) 49 48 { 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; 50 53 if (parent) 51 54 parent->appendChild(this); … … 95 98 { 96 99 return m_itemData.count(); 100 97 101 } 98 102 99 103 QVariant UICustomFileSystemItem::data(int column) const 100 104 { 101 return m_itemData.value( column);105 return m_itemData.value(static_cast<UICustomFileSystemModelColumn>(column), QVariant()); 102 106 } 103 107 104 108 QString UICustomFileSystemItem::name() const 105 109 { 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)) 107 112 return QString(); 108 return m_itemData[0].toString();113 return data.toString(); 109 114 } 110 115 111 116 void UICustomFileSystemItem::setData(const QVariant &data, int index) 112 117 { 113 if (index >= m_itemData.length()) 114 return; 115 m_itemData[index] = data; 118 m_itemData[static_cast<UICustomFileSystemModelColumn>(index)] = data; 119 } 120 121 void UICustomFileSystemItem::setData(const QVariant &data, UICustomFileSystemModelColumn enmColumn) 122 { 123 m_itemData[enmColumn] = data; 116 124 } 117 125 … … 220 228 { 221 229 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;236 230 } 237 231 … … 479 473 UICustomFileSystemItem *parentItem = childItem->parentItem(); 480 474 481 if ( parentItem == rootItem())475 if (!parentItem || parentItem == rootItem()) 482 476 return QModelIndex(); 483 477 … … 539 533 void UICustomFileSystemModel::initializeTree() 540 534 { 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 42 42 public: 43 43 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); 49 46 ~UICustomFileSystemItem(); 50 47 51 void appendChild(UICustomFileSystemItem *child);52 48 void reset(); 53 49 UICustomFileSystemItem *child(int row) const; … … 58 54 QVariant data(int column) const; 59 55 void setData(const QVariant &data, int index); 56 void setData(const QVariant &data, UICustomFileSystemModelColumn enmColumn); 60 57 int row() const; 61 58 UICustomFileSystemItem *parentItem(); … … 93 90 bool isDriveItem() const; 94 91 95 static QVector<QVariant> createTreeItemData(const QString &strName, unsigned long long size, const QDateTime &changeTime,96 const QString &strOwner, const QString &strPermissions);97 98 92 private: 93 void appendChild(UICustomFileSystemItem *child); 99 94 100 95 QList<UICustomFileSystemItem*> m_childItems; 101 96 /** Used to find children by name */ 102 97 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; 105 99 UICustomFileSystemItem *m_parentItem; 106 100 bool m_bIsOpened; -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp ¶
r76429 r76495 205 205 QDateTime changeTime = QDateTime::fromMSecsSinceEpoch(fsInfo.GetChangeTime()/RT_NS_1MS); 206 206 207 data << fsInfo.GetName() << static_cast<qulonglong>(fsInfo.GetObjectSize())208 << changeTime << fsInfo.GetUserName() << permissionString(fsInfo);209 210 207 KFsObjType fsObjectType = fileType(fsInfo); 211 UICustomFileSystemItem *item = new UICustomFileSystemItem( data, parent, fsObjectType);208 UICustomFileSystemItem *item = new UICustomFileSystemItem(fsInfo.GetName(), parent, fsObjectType); 212 209 213 210 if (!item) 214 211 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); 215 217 item->setPath(UIPathOperations::mergePaths(strPath, fsInfo.GetName())); 218 item->setIsOpened(false); 216 219 fileObjects.insert(fsInfo.GetName(), item); 217 item->setIsOpened(false);218 220 /* @todo. We will need to wait a fully implemented SymlinkRead function 219 221 * to be able to handle sym links properly: */ -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp ¶
r76429 r76495 148 148 return; 149 149 QFileInfoList entries = directory.entryInfoList(); 150 151 152 150 for (int i = 0; i < entries.size(); ++i) 153 151 { 154 155 156 152 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 160 154 if (fileInfo.fileName() == ".") 161 155 continue; … … 163 157 continue; 164 158 165 UICustomFileSystemItem *item = new UICustomFileSystemItem( itemData, parent, fileType(fileInfo));159 UICustomFileSystemItem *item = new UICustomFileSystemItem(fileInfo.fileName(), parent, fileType(fileInfo)); 166 160 if (!item) 167 161 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); 168 167 item->setPath(fileInfo.absoluteFilePath()); 169 168 /* if the item is a symlink set the target path and -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp ¶
r76429 r76495 551 551 552 552 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); 556 554 startItem->setPath(startPath); 557 rootItem()->appendChild(startItem);558 555 startItem->setIsOpened(false); 559 556 populateStartDirectory(startItem); … … 576 573 for (int i = 0; i < m_driveLetterList.size(); ++i) 577 574 { 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); 581 576 driveItem->setPath(m_driveLetterList[i]); 582 startItem->appendChild(driveItem);583 577 driveItem->setIsOpened(false); 584 578 driveItem->setIsDriveItem(true); … … 596 590 if (!map.contains(UICustomFileSystemModel::strUpDirectoryString) && !isStartDir) 597 591 { 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); 602 594 item->setIsOpened(false); 603 595 map.insert(UICustomFileSystemModel::strUpDirectoryString, item);
Note:
See TracChangeset
for help on using the changeset viewer.