diff options
author | Alexia <alexia@robotbrain.info> | 2016-05-12 16:51:25 -0400 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-05-15 16:01:05 +0200 |
commit | 377316999ea9ef6adbc75c52a858eb8e526616e7 (patch) | |
tree | 1ad7ba47c89c69d0e25f7e6e0f592782e75b81d1 /application/dialogs/SkinUploadDialog.cpp | |
parent | f9791a5cc80b8e99eebd68176c33fdc1c377af86 (diff) | |
download | MultiMC-377316999ea9ef6adbc75c52a858eb8e526616e7.tar MultiMC-377316999ea9ef6adbc75c52a858eb8e526616e7.tar.gz MultiMC-377316999ea9ef6adbc75c52a858eb8e526616e7.tar.lz MultiMC-377316999ea9ef6adbc75c52a858eb8e526616e7.tar.xz MultiMC-377316999ea9ef6adbc75c52a858eb8e526616e7.zip |
GH-767 Basic skin upload
Diffstat (limited to 'application/dialogs/SkinUploadDialog.cpp')
-rw-r--r-- | application/dialogs/SkinUploadDialog.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/application/dialogs/SkinUploadDialog.cpp b/application/dialogs/SkinUploadDialog.cpp new file mode 100644 index 00000000..ebbab785 --- /dev/null +++ b/application/dialogs/SkinUploadDialog.cpp @@ -0,0 +1,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); +} |