Commit 546c49ae authored by Rafał Malinowski's avatar Rafał Malinowski

parser: replace bool parameter with enum

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent d33792dd
......@@ -37,7 +37,7 @@ KaduChatMessagesRenderer::KaduChatMessagesRenderer(ChatMessagesRendererConfigura
ChatMessagesRenderer{std::move(configuration), parent},
m_style{std::move(style)}
{
auto top = Parser::parse(m_style->top(), Talkable(this->configuration().chat().contacts().toContact()), true);
auto top = Parser::parse(m_style->top(), Talkable(this->configuration().chat().contacts().toContact()), ParserEscape::HtmlEscape);
auto html = QString{
"<html>"
......@@ -112,7 +112,7 @@ QString KaduChatMessagesRenderer::formatMessage(const Message &message, const Me
? m_style->withHeader()
: m_style->withoutHeader();
return Parser::parse(format, Talkable{sender}, &messageRenderInfo, true);
return Parser::parse(format, Talkable{sender}, &messageRenderInfo, ParserEscape::HtmlEscape);
}
QString KaduChatMessagesRenderer::scriptsAtEnd(const QString &html)
......
......@@ -202,7 +202,7 @@ void BuddyInfoPanel::displayItem(Talkable item)
}
QDomDocument domDocument;
domDocument.setContent(Template.arg(Parser::parse(Syntax, item)));
domDocument.setContent(Template.arg(Parser::parse(Syntax, item, ParserEscape::HtmlEscape)));
Core::instance()->domProcessorService()->process(domDocument);
......
......@@ -405,7 +405,7 @@ void ChatWidget::refreshTitle()
QString conferenceContents = ChatConfigurationHolder::instance()->conferenceContents();
QStringList contactslist;
foreach (Contact contact, chat().contacts())
contactslist.append(Parser::parse(conferenceContents.isEmpty() ? "%a" : conferenceContents, Talkable(contact), false));
contactslist.append(Parser::parse(conferenceContents.isEmpty() ? "%a" : conferenceContents, Talkable(contact), ParserEscape::NoEscape));
title.append(contactslist.join(", "));
}
......@@ -417,12 +417,12 @@ void ChatWidget::refreshTitle()
{
title = tr("Chat with ");
if (contact.isAnonymous())
title += Parser::parse("%a", Talkable(contact), false);
title += Parser::parse("%a", Talkable(contact), ParserEscape::NoEscape);
else
title += Parser::parse("%a (%s[: %d])", Talkable(contact), false);
title += Parser::parse("%a (%s[: %d])", Talkable(contact), ParserEscape::NoEscape);
}
else
title = Parser::parse(ChatConfigurationHolder::instance()->chatContents(), Talkable(contact), false);
title = Parser::parse(ChatConfigurationHolder::instance()->chatContents(), Talkable(contact), ParserEscape::NoEscape);
if (ChatConfigurationHolder::instance()->contactStateWindowTitle())
{
......
......@@ -62,7 +62,7 @@ KaduWebView * Preview::webView() const
void Preview::syntaxChanged(const QString &content)
{
QString syntax = content;
QString text = Parser::parse(syntax, Talkable(Buddy::dummy()));
QString text = Parser::parse(syntax, Talkable(Buddy::dummy()), ParserEscape::HtmlEscape);
emit needFixup(text);
WebView->setHtml(text);
......
......@@ -785,7 +785,7 @@ void KaduWindowActions::copyPersonalInfoActionActivated(QAction *sender, bool to
+ Parser::escape(tr("Mobile:")) + " %m\n]";
QString copyPersonalDataSyntax = config_file.readEntry("General", "CopyPersonalDataSyntax", defaultSyntax);
foreach (Contact contact, contacts)
infoList.append(Parser::parse(copyPersonalDataSyntax, Talkable(contact), false));
infoList.append(Parser::parse(copyPersonalDataSyntax, Talkable(contact), ParserEscape::NoEscape));
QString info = infoList.join("\n");
if (info.isEmpty())
......
......@@ -295,7 +295,7 @@ void StatusWindow::applyStatus()
DescriptionManager::instance()->addDescription(description);
if (config_file.readBoolEntry("General", "ParseStatus", false))
description = Parser::parse(description, Talkable(Core::instance()->myself()), false);
description = Parser::parse(description, Talkable(Core::instance()->myself()), ParserEscape::NoEscape);
foreach (StatusContainer *container, Container->subStatusContainers())
{
......
......@@ -220,7 +220,7 @@ bool Parser::isActionParserTokenAtTop(const QStack<ParserToken> &parseStack, con
return found;
}
ParserToken Parser::parsePercentSyntax(const QString &s, int &idx, const Talkable &talkable, bool htmlEscape)
ParserToken Parser::parsePercentSyntax(const QString &s, int &idx, const Talkable &talkable, ParserEscape escape)
{
ParserToken pe;
pe.setType(PT_STRING);
......@@ -287,7 +287,7 @@ ParserToken Parser::parsePercentSyntax(const QString &s, int &idx, const Talkabl
if (contact)
{
QString description = contact.currentStatus().description();
if (htmlEscape)
if (escape == ParserEscape::HtmlEscape)
Qt::escape(description);
pe.setContent(description);
......@@ -344,7 +344,7 @@ ParserToken Parser::parsePercentSyntax(const QString &s, int &idx, const Talkabl
++idx;
QString nickName = chat ? ChatDataExtractor::data(chat, Qt::DisplayRole).toString() : buddy.nickName();
if (htmlEscape)
if (escape == ParserEscape::HtmlEscape)
Qt::escape(nickName);
pe.setContent(nickName);
......@@ -356,7 +356,7 @@ ParserToken Parser::parsePercentSyntax(const QString &s, int &idx, const Talkabl
++idx;
QString display = chat ? ChatDataExtractor::data(chat, Qt::DisplayRole).toString() : buddy.display();
if (htmlEscape)
if (escape == ParserEscape::HtmlEscape)
Qt::escape(display);
pe.setContent(display);
......@@ -368,7 +368,7 @@ ParserToken Parser::parsePercentSyntax(const QString &s, int &idx, const Talkabl
++idx;
QString firstName = buddy.firstName();
if (htmlEscape)
if (escape == ParserEscape::HtmlEscape)
Qt::escape(firstName);
pe.setContent(firstName);
......@@ -380,7 +380,7 @@ ParserToken Parser::parsePercentSyntax(const QString &s, int &idx, const Talkabl
++idx;
QString lastName = buddy.lastName();
if (htmlEscape)
if (escape == ParserEscape::HtmlEscape)
Qt::escape(lastName);
pe.setContent(lastName);
......@@ -490,9 +490,9 @@ QString Parser::joinParserTokens(const ContainerClass &parseStack)
return joined;
}
QString Parser::parse(const QString &s, Talkable talkable, const ParserData * const parserData, bool htmlEscape)
QString Parser::parse(const QString &s, Talkable talkable, const ParserData * const parserData, ParserEscape escape = ParserEscape::HtmlEscape)
{
kdebugmf(KDEBUG_DUMP, "%s htmlEscape=%i\n", qPrintable(s), htmlEscape);
kdebugmf(KDEBUG_DUMP, "%s htmlEscape=%i\n", qPrintable(s), escape);
prepareSearchChars();
......@@ -524,7 +524,7 @@ QString Parser::parse(const QString &s, Talkable talkable, const ParserData * co
if (idx == len)
break;
pe = parsePercentSyntax(s, idx, talkable, htmlEscape);
pe = parsePercentSyntax(s, idx, talkable, escape);
pe.encodeContent(QByteArray(), ENCODE_INCLUDE_CHARS);
parseStack.push(pe);
......
......@@ -38,6 +38,12 @@ template<typename T> class QStack;
class ParserData;
class ParserToken;
enum class ParserEscape
{
NoEscape,
HtmlEscape
};
class KADUAPI Parser
{
using ObjectTagCallback = std::function<QString(const ParserData * const)>;
......@@ -49,7 +55,7 @@ class KADUAPI Parser
static QString executeCmd(const QString &cmd);
static bool isActionParserTokenAtTop(const QStack<ParserToken> &parseStack, const QVector<ParserTokenType> &acceptedTokens);
static ParserToken parsePercentSyntax(const QString &s, int &idx, const Talkable &talkable, bool escape);
static ParserToken parsePercentSyntax(const QString &s, int &idx, const Talkable &talkable, ParserEscape escape);
template<typename ContainerClass>
static QString joinParserTokens(const ContainerClass &parseStack);
......@@ -59,15 +65,15 @@ public:
static QString escape(const QString &string);
static QString parse(const QString &s, const ParserData * const parserData, bool htmlEscape = true)
static QString parse(const QString &s, const ParserData * const parserData, ParserEscape escape)
{
return parse(s, Talkable(), parserData, htmlEscape);
return parse(s, Talkable(), parserData, escape);
}
static QString parse(const QString &s, Talkable talkable, bool htmlEscape = true)
static QString parse(const QString &s, Talkable talkable, ParserEscape escape)
{
return parse(s, talkable, 0, htmlEscape);
return parse(s, talkable, 0, escape);
}
static QString parse(const QString &s, Talkable talkable, const ParserData * const parserData, bool escape = true);
static QString parse(const QString &s, Talkable talkable, const ParserData * const parserData, ParserEscape escape);
static bool registerTag(const QString &name, TalkableTagCallback);
static bool unregisterTag(const QString &name);
......
......@@ -250,7 +250,7 @@ void AutoAway::descriptionChangeChanged(int index)
QString AutoAway::parseDescription(const QString &parseDescription)
{
if (parseAutoStatus)
return (Parser::parse(parseDescription, Talkable(Core::instance()->myself()), true));
return (Parser::parse(parseDescription, Talkable(Core::instance()->myself()), ParserEscape::HtmlEscape));
else
return parseDescription;
}
......
......@@ -109,7 +109,7 @@ bool AutoResponder::acceptMessage(const Message &message)
|| (Configuration.statusBusy() && protocol->status().group() == StatusTypeGroupAway))
{
MessageManager::instance()->sendMessage(message.messageChat(), tr("KADU AUTORESPONDER:") + '\n'
+ Parser::parse(Configuration.autoRespondText(), Talkable(message.messageSender())), true);
+ Parser::parse(Configuration.autoRespondText(), Talkable(message.messageSender()), ParserEscape::HtmlEscape), true);
RepliedChats.insert(message.messageChat());
}
......
......@@ -239,11 +239,11 @@ void ExecNotify::notify(Notification *notification)
Contact contact = *contacts.constBegin();
foreach (QString it, s)
result.append(Parser::parse(it.replace("%ids", sendersString), Talkable(contact), notification));
result.append(Parser::parse(it.replace("%ids", sendersString), Talkable(contact), notification, ParserEscape::HtmlEscape));
}
else
foreach (const QString &it, s)
result.append(Parser::parse(it, notification));
result.append(Parser::parse(it, notification, ParserEscape::HtmlEscape));
run(result);
}
......
......@@ -154,7 +154,7 @@ void HintOverUserConfigurationWindow::syntaxChanged()
if (!hintSyntax->document()->isModified())
return;
QString text = Parser::parse(hintSyntax->toPlainText(), Talkable(ExampleBuddy));
QString text = Parser::parse(hintSyntax->toPlainText(), Talkable(ExampleBuddy), ParserEscape::HtmlEscape);
/* Dorr: the file:// in img tag doesn't generate the image on hint.
* for compatibility with other syntaxes we're allowing to put the file://
......
......@@ -173,10 +173,10 @@ void Hint::updateText()
if (CurrentChat)
{
Contact contact = *CurrentChat.contacts().constBegin();
text = Parser::parse(syntax, Talkable(contact), notification);
text = Parser::parse(syntax, Talkable(contact), notification, ParserEscape::HtmlEscape);
}
else
text = Parser::parse(syntax, notification);
text = Parser::parse(syntax, notification, ParserEscape::HtmlEscape);
/* Dorr: the file:// in img tag doesn't generate the image on hint.
* for compatibility with other syntaxes we're allowing to put the file://
......
......@@ -489,7 +489,7 @@ void HintManager::setLayoutDirection()
void HintManager::prepareOverUserHint(QFrame *tipFrame, QLabel *tipLabel, Talkable talkable)
{
QString text = Parser::parse(config_file.readEntry("Hints", "MouseOverUserSyntax"), talkable);
QString text = Parser::parse(config_file.readEntry("Hints", "MouseOverUserSyntax"), talkable, ParserEscape::HtmlEscape);
/* Dorr: the file:// in img tag doesn't generate the image on hint.
* for compatibility with other syntaxes we're allowing to put the file://
......
......@@ -93,10 +93,10 @@ QString Qt4Notify::parseText(const QString &text, Notification *notification, co
if (chatNotification)
{
Contact contact = *chatNotification->chat().contacts().constBegin();
ret = Parser::parse(text, Talkable(contact), notification);
ret = Parser::parse(text, Talkable(contact), notification, ParserEscape::HtmlEscape);
}
else
ret = Parser::parse(text, notification);
ret = Parser::parse(text, notification, ParserEscape::HtmlEscape);
ret = ret.replace("%&m", notification->text());
ret = ret.replace("%&t", notification->title());
......
......@@ -110,7 +110,7 @@ void SpeechConfigurationUiHandler::testSpeech()
kdebugm(KDEBUG_INFO, "%d %d %d\n", frequency, tempo, baseFrequency);
QString text;
text = Parser::parse(formatF, Talkable(Buddy::dummy()));
text = Parser::parse(formatF, Talkable(Buddy::dummy()), ParserEscape::HtmlEscape);
Speech::instance()->say(text.contains("%1") ? text.arg("Test") : QString("Test"), program, klatt, mel, sound_system, device, frequency, tempo, baseFrequency);
......
......@@ -252,10 +252,10 @@ void Speech::notify(Notification *notification)
if (chat)
{
Contact contact = *chat.contacts().begin();
text = Parser::parse(syntax, Talkable(contact), notification);
text = Parser::parse(syntax, Talkable(contact), notification, ParserEscape::HtmlEscape);
}
else
text= Parser::parse(syntax, notification);
text= Parser::parse(syntax, notification, ParserEscape::HtmlEscape);
}
QTextDocument document;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment