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
This commit is contained in:
thunder2 2010-08-31 17:13:52 +00:00
parent c7c6f6d36a
commit b6b5fa5cd6
18 changed files with 832 additions and 175 deletions

View File

@ -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 */

View File

@ -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<ChatInfo> &chats) = 0;
virtual bool ChatSend(ChatInfo &ci) = 0;
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;

View File

@ -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<ChatInfo> &chats)
{
/* get any messages and push them to iface */
// get the items from the list.
std::list<RsChatMsgItem *> clist = mChatSrv -> getChatQueue();
if (clist.size() < 1)
{
return false;
}
std::list<RsChatMsgItem *>::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)

View File

@ -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;
};

View File

@ -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<RsChatMsgItem *> p3ChatService::getChatQueue()
void p3ChatService::receiveChatQueue()
{
bool changed = false;
time_t now = time(NULL);
RsItem *item ;
std::list<RsChatMsgItem *> 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<RsChatMsgItem*>(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<RsChatMsgItem *> p3ChatService::getChatQueue()
std::map<std::string,AvatarInfo *>::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<RsChatMsgItem *> 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<RsChatMsgItem *> p3ChatService::getChatQueue()
}
}
return ilist;
if (changed) {
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT, NOTIFY_TYPE_ADD);
}
}
bool p3ChatService::getChatQueue(std::list<ChatInfo> &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<RsChatMsgItem *>::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)

View File

@ -27,15 +27,13 @@
#ifndef SERVICE_CHAT_HEADER
#define SERVICE_CHAT_HEADER
#include <list>
#include <string>
#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<RsChatMsgItem *> getChatQueue();
bool getChatQueue(std::list<ChatInfo> &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<RsChatMsgItem *> ilist;
AvatarInfo *_own_avatar ;
std::map<std::string,AvatarInfo *> _avatars ;

View File

@ -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 \

View File

@ -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)
{

View File

@ -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;

View File

@ -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<ChatInfo> 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<ChatInfo>::iterator it;
std::list<ChatInfo> 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<ChatInfo>::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 = "<span style=\"color:#C00000\">" + timestamp + "</span>" +
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
QString msgContents = QString::fromStdWString(it->msg);
QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss");
QString name = QString::fromStdString(peer_name);
QString line = "<span style=\"color:#C00000\">" + timestamp + "</span>" +
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
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 */
}

View File

@ -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 <a href> 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);
}

View File

@ -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 <QDateTime>
#include <QTimer>
#include "ChatMsgItem.h"
#include "FeedHolder.h"
#include "../RsAutoUpdatePage.h"
#include "gui/msgs/MessageComposer.h"
#include <retroshare/rsmsgs.h>
#include <retroshare/rspeers.h>
#include <sstream>
/*****
* #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("<span style=\"font-size:14pt; font-weight:500;"
"color:#990033;\">%1</span>");
/* 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"));
}
}

View File

@ -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 <stdint.h>
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

View File

@ -0,0 +1,294 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ChatMsgItem</class>
<widget class="QWidget" name="ChatMsgItem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>652</width>
<height>193</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">QFrame#frame{border: 2px solid #FCE5A1;
background-color: #FEF6DE;
border-radius: 10px}</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" rowspan="2">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="avatar_label">
<property name="minimumSize">
<size>
<width>70</width>
<height>70</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>70</width>
<height>70</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QLabel#avatar_label{border: 2px solid #FCE5A1;
}</string>
</property>
<property name="text">
<string/>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="peernameLabel">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>Peer Name</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="titleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<italic>true</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Connected</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>190</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lastLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="expandButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Expand</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/edit_add24.png</normaloff>:/images/edit_add24.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remove Item</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/close_normal.png</normaloff>:/images/close_normal.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>388</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="msgButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Send Mail</string>
</property>
<property name="text">
<string>Write Message</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/mail_send.png</normaloff>:/images/mail_send.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="chatButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Chat</string>
</property>
<property name="text">
<string>Start Chat</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/chat.png</normaloff>:/images/chat.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<widget class="QFrame" name="expandFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="chatText_label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -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;
}

View File

@ -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:

View File

@ -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);
}

View File

@ -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() )) ;