diff --git a/cockatrice/src/dlg_connect.cpp b/cockatrice/src/dlg_connect.cpp index 0c3d7621..ce3450be 100644 --- a/cockatrice/src/dlg_connect.cpp +++ b/cockatrice/src/dlg_connect.cpp @@ -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(); } diff --git a/cockatrice/src/dlg_connect.h b/cockatrice/src/dlg_connect.h index 00f39b6b..036595f3 100644 --- a/cockatrice/src/dlg_connect.h +++ b/cockatrice/src/dlg_connect.h @@ -2,19 +2,21 @@ #define DLG_CONNECT_H #include +#include 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; diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index 00e3d696..0d0822f1 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -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();