refactoring chat-system

This commit is contained in:
doitux
2009-08-17 23:20:58 +00:00
parent 75007aa80e
commit 91c4304b78
17 changed files with 138 additions and 592 deletions
-116
View File
@@ -1,116 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "chat.h"
#include "gametableimpl.h"
#include "session.h"
#include "game.h"
#include "playerinterface.h"
#include "chattools.h"
#include "configfile.h"
#include "gametablestylereader.h"
using namespace std;
#define COMMAND_KICK_STR "/kick "
Chat::Chat(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c)
{
myChatTools = new ChatTools(myW->lineEdit_ChatInput, myConfig, 2, myW->textBrowser_Chat);
}
Chat::~Chat()
{
delete myConfig;
myConfig = 0;
}
void Chat::sendMessage() {
//filter /kick command
if(myW->lineEdit_ChatInput->text().startsWith(COMMAND_KICK_STR)) {
QString playerToKick = myW->lineEdit_ChatInput->text();
playerToKick.remove(0, sizeof(COMMAND_KICK_STR) - 1);
myW->lineEdit_ChatInput->setText("");
if(myW->getSession()->getClientGameInfo(myW->getSession()->getClientCurrentGameId()).adminPlayerId == myW->getSession()->getCurrentGame()->getSeatsList()->front()->getMyUniqueID()) {
if(playerToKick.toUtf8().constData() == myW->getSession()->getCurrentGame()->getSeatsList()->front()->getMyName()) {
myW->textBrowser_Chat->append("<span style=\"color:#ff0000;\">"+tr("You cannot kick yourself!")+"</span>");
}
else {
myW->getSession()->kickPlayer(playerToKick.toUtf8().constData());
}
}
else {
myW->textBrowser_Chat->append("<span style=\"color:#ff0000;\">"+tr("You cannot kick any player - You are not game admin!")+"</span>");
}
return;
}
fillChatLinesHistory(myW->lineEdit_ChatInput->text());
myW->getSession()->sendGameChatMessage(myW->lineEdit_ChatInput->text().toUtf8().constData());
myW->lineEdit_ChatInput->setText("");
}
void Chat::receiveMessage(QString playerName, QString message) {
myChatTools->receiveMessage(playerName, message);
checkInvisible();
}
void Chat::checkInvisible() {
switch (myW->tabWidget_Left->currentIndex()) {
case 1: { myW->tabWidget_Left->stopBlinkChatTab();
myW->tabWidget_Left->showDefaultChatTab();
}
break;
default: { myW->tabWidget_Left->startBlinkChatTab(); }
}
}
void Chat::checkInputLength(QString string) {
if(string.toUtf8().length() > 120) myW->lineEdit_ChatInput->setMaxLength(string.length());
}
void Chat::clearNewGame() {
myW->textBrowser_Chat->clear();
}
void Chat::setPlayerNicksList(QStringList nickList) {
//fill playerNicksList for nick-autocompletition
myChatTools->setPlayerNicksList(nickList);
}
void Chat::fillChatLinesHistory(QString fillString) { myChatTools->fillChatLinesHistory(fillString); }
int Chat::getChatLinesHistorySize() { return myChatTools->getChatLinesHistorySize(); }
void Chat::showChatHistoryIndex(int index) { myChatTools->showChatHistoryIndex(index); }
void Chat::nickAutoCompletition() { myChatTools->nickAutoCompletition(); }
void Chat::setChatTextEdited() { myChatTools->setChatTextEdited(); }
void Chat::transportMyStyle(GameTableStyleReader *s)
{
myChatTools->setMyStyle(s);
}
-69
View File
@@ -1,69 +0,0 @@
/***************************************************************************
* 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. *
***************************************************************************/
#ifndef CHAT_H
#define CHAT_H
#include <string>
#include <QtCore>
class gameTableImpl;
class ChatTools;
class ConfigFile;
class GameTableStyleReader;
class Chat : public QObject
{
Q_OBJECT
public:
Chat(gameTableImpl*, ConfigFile *c);
~Chat();
public slots:
void sendMessage();
void receiveMessage(QString playerName, QString msg);
void checkInvisible();
void checkInputLength(QString);
void clearNewGame();
void transportMyStyle(GameTableStyleReader*);
ChatTools* getMyChatTools() const { return myChatTools; }
void fillChatLinesHistory(QString fillString);
void showChatHistoryIndex(int index);
int getChatLinesHistorySize();
void nickAutoCompletition();
void setChatTextEdited();
void setPlayerNicksList(QStringList);
private:
gameTableImpl *myW;
ConfigFile *myConfig;
ChatTools *myChatTools;
friend class GuiWrapper;
};
#endif
+6 -8
View File
@@ -32,7 +32,7 @@
#include "mytimeoutlabel.h"
#include "mymenubar.h"
#include "log.h"
#include "chat.h"
#include "chattools.h"
#include "playerinterface.h"
#include "boardinterface.h"
@@ -388,9 +388,9 @@ gameTableImpl::gameTableImpl(ConfigFile *c, QMainWindow *parent)
}
// Dialogs
myChat = new Chat(this, myConfig);
myChat->transportMyStyle(myGameTableStyle);
myChat = new ChatTools(lineEdit_ChatInput, myConfig, INGAME_CHAT, textBrowser_Chat);
myChat->setMyStyle(myGameTableStyle);
lineEdit_ChatInput->installEventFilter(this);
this->installEventFilter(this);
@@ -2775,9 +2775,7 @@ void gameTableImpl::tabSwitchAction() {
switch(tabWidget_Left->currentIndex()) {
case 1: { lineEdit_ChatInput->setFocus();
myChat->checkInvisible();
}
case 1: { lineEdit_ChatInput->setFocus(); }
break;
default: { lineEdit_ChatInput->clearFocus(); }
@@ -2821,7 +2819,7 @@ void gameTableImpl::networkGameModification() {
tabWidget_Left->removeTab(2);
tabWidget_Left->setCurrentIndex(1);
myChat->clearNewGame();
myChat->clearChat();
int i;
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++ ) {
+12 -12
View File
@@ -30,7 +30,7 @@
#include <QtCore>
class Log;
class Chat;
class ChatTools;
class ConfigFile;
class Session;
class Game;
@@ -64,7 +64,7 @@ public:
void setLog(Log* l) { myLog = l; }
SDLPlayer* getMySDLPlayer() const { return mySDLPlayer; }
Chat* getMyChat() const { return myChat; }
ChatTools* getMyChat() const { return myChat; }
GameTableStyleReader* getMyGameTableStyle() const { return myGameTableStyle; }
@@ -125,7 +125,7 @@ signals:
void signalChangeVoteOnKickButtonsState(bool showHide);
void signalEndVoteOnKick();
void signalNetClientPlayerLeft(unsigned playerId);
void signalNetClientPlayerLeft(unsigned playerId);
public slots:
@@ -302,12 +302,12 @@ public slots:
void saveGameTableGeometry();
void restoreGameTableGeometry();
void netClientPlayerLeft(unsigned playerId);
void netClientPlayerLeft(unsigned playerId);
private:
boost::shared_ptr<GuiInterface> myServerGuiInterface;
Log *myLog;
Chat *myChat;
ChatTools *myChat;
ConfigFile *myConfig;
//Timer
@@ -356,9 +356,9 @@ private:
QLabel *cashTopLabelArray[MAX_NUMBER_OF_PLAYERS];
MySetLabel *setLabelArray[MAX_NUMBER_OF_PLAYERS];
QLabel *actionLabelArray[MAX_NUMBER_OF_PLAYERS];
MyNameLabel *playerNameLabelArray[MAX_NUMBER_OF_PLAYERS];
MyNameLabel *playerNameLabelArray[MAX_NUMBER_OF_PLAYERS];
MyAvatarLabel *playerAvatarLabelArray[MAX_NUMBER_OF_PLAYERS];
MyTimeoutLabel *timeoutLabelArray[MAX_NUMBER_OF_PLAYERS];
MyTimeoutLabel *timeoutLabelArray[MAX_NUMBER_OF_PLAYERS];
QGroupBox *groupBoxArray[MAX_NUMBER_OF_PLAYERS];
MyCardsPixmapLabel *boardCardsArray[5];
@@ -422,11 +422,11 @@ private:
CardDeckStyleReader *myCardDeckStyle;
QString AllInString;
QString RaiseString;
QString BetString;
QString CallString;
QString CheckString;
QString FoldString;
QString RaiseString;
QString BetString;
QString CallString;
QString CheckString;
QString FoldString;
QString PotString;
QString TotalString;
QString BetsString;