/***************************************************************************
- * Copyright (C) 2005-09 by the Quassel Project *
+ * Copyright (C) 2005-2014 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+
#include <QApplication>
#include "buffersettings.h"
UiStyle::StyledString UiStyle::styleString(const QString &s_, quint32 baseFormat)
{
QString s = s_;
+ StyledString result;
+ result.formatList.append(qMakePair((quint16)0, baseFormat));
+
if (s.length() > 65535) {
+ // We use quint16 for indexes
qWarning() << QString("String too long to be styled: %1").arg(s);
- return StyledString();
+ result.plainText = s;
+ return result;
}
- StyledString result;
- result.formatList.append(qMakePair((quint16)0, baseFormat));
+
quint32 curfmt = baseFormat;
int pos = 0; quint16 length = 0;
for (;;) {
QString UiStyle::mircToInternal(const QString &mirc_)
{
- QString mirc = mirc_;
- mirc.replace('%', "%%"); // escape % just to be sure
- mirc.replace('\t', " "); // tabs break layout, also this is italics in Konversation
- mirc.replace('\x02', "%B");
- mirc.replace('\x0f', "%O");
- mirc.replace('\x12', "%R");
- mirc.replace('\x16', "%R");
- mirc.replace('\x1d', "%S");
- mirc.replace('\x1f', "%U");
+ QString mirc;
+ mirc.reserve(mirc_.size());
+ foreach (const QChar &c, mirc_) {
+ if ((c < '\x20' || c == '\x7f') && c != '\x03') {
+ switch (c.unicode()) {
+ case '\x02':
+ mirc += "%B";
+ break;
+ case '\x0f':
+ mirc += "%O";
+ break;
+ case '\x09':
+ mirc += " ";
+ break;
+ case '\x12':
+ case '\x16':
+ mirc += "%R";
+ break;
+ case '\x1d':
+ mirc += "%S";
+ break;
+ case '\x1f':
+ mirc += "%U";
+ break;
+ case '\x7f':
+ mirc += QChar(0x2421);
+ break;
+ default:
+ mirc += QChar(0x2400 + c.unicode());
+ }
+ } else {
+ if (c == '%')
+ mirc += c;
+ mirc += c;
+ }
+ }
// Now we bring the color codes (\x03) in a sane format that can be parsed more easily later.
// %Dcfxx is foreground, %Dcbxx is background color, where xx is a 2 digit dec number denoting the color code.
QString t;
switch (type()) {
case Message::Plain:
- //: Plain Message
- t = tr("%1").arg(txt); break;
+ t = QString("%1").arg(txt); break;
case Message::Notice:
- //: Notice Message
- t = tr("%1").arg(txt); break;
+ t = QString("%1").arg(txt); break;
case Message::Action:
- //: Action Message
- t = tr("%DN%1%DN %2").arg(nick).arg(txt);
+ t = QString("%DN%1%DN %2").arg(nick).arg(txt);
break;
case Message::Nick:
//: Nick Message
//case Message::Kill: FIXME
case Message::Server:
- //: Server Message
- t = tr("%1").arg(txt); break;
+ t = QString("%1").arg(txt); break;
case Message::Info:
- //: Info Message
- t = tr("%1").arg(txt); break;
+ t = QString("%1").arg(txt); break;
case Message::Error:
- //: Error Message
- t = tr("%1").arg(txt); break;
+ t = QString("%1").arg(txt); break;
case Message::DayChange:
+ {
//: Day Change Message
- t = tr("{Day changed to %1}").arg(timestamp().toString());
+ t = tr("{Day changed to %1}").arg(timestamp().date().toString(Qt::DefaultLocaleLongDate));
+ }
break;
case Message::Topic:
- //: Topic Message
- t = tr("%1").arg(txt); break;
+ t = QString("%1").arg(txt); break;
case Message::NetsplitJoin:
{
QStringList users = txt.split("#:#");
}
break;
case Message::Invite:
- //: Invite Message
- t = tr("%1").arg(txt); break;
+ t = QString("%1").arg(txt); break;
default:
- t = tr("[%1]").arg(txt);
+ t = QString("[%1]").arg(txt);
}
_contents = UiStyle::styleString(t, UiStyle::formatType(type()));
}
{
switch (type()) {
case Message::Plain:
- return tr("<%1>").arg(plainSender()); break;
+ return QString("<%1>").arg(plainSender()); break;
case Message::Notice:
- return tr("[%1]").arg(plainSender()); break;
+ return QString("[%1]").arg(plainSender()); break;
case Message::Action:
return "-*-"; break;
case Message::Nick:
if (chopCount < nick.size())
nick.chop(chopCount);
}
- quint16 hash = qChecksum(nick.toAscii().data(), nick.toAscii().size());
+ quint16 hash = qChecksum(nick.toLatin1().data(), nick.toLatin1().size());
return (_senderHash = (hash & 0xf) + 1);
}