Changeset 71563 in vbox
- Timestamp:
- Mar 29, 2018 11:14:12 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 7 edited
-
Makefile.kmk (modified) (1 diff)
-
src/runtime/guestctrl/UIGuestControlFileTable.cpp (modified) (3 diffs)
-
src/runtime/guestctrl/UIGuestControlFileTable.h (modified) (3 diffs)
-
src/runtime/guestctrl/UIGuestFileTable.cpp (modified) (5 diffs)
-
src/runtime/guestctrl/UIGuestFileTable.h (modified) (1 diff)
-
src/runtime/guestctrl/UIHostFileTable.cpp (modified) (7 diffs)
-
src/runtime/guestctrl/UIHostFileTable.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r71508 r71563 600 600 src/runtime/guestctrl/UIGuestControlFileTable.cpp \ 601 601 src/runtime/guestctrl/UIGuestControlWidget.cpp \ 602 src/runtime/guestctrl/UIGuestFileTable.cpp \ 602 603 src/runtime/guestctrl/UIHostFileTable.cpp \ 603 604 src/selector/UIActionPoolSelector.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp
r71536 r71563 137 137 138 138 /********************************************************************************************************************************* 139 * UIHostDirectoryDiskUsageComputer implementation. * 140 *********************************************************************************************************************************/ 141 142 UIDirectoryDiskUsageComputer::UIDirectoryDiskUsageComputer(QObject *parent, QStringList pathList) 143 :QThread(parent) 144 , m_pathList(pathList) 145 , m_bContinueRunning(true) 146 { 147 } 148 149 void UIDirectoryDiskUsageComputer::run() 150 { 151 for (int i = 0; i < m_pathList.size(); ++i) 152 directoryStatisticsRecursive(m_pathList[i], m_resultStatistics); 153 } 154 155 void UIDirectoryDiskUsageComputer::stopRecursion() 156 { 157 m_mutex.lock(); 158 m_bContinueRunning = false; 159 m_mutex.unlock(); 160 } 161 162 163 /********************************************************************************************************************************* 139 164 * UIPathOperations implementation. * 140 165 *********************************************************************************************************************************/ … … 668 693 , m_pCut(0) 669 694 , m_pPaste(0) 695 , m_pPropertiesDialog(0) 670 696 , m_pMainLayout(0) 671 697 , m_pLocationComboBox(0) … … 1432 1458 } 1433 1459 1460 void UIGuestControlFileTable::sltReceiveDirectoryStatistics(UIDirectoryStatistics statistics) 1461 { 1462 if (!m_pPropertiesDialog) 1463 return; 1464 m_pPropertiesDialog->addDirectoryStatistics(statistics); 1465 } 1434 1466 1435 1467 #include "UIGuestControlFileTable.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h
r71509 r71563 20 20 21 21 /* Qt includes: */ 22 # include <QMutex> 23 #include <QThread> 22 24 #include <QWidget> 23 25 … … 67 69 68 70 Q_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 */ 76 class UIDirectoryDiskUsageComputer : public QThread 77 { 78 Q_OBJECT; 79 80 signals: 81 82 void sigResultUpdated(UIDirectoryStatistics); 83 84 public: 85 86 UIDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath); 87 void stopRecursion(); 88 89 protected: 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 69 101 70 102 /** A QIDialog child to display properties of a file object */ … … 243 275 QAction *m_pCut; 244 276 QAction *m_pPaste; 245 277 UIPropertiesDialog *m_pPropertiesDialog; 278 279 protected slots: 280 281 void sltReceiveDirectoryStatistics(UIDirectoryStatistics statictics); 246 282 247 283 private slots: -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.cpp
r71537 r71563 37 37 38 38 #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 */ 46 class UIGuestDirectoryDiskUsageComputer : public UIDirectoryDiskUsageComputer 47 { 48 Q_OBJECT; 49 50 public: 51 52 UIGuestDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath, const CGuestSession &session); 53 54 protected: 55 56 virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) /* override */; 57 58 private: 59 60 CGuestSession m_comGuestSession; 61 }; 62 63 64 /********************************************************************************************************************************* 65 * UIGuestDirectoryDiskUsageComputer implementation. * 66 *********************************************************************************************************************************/ 67 68 UIGuestDirectoryDiskUsageComputer::UIGuestDirectoryDiskUsageComputer(QObject *parent, QStringList pathList, const CGuestSession &session) 69 :UIDirectoryDiskUsageComputer(parent, pathList) 70 , m_comGuestSession(session) 71 { 72 } 73 74 void 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 } 39 125 40 126 UIGuestFileTable::UIGuestFileTable(QWidget *pParent /*= 0*/) … … 290 376 QString UIGuestFileTable::fsObjectPropertyString() 291 377 { 292 if (m_comGuestSession.isNull())293 return QString();294 295 378 QStringList selectedObjects = selectedItemPathList(); 296 379 if (selectedObjects.isEmpty()) … … 300 383 if (selectedObjects.at(0).isNull()) 301 384 return QString(); 385 302 386 CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(selectedObjects.at(0), true); 303 387 if (!m_comGuestSession.isOk()) … … 305 389 306 390 QString propertyString; 391 307 392 /* Name: */ 308 393 propertyString += "<b>Name:</b> " + UIPathOperations::getObjectName(fileInfo.GetName()) + "\n"; … … 327 412 return propertyString; 328 413 } 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; 330 441 } 331 442 332 443 void UIGuestFileTable::showProperties() 333 444 { 445 if (m_comGuestSession.isNull()) 446 return; 334 447 QString fsPropertyString = fsObjectPropertyString(); 335 448 if (fsPropertyString.isEmpty()) 336 449 return; 337 450 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 49 49 virtual QString fsObjectPropertyString() /* override */; 50 50 virtual void showProperties() /* override */; 51 51 52 private: 52 53 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.cpp
r71537 r71563 24 24 # include <QDateTime> 25 25 # include <QDir> 26 # include <QMutex>27 # include <QThread>28 26 29 27 /* GUI includes: */ … … 39 37 40 38 /** Open directories recursively and sum the disk usage. Don't block the GUI thread while doing this */ 41 class UIHostDirectoryDiskUsageComputer : public QThread39 class UIHostDirectoryDiskUsageComputer : public UIDirectoryDiskUsageComputer 42 40 { 43 41 Q_OBJECT; 44 42 45 signals:46 47 void sigResultUpdated(UIDirectoryStatistics);48 49 43 public: 50 44 51 45 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 47 protected: 48 49 virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) /* override */; 64 50 }; 65 51 … … 70 56 71 57 UIHostDirectoryDiskUsageComputer::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 85 62 void UIHostDirectoryDiskUsageComputer::directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) 86 63 { … … 132 109 } 133 110 134 void UIHostDirectoryDiskUsageComputer::stopRecursion()135 {136 m_mutex.lock();137 m_bContinueRunning = false;138 m_mutex.unlock();139 140 }141 142 111 143 112 /********************************************************************************************************************************* … … 147 116 UIHostFileTable::UIHostFileTable(QWidget *pParent /* = 0 */) 148 117 :UIGuestControlFileTable(pParent) 149 , m_pPropertiesDialog(0)150 118 { 151 119 initializeFileTree(); … … 369 337 return; 370 338 339 delete m_pPropertiesDialog; 340 371 341 m_pPropertiesDialog = new UIPropertiesDialog(); 372 342 if (!m_pPropertiesDialog) … … 405 375 } 406 376 407 void UIHostFileTable::sltReceiveDirectoryStatistics(UIDirectoryStatistics statistics)408 {409 if (!m_pPropertiesDialog)410 return;411 m_pPropertiesDialog->addDirectoryStatistics(statistics);412 }413 414 377 #include "UIHostFileTable.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.h
r71531 r71563 44 44 virtual void showProperties() /* override */; 45 45 46 private slots:47 48 void sltReceiveDirectoryStatistics(UIDirectoryStatistics statictics);49 50 46 private: 51 47 52 48 void prepareActions(); 53 54 UIPropertiesDialog *m_pPropertiesDialog;55 49 }; 56 50
Note:
See TracChangeset
for help on using the changeset viewer.

