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