23 #include "ircchanneladapter.h" 24 #include "irc/configuration/ircconfig.h" 25 #include "irc/ircglobal.h" 26 #include "irc/ircmessageclass.h" 27 #include "irc/ircnetworkadapter.h" 28 #include "irc/ircuserinfo.h" 29 #include "irc/ircuserlist.h" 31 IRCChannelAdapter::IRCChannelAdapter(
IRCNetworkAdapter* pNetwork,
const QString& recipient)
37 IRCChannelAdapter::~IRCChannelAdapter()
39 if (this->pNetwork != NULL)
41 sendMessage(
"/part " + this->recipientName +
" " + gIRCConfig.personal.quitMessage);
49 const QString& myNickname = pNetwork->myNickname();
50 return isOperator(myNickname);
64 foreach (
const QString &name, names)
66 appendNameToCachedList(name);
72 pNetwork->banUser(nickname, reason, this->recipientName);
77 emit nameListUpdated(*users);
85 QString actualSenderName = sender;
86 if (pUserInfo != NULL)
93 const QString& myNickname = pNetwork->myNickname();
94 if (content.contains(myNickname, Qt::CaseInsensitive)
95 && sender.compare(myNickname, Qt::CaseInsensitive) != 0)
97 emit myNicknameUsed();
103 bool IRCChannelAdapter::hasUser(
const QString& nickname)
105 return users->hasUser(nickname);
113 return pUser->isOp();
121 if (hasUser(nickname))
124 this->sendMessage(QString(
"/kick %1 %2 %3").arg(this->recipientName, cleanNickname, reason));
132 if (!users->removeNameFromCachedList(name))
134 emit error(QString(
"Attempted to remove name \"%1\" from the \"%2\" channel's name list but no such name is on the list.").arg(name, this->recipientName));
138 emit nameRemoved(user);
144 pNetwork->setChannelMode(this->recipientName, nickname,
"h", bSet);
149 pNetwork->setChannelMode(this->recipientName, nickname,
"o", bSet);
154 pNetwork->setChannelMode(this->recipientName, nickname,
"v", bSet);
159 if (hasUser(oldNickname))
161 IRCUserInfo oldName = users->userCopy(oldNickname);
163 users->changeNick(oldNickname, newNickname);
164 emit nameRemoved(oldName);
165 emit nameAdded(users->userCopy(newNickname));
167 emit messageWithClass(tr(
"%1 is now known as %2").arg(oldNickname, newNickname),
168 IRCMessageClass::ChannelAction);
174 appendNameToCachedList(nickname);
176 emit messageWithClass(tr(
"User %1 [%2] has joined the channel.").arg(nickname, fullSignature),
177 IRCMessageClass::ChannelAction);
182 if (!hasUser(nickname))
188 removeNameFromCachedList(nickname);
192 case IRCChatAdapter::ChannelPart:
193 emit messageWithClass(tr(
"User %1 has left the channel. (PART: %2)").arg(nickname, farewellMessage),
194 IRCMessageClass::ChannelAction);
197 case IRCChatAdapter::NetworkKill:
198 emit messageWithClass(tr(
"Connection for user %1 has been killed. (KILL: %2)").arg(nickname, farewellMessage),
199 IRCMessageClass::NetworkAction);
202 case IRCChatAdapter::NetworkQuit:
203 emit messageWithClass(tr(
"User %1 has quit the network. (QUIT: %2)").arg(nickname, farewellMessage),
204 IRCMessageClass::NetworkAction);
208 emit error(tr(
"Unknown quit type from user %1.").arg(nickname));
214 const QList<char> &addedFlags,
const QList<char> &removedFlags)
216 const IRCUserInfo* pUserInfo = this->users->user(nickname);
217 if (pUserInfo != NULL)
220 foreach (
char mode, addedFlags)
222 newUserInfo.setMode(mode);
224 foreach (
char mode, removedFlags)
226 newUserInfo.unsetMode(mode);
229 this->users->setUserModes(nickname, newUserInfo.modes());
230 emit nameUpdated(newUserInfo);
Interprets communication between the client and the IRC server.
Allows to perform operation on a list of users.
void emitCachedNameListUpdated()
Emits cached list of names. This should be called when end of names list message is received for this...
void userJoins(const QString &nickname, const QString &fullSignature)
Use this to register the fact that user has joined the chat.
void userModeChanges(const QString &nickname, const QList< char > &addedFlags, const QList< char > &removedFlags)
void kickUser(const QString &nickname, const QString &reason)
Kicks user from the channel.
void removeNameFromCachedList(const QString &name)
Removes a name from the sortecd cachedNames list.
void setHalfOp(const QString &nickname, bool bSet)
Sets half op mode for given user.
void appendNamesToCachedList(const QStringList &names)
Appends a list of names to cachedNames list. This ensures that no duplicate names are found on the li...
QString cleanNickname() const
Returns nickname with no prefixes, contrary to the prefixedName() .
virtual void emitChatMessage(const QString &sender, const QString &content)
Emits message() signal formatting it to present sender's message.
QString prefixedName() const
Will generate prefix based on the user flags.
bool amIOperator() const
Checks if this client is an operator on this channel.
Handles chatting through IRC.
void banUser(const QString &nickname, const QString &reason)
Bans and kicks user from the channel.
void userLeaves(const QString &nickname, const QString &farewellMessage, IRCQuitType quitType)
Use this to register the fact that user has left the chat.
void userChangesNickname(const QString &oldNickname, const QString &newNickname)
void setVoiced(const QString &nickname, bool bSet)
Sets voice mode for given user.
Holds information flags about given nickname.
void setOp(const QString &nickname, bool bSet)
Sets op mode for given user.
virtual IRCNetworkAdapter * network()=0
The idea of the adapter system is that each adapter is either a network or is a child of a network...
bool isOperator(const QString &nickname) const
Checks if user is an operator on this channel.
void emitChatMessage(const QString &sender, const QString &content)
Emits message() signal formatting it to present sender's message.
void appendNameToCachedList(const QString &name)
Appends a single name to the sorted cachedNames list.