← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2866: Show chat logs with a dim text color

 

------------------------------------------------------------
revno: 2866
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2012-02-12 16:34:48 +0100
message:
  Show chat logs with a dim text color
modified:
  changelog.txt
  win32/AspectChat.h
  win32/HtmlToRtf.cpp
  win32/HubFrame.cpp
  win32/PrivateFrame.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2012-02-12 14:20:18 +0000
+++ changelog.txt	2012-02-12 15:34:48 +0000
@@ -19,6 +19,7 @@
 * Fix favorite hub groups on Win XP (poy)
 * [L#925659] Safer window cleanup (poy)
 * [L#923612] Show the last chat line in taskbar previews (poy)
+* Show chat logs with a dim text color (poy)
 
 -- 0.791 2012-01-14 --
 * Update translations

=== modified file 'win32/AspectChat.h'
--- win32/AspectChat.h	2012-02-07 19:10:02 +0000
+++ win32/AspectChat.h	2012-02-12 15:34:48 +0000
@@ -21,6 +21,7 @@
 
 #include <dcpp/ChatMessage.h>
 #include <dcpp/File.h>
+#include <dcpp/SimpleXML.h>
 
 #include <dwt/WidgetCreator.h>
 
@@ -73,30 +74,34 @@
 
 	/// add a chat message and call addedChat.
 	void addChat(const tstring& message) {
-		addChat_(dwt::RichTextBox::rtfEscape(message));
+		addChatRTF(dwt::RichTextBox::rtfEscape(message));
 		t().addedChat(message);
 	}
 
 	/// add a ChatMessage and call addedChat.
 	void addChat(const ChatMessage& message) {
-		addChat_(HtmlToRtf::convert(message.htmlMessage, chat));
+		addChatHTML(message.htmlMessage);
 		t().addedChat(Text::toT(message.message));
 	}
 
 	/// just add to the chat; don't call addedChat.
-	void addChatRaw(const tstring& message) {
-		addChat_(dwt::RichTextBox::rtfEscape(message));
+	void addChatPlain(const tstring& message) {
+		addChatRTF(dwt::RichTextBox::rtfEscape(message));
 	}
 
-private:
-	/// @internal @param message RTF-formatted message.
-	void addChat_(tstring message) {
+	/// add an RTF-formatted message.
+	void addChatRTF(tstring message) {
 		/// @todo factor out to dwt
 		if(chat->length() > 0)
 			message = _T("\\line\n") + message;
 		chat->addTextSteady(_T("{\\urtf1\n") + message + _T("}\n"));
 	}
 
+	/// add an HTML-formatted message.
+	void addChatHTML(const string& message) {
+		addChatRTF(HtmlToRtf::convert(message, chat));
+	}
+
 protected:
 	void readLog(const string& logPath, const unsigned setting) {
 		if(setting == 0)
@@ -121,9 +126,23 @@
 		// the last line in the log file is an empty line; remove it
 		lines.pop_back();
 
+		string html;
+		string tmp;
+
 		const size_t linesCount = lines.size();
 		for(size_t i = (linesCount > setting) ? (linesCount - setting) : 0; i < linesCount; ++i) {
-			addChatRaw(_T("- ") + Text::toT(lines[i]));
+			html += SimpleXML::escape(lines[i], tmp, false) + "<br/>";
+		}
+
+		if(!html.empty()) {
+			// more grey text color
+			auto hls = RGB2HLS(chat->getTextColor());
+			auto color = HLS2RGB(HLS(HLS_H(hls), 127, HLS_S(hls) / 2));
+
+			tmp.resize(8);
+			snprintf(&tmp[0], tmp.size(), "%.2X%.2X%.2X", GetRValue(color), GetGValue(color), GetBValue(color));
+
+			addChatHTML("<span style=\"white-space: pre-wrap; color: #" + tmp + ";\">" + html + "</span>");
 		}
 	}
 

=== modified file 'win32/HtmlToRtf.cpp'
--- win32/HtmlToRtf.cpp	2012-02-04 17:18:19 +0000
+++ win32/HtmlToRtf.cpp	2012-02-12 15:34:48 +0000
@@ -21,6 +21,8 @@
 #include "stdafx.h"
 #include "HtmlToRtf.h"
 
+#include <boost/algorithm/string/trim.hpp>
+
 #include <dcpp/debug.h>
 #include <dcpp/Flags.h>
 #include <dcpp/ScopedFunctor.h>
@@ -79,7 +81,9 @@
 	write(contexts.back());
 }
 
-void Parser::startTag(const string& name, StringPairList& attribs, bool simple) {
+void Parser::startTag(const string& name_, StringPairList& attribs, bool simple) {
+	auto name = boost::algorithm::trim_copy(name_);
+
 	if(name == "br") {
 		ret += _T("\\line\n");
 	}
@@ -113,6 +117,8 @@
 		tmp = style.substr(i, j - i);
 		i = j + 1;
 
+		boost::algorithm::trim(tmp);
+
 		switch(state) {
 		case Declaration:
 			{

=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp	2012-02-07 19:10:02 +0000
+++ win32/HubFrame.cpp	2012-02-12 15:34:48 +0000
@@ -542,7 +542,7 @@
 
 	if(legitimate) {
 		if(BOOLSETTING(STATUS_IN_CHAT)) {
-			addChatRaw(_T("*** ") + message);
+			addChatPlain(_T("*** ") + message);
 			addedChat(text); // addedChat expects a message with no timestamp
 		} else
 			setDirty(SettingsManager::BOLD_HUB);

=== modified file 'win32/PrivateFrame.cpp'
--- win32/PrivateFrame.cpp	2012-02-07 19:25:58 +0000
+++ win32/PrivateFrame.cpp	2012-02-12 15:34:48 +0000
@@ -64,7 +64,7 @@
 	if(i == frames.end()) {
 		// creating a new window
 
-		if(frames.size() >= SETTING(MAX_PM_WINDOWS)) {
+		if(static_cast<int>(frames.size()) >= SETTING(MAX_PM_WINDOWS)) {
 			return false;
 		}
 
@@ -214,7 +214,7 @@
 	status->setText(STATUS_STATUS, message);
 
 	if(BOOLSETTING(STATUS_IN_CHAT)) {
-		addChatRaw(_T("*** ") + message);
+		addChatPlain(_T("*** ") + message);
 		addedChat(text); // addedChat expects a message with no timestamp
 	}
 }