From d2f4b8e3deed13f4874ab969b1cc6b5e6768537e Mon Sep 17 00:00:00 2001 From: Zachary Blair Date: Wed, 27 Jul 2011 23:30:45 -0700 Subject: [PATCH] Fixed 2915 (GUI: Show files checked in progress bar) --- gui/common.h | 3 +++ gui/resultsview.cpp | 13 ++++++++++--- gui/resultsview.h | 4 ++-- gui/threadhandler.cpp | 4 ++-- gui/threadresult.cpp | 33 +++++++++++++++++++++++++++------ gui/threadresult.h | 20 ++++++++++++++++---- 6 files changed, 60 insertions(+), 17 deletions(-) diff --git a/gui/common.h b/gui/common.h index 4d414cd6b..292bc4174 100644 --- a/gui/common.h +++ b/gui/common.h @@ -88,5 +88,8 @@ ShowTypes; #define SETTINGS_INCONCLUSIVE_ERRORS "Inconclusive errors" #define SETTINGS_MRU_PROJECTS "MRU Projects" +// The maximum value for the progress bar +#define PROGRESS_MAX 1024.0 + /// @} #endif diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 3641a646e..e22d65d90 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "common.h" #include "erroritem.h" #include "resultsview.h" #include "resultstree.h" @@ -74,13 +75,15 @@ void ResultsView::Clear() mStatistics->Clear(); //Clear the progressbar - mUI.mProgress->setMaximum(100); + mUI.mProgress->setMaximum(PROGRESS_MAX); mUI.mProgress->setValue(0); + mUI.mProgress->setFormat(tr("%p%")); } -void ResultsView::Progress(int value) +void ResultsView::Progress(int value, const QString& description) { mUI.mProgress->setValue(value); + mUI.mProgress->setFormat(tr("%p% (%1)").arg(description)); } void ResultsView::Error(const ErrorItem &item) @@ -184,12 +187,16 @@ void ResultsView::SetCheckDirectory(const QString &dir) void ResultsView::CheckingStarted(int count) { mUI.mProgress->setVisible(true); - mUI.mProgress->setMaximum(count); + mUI.mProgress->setMaximum(PROGRESS_MAX); + mUI.mProgress->setValue(0); + mUI.mProgress->setFormat(tr("%p% (%1 of %2 files checked)").arg(0).arg(count)); } void ResultsView::CheckingFinished() { mUI.mProgress->setVisible(false); + mUI.mProgress->setFormat("%p%"); + //Should we inform user of non visible/not found errors? if (mShowNoErrorsMessage) { diff --git a/gui/resultsview.h b/gui/resultsview.h index 1bcee5fab..068e08062 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -173,8 +173,9 @@ public slots: * @brief Slot for updating the checking progress * * @param value Current progress value + * @param description Description to accompany the progress */ - void Progress(int value); + void Progress(int value, const QString& description); /** * @brief Slot for new error to be displayed @@ -225,7 +226,6 @@ protected: CheckStatistics *mStatistics; - private: }; /// @} diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 05529a544..185d57cdb 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -146,8 +146,8 @@ void ThreadHandler::Stop() void ThreadHandler::Initialize(ResultsView *view) { - connect(&mResults, SIGNAL(Progress(int)), - view, SLOT(Progress(int))); + connect(&mResults, SIGNAL(Progress(int, const QString&)), + view, SLOT(Progress(int, const QString&))); connect(&mResults, SIGNAL(Error(const ErrorItem &)), view, SLOT(Error(const ErrorItem &))); diff --git a/gui/threadresult.cpp b/gui/threadresult.cpp index dc1545800..7fe32ca0f 100644 --- a/gui/threadresult.cpp +++ b/gui/threadresult.cpp @@ -16,17 +16,18 @@ * along with this program. If not, see . */ - +#include #include #include #include #include #include +#include "common.h" #include "erroritem.h" #include "errorlogger.h" #include "threadresult.h" -ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0) +ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0), mFilesChecked(0), mTotalFiles(0) { //ctor } @@ -44,9 +45,17 @@ void ThreadResult::reportOut(const std::string &outmsg) void ThreadResult::FileChecked(const QString &file) { QMutexLocker locker(&mutex); - Q_UNUSED(file); //For later use maybe? - mProgress++; - emit Progress(mProgress); + + mProgress += QFile(file).size(); + mFilesChecked ++; + + if (mMaxProgress > 0) + { + const int value = static_cast(PROGRESS_MAX * mProgress / mMaxProgress); + const QString description = tr("%1 of %2 files checked").arg(mFilesChecked).arg(mTotalFiles); + + emit Progress(value, description); + } } void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg) @@ -96,13 +105,25 @@ void ThreadResult::SetFiles(const QStringList &files) QMutexLocker locker(&mutex); mFiles = files; mProgress = 0; - mMaxProgress = files.size(); + mFilesChecked = 0; + mTotalFiles = files.size(); + + // Determine the total size of all of the files to check, so that we can + // show an accurate progress estimate + quint64 sizeOfFiles = 0; + foreach(const QString& file, files) + { + sizeOfFiles += QFile(file).size(); + } + mMaxProgress = sizeOfFiles; } void ThreadResult::ClearFiles() { QMutexLocker locker(&mutex); mFiles.clear(); + mFilesChecked = 0; + mTotalFiles = 0; } int ThreadResult::GetFileCount() diff --git a/gui/threadresult.h b/gui/threadresult.h index a091ffdaa..5b4cdbd63 100644 --- a/gui/threadresult.h +++ b/gui/threadresult.h @@ -83,8 +83,9 @@ signals: /** * @brief Progress signal * @param value Current progress + * @param description Description of the current stage */ - void Progress(int value); + void Progress(int value, const QString& description); /** * @brief Signal of a new error @@ -125,14 +126,25 @@ protected: * @brief Max progress * */ - int mMaxProgress; + quint64 mMaxProgress; /** * @brief Current progress * */ - int mProgress; -private: + quint64 mProgress; + + /** + * @brief Current number of files checked + * + */ + unsigned long mFilesChecked; + + /** + * @brief Total number of files + * + */ + unsigned long mTotalFiles; }; /// @} #endif // THREADRESULT_H