QTfrontend/gameuiconfig.cpp
changeset 5229 148d581b17ab
parent 5204 e1a5f4d5d86a
child 5237 963d787a25c2
equal deleted inserted replaced
5228:b018f6117fc1 5229:148d581b17ab
    20 #include <QCheckBox>
    20 #include <QCheckBox>
    21 #include <QLineEdit>
    21 #include <QLineEdit>
    22 #include <QDesktopWidget>
    22 #include <QDesktopWidget>
    23 #include <QApplication>
    23 #include <QApplication>
    24 #include <QInputDialog>
    24 #include <QInputDialog>
       
    25 #include <QCryptographicHash>
    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"
    64                 QObject::tr("Please enter your nickname"),
    65                 QObject::tr("Please enter your nickname"),
    65                 QLineEdit::Normal,
    66                 QLineEdit::Normal,
    66                 QDir::home().dirName());
    67                 QDir::home().dirName());
    67 
    68 
    68     Form->ui.pageOptions->editNetNick->setText(netNick);
    69     Form->ui.pageOptions->editNetNick->setText(netNick);
       
    70     
       
    71     int passLength = value("net/passwordlength", 0).toInt();
       
    72     setNetPasswordLength(passLength);
    69 
    73 
    70     delete netHost;
    74     delete netHost;
    71     netHost = new QString(value("net/ip", "").toString());
    75     netHost = new QString(value("net/ip", "").toString());
    72     netPort = value("net/port", 46631).toUInt();
    76     netPort = value("net/port", 46631).toUInt();
    73 
    77 
   136     setValue("audio/music", isMusicEnabled());
   140     setValue("audio/music", isMusicEnabled());
   137     setValue("frontend/music", isFrontendMusicEnabled());
   141     setValue("frontend/music", isFrontendMusicEnabled());
   138     setValue("audio/volume", Form->ui.pageOptions->volumeBox->value());
   142     setValue("audio/volume", Form->ui.pageOptions->volumeBox->value());
   139 
   143 
   140     setValue("net/nick", netNick());
   144     setValue("net/nick", netNick());
       
   145     if (netPasswordIsValid())
       
   146     {
       
   147         setValue("net/passwordhash", netPasswordHash());
       
   148         setValue("net/passwordlength", netPasswordLength());
       
   149     }
   141     setValue("net/ip", *netHost);
   150     setValue("net/ip", *netHost);
   142     setValue("net/port", netPort);
   151     setValue("net/port", netPort);
   143     setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text());
   152     setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text());
   144     setValue("net/serverport", Form->ui.pageNetServer->sbPort->value());
   153     setValue("net/serverport", Form->ui.pageNetServer->sbPort->value());
   145 
   154 
   146     setValue("fps/show", isShowFPSEnabled());
   155     setValue("fps/show", isShowFPSEnabled());
   147     setValue("fps/limit", Form->ui.pageOptions->fpsedit->value());
   156     setValue("fps/limit", Form->ui.pageOptions->fpsedit->value());
   148 
   157     
   149     setValue("misc/altdamage", isAltDamageEnabled());
   158     setValue("misc/altdamage", isAltDamageEnabled());
   150     setValue("misc/appendTimeToRecords", appendDateTimeToRecordName());
   159     setValue("misc/appendTimeToRecords", appendDateTimeToRecordName());
   151     setValue("misc/locale", language());
   160     setValue("misc/locale", language());
   152 
   161 
   153 #ifdef SPARKLE_ENABLED
   162 #ifdef SPARKLE_ENABLED
   294 QString GameUIConfig::netNick()
   303 QString GameUIConfig::netNick()
   295 {
   304 {
   296     return Form->ui.pageOptions->editNetNick->text();
   305     return Form->ui.pageOptions->editNetNick->text();
   297 }
   306 }
   298 
   307 
       
   308 QByteArray GameUIConfig::netPasswordHash()
       
   309 {
       
   310     return QCryptographicHash::hash(Form->ui.pageOptions->editNetPassword->text().toLatin1(), QCryptographicHash::Md5).toHex();
       
   311 }
       
   312 
       
   313 int GameUIConfig::netPasswordLength()
       
   314 {
       
   315     return Form->ui.pageOptions->editNetPassword->text().size();
       
   316 }
       
   317 
       
   318 bool GameUIConfig::netPasswordIsValid()
       
   319 {
       
   320     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
       
   321 }
       
   322 
       
   323 void GameUIConfig::setNetPasswordLength(int passwordLength)
       
   324 {
       
   325     if (passwordLength > 0)
       
   326     {
       
   327         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));
       
   328     }
       
   329     else
       
   330     {
       
   331         Form->ui.pageOptions->editNetPassword->setText("");
       
   332     }
       
   333 }
       
   334 
   299 quint8 GameUIConfig::volume()
   335 quint8 GameUIConfig::volume()
   300 {
   336 {
   301     return Form->ui.pageOptions->volumeBox->value() * 128 / 100;
   337     return Form->ui.pageOptions->volumeBox->value() * 128 / 100;
   302 }
   338 }