+/***********************************************************************************/
+UiStyle::StyledMessage::StyledMessage(const Message &msg)
+ : Message(msg)
+{
+ if(type() == Message::Plain)
+ _senderHash = 0xff;
+ else
+ _senderHash = 0x00; // this means we never compute the hash for msgs that aren't plain
+}
+
+void UiStyle::StyledMessage::style() const {
+ QString user = userFromMask(sender());
+ QString host = hostFromMask(sender());
+ QString nick = nickFromMask(sender());
+ QString txt = UiStyle::mircToInternal(contents());
+ QString bufferName = bufferInfo().bufferName();
+ bufferName.replace('%', "%%"); // well, you _can_ have a % in a buffername apparently... -_-
+
+ QString t;
+ switch(type()) {
+ case Message::Plain:
+ //: Plain Message
+ t = tr("%1").arg(txt); break;
+ case Message::Notice:
+ //: Notice Message
+ t = tr("%1").arg(txt); break;
+ case Message::Action:
+ //: Action Message
+ t = tr("%DN%1%DN %2").arg(nick).arg(txt);
+ break;
+ case Message::Nick:
+ //: Nick Message
+ if(nick == contents()) t = tr("You are now known as %DN%1%DN").arg(txt);
+ else t = tr("%DN%1%DN is now known as %DN%2%DN").arg(nick, txt);
+ break;
+ case Message::Mode:
+ //: Mode Message
+ if(nick.isEmpty()) t = tr("User mode: %DM%1%DM").arg(txt);
+ else t = tr("Mode %DM%1%DM by %DN%2%DN").arg(txt, nick);
+ break;
+ case Message::Join:
+ //: Join Message
+ t = tr("%DN%1%DN %DH(%2@%3)%DH has joined %DC%4%DC").arg(nick, user, host, bufferName); break;
+ case Message::Part:
+ //: Part Message
+ t = tr("%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:
+ //: Quit Message
+ t = tr("%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);
+ //: Kick Message
+ t = tr("%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::Kill: FIXME
+
+ case Message::Server:
+ //: Server Message
+ t = tr("%1").arg(txt); break;
+ case Message::Info:
+ //: Info Message
+ t = tr("%1").arg(txt); break;
+ case Message::Error:
+ //: Error Message
+ t = tr("%1").arg(txt); break;
+ case Message::DayChange:
+ //: Day Change Message
+ t = tr("{Day changed to %1}").arg(timestamp().toString());
+ break;
+ default:
+ t = tr("[%1]").arg(txt);
+ }
+ _contents = UiStyle::styleString(t, UiStyle::formatType(type()));
+}
+
+const QString &UiStyle::StyledMessage::plainContents() const {
+ if(_contents.plainText.isNull())
+ style();
+
+ return _contents.plainText;
+}
+
+const UiStyle::FormatList &UiStyle::StyledMessage::contentsFormatList() const {
+ if(_contents.plainText.isNull())
+ style();
+
+ return _contents.formatList;
+}
+
+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();