aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2021-02-11 02:22:43 +0100
committerPetr Mrázek <peterix@gmail.com>2021-02-11 02:23:00 +0100
commit1edcd9b86e1174ca236e24002650940c36124a22 (patch)
treed428777a37570c1a9e38add7cf9acfb2e83713b0
parent280903e52b95d9b68e37d10c0b9abc40346660b3 (diff)
downloadPrismLauncher-1edcd9b86e1174ca236e24002650940c36124a22.tar.gz
PrismLauncher-1edcd9b86e1174ca236e24002650940c36124a22.tar.bz2
PrismLauncher-1edcd9b86e1174ca236e24002650940c36124a22.zip
NOISSUE implement deleting skins
-rw-r--r--api/logic/CMakeLists.txt8
-rw-r--r--api/logic/minecraft/services/SkinDelete.cpp42
-rw-r--r--api/logic/minecraft/services/SkinDelete.h30
-rw-r--r--api/logic/minecraft/services/SkinUpload.cpp (renamed from api/logic/minecraft/SkinUpload.cpp)0
-rw-r--r--api/logic/minecraft/services/SkinUpload.h (renamed from api/logic/minecraft/SkinUpload.h)0
-rw-r--r--application/dialogs/SkinUploadDialog.cpp2
-rw-r--r--application/pages/global/AccountListPage.cpp24
-rw-r--r--application/pages/global/AccountListPage.h21
-rw-r--r--application/pages/global/AccountListPage.ui10
9 files changed, 118 insertions, 19 deletions
diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt
index 3d385b1c..84438a6b 100644
--- a/api/logic/CMakeLists.txt
+++ b/api/logic/CMakeLists.txt
@@ -303,9 +303,11 @@ set(MINECRAFT_SOURCES
minecraft/AssetsUtils.h
minecraft/AssetsUtils.cpp
- # Skin upload utilities
- minecraft/SkinUpload.cpp
- minecraft/SkinUpload.h
+ # Minecraft services
+ minecraft/services/SkinUpload.cpp
+ minecraft/services/SkinUpload.h
+ minecraft/services/SkinDelete.cpp
+ minecraft/services/SkinDelete.h
mojang/PackageManifest.h
mojang/PackageManifest.cpp
diff --git a/api/logic/minecraft/services/SkinDelete.cpp b/api/logic/minecraft/services/SkinDelete.cpp
new file mode 100644
index 00000000..34977257
--- /dev/null
+++ b/api/logic/minecraft/services/SkinDelete.cpp
@@ -0,0 +1,42 @@
+#include "SkinDelete.h"
+#include <QNetworkRequest>
+#include <QHttpMultiPart>
+#include <Env.h>
+
+SkinDelete::SkinDelete(QObject *parent, AuthSessionPtr session)
+ : Task(parent), m_session(session)
+{
+}
+
+void SkinDelete::executeTask()
+{
+ QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/skins/active"));
+ request.setRawHeader("Authorization", QString("Bearer %1").arg(m_session->access_token).toLocal8Bit());
+ QNetworkReply *rep = ENV.qnam().deleteResource(request);
+ m_reply = std::shared_ptr<QNetworkReply>(rep);
+
+ setStatus(tr("Deleting skin"));
+ connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress);
+ connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
+ connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));
+}
+
+void SkinDelete::downloadError(QNetworkReply::NetworkError error)
+{
+ // error happened during download.
+ qCritical() << "Network error: " << error;
+ emitFailed(m_reply->errorString());
+}
+
+void SkinDelete::downloadFinished()
+{
+ // if the download failed
+ if (m_reply->error() != QNetworkReply::NetworkError::NoError)
+ {
+ emitFailed(QString("Network error: %1").arg(m_reply->errorString()));
+ m_reply.reset();
+ return;
+ }
+ emitSucceeded();
+}
+
diff --git a/api/logic/minecraft/services/SkinDelete.h b/api/logic/minecraft/services/SkinDelete.h
new file mode 100644
index 00000000..705ce8ef
--- /dev/null
+++ b/api/logic/minecraft/services/SkinDelete.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <QFile>
+#include <QtNetwork/QtNetwork>
+#include <memory>
+#include <minecraft/auth/AuthSession.h>
+#include "tasks/Task.h"
+#include "multimc_logic_export.h"
+
+typedef std::shared_ptr<class SkinDelete> SkinDeletePtr;
+
+class MULTIMC_LOGIC_EXPORT SkinDelete : public Task
+{
+ Q_OBJECT
+public:
+ SkinDelete(QObject *parent, AuthSessionPtr session);
+ virtual ~SkinDelete() = default;
+
+private:
+ AuthSessionPtr m_session;
+ std::shared_ptr<QNetworkReply> m_reply;
+
+protected:
+ virtual void executeTask();
+
+public slots:
+ void downloadError(QNetworkReply::NetworkError);
+ void downloadFinished();
+};
+
diff --git a/api/logic/minecraft/SkinUpload.cpp b/api/logic/minecraft/services/SkinUpload.cpp
index 4e5a1698..4e5a1698 100644
--- a/api/logic/minecraft/SkinUpload.cpp
+++ b/api/logic/minecraft/services/SkinUpload.cpp
diff --git a/api/logic/minecraft/SkinUpload.h b/api/logic/minecraft/services/SkinUpload.h
index c77abb03..c77abb03 100644
--- a/api/logic/minecraft/SkinUpload.h
+++ b/api/logic/minecraft/services/SkinUpload.h
diff --git a/application/dialogs/SkinUploadDialog.cpp b/application/dialogs/SkinUploadDialog.cpp
index 7d2ff829..56133529 100644
--- a/application/dialogs/SkinUploadDialog.cpp
+++ b/application/dialogs/SkinUploadDialog.cpp
@@ -1,7 +1,7 @@
#include <QFileInfo>
#include <QFileDialog>
#include <FileSystem.h>
-#include <minecraft/SkinUpload.h>
+#include <minecraft/services/SkinUpload.h>
#include "SkinUploadDialog.h"
#include "ui_SkinUploadDialog.h"
#include "ProgressDialog.h"
diff --git a/application/pages/global/AccountListPage.cpp b/application/pages/global/AccountListPage.cpp
index 5a508df4..ff3736ed 100644
--- a/application/pages/global/AccountListPage.cpp
+++ b/application/pages/global/AccountListPage.cpp
@@ -30,6 +30,7 @@
#include "dialogs/SkinUploadDialog.h"
#include "tasks/Task.h"
#include "minecraft/auth/YggdrasilTask.h"
+#include "minecraft/services/SkinDelete.h"
#include "MultiMC.h"
@@ -142,6 +143,7 @@ void AccountListPage::updateButtonStates()
ui->actionRemove->setEnabled(selection.size() > 0);
ui->actionSetDefault->setEnabled(selection.size() > 0);
ui->actionUploadSkin->setEnabled(selection.size() > 0);
+ ui->actionDeleteSkin->setEnabled(selection.size() > 0);
if(m_accounts->activeAccount().get() == nullptr) {
ui->actionNoDefault->setEnabled(false);
@@ -191,3 +193,25 @@ void AccountListPage::on_actionUploadSkin_triggered()
dialog.exec();
}
}
+
+void AccountListPage::on_actionDeleteSkin_triggered()
+{
+ QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
+ if (selection.size() <= 0)
+ return;
+
+ QModelIndex selected = selection.first();
+ AuthSessionPtr session = std::make_shared<AuthSession>();
+ MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
+ auto login = account->login(session);
+ ProgressDialog prog(this);
+ if (prog.execWithTask((Task*)login.get()) != QDialog::Accepted) {
+ CustomMessageBox::selectable(this, tr("Skin Delete"), tr("Failed to login!"), QMessageBox::Warning)->exec();
+ return;
+ }
+ auto deleteSkinTask = std::make_shared<SkinDelete>(this, session);
+ if (prog.execWithTask((Task*)deleteSkinTask.get()) != QDialog::Accepted) {
+ CustomMessageBox::selectable(this, tr("Skin Delete"), tr("Failed to delete current skin!"), QMessageBox::Warning)->exec();
+ return;
+ }
+}
diff --git a/application/pages/global/AccountListPage.h b/application/pages/global/AccountListPage.h
index 364eab3d..fba1833f 100644
--- a/application/pages/global/AccountListPage.h
+++ b/application/pages/global/AccountListPage.h
@@ -59,35 +59,26 @@ public:
return "Getting-Started#adding-an-account";
}
-private:
- void changeEvent(QEvent * event) override;
- QMenu * createPopupMenu() override;
-
-public
-slots:
+public slots:
void on_actionAdd_triggered();
-
void on_actionRemove_triggered();
-
void on_actionSetDefault_triggered();
-
void on_actionNoDefault_triggered();
-
void on_actionUploadSkin_triggered();
+ void on_actionDeleteSkin_triggered();
void listChanged();
//! Updates the states of the dialog's buttons.
void updateButtonStates();
-protected:
- std::shared_ptr<MojangAccountList> m_accounts;
-
-protected
-slots:
+protected slots:
void ShowContextMenu(const QPoint &pos);
void addAccount(const QString& errMsg="");
private:
+ void changeEvent(QEvent * event) override;
+ QMenu * createPopupMenu() override;
+ std::shared_ptr<MojangAccountList> m_accounts;
Ui::AccountListPage *ui;
};
diff --git a/application/pages/global/AccountListPage.ui b/application/pages/global/AccountListPage.ui
index ba07445e..71647db3 100644
--- a/application/pages/global/AccountListPage.ui
+++ b/application/pages/global/AccountListPage.ui
@@ -40,7 +40,9 @@
<addaction name="actionRemove"/>
<addaction name="actionSetDefault"/>
<addaction name="actionNoDefault"/>
+ <addaction name="separator"/>
<addaction name="actionUploadSkin"/>
+ <addaction name="actionDeleteSkin"/>
</widget>
<action name="actionAdd">
<property name="text">
@@ -70,6 +72,14 @@
<string>Upload Skin</string>
</property>
</action>
+ <action name="actionDeleteSkin">
+ <property name="text">
+ <string>Delete Skin</string>
+ </property>
+ <property name="toolTip">
+ <string>Delete the currently active skin and go back to the default one</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>