summaryrefslogtreecommitdiff
path: root/meshmc/launcher/ui/dialogs/SkinUploadDialog.cpp
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:45:07 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:45:07 +0300
commit31b9a8949ed0a288143e23bf739f2eb64fdc63be (patch)
tree8a984fa143c38fccad461a77792d6864f3e82cd3 /meshmc/launcher/ui/dialogs/SkinUploadDialog.cpp
parent934382c8a1ce738589dee9ee0f14e1cec812770e (diff)
parentfad6a1066616b69d7f5fef01178efdf014c59537 (diff)
downloadProject-Tick-31b9a8949ed0a288143e23bf739f2eb64fdc63be.tar.gz
Project-Tick-31b9a8949ed0a288143e23bf739f2eb64fdc63be.zip
Add 'meshmc/' from commit 'fad6a1066616b69d7f5fef01178efdf014c59537'
git-subtree-dir: meshmc git-subtree-mainline: 934382c8a1ce738589dee9ee0f14e1cec812770e git-subtree-split: fad6a1066616b69d7f5fef01178efdf014c59537
Diffstat (limited to 'meshmc/launcher/ui/dialogs/SkinUploadDialog.cpp')
-rw-r--r--meshmc/launcher/ui/dialogs/SkinUploadDialog.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/meshmc/launcher/ui/dialogs/SkinUploadDialog.cpp b/meshmc/launcher/ui/dialogs/SkinUploadDialog.cpp
new file mode 100644
index 0000000000..414e0acaf0
--- /dev/null
+++ b/meshmc/launcher/ui/dialogs/SkinUploadDialog.cpp
@@ -0,0 +1,163 @@
+/* SPDX-FileCopyrightText: 2026 Project Tick
+ * SPDX-FileContributor: Project Tick
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * MeshMC - A Custom Launcher for Minecraft
+ * Copyright (C) 2026 Project Tick
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <QFileInfo>
+#include <QFileDialog>
+#include <QPainter>
+#include <QRegularExpression>
+
+#include <FileSystem.h>
+
+#include <minecraft/services/SkinUpload.h>
+#include <minecraft/services/CapeChange.h>
+#include <tasks/SequentialTask.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()
+{
+ QString fileName;
+ QString input = ui->skinPathTextBox->text();
+ QRegularExpression urlPrefixMatcher("^([a-z]+)://.+$");
+ bool isLocalFile = false;
+ // it has an URL prefix -> it is an URL
+ if (urlPrefixMatcher.match(input).hasMatch()) {
+ QUrl fileURL = input;
+ if (fileURL.isValid()) {
+ // local?
+ if (fileURL.isLocalFile()) {
+ isLocalFile = true;
+ fileName = fileURL.toLocalFile();
+ } else {
+ CustomMessageBox::selectable(
+ this, tr("Skin Upload"),
+ tr("Using remote URLs for setting skins is not implemented "
+ "yet."),
+ QMessageBox::Warning)
+ ->exec();
+ close();
+ return;
+ }
+ } else {
+ CustomMessageBox::selectable(
+ this, tr("Skin Upload"),
+ tr("You cannot use an invalid URL for uploading skins."),
+ QMessageBox::Warning)
+ ->exec();
+ close();
+ return;
+ }
+ } else {
+ // just assume it's a path then
+ isLocalFile = true;
+ fileName = ui->skinPathTextBox->text();
+ }
+ if (isLocalFile && !QFile::exists(fileName)) {
+ CustomMessageBox::selectable(this, tr("Skin Upload"),
+ tr("Skin file does not exist!"),
+ 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;
+ }
+ ProgressDialog prog(this);
+ SequentialTask skinUpload;
+ skinUpload.addTask(shared_qobject_ptr<SkinUpload>(new SkinUpload(
+ this, m_acct->accessToken(), FS::read(fileName), model)));
+ auto selectedCape = ui->capeCombo->currentData().toString();
+ if (selectedCape != m_acct->accountData()->minecraftProfile.currentCape) {
+ skinUpload.addTask(shared_qobject_ptr<CapeChange>(
+ new CapeChange(this, m_acct->accessToken(), selectedCape)));
+ }
+ if (prog.execWithTask(&skinUpload) != QDialog::Accepted) {
+ CustomMessageBox::selectable(this, tr("Skin Upload"),
+ tr("Failed to upload skin!"),
+ QMessageBox::Warning)
+ ->exec();
+ close();
+ return;
+ }
+ CustomMessageBox::selectable(this, tr("Skin Upload"), tr("Success"),
+ QMessageBox::Information)
+ ->exec();
+ close();
+}
+
+void SkinUploadDialog::on_skinBrowseBtn_clicked()
+{
+ QString raw_path = QFileDialog::getOpenFileName(
+ this, tr("Select Skin Texture"), QString(), "*.png");
+ if (raw_path.isEmpty() || !QFileInfo::exists(raw_path)) {
+ return;
+ }
+ QString cooked_path = FS::NormalizePath(raw_path);
+ ui->skinPathTextBox->setText(cooked_path);
+}
+
+SkinUploadDialog::SkinUploadDialog(MinecraftAccountPtr acct, QWidget* parent)
+ : QDialog(parent), m_acct(acct), ui(new Ui::SkinUploadDialog)
+{
+ ui->setupUi(this);
+
+ // FIXME: add a model for this, download/refresh the capes on demand
+ auto& data = *acct->accountData();
+ int index = 0;
+ ui->capeCombo->addItem(tr("No Cape"), QVariant());
+ auto currentCape = data.minecraftProfile.currentCape;
+ if (currentCape.isEmpty()) {
+ ui->capeCombo->setCurrentIndex(index);
+ }
+
+ for (auto& cape : data.minecraftProfile.capes) {
+ index++;
+ if (cape.data.size()) {
+ QPixmap capeImage;
+ if (capeImage.loadFromData(cape.data, "PNG")) {
+ QPixmap preview = QPixmap(10, 16);
+ QPainter painter(&preview);
+ painter.drawPixmap(0, 0, capeImage.copy(1, 1, 10, 16));
+ ui->capeCombo->addItem(capeImage, cape.alias, cape.id);
+ if (currentCape == cape.id) {
+ ui->capeCombo->setCurrentIndex(index);
+ }
+ continue;
+ }
+ }
+ ui->capeCombo->addItem(cape.alias, cape.id);
+ if (currentCape == cape.id) {
+ ui->capeCombo->setCurrentIndex(index);
+ }
+ }
+}