linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #03141
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2406: User frame updates, more dynaic grid control
------------------------------------------------------------
revno: 2406
committer: Jacek Sieka <arnetheduck@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Sun 2011-01-30 21:01:21 +0100
message:
User frame updates, more dynaic grid control
modified:
changelog.txt
dcpp/FavoriteManager.cpp
dwt/include/dwt/widgets/Grid.h
dwt/src/widgets/Grid.cpp
win32/MainWindow.cpp
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 'changelog.txt'
--- changelog.txt 2011-01-29 14:15:43 +0000
+++ changelog.txt 2011-01-30 20:01:21 +0000
@@ -1,8 +1,9 @@
-* Fav users frame becomes users frame with more stuff
+* Fav users frame becomes users frame and shows all users
* Experimental implementation of KEYP ADC extension
* Prevent a remote crash triggered via malformed user commands (poy)
* Avoid crashes when closing from the taskbar too often (poy)
* [L#580051] Restore DC++ colors to fav hubs on >= Vista (poy)
+* Favorite user nicks are saved in Users.xml
-- 0.781 2011-01-12 --
* Add a dummy serial number to TLS certs to satisfy some parsers (poy)
=== modified file 'dcpp/FavoriteManager.cpp'
--- dcpp/FavoriteManager.cpp 2011-01-29 14:15:43 +0000
+++ dcpp/FavoriteManager.cpp 2011-01-30 20:01:21 +0000
@@ -160,21 +160,25 @@
}
void FavoriteManager::addFavoriteUser(const UserPtr& aUser) {
- Lock l(cs);
- if(users.find(aUser->getCID()) == users.end()) {
- StringList urls = ClientManager::getInstance()->getHubs(aUser->getCID(), Util::emptyString);
- StringList nicks = ClientManager::getInstance()->getNicks(aUser->getCID(), Util::emptyString);
-
- /// @todo make this an error probably...
- if(urls.empty())
- urls.push_back(Util::emptyString);
- if(nicks.empty())
- nicks.push_back(Util::emptyString);
-
- FavoriteMap::iterator i = users.insert(make_pair(aUser->getCID(), FavoriteUser(aUser, nicks[0], urls[0]))).first;
- fire(FavoriteManagerListener::UserAdded(), i->second);
- save();
+ {
+ Lock l(cs);
+ if(users.find(aUser->getCID()) == users.end()) {
+ StringList urls = ClientManager::getInstance()->getHubs(aUser->getCID(), Util::emptyString);
+ StringList nicks = ClientManager::getInstance()->getNicks(aUser->getCID(), Util::emptyString);
+
+ /// @todo make this an error probably...
+ if(urls.empty())
+ urls.push_back(Util::emptyString);
+ if(nicks.empty())
+ nicks.push_back(Util::emptyString);
+
+ FavoriteMap::iterator i = users.insert(make_pair(aUser->getCID(), FavoriteUser(aUser, nicks[0], urls[0]))).first;
+ fire(FavoriteManagerListener::UserAdded(), i->second);
+ save();
+ }
}
+
+ ClientManager::getInstance()->saveUser(aUser->getCID());
}
void FavoriteManager::removeFavoriteUser(const UserPtr& aUser) {
@@ -528,6 +532,8 @@
} else {
u = ClientManager::getInstance()->getUser(CID(cid));
}
+
+ ClientManager::getInstance()->saveUser(u->getCID());
FavoriteMap::iterator i = users.insert(make_pair(u->getCID(), FavoriteUser(u, nick, hubUrl))).first;
if(aXml.getBoolChildAttrib("GrantSlot"))
=== modified file 'dwt/include/dwt/widgets/Grid.h'
--- dwt/include/dwt/widgets/Grid.h 2011-01-02 17:12:02 +0000
+++ dwt/include/dwt/widgets/Grid.h 2011-01-30 20:01:21 +0000
@@ -88,10 +88,15 @@
};
virtual void layout(const Rectangle& r);
-
void addRow(const GridInfo& gp) { rows.push_back(gp); }
void addColumn(const GridInfo& gp) { columns.push_back(gp); }
+ void removeRow(size_t i) { rows.erase(rows.begin() + i); }
+ void removeColumn(size_t i) { columns.erase(columns.begin() + i); }
+
+ void clearRows() { rows.clear(); }
+ void clearColumns() { columns.clear(); }
+
void setWidget(Widget* w, size_t row, size_t column, size_t rowSpan = 1, size_t colSpan = 1);
void setWidget(Widget* w);
@@ -101,10 +106,16 @@
GridInfo& row(size_t i);
GridInfo& column(size_t i);
+ size_t rowCount() const { return rows.size(); }
+ size_t columnCount() const { return columns.size(); }
+
void create( const Seed & cs = Seed() );
Point getPreferredSize();
+ /// Returns true if handled, else false
+ virtual bool handleMessage(const MSG &msg, LRESULT &retVal);
+
protected:
friend class WidgetCreator<Grid>;
=== modified file 'dwt/src/widgets/Grid.cpp'
--- dwt/src/widgets/Grid.cpp 2011-01-29 14:15:43 +0000
+++ dwt/src/widgets/Grid.cpp 2011-01-30 20:01:21 +0000
@@ -58,12 +58,6 @@
}
Point Grid::getPreferredSize() {
- // TODO find better way of keeping track of children
- for(HWND wnd = ::FindWindowEx(handle(), NULL, NULL, NULL); wnd; wnd = ::FindWindowEx(handle(), wnd, NULL, NULL)) {
- // Update widget info if it's missing for some children...
- getWidgetInfo(wnd);
- }
-
std::vector<size_t> rowSize = calcSizes(rows, columns, 0, true);
std::vector<size_t> colSize = calcSizes(columns, rows, 0, false);
Point p(
@@ -156,6 +150,9 @@
// Layout children first.
auto children = getChildren<Widget>();
+ // Make sure we have WidgetInfo's for every child...
+ std::for_each(children.first, children.second, [=](Widget* w) { getWidgetInfo(w->handle()); });
+
Point size = r.size;
Point as = actualSpacing();
@@ -291,4 +288,22 @@
}
}
+bool Grid::handleMessage(const MSG &msg, LRESULT &retVal) {
+ if(msg.message == WM_PARENTNOTIFY) {
+ if(LOWORD(msg.wParam) == WM_DESTROY) {
+ auto wnd = (HWND)msg.lParam;
+ if(::GetParent(wnd) == handle()) {
+ for(auto i = widgetInfo.begin(); i != widgetInfo.end(); ++i) {
+ if(i->w->handle() == wnd) {
+ widgetInfo.erase(i);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return BaseType::handleMessage(msg, retVal);
+}
+
}
=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp 2011-01-29 14:15:43 +0000
+++ win32/MainWindow.cpp 2011-01-30 20:01:21 +0000
@@ -260,7 +260,7 @@
[this] { PublicHubsFrame::openWindow(getTabView()); }, WinUtil::menuIcon(IDI_PUBLICHUBS));
viewIndexes[FavHubsFrame::id] = viewMenu->appendItem(T_("&Favorite Hubs\tCtrl+F"),
[this] { FavHubsFrame::openWindow(getTabView()); }, WinUtil::menuIcon(IDI_FAVORITE_HUBS));
- viewIndexes[UsersFrame::id] = viewMenu->appendItem(T_("Favorite &Users\tCtrl+U"),
+ viewIndexes[UsersFrame::id] = viewMenu->appendItem(T_("&Users\tCtrl+U"),
[this] { UsersFrame::openWindow(getTabView()); }, WinUtil::menuIcon(IDI_FAVORITE_USERS));
viewMenu->appendSeparator();
viewIndexes[QueueFrame::id] = viewMenu->appendItem(T_("&Download Queue\tCtrl+D"),
@@ -357,7 +357,7 @@
std::bind(&MainWindow::handleRedirect, this));
toolbar->addButton(FavHubsFrame::id, WinUtil::toolbarIcon(IDI_FAVORITE_HUBS), 0, T_("Favorite Hubs"), IDH_TOOLBAR_FAVORITE_HUBS,
[this] { FavHubsFrame::openWindow(getTabView()); }, std::bind(&MainWindow::handleFavHubsDropDown, this, _1));
- toolbar->addButton(UsersFrame::id, WinUtil::toolbarIcon(IDI_FAVORITE_USERS), 0, T_("Favorite Users"), IDH_TOOLBAR_FAVORITE_USERS,
+ toolbar->addButton(UsersFrame::id, WinUtil::toolbarIcon(IDI_FAVORITE_USERS), 0, T_("Users"), IDH_TOOLBAR_FAVORITE_USERS,
[this] { UsersFrame::openWindow(getTabView()); });
toolbar->addButton(QueueFrame::id, WinUtil::toolbarIcon(IDI_QUEUE), 0, T_("Download Queue"), IDH_TOOLBAR_QUEUE,
[this] { QueueFrame::openWindow(getTabView()); });
=== modified file 'win32/UsersFrame.cpp'
--- win32/UsersFrame.cpp 2011-01-30 16:17:57 +0000
+++ win32/UsersFrame.cpp 2011-01-30 20:01:21 +0000
@@ -32,9 +32,9 @@
dwt::ImageListPtr UsersFrame::userIcons;
static const ColumnInfo usersColumns[] = {
- { N_("Favorite"), 30, false },
- { N_("Nick"), 50, false },
- { N_("Grant slot"), 30, false },
+ { N_("Favorite"), 25, false },
+ { N_("Grant slot"), 25, false },
+ { N_("Nick"), 125, false },
{ N_("Hub (last seen in, if offline)"), 300, false },
{ N_("Time last seen"), 150, false },
{ N_("Description"), 200, false },
@@ -53,7 +53,7 @@
};
UsersFrame::UsersFrame(TabViewPtr parent) :
- BaseType(parent, T_("Favorite Users"), IDH_FAVUSERS, IDI_FAVORITE_USERS),
+ BaseType(parent, T_("Users"), IDH_FAVUSERS, IDI_FAVORITE_USERS),
users(0),
startup(true)
{
@@ -165,6 +165,7 @@
void UsersFrame::UserInfo::update(const UserPtr& u) {
columns[COLUMN_NICK] = WinUtil::getNicks(u, Util::emptyString);
+ columns[COLUMN_HUB] = u->isOnline() ? WinUtil::getHubNames(u, Util::emptyString).first : Util::emptyStringT;
columns[COLUMN_SEEN] = u->isOnline() ? T_("Online") : Text::toT(Util::formatTime("%Y-%m-%d %H:%M", FavoriteManager::getInstance()->getLastSeen(u)));
columns[COLUMN_CID] = Text::toT(u->getCID().toBase32());
@@ -196,7 +197,7 @@
if(ui != userInfos.end()) {
auto i = users->find(ui->second);
if(i != -1) {
- ui->second->columns[COLUMN_SEEN] = aUser->isOnline() ? T_("Online") : Text::toT(Util::formatTime("%Y-%m-%d %H:%M", FavoriteManager::getInstance()->getLastSeen(aUser)));
+ ui->second->update(aUser);
users->update(i);
}
}
@@ -212,20 +213,20 @@
void UsersFrame::handleSelectionChanged() {
// Clear old items
- auto children = userInfo->getChildren<Container>();
- auto v = std::vector<Container*>();
- for(auto i = children.first; i != children.second; ++i) {
- v.push_back(&(**i));
- }
-
- for_each(v.begin(), v.end(), [](Container *c) { c->close(); });
+ auto children = userInfo->getChildren<Control>();
+ auto v = std::vector<Control*>(children.first, children.second);
+
+ for_each(v.begin(), v.end(), [](Control *w) { w->close(); });
+
+ userInfo->clearRows();
auto sel = users->getSelectedData();
if(!sel) {
-
return;
}
+ dcdebug("Selected %s\n", sel->getUser().user->getCID().toBase32().c_str());
+
auto lock = ClientManager::getInstance()->lock();
auto ui = ClientManager::getInstance()->findOnlineUser(sel->getUser(), false);
if(!ui) {
@@ -235,10 +236,12 @@
auto info = ui->getIdentity().getInfo();
tstring text;
for(auto i = info.begin(); i != info.end(); ++i) {
- text += Text::toT(i->first) + _T(":") + Text::toT(i->second) + _T("\r\n");
+ userInfo->addRow(GridInfo());
+ userInfo->addChild(Label::Seed(Text::toT(i->first)));
+ userInfo->addChild(Label::Seed(Text::toT(i->second)));
}
- userInfo->setText(text);
+ layout();
}
void UsersFrame::handleDescription() {
=== modified file 'win32/UsersFrame.h'
--- win32/UsersFrame.h 2011-01-30 16:17:57 +0000
+++ win32/UsersFrame.h 2011-01-30 20:01:21 +0000
@@ -63,8 +63,8 @@
enum {
COLUMN_FIRST,
COLUMN_FAVORITE = COLUMN_FIRST,
+ COLUMN_SLOT,
COLUMN_NICK,
- COLUMN_SLOT,
COLUMN_HUB,
COLUMN_SEEN,
COLUMN_DESCRIPTION,
@@ -97,7 +97,11 @@
}
static int compareItems(UserInfo* a, UserInfo* b, int col) {
- return lstrcmpi(a->columns[col].c_str(), b->columns[col].c_str());
+ switch(col) {
+ case COLUMN_FAVORITE: return compare(a->isFavorite, b->isFavorite);
+ case COLUMN_SLOT: return compare(a->grantSlot, b->grantSlot);
+ default: return lstrcmpi(a->columns[col].c_str(), b->columns[col].c_str());
+ }
}
void remove();