Files
pokerth/src/gui/qt/settingsdialog/settingsdialogimpl.cpp
T

181 lines
9.4 KiB
C++
Raw Normal View History

2007-01-17 01:22:55 +00:00
/***************************************************************************
* Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de *
* *
* 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; either version 2 of the License, or *
* (at your option) any later version. *
* *
* 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 "settingsdialogimpl.h"
2007-01-17 23:57:41 +00:00
#include "configfile.h"
#include <iostream>
2007-01-17 01:22:55 +00:00
2007-02-01 02:18:59 +00:00
settingsDialogImpl::settingsDialogImpl(QWidget *parent)
: QDialog(parent)
2007-01-17 01:22:55 +00:00
{
setupUi(this);
2007-01-17 23:57:41 +00:00
playerNickIsChanged = FALSE;
2007-01-17 23:57:41 +00:00
//Formulare Füllen
2007-01-22 22:25:58 +00:00
ConfigFile myConfig;
2007-01-17 23:57:41 +00:00
//Player Nicks
2007-02-03 22:47:16 +00:00
lineEdit_humanPlayerName->setText(QString::fromStdString(myConfig.readConfigString("MyName")));
lineEdit_Opponent1Name->setText(QString::fromStdString(myConfig.readConfigString("Opponent1Name")));
lineEdit_Opponent2Name->setText(QString::fromStdString(myConfig.readConfigString("Opponent2Name")));
lineEdit_Opponent3Name->setText(QString::fromStdString(myConfig.readConfigString("Opponent3Name")));
lineEdit_Opponent4Name->setText(QString::fromStdString(myConfig.readConfigString("Opponent4Name")));
2007-01-17 23:57:41 +00:00
2007-02-22 22:59:42 +00:00
//Local Game Settings
2007-02-03 22:47:16 +00:00
spinBox_quantityPlayers->setValue(myConfig.readConfigInt("NumberOfPlayers"));
spinBox_startCash->setValue(myConfig.readConfigInt("StartCash"));
spinBox_smallBlind->setValue(myConfig.readConfigInt("SmallBlind"));
spinBox_handsBeforeRaiseSmallBlind->setValue(myConfig.readConfigInt("HandsBeforeRaiseSmallBlind"));
spinBox_gameSpeed->setValue(myConfig.readConfigInt("GameSpeed"));
checkBox_pauseBetweenHands->setChecked(myConfig.readConfigInt("PauseBetweenHands"));
checkBox_showGameSettingsDialogOnNewGame->setChecked(myConfig.readConfigInt("ShowGameSettingsDialogOnNewGame"));
2007-02-22 22:59:42 +00:00
//Network Game Settings
spinBox_netQuantityPlayers->setValue(myConfig.readConfigInt("NetNumberOfPlayers"));
spinBox_netStartCash->setValue(myConfig.readConfigInt("NetStartCash"));
spinBox_netSmallBlind->setValue(myConfig.readConfigInt("NetSmallBlind"));
spinBox_netHandsBeforeRaiseSmallBlind->setValue(myConfig.readConfigInt("NetHandsBeforeRaiseSmallBlind"));
spinBox_netGameSpeed->setValue(myConfig.readConfigInt("NetGameSpeed"));
2007-02-26 00:44:09 +00:00
spinBox_serverPort->setValue(myConfig.readConfigInt("ServerPort"));
2007-02-22 22:59:42 +00:00
lineEdit_serverPassword->setText(QString::fromStdString(myConfig.readConfigString("ServerPassword")));
2007-02-25 23:14:48 +00:00
checkBox_useIpv6->setChecked(myConfig.readConfigInt("ServerUseIpv6"));
2007-02-22 22:59:42 +00:00
2007-01-20 01:38:40 +00:00
//Interface
2007-02-20 00:05:09 +00:00
checkBox_showLeftToolbox->setChecked(myConfig.readConfigInt("ShowLeftToolBox"));
checkBox_showRightToolbox->setChecked(myConfig.readConfigInt("ShowRightToolBox"));
2007-02-03 22:47:16 +00:00
checkBox_showIntro->setChecked(myConfig.readConfigInt("ShowIntro"));
checkBox_showFadeOutCardsAnimation->setChecked(myConfig.readConfigInt("ShowFadeOutCardsAnimation"));
checkBox_showFlipCardsAnimation->setChecked(myConfig.readConfigInt("ShowFlipCardsAnimation"));
radioButton_flipsideTux->setChecked(myConfig.readConfigInt("FlipsideTux"));
radioButton_flipsideOwn->setChecked(myConfig.readConfigInt("FlipsideOwn"));
2007-01-29 00:53:20 +00:00
if(radioButton_flipsideOwn->isChecked()) {
lineEdit_OwnFlipsideFilename->setEnabled(TRUE);
pushButton_openFlipsidePicture->setEnabled(TRUE);
}
2007-02-03 22:47:16 +00:00
lineEdit_OwnFlipsideFilename->setText(QString::fromStdString(myConfig.readConfigString("FlipsideOwnFile")));
2007-02-03 10:10:25 +00:00
//Log
2007-02-03 22:47:16 +00:00
lineEdit_logDir->setText(QString::fromStdString(myConfig.readConfigString("LogDir")));
spinBox_logStoreDuration->setValue(myConfig.readConfigInt("LogStoreDuration"));
2007-01-17 01:22:55 +00:00
2007-01-20 01:38:40 +00:00
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( isAccepted() ) );
connect( lineEdit_humanPlayerName, SIGNAL( textChanged( const QString &) ), this, SLOT( playerNickChanged() ) );
connect( lineEdit_Opponent1Name, SIGNAL( textChanged(const QString &) ), this, SLOT( playerNickChanged() ) );
connect( lineEdit_Opponent2Name, SIGNAL( textChanged(const QString &) ), this, SLOT( playerNickChanged() ) );
connect( lineEdit_Opponent3Name, SIGNAL( textChanged(const QString &) ), this, SLOT( playerNickChanged() ) );
connect( lineEdit_Opponent4Name, SIGNAL( textChanged(const QString &) ), this, SLOT( playerNickChanged() ) );
2007-01-28 23:33:48 +00:00
connect( pushButton_openFlipsidePicture, SIGNAL( clicked() ), this, SLOT( setFlipsidePicFileName()) );
2007-02-03 10:10:25 +00:00
connect( pushButton_openLogDir, SIGNAL( clicked() ), this, SLOT( setLogDir()) );
2007-01-28 23:33:48 +00:00
2007-01-17 23:57:41 +00:00
}
2007-01-20 01:38:40 +00:00
void settingsDialogImpl::isAccepted() {
2007-01-17 23:57:41 +00:00
2007-02-03 22:47:16 +00:00
settingsCorrect = TRUE;
2007-01-17 23:57:41 +00:00
//Daten speichern
2007-01-22 22:25:58 +00:00
ConfigFile myConfig;
2007-01-17 23:57:41 +00:00
2007-01-22 22:25:58 +00:00
// Player Nicks
myConfig.writeConfigString("MyName", lineEdit_humanPlayerName->text().toStdString());
myConfig.writeConfigString("Opponent1Name", lineEdit_Opponent1Name->text().toStdString());
myConfig.writeConfigString("Opponent2Name", lineEdit_Opponent2Name->text().toStdString());
myConfig.writeConfigString("Opponent3Name", lineEdit_Opponent3Name->text().toStdString());
myConfig.writeConfigString("Opponent4Name", lineEdit_Opponent4Name->text().toStdString());
2007-01-17 23:57:41 +00:00
2007-02-22 22:59:42 +00:00
// Local Game Settings
2007-01-22 22:25:58 +00:00
myConfig.writeConfigInt("NumberOfPlayers", spinBox_quantityPlayers->value());
myConfig.writeConfigInt("StartCash", spinBox_startCash->value());
myConfig.writeConfigInt("SmallBlind", spinBox_smallBlind->value());
2007-01-23 19:20:18 +00:00
myConfig.writeConfigInt("HandsBeforeRaiseSmallBlind", spinBox_handsBeforeRaiseSmallBlind->value());
2007-01-22 22:25:58 +00:00
myConfig.writeConfigInt("GameSpeed", spinBox_gameSpeed->value());
myConfig.writeConfigInt("PauseBetweenHands", checkBox_pauseBetweenHands->isChecked());
2007-01-22 22:25:58 +00:00
myConfig.writeConfigInt("ShowGameSettingsDialogOnNewGame", checkBox_showGameSettingsDialogOnNewGame->isChecked());
2007-01-17 23:57:41 +00:00
2007-02-22 22:59:42 +00:00
//Network Game Settings
myConfig.writeConfigInt("NetNumberOfPlayers", spinBox_netQuantityPlayers->value());
myConfig.writeConfigInt("NetStartCash", spinBox_netStartCash->value());
myConfig.writeConfigInt("NetSmallBlind", spinBox_netSmallBlind->value());
myConfig.writeConfigInt("NetHandsBeforeRaiseSmallBlind", spinBox_netHandsBeforeRaiseSmallBlind->value());
myConfig.writeConfigInt("NetGameSpeed", spinBox_netGameSpeed->value());
2007-02-26 00:44:09 +00:00
myConfig.writeConfigInt("ServerPort", spinBox_serverPort->value());
2007-02-22 22:59:42 +00:00
myConfig.writeConfigString("ServerPassword", lineEdit_serverPassword->text().toStdString());
2007-02-25 23:14:48 +00:00
myConfig.writeConfigInt("ServerUseIpv6", checkBox_useIpv6->isChecked());
2007-02-22 22:59:42 +00:00
2007-01-22 22:25:58 +00:00
// Interface
2007-02-20 00:05:09 +00:00
myConfig.writeConfigInt("ShowLeftToolBox", checkBox_showLeftToolbox->isChecked());
myConfig.writeConfigInt("ShowRightToolBox", checkBox_showRightToolbox->isChecked());
2007-01-26 08:59:40 +00:00
myConfig.writeConfigInt("ShowIntro", checkBox_showIntro->isChecked());
myConfig.writeConfigInt("ShowFadeOutCardsAnimation", checkBox_showFadeOutCardsAnimation->isChecked());
myConfig.writeConfigInt("ShowFlipCardsAnimation", checkBox_showFlipCardsAnimation->isChecked());
2007-01-28 23:33:48 +00:00
myConfig.writeConfigInt("FlipsideTux", radioButton_flipsideTux->isChecked());
myConfig.writeConfigInt("FlipsideOwn", radioButton_flipsideOwn->isChecked());
2007-02-04 00:34:44 +00:00
2007-02-05 09:14:11 +00:00
if(radioButton_flipsideOwn->isChecked()) {
if(QFile::QFile(lineEdit_OwnFlipsideFilename->text()).exists() && lineEdit_OwnFlipsideFilename->text() != "") {myConfig.writeConfigString("FlipsideOwnFile", lineEdit_OwnFlipsideFilename->text().toStdString()); }
else { QMessageBox::warning(this, tr("Settings Error"),
tr("The entered Flipside Picture doesn't exists.\n"
"Please enter an valid Picture!"),
QMessageBox::Ok);
settingsCorrect = FALSE;
}
}
2007-01-20 01:38:40 +00:00
2007-02-03 10:10:25 +00:00
// Log
2007-02-03 22:47:16 +00:00
if(QDir::QDir(lineEdit_logDir->text()).exists() && lineEdit_logDir->text() != "") { myConfig.writeConfigString("LogDir", lineEdit_logDir->text().toStdString()); }
else {
QMessageBox::warning(this, tr("Settings Error"),
tr("The Log File Directory doesn't exists.\n"
2007-02-04 00:34:44 +00:00
"Please select an valid Directory!"),
2007-02-03 22:47:16 +00:00
QMessageBox::Ok);
settingsCorrect = FALSE;
}
2007-02-03 10:10:25 +00:00
myConfig.writeConfigInt("LogStoreDuration", spinBox_logStoreDuration->value());
2007-02-03 22:47:16 +00:00
2007-02-04 00:34:44 +00:00
//Wenn alles richtig eingegeben wurde --> Dialog schließen
2007-02-03 22:47:16 +00:00
if(settingsCorrect) { this->hide(); }
2007-01-17 01:22:55 +00:00
}
2007-01-28 23:33:48 +00:00
void settingsDialogImpl::setFlipsidePicFileName()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Select your Flipside Picture"),
QDir::homePath(),
2007-01-29 21:25:33 +00:00
tr("Images (*.bmp *.png *.xpm)"));
2007-01-28 23:33:48 +00:00
if (!fileName.isEmpty())
lineEdit_OwnFlipsideFilename->setText(fileName);
2007-01-29 00:53:20 +00:00
}
2007-02-03 10:10:25 +00:00
void settingsDialogImpl::setLogDir()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
QDir::homePath(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty()) lineEdit_logDir->setText(dir);
}