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;
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.
virtual void emitChatMessage(const QString &sender, const QString &content)
Emits message() signal formatting it to present sender's message.
QString title() const override
For chat adapters this will return recipientName.
void doSendMessage(const QString &message, IRCAdapterBase *pOrigin) override
Implemented to support direct communication between client and server.
void titleChange()
Can be called when the variable returned by title() might have changed and the application should be ...
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) override
Splits valid arrays of UTF-8 characters into smaller arrays without splitting in-between chars...