ircprivadapter.cpp
1 //------------------------------------------------------------------------------
2 // ircprivadapter.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 "irc/ircglobal.h"
24 #include "irc/ircmessageclass.h"
25 #include "irc/ircuserinfo.h"
26 #include "ircprivadapter.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  Q_UNUSED(nickname);
46  Q_UNUSED(fullSignature);
47  // Ignore. This has no sensible application here.
48 }
49 
50 void IRCPrivAdapter::userLeaves(const QString &nickname, const QString &farewellMessage, IRCQuitType quitType)
51 {
52  // Make sure that this user is the recipient of this adapter.
53  IRCUserInfo recipientUserInfo(recipientName, network());
54  if (recipientUserInfo.isSameNickname(nickname))
55  {
56  QString message = "";
57 
58  switch (quitType)
59  {
60  case IRCChatAdapter::NetworkKill:
61  message = tr("This user connection has been killed. (KILL: %1)").arg(farewellMessage);
62  break;
63 
64  case IRCChatAdapter::NetworkQuit:
65  message = tr("This user has left the network. (QUIT: %1)").arg(farewellMessage);
66  break;
67 
68  default:
69  emit error(tr("Unhandled IRCQuitType in IRCPrivAdapter::userLeaves()"));
70  break;
71  }
72 
73  if (!message.isEmpty())
74  emit messageWithClass(message, IRCMessageClass::NetworkAction);
75  }
76 }