NOISSUE continue refactoring things to make tests pass

This commit is contained in:
Petr Mrázek
2021-11-21 23:21:12 +01:00
parent c2c56a2f6c
commit 69213b1206
103 changed files with 634 additions and 773 deletions

View File

@ -5,18 +5,18 @@
#include <QJsonObject>
#include <QUrl>
#include <QStringList>
#include "BuildConfig.h"
#include "Env.h"
#include <QDebug>
ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots)
#include "BuildConfig.h"
#include "Application.h"
ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenShot::Ptr> screenshots) : NetAction(), m_screenshots(screenshots)
{
m_url = BuildConfig.IMGUR_BASE_URL + "album.json";
m_status = Job_NotStarted;
}
void ImgurAlbumCreation::start()
void ImgurAlbumCreation::startImpl()
{
m_status = Job_InProgress;
QNetworkRequest request(m_url);
@ -33,7 +33,7 @@ void ImgurAlbumCreation::start()
const QByteArray data = "deletehashes=" + hashes.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden";
QNetworkReply *rep = ENV->network().post(request, data);
QNetworkReply *rep = APPLICATION->network()->post(request, data);
m_reply.reset(rep);
connect(rep, &QNetworkReply::uploadProgress, this, &ImgurAlbumCreation::downloadProgress);

View File

@ -1,13 +1,14 @@
#pragma once
#include "net/NetAction.h"
#include "Screenshot.h"
#include "QObjectPtr.h"
typedef std::shared_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr;
typedef shared_qobject_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr;
class ImgurAlbumCreation : public NetAction
{
public:
explicit ImgurAlbumCreation(QList<ScreenshotPtr> screenshots);
static ImgurAlbumCreationPtr make(QList<ScreenshotPtr> screenshots)
explicit ImgurAlbumCreation(QList<ScreenShot::Ptr> screenshots);
static ImgurAlbumCreationPtr make(QList<ScreenShot::Ptr> screenshots)
{
return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots));
}
@ -32,10 +33,10 @@ slots:
public
slots:
virtual void start();
virtual void startImpl();
private:
QList<ScreenshotPtr> m_screenshots;
QList<ScreenShot::Ptr> m_screenshots;
QString m_deleteHash;
QString m_id;

View File

@ -1,4 +1,5 @@
#include "ImgurUpload.h"
#include "BuildConfig.h"
#include <QNetworkRequest>
#include <QHttpMultiPart>
@ -7,18 +8,15 @@
#include <QHttpPart>
#include <QFile>
#include <QUrl>
#include "BuildConfig.h"
#include "Env.h"
#include <QDebug>
ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot)
ImgurUpload::ImgurUpload(ScreenShot::Ptr shot) : NetAction(), m_shot(shot)
{
m_url = BuildConfig.IMGUR_BASE_URL + "upload.json";
m_status = Job_NotStarted;
}
void ImgurUpload::start()
void ImgurUpload::startImpl()
{
finished = false;
m_status = Job_InProgress;
@ -49,7 +47,7 @@ void ImgurUpload::start()
namePart.setBody(m_shot->m_file.baseName().toUtf8());
multipart->append(namePart);
QNetworkReply *rep = ENV->network().post(request, multipart);
QNetworkReply *rep = m_network->post(request, multipart);
m_reply.reset(rep);
connect(rep, &QNetworkReply::uploadProgress, this, &ImgurUpload::downloadProgress);

View File

@ -1,15 +1,15 @@
#pragma once
#include "QObjectPtr.h"
#include "net/NetAction.h"
#include "Screenshot.h"
typedef std::shared_ptr<class ImgurUpload> ImgurUploadPtr;
class ImgurUpload : public NetAction
{
class ImgurUpload : public NetAction {
public:
explicit ImgurUpload(ScreenshotPtr shot);
static ImgurUploadPtr make(ScreenshotPtr shot)
{
return ImgurUploadPtr(new ImgurUpload(shot));
using Ptr = shared_qobject_ptr<ImgurUpload>;
explicit ImgurUpload(ScreenShot::Ptr shot);
static Ptr make(ScreenShot::Ptr shot) {
return Ptr(new ImgurUpload(shot));
}
protected
@ -17,15 +17,13 @@ slots:
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
virtual void downloadError(QNetworkReply::NetworkError error);
virtual void downloadFinished();
virtual void downloadReadyRead()
{
}
virtual void downloadReadyRead() {}
public
slots:
virtual void start();
void startImpl() override;
private:
ScreenshotPtr m_shot;
ScreenShot::Ptr m_shot;
bool finished = true;
};

View File

@ -5,10 +5,10 @@
#include <QFileInfo>
#include <memory>
struct ScreenShot
{
ScreenShot(QFileInfo file)
{
struct ScreenShot {
using Ptr = std::shared_ptr<ScreenShot>;
ScreenShot(QFileInfo file) {
m_file = file;
}
QFileInfo m_file;
@ -16,5 +16,3 @@ struct ScreenShot
QString m_imgurId;
QString m_imgurDeleteHash;
};
typedef std::shared_ptr<ScreenShot> ScreenshotPtr;