QTfrontend/gameuiconfig.cpp
branchwebgl
changeset 9127 e350500c4edb
parent 8833 c13ebed437cb
parent 9080 9b42757d7e71
child 9521 8054d9d775fd
equal deleted inserted replaced
8860:bde641cf53c8 9127:e350500c4edb
     1 /*
     1 /*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    23 #include <QCryptographicHash>
    23 #include <QCryptographicHash>
    24 #include <QStandardItemModel>
    24 #include <QStandardItemModel>
    25 #include <QNetworkProxy>
    25 #include <QNetworkProxy>
    26 #include <QNetworkProxyFactory>
    26 #include <QNetworkProxyFactory>
    27 #include <utility>
    27 #include <utility>
       
    28 #include <QVariant>
    28 
    29 
    29 #include "gameuiconfig.h"
    30 #include "gameuiconfig.h"
    30 #include "hwform.h"
    31 #include "hwform.h"
    31 #include "pageoptions.h"
    32 #include "pageoptions.h"
    32 #include "pagevideos.h"
    33 #include "pagevideos.h"
    92     QString wWidth = value("video/windowedWidth", widthStr).toString();
    93     QString wWidth = value("video/windowedWidth", widthStr).toString();
    93     QString wHeight = value("video/windowedHeight", heightStr).toString();
    94     QString wHeight = value("video/windowedHeight", heightStr).toString();
    94     // If left blank reset the resolution to the default
    95     // If left blank reset the resolution to the default
    95     wWidth = (wWidth == "" ? widthStr : wWidth);
    96     wWidth = (wWidth == "" ? widthStr : wWidth);
    96     wHeight = (wHeight == "" ? heightStr : wHeight);
    97     wHeight = (wHeight == "" ? heightStr : wHeight);
    97     Form->ui.pageOptions->windowWidthEdit->setText(wWidth);
    98     Form->ui.pageOptions->windowWidthEdit->setValue(wWidth.toInt());
    98     Form->ui.pageOptions->windowHeightEdit->setText(wHeight);
    99     Form->ui.pageOptions->windowHeightEdit->setValue(wHeight.toInt());
    99 
   100 
   100     Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 1 : t);
   101     Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 1 : t);
   101     Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
   102     Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
   102     bool ffscr=value("frontend/fullscreen", false).toBool();
   103     bool ffscr=value("frontend/fullscreen", false).toBool();
   103     Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr);
   104     Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr);
   109     Form->ui.pageOptions->CBFrontendSound->setChecked(value("frontend/sound", true).toBool());
   110     Form->ui.pageOptions->CBFrontendSound->setChecked(value("frontend/sound", true).toBool());
   110     Form->ui.pageOptions->CBMusic->setChecked(value("audio/music", true).toBool());
   111     Form->ui.pageOptions->CBMusic->setChecked(value("audio/music", true).toBool());
   111     Form->ui.pageOptions->CBFrontendMusic->setChecked(value("frontend/music", true).toBool());
   112     Form->ui.pageOptions->CBFrontendMusic->setChecked(value("frontend/music", true).toBool());
   112     Form->ui.pageOptions->SLVolume->setValue(value("audio/volume", 100).toUInt());
   113     Form->ui.pageOptions->SLVolume->setValue(value("audio/volume", 100).toUInt());
   113 
   114 
   114     QString netNick = value("net/nick", "").toString();
   115     QString netNick = value("net/nick", tr("Guest")+QString("%1").arg(rand())).toString();
   115     Form->ui.pageOptions->editNetNick->setText(netNick);
   116     Form->ui.pageOptions->editNetNick->setText(netNick);
   116     bool savePwd = value("net/savepassword",true).toBool();
   117     bool savePwd = value("net/savepassword",true).toBool();
   117     Form->ui.pageOptions->CBSavePassword->setChecked(savePwd);
   118     Form->ui.pageOptions->CBSavePassword->setChecked(savePwd);
   118 
   119 
   119     Form->ui.pageOptions->editNetPassword->installEventFilter(this);
   120     Form->ui.pageOptions->editNetPassword->installEventFilter(this);
   154     Form->ui.pageOptions->leProxyPassword->setText(value("proxy/password", "").toString());
   155     Form->ui.pageOptions->leProxyPassword->setText(value("proxy/password", "").toString());
   155 
   156 
   156     { // load colors
   157     { // load colors
   157         QStandardItemModel * model = DataManager::instance().colorsModel();
   158         QStandardItemModel * model = DataManager::instance().colorsModel();
   158         for(int i = model->rowCount() - 1; i >= 0; --i)
   159         for(int i = model->rowCount() - 1; i >= 0; --i)
   159             model->item(i)->setData(value(QString("colors/color%1").arg(i), model->item(i)->data()));
   160             model->item(i)->setData(QColor(value(QString("colors/color%1").arg(i), model->item(i)->data()).toString()));
   160     }
   161     }
   161 
   162 
   162     { // load binds
   163     { // load binds
   163         for(int i = 0; i < BINDS_NUMBER; i++)
   164         for(int i = 0; i < BINDS_NUMBER; i++)
   164         {
   165         {
   317     }
   318     }
   318 
   319 
   319     { // save colors
   320     { // save colors
   320         QStandardItemModel * model = DataManager::instance().colorsModel();
   321         QStandardItemModel * model = DataManager::instance().colorsModel();
   321         for(int i = model->rowCount() - 1; i >= 0; --i)
   322         for(int i = model->rowCount() - 1; i >= 0; --i)
   322             setValue(QString("colors/color%1").arg(i), model->item(i)->data());
   323             setValue(QString("colors/color%1").arg(i), model->item(i)->data().value<QColor>().name());
   323     }
   324     }
   324 
   325 
   325     sync();
   326     sync();
   326 }
   327 }
   327 
   328 
   518 void GameUIConfig::clearPasswordHash()
   519 void GameUIConfig::clearPasswordHash()
   519 {
   520 {
   520     setValue("net/passwordhash", QString());
   521     setValue("net/passwordhash", QString());
   521     setValue("net/passwordlength", 0);
   522     setValue("net/passwordlength", 0);
   522     setValue("net/savepassword", false); //changes the savepassword value to false in order to not let the user save an empty password in PAGE_SETUP
   523     setValue("net/savepassword", false); //changes the savepassword value to false in order to not let the user save an empty password in PAGE_SETUP
   523     reloadValues(); //reloads the values of PAGE_SETUP
   524     Form->ui.pageOptions->editNetPassword->setEnabled(false);
       
   525     Form->ui.pageOptions->editNetPassword->setText("");
   524 }
   526 }
   525 
   527 
   526 void GameUIConfig::setPasswordHash(const QString & passwordhash)
   528 void GameUIConfig::setPasswordHash(const QString & passwordhash)
   527 {
   529 {
   528     setValue("net/passwordhash", passwordhash);
   530     setValue("net/passwordhash", passwordhash);
   529     setValue("net/passwordlength", passwordhash.size()/4);
   531     if (passwordhash!=NULL && passwordhash.size() > 0)
   530     setNetPasswordLength(passwordhash.size()/4);  //the hash.size() is divided by 4 let PAGE_SETUP use a reasonable number of stars to display the PW
   532     {
       
   533     // WTF - the whole point of "password length" was to have the dots match what they typed.  This is totally pointless, and all hashes are the same length for a given hash so might as well hardcode it.
       
   534     // setValue("net/passwordlength", passwordhash.size()/4);
       
   535         setValue("net/passwordlength", 8);
       
   536 
       
   537     // More WTF
       
   538     //setNetPasswordLength(passwordhash.size()/4);  //the hash.size() is divided by 4 let PAGE_SETUP use a reasonable number of stars to display the PW
       
   539         setNetPasswordLength(8);
       
   540     }
       
   541     else
       
   542     {
       
   543         setValue("net/passwordlength", 0);
       
   544         setNetPasswordLength(0);
       
   545     }
   531 }
   546 }
   532 
   547 
   533 QString GameUIConfig::passwordHash()
   548 QString GameUIConfig::passwordHash()
   534 {
   549 {
   535     return value("net/passwordhash").toString();
   550     return value("net/passwordhash").toString();