Patch (modified) from Phenom to allow auto-subscribe to chat lobbies

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6466 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-06-29 16:15:33 +00:00
parent 9f88917ac1
commit 7414659bd9
12 changed files with 243 additions and 16 deletions

View file

@ -25,6 +25,8 @@
#define ROLE_ID Qt::UserRole + 1
#define ROLE_SUBSCRIBED Qt::UserRole + 2
#define ROLE_PRIVACYLEVEL Qt::UserRole + 3
#define ROLE_AUTOSUBSCRIBE Qt::UserRole + 4
#define TYPE_FOLDER 0
#define TYPE_LOBBY 1
@ -38,6 +40,7 @@
#define IMAGE_PEER_LEAVING ":images/user/remove_user24.png"
#define IMAGE_TYPING ":images/typing.png"
#define IMAGE_MESSAGE ":images/chat.png"
#define IMAGE_AUTOSUBSCRIBE ":images/accepted16.png"
ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags)
: RsAutoUpdatePage(5000, parent, flags)
@ -138,6 +141,11 @@ void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint)
} else {
contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Subscribe"), this, SLOT(subscribeItem()));
}
if (item->data(COLUMN_DATA, ROLE_AUTOSUBSCRIBE).toBool()) {
contextMnu.addAction(QIcon(IMAGE_AUTOSUBSCRIBE), tr("Remove Auto Subscribe"), this, SLOT(autoSubscribeItem()));
} else {
contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Add Auto Subscribe"), this, SLOT(autoSubscribeItem()));
}
}
if (contextMnu.children().count() == 0) {
@ -152,7 +160,7 @@ void ChatLobbyWidget::lobbyChanged()
updateDisplay();
}
static void updateItem(QTreeWidgetItem *item, ChatLobbyId id, const std::string &name, const std::string &topic, int count, bool subscribed)
static void updateItem(QTreeWidgetItem *item, ChatLobbyId id, const std::string &name, const std::string &topic, int count, bool subscribed, bool autoSubscribe)
{
item->setText(COLUMN_NAME, QString::fromUtf8(name.c_str()));
item->setData(COLUMN_NAME, ROLE_SORT, QString::fromUtf8(name.c_str()));
@ -172,6 +180,7 @@ static void updateItem(QTreeWidgetItem *item, ChatLobbyId id, const std::string
item->setData(COLUMN_DATA, ROLE_ID, (qulonglong)id);
item->setData(COLUMN_DATA, ROLE_SUBSCRIBED, subscribed);
item->setData(COLUMN_DATA, ROLE_AUTOSUBSCRIBE, autoSubscribe);
QColor color = QApplication::palette().color(QPalette::Active, QPalette::Text);
if (!subscribed) {
@ -311,7 +320,23 @@ void ChatLobbyWidget::updateDisplay()
subscribed = true;
}
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed);
bool autoSubscribe = rsMsgs->getLobbyAutoSubscribe(lobby.lobby_id);
if (autoSubscribe && subscribed)
{
if(_lobby_infos.find(lobby.lobby_id) == _lobby_infos.end())
{
if (item == lobbyTreeWidget->currentItem())
{
ChatDialog::chatFriend(vpid) ;
}else{
ChatDialog::chatFriend(vpid,false) ;
}
}
}
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed, autoSubscribe);
}
// time_t now = time(NULL) ;
@ -358,7 +383,9 @@ void ChatLobbyWidget::updateDisplay()
// item->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE));
// }
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.nick_names.size(), true);
bool autoSubscribe = rsMsgs->getLobbyAutoSubscribe(lobby.lobby_id);
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.nick_names.size(), true, autoSubscribe);
}
}
@ -399,11 +426,23 @@ static void subscribeLobby(QTreeWidgetItem *item)
if (rsMsgs->joinVisibleChatLobby(id)) {
std::string vpeer_id;
if (rsMsgs->getVirtualPeerId(id, vpeer_id)) {
ChatDialog::chatFriend(vpeer_id) ;
ChatDialog::chatFriend(vpeer_id,true) ;
}
}
}
void ChatLobbyWidget::autoSubscribeLobby(QTreeWidgetItem *item)
{
if (item == NULL && item->type() != TYPE_LOBBY) {
return;
}
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id);
rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe);
if (!isAutoSubscribe) subscribeLobby(item);
}
void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
{
// show the default blank page.
@ -439,6 +478,11 @@ void ChatLobbyWidget::subscribeItem()
subscribeLobby(lobbyTreeWidget->currentItem());
}
void ChatLobbyWidget::autoSubscribeItem()
{
autoSubscribeLobby(lobbyTreeWidget->currentItem());
}
QTreeWidgetItem *ChatLobbyWidget::getTreeWidgetItem(ChatLobbyId id)
{
for(int p=0;p<2;++p)
@ -539,6 +583,9 @@ void ChatLobbyWidget::unsubscribeChatLobby(ChatLobbyId id)
ChatDialog::closeChat(vpeer_id);
rsMsgs->unsubscribeChatLobby(id);
bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id);
if (isAutoSubscribe) rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe);
}
void ChatLobbyWidget::updateCurrentLobby()
@ -605,7 +652,7 @@ void ChatLobbyWidget::readChatLobbyInvites()
std::string vpid;
if(rsMsgs->getVirtualPeerId((*it).lobby_id,vpid )) {
ChatDialog::chatFriend(vpid);
ChatDialog::chatFriend(vpid,true);
} else {
std::cerr << "No lobby known with id 0x" << std::hex << (*it).lobby_id << std::dec << std::endl;
}

View file

@ -51,8 +51,11 @@ protected slots:
void updateMessageChanged(ChatLobbyId);
void updatePeerEntering(ChatLobbyId);
void updatePeerLeaving(ChatLobbyId);
void autoSubscribeItem();
private:
void autoSubscribeLobby(QTreeWidgetItem *item);
RSTreeWidgetItemCompareRole *compareRole;
QTreeWidgetItem *privateLobbyItem;
QTreeWidgetItem *publicLobbyItem;

View file

@ -95,7 +95,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
ChatLobbyId lobby_id = 0;
if (rsMsgs->isLobbyId(peerId, lobby_id)) {
chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags
// chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags
}
uint32_t distant_peer_status ;
@ -211,7 +211,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
}
}
/*static*/ void ChatDialog::chatFriend(const std::string &peerId)
/*static*/ void ChatDialog::chatFriend(const std::string &peerId, const bool forceFocus)
{
if (peerId.empty()){
return;
@ -222,14 +222,13 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
if(rsMsgs->getDistantChatStatus(peerId,distant_peer_status,distant_chat_pgp_id))
{
getChat(peerId,RS_CHAT_OPEN | RS_CHAT_FOCUS); // use own flags
getChat(peerId, forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN ); // use own flags
return ;
}
ChatLobbyId lid;
if (rsMsgs->isLobbyId(peerId, lid)) {
getChat(peerId, RS_CHAT_OPEN | RS_CHAT_FOCUS);
return;
getChat(peerId, (forceFocus ? (RS_CHAT_OPEN | RS_CHAT_FOCUS) : RS_CHAT_OPEN));
}
RsPeerDetails detail;
@ -245,7 +244,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
if (sslIds.size() == 1) {
// chat with the one ssl id (online or offline)
getChat(sslIds.front(), RS_CHAT_OPEN | RS_CHAT_FOCUS);
getChat(sslIds.front(), forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN);
return;
}
@ -258,7 +257,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
if (onlineIds.size() == 1) {
// chat with the online ssl id
getChat(onlineIds.front(), RS_CHAT_OPEN | RS_CHAT_FOCUS);
getChat(onlineIds.front(), forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN);
return;
}
@ -267,7 +266,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
mb.setWindowIcon(QIcon(":/images/rstray3.png"));
mb.exec();
} else {
getChat(peerId, RS_CHAT_OPEN | RS_CHAT_FOCUS);
getChat(peerId, forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN);
}
}

View file

@ -37,7 +37,7 @@ public:
static ChatDialog *getExistingChat(const std::string &peerId);
static ChatDialog *getChat(const std::string &peerId, uint chatflags);
static void cleanupChat();
static void chatFriend(const std::string &peerId);
static void chatFriend(const std::string &peerId, bool forceFocus = true);
static void closeChat(const std::string &peerId);
static void chatChanged(int list, int type);