Skip to content

Commit d2f4b8e

Browse files
committed
Fixed 2915 (GUI: Show files checked in progress bar)
1 parent dc629b4 commit d2f4b8e

6 files changed

Lines changed: 60 additions & 17 deletions

File tree

gui/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,8 @@ ShowTypes;
8888
#define SETTINGS_INCONCLUSIVE_ERRORS "Inconclusive errors"
8989
#define SETTINGS_MRU_PROJECTS "MRU Projects"
9090

91+
// The maximum value for the progress bar
92+
#define PROGRESS_MAX 1024.0
93+
9194
/// @}
9295
#endif

gui/resultsview.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QString>
2626
#include <QModelIndex>
2727
#include <QSettings>
28+
#include "common.h"
2829
#include "erroritem.h"
2930
#include "resultsview.h"
3031
#include "resultstree.h"
@@ -74,13 +75,15 @@ void ResultsView::Clear()
7475
mStatistics->Clear();
7576

7677
//Clear the progressbar
77-
mUI.mProgress->setMaximum(100);
78+
mUI.mProgress->setMaximum(PROGRESS_MAX);
7879
mUI.mProgress->setValue(0);
80+
mUI.mProgress->setFormat(tr("%p%"));
7981
}
8082

81-
void ResultsView::Progress(int value)
83+
void ResultsView::Progress(int value, const QString& description)
8284
{
8385
mUI.mProgress->setValue(value);
86+
mUI.mProgress->setFormat(tr("%p% (%1)").arg(description));
8487
}
8588

8689
void ResultsView::Error(const ErrorItem &item)
@@ -184,12 +187,16 @@ void ResultsView::SetCheckDirectory(const QString &dir)
184187
void ResultsView::CheckingStarted(int count)
185188
{
186189
mUI.mProgress->setVisible(true);
187-
mUI.mProgress->setMaximum(count);
190+
mUI.mProgress->setMaximum(PROGRESS_MAX);
191+
mUI.mProgress->setValue(0);
192+
mUI.mProgress->setFormat(tr("%p% (%1 of %2 files checked)").arg(0).arg(count));
188193
}
189194

190195
void ResultsView::CheckingFinished()
191196
{
192197
mUI.mProgress->setVisible(false);
198+
mUI.mProgress->setFormat("%p%");
199+
193200
//Should we inform user of non visible/not found errors?
194201
if (mShowNoErrorsMessage)
195202
{

gui/resultsview.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ public slots:
173173
* @brief Slot for updating the checking progress
174174
*
175175
* @param value Current progress value
176+
* @param description Description to accompany the progress
176177
*/
177-
void Progress(int value);
178+
void Progress(int value, const QString& description);
178179

179180
/**
180181
* @brief Slot for new error to be displayed
@@ -225,7 +226,6 @@ public slots:
225226

226227
CheckStatistics *mStatistics;
227228

228-
229229
private:
230230
};
231231
/// @}

gui/threadhandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ void ThreadHandler::Stop()
146146
void ThreadHandler::Initialize(ResultsView *view)
147147
{
148148

149-
connect(&mResults, SIGNAL(Progress(int)),
150-
view, SLOT(Progress(int)));
149+
connect(&mResults, SIGNAL(Progress(int, const QString&)),
150+
view, SLOT(Progress(int, const QString&)));
151151

152152
connect(&mResults, SIGNAL(Error(const ErrorItem &)),
153153
view, SLOT(Error(const ErrorItem &)));

gui/threadresult.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
19+
#include <QFile>
2020
#include <QString>
2121
#include <QMutexLocker>
2222
#include <QList>
2323
#include <QStringList>
2424
#include <QDebug>
25+
#include "common.h"
2526
#include "erroritem.h"
2627
#include "errorlogger.h"
2728
#include "threadresult.h"
2829

29-
ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0)
30+
ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0), mFilesChecked(0), mTotalFiles(0)
3031
{
3132
//ctor
3233
}
@@ -44,9 +45,17 @@ void ThreadResult::reportOut(const std::string &outmsg)
4445
void ThreadResult::FileChecked(const QString &file)
4546
{
4647
QMutexLocker locker(&mutex);
47-
Q_UNUSED(file); //For later use maybe?
48-
mProgress++;
49-
emit Progress(mProgress);
48+
49+
mProgress += QFile(file).size();
50+
mFilesChecked ++;
51+
52+
if (mMaxProgress > 0)
53+
{
54+
const int value = static_cast<int>(PROGRESS_MAX * mProgress / mMaxProgress);
55+
const QString description = tr("%1 of %2 files checked").arg(mFilesChecked).arg(mTotalFiles);
56+
57+
emit Progress(value, description);
58+
}
5059
}
5160

5261
void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
@@ -96,13 +105,25 @@ void ThreadResult::SetFiles(const QStringList &files)
96105
QMutexLocker locker(&mutex);
97106
mFiles = files;
98107
mProgress = 0;
99-
mMaxProgress = files.size();
108+
mFilesChecked = 0;
109+
mTotalFiles = files.size();
110+
111+
// Determine the total size of all of the files to check, so that we can
112+
// show an accurate progress estimate
113+
quint64 sizeOfFiles = 0;
114+
foreach(const QString& file, files)
115+
{
116+
sizeOfFiles += QFile(file).size();
117+
}
118+
mMaxProgress = sizeOfFiles;
100119
}
101120

102121
void ThreadResult::ClearFiles()
103122
{
104123
QMutexLocker locker(&mutex);
105124
mFiles.clear();
125+
mFilesChecked = 0;
126+
mTotalFiles = 0;
106127
}
107128

108129
int ThreadResult::GetFileCount()

gui/threadresult.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ public slots:
8383
/**
8484
* @brief Progress signal
8585
* @param value Current progress
86+
* @param description Description of the current stage
8687
*/
87-
void Progress(int value);
88+
void Progress(int value, const QString& description);
8889

8990
/**
9091
* @brief Signal of a new error
@@ -125,14 +126,25 @@ public slots:
125126
* @brief Max progress
126127
*
127128
*/
128-
int mMaxProgress;
129+
quint64 mMaxProgress;
129130

130131
/**
131132
* @brief Current progress
132133
*
133134
*/
134-
int mProgress;
135-
private:
135+
quint64 mProgress;
136+
137+
/**
138+
* @brief Current number of files checked
139+
*
140+
*/
141+
unsigned long mFilesChecked;
142+
143+
/**
144+
* @brief Total number of files
145+
*
146+
*/
147+
unsigned long mTotalFiles;
136148
};
137149
/// @}
138150
#endif // THREADRESULT_H

0 commit comments

Comments
 (0)