← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2827: Add predefined user matching defs for favs (bold, more red) & ops (more blue)

 

------------------------------------------------------------
revno: 2827
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2012-01-19 21:18:37 +0100
message:
  Add predefined user matching defs for favs (bold, more red) & ops (more blue)
added:
  dcpp/Style.h
modified:
  changelog.txt
  dcpp/UserMatch.h
  dcpp/UserMatchManager.cpp
  dwt/include/dwt/resources/Font.h
  dwt/src/Font.cpp
  dwt/src/widgets/Menu.cpp
  win32/StylesPage.cpp
  win32/StylesPage.h
  win32/UserMatchDlg.cpp
  win32/UserMatchPage.cpp
  win32/WinUtil.cpp
  win32/WinUtil.h


--
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-01-16 18:29:26 +0000
+++ changelog.txt	2012-01-19 20:18:37 +0000
@@ -12,6 +12,8 @@
 * Add a setting to enable away mode when Windows is locked (poy)
 * Make the away message optional (poy)
 * [L#704502] Away mode after some time of inactivity (poy)
+* Allow empty user matching definitions that match every user (poy)
+* Add predefined user matching defs for favs (bold, more red) & ops (more blue) (poy)
 
 -- 0.791 2012-01-14 --
 * Update translations

=== added file 'dcpp/Style.h'
--- dcpp/Style.h	1970-01-01 00:00:00 +0000
+++ dcpp/Style.h	2012-01-19 20:18:37 +0000
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ */
+
+#ifndef DCPLUSPLUS_DCPP_STYLE_H
+#define DCPLUSPLUS_DCPP_STYLE_H
+
+#include <string>
+
+namespace dcpp {
+
+using std::string;
+
+struct Style {
+	string font;
+	int textColor;
+	int bgColor;
+
+	Style() : textColor(-1), bgColor(-1) { }
+};
+
+} // namespace dcpp
+
+#endif

=== modified file 'dcpp/UserMatch.h'
--- dcpp/UserMatch.h	2012-01-13 20:55:20 +0000
+++ dcpp/UserMatch.h	2012-01-19 20:18:37 +0000
@@ -22,6 +22,7 @@
 #include "forward.h"
 #include "Flags.h"
 #include "StringMatch.h"
+#include "Style.h"
 
 #include <string>
 #include <vector>
@@ -34,17 +35,10 @@
 using std::string;
 using std::vector;
 
-struct Style {
-	string font;
-	int textColor;
-	int bgColor;
-
-	Style() : textColor(-1), bgColor(-1) { }
-};
-
 /** Defines rules to match users. */
 struct UserMatch : public Flags {
 	enum {
+		PREDEFINED_BIT,
 		GENERATED_BIT,
 		FAVS_BIT,
 		OPS_BIT,
@@ -54,6 +48,7 @@
 	};
 
 	enum {
+		PREDEFINED = 1 << PREDEFINED_BIT, /** Defined by DC++ by default; cannot be removed. */
 		GENERATED = 1 << GENERATED_BIT, /** Generated by DC++. Matchers that the user touches
 										become precious and cannot be modified anymore by DC++ when
 										automating actions. */

=== modified file 'dcpp/UserMatchManager.cpp'
--- dcpp/UserMatchManager.cpp	2012-01-13 20:55:20 +0000
+++ dcpp/UserMatchManager.cpp	2012-01-19 20:18:37 +0000
@@ -149,6 +149,7 @@
 
 			match.name = xml.getChildAttrib("Name");
 
+			if(xml.getBoolChildAttrib("Predefined")) { match.setFlag(UserMatch::PREDEFINED); }
 			if(xml.getBoolChildAttrib("Generated")) { match.setFlag(UserMatch::GENERATED); }
 			if(xml.getBoolChildAttrib("Favs")) { match.setFlag(UserMatch::FAVS); }
 			if(xml.getBoolChildAttrib("Ops")) { match.setFlag(UserMatch::OPS); }
@@ -191,6 +192,7 @@
 
 		xml.addChildAttrib("Name", i->name);
 
+		if(i->isSet(UserMatch::PREDEFINED)) { xml.addChildAttrib("Predefined", true); }
 		if(i->isSet(UserMatch::GENERATED)) { xml.addChildAttrib("Generated", true); }
 		if(i->isSet(UserMatch::FAVS)) { xml.addChildAttrib("Favs", true); }
 		if(i->isSet(UserMatch::OPS)) { xml.addChildAttrib("Ops", true); }

=== modified file 'dwt/include/dwt/resources/Font.h'
--- dwt/include/dwt/resources/Font.h	2012-01-13 20:55:20 +0000
+++ dwt/include/dwt/resources/Font.h	2012-01-19 20:18:37 +0000
@@ -69,6 +69,8 @@
 	};
 	Font(Predefined predef);
 
+	LOGFONT getLogFont() const;
+
 	/// get a new font with the same characteristics as this one, but bold.
 	FontPtr makeBold() const;
 

=== modified file 'dwt/src/Font.cpp'
--- dwt/src/Font.cpp	2012-01-13 20:55:20 +0000
+++ dwt/src/Font.cpp	2012-01-19 20:18:37 +0000
@@ -52,9 +52,14 @@
 {
 }
 
-FontPtr Font::makeBold() const {
+LOGFONT Font::getLogFont() const {
 	LOGFONT lf;
 	::GetObject(handle(), sizeof(lf), &lf);
+	return lf;
+}
+
+FontPtr Font::makeBold() const {
+	auto lf = getLogFont();
 	lf.lfWeight = FW_BOLD;
 	return new Font(lf);
 }

=== modified file 'dwt/src/widgets/Menu.cpp'
--- dwt/src/widgets/Menu.cpp	2012-01-13 20:55:20 +0000
+++ dwt/src/widgets/Menu.cpp	2012-01-19 20:18:37 +0000
@@ -423,8 +423,7 @@
 
 	if(drawSidebar) {
 		// get logical info for title font
-		LOGFONT lf;
-		::GetObject(titleFont->handle(), sizeof(lf), &lf);
+		auto lf = titleFont->getLogFont();
 
 		// 90 degree rotation and bold
 		lf.lfOrientation = lf.lfEscapement = 900;

=== modified file 'win32/StylesPage.cpp'
--- win32/StylesPage.cpp	2012-01-13 20:55:20 +0000
+++ win32/StylesPage.cpp	2012-01-19 20:18:37 +0000
@@ -48,7 +48,6 @@
 StylesPage::StylesPage(dwt::Widget* parent) :
 PropPage(parent, 1, 1),
 globalData(0),
-noUserMatchData(0),
 table(0),
 preview(0),
 customFont(0),
@@ -187,30 +186,21 @@
 }
 
 void StylesPage::updateUserMatches(std::vector<UserMatch>& userMatches) {
+	// remove previous user matching rows.
 	for(size_t i = 0; i < table->size();) {
-		auto data = table->getData(i);
-		if(data == noUserMatchData) {
-			table->erase(i);
-			noUserMatchData = 0;
-		} else if(dynamic_cast<UserMatchData*>(data)) {
+		if(dynamic_cast<UserMatchData*>(table->getData(i))) {
 			table->erase(i);
 		} else {
 			++i;
 		}
 	}
 
-	bool added = false;
+	// add current user matching rows.
 	for(auto i = userMatches.begin(), iend = userMatches.end(); i != iend; ++i) {
 		if(showGen->getChecked() || !i->isSet(UserMatch::GENERATED)) {
 			table->insert(table->isGrouped() ? GROUP_USERS : -1, new UserMatchData(*i));
-			added = true;
 		}
 	}
-
-	if(!added) {
-		noUserMatchData = new Data(T_("No user matching definition has been set yet"), IDH_SETTINGS_STYLES_NO_USER_MATCH);
-		table->insert(table->isGrouped() ? GROUP_USERS : -1, noUserMatchData);
-	}
 }
 
 StylesPage::Data::Data(tstring&& text, const unsigned helpId) :
@@ -333,11 +323,8 @@
 
 void StylesPage::handleSelectionChanged() {
 	auto data = table->getSelectedData();
-	if(data == noUserMatchData) {
-		data = nullptr;
-	}
-
 	bool enable = data;
+
 	if(data) {
 		updatePreview(data);
 	}

=== modified file 'win32/StylesPage.h'
--- win32/StylesPage.h	2012-01-13 20:55:20 +0000
+++ win32/StylesPage.h	2012-01-19 20:18:37 +0000
@@ -115,7 +115,6 @@
 	};
 
 	Data* globalData;
-	Data* noUserMatchData;
 
 	typedef TypedTable<Data> Table;
 	Table* table;

=== modified file 'win32/UserMatchDlg.cpp'
--- win32/UserMatchDlg.cpp	2012-01-13 20:55:20 +0000
+++ win32/UserMatchDlg.cpp	2012-01-19 20:18:37 +0000
@@ -185,12 +185,6 @@
 		}
 	});
 
-	if(result.empty()) {
-		dwt::MessageBox(this).show(T_("This user matching definition won't match any user; specify some rules"),
-			_T(APPNAME) _T(" ") _T(VERSIONSTRING), dwt::MessageBox::BOX_OK, dwt::MessageBox::BOX_ICONEXCLAMATION);
-		return;
-	}
-
 	if(forceChat->getChecked()) { result.setFlag(UserMatch::FORCE_CHAT); }
 	else if(ignoreChat->getChecked()) { result.setFlag(UserMatch::IGNORE_CHAT); }
 

=== modified file 'win32/UserMatchPage.cpp'
--- win32/UserMatchPage.cpp	2012-01-13 20:55:20 +0000
+++ win32/UserMatchPage.cpp	2012-01-19 20:18:37 +0000
@@ -168,10 +168,13 @@
 
 void UserMatchPage::handleSelectionChanged() {
 	auto sel = table->countSelected();
-	edit->setEnabled(sel == 1);
+	auto& matcher = list[sel];
+	auto predef = matcher.isSet(UserMatch::PREDEFINED);
+
+	edit->setEnabled(sel == 1 && !predef);
 	up->setEnabled(sel > 0);
 	down->setEnabled(sel > 0);
-	remove->setEnabled(sel > 0);
+	remove->setEnabled(sel > 0 && !predef);
 }
 
 tstring UserMatchPage::handleTooltip(int i) {
@@ -187,6 +190,14 @@
 		ret += _T("\r\n") + line;
 	};
 
+	if(matcher.isSet(UserMatch::PREDEFINED))
+		addLine(T_("Predefined"));
+	if(matcher.isSet(UserMatch::GENERATED))
+		addLine(str(TF_("Generated by %1%") % APPNAME));
+
+	if(matcher.empty())
+		addLine(T_("Match every user"));
+
 	if(matcher.isSet(UserMatch::FAVS))
 		addLine(T_("Match favorite users"));
 	if(matcher.isSet(UserMatch::OPS))
@@ -232,7 +243,11 @@
 	if(sel == -1)
 		return;
 
-	UserMatchDlg dlg(this, &list[sel]);
+	auto matcher = &list[sel];
+	if(matcher->isSet(UserMatch::PREDEFINED))
+		return;
+
+	UserMatchDlg dlg(this, matcher);
 	if(dlg.run() == IDOK) {
 		list[sel] = dlg.getResult();
 
@@ -285,11 +300,16 @@
 	if(dwt::MessageBox(this).show(T_("Do you really want to delete selected user matching definitions?"),
 		_T(APPNAME) _T(" ") _T(VERSIONSTRING), dwt::MessageBox::BOX_YESNO, dwt::MessageBox::BOX_ICONQUESTION) == IDYES)
 	{
-		int i;
-		while((i = table->getNext(-1, LVNI_SELECTED)) != -1) {
+		int i, j = -1;
+		while((i = table->getNext(j, LVNI_SELECTED)) != -1) {
+			if(list[i].isSet(UserMatch::PREDEFINED)) {
+				j = i + 1;
+				continue;
+			}
+
 			list.erase(list.begin() + i);
-
 			table->erase(i);
+			j = -1;
 		}
 	}
 

=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp	2012-01-16 17:56:17 +0000
+++ win32/WinUtil.cpp	2012-01-19 20:18:37 +0000
@@ -156,7 +156,8 @@
 	initFont();
 	updateUploadFont();
 	updateDownloadFont();
-	updateUserMatchFonts();
+
+	initUserMatching();
 
 	fileImages = dwt::ImageListPtr(new dwt::ImageList(dwt::Point(16, 16)));
 
@@ -428,6 +429,48 @@
 	}
 }
 
+void WinUtil::initUserMatching() {
+	// make sure predefined definitions are here.
+	bool favDefHere = false, opDefHere = false;
+	const auto& list = UserMatchManager::getInstance()->getList();
+	for(auto i = list.cbegin(), iend = list.cend(); i != iend; ++i) {
+		if(i->isSet(UserMatch::PREDEFINED)) {
+			if(i->isSet(UserMatch::FAVS)) { favDefHere = true; }
+			else if(i->isSet(UserMatch::OPS)) { opDefHere = true; }
+			if(favDefHere && opDefHere) { break; }
+		}
+	}
+
+	if(!favDefHere || !opDefHere) {
+		auto newList = list;
+
+		if(!favDefHere) {
+			// add a matcher for favs.
+			UserMatch matcher;
+			matcher.setFlag(UserMatch::PREDEFINED);
+			matcher.setFlag(UserMatch::FAVS);
+			matcher.name = str(F_("Favorite users (added by %1%)") % APPNAME);
+			matcher.style.font = Text::fromT(encodeFont(font->makeBold()->getLogFont()));
+			matcher.style.textColor = modRed(SETTING(TEXT_COLOR), 127); // more red
+			newList.push_back(std::move(matcher));
+		}
+
+		if(!opDefHere) {
+			// add a matcher for ops.
+			UserMatch matcher;
+			matcher.setFlag(UserMatch::PREDEFINED);
+			matcher.setFlag(UserMatch::OPS);
+			matcher.name = str(F_("Operators (added by %1%)") % APPNAME);
+			matcher.style.textColor = modBlue(SETTING(TEXT_COLOR), 127); // more blue
+			newList.push_back(std::move(matcher));
+		}
+
+		UserMatchManager::getInstance()->setList(std::move(newList));
+	}
+
+	updateUserMatchFonts();
+}
+
 void WinUtil::updateUserMatchFonts() {
 	userMatchFonts.clear();
 
@@ -1206,6 +1249,45 @@
 	return HLS2RGB(HLS(h, l, s));
 }
 
+COLORREF modRed(COLORREF col, int16_t mod) {
+	int16_t r = GetRValue(col) + mod, g = GetGValue(col), b = GetBValue(col);
+	if(r > 255) {
+		int16_t delta = r - 255;
+		r = 255;
+		g -= delta;
+		b -= delta;
+		if(g < 0) { g = 0; }
+		if(b < 0) { b = 0; }
+	}
+	return RGB(r, g, b);
+}
+
+COLORREF modGreen(COLORREF col, int16_t mod) {
+	int16_t r = GetRValue(col), g = GetGValue(col) + mod, b = GetBValue(col);
+	if(g > 255) {
+		int16_t delta = g - 255;
+		r -= delta;
+		g = 255;
+		b -= delta;
+		if(r < 0) { r = 0; }
+		if(b < 0) { b = 0; }
+	}
+	return RGB(r, g, b);
+}
+
+COLORREF modBlue(COLORREF col, int16_t mod) {
+	int16_t r = GetRValue(col), g = GetGValue(col), b = GetBValue(col) + mod;
+	if(b > 255) {
+		int16_t delta = b - 255;
+		r -= delta;
+		g -= delta;
+		b = 255;
+		if(r < 0) { r = 0; }
+		if(g < 0) { g = 0; }
+	}
+	return RGB(r, g, b);
+}
+
 bool registerHandler_(const tstring& name) {
 	HKEY hk;
 	TCHAR Buf[512];

=== modified file 'win32/WinUtil.h'
--- win32/WinUtil.h	2012-01-13 20:55:20 +0000
+++ win32/WinUtil.h	2012-01-19 20:18:37 +0000
@@ -65,6 +65,11 @@
 
 COLORREF HLS_TRANSFORM (COLORREF rgb, int percent_L, int percent_S);
 
+// rudimentary functions to adjust the red / green / blue value of a color.
+COLORREF modRed(COLORREF col, int16_t mod);
+COLORREF modGreen(COLORREF col, int16_t mod);
+COLORREF modBlue(COLORREF col, int16_t mod);
+
 class MainWindow;
 
 struct ColumnInfo {
@@ -316,6 +321,7 @@
 private:
 	static bool handleBoxDblClick(dwt::TextBoxBase* box, const dwt::MouseEvent& ev);
 
+	static void initUserMatching();
 	static void initHelpPath();
 
 	static DWORD helpCookie;