diff options
Diffstat (limited to 'launcher/screenshots')
-rw-r--r-- | launcher/screenshots/ImgurAlbumCreation.cpp | 30 | ||||
-rw-r--r-- | launcher/screenshots/ImgurAlbumCreation.h | 27 | ||||
-rw-r--r-- | launcher/screenshots/ImgurUpload.cpp | 33 | ||||
-rw-r--r-- | launcher/screenshots/ImgurUpload.h | 18 | ||||
-rw-r--r-- | launcher/screenshots/Screenshot.h | 6 |
5 files changed, 44 insertions, 70 deletions
diff --git a/launcher/screenshots/ImgurAlbumCreation.cpp b/launcher/screenshots/ImgurAlbumCreation.cpp index ab425f1a..d598d77e 100644 --- a/launcher/screenshots/ImgurAlbumCreation.cpp +++ b/launcher/screenshots/ImgurAlbumCreation.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * @@ -36,15 +36,15 @@ #include "ImgurAlbumCreation.h" -#include <QNetworkRequest> +#include <QDebug> #include <QJsonDocument> #include <QJsonObject> -#include <QUrl> +#include <QNetworkRequest> #include <QStringList> -#include <QDebug> +#include <QUrl> -#include "BuildConfig.h" #include "Application.h" +#include "BuildConfig.h" ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenShot::Ptr> screenshots) : NetAction(), m_screenshots(screenshots) { @@ -62,19 +62,18 @@ void ImgurAlbumCreation::executeTask() request.setRawHeader("Accept", "application/json"); QStringList hashes; - for (auto shot : m_screenshots) - { + for (auto shot : m_screenshots) { hashes.append(shot->m_imgurDeleteHash); } const QByteArray data = "deletehashes=" + hashes.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden"; - QNetworkReply *rep = APPLICATION->network()->post(request, data); + QNetworkReply* rep = APPLICATION->network()->post(request, data); m_reply.reset(rep); connect(rep, &QNetworkReply::uploadProgress, this, &ImgurAlbumCreation::downloadProgress); connect(rep, &QNetworkReply::finished, this, &ImgurAlbumCreation::downloadFinished); -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15 +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15 connect(rep, &QNetworkReply::errorOccurred, this, &ImgurAlbumCreation::downloadError); #else connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &ImgurAlbumCreation::downloadError); @@ -90,21 +89,18 @@ void ImgurAlbumCreation::downloadError(QNetworkReply::NetworkError error) void ImgurAlbumCreation::downloadFinished() { - if (m_state != State::Failed) - { + if (m_state != State::Failed) { QByteArray data = m_reply->readAll(); m_reply.reset(); QJsonParseError jsonError; QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { + if (jsonError.error != QJsonParseError::NoError) { qDebug() << jsonError.errorString(); emitFailed(); return; } auto object = doc.object(); - if (!object.value("success").toBool()) - { + if (!object.value("success").toBool()) { qDebug() << doc.toJson(); emitFailed(); return; @@ -114,9 +110,7 @@ void ImgurAlbumCreation::downloadFinished() m_state = State::Succeeded; emit succeeded(); return; - } - else - { + } else { qDebug() << m_reply->readAll(); m_reply.reset(); emitFailed(); diff --git a/launcher/screenshots/ImgurAlbumCreation.h b/launcher/screenshots/ImgurAlbumCreation.h index 0228b6e4..3a82a956 100644 --- a/launcher/screenshots/ImgurAlbumCreation.h +++ b/launcher/screenshots/ImgurAlbumCreation.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> * * This program is free software: you can redistribute it and/or modify @@ -35,40 +35,31 @@ #pragma once -#include "net/NetAction.h" #include "Screenshot.h" +#include "net/NetAction.h" typedef shared_qobject_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr; -class ImgurAlbumCreation : public NetAction -{ -public: +class ImgurAlbumCreation : public NetAction { + public: explicit ImgurAlbumCreation(QList<ScreenShot::Ptr> screenshots); static ImgurAlbumCreationPtr make(QList<ScreenShot::Ptr> screenshots) { return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots)); } - QString deleteHash() const - { - return m_deleteHash; - } - QString id() const - { - return m_id; - } + QString deleteHash() const { return m_deleteHash; } + QString id() const { return m_id; } -protected -slots: + protected slots: void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override; void downloadError(QNetworkReply::NetworkError error) override; void downloadFinished() override; void downloadReadyRead() override {} -public -slots: + public slots: void executeTask() override; -private: + private: QList<ScreenShot::Ptr> m_screenshots; QString m_deleteHash; diff --git a/launcher/screenshots/ImgurUpload.cpp b/launcher/screenshots/ImgurUpload.cpp index a50f9afa..706af7ba 100644 --- a/launcher/screenshots/ImgurUpload.cpp +++ b/launcher/screenshots/ImgurUpload.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * @@ -35,17 +35,17 @@ */ #include "ImgurUpload.h" -#include "BuildConfig.h" #include "Application.h" +#include "BuildConfig.h" -#include <QNetworkRequest> +#include <QDebug> +#include <QFile> #include <QHttpMultiPart> +#include <QHttpPart> #include <QJsonDocument> #include <QJsonObject> -#include <QHttpPart> -#include <QFile> +#include <QNetworkRequest> #include <QUrl> -#include <QDebug> ImgurUpload::ImgurUpload(ScreenShot::Ptr shot) : NetAction(), m_shot(shot) { @@ -63,13 +63,12 @@ void ImgurUpload::executeTask() request.setRawHeader("Accept", "application/json"); QFile f(m_shot->m_file.absoluteFilePath()); - if (!f.open(QFile::ReadOnly)) - { + if (!f.open(QFile::ReadOnly)) { emitFailed(); return; } - QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + QHttpMultiPart* multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart filePart; filePart.setBody(f.readAll().toBase64()); filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png"); @@ -84,12 +83,12 @@ void ImgurUpload::executeTask() namePart.setBody(m_shot->m_file.baseName().toUtf8()); multipart->append(namePart); - QNetworkReply *rep = m_network->post(request, multipart); + QNetworkReply* rep = m_network->post(request, multipart); m_reply.reset(rep); connect(rep, &QNetworkReply::uploadProgress, this, &ImgurUpload::downloadProgress); connect(rep, &QNetworkReply::finished, this, &ImgurUpload::downloadFinished); -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15 +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15 connect(rep, &QNetworkReply::errorOccurred, this, &ImgurUpload::downloadError); #else connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &ImgurUpload::downloadError); @@ -100,8 +99,7 @@ void ImgurUpload::executeTask() void ImgurUpload::downloadError(QNetworkReply::NetworkError error) { qCritical() << "ImgurUpload failed with error" << m_reply->errorString() << "Server reply:\n" << m_reply->readAll(); - if(finished) - { + if (finished) { qCritical() << "Double finished ImgurUpload!"; return; } @@ -113,8 +111,7 @@ void ImgurUpload::downloadError(QNetworkReply::NetworkError error) void ImgurUpload::downloadFinished() { - if(finished) - { + if (finished) { qCritical() << "Double finished ImgurUpload!"; return; } @@ -122,8 +119,7 @@ void ImgurUpload::downloadFinished() m_reply.reset(); QJsonParseError jsonError; QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { + if (jsonError.error != QJsonParseError::NoError) { qDebug() << "imgur server did not reply with JSON" << jsonError.errorString(); finished = true; m_reply.reset(); @@ -131,8 +127,7 @@ void ImgurUpload::downloadFinished() return; } auto object = doc.object(); - if (!object.value("success").toBool()) - { + if (!object.value("success").toBool()) { qDebug() << "Screenshot upload not successful:" << doc.toJson(); finished = true; m_reply.reset(); diff --git a/launcher/screenshots/ImgurUpload.h b/launcher/screenshots/ImgurUpload.h index 404dc876..8714e0c0 100644 --- a/launcher/screenshots/ImgurUpload.h +++ b/launcher/screenshots/ImgurUpload.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> * * This program is free software: you can redistribute it and/or modify @@ -35,30 +35,26 @@ #pragma once -#include "net/NetAction.h" #include "Screenshot.h" +#include "net/NetAction.h" class ImgurUpload : public NetAction { -public: + public: using Ptr = shared_qobject_ptr<ImgurUpload>; explicit ImgurUpload(ScreenShot::Ptr shot); - static Ptr make(ScreenShot::Ptr shot) { - return Ptr(new ImgurUpload(shot)); - } + static Ptr make(ScreenShot::Ptr shot) { return Ptr(new ImgurUpload(shot)); } -protected -slots: + protected slots: void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override; void downloadError(QNetworkReply::NetworkError error) override; void downloadFinished() override; void downloadReadyRead() override {} -public -slots: + public slots: void executeTask() override; -private: + private: ScreenShot::Ptr m_shot; bool finished = true; }; diff --git a/launcher/screenshots/Screenshot.h b/launcher/screenshots/Screenshot.h index ca45aabf..767f3906 100644 --- a/launcher/screenshots/Screenshot.h +++ b/launcher/screenshots/Screenshot.h @@ -1,16 +1,14 @@ #pragma once #include <QDateTime> -#include <QString> #include <QFileInfo> +#include <QString> #include <memory> struct ScreenShot { using Ptr = std::shared_ptr<ScreenShot>; - ScreenShot(QFileInfo file) { - m_file = file; - } + ScreenShot(QFileInfo file) { m_file = file; } QFileInfo m_file; QString m_url; QString m_imgurId; |