Merge branch 'develop' into feat/acknowledge_release_type
Signed-off-by: Alexandru Ionut Tripon <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -34,26 +34,28 @@
|
||||
*/
|
||||
|
||||
#include "AboutDialog.h"
|
||||
#include "BuildConfig.h"
|
||||
#include "ui_AboutDialog.h"
|
||||
#include <QIcon>
|
||||
#include "Application.h"
|
||||
#include "BuildConfig.h"
|
||||
#include "Markdown.h"
|
||||
#include "ui_AboutDialog.h"
|
||||
|
||||
#include <net/NetJob.h>
|
||||
#include <qobject.h>
|
||||
|
||||
namespace {
|
||||
QString getLink(QString link, QString name) {
|
||||
QString getLink(QString link, QString name)
|
||||
{
|
||||
return QString("<<a href='%1'>%2</a>>").arg(link).arg(name);
|
||||
}
|
||||
|
||||
QString getWebsite(QString link) {
|
||||
QString getWebsite(QString link)
|
||||
{
|
||||
return getLink(link, QObject::tr("Website"));
|
||||
}
|
||||
|
||||
QString getGitHub(QString username) {
|
||||
QString getGitHub(QString username)
|
||||
{
|
||||
return getLink("https://github.com/" + username, "GitHub");
|
||||
}
|
||||
|
||||
@ -70,19 +72,19 @@ QString getCreditsHtml()
|
||||
|
||||
//: %1 is the name of the launcher, determined at build time, e.g. "Prism Launcher Developers"
|
||||
stream << "<h3>" << QObject::tr("%1 Developers", "About Credits").arg(BuildConfig.LAUNCHER_DISPLAYNAME) << "</h3>\n";
|
||||
stream << QString("<p>Sefa Eyeoglu (Scrumplex) %1</p>\n") .arg(getWebsite("https://scrumplex.net"));
|
||||
stream << QString("<p>d-513 %1</p>\n") .arg(getGitHub("d-513"));
|
||||
stream << QString("<p>txtsd %1</p>\n") .arg(getWebsite("https://ihavea.quest"));
|
||||
stream << QString("<p>timoreo %1</p>\n") .arg(getGitHub("timoreo22"));
|
||||
stream << QString("<p>Ezekiel Smith (ZekeSmith) %1</p>\n") .arg(getGitHub("ZekeSmith"));
|
||||
stream << QString("<p>cozyGalvinism %1</p>\n") .arg(getGitHub("cozyGalvinism"));
|
||||
stream << QString("<p>DioEgizio %1</p>\n") .arg(getGitHub("DioEgizio"));
|
||||
stream << QString("<p>flowln %1</p>\n") .arg(getGitHub("flowln"));
|
||||
stream << QString("<p>ViRb3 %1</p>\n") .arg(getGitHub("ViRb3"));
|
||||
stream << QString("<p>Rachel Powers (Ryex) %1</p>\n") .arg(getGitHub("Ryex"));
|
||||
stream << QString("<p>TayouVR %1</p>\n") .arg(getGitHub("TayouVR"));
|
||||
stream << QString("<p>TheKodeToad %1</p>\n") .arg(getGitHub("TheKodeToad"));
|
||||
stream << QString("<p>getchoo %1</p>\n") .arg(getGitHub("getchoo"));
|
||||
stream << QString("<p>Sefa Eyeoglu (Scrumplex) %1</p>\n").arg(getWebsite("https://scrumplex.net"));
|
||||
stream << QString("<p>d-513 %1</p>\n").arg(getGitHub("d-513"));
|
||||
stream << QString("<p>txtsd %1</p>\n").arg(getWebsite("https://ihavea.quest"));
|
||||
stream << QString("<p>timoreo %1</p>\n").arg(getGitHub("timoreo22"));
|
||||
stream << QString("<p>Ezekiel Smith (ZekeSmith) %1</p>\n").arg(getGitHub("ZekeSmith"));
|
||||
stream << QString("<p>cozyGalvinism %1</p>\n").arg(getGitHub("cozyGalvinism"));
|
||||
stream << QString("<p>DioEgizio %1</p>\n").arg(getGitHub("DioEgizio"));
|
||||
stream << QString("<p>flowln %1</p>\n").arg(getGitHub("flowln"));
|
||||
stream << QString("<p>ViRb3 %1</p>\n").arg(getGitHub("ViRb3"));
|
||||
stream << QString("<p>Rachel Powers (Ryex) %1</p>\n").arg(getGitHub("Ryex"));
|
||||
stream << QString("<p>TayouVR %1</p>\n").arg(getGitHub("TayouVR"));
|
||||
stream << QString("<p>TheKodeToad %1</p>\n").arg(getGitHub("TheKodeToad"));
|
||||
stream << QString("<p>getchoo %1</p>\n").arg(getGitHub("getchoo"));
|
||||
stream << "<br />\n";
|
||||
|
||||
// TODO: possibly retrieve from git history at build time?
|
||||
@ -96,20 +98,21 @@ QString getCreditsHtml()
|
||||
stream << "<br />\n";
|
||||
|
||||
stream << "<h3>" << QObject::tr("With thanks to", "About Credits") << "</h3>\n";
|
||||
stream << QString("<p>Boba %1</p>\n") .arg(getWebsite("https://bobaonline.neocities.org/"));
|
||||
stream << QString("<p>Davi Rafael %1</p>\n") .arg(getWebsite("https://auti.one/"));
|
||||
stream << QString("<p>Fulmine %1</p>\n") .arg(getWebsite("https://www.fulmine.xyz/"));
|
||||
stream << QString("<p>ely %1</p>\n") .arg(getGitHub("elyrodso"));
|
||||
stream << QString("<p>gon sawa %1</p>\n") .arg(getGitHub("gonsawa"));
|
||||
stream << QString("<p>Boba %1</p>\n").arg(getWebsite("https://bobaonline.neocities.org/"));
|
||||
stream << QString("<p>Davi Rafael %1</p>\n").arg(getWebsite("https://auti.one/"));
|
||||
stream << QString("<p>Fulmine %1</p>\n").arg(getWebsite("https://www.fulmine.xyz/"));
|
||||
stream << QString("<p>ely %1</p>\n").arg(getGitHub("elyrodso"));
|
||||
stream << QString("<p>gon sawa %1</p>\n").arg(getGitHub("gonsawa"));
|
||||
stream << QString("<p>Pankakes</p>\n");
|
||||
stream << QString("<p>tobimori %1</p>\n") .arg(getGitHub("tobimori"));
|
||||
stream << QString("<p>tobimori %1</p>\n").arg(getGitHub("tobimori"));
|
||||
stream << "<p>Orochimarufan <<a href='mailto:orochimarufan.x3@gmail.com'>orochimarufan.x3@gmail.com</a>></p>\n";
|
||||
stream << "<p>TakSuyu <<a href='mailto:taksuyu@gmail.com'>taksuyu@gmail.com</a>></p>\n";
|
||||
stream << "<p>Kilobyte <<a href='mailto:stiepen22@gmx.de'>stiepen22@gmx.de</a>></p>\n";
|
||||
stream << "<p>Rootbear75 <<a href='https://twitter.com/rootbear75'>@rootbear75</a>></p>\n";
|
||||
stream << "<p>Zeker Zhayard <<a href='https://twitter.com/zeker_zhayard'>@Zeker_Zhayard</a>></p>\n";
|
||||
stream << "<p>Everyone who helped establish our branding!</p>\n";
|
||||
stream << "<p>And everyone else who <a href='https://github.com/PrismLauncher/PrismLauncher/graphs/contributors'>contributed</a>!</p>\n";
|
||||
stream
|
||||
<< "<p>And everyone else who <a href='https://github.com/PrismLauncher/PrismLauncher/graphs/contributors'>contributed</a>!</p>\n";
|
||||
stream << "<br />\n";
|
||||
|
||||
stream << "</center>\n";
|
||||
@ -124,9 +127,9 @@ QString getLicenseHtml()
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog)
|
||||
AboutDialog::AboutDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AboutDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -148,7 +151,7 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDia
|
||||
ui->versionLabel->setText(BuildConfig.printableVersionString());
|
||||
|
||||
if (!BuildConfig.BUILD_PLATFORM.isEmpty())
|
||||
ui->platformLabel->setText(tr("Platform") +": " + BuildConfig.BUILD_PLATFORM);
|
||||
ui->platformLabel->setText(tr("Platform") + ": " + BuildConfig.BUILD_PLATFORM);
|
||||
else
|
||||
ui->platformLabel->setVisible(false);
|
||||
|
||||
@ -163,14 +166,14 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDia
|
||||
ui->buildDateLabel->setVisible(false);
|
||||
|
||||
if (!BuildConfig.VERSION_CHANNEL.isEmpty())
|
||||
ui->channelLabel->setText(tr("Channel") +": " + BuildConfig.VERSION_CHANNEL);
|
||||
ui->channelLabel->setText(tr("Channel") + ": " + BuildConfig.VERSION_CHANNEL);
|
||||
else
|
||||
ui->channelLabel->setVisible(false);
|
||||
|
||||
QString urlText("<html><head/><body><p><a href=\"%1\">%1</a></p></body></html>");
|
||||
ui->urlLabel->setText(urlText.arg(BuildConfig.LAUNCHER_GIT));
|
||||
|
||||
QString copyText("© 2022 %1");
|
||||
QString copyText("© 2022-2023 %1");
|
||||
ui->copyLabel->setText(copyText.arg(BuildConfig.LAUNCHER_COPYRIGHT));
|
||||
|
||||
connect(ui->closeButton, SIGNAL(clicked()), SLOT(close()));
|
||||
|
@ -15,26 +15,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <net/NetJob.h>
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class AboutDialog;
|
||||
}
|
||||
|
||||
class AboutDialog : public QDialog
|
||||
{
|
||||
class AboutDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AboutDialog(QWidget *parent = 0);
|
||||
public:
|
||||
explicit AboutDialog(QWidget* parent = 0);
|
||||
~AboutDialog();
|
||||
|
||||
private:
|
||||
Ui::AboutDialog *ui;
|
||||
private:
|
||||
Ui::AboutDialog* ui;
|
||||
|
||||
NetJob::Ptr netJob;
|
||||
QByteArray dataSink;
|
||||
};
|
||||
|
||||
|
@ -313,7 +313,7 @@ bool BlockedModsDialog::checkValidPath(QString path)
|
||||
// efectivly compare two strings ignoring all separators and case
|
||||
auto laxCompare = [](QString fsfilename, QString metadataFilename) {
|
||||
// allowed character seperators
|
||||
QList<QChar> allowedSeperators = { '-', '+', '.' , '_'};
|
||||
QList<QChar> allowedSeperators = { '-', '+', '.', '_' };
|
||||
|
||||
// copy in lowercase
|
||||
auto fsName = fsfilename.toLower();
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -107,8 +107,8 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget* parent)
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
ui->symbolicLinksCheckbox->setIcon(style()->standardIcon(QStyle::SP_VistaShield));
|
||||
ui->symbolicLinksCheckbox->setToolTip(tr("Use symbolic links instead of copying files.") +
|
||||
"\n" + tr("On Windows, symbolic links may require admin permission to create."));
|
||||
ui->symbolicLinksCheckbox->setToolTip(tr("Use symbolic links instead of copying files.") + "\n" +
|
||||
tr("On Windows, symbolic links may require admin permission to create."));
|
||||
#endif
|
||||
|
||||
updateLinkOptions();
|
||||
|
@ -15,13 +15,15 @@
|
||||
|
||||
#include "CustomMessageBox.h"
|
||||
|
||||
namespace CustomMessageBox
|
||||
{
|
||||
QMessageBox *selectable(QWidget *parent, const QString &title, const QString &text,
|
||||
QMessageBox::Icon icon, QMessageBox::StandardButtons buttons,
|
||||
namespace CustomMessageBox {
|
||||
QMessageBox* selectable(QWidget* parent,
|
||||
const QString& title,
|
||||
const QString& text,
|
||||
QMessageBox::Icon icon,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
QMessageBox::StandardButton defaultButton)
|
||||
{
|
||||
QMessageBox *messageBox = new QMessageBox(parent);
|
||||
QMessageBox* messageBox = new QMessageBox(parent);
|
||||
messageBox->setWindowTitle(title);
|
||||
messageBox->setText(text);
|
||||
messageBox->setStandardButtons(buttons);
|
||||
@ -32,4 +34,4 @@ QMessageBox *selectable(QWidget *parent, const QString &title, const QString &te
|
||||
|
||||
return messageBox;
|
||||
}
|
||||
}
|
||||
} // namespace CustomMessageBox
|
||||
|
@ -17,9 +17,10 @@
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
namespace CustomMessageBox
|
||||
{
|
||||
QMessageBox *selectable(QWidget *parent, const QString &title, const QString &text,
|
||||
namespace CustomMessageBox {
|
||||
QMessageBox* selectable(QWidget* parent,
|
||||
const QString& title,
|
||||
const QString& text,
|
||||
QMessageBox::Icon icon = QMessageBox::NoIcon,
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
|
||||
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
|
||||
|
@ -14,12 +14,11 @@
|
||||
*/
|
||||
|
||||
#include "EditAccountDialog.h"
|
||||
#include "ui_EditAccountDialog.h"
|
||||
#include <DesktopServices.h>
|
||||
#include <QUrl>
|
||||
#include "ui_EditAccountDialog.h"
|
||||
|
||||
EditAccountDialog::EditAccountDialog(const QString &text, QWidget *parent, int flags)
|
||||
: QDialog(parent), ui(new Ui::EditAccountDialog)
|
||||
EditAccountDialog::EditAccountDialog(const QString& text, QWidget* parent, int flags) : QDialog(parent), ui(new Ui::EditAccountDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -35,12 +34,12 @@ EditAccountDialog::~EditAccountDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditAccountDialog::on_label_linkActivated(const QString &link)
|
||||
void EditAccountDialog::on_label_linkActivated(const QString& link)
|
||||
{
|
||||
DesktopServices::openUrl(QUrl(link));
|
||||
}
|
||||
|
||||
void EditAccountDialog::setUsername(const QString & user) const
|
||||
void EditAccountDialog::setUsername(const QString& user) const
|
||||
{
|
||||
ui->userTextBox->setText(user);
|
||||
}
|
||||
@ -50,7 +49,7 @@ QString EditAccountDialog::username() const
|
||||
return ui->userTextBox->text();
|
||||
}
|
||||
|
||||
void EditAccountDialog::setPassword(const QString & pass) const
|
||||
void EditAccountDialog::setPassword(const QString& pass) const
|
||||
{
|
||||
ui->passTextBox->setText(pass);
|
||||
}
|
||||
|
@ -17,28 +17,24 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class EditAccountDialog;
|
||||
}
|
||||
|
||||
class EditAccountDialog : public QDialog
|
||||
{
|
||||
class EditAccountDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditAccountDialog(const QString &text = "", QWidget *parent = 0,
|
||||
int flags = UsernameField | PasswordField);
|
||||
public:
|
||||
explicit EditAccountDialog(const QString& text = "", QWidget* parent = 0, int flags = UsernameField | PasswordField);
|
||||
~EditAccountDialog();
|
||||
|
||||
void setUsername(const QString & user) const;
|
||||
void setPassword(const QString & pass) const;
|
||||
void setUsername(const QString& user) const;
|
||||
void setPassword(const QString& pass) const;
|
||||
|
||||
QString username() const;
|
||||
QString password() const;
|
||||
|
||||
enum Flags
|
||||
{
|
||||
enum Flags {
|
||||
NoFlags = 0,
|
||||
|
||||
//! Specifies that the dialog should have a username field.
|
||||
@ -48,9 +44,9 @@ public:
|
||||
PasswordField,
|
||||
};
|
||||
|
||||
private slots:
|
||||
void on_label_linkActivated(const QString &link);
|
||||
private slots:
|
||||
void on_label_linkActivated(const QString& link);
|
||||
|
||||
private:
|
||||
Ui::EditAccountDialog *ui;
|
||||
private:
|
||||
Ui::EditAccountDialog* ui;
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* 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
|
||||
@ -35,24 +36,29 @@
|
||||
*/
|
||||
|
||||
#include "ExportInstanceDialog.h"
|
||||
#include "ui_ExportInstanceDialog.h"
|
||||
#include <BaseInstance.h>
|
||||
#include <MMCZip.h>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QFileSystemModel>
|
||||
#include <QMessageBox>
|
||||
#include "FileIgnoreProxy.h"
|
||||
#include "QObjectPtr.h"
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
#include "ui/dialogs/ProgressDialog.h"
|
||||
#include "ui_ExportInstanceDialog.h"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QDebug>
|
||||
#include <QSaveFile>
|
||||
#include <QStack>
|
||||
#include <QFileInfo>
|
||||
#include "SeparatorPrefixTree.h"
|
||||
#include "Application.h"
|
||||
#include <icons/IconList.h>
|
||||
#include <FileSystem.h>
|
||||
#include <icons/IconList.h>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QSaveFile>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStack>
|
||||
#include <functional>
|
||||
#include "Application.h"
|
||||
#include "SeparatorPrefixTree.h"
|
||||
|
||||
ExportInstanceDialog::ExportInstanceDialog(InstancePtr instance, QWidget *parent)
|
||||
ExportInstanceDialog::ExportInstanceDialog(InstancePtr instance, QWidget* parent)
|
||||
: QDialog(parent), ui(new Ui::ExportInstanceDialog), m_instance(instance)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -60,13 +66,19 @@ ExportInstanceDialog::ExportInstanceDialog(InstancePtr instance, QWidget *parent
|
||||
model->setIconProvider(&icons);
|
||||
auto root = instance->instanceRoot();
|
||||
proxyModel = new FileIgnoreProxy(root, this);
|
||||
loadPackIgnore();
|
||||
proxyModel->setSourceModel(model);
|
||||
auto prefix = QDir(instance->instanceRoot()).relativeFilePath(instance->gameRoot());
|
||||
proxyModel->ignoreFilesWithPath().insert({ FS::PathCombine(prefix, "logs"), FS::PathCombine(prefix, "crash-reports") });
|
||||
proxyModel->ignoreFilesWithName().append({ ".DS_Store", "thumbs.db", "Thumbs.db" });
|
||||
proxyModel->ignoreFilesWithPath().insert(
|
||||
{ FS::PathCombine(prefix, ".cache"), FS::PathCombine(prefix, ".fabric"), FS::PathCombine(prefix, ".quilt") });
|
||||
loadPackIgnore();
|
||||
|
||||
ui->treeView->setModel(proxyModel);
|
||||
ui->treeView->setRootIndex(proxyModel->mapFromSource(model->index(root)));
|
||||
ui->treeView->sortByColumn(0, Qt::AscendingOrder);
|
||||
|
||||
connect(proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(rowsInserted(QModelIndex,int,int)));
|
||||
connect(proxyModel, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(rowsInserted(QModelIndex, int, int)));
|
||||
|
||||
model->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Hidden);
|
||||
model->setRootPath(root);
|
||||
@ -86,32 +98,26 @@ void SaveIcon(InstancePtr m_instance)
|
||||
auto iconKey = m_instance->iconKey();
|
||||
auto iconList = APPLICATION->icons();
|
||||
auto mmcIcon = iconList->icon(iconKey);
|
||||
if(!mmcIcon || mmcIcon->isBuiltIn()) {
|
||||
if (!mmcIcon || mmcIcon->isBuiltIn()) {
|
||||
return;
|
||||
}
|
||||
auto path = mmcIcon->getFilePath();
|
||||
if(!path.isNull()) {
|
||||
QFileInfo inInfo (path);
|
||||
FS::copy(path, FS::PathCombine(m_instance->instanceRoot(), inInfo.fileName())) ();
|
||||
if (!path.isNull()) {
|
||||
QFileInfo inInfo(path);
|
||||
FS::copy(path, FS::PathCombine(m_instance->instanceRoot(), inInfo.fileName()))();
|
||||
return;
|
||||
}
|
||||
auto & image = mmcIcon->m_images[mmcIcon->type()];
|
||||
auto & icon = image.icon;
|
||||
auto& image = mmcIcon->m_images[mmcIcon->type()];
|
||||
auto& icon = image.icon;
|
||||
auto sizes = icon.availableSizes();
|
||||
if(sizes.size() == 0)
|
||||
{
|
||||
if (sizes.size() == 0) {
|
||||
return;
|
||||
}
|
||||
auto areaOf = [](QSize size)
|
||||
{
|
||||
return size.width() * size.height();
|
||||
};
|
||||
auto areaOf = [](QSize size) { return size.width() * size.height(); };
|
||||
QSize largest = sizes[0];
|
||||
// find variant with largest area
|
||||
for(auto size: sizes)
|
||||
{
|
||||
if(areaOf(largest) < areaOf(size))
|
||||
{
|
||||
for (auto size : sizes) {
|
||||
if (areaOf(largest) < areaOf(size)) {
|
||||
largest = size;
|
||||
}
|
||||
}
|
||||
@ -119,66 +125,57 @@ void SaveIcon(InstancePtr m_instance)
|
||||
pixmap.save(FS::PathCombine(m_instance->instanceRoot(), iconKey + ".png"));
|
||||
}
|
||||
|
||||
bool ExportInstanceDialog::doExport()
|
||||
void ExportInstanceDialog::doExport()
|
||||
{
|
||||
auto name = FS::RemoveInvalidFilenameChars(m_instance->name());
|
||||
|
||||
const QString output = QFileDialog::getSaveFileName(
|
||||
this, tr("Export %1").arg(m_instance->name()),
|
||||
FS::PathCombine(QDir::homePath(), name + ".zip"), "Zip (*.zip)", nullptr);
|
||||
if (output.isEmpty())
|
||||
{
|
||||
return false;
|
||||
const QString output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(m_instance->name()),
|
||||
FS::PathCombine(QDir::homePath(), name + ".zip"), "Zip (*.zip)", nullptr);
|
||||
if (output.isEmpty()) {
|
||||
QDialog::done(QDialog::Rejected);
|
||||
return;
|
||||
}
|
||||
|
||||
SaveIcon(m_instance);
|
||||
|
||||
auto & blocked = proxyModel->blockedPaths();
|
||||
using std::placeholders::_1;
|
||||
auto files = QFileInfoList();
|
||||
if (!MMCZip::collectFileListRecursively(m_instance->instanceRoot(), nullptr, &files,
|
||||
std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1))) {
|
||||
std::bind(&FileIgnoreProxy::filterFile, proxyModel, std::placeholders::_1))) {
|
||||
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
||||
return false;
|
||||
QDialog::done(QDialog::Rejected);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MMCZip::compressDirFiles(output, m_instance->instanceRoot(), files, true))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
auto task = makeShared<MMCZip::ExportToZipTask>(output, m_instance->instanceRoot(), files, "", true);
|
||||
|
||||
connect(task.get(), &Task::failed, this,
|
||||
[this, output](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
|
||||
connect(task.get(), &Task::finished, this, [task] { task->deleteLater(); });
|
||||
|
||||
ProgressDialog progress(this);
|
||||
progress.setSkipButton(true, tr("Abort"));
|
||||
auto result = progress.execWithTask(task.get());
|
||||
QDialog::done(result);
|
||||
}
|
||||
|
||||
void ExportInstanceDialog::done(int result)
|
||||
{
|
||||
savePackIgnore();
|
||||
if (result == QDialog::Accepted)
|
||||
{
|
||||
if (doExport())
|
||||
{
|
||||
QDialog::done(QDialog::Accepted);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (result == QDialog::Accepted) {
|
||||
doExport();
|
||||
return;
|
||||
}
|
||||
QDialog::done(result);
|
||||
}
|
||||
|
||||
void ExportInstanceDialog::rowsInserted(QModelIndex parent, int top, int bottom)
|
||||
{
|
||||
//WARNING: possible off-by-one?
|
||||
for(int i = top; i < bottom; i++)
|
||||
{
|
||||
// WARNING: possible off-by-one?
|
||||
for (int i = top; i < bottom; i++) {
|
||||
auto node = proxyModel->index(i, 0, parent);
|
||||
if(proxyModel->shouldExpand(node))
|
||||
{
|
||||
if (proxyModel->shouldExpand(node)) {
|
||||
auto expNode = node.parent();
|
||||
if(!expNode.isValid())
|
||||
{
|
||||
if (!expNode.isValid()) {
|
||||
continue;
|
||||
}
|
||||
ui->treeView->expand(node);
|
||||
@ -195,8 +192,7 @@ void ExportInstanceDialog::loadPackIgnore()
|
||||
{
|
||||
auto filename = ignoreFileName();
|
||||
QFile ignoreFile(filename);
|
||||
if(!ignoreFile.open(QIODevice::ReadOnly))
|
||||
{
|
||||
if (!ignoreFile.open(QIODevice::ReadOnly)) {
|
||||
return;
|
||||
}
|
||||
auto data = ignoreFile.readAll();
|
||||
@ -212,12 +208,9 @@ void ExportInstanceDialog::savePackIgnore()
|
||||
{
|
||||
auto data = proxyModel->blockedPaths().toStringList().join('\n').toUtf8();
|
||||
auto filename = ignoreFileName();
|
||||
try
|
||||
{
|
||||
try {
|
||||
FS::write(filename, data);
|
||||
}
|
||||
catch (const Exception &e)
|
||||
{
|
||||
} catch (const Exception& e) {
|
||||
qWarning() << e.cause();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* 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
|
||||
@ -38,39 +39,37 @@
|
||||
#include <QDialog>
|
||||
#include <QModelIndex>
|
||||
#include <memory>
|
||||
#include "FileIgnoreProxy.h"
|
||||
#include "FastFileIconProvider.h"
|
||||
#include "FileIgnoreProxy.h"
|
||||
|
||||
class BaseInstance;
|
||||
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class ExportInstanceDialog;
|
||||
}
|
||||
|
||||
class ExportInstanceDialog : public QDialog
|
||||
{
|
||||
class ExportInstanceDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ExportInstanceDialog(InstancePtr instance, QWidget *parent = 0);
|
||||
public:
|
||||
explicit ExportInstanceDialog(InstancePtr instance, QWidget* parent = 0);
|
||||
~ExportInstanceDialog();
|
||||
|
||||
virtual void done(int result);
|
||||
|
||||
private:
|
||||
bool doExport();
|
||||
private:
|
||||
void doExport();
|
||||
void loadPackIgnore();
|
||||
void savePackIgnore();
|
||||
QString ignoreFileName();
|
||||
|
||||
private:
|
||||
Ui::ExportInstanceDialog *ui;
|
||||
private:
|
||||
Ui::ExportInstanceDialog* ui;
|
||||
InstancePtr m_instance;
|
||||
FileIgnoreProxy * proxyModel;
|
||||
FileIgnoreProxy* proxyModel;
|
||||
FastFileIconProvider icons;
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void rowsInserted(QModelIndex parent, int top, int bottom);
|
||||
};
|
||||
|
@ -16,11 +16,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ExportMrPackDialog.h"
|
||||
#include "ExportPackDialog.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "modplatform/flame/FlamePackExportTask.h"
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
#include "ui/dialogs/ProgressDialog.h"
|
||||
#include "ui_ExportMrPackDialog.h"
|
||||
#include "ui_ExportPackDialog.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFileSystemModel>
|
||||
@ -32,17 +34,24 @@
|
||||
#include "MMCZip.h"
|
||||
#include "modplatform/modrinth/ModrinthPackExportTask.h"
|
||||
|
||||
ExportMrPackDialog::ExportMrPackDialog(InstancePtr instance, QWidget* parent)
|
||||
: QDialog(parent), instance(instance), ui(new Ui::ExportMrPackDialog)
|
||||
ExportPackDialog::ExportPackDialog(InstancePtr instance, QWidget* parent, ModPlatform::ResourceProvider provider)
|
||||
: QDialog(parent), instance(instance), ui(new Ui::ExportPackDialog), m_provider(provider)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->name->setText(instance->name());
|
||||
ui->summary->setText(instance->notes().split(QRegularExpression("\\r?\\n"))[0]);
|
||||
if (m_provider == ModPlatform::ResourceProvider::MODRINTH) {
|
||||
ui->summary->setText(instance->notes().split(QRegularExpression("\\r?\\n"))[0]);
|
||||
setWindowTitle("Export Modrinth Pack");
|
||||
} else {
|
||||
setWindowTitle("Export CurseForge Pack");
|
||||
ui->version->setText("");
|
||||
ui->summaryLabel->setText("Author");
|
||||
}
|
||||
|
||||
// ensure a valid pack is generated
|
||||
// the name and version fields mustn't be empty
|
||||
connect(ui->name, &QLineEdit::textEdited, this, &ExportMrPackDialog::validate);
|
||||
connect(ui->version, &QLineEdit::textEdited, this, &ExportMrPackDialog::validate);
|
||||
connect(ui->name, &QLineEdit::textEdited, this, &ExportPackDialog::validate);
|
||||
connect(ui->version, &QLineEdit::textEdited, this, &ExportPackDialog::validate);
|
||||
// the instance name can technically be empty
|
||||
validate();
|
||||
|
||||
@ -52,8 +61,9 @@ ExportMrPackDialog::ExportMrPackDialog(InstancePtr instance, QWidget* parent)
|
||||
// use the game root - everything outside cannot be exported
|
||||
const QDir root(instance->gameRoot());
|
||||
proxy = new FileIgnoreProxy(instance->gameRoot(), this);
|
||||
proxy->ignoreFilesWithPath().insert({ "logs", "crash-reports", ".cache", ".fabric", ".quilt" });
|
||||
proxy->ignoreFilesWithName().append({ ".DS_Store", "thumbs.db", "Thumbs.db" });
|
||||
proxy->setSourceModel(model);
|
||||
proxy->setFilterRegularExpression("^(?!(\\.DS_Store)|([tT]humbs\\.db)).+$");
|
||||
|
||||
const QDir::Filters filter(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Hidden);
|
||||
|
||||
@ -65,6 +75,7 @@ ExportMrPackDialog::ExportMrPackDialog(InstancePtr instance, QWidget* parent)
|
||||
|
||||
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
|
||||
if (mcInstance) {
|
||||
mcInstance->loaderModList()->update();
|
||||
const QDir index = mcInstance->loaderModList()->indexDir();
|
||||
if (index.exists())
|
||||
proxy->blockedPaths().insert(root.relativeFilePath(index.absolutePath()));
|
||||
@ -82,43 +93,54 @@ ExportMrPackDialog::ExportMrPackDialog(InstancePtr instance, QWidget* parent)
|
||||
headerView->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
ExportMrPackDialog::~ExportMrPackDialog()
|
||||
ExportPackDialog::~ExportPackDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ExportMrPackDialog::done(int result)
|
||||
void ExportPackDialog::done(int result)
|
||||
{
|
||||
if (result == Accepted) {
|
||||
const QString filename = FS::RemoveInvalidFilenameChars(ui->name->text());
|
||||
const QString output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()),
|
||||
FS::PathCombine(QDir::homePath(), filename + ".mrpack"),
|
||||
"Modrinth pack (*.mrpack *.zip)", nullptr);
|
||||
QString output;
|
||||
if (m_provider == ModPlatform::ResourceProvider::MODRINTH)
|
||||
output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()),
|
||||
FS::PathCombine(QDir::homePath(), filename + ".mrpack"), "Modrinth pack (*.mrpack *.zip)",
|
||||
nullptr);
|
||||
else
|
||||
output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()),
|
||||
FS::PathCombine(QDir::homePath(), filename + ".zip"), "CurseForge pack (*.zip)", nullptr);
|
||||
|
||||
if (output.isEmpty())
|
||||
return;
|
||||
Task* task;
|
||||
if (m_provider == ModPlatform::ResourceProvider::MODRINTH)
|
||||
task = new ModrinthPackExportTask(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
|
||||
std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
|
||||
else
|
||||
task = new FlamePackExportTask(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
|
||||
std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
|
||||
|
||||
ModrinthPackExportTask task(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
|
||||
[this](const QString& path) { return proxy->blockedPaths().covers(path); });
|
||||
|
||||
connect(&task, &Task::failed,
|
||||
connect(task, &Task::failed,
|
||||
[this](const QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
|
||||
connect(&task, &Task::aborted, [this] {
|
||||
connect(task, &Task::aborted, [this] {
|
||||
CustomMessageBox::selectable(this, tr("Task aborted"), tr("The task has been aborted by the user."), QMessageBox::Information)
|
||||
->show();
|
||||
});
|
||||
connect(task, &Task::finished, [task] { task->deleteLater(); });
|
||||
|
||||
ProgressDialog progress(this);
|
||||
progress.setSkipButton(true, tr("Abort"));
|
||||
if (progress.execWithTask(&task) != QDialog::Accepted)
|
||||
if (progress.execWithTask(task) != QDialog::Accepted)
|
||||
return;
|
||||
}
|
||||
|
||||
QDialog::done(result);
|
||||
}
|
||||
|
||||
void ExportMrPackDialog::validate()
|
||||
void ExportPackDialog::validate()
|
||||
{
|
||||
const bool invalid = ui->name->text().isEmpty() || ui->version->text().isEmpty();
|
||||
const bool invalid =
|
||||
ui->name->text().isEmpty() || ((m_provider == ModPlatform::ResourceProvider::MODRINTH) && ui->version->text().isEmpty());
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(invalid);
|
||||
}
|
@ -22,24 +22,28 @@
|
||||
#include "BaseInstance.h"
|
||||
#include "FastFileIconProvider.h"
|
||||
#include "FileIgnoreProxy.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
|
||||
namespace Ui {
|
||||
class ExportMrPackDialog;
|
||||
class ExportPackDialog;
|
||||
}
|
||||
|
||||
class ExportMrPackDialog : public QDialog {
|
||||
class ExportPackDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ExportMrPackDialog(InstancePtr instance, QWidget* parent = nullptr);
|
||||
~ExportMrPackDialog();
|
||||
explicit ExportPackDialog(InstancePtr instance,
|
||||
QWidget* parent = nullptr,
|
||||
ModPlatform::ResourceProvider provider = ModPlatform::ResourceProvider::MODRINTH);
|
||||
~ExportPackDialog();
|
||||
|
||||
void done(int result) override;
|
||||
void validate();
|
||||
|
||||
private:
|
||||
const InstancePtr instance;
|
||||
Ui::ExportMrPackDialog* ui;
|
||||
Ui::ExportPackDialog* ui;
|
||||
FileIgnoreProxy* proxy;
|
||||
FastFileIconProvider icons;
|
||||
const ModPlatform::ResourceProvider m_provider;
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ExportMrPackDialog</class>
|
||||
<widget class="QDialog" name="ExportMrPackDialog">
|
||||
<class>ExportPackDialog</class>
|
||||
<widget class="QDialog" name="ExportPackDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Export Modrinth Pack</string>
|
||||
<string>Export Pack</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
@ -24,7 +24,7 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="versionLabel">
|
||||
<widget class="QLabel" name="summaryLabel">
|
||||
<property name="text">
|
||||
<string>Summary</string>
|
||||
</property>
|
||||
@ -41,7 +41,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="summaryLabel">
|
||||
<widget class="QLabel" name="versionLabel">
|
||||
<property name="text">
|
||||
<string>Version</string>
|
||||
</property>
|
||||
@ -57,6 +57,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -103,7 +104,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ExportMrPackDialog</receiver>
|
||||
<receiver>ExportPackDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
@ -119,7 +120,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ExportMrPackDialog</receiver>
|
||||
<receiver>ExportPackDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
223
launcher/ui/dialogs/ExportToModListDialog.cpp
Normal file
223
launcher/ui/dialogs/ExportToModListDialog.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 "ExportToModListDialog.h"
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QTextEdit>
|
||||
#include "FileSystem.h"
|
||||
#include "Markdown.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "modplatform/helpers/ExportToModList.h"
|
||||
#include "ui_ExportToModListDialog.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFileSystemModel>
|
||||
#include <QJsonDocument>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
|
||||
const QHash<ExportToModList::Formats, QString> ExportToModListDialog::exampleLines = {
|
||||
{ ExportToModList::HTML, "<li><a href=\"{url}\">{name}</a> [{version}] by {authors}</li>" },
|
||||
{ ExportToModList::MARKDOWN, "[{name}]({url}) [{version}] by {authors}" },
|
||||
{ ExportToModList::PLAINTXT, "{name} ({url}) [{version}] by {authors}" },
|
||||
{ ExportToModList::JSON, "{\"name\":\"{name}\",\"url\":\"{url}\",\"version\":\"{version}\",\"authors\":\"{authors}\"}," },
|
||||
{ ExportToModList::CSV, "{name},{url},{version},\"{authors}\"" },
|
||||
};
|
||||
|
||||
ExportToModListDialog::ExportToModListDialog(InstancePtr instance, QWidget* parent)
|
||||
: QDialog(parent), m_template_changed(false), name(instance->name()), ui(new Ui::ExportToModListDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
enableCustom(false);
|
||||
|
||||
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
|
||||
if (mcInstance) {
|
||||
mcInstance->loaderModList()->update();
|
||||
connect(mcInstance->loaderModList().get(), &ModFolderModel::updateFinished, this, [this, mcInstance]() {
|
||||
m_allMods = mcInstance->loaderModList()->allMods();
|
||||
triggerImp();
|
||||
});
|
||||
}
|
||||
|
||||
connect(ui->formatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ExportToModListDialog::formatChanged);
|
||||
connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||
connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||
connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||
connect(ui->authorsButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Authors); });
|
||||
connect(ui->versionButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Version); });
|
||||
connect(ui->urlButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Url); });
|
||||
connect(ui->templateText, &QTextEdit::textChanged, this, [this] {
|
||||
if (ui->templateText->toPlainText() != exampleLines[format])
|
||||
ui->formatComboBox->setCurrentIndex(5);
|
||||
else
|
||||
triggerImp();
|
||||
});
|
||||
connect(ui->copyButton, &QPushButton::clicked, this, [this](bool) {
|
||||
this->ui->finalText->selectAll();
|
||||
this->ui->finalText->copy();
|
||||
});
|
||||
}
|
||||
|
||||
ExportToModListDialog::~ExportToModListDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ExportToModListDialog::formatChanged(int index)
|
||||
{
|
||||
switch (index) {
|
||||
case 0: {
|
||||
enableCustom(false);
|
||||
ui->resultText->show();
|
||||
format = ExportToModList::HTML;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
enableCustom(false);
|
||||
ui->resultText->show();
|
||||
format = ExportToModList::MARKDOWN;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
enableCustom(false);
|
||||
ui->resultText->hide();
|
||||
format = ExportToModList::PLAINTXT;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
enableCustom(false);
|
||||
ui->resultText->hide();
|
||||
format = ExportToModList::JSON;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
enableCustom(false);
|
||||
ui->resultText->hide();
|
||||
format = ExportToModList::CSV;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
m_template_changed = true;
|
||||
enableCustom(true);
|
||||
ui->resultText->hide();
|
||||
format = ExportToModList::CUSTOM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
triggerImp();
|
||||
}
|
||||
|
||||
void ExportToModListDialog::triggerImp()
|
||||
{
|
||||
if (format == ExportToModList::CUSTOM) {
|
||||
ui->finalText->setPlainText(ExportToModList::exportToModList(m_allMods, ui->templateText->toPlainText()));
|
||||
return;
|
||||
}
|
||||
auto opt = 0;
|
||||
if (ui->authorsCheckBox->isChecked())
|
||||
opt |= ExportToModList::Authors;
|
||||
if (ui->versionCheckBox->isChecked())
|
||||
opt |= ExportToModList::Version;
|
||||
if (ui->urlCheckBox->isChecked())
|
||||
opt |= ExportToModList::Url;
|
||||
auto txt = ExportToModList::exportToModList(m_allMods, format, static_cast<ExportToModList::OptionalData>(opt));
|
||||
ui->finalText->setPlainText(txt);
|
||||
switch (format) {
|
||||
case ExportToModList::CUSTOM:
|
||||
return;
|
||||
case ExportToModList::HTML:
|
||||
ui->resultText->setHtml(txt);
|
||||
break;
|
||||
case ExportToModList::MARKDOWN:
|
||||
ui->resultText->setHtml(markdownToHTML(txt));
|
||||
break;
|
||||
case ExportToModList::PLAINTXT:
|
||||
break;
|
||||
case ExportToModList::JSON:
|
||||
break;
|
||||
case ExportToModList::CSV:
|
||||
break;
|
||||
}
|
||||
auto exampleLine = exampleLines[format];
|
||||
if (!m_template_changed && ui->templateText->toPlainText() != exampleLine)
|
||||
ui->templateText->setPlainText(exampleLine);
|
||||
}
|
||||
|
||||
void ExportToModListDialog::done(int result)
|
||||
{
|
||||
if (result == Accepted) {
|
||||
const QString filename = FS::RemoveInvalidFilenameChars(name);
|
||||
const QString output =
|
||||
QFileDialog::getSaveFileName(this, tr("Export %1").arg(name), FS::PathCombine(QDir::homePath(), filename + extension()),
|
||||
"File (*.txt *.html *.md *.json *.csv)", nullptr);
|
||||
|
||||
if (output.isEmpty())
|
||||
return;
|
||||
FS::write(output, ui->finalText->toPlainText().toUtf8());
|
||||
}
|
||||
|
||||
QDialog::done(result);
|
||||
}
|
||||
|
||||
QString ExportToModListDialog::extension()
|
||||
{
|
||||
switch (format) {
|
||||
case ExportToModList::HTML:
|
||||
return ".html";
|
||||
case ExportToModList::MARKDOWN:
|
||||
return ".md";
|
||||
case ExportToModList::PLAINTXT:
|
||||
return ".txt";
|
||||
case ExportToModList::CUSTOM:
|
||||
return ".txt";
|
||||
case ExportToModList::JSON:
|
||||
return ".json";
|
||||
case ExportToModList::CSV:
|
||||
return ".csv";
|
||||
}
|
||||
return ".txt";
|
||||
}
|
||||
|
||||
void ExportToModListDialog::addExtra(ExportToModList::OptionalData option)
|
||||
{
|
||||
if (format != ExportToModList::CUSTOM)
|
||||
return;
|
||||
switch (option) {
|
||||
case ExportToModList::Authors:
|
||||
ui->templateText->insertPlainText("{authors}");
|
||||
break;
|
||||
case ExportToModList::Url:
|
||||
ui->templateText->insertPlainText("{url}");
|
||||
break;
|
||||
case ExportToModList::Version:
|
||||
ui->templateText->insertPlainText("{version}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
void ExportToModListDialog::enableCustom(bool enabled)
|
||||
{
|
||||
ui->authorsCheckBox->setHidden(enabled);
|
||||
ui->versionCheckBox->setHidden(enabled);
|
||||
ui->urlCheckBox->setHidden(enabled);
|
||||
|
||||
ui->authorsButton->setHidden(!enabled);
|
||||
ui->versionButton->setHidden(!enabled);
|
||||
ui->urlButton->setHidden(!enabled);
|
||||
}
|
55
launcher/ui/dialogs/ExportToModListDialog.h
Normal file
55
launcher/ui/dialogs/ExportToModListDialog.h
Normal file
@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QList>
|
||||
#include "BaseInstance.h"
|
||||
#include "minecraft/mod/Mod.h"
|
||||
#include "modplatform/helpers/ExportToModList.h"
|
||||
|
||||
namespace Ui {
|
||||
class ExportToModListDialog;
|
||||
}
|
||||
|
||||
class ExportToModListDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ExportToModListDialog(InstancePtr instance, QWidget* parent = nullptr);
|
||||
~ExportToModListDialog();
|
||||
|
||||
void done(int result) override;
|
||||
|
||||
protected slots:
|
||||
void formatChanged(int index);
|
||||
void triggerImp();
|
||||
void trigger(int) { triggerImp(); };
|
||||
void addExtra(ExportToModList::OptionalData option);
|
||||
|
||||
private:
|
||||
QString extension();
|
||||
void enableCustom(bool enabled);
|
||||
QList<Mod*> m_allMods;
|
||||
bool m_template_changed;
|
||||
QString name;
|
||||
ExportToModList::Formats format = ExportToModList::Formats::HTML;
|
||||
Ui::ExportToModListDialog* ui;
|
||||
static const QHash<ExportToModList::Formats, QString> exampleLines;
|
||||
};
|
240
launcher/ui/dialogs/ExportToModListDialog.ui
Normal file
240
launcher/ui/dialogs/ExportToModListDialog.ui
Normal file
@ -0,0 +1,240 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ExportToModListDialog</class>
|
||||
<widget class="QDialog" name="ExportToModListDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>650</width>
|
||||
<height>446</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Export Pack to ModList</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="formatComboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>HTML</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Markdown</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Plaintext</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>JSON</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>CSV</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Custom</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="templateGroup">
|
||||
<property name="title">
|
||||
<string>Template</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="templateText"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QGroupBox" name="optionsGroup">
|
||||
<property name="title">
|
||||
<string>Optional Info</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="versionCheckBox">
|
||||
<property name="text">
|
||||
<string>Version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="authorsCheckBox">
|
||||
<property name="text">
|
||||
<string>Authors</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="urlCheckBox">
|
||||
<property name="text">
|
||||
<string>URL</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="versionButton">
|
||||
<property name="text">
|
||||
<string>Version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="authorsButton">
|
||||
<property name="text">
|
||||
<string>Authors</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="urlButton">
|
||||
<property name="text">
|
||||
<string>URL</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Format</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
<string>Result</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="finalText">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>143</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="resultText">
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="warningLabel">
|
||||
<property name="text">
|
||||
<string>This depends on the mods' metadata. To ensure it is available, run an update on the instance. Installing the updates isn't necessary.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="copyButton">
|
||||
<property name="text">
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ExportToModListDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>334</x>
|
||||
<y>435</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>324</x>
|
||||
<y>206</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ExportToModListDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>324</x>
|
||||
<y>390</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>324</x>
|
||||
<y>206</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -13,9 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QKeyEvent>
|
||||
#include <QPushButton>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
@ -24,12 +24,11 @@
|
||||
|
||||
#include "ui/instanceview/InstanceDelegate.h"
|
||||
|
||||
#include <DesktopServices.h>
|
||||
#include "icons/IconList.h"
|
||||
#include "icons/IconUtils.h"
|
||||
#include <DesktopServices.h>
|
||||
|
||||
IconPickerDialog::IconPickerDialog(QWidget *parent)
|
||||
: QDialog(parent), ui(new Ui::IconPickerDialog)
|
||||
IconPickerDialog::IconPickerDialog(QWidget* parent) : QDialog(parent), ui(new Ui::IconPickerDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
@ -69,31 +68,30 @@ IconPickerDialog::IconPickerDialog(QWidget *parent)
|
||||
|
||||
connect(contentsWidget, SIGNAL(doubleClicked(QModelIndex)), SLOT(activated(QModelIndex)));
|
||||
|
||||
connect(contentsWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(selectionChanged(QItemSelection, QItemSelection)));
|
||||
connect(contentsWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||
SLOT(selectionChanged(QItemSelection, QItemSelection)));
|
||||
|
||||
auto buttonFolder = ui->buttonBox->addButton(tr("Open Folder"), QDialogButtonBox::ResetRole);
|
||||
connect(buttonFolder, &QPushButton::clicked, this, &IconPickerDialog::openFolder);
|
||||
}
|
||||
|
||||
bool IconPickerDialog::eventFilter(QObject *obj, QEvent *evt)
|
||||
bool IconPickerDialog::eventFilter(QObject* obj, QEvent* evt)
|
||||
{
|
||||
if (obj != ui->iconView)
|
||||
return QDialog::eventFilter(obj, evt);
|
||||
if (evt->type() != QEvent::KeyPress)
|
||||
{
|
||||
if (evt->type() != QEvent::KeyPress) {
|
||||
return QDialog::eventFilter(obj, evt);
|
||||
}
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(evt);
|
||||
switch (keyEvent->key())
|
||||
{
|
||||
case Qt::Key_Delete:
|
||||
removeSelectedIcon();
|
||||
return true;
|
||||
case Qt::Key_Plus:
|
||||
addNewIcon();
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(evt);
|
||||
switch (keyEvent->key()) {
|
||||
case Qt::Key_Delete:
|
||||
removeSelectedIcon();
|
||||
return true;
|
||||
case Qt::Key_Plus:
|
||||
addNewIcon();
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QDialog::eventFilter(obj, evt);
|
||||
}
|
||||
@ -142,8 +140,7 @@ int IconPickerDialog::execWithSelection(QString selection)
|
||||
|
||||
int index_nr = list->getIconIndex(selection);
|
||||
auto model_index = list->index(index_nr);
|
||||
contentsWidget->selectionModel()->select(
|
||||
model_index, QItemSelectionModel::Current | QItemSelectionModel::Select);
|
||||
contentsWidget->selectionModel()->select(model_index, QItemSelectionModel::Current | QItemSelectionModel::Select);
|
||||
|
||||
QMetaObject::invokeMethod(this, "delayed_scroll", Qt::QueuedConnection, Q_ARG(QModelIndex, model_index));
|
||||
return QDialog::exec();
|
||||
|
@ -17,30 +17,27 @@
|
||||
#include <QDialog>
|
||||
#include <QItemSelection>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class IconPickerDialog;
|
||||
}
|
||||
|
||||
class IconPickerDialog : public QDialog
|
||||
{
|
||||
class IconPickerDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IconPickerDialog(QWidget *parent = 0);
|
||||
public:
|
||||
explicit IconPickerDialog(QWidget* parent = 0);
|
||||
~IconPickerDialog();
|
||||
int execWithSelection(QString selection);
|
||||
QString selectedIconKey;
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject *, QEvent *);
|
||||
protected:
|
||||
virtual bool eventFilter(QObject*, QEvent*);
|
||||
|
||||
private:
|
||||
Ui::IconPickerDialog *ui;
|
||||
QPushButton *buttonRemove;
|
||||
private:
|
||||
Ui::IconPickerDialog* ui;
|
||||
QPushButton* buttonRemove;
|
||||
|
||||
private
|
||||
slots:
|
||||
private slots:
|
||||
void selectionChanged(QItemSelection, QItemSelection);
|
||||
void activated(QModelIndex);
|
||||
void delayed_scroll(QModelIndex);
|
||||
|
@ -17,7 +17,7 @@ class ImportResourceDialog : public QDialog {
|
||||
explicit ImportResourceDialog(QString file_path, PackedResourceType type, QWidget* parent = nullptr);
|
||||
~ImportResourceDialog() override;
|
||||
QString selectedInstanceKey;
|
||||
|
||||
|
||||
private:
|
||||
Ui::ImportResourceDialog* ui;
|
||||
PackedResourceType m_resource_type;
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LoginDialog)
|
||||
LoginDialog::LoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::LoginDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->progressBar->setVisible(false);
|
||||
@ -59,27 +59,24 @@ void LoginDialog::setUserInputsEnabled(bool enable)
|
||||
}
|
||||
|
||||
// Enable the OK button only when both textboxes contain something.
|
||||
void LoginDialog::on_userTextBox_textEdited(const QString &newText)
|
||||
void LoginDialog::on_userTextBox_textEdited(const QString& newText)
|
||||
{
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)
|
||||
->setEnabled(!newText.isEmpty() && !ui->passTextBox->text().isEmpty());
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!newText.isEmpty() && !ui->passTextBox->text().isEmpty());
|
||||
}
|
||||
void LoginDialog::on_passTextBox_textEdited(const QString &newText)
|
||||
void LoginDialog::on_passTextBox_textEdited(const QString& newText)
|
||||
{
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)
|
||||
->setEnabled(!newText.isEmpty() && !ui->userTextBox->text().isEmpty());
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!newText.isEmpty() && !ui->userTextBox->text().isEmpty());
|
||||
}
|
||||
|
||||
void LoginDialog::onTaskFailed(const QString &reason)
|
||||
void LoginDialog::onTaskFailed(const QString& reason)
|
||||
{
|
||||
// Set message
|
||||
auto lines = reason.split('\n');
|
||||
QString processed;
|
||||
for(auto line: lines) {
|
||||
if(line.size()) {
|
||||
for (auto line : lines) {
|
||||
if (line.size()) {
|
||||
processed += "<font color='red'>" + line + "</font><br />";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
processed += "<br />";
|
||||
}
|
||||
}
|
||||
@ -95,7 +92,7 @@ void LoginDialog::onTaskSucceeded()
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void LoginDialog::onTaskStatus(const QString &status)
|
||||
void LoginDialog::onTaskStatus(const QString& status)
|
||||
{
|
||||
ui->label->setText(status);
|
||||
}
|
||||
@ -107,12 +104,11 @@ void LoginDialog::onTaskProgress(qint64 current, qint64 total)
|
||||
}
|
||||
|
||||
// Public interface
|
||||
MinecraftAccountPtr LoginDialog::newAccount(QWidget *parent, QString msg)
|
||||
MinecraftAccountPtr LoginDialog::newAccount(QWidget* parent, QString msg)
|
||||
{
|
||||
LoginDialog dlg(parent);
|
||||
dlg.ui->label->setText(msg);
|
||||
if (dlg.exec() == QDialog::Accepted)
|
||||
{
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
return dlg.m_account;
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -15,45 +15,42 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QtWidgets/QDialog>
|
||||
|
||||
#include "minecraft/auth/MinecraftAccount.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class LoginDialog;
|
||||
}
|
||||
|
||||
class LoginDialog : public QDialog
|
||||
{
|
||||
class LoginDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
~LoginDialog();
|
||||
|
||||
static MinecraftAccountPtr newAccount(QWidget *parent, QString message);
|
||||
static MinecraftAccountPtr newAccount(QWidget* parent, QString message);
|
||||
|
||||
private:
|
||||
explicit LoginDialog(QWidget *parent = 0);
|
||||
private:
|
||||
explicit LoginDialog(QWidget* parent = 0);
|
||||
|
||||
void setUserInputsEnabled(bool enable);
|
||||
|
||||
protected
|
||||
slots:
|
||||
protected slots:
|
||||
void accept();
|
||||
|
||||
void onTaskFailed(const QString &reason);
|
||||
void onTaskFailed(const QString& reason);
|
||||
void onTaskSucceeded();
|
||||
void onTaskStatus(const QString &status);
|
||||
void onTaskStatus(const QString& status);
|
||||
void onTaskProgress(qint64 current, qint64 total);
|
||||
|
||||
void on_userTextBox_textEdited(const QString &newText);
|
||||
void on_passTextBox_textEdited(const QString &newText);
|
||||
void on_userTextBox_textEdited(const QString& newText);
|
||||
void on_passTextBox_textEdited(const QString& newText);
|
||||
|
||||
private:
|
||||
Ui::LoginDialog *ui;
|
||||
private:
|
||||
Ui::LoginDialog* ui;
|
||||
MinecraftAccountPtr m_account;
|
||||
Task::Ptr m_loginTask;
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -39,12 +39,12 @@
|
||||
#include "DesktopServices.h"
|
||||
#include "minecraft/auth/AccountTask.h"
|
||||
|
||||
#include <QtWidgets/QPushButton>
|
||||
#include <QUrl>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QUrl>
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
MSALoginDialog::MSALoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MSALoginDialog)
|
||||
MSALoginDialog::MSALoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::MSALoginDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->progressBar->setVisible(false);
|
||||
@ -55,7 +55,8 @@ MSALoginDialog::MSALoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MS
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
}
|
||||
|
||||
int MSALoginDialog::exec() {
|
||||
int MSALoginDialog::exec()
|
||||
{
|
||||
setUserInputsEnabled(false);
|
||||
ui->progressBar->setVisible(true);
|
||||
|
||||
@ -74,24 +75,24 @@ int MSALoginDialog::exec() {
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
|
||||
MSALoginDialog::~MSALoginDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MSALoginDialog::externalLoginTick() {
|
||||
void MSALoginDialog::externalLoginTick()
|
||||
{
|
||||
m_externalLoginElapsed++;
|
||||
ui->progressBar->setValue(m_externalLoginElapsed);
|
||||
ui->progressBar->repaint();
|
||||
|
||||
if(m_externalLoginElapsed >= m_externalLoginTimeout) {
|
||||
if (m_externalLoginElapsed >= m_externalLoginTimeout) {
|
||||
m_externalLoginTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MSALoginDialog::showVerificationUriAndCode(const QUrl& uri, const QString& code, int expiresIn) {
|
||||
void MSALoginDialog::showVerificationUriAndCode(const QUrl& uri, const QString& code, int expiresIn)
|
||||
{
|
||||
m_externalLoginElapsed = 0;
|
||||
m_externalLoginTimeout = expiresIn;
|
||||
|
||||
@ -104,7 +105,8 @@ void MSALoginDialog::showVerificationUriAndCode(const QUrl& uri, const QString&
|
||||
|
||||
QString urlString = uri.toString();
|
||||
QString linkString = QString("<a href=\"%1\">%2</a>").arg(urlString, urlString);
|
||||
ui->label->setText(tr("<p>Please open up %1 in a browser and put in the code <b>%2</b> to proceed with login.</p>").arg(linkString, code));
|
||||
ui->label->setText(
|
||||
tr("<p>Please open up %1 in a browser and put in the code <b>%2</b> to proceed with login.</p>").arg(linkString, code));
|
||||
ui->actionButton->setVisible(true);
|
||||
connect(ui->actionButton, &QPushButton::clicked, [=]() {
|
||||
DesktopServices::openUrl(uri);
|
||||
@ -113,7 +115,8 @@ void MSALoginDialog::showVerificationUriAndCode(const QUrl& uri, const QString&
|
||||
});
|
||||
}
|
||||
|
||||
void MSALoginDialog::hideVerificationUriAndCode() {
|
||||
void MSALoginDialog::hideVerificationUriAndCode()
|
||||
{
|
||||
m_externalLoginTimer.stop();
|
||||
ui->actionButton->setVisible(false);
|
||||
}
|
||||
@ -123,16 +126,15 @@ void MSALoginDialog::setUserInputsEnabled(bool enable)
|
||||
ui->buttonBox->setEnabled(enable);
|
||||
}
|
||||
|
||||
void MSALoginDialog::onTaskFailed(const QString &reason)
|
||||
void MSALoginDialog::onTaskFailed(const QString& reason)
|
||||
{
|
||||
// Set message
|
||||
auto lines = reason.split('\n');
|
||||
QString processed;
|
||||
for(auto line: lines) {
|
||||
if(line.size()) {
|
||||
for (auto line : lines) {
|
||||
if (line.size()) {
|
||||
processed += "<font color='red'>" + line + "</font><br />";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
processed += "<br />";
|
||||
}
|
||||
}
|
||||
@ -149,7 +151,7 @@ void MSALoginDialog::onTaskSucceeded()
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void MSALoginDialog::onTaskStatus(const QString &status)
|
||||
void MSALoginDialog::onTaskStatus(const QString& status)
|
||||
{
|
||||
ui->label->setText(status);
|
||||
}
|
||||
@ -161,12 +163,11 @@ void MSALoginDialog::onTaskProgress(qint64 current, qint64 total)
|
||||
}
|
||||
|
||||
// Public interface
|
||||
MinecraftAccountPtr MSALoginDialog::newAccount(QWidget *parent, QString msg)
|
||||
MinecraftAccountPtr MSALoginDialog::newAccount(QWidget* parent, QString msg)
|
||||
{
|
||||
MSALoginDialog dlg(parent);
|
||||
dlg.ui->label->setText(msg);
|
||||
if (dlg.exec() == QDialog::Accepted)
|
||||
{
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
return dlg.m_account;
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -15,49 +15,45 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QTimer>
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QtWidgets/QDialog>
|
||||
|
||||
#include "minecraft/auth/MinecraftAccount.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class MSALoginDialog;
|
||||
}
|
||||
|
||||
class MSALoginDialog : public QDialog
|
||||
{
|
||||
class MSALoginDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
~MSALoginDialog();
|
||||
|
||||
static MinecraftAccountPtr newAccount(QWidget *parent, QString message);
|
||||
static MinecraftAccountPtr newAccount(QWidget* parent, QString message);
|
||||
int exec() override;
|
||||
|
||||
private:
|
||||
explicit MSALoginDialog(QWidget *parent = 0);
|
||||
private:
|
||||
explicit MSALoginDialog(QWidget* parent = 0);
|
||||
|
||||
void setUserInputsEnabled(bool enable);
|
||||
|
||||
protected
|
||||
slots:
|
||||
void onTaskFailed(const QString &reason);
|
||||
protected slots:
|
||||
void onTaskFailed(const QString& reason);
|
||||
void onTaskSucceeded();
|
||||
void onTaskStatus(const QString &status);
|
||||
void onTaskStatus(const QString& status);
|
||||
void onTaskProgress(qint64 current, qint64 total);
|
||||
void showVerificationUriAndCode(const QUrl &uri, const QString &code, int expiresIn);
|
||||
void showVerificationUriAndCode(const QUrl& uri, const QString& code, int expiresIn);
|
||||
void hideVerificationUriAndCode();
|
||||
|
||||
void externalLoginTick();
|
||||
|
||||
private:
|
||||
Ui::MSALoginDialog *ui;
|
||||
private:
|
||||
Ui::MSALoginDialog* ui;
|
||||
MinecraftAccountPtr m_account;
|
||||
shared_qobject_ptr<AccountTask> m_loginTask;
|
||||
QTimer m_externalLoginTimer;
|
||||
int m_externalLoginElapsed = 0;
|
||||
int m_externalLoginTimeout = 0;
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,9 @@ class ModUpdateDialog final : public ReviewMessageBox {
|
||||
|
||||
private slots:
|
||||
void onMetadataEnsured(Mod*);
|
||||
void onMetadataFailed(Mod*, bool try_others = false, ModPlatform::ResourceProvider first_choice = ModPlatform::ResourceProvider::MODRINTH);
|
||||
void onMetadataFailed(Mod*,
|
||||
bool try_others = false,
|
||||
ModPlatform::ResourceProvider first_choice = ModPlatform::ResourceProvider::MODRINTH);
|
||||
|
||||
private:
|
||||
QWidget* m_parent;
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -33,28 +33,28 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "Application.h"
|
||||
#include "NewComponentDialog.h"
|
||||
#include "Application.h"
|
||||
#include "ui_NewComponentDialog.h"
|
||||
|
||||
#include <BaseVersion.h>
|
||||
#include <InstanceList.h>
|
||||
#include <icons/IconList.h>
|
||||
#include <tasks/Task.h>
|
||||
#include <InstanceList.h>
|
||||
|
||||
#include "VersionSelectDialog.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "IconPickerDialog.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "VersionSelectDialog.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QLayout>
|
||||
#include <QPushButton>
|
||||
#include <QFileDialog>
|
||||
#include <QValidator>
|
||||
|
||||
#include <meta/Index.h>
|
||||
#include <meta/VersionList.h>
|
||||
|
||||
NewComponentDialog::NewComponentDialog(const QString & initialName, const QString & initialUid, QWidget *parent)
|
||||
NewComponentDialog::NewComponentDialog(const QString& initialName, const QString& initialUid, QWidget* parent)
|
||||
: QDialog(parent), ui(new Ui::NewComponentDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -81,12 +81,9 @@ void NewComponentDialog::updateDialogState()
|
||||
{
|
||||
auto protoUid = ui->nameTextBox->text().toLower();
|
||||
protoUid.remove(QRegularExpression("[^a-z]"));
|
||||
if(protoUid.isEmpty())
|
||||
{
|
||||
if (protoUid.isEmpty()) {
|
||||
ui->uidTextBox->setPlaceholderText(originalPlaceholderText);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QString suggestedUid = "org.multimc.custom." + protoUid;
|
||||
ui->uidTextBox->setPlaceholderText(suggestedUid);
|
||||
}
|
||||
@ -97,8 +94,7 @@ void NewComponentDialog::updateDialogState()
|
||||
QString NewComponentDialog::name() const
|
||||
{
|
||||
auto result = ui->nameTextBox->text();
|
||||
if(result.size())
|
||||
{
|
||||
if (result.size()) {
|
||||
return result.trimmed();
|
||||
}
|
||||
return QString();
|
||||
@ -107,13 +103,11 @@ QString NewComponentDialog::name() const
|
||||
QString NewComponentDialog::uid() const
|
||||
{
|
||||
auto result = ui->uidTextBox->text();
|
||||
if(result.size())
|
||||
{
|
||||
if (result.size()) {
|
||||
return result.trimmed();
|
||||
}
|
||||
result = ui->uidTextBox->placeholderText();
|
||||
if(result.size() && result != originalPlaceholderText)
|
||||
{
|
||||
if (result.size() && result != originalPlaceholderText) {
|
||||
return result.trimmed();
|
||||
}
|
||||
return QString();
|
||||
|
@ -20,28 +20,26 @@
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class NewComponentDialog;
|
||||
}
|
||||
|
||||
class NewComponentDialog : public QDialog
|
||||
{
|
||||
class NewComponentDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NewComponentDialog(const QString & initialName = QString(), const QString & initialUid = QString(), QWidget *parent = 0);
|
||||
public:
|
||||
explicit NewComponentDialog(const QString& initialName = QString(), const QString& initialUid = QString(), QWidget* parent = 0);
|
||||
virtual ~NewComponentDialog();
|
||||
void setBlacklist(QStringList badUids);
|
||||
|
||||
QString name() const;
|
||||
QString uid() const;
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void updateDialogState();
|
||||
|
||||
private:
|
||||
Ui::NewComponentDialog *ui;
|
||||
private:
|
||||
Ui::NewComponentDialog* ui;
|
||||
|
||||
QString originalPlaceholderText;
|
||||
QStringList uidBlacklist;
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -33,38 +33,37 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "Application.h"
|
||||
#include "NewInstanceDialog.h"
|
||||
#include "Application.h"
|
||||
#include "ui/pages/modplatform/import_ftb/ImportFTBPage.h"
|
||||
#include "ui_NewInstanceDialog.h"
|
||||
|
||||
#include <BaseVersion.h>
|
||||
#include <InstanceList.h>
|
||||
#include <icons/IconList.h>
|
||||
#include <tasks/Task.h>
|
||||
#include <InstanceList.h>
|
||||
|
||||
#include "VersionSelectDialog.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "IconPickerDialog.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "VersionSelectDialog.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFileDialog>
|
||||
#include <QLayout>
|
||||
#include <QPushButton>
|
||||
#include <QFileDialog>
|
||||
#include <QValidator>
|
||||
#include <QDialogButtonBox>
|
||||
#include <utility>
|
||||
|
||||
#include "ui/widgets/PageContainer.h"
|
||||
#include "ui/pages/modplatform/CustomPage.h"
|
||||
#include "ui/pages/modplatform/atlauncher/AtlPage.h"
|
||||
#include "ui/pages/modplatform/legacy_ftb/Page.h"
|
||||
#include "ui/pages/modplatform/flame/FlamePage.h"
|
||||
#include "ui/pages/modplatform/ImportPage.h"
|
||||
#include "ui/pages/modplatform/atlauncher/AtlPage.h"
|
||||
#include "ui/pages/modplatform/flame/FlamePage.h"
|
||||
#include "ui/pages/modplatform/legacy_ftb/Page.h"
|
||||
#include "ui/pages/modplatform/modrinth/ModrinthPage.h"
|
||||
#include "ui/pages/modplatform/technic/TechnicPage.h"
|
||||
#include "ui/widgets/PageContainer.h"
|
||||
|
||||
|
||||
|
||||
NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString & url, QWidget *parent)
|
||||
NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, const QString& url, QWidget* parent)
|
||||
: QDialog(parent), ui(new Ui::NewInstanceDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -88,15 +87,14 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString
|
||||
groupList.push_front("");
|
||||
ui->groupBox->addItems(groupList);
|
||||
int index = groupList.indexOf(initialGroup);
|
||||
if(index == -1)
|
||||
{
|
||||
if (index == -1) {
|
||||
index = 0;
|
||||
}
|
||||
ui->groupBox->setCurrentIndex(index);
|
||||
ui->groupBox->lineEdit()->setPlaceholderText(tr("No group"));
|
||||
|
||||
|
||||
// NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not move this below.
|
||||
// NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not
|
||||
// move this below.
|
||||
m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
|
||||
m_container = new PageContainer(this, {}, this);
|
||||
@ -123,8 +121,7 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString
|
||||
HelpButton->setAutoDefault(false);
|
||||
connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);
|
||||
|
||||
if(!url.isEmpty())
|
||||
{
|
||||
if (!url.isEmpty()) {
|
||||
QUrl actualUrl(url);
|
||||
m_container->selectPage("import");
|
||||
importPage->setUrl(url);
|
||||
@ -156,9 +153,9 @@ void NewInstanceDialog::accept()
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
QList<BasePage *> NewInstanceDialog::getPages()
|
||||
QList<BasePage*> NewInstanceDialog::getPages()
|
||||
{
|
||||
QList<BasePage *> pages;
|
||||
QList<BasePage*> pages;
|
||||
|
||||
importPage = new ImportPage(this);
|
||||
|
||||
@ -168,6 +165,7 @@ QList<BasePage *> NewInstanceDialog::getPages()
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame)
|
||||
pages.append(new FlamePage(this));
|
||||
pages.append(new LegacyFTB::Page(this));
|
||||
pages.append(new FTBImportAPP::ImportFTBPage(this));
|
||||
pages.append(new ModrinthPage(this));
|
||||
pages.append(new TechnicPage(this));
|
||||
|
||||
@ -216,17 +214,17 @@ void NewInstanceDialog::setSuggestedPack(const QString& name, QString version, I
|
||||
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(allowOK);
|
||||
}
|
||||
|
||||
void NewInstanceDialog::setSuggestedIconFromFile(const QString &path, const QString &name)
|
||||
void NewInstanceDialog::setSuggestedIconFromFile(const QString& path, const QString& name)
|
||||
{
|
||||
importIcon = true;
|
||||
importIconPath = path;
|
||||
importIconName = name;
|
||||
|
||||
//Hmm, for some reason they can be to small
|
||||
// Hmm, for some reason they can be to small
|
||||
ui->iconButton->setIcon(QIcon(path));
|
||||
}
|
||||
|
||||
void NewInstanceDialog::setSuggestedIcon(const QString &key)
|
||||
void NewInstanceDialog::setSuggestedIcon(const QString& key)
|
||||
{
|
||||
auto icon = APPLICATION->icons()->getIcon(key);
|
||||
importIcon = false;
|
||||
@ -234,9 +232,9 @@ void NewInstanceDialog::setSuggestedIcon(const QString &key)
|
||||
ui->iconButton->setIcon(icon);
|
||||
}
|
||||
|
||||
InstanceTask * NewInstanceDialog::extractTask()
|
||||
InstanceTask* NewInstanceDialog::extractTask()
|
||||
{
|
||||
InstanceTask * extracted = creationTask.get();
|
||||
InstanceTask* extracted = creationTask.get();
|
||||
creationTask.release();
|
||||
|
||||
InstanceName inst_name(ui->instNameTextBox->placeholderText().trimmed(), importVersion);
|
||||
@ -252,8 +250,7 @@ void NewInstanceDialog::updateDialogState()
|
||||
{
|
||||
auto allowOK = creationTask && !instName().isEmpty();
|
||||
auto OkButton = m_buttons->button(QDialogButtonBox::Ok);
|
||||
if(OkButton->isEnabled() != allowOK)
|
||||
{
|
||||
if (OkButton->isEnabled() != allowOK) {
|
||||
OkButton->setEnabled(allowOK);
|
||||
}
|
||||
}
|
||||
@ -261,13 +258,11 @@ void NewInstanceDialog::updateDialogState()
|
||||
QString NewInstanceDialog::instName() const
|
||||
{
|
||||
auto result = ui->instNameTextBox->text().trimmed();
|
||||
if(result.size())
|
||||
{
|
||||
if (result.size()) {
|
||||
return result;
|
||||
}
|
||||
result = ui->instNameTextBox->placeholderText().trimmed();
|
||||
if(result.size())
|
||||
{
|
||||
if (result.size()) {
|
||||
return result;
|
||||
}
|
||||
return QString();
|
||||
@ -284,26 +279,25 @@ QString NewInstanceDialog::iconKey() const
|
||||
|
||||
void NewInstanceDialog::on_iconButton_clicked()
|
||||
{
|
||||
importIconNow(); //so the user can switch back
|
||||
importIconNow(); // so the user can switch back
|
||||
IconPickerDialog dlg(this);
|
||||
dlg.execWithSelection(InstIconKey);
|
||||
|
||||
if (dlg.result() == QDialog::Accepted)
|
||||
{
|
||||
if (dlg.result() == QDialog::Accepted) {
|
||||
InstIconKey = dlg.selectedIconKey;
|
||||
ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey));
|
||||
importIcon = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
|
||||
void NewInstanceDialog::on_instNameTextBox_textChanged(const QString& arg1)
|
||||
{
|
||||
updateDialogState();
|
||||
}
|
||||
|
||||
void NewInstanceDialog::importIconNow()
|
||||
{
|
||||
if(importIcon) {
|
||||
if (importIcon) {
|
||||
APPLICATION->icons()->installIcon(importIconPath, importIconName);
|
||||
InstIconKey = importIconName;
|
||||
importIcon = false;
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -37,11 +37,10 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "ui/pages/BasePageProvider.h"
|
||||
#include "InstanceTask.h"
|
||||
#include "ui/pages/BasePageProvider.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class NewInstanceDialog;
|
||||
}
|
||||
|
||||
@ -50,45 +49,44 @@ class QDialogButtonBox;
|
||||
class ImportPage;
|
||||
class FlamePage;
|
||||
|
||||
class NewInstanceDialog : public QDialog, public BasePageProvider
|
||||
{
|
||||
class NewInstanceDialog : public QDialog, public BasePageProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NewInstanceDialog(const QString & initialGroup, const QString & url = QString(), QWidget *parent = 0);
|
||||
public:
|
||||
explicit NewInstanceDialog(const QString& initialGroup, const QString& url = QString(), QWidget* parent = 0);
|
||||
~NewInstanceDialog();
|
||||
|
||||
void updateDialogState();
|
||||
|
||||
void setSuggestedPack(const QString& name = QString(), InstanceTask * task = nullptr);
|
||||
void setSuggestedPack(const QString& name, QString version, InstanceTask * task = nullptr);
|
||||
void setSuggestedIconFromFile(const QString &path, const QString &name);
|
||||
void setSuggestedIcon(const QString &key);
|
||||
void setSuggestedPack(const QString& name = QString(), InstanceTask* task = nullptr);
|
||||
void setSuggestedPack(const QString& name, QString version, InstanceTask* task = nullptr);
|
||||
void setSuggestedIconFromFile(const QString& path, const QString& name);
|
||||
void setSuggestedIcon(const QString& key);
|
||||
|
||||
InstanceTask * extractTask();
|
||||
InstanceTask* extractTask();
|
||||
|
||||
QString dialogTitle() override;
|
||||
QList<BasePage *> getPages() override;
|
||||
QList<BasePage*> getPages() override;
|
||||
|
||||
QString instName() const;
|
||||
QString instGroup() const;
|
||||
QString iconKey() const;
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void on_iconButton_clicked();
|
||||
void on_instNameTextBox_textChanged(const QString &arg1);
|
||||
void on_instNameTextBox_textChanged(const QString& arg1);
|
||||
|
||||
private:
|
||||
Ui::NewInstanceDialog *ui = nullptr;
|
||||
PageContainer * m_container = nullptr;
|
||||
QDialogButtonBox * m_buttons = nullptr;
|
||||
private:
|
||||
Ui::NewInstanceDialog* ui = nullptr;
|
||||
PageContainer* m_container = nullptr;
|
||||
QDialogButtonBox* m_buttons = nullptr;
|
||||
|
||||
QString InstIconKey;
|
||||
ImportPage *importPage = nullptr;
|
||||
ImportPage* importPage = nullptr;
|
||||
std::unique_ptr<InstanceTask> creationTask;
|
||||
|
||||
bool importIcon = false;
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
OfflineLoginDialog::OfflineLoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::OfflineLoginDialog)
|
||||
OfflineLoginDialog::OfflineLoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::OfflineLoginDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->progressBar->setVisible(false);
|
||||
@ -52,22 +52,20 @@ void OfflineLoginDialog::on_allowLongUsernames_stateChanged(int value)
|
||||
}
|
||||
|
||||
// Enable the OK button only when the textbox contains something.
|
||||
void OfflineLoginDialog::on_userTextBox_textEdited(const QString &newText)
|
||||
void OfflineLoginDialog::on_userTextBox_textEdited(const QString& newText)
|
||||
{
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)
|
||||
->setEnabled(!newText.isEmpty());
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!newText.isEmpty());
|
||||
}
|
||||
|
||||
void OfflineLoginDialog::onTaskFailed(const QString &reason)
|
||||
void OfflineLoginDialog::onTaskFailed(const QString& reason)
|
||||
{
|
||||
// Set message
|
||||
auto lines = reason.split('\n');
|
||||
QString processed;
|
||||
for(auto line: lines) {
|
||||
if(line.size()) {
|
||||
for (auto line : lines) {
|
||||
if (line.size()) {
|
||||
processed += "<font color='red'>" + line + "</font><br />";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
processed += "<br />";
|
||||
}
|
||||
}
|
||||
@ -83,7 +81,7 @@ void OfflineLoginDialog::onTaskSucceeded()
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void OfflineLoginDialog::onTaskStatus(const QString &status)
|
||||
void OfflineLoginDialog::onTaskStatus(const QString& status)
|
||||
{
|
||||
ui->label->setText(status);
|
||||
}
|
||||
@ -95,12 +93,11 @@ void OfflineLoginDialog::onTaskProgress(qint64 current, qint64 total)
|
||||
}
|
||||
|
||||
// Public interface
|
||||
MinecraftAccountPtr OfflineLoginDialog::newAccount(QWidget *parent, QString msg)
|
||||
MinecraftAccountPtr OfflineLoginDialog::newAccount(QWidget* parent, QString msg)
|
||||
{
|
||||
OfflineLoginDialog dlg(parent);
|
||||
dlg.ui->label->setText(msg);
|
||||
if (dlg.exec() == QDialog::Accepted)
|
||||
{
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
return dlg.m_account;
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -1,44 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QtWidgets/QDialog>
|
||||
|
||||
#include "minecraft/auth/MinecraftAccount.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class OfflineLoginDialog;
|
||||
}
|
||||
|
||||
class OfflineLoginDialog : public QDialog
|
||||
{
|
||||
class OfflineLoginDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
~OfflineLoginDialog();
|
||||
|
||||
static MinecraftAccountPtr newAccount(QWidget *parent, QString message);
|
||||
static MinecraftAccountPtr newAccount(QWidget* parent, QString message);
|
||||
|
||||
private:
|
||||
explicit OfflineLoginDialog(QWidget *parent = 0);
|
||||
private:
|
||||
explicit OfflineLoginDialog(QWidget* parent = 0);
|
||||
|
||||
void setUserInputsEnabled(bool enable);
|
||||
|
||||
protected
|
||||
slots:
|
||||
protected slots:
|
||||
void accept();
|
||||
|
||||
void onTaskFailed(const QString &reason);
|
||||
void onTaskFailed(const QString& reason);
|
||||
void onTaskSucceeded();
|
||||
void onTaskStatus(const QString &status);
|
||||
void onTaskStatus(const QString& status);
|
||||
void onTaskProgress(qint64 current, qint64 total);
|
||||
|
||||
void on_userTextBox_textEdited(const QString &newText);
|
||||
void on_userTextBox_textEdited(const QString& newText);
|
||||
void on_allowLongUsernames_stateChanged(int value);
|
||||
|
||||
private:
|
||||
Ui::OfflineLoginDialog *ui;
|
||||
private:
|
||||
Ui::OfflineLoginDialog* ui;
|
||||
MinecraftAccountPtr m_account;
|
||||
Task::Ptr m_loginTask;
|
||||
};
|
||||
|
@ -16,43 +16,38 @@
|
||||
#include "ProfileSelectDialog.h"
|
||||
#include "ui_ProfileSelectDialog.h"
|
||||
|
||||
#include <QItemSelectionModel>
|
||||
#include <QDebug>
|
||||
#include <QItemSelectionModel>
|
||||
|
||||
#include "SkinUtils.h"
|
||||
#include "Application.h"
|
||||
#include "SkinUtils.h"
|
||||
|
||||
#include "ui/dialogs/ProgressDialog.h"
|
||||
|
||||
ProfileSelectDialog::ProfileSelectDialog(const QString &message, int flags, QWidget *parent)
|
||||
ProfileSelectDialog::ProfileSelectDialog(const QString& message, int flags, QWidget* parent)
|
||||
: QDialog(parent), ui(new Ui::ProfileSelectDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_accounts = APPLICATION->accounts();
|
||||
auto view = ui->listView;
|
||||
//view->setModel(m_accounts.get());
|
||||
//view->hideColumn(AccountList::ActiveColumn);
|
||||
// view->setModel(m_accounts.get());
|
||||
// view->hideColumn(AccountList::ActiveColumn);
|
||||
view->setColumnCount(1);
|
||||
view->setRootIsDecorated(false);
|
||||
// FIXME: use a real model, not this
|
||||
if(QTreeWidgetItem* header = view->headerItem())
|
||||
{
|
||||
if (QTreeWidgetItem* header = view->headerItem()) {
|
||||
header->setText(0, tr("Name"));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
view->setHeaderLabel(tr("Name"));
|
||||
}
|
||||
QList <QTreeWidgetItem *> items;
|
||||
for (int i = 0; i < m_accounts->count(); i++)
|
||||
{
|
||||
QList<QTreeWidgetItem*> items;
|
||||
for (int i = 0; i < m_accounts->count(); i++) {
|
||||
MinecraftAccountPtr account = m_accounts->at(i);
|
||||
QString profileLabel;
|
||||
if(account->isInUse()) {
|
||||
if (account->isInUse()) {
|
||||
profileLabel = tr("%1 (in use)").arg(account->profileName());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
profileLabel = account->profileName();
|
||||
}
|
||||
auto item = new QTreeWidgetItem(view);
|
||||
@ -101,8 +96,7 @@ bool ProfileSelectDialog::useAsInstDefaullt() const
|
||||
void ProfileSelectDialog::on_buttonBox_accepted()
|
||||
{
|
||||
QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
|
||||
if (selection.size() > 0)
|
||||
{
|
||||
if (selection.size() > 0) {
|
||||
QModelIndex selected = selection.first();
|
||||
m_selected = selected.data(AccountList::PointerRole).value<MinecraftAccountPtr>();
|
||||
}
|
||||
|
@ -21,17 +21,14 @@
|
||||
|
||||
#include "minecraft/auth/AccountList.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class ProfileSelectDialog;
|
||||
}
|
||||
|
||||
class ProfileSelectDialog : public QDialog
|
||||
{
|
||||
class ProfileSelectDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Flags
|
||||
{
|
||||
public:
|
||||
enum Flags {
|
||||
NoFlags = 0,
|
||||
|
||||
/*!
|
||||
@ -52,7 +49,7 @@ public:
|
||||
* Constructs a new account select dialog with the given parent and message.
|
||||
* The message will be shown at the top of the dialog. It is an empty string by default.
|
||||
*/
|
||||
explicit ProfileSelectDialog(const QString& message="", int flags=0, QWidget *parent = 0);
|
||||
explicit ProfileSelectDialog(const QString& message = "", int flags = 0, QWidget* parent = 0);
|
||||
~ProfileSelectDialog();
|
||||
|
||||
/*!
|
||||
@ -73,18 +70,17 @@ public:
|
||||
*/
|
||||
bool useAsInstDefaullt() const;
|
||||
|
||||
public
|
||||
slots:
|
||||
public slots:
|
||||
void on_buttonBox_accepted();
|
||||
|
||||
void on_buttonBox_rejected();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
shared_qobject_ptr<AccountList> m_accounts;
|
||||
|
||||
//! The account that was selected when the user clicked OK.
|
||||
MinecraftAccountPtr m_selected;
|
||||
|
||||
private:
|
||||
Ui::ProfileSelectDialog *ui;
|
||||
private:
|
||||
Ui::ProfileSelectDialog* ui;
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -36,11 +36,11 @@
|
||||
#include "ProfileSetupDialog.h"
|
||||
#include "ui_ProfileSetupDialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QAction>
|
||||
#include <QRegularExpressionValidator>
|
||||
#include <QJsonDocument>
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QPushButton>
|
||||
#include <QRegularExpressionValidator>
|
||||
|
||||
#include "ui/dialogs/ProgressDialog.h"
|
||||
|
||||
@ -48,8 +48,7 @@
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
|
||||
|
||||
ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget *parent)
|
||||
ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget* parent)
|
||||
: QDialog(parent), m_accountToSetup(accountToSetup), ui(new Ui::ProfileSetupDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -91,13 +90,11 @@ void ProfileSetupDialog::setNameStatus(ProfileSetupDialog::NameStatus status, QS
|
||||
{
|
||||
nameStatus = status;
|
||||
auto okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||
switch(nameStatus)
|
||||
{
|
||||
switch (nameStatus) {
|
||||
case NameStatus::Available: {
|
||||
validityAction->setIcon(goodIcon);
|
||||
okButton->setEnabled(true);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case NameStatus::NotSet:
|
||||
case NameStatus::Pending:
|
||||
validityAction->setIcon(yellowIcon);
|
||||
@ -109,43 +106,44 @@ void ProfileSetupDialog::setNameStatus(ProfileSetupDialog::NameStatus status, QS
|
||||
okButton->setEnabled(false);
|
||||
break;
|
||||
}
|
||||
if(!errorString.isEmpty()) {
|
||||
if (!errorString.isEmpty()) {
|
||||
ui->errorLabel->setText(errorString);
|
||||
ui->errorLabel->setVisible(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ui->errorLabel->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileSetupDialog::nameEdited(const QString& name)
|
||||
{
|
||||
if(!ui->nameEdit->hasAcceptableInput()) {
|
||||
if (!ui->nameEdit->hasAcceptableInput()) {
|
||||
setNameStatus(NameStatus::NotSet, tr("Name is too short - must be between 3 and 16 characters long."));
|
||||
return;
|
||||
}
|
||||
scheduleCheck(name);
|
||||
}
|
||||
|
||||
void ProfileSetupDialog::scheduleCheck(const QString& name) {
|
||||
void ProfileSetupDialog::scheduleCheck(const QString& name)
|
||||
{
|
||||
queuedCheck = name;
|
||||
setNameStatus(NameStatus::Pending);
|
||||
checkStartTimer.start(1000);
|
||||
}
|
||||
|
||||
void ProfileSetupDialog::startCheck() {
|
||||
if(isChecking) {
|
||||
void ProfileSetupDialog::startCheck()
|
||||
{
|
||||
if (isChecking) {
|
||||
return;
|
||||
}
|
||||
if(queuedCheck.isNull()) {
|
||||
if (queuedCheck.isNull()) {
|
||||
return;
|
||||
}
|
||||
checkName(queuedCheck);
|
||||
}
|
||||
|
||||
|
||||
void ProfileSetupDialog::checkName(const QString &name) {
|
||||
if(isChecking) {
|
||||
void ProfileSetupDialog::checkName(const QString& name)
|
||||
{
|
||||
if (isChecking) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -160,44 +158,38 @@ void ProfileSetupDialog::checkName(const QString &name) {
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(token).toUtf8());
|
||||
|
||||
AuthRequest *requestor = new AuthRequest(this);
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &ProfileSetupDialog::checkFinished);
|
||||
requestor->get(request);
|
||||
}
|
||||
|
||||
void ProfileSetupDialog::checkFinished(
|
||||
QNetworkReply::NetworkError error,
|
||||
QByteArray data,
|
||||
QList<QNetworkReply::RawHeaderPair> headers
|
||||
) {
|
||||
auto requestor = qobject_cast<AuthRequest *>(QObject::sender());
|
||||
void ProfileSetupDialog::checkFinished(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
if(error == QNetworkReply::NoError) {
|
||||
if (error == QNetworkReply::NoError) {
|
||||
auto doc = QJsonDocument::fromJson(data);
|
||||
auto root = doc.object();
|
||||
auto statusValue = root.value("status").toString("INVALID");
|
||||
if(statusValue == "AVAILABLE") {
|
||||
if (statusValue == "AVAILABLE") {
|
||||
setNameStatus(NameStatus::Available);
|
||||
}
|
||||
else if (statusValue == "DUPLICATE") {
|
||||
} else if (statusValue == "DUPLICATE") {
|
||||
setNameStatus(NameStatus::Exists, tr("Minecraft profile with name %1 already exists.").arg(currentCheck));
|
||||
}
|
||||
else if (statusValue == "NOT_ALLOWED") {
|
||||
} else if (statusValue == "NOT_ALLOWED") {
|
||||
setNameStatus(NameStatus::Exists, tr("The name %1 is not allowed.").arg(currentCheck));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
setNameStatus(NameStatus::Error, tr("Unhandled profile name status: %1").arg(statusValue));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
setNameStatus(NameStatus::Error, tr("Failed to check name availability."));
|
||||
}
|
||||
isChecking = false;
|
||||
}
|
||||
|
||||
void ProfileSetupDialog::setupProfile(const QString &profileName) {
|
||||
if(isWorking) {
|
||||
void ProfileSetupDialog::setupProfile(const QString& profileName)
|
||||
{
|
||||
if (isWorking) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -212,7 +204,7 @@ void ProfileSetupDialog::setupProfile(const QString &profileName) {
|
||||
QString payloadTemplate("{\"profileName\":\"%1\"}");
|
||||
auto data = payloadTemplate.arg(profileName).toUtf8();
|
||||
|
||||
AuthRequest *requestor = new AuthRequest(this);
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &ProfileSetupDialog::setupProfileFinished);
|
||||
requestor->post(request, data);
|
||||
isWorking = true;
|
||||
@ -223,8 +215,9 @@ void ProfileSetupDialog::setupProfile(const QString &profileName) {
|
||||
|
||||
namespace {
|
||||
|
||||
struct MojangError{
|
||||
static MojangError fromJSON(QByteArray data) {
|
||||
struct MojangError {
|
||||
static MojangError fromJSON(QByteArray data)
|
||||
{
|
||||
MojangError out;
|
||||
out.error = QString::fromUtf8(data);
|
||||
auto doc = QJsonDocument::fromJson(data, &out.parseError);
|
||||
@ -247,25 +240,23 @@ struct MojangError{
|
||||
QString errorMessage;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ProfileSetupDialog::setupProfileFinished(
|
||||
QNetworkReply::NetworkError error,
|
||||
QByteArray data,
|
||||
QList<QNetworkReply::RawHeaderPair> headers
|
||||
) {
|
||||
auto requestor = qobject_cast<AuthRequest *>(QObject::sender());
|
||||
void ProfileSetupDialog::setupProfileFinished(QNetworkReply::NetworkError error,
|
||||
QByteArray data,
|
||||
QList<QNetworkReply::RawHeaderPair> headers)
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
isWorking = false;
|
||||
if(error == QNetworkReply::NoError) {
|
||||
if (error == QNetworkReply::NoError) {
|
||||
/*
|
||||
* data contains the profile in the response
|
||||
* ... we could parse it and update the account, but let's just return back to the normal login flow instead...
|
||||
*/
|
||||
accept();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
auto parsedError = MojangError::fromJSON(data);
|
||||
ui->errorLabel->setVisible(true);
|
||||
ui->errorLabel->setText(tr("The server returned the following error:") + "\n\n" + parsedError.errorMessage);
|
||||
|
@ -17,65 +17,48 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QIcon>
|
||||
#include <QTimer>
|
||||
#include <QNetworkReply>
|
||||
#include <QTimer>
|
||||
|
||||
#include <memory>
|
||||
#include <minecraft/auth/MinecraftAccount.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class ProfileSetupDialog;
|
||||
}
|
||||
|
||||
class ProfileSetupDialog : public QDialog
|
||||
{
|
||||
class ProfileSetupDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
explicit ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget *parent = 0);
|
||||
public:
|
||||
explicit ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget* parent = 0);
|
||||
~ProfileSetupDialog();
|
||||
|
||||
enum class NameStatus
|
||||
{
|
||||
NotSet,
|
||||
Pending,
|
||||
Available,
|
||||
Exists,
|
||||
Error
|
||||
} nameStatus = NameStatus::NotSet;
|
||||
enum class NameStatus { NotSet, Pending, Available, Exists, Error } nameStatus = NameStatus::NotSet;
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void on_buttonBox_accepted();
|
||||
void on_buttonBox_rejected();
|
||||
|
||||
void nameEdited(const QString &name);
|
||||
void checkFinished(
|
||||
QNetworkReply::NetworkError error,
|
||||
QByteArray data,
|
||||
QList<QNetworkReply::RawHeaderPair> headers
|
||||
);
|
||||
void nameEdited(const QString& name);
|
||||
void checkFinished(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers);
|
||||
void startCheck();
|
||||
|
||||
void setupProfileFinished(
|
||||
QNetworkReply::NetworkError error,
|
||||
QByteArray data,
|
||||
QList<QNetworkReply::RawHeaderPair> headers
|
||||
);
|
||||
protected:
|
||||
void scheduleCheck(const QString &name);
|
||||
void checkName(const QString &name);
|
||||
void setupProfileFinished(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers);
|
||||
|
||||
protected:
|
||||
void scheduleCheck(const QString& name);
|
||||
void checkName(const QString& name);
|
||||
void setNameStatus(NameStatus status, QString errorString);
|
||||
|
||||
void setupProfile(const QString & profileName);
|
||||
void setupProfile(const QString& profileName);
|
||||
|
||||
private:
|
||||
private:
|
||||
MinecraftAccountPtr m_accountToSetup;
|
||||
Ui::ProfileSetupDialog *ui;
|
||||
Ui::ProfileSetupDialog* ui;
|
||||
QIcon goodIcon;
|
||||
QIcon yellowIcon;
|
||||
QIcon badIcon;
|
||||
QAction * validityAction = nullptr;
|
||||
QAction* validityAction = nullptr;
|
||||
|
||||
QString queuedCheck;
|
||||
|
||||
@ -85,4 +68,3 @@ private:
|
||||
|
||||
QTimer checkStartTimer;
|
||||
};
|
||||
|
||||
|
@ -34,20 +34,20 @@
|
||||
*/
|
||||
|
||||
#include "ProgressDialog.h"
|
||||
#include <QPoint>
|
||||
#include "ui_ProgressDialog.h"
|
||||
|
||||
#include <limits>
|
||||
#include <QDebug>
|
||||
#include <QKeyEvent>
|
||||
#include <limits>
|
||||
|
||||
#include "tasks/Task.h"
|
||||
|
||||
#include "ui/widgets/SubTaskProgressBar.h"
|
||||
|
||||
|
||||
// map a value in a numeric range of an arbitrary type to between 0 and INT_MAX
|
||||
// for getting the best precision out of the qt progress bar
|
||||
template<typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true>
|
||||
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true>
|
||||
std::tuple<int, int> map_int_zero_max(T current, T range_max, T range_min)
|
||||
{
|
||||
int int_max = std::numeric_limits<int>::max();
|
||||
@ -56,18 +56,18 @@ std::tuple<int, int> map_int_zero_max(T current, T range_max, T range_min)
|
||||
double percentage = static_cast<double>(current - range_min) / static_cast<double>(type_range);
|
||||
int mapped_current = percentage * int_max;
|
||||
|
||||
return {mapped_current, int_max};
|
||||
return { mapped_current, int_max };
|
||||
}
|
||||
|
||||
|
||||
ProgressDialog::ProgressDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ProgressDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->taskProgressScrollArea->setHidden(true);
|
||||
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
setAttribute(Qt::WidgetAttribute::WA_QuitOnClose, true);
|
||||
setSkipButton(false);
|
||||
changeProgress(0, 100);
|
||||
updateSize(true);
|
||||
setSkipButton(false);
|
||||
}
|
||||
|
||||
void ProgressDialog::setSkipButton(bool present, QString label)
|
||||
@ -93,25 +93,36 @@ ProgressDialog::~ProgressDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ProgressDialog::updateSize()
|
||||
{
|
||||
void ProgressDialog::updateSize(bool recenterParent)
|
||||
{
|
||||
QSize lastSize = this->size();
|
||||
QSize qSize = QSize(480, minimumSizeHint().height());
|
||||
QPoint lastPos = this->pos();
|
||||
int minHeight = ui->globalStatusDetailsLabel->minimumSize().height() + (ui->verticalLayout->spacing() * 2);
|
||||
minHeight += ui->globalProgressBar->minimumSize().height() + ui->verticalLayout->spacing();
|
||||
if (!ui->taskProgressScrollArea->isHidden())
|
||||
minHeight += ui->taskProgressScrollArea->minimumSizeHint().height() + ui->verticalLayout->spacing();
|
||||
if (ui->skipButton->isVisible())
|
||||
minHeight += ui->skipButton->height() + ui->verticalLayout->spacing();
|
||||
minHeight = std::max(minHeight, 60);
|
||||
QSize minSize = QSize(480, minHeight);
|
||||
|
||||
// if the current window is too small
|
||||
if ((lastSize != qSize) && (lastSize.height() < qSize.height()))
|
||||
{
|
||||
resize(qSize);
|
||||
|
||||
// keep the dialog in the center after a resize
|
||||
this->move(
|
||||
this->parentWidget()->x() + (this->parentWidget()->width() - this->width()) / 2,
|
||||
this->parentWidget()->y() + (this->parentWidget()->height() - this->height()) / 2
|
||||
);
|
||||
setMinimumSize(minSize);
|
||||
adjustSize();
|
||||
|
||||
QSize newSize = this->size();
|
||||
// if the current window is a different size
|
||||
auto parent = this->parentWidget();
|
||||
if (recenterParent && parent) {
|
||||
auto newX = std::max(0, parent->x() + ((parent->width() - newSize.width()) / 2));
|
||||
auto newY = std::max(0, parent->y() + ((parent->height() - newSize.height()) / 2));
|
||||
this->move(newX, newY);
|
||||
} else if (lastSize != newSize) {
|
||||
// center on old position after resize
|
||||
QSize sizeDiff = lastSize - newSize; // last size was smaller, the results should be negative
|
||||
auto newX = std::max(0, lastPos.x() + (sizeDiff.width() / 2));
|
||||
auto newY = std::max(0, lastPos.y() + (sizeDiff.height() / 2));
|
||||
this->move(newX, newY);
|
||||
}
|
||||
|
||||
setMinimumSize(qSize);
|
||||
|
||||
}
|
||||
|
||||
int ProgressDialog::execWithTask(Task* task)
|
||||
@ -123,7 +134,7 @@ int ProgressDialog::execWithTask(Task* task)
|
||||
return QDialog::DialogCode::Accepted;
|
||||
}
|
||||
|
||||
QDialog::DialogCode result {};
|
||||
QDialog::DialogCode result{};
|
||||
if (handleImmediateResult(result)) {
|
||||
return result;
|
||||
}
|
||||
@ -201,7 +212,9 @@ void ProgressDialog::onTaskSucceeded()
|
||||
void ProgressDialog::changeStatus(const QString& status)
|
||||
{
|
||||
ui->globalStatusLabel->setText(task->getStatus());
|
||||
ui->globalStatusLabel->adjustSize();
|
||||
ui->globalStatusDetailsLabel->setText(task->getDetails());
|
||||
ui->globalStatusDetailsLabel->adjustSize();
|
||||
|
||||
updateSize();
|
||||
}
|
||||
@ -216,16 +229,15 @@ void ProgressDialog::addTaskProgress(TaskStepProgress const& progress)
|
||||
void ProgressDialog::changeStepProgress(TaskStepProgress const& task_progress)
|
||||
{
|
||||
m_is_multi_step = true;
|
||||
if(ui->taskProgressScrollArea->isHidden()) {
|
||||
if (ui->taskProgressScrollArea->isHidden()) {
|
||||
ui->taskProgressScrollArea->setHidden(false);
|
||||
updateSize();
|
||||
}
|
||||
|
||||
|
||||
if (!taskProgress.contains(task_progress.uid))
|
||||
addTaskProgress(task_progress);
|
||||
auto task_bar = taskProgress.value(task_progress.uid);
|
||||
|
||||
|
||||
auto const [mapped_current, mapped_total] = map_int_zero_max<qint64>(task_progress.current, task_progress.total, 0);
|
||||
if (task_progress.total <= 0) {
|
||||
task_bar->setRange(0, 0);
|
||||
@ -240,14 +252,12 @@ void ProgressDialog::changeStepProgress(TaskStepProgress const& task_progress)
|
||||
if (task_progress.isDone()) {
|
||||
task_bar->setVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ProgressDialog::changeProgress(qint64 current, qint64 total)
|
||||
{
|
||||
ui->globalProgressBar->setMaximum(total);
|
||||
ui->globalProgressBar->setValue(current);
|
||||
|
||||
}
|
||||
|
||||
void ProgressDialog::keyPressEvent(QKeyEvent* e)
|
||||
|
@ -33,13 +33,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
#include <QHash>
|
||||
#include <QUuid>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "tasks/Task.h"
|
||||
@ -49,60 +48,52 @@
|
||||
class Task;
|
||||
class SequentialTask;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class ProgressDialog;
|
||||
}
|
||||
|
||||
class ProgressDialog : public QDialog
|
||||
{
|
||||
class ProgressDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProgressDialog(QWidget *parent = 0);
|
||||
public:
|
||||
explicit ProgressDialog(QWidget* parent = 0);
|
||||
~ProgressDialog();
|
||||
|
||||
void updateSize();
|
||||
void updateSize(bool recenterParent = false);
|
||||
|
||||
int execWithTask(Task* task);
|
||||
int execWithTask(std::unique_ptr<Task> &&task);
|
||||
int execWithTask(std::unique_ptr<Task> &task);
|
||||
int execWithTask(std::unique_ptr<Task>&& task);
|
||||
int execWithTask(std::unique_ptr<Task>& task);
|
||||
|
||||
void setSkipButton(bool present, QString label = QString());
|
||||
|
||||
Task *getTask();
|
||||
Task* getTask();
|
||||
|
||||
public
|
||||
slots:
|
||||
public slots:
|
||||
void onTaskStarted();
|
||||
void onTaskFailed(QString failure);
|
||||
void onTaskSucceeded();
|
||||
|
||||
void changeStatus(const QString &status);
|
||||
void changeStatus(const QString& status);
|
||||
void changeProgress(qint64 current, qint64 total);
|
||||
void changeStepProgress(TaskStepProgress const& task_progress);
|
||||
|
||||
|
||||
private
|
||||
slots:
|
||||
private slots:
|
||||
void on_skipButton_clicked(bool checked);
|
||||
|
||||
protected:
|
||||
virtual void keyPressEvent(QKeyEvent *e);
|
||||
virtual void closeEvent(QCloseEvent *e);
|
||||
protected:
|
||||
virtual void keyPressEvent(QKeyEvent* e);
|
||||
virtual void closeEvent(QCloseEvent* e);
|
||||
|
||||
private:
|
||||
bool handleImmediateResult(QDialog::DialogCode &result);
|
||||
private:
|
||||
bool handleImmediateResult(QDialog::DialogCode& result);
|
||||
void addTaskProgress(TaskStepProgress const& progress);
|
||||
|
||||
private:
|
||||
Ui::ProgressDialog *ui;
|
||||
private:
|
||||
Ui::ProgressDialog* ui;
|
||||
|
||||
Task *task;
|
||||
Task* task;
|
||||
|
||||
bool m_is_multi_step = false;
|
||||
QHash<QUuid, SubTaskProgressBar*> taskProgress;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include "ui/pages/modplatform/flame/FlameResourcePages.h"
|
||||
#include "ui/pages/modplatform/modrinth/ModrinthResourcePages.h"
|
||||
|
||||
#include "modplatform/flame/FlameAPI.h"
|
||||
#include "modplatform/modrinth/ModrinthAPI.h"
|
||||
#include "ui/widgets/PageContainer.h"
|
||||
|
||||
namespace ResourceDownload {
|
||||
@ -282,8 +284,11 @@ QList<BasePage*> ModDownloadDialog::getPages()
|
||||
{
|
||||
QList<BasePage*> pages;
|
||||
|
||||
pages.append(ModrinthModPage::create(this, *m_instance));
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame)
|
||||
auto loaders = static_cast<MinecraftInstance*>(m_instance)->getPackProfile()->getModLoaders().value();
|
||||
|
||||
if (ModrinthAPI::validateModLoaders(loaders))
|
||||
pages.append(ModrinthModPage::create(this, *m_instance));
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame && FlameAPI::validateModLoaders(loaders))
|
||||
pages.append(FlameModPage::create(this, *m_instance));
|
||||
|
||||
m_selectedPage = dynamic_cast<ModPage*>(pages[0]);
|
||||
|
@ -1,15 +1,16 @@
|
||||
#include "ScrollMessageBox.h"
|
||||
#include "ui_ScrollMessageBox.h"
|
||||
|
||||
|
||||
ScrollMessageBox::ScrollMessageBox(QWidget *parent, const QString &title, const QString &text, const QString &body) :
|
||||
QDialog(parent), ui(new Ui::ScrollMessageBox) {
|
||||
ScrollMessageBox::ScrollMessageBox(QWidget* parent, const QString& title, const QString& text, const QString& body)
|
||||
: QDialog(parent), ui(new Ui::ScrollMessageBox)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setWindowTitle(title);
|
||||
ui->label->setText(text);
|
||||
ui->textBrowser->setText(body);
|
||||
}
|
||||
|
||||
ScrollMessageBox::~ScrollMessageBox() {
|
||||
ScrollMessageBox::~ScrollMessageBox()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
@ -2,19 +2,20 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class ScrollMessageBox; }
|
||||
namespace Ui {
|
||||
class ScrollMessageBox;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class ScrollMessageBox : public QDialog {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScrollMessageBox(QWidget *parent, const QString &title, const QString &text, const QString &body);
|
||||
public:
|
||||
ScrollMessageBox(QWidget* parent, const QString& title, const QString& text, const QString& body);
|
||||
|
||||
~ScrollMessageBox() override;
|
||||
|
||||
private:
|
||||
Ui::ScrollMessageBox *ui;
|
||||
private:
|
||||
Ui::ScrollMessageBox* ui;
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -33,20 +33,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
|
||||
#include <FileSystem.h>
|
||||
|
||||
#include <minecraft/services/SkinUpload.h>
|
||||
#include <minecraft/services/CapeChange.h>
|
||||
#include <minecraft/services/SkinUpload.h>
|
||||
#include <tasks/SequentialTask.h>
|
||||
|
||||
#include "CustomMessageBox.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "SkinUploadDialog.h"
|
||||
#include "ui_SkinUploadDialog.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "CustomMessageBox.h"
|
||||
|
||||
void SkinUploadDialog::on_buttonBox_rejected()
|
||||
{
|
||||
@ -64,71 +64,51 @@ void SkinUploadDialog::on_buttonBox_accepted()
|
||||
QRegularExpression urlPrefixMatcher(QRegularExpression::anchoredPattern("^([a-z]+)://.+$"));
|
||||
bool isLocalFile = false;
|
||||
// it has an URL prefix -> it is an URL
|
||||
if(urlPrefixMatcher.match(input).hasMatch())
|
||||
{
|
||||
if (urlPrefixMatcher.match(input).hasMatch()) {
|
||||
QUrl fileURL = input;
|
||||
if(fileURL.isValid())
|
||||
{
|
||||
if (fileURL.isValid()) {
|
||||
// local?
|
||||
if(fileURL.isLocalFile())
|
||||
{
|
||||
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();
|
||||
} 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();
|
||||
} else {
|
||||
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("You cannot use an invalid URL for uploading skins."),
|
||||
QMessageBox::Warning)
|
||||
->exec();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// just assume it's a path then
|
||||
isLocalFile = true;
|
||||
fileName = ui->skinPathTextBox->text();
|
||||
}
|
||||
if (isLocalFile && !QFile::exists(fileName))
|
||||
{
|
||||
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())
|
||||
{
|
||||
if (ui->steveBtn->isChecked()) {
|
||||
model = SkinUpload::STEVE;
|
||||
}
|
||||
else if (ui->alexBtn->isChecked())
|
||||
{
|
||||
} else if (ui->alexBtn->isChecked()) {
|
||||
model = SkinUpload::ALEX;
|
||||
}
|
||||
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) {
|
||||
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)
|
||||
{
|
||||
if (prog.execWithTask(&skinUpload) != QDialog::Accepted) {
|
||||
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("Failed to upload skin!"), QMessageBox::Warning)->exec();
|
||||
close();
|
||||
return;
|
||||
@ -141,45 +121,43 @@ void SkinUploadDialog::on_skinBrowseBtn_clicked()
|
||||
{
|
||||
auto filter = QMimeDatabase().mimeTypeForName("image/png").filterString();
|
||||
QString raw_path = QFileDialog::getOpenFileName(this, tr("Select Skin Texture"), QString(), filter);
|
||||
if (raw_path.isEmpty() || !QFileInfo::exists(raw_path))
|
||||
{
|
||||
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)
|
||||
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();
|
||||
auto& data = *acct->accountData();
|
||||
int index = 0;
|
||||
ui->capeCombo->addItem(tr("No Cape"), QVariant());
|
||||
auto currentCape = data.minecraftProfile.currentCape;
|
||||
if(currentCape.isEmpty()) {
|
||||
if (currentCape.isEmpty()) {
|
||||
ui->capeCombo->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
for(auto & cape: data.minecraftProfile.capes) {
|
||||
for (auto& cape : data.minecraftProfile.capes) {
|
||||
index++;
|
||||
if(cape.data.size()) {
|
||||
if (cape.data.size()) {
|
||||
QPixmap capeImage;
|
||||
if(capeImage.loadFromData(cape.data, "PNG")) {
|
||||
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) {
|
||||
if (currentCape == cape.id) {
|
||||
ui->capeCombo->setCurrentIndex(index);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ui->capeCombo->addItem(cape.alias, cape.id);
|
||||
if(currentCape == cape.id) {
|
||||
if (currentCape == cape.id) {
|
||||
ui->capeCombo->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <minecraft/auth/MinecraftAccount.h>
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class SkinUploadDialog;
|
||||
namespace Ui {
|
||||
class SkinUploadDialog;
|
||||
}
|
||||
|
||||
class SkinUploadDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SkinUploadDialog(MinecraftAccountPtr acct, QWidget *parent = 0);
|
||||
virtual ~SkinUploadDialog() {};
|
||||
public:
|
||||
explicit SkinUploadDialog(MinecraftAccountPtr acct, QWidget* parent = 0);
|
||||
virtual ~SkinUploadDialog(){};
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
void on_buttonBox_accepted();
|
||||
|
||||
void on_buttonBox_rejected();
|
||||
|
||||
void on_skinBrowseBtn_clicked();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
MinecraftAccountPtr m_acct;
|
||||
|
||||
private:
|
||||
Ui::SkinUploadDialog *ui;
|
||||
private:
|
||||
Ui::SkinUploadDialog* ui;
|
||||
};
|
||||
|
@ -35,20 +35,19 @@
|
||||
|
||||
#include "VersionSelectDialog.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QtWidgets/QButtonGroup>
|
||||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QHBoxLayout>
|
||||
#include <QtWidgets/QPushButton>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ui/widgets/VersionSelectWidget.h"
|
||||
|
||||
#include "BaseVersion.h"
|
||||
#include "BaseVersionList.h"
|
||||
|
||||
VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent, bool cancelable)
|
||||
: QDialog(parent)
|
||||
VersionSelectDialog::VersionSelectDialog(BaseVersionList* vlist, QString title, QWidget* parent, bool cancelable) : QDialog(parent)
|
||||
{
|
||||
setObjectName(QStringLiteral("VersionSelectDialog"));
|
||||
resize(400, 347);
|
||||
@ -68,7 +67,7 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title,
|
||||
m_buttonBox = new QDialogButtonBox(this);
|
||||
m_buttonBox->setObjectName(QStringLiteral("buttonBox"));
|
||||
m_buttonBox->setOrientation(Qt::Horizontal);
|
||||
m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||
m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
||||
m_horizontalLayout->addWidget(m_buttonBox);
|
||||
|
||||
m_verticalLayout->addLayout(m_horizontalLayout);
|
||||
@ -84,8 +83,7 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title,
|
||||
|
||||
m_vlist = vlist;
|
||||
|
||||
if (!cancelable)
|
||||
{
|
||||
if (!cancelable) {
|
||||
m_buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
|
||||
}
|
||||
}
|
||||
@ -123,8 +121,7 @@ int VersionSelectDialog::exec()
|
||||
{
|
||||
QDialog::open();
|
||||
m_versionWidget->initialize(m_vlist);
|
||||
if(resizeOnColumn != -1)
|
||||
{
|
||||
if (resizeOnColumn != -1) {
|
||||
m_versionWidget->setResizeOn(resizeOnColumn);
|
||||
}
|
||||
return QDialog::exec();
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include <QDialog>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
|
||||
#include "BaseVersionList.h"
|
||||
|
||||
class QVBoxLayout;
|
||||
@ -27,52 +26,50 @@ class QDialogButtonBox;
|
||||
class VersionSelectWidget;
|
||||
class QPushButton;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class VersionSelectDialog;
|
||||
}
|
||||
|
||||
class VersionProxyModel;
|
||||
|
||||
class VersionSelectDialog : public QDialog
|
||||
{
|
||||
class VersionSelectDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent = 0, bool cancelable = true);
|
||||
virtual ~VersionSelectDialog() {};
|
||||
public:
|
||||
explicit VersionSelectDialog(BaseVersionList* vlist, QString title, QWidget* parent = 0, bool cancelable = true);
|
||||
virtual ~VersionSelectDialog(){};
|
||||
|
||||
int exec() override;
|
||||
|
||||
BaseVersion::Ptr selectedVersion() const;
|
||||
|
||||
void setCurrentVersion(const QString & version);
|
||||
void setCurrentVersion(const QString& version);
|
||||
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
|
||||
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
|
||||
void setEmptyString(QString emptyString);
|
||||
void setEmptyErrorString(QString emptyErrorString);
|
||||
void setResizeOn(int column);
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void on_refreshButton_clicked();
|
||||
|
||||
private:
|
||||
private:
|
||||
void retranslate();
|
||||
void selectRecommended();
|
||||
|
||||
private:
|
||||
private:
|
||||
QString m_currentVersion;
|
||||
VersionSelectWidget *m_versionWidget = nullptr;
|
||||
QVBoxLayout *m_verticalLayout = nullptr;
|
||||
QHBoxLayout *m_horizontalLayout = nullptr;
|
||||
QPushButton *m_refreshButton = nullptr;
|
||||
QDialogButtonBox *m_buttonBox = nullptr;
|
||||
VersionSelectWidget* m_versionWidget = nullptr;
|
||||
QVBoxLayout* m_verticalLayout = nullptr;
|
||||
QHBoxLayout* m_horizontalLayout = nullptr;
|
||||
QPushButton* m_refreshButton = nullptr;
|
||||
QDialogButtonBox* m_buttonBox = nullptr;
|
||||
|
||||
BaseVersionList *m_vlist = nullptr;
|
||||
BaseVersionList* m_vlist = nullptr;
|
||||
|
||||
VersionProxyModel *m_proxyModel = nullptr;
|
||||
VersionProxyModel* m_proxyModel = nullptr;
|
||||
|
||||
int resizeOnColumn = -1;
|
||||
|
||||
Task * loadTask = nullptr;
|
||||
Task* loadTask = nullptr;
|
||||
};
|
||||
|
Reference in New Issue
Block a user