<commit_before>#include "image-loader.h"
#include <QUuid>
#include <utility>
#include "downloader/image-downloader.h"
#include "models/filename.h"
#include "models/image.h"
#include "models/profile.h"


ImageLoader::ImageLoader(QObject *parent)
	: QObject(parent), m_size(Size::Full), m_automatic(true), m_status(Status::Null), m_progress(0)
{}


QSharedPointer<Image> ImageLoader::image() const
{
	return m_image;
}
void ImageLoader::setImage(QSharedPointer<Image> image)
{
	m_image = std::move(image);
	emit imageChanged();

	if (!m_image.isNull() && m_automatic) {
		load();
	}
}

ImageLoader::Size ImageLoader::size() const
{
	return m_size;
}
void ImageLoader::setSize(ImageLoader::Size size)
{
	m_size = size;
	emit sizeChanged();
}

bool ImageLoader::automatic() const
{
	return m_automatic;
}
void ImageLoader::setAutomatic(bool automatic)
{
	m_automatic = automatic;
	emit automaticChanged();
}

qreal ImageLoader::progress() const
{
	return m_progress;
}
ImageLoader::Status ImageLoader::status() const
{
	return m_status;
}
QString ImageLoader::error() const
{
	return m_error;
}

QString ImageLoader::source() const
{
	return m_source;
}
void ImageLoader::setSource(QString source)
{
	m_source = source;
	emit sourceChanged();
}


void ImageLoader::load()
{
	m_status = Status::Loading;
	m_error = QString();
	emit statusChanged();
	emit errorChanged();

	static const  QMap<Size, QString> sizeToString = {
		{ Size::Full, QStringLiteral("full") },
		{ Size::Sample, QStringLiteral("sample") },
		{ Size::Thumbnail, QStringLiteral("thumb") }
	};

	Profile *profile = m_image->getProfile();
	const Filename fn = Filename(sizeToString[m_size] + "_" + QUuid::createUuid().toString().mid(1, 36) + ".%ext%");
	const QStringList paths = fn.path(*m_image.data(), profile, profile->tempPath(), 1, Filename::ExpandConditionals | Filename::Path);

	auto downloader = new ImageDownloader(profile, m_image, paths, 1, false, false, this, false, false, imageSize(), false, false);
	connect(downloader, &ImageDownloader::downloadProgress, this, &ImageLoader::downloadProgress);
	connect(downloader, &ImageDownloader::saved, this, &ImageLoader::saved);
	connect(downloader, &ImageDownloader::saved, downloader, &ImageDownloader::deleteLater);
	downloader->save();
}

void ImageLoader::downloadProgress(const QSharedPointer<Image> &img, qint64 v1, qint64 v2)
{
	Q_UNUSED(img);
<commit_msg>Fix minor style issue<commit_after>#include "image-loader.h"
#include <QUuid>
#include <utility>
#include "downloader/image-downloader.h"
#include "models/filename.h"
#include "models/image.h"
#include "models/profile.h"


ImageLoader::ImageLoader(QObject *parent)
	: QObject(parent), m_size(Size::Full), m_automatic(true), m_status(Status::Null), m_progress(0)
{}


QSharedPointer<Image> ImageLoader::image() const
{
	return m_image;
}
void ImageLoader::setImage(QSharedPointer<Image> image)
{
	m_image = std::move(image);
	emit imageChanged();

	if (!m_image.isNull() && m_automatic) {
		load();
	}
}

ImageLoader::Size ImageLoader::size() const
{
	return m_size;
}
void ImageLoader::setSize(ImageLoader::Size size)
{
	m_size = size;
	emit sizeChanged();
}

bool ImageLoader::automatic() const
{
	return m_automatic;
}
void ImageLoader::setAutomatic(bool automatic)
{
	m_automatic = automatic;
	emit automaticChanged();
}

qreal ImageLoader::progress() const
{
	return m_progress;
}
ImageLoader::Status ImageLoader::status() const
{
	return m_status;
}
QString ImageLoader::error() const
{
	return m_error;
}

QString ImageLoader::source() const
{
	return m_source;
}
void ImageLoader::setSource(QString source)
{
	m_source = source;
	emit sourceChanged();
}


void ImageLoader::load()
{
	m_status = Status::Loading;
	m_error = QString();
	emit statusChanged();
	emit errorChanged();

	static const QMap<Size, QString> sizeToString = {
		{ Size::Full, QStringLiteral("full") },
		{ Size::Sample, QStringLiteral("sample") },
		{ Size::Thumbnail, QStringLiteral("thumb") }
	};

	Profile *profile = m_image->getProfile();
	const Filename fn = Filename(sizeToString[m_size] + "_" + QUuid::createUuid().toString().mid(1, 36) + ".%ext%");
	const QStringList paths = fn.path(*m_image.data(), profile, profile->tempPath(), 1, Filename::ExpandConditionals | Filename::Path);

	auto downloader = new ImageDownloader(profile, m_image, paths, 1, false, false, this, false, false, imageSize(), false, false);
	connect(downloader, &ImageDownloader::downloadProgress, this, &ImageLoader::downloadProgress);
	connect(downloader, &ImageDownloader::saved, this, &ImageLoader::saved);
	connect(downloader, &ImageDownloader::saved, downloader, &ImageDownloader::deleteLater);
	downloader->save();
}

void ImageLoader::downloadProgress(const QSharedPointer<Image> &img, qint64 v1, qint64 v2)
{
	Q_UNUSED(img);

{'fraction_non_alphanumeric': 0.1524607329842932, 'fraction_numerical': 0.005026178010471204, 'mean_word_length': 7.026890756302521, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '500678', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1574, 'n_words': 333}