Fixed 2915 (GUI: Show files checked in progress bar)

This commit is contained in:
Zachary Blair 2011-07-27 23:30:45 -07:00
parent dc629b4c39
commit d2f4b8e3de
6 changed files with 60 additions and 17 deletions

View File

@ -88,5 +88,8 @@ ShowTypes;
#define SETTINGS_INCONCLUSIVE_ERRORS "Inconclusive errors" #define SETTINGS_INCONCLUSIVE_ERRORS "Inconclusive errors"
#define SETTINGS_MRU_PROJECTS "MRU Projects" #define SETTINGS_MRU_PROJECTS "MRU Projects"
// The maximum value for the progress bar
#define PROGRESS_MAX 1024.0
/// @} /// @}
#endif #endif

View File

@ -25,6 +25,7 @@
#include <QString> #include <QString>
#include <QModelIndex> #include <QModelIndex>
#include <QSettings> #include <QSettings>
#include "common.h"
#include "erroritem.h" #include "erroritem.h"
#include "resultsview.h" #include "resultsview.h"
#include "resultstree.h" #include "resultstree.h"
@ -74,13 +75,15 @@ void ResultsView::Clear()
mStatistics->Clear(); mStatistics->Clear();
//Clear the progressbar //Clear the progressbar
mUI.mProgress->setMaximum(100); mUI.mProgress->setMaximum(PROGRESS_MAX);
mUI.mProgress->setValue(0); 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->setValue(value);
mUI.mProgress->setFormat(tr("%p% (%1)").arg(description));
} }
void ResultsView::Error(const ErrorItem &item) void ResultsView::Error(const ErrorItem &item)
@ -184,12 +187,16 @@ void ResultsView::SetCheckDirectory(const QString &dir)
void ResultsView::CheckingStarted(int count) void ResultsView::CheckingStarted(int count)
{ {
mUI.mProgress->setVisible(true); 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() void ResultsView::CheckingFinished()
{ {
mUI.mProgress->setVisible(false); mUI.mProgress->setVisible(false);
mUI.mProgress->setFormat("%p%");
//Should we inform user of non visible/not found errors? //Should we inform user of non visible/not found errors?
if (mShowNoErrorsMessage) if (mShowNoErrorsMessage)
{ {

View File

@ -173,8 +173,9 @@ public slots:
* @brief Slot for updating the checking progress * @brief Slot for updating the checking progress
* *
* @param value Current progress value * @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 * @brief Slot for new error to be displayed
@ -225,7 +226,6 @@ protected:
CheckStatistics *mStatistics; CheckStatistics *mStatistics;
private: private:
}; };
/// @} /// @}

View File

@ -146,8 +146,8 @@ void ThreadHandler::Stop()
void ThreadHandler::Initialize(ResultsView *view) void ThreadHandler::Initialize(ResultsView *view)
{ {
connect(&mResults, SIGNAL(Progress(int)), connect(&mResults, SIGNAL(Progress(int, const QString&)),
view, SLOT(Progress(int))); view, SLOT(Progress(int, const QString&)));
connect(&mResults, SIGNAL(Error(const ErrorItem &)), connect(&mResults, SIGNAL(Error(const ErrorItem &)),
view, SLOT(Error(const ErrorItem &))); view, SLOT(Error(const ErrorItem &)));

View File

@ -16,17 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QFile>
#include <QString> #include <QString>
#include <QMutexLocker> #include <QMutexLocker>
#include <QList> #include <QList>
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QDebug>
#include "common.h"
#include "erroritem.h" #include "erroritem.h"
#include "errorlogger.h" #include "errorlogger.h"
#include "threadresult.h" #include "threadresult.h"
ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0) ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0), mFilesChecked(0), mTotalFiles(0)
{ {
//ctor //ctor
} }
@ -44,9 +45,17 @@ void ThreadResult::reportOut(const std::string &outmsg)
void ThreadResult::FileChecked(const QString &file) void ThreadResult::FileChecked(const QString &file)
{ {
QMutexLocker locker(&mutex); QMutexLocker locker(&mutex);
Q_UNUSED(file); //For later use maybe?
mProgress++; mProgress += QFile(file).size();
emit Progress(mProgress); mFilesChecked ++;
if (mMaxProgress > 0)
{
const int value = static_cast<int>(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) void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
@ -96,13 +105,25 @@ void ThreadResult::SetFiles(const QStringList &files)
QMutexLocker locker(&mutex); QMutexLocker locker(&mutex);
mFiles = files; mFiles = files;
mProgress = 0; 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() void ThreadResult::ClearFiles()
{ {
QMutexLocker locker(&mutex); QMutexLocker locker(&mutex);
mFiles.clear(); mFiles.clear();
mFilesChecked = 0;
mTotalFiles = 0;
} }
int ThreadResult::GetFileCount() int ThreadResult::GetFileCount()

View File

@ -83,8 +83,9 @@ signals:
/** /**
* @brief Progress signal * @brief Progress signal
* @param value Current progress * @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 * @brief Signal of a new error
@ -125,14 +126,25 @@ protected:
* @brief Max progress * @brief Max progress
* *
*/ */
int mMaxProgress; quint64 mMaxProgress;
/** /**
* @brief Current progress * @brief Current progress
* *
*/ */
int mProgress; quint64 mProgress;
private:
/**
* @brief Current number of files checked
*
*/
unsigned long mFilesChecked;
/**
* @brief Total number of files
*
*/
unsigned long mTotalFiles;
}; };
/// @} /// @}
#endif // THREADRESULT_H #endif // THREADRESULT_H