summaryrefslogtreecommitdiffstats
path: root/application/dialogs/SkinUploadDialog.cpp
blob: ebbab7859235a2827b957fb4fccec3b85497e68e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <QFileInfo>
#include <QFileDialog>
#include <FileSystem.h>
#include <minecraft/SkinUpload.h>
#include "SkinUploadDialog.h"
#include "ui_SkinUploadDialog.h"
#include "ProgressDialog.h"
#include "CustomMessageBox.h"

void SkinUploadDialog::on_buttonBox_rejected()
{
	close();
}

void SkinUploadDialog::on_buttonBox_accepted()
{
	AuthSessionPtr session = std::make_shared<AuthSession>();
	auto login = m_acct->login(session);
	ProgressDialog prog(this);
	if (prog.execWithTask((Task*)login.get()) != QDialog::Accepted)
	{
		//FIXME: recover with password prompt
		CustomMessageBox::selectable(this, tr("Failed to login!"), tr("Unknown error"), QMessageBox::Warning)->exec();
		close();
		return;
	}
	QString fileName = ui->skinPathTextBox->text();
	if (!QFile::exists(fileName))
	{
		CustomMessageBox::selectable(this, tr("Skin file does not exist!"), tr("Unknown error"), QMessageBox::Warning)->exec();
		close();
		return;
	}
	SkinUpload::Model model = SkinUpload::STEVE;
	if (ui->steveBtn->isChecked())
	{
		model = SkinUpload::STEVE;
	}
	else if (ui->alexBtn->isChecked())
	{
		model = SkinUpload::ALEX;
	}
	SkinUploadPtr upload = std::make_shared<SkinUpload>(this, session, FS::read(fileName), model);
	if (prog.execWithTask((Task*)upload.get()) != QDialog::Accepted)
	{
		CustomMessageBox::selectable(this, tr("Failed to upload skin!"), tr("Unknown error"), QMessageBox::Warning)->exec();
		close();
		return;
	}
	CustomMessageBox::selectable(this, tr("Skin uploaded!"), tr("Success"), QMessageBox::Information)->exec();
	close();
}

void SkinUploadDialog::on_skinBrowseBtn_clicked()
{
	QString raw_path = QFileDialog::getOpenFileName(this, tr("Select Skin Texture"), QString(), "*.png");
	QString cooked_path = FS::NormalizePath(raw_path);
	if (cooked_path.isEmpty() || !QFileInfo::exists(cooked_path))
	{
		return;
	}
	ui->skinPathTextBox->setText(cooked_path);
}

SkinUploadDialog::SkinUploadDialog(MojangAccountPtr acct, QWidget *parent)
	:QDialog(parent), m_acct(acct), ui(new Ui::SkinUploadDialog)
{
	ui->setupUi(this);
}