NOISSUE implement deleting skins
This commit is contained in:
parent
280903e52b
commit
1edcd9b86e
@ -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
|
||||
|
42
api/logic/minecraft/services/SkinDelete.cpp
Normal file
42
api/logic/minecraft/services/SkinDelete.cpp
Normal file
@ -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();
|
||||
}
|
||||
|
30
api/logic/minecraft/services/SkinDelete.h
Normal file
30
api/logic/minecraft/services/SkinDelete.h
Normal file
@ -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();
|
||||
};
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user