/***************************************************************************
- * Copyright (C) 2005-07 by the Quassel IRC Development Team *
+ * Copyright (C) 2005-07 by the Quassel IRC Team *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
+ * (at your option) version 3. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
Message::Message(BufferInfo __buffer, Type __type, QString __text, QString __sender, quint8 __flags)
: _buffer(__buffer), _text(__text), _sender(__sender), _type(__type), _flags(__flags) {
- _timeStamp = QDateTime::currentDateTime().toUTC();
+ _timestamp = QDateTime::currentDateTime().toUTC();
}
Message::Message(QDateTime __ts, BufferInfo __buffer, Type __type, QString __text, QString __sender, quint8 __flags)
- : _timeStamp(__ts), _buffer(__buffer), _text(__text), _sender(__sender), _type(__type), _flags(__flags) {
+ : _timestamp(__ts), _buffer(__buffer), _text(__text), _sender(__sender), _type(__type), _flags(__flags) {
}
return _flags;
}
-QDateTime Message::timeStamp() const {
- return _timeStamp;
+QDateTime Message::timestamp() const {
+ return _timestamp;
}
QString Message::mircToInternal(QString mirc) {
mirc.replace('%', "%%"); // escape % just to be sure
mirc.replace('\x02', "%B");
- mirc.replace('\x03', "%C");
mirc.replace('\x0f', "%O");
mirc.replace('\x12', "%R");
mirc.replace('\x16', "%R");
mirc.replace('\x1d', "%S");
mirc.replace('\x1f', "%U");
+
+ // 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.
+ // %Dc- turns color off.
+ // Note: We use the "mirc standard" as described in <http://www.mirc.co.uk/help/color.txt>.
+ // This means that we don't accept something like \x03,5 (even though others, like WeeChat, do).
+ int pos = 0;
+ for(;;) {
+ pos = mirc.indexOf('\x03', pos);
+ if(pos < 0) break; // no more mirc color codes
+ QString ins, num;
+ int l = mirc.length();
+ int i = pos + 1;
+ // check for fg color
+ if(i < l && mirc[i].isDigit()) {
+ num = mirc[i++];
+ if(i < l && mirc[i].isDigit()) num.append(mirc[i++]);
+ else num.prepend('0');
+ ins = QString("%Dcf%1").arg(num);
+
+ if(i+1 < l && mirc[i] == ',' && mirc[i+1].isDigit()) {
+ i++;
+ num = mirc[i++];
+ if(i < l && mirc[i].isDigit()) num.append(mirc[i++]);
+ else num.prepend('0');
+ ins += QString("%Dcb%1").arg(num);
+ }
+ } else {
+ ins = "%Dc-";
+ }
+ mirc.replace(pos, i-pos, ins);
+ }
return mirc;
}
QString networkName = buffer().network();
QString bufferName = buffer().buffer();
- _formattedTimeStamp = tr("%DT[%1]").arg(timeStamp().toLocalTime().toString("hh:mm:ss"));
+ _formattedTimestamp = tr("%DT[%1]").arg(timestamp().toLocalTime().toString("hh:mm:ss"));
QString s, t;
switch(type()) {
_formattedText = t;
}
-QString Message::formattedTimeStamp() {
+QString Message::formattedTimestamp() {
format();
- return _formattedTimeStamp;
+ return _formattedTimestamp;
}
QString Message::formattedSender() {
*/
QDataStream &operator<<(QDataStream &out, const Message &msg) {
- out << (quint32)msg.timeStamp().toTime_t() << (quint8)msg.type() << (quint8)msg.flags()
+ out << (quint32)msg.timestamp().toTime_t() << (quint8)msg.type() << (quint8)msg.flags()
<< msg.buffer() << msg.sender().toUtf8() << msg.text().toUtf8();
return out;
}
msg._type = (Message::Type)t;
msg._flags = (quint8)f;
msg._buffer = buf;
- msg._timeStamp = QDateTime::fromTime_t(ts);
+ msg._timestamp = QDateTime::fromTime_t(ts);
msg._sender = QString::fromUtf8(s);
msg._text = QString::fromUtf8(m);
return in;