This commit is contained in:
Petr Mrázek 2013-09-06 22:00:19 +02:00
commit e6b8923b23
4 changed files with 52 additions and 8 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -473,8 +473,13 @@ 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)
{
if (loginDlg->isOnline())
{
UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()};
@ -485,6 +490,13 @@ void MainWindow::doLogin(const QString& errorMsg)
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);
}
}
}
void MainWindow::onLoginComplete()