diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp index 2c8c5d97f..a9ca8648d 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.cpp +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -10,6 +10,7 @@ #include "common/RSTreeWidgetItem.h" #include "notifyqt.h" #include "chat/ChatLobbyDialog.h" +#include "chat/ChatLobbyUserNotify.h" #include "util/HandleRichText.h" #include "util/QtVersion.h" #include @@ -186,6 +187,16 @@ ChatLobbyWidget::~ChatLobbyWidget() } } +UserNotify *ChatLobbyWidget::getUserNotify(QObject *parent) +{ + ChatLobbyUserNotify *notify = new ChatLobbyUserNotify(parent); + connect(this, SIGNAL(unreadCountChanged(uint)), notify, SLOT(unreadCountChanged(uint))); + + notify->unreadCountChanged(unreadCount()); + + return notify; +} + void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint) { std::cerr << "Creating customPopupMennu" << std::endl; @@ -286,6 +297,7 @@ void ChatLobbyWidget::addChatPage(ChatLobbyDialog *d) _lobby_infos[id].dialog = d ; _lobby_infos[id].default_icon = QIcon() ; _lobby_infos[id].last_typing_event = time(NULL) ; + _lobby_infos[id].unread_count = 0; std::list lobbies; rsMsgs->getChatLobbyList(lobbies); @@ -736,6 +748,7 @@ void ChatLobbyWidget::unsubscribeChatLobby(ChatLobbyId id) { ui.stackedWidget->removeWidget(it->second.dialog) ; _lobby_infos.erase(it) ; + emit unreadCountChanged(unreadCount()); } // Unsubscribe the chat lobby @@ -778,7 +791,10 @@ void ChatLobbyWidget::updateCurrentLobby() int iPrivacyLevel= item->parent()->data(COLUMN_DATA, ROLE_PRIVACYLEVEL).toInt(); QIcon icon = (iPrivacyLevel==RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC) ? QIcon(IMAGE_PUBLIC) : QIcon(IMAGE_PRIVATE); _lobby_infos[id].default_icon = icon ; + _lobby_infos[id].unread_count = 0; item->setIcon(COLUMN_NAME, icon) ; + + emit unreadCountChanged(unreadCount()); } } @@ -796,6 +812,9 @@ void ChatLobbyWidget::updateMessageChanged(ChatLobbyId id) return ; _lobby_infos[id].default_icon = QIcon(IMAGE_MESSAGE) ; + ++_lobby_infos[id].unread_count; + + emit unreadCountChanged(unreadCount()); QTreeWidgetItem *item = getTreeWidgetItem(id) ; @@ -953,3 +972,13 @@ int ChatLobbyWidget::getNumColVisible() return iNumColVis; } +uint ChatLobbyWidget::unreadCount() +{ + uint count = 0; + + for (std::map::iterator it = _lobby_infos.begin(); it != _lobby_infos.end(); ++it) { + count += it->second.unread_count; + } + + return count; +} diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.h b/retroshare-gui/src/gui/ChatLobbyWidget.h index 58caad9ea..e22802317 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.h +++ b/retroshare-gui/src/gui/ChatLobbyWidget.h @@ -17,6 +17,7 @@ struct ChatLobbyInfoStruct QIcon default_icon ; ChatLobbyDialog *dialog ; time_t last_typing_event ; + uint unread_count; }; class ChatLobbyWidget : public RsAutoUpdatePage @@ -34,11 +35,18 @@ public: virtual QString pageName() const { return tr("Chat Lobbies") ; } //MainPage virtual QString helpText() const { return ""; } //MainPage + virtual UserNotify *getUserNotify(QObject *parent); + virtual void updateDisplay(); void setCurrentChatPage(ChatLobbyDialog *) ; // used by ChatLobbyDialog to raise. void addChatPage(ChatLobbyDialog *) ; + uint unreadCount(); + +signals: + void unreadCountChanged(uint unreadCount); + protected slots: void lobbyChanged(); void lobbyTreeWidgetCustomPopupMenu(QPoint); diff --git a/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp b/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp new file mode 100644 index 000000000..6bb7b5c28 --- /dev/null +++ b/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.cpp @@ -0,0 +1,64 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2014 RetroShare Team + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include "ChatLobbyUserNotify.h" +#include "gui/notifyqt.h" +#include "gui/MainWindow.h" + +ChatLobbyUserNotify::ChatLobbyUserNotify(QObject *parent) : + UserNotify(parent) +{ +} + +bool ChatLobbyUserNotify::hasSetting(QString *name, QString *group) +{ + if (name) *name = tr("Chat Lobbies"); + if (group) *group = "ChatLobby"; + + return true; +} + +QIcon ChatLobbyUserNotify::getIcon() +{ + return QIcon(":/images/chat_32.png"); +} + +QIcon ChatLobbyUserNotify::getMainIcon(bool hasNew) +{ + return hasNew ? QIcon(":/images/chat_red24.png") : QIcon(":/images/chat_32.png"); +} + +unsigned int ChatLobbyUserNotify::getNewCount() +{ + return mUnreadCount; +} + +void ChatLobbyUserNotify::iconClicked() +{ + MainWindow::showWindow(MainWindow::ChatLobby); +} + +void ChatLobbyUserNotify::unreadCountChanged(unsigned int unreadCount) +{ + mUnreadCount = unreadCount; + + updateIcon(); +} diff --git a/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.h b/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.h new file mode 100644 index 000000000..5e7d0e034 --- /dev/null +++ b/retroshare-gui/src/gui/chat/ChatLobbyUserNotify.h @@ -0,0 +1,49 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2014 RetroShare Team + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifndef CHATLOBBYUSERNOTIFY_H +#define CHATLOBBYUSERNOTIFY_H + +#include "gui/common/UserNotify.h" + +class ChatLobbyUserNotify : public UserNotify +{ + Q_OBJECT + +public: + ChatLobbyUserNotify(QObject *parent = 0); + + virtual bool hasSetting(QString *name, QString *group); + +public slots: + void unreadCountChanged(uint unreadCount); + +private: + virtual QIcon getIcon(); + virtual QIcon getMainIcon(bool hasNew); + virtual unsigned int getNewCount(); + virtual void iconClicked(); + +private: + uint mUnreadCount; +}; + +#endif // CHATLOBBYUSERNOTIFY_H diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 2bd6b089c..39568a5bc 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -392,6 +392,7 @@ HEADERS += rshare.h \ gui/chat/CreateLobbyDialog.h \ gui/chat/ChatStyle.h \ gui/chat/ChatUserNotify.h \ + gui/chat/ChatLobbyUserNotify.h \ gui/connect/ConfCertDialog.h \ gui/msgs/MessageComposer.h \ gui/msgs/MessageWindow.h \ @@ -724,6 +725,7 @@ SOURCES += main.cpp \ gui/chat/CreateLobbyDialog.cpp \ gui/chat/ChatStyle.cpp \ gui/chat/ChatUserNotify.cpp \ + gui/chat/ChatLobbyUserNotify.cpp \ gui/connect/ConfCertDialog.cpp \ gui/msgs/MessageComposer.cpp \ gui/msgs/MessageWidget.cpp \