Files
pokerth/src/gui/qt/mymessagedialog/mymessagedialogimpl.cpp
T

141 lines
4.2 KiB
C++
Raw Normal View History

/*****************************************************************************
* PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/ #include "mymessagedialogimpl.h"
2010-03-28 16:16:48 +00:00
#include <QtCore>
#include "configfile.h"
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <fstream>
2010-03-28 16:16:48 +00:00
using namespace std;
myMessageDialogImpl::myMessageDialogImpl(ConfigFile *c, QWidget *parent)
: QDialog(parent), myConfig(c), currentMsgId(0)
{
2007-12-04 01:37:43 +00:00
#ifdef __APPLE__
setWindowModality(Qt::ApplicationModal);
setWindowFlags(Qt::WindowSystemMenuHint | Qt::CustomizeWindowHint | Qt::Dialog);
#endif
setupUi(this);
}
2010-03-28 16:16:48 +00:00
2010-03-29 13:08:59 +00:00
int myMessageDialogImpl::exec(int messageId, QString msg, QString title, QPixmap pix, QDialogButtonBox::StandardButtons buttons, bool showCheckBox)
2010-03-28 16:16:48 +00:00
{
if(showCheckBox) checkBox->show();
else checkBox->hide();
2010-03-29 13:08:59 +00:00
bool show = false;
bool found = false;
2010-03-28 16:16:48 +00:00
currentMsgId = messageId;
2010-03-28 16:16:48 +00:00
currentMsgShowList = myConfig->readConfigStringList("IfInfoMessageShowList");
list<std::string>::iterator it1;
for(it1= currentMsgShowList.begin(); it1 != currentMsgShowList.end(); ++it1) {
2010-03-28 16:16:48 +00:00
QString tmpString = QString::fromUtf8(it1->c_str());
if(QString("%1").arg(messageId) == tmpString.split(",").at(1)) {
2010-03-28 16:16:48 +00:00
found = true;
show = tmpString.split(",").at(0).toInt();
2010-03-28 16:16:48 +00:00
break;
}
}
2010-03-28 16:16:48 +00:00
if(!found) {
currentMsgShowList.push_back(QString("1,%1").arg(messageId).toUtf8().constData());
myConfig->writeConfigStringList("IfInfoMessageShowList", currentMsgShowList);
myConfig->writeBuffer();
}
2010-03-28 16:16:48 +00:00
if(!found || show) {
2010-03-28 16:16:48 +00:00
setWindowTitle(title);
label_icon->setPixmap(pix.scaled(50,50,Qt::KeepAspectRatio,Qt::SmoothTransformation));
label->setText(msg);
buttonBox->setStandardButtons(buttons);
2010-03-28 16:16:48 +00:00
return QDialog::exec();
}
2010-03-28 16:16:48 +00:00
return -1;
2010-03-28 16:16:48 +00:00
}
void myMessageDialogImpl::accept()
{
writeConfig();
QDialog::accept();
2010-03-28 16:16:48 +00:00
}
void myMessageDialogImpl::reject()
{
writeConfig();
QDialog::reject();
2010-03-28 16:16:48 +00:00
}
void myMessageDialogImpl::writeConfig()
{
if(checkBox->isChecked()) {
2010-03-28 16:16:48 +00:00
list<std::string>::iterator it1;
for(it1= currentMsgShowList.begin(); it1 != currentMsgShowList.end(); ++it1) {
2010-03-28 16:16:48 +00:00
QString tmpString = QString::fromUtf8(it1->c_str());
if(QString("%1").arg(currentMsgId) == tmpString.split(",").at(1)) {
2010-03-28 16:16:48 +00:00
(*it1) = QString("0,%1").arg(currentMsgId).toUtf8().constData();
break;
}
}
2010-03-28 16:16:48 +00:00
myConfig->writeConfigStringList("IfInfoMessageShowList", currentMsgShowList);
myConfig->writeBuffer();
}
2010-03-28 16:16:48 +00:00
}
bool myMessageDialogImpl::checkIfMesssageWillBeDisplayed(int id)
{
bool found = false;
bool show = true;
2010-03-28 16:16:48 +00:00
currentMsgShowList = myConfig->readConfigStringList("IfInfoMessageShowList");
list<std::string>::iterator it1;
for(it1= currentMsgShowList.begin(); it1 != currentMsgShowList.end(); ++it1) {
2010-03-28 16:16:48 +00:00
QString tmpString = QString::fromUtf8(it1->c_str());
if(QString("%1").arg(id) == tmpString.split(",").at(1)) {
2010-03-28 16:16:48 +00:00
found = true;
show = tmpString.split(",").at(0).toInt();
2010-03-28 16:16:48 +00:00
break;
}
}
2010-03-28 16:16:48 +00:00
if(!found) {
currentMsgShowList.push_back(QString("1,%1").arg(id).toUtf8().constData());
myConfig->writeConfigStringList("IfInfoMessageShowList", currentMsgShowList);
myConfig->writeBuffer();
}
2010-03-28 16:16:48 +00:00
return show;
2010-03-28 16:16:48 +00:00
}