add a checkbox for the password field prompt (issue 316)
authorStepan777
Sun, 22 Apr 2012 17:03:55 +0200
changeset 6910 ea058558c68b
parent 6909 2b9c1228d516
child 6911 1cda333286e0
add a checkbox for the password field prompt (issue #316)
QTfrontend/hwform.cpp
QTfrontend/ui/dialog/input_password.cpp
QTfrontend/ui/dialog/input_password.h
project_files/hedgewars.pro
--- a/QTfrontend/hwform.cpp	Sun Apr 22 15:13:17 2012 +0200
+++ b/QTfrontend/hwform.cpp	Sun Apr 22 17:03:55 2012 +0200
@@ -83,6 +83,7 @@
 #include "netudpserver.h"
 #include "chatwidget.h"
 #include "input_ip.h"
+#include "input_password.h"
 #include "ammoSchemeModel.h"
 #include "bgwidget.h"
 #include "xfire.h"
@@ -935,25 +936,34 @@
 
 void HWForm::NetPassword(const QString & nick)
 {
-    bool ok = false;
     int passLength = config->value("net/passwordlength", 0).toInt();
     QString hash = config->value("net/passwordhash", "").toString();
 
     // If the password is blank, ask the user to enter one in
     if (passLength == 0)
     {
-        QString password = QInputDialog::getText(this, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok);
-
-        if (!ok)
+        HWPasswordDialog * hpd = new HWPasswordDialog(this, tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick));
+        hpd->cbSave->setChecked(config->value("net/savepassword", true).toBool());
+        if (hpd->exec() != QDialog::Accepted)
         {
             ForcedDisconnect(tr("No password supplied."));
+            delete hpd;
             return;
         }
 
+        QString password = hpd->lePassword->text();
         hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex();
-        config->setValue("net/passwordhash", hash);
-        config->setValue("net/passwordlength", password.size());
-        config->setNetPasswordLength(password.size());
+
+        bool save = hpd->cbSave->isChecked();
+        config->setValue("net/savepassword", save);
+        if (save) // user wants to save password
+        {
+            config->setValue("net/passwordhash", hash);
+            config->setValue("net/passwordlength", password.size());
+            config->setNetPasswordLength(password.size());
+        }
+
+        delete hpd;
     }
 
     hwnet->SendPasswordHash(hash);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/dialog/input_password.cpp	Sun Apr 22 17:03:55 2012 +0200
@@ -0,0 +1,53 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2007-2012 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <QLineEdit>
+#include <QDialogButtonBox>
+#include <QPushButton>
+#include <QGridLayout>
+#include <QCheckBox>
+#include <QLabel>
+
+#include "input_password.h"
+
+HWPasswordDialog::HWPasswordDialog(QWidget* parent, const QString & label) : QDialog(parent)
+{
+    setWindowTitle(tr("Password"));
+
+    QGridLayout * layout = new QGridLayout(this);
+
+    QLabel * lbLabel = new QLabel(this);
+    lbLabel->setText(label);
+    layout->addWidget(lbLabel, 0, 0);
+
+    lePassword = new QLineEdit(this);
+    lePassword->setEchoMode(QLineEdit::Password);
+    layout->addWidget(lePassword, 1, 0);
+
+    cbSave = new QCheckBox(this);
+    cbSave->setText(QCheckBox::tr("Save password"));
+    layout->addWidget(cbSave, 2, 0);
+
+    QDialogButtonBox* dbbButtons = new QDialogButtonBox(this);
+    QPushButton * pbOK = dbbButtons->addButton(QDialogButtonBox::Ok);
+    QPushButton * pbCancel = dbbButtons->addButton(QDialogButtonBox::Cancel);
+    layout->addWidget(dbbButtons, 3, 0);
+
+    connect(pbOK, SIGNAL(clicked()), this, SLOT(accept()));
+    connect(pbCancel, SIGNAL(clicked()), this, SLOT(reject()));
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/dialog/input_password.h	Sun Apr 22 17:03:55 2012 +0200
@@ -0,0 +1,38 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2007-2012 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef INPUT_PASSWORD_H
+#define INPUT_PASSWORD_H
+
+#include <QDialog>
+
+class QLineEdit;
+class QCheckBox;
+
+class HWPasswordDialog : public QDialog
+{
+        Q_OBJECT
+    public:
+        HWPasswordDialog(QWidget* parent, const QString & label);
+
+        QLineEdit* lePassword;
+        QCheckBox* cbSave;
+};
+
+
+#endif // INPUT_PASSWORD_H
--- a/project_files/hedgewars.pro	Sun Apr 22 15:13:17 2012 +0200
+++ b/project_files/hedgewars.pro	Sun Apr 22 17:03:55 2012 +0200
@@ -100,7 +100,8 @@
     ../QTfrontend/ui/qpushbuttonwithsound.h \
     ../QTfrontend/ui/widget/qpushbuttonwithsound.h \
     ../QTfrontend/ui/page/pagefeedback.h \
-    ../QTfrontend/model/roomslistmodel.h
+    ../QTfrontend/model/roomslistmodel.h \
+    ../QTfrontend/ui/dialog/input_password.h
 
 SOURCES += ../QTfrontend/model/ammoSchemeModel.cpp \
     ../QTfrontend/model/themesmodel.cpp \
@@ -178,7 +179,8 @@
     ../QTfrontend/ui/mouseoverfilter.cpp \
     ../QTfrontend/ui/widget/qpushbuttonwithsound.cpp \
     ../QTfrontend/ui/page/pagefeedback.cpp \
-    ../QTfrontend/model/roomslistmodel.cpp
+    ../QTfrontend/model/roomslistmodel.cpp \
+    ../QTfrontend/ui/dialog/input_password.cpp
 
 win32 {
     SOURCES += ../QTfrontend/xfire.cpp