QTfrontend/gameuiconfig.cpp
changeset 5260 f50f620771ee
parent 5252 ded882439548
child 5262 505a90cfa377
equal deleted inserted replaced
5258:7e9dad2783bc 5260:f50f620771ee
    20 #include <QCheckBox>
    20 #include <QCheckBox>
    21 #include <QLineEdit>
    21 #include <QLineEdit>
    22 #include <QDesktopWidget>
    22 #include <QDesktopWidget>
    23 #include <QInputDialog>
    23 #include <QInputDialog>
    24 #include <QCryptographicHash>
    24 #include <QCryptographicHash>
       
    25 #include <QFocusEvent>
    25 
    26 
    26 #include "gameuiconfig.h"
    27 #include "gameuiconfig.h"
    27 #include "hwform.h"
    28 #include "hwform.h"
    28 #include "pageoptions.h"
    29 #include "pageoptions.h"
    29 #include "pagenetserver.h"
    30 #include "pagenetserver.h"
    72                 QObject::tr("Please enter your nickname"),
    73                 QObject::tr("Please enter your nickname"),
    73                 QLineEdit::Normal,
    74                 QLineEdit::Normal,
    74                 QDir::home().dirName());
    75                 QDir::home().dirName());
    75 
    76 
    76     Form->ui.pageOptions->editNetNick->setText(netNick);
    77     Form->ui.pageOptions->editNetNick->setText(netNick);
       
    78     
       
    79     Form->ui.pageOptions->editNetPassword->installEventFilter(this);
    77     
    80     
    78     int passLength = value("net/passwordlength", 0).toInt();
    81     int passLength = value("net/passwordlength", 0).toInt();
    79     setNetPasswordLength(passLength);
    82     setNetPasswordLength(passLength);
    80 
    83 
    81     delete netHost;
    84     delete netHost;
   325 bool GameUIConfig::netPasswordIsValid()
   328 bool GameUIConfig::netPasswordIsValid()
   326 {
   329 {
   327     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
   330     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
   328 }
   331 }
   329 
   332 
       
   333 // 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
       
   334 bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
       
   335 {
       
   336     if (event->type() == QEvent::FocusIn)
       
   337     {
       
   338         if ((QLineEdit *)object == Form->ui.pageOptions->editNetPassword)
       
   339         {
       
   340             if (!netPasswordIsValid())
       
   341             {
       
   342                 Form->ui.pageOptions->editNetPassword->clear();
       
   343             }
       
   344         }
       
   345     }
       
   346     
       
   347     // Don't filter anything
       
   348     return false;
       
   349 }
       
   350 
   330 void GameUIConfig::setNetPasswordLength(int passwordLength)
   351 void GameUIConfig::setNetPasswordLength(int passwordLength)
   331 {
   352 {
   332     if (passwordLength > 0)
   353     if (passwordLength > 0)
   333     {
   354     {
   334         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));
   355         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));