ircprivadapter.cpp
1 //------------------------------------------------------------------------------
2 // ircprivadapter.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the 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 General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "ircprivadapter.h"
24 #include "irc/ircmessageclass.h"
25 #include "irc/ircglobal.h"
26 #include "irc/ircuserinfo.h"
27 
28 IRCPrivAdapter::IRCPrivAdapter(IRCNetworkAdapter* pNetwork, const QString& recipient)
29 : IRCChatAdapter(pNetwork, recipient)
30 {
31 }
32 
33 void IRCPrivAdapter::userChangesNickname(const QString& oldNickname, const QString& newNickname)
34 {
35  if (recipientName.compare(oldNickname, Qt::CaseInsensitive) == 0)
36  {
37  emit messageWithClass(tr("This user changed nickname from %1 to %2")
38  .arg(oldNickname, newNickname), IRCMessageClass::ChannelAction);
39  setRecipient(newNickname);
40  }
41 }
42 
43 void IRCPrivAdapter::userJoins(const QString& nickname, const QString& fullSignature)
44 {
45  // Ignore. This has no sensible application here.
46 }
47 
48 void IRCPrivAdapter::userLeaves(const QString& nickname, const QString& farewellMessage, IRCQuitType quitType)
49 {
50  // Make sure that this user is the recipient of this adapter.
51  IRCUserInfo recipientUserInfo(recipientName, network());
52  if (recipientUserInfo.isSameNickname(nickname))
53  {
54  QString message = "";
55 
56  switch (quitType)
57  {
58  case IRCChatAdapter::NetworkKill:
59  message = tr("This user connection has been killed. (KILL: %1)").arg(farewellMessage);
60  break;
61 
62  case IRCChatAdapter::NetworkQuit:
63  message = tr("This user has left the network. (QUIT: %1)").arg(farewellMessage);
64  break;
65 
66  default:
67  emit error(tr("Unhandled IRCQuitType in IRCPrivAdapter::userLeaves()"));
68  break;
69  }
70 
71  if (!message.isEmpty())
72  {
73  emit messageWithClass(message, IRCMessageClass::NetworkAction);
74  }
75  }
76 }
Interprets communication between the client and the IRC server.
void userChangesNickname(const QString &oldNickname, const QString &newNickname)
Use this to register the fact that user has changed his/hers nickname.
Handles chatting through IRC.
IRCNetworkAdapter * network()
The idea of the adapter system is that each adapter is either a network or is a child of a network...
void userJoins(const QString &nickname, const QString &fullSignature)
Use this to register the fact that user has joined the chat.
void userLeaves(const QString &nickname, const QString &farewellMessage, IRCQuitType quitType)
Use this to register the fact that user has left the chat.
bool isSameNickname(const IRCUserInfo &otherUser) const
Check if this user and user specified as parameter are the same user.
Definition: ircuserinfo.cpp:79
Holds information flags about given nickname.
Definition: ircuserinfo.h:35