From b6b5fa5cd6f7e04e7d2569a1e082fd00574c2b1e Mon Sep 17 00:00:00 2001 From: thunder2 Date: Tue, 31 Aug 2010 17:13:52 +0000 Subject: [PATCH] Changed the chat service from a timer tick from the gui to a service tick. Created a new notifier for new chat available - NOTIFY_LIST_CHAT. Removed the QTimer in PeersDialog and connect the signal. Created news feed for public chat (prework of defnax, need still some gui changes) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3413 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsiface.h | 1 + libretroshare/src/retroshare/rsmsgs.h | 6 +- libretroshare/src/rsserver/p3msgs.cc | 49 +-- libretroshare/src/rsserver/p3msgs.h | 6 +- libretroshare/src/services/p3chatservice.cc | 86 ++++- libretroshare/src/services/p3chatservice.h | 27 +- retroshare-gui/src/RetroShare.pro | 3 + retroshare-gui/src/gui/NewsFeed.cpp | 11 +- retroshare-gui/src/gui/NewsFeed.h | 2 +- retroshare-gui/src/gui/PeersDialog.cpp | 165 +++++----- .../src/gui/chat/PopupChatDialog.cpp | 6 +- retroshare-gui/src/gui/feeds/ChatMsgItem.cpp | 261 ++++++++++++++++ retroshare-gui/src/gui/feeds/ChatMsgItem.h | 72 +++++ retroshare-gui/src/gui/feeds/ChatMsgItem.ui | 294 ++++++++++++++++++ retroshare-gui/src/gui/notifyqt.cpp | 6 + retroshare-gui/src/gui/notifyqt.h | 5 +- .../src/gui/settings/NotifyPage.cpp | 6 +- retroshare-gui/src/main.cpp | 1 + 18 files changed, 832 insertions(+), 175 deletions(-) create mode 100644 retroshare-gui/src/gui/feeds/ChatMsgItem.cpp create mode 100644 retroshare-gui/src/gui/feeds/ChatMsgItem.h create mode 100644 retroshare-gui/src/gui/feeds/ChatMsgItem.ui diff --git a/libretroshare/src/retroshare/rsiface.h b/libretroshare/src/retroshare/rsiface.h index d30b109d6..9aba35f2e 100644 --- a/libretroshare/src/retroshare/rsiface.h +++ b/libretroshare/src/retroshare/rsiface.h @@ -227,6 +227,7 @@ const int NOTIFY_LIST_DIRLIST_LOCAL = 9; const int NOTIFY_LIST_DIRLIST_FRIENDS = 10; const int NOTIFY_LIST_FORUMLIST_LOCKED = 11; // use connect with Qt::QueuedConnection const int NOTIFY_LIST_MESSAGE_TAGS = 12; +const int NOTIFY_LIST_CHAT = 13; const int NOTIFY_TYPE_SAME = 0x01; const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */ diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 0f865ea27..e2cb48f9f 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -127,7 +127,6 @@ class ChatInfo public: std::string rsid; unsigned int chatflags; - std::string name; std::wstring msg; }; @@ -175,9 +174,8 @@ virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0; /****************************************/ /* Chat */ -virtual bool chatAvailable() = 0; -virtual bool ChatSend(ChatInfo &ci) = 0; -virtual bool getNewChat(std::list &chats) = 0; +virtual bool ChatSend(ChatInfo &ci) = 0; +virtual bool getNewChat(std::list &chats) = 0; virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ; virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 81b01fa52..a854490db 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -159,56 +159,9 @@ void p3Msgs::sendStatusString(const std::string& peer_id,const std::string& stat mChatSrv->sendStatusString(peer_id,status_string); } -bool p3Msgs::chatAvailable() -{ - return mChatSrv->receivedItems(); -} - bool p3Msgs::getNewChat(std::list &chats) { - /* get any messages and push them to iface */ - - // get the items from the list. - std::list clist = mChatSrv -> getChatQueue(); - if (clist.size() < 1) - { - return false; - } - - std::list::iterator it; - for(it = clist.begin(); it != clist.end(); it++) - { - ChatInfo ci; - initRsChatInfo((*it), ci); - chats.push_back(ci); - delete (*it); - } - return true; -} - -/**** HELPER FNS For Chat/Msg/Channel Lists ************ - * - * The iface->Mutex is required to be locked - * for intAddChannel / intAddChannelMsg. - */ - -void p3Msgs::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i) -{ - i.rsid = c -> PeerId(); - i.name = rsPeers->getPeerName(c -> PeerId()); - i.chatflags = 0 ; - i.msg = c -> message; - - if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE) - { - i.chatflags |= RS_CHAT_PRIVATE; - //std::cerr << "RsServer::initRsChatInfo() Chat Private!!!"; - } - else - { - i.chatflags |= RS_CHAT_PUBLIC; - //std::cerr << "RsServer::initRsChatInfo() Chat Public!!!"; - } + return mChatSrv->getChatQueue(chats); } void p3Msgs::getOwnAvatarData(unsigned char *& data,int& size) diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 68dc30244..e46f028f5 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -107,9 +107,9 @@ class p3Msgs: public RsMsgs /****************************************/ /* Chat */ /*! - * @return whether chat is available + * sends chat (public and private) + * @param ci chat info */ - virtual bool chatAvailable(); virtual bool ChatSend(ChatInfo &ci); /*! @@ -135,8 +135,6 @@ class p3Msgs: public RsMsgs private: - void initRsChatInfo(RsChatMsgItem *c, ChatInfo &i); - p3MsgService *mMsgSrv; p3ChatService *mChatSrv; }; diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index e908d4cd4..5d9a548ec 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -52,6 +52,10 @@ p3ChatService::p3ChatService(p3ConnectMgr *cm) int p3ChatService::tick() { + if (receivedItems()) { + receiveChatQueue(); + } + return 0; } @@ -277,24 +281,24 @@ int p3ChatService::sendPrivateChat( std::wstring msg, std::string id) return 1; } -std::list p3ChatService::getChatQueue() +void p3ChatService::receiveChatQueue() { + bool changed = false; + time_t now = time(NULL); - RsItem *item ; - std::list ilist; - + while(NULL != (item=recvItem())) { #ifdef CHAT_DEBUG - std::cerr << "p3ChatService::getChatQueue() Item:" << (void*)item << std::endl ; + std::cerr << "p3ChatService::receiveChatQueue() Item:" << (void*)item << std::endl ; #endif RsChatMsgItem *ci = dynamic_cast(item) ; if(ci != NULL) // real chat message { #ifdef CHAT_DEBUG - std::cerr << "p3ChatService::getChatQueue() Item:"; + std::cerr << "p3ChatService::receiveChatQueue() Item:"; std::cerr << std::endl; ci->print(std::cerr); std::cerr << std::endl; @@ -318,9 +322,9 @@ std::list p3ChatService::getChatQueue() std::map::const_iterator it = _avatars.find(ci->PeerId()) ; - #ifdef CHAT_DEBUG +#ifdef CHAT_DEBUG std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ; - #endif +#endif // has avatar. Return it strait away. // if(it!=_avatars.end() && it->second->_peer_is_new) @@ -329,9 +333,22 @@ std::list p3ChatService::getChatQueue() ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ; } - ci->recvTime = now; - ilist.push_back(ci); // don't delete the item !! + if ((ci->chatFlags & RS_CHAT_FLAG_PRIVATE) == 0) { + std::string message; + message.assign(ci->message.begin(), ci->message.end()); + getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId(), message, ""); + } + + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + ci->recvTime = now; + ilist.push_back(ci); // don't delete the item !! + } /* UNLOCK */ + + changed = true; } + continue ; } @@ -385,7 +402,54 @@ std::list p3ChatService::getChatQueue() } } - return ilist; + if (changed) { + rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT, NOTIFY_TYPE_ADD); + } +} + +bool p3ChatService::getChatQueue(std::list &chats) +{ + /* get any messages and push them to iface */ + + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + // get the items from the list. + if (ilist.size() == 0) + { + return false; + } + + std::list::iterator it; + while (ilist.size()) + { + RsChatMsgItem *c = ilist.front(); + ilist.pop_front(); + + ChatInfo ci; + initRsChatInfo(c, ci); + chats.push_back(ci); + + delete c; + } + return true; +} + +void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i) +{ + i.rsid = c -> PeerId(); + i.chatflags = 0 ; + i.msg = c -> message; + + if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE) + { + i.chatflags |= RS_CHAT_PRIVATE; + //std::cerr << "RsServer::initRsChatInfo() Chat Private!!!"; + } + else + { + i.chatflags |= RS_CHAT_PUBLIC; + //std::cerr << "RsServer::initRsChatInfo() Chat Public!!!"; + } } void p3ChatService::setOwnCustomStateString(const std::string& s) diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index d80e61015..7e88869ef 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -27,15 +27,13 @@ #ifndef SERVICE_CHAT_HEADER #define SERVICE_CHAT_HEADER - - #include #include #include "serialiser/rsmsgitems.h" #include "services/p3service.h" #include "pqi/p3connmgr.h" - +#include "retroshare/rsmsgs.h" //!The basic Chat service. /** @@ -50,6 +48,13 @@ class p3ChatService: public p3Service, public p3Config p3ChatService(p3ConnectMgr *cm); /* overloaded */ + /*! + * This retrieves all chat msg items and also (important!) + * processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned + * (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status + * : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar + * @see NotifyBase + */ virtual int tick(); virtual int status(); @@ -112,13 +117,9 @@ class p3ChatService: public p3Service, public p3Config /*! - * This retrieves all chat msg items and also (important!) - * processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned - * (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status - * : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar - * @see NotifyBase + * This retrieves all chat msg items */ - std::list getChatQueue(); + bool getChatQueue(std::list &chats); /************* from p3Config *******************/ virtual RsSerialiser *setupSerialiser() ; @@ -135,6 +136,12 @@ class p3ChatService: public p3Service, public p3Config class AvatarInfo ; class StateStringInfo ; + // Receive chat queue + void receiveChatQueue(); + + void initRsChatInfo(RsChatMsgItem *c, ChatInfo &i); + + /// Send avatar info to peer in jpeg format. void sendAvatarJpegData(const std::string& peer_id) ; @@ -156,6 +163,8 @@ class p3ChatService: public p3Service, public p3Config p3ConnectMgr *mConnMgr; + std::list ilist; + AvatarInfo *_own_avatar ; std::map _avatars ; diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index ef9188752..341f6badc 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -285,6 +285,7 @@ HEADERS += rshare.h \ gui/feeds/ForumMsgItem.h \ gui/feeds/PeerItem.h \ gui/feeds/MsgItem.h \ + gui/feeds/ChatMsgItem.h \ gui/feeds/ChanNewItem.h \ gui/feeds/ChanMsgItem.h \ gui/feeds/SubFileItem.h \ @@ -360,6 +361,7 @@ FORMS += gui/StartDialog.ui \ gui/feeds/ForumMsgItem.ui \ gui/feeds/PeerItem.ui \ gui/feeds/MsgItem.ui \ + gui/feeds/ChatMsgItem.ui \ gui/feeds/ChanNewItem.ui \ gui/feeds/ChanMsgItem.ui \ gui/feeds/SubFileItem.ui \ @@ -486,6 +488,7 @@ SOURCES += main.cpp \ gui/feeds/ForumMsgItem.cpp \ gui/feeds/PeerItem.cpp \ gui/feeds/MsgItem.cpp \ + gui/feeds/ChatMsgItem.cpp \ gui/feeds/ChanNewItem.cpp \ gui/feeds/ChanMsgItem.cpp \ gui/feeds/SubFileItem.cpp \ diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index b164c0c05..d2b49a28d 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -37,6 +37,7 @@ #include "feeds/MsgItem.h" #include "feeds/PeerItem.h" +#include "feeds/ChatMsgItem.h" #include "settings/rsharesettings.h" #include "chat/PopupChatDialog.h" @@ -49,6 +50,7 @@ const uint32_t NEWSFEED_CHANMSGLIST = 0x0005; const uint32_t NEWSFEED_BLOGNEWLIST = 0x0006; const uint32_t NEWSFEED_BLOGMSGLIST = 0x0007; const uint32_t NEWSFEED_MESSAGELIST = 0x0008; +const uint32_t NEWSFEED_CHATMSGLIST = 0x0009; /***** * #define NEWS_DEBUG 1 @@ -371,8 +373,15 @@ void NewsFeed::addFeedItemChatNew(RsFeedItem &fi) std::cerr << "NewsFeed::addFeedItemChatNew()"; std::cerr << std::endl; #endif -} + /* make new widget */ + ChatMsgItem *cm = new ChatMsgItem(this, NEWSFEED_CHATMSGLIST, fi.mId1, fi.mId2, true); + + /* store in forum list */ + + /* add to layout */ + verticalLayout->insertWidget(0, cm); +} void NewsFeed::addFeedItemMessage(RsFeedItem &fi) { diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index b78e5db0a..93bb23bed 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -30,6 +30,7 @@ class RsFeedItem; class ForumNewItem; class ChanMsgItem; +class ChatMsgItem; class NewsFeed : public MainPage, public FeedHolder, private Ui::NewsFeed { @@ -66,7 +67,6 @@ private: void addFeedItemChatNew(RsFeedItem &fi); void addFeedItemMessage(RsFeedItem &fi); void addFeedItemFilesNew(RsFeedItem &fi); -; QLayout *mLayout; diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 7741cf837..d1fd82a32 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -226,10 +226,6 @@ PeersDialog::PeersDialog(QWidget *parent) _underline = false; - QTimer *timer = new QTimer(this); - timer->connect(timer, SIGNAL(timeout()), this, SLOT(insertChat())); - timer->start(500); /* half a second */ - QMenu *menu = new QMenu(); menu->addAction(ui.actionAdd_Friend); menu->addSeparator(); @@ -1073,103 +1069,97 @@ void PeersDialog::updatePeerStatusString(const QString& peer_id,const QString& s void PeersDialog::insertChat() { - if (!rsMsgs->chatAvailable()) - { - #ifdef PEERS_DEBUG - std::cerr << "no chat available." << std::endl ; - #endif - return; - } + std::list newchat; + if (!rsMsgs->getNewChat(newchat)) + { +#ifdef PEERS_DEBUG + std::cerr << "no chat available." << std::endl ; +#endif + return; + } +#ifdef PEERS_DEBUG + std::cerr << "got new chat." << std::endl; +#endif + QTextEdit *msgWidget = ui.msgText; + std::list::iterator it; - std::list newchat; - if (!rsMsgs->getNewChat(newchat)) - { - #ifdef PEERS_DEBUG - std::cerr << "could not get new chat." << std::endl ; - #endif - return; - } - #ifdef PEERS_DEBUG - std::cerr << "got new chat." << std::endl; - #endif - QTextEdit *msgWidget = ui.msgText; - std::list::iterator it; + uint chatflags = Settings->getChatFlags(); - uint chatflags = Settings->getChatFlags(); + /* add in lines at the bottom */ + for(it = newchat.begin(); it != newchat.end(); it++) + { + std::string msg(it->msg.begin(), it->msg.end()); +#ifdef PEERS_DEBUG + std::cerr << "PeersDialog::insertChat(): " << msg << std::endl; +#endif - /* add in lines at the bottom */ - for(it = newchat.begin(); it != newchat.end(); it++) - { - std::string msg(it->msg.begin(), it->msg.end()); - #ifdef PEERS_DEBUG - std::cerr << "PeersDialog::insertChat(): " << msg << std::endl; - #endif + std::string peer_name = rsPeers->getPeerName(it->rsid); - /* are they private? */ - if (it->chatflags & RS_CHAT_PRIVATE) - { - PopupChatDialog *pcd = PopupChatDialog::getPrivateChat(it->rsid, it->name, chatflags); - pcd->addChatMsg(&(*it)); - playsound(); - QApplication::alert(pcd); - continue; - } + /* are they private? */ + if (it->chatflags & RS_CHAT_PRIVATE) + { + PopupChatDialog *pcd = PopupChatDialog::getPrivateChat(it->rsid, peer_name, chatflags); + pcd->addChatMsg(&(*it)); + playsound(); + QApplication::alert(pcd); + continue; + } - std::ostringstream out; - QString extraTxt; + std::ostringstream out; + QString extraTxt; - QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss"); - QString name = QString::fromStdString(it->name); - QString line = "" + timestamp + "" + - "" + " " + name + ""; - QString msgContents = QString::fromStdWString(it->msg); + QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss"); + QString name = QString::fromStdString(peer_name); + QString line = "" + timestamp + "" + + "" + " " + name + ""; + QString msgContents = QString::fromStdWString(it->msg); - //std::cerr << "PeersDialog::insertChat(): 1.11\n"; - historyKeeper.addMessage(name, "THIS", msgContents); - //std::cerr << "PeersDialog::insertChat(): 1.12\n"; - extraTxt += line; + //std::cerr << "PeersDialog::insertChat(): 1.11\n"; + historyKeeper.addMessage(name, "THIS", msgContents); + //std::cerr << "PeersDialog::insertChat(): 1.12\n"; + extraTxt += line; - // notify with a systray icon msg - if(it->rsid != rsPeers->getOwnId()) - { - // This is a trick to translate HTML into text. - QTextEdit editor ; - editor.setHtml(QString::fromStdWString(it->msg)); - QString notifyMsg(QString::fromStdString(it->name)+": "+editor.toPlainText()) ; + // notify with a systray icon msg + if(it->rsid != rsPeers->getOwnId()) + { + // This is a trick to translate HTML into text. + QTextEdit editor ; + editor.setHtml(QString::fromStdWString(it->msg)); + QString notifyMsg(name+": "+editor.toPlainText()) ; - if(notifyMsg.length() > 30) - emit notifyGroupChat(QString("New group chat"), notifyMsg.left(30)+QString("...")); - else - emit notifyGroupChat(QString("New group chat"), notifyMsg); - } + if(notifyMsg.length() > 30) + emit notifyGroupChat(QString("New group chat"), notifyMsg.left(30)+QString("...")); + else + emit notifyGroupChat(QString("New group chat"), notifyMsg); + } - // create a DOM tree object from the message and embed contents with HTML tags - QDomDocument doc; - doc.setContent(msgContents); + // create a DOM tree object from the message and embed contents with HTML tags + QDomDocument doc; + doc.setContent(msgContents); - // embed links - QDomElement body = doc.documentElement(); - RsChat::embedHtml(doc, body, defEmbedAhref); + // embed links + QDomElement body = doc.documentElement(); + RsChat::embedHtml(doc, body, defEmbedAhref); - // embed smileys - Settings->beginGroup("Chat"); - if (Settings->value(QString::fromUtf8("Emoteicons_GroupChat"), true).toBool()) - RsChat::embedHtml(doc, body, defEmbedImg); - Settings->endGroup(); + // embed smileys + Settings->beginGroup("Chat"); + if (Settings->value(QString::fromUtf8("Emoteicons_GroupChat"), true).toBool()) + RsChat::embedHtml(doc, body, defEmbedImg); + Settings->endGroup(); - msgContents = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit - extraTxt += msgContents; + msgContents = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit + extraTxt += msgContents; - if ((msgWidget->verticalScrollBar()->maximum() - 30) < msgWidget->verticalScrollBar()->value() ) { - msgWidget->append(extraTxt); - } else { - //the vertical scroll is not at the bottom, so just update the text, the scroll will stay at the current position - int scroll = msgWidget->verticalScrollBar()->value(); - msgWidget->setHtml(msgWidget->toHtml() + extraTxt); - msgWidget->verticalScrollBar()->setValue(scroll); - msgWidget->update(); - } - } + if ((msgWidget->verticalScrollBar()->maximum() - 30) < msgWidget->verticalScrollBar()->value() ) { + msgWidget->append(extraTxt); + } else { + //the vertical scroll is not at the bottom, so just update the text, the scroll will stay at the current position + int scroll = msgWidget->verticalScrollBar()->value(); + msgWidget->setHtml(msgWidget->toHtml() + extraTxt); + msgWidget->verticalScrollBar()->setValue(scroll); + msgWidget->update(); + } + } } void PeersDialog::checkChat() @@ -1695,7 +1685,6 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) { const RsConfig &conf = rsiface->getConfig(); ci.rsid = conf.ownId; - ci.name = conf.ownName; rsiface->unlockData(); /* Unlock Interface */ } diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 654e10d10..14385f85d 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -457,7 +457,7 @@ void PopupChatDialog::addChatMsg(ChatInfo *ci) } QString timestamp = "[" + QDateTime::currentDateTime().toString("hh:mm:ss") + "]"; - QString name = QString::fromStdString(ci ->name); + QString name = QString::fromStdString(rsPeers->getPeerName(ci->rsid)); QString message = QString::fromStdWString(ci -> msg); //replace http://, https:// and www. with links @@ -536,7 +536,6 @@ void PopupChatDialog::sendChat() const RsConfig &conf = rsiface->getConfig(); ci.rsid = conf.ownId; - ci.name = conf.ownName; rsiface->unlockData(); /* Unlock Interface */ } @@ -552,7 +551,6 @@ std::cout << "PopupChatDialog:sendChat " << styleHtm.toStdString() << std::endl; /* put proper destination */ ci.rsid = dialogId; - ci.name = dialogName; rsMsgs -> ChatSend(ci); chatWidget ->clear(); @@ -1002,7 +1000,6 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file) const RsConfig &conf = rsiface->getConfig(); ci.rsid = conf.ownId; - ci.name = conf.ownName; rsiface->unlockData(); /* Unlock Interface */ } @@ -1030,7 +1027,6 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file) /* put proper destination */ ci.rsid = dialogId; - ci.name = dialogName; rsMsgs -> ChatSend(ci); } diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp b/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp new file mode 100644 index 000000000..157771287 --- /dev/null +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp @@ -0,0 +1,261 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2008 Robert Fernie + * + * 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 +#include + +#include "ChatMsgItem.h" +#include "FeedHolder.h" +#include "../RsAutoUpdatePage.h" +#include "gui/msgs/MessageComposer.h" + +#include +#include + +#include + +/***** + * #define DEBUG_ITEM 1 + ****/ + +/** Constructor */ +ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string message, bool isHome) +:QWidget(NULL), mParent(parent), mFeedId(feedId), + mPeerId(peerId), mIsHome(isHome) +{ + /* Invoke the Qt Designer generated object setup routine */ + setupUi(this); + + /* general ones */ + connect( expandButton, SIGNAL( clicked( void ) ), this, SLOT( toggle ( void ) ) ); + connect( clearButton, SIGNAL( clicked( void ) ), this, SLOT( removeItem ( void ) ) ); + + /* specific ones */ + connect( chatButton, SIGNAL( clicked( void ) ), this, SLOT( openChat ( void ) ) ); + connect( msgButton, SIGNAL( clicked( void ) ), this, SLOT( sendMsg ( void ) ) ); + + small(); + updateItemStatic(); + updateItem(); + insertChat(message); +} + +void ChatMsgItem::updateItemStatic() +{ + if (!rsPeers) + return; + + RsPeerDetails details; + if (rsPeers->getPeerDetails(mPeerId, details)) + { + QString title; + titleLabel->setText(title); + + /* set textcolor for peername */ + QString nameStr("%1"); + + /* set Peer name */ + QString peername = QString::fromStdString(details.name); + peernameLabel->setText(nameStr.arg(peername)); + } + else + { + chatButton->setEnabled(false); + msgButton->setEnabled(false); + } + + /* fill in */ +#ifdef DEBUG_ITEM + std::cerr << "ChatMsgItem::updateItemStatic()"; + std::cerr << std::endl; +#endif + + if (mIsHome) + { + /* disable buttons */ + clearButton->setEnabled(false); + //gotoButton->setEnabled(false); + + /* disable buttons */ + clearButton->hide(); + } +} + +void ChatMsgItem::updateItem() +{ + if (!rsPeers) + return; + + /* fill in */ +#ifdef DEBUG_ITEM + std::cerr << "ChatMsgItem::updateItem()"; + std::cerr << std::endl; +#endif + + if(!RsAutoUpdatePage::eventsLocked()) { + RsPeerDetails details; + if (!rsPeers->getPeerDetails(mPeerId, details)) + { + return; + } + + /* do buttons */ + chatButton->setEnabled(details.state & RS_PEER_STATE_CONNECTED); + if (details.state & RS_PEER_STATE_FRIEND) + { + msgButton->setEnabled(true); + } + else + { + msgButton->setEnabled(false); + } + } + + /* slow Tick */ + int msec_rate = 10129; + + loadAvatar(); + + QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) )); + return; +} + +void ChatMsgItem::insertChat(std::string &message) +{ +#ifdef DEBUG_ITEM + std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl; +#endif + + QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss"); + lastLabel->setText(timestamp); + + chatText_label->setText(QString::fromStdString(message)); +} + + +void ChatMsgItem::small() +{ + expandFrame->hide(); +} + +void ChatMsgItem::toggle() +{ + if (expandFrame->isHidden()) + { + expandFrame->show(); + expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png"))); + expandButton->setToolTip("Hide"); + } + else + { + expandFrame->hide(); + expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); + expandButton->setToolTip("Expand"); + } +} + + +void ChatMsgItem::removeItem() +{ +#ifdef DEBUG_ITEM + std::cerr << "ChatMsgItem::removeItem()"; + std::cerr << std::endl; +#endif + hide(); + if (mParent) + { + mParent->deleteFeedItem(this, mFeedId); + } +} + + +void ChatMsgItem::gotoHome() +{ +#ifdef DEBUG_ITEM + std::cerr << "ChatMsgItem::gotoHome()"; + std::cerr << std::endl; +#endif +} + +/*********** SPECIFIC FUNCTIOSN ***********************/ + + +void ChatMsgItem::sendMsg() +{ +#ifdef DEBUG_ITEM + std::cerr << "ChatMsgItem::sendMsg()"; + std::cerr << std::endl; +#endif + + if (mParent) + { + //mParent->openMsg(FEEDHOLDER_MSG_MESSAGE, mPeerId, ""); + + MessageComposer *nMsgDialog = new MessageComposer(); + nMsgDialog->newMsg(); + + nMsgDialog->addRecipient( mPeerId ) ; + nMsgDialog->show(); + nMsgDialog->activateWindow(); + + /* window will destroy itself! */ + } +} + + +void ChatMsgItem::openChat() +{ +#ifdef DEBUG_ITEM + std::cerr << "ChatMsgItem::openChat()"; + std::cerr << std::endl; +#endif + if (mParent) + { + mParent->openChat(mPeerId); + } +} + +void ChatMsgItem::loadAvatar() +{ + + unsigned char *data = NULL; + int size = 0 ; + + rsMsgs->getAvatarData(mPeerId,data,size); + + + if(size != 0) + { + // set the image + QPixmap pix ; + pix.loadFromData(data,size,"PNG") ; + avatar_label->setPixmap(pix); + delete[] data ; + + } + else + { + avatar_label->setPixmap(QPixmap(":/images/user/personal64.png")); + } +} + + diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.h b/retroshare-gui/src/gui/feeds/ChatMsgItem.h new file mode 100644 index 000000000..3dd6afb95 --- /dev/null +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.h @@ -0,0 +1,72 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2008 Robert Fernie + * + * 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 _CHATMSG_ITEM_DIALOG_H +#define _CHATMSG_ITEM_DIALOG_H + +#include "ui_ChatMsgItem.h" +#include + + +class FeedHolder; + + +class ChatMsgItem : public QWidget, private Ui::ChatMsgItem +{ + Q_OBJECT + +public: + /** Default Constructor */ + ChatMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string message, bool isHome); + + /** Default Destructor */ + + void updateItemStatic(); + void small(); + void loadAvatar(); + + +private slots: + /* default stuff */ + void gotoHome(); + void removeItem(); + void toggle(); + + void sendMsg(); + void openChat(); + + void updateItem(); + +private: + void insertChat(std::string &message); + + FeedHolder *mParent; + uint32_t mFeedId; + + std::string mPeerId; + + bool mIsHome; +}; + + + +#endif + diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.ui b/retroshare-gui/src/gui/feeds/ChatMsgItem.ui new file mode 100644 index 000000000..c7ea86014 --- /dev/null +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.ui @@ -0,0 +1,294 @@ + + + ChatMsgItem + + + + 0 + 0 + 652 + 193 + + + + Form + + + + 6 + + + + + + 0 + 0 + + + + QFrame#frame{border: 2px solid #FCE5A1; + background-color: #FEF6DE; +border-radius: 10px} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 70 + 70 + + + + + 70 + 70 + + + + QLabel#avatar_label{border: 2px solid #FCE5A1; + +} + + + + + + 0 + + + + + + + + + + Peer Name + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 0 + 0 + + + + + 75 + true + true + + + + Connected + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + + Qt::Horizontal + + + + 190 + 13 + + + + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Expand + + + + + + + :/images/edit_add24.png:/images/edit_add24.png + + + + + + + + 0 + 0 + + + + Remove Item + + + + + + + :/images/close_normal.png:/images/close_normal.png + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 388 + 21 + + + + + + + + + 0 + 0 + + + + Send Mail + + + Write Message + + + + :/images/mail_send.png:/images/mail_send.png + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + + 0 + 0 + + + + Chat + + + Start Chat + + + + :/images/chat.png:/images/chat.png + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + TextLabel + + + + + + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index 330ce7ebf..0c9878bd1 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -224,6 +224,12 @@ void NotifyQt::notifyListChange(int list, int type) #endif emit forumsChanged(); // use connect with Qt::QueuedConnection break; + case NOTIFY_LIST_CHAT: +#ifdef NOTIFY_DEBUG + std::cerr << "received chat changed" << std::endl ; +#endif + emit chatChanged(); + break; default: break; } diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index f2afeaad1..68d63bad7 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -70,8 +70,9 @@ class NotifyQt: public QObject, public NotifyBase void ownStatusMessageChanged() const ; void errorOccurred(int,int,const QString&) const ; void diskFull(int,int) const ; - void peerStatusChanged(const QString& /* peer_id */, int /* status */); - void peerStatusChangedSummary() const; + void peerStatusChanged(const QString& /* peer_id */, int /* status */); + void peerStatusChangedSummary() const; + void chatChanged() const ; public slots: diff --git a/retroshare-gui/src/gui/settings/NotifyPage.cpp b/retroshare-gui/src/gui/settings/NotifyPage.cpp index 4275efbd0..819a65ac1 100755 --- a/retroshare-gui/src/gui/settings/NotifyPage.cpp +++ b/retroshare-gui/src/gui/settings/NotifyPage.cpp @@ -96,6 +96,8 @@ NotifyPage::save(QString &errmsg) newsflags |= RS_FEED_TYPE_CHAT; if (ui.notify_Messages->isChecked()) newsflags |= RS_FEED_TYPE_MSG; + if (ui.notify_Chat->isChecked()) + newsflags |= RS_FEED_TYPE_CHAT; if (ui.chat_NewWindow->isChecked()) chatflags |= RS_CHAT_OPEN_NEW; @@ -136,6 +138,7 @@ void NotifyPage::load() ui.notify_Blogs->setChecked(newsflags & RS_FEED_TYPE_BLOG); ui.notify_Chat->setChecked(newsflags & RS_FEED_TYPE_CHAT); ui.notify_Messages->setChecked(newsflags & RS_FEED_TYPE_MSG); + ui.notify_Chat->setChecked(newsflags & RS_FEED_TYPE_CHAT); ui.chat_NewWindow->setChecked(chatflags & RS_CHAT_OPEN_NEW); ui.chat_Reopen->setChecked(chatflags & RS_CHAT_REOPEN); @@ -144,8 +147,7 @@ void NotifyPage::load() ui.systray_GroupChat->setChecked(Settings->getDisplayTrayGroupChat()); /* disable ones that don't work yet */ - ui.notify_Chat->setEnabled(false); - //ui.popup_NewChat->setEnabled(false); + } diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index fc3f3ec3c..7fd9005ec 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -176,6 +176,7 @@ int main(int argc, char *argv[]) QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool) )) ; QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ; QObject::connect(notify,SIGNAL(friendsChanged()) ,w->peersDialog ,SLOT(insertPeers() )) ; + QObject::connect(notify,SIGNAL(chatChanged()) ,w->peersDialog ,SLOT(insertChat() )); QObject::connect(notify,SIGNAL(neighborsChanged()) ,w->networkDialog ,SLOT(insertConnect() )) ; QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ; QObject::connect(notify,SIGNAL(messagesTagsChanged()) ,w->messagesDialog ,SLOT(messagesTagsChanged() )) ;