+ return mirc;
+}
+
+UiStyle::StyledMessage UiStyle::styleMessage(const Message &msg) {
+ return StyledMessage(msg, this);
+}
+
+/***********************************************************************************/
+
+UiStyle::StyledMessage::StyledMessage(const Message &msg, UiStyle *style) {
+ QString user = userFromMask(msg.sender());
+ QString host = hostFromMask(msg.sender());
+ QString nick = nickFromMask(msg.sender());
+ QString txt = style->mircToInternal(msg.contents());
+ QString bufferName = msg.bufferInfo().bufferName();
+ bufferName.replace('%', "%%"); // well, you _can_ have a % in a buffername apparently... -_-
+
+ _msgType = msg.type();
+ _timestamp = msg.timestamp();
+
+ QString t;
+ switch(msg.type()) {
+ case Message::Plain:
+ _sender = nick;
+ t = tr("%D0%1").arg(txt); break;
+ case Message::Notice:
+ _sender = nick;
+ 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);
+ //if(victim == ui.ownNick->currentText()) victim = tr("you");
+ 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 == msg.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:
+ _sender = msg.sender();
+ t = tr("%De[%1]").arg(txt);
+ }
+ _contents = style->styleString(t);
+}
+
+QDateTime UiStyle::StyledMessage::timestamp() const {
+ return _timestamp;
+}
+
+QString UiStyle::StyledMessage::decoratedTimestamp() const {
+ return QString("[%1]").arg(_timestamp.toLocalTime().toString("hh:mm:ss"));
+}
+
+QString UiStyle::StyledMessage::sender() const {
+ switch(type()) {
+ case Message::Plain:
+ case Message::Notice:
+ return _sender;
+ default:
+ return QString();
+ }
+}
+
+QString UiStyle::StyledMessage::decoratedSender() const {
+ switch(type()) {
+ case Message::Plain:
+ return tr("<%1>").arg(_sender); break;
+ case Message::Notice:
+ return tr("[%1]").arg(_sender); 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(_sender);
+ }
+}
+
+QString UiStyle::StyledMessage::contents() const {
+ return _contents.plainText;
+}
+
+UiStyle::FormatType UiStyle::StyledMessage::timestampFormat() const {
+ return UiStyle::Timestamp;
+}
+
+UiStyle::FormatType UiStyle::StyledMessage::senderFormat() const {
+ switch(type()) {
+ case Message::Plain:
+ return UiStyle::Sender; break;
+ 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;
+ }
+}
+
+UiStyle::FormatList UiStyle::StyledMessage::contentsFormatList() const {
+ return _contents.formatList;
+}
+
+/***********************************************************************************/
+
+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;