• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdegames
 

libtdegames

  • libtdegames
kchat.cpp
1 /*
2  This file is part of the TDE games library
3  Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <tdelocale.h>
21 #include <kdebug.h>
22 
23 #include "kchat.h"
24 
25 class KChatPrivate
26 {
27 public:
28  KChatPrivate()
29  {
30  }
31 
32  bool mAutoAddMessages;
33 
34  TQMap<int, TQString> mPlayerMap;
35  int mPlayerId;
36  int mFromId;
37 };
38 
39 KChat::KChat(TQWidget* parent, bool twoPlayerGame) : KChatBase(parent, twoPlayerGame)
40 {
41  init();
42 }
43 
44 KChat::~KChat()
45 {
46  kdDebug(11000) << "DESTRUCT KChat " << this << endl;
47  delete d;
48 }
49 
50 void KChat::init()
51 {
52  kdDebug(11001) << "INIT KChat " << this << endl;
53  d = new KChatPrivate;
54  d->mAutoAddMessages = true;
55  d->mPlayerId = 1;
56  d->mFromId = 1;
57 }
58 
59 void KChat::setFromNickname(const TQString& n)
60 { d->mFromId = addPlayer(n); }
61 const TQString& KChat::fromName() const
62 { return player(fromId()); }
63 void KChat::setAutoAddMessages(bool add)
64 { d->mAutoAddMessages = add; }
65 bool KChat::autoAddMessages() const
66 { return d->mAutoAddMessages; }
67 int KChat::uniqueId()
68 { return d->mPlayerId++; }
69 int KChat::fromId() const
70 { return d->mFromId; }
71 const TQString& KChat::player(int id) const
72 { return d->mPlayerMap[id]; }
73 
74 void KChat::returnPressed(const TQString& text)
75 {
76  int id = fromId();
77  if (id < 0) {
78  // don't return - just display "unknown" as name
79  kdWarning(11000) << "KChat: no fromNickname has been set!" << endl;
80  }
81  emit signalSendMessage(id, text);
82  if (autoAddMessages()) {
83  TQString p = player(id);
84  if (p.isNull()) {
85  p = i18n("Unknown");
86  }
87  kdDebug(11000) << "auto adding message from player " << p << " ;id=" << id << endl;
88  addMessage(p, text);
89  }
90 }
91 
92 int KChat::addPlayer(const TQString& nickname)
93 {
94  int id = uniqueId();
95  d->mPlayerMap.insert(id, nickname);
96  return id;
97 }
98 
99 void KChat::removePlayer(int id)
100 {
101  d->mPlayerMap.remove(id);
102 }
103 
104 void KChat::removePlayer(const TQString& nickname)
105 {
106  TQMap<int, TQString>::Iterator it;
107  for (it = d->mPlayerMap.begin(); it != d->mPlayerMap.end(); ++it) {
108  if (it.data() == nickname) {
109  d->mPlayerMap.remove(it);
110  }
111  }
112 }
113 
114 
115 #include "kchat.moc"
KChat::uniqueId
int uniqueId()
The Id of the next player.
Definition: kchat.cpp:67
KChat::player
const TQString & player(int id) const
Definition: kchat.cpp:71
KChat::signalSendMessage
void signalSendMessage(int id, const TQString &msg)
This signal is emitted when the player wants to send a message.
KChatBase
The base class for chat widgets.
Definition: kchatbase.h:184
KChat::fromName
virtual const TQString & fromName() const
Equivalent to player(fromId())
Definition: kchat.cpp:61
KChatBase::addMessage
virtual void addMessage(const TQString &fromName, const TQString &text)
Add a text in the listbox.
Definition: kchatbase.cpp:349
KChat::KChat
KChat(TQWidget *parent, bool twoPlayerGame=false)
Definition: kchat.cpp:39
KChat::setFromNickname
void setFromNickname(const TQString &name)
This sets the name that will be shown on all chat widgets if this widget sends a message.
Definition: kchat.cpp:59
KChat::setAutoAddMessages
void setAutoAddMessages(bool add)
Usually the messages which will be sent from here (see signalSendMessage) are added autmatically to t...
Definition: kchat.cpp:63
KChat::addPlayer
int addPlayer(const TQString &nick)
Adds a player nickname.
Definition: kchat.cpp:92
KChat::returnPressed
virtual void returnPressed(const TQString &)
This emits signalSendMessage and, if autoAddMessages is true, calls KChatBase::addMessage.
Definition: kchat.cpp:74
KChat::fromId
int fromId() const
Definition: kchat.cpp:69
KChat::autoAddMessages
bool autoAddMessages() const
Definition: kchat.cpp:65
KChat::removePlayer
void removePlayer(const TQString &nick)
Removes all players with this nickname.
Definition: kchat.cpp:104

libtdegames

Skip menu "libtdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.8.13
This website is maintained by Timothy Pearson.