diff options
Diffstat (limited to 'application/dialogs')
-rw-r--r-- | application/dialogs/SkinUploadDialog.cpp | 69 | ||||
-rw-r--r-- | application/dialogs/SkinUploadDialog.h | 29 | ||||
-rw-r--r-- | application/dialogs/SkinUploadDialog.ui | 85 |
3 files changed, 183 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); +} diff --git a/application/dialogs/SkinUploadDialog.h b/application/dialogs/SkinUploadDialog.h new file mode 100644 index 00000000..514eabc8 --- /dev/null +++ b/application/dialogs/SkinUploadDialog.h @@ -0,0 +1,29 @@ +#pragma once + +#include <QDialog> +#include <minecraft/auth/MojangAccount.h> + +namespace Ui +{ + class SkinUploadDialog; +} + +class SkinUploadDialog : public QDialog { + Q_OBJECT +public: + explicit SkinUploadDialog(MojangAccountPtr acct, QWidget *parent = 0); + virtual ~SkinUploadDialog() {}; + +public slots: + void on_buttonBox_accepted(); + + void on_buttonBox_rejected(); + + void on_skinBrowseBtn_clicked(); + +protected: + MojangAccountPtr m_acct; + +private: + Ui::SkinUploadDialog *ui; +}; diff --git a/application/dialogs/SkinUploadDialog.ui b/application/dialogs/SkinUploadDialog.ui new file mode 100644 index 00000000..6f5307e3 --- /dev/null +++ b/application/dialogs/SkinUploadDialog.ui @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SkinUploadDialog</class> + <widget class="QDialog" name="SkinUploadDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>413</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Skin Upload</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="fileBox"> + <property name="title"> + <string>Skin File</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLineEdit" name="skinPathTextBox"/> + </item> + <item> + <widget class="QPushButton" name="skinBrowseBtn"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>28</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string notr="true">...</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="modelBox"> + <property name="title"> + <string>Player Model</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_1"> + <item> + <widget class="QRadioButton" name="steveBtn"> + <property name="text"> + <string>Steve Model</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="alexBtn"> + <property name="text"> + <string>Alex Model</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> |