From 69213b1206e97f7d4db4270a4b3b0af41dc9e6fc Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 21 Nov 2021 23:21:12 +0100 Subject: NOISSUE continue refactoring things to make tests pass --- launcher/screenshots/ImgurAlbumCreation.cpp | 10 +++++----- launcher/screenshots/ImgurAlbumCreation.h | 11 ++++++----- launcher/screenshots/ImgurUpload.cpp | 10 ++++------ launcher/screenshots/ImgurUpload.h | 22 ++++++++++------------ launcher/screenshots/Screenshot.h | 10 ++++------ 5 files changed, 29 insertions(+), 34 deletions(-) (limited to 'launcher/screenshots') diff --git a/launcher/screenshots/ImgurAlbumCreation.cpp b/launcher/screenshots/ImgurAlbumCreation.cpp index d1b21f5f..d5de302a 100644 --- a/launcher/screenshots/ImgurAlbumCreation.cpp +++ b/launcher/screenshots/ImgurAlbumCreation.cpp @@ -5,18 +5,18 @@ #include #include #include +#include #include "BuildConfig.h" -#include "Env.h" -#include +#include "Application.h" -ImgurAlbumCreation::ImgurAlbumCreation(QList screenshots) : NetAction(), m_screenshots(screenshots) +ImgurAlbumCreation::ImgurAlbumCreation(QList 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); diff --git a/launcher/screenshots/ImgurAlbumCreation.h b/launcher/screenshots/ImgurAlbumCreation.h index 954637e6..cb048a23 100644 --- a/launcher/screenshots/ImgurAlbumCreation.h +++ b/launcher/screenshots/ImgurAlbumCreation.h @@ -1,13 +1,14 @@ #pragma once #include "net/NetAction.h" #include "Screenshot.h" +#include "QObjectPtr.h" -typedef std::shared_ptr ImgurAlbumCreationPtr; +typedef shared_qobject_ptr ImgurAlbumCreationPtr; class ImgurAlbumCreation : public NetAction { public: - explicit ImgurAlbumCreation(QList screenshots); - static ImgurAlbumCreationPtr make(QList screenshots) + explicit ImgurAlbumCreation(QList screenshots); + static ImgurAlbumCreationPtr make(QList screenshots) { return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots)); } @@ -32,10 +33,10 @@ slots: public slots: - virtual void start(); + virtual void startImpl(); private: - QList m_screenshots; + QList m_screenshots; QString m_deleteHash; QString m_id; diff --git a/launcher/screenshots/ImgurUpload.cpp b/launcher/screenshots/ImgurUpload.cpp index dfdbf2e8..76a84947 100644 --- a/launcher/screenshots/ImgurUpload.cpp +++ b/launcher/screenshots/ImgurUpload.cpp @@ -1,4 +1,5 @@ #include "ImgurUpload.h" +#include "BuildConfig.h" #include #include @@ -7,18 +8,15 @@ #include #include #include - -#include "BuildConfig.h" -#include "Env.h" #include -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); diff --git a/launcher/screenshots/ImgurUpload.h b/launcher/screenshots/ImgurUpload.h index 0507d499..ac57d1ba 100644 --- a/launcher/screenshots/ImgurUpload.h +++ b/launcher/screenshots/ImgurUpload.h @@ -1,15 +1,15 @@ #pragma once +#include "QObjectPtr.h" #include "net/NetAction.h" #include "Screenshot.h" -typedef std::shared_ptr 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; + + 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; }; diff --git a/launcher/screenshots/Screenshot.h b/launcher/screenshots/Screenshot.h index 9db3a8a1..ca45aabf 100644 --- a/launcher/screenshots/Screenshot.h +++ b/launcher/screenshots/Screenshot.h @@ -5,10 +5,10 @@ #include #include -struct ScreenShot -{ - ScreenShot(QFileInfo file) - { +struct ScreenShot { + using Ptr = std::shared_ptr; + + 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 ScreenshotPtr; -- cgit