2009-03-01 21:44:42 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-01-28 10:16:34 +01:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2009-03-01 21:44:42 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-03-01 21:44:42 +01:00
|
|
|
*/
|
|
|
|
|
2021-04-03 21:30:50 +02:00
|
|
|
#include "threadresult.h"
|
|
|
|
|
2011-07-28 08:30:45 +02:00
|
|
|
#include "common.h"
|
2010-07-14 13:24:46 +02:00
|
|
|
#include "erroritem.h"
|
2010-10-31 12:16:55 +01:00
|
|
|
#include "errorlogger.h"
|
2022-04-13 12:24:00 +02:00
|
|
|
#include "errortypes.h"
|
2009-03-01 21:44:42 +01:00
|
|
|
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <numeric>
|
|
|
|
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QFile>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QMutexLocker>
|
2022-02-02 16:17:28 +01:00
|
|
|
|
2009-03-01 21:44:42 +01:00
|
|
|
ThreadResult::~ThreadResult()
|
|
|
|
{
|
|
|
|
//dtor
|
|
|
|
}
|
|
|
|
|
2022-09-27 20:03:25 +02:00
|
|
|
void ThreadResult::reportOut(const std::string &outmsg, Color /*c*/)
|
2009-03-01 21:44:42 +01:00
|
|
|
{
|
2017-07-28 12:39:28 +02:00
|
|
|
emit log(QString::fromStdString(outmsg));
|
2009-03-01 21:44:42 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:39:28 +02:00
|
|
|
void ThreadResult::fileChecked(const QString &file)
|
2009-03-02 20:56:51 +01:00
|
|
|
{
|
2009-06-09 08:30:28 +02:00
|
|
|
QMutexLocker locker(&mutex);
|
2011-07-28 08:30:45 +02:00
|
|
|
|
|
|
|
mProgress += QFile(file).size();
|
2021-08-07 20:51:18 +02:00
|
|
|
mFilesChecked++;
|
2011-07-28 08:30:45 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mMaxProgress > 0) {
|
2011-07-28 08:30:45 +02:00
|
|
|
const int value = static_cast<int>(PROGRESS_MAX * mProgress / mMaxProgress);
|
|
|
|
const QString description = tr("%1 of %2 files checked").arg(mFilesChecked).arg(mTotalFiles);
|
|
|
|
|
2017-07-28 12:39:28 +02:00
|
|
|
emit progress(value, description);
|
2011-07-28 08:30:45 +02:00
|
|
|
}
|
2009-03-02 20:56:51 +01:00
|
|
|
}
|
|
|
|
|
2020-05-23 07:16:49 +02:00
|
|
|
void ThreadResult::reportErr(const ErrorMessage &msg)
|
2009-03-01 21:44:42 +01:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
2017-05-21 08:25:55 +02:00
|
|
|
const ErrorItem item(msg);
|
2019-08-18 12:19:05 +02:00
|
|
|
if (msg.severity != Severity::debug)
|
2017-07-28 12:39:28 +02:00
|
|
|
emit error(item);
|
2010-08-28 19:37:21 +02:00
|
|
|
else
|
2017-07-28 12:39:28 +02:00
|
|
|
emit debugError(item);
|
2009-03-01 21:44:42 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:39:28 +02:00
|
|
|
QString ThreadResult::getNextFile()
|
2009-03-01 21:44:42 +01:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
2013-01-16 15:37:07 +01:00
|
|
|
if (mFiles.isEmpty()) {
|
2017-08-03 12:39:31 +02:00
|
|
|
return QString();
|
2009-03-01 21:44:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return mFiles.takeFirst();
|
|
|
|
}
|
|
|
|
|
2017-07-28 12:39:28 +02:00
|
|
|
ImportProject::FileSettings ThreadResult::getNextFileSettings()
|
2016-08-18 21:58:50 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
if (mFileSettings.empty()) {
|
|
|
|
return ImportProject::FileSettings();
|
|
|
|
}
|
|
|
|
const ImportProject::FileSettings fs = mFileSettings.front();
|
|
|
|
mFileSettings.pop_front();
|
|
|
|
return fs;
|
|
|
|
}
|
|
|
|
|
2017-07-28 12:39:28 +02:00
|
|
|
void ThreadResult::setFiles(const QStringList &files)
|
2009-03-01 21:44:42 +01:00
|
|
|
{
|
2009-03-02 20:56:51 +01:00
|
|
|
QMutexLocker locker(&mutex);
|
2009-03-01 21:44:42 +01:00
|
|
|
mFiles = files;
|
|
|
|
mProgress = 0;
|
2011-07-28 08:30:45 +02:00
|
|
|
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
|
2023-03-21 18:16:40 +01:00
|
|
|
quint64 sizeOfFiles = std::accumulate(files.begin(), files.end(), 0, [](quint64 total, const QString& file) {
|
|
|
|
return total + QFile(file).size();
|
|
|
|
});
|
2011-07-28 08:30:45 +02:00
|
|
|
mMaxProgress = sizeOfFiles;
|
2009-03-01 21:44:42 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:39:28 +02:00
|
|
|
void ThreadResult::setProject(const ImportProject &prj)
|
2016-08-18 21:58:50 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
mFiles.clear();
|
|
|
|
mFileSettings = prj.fileSettings;
|
|
|
|
mProgress = 0;
|
|
|
|
mFilesChecked = 0;
|
|
|
|
mTotalFiles = prj.fileSettings.size();
|
|
|
|
|
|
|
|
// Determine the total size of all of the files to check, so that we can
|
|
|
|
// show an accurate progress estimate
|
2023-03-04 11:58:12 +01:00
|
|
|
mMaxProgress = std::accumulate(prj.fileSettings.begin(), prj.fileSettings.end(), quint64{ 0 }, [](quint64 v, const ImportProject::FileSettings& fs) {
|
|
|
|
return v + QFile(QString::fromStdString(fs.filename)).size();
|
|
|
|
});
|
2016-08-18 21:58:50 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:39:28 +02:00
|
|
|
void ThreadResult::clearFiles()
|
2009-03-01 21:44:42 +01:00
|
|
|
{
|
2009-03-02 20:56:51 +01:00
|
|
|
QMutexLocker locker(&mutex);
|
2009-03-01 21:44:42 +01:00
|
|
|
mFiles.clear();
|
2016-08-18 21:58:50 +02:00
|
|
|
mFileSettings.clear();
|
2011-07-28 08:30:45 +02:00
|
|
|
mFilesChecked = 0;
|
|
|
|
mTotalFiles = 0;
|
2009-03-01 21:44:42 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:39:28 +02:00
|
|
|
int ThreadResult::getFileCount() const
|
2009-03-01 21:44:42 +01:00
|
|
|
{
|
2009-03-02 20:56:51 +01:00
|
|
|
QMutexLocker locker(&mutex);
|
2016-08-18 21:58:50 +02:00
|
|
|
return mFiles.size() + mFileSettings.size();
|
2009-03-01 21:44:42 +01:00
|
|
|
}
|