mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-10-03 16:51:30 +00:00
UltimMC: Make separate section for local accounts
This commit is contained in:
@@ -782,6 +782,8 @@ SET(LAUNCHER_SOURCES
|
|||||||
ui/dialogs/LoginDialog.h
|
ui/dialogs/LoginDialog.h
|
||||||
ui/dialogs/MSALoginDialog.cpp
|
ui/dialogs/MSALoginDialog.cpp
|
||||||
ui/dialogs/MSALoginDialog.h
|
ui/dialogs/MSALoginDialog.h
|
||||||
|
ui/dialogs/LocalLoginDialog.cpp
|
||||||
|
ui/dialogs/LocalLoginDialog.h
|
||||||
ui/dialogs/NewComponentDialog.cpp
|
ui/dialogs/NewComponentDialog.cpp
|
||||||
ui/dialogs/NewComponentDialog.h
|
ui/dialogs/NewComponentDialog.h
|
||||||
ui/dialogs/NewInstanceDialog.cpp
|
ui/dialogs/NewInstanceDialog.cpp
|
||||||
@@ -897,6 +899,7 @@ qt5_wrap_ui(LAUNCHER_UI
|
|||||||
ui/dialogs/IconPickerDialog.ui
|
ui/dialogs/IconPickerDialog.ui
|
||||||
ui/dialogs/MSALoginDialog.ui
|
ui/dialogs/MSALoginDialog.ui
|
||||||
ui/dialogs/AboutDialog.ui
|
ui/dialogs/AboutDialog.ui
|
||||||
|
ui/dialogs/LocalLoginDialog.ui
|
||||||
ui/dialogs/LoginDialog.ui
|
ui/dialogs/LoginDialog.ui
|
||||||
ui/dialogs/EditAccountDialog.ui
|
ui/dialogs/EditAccountDialog.ui
|
||||||
ui/dialogs/CreateShortcutDialog.ui
|
ui/dialogs/CreateShortcutDialog.ui
|
||||||
|
106
launcher/ui/dialogs/LocalLoginDialog.cpp
Normal file
106
launcher/ui/dialogs/LocalLoginDialog.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include "LocalLoginDialog.h"
|
||||||
|
#include "ui_LocalLoginDialog.h"
|
||||||
|
|
||||||
|
#include "minecraft/auth/AuthProviders.h"
|
||||||
|
#include "minecraft/auth/AccountTask.h"
|
||||||
|
|
||||||
|
#include <QtWidgets/QPushButton>
|
||||||
|
|
||||||
|
LocalLoginDialog::LocalLoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LocalLoginDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->progressBar->setVisible(false);
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
|
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalLoginDialog::~LocalLoginDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stage 1: User interaction
|
||||||
|
void LocalLoginDialog::accept()
|
||||||
|
{
|
||||||
|
setUserInputsEnabled(false);
|
||||||
|
ui->progressBar->setVisible(true);
|
||||||
|
|
||||||
|
m_account = MinecraftAccount::createFromUsername(ui->userTextBox->text());
|
||||||
|
m_account->setProvider(AuthProviders::lookup("dummy"));
|
||||||
|
|
||||||
|
// Setup the login task and start it
|
||||||
|
const char *dummy_password = " ";
|
||||||
|
m_loginTask = m_account->login(QString::fromLatin1(dummy_password));
|
||||||
|
connect(m_loginTask.get(), &Task::failed, this, &LocalLoginDialog::onTaskFailed);
|
||||||
|
connect(m_loginTask.get(), &Task::succeeded, this, &LocalLoginDialog::onTaskSucceeded);
|
||||||
|
connect(m_loginTask.get(), &Task::status, this, &LocalLoginDialog::onTaskStatus);
|
||||||
|
connect(m_loginTask.get(), &Task::progress, this, &LocalLoginDialog::onTaskProgress);
|
||||||
|
if (!m_loginTask)
|
||||||
|
{
|
||||||
|
onTaskSucceeded();
|
||||||
|
} else {
|
||||||
|
m_loginTask->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalLoginDialog::setUserInputsEnabled(bool enable)
|
||||||
|
{
|
||||||
|
ui->userTextBox->setEnabled(enable);
|
||||||
|
ui->buttonBox->setEnabled(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalLoginDialog::on_userTextBox_textEdited(const QString &newText)
|
||||||
|
{
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)
|
||||||
|
->setEnabled(!newText.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalLoginDialog::onTaskFailed(const QString &reason)
|
||||||
|
{
|
||||||
|
// Set message
|
||||||
|
auto lines = reason.split('\n');
|
||||||
|
QString processed;
|
||||||
|
for(auto line: lines) {
|
||||||
|
if(line.size()) {
|
||||||
|
processed += "<font color='red'>" + line + "</font><br />";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
processed += "<br />";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->label->setText(processed);
|
||||||
|
|
||||||
|
// Re-enable user-interaction
|
||||||
|
setUserInputsEnabled(true);
|
||||||
|
ui->progressBar->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalLoginDialog::onTaskSucceeded()
|
||||||
|
{
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalLoginDialog::onTaskStatus(const QString &status)
|
||||||
|
{
|
||||||
|
ui->label->setText(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalLoginDialog::onTaskProgress(qint64 current, qint64 total)
|
||||||
|
{
|
||||||
|
ui->progressBar->setMaximum(total);
|
||||||
|
ui->progressBar->setValue(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public interface
|
||||||
|
MinecraftAccountPtr LocalLoginDialog::newAccount(QWidget *parent, QString msg)
|
||||||
|
{
|
||||||
|
LocalLoginDialog dlg(parent);
|
||||||
|
dlg.ui->label->setText(msg);
|
||||||
|
if (dlg.exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
return dlg.m_account;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
58
launcher/ui/dialogs/LocalLoginDialog.h
Normal file
58
launcher/ui/dialogs/LocalLoginDialog.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* Copyright 2013-2021 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtWidgets/QDialog>
|
||||||
|
#include <QtCore/QEventLoop>
|
||||||
|
|
||||||
|
#include "minecraft/auth/MinecraftAccount.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class LocalLoginDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocalLoginDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
~LocalLoginDialog();
|
||||||
|
|
||||||
|
static MinecraftAccountPtr newAccount(QWidget *parent, QString message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit LocalLoginDialog(QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setUserInputsEnabled(bool enable);
|
||||||
|
|
||||||
|
protected
|
||||||
|
slots:
|
||||||
|
void accept();
|
||||||
|
|
||||||
|
void onTaskFailed(const QString &reason);
|
||||||
|
void onTaskSucceeded();
|
||||||
|
void onTaskStatus(const QString &status);
|
||||||
|
void onTaskProgress(qint64 current, qint64 total);
|
||||||
|
|
||||||
|
void on_userTextBox_textEdited(const QString &newText);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::LocalLoginDialog *ui;
|
||||||
|
MinecraftAccountPtr m_account;
|
||||||
|
Task::Ptr m_loginTask;
|
||||||
|
};
|
70
launcher/ui/dialogs/LocalLoginDialog.ui
Normal file
70
launcher/ui/dialogs/LocalLoginDialog.ui
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>LocalLoginDialog</class>
|
||||||
|
<widget class="QDialog" name="LocalLoginDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>421</width>
|
||||||
|
<height>198</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Add Local Account</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">Message label placeholder.</string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::RichText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="textInteractionFlags">
|
||||||
|
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="userTextBox">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Username</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QProgressBar" name="progressBar">
|
||||||
|
<property name="value">
|
||||||
|
<number>24</number>
|
||||||
|
</property>
|
||||||
|
<property name="textVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="radioLayout"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@@ -29,14 +29,14 @@ LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LoginDia
|
|||||||
|
|
||||||
for(auto provider: AuthProviders::getAll()) {
|
for(auto provider: AuthProviders::getAll()) {
|
||||||
auto providerId = provider->id();
|
auto providerId = provider->id();
|
||||||
// Exclude Microsoft account from here...
|
// Exclude Microsoft and Local accounts from here...
|
||||||
if (providerId != "MSA") {
|
if (providerId != "MSA" && providerId != "dummy") {
|
||||||
QRadioButton *button = new QRadioButton(provider->displayName());
|
QRadioButton *button = new QRadioButton(provider->displayName());
|
||||||
m_radioButtons[providerId] = button;
|
m_radioButtons[providerId] = button;
|
||||||
ui->radioLayout->addWidget(button);
|
ui->radioLayout->addWidget(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_radioButtons["dummy"]->setChecked(true);
|
m_radioButtons["elyby"]->setChecked(true);
|
||||||
adjustSize();
|
adjustSize();
|
||||||
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "ui/dialogs/ProgressDialog.h"
|
#include "ui/dialogs/ProgressDialog.h"
|
||||||
#include "ui/dialogs/LoginDialog.h"
|
#include "ui/dialogs/LoginDialog.h"
|
||||||
#include "ui/dialogs/MSALoginDialog.h"
|
#include "ui/dialogs/MSALoginDialog.h"
|
||||||
|
#include "ui/dialogs/LocalLoginDialog.h"
|
||||||
#include "ui/dialogs/CustomMessageBox.h"
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
#include "ui/dialogs/SkinUploadDialog.h"
|
#include "ui/dialogs/SkinUploadDialog.h"
|
||||||
|
|
||||||
@@ -45,7 +46,8 @@ AccountListPage::AccountListPage(QWidget *parent)
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->listView->setEmptyString(tr(
|
ui->listView->setEmptyString(tr(
|
||||||
"Welcome!\n"
|
"Welcome!\n"
|
||||||
"If you're new here, you can click the \"Add\" button to add your Mojang, local, or ElyBy account."
|
"If you're new here, you can click the \"Add Local\" button to add your local account.\n"
|
||||||
|
"Or click the \"Add Premium\" button to add your Ely.by or Mojang account."
|
||||||
));
|
));
|
||||||
ui->listView->setEmptyMode(VersionListView::String);
|
ui->listView->setEmptyMode(VersionListView::String);
|
||||||
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
|
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
@@ -111,6 +113,22 @@ void AccountListPage::listChanged()
|
|||||||
updateButtonStates();
|
updateButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AccountListPage::on_actionAddLocal_triggered()
|
||||||
|
{
|
||||||
|
MinecraftAccountPtr account = LocalLoginDialog::newAccount(
|
||||||
|
this,
|
||||||
|
tr("Please enter your desired username to add your account.")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (account)
|
||||||
|
{
|
||||||
|
m_accounts->addAccount(account);
|
||||||
|
if (m_accounts->count() == 1) {
|
||||||
|
m_accounts->setDefaultAccount(account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AccountListPage::on_actionAddMojang_triggered()
|
void AccountListPage::on_actionAddMojang_triggered()
|
||||||
{
|
{
|
||||||
MinecraftAccountPtr account = LoginDialog::newAccount(
|
MinecraftAccountPtr account = LoginDialog::newAccount(
|
||||||
|
@@ -60,6 +60,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void on_actionAddLocal_triggered();
|
||||||
void on_actionAddMojang_triggered();
|
void on_actionAddMojang_triggered();
|
||||||
void on_actionAddMicrosoft_triggered();
|
void on_actionAddMicrosoft_triggered();
|
||||||
void on_actionRemove_triggered();
|
void on_actionRemove_triggered();
|
||||||
|
@@ -52,6 +52,7 @@
|
|||||||
<attribute name="toolBarBreak">
|
<attribute name="toolBarBreak">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<addaction name="actionAddLocal"/>
|
||||||
<addaction name="actionAddMicrosoft"/>
|
<addaction name="actionAddMicrosoft"/>
|
||||||
<addaction name="actionAddMojang"/>
|
<addaction name="actionAddMojang"/>
|
||||||
<addaction name="actionRefresh"/>
|
<addaction name="actionRefresh"/>
|
||||||
@@ -62,9 +63,14 @@
|
|||||||
<addaction name="actionUploadSkin"/>
|
<addaction name="actionUploadSkin"/>
|
||||||
<addaction name="actionDeleteSkin"/>
|
<addaction name="actionDeleteSkin"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<action name="actionAddLocal">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add Local</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
<action name="actionAddMojang">
|
<action name="actionAddMojang">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add Account</string>
|
<string>Add Premium</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionRemove">
|
<action name="actionRemove">
|
||||||
|
Reference in New Issue
Block a user