VirtualBox

Changeset 71563 in vbox


Ignore:
Timestamp:
Mar 29, 2018 11:14:12 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699 Handle property display in case of multiple selections, guest file system variant

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r71508 r71563  
    600600        src/runtime/guestctrl/UIGuestControlFileTable.cpp \
    601601        src/runtime/guestctrl/UIGuestControlWidget.cpp \
     602        src/runtime/guestctrl/UIGuestFileTable.cpp \
    602603        src/runtime/guestctrl/UIHostFileTable.cpp \
    603604        src/selector/UIActionPoolSelector.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp

    r71536 r71563  
    137137
    138138/*********************************************************************************************************************************
     139*   UIHostDirectoryDiskUsageComputer implementation.                                                                             *
     140*********************************************************************************************************************************/
     141
     142UIDirectoryDiskUsageComputer::UIDirectoryDiskUsageComputer(QObject *parent, QStringList pathList)
     143    :QThread(parent)
     144    , m_pathList(pathList)
     145    , m_bContinueRunning(true)
     146{
     147}
     148
     149void UIDirectoryDiskUsageComputer::run()
     150{
     151    for (int i = 0; i < m_pathList.size(); ++i)
     152        directoryStatisticsRecursive(m_pathList[i], m_resultStatistics);
     153}
     154
     155void UIDirectoryDiskUsageComputer::stopRecursion()
     156{
     157    m_mutex.lock();
     158    m_bContinueRunning = false;
     159    m_mutex.unlock();
     160}
     161
     162
     163/*********************************************************************************************************************************
    139164*   UIPathOperations implementation.                                                                                             *
    140165*********************************************************************************************************************************/
     
    668693    , m_pCut(0)
    669694    , m_pPaste(0)
     695    , m_pPropertiesDialog(0)
    670696    , m_pMainLayout(0)
    671697    , m_pLocationComboBox(0)
     
    14321458}
    14331459
     1460void UIGuestControlFileTable::sltReceiveDirectoryStatistics(UIDirectoryStatistics statistics)
     1461{
     1462    if (!m_pPropertiesDialog)
     1463        return;
     1464    m_pPropertiesDialog->addDirectoryStatistics(statistics);
     1465}
    14341466
    14351467#include "UIGuestControlFileTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h

    r71509 r71563  
    2020
    2121/* Qt includes: */
     22# include <QMutex>
     23#include <QThread>
    2224#include <QWidget>
    2325
     
    6769
    6870Q_DECLARE_METATYPE(UIDirectoryStatistics);
     71
     72
     73/** Examines the paths in @p strStartPath and collects some staticstics from them recursively (in case directories)
     74    Runs on a worker thread to avoid GUI freezes. UIGuestFileTable and UIHostFileTable uses specialized children
     75    of this class since the call made on file objects are different */
     76class UIDirectoryDiskUsageComputer : public QThread
     77{
     78    Q_OBJECT;
     79
     80signals:
     81
     82    void sigResultUpdated(UIDirectoryStatistics);
     83
     84public:
     85
     86    UIDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath);
     87    void stopRecursion();
     88
     89protected:
     90
     91    /** Read the directory with the path @p path recursively and collect #of objects and
     92        total size */
     93    virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) = 0;
     94    void                  run();
     95    QStringList           m_pathList;
     96    UIDirectoryStatistics m_resultStatistics;
     97    bool                  m_bContinueRunning;
     98    QMutex                m_mutex;
     99};
     100
    69101
    70102/** A QIDialog child to display properties of a file object */
     
    243275    QAction                 *m_pCut;
    244276    QAction                 *m_pPaste;
    245 
     277    UIPropertiesDialog      *m_pPropertiesDialog;
     278
     279protected slots:
     280
     281    void sltReceiveDirectoryStatistics(UIDirectoryStatistics statictics);
    246282
    247283private slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.cpp

    r71537 r71563  
    3737
    3838#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     39
     40
     41/*********************************************************************************************************************************
     42*   UIGuestDirectoryDiskUsageComputer definition.                                                                                *
     43*********************************************************************************************************************************/
     44
     45/** Open directories recursively and sum the disk usage. Don't block the GUI thread while doing this */
     46class UIGuestDirectoryDiskUsageComputer : public UIDirectoryDiskUsageComputer
     47{
     48    Q_OBJECT;
     49
     50public:
     51
     52    UIGuestDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath, const CGuestSession &session);
     53
     54protected:
     55
     56    virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) /* override */;
     57
     58private:
     59
     60    CGuestSession m_comGuestSession;
     61};
     62
     63
     64/*********************************************************************************************************************************
     65*   UIGuestDirectoryDiskUsageComputer implementation.                                                                            *
     66*********************************************************************************************************************************/
     67
     68UIGuestDirectoryDiskUsageComputer::UIGuestDirectoryDiskUsageComputer(QObject *parent, QStringList pathList, const CGuestSession &session)
     69    :UIDirectoryDiskUsageComputer(parent, pathList)
     70    , m_comGuestSession(session)
     71{
     72}
     73
     74void UIGuestDirectoryDiskUsageComputer::directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics)
     75{
     76    if (m_comGuestSession.isNull())
     77        return;
     78    if (!m_bContinueRunning)
     79        return;
     80    CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(path, true);
     81
     82    if (!m_comGuestSession.isOk())
     83        return;
     84
     85    /* if the object is a file or a symlink then read the size and return: */
     86    if (fileInfo.GetType() == KFsObjType_File)
     87    {
     88        statistics.m_totalSize += fileInfo.GetObjectSize();
     89        ++statistics.m_uFileCount;
     90        sigResultUpdated(statistics);
     91        return;
     92    }
     93    else if (fileInfo.GetType() == KFsObjType_Symlink)
     94    {
     95        statistics.m_totalSize += fileInfo.GetObjectSize();
     96        ++statistics.m_uSymlinkCount;
     97        sigResultUpdated(statistics);
     98        return;
     99    }
     100
     101    if (fileInfo.GetType() != KFsObjType_Directory)
     102        return;
     103    /* Open the directory to start reading its content: */
     104    QVector<KDirectoryOpenFlag> flag(KDirectoryOpenFlag_None);
     105    CGuestDirectory directory = m_comGuestSession.DirectoryOpen(path, /*aFilter*/ "", flag);
     106
     107    if (directory.isOk())
     108    {
     109        CFsObjInfo fsInfo = directory.Read();
     110        while (fsInfo.isOk())
     111        {
     112            if (fsInfo.GetType() == KFsObjType_File)
     113                statistics.m_uFileCount++;
     114            else if (fsInfo.GetType() == KFsObjType_Symlink)
     115                statistics.m_uSymlinkCount++;
     116            else if(fsInfo.GetType() == KFsObjType_Directory)
     117            {
     118                QString dirPath = UIPathOperations::mergePaths(path, fsInfo.GetName());
     119                directoryStatisticsRecursive(dirPath, statistics);
     120            }
     121        }
     122    }
     123    sigResultUpdated(statistics);
     124}
    39125
    40126UIGuestFileTable::UIGuestFileTable(QWidget *pParent /*= 0*/)
     
    290376QString UIGuestFileTable::fsObjectPropertyString()
    291377{
    292     if (m_comGuestSession.isNull())
    293         return QString();
    294 
    295378    QStringList selectedObjects = selectedItemPathList();
    296379    if (selectedObjects.isEmpty())
     
    300383        if (selectedObjects.at(0).isNull())
    301384            return QString();
     385
    302386        CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(selectedObjects.at(0), true);
    303387        if (!m_comGuestSession.isOk())
     
    305389
    306390        QString propertyString;
     391
    307392        /* Name: */
    308393        propertyString += "<b>Name:</b> " + UIPathOperations::getObjectName(fileInfo.GetName()) + "\n";
     
    327412        return propertyString;
    328413    }
    329     return QString();
     414
     415    int fileCount = 0;
     416    int directoryCount = 0;
     417    ULONG64 totalSize = 0;
     418
     419    for(int i = 0; i < selectedObjects.size(); ++i)
     420    {
     421        CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(selectedObjects.at(0), true);
     422        if (!m_comGuestSession.isOk())
     423            continue;
     424        FileObjectType type = fileType(fileInfo);
     425
     426        if (type == FileObjectType_File)
     427            ++fileCount;
     428        if (type == FileObjectType_Directory)
     429            ++directoryCount;
     430        totalSize += fileInfo.GetObjectSize();
     431    }
     432    QString propertyString;
     433    propertyString += "<b>Selected:</b> " + QString::number(fileCount) + " files ";
     434    propertyString += "and " + QString::number(directoryCount) + " directories";
     435    propertyString += "<br/>";
     436    propertyString += "<b>Size:</b> " + QString::number(totalSize) + QString(" bytes");
     437    if (totalSize >= m_iKiloByte)
     438        propertyString += " (" + humanReadableSize(totalSize) + ")";
     439
     440    return propertyString;
    330441}
    331442
    332443void UIGuestFileTable::showProperties()
    333444{
     445    if (m_comGuestSession.isNull())
     446        return;
    334447    QString fsPropertyString = fsObjectPropertyString();
    335448    if (fsPropertyString.isEmpty())
    336449        return;
    337450
    338     UIPropertiesDialog *dialog = new UIPropertiesDialog();
    339     if (!dialog)
    340         return;
    341     dialog->setWindowTitle("Properties");
    342     dialog->setPropertyText(fsPropertyString);
    343     dialog->execute();
    344     delete dialog;
    345 }
     451    delete m_pPropertiesDialog;
     452
     453    m_pPropertiesDialog = new UIPropertiesDialog();
     454    if (!m_pPropertiesDialog)
     455        return;
     456
     457    QStringList selectedObjects = selectedItemPathList();
     458    if (selectedObjects.size() == 0)
     459        return;
     460    UIGuestDirectoryDiskUsageComputer *directoryThread = 0;
     461
     462    /** @todo I have decided to look into this afterwards when API is more mature, for
     463        currently this stuff runs into an assert in Main: */
     464    /* if the selection include a directory or it is a multiple selection the create a worker thread
     465       to compute total size of the selection (recusively) */
     466    // bool createWorkerThread = (selectedObjects.size() > 1);
     467    // if (!createWorkerThread &&
     468    //     fileType(m_comGuestSession.FsObjQueryInfo(selectedObjects[0], true)) == FileObjectType_Directory)
     469    //     createWorkerThread = true;
     470    // if (createWorkerThread)
     471    // {
     472    //     directoryThread = new UIGuestDirectoryDiskUsageComputer(this, selectedObjects, m_comGuestSession);
     473    //     if (directoryThread)
     474    //     {
     475    //         connect(directoryThread, &UIGuestDirectoryDiskUsageComputer::sigResultUpdated,
     476    //                 this, &UIGuestFileTable::sltReceiveDirectoryStatistics/*, Qt::DirectConnection*/);
     477    //         directoryThread->start();
     478    //     }
     479    // }
     480
     481    m_pPropertiesDialog->setWindowTitle("Properties");
     482    m_pPropertiesDialog->setPropertyText(fsPropertyString);
     483    m_pPropertiesDialog->execute();
     484
     485    if (directoryThread)
     486    {
     487        if (directoryThread->isRunning())
     488            directoryThread->stopRecursion();
     489        disconnect(directoryThread, &UIGuestDirectoryDiskUsageComputer::sigResultUpdated,
     490                   this, &UIGuestFileTable::sltReceiveDirectoryStatistics/*, Qt::DirectConnection*/);
     491    }
     492
     493    delete m_pPropertiesDialog;
     494}
     495
     496#include "UIGuestFileTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.h

    r71505 r71563  
    4949    virtual QString fsObjectPropertyString() /* override */;
    5050    virtual void  showProperties() /* override */;
     51
    5152private:
    5253
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.cpp

    r71537 r71563  
    2424# include <QDateTime>
    2525# include <QDir>
    26 # include <QMutex>
    27 # include <QThread>
    2826
    2927/* GUI includes: */
     
    3937
    4038/** Open directories recursively and sum the disk usage. Don't block the GUI thread while doing this */
    41 class UIHostDirectoryDiskUsageComputer : public QThread
     39class UIHostDirectoryDiskUsageComputer : public UIDirectoryDiskUsageComputer
    4240{
    4341    Q_OBJECT;
    4442
    45 signals:
    46 
    47     void sigResultUpdated(UIDirectoryStatistics);
    48 
    4943public:
    5044
    5145    UIHostDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath);
    52     void stopRecursion();
    53 
    54 private:
    55 
    56     /** Read the directory with the path @p path recursively and collect #of objects and
    57         total size */
    58     void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics);
    59     void                  run();
    60     QStringList           m_pathList;
    61     UIDirectoryStatistics m_resultStatistics;
    62     bool                  m_bContinueRunning;
    63     QMutex                m_mutex;
     46
     47protected:
     48
     49    virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) /* override */;
    6450};
    6551
     
    7056
    7157UIHostDirectoryDiskUsageComputer::UIHostDirectoryDiskUsageComputer(QObject *parent, QStringList pathList)
    72     :QThread(parent)
    73     , m_pathList(pathList)
    74     , m_bContinueRunning(true)
    75 {
    76 }
    77 
    78 void UIHostDirectoryDiskUsageComputer::run()
    79 {
    80     for (int i = 0; i < m_pathList.size(); ++i)
    81         directoryStatisticsRecursive(m_pathList[i], m_resultStatistics);
    82 }
    83 
    84 /** @todo Move the following function to a worker thread as it may take atbitrarly long time */
     58    :UIDirectoryDiskUsageComputer(parent, pathList)
     59{
     60}
     61
    8562void UIHostDirectoryDiskUsageComputer::directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics)
    8663{
     
    132109}
    133110
    134 void UIHostDirectoryDiskUsageComputer::stopRecursion()
    135 {
    136     m_mutex.lock();
    137     m_bContinueRunning = false;
    138     m_mutex.unlock();
    139 
    140 }
    141 
    142111
    143112/*********************************************************************************************************************************
     
    147116UIHostFileTable::UIHostFileTable(QWidget *pParent /* = 0 */)
    148117    :UIGuestControlFileTable(pParent)
    149     , m_pPropertiesDialog(0)
    150118{
    151119    initializeFileTree();
     
    369337        return;
    370338
     339    delete m_pPropertiesDialog;
     340
    371341    m_pPropertiesDialog = new UIPropertiesDialog();
    372342    if (!m_pPropertiesDialog)
     
    405375}
    406376
    407 void UIHostFileTable::sltReceiveDirectoryStatistics(UIDirectoryStatistics statistics)
    408 {
    409     if (!m_pPropertiesDialog)
    410         return;
    411     m_pPropertiesDialog->addDirectoryStatistics(statistics);
    412 }
    413 
    414377#include "UIHostFileTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.h

    r71531 r71563  
    4444    virtual void  showProperties() /* override */;
    4545
    46 private slots:
    47 
    48     void sltReceiveDirectoryStatistics(UIDirectoryStatistics statictics);
    49 
    5046private:
    5147
    5248    void prepareActions();
    53 
    54     UIPropertiesDialog *m_pPropertiesDialog;
    5549};
    5650
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