1 /*****************************************************************************
2 * PokerTH - The open source texas holdem engine *
3 * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
4 * *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU Affero General Public License as *
7 * published by the Free Software Foundation, either version 3 of the *
8 * License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU Affero General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Affero General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 * *
18 * *
19 * Additional permission under GNU AGPL version 3 section 7 *
20 * *
21 * If you modify this program, or any covered work, by linking or *
22 * combining it with the OpenSSL project's OpenSSL library (or a *
23 * modified version of that library), containing parts covered by the *
24 * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
25 * (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
26 * permission to convey the resulting work. *
27 * Corresponding Source for a non-source form of such a combination *
28 * shall include the source code for the parts of OpenSSL used as well *
29 * as that of the covered work. *
30 *****************************************************************************/
31 #include "mymessagedialogimpl.h"
32 #include <QtCore>
33 #include "configfile.h"
34 #include <iostream>
35 #include <sstream>
36 #include <cstdlib>
37 #include <fstream>
38
39 using namespace std;
40
41
myMessageDialogImpl(ConfigFile * c,QWidget * parent)42 myMessageDialogImpl::myMessageDialogImpl(ConfigFile *c, QWidget *parent)
43 : QDialog(parent), myConfig(c), currentMsgId(0)
44 {
45 #ifdef __APPLE__
46 setWindowModality(Qt::ApplicationModal);
47 setWindowFlags(Qt::WindowSystemMenuHint | Qt::CustomizeWindowHint | Qt::Dialog);
48 #endif
49 setupUi(this);
50
51 #ifdef ANDROID
52 this->setWindowState(Qt::WindowFullScreen);
53 #endif
54 }
55
exec(int messageId,QString msg,QString title,QPixmap pix,QDialogButtonBox::StandardButtons buttons,bool showCheckBox)56 int myMessageDialogImpl::exec(int messageId, QString msg, QString title, QPixmap pix, QDialogButtonBox::StandardButtons buttons, bool showCheckBox)
57 {
58 if(showCheckBox) checkBox->show();
59 else checkBox->hide();
60
61 bool show = false;
62 bool found = false;
63
64 currentMsgId = messageId;
65
66 currentMsgShowList = myConfig->readConfigStringList("IfInfoMessageShowList");
67 list<std::string>::iterator it1;
68 for(it1= currentMsgShowList.begin(); it1 != currentMsgShowList.end(); ++it1) {
69
70 QString tmpString = QString::fromUtf8(it1->c_str());
71 if(QString("%1").arg(messageId) == tmpString.split(",").at(1)) {
72
73 found = true;
74 show = tmpString.split(",").at(0).toInt();
75
76 break;
77 }
78 }
79
80 if(!found) {
81 currentMsgShowList.push_back(QString("1,%1").arg(messageId).toUtf8().constData());
82 myConfig->writeConfigStringList("IfInfoMessageShowList", currentMsgShowList);
83 myConfig->writeBuffer();
84 }
85
86 if(!found || show) {
87
88 setWindowTitle(title);
89 label_icon->setPixmap(pix.scaled(50,50,Qt::KeepAspectRatio,Qt::SmoothTransformation));
90 label->setText(msg);
91 buttonBox->setStandardButtons(buttons);
92
93 return QDialog::exec();
94 }
95
96 return -1;
97 }
98
show(int messageId,QString msg,QString title,QPixmap pix,QDialogButtonBox::StandardButtons buttons,bool showCheckBox)99 void myMessageDialogImpl::show(int messageId, QString msg, QString title, QPixmap pix, QDialogButtonBox::StandardButtons buttons, bool showCheckBox)
100 {
101 if(showCheckBox) checkBox->show();
102 else checkBox->hide();
103
104 bool show = false;
105 bool found = false;
106
107 currentMsgId = messageId;
108
109 currentMsgShowList = myConfig->readConfigStringList("IfInfoMessageShowList");
110 list<std::string>::iterator it1;
111 for(it1= currentMsgShowList.begin(); it1 != currentMsgShowList.end(); ++it1) {
112
113 QString tmpString = QString::fromUtf8(it1->c_str());
114 if(QString("%1").arg(messageId) == tmpString.split(",").at(1)) {
115
116 found = true;
117 show = tmpString.split(",").at(0).toInt();
118
119 break;
120 }
121 }
122
123 if(!found) {
124 currentMsgShowList.push_back(QString("1,%1").arg(messageId).toUtf8().constData());
125 myConfig->writeConfigStringList("IfInfoMessageShowList", currentMsgShowList);
126 myConfig->writeBuffer();
127 }
128
129 if(!found || show) {
130
131 setWindowTitle(title);
132 label_icon->setPixmap(pix.scaled(50,50,Qt::KeepAspectRatio,Qt::SmoothTransformation));
133 label->setText(msg);
134 buttonBox->setStandardButtons(buttons);
135
136 QDialog::show();
137 }
138 }
139
140
accept()141 void myMessageDialogImpl::accept()
142 {
143 writeConfig();
144 QDialog::accept();
145 }
146
reject()147 void myMessageDialogImpl::reject()
148 {
149 writeConfig();
150 QDialog::reject();
151 }
152
writeConfig()153 void myMessageDialogImpl::writeConfig()
154 {
155 if(checkBox->isChecked()) {
156
157 list<std::string>::iterator it1;
158 for(it1= currentMsgShowList.begin(); it1 != currentMsgShowList.end(); ++it1) {
159
160 QString tmpString = QString::fromUtf8(it1->c_str());
161 if(QString("%1").arg(currentMsgId) == tmpString.split(",").at(1)) {
162
163 (*it1) = QString("0,%1").arg(currentMsgId).toUtf8().constData();
164 break;
165 }
166 }
167
168 myConfig->writeConfigStringList("IfInfoMessageShowList", currentMsgShowList);
169 myConfig->writeBuffer();
170 }
171 }
172
checkIfMesssageWillBeDisplayed(int id)173 bool myMessageDialogImpl::checkIfMesssageWillBeDisplayed(int id)
174 {
175 bool found = false;
176 bool show = true;
177
178 currentMsgShowList = myConfig->readConfigStringList("IfInfoMessageShowList");
179 list<std::string>::iterator it1;
180 for(it1= currentMsgShowList.begin(); it1 != currentMsgShowList.end(); ++it1) {
181
182 QString tmpString = QString::fromUtf8(it1->c_str());
183 if(QString("%1").arg(id) == tmpString.split(",").at(1)) {
184
185 found = true;
186 show = tmpString.split(",").at(0).toInt();
187
188 break;
189 }
190 }
191
192 if(!found) {
193 currentMsgShowList.push_back(QString("1,%1").arg(id).toUtf8().constData());
194 myConfig->writeConfigStringList("IfInfoMessageShowList", currentMsgShowList);
195 myConfig->writeBuffer();
196 }
197
198 return show;
199 }
200