diff --git a/src/viewer/ircview.h b/src/viewer/ircview.h --- a/src/viewer/ircview.h +++ b/src/viewer/ircview.h @@ -287,8 +287,10 @@ QChar::Direction basicDirection(const QString &string); + bool dateRtlDirection(); + /// Returns a formated timestamp if timestamps are enabled else it returns QString::null - QString timeStamp(QHash messageTags); + QString timeStamp(QHash messageTags, bool rtl); /// Returns a formated nick string //! FIXME formatted in what way? diff --git a/src/viewer/ircview.cpp b/src/viewer/ircview.cpp --- a/src/viewer/ircview.cpp +++ b/src/viewer/ircview.cpp @@ -536,6 +536,10 @@ viewport()->setPalette(p); } +bool IRCView::dateRtlDirection() +{ + return QLocale().toString(QDate::currentDate(), QLocale::ShortFormat).isRightToLeft(); // Keep format synced with IRCView::timeStamp +} // Data insertion @@ -545,20 +549,29 @@ m_tabNotification = Konversation::tnfNormal; - QString nickLine = createNickLine(nick, channelColor); + QString nickLine = createNickLine(nick, channelColor); // _nick] QChar::Direction dir; QString text(filter(message, channelColor, nick, true, true, false, &dir)); QString line; bool rtl = (dir == QChar::DirR); - QChar directionOfLine = rtl ? RLM : LRM; - line = directionOfLine; + if (!rtl == dateRtlDirection()) // NOT Left-aligned + Arabic digit OR Right-aligned + Indic digit + line += (rtl ? RLM : LRM); if (!label.isEmpty()) { line += "[%4]"; } - line += "%1" + directionOfLine + nickLine + directionOfLine + " %3"; - line = line.arg(timeStamp(messageTags), nick, text); + line += "%1"; + if (rtl) line += LRM; // :[nick_ -> :[_nick] + line += nickLine; + if (rtl) + { + line += LRM; // :[_nick] -> :_nick] + if (!text.isRightToLeft()) + line += RLM; // ARABIC_TEXT _nick]: Hi -> ARABIC_TEXT Hi :_nick] + } + line += " %3"; + line = line.arg(timeStamp(messageTags, rtl), nick, text); if (!label.isEmpty()) { @@ -576,7 +589,7 @@ : Preferences::self()->color(Preferences::ServerMessage); m_tabNotification = Konversation::tnfNone; - QString line = QString(timeStamp(QHash()) + " " + message + ""); + QString line = QString(timeStamp(QHash(), false /*TODO*/) + " " + message + ""); doAppend(line, false, self); } @@ -597,16 +610,26 @@ m_tabNotification = Konversation::tnfPrivate; - QString nickLine = createNickLine(nick, queryColor, true, inChannel); + QString nickLine = createNickLine(nick, queryColor, true, inChannel); // _nick] QString line; QChar::Direction dir; QString text(filter(message, queryColor, nick, true, true, false, &dir)); bool rtl = (dir == QChar::DirR); - QChar directionOfLine = rtl ? RLM : LRM; - line = directionOfLine + "%1" + directionOfLine + nickLine + directionOfLine + " %3"; - line = line.arg(timeStamp(messageTags), nick, text); + if (!rtl == dateRtlDirection()) // NOT Left-aligned + Arabic digit OR Right-aligned + Indic digit + line += (rtl ? RLM : LRM); + line += "%1"; + if (rtl) line += LRM; // :[nick_ -> :[_nick] + line += nickLine; + if (rtl) + { + line += LRM; // :[_nick] -> :_nick] + if (!text.isRightToLeft()) + line += RLM; // ARABIC_TEXT _nick]: Hi -> ARABIC_TEXT Hi :_nick] + } + line += " %3"; + line = line.arg(timeStamp(messageTags, rtl), nick, text); if (inChannel) { emit textToLog(QString("<-> %1>\t%2").arg(nick, message)); @@ -635,13 +658,13 @@ QString line; - QString nickLine = createNickLine(nick, actionColor, false); + QString nickLine = createNickLine(nick, actionColor, false); // _nick] if (message.isEmpty()) { line = LRM + "%1 * " + nickLine + ""; - line = line.arg(timeStamp(messageTags), nick); + line = line.arg(timeStamp(messageTags, false /*TODO*/), nick); emit textToLog(QString("\t * %1").arg(nick)); @@ -653,9 +676,19 @@ QString text(filter(message, actionColor, nick, true,true, false, &dir)); bool rtl = (dir == QChar::DirR); - QChar directionOfLine = rtl ? RLM : LRM; - line = directionOfLine + "%1 " + directionOfLine + "* " + nickLine + directionOfLine + " %3"; - line = line.arg(timeStamp(messageTags), nick, text); + if (!rtl == dateRtlDirection()) // NOT Left-aligned + Arabic digit OR Right-aligned + Indic digit + line += (rtl ? RLM : LRM); + line += "%1 * "; + if (rtl) line += LRM; // *[nick_ -> *[_nick] + line += nickLine; + if (rtl) + { + line += LRM; // *[_nick] -> *_nick] + if (!text.isRightToLeft()) + line += RLM; // ARABIC_TEXT _nick]* Hi -> ARABIC_TEXT Hi *_nick] + } + line += " %3"; + line = line.arg(timeStamp(messageTags, rtl), nick, text); emit textToLog(QString("\t * %1 %2").arg(nick, message)); @@ -679,11 +712,15 @@ QString line; QChar::Direction dir; QString text(filter(message, serverColor, 0 , true, parseURL, false, &dir)); - bool rtl = (dir == QChar::DirR); + bool rtl = text.isRightToLeft(); // Server text may be translated strings. Treat with first strong, since it's not user input. - QChar directionOfLine = rtl ? RLM : LRM; - line = directionOfLine + "%1 " + directionOfLine + "[%2]" + directionOfLine + " %3"; - line = line.arg(timeStamp(messageTags), type, text); + if (!rtl == dateRtlDirection()) // NOT Left-aligned + Arabic digit OR Right-aligned + Indic digit + line += (rtl ? RLM : LRM); + line += "%1 [%2]"; + if (!rtl == type.isRightToLeft()) + line += (rtl ? RLM : LRM); // [50 [ARABIC_TEXT users -> [ARABIC_TEXT] 50 users + line += " %3"; + line = line.arg(timeStamp(messageTags, rtl), type, text); emit textToLog(QString("%1\t%2").arg(type, message)); @@ -711,11 +748,10 @@ QString line; QChar::Direction dir; QString text(filter(message, commandColor, 0, true, parseURL, self, &dir)); - bool rtl = text.isRightToLeft(); + bool rtl = text.isRightToLeft(); // Commands are translated and contain LTR IP addresses. Treat with first strong. - QChar directionOfLine = rtl ? RLM : LRM; - line = directionOfLine + "%1 %2 %3"; - line = line.arg(timeStamp(messageTags), prefix, text); + line = "%1 %2 %3"; + line = line.arg(timeStamp(messageTags, rtl), prefix, text); emit textToLog(QString("%1\t%2").arg(type, message)); @@ -739,10 +775,6 @@ { nick = '|' + nick + '|'; } - else //It's a real nick - { - nick = LRM + nick + LRM; - } // Nicks are in "" format so replace the "<>" nick.replace('<',"<"); @@ -753,8 +785,29 @@ QString text(filter(message, backlogColor, NULL, false, false, false, &dir)); bool rtl = nick.startsWith('|') ? text.isRightToLeft() : (dir == QChar::DirR); - QChar directionOfLine = rtl ? RLM : LRM; - line = directionOfLine + "%1 " + directionOfLine + "%2" + directionOfLine + " %3"; + if (!rtl == dateRtlDirection()) // NOT Left-aligned + Arabic digit OR Right-aligned + Indic digit + line += (rtl ? RLM : LRM); + else if (!time.isRightToLeft() == dateRtlDirection()) // Special case: viewing a file with LTR date while current digit is RTL (Chaning UI language) + line += (!time.isRightToLeft() ? RLM : LRM); + line += "%1 "; + if (nick.startsWith('|')) + { + line += "%2 %3"; + } + else // It's a nickname not mode-name + { + if (!time.isRightToLeft() == dateRtlDirection()) // Special case above + line += (!time.isRightToLeft() ? RLM : LRM); + if (rtl) line += LRM; // :[nick_ -> :[_nick] + line += "%2"; + if (rtl) + { + line += LRM; // :[_nick] -> :_nick] + if (!text.isRightToLeft()) + line += RLM; // ARABIC_TEXT _nick]: Hi -> ARABIC_TEXT Hi :_nick] + } + line += " %3"; + } line = line.arg(time, nick, text); doAppend(line, rtl); @@ -813,7 +866,7 @@ formatCursor.setBlockFormat(format); } -QString IRCView::timeStamp(QHash messageTags) +QString IRCView::timeStamp(QHash messageTags, bool rtl) { if(Preferences::self()->timestamping()) { @@ -827,8 +880,7 @@ QString timeFormat = Preferences::self()->timestampFormat(); QString timeString; - bool rtlLocale = (QLocale().zeroDigit() == QChar((ushort)0x0660)) || // ARABIC-INDIC DIGIT ZERO - (QLocale().zeroDigit() == QChar((ushort)0x06F0)); // EXTENDED ARABIC-INDIC DIGIT ZERO + bool dateRtl = dateRtlDirection(); if(!Preferences::self()->showDate()) { @@ -839,10 +891,10 @@ QDate date = serverTime.isValid() ? serverTime.date() : QDate::currentDate(); timeString = QString("[%1%2 %3%4] ") - .arg(rtlLocale ? RLM : LRM, - QLocale().toString(date, QLocale::ShortFormat), - time.toString(timeFormat), - !rtlLocale ? RLM : LRM); + .arg((dateRtl==rtl) ? QString() : (dateRtl ? RLM : LRM), + QLocale().toString(date, QLocale::ShortFormat), + time.toString(timeFormat), + (dateRtl==rtl) ? QString() : (!dateRtl ? RLM : LRM)); } return timeString; @@ -853,7 +905,7 @@ QString IRCView::createNickLine(const QString& nick, const QString& defaultColor, bool encapsulateNick, bool privMsg) { - QString nickLine = LRM + "%2" + LRM; + QString nickLine ="%2"; QString nickColor; if (Preferences::self()->useColoredNicks())