linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04861
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2695: user matching
------------------------------------------------------------
revno: 2695
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2011-12-04 15:56:09 +0100
message:
user matching
modified:
dcpp/AdcHub.cpp
dcpp/ClientManager.h
dcpp/NmdcHub.cpp
dcpp/OnlineUser.h
dcpp/User.cpp
dcpp/UserMatch.cpp
dcpp/UserMatchManager.cpp
win32/HubFrame.cpp
win32/StylesPage.cpp
win32/StylesPage.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 'dcpp/AdcHub.cpp'
--- dcpp/AdcHub.cpp 2011-12-03 21:53:57 +0000
+++ dcpp/AdcHub.cpp 2011-12-04 14:56:09 +0000
@@ -252,9 +252,7 @@
return;
auto from = findUser(c.getFrom());
- if(!from)
- return;
- if(from->getIdentity().match && from->getIdentity().match->noChat)
+ if(!from || from->getIdentity().noChat())
return;
ChatMessage message = { c.getParam(0), from };
=== modified file 'dcpp/ClientManager.h'
--- dcpp/ClientManager.h 2011-12-03 21:53:57 +0000
+++ dcpp/ClientManager.h 2011-12-04 14:56:09 +0000
@@ -93,7 +93,7 @@
string findHub(const string& ipPort) const;
string findHubEncoding(const string& aUrl) const;
- /**
+ /** Get an OnlineUser object - lock it with lock()!
* @param priv discard any user that doesn't match the hint.
* @return OnlineUser* found by CID and hint; might be only by CID if priv is false.
*/
=== modified file 'dcpp/NmdcHub.cpp'
--- dcpp/NmdcHub.cpp 2011-12-03 21:53:57 +0000
+++ dcpp/NmdcHub.cpp 2011-12-04 14:56:09 +0000
@@ -212,7 +212,7 @@
}
auto from = findUser(nick);
- if(from && from->getIdentity().match && from->getIdentity().match->noChat)
+ if(from && from->getIdentity().noChat())
return;
ChatMessage chatMessage = { unescape(message), from };
@@ -405,7 +405,8 @@
setMyIdentity(u.getIdentity());
}
- fire(ClientListener::UserUpdated(), this, u);
+ updated(u);
+
} else if(cmd == "$Quit") {
if(!param.empty()) {
const string& nick = param;
@@ -707,7 +708,7 @@
}
auto from = findUser(fromNick);
- if(from && from->getIdentity().match && from->getIdentity().match->noChat)
+ if(from && from->getIdentity().noChat())
return;
ChatMessage message = { unescape(param.substr(j + 2)), from, &getUser(getMyNick()), findUser(rtNick) };
=== modified file 'dcpp/OnlineUser.h'
--- dcpp/OnlineUser.h 2011-12-03 21:53:57 +0000
+++ dcpp/OnlineUser.h 2011-12-04 14:56:09 +0000
@@ -113,6 +113,10 @@
bool isSet(const char* name) const;
string getSIDString() const { return string((const char*)&sid, 4); }
+ UserMatchPropsPtr getMatch() const;
+ void setMatch(UserMatchPropsPtr match);
+ bool noChat() const;
+
bool isClientType(ClientType ct) const;
void getParams(ParamMap& params, const string& prefix, bool compatibility) const;
@@ -120,13 +124,13 @@
GETSET(UserPtr, user, User);
GETSET(uint32_t, sid, SID);
- UserMatchPropsPtr match;
-
private:
typedef std::unordered_map<short, string> InfMap;
typedef InfMap::iterator InfIter;
InfMap info;
+ UserMatchPropsPtr match;
+
static FastCriticalSection cs;
};
=== modified file 'dcpp/User.cpp'
--- dcpp/User.cpp 2011-10-11 18:38:23 +0000
+++ dcpp/User.cpp 2011-12-04 14:56:09 +0000
@@ -190,6 +190,21 @@
return ret;
}
+UserMatchPropsPtr Identity::getMatch() const {
+ FastLock l(cs);
+ return match;
+}
+
+void Identity::setMatch(UserMatchPropsPtr match) {
+ FastLock l(cs);
+ this->match = match;
+}
+
+bool Identity::noChat() const {
+ FastLock l(cs);
+ return match && match->noChat;
+}
+
void FavoriteUser::update(const OnlineUser& info) {
setNick(info.getIdentity().getNick());
setUrl(info.getClient().getHubUrl());
=== modified file 'dcpp/UserMatch.cpp'
--- dcpp/UserMatch.cpp 2011-12-03 21:53:57 +0000
+++ dcpp/UserMatch.cpp 2011-12-04 14:56:09 +0000
@@ -122,7 +122,7 @@
}
}
- identity.match = props;
+ identity.setMatch(props);
return true;
}
=== modified file 'dcpp/UserMatchManager.cpp'
--- dcpp/UserMatchManager.cpp 2011-12-03 21:53:57 +0000
+++ dcpp/UserMatchManager.cpp 2011-12-04 14:56:09 +0000
@@ -61,7 +61,7 @@
return;
}
}
- identity.match.reset();
+ identity.setMatch(nullptr);
}
void UserMatchManager::on(SettingsManagerListener::Load, SimpleXML& xml) noexcept {
=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp 2011-12-03 21:53:57 +0000
+++ win32/HubFrame.cpp 2011-12-04 14:56:09 +0000
@@ -773,25 +773,25 @@
}
int HubFrame::UserInfo::getStyle(HFONT& font, COLORREF& textColor, COLORREF& bgColor, int) const {
- if(!identity.match) {
+ auto match = identity.getMatch();
+ if(!match) {
return CDRF_DODEFAULT;
}
- const auto& match = *identity.match;
- if(!match.font.empty()) {
+ if(!match->font.empty()) {
// cache lookup might fail when refreshing the list of user matching defs...
- auto cached = WinUtil::userMatchFonts.find(match.font);
+ auto cached = WinUtil::userMatchFonts.find(match->font);
if(cached != WinUtil::userMatchFonts.end()) {
font = cached->second->handle();
}
}
- if(match.textColor != -1) {
- textColor = match.textColor;
+ if(match->textColor != -1) {
+ textColor = match->textColor;
}
- if(match.bgColor != -1) {
- bgColor = match.bgColor;
+ if(match->bgColor != -1) {
+ bgColor = match->bgColor;
}
return CDRF_NEWFONT;
=== modified file 'win32/StylesPage.cpp'
--- win32/StylesPage.cpp 2011-12-03 21:53:57 +0000
+++ win32/StylesPage.cpp 2011-12-04 14:56:09 +0000
@@ -59,6 +59,8 @@
StylesPage::StylesPage(dwt::Widget* parent) :
PropPage(parent, 2, 1),
+globalData(0),
+noUserMatchData(0),
table(0),
preview(0),
customFont(0),
@@ -148,7 +150,7 @@
table->setGroups(groups);
auto grouped = table->isGrouped();
- auto add = [this, grouped](tstring&& text, unsigned helpId, int group, int fontSetting, int textColorSetting, int bgColorSetting) -> SettingsData* {
+ auto add = [this, grouped](tstring&& text, unsigned helpId, int group, int fontSetting, int textColorSetting, int bgColorSetting) -> Data* {
auto data = new SettingsData(forward<tstring>(text), helpId, fontSetting, textColorSetting, bgColorSetting);
table->insert(grouped ? group : -1, data);
return data;
@@ -187,7 +189,11 @@
void StylesPage::updateUserMatches(std::vector<UserMatch>& userMatches) {
for(size_t i = 0; i < table->size();) {
- if(dynamic_cast<UserMatchData*>(table->getData(i))) {
+ auto data = table->getData(i);
+ if(data == noUserMatchData) {
+ table->erase(i);
+ noUserMatchData = 0;
+ } else if(dynamic_cast<UserMatchData*>(data)) {
table->erase(i);
} else {
++i;
@@ -195,7 +201,8 @@
}
if(userMatches.empty()) {
- table->insert(table->isGrouped() ? GROUP_USERS : -1, new Data(T_("No user matching definition has been set yet"), IDH_SETTINGS_STYLES_NO_USER_MATCH));
+ 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);
} else {
for(auto i = userMatches.begin(), iend = userMatches.end(); i != iend; ++i) {
table->insert(table->isGrouped() ? GROUP_USERS : -1, new UserMatchData(*i));
@@ -322,6 +329,9 @@
void StylesPage::handleSelectionChanged() {
auto data = table->getSelectedData();
+ if(data == noUserMatchData) {
+ data = nullptr;
+ }
bool enable = data;
if(data) {
=== modified file 'win32/StylesPage.h'
--- win32/StylesPage.h 2011-12-03 21:53:57 +0000
+++ win32/StylesPage.h 2011-12-04 14:56:09 +0000
@@ -114,7 +114,8 @@
UserMatchPropsPtr props;
};
- SettingsData* globalData;
+ Data* globalData;
+ Data* noUserMatchData;
typedef TypedTable<Data> Table;
Table* table;