23 #include "ircchatadapter.h" 25 #include "irc/ircnetworkadapter.h" 26 #include "utf8splitter.h" 30 this->pNetwork = pNetwork;
31 this->recipientName = recipient;
34 IRCChatAdapter::~IRCChatAdapter()
36 if (this->pNetwork != NULL)
52 emit error(
"This chat window is not attached to any network. This is probably a bug in Doomseeker.");
57 QString messageTrimmed = message.trimmed();
59 if (messageTrimmed.startsWith(
"/"))
68 sendChatMessage(messageTrimmed);
74 emit message(QString(
"<%1>: %2").arg(sender, content));
79 QByteArray sentence =
"";
80 while(!words.isEmpty())
82 QByteArray word = words.takeFirst().toUtf8();
85 if (sentence.length() + word.length() + 1 > maxLength)
90 if (sentence.isEmpty())
93 QList<QByteArray> splitWordTokens =
Utf8Splitter().split(word, maxLength);
95 sentence = splitWordTokens.takeFirst();
98 QString wordRemainder =
"";
99 foreach (
const QByteArray &wordToken, splitWordTokens)
101 wordRemainder += QString::fromUtf8(wordToken.constData(), wordToken.size());
103 words.prepend(wordRemainder);
109 words.prepend(QString::fromUtf8(word.constData(), word.size()));
115 sentence += word +
" ";
117 return QString::fromUtf8(sentence.constData(), sentence.size()).trimmed();
120 void IRCChatAdapter::sendChatMessage(
const QString& message)
127 QString ircCall = QString(
"/PRIVMSG %1 ").arg(recipientName);
128 int maxLength = IRCClient::SAFE_MESSAGE_LENGTH - ircCall.toUtf8().length();
129 QStringList wordLines = message.split(
"\n");
131 foreach(QString line, wordLines)
133 QStringList words = line.split(
" ");
135 while (!words.isEmpty())
145 this->pNetwork = pNetwork;
148 void IRCChatAdapter::setRecipient(
const QString& name)
150 this->recipientName = name;
156 return recipientName;
Interprets communication between the client and the IRC server.
void setNetwork(IRCNetworkAdapter *pNetwork)
Sets IRCNetworkAdapter for this chat window. This adapter is not detached from the old network...
Provides an unified communication interface between a client and IRC network entities.
void doSendMessage(const QString &message, IRCAdapterBase *pOrigin)
Implemented to support direct communication between client and server.
virtual void emitChatMessage(const QString &sender, const QString &content)
Emits message() signal formatting it to present sender's message.
void titleChange()
Can be called when the variable returned by title() might have changed and the application should be ...
QString title() const
For chat adapters this will return recipientName.
IRCChatAdapter(IRCNetworkAdapter *pNetwork, const QString &recipient)
void detachChatWindow(const IRCChatAdapter *pAdapter)
Detaches the specified IRCChatAdapter instance from this network without deleting it...
QString extractMessageLine(QStringList &words, int maxLength)
void doSendMessage(const QString &message, IRCAdapterBase *pOrigin)
Splits valid arrays of UTF-8 characters into smaller arrays without splitting in-between chars...