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 !=
nullptr)
51 if (pNetwork ==
nullptr)
53 emit error(
"This chat window is not attached to any network. This is probably a bug in Doomseeker.");
58 QString messageTrimmed = message.trimmed();
60 if (messageTrimmed.startsWith(
"/"))
69 sendChatMessage(messageTrimmed);
75 emit message(QString(
"<%1>: %2").arg(sender, content));
80 QByteArray sentence =
"";
81 while (!words.isEmpty())
83 QByteArray word = words.takeFirst().toUtf8();
86 if (sentence.length() + word.length() + 1 > maxLength)
91 if (sentence.isEmpty())
94 QList<QByteArray> splitWordTokens =
Utf8Splitter().split(word, maxLength);
96 sentence = splitWordTokens.takeFirst();
99 QString wordRemainder =
"";
100 for (
const QByteArray &wordToken : splitWordTokens)
102 wordRemainder += QString::fromUtf8(wordToken.constData(), wordToken.size());
104 words.prepend(wordRemainder);
110 words.prepend(QString::fromUtf8(word.constData(), word.size()));
116 sentence += word +
" ";
118 return QString::fromUtf8(sentence.constData(), sentence.size()).trimmed();
121 void IRCChatAdapter::sendChatMessage(
const QString &message)
128 QString ircCall = QString(
"/PRIVMSG %1 ").arg(recipientName);
129 int maxLength = IRCClient::SAFE_MESSAGE_LENGTH - ircCall.toUtf8().length();
130 QStringList wordLines = message.split(
"\n");
132 for (QString line : wordLines)
134 QStringList words = line.split(
" ");
136 while (!words.isEmpty())
146 this->pNetwork = pNetwork;
149 void IRCChatAdapter::setRecipient(
const QString &name)
151 this->recipientName = name;
157 return recipientName;