mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-09-02 21:19:25 +00:00
Implemented basic offline mode
This commit is contained in:
parent
d587e7ada4
commit
2acfd00d76
@ -39,7 +39,8 @@ HEADERS += gui/mainwindow.h \
|
||||
FORMS += gui/mainwindow.ui \
|
||||
gui/settingsdialog.ui \
|
||||
gui/modeditwindow.ui \
|
||||
gui/instancesettings.ui
|
||||
gui/instancesettings.ui \
|
||||
gui/logindialog.ui
|
||||
|
||||
RESOURCES += \
|
||||
multimc.qrc
|
||||
|
@ -24,12 +24,21 @@ LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
//TODO: make translateable
|
||||
offlineButton = new QPushButton("Offline Once");
|
||||
|
||||
ui->loginButtonBox->addButton(offlineButton, QDialogButtonBox::ActionRole);
|
||||
|
||||
blockToggles = false;
|
||||
isOnline_ = true;
|
||||
onlineForced = false;
|
||||
|
||||
//FIXME: translateable?
|
||||
ui->usernameTextBox->lineEdit()->setPlaceholderText(QApplication::translate("LoginDialog", "Name", 0));
|
||||
|
||||
connect(ui->usernameTextBox, SIGNAL(currentTextChanged(QString)), this, SLOT(userTextChanged(QString)));
|
||||
connect(ui->forgetButton, SIGNAL(clicked(bool)), this, SLOT(forgetCurrentUser()));
|
||||
connect(offlineButton, SIGNAL(clicked(bool)), this, SLOT(launchOffline()));
|
||||
|
||||
if (loginErrMsg.isEmpty())
|
||||
ui->loginErrorLabel->setVisible(false);
|
||||
@ -60,6 +69,7 @@ LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) :
|
||||
|
||||
LoginDialog::~LoginDialog()
|
||||
{
|
||||
delete offlineButton;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -173,3 +183,15 @@ void LoginDialog::accept()
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void LoginDialog::launchOffline()
|
||||
{
|
||||
isOnline_ = false;
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void LoginDialog::forceOnline()
|
||||
{
|
||||
onlineForced = true;
|
||||
offlineButton->setEnabled(false);
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
#define LOGINDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
|
||||
namespace Ui {
|
||||
class LoginDialog;
|
||||
@ -33,6 +34,10 @@ public:
|
||||
QString getUsername() const;
|
||||
QString getPassword() const;
|
||||
|
||||
inline bool isOnline() { return isOnline_; }
|
||||
|
||||
void forceOnline();
|
||||
|
||||
public slots:
|
||||
virtual void accept();
|
||||
virtual void userTextChanged(const QString& user);
|
||||
@ -40,9 +45,13 @@ public slots:
|
||||
private slots:
|
||||
void usernameToggled ( bool );
|
||||
void passwordToggled ( bool );
|
||||
void launchOffline();
|
||||
private:
|
||||
Ui::LoginDialog *ui;
|
||||
bool blockToggles;
|
||||
QPushButton *offlineButton;
|
||||
bool isOnline_;
|
||||
bool onlineForced;
|
||||
};
|
||||
|
||||
#endif // LOGINDIALOG_H
|
||||
|
@ -473,17 +473,29 @@ void MainWindow::doLogin(const QString& errorMsg)
|
||||
return;
|
||||
|
||||
LoginDialog* loginDlg = new LoginDialog(this, errorMsg);
|
||||
if (!m_selectedInstance->lastLaunch())
|
||||
loginDlg->forceOnline();
|
||||
|
||||
loginDlg->exec();
|
||||
if(loginDlg->result() == QDialog::Accepted)
|
||||
{
|
||||
UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()};
|
||||
if (loginDlg->isOnline())
|
||||
{
|
||||
UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()};
|
||||
|
||||
TaskDialog* tDialog = new TaskDialog(this);
|
||||
LoginTask* loginTask = new LoginTask(uInfo, tDialog);
|
||||
connect(loginTask, SIGNAL(succeeded()),SLOT(onLoginComplete()), Qt::QueuedConnection);
|
||||
connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection);
|
||||
m_activeInst = m_selectedInstance;
|
||||
tDialog->exec(loginTask);
|
||||
TaskDialog* tDialog = new TaskDialog(this);
|
||||
LoginTask* loginTask = new LoginTask(uInfo, tDialog);
|
||||
connect(loginTask, SIGNAL(succeeded()),SLOT(onLoginComplete()), Qt::QueuedConnection);
|
||||
connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection);
|
||||
m_activeInst = m_selectedInstance;
|
||||
tDialog->exec(loginTask);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_activeLogin = {loginDlg->getUsername(), QString("Offline"), qint64(-1)};
|
||||
m_activeInst = m_selectedInstance;
|
||||
launchInstance(m_activeInst, m_activeLogin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user