← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2416: Users frame updates

 

------------------------------------------------------------
revno: 2416
committer: Jacek Sieka <arnetheduck@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Tue 2011-02-08 20:27:11 +0100
message:
  Users frame updates
modified:
  win32/UsersFrame.cpp
  win32/UsersFrame.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 'win32/UsersFrame.cpp'
--- win32/UsersFrame.cpp	2011-02-01 21:05:24 +0000
+++ win32/UsersFrame.cpp	2011-02-08 19:27:11 +0000
@@ -57,7 +57,17 @@
 	users(0),
 	startup(true)
 {
-	splitter = addChild(VSplitter::Seed(0.3));
+	filterGrid = addChild(Grid::Seed(1, 2));
+
+	filter = filterGrid->addChild(WinUtil::Seeds::textBox);
+	filter->onUpdated(std::bind(&UsersFrame::handleFilterUpdated, this));
+	filterGrid->column(0).mode = GridInfo::FILL;
+
+	showFavs = filterGrid->addChild(WinUtil::Seeds::checkBox);
+	showFavs->setText(_T("Favorite users only"));
+	showFavs->onClicked(std::bind(&UsersFrame::handleFilterUpdated, this));
+
+	splitter = addChild(VSplitter::Seed(0.7));
 
 	if(!userIcons) {
 		userIcons = dwt::ImageListPtr(new dwt::ImageList(dwt::Point(16, 16)));
@@ -99,7 +109,6 @@
 		auto lock = ClientManager::getInstance()->lock();
 		auto &ou = ClientManager::getInstance()->getUsers();
 
-		HoldRedraw hold(users);
 		for(auto i = ou.begin(); i != ou.end(); ++i) {
 			if(i->second->isOnline()) {
 				addUser(i->second);
@@ -110,7 +119,6 @@
 	{
 		auto fu = FavoriteManager::getInstance()->getFavoriteUsers();
 
-		HoldRedraw hold(users);
 		for(auto i = fu.begin(); i != fu.end(); ++i) {
 			addUser(i->second.getUser());
 		}
@@ -124,6 +132,8 @@
 	layout();
 
 	startup = false;
+
+	handleFilterUpdated();
 }
 
 UsersFrame::~UsersFrame() {
@@ -134,6 +144,14 @@
 
 	status->layout(r);
 
+	auto r2 = r;
+	r2.size.y = filter->getPreferredSize().y;
+
+	filterGrid->layout(r2);
+
+	r.pos.y += filter->getWindowSize().y + 3;
+	r.size.y -= filter->getWindowSize().y + 3;
+
 	splitter->layout(r);
 }
 
@@ -185,9 +203,12 @@
 void UsersFrame::addUser(const UserPtr& aUser) {
 	auto ui = userInfos.find(aUser);
 	if(ui == userInfos.end()) {
-		auto x = new UserInfo(aUser);
-		userInfos.insert(std::make_pair(aUser, x));
-		users->insert(x);
+		auto x = make_shared<UserInfo>(aUser);
+		if(matches(*x)){
+			users->insert(x.get());
+		}
+
+		userInfos.insert(std::make_pair(aUser, std::move(x)));
 	} else {
 		// TODO Update
 	}
@@ -196,18 +217,26 @@
 void UsersFrame::updateUser(const UserPtr& aUser) {
 	auto ui = userInfos.find(aUser);
 	if(ui != userInfos.end()) {
-		auto i = users->find(ui->second);
-		if(i != -1) {
-			ui->second->update(aUser);
-			users->update(i);
+		ui->second->update(aUser);
+
+		if(matches(*ui->second)) {
+			auto i = users->find(ui->second.get());
+			if(i != -1) {
+				users->update(i);
+			}
 		}
 	}
 }
 
 void UsersFrame::removeUser(const UserPtr& aUser) {
+	if(FavoriteManager::getInstance()->isFavoriteUser(aUser)) {
+		updateUser(aUser);
+		return;
+	}
+
 	auto ui = userInfos.find(aUser);
 	if(ui != userInfos.end()) {
-		users->erase(ui->second);
+		users->erase(ui->second.get());
 		userInfos.erase(ui);
 	}
 }
@@ -328,6 +357,30 @@
 	return true;
 }
 
+void UsersFrame::handleFilterUpdated() {
+	HoldRedraw h(users);
+	users->clear();
+	for(auto i = userInfos.begin(); i != userInfos.end(); ++i) {
+		if(matches(*i->second)) {
+			users->insert(i->second.get());
+		}
+	}
+}
+
+bool UsersFrame::matches(const UserInfo &ui) {
+	if(showFavs->getChecked() && !FavoriteManager::getInstance()->isFavoriteUser(ui.getUser())) {
+		return false;
+	}
+
+	auto txt = filter->getText();
+
+	if(Util::findSubString(ui.columns[COLUMN_NICK], txt) != string::npos) {
+		return true;
+	}
+
+	return false;
+}
+
 UsersFrame::UserInfoList UsersFrame::selectedUsersImpl() const {
 	return usersFromTable(users);
 }
@@ -348,6 +401,10 @@
 	callAsync(std::bind(&UsersFrame::addUser, this, aUser));
 }
 
+void UsersFrame::on(UserUpdated, const UserPtr& aUser) throw() {
+	callAsync(std::bind(&UsersFrame::updateUser, this, aUser));
+}
+
 void UsersFrame::on(UserDisconnected, const UserPtr& aUser) throw() {
-	callAsync(std::bind(&UsersFrame::updateUser, this, aUser));
+	callAsync(std::bind(&UsersFrame::removeUser, this, aUser));
 }

=== modified file 'win32/UsersFrame.h'
--- win32/UsersFrame.h	2011-01-30 20:01:21 +0000
+++ win32/UsersFrame.h	2011-02-08 19:27:11 +0000
@@ -115,14 +115,22 @@
 		bool grantSlot;
 	};
 
-	typedef TypedTable<UserInfo> WidgetUsers;
+	typedef TypedTable<UserInfo, false> WidgetUsers;
 	typedef WidgetUsers* WidgetUsersPtr;
+
+	GridPtr filterGrid;
+
 	WidgetUsersPtr users;
 	GridPtr userInfo;
 	VSplitterPtr splitter;
+
+	TextBoxPtr filter;
+	CheckBoxPtr showFavs;
+
 	static dwt::ImageListPtr userIcons;
 
-	std::unordered_map<UserPtr, UserInfo*, User::Hash> userInfos;
+	// TODO change to unique_ptr once g++ map supports it (no move insert in 4.5 it seems...)
+	std::unordered_map<UserPtr, shared_ptr<UserInfo>, User::Hash> userInfos;
 
 	bool startup;
 
@@ -137,6 +145,8 @@
 	bool handleContextMenu(dwt::ScreenCoordinate pt);
 	void handleSelectionChanged();
 	bool handleClick(const dwt::MouseEvent &me);
+	void handleFilterUpdated();
+	bool matches(const UserInfo& ui);
 
 	// AspectUserInfo
 	UserInfoList selectedUsersImpl() const;
@@ -148,6 +158,7 @@
 
 	// ClientManagerListner
 	virtual void on(UserConnected, const UserPtr& aUser) throw();
+	virtual void on(UserUpdated, const UserPtr& aUser) throw();
 	virtual void on(UserDisconnected, const UserPtr& aUser) throw();
 };