From 2b94ce958f554f6e571e69aa37b49fda8833dcec Mon Sep 17 00:00:00 2001 From: doitux Date: Wed, 18 Apr 2007 00:11:24 +0000 Subject: [PATCH] path to UTF8 configfile split --- TODO | 4 +- pokerth.pro | 8 +- src/config/configfile.cpp | 270 ++-------------- src/config/configfile.h | 12 +- src/engine/enginefactory.h | 3 +- .../local_engine/localenginefactory.cpp | 2 +- src/engine/local_engine/localenginefactory.h | 3 +- src/engine/local_engine/localplayer.cpp | 24 +- src/engine/local_engine/localplayer.h | 6 +- src/game.cpp | 7 +- src/game.h | 5 +- src/gui/guiinterface.h | 4 +- .../createnetworkgamedialogimpl.cpp | 19 +- .../createnetworkgamedialogimpl.h | 9 +- src/gui/qt/defaultconfig/defaultconfig.cpp | 288 ++++++++++++++++++ src/gui/qt/defaultconfig/defaultconfig.h | 44 +++ src/gui/qt/guiwrapper.cpp | 12 +- src/gui/qt/guiwrapper.h | 7 +- .../joinnetworkgamedialogimpl.cpp | 11 +- .../joinnetworkgamedialogimpl.h | 8 +- src/gui/qt/log/log.cpp | 4 +- src/gui/qt/log/log.h | 1 - src/gui/qt/mainwindow/mainwindowimpl.cpp | 25 +- src/gui/qt/mainwindow/mainwindowimpl.h | 3 +- .../newlocalgamedialog/newgamedialogimpl.cpp | 14 +- .../qt/newlocalgamedialog/newgamedialogimpl.h | 7 +- src/gui/qt/qthelper/qthelper.cpp | 30 -- src/gui/qt/qthelper/qthelper.h | 29 -- .../qt/settingsdialog/settingsdialogimpl.cpp | 174 +++++------ .../qt/settingsdialog/settingsdialogimpl.h | 5 +- src/pokerth.cpp | 8 +- src/session.cpp | 8 +- src/session.h | 9 +- 33 files changed, 565 insertions(+), 498 deletions(-) create mode 100644 src/gui/qt/defaultconfig/defaultconfig.cpp create mode 100644 src/gui/qt/defaultconfig/defaultconfig.h delete mode 100644 src/gui/qt/qthelper/qthelper.cpp delete mode 100644 src/gui/qt/qthelper/qthelper.h diff --git a/TODO b/TODO index 47041073..cdafc6fc 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,6 @@ #todo items for future releases - save games to continue at the saved game-state# -- blinking start-stop button when click start is needed for next round \ No newline at end of file +- blinking start-stop button when click start is needed for next round +- chip stack animation +- fold cards animation (throw in the center) \ No newline at end of file diff --git a/pokerth.pro b/pokerth.pro index 9125a1a2..c1f4c983 100755 --- a/pokerth.pro +++ b/pokerth.pro @@ -22,7 +22,7 @@ DEPENDPATH += . \ src/gui/qt/createnetworkgamedialog \ src/gui/qt/joinnetworkgamedialog \ src/gui/qt/log \ - src/gui/qt/qthelper \ + src/gui/qt/defaultconfig \ src/gui/qt/newlocalgamedialog \ src/gui/qt/settingsdialog \ src/gui/qt/startnetworkgamedialog \ @@ -37,7 +37,7 @@ INCLUDEPATH += . \ src/core/tinyxml \ src/gui/qt \ src/gui/qt/log \ - src/gui/qt/qthelper \ + src/gui/qt/defaultconfig \ src/gui/qt/connecttoserverdialog \ src/core \ src/gui/qt/mainwindow \ @@ -102,7 +102,7 @@ HEADERS += src/game.h \ src/gui/qt/settingsdialog/settingsdialogimpl.h \ src/gui/qt/startnetworkgamedialog/startnetworkgamedialogimpl.h \ src/gui/qt/waitforservertostartgamedialog/waitforservertostartgamedialogimpl.h \ - src/gui/qt/qthelper/qthelper.h + src/gui/qt/defaultconfig/defaultconfig.h FORMS += src/gui/qt/mainwindow.ui \ src/gui/qt/aboutpokerth.ui \ src/gui/qt/connecttoserverdialog.ui \ @@ -174,7 +174,7 @@ SOURCES += src/game.cpp \ src/gui/qt/settingsdialog/settingsdialogimpl.cpp \ src/gui/qt/startnetworkgamedialog/startnetworkgamedialogimpl.cpp \ src/gui/qt/waitforservertostartgamedialog/waitforservertostartgamedialogimpl.cpp \ - src/gui/qt/qthelper/qthelper.cpp + src/gui/qt/defaultconfig/defaultconfig.cpp RESOURCES += src/gui/qt/resources.qrc TEMPLATE = vcapp diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index ff306729..29570710 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -32,255 +32,21 @@ using namespace std; -ConfigFile::ConfigFile() -{ - // !!!! Revisionsnummer der Configdefaults !!!!! - configRev = 17; - - // Pfad und Dateinamen setzen -#ifdef _WIN32 - const char *appDataPath = getenv("AppData"); - if (appDataPath && appDataPath[0] != 0) { - configFileName = appDataPath; - } - else { - const int MaxPathSize = 1024; - char curDir[MaxPathSize + 1]; - curDir[0] = 0; - _getcwd(curDir, MaxPathSize); - curDir[MaxPathSize] = 0; - configFileName = curDir; - // Testen ob das Verzeichnis beschreibbar ist - ofstream tmpFile; - const char *tmpFileName = "pokerth_test.tmp"; - tmpFile.open((configFileName + "\\" + tmpFileName).c_str()); - if (tmpFile) { - // Erfolgreich, Verzeichnis beschreibbar. - // Datei wieder loeschen. - tmpFile.close(); - remove((configFileName + "\\" + tmpFileName).c_str()); - } - else { - // Fehlgeschlagen, Verzeichnis nicht beschreibbar - curDir[0] = 0; - GetTempPathA(MaxPathSize, curDir); - curDir[MaxPathSize] = 0; - configFileName = curDir; - } - } - //Programmordner erstellen - configFileName += "\\pokerth\\"; - mkdir(configFileName.c_str()); - //Log-File Ordner auch erstellen - logDir = configFileName; - logDir += "log-files\\"; - mkdir(logDir.c_str()); - //data Ordner auch erstellen - dataDir = configFileName; - dataDir += "data\\"; - mkdir(dataDir.c_str()); - -#else - //Programmordner erstellen - const char *homePath = getenv("HOME"); - if(homePath) { - configFileName = homePath; - configFileName += "/.pokerth/"; - mkdir(configFileName.c_str(), MODUS) ; - //Log-File Ordner auch erstellen - logDir = configFileName; - logDir += "log-files/"; - mkdir(logDir.c_str(), MODUS); - //data Ordner auch erstellen - dataDir = configFileName; - dataDir += "data/"; - mkdir(dataDir.c_str(), MODUS); - } -#endif - configFileName += "config.xml"; - - //Prüfen ob Configfile existiert --> sonst anlegen - TiXmlDocument doc(configFileName); - if(!doc.LoadFile()){ createDefaultConfig(); } - else { - //Prüfen ob die Revision stimmt ansonsten löschen und neue anlegen - int temp = 0; - TiXmlHandle docHandle( &doc ); - TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement(); - if ( conf ) { conf->QueryIntAttribute("value", &temp ); } - if (temp < configRev) { /*löschen()*/ createDefaultConfig() ;} - } - +ConfigFile::ConfigFile(std::string path) +: myPath(path) +{ } - ConfigFile::~ConfigFile() { } -void ConfigFile::createDefaultConfig() { - - //Anlegen! - TiXmlDocument doc; - TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", ""); - doc.LinkEndChild( decl ); - - TiXmlElement * root = new TiXmlElement( "PokerTH" ); - doc.LinkEndChild( root ); -// - TiXmlElement * config; - config = new TiXmlElement( "Configuration" ); - root->LinkEndChild( config ); - - - TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" ); - config->LinkEndChild( confElement0 ); - confElement0->SetAttribute("value", configRev); - TiXmlElement * confElement11 = new TiXmlElement( "ShowLeftToolBox" ); - config->LinkEndChild( confElement11 ); - confElement11->SetAttribute("value", 1); - TiXmlElement * confElement22 = new TiXmlElement( "ShowRightToolBox" ); - config->LinkEndChild( confElement22 ); - confElement22->SetAttribute("value", 1); - TiXmlElement * confElement43 = new TiXmlElement( "ShowStatusbarMessages" ); - config->LinkEndChild( confElement43 ); - confElement43->SetAttribute("value", 1); - TiXmlElement * confElement13 = new TiXmlElement( "ShowIntro" ); - config->LinkEndChild( confElement13 ); - confElement13->SetAttribute("value", 1); - TiXmlElement * confElement15 = new TiXmlElement( "ShowFadeOutCardsAnimation" ); - config->LinkEndChild( confElement15 ); - confElement15->SetAttribute("value", 1); - TiXmlElement * confElement19 = new TiXmlElement( "ShowFlipCardsAnimation" ); - config->LinkEndChild( confElement19 ); - confElement19->SetAttribute("value", 1); - TiXmlElement * confElement16 = new TiXmlElement( "FlipsideTux" ); - config->LinkEndChild( confElement16 ); - confElement16->SetAttribute("value", 1); - TiXmlElement * confElement17 = new TiXmlElement( "FlipsideOwn" ); - config->LinkEndChild( confElement17 ); - confElement17->SetAttribute("value", 0); - TiXmlElement * confElement18 = new TiXmlElement( "FlipsideOwnFile" ); - config->LinkEndChild( confElement18 ); - confElement18->SetAttribute("value", ""); - - TiXmlElement * confElement1 = new TiXmlElement( "NumberOfPlayers" ); - config->LinkEndChild( confElement1 ); - confElement1->SetAttribute("value", 7); - TiXmlElement * confElement2 = new TiXmlElement( "StartCash" ); - config->LinkEndChild( confElement2 ); - confElement2->SetAttribute("value", 3000); - TiXmlElement * confElement3 = new TiXmlElement( "SmallBlind" ); - config->LinkEndChild( confElement3 ); - confElement3->SetAttribute("value", 10); - TiXmlElement * confElement12 = new TiXmlElement( "HandsBeforeRaiseSmallBlind" ); - config->LinkEndChild( confElement12 ); - confElement12->SetAttribute("value", 8); - TiXmlElement * confElement4 = new TiXmlElement( "GameSpeed" ); - config->LinkEndChild( confElement4 ); - confElement4->SetAttribute("value", 4); - TiXmlElement * confElement32 = new TiXmlElement( "EngineVersion" ); - config->LinkEndChild( confElement32 ); - confElement32->SetAttribute("value", 0); - TiXmlElement * confElement14 = new TiXmlElement( "PauseBetweenHands" ); - config->LinkEndChild( confElement14 ); - confElement14->SetAttribute("value", 0); - TiXmlElement * confElement5 = new TiXmlElement( "ShowGameSettingsDialogOnNewGame" ); - config->LinkEndChild( confElement5 ); - confElement5->SetAttribute("value", 1); - - TiXmlElement * confElement23 = new TiXmlElement( "NetNumberOfPlayers" ); - config->LinkEndChild( confElement23 ); - confElement23->SetAttribute("value", 7); - TiXmlElement * confElement24 = new TiXmlElement( "NetStartCash" ); - config->LinkEndChild( confElement24 ); - confElement24->SetAttribute("value", 2000); - TiXmlElement * confElement25 = new TiXmlElement( "NetSmallBlind" ); - config->LinkEndChild( confElement25 ); - confElement25->SetAttribute("value", 10); - TiXmlElement * confElement26 = new TiXmlElement( "NetHandsBeforeRaiseSmallBlind" ); - config->LinkEndChild( confElement26 ); - confElement26->SetAttribute("value", 9); - TiXmlElement * confElement27 = new TiXmlElement( "NetGameSpeed" ); - config->LinkEndChild( confElement27 ); - confElement27->SetAttribute("value", 4); - TiXmlElement * confElement33 = new TiXmlElement( "NetEngineVersion" ); - config->LinkEndChild( confElement33 ); - confElement33->SetAttribute("value", 1); - TiXmlElement * confElement28 = new TiXmlElement( "ServerPassword" ); - config->LinkEndChild( confElement28 ); - confElement28->SetAttribute("value", ""); - TiXmlElement * confElement29 = new TiXmlElement( "ServerUseIpv6" ); - config->LinkEndChild( confElement29 ); - confElement29->SetAttribute("value", 0); - TiXmlElement * confElement30 = new TiXmlElement( "ServerPort" ); - config->LinkEndChild( confElement30 ); - confElement30->SetAttribute("value", 7234); - - TiXmlElement * confElement6 = new TiXmlElement( "MyName" ); - config->LinkEndChild( confElement6 ); - confElement6->SetAttribute("value", "Human Player"); - TiXmlElement * confElement34 = new TiXmlElement( "MyAvatar" ); - config->LinkEndChild( confElement34 ); - confElement34->SetAttribute("value", ""); - TiXmlElement * confElement7 = new TiXmlElement( "Opponent1Name" ); - config->LinkEndChild( confElement7 ); - confElement7->SetAttribute("value", "Player 1"); - TiXmlElement * confElement35 = new TiXmlElement( "Opponent1Avatar" ); - config->LinkEndChild( confElement35 ); - confElement35->SetAttribute("value", ""); - TiXmlElement * confElement8 = new TiXmlElement( "Opponent2Name" ); - config->LinkEndChild( confElement8 ); - confElement8->SetAttribute("value", "Player 2"); - TiXmlElement * confElement36 = new TiXmlElement( "Opponent2Avatar" ); - config->LinkEndChild( confElement36 ); - confElement36->SetAttribute("value", ""); - TiXmlElement * confElement9 = new TiXmlElement( "Opponent3Name" ); - config->LinkEndChild( confElement9 ); - confElement9->SetAttribute("value", "Player 3"); - TiXmlElement * confElement37 = new TiXmlElement( "Opponent3Avatar" ); - config->LinkEndChild( confElement37 ); - confElement37->SetAttribute("value", ""); - TiXmlElement * confElement10 = new TiXmlElement( "Opponent4Name" ); - config->LinkEndChild( confElement10 ); - confElement10->SetAttribute("value", "Player 4"); - TiXmlElement * confElement38 = new TiXmlElement( "Opponent4Avatar" ); - config->LinkEndChild( confElement38 ); - confElement38->SetAttribute("value", ""); - TiXmlElement * confElement39 = new TiXmlElement( "Opponent5Name" ); - config->LinkEndChild( confElement39 ); - confElement39->SetAttribute("value", "Player 5"); - TiXmlElement * confElement40 = new TiXmlElement( "Opponent5Avatar" ); - config->LinkEndChild( confElement40 ); - confElement40->SetAttribute("value", ""); - TiXmlElement * confElement41 = new TiXmlElement( "Opponent6Name" ); - config->LinkEndChild( confElement41 ); - confElement41->SetAttribute("value", "Player 6"); - TiXmlElement * confElement42 = new TiXmlElement( "Opponent6Avatar" ); - config->LinkEndChild( confElement42 ); - confElement42->SetAttribute("value", ""); - - TiXmlElement * confElement20 = new TiXmlElement( "LogDir" ); - config->LinkEndChild( confElement20 ); - confElement20->SetAttribute("value", logDir); - TiXmlElement * confElement21 = new TiXmlElement( "LogStoreDuration" ); - config->LinkEndChild( confElement21 ); - confElement21->SetAttribute("value", 2); - - TiXmlElement * confElement31 = new TiXmlElement( "DataDir" ); - config->LinkEndChild( confElement31 ); - confElement31->SetAttribute("value", dataDir); - - doc.SaveFile( configFileName ); - -} - string ConfigFile::readConfigString(string varName) { string tempString(""); - TiXmlDocument doc(configFileName); - if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; } + TiXmlDocument doc(myPath.c_str()); + if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << myPath << "\n"; } TiXmlHandle docHandle( &doc ); TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement(); @@ -294,7 +60,7 @@ string ConfigFile::readConfigString(string varName) TiXmlElement * confElement1 = new TiXmlElement( varName ); config->LinkEndChild( confElement1 ); confElement1->SetAttribute("value", defaultValue); - if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; } + if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; } return readConfigString(varName, defaultValue); } @@ -307,8 +73,8 @@ int ConfigFile::readConfigInt(string varName) { int tempInt=0; // cout << varName << " : " << tempInt << "\n"; - TiXmlDocument doc(configFileName); - if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; } + TiXmlDocument doc(myPath.c_str()); + if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << myPath << "\n"; } TiXmlHandle docHandle( &doc ); TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement(); @@ -323,7 +89,7 @@ int ConfigFile::readConfigInt(string varName) TiXmlElement * confElement1 = new TiXmlElement( varName ); config->LinkEndChild( confElement1 ); confElement1->SetAttribute("value", defaultValue); - if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; } + if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; } return readConfigInt(varName, defaultValue); } @@ -336,14 +102,14 @@ int ConfigFile::readConfigInt(string varName) void ConfigFile::writeConfigInt(string varName, int varCont) { - TiXmlDocument doc(configFileName); - if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; } + TiXmlDocument doc(myPath.c_str()); + if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << myPath << "\n"; } TiXmlHandle docHandle( &doc ); TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement(); if ( conf ) { conf->SetAttribute("value", varCont ); - if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; } + if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; } } else { //Wenn nicht gefunden eines neues Anlegen TiXmlElement* config = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).ToElement(); @@ -354,17 +120,17 @@ void ConfigFile::writeConfigInt(string varName, int varCont) config->LinkEndChild( confElement1 ); confElement1->SetAttribute("value", varCont); - if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; } + if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; } } } - if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; } + if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; } } void ConfigFile::writeConfigString(string varName, string varCont) { - TiXmlDocument doc(configFileName); - if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; } + TiXmlDocument doc(myPath.c_str()); + if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << myPath << "\n"; } TiXmlHandle docHandle( &doc ); TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement(); @@ -377,10 +143,10 @@ void ConfigFile::writeConfigString(string varName, string varCont) TiXmlElement * confElement1 = new TiXmlElement( varName ); config->LinkEndChild( confElement1 ); confElement1->SetAttribute("value", varCont); - if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; } + if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; } } } - if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; } + if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; } } diff --git a/src/config/configfile.h b/src/config/configfile.h index 79f948a6..b4d90a3a 100644 --- a/src/config/configfile.h +++ b/src/config/configfile.h @@ -25,25 +25,19 @@ class ConfigFile{ public: - ConfigFile(); + ConfigFile(std::string); ~ConfigFile(); - void createDefaultConfig(); - std::string readConfigString(std::string varName); void writeConfigString(std::string varName, std::string varCont); int readConfigInt(std::string varName); void writeConfigInt(std::string varName, int varCont); - private: - std::string configFileName; - std::string logDir; - std::string dataDir; - int configRev; - + + std::string myPath; }; #endif diff --git a/src/engine/enginefactory.h b/src/engine/enginefactory.h index ba17019a..fef27a9b 100644 --- a/src/engine/enginefactory.h +++ b/src/engine/enginefactory.h @@ -27,6 +27,7 @@ #include "flopinterface.h" #include "turninterface.h" #include "riverinterface.h" +#include "session.h" class EngineFactory{ @@ -36,7 +37,7 @@ public: virtual HandInterface* createHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC) =0; virtual BoardInterface* createBoard() =0; - virtual PlayerInterface* createPlayer(BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) =0; + virtual PlayerInterface* createPlayer(Session*s, BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) =0; virtual PreflopInterface* createPreflop(HandInterface* hi, int id, int aP, int dP, int sB) =0; virtual FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB) =0; virtual TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB) =0; diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index b903dfc6..97e46368 100644 --- a/src/engine/local_engine/localenginefactory.cpp +++ b/src/engine/local_engine/localenginefactory.cpp @@ -35,7 +35,7 @@ HandInterface* LocalEngineFactory::createHand(EngineFactory *f, GuiInterface *g, BoardInterface* LocalEngineFactory::createBoard() { return new LocalBoard; } -PlayerInterface* LocalEngineFactory::createPlayer(BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) { return new LocalPlayer(b, id, name, avatar, sC, aS, mB); } +PlayerInterface* LocalEngineFactory::createPlayer(Session *s, BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) { return new LocalPlayer(s, b, id, name, avatar, sC, aS, mB); } PreflopInterface* LocalEngineFactory::createPreflop(HandInterface* hi, int id, int aP, int dP, int sB) { return new LocalPreflop(hi, id, aP, dP, sB); } diff --git a/src/engine/local_engine/localenginefactory.h b/src/engine/local_engine/localenginefactory.h index 885ce2b4..bea6487b 100644 --- a/src/engine/local_engine/localenginefactory.h +++ b/src/engine/local_engine/localenginefactory.h @@ -29,6 +29,7 @@ #include "localflop.h" #include "localturn.h" #include "localriver.h" +#include "session.h" class LocalEngineFactory : public EngineFactory { @@ -39,7 +40,7 @@ public: HandInterface* createHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC); BoardInterface* createBoard(); - PlayerInterface* createPlayer(BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB); + PlayerInterface* createPlayer(Session *s, BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB); PreflopInterface* createPreflop(HandInterface* hi, int id, int aP, int dP, int sB); FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB); TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB); diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index dea654b6..17b52c4e 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -23,7 +23,7 @@ using namespace std; -LocalPlayer::LocalPlayer(BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) : PlayerInterface(), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) +LocalPlayer::LocalPlayer(Session *s, BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) : PlayerInterface(), mySession(s), actualHand(0), actualBoard(b), myCardsValue(0), myConfig(0), myID(id), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) { // for statistic development @@ -32,7 +32,9 @@ LocalPlayer::LocalPlayer(BoardInterface *b, int id, std::string name, std::strin // myCash=0; // } //////////////////////////// - + + myConfig = new ConfigFile(mySession->getConfigPath()); + // myBestHandPosition mit -1 initialisieren int i; for(i=0; i<5; i++) { @@ -83,12 +85,11 @@ void LocalPlayer::setHand(HandInterface* br) { actualHand = br; } void LocalPlayer::action() { - ConfigFile myConfig; - + switch(actualHand->getActualRound()) { case 0: { - if(myConfig.readConfigInt("EngineVersion")) preflopEngine3(); + if(myConfig->readConfigInt("EngineVersion")) preflopEngine3(); else preflopEngine(); actualBoard->collectSets(); @@ -97,7 +98,7 @@ void LocalPlayer::action() { } break; case 1: { - if(myConfig.readConfigInt("EngineVersion")) flopEngine3(); + if(myConfig->readConfigInt("EngineVersion")) flopEngine3(); else flopEngine(); actualBoard->collectSets(); @@ -106,7 +107,7 @@ void LocalPlayer::action() { } break; case 2: { - if(myConfig.readConfigInt("EngineVersion")) turnEngine3(); + if(myConfig->readConfigInt("EngineVersion")) turnEngine3(); else turnEngine(); actualBoard->collectSets(); @@ -115,7 +116,7 @@ void LocalPlayer::action() { } break; case 3: { - if(myConfig.readConfigInt("EngineVersion")) riverEngine3(); + if(myConfig->readConfigInt("EngineVersion")) riverEngine3(); else riverEngine(); actualBoard->collectSets(); @@ -809,7 +810,6 @@ void LocalPlayer::flopEngine() { void LocalPlayer::turnEngine() { - ConfigFile myConfig; // int tempArray[6]; // int boardCards[5]; @@ -1056,7 +1056,6 @@ void LocalPlayer::turnEngine() { void LocalPlayer::riverEngine() { - ConfigFile myConfig; // int tempArray[6]; // int boardCards[5]; @@ -2057,7 +2056,6 @@ int LocalPlayer::flopCardsValue(int* cards) { void LocalPlayer::readFile() { - ConfigFile myConfig; int handCode; switch(actualHand->getActualRound()) { @@ -2066,7 +2064,7 @@ void LocalPlayer::readFile() { handCode = preflopCardsValue(myCards); - std::string fileName = myConfig.readConfigString("DataDir")+"preflopValues"; + std::string fileName = myConfig->readConfigString("DataDir")+"preflopValues"; ifstream fin; @@ -2120,7 +2118,7 @@ void LocalPlayer::readFile() { // cout << "\t" << handCode << endl; - std::string fileName = myConfig.readConfigString("DataDir")+"flopValues"; + std::string fileName = myConfig->readConfigString("DataDir")+"flopValues"; ifstream fin; diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index 0e4a18c3..e40bf5b1 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -25,6 +25,7 @@ #include "cardsvalue.h" #include "configfile.h" +#include "session.h" #include #include @@ -36,7 +37,7 @@ class BoardInterface; class LocalPlayer : public PlayerInterface{ public: - LocalPlayer(BoardInterface*, int, std::string, std::string, int, bool, int); + LocalPlayer(Session*, BoardInterface*, int, std::string, std::string, int, bool, int); ~LocalPlayer(); @@ -140,10 +141,11 @@ public: private: + Session *mySession; HandInterface *actualHand; BoardInterface *actualBoard; - CardsValue *myCardsValue; + ConfigFile *myConfig; // Konstanten int myID; diff --git a/src/game.cpp b/src/game.cpp index 3d5437a0..4dde9c17 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -28,13 +28,16 @@ #include "handinterface.h" #include "configfile.h" +#include "session.h" using namespace std; -Game::Game(ConfigFile* c, GuiInterface* g, int qP, int sC, int sB, int gId) : myConfig(c), myGui(g), actualHand(0), actualBoard(0), startQuantityPlayers(qP), startCash(sC), startSmallBlind(sB), myGameID(gId), actualQuantityPlayers(qP), actualSmallBlind(sB), actualHandID(0), dealerPosition(0) +Game::Game(Session* s, GuiInterface* g, int qP, int sC, int sB, int gId) : mySession(s), myConfig(0), myGui(g), actualHand(0), actualBoard(0), startQuantityPlayers(qP), startCash(sC), startSmallBlind(sB), myGameID(gId), actualQuantityPlayers(qP), actualSmallBlind(sB), actualHandID(0), dealerPosition(0) { // cout << "Create Game Object" << "\n"; int i; + + myConfig = new ConfigFile(mySession->getConfigPath()); actualHandID = 0; @@ -69,7 +72,7 @@ Game::Game(ConfigFile* c, GuiInterface* g, int qP, int sC, int sB, int gId) : my else { myAvatar << "Opponent" << i << "Avatar"; } //PlayerObjekte erzeugen - tempPlayer = myFactory->createPlayer(actualBoard, i, myConfig->readConfigString(myName.str()), myConfig->readConfigString(myAvatar.str()), startCash, startQuantityPlayers > i, 0); + tempPlayer = myFactory->createPlayer(mySession, actualBoard, i, myConfig->readConfigString(myName.str()), myConfig->readConfigString(myAvatar.str()), startCash, startQuantityPlayers > i, 0); playerArray[i] = tempPlayer; } actualBoard->setPlayer(playerArray); diff --git a/src/game.h b/src/game.h index bc1e7cf0..e6cc83c4 100755 --- a/src/game.h +++ b/src/game.h @@ -32,12 +32,14 @@ class PlayerInterface; class BoardInterface; class EngineFactory; class ConfigFile; +class Session; + class Game { public: - Game(ConfigFile*, GuiInterface*, int, int, int, int); + Game(Session*, GuiInterface*, int, int, int, int); ~Game(); @@ -82,6 +84,7 @@ public: private: EngineFactory *myFactory; + Session *mySession; ConfigFile *myConfig; GuiInterface *myGui; diff --git a/src/gui/guiinterface.h b/src/gui/guiinterface.h index 7d73f1f0..87ff07a7 100644 --- a/src/gui/guiinterface.h +++ b/src/gui/guiinterface.h @@ -90,13 +90,11 @@ public: // virtual void timerBlockerFalse() const=0; virtual void meInAction() const=0; - //log.cpp virtual void logPlayerActionMsg(std::string playName, int action, int setValue) =0; virtual void logNewGameHandMsg(int gameID, int HandID) =0; - //qthelper.cpp - virtual std::string stringToUtf8(const std::string &) =0; + }; diff --git a/src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.cpp b/src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.cpp index 953cb4a3..67f13408 100644 --- a/src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.cpp +++ b/src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.cpp @@ -21,11 +21,13 @@ #include "session.h" #include "configfile.h" -createNetworkGameDialogImpl::createNetworkGameDialogImpl(QWidget *parent) - : QDialog(parent) +createNetworkGameDialogImpl::createNetworkGameDialogImpl(QWidget *parent, std::string path) + : QDialog(parent), myConfig(0) { - setupUi(this); + myConfig = new ConfigFile(path); + + setupUi(this); fillFormular(); @@ -46,14 +48,13 @@ void createNetworkGameDialogImpl::cancel() { void createNetworkGameDialogImpl::fillFormular() { //Formulare Füllen - ConfigFile myConfig; //Network Game Settings - spinBox_quantityPlayers->setValue(myConfig.readConfigInt("NetNumberOfPlayers")); - spinBox_startCash->setValue(myConfig.readConfigInt("NetStartCash")); - spinBox_smallBlind->setValue(myConfig.readConfigInt("NetSmallBlind")); - spinBox_handsBeforeRaiseSmallBlind->setValue(myConfig.readConfigInt("NetHandsBeforeRaiseSmallBlind")); - spinBox_gameSpeed->setValue(myConfig.readConfigInt("NetGameSpeed")); + spinBox_quantityPlayers->setValue(myConfig->readConfigInt("NetNumberOfPlayers")); + spinBox_startCash->setValue(myConfig->readConfigInt("NetStartCash")); + spinBox_smallBlind->setValue(myConfig->readConfigInt("NetSmallBlind")); + spinBox_handsBeforeRaiseSmallBlind->setValue(myConfig->readConfigInt("NetHandsBeforeRaiseSmallBlind")); + spinBox_gameSpeed->setValue(myConfig->readConfigInt("NetGameSpeed")); } void createNetworkGameDialogImpl::showDialog() { diff --git a/src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.h b/src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.h index db8f06ac..e2c3917e 100644 --- a/src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.h +++ b/src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.h @@ -23,15 +23,18 @@ #include "ui_createnetworkgamedialog.h" #include +#include #include #include class Session; +class ConfigFile; + class createNetworkGameDialogImpl: public QDialog, public Ui::createNetworkGameDialog { Q_OBJECT public: - createNetworkGameDialogImpl(QWidget *parent = 0); + createNetworkGameDialogImpl(QWidget *parent = 0, std::string = ""); public slots: @@ -40,6 +43,10 @@ public slots: void fillFormular(); void showDialog(); void keyPressEvent ( QKeyEvent * event ); +private: + + ConfigFile *myConfig; + }; #endif diff --git a/src/gui/qt/defaultconfig/defaultconfig.cpp b/src/gui/qt/defaultconfig/defaultconfig.cpp new file mode 100644 index 00000000..ceadadc2 --- /dev/null +++ b/src/gui/qt/defaultconfig/defaultconfig.cpp @@ -0,0 +1,288 @@ +/*************************************************************************** + * Copyright (C) 2006 by Felix Hammer * + * f.hammer@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 "defaultconfig.h" + +#include + +#include +#include +#include +#include +#define MODUS 0711 + +#ifdef _WIN32 +#include +#include +#endif + +using namespace std; + +DefaultConfig::DefaultConfig() +{ + // !!!! Revisionsnummer der Configdefaults !!!!! + configRev = 17; + + // Pfad und Dateinamen setzen +#ifdef _WIN32 + const char *appDataPath = getenv("AppData"); + if (appDataPath && appDataPath[0] != 0) { + configFileName = appDataPath; + } + else { + const int MaxPathSize = 1024; + char curDir[MaxPathSize + 1]; + curDir[0] = 0; + _getcwd(curDir, MaxPathSize); + curDir[MaxPathSize] = 0; + configFileName = curDir; + // Testen ob das Verzeichnis beschreibbar ist + ofstream tmpFile; + const char *tmpFileName = "pokerth_test.tmp"; + tmpFile.open((configFileName + "\\" + tmpFileName).c_str()); + if (tmpFile) { + // Erfolgreich, Verzeichnis beschreibbar. + // Datei wieder loeschen. + tmpFile.close(); + remove((configFileName + "\\" + tmpFileName).c_str()); + } + else { + // Fehlgeschlagen, Verzeichnis nicht beschreibbar + curDir[0] = 0; + GetTempPathA(MaxPathSize, curDir); + curDir[MaxPathSize] = 0; + configFileName = curDir; + } + } + + //UTF8 !!!! + QString tmpString = QString::fromStdString(configFileName); + configFileName = tmpString.toUtf8().constData(); + //UTF8 !!!! + + + //Programmordner erstellen + configFileName += "\\pokerth\\"; + mkdir(configFileName.c_str()); + //Log-File Ordner auch erstellen + logDir = configFileName; + logDir += "log-files\\"; + mkdir(logDir.c_str()); + //data Ordner auch erstellen + dataDir = configFileName; + dataDir += "data\\"; + mkdir(dataDir.c_str()); + +#else + //Programmordner erstellen + const char *homePath = getenv("HOME"); + if(homePath) { + configFileName = homePath; + configFileName += "/.pokerth/"; + mkdir(configFileName.c_str(), MODUS) ; + //Log-File Ordner auch erstellen + logDir = configFileName; + logDir += "log-files/"; + mkdir(logDir.c_str(), MODUS); + //data Ordner auch erstellen + dataDir = configFileName; + dataDir += "data/"; + mkdir(dataDir.c_str(), MODUS); + } +#endif + configFileName += "config.xml"; + + //Prüfen ob Configfile existiert --> sonst anlegen + + TiXmlDocument doc(configFileName); + if(!doc.LoadFile()){ createDefaultConfig(); } + else { + + //Prüfen ob die Revision stimmt ansonsten löschen und neue anlegen + int temp = 0; + TiXmlHandle docHandle( &doc ); + TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement(); + if ( conf ) { conf->QueryIntAttribute("value", &temp ); } + + if (temp < configRev) { /*löschen()*/ createDefaultConfig() ;} + } + +} + + +DefaultConfig::~DefaultConfig() +{ +} + +void DefaultConfig::createDefaultConfig() { + + //Anlegen! + TiXmlDocument doc; + TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", ""); + doc.LinkEndChild( decl ); + + TiXmlElement * root = new TiXmlElement( "PokerTH" ); + doc.LinkEndChild( root ); +// + TiXmlElement * config; + config = new TiXmlElement( "Configuration" ); + root->LinkEndChild( config ); + + + TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" ); + config->LinkEndChild( confElement0 ); + confElement0->SetAttribute("value", configRev); + TiXmlElement * confElement11 = new TiXmlElement( "ShowLeftToolBox" ); + config->LinkEndChild( confElement11 ); + confElement11->SetAttribute("value", 1); + TiXmlElement * confElement22 = new TiXmlElement( "ShowRightToolBox" ); + config->LinkEndChild( confElement22 ); + confElement22->SetAttribute("value", 1); + TiXmlElement * confElement43 = new TiXmlElement( "ShowStatusbarMessages" ); + config->LinkEndChild( confElement43 ); + confElement43->SetAttribute("value", 1); + TiXmlElement * confElement13 = new TiXmlElement( "ShowIntro" ); + config->LinkEndChild( confElement13 ); + confElement13->SetAttribute("value", 1); + TiXmlElement * confElement15 = new TiXmlElement( "ShowFadeOutCardsAnimation" ); + config->LinkEndChild( confElement15 ); + confElement15->SetAttribute("value", 1); + TiXmlElement * confElement19 = new TiXmlElement( "ShowFlipCardsAnimation" ); + config->LinkEndChild( confElement19 ); + confElement19->SetAttribute("value", 1); + TiXmlElement * confElement16 = new TiXmlElement( "FlipsideTux" ); + config->LinkEndChild( confElement16 ); + confElement16->SetAttribute("value", 1); + TiXmlElement * confElement17 = new TiXmlElement( "FlipsideOwn" ); + config->LinkEndChild( confElement17 ); + confElement17->SetAttribute("value", 0); + TiXmlElement * confElement18 = new TiXmlElement( "FlipsideOwnFile" ); + config->LinkEndChild( confElement18 ); + confElement18->SetAttribute("value", ""); + + TiXmlElement * confElement1 = new TiXmlElement( "NumberOfPlayers" ); + config->LinkEndChild( confElement1 ); + confElement1->SetAttribute("value", 7); + TiXmlElement * confElement2 = new TiXmlElement( "StartCash" ); + config->LinkEndChild( confElement2 ); + confElement2->SetAttribute("value", 3000); + TiXmlElement * confElement3 = new TiXmlElement( "SmallBlind" ); + config->LinkEndChild( confElement3 ); + confElement3->SetAttribute("value", 10); + TiXmlElement * confElement12 = new TiXmlElement( "HandsBeforeRaiseSmallBlind" ); + config->LinkEndChild( confElement12 ); + confElement12->SetAttribute("value", 8); + TiXmlElement * confElement4 = new TiXmlElement( "GameSpeed" ); + config->LinkEndChild( confElement4 ); + confElement4->SetAttribute("value", 4); + TiXmlElement * confElement32 = new TiXmlElement( "EngineVersion" ); + config->LinkEndChild( confElement32 ); + confElement32->SetAttribute("value", 0); + TiXmlElement * confElement14 = new TiXmlElement( "PauseBetweenHands" ); + config->LinkEndChild( confElement14 ); + confElement14->SetAttribute("value", 0); + TiXmlElement * confElement5 = new TiXmlElement( "ShowGameSettingsDialogOnNewGame" ); + config->LinkEndChild( confElement5 ); + confElement5->SetAttribute("value", 1); + + TiXmlElement * confElement23 = new TiXmlElement( "NetNumberOfPlayers" ); + config->LinkEndChild( confElement23 ); + confElement23->SetAttribute("value", 7); + TiXmlElement * confElement24 = new TiXmlElement( "NetStartCash" ); + config->LinkEndChild( confElement24 ); + confElement24->SetAttribute("value", 2000); + TiXmlElement * confElement25 = new TiXmlElement( "NetSmallBlind" ); + config->LinkEndChild( confElement25 ); + confElement25->SetAttribute("value", 10); + TiXmlElement * confElement26 = new TiXmlElement( "NetHandsBeforeRaiseSmallBlind" ); + config->LinkEndChild( confElement26 ); + confElement26->SetAttribute("value", 9); + TiXmlElement * confElement27 = new TiXmlElement( "NetGameSpeed" ); + config->LinkEndChild( confElement27 ); + confElement27->SetAttribute("value", 4); + TiXmlElement * confElement33 = new TiXmlElement( "NetEngineVersion" ); + config->LinkEndChild( confElement33 ); + confElement33->SetAttribute("value", 1); + TiXmlElement * confElement28 = new TiXmlElement( "ServerPassword" ); + config->LinkEndChild( confElement28 ); + confElement28->SetAttribute("value", ""); + TiXmlElement * confElement29 = new TiXmlElement( "ServerUseIpv6" ); + config->LinkEndChild( confElement29 ); + confElement29->SetAttribute("value", 0); + TiXmlElement * confElement30 = new TiXmlElement( "ServerPort" ); + config->LinkEndChild( confElement30 ); + confElement30->SetAttribute("value", 7234); + + TiXmlElement * confElement6 = new TiXmlElement( "MyName" ); + config->LinkEndChild( confElement6 ); + confElement6->SetAttribute("value", "Human Player"); + TiXmlElement * confElement34 = new TiXmlElement( "MyAvatar" ); + config->LinkEndChild( confElement34 ); + confElement34->SetAttribute("value", ""); + TiXmlElement * confElement7 = new TiXmlElement( "Opponent1Name" ); + config->LinkEndChild( confElement7 ); + confElement7->SetAttribute("value", "Player 1"); + TiXmlElement * confElement35 = new TiXmlElement( "Opponent1Avatar" ); + config->LinkEndChild( confElement35 ); + confElement35->SetAttribute("value", ""); + TiXmlElement * confElement8 = new TiXmlElement( "Opponent2Name" ); + config->LinkEndChild( confElement8 ); + confElement8->SetAttribute("value", "Player 2"); + TiXmlElement * confElement36 = new TiXmlElement( "Opponent2Avatar" ); + config->LinkEndChild( confElement36 ); + confElement36->SetAttribute("value", ""); + TiXmlElement * confElement9 = new TiXmlElement( "Opponent3Name" ); + config->LinkEndChild( confElement9 ); + confElement9->SetAttribute("value", "Player 3"); + TiXmlElement * confElement37 = new TiXmlElement( "Opponent3Avatar" ); + config->LinkEndChild( confElement37 ); + confElement37->SetAttribute("value", ""); + TiXmlElement * confElement10 = new TiXmlElement( "Opponent4Name" ); + config->LinkEndChild( confElement10 ); + confElement10->SetAttribute("value", "Player 4"); + TiXmlElement * confElement38 = new TiXmlElement( "Opponent4Avatar" ); + config->LinkEndChild( confElement38 ); + confElement38->SetAttribute("value", ""); + TiXmlElement * confElement39 = new TiXmlElement( "Opponent5Name" ); + config->LinkEndChild( confElement39 ); + confElement39->SetAttribute("value", "Player 5"); + TiXmlElement * confElement40 = new TiXmlElement( "Opponent5Avatar" ); + config->LinkEndChild( confElement40 ); + confElement40->SetAttribute("value", ""); + TiXmlElement * confElement41 = new TiXmlElement( "Opponent6Name" ); + config->LinkEndChild( confElement41 ); + confElement41->SetAttribute("value", "Player 6"); + TiXmlElement * confElement42 = new TiXmlElement( "Opponent6Avatar" ); + config->LinkEndChild( confElement42 ); + confElement42->SetAttribute("value", ""); + + TiXmlElement * confElement20 = new TiXmlElement( "LogDir" ); + config->LinkEndChild( confElement20 ); + confElement20->SetAttribute("value", logDir); + TiXmlElement * confElement21 = new TiXmlElement( "LogStoreDuration" ); + config->LinkEndChild( confElement21 ); + confElement21->SetAttribute("value", 2); + + TiXmlElement * confElement31 = new TiXmlElement( "DataDir" ); + config->LinkEndChild( confElement31 ); + confElement31->SetAttribute("value", dataDir); + + doc.SaveFile( configFileName ); + +} diff --git a/src/gui/qt/defaultconfig/defaultconfig.h b/src/gui/qt/defaultconfig/defaultconfig.h new file mode 100644 index 00000000..1a556af3 --- /dev/null +++ b/src/gui/qt/defaultconfig/defaultconfig.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2006 by Felix Hammer * + * f.hammer@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. * + ***************************************************************************/ +#ifndef DEFAULTCONFIG_H +#define DEFAULTCONFIG_H + +#include "tinyxml.h" +#include + +class DefaultConfig{ +public: + DefaultConfig(); + + ~DefaultConfig(); + + void createDefaultConfig(); + + std::string getMyPath() const { return configFileName; } + +private: + std::string configFileName; + std::string logDir; + std::string dataDir; + int configRev; + +}; + +#endif diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index 56272914..81f5f121 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -24,16 +24,13 @@ using namespace std; -GuiWrapper::GuiWrapper() : myLog(0), myW(0) +GuiWrapper::GuiWrapper(Session *session) : myLog(0), myW(0) { - - - myW = new mainWindowImpl; + myW = new mainWindowImpl(session); myW->show(); myLog = new Log(myW); - myConfig = new ConfigFile; - + } @@ -88,9 +85,6 @@ void GuiWrapper::meInAction() const { myW->meInAction(); } void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->logPlayerActionMsg(playerName, action, setValue); } void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->logNewGameHandMsg(gameID, handID); } -std::string GuiWrapper::stringToUtf8(const std::string &myString) { return myQtHelper->stringToUtf8(myString); } - - void GuiWrapper::SignalNetClientConnect(int actionID) { myW->SignalNetClientConnect(actionID); } void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->SignalNetClientGameInfo(actionID); } void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->SignalNetClientError(errorID, osErrorID); } diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index 8990b6f8..e4ecc2ea 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -25,7 +25,6 @@ #include "log.h" #include "mainwindowimpl.h" #include "connecttoserverdialogimpl.h" -#include "qthelper.h" #include "configfile.h" #include @@ -39,7 +38,7 @@ class GuiWrapper : public GuiInterface { public: - GuiWrapper(); + GuiWrapper(Session*); ~GuiWrapper(); @@ -89,8 +88,6 @@ public: void logPlayerActionMsg(std::string playerName, int action, int setValue) ; void logNewGameHandMsg(int gameID, int handID) ; - std::string stringToUtf8(const std::string &); - void SignalNetClientConnect(int actionID); void SignalNetClientGameInfo(int actionID); void SignalNetClientError(int errorID, int osErrorID); @@ -103,8 +100,6 @@ private: Log *myLog; mainWindowImpl *myW; - ConfigFile *myConfig; - QtHelper *myQtHelper; }; diff --git a/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.cpp b/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.cpp index b5b3874f..c5ec1599 100644 --- a/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.cpp +++ b/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.cpp @@ -24,11 +24,12 @@ using namespace std; -joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent) - : QDialog(parent) +joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent, std::string path) + : QDialog(parent), myConfig(0) { - - setupUi(this); + myConfig = new ConfigFile(path); + + setupUi(this); //Profile Name darf nicht mit einer Zahl beginnen --> XML konform QRegExp rx("[A-Z|a-z]+[A-Z|a-z|\\d]*"); @@ -39,7 +40,7 @@ joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent) lineEdit_ipAddress->setFocus(); - myServerProfilesFile = myConfig.readConfigString("DataDir")+"serverprofiles.xml"; + myServerProfilesFile = myConfig->readConfigString("DataDir")+"serverprofiles.xml"; //Anlegen wenn noch nicht existiert! QFile serverProfilesfile(QString::fromUtf8(myServerProfilesFile.c_str())); diff --git a/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.h b/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.h index 32b70e84..3e4fafad 100644 --- a/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.h +++ b/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.h @@ -24,7 +24,6 @@ #include #include -#include "configfile.h" #include #include @@ -34,9 +33,9 @@ class ConfigFile; class joinNetworkGameDialogImpl: public QDialog, public Ui::joinNetworkGameDialog { Q_OBJECT public: - joinNetworkGameDialogImpl(QWidget *parent = 0); + joinNetworkGameDialogImpl(QWidget *parent = 0, std::string = ""); - ConfigFile myConfig; + std::string myServerProfilesFile; public slots: @@ -47,6 +46,9 @@ public slots: void saveServerProfile(); void deleteServerProfile(); void keyPressEvent ( QKeyEvent * event ); + +private: + ConfigFile *myConfig; }; #endif diff --git a/src/gui/qt/log/log.cpp b/src/gui/qt/log/log.cpp index 7e40422e..d98b96af 100644 --- a/src/gui/qt/log/log.cpp +++ b/src/gui/qt/log/log.cpp @@ -21,6 +21,7 @@ #include "mainwindowimpl.h" #include +#include "session.h" using namespace std; @@ -28,7 +29,8 @@ Log::Log(mainWindowImpl* w) : myW(w) { myW->setLog(this); - myConfig = new ConfigFile; + myConfig = new ConfigFile(myW->getSession()->getConfigPath()); + if(myConfig->readConfigString("LogDir") != "" && QDir::QDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())).exists()) { #ifdef _WIN32 diff --git a/src/gui/qt/log/log.h b/src/gui/qt/log/log.h index 6553aa52..b1b53fe8 100644 --- a/src/gui/qt/log/log.h +++ b/src/gui/qt/log/log.h @@ -30,7 +30,6 @@ class mainWindowImpl; - class Log{ public: Log(mainWindowImpl*); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 688596c9..206083d2 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -39,6 +39,7 @@ #include "log.h" #include "configfile.h" +#include "defaultconfig.h" #include @@ -48,8 +49,8 @@ using namespace std; -mainWindowImpl::mainWindowImpl(QMainWindow *parent) - : QMainWindow(parent), actualGame(0), actualHand(0), mySession(0), gameSpeed(0), debugMode(0), breakAfterActualHand(FALSE) +mainWindowImpl::mainWindowImpl(Session* s, QMainWindow *parent) + : QMainWindow(parent), actualGame(0), actualHand(0), mySession(s), gameSpeed(0), debugMode(0), breakAfterActualHand(FALSE) { int i; @@ -59,7 +60,13 @@ mainWindowImpl::mainWindowImpl(QMainWindow *parent) } //////////////////////////// - myConfig = new ConfigFile; + //Create Defaultconfig if there is no one + DefaultConfig myDefaultConfig; + + //set SessionConfigPath + mySession->setConfigPath(myDefaultConfig.getMyPath()); + + myConfig = new ConfigFile(mySession->getConfigPath()); // Resourcen abladen QFile preflopValuesFile(":data/resources/data/preflopValues"); @@ -479,10 +486,10 @@ mainWindowImpl::mainWindowImpl(QMainWindow *parent) } //Dialoge - myJoinNetworkGameDialog = new joinNetworkGameDialogImpl(this); + myJoinNetworkGameDialog = new joinNetworkGameDialogImpl(this, mySession->getConfigPath()); myConnectToServerDialog = new connectToServerDialogImpl(this); myStartNetworkGameDialog = new startNetworkGameDialogImpl(this); - myCreateNetworkGameDialog = new createNetworkGameDialogImpl(this); + myCreateNetworkGameDialog = new createNetworkGameDialogImpl(this, mySession->getConfigPath()); myWaitingForServerGameDialog = new waitForServerToStartGameDialogImpl(this); //Connects @@ -554,7 +561,7 @@ void mainWindowImpl::callNewGameDialog() { //wenn Dialogfenster gezeigt werden soll if(myConfig->readConfigInt("ShowGameSettingsDialogOnNewGame")){ - newGameDialogImpl *v = new newGameDialogImpl(this); + newGameDialogImpl *v = new newGameDialogImpl(this, mySession->getConfigPath()); v->exec(); if (v->result() == QDialog::Accepted ) { startNewLocalGame(v); } // else { startNewLocalGame(); } @@ -685,7 +692,7 @@ void mainWindowImpl::callJoinNetworkGameDialog() { void mainWindowImpl::callSettingsDialog() { - settingsDialogImpl *v = new settingsDialogImpl(this); + settingsDialogImpl *v = new settingsDialogImpl(this, mySession->getConfigPath()); v->exec(); @@ -826,7 +833,7 @@ void mainWindowImpl::refreshPlayerAvatar() { if(actualHand->getPlayerArray()[i]->getMyActiveStatus()) { if(!i) { - if(actualHand->getPlayerArray()[0]->getMyAvatar() == "") { + if(actualHand->getPlayerArray()[0]->getMyAvatar() == ""/* || !QDir::QDir(QString::fromUtf8(actualHand->getPlayerArray()[0]->getMyAvatar().c_str())).exists()*/) { playerAvatarLabelArray[0]->setPixmap(QPixmap(":/guiv2/resources/guiv2/genereticAvatar.png")); } else { @@ -834,7 +841,7 @@ void mainWindowImpl::refreshPlayerAvatar() { } } else { - if(actualHand->getPlayerArray()[i]->getMyAvatar() == "") { + if(actualHand->getPlayerArray()[i]->getMyAvatar() == ""/* || !QDir::QDir(QString::fromUtf8(actualHand->getPlayerArray()[i]->getMyAvatar().c_str())).exists()*/) { playerAvatarLabelArray[i]->setPixmap(QPixmap(":/guiv2/resources/guiv2/genereticAvatar.png")); } else { diff --git a/src/gui/qt/mainwindow/mainwindowimpl.h b/src/gui/qt/mainwindow/mainwindowimpl.h index 9e5b2cee..ae0975a2 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.h +++ b/src/gui/qt/mainwindow/mainwindowimpl.h @@ -53,13 +53,14 @@ class mainWindowImpl: public QMainWindow, public Ui::mainWindow { Q_OBJECT public: - mainWindowImpl(QMainWindow *parent = 0 ); + mainWindowImpl(Session* = 0, QMainWindow *parent = 0 ); ~mainWindowImpl(); void setGame(Game*); void setHand(HandInterface*); void setSession(Session*); + Session* getSession() { return mySession; } void setLog(Log*); void setActualHand(HandInterface* theValue) { actualHand = theValue;} diff --git a/src/gui/qt/newlocalgamedialog/newgamedialogimpl.cpp b/src/gui/qt/newlocalgamedialog/newgamedialogimpl.cpp index 488a3cdc..a0b11608 100755 --- a/src/gui/qt/newlocalgamedialog/newgamedialogimpl.cpp +++ b/src/gui/qt/newlocalgamedialog/newgamedialogimpl.cpp @@ -20,22 +20,22 @@ #include "newgamedialogimpl.h" #include "configfile.h" -newGameDialogImpl::newGameDialogImpl(QWidget *parent) +newGameDialogImpl::newGameDialogImpl(QWidget *parent, std::string path) : QDialog(parent) { setupUi(this); //Formulare Füllen - ConfigFile myConfig; + myConfig = new ConfigFile(path); //Game Settings - spinBox_quantityPlayers->setValue(myConfig.readConfigInt("NumberOfPlayers")); - spinBox_startCash->setValue(myConfig.readConfigInt("StartCash")); - spinBox_smallBlind->setValue(myConfig.readConfigInt("SmallBlind")); - spinBox_gameSpeed->setValue(myConfig.readConfigInt("GameSpeed")); - spinBox_handsBeforeRaiseSmallBlind->setValue(myConfig.readConfigInt("HandsBeforeRaiseSmallBlind")); + spinBox_quantityPlayers->setValue(myConfig->readConfigInt("NumberOfPlayers")); + spinBox_startCash->setValue(myConfig->readConfigInt("StartCash")); + spinBox_smallBlind->setValue(myConfig->readConfigInt("SmallBlind")); + spinBox_gameSpeed->setValue(myConfig->readConfigInt("GameSpeed")); + spinBox_handsBeforeRaiseSmallBlind->setValue(myConfig->readConfigInt("HandsBeforeRaiseSmallBlind")); } diff --git a/src/gui/qt/newlocalgamedialog/newgamedialogimpl.h b/src/gui/qt/newlocalgamedialog/newgamedialogimpl.h index d147bda0..c29ce57d 100755 --- a/src/gui/qt/newlocalgamedialog/newgamedialogimpl.h +++ b/src/gui/qt/newlocalgamedialog/newgamedialogimpl.h @@ -23,17 +23,22 @@ #include "ui_newgamedialog.h" #include +#include #include #include +class ConfigFile; class newGameDialogImpl: public QDialog, public Ui::newGameDialog { Q_OBJECT public: - newGameDialogImpl(QWidget *parent = 0); + newGameDialogImpl(QWidget *parent = 0, std::string = ""); public slots: + +private: + ConfigFile *myConfig; }; #endif diff --git a/src/gui/qt/qthelper/qthelper.cpp b/src/gui/qt/qthelper/qthelper.cpp deleted file mode 100644 index 3c8273ca..00000000 --- a/src/gui/qt/qthelper/qthelper.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// -// C++ Implementation: qthelper -// -// Description: -// -// -// Author: FThauer FHammer , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// -#include "qthelper.h" - -QtHelper::QtHelper() -{ -} - - -QtHelper::~QtHelper() -{ -} - -std::string QtHelper::stringToUtf8(const std::string &myString) { - - QString tmpString = QString::fromStdString(myString); - std::string myUtf8String = tmpString.toUtf8().constData(); - - return myUtf8String; -} - diff --git a/src/gui/qt/qthelper/qthelper.h b/src/gui/qt/qthelper/qthelper.h deleted file mode 100644 index 49ba2cb5..00000000 --- a/src/gui/qt/qthelper/qthelper.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// C++ Interface: qthelper -// -// Description: -// -// -// Author: FThauer FHammer , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// -#ifndef QTHELPER_H -#define QTHELPER_H - -#include -/** - @author FThauer FHammer -*/ -class QtHelper{ -public: - QtHelper(); - - ~QtHelper(); - - std::string stringToUtf8(const std::string &); - -}; - -#endif diff --git a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp index 38b389bb..7b095945 100644 --- a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp +++ b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp @@ -22,9 +22,10 @@ #include -settingsDialogImpl::settingsDialogImpl(QWidget *parent) +settingsDialogImpl::settingsDialogImpl(QWidget *parent, std::string path) : QDialog(parent) { + myConfig = new ConfigFile(path); setupUi(this); @@ -35,64 +36,64 @@ settingsDialogImpl::settingsDialogImpl(QWidget *parent) playerNickIsChanged = FALSE; //Formulare Füllen - ConfigFile myConfig; + //Player Nicks - lineEdit_humanPlayerName->setText(QString::fromUtf8(myConfig.readConfigString("MyName").c_str())); - lineEdit_humanPlayerAvatar->setText(QString::fromUtf8(myConfig.readConfigString("MyAvatar").c_str())); - lineEdit_Opponent1Name->setText(QString::fromUtf8(myConfig.readConfigString("Opponent1Name").c_str())); - lineEdit_Opponent1Avatar->setText(QString::fromUtf8(myConfig.readConfigString("Opponent1Avatar").c_str())); - lineEdit_Opponent2Name->setText(QString::fromUtf8(myConfig.readConfigString("Opponent2Name").c_str())); - lineEdit_Opponent2Avatar->setText(QString::fromUtf8(myConfig.readConfigString("Opponent2Avatar").c_str())); - lineEdit_Opponent3Name->setText(QString::fromUtf8(myConfig.readConfigString("Opponent3Name").c_str())); - lineEdit_Opponent3Avatar->setText(QString::fromUtf8(myConfig.readConfigString("Opponent3Avatar").c_str())); - lineEdit_Opponent4Name->setText(QString::fromUtf8(myConfig.readConfigString("Opponent4Name").c_str())); - lineEdit_Opponent4Avatar->setText(QString::fromUtf8(myConfig.readConfigString("Opponent4Avatar").c_str())); - lineEdit_Opponent5Name->setText(QString::fromUtf8(myConfig.readConfigString("Opponent5Name").c_str())); - lineEdit_Opponent5Avatar->setText(QString::fromUtf8(myConfig.readConfigString("Opponent5Avatar").c_str())); - lineEdit_Opponent6Name->setText(QString::fromUtf8(myConfig.readConfigString("Opponent6Name").c_str())); - lineEdit_Opponent6Avatar->setText(QString::fromUtf8(myConfig.readConfigString("Opponent6Avatar").c_str())); + lineEdit_humanPlayerName->setText(QString::fromUtf8(myConfig->readConfigString("MyName").c_str())); + lineEdit_humanPlayerAvatar->setText(QString::fromUtf8(myConfig->readConfigString("MyAvatar").c_str())); + lineEdit_Opponent1Name->setText(QString::fromUtf8(myConfig->readConfigString("Opponent1Name").c_str())); + lineEdit_Opponent1Avatar->setText(QString::fromUtf8(myConfig->readConfigString("Opponent1Avatar").c_str())); + lineEdit_Opponent2Name->setText(QString::fromUtf8(myConfig->readConfigString("Opponent2Name").c_str())); + lineEdit_Opponent2Avatar->setText(QString::fromUtf8(myConfig->readConfigString("Opponent2Avatar").c_str())); + lineEdit_Opponent3Name->setText(QString::fromUtf8(myConfig->readConfigString("Opponent3Name").c_str())); + lineEdit_Opponent3Avatar->setText(QString::fromUtf8(myConfig->readConfigString("Opponent3Avatar").c_str())); + lineEdit_Opponent4Name->setText(QString::fromUtf8(myConfig->readConfigString("Opponent4Name").c_str())); + lineEdit_Opponent4Avatar->setText(QString::fromUtf8(myConfig->readConfigString("Opponent4Avatar").c_str())); + lineEdit_Opponent5Name->setText(QString::fromUtf8(myConfig->readConfigString("Opponent5Name").c_str())); + lineEdit_Opponent5Avatar->setText(QString::fromUtf8(myConfig->readConfigString("Opponent5Avatar").c_str())); + lineEdit_Opponent6Name->setText(QString::fromUtf8(myConfig->readConfigString("Opponent6Name").c_str())); + lineEdit_Opponent6Avatar->setText(QString::fromUtf8(myConfig->readConfigString("Opponent6Avatar").c_str())); //Local Game Settings - 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")); - comboBox_engineVersion->setCurrentIndex(myConfig.readConfigInt("EngineVersion")); + 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")); + comboBox_engineVersion->setCurrentIndex(myConfig->readConfigInt("EngineVersion")); //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")); - comboBox_netEngineVersion->setCurrentIndex(myConfig.readConfigInt("NetEngineVersion")); - spinBox_serverPort->setValue(myConfig.readConfigInt("ServerPort")); - lineEdit_serverPassword->setText(QString::fromUtf8(myConfig.readConfigString("ServerPassword").c_str())); - checkBox_useIpv6->setChecked(myConfig.readConfigInt("ServerUseIpv6")); + 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")); + comboBox_netEngineVersion->setCurrentIndex(myConfig->readConfigInt("NetEngineVersion")); + spinBox_serverPort->setValue(myConfig->readConfigInt("ServerPort")); + lineEdit_serverPassword->setText(QString::fromUtf8(myConfig->readConfigString("ServerPassword").c_str())); + checkBox_useIpv6->setChecked(myConfig->readConfigInt("ServerUseIpv6")); //Interface - checkBox_showLeftToolbox->setChecked(myConfig.readConfigInt("ShowLeftToolBox")); - checkBox_showRightToolbox->setChecked(myConfig.readConfigInt("ShowRightToolBox")); - checkBox_showStatusbarMessages->setChecked(myConfig.readConfigInt("ShowStatusbarMessages")); - 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")); + checkBox_showLeftToolbox->setChecked(myConfig->readConfigInt("ShowLeftToolBox")); + checkBox_showRightToolbox->setChecked(myConfig->readConfigInt("ShowRightToolBox")); + checkBox_showStatusbarMessages->setChecked(myConfig->readConfigInt("ShowStatusbarMessages")); + 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")); if(radioButton_flipsideOwn->isChecked()) { lineEdit_OwnFlipsideFilename->setEnabled(TRUE); pushButton_openFlipsidePicture->setEnabled(TRUE); } - lineEdit_OwnFlipsideFilename->setText(QString::fromUtf8(myConfig.readConfigString("FlipsideOwnFile").c_str())); + lineEdit_OwnFlipsideFilename->setText(QString::fromUtf8(myConfig->readConfigString("FlipsideOwnFile").c_str())); //Log - lineEdit_logDir->setText(QString::fromUtf8(myConfig.readConfigString("LogDir").c_str())); - spinBox_logStoreDuration->setValue(myConfig.readConfigInt("LogStoreDuration")); + lineEdit_logDir->setText(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())); + spinBox_logStoreDuration->setValue(myConfig->readConfigInt("LogStoreDuration")); connect( buttonBox, SIGNAL( accepted() ), this, SLOT( isAccepted() ) ); connect( lineEdit_humanPlayerName, SIGNAL( textChanged( const QString &) ), this, SLOT( playerNickChanged() ) ); @@ -118,12 +119,11 @@ void settingsDialogImpl::isAccepted() { settingsCorrect = TRUE; //Daten speichern - ConfigFile myConfig; // Player Nicks - myConfig.writeConfigString("MyName", lineEdit_humanPlayerName->text().toUtf8().constData()); + myConfig->writeConfigString("MyName", lineEdit_humanPlayerName->text().toUtf8().constData()); if(QFile::QFile(lineEdit_humanPlayerAvatar->text()).exists() || lineEdit_humanPlayerAvatar->text() == "") { - myConfig.writeConfigString("MyAvatar", lineEdit_humanPlayerAvatar->text().toUtf8().constData()); + myConfig->writeConfigString("MyAvatar", lineEdit_humanPlayerAvatar->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The entered human player avatar picture doesn't exists.\n" @@ -132,9 +132,9 @@ void settingsDialogImpl::isAccepted() { settingsCorrect = FALSE; } - myConfig.writeConfigString("Opponent1Name", lineEdit_Opponent1Name->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent1Name", lineEdit_Opponent1Name->text().toUtf8().constData()); if(QFile::QFile(lineEdit_Opponent1Avatar->text()).exists() || lineEdit_Opponent1Avatar->text() == "") { - myConfig.writeConfigString("Opponent1Avatar", lineEdit_Opponent1Avatar->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent1Avatar", lineEdit_Opponent1Avatar->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The entered \"opponent 1\" avatar picture doesn't exists.\n" @@ -143,9 +143,9 @@ void settingsDialogImpl::isAccepted() { settingsCorrect = FALSE; } - myConfig.writeConfigString("Opponent2Name", lineEdit_Opponent2Name->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent2Name", lineEdit_Opponent2Name->text().toUtf8().constData()); if(QFile::QFile(lineEdit_Opponent2Avatar->text()).exists() || lineEdit_Opponent2Avatar->text() == "") { - myConfig.writeConfigString("Opponent2Avatar", lineEdit_Opponent2Avatar->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent2Avatar", lineEdit_Opponent2Avatar->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The entered \"opponent 2\" avatar picture doesn't exists.\n" @@ -154,9 +154,9 @@ void settingsDialogImpl::isAccepted() { settingsCorrect = FALSE; } - myConfig.writeConfigString("Opponent3Name", lineEdit_Opponent3Name->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent3Name", lineEdit_Opponent3Name->text().toUtf8().constData()); if(QFile::QFile(lineEdit_Opponent3Avatar->text()).exists() || lineEdit_Opponent3Avatar->text() == "") { - myConfig.writeConfigString("Opponent3Avatar", lineEdit_Opponent3Avatar->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent3Avatar", lineEdit_Opponent3Avatar->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The entered \"opponent 3\" avatar picture doesn't exists.\n" @@ -165,9 +165,9 @@ void settingsDialogImpl::isAccepted() { settingsCorrect = FALSE; } - myConfig.writeConfigString("Opponent4Name", lineEdit_Opponent4Name->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent4Name", lineEdit_Opponent4Name->text().toUtf8().constData()); if(QFile::QFile(lineEdit_Opponent4Avatar->text()).exists() || lineEdit_Opponent4Avatar->text() == "") { - myConfig.writeConfigString("Opponent4Avatar", lineEdit_Opponent4Avatar->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent4Avatar", lineEdit_Opponent4Avatar->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The entered \"opponent 4\" avatar picture doesn't exists.\n" @@ -176,9 +176,9 @@ void settingsDialogImpl::isAccepted() { settingsCorrect = FALSE; } - myConfig.writeConfigString("Opponent5Name", lineEdit_Opponent5Name->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent5Name", lineEdit_Opponent5Name->text().toUtf8().constData()); if(QFile::QFile(lineEdit_Opponent5Avatar->text()).exists() || lineEdit_Opponent5Avatar->text() == "") { - myConfig.writeConfigString("Opponent5Avatar", lineEdit_Opponent5Avatar->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent5Avatar", lineEdit_Opponent5Avatar->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The entered \"opponent 5\" avatar picture doesn't exists.\n" @@ -187,9 +187,9 @@ void settingsDialogImpl::isAccepted() { settingsCorrect = FALSE; } - myConfig.writeConfigString("Opponent6Name", lineEdit_Opponent6Name->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent6Name", lineEdit_Opponent6Name->text().toUtf8().constData()); if(QFile::QFile(lineEdit_Opponent6Avatar->text()).exists() || lineEdit_Opponent6Avatar->text() == "") { - myConfig.writeConfigString("Opponent6Avatar", lineEdit_Opponent6Avatar->text().toUtf8().constData()); + myConfig->writeConfigString("Opponent6Avatar", lineEdit_Opponent6Avatar->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The entered \"opponent 6\" avatar picture doesn't exists.\n" @@ -199,38 +199,38 @@ void settingsDialogImpl::isAccepted() { } // Local Game Settings - myConfig.writeConfigInt("NumberOfPlayers", spinBox_quantityPlayers->value()); - myConfig.writeConfigInt("StartCash", spinBox_startCash->value()); - myConfig.writeConfigInt("SmallBlind", spinBox_smallBlind->value()); - myConfig.writeConfigInt("HandsBeforeRaiseSmallBlind", spinBox_handsBeforeRaiseSmallBlind->value()); - myConfig.writeConfigInt("GameSpeed", spinBox_gameSpeed->value()); - myConfig.writeConfigInt("EngineVersion", comboBox_engineVersion->currentIndex()); - myConfig.writeConfigInt("PauseBetweenHands", checkBox_pauseBetweenHands->isChecked()); - myConfig.writeConfigInt("ShowGameSettingsDialogOnNewGame", checkBox_showGameSettingsDialogOnNewGame->isChecked()); + myConfig->writeConfigInt("NumberOfPlayers", spinBox_quantityPlayers->value()); + myConfig->writeConfigInt("StartCash", spinBox_startCash->value()); + myConfig->writeConfigInt("SmallBlind", spinBox_smallBlind->value()); + myConfig->writeConfigInt("HandsBeforeRaiseSmallBlind", spinBox_handsBeforeRaiseSmallBlind->value()); + myConfig->writeConfigInt("GameSpeed", spinBox_gameSpeed->value()); + myConfig->writeConfigInt("EngineVersion", comboBox_engineVersion->currentIndex()); + myConfig->writeConfigInt("PauseBetweenHands", checkBox_pauseBetweenHands->isChecked()); + myConfig->writeConfigInt("ShowGameSettingsDialogOnNewGame", checkBox_showGameSettingsDialogOnNewGame->isChecked()); //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()); - myConfig.writeConfigInt("NetEngineVersion", comboBox_netEngineVersion->currentIndex()); - myConfig.writeConfigInt("ServerPort", spinBox_serverPort->value()); - myConfig.writeConfigString("ServerPassword", lineEdit_serverPassword->text().toUtf8().constData()); - myConfig.writeConfigInt("ServerUseIpv6", checkBox_useIpv6->isChecked()); + 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()); + myConfig->writeConfigInt("NetEngineVersion", comboBox_netEngineVersion->currentIndex()); + myConfig->writeConfigInt("ServerPort", spinBox_serverPort->value()); + myConfig->writeConfigString("ServerPassword", lineEdit_serverPassword->text().toUtf8().constData()); + myConfig->writeConfigInt("ServerUseIpv6", checkBox_useIpv6->isChecked()); // Interface - myConfig.writeConfigInt("ShowLeftToolBox", checkBox_showLeftToolbox->isChecked()); - myConfig.writeConfigInt("ShowRightToolBox", checkBox_showRightToolbox->isChecked()); - myConfig.writeConfigInt("ShowStatusbarMessages", checkBox_showStatusbarMessages->isChecked()); - myConfig.writeConfigInt("ShowIntro", checkBox_showIntro->isChecked()); - myConfig.writeConfigInt("ShowFadeOutCardsAnimation", checkBox_showFadeOutCardsAnimation->isChecked()); - myConfig.writeConfigInt("ShowFlipCardsAnimation", checkBox_showFlipCardsAnimation->isChecked()); - myConfig.writeConfigInt("FlipsideTux", radioButton_flipsideTux->isChecked()); - myConfig.writeConfigInt("FlipsideOwn", radioButton_flipsideOwn->isChecked()); + myConfig->writeConfigInt("ShowLeftToolBox", checkBox_showLeftToolbox->isChecked()); + myConfig->writeConfigInt("ShowRightToolBox", checkBox_showRightToolbox->isChecked()); + myConfig->writeConfigInt("ShowStatusbarMessages", checkBox_showStatusbarMessages->isChecked()); + myConfig->writeConfigInt("ShowIntro", checkBox_showIntro->isChecked()); + myConfig->writeConfigInt("ShowFadeOutCardsAnimation", checkBox_showFadeOutCardsAnimation->isChecked()); + myConfig->writeConfigInt("ShowFlipCardsAnimation", checkBox_showFlipCardsAnimation->isChecked()); + myConfig->writeConfigInt("FlipsideTux", radioButton_flipsideTux->isChecked()); + myConfig->writeConfigInt("FlipsideOwn", radioButton_flipsideOwn->isChecked()); if(radioButton_flipsideOwn->isChecked()) { - if(QFile::QFile(lineEdit_OwnFlipsideFilename->text()).exists() && lineEdit_OwnFlipsideFilename->text() != "") {myConfig.writeConfigString("FlipsideOwnFile", lineEdit_OwnFlipsideFilename->text().toUtf8().constData()); } + if(QFile::QFile(lineEdit_OwnFlipsideFilename->text()).exists() && lineEdit_OwnFlipsideFilename->text() != "") {myConfig->writeConfigString("FlipsideOwnFile", lineEdit_OwnFlipsideFilename->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The entered flipside picture doesn't exists.\n" "Please enter an valid picture!"), @@ -240,7 +240,7 @@ void settingsDialogImpl::isAccepted() { } // Log - if(QDir::QDir(lineEdit_logDir->text()).exists() && lineEdit_logDir->text() != "") { myConfig.writeConfigString("LogDir", lineEdit_logDir->text().toUtf8().constData()); } + if(QDir::QDir(lineEdit_logDir->text()).exists() && lineEdit_logDir->text() != "") { myConfig->writeConfigString("LogDir", lineEdit_logDir->text().toUtf8().constData()); } else { QMessageBox::warning(this, tr("Settings Error"), tr("The log file directory doesn't exists.\n" @@ -249,7 +249,7 @@ void settingsDialogImpl::isAccepted() { settingsCorrect = FALSE; } - myConfig.writeConfigInt("LogStoreDuration", spinBox_logStoreDuration->value()); + myConfig->writeConfigInt("LogStoreDuration", spinBox_logStoreDuration->value()); //Wenn alles richtig eingegeben wurde --> Dialog schließen if(settingsCorrect) { this->hide(); } diff --git a/src/gui/qt/settingsdialog/settingsdialogimpl.h b/src/gui/qt/settingsdialog/settingsdialogimpl.h index 1e1f1592..b6b93259 100644 --- a/src/gui/qt/settingsdialog/settingsdialogimpl.h +++ b/src/gui/qt/settingsdialog/settingsdialogimpl.h @@ -22,14 +22,16 @@ #include "ui_settingsdialog.h" +#include #include #include +class ConfigFile; class settingsDialogImpl: public QDialog, public Ui::settingsDialog { Q_OBJECT public: - settingsDialogImpl(QWidget *parent = 0); + settingsDialogImpl(QWidget *parent = 0, std::string = ""); void setPlayerNickIsChanged(bool theValue){ playerNickIsChanged = theValue;} bool getPlayerNickIsChanged() const{ return playerNickIsChanged;} @@ -53,6 +55,7 @@ private: bool playerNickIsChanged; bool settingsCorrect; + ConfigFile *myConfig; }; diff --git a/src/pokerth.cpp b/src/pokerth.cpp index ca22d92d..d4f3039c 100755 --- a/src/pokerth.cpp +++ b/src/pokerth.cpp @@ -67,9 +67,11 @@ int main( int argc, char **argv ) Q_INIT_RESOURCE(resources); /////////////////////////////////////////////////// - GuiInterface *myGuiInterface = new GuiWrapper(); - Session theFirst(myGuiInterface); - myGuiInterface->setSession(&theFirst); + Session *theFirst = new Session(); + GuiInterface *myGuiInterface = new GuiWrapper(theFirst); + + theFirst->setGuiInterface(myGuiInterface); +// myGuiInterface->setSession(&theFirst); int retVal = a.exec(); diff --git a/src/session.cpp b/src/session.cpp index 099cb23c..979ae66b 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -29,10 +29,10 @@ using namespace std; -Session::Session(GuiInterface *g) -: actualGameID(0), myNetClient(0), myNetServer(0), actualGame(0), myGui(g) +Session::Session() +: actualGameID(0), myNetClient(0), myNetServer(0), actualGame(0), myGui(0) { - myConfig = new ConfigFile; + myConfig = new ConfigFile(getConfigPath()); } @@ -49,7 +49,7 @@ void Session::startGame(int qP, int sC, int sB) { actualGameID++; - actualGame = new Game(myConfig, myGui, qP, sC, sB, actualGameID); + actualGame = new Game(this, myGui, qP, sC, sB, actualGameID); } void Session::deleteGame() { diff --git a/src/session.h b/src/session.h index cce53793..83d8c50b 100755 --- a/src/session.h +++ b/src/session.h @@ -30,10 +30,12 @@ class ServerThread; class Session{ public: - Session(GuiInterface*); + Session(); ~Session(); + void setGuiInterface(GuiInterface *gui) { myGui = gui; } + void startGame(int, int, int); void deleteGame(); @@ -48,6 +50,9 @@ public: void setActualGameID(const int& theValue) { actualGameID = theValue; } int getActualGameID() const { return actualGameID; } + void setConfigPath(const std::string& theValue) { configPath = theValue; } + std::string getConfigPath() const { return configPath; } + // void createConfig(); private: @@ -61,6 +66,8 @@ private: GuiInterface *myGui; ConfigFile *myConfig; + std::string configPath; + };