1 /***************************************************************************
2 * Copyright (C) 2005-2016 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include <QApplication>
24 #include "buffersettings.h"
25 #include "qssparser.h"
28 #include "uisettings.h"
31 QHash<QString, UiStyle::FormatType> UiStyle::_formatCodes;
32 QString UiStyle::_timestampFormatString; /// Timestamp format
33 bool UiStyle::_showSenderBrackets; /// If true, show brackets around sender names
35 UiStyle::UiStyle(QObject *parent)
37 _channelJoinedIcon(QIcon::fromTheme("irc-channel-joined", QIcon(":/icons/irc-channel-joined.png"))),
38 _channelPartedIcon(QIcon::fromTheme("irc-channel-parted", QIcon(":/icons/irc-channel-parted.png"))),
39 _userOfflineIcon(QIcon::fromTheme("im-user-offline", QIcon::fromTheme("user-offline", QIcon(":/icons/im-user-offline.png")))),
40 _userOnlineIcon(QIcon::fromTheme("im-user", QIcon::fromTheme("user-available", QIcon(":/icons/im-user.png")))), // im-user-* are non-standard oxygen extensions
41 _userAwayIcon(QIcon::fromTheme("im-user-away", QIcon::fromTheme("user-away", QIcon(":/icons/im-user-away.png")))),
42 _categoryOpIcon(QIcon::fromTheme("irc-operator")),
43 _categoryVoiceIcon(QIcon::fromTheme("irc-voice")),
44 _opIconLimit(UserCategoryItem::categoryFromModes("o")),
45 _voiceIconLimit(UserCategoryItem::categoryFromModes("v"))
47 // register FormatList if that hasn't happened yet
48 // FIXME I don't think this actually avoids double registration... then again... does it hurt?
49 if (QVariant::nameToType("UiStyle::FormatList") == QVariant::Invalid) {
50 qRegisterMetaType<FormatList>("UiStyle::FormatList");
51 qRegisterMetaTypeStreamOperators<FormatList>("UiStyle::FormatList");
52 Q_ASSERT(QVariant::nameToType("UiStyle::FormatList") != QVariant::Invalid);
55 _uiStylePalette = QVector<QBrush>(NumRoles, QBrush());
57 // Now initialize the mapping between FormatCodes and FormatTypes...
58 _formatCodes["%O"] = Base;
59 _formatCodes["%B"] = Bold;
60 _formatCodes["%S"] = Italic;
61 _formatCodes["%U"] = Underline;
62 _formatCodes["%R"] = Reverse;
64 _formatCodes["%DN"] = Nick;
65 _formatCodes["%DH"] = Hostmask;
66 _formatCodes["%DC"] = ChannelName;
67 _formatCodes["%DM"] = ModeFlags;
68 _formatCodes["%DU"] = Url;
70 // Initialize fallback defaults
71 // NOTE: If you change this, update qtui/chatviewsettings.h, too. More explanations available
73 setTimestampFormatString(" hh:mm:ss");
74 enableSenderBrackets(true);
76 // BufferView / NickView settings
78 _showBufferViewIcons = _showNickViewIcons = s.value("ShowItemViewIcons", true).toBool();
79 s.notify("ShowItemViewIcons", this, SLOT(showItemViewIconsChanged(QVariant)));
81 _allowMircColors = s.value("AllowMircColors", true).toBool();
82 s.notify("AllowMircColors", this, SLOT(allowMircColorsChanged(QVariant)));
90 qDeleteAll(_metricsCache);
94 void UiStyle::reload()
100 void UiStyle::loadStyleSheet()
102 qDeleteAll(_metricsCache);
103 _metricsCache.clear();
104 _formatCache.clear();
110 styleSheet += loadStyleSheet("file:///" + Quassel::findDataFilePath("stylesheets/default.qss"));
111 styleSheet += loadStyleSheet("file:///" + Quassel::configDirPath() + "settings.qss");
112 if (s.value("UseCustomStyleSheet", false).toBool()) {
113 QString customSheetPath(s.value("CustomStyleSheetPath").toString());
114 QString customSheet = loadStyleSheet("file:///" + customSheetPath, true);
115 if (customSheet.isEmpty()) {
116 // MIGRATION: changed default install path for data from /usr/share/apps to /usr/share
117 if (customSheetPath.startsWith("/usr/share/apps/quassel")) {
118 customSheetPath.replace(QRegExp("^/usr/share/apps"), "/usr/share");
119 customSheet = loadStyleSheet("file:///" + customSheetPath, true);
120 if (!customSheet.isEmpty()) {
121 s.setValue("CustomStyleSheetPath", customSheetPath);
122 qDebug() << "Custom stylesheet path migrated to" << customSheetPath;
126 styleSheet += customSheet;
128 styleSheet += loadStyleSheet("file:///" + Quassel::optionValue("qss"), true);
130 if (!styleSheet.isEmpty()) {
132 parser.processStyleSheet(styleSheet);
133 QApplication::setPalette(parser.palette());
135 _uiStylePalette = parser.uiStylePalette();
136 _formats = parser.formats();
137 _listItemFormats = parser.listItemFormats();
139 styleSheet = styleSheet.trimmed();
140 if (!styleSheet.isEmpty())
141 qApp->setStyleSheet(styleSheet); // pass the remaining sections to the application
148 QString UiStyle::loadStyleSheet(const QString &styleSheet, bool shouldExist)
150 QString ss = styleSheet;
151 if (ss.startsWith("file:///")) {
157 if (file.open(QFile::ReadOnly)) {
158 QTextStream stream(&file);
159 ss = stream.readAll();
164 qWarning() << "Could not open stylesheet file:" << file.fileName();
171 // FIXME The following should trigger a reload/refresh of the chat view.
172 void UiStyle::setTimestampFormatString(const QString &format)
174 if (_timestampFormatString != format) {
175 _timestampFormatString = format;
179 void UiStyle::enableSenderBrackets(bool enabled)
181 if (_showSenderBrackets != enabled) {
182 _showSenderBrackets = enabled;
187 void UiStyle::allowMircColorsChanged(const QVariant &v)
189 _allowMircColors = v.toBool();
194 /******** ItemView Styling *******/
196 void UiStyle::showItemViewIconsChanged(const QVariant &v)
198 _showBufferViewIcons = _showNickViewIcons = v.toBool();
202 QVariant UiStyle::bufferViewItemData(const QModelIndex &index, int role) const
204 BufferInfo::Type type = (BufferInfo::Type)index.data(NetworkModel::BufferTypeRole).toInt();
205 bool isActive = index.data(NetworkModel::ItemActiveRole).toBool();
207 if (role == Qt::DecorationRole) {
208 if (!_showBufferViewIcons)
212 case BufferInfo::ChannelBuffer:
214 return _channelJoinedIcon;
216 return _channelPartedIcon;
217 case BufferInfo::QueryBuffer:
219 return _userOfflineIcon;
220 if (index.data(NetworkModel::UserAwayRole).toBool())
221 return _userAwayIcon;
223 return _userOnlineIcon;
229 quint32 fmtType = BufferViewItem;
231 case BufferInfo::StatusBuffer:
232 fmtType |= NetworkItem;
234 case BufferInfo::ChannelBuffer:
235 fmtType |= ChannelBufferItem;
237 case BufferInfo::QueryBuffer:
238 fmtType |= QueryBufferItem;
244 QTextCharFormat fmt = _listItemFormats.value(BufferViewItem);
245 fmt.merge(_listItemFormats.value(fmtType));
247 BufferInfo::ActivityLevel activity = (BufferInfo::ActivityLevel)index.data(NetworkModel::BufferActivityRole).toInt();
248 if (activity & BufferInfo::Highlight) {
249 fmt.merge(_listItemFormats.value(BufferViewItem | HighlightedBuffer));
250 fmt.merge(_listItemFormats.value(fmtType | HighlightedBuffer));
252 else if (activity & BufferInfo::NewMessage) {
253 fmt.merge(_listItemFormats.value(BufferViewItem | UnreadBuffer));
254 fmt.merge(_listItemFormats.value(fmtType | UnreadBuffer));
256 else if (activity & BufferInfo::OtherActivity) {
257 fmt.merge(_listItemFormats.value(BufferViewItem | ActiveBuffer));
258 fmt.merge(_listItemFormats.value(fmtType | ActiveBuffer));
260 else if (!isActive) {
261 fmt.merge(_listItemFormats.value(BufferViewItem | InactiveBuffer));
262 fmt.merge(_listItemFormats.value(fmtType | InactiveBuffer));
264 else if (index.data(NetworkModel::UserAwayRole).toBool()) {
265 fmt.merge(_listItemFormats.value(BufferViewItem | UserAway));
266 fmt.merge(_listItemFormats.value(fmtType | UserAway));
269 return itemData(role, fmt);
273 QVariant UiStyle::nickViewItemData(const QModelIndex &index, int role) const
275 NetworkModel::ItemType type = (NetworkModel::ItemType)index.data(NetworkModel::ItemTypeRole).toInt();
277 if (role == Qt::DecorationRole) {
278 if (!_showNickViewIcons)
282 case NetworkModel::UserCategoryItemType:
284 int categoryId = index.data(TreeModel::SortRole).toInt();
285 if (categoryId <= _opIconLimit)
286 return _categoryOpIcon;
287 if (categoryId <= _voiceIconLimit)
288 return _categoryVoiceIcon;
289 return _userOnlineIcon;
291 case NetworkModel::IrcUserItemType:
292 if (index.data(NetworkModel::ItemActiveRole).toBool())
293 return _userOnlineIcon;
295 return _userAwayIcon;
301 QTextCharFormat fmt = _listItemFormats.value(NickViewItem);
304 case NetworkModel::IrcUserItemType:
305 fmt.merge(_listItemFormats.value(NickViewItem | IrcUserItem));
306 if (!index.data(NetworkModel::ItemActiveRole).toBool()) {
307 fmt.merge(_listItemFormats.value(NickViewItem | UserAway));
308 fmt.merge(_listItemFormats.value(NickViewItem | IrcUserItem | UserAway));
311 case NetworkModel::UserCategoryItemType:
312 fmt.merge(_listItemFormats.value(NickViewItem | UserCategoryItem));
318 return itemData(role, fmt);
322 QVariant UiStyle::itemData(int role, const QTextCharFormat &format) const
326 return format.font();
327 case Qt::ForegroundRole:
328 return format.property(QTextFormat::ForegroundBrush);
329 case Qt::BackgroundRole:
330 return format.property(QTextFormat::BackgroundBrush);
337 /******** Caching *******/
339 QTextCharFormat UiStyle::format(quint64 key) const
341 return _formats.value(key, QTextCharFormat());
345 QTextCharFormat UiStyle::cachedFormat(quint32 formatType, quint32 messageLabel) const
347 return _formatCache.value(formatType | ((quint64)messageLabel << 32), QTextCharFormat());
351 void UiStyle::setCachedFormat(const QTextCharFormat &format, quint32 formatType, quint32 messageLabel) const
353 _formatCache[formatType | ((quint64)messageLabel << 32)] = format;
357 QFontMetricsF *UiStyle::fontMetrics(quint32 ftype, quint32 label) const
359 // QFontMetricsF is not assignable, so we need to store pointers :/
360 quint64 key = ftype | ((quint64)label << 32);
362 if (_metricsCache.contains(key))
363 return _metricsCache.value(key);
365 return (_metricsCache[key] = new QFontMetricsF(format(ftype, label).font()));
369 /******** Generate formats ********/
371 // NOTE: This and the following functions are intimately tied to the values in FormatType. Don't change this
372 // until you _really_ know what you do!
373 QTextCharFormat UiStyle::format(quint32 ftype, quint32 label_) const
375 if (ftype == Invalid)
376 return QTextCharFormat();
378 quint64 label = (quint64)label_ << 32;
380 // check if we have exactly this format readily cached already
381 QTextCharFormat fmt = cachedFormat(ftype, label_);
382 if (fmt.properties().count())
385 mergeFormat(fmt, ftype, label & Q_UINT64_C(0xffff000000000000));
387 for (quint64 mask = Q_UINT64_C(0x0000000100000000); mask <= (quint64)Selected << 32; mask <<= 1) {
389 mergeFormat(fmt, ftype, mask | Q_UINT64_C(0xffff000000000000));
392 setCachedFormat(fmt, ftype, label_);
397 void UiStyle::mergeFormat(QTextCharFormat &fmt, quint32 ftype, quint64 label) const
399 mergeSubElementFormat(fmt, ftype & 0x00ff, label);
401 // TODO: allow combinations for mirc formats and colors (each), e.g. setting a special format for "bold and italic"
402 // or "foreground 01 and background 03"
403 if ((ftype & 0xfff00)) { // element format
404 for (quint32 mask = 0x00100; mask <= 0x40000; mask <<= 1) {
406 mergeSubElementFormat(fmt, ftype & (mask | 0xff), label);
411 // Now we handle color codes
412 // We assume that those can't be combined with subelement and message types.
413 if (_allowMircColors) {
414 if (ftype & 0x00400000)
415 mergeSubElementFormat(fmt, ftype & 0x0f400000, label); // foreground
416 if (ftype & 0x00800000)
417 mergeSubElementFormat(fmt, ftype & 0xf0800000, label); // background
418 if ((ftype & 0x00c00000) == 0x00c00000)
419 mergeSubElementFormat(fmt, ftype & 0xffc00000, label); // combination
424 mergeSubElementFormat(fmt, ftype & (Url | 0x000000ff), label);
428 // Merge a subelement format into an existing message format
429 void UiStyle::mergeSubElementFormat(QTextCharFormat &fmt, quint32 ftype, quint64 label) const
431 quint64 key = ftype | label;
432 fmt.merge(format(key & Q_UINT64_C(0x0000ffffffffff00))); // label + subelement
433 fmt.merge(format(key & Q_UINT64_C(0x0000ffffffffffff))); // label + subelement + msgtype
434 fmt.merge(format(key & Q_UINT64_C(0xffffffffffffff00))); // label + subelement + nickhash
435 fmt.merge(format(key & Q_UINT64_C(0xffffffffffffffff))); // label + subelement + nickhash + msgtype
439 UiStyle::FormatType UiStyle::formatType(Message::Type msgType)
444 case Message::Notice:
446 case Message::Action:
462 case Message::Server:
468 case Message::DayChange:
472 case Message::NetsplitJoin:
473 return NetsplitJoinMsg;
474 case Message::NetsplitQuit:
475 return NetsplitQuitMsg;
476 case Message::Invite:
479 //Q_ASSERT(false); // we need to handle all message types
480 qWarning() << Q_FUNC_INFO << "Unknown message type:" << msgType;
485 UiStyle::FormatType UiStyle::formatType(const QString &code)
487 if (_formatCodes.contains(code)) return _formatCodes.value(code);
492 QString UiStyle::formatCode(FormatType ftype)
494 return _formatCodes.key(ftype);
498 QList<QTextLayout::FormatRange> UiStyle::toTextLayoutList(const FormatList &formatList, int textLength, quint32 messageLabel) const
500 QList<QTextLayout::FormatRange> formatRanges;
501 QTextLayout::FormatRange range;
503 for (i = 0; i < formatList.count(); i++) {
504 range.format = format(formatList.at(i).second, messageLabel);
505 range.start = formatList.at(i).first;
506 if (i > 0) formatRanges.last().length = range.start - formatRanges.last().start;
507 formatRanges.append(range);
509 if (i > 0) formatRanges.last().length = textLength - formatRanges.last().start;
514 // This method expects a well-formatted string, there is no error checking!
515 // Since we create those ourselves, we should be pretty safe that nobody does something crappy here.
516 UiStyle::StyledString UiStyle::styleString(const QString &s_, quint32 baseFormat)
520 result.formatList.append(qMakePair((quint16)0, baseFormat));
522 if (s.length() > 65535) {
523 // We use quint16 for indexes
524 qWarning() << QString("String too long to be styled: %1").arg(s);
525 result.plainText = s;
529 quint32 curfmt = baseFormat;
530 int pos = 0; quint16 length = 0;
532 pos = s.indexOf('%', pos);
534 if (s[pos+1] == '%') { // escaped %, we just remove one and continue
539 if (s[pos+1] == 'D' && s[pos+2] == 'c') { // color code
540 if (s[pos+3] == '-') { // color off
541 curfmt &= 0x003fffff;
545 int color = 10 * s[pos+4].digitValue() + s[pos+5].digitValue();
546 //TODO: use 99 as transparent color (re mirc color "standard")
548 if (s[pos+3] == 'f') {
549 curfmt &= 0xf0ffffff;
550 curfmt |= (quint32)(color << 24) | 0x00400000;
553 curfmt &= 0x0fffffff;
554 curfmt |= (quint32)(color << 28) | 0x00800000;
559 else if (s[pos+1] == 'O') { // reset formatting
560 curfmt &= 0x000000ff; // we keep message type-specific formatting
563 else if (s[pos+1] == 'R') { // reverse
564 // TODO: implement reverse formatting
568 else { // all others are toggles
569 QString code = QString("%") + s[pos+1];
570 if (s[pos+1] == 'D') code += s[pos+2];
571 FormatType ftype = formatType(code);
572 if (ftype == Invalid) {
574 qWarning() << (QString("Invalid format code in string: %1").arg(s));
578 length = code.length();
580 s.remove(pos, length);
581 if (pos == result.formatList.last().first)
582 result.formatList.last().second = curfmt;
584 result.formatList.append(qMakePair((quint16)pos, curfmt));
586 result.plainText = s;
591 QString UiStyle::mircToInternal(const QString &mirc_)
594 mirc.reserve(mirc_.size());
595 foreach (const QChar &c, mirc_) {
596 if ((c < '\x20' || c == '\x7f') && c != '\x03') {
597 switch (c.unicode()) {
618 mirc += QChar(0x2421);
621 mirc += QChar(0x2400 + c.unicode());
630 // Now we bring the color codes (\x03) in a sane format that can be parsed more easily later.
631 // %Dcfxx is foreground, %Dcbxx is background color, where xx is a 2 digit dec number denoting the color code.
632 // %Dc- turns color off.
633 // Note: We use the "mirc standard" as described in <http://www.mirc.co.uk/help/color.txt>.
634 // This means that we don't accept something like \x03,5 (even though others, like WeeChat, do).
637 pos = mirc.indexOf('\x03', pos);
638 if (pos < 0) break; // no more mirc color codes
640 int l = mirc.length();
642 // check for fg color
643 if (i < l && mirc[i].isDigit()) {
645 if (i < l && mirc[i].isDigit()) num.append(mirc[i++]);
646 else num.prepend('0');
647 ins = QString("%Dcf%1").arg(num);
649 if (i+1 < l && mirc[i] == ',' && mirc[i+1].isDigit()) {
652 if (i < l && mirc[i].isDigit()) num.append(mirc[i++]);
653 else num.prepend('0');
654 ins += QString("%Dcb%1").arg(num);
660 mirc.replace(pos, i-pos, ins);
666 /***********************************************************************************/
667 UiStyle::StyledMessage::StyledMessage(const Message &msg)
670 if (type() == Message::Plain)
673 _senderHash = 0x00; // this means we never compute the hash for msgs that aren't plain
677 void UiStyle::StyledMessage::style() const
679 QString user = userFromMask(sender());
680 QString host = hostFromMask(sender());
681 QString nick = nickFromMask(sender());
682 QString txt = UiStyle::mircToInternal(contents());
683 QString bufferName = bufferInfo().bufferName();
684 bufferName.replace('%', "%%"); // well, you _can_ have a % in a buffername apparently... -_-
685 host.replace('%', "%%"); // hostnames too...
686 user.replace('%', "%%"); // and the username...
687 nick.replace('%', "%%"); // ... and then there's totally RFC-violating servers like justin.tv m(
688 const int maxNetsplitNicks = 15;
693 t = QString("%1").arg(txt); break;
694 case Message::Notice:
695 t = QString("%1").arg(txt); break;
696 case Message::Action:
697 t = QString("%DN%1%DN %2").arg(nick).arg(txt);
701 if (nick == contents()) t = tr("You are now known as %DN%1%DN").arg(txt);
702 else t = tr("%DN%1%DN is now known as %DN%2%DN").arg(nick, txt);
706 if (nick.isEmpty()) t = tr("User mode: %DM%1%DM").arg(txt);
707 else t = tr("Mode %DM%1%DM by %DN%2%DN").arg(txt, nick);
711 t = tr("%DN%1%DN %DH(%2@%3)%DH has joined %DC%4%DC").arg(nick, user, host, bufferName); break;
714 t = tr("%DN%1%DN %DH(%2@%3)%DH has left %DC%4%DC").arg(nick, user, host, bufferName);
715 if (!txt.isEmpty()) t = QString("%1 (%2)").arg(t).arg(txt);
719 t = tr("%DN%1%DN %DH(%2@%3)%DH has quit").arg(nick, user, host);
720 if (!txt.isEmpty()) t = QString("%1 (%2)").arg(t).arg(txt);
724 QString victim = txt.section(" ", 0, 0);
725 QString kickmsg = txt.section(" ", 1);
727 t = tr("%DN%1%DN has kicked %DN%2%DN from %DC%3%DC").arg(nick).arg(victim).arg(bufferName);
728 if (!kickmsg.isEmpty()) t = QString("%1 (%2)").arg(t).arg(kickmsg);
731 //case Message::Kill: FIXME
733 case Message::Server:
734 t = QString("%1").arg(txt); break;
736 t = QString("%1").arg(txt); break;
738 t = QString("%1").arg(txt); break;
739 case Message::DayChange:
741 //: Day Change Message
742 t = tr("{Day changed to %1}").arg(timestamp().date().toString(Qt::DefaultLocaleLongDate));
746 t = QString("%1").arg(txt); break;
747 case Message::NetsplitJoin:
749 QStringList users = txt.split("#:#");
750 QStringList servers = users.takeLast().split(" ");
752 for (int i = 0; i < users.count() && i < maxNetsplitNicks; i++)
753 users[i] = nickFromMask(users.at(i));
755 t = tr("Netsplit between %DH%1%DH and %DH%2%DH ended. Users joined: ").arg(servers.at(0), servers.at(1));
756 if (users.count() <= maxNetsplitNicks)
757 t.append(QString("%DN%1%DN").arg(users.join(", ")));
759 t.append(tr("%DN%1%DN (%2 more)").arg(static_cast<QStringList>(users.mid(0, maxNetsplitNicks)).join(", ")).arg(users.count() - maxNetsplitNicks));
762 case Message::NetsplitQuit:
764 QStringList users = txt.split("#:#");
765 QStringList servers = users.takeLast().split(" ");
767 for (int i = 0; i < users.count() && i < maxNetsplitNicks; i++)
768 users[i] = nickFromMask(users.at(i));
770 t = tr("Netsplit between %DH%1%DH and %DH%2%DH. Users quit: ").arg(servers.at(0), servers.at(1));
772 if (users.count() <= maxNetsplitNicks)
773 t.append(QString("%DN%1%DN").arg(users.join(", ")));
775 t.append(tr("%DN%1%DN (%2 more)").arg(static_cast<QStringList>(users.mid(0, maxNetsplitNicks)).join(", ")).arg(users.count() - maxNetsplitNicks));
778 case Message::Invite:
779 t = QString("%1").arg(txt); break;
781 t = QString("[%1]").arg(txt);
783 _contents = UiStyle::styleString(t, UiStyle::formatType(type()));
787 const QString &UiStyle::StyledMessage::plainContents() const
789 if (_contents.plainText.isNull())
792 return _contents.plainText;
796 const UiStyle::FormatList &UiStyle::StyledMessage::contentsFormatList() const
798 if (_contents.plainText.isNull())
801 return _contents.formatList;
805 QString UiStyle::StyledMessage::decoratedTimestamp() const
807 return timestamp().toLocalTime().toString(UiStyle::timestampFormatString());
811 QString UiStyle::StyledMessage::plainSender() const
815 case Message::Notice:
816 return nickFromMask(sender());
823 QString UiStyle::StyledMessage::decoratedSender() const
827 if (_showSenderBrackets)
828 return QString("<%1>").arg(plainSender());
830 return QString("%1").arg(plainSender());
832 case Message::Notice:
833 return QString("[%1]").arg(plainSender()); break;
834 case Message::Action:
850 case Message::Server:
856 case Message::DayChange:
860 case Message::NetsplitJoin:
862 case Message::NetsplitQuit:
864 case Message::Invite:
867 return QString("%1").arg(plainSender());
872 // FIXME hardcoded to 16 sender hashes
873 quint8 UiStyle::StyledMessage::senderHash() const
875 if (_senderHash != 0xff)
878 QString nick = nickFromMask(sender()).toLower();
879 if (!nick.isEmpty()) {
881 while (chopCount < nick.size() && nick.at(nick.count() - 1 - chopCount) == '_')
883 if (chopCount < nick.size())
884 nick.chop(chopCount);
886 quint16 hash = qChecksum(nick.toLatin1().data(), nick.toLatin1().size());
887 return (_senderHash = (hash & 0xf) + 1);
891 /***********************************************************************************/
893 QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList)
895 out << formatList.count();
896 UiStyle::FormatList::const_iterator it = formatList.begin();
897 while (it != formatList.end()) {
898 out << (*it).first << (*it).second;
905 QDataStream &operator>>(QDataStream &in, UiStyle::FormatList &formatList)
909 for (quint16 i = 0; i < cnt; i++) {
910 quint16 pos; quint32 ftype;
912 formatList.append(qMakePair((quint16)pos, ftype));