Files
pokerth/src/gui/qt/log.cpp
T

152 lines
4.9 KiB
C++
Raw Normal View History

2007-01-13 02:40:33 +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. *
***************************************************************************/
2007-01-31 22:48:44 +00:00
#include "log.h"
2007-01-13 02:40:33 +00:00
#include "mainwindowimpl.h"
using namespace std;
2007-01-31 22:48:44 +00:00
Log::Log(mainWindowImpl* w) : myW(w)
2007-01-13 02:40:33 +00:00
{
2007-01-31 22:48:44 +00:00
myW->setLog(this);
2007-02-03 22:47:16 +00:00
myConfig = new ConfigFile;
if(myConfig->readConfigString("LogDir") != "" && QDir::QDir(QString::fromStdString(myConfig->readConfigString("LogDir"))).exists()) {
2007-02-05 22:33:52 +00:00
#ifdef _WIN32
2007-02-06 01:14:00 +00:00
myLogDir = new QDir(QString::fromStdString(myConfig->readConfigString("LogDir")).replace("\\","/"));
#else
myLogDir = new QDir(QString::fromStdString(myConfig->readConfigString("LogDir")));
2007-02-05 22:33:52 +00:00
#endif
2007-02-06 01:14:00 +00:00
myLogFile = new QFile(myLogDir->absolutePath()+"/pokerth-log-"+QDateTime::currentDateTime().toString("yyyy-MM-dd_hh:mm:ss")+".html");
2007-02-04 00:34:44 +00:00
//Logo-Pixmap extrahieren
2007-02-05 22:33:52 +00:00
QPixmap::QPixmap(":graphics/graphics/logo-140-100.png").save(myLogDir->absolutePath()+"/logo.png");
2007-02-03 22:47:16 +00:00
myLogFile->open( QIODevice::WriteOnly );
QTextStream stream( myLogFile );
2007-02-04 13:46:27 +00:00
stream << "<html>\n";
stream << "<body>\n";
stream << "<img src='logo.png'>\n";
stream << "<h3><b>Log-File for PokerTH Session started on "+QDate::currentDate().toString("yyyy-MM-dd")+" at "+QTime::currentTime().toString("hh:mm:ss")+"</b></h3>\n";
2007-02-04 23:58:50 +00:00
// stream << "</body>\n";
// stream << "</html>\n";
2007-02-03 22:47:16 +00:00
myLogFile->close();
2007-02-04 13:46:27 +00:00
2007-02-04 23:58:50 +00:00
linesInFile = 3;
2007-02-03 22:47:16 +00:00
}
2007-01-13 02:40:33 +00:00
}
2007-01-31 22:48:44 +00:00
Log::~Log()
2007-01-13 02:40:33 +00:00
{
}
2007-02-04 13:46:27 +00:00
void Log::logPlayerActionMsg(string playerName, int action, int setValue) {
int i;
2007-01-13 02:40:33 +00:00
QString msg;
msg = QString::fromStdString(playerName);
switch (action) {
case 1: msg += " folds.";
break;
case 2: msg += " checks.";
break;
case 3: msg += " calls ";
break;
case 4: msg += " bets ";
break;
case 5: msg += " sets ";
break;
case 6: msg += " is all in with ";
break;
default: msg += "ERROR";
}
if (action >= 3) { msg += QString::number(setValue,10)+"$."; }
myW->textBrowser_Log->append(msg);
2007-02-04 13:46:27 +00:00
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
2007-02-04 23:58:50 +00:00
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
2007-02-04 13:46:27 +00:00
stream << msg+"</br>\n";
2007-02-04 23:58:50 +00:00
// stream << "</body>\n";
// stream << "</html>\n";
2007-02-04 13:46:27 +00:00
myLogFile->close();
linesInFile++;
2007-01-13 02:40:33 +00:00
}
2007-02-04 13:46:27 +00:00
void Log::logNewGameHandMsg(int gameID, int handID) {
2007-01-13 02:40:33 +00:00
2007-02-04 13:46:27 +00:00
int i;
2007-01-13 02:40:33 +00:00
2007-02-04 13:46:27 +00:00
myW->textBrowser_Log->append("## Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+" ##");
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
2007-02-04 23:58:50 +00:00
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
2007-02-04 13:46:27 +00:00
2007-02-04 23:58:50 +00:00
QString msg("<p><b>##### Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+" #####</b></br>");
2007-02-04 13:46:27 +00:00
stream << msg << "\n";
2007-02-04 23:58:50 +00:00
for(i=0; i<myW->getMaxQuantityPlayers(); i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyButton() == 1) {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$, ";
}
else {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$, ";
}
}
stream << "</p>\n";
// stream << "</body>\n";
// stream << "</html>\n";
2007-02-04 13:46:27 +00:00
myLogFile->close();
linesInFile++;
2007-02-04 23:58:50 +00:00
linesInFile++;
}
void Log::logPlayerWinsMsg(int playerID) {
int i;
myW->textBrowser_Log->append(QString::fromStdString(myW->getActualHand()->getPlayerArray()[playerID]->getMyName())+" wins!!! ");
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
QString msg("<p><i>"+QString::fromStdString(myW->getActualHand()->getPlayerArray()[playerID]->getMyName())+" wins!!!</i></p>\n");
stream << msg;
myLogFile->close();
linesInFile++;
linesInFile++;
2007-02-04 13:46:27 +00:00
}