Feature #1744 » highlight.patch
src/plugins/azoth/core.cpp | ||
---|---|---|
#include <util/shortcuts/shortcutmanager.h>
|
||
#include <util/sys/resourceloader.h>
|
||
#include <util/sll/urloperator.h>
|
||
#include <util/sll/prelude.h>
|
||
#include <interfaces/iplugin2.h>
|
||
#include <interfaces/an/constants.h>
|
||
#include <interfaces/core/icoreproxy.h>
|
||
... | ... | |
return string;
|
||
}
|
||
QString Core::FormatBody (QString body, IMessage *msg)
|
||
namespace
|
||
{
|
||
void HighlightNicks (QString& body, IMessage *msg, const QList<QColor>& colors)
|
||
{
|
||
const auto entry = qobject_cast<IMUCEntry*> (msg->ParentCLEntry ());
|
||
if (!entry)
|
||
return;
|
||
const auto& nicks = Util::Map (entry->GetParticipants (),
|
||
[] (QObject *obj) { return qobject_cast<ICLEntry*> (obj)->GetEntryName (); });
|
||
for (const auto& nick : nicks)
|
||
{
|
||
if (!body.contains (nick))
|
||
continue;
|
||
const auto& nickColor = GetNickColor (nick, colors);
|
||
if (nickColor.isNull ())
|
||
continue;
|
||
int pos = 0;
|
||
while ((pos = body.indexOf (nick, pos)) >= 0)
|
||
{
|
||
const auto nickEnd = pos + nick.size ();
|
||
if ((pos > 0 && !body.at (pos - 1).isSpace ()) ||
|
||
(nickEnd + 1 < body.size () && !body.at (nickEnd + 1).isSpace ()))
|
||
{
|
||
pos += nick.size ();
|
||
continue;
|
||
}
|
||
const auto& startStr = "<span style='color: " + nickColor + "'>";
|
||
const QString endStr { "</span>" };
|
||
body.insert (nickEnd, endStr);
|
||
body.insert (pos, startStr);
|
||
pos += nick.size () + startStr.size () + endStr.size ();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
QString Core::FormatBody (QString body, IMessage *msg, const QList<QColor>& colors)
|
||
{
|
||
QObject *msgObj = msg->GetQObject ();
|
||
... | ... | |
body = HandleSmiles (body);
|
||
if (msg->GetMessageType () == IMessage::Type::MUCMessage)
|
||
HighlightNicks (body, msg, colors);
|
||
proxy.reset (new Util::DefaultHookProxy);
|
||
proxy->SetValue ("body", body);
|
||
emit hookFormatBodyEnd (proxy, msgObj);
|
src/plugins/azoth/core.h | ||
---|---|---|
QString FormatDate (QDateTime, IMessage*);
|
||
QString FormatNickname (QString, IMessage*, const QString& color);
|
||
QString FormatBody (QString body, IMessage *msg);
|
||
QString FormatBody (QString body, IMessage *msg, const QList<QColor>& coloring);
|
||
QString HandleSmiles (QString body);
|
||
/** This function increases the number of unread messages by
|
src/plugins/azoth/interfaces/azoth/iproxyobject.h | ||
---|---|---|
* This function should be used to format the body of the given
|
||
* message.
|
||
*
|
||
* This function also accepts the list of colors used for
|
||
* nick coloring in the current chat window, since the
|
||
* \em body of the \em message may also be colored if it contains
|
||
* other participants' nicks.
|
||
*
|
||
* @param[in] body The body to format.
|
||
* @param[in] message The message object implementing IMessage.
|
||
* @param[in] coloring The set of colors used for nick coloring.
|
||
* @return The formatted body.
|
||
*/
|
||
virtual QString FormatBody (QString body, QObject *message) const = 0;
|
||
virtual QString FormatBody (QString body, QObject *message, const QList<QColor>& coloring) const = 0;
|
||
/** @brief Preprocesses the message before displaying it.
|
||
*
|
src/plugins/azoth/plugins/adiumstyles/adiumstylesource.cpp | ||
---|---|---|
Coloring2Colors_ ["hash"] = Proxy_->GenerateColors ("hash", {});
|
||
// %senderColor%
|
||
const QString& nickColor = Proxy_->GetNickColor (senderNick, Coloring2Colors_ ["hash"]);
|
||
const auto& colors = Coloring2Colors_ ["hash"];
|
||
const auto& nickColor = Proxy_->GetNickColor (senderNick, colors);
|
||
templ.replace ("%senderColor%", nickColor);
|
||
// %senderColor{N}%
|
||
... | ... | |
.arg (senderNick)
|
||
.arg (body.mid (4));
|
||
body = Proxy_->FormatBody (body, msgObj);
|
||
body = Proxy_->FormatBody (body, msgObj, colors);
|
||
if (isHighlightMsg && !hasHighBackground)
|
||
body = "<span style=\"color:" + highColor +
|
src/plugins/azoth/plugins/standardstyles/standardstylesource.cpp | ||
---|---|---|
if (body.isEmpty ())
|
||
body = msg->GetEscapedBody ();
|
||
body = Proxy_->FormatBody (body, msg->GetQObject ());
|
||
body = Proxy_->FormatBody (body, msg->GetQObject (), colors);
|
||
const QString dateBegin ("<span class='datetime'>");
|
||
const QString dateEnd ("</span>");
|
src/plugins/azoth/proxyobject.cpp | ||
---|---|---|
return Core::Instance ().FormatNickname (nick, qobject_cast<IMessage*> (obj), color);
|
||
}
|
||
QString ProxyObject::FormatBody (QString body, QObject *obj) const
|
||
QString ProxyObject::FormatBody (QString body, QObject *obj, const QList<QColor>& coloring) const
|
||
{
|
||
return Core::Instance ().FormatBody (body, qobject_cast<IMessage*> (obj));
|
||
return Core::Instance ().FormatBody (body, qobject_cast<IMessage*> (obj), coloring);
|
||
}
|
||
void ProxyObject::PreprocessMessage (QObject *msgObj)
|
src/plugins/azoth/proxyobject.h | ||
---|---|---|
QString GetNickColor (const QString&, const QList<QColor>&) const;
|
||
QString FormatDate (QDateTime, QObject*) const;
|
||
QString FormatNickname (QString, QObject*, const QString&) const;
|
||
QString FormatBody (QString, QObject*) const;
|
||
QString FormatBody (QString, QObject*, const QList<QColor>&) const;
|
||
void PreprocessMessage (QObject*);
|
||
Util::ResourceLoader* GetResourceLoader (PublicResourceLoader) const;
|
||
QIcon GetIconForState (State) const;
|
- « Previous
- 1
- 2
- Next »