24 #include "irc/ircadapterbase.h" 25 #include "irc/ircclient.h" 26 #include "irc/ircctcpparser.h" 27 #include "irc/ircglobal.h" 28 #include "irc/ircmessageclass.h" 29 #include "irc/ircnetworkadapter.h" 30 #include "irc/ircuserinfo.h" 31 #include "ircrequestparser.h" 32 #include <QStringList> 34 DClass<IRCRequestParser>
50 IRCRequestParser::~IRCRequestParser()
56 return d->adapter->network();
59 const QString &IRCRequestParser::output()
const 66 d->adapter = pAdapter;
71 input = input.trimmed();
74 return ErrorMessageEmpty;
77 return ErrorInputNotPrependedWithSlash;
81 return ErrorMessageEmpty;
83 QStringList inputSplit = input.split(
" ", QString::SkipEmptyParts);
84 d->message = inputSplit.takeFirst().toUpper();
85 d->tokens = inputSplit;
87 IRCRequestParser::IRCRequestParseResult result = buildOutput();
90 if (isOutputTooLong())
91 return ErrorMessageTooLong;
97 IRCRequestParser::IRCRequestParseResult IRCRequestParser::buildOutput()
99 if (d->message ==
"QUIT")
101 d->output = QString(
"%1 :%2").arg(d->message, d->tokens.join(
" "));
104 else if (d->message ==
"AWAY")
105 d->output = QString(
"%1 :%2").arg(d->message, d->tokens.join(
" "));
106 else if (d->message ==
"PART")
108 if (d->tokens.isEmpty())
109 return ErrorInputInsufficientParameters;
111 QString channel = d->tokens.takeFirst();
112 QString farewellMessage = d->tokens.join(
" ");
113 d->output = QString(
"%1 %2 :%3").arg(d->message, channel, farewellMessage);
115 else if (d->message ==
"KICK")
117 if (d->tokens.length() < 2)
118 return ErrorInputInsufficientParameters;
120 QString channel = d->tokens.takeFirst();
121 QString user = d->tokens.takeFirst();
122 QString reason = d->tokens.join(
" ");
123 d->output = QString(
"%1 %2 %3 :%4").arg(d->message, channel, user, reason);
125 else if (d->message ==
"PRIVMSG" || d->message ==
"NOTICE")
128 if (d->tokens.length() < 2)
129 return ErrorInputInsufficientParameters;
131 QString recipient = d->tokens.takeFirst();
132 QString content = d->tokens.join(
" ");
133 d->output = QString(
"%1 %2 :%3").arg(d->message, recipient, content);
134 if (isOutputTooLong())
139 return ErrorMessageTooLong;
141 if (d->message ==
"PRIVMSG")
149 case IRCCtcpParser::PrintAsNormalMessage:
150 network()->printMsgLiteral(recipient, ctcp.printable(), IRCMessageClass::Ctcp);
152 case IRCCtcpParser::DisplayInServerTab:
153 network()->printWithClass(ctcp.printable(), QString(), IRCMessageClass::Ctcp);
155 case IRCCtcpParser::DisplayThroughGlobalMessage:
156 network()->printToCurrentChatBox(ctcp.printable(), IRCMessageClass::Ctcp);
158 case IRCCtcpParser::DontShow:
166 else if (d->message ==
"MSG")
170 parse(d->adapter, QString(
"/PRIVMSG %1").arg(d->tokens.join(
" ")));
172 else if (d->message ==
"QUERY")
174 if (!d->tokens.isEmpty())
176 QString recipient = d->tokens.takeFirst();
177 if (!IRCGlobal::isChannelName(recipient))
179 IRCUserInfo userInfo(recipient, d->adapter->network());
180 emit
query(userInfo.cleanNickname());
184 else if (d->message ==
"ME")
186 QString recipient = d->adapter->recipient();
187 if (recipient.isEmpty())
188 return ErrorChatWindowOnly;
189 QString content = d->tokens.join(
" ");
190 parse(d->adapter, QString(
"/PRIVMSG %1 %2ACTION %3%2").arg(recipient, QChar(0x1), content));
193 d->output = QString(
"%1 %2").arg(d->message, d->tokens.join(
" "));
198 bool IRCRequestParser::isOutputTooLong()
const 200 return d->output.toUtf8().length() > IRCClient::MAX_MESSAGE_LENGTH;
Interprets communication between the client and the IRC server.
Parses request and interprets them in a way that emulates mIRC (or any even slightly sane IRC client ...
Provides an unified communication interface between a client and IRC network entities.
void query(const QString &who)
Emitted when "/query" alias is used.
IRCRequestParseResult parse(IRCAdapterBase *pAdapter, QString input)
Parses input string and returns it through output string. Additional information is passed through re...
A question is being asked through PRIVMSG.
void echoPrivmsg(const QString &recipient, const QString &content)
Echoes back all PRIVMSG commands.
Holds information flags about given nickname.