You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
2.7 KiB
116 lines
2.7 KiB
15 years ago
|
/*
|
||
|
This file is part of the KDE games library
|
||
|
Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <klocale.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
#include "kchat.h"
|
||
|
|
||
|
class KChatPrivate
|
||
|
{
|
||
|
public:
|
||
|
KChatPrivate()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool mAutoAddMessages;
|
||
|
|
||
15 years ago
|
TQMap<int, TQString> mPlayerMap;
|
||
15 years ago
|
int mPlayerId;
|
||
|
int mFromId;
|
||
|
};
|
||
|
|
||
14 years ago
|
KChat::KChat(TQWidget* parent, bool twoPlayerGame) : KChatBase(parent, twoPlayerGame)
|
||
15 years ago
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
KChat::~KChat()
|
||
|
{
|
||
|
kdDebug(11000) << "DESTRUCT KChat " << this << endl;
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
void KChat::init()
|
||
|
{
|
||
|
kdDebug(11001) << "INIT KChat " << this << endl;
|
||
|
d = new KChatPrivate;
|
||
|
d->mAutoAddMessages = true;
|
||
|
d->mPlayerId = 1;
|
||
|
d->mFromId = 1;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KChat::setFromNickname(const TQString& n)
|
||
15 years ago
|
{ d->mFromId = addPlayer(n); }
|
||
15 years ago
|
const TQString& KChat::fromName() const
|
||
15 years ago
|
{ return player(fromId()); }
|
||
|
void KChat::setAutoAddMessages(bool add)
|
||
|
{ d->mAutoAddMessages = add; }
|
||
|
bool KChat::autoAddMessages() const
|
||
|
{ return d->mAutoAddMessages; }
|
||
|
int KChat::uniqueId()
|
||
|
{ return d->mPlayerId++; }
|
||
|
int KChat::fromId() const
|
||
|
{ return d->mFromId; }
|
||
15 years ago
|
const TQString& KChat::player(int id) const
|
||
15 years ago
|
{ return d->mPlayerMap[id]; }
|
||
|
|
||
15 years ago
|
void KChat::returnPressed(const TQString& text)
|
||
15 years ago
|
{
|
||
|
int id = fromId();
|
||
|
if (id < 0) {
|
||
|
// don't return - just display "unknown" as name
|
||
|
kdWarning(11000) << "KChat: no fromNickname has been set!" << endl;
|
||
|
}
|
||
|
emit signalSendMessage(id, text);
|
||
|
if (autoAddMessages()) {
|
||
15 years ago
|
TQString p = player(id);
|
||
15 years ago
|
if (p.isNull()) {
|
||
|
p = i18n("Unknown");
|
||
|
}
|
||
|
kdDebug(11000) << "auto adding message from player " << p << " ;id=" << id << endl;
|
||
|
addMessage(p, text);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
int KChat::addPlayer(const TQString& nickname)
|
||
15 years ago
|
{
|
||
|
int id = uniqueId();
|
||
|
d->mPlayerMap.insert(id, nickname);
|
||
|
return id;
|
||
|
}
|
||
|
|
||
|
void KChat::removePlayer(int id)
|
||
|
{
|
||
|
d->mPlayerMap.remove(id);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KChat::removePlayer(const TQString& nickname)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQMap<int, TQString>::Iterator it;
|
||
15 years ago
|
for (it = d->mPlayerMap.begin(); it != d->mPlayerMap.end(); ++it) {
|
||
|
if (it.data() == nickname) {
|
||
|
d->mPlayerMap.remove(it);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "kchat.moc"
|