+ return mirc;
+}
+
+/***********************************************************************************/
+UiStyle::StyledMessage::StyledMessage(const Message &msg)
+ : Message(msg)
+{
+}
+
+void UiStyle::StyledMessage::style(UiStyle *style) const {
+ QString user = userFromMask(sender());
+ QString host = hostFromMask(sender());
+ QString nick = nickFromMask(sender());
+ QString txt = style->mircToInternal(contents());
+ QString bufferName = bufferInfo().bufferName();
+ bufferName.replace('%', "%%"); // well, you _can_ have a % in a buffername apparently... -_-
+
+ QString t;
+ switch(type()) {
+ case Message::Plain:
+ t = tr("%D0%1").arg(txt); break;
+ case Message::Notice:
+ t = tr("%Dn%1").arg(txt); break;
+ case Message::Server:
+ t = tr("%Ds%1").arg(txt); break;
+ case Message::Error:
+ t = tr("%De%1").arg(txt); break;
+ case Message::Join:
+ t = tr("%Dj%DN%1%DN %DH(%2@%3)%DH has joined %DC%4%DC").arg(nick, user, host, bufferName); break;
+ case Message::Part:
+ t = tr("%Dp%DN%1%DN %DH(%2@%3)%DH has left %DC%4%DC").arg(nick, user, host, bufferName);
+ if(!txt.isEmpty()) t = QString("%1 (%2)").arg(t).arg(txt);
+ break;
+ case Message::Quit:
+ t = tr("%Dq%DN%1%DN %DH(%2@%3)%DH has quit").arg(nick, user, host);
+ if(!txt.isEmpty()) t = QString("%1 (%2)").arg(t).arg(txt);
+ break;
+ case Message::Kick: {
+ QString victim = txt.section(" ", 0, 0);
+ QString kickmsg = txt.section(" ", 1);
+ t = tr("%Dk%DN%1%DN has kicked %DN%2%DN from %DC%3%DC").arg(nick).arg(victim).arg(bufferName);
+ if(!kickmsg.isEmpty()) t = QString("%1 (%2)").arg(t).arg(kickmsg);
+ }
+ break;
+ case Message::Nick:
+ if(nick == contents()) t = tr("%DrYou are now known as %DN%1%DN").arg(txt);
+ else t = tr("%Dr%DN%1%DN is now known as %DN%2%DN").arg(nick, txt);
+ break;
+ case Message::Mode:
+ if(nick.isEmpty()) t = tr("%DmUser mode: %DM%1%DM").arg(txt);
+ else t = tr("%DmMode %DM%1%DM by %DN%2%DN").arg(txt, nick);
+ break;
+ case Message::Action:
+ t = tr("%Da%DN%1%DN %2").arg(nick).arg(txt);
+ break;
+ default:
+ t = tr("%De[%1]").arg(txt);
+ }
+ _contents = style->styleString(t);
+}
+
+QString UiStyle::StyledMessage::decoratedTimestamp() const {
+ return QString("[%1]").arg(timestamp().toLocalTime().toString("hh:mm:ss"));
+}
+
+QString UiStyle::StyledMessage::plainSender() const {
+ switch(type()) {
+ case Message::Plain:
+ case Message::Notice:
+ return nickFromMask(sender());
+ default:
+ return QString();
+ }
+}
+
+QString UiStyle::StyledMessage::decoratedSender() const {
+ switch(type()) {
+ case Message::Plain:
+ return tr("<%1>").arg(plainSender()); break;
+ case Message::Notice:
+ return tr("[%1]").arg(plainSender()); break;
+ case Message::Server:
+ return tr("*"); break;
+ case Message::Error:
+ return tr("*"); break;
+ case Message::Join:
+ return tr("-->"); break;
+ case Message::Part:
+ return tr("<--"); break;
+ case Message::Quit:
+ return tr("<--"); break;
+ case Message::Kick:
+ return tr("<-*"); break;
+ case Message::Nick:
+ return tr("<->"); break;
+ case Message::Mode:
+ return tr("***"); break;
+ case Message::Action:
+ return tr("-*-"); break;
+ default:
+ return tr("%1").arg(plainSender());
+ }
+}
+
+UiStyle::FormatType UiStyle::StyledMessage::senderFormat() const {
+ quint16 hash;
+ switch(type()) {
+ case Message::Plain:
+ // To produce random like but stable nick colorings some sort of hashing should work best.
+ // In this case we just use the qt function qChecksum which produces a
+ // CRC16 hash. This should be fast and 16 bits are more than enough.
+ hash = qChecksum(sender().toAscii().data(), sender().toAscii().size());
+ return (UiStyle::FormatType)((((hash % 12) + 1) << 24) + 0x200); // FIXME: amount of sender colors hardwired
+ case Message::Notice:
+ return UiStyle::NoticeMsg; break;
+ case Message::Server:
+ return UiStyle::ServerMsg; break;
+ case Message::Error:
+ return UiStyle::ErrorMsg; break;
+ case Message::Join:
+ return UiStyle::JoinMsg; break;
+ case Message::Part:
+ return UiStyle::PartMsg; break;
+ case Message::Quit:
+ return UiStyle::QuitMsg; break;
+ case Message::Kick:
+ return UiStyle::KickMsg; break;
+ case Message::Nick:
+ return UiStyle::RenameMsg; break;
+ case Message::Mode:
+ return UiStyle::ModeMsg; break;
+ case Message::Action:
+ return UiStyle::ActionMsg; break;
+ default:
+ return UiStyle::ErrorMsg;
+ }
+}
+
+
+/***********************************************************************************/
+
+QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList) {
+ out << formatList.count();
+ UiStyle::FormatList::const_iterator it = formatList.begin();
+ while(it != formatList.end()) {
+ out << (*it).first << (*it).second;
+ ++it;
+ }
+ return out;