linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05441
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2879: customizable link & log colors
------------------------------------------------------------
revno: 2879
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2012-03-11 19:06:18 +0100
message:
customizable link & log colors
modified:
dcpp/ChatMessage.cpp
dcpp/SettingsManager.cpp
dcpp/SettingsManager.h
dcpp/Util.cpp
dcpp/Util.h
dwt/src/widgets/RichTextBox.cpp
help/settings_styles.html
win32/AspectChat.h
win32/HtmlToRtf.cpp
win32/HubFrame.cpp
win32/StylesPage.cpp
win32/StylesPage.h
win32/WinUtil.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 'dcpp/ChatMessage.cpp'
--- dcpp/ChatMessage.cpp 2012-02-09 19:42:43 +0000
+++ dcpp/ChatMessage.cpp 2012-03-11 18:06:18 +0000
@@ -24,46 +24,10 @@
#include "OnlineUser.h"
#include "SettingsManager.h"
#include "SimpleXML.h"
-#include "StringTokenizer.h"
#include "Util.h"
namespace dcpp {
-namespace {
-
-// helpers that convert style settings to CSS declarations (implementation dependant).
-
-string cssColor(int color) {
-#ifdef _WIN32
- // assume it's a COLORREF.
- char buf[8];
- snprintf(buf, sizeof(buf), "%.2X%.2X%.2X", GetRValue(color), GetGValue(color), GetBValue(color));
- return buf;
-#else
- ///@todo
- return string();
-#endif
-}
-
-string cssFont(const string& font) {
-#ifdef _WIN32
- StringTokenizer<string> st(font, ',');
- auto& l = st.getTokens();
- if(l.size() >= 4) {
- std::stringstream stream;
- stream << (Util::toInt(l[3]) ? "italic" : "normal") << " " << l[2] << " " <<
- abs(Util::toFloat(l[1])) << "px '" << l[0] << "'";
- return stream.str();
- }
- return string();
-#else
- ///@todo
- return string();
-#endif
-}
-
-} // unnamed namespace
-
ChatMessage::ChatMessage(const string& text, const OnlineUser* from,
const OnlineUser* to, const OnlineUser* replyTo,
bool thirdPerson, time_t messageTimestamp) :
@@ -108,9 +72,9 @@
auto style = from->getIdentity().getStyle();
string styleAttr;
- if(!style.font.empty()) { styleAttr += "font: " + cssFont(style.font) + ";"; }
- if(style.textColor != -1) { styleAttr += "color: #" + cssColor(style.textColor) + ";"; }
- if(style.bgColor != -1) { styleAttr += "background-color: #" + cssColor(style.bgColor) + ";"; }
+ if(!style.font.empty()) { styleAttr += "font: " + Util::cssFont(style.font) + ";"; }
+ if(style.textColor != -1) { styleAttr += "color: #" + Util::cssColor(style.textColor) + ";"; }
+ if(style.bgColor != -1) { styleAttr += "background-color: #" + Util::cssColor(style.bgColor) + ";"; }
htmlMessage += addSpan("nick", tmp, styleAttr) + " ";
// Check all '<' and '[' after newlines as they're probably pastes...
=== modified file 'dcpp/SettingsManager.cpp'
--- dcpp/SettingsManager.cpp 2012-03-03 19:33:45 +0000
+++ dcpp/SettingsManager.cpp 2012-03-11 18:06:18 +0000
@@ -56,6 +56,7 @@
// Ints
"IncomingConnections", "InPort", "Slots", "AutoFollow", "ClearSearch",
"TextColor", "BackgroundColor", "UploadTextColor", "UploadBgColor", "DownloadTextColor", "DownloadBgColor",
+ "LinkColor", "LogColor",
"ShareHidden", "FilterMessages", "MinimizeToTray", "AlwaysTray",
"AutoSearch", "TimeStamps", "PopupHubPms", "PopupBotPms", "IgnoreHubPms", "IgnoreBotPms",
"ListDuplicates", "BufferSize", "DownloadSlots", "MaxDownloadSpeed", "LogMainChat", "LogPrivateChat",
=== modified file 'dcpp/SettingsManager.h'
--- dcpp/SettingsManager.h 2012-02-12 15:41:21 +0000
+++ dcpp/SettingsManager.h 2012-03-11 18:06:18 +0000
@@ -74,6 +74,7 @@
enum IntSetting { INT_FIRST = STR_LAST + 1,
INCOMING_CONNECTIONS = INT_FIRST, TCP_PORT, SLOTS, AUTO_FOLLOW, CLEAR_SEARCH,
TEXT_COLOR, BACKGROUND_COLOR, UPLOAD_TEXT_COLOR, UPLOAD_BG_COLOR, DOWNLOAD_TEXT_COLOR, DOWNLOAD_BG_COLOR,
+ LINK_COLOR, LOG_COLOR,
SHARE_HIDDEN, FILTER_MESSAGES, MINIMIZE_TRAY, ALWAYS_TRAY,
AUTO_SEARCH, TIME_STAMPS, POPUP_HUB_PMS, POPUP_BOT_PMS, IGNORE_HUB_PMS, IGNORE_BOT_PMS,
LIST_DUPES, BUFFER_SIZE, DOWNLOAD_SLOTS, MAX_DOWNLOAD_SPEED, LOG_MAIN_CHAT, LOG_PRIVATE_CHAT,
=== modified file 'dcpp/Util.cpp'
--- dcpp/Util.cpp 2012-03-03 19:33:45 +0000
+++ dcpp/Util.cpp 2012-03-11 18:06:18 +0000
@@ -34,6 +34,7 @@
#include "LogManager.h"
#include "SettingsManager.h"
#include "SimpleXML.h"
+#include "StringTokenizer.h"
#include "version.h"
#ifndef _WIN32
@@ -755,6 +756,35 @@
return (a >= end) ? 0 : ((int)Text::toLower(ca) - (int)Text::toLower(cb));
}
+string Util::cssColor(int color) {
+#ifdef _WIN32
+ // assume it's a COLORREF.
+ char buf[8];
+ snprintf(buf, sizeof(buf), "%.2X%.2X%.2X", GetRValue(color), GetGValue(color), GetBValue(color));
+ return buf;
+#else
+ ///@todo
+ return string();
+#endif
+}
+
+string Util::cssFont(const string& font) {
+#ifdef _WIN32
+ StringTokenizer<string> st(font, ',');
+ auto& l = st.getTokens();
+ if(l.size() >= 4) {
+ std::stringstream stream;
+ stream << (Util::toInt(l[3]) ? "italic" : "normal") << " " << l[2] << " " <<
+ abs(Util::toFloat(l[1])) << "px '" << l[0] << "'";
+ return stream.str();
+ }
+ return string();
+#else
+ ///@todo
+ return string();
+#endif
+}
+
string Util::encodeURI(const string& aString, bool reverse) {
// reference: rfc2396
string tmp = aString;
=== modified file 'dcpp/Util.h'
--- dcpp/Util.h 2012-02-17 23:34:33 +0000
+++ dcpp/Util.h 2012-03-11 18:06:18 +0000
@@ -403,6 +403,11 @@
return t1;
}
+ /// make a color suitable for a CSS declaration (implementation dependant).
+ static string cssColor(int color);
+ /// make a font suitable for a CSS declaration (implementation dependant).
+ static string cssFont(const string& font);
+
static string encodeURI(const string& /*aString*/, bool reverse = false);
static string getLocalIp();
static bool isPrivateIp(string const& ip);
=== modified file 'dwt/src/widgets/RichTextBox.cpp'
--- dwt/src/widgets/RichTextBox.cpp 2012-03-11 16:34:55 +0000
+++ dwt/src/widgets/RichTextBox.cpp 2012-03-11 18:06:18 +0000
@@ -44,6 +44,9 @@
namespace dwt {
+#ifndef MSFTEDIT_CLASS /// @todo remove when MinGW has this
+#define MSFTEDIT_CLASS L"RICHEDIT50W"
+#endif
const TCHAR RichTextBox::windowClass[] = MSFTEDIT_CLASS;
RichTextBox::Seed::Seed() :
=== modified file 'help/settings_styles.html'
--- help/settings_styles.html 2012-01-20 22:57:52 +0000
+++ help/settings_styles.html 2012-03-11 18:06:18 +0000
@@ -31,6 +31,19 @@
The style used to paint download transfer bars. Default background color: RGB(55, 170, 85).
</p>
+ <h2>Chat</h2>
+ <h3>Links</h3>
+ <p cshelp="IDH_SETTINGS_STYLES_LINKS">
+ The style used to display clickable links in chat. A default value is generated when DC++ is
+ started, based on the global text color.
+ </p>
+ <h3>Logs</h3>
+ <p cshelp="IDH_SETTINGS_STYLES_LOGS">
+ The style used to display chat logs that show up in new chat windows, assuming there is a
+ relevant chat history to be found. A default value is generated when DC++ is started, based
+ on the global text color (DC++ tries to make it look more grey).
+ </p>
+
<h2>Users</h2>
<p cshelp="IDH_SETTINGS_STYLES_USER_MATCH">
The styles used to paint users that match user matching definitions.
=== modified file 'win32/AspectChat.h'
--- win32/AspectChat.h 2012-02-21 22:11:22 +0000
+++ win32/AspectChat.h 2012-03-11 18:06:18 +0000
@@ -134,14 +134,7 @@
}
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>");
+ addChatHTML("<span style=\"white-space: pre-wrap; color: #" + Util::cssColor(SETTING(LOG_COLOR)) + ";\">" + html + "</span>");
}
}
=== modified file 'win32/HtmlToRtf.cpp'
--- win32/HtmlToRtf.cpp 2012-03-11 16:34:55 +0000
+++ win32/HtmlToRtf.cpp 2012-03-11 18:06:18 +0000
@@ -22,7 +22,6 @@
#include "HtmlToRtf.h"
#include <boost/algorithm/string/trim.hpp>
-#include <boost/scoped_array.hpp>
#include <dcpp/debug.h>
#include <dcpp/Flags.h>
@@ -116,7 +115,6 @@
auto& context = contexts.back();
context.link = link;
context.setFlag(Context::Underlined);
- /// @todo custom color
}
}
=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp 2012-03-11 16:36:44 +0000
+++ win32/HubFrame.cpp 2012-03-11 18:06:18 +0000
@@ -903,7 +903,8 @@
string tmp;
addStatus(msgT, false);
/// @todo change to "javascript: external.redirect" when switching to an HTML control
- addChatHTML("<span>*** </span><a href=\"redirect: " + SimpleXML::escape(line, tmp, true) + "\">" +
+ addChatHTML("<span>*** </span><a href=\"redirect: " + SimpleXML::escape(line, tmp, true) +
+ "\" style=\"color: #" + Util::cssColor(SETTING(LINK_COLOR)) + ";\">" +
SimpleXML::escape(msg, tmp, false) + "</a>");
addedChat(_T("*** ") + msgT);
}
=== modified file 'win32/StylesPage.cpp'
--- win32/StylesPage.cpp 2012-03-03 19:33:45 +0000
+++ win32/StylesPage.cpp 2012-03-11 18:06:18 +0000
@@ -145,6 +145,7 @@
TStringList groups(GROUP_LAST);
groups[GROUP_GENERAL] = T_("General");
groups[GROUP_TRANSFERS] = T_("Transfers");
+ groups[GROUP_CHAT] = T_("Chat");
groups[GROUP_USERS] = T_("Users");
table->setGroups(groups);
auto grouped = table->isGrouped();
@@ -163,6 +164,9 @@
add(T_("Downloads"), IDH_SETTINGS_STYLES_DOWNLOADS, GROUP_TRANSFERS,
SettingsManager::DOWNLOAD_FONT, SettingsManager::DOWNLOAD_TEXT_COLOR, SettingsManager::DOWNLOAD_BG_COLOR);
+ add(T_("Links"), IDH_SETTINGS_STYLES_LINKS, GROUP_CHAT, -1, SettingsManager::LINK_COLOR, -1);
+ add(T_("Logs"), IDH_SETTINGS_STYLES_LOGS, GROUP_CHAT, -1, SettingsManager::LOG_COLOR, -1);
+
update(globalData);
handleSelectionChanged();
@@ -204,6 +208,7 @@
}
StylesPage::Data::Data(tstring&& text, const unsigned helpId) :
+Flags(),
text(forward<tstring>(text)),
helpId(helpId)
{
@@ -245,15 +250,30 @@
textColorSetting(textColorSetting),
bgColorSetting(bgColorSetting)
{
- customFont = !SettingsManager::getInstance()->isDefault(static_cast<SettingsManager::StrSetting>(fontSetting));
- makeFont(font, SettingsManager::getInstance()->get(static_cast<SettingsManager::StrSetting>(fontSetting)));
- makeFont(defaultFont, SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::StrSetting>(fontSetting)));
-
- customTextColor = !SettingsManager::getInstance()->isDefault(static_cast<SettingsManager::IntSetting>(textColorSetting));
- textColor = SettingsManager::getInstance()->get(static_cast<SettingsManager::IntSetting>(textColorSetting));
-
- customBgColor = !SettingsManager::getInstance()->isDefault(static_cast<SettingsManager::IntSetting>(bgColorSetting));
- bgColor = SettingsManager::getInstance()->get(static_cast<SettingsManager::IntSetting>(bgColorSetting));
+ if(fontSetting != -1) {
+ setFlag(FONT_CHANGEABLE);
+ customFont = !SettingsManager::getInstance()->isDefault(static_cast<SettingsManager::StrSetting>(fontSetting));
+ makeFont(font, SettingsManager::getInstance()->get(static_cast<SettingsManager::StrSetting>(fontSetting)));
+ makeFont(defaultFont, SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::StrSetting>(fontSetting)));
+ } else {
+ customFont = false;
+ }
+
+ if(textColorSetting != -1) {
+ setFlag(TEXT_COLOR_CHANGEABLE);
+ customTextColor = !SettingsManager::getInstance()->isDefault(static_cast<SettingsManager::IntSetting>(textColorSetting));
+ textColor = SettingsManager::getInstance()->get(static_cast<SettingsManager::IntSetting>(textColorSetting));
+ } else {
+ customTextColor = false;
+ }
+
+ if(bgColorSetting != -1) {
+ setFlag(BG_COLOR_CHANGEABLE);
+ customBgColor = !SettingsManager::getInstance()->isDefault(static_cast<SettingsManager::IntSetting>(bgColorSetting));
+ bgColor = SettingsManager::getInstance()->get(static_cast<SettingsManager::IntSetting>(bgColorSetting));
+ } else {
+ customBgColor = false;
+ }
}
const StylesPage::Data::Font& StylesPage::SettingsData::getFont() const {
@@ -261,30 +281,40 @@
}
int StylesPage::SettingsData::getTextColor() const {
- return customTextColor ? textColor : SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::IntSetting>(textColorSetting));
+ return customTextColor ? textColor :
+ (textColorSetting != -1) ? SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::IntSetting>(textColorSetting)) :
+ -1;
}
int StylesPage::SettingsData::getBgColor() const {
- return customBgColor ? bgColor : SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::IntSetting>(bgColorSetting));
+ return customBgColor ? bgColor :
+ (bgColorSetting != -1) ? SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::IntSetting>(bgColorSetting)) :
+ -1;
}
void StylesPage::SettingsData::write() {
- if(customFont) {
- SettingsManager::getInstance()->set(static_cast<SettingsManager::StrSetting>(fontSetting), Text::fromT(WinUtil::encodeFont(font.second)));
- } else {
- SettingsManager::getInstance()->unset(static_cast<SettingsManager::StrSetting>(fontSetting));
- }
-
- if(customTextColor) {
- SettingsManager::getInstance()->set(static_cast<SettingsManager::IntSetting>(textColorSetting), textColor);
- } else {
- SettingsManager::getInstance()->unset(static_cast<SettingsManager::IntSetting>(textColorSetting));
- }
-
- if(customBgColor) {
- SettingsManager::getInstance()->set(static_cast<SettingsManager::IntSetting>(bgColorSetting), bgColor);
- } else {
- SettingsManager::getInstance()->unset(static_cast<SettingsManager::IntSetting>(bgColorSetting));
+ if(fontSetting != -1) {
+ if(customFont) {
+ SettingsManager::getInstance()->set(static_cast<SettingsManager::StrSetting>(fontSetting), Text::fromT(WinUtil::encodeFont(font.second)));
+ } else {
+ SettingsManager::getInstance()->unset(static_cast<SettingsManager::StrSetting>(fontSetting));
+ }
+ }
+
+ if(textColorSetting != -1) {
+ if(customTextColor) {
+ SettingsManager::getInstance()->set(static_cast<SettingsManager::IntSetting>(textColorSetting), textColor);
+ } else {
+ SettingsManager::getInstance()->unset(static_cast<SettingsManager::IntSetting>(textColorSetting));
+ }
+ }
+
+ if(bgColorSetting != -1) {
+ if(customBgColor) {
+ SettingsManager::getInstance()->set(static_cast<SettingsManager::IntSetting>(bgColorSetting), bgColor);
+ } else {
+ SettingsManager::getInstance()->unset(static_cast<SettingsManager::IntSetting>(bgColorSetting));
+ }
}
}
@@ -292,12 +322,15 @@
Data(Text::toT(matcher.name), IDH_SETTINGS_STYLES_USER_MATCH),
matcher(matcher)
{
+ setFlag(FONT_CHANGEABLE);
customFont = !matcher.style.font.empty();
makeFont(font, matcher.style.font);
+ setFlag(TEXT_COLOR_CHANGEABLE);
customTextColor = matcher.style.textColor >= 0;
textColor = matcher.style.textColor;
+ setFlag(BG_COLOR_CHANGEABLE);
customBgColor = matcher.style.bgColor >= 0;
bgColor = matcher.style.bgColor;
}
@@ -335,17 +368,17 @@
enable = data && data->customFont;
customFont->setChecked(enable);
- customFont->setEnabled(data);
+ customFont->setEnabled(data && data->isSet(Data::FONT_CHANGEABLE));
font->setEnabled(enable);
enable = data && data->customTextColor;
customTextColor->setChecked(enable);
- customTextColor->setEnabled(data);
+ customTextColor->setEnabled(data && data->isSet(Data::TEXT_COLOR_CHANGEABLE));
textColor->setEnabled(enable);
enable = data && data->customBgColor;
customBgColor->setChecked(enable);
- customBgColor->setEnabled(data);
+ customBgColor->setEnabled(data && data->isSet(Data::BG_COLOR_CHANGEABLE));
bgColor->setEnabled(enable);
}
=== modified file 'win32/StylesPage.h'
--- win32/StylesPage.h 2012-01-19 20:18:37 +0000
+++ win32/StylesPage.h 2012-03-11 18:06:18 +0000
@@ -44,16 +44,19 @@
enum {
GROUP_GENERAL,
GROUP_TRANSFERS,
+ GROUP_CHAT,
GROUP_USERS,
GROUP_LAST
};
- class Data {
+ class Data : public Flags {
protected:
typedef pair<dwt::FontPtr, LOGFONT> Font;
public:
+ enum { FONT_CHANGEABLE = 1 << 0, TEXT_COLOR_CHANGEABLE = 1 << 1, BG_COLOR_CHANGEABLE = 1 << 2 };
+
Data(tstring&& text, const unsigned helpId);
virtual ~Data() { }
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2012-03-11 16:34:55 +0000
+++ win32/WinUtil.cpp 2012-03-11 18:06:18 +0000
@@ -159,6 +159,18 @@
initUserMatching();
+ {
+ // default link color: shift the hue, set lum & sat to middle values
+ auto hls = RGB2HLS(textColor);
+ SettingsManager::getInstance()->setDefault(SettingsManager::LINK_COLOR, HLS2RGB(HLS((HLS_H(hls) + 60) % 239, 120, 120)));
+ }
+
+ {
+ // default log color: more grey than the text color
+ auto hls = RGB2HLS(textColor);
+ SettingsManager::getInstance()->setDefault(SettingsManager::LOG_COLOR, HLS2RGB(HLS(HLS_H(hls), 120, HLS_S(hls) / 2)));
+ }
+
fileImages = dwt::ImageListPtr(new dwt::ImageList(dwt::Point(16, 16)));
// get the directory icon (DIR_ICON).