save/restore login information
This commit is contained in:
parent
a246a8d561
commit
be9ac2e061
3 changed files with 36 additions and 34 deletions
|
@ -4,27 +4,30 @@
|
||||||
DlgConnect::DlgConnect(QWidget *parent)
|
DlgConnect::DlgConnect(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup("server");
|
||||||
|
|
||||||
hostLabel = new QLabel(tr("&Host:"));
|
hostLabel = new QLabel(tr("&Host:"));
|
||||||
hostEdit = new QLineEdit("cockatrice.de");
|
hostEdit = new QLineEdit(settings.value("hostname", "cockatrice.de").toString());
|
||||||
hostLabel->setBuddy(hostEdit);
|
hostLabel->setBuddy(hostEdit);
|
||||||
|
|
||||||
portLabel = new QLabel(tr("&Port:"));
|
portLabel = new QLabel(tr("&Port:"));
|
||||||
portEdit = new QLineEdit("4747");
|
portEdit = new QLineEdit(settings.value("port", "4747").toString());
|
||||||
portLabel->setBuddy(portEdit);
|
portLabel->setBuddy(portEdit);
|
||||||
|
|
||||||
playernameLabel = new QLabel(tr("Player &name:"));
|
playernameLabel = new QLabel(tr("Player &name:"));
|
||||||
playernameEdit = new QLineEdit("Player");
|
playernameEdit = new QLineEdit(settings.value("playername", "Player").toString());
|
||||||
playernameLabel->setBuddy(playernameEdit);
|
playernameLabel->setBuddy(playernameEdit);
|
||||||
|
|
||||||
passwordLabel = new QLabel(tr("P&assword:"));
|
passwordLabel = new QLabel(tr("P&assword:"));
|
||||||
passwordEdit = new QLineEdit;
|
passwordEdit = new QLineEdit(settings.value("password").toString());
|
||||||
passwordLabel->setBuddy(passwordEdit);
|
passwordLabel->setBuddy(passwordEdit);
|
||||||
passwordEdit->setEchoMode(QLineEdit::Password);
|
passwordEdit->setEchoMode(QLineEdit::Password);
|
||||||
|
|
||||||
okButton = new QPushButton(tr("&OK"));
|
okButton = new QPushButton(tr("&OK"));
|
||||||
okButton->setDefault(true);
|
okButton->setDefault(true);
|
||||||
cancelButton = new QPushButton(tr("&Cancel"));
|
cancelButton = new QPushButton(tr("&Cancel"));
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout;
|
QGridLayout *grid = new QGridLayout;
|
||||||
grid->addWidget(hostLabel, 0, 0);
|
grid->addWidget(hostLabel, 0, 0);
|
||||||
grid->addWidget(hostEdit, 0, 1);
|
grid->addWidget(hostEdit, 0, 1);
|
||||||
|
@ -34,40 +37,33 @@ DlgConnect::DlgConnect(QWidget *parent)
|
||||||
grid->addWidget(playernameEdit, 2, 1);
|
grid->addWidget(playernameEdit, 2, 1);
|
||||||
grid->addWidget(passwordLabel, 3, 0);
|
grid->addWidget(passwordLabel, 3, 0);
|
||||||
grid->addWidget(passwordEdit, 3, 1);
|
grid->addWidget(passwordEdit, 3, 1);
|
||||||
|
|
||||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||||
buttonLayout->addStretch();
|
buttonLayout->addStretch();
|
||||||
buttonLayout->addWidget(okButton);
|
buttonLayout->addWidget(okButton);
|
||||||
buttonLayout->addWidget(cancelButton);
|
buttonLayout->addWidget(cancelButton);
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(grid);
|
mainLayout->addLayout(grid);
|
||||||
mainLayout->addLayout(buttonLayout);
|
mainLayout->addLayout(buttonLayout);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setWindowTitle(tr("Connect to server"));
|
setWindowTitle(tr("Connect to server"));
|
||||||
setFixedHeight(sizeHint().height());
|
setFixedHeight(sizeHint().height());
|
||||||
|
|
||||||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
connect(okButton, SIGNAL(clicked()), this, SLOT(actOk()));
|
||||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DlgConnect::getHost()
|
void DlgConnect::actOk()
|
||||||
{
|
{
|
||||||
return hostEdit->text();
|
QSettings settings;
|
||||||
}
|
settings.beginGroup("server");
|
||||||
|
settings.setValue("hostname", hostEdit->text());
|
||||||
|
settings.setValue("port", portEdit->text());
|
||||||
|
settings.setValue("playername", playernameEdit->text());
|
||||||
|
settings.setValue("password", passwordEdit->text());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
int DlgConnect::getPort()
|
accept();
|
||||||
{
|
|
||||||
return portEdit->text().toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DlgConnect::getPlayerName()
|
|
||||||
{
|
|
||||||
return playernameEdit->text();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DlgConnect::getPassword()
|
|
||||||
{
|
|
||||||
return passwordEdit->text();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,21 @@
|
||||||
#define DLG_CONNECT_H
|
#define DLG_CONNECT_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QLineEdit;
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
||||||
class DlgConnect : public QDialog {
|
class DlgConnect : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DlgConnect(QWidget *parent = 0);
|
DlgConnect(QWidget *parent = 0);
|
||||||
QString getHost();
|
QString getHost() const { return hostEdit->text(); }
|
||||||
int getPort();
|
int getPort() const { return portEdit->text().toInt(); }
|
||||||
QString getPlayerName();
|
QString getPlayerName() const { return playernameEdit->text(); }
|
||||||
QString getPassword();
|
QString getPassword() const { return passwordEdit->text(); }
|
||||||
|
private slots:
|
||||||
|
void actOk();
|
||||||
private:
|
private:
|
||||||
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
|
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
|
||||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
|
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
|
||||||
|
|
|
@ -43,6 +43,10 @@ int main(int argc, char *argv[])
|
||||||
app.addLibraryPath("plugins");
|
app.addLibraryPath("plugins");
|
||||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
QCoreApplication::setOrganizationName("Cockatrice");
|
||||||
|
QCoreApplication::setOrganizationDomain("cockatrice.de");
|
||||||
|
QCoreApplication::setApplicationName("Cockatrice");
|
||||||
|
|
||||||
MainWindow *ui = new MainWindow;
|
MainWindow *ui = new MainWindow;
|
||||||
qDebug("main(): MainWindow constructor finished");
|
qDebug("main(): MainWindow constructor finished");
|
||||||
ui->show();
|
ui->show();
|
||||||
|
|
Loading…
Reference in a new issue