fixed icons in chat lobbies

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6160 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-02-27 22:17:49 +00:00
parent c13192b4c3
commit 061a8113bb
6 changed files with 89 additions and 36 deletions

View File

@ -32,8 +32,12 @@
#define IMAGE_CREATE "" #define IMAGE_CREATE ""
#define IMAGE_PUBLIC "" #define IMAGE_PUBLIC ""
#define IMAGE_PRIVATE "" #define IMAGE_PRIVATE ""
#define IMAGE_UNSUBSCRIBE ""
#define IMAGE_SUBSCRIBE "" #define IMAGE_SUBSCRIBE ""
#define IMAGE_UNSUBSCRIBE "" #define IMAGE_PEER_ENTERING ":images/user/add_user24.png"
#define IMAGE_PEER_LEAVING ":images/user/remove_user24.png"
#define IMAGE_TYPING ":images/typing.png"
#define IMAGE_MESSAGE ":images/chat.png"
ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags) ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags)
: RsAutoUpdatePage(5000, parent, flags) : RsAutoUpdatePage(5000, parent, flags)
@ -91,7 +95,6 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags)
stackedWidget->addWidget(_lobby_blank_page) ; stackedWidget->addWidget(_lobby_blank_page) ;
lobbyTreeWidget->expandAll(); lobbyTreeWidget->expandAll();
// lobbyTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
lobbyChanged(); lobbyChanged();
showBlankPage(0) ; showBlankPage(0) ;
@ -166,14 +169,18 @@ void ChatLobbyWidget::addChatPage(ChatLobbyDialog *d)
{ {
// check that the page does not already exist. // check that the page does not already exist.
if(_lobby_dialogs.find(d->id()) == _lobby_dialogs.end()) if(_lobby_infos.find(d->id()) == _lobby_infos.end())
{ {
stackedWidget->addWidget(d) ; stackedWidget->addWidget(d) ;
connect(d,SIGNAL(lobbyLeave(ChatLobbyId)),this,SLOT(unsubscribeChatLobby(ChatLobbyId))) ; connect(d,SIGNAL(lobbyLeave(ChatLobbyId)),this,SLOT(unsubscribeChatLobby(ChatLobbyId))) ;
connect(d,SIGNAL(typingEventReceived(ChatLobbyId)),this,SLOT(updateTypingStatus(ChatLobbyId))) ; connect(d,SIGNAL(typingEventReceived(ChatLobbyId)),this,SLOT(updateTypingStatus(ChatLobbyId))) ;
connect(d,SIGNAL(messageReceived(ChatLobbyId)),this,SLOT(updateMessageChanged(ChatLobbyId))) ;
connect(d,SIGNAL(peerJoined(ChatLobbyId)),this,SLOT(updatePeerEntering(ChatLobbyId))) ;
connect(d,SIGNAL(peerLeft(ChatLobbyId)),this,SLOT(updatePeerLeaving(ChatLobbyId))) ;
_lobby_dialogs[d->id()] = d ; _lobby_infos[d->id()].dialog = d ;
_lobby_infos[d->id()].default_icon = QIcon() ;
} }
} }
@ -272,10 +279,10 @@ void ChatLobbyWidget::updateDisplay()
lobby_item->addChild(item); lobby_item->addChild(item);
} }
if(lobby_item == publicLobbyItem) // if(lobby_item == publicLobbyItem)
item->setIcon(COLUMN_NAME, QIcon(IMAGE_PUBLIC)); // item->setIcon(COLUMN_NAME, QIcon(IMAGE_PUBLIC));
else // else
item->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE)); // item->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE));
bool subscribed = false; bool subscribed = false;
if (rsMsgs->getVirtualPeerId(lobby.lobby_id, vpid)) { if (rsMsgs->getVirtualPeerId(lobby.lobby_id, vpid)) {
@ -285,6 +292,8 @@ void ChatLobbyWidget::updateDisplay()
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed); updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed);
} }
time_t now = time(NULL) ;
// Now add participating lobbies. // Now add participating lobbies.
// //
for (lobbyIt = lobbies.begin(); lobbyIt != lobbies.end(); ++lobbyIt) for (lobbyIt = lobbies.begin(); lobbyIt != lobbies.end(); ++lobbyIt)
@ -319,11 +328,13 @@ void ChatLobbyWidget::updateDisplay()
itemParent->addChild(item); itemParent->addChild(item);
} }
if (lobby.lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC) { // if(_icon_changed_map.find(*lobbyIt) != _icon_changed_map.end())
item->setIcon(COLUMN_NAME, QIcon(IMAGE_PUBLIC)); // && _icon_changed_map[*lobbyIt]+5 < now
} else { // if (lobby.lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC) {
item->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE)); // item->setIcon(COLUMN_NAME, QIcon(IMAGE_PUBLIC));
} // } else {
// item->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE));
// }
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.nick_names.size(), true); updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.nick_names.size(), true);
} }
@ -350,10 +361,10 @@ void ChatLobbyWidget::showLobby(QTreeWidgetItem *item)
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong(); ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
if(_lobby_dialogs.find(id) == _lobby_dialogs.end()) if(_lobby_infos.find(id) == _lobby_infos.end())
showBlankPage(id) ; showBlankPage(id) ;
else else
stackedWidget->setCurrentWidget(_lobby_dialogs[id]) ; stackedWidget->setCurrentWidget(_lobby_infos[id].dialog) ;
} }
static void subscribeLobby(QTreeWidgetItem *item) static void subscribeLobby(QTreeWidgetItem *item)
@ -432,33 +443,46 @@ void ChatLobbyWidget::updateTypingStatus(ChatLobbyId id)
if(item != NULL) if(item != NULL)
{ {
item->setIcon(0,QIcon(":images/typing.png")) ; item->setIcon(0,QIcon(IMAGE_TYPING)) ;
_lobby_infos[id].last_typing_event = time(NULL) ;
_icon_changed_map[item] = time(NULL) ;
QTimer::singleShot(5000,this,SLOT(resetLobbyTreeIcons())) ; QTimer::singleShot(5000,this,SLOT(resetLobbyTreeIcons())) ;
} }
else
std::cerr << "Could not find item for lobby id " << (void*)id << std::endl;
} }
void ChatLobbyWidget::updatePeerLeaving(ChatLobbyId id)
{
QTreeWidgetItem *item = getTreeWidgetItem(id) ;
if(item != NULL)
{
item->setIcon(0,QIcon(IMAGE_PEER_LEAVING)) ;
_lobby_infos[id].last_typing_event = time(NULL) ;
QTimer::singleShot(5000,this,SLOT(resetLobbyTreeIcons())) ;
}
}
void ChatLobbyWidget::updatePeerEntering(ChatLobbyId id)
{
QTreeWidgetItem *item = getTreeWidgetItem(id) ;
if(item != NULL)
{
item->setIcon(0,QIcon(IMAGE_PEER_ENTERING)) ;
_lobby_infos[id].last_typing_event = time(NULL) ;
QTimer::singleShot(5000,this,SLOT(resetLobbyTreeIcons())) ;
}
}
void ChatLobbyWidget::resetLobbyTreeIcons() void ChatLobbyWidget::resetLobbyTreeIcons()
{ {
time_t now = time(NULL) ; time_t now = time(NULL) ;
for(std::map<QTreeWidgetItem*,time_t>::iterator it(_icon_changed_map.begin());it!=_icon_changed_map.end();) for(std::map<ChatLobbyId,ChatLobbyInfoStruct>::iterator it(_lobby_infos.begin());it!=_lobby_infos.end();++it)
if(it->second + 5 < now) if(it->second.last_typing_event + 5 <= now)
{ {
it->first->setIcon(0,QIcon()) ; getTreeWidgetItem(it->first)->setIcon(0,it->second.default_icon) ;
std::cerr << "Reseted 1 lobby icon." << std::endl;
std::map<QTreeWidgetItem*,time_t>::iterator tmp(it) ;
++tmp ;
_icon_changed_map.erase(it) ;
it = tmp ;
} }
else
++it ;
} }
void ChatLobbyWidget::unsubscribeItem() void ChatLobbyWidget::unsubscribeItem()
@ -479,12 +503,12 @@ void ChatLobbyWidget::unsubscribeChatLobby(ChatLobbyId id)
// close the tab. // close the tab.
std::map<ChatLobbyId,ChatLobbyDialog*>::iterator it = _lobby_dialogs.find(id) ; std::map<ChatLobbyId,ChatLobbyInfoStruct>::iterator it = _lobby_infos.find(id) ;
if(it != _lobby_dialogs.end()) if(it != _lobby_infos.end())
{ {
stackedWidget->removeWidget(it->second) ; stackedWidget->removeWidget(it->second.dialog) ;
_lobby_dialogs.erase(it) ; _lobby_infos.erase(it) ;
} }
// Unsubscribe the chat lobby // Unsubscribe the chat lobby
@ -502,7 +526,18 @@ void ChatLobbyWidget::updateCurrentLobby()
if(items.empty()) if(items.empty())
showLobby(0) ; showLobby(0) ;
else else
{
showLobby(items.front()); showLobby(items.front());
items.front()->setIcon(0,QIcon()) ;
}
}
void ChatLobbyWidget::updateMessageChanged(ChatLobbyId id)
{
_lobby_infos[id].default_icon = QIcon(IMAGE_MESSAGE) ;
QTreeWidgetItem *item = getTreeWidgetItem(id) ;
item->setIcon(0,_lobby_infos[id].default_icon) ;
} }
void ChatLobbyWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/) void ChatLobbyWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/)

View File

@ -10,6 +10,13 @@ class ChatTabWidget ;
class ChatLobbyDialog ; class ChatLobbyDialog ;
class QTextBrowser ; class QTextBrowser ;
struct ChatLobbyInfoStruct
{
QIcon default_icon ;
ChatLobbyDialog *dialog ;
time_t last_typing_event ;
};
class ChatLobbyWidget : public RsAutoUpdatePage, Ui::ChatLobbyWidget class ChatLobbyWidget : public RsAutoUpdatePage, Ui::ChatLobbyWidget
{ {
Q_OBJECT Q_OBJECT
@ -41,6 +48,9 @@ protected slots:
void unsubscribeChatLobby(ChatLobbyId id) ; void unsubscribeChatLobby(ChatLobbyId id) ;
void updateTypingStatus(ChatLobbyId id) ; void updateTypingStatus(ChatLobbyId id) ;
void resetLobbyTreeIcons() ; void resetLobbyTreeIcons() ;
void updateMessageChanged(ChatLobbyId);
void updatePeerEntering(ChatLobbyId);
void updatePeerLeaving(ChatLobbyId);
private: private:
RSTreeWidgetItemCompareRole *compareRole; RSTreeWidgetItemCompareRole *compareRole;
@ -50,7 +60,7 @@ private:
ChatTabWidget *tabWidget ; ChatTabWidget *tabWidget ;
std::map<ChatLobbyId,ChatLobbyDialog*> _lobby_dialogs ; std::map<ChatLobbyId,ChatLobbyInfoStruct> _lobby_infos ;
QTextBrowser *_lobby_blank_page ; QTextBrowser *_lobby_blank_page ;
std::map<QTreeWidgetItem*,time_t> _icon_changed_map ; std::map<QTreeWidgetItem*,time_t> _icon_changed_map ;

View File

@ -303,6 +303,8 @@ void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
lastUpdateListTime = now; lastUpdateListTime = now;
updateParticipantsList(); updateParticipantsList();
} }
emit messageReceived(id()) ;
} }
/** /**
@ -477,9 +479,11 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname,
switch (event_type) { switch (event_type) {
case RS_CHAT_LOBBY_EVENT_PEER_LEFT: case RS_CHAT_LOBBY_EVENT_PEER_LEFT:
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(str), ChatWidget::TYPE_SYSTEM); ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(str), ChatWidget::TYPE_SYSTEM);
emit peerLeft(id()) ;
break; break;
case RS_CHAT_LOBBY_EVENT_PEER_JOINED: case RS_CHAT_LOBBY_EVENT_PEER_JOINED:
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(str), ChatWidget::TYPE_SYSTEM); ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(str), ChatWidget::TYPE_SYSTEM);
emit peerJoined(id()) ;
break; break;
case RS_CHAT_LOBBY_EVENT_PEER_STATUS: case RS_CHAT_LOBBY_EVENT_PEER_STATUS:
ui.chatWidget->updateStatusString(nickname + " %1", str); ui.chatWidget->updateStatusString(nickname + " %1", str);

View File

@ -52,6 +52,9 @@ private slots:
signals: signals:
void lobbyLeave(ChatLobbyId) ; void lobbyLeave(ChatLobbyId) ;
void typingEventReceived(ChatLobbyId) ; void typingEventReceived(ChatLobbyId) ;
void messageReceived(ChatLobbyId) ;
void peerJoined(ChatLobbyId) ;
void peerLeft(ChatLobbyId) ;
protected: protected:
/** Default constructor */ /** Default constructor */

View File

@ -453,6 +453,7 @@
<file>images/thumb-default-video.png</file> <file>images/thumb-default-video.png</file>
<file>images/user/add_user24.png</file> <file>images/user/add_user24.png</file>
<file>images/user/add_user48.png</file> <file>images/user/add_user48.png</file>
<file>images/user/remove_user24.png</file>
<file>images/user/deny_user48.png</file> <file>images/user/deny_user48.png</file>
<file>images/user/friends24.png</file> <file>images/user/friends24.png</file>
<file>images/user/friend_suggestion16.png</file> <file>images/user/friend_suggestion16.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB