When the password field is filled with null characters and when the user tries to edit the field, clear it.
authorZorg <zorgiepoo@gmail.com>
Sun, 19 Jun 2011 20:55:34 -0400
changeset 5260 f50f620771ee
parent 5258 7e9dad2783bc
child 5262 505a90cfa377
When the password field is filled with null characters and when the user tries to edit the field, clear it.
QTfrontend/gameuiconfig.cpp
QTfrontend/gameuiconfig.h
--- a/QTfrontend/gameuiconfig.cpp	Sun Jun 19 18:45:10 2011 +0200
+++ b/QTfrontend/gameuiconfig.cpp	Sun Jun 19 20:55:34 2011 -0400
@@ -22,6 +22,7 @@
 #include <QDesktopWidget>
 #include <QInputDialog>
 #include <QCryptographicHash>
+#include <QFocusEvent>
 
 #include "gameuiconfig.h"
 #include "hwform.h"
@@ -75,6 +76,8 @@
 
     Form->ui.pageOptions->editNetNick->setText(netNick);
     
+    Form->ui.pageOptions->editNetPassword->installEventFilter(this);
+    
     int passLength = value("net/passwordlength", 0).toInt();
     setNetPasswordLength(passLength);
 
@@ -327,6 +330,24 @@
     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
 }
 
+// When hedgewars launches, the password field is set with null characters. If the user tries to edit the field and there are such characters, then clear the field
+bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
+{
+    if (event->type() == QEvent::FocusIn)
+    {
+        if ((QLineEdit *)object == Form->ui.pageOptions->editNetPassword)
+        {
+            if (!netPasswordIsValid())
+            {
+                Form->ui.pageOptions->editNetPassword->clear();
+            }
+        }
+    }
+    
+    // Don't filter anything
+    return false;
+}
+
 void GameUIConfig::setNetPasswordLength(int passwordLength)
 {
     if (passwordLength > 0)
--- a/QTfrontend/gameuiconfig.h	Sun Jun 19 18:45:10 2011 +0200
+++ b/QTfrontend/gameuiconfig.h	Sun Jun 19 20:55:34 2011 -0400
@@ -22,6 +22,7 @@
 #include <QSettings>
 #include <QStringList>
 #include <QRect>
+#include <QEvent>
 
 class HWForm;
 class QSettings;
@@ -69,9 +70,9 @@
 
 public slots:
     void SaveOptions();
-
 private:
     bool netPasswordIsValid();
+    bool eventFilter(QObject *object, QEvent *event);
     quint8 depth;
 };