From 823528584f21bfc8f47f4449db09572f667636ea Mon Sep 17 00:00:00 2001 From: btsai Date: Mon, 16 Mar 2009 02:56:17 +0000 Subject: [PATCH] Took two large code duplication that converted a kopete::message to a msn::message and pulled it out into a function. Squashed commit of the following: commit 750e654946d5970dbb9216dcda92f6bd8c3a36ce Author: Benson Tsai Date: Sun Mar 15 11:19:58 2009 -0400 cleaning up msn a little bit git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/KDE/kdenetwork@939940 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/protocols/wlm/wlmchatsession.cpp | 113 +++++++++++++------------------- kopete/protocols/wlm/wlmchatsession.h | 1 + 2 files changed, 45 insertions(+), 69 deletions(-) diff --git a/kopete/protocols/wlm/wlmchatsession.cpp b/kopete/protocols/wlm/wlmchatsession.cpp index cb3a1d7c1..514009c91 100644 --- a/kopete/protocols/wlm/wlmchatsession.cpp +++ b/kopete/protocols/wlm/wlmchatsession.cpp @@ -381,6 +381,48 @@ WlmChatSession::setChatService (MSN::SwitchboardServerConnection * conn) } } +MSN::Message WlmChatSession::parseMessage(Kopete::Message & msg) +{ + // send the message and wait for the ACK + int fontEffects = 0; + QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8")); + MSN::Message mmsg(msg.plainBody().toAscii().data()); + + // FIXME: Can we add FontFamily FF_DONTCARE ? + if (msg.format() == Qt::RichText) + { + mmsg.setFontName(msg.font().family().toAscii().data()); + if (msg.font().bold()) + fontEffects |= MSN::Message::BOLD_FONT; + if (msg.font().italic()) + fontEffects |= MSN::Message::ITALIC_FONT; + if (msg.font().underline()) + fontEffects |= MSN::Message::UNDERLINE_FONT; + if (msg.font().strikeOut()) + fontEffects |= MSN::Message::STRIKETHROUGH_FONT; + + mmsg.setFontEffects(fontEffects); + QColor color = msg.foregroundColor(); + mmsg.setColor(color.red(), color.green(), color.blue()); + } + + // stolen from msn plugin + const QHash emap = Kopete::Emoticons::self()->theme().emoticonsMap(); + + // Check the list for any custom emoticons + for (QHash::const_iterator itr = emap.begin(); itr != emap.end(); ++itr) + { + for (QStringList::const_iterator itr2 = itr.value().constBegin(); itr2 != itr.value().constEnd(); ++itr2) + { + if (msg.plainBody().contains(*itr2)) + { + getChatService()->sendEmoticon((*itr2).toAscii().data(), itr.key().toAscii().data()); + } + } + } + return mmsg; +} + void WlmChatSession::setReady (bool value) { @@ -416,38 +458,7 @@ WlmChatSession::setReady (bool value) for (it2 = m_messagesQueue.begin (); it2 != m_messagesQueue.end (); ++it2) { - int fontEffects = 0; - QTextCodec::setCodecForCStrings (QTextCodec:: - codecForName ("utf8")); - MSN::Message mmsg ((*it2).plainBody ().toAscii ().data ()); - mmsg.setFontName ((*it2).font ().family ().toAscii ().data ()); - if ((*it2).font ().bold ()) - fontEffects |= MSN::Message::BOLD_FONT; - if ((*it2).font ().italic ()) - fontEffects |= MSN::Message::ITALIC_FONT; - if ((*it2).font ().underline ()) - fontEffects |= MSN::Message::UNDERLINE_FONT; - if ((*it2).font ().strikeOut ()) - fontEffects |= MSN::Message::STRIKETHROUGH_FONT; - - mmsg.setFontEffects (fontEffects); - QColor color = (*it2).foregroundColor (); - mmsg.setColor (color.red (), color.green (), color.blue ()); - - // stolen from msn plugin - const QHash emap = Kopete::Emoticons::self()->theme().emoticonsMap(); - - // Check the list for any custom emoticons - for (QHash::const_iterator itr = emap.begin(); itr != emap.end(); ++itr) - { - for ( QStringList::const_iterator itr2 = itr.value().constBegin(); itr2 != itr.value().constEnd(); ++itr2 ) - { - if ( (*it2).plainBody().contains( *itr2 ) ) - { - getChatService ()->sendEmoticon((*itr2).toAscii().data(), itr.key().toAscii().data()); - } - } - } + MSN::Message mmsg = parseMessage(*it2); int trid = getChatService ()->sendMessage (&mmsg); @@ -532,43 +543,7 @@ WlmChatSession::slotMessageSent (Kopete::Message & msg, if (isReady ()) { - // send the message and wait for the ACK - int fontEffects = 0; - QTextCodec::setCodecForCStrings (QTextCodec::codecForName ("utf8")); - MSN::Message mmsg (msg.plainBody ().toAscii ().data ()); - - // FIXME: Can we add FontFamily FF_DONTCARE ? - if ( msg.format() == Qt::RichText ) - { - mmsg.setFontName (msg.font ().family ().toAscii ().data ()); - if (msg.font ().bold ()) - fontEffects |= MSN::Message::BOLD_FONT; - if (msg.font ().italic ()) - fontEffects |= MSN::Message::ITALIC_FONT; - if (msg.font ().underline ()) - fontEffects |= MSN::Message::UNDERLINE_FONT; - if (msg.font ().strikeOut ()) - fontEffects |= MSN::Message::STRIKETHROUGH_FONT; - - mmsg.setFontEffects (fontEffects); - QColor color = msg.foregroundColor (); - mmsg.setColor (color.red (), color.green (), color.blue ()); - } - - // stolen from msn plugin - const QHash emap = Kopete::Emoticons::self()->theme().emoticonsMap(); - - // Check the list for any custom emoticons - for (QHash::const_iterator itr = emap.begin(); itr != emap.end(); ++itr) - { - for ( QStringList::const_iterator itr2 = itr.value().constBegin(); itr2 != itr.value().constEnd(); ++itr2 ) - { - if ( msg.plainBody().contains( *itr2 ) ) - { - getChatService ()->sendEmoticon((*itr2).toAscii().data(), itr.key().toAscii().data()); - } - } - } + MSN::Message mmsg = parseMessage(msg); int trid = getChatService ()->sendMessage (&mmsg); diff --git a/kopete/protocols/wlm/wlmchatsession.h b/kopete/protocols/wlm/wlmchatsession.h index 45b08d0a6..2c6a81bdc 100644 --- a/kopete/protocols/wlm/wlmchatsession.h +++ b/kopete/protocols/wlm/wlmchatsession.h @@ -88,6 +88,7 @@ class WlmChatSession: public Kopete::ChatSession void sendKeepAlive (); private: + MSN::Message parseMessage(Kopete::Message & msg); MSN::SwitchboardServerConnection * m_chatService; bool m_downloadDisplayPicture; -- 2.11.4.GIT