refactor: Toast (#4899)

* Fixes a bug where avatars weren't loaded on fresh installations of Chatterino.
* Avatars now update every two weeks.
* Removes misleading `DownlaodManager` (now part of `Toasts.cpp`).
* Refactors usage of WinToast to be easier to read.
* Added version to AUMI.
* Removes manual `QString` → `std::wstring` conversions.
* Removes uses of implicit ASCII casts in `Toasts.cpp`, meaning it can be compiled with `QT_NO_CAST_FROM_ASCII`.
This commit is contained in:
nerix
2023-10-17 03:50:18 +02:00
committed by GitHub
parent bddc08abd0
commit b975900043
9 changed files with 186 additions and 210 deletions
-83
View File
@@ -1,83 +0,0 @@
#include "DownloadManager.hpp"
#include "common/QLogging.hpp"
#include "singletons/Paths.hpp"
#include <QDesktopServices>
namespace chatterino {
DownloadManager::DownloadManager(QObject *parent)
: QObject(parent)
, manager_(new QNetworkAccessManager)
{
}
DownloadManager::~DownloadManager()
{
this->manager_->deleteLater();
}
void DownloadManager::setFile(QString fileURL, const QString &channelName)
{
QString saveFilePath;
saveFilePath =
getPaths()->twitchProfileAvatars + "/twitch/" + channelName + ".png";
QNetworkRequest request;
request.setUrl(QUrl(fileURL));
this->reply_ = this->manager_->get(request);
this->file_ = new QFile;
this->file_->setFileName(saveFilePath);
this->file_->open(QIODevice::WriteOnly);
connect(this->reply_, SIGNAL(downloadProgress(qint64, qint64)), this,
SLOT(onDownloadProgress(qint64, qint64)));
connect(this->manager_, SIGNAL(finished(QNetworkReply *)), this,
SLOT(onFinished(QNetworkReply *)));
connect(this->reply_, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(this->reply_, SIGNAL(finished()), this, SLOT(onReplyFinished()));
}
void DownloadManager::onDownloadProgress(qint64 bytesRead, qint64 bytesTotal)
{
qCDebug(chatterinoCommon)
<< "Download progress: " << bytesRead << "/" << bytesTotal;
}
void DownloadManager::onFinished(QNetworkReply *reply)
{
switch (reply->error())
{
case QNetworkReply::NoError: {
qCDebug(chatterinoCommon) << "file is downloaded successfully.";
}
break;
default: {
qCDebug(chatterinoCommon) << reply->errorString().toLatin1();
};
}
if (this->file_->isOpen())
{
this->file_->close();
this->file_->deleteLater();
}
emit downloadComplete();
}
void DownloadManager::onReadyRead()
{
this->file_->write(this->reply_->readAll());
}
void DownloadManager::onReplyFinished()
{
if (this->file_->isOpen())
{
this->file_->close();
this->file_->deleteLater();
}
}
} // namespace chatterino
-33
View File
@@ -1,33 +0,0 @@
#pragma once
#include <QFile>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QObject>
namespace chatterino {
class DownloadManager : public QObject
{
Q_OBJECT
public:
explicit DownloadManager(QObject *parent = nullptr);
virtual ~DownloadManager();
void setFile(QString fileURL, const QString &channelName);
private:
QNetworkAccessManager *manager_;
QNetworkReply *reply_{};
QFile *file_{};
private slots:
void onDownloadProgress(qint64, qint64);
void onFinished(QNetworkReply *);
void onReadyRead();
void onReplyFinished();
signals:
void downloadComplete();
};
} // namespace chatterino