VirtualBox

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


Ignore:
Timestamp:
Mar 20, 2018 4:27:18 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699 Recursively compute file object statistics for directories (for host)

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

Legend:

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

    r71388 r71412  
    13331333}
    13341334
     1335QString UIGuestControlFileTable::humanReadableSize(ULONG64 size)
     1336{
     1337    int i = 0;
     1338    double dSize = size;
     1339    const char* units[] = {" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"};
     1340    while (size > 1024) {
     1341        size /= 1024;
     1342        dSize /= (double)1024;
     1343        i++;
     1344    }
     1345    if (i > 8)
     1346        return QString();
     1347
     1348    QString strResult(QString::number(dSize, 'f', 2));
     1349    strResult += units[i];
     1350    return strResult;
     1351}
     1352
     1353
    13351354#include "UIGuestControlFileTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h

    r71388 r71412  
    182182    void keyPressEvent(QKeyEvent * pEvent);
    183183    CGuestFsObjInfo guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const;
    184 
     184    static QString humanReadableSize(ULONG64 size);
    185185
    186186    UIFileTableItem         *m_pRootItem;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.cpp

    r71391 r71412  
    148148        return;
    149149
    150     QString userHome = UIPathOperations::sanitize(m_comGuestSession.GetUserHome());
     150    QString userHome = UIPathOperations::sanitize(m_comGuestSession.GetUserHome()).remove(0,1);
     151
    151152    QList<QString> pathTrail = userHome.split(UIPathOperations::delimiter);
    152153
     
    306307        propertyString += "<br/>";
    307308        /* Size: */
    308         propertyString += "<b>Size:</b> " + QString::number(fileInfo.GetObjectSize()) + QString(" bytes");
     309        LONG64 size = fileInfo.GetObjectSize();
     310        propertyString += "<b>Size:</b> " + QString::number(size) + QString(" bytes");
     311        if (size >= 1024)
     312            propertyString += " (" + humanReadableSize(size) + ")";
    309313        propertyString += "<br/>";
    310314        /* Type: */
     
    312316        propertyString += "<br/>";
    313317        /* Creation Date: */
    314         //     LONG64 GetChangeTime() const;
    315318        propertyString += "<b>Created:</b> " + QDateTime::fromMSecsSinceEpoch(fileInfo.GetChangeTime()/1000000).toString();
    316319        propertyString += "<br/>";
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.cpp

    r71388 r71412  
    194194        /* Size: */
    195195        propertyString += "<b>Size:</b> " + QString::number(fileInfo.size()) + QString(" bytes");
     196        if (fileInfo.size() >= 1024)
     197            propertyString += " (" + humanReadableSize(fileInfo.size()) + ")";
    196198        propertyString += "<br/>";
    197199        /* Type: */
     
    207209        propertyString += "<b>Owner:</b> " + fileInfo.owner();
    208210
    209 
     211        if (fileInfo.isDir())
     212            directoryStatisticsRecursive(fileInfo.absoluteFilePath());
    210213        return propertyString;
    211214    }
    212215    return QString();
    213216}
     217
     218void UIHostFileTable::directoryStatisticsRecursive(const QString &path)
     219{
     220    QDir dir(path);
     221    if (!dir.exists())
     222        return;
     223
     224    QFileInfoList entryList = dir.entryInfoList();
     225    for (int i = 0; i < entryList.size(); ++i)
     226    {
     227
     228        const QFileInfo &entryInfo = entryList.at(i);
     229        if (entryInfo.baseName().isEmpty() || entryInfo.baseName() == "." || entryInfo.baseName() == "..")
     230            continue;
     231
     232        if (entryInfo.isSymLink())
     233            continue;
     234        if (entryInfo.isDir())
     235        {
     236            directoryStatisticsRecursive(entryInfo.absoluteFilePath());
     237        }
     238    }
     239}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.h

    r71388 r71412  
    4343    virtual QString fsObjectPropertyString() /* override */;
    4444
     45private:
     46
     47    /** Read the directory with the path @p path recursively and collect #of objects and
     48        total size */
     49    void directoryStatisticsRecursive(const QString &path);
     50
    4551};
    4652
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