Modified the patch from electron.

Moved the calls to the plugin to ChatWidget for use with all types of chats (private chat, chat lobby and distant chat).
Recompile needed

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6980 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-01-02 00:56:46 +00:00
parent 7b0a6afa56
commit 92fabf4c56
15 changed files with 222 additions and 237 deletions

View file

@ -35,7 +35,6 @@
#include <retroshare/rsiface.h>
#include <retroshare/rsnotify.h>
#include <retroshare/rspeers.h>
#include <retroshare/rsplugin.h>
static std::map<std::string, ChatDialog*> chatDialogs;
@ -125,14 +124,8 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
} else {
RsPeerDetails sslDetails;
if (rsPeers->getPeerDetails(peerId, sslDetails)) {
PopupChatDialog* pcd = new PopupChatDialog();
PopupChatDialog_WidgetsHolder *wh = NULL;
for(int i=0;i<rsPlugins->nbPlugins();++i){
if(rsPlugins->plugin(i) != NULL && (wh = rsPlugins->plugin(i)->qt_allocate_new_popup_chat_dialog_widgets()) != NULL){
pcd->addWidgets(wh);
}
}
cd = pcd;
cd = new PopupChatDialog();
chatDialogs[peerId] = cd;
cd->init(peerId, PeerDefs::nameWithLocation(sslDetails));
}

View file

@ -293,7 +293,7 @@ void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
//std::cerr << "message from rsid " << info.rsid.c_str() << std::endl;
if(!isParticipantMuted(name)) {
ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::MSGTYPE_NORMAL);
emit messageReceived(id()) ;
}
@ -520,12 +520,12 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname,
switch (event_type) {
case RS_CHAT_LOBBY_EVENT_PEER_LEFT:
qsParticipant=str;
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM);
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(RsHtml::plainText(str)), ChatWidget::MSGTYPE_SYSTEM);
emit peerLeft(id()) ;
break;
case RS_CHAT_LOBBY_EVENT_PEER_JOINED:
qsParticipant=str;
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM);
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(RsHtml::plainText(str)), ChatWidget::MSGTYPE_SYSTEM);
emit peerJoined(id()) ;
break;
case RS_CHAT_LOBBY_EVENT_PEER_STATUS:
@ -537,7 +537,7 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname,
break;
case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME:
qsParticipant=str;
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 changed his name to: %2").arg(RsHtml::plainText(nickname), RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM);
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 changed his name to: %2").arg(RsHtml::plainText(nickname), RsHtml::plainText(str)), ChatWidget::MSGTYPE_SYSTEM);
// TODO if a user was muted and changed his name, update mute list, but only, when the muted peer, dont change his name to a other peer in your chat lobby
if (isParticipantMuted(nickname) && !isNicknameInLobby(str)) {

View file

@ -52,6 +52,7 @@
#include <retroshare/rspeers.h>
#include <retroshare/rshistory.h>
#include <retroshare/rsmsgs.h>
#include <retroshare/rsplugin.h>
#include <time.h>
@ -67,7 +68,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
newMessages = false;
typing = false;
peerStatus = 0;
isChatLobby = false;
mChatType = CHATTYPE_UNKNOWN;
firstShow = true;
inChatCharFormatChanged = false;
completer = NULL;
@ -152,6 +153,11 @@ ChatWidget::~ChatWidget()
{
processSettings(false);
/* Cleanup plugin functions */
foreach (ChatWidgetHolder *chatWidgetHolder, mChatWidgetHolder) {
delete(chatWidgetHolder);
}
delete ui;
}
@ -178,10 +184,26 @@ void ChatWidget::init(const std::string &peerId, const QString &title)
ChatLobbyId lid;
if (rsMsgs->isLobbyId(peerId, lid)) {
isChatLobby = true;
chatStyle.setStyleFromSettings(ChatStyle::TYPE_PUBLIC);
mChatType = CHATTYPE_LOBBY;
} else {
uint32_t status;
std::string pgp_id;
if (rsMsgs->getDistantChatStatus(peerId, status, pgp_id)) {
mChatType = CHATTYPE_DISTANT;
} else {
mChatType = CHATTYPE_PRIVATE;
}
}
switch (mChatType) {
case CHATTYPE_UNKNOWN:
case CHATTYPE_PRIVATE:
case CHATTYPE_DISTANT:
chatStyle.setStyleFromSettings(ChatStyle::TYPE_PRIVATE);
break;
case CHATTYPE_LOBBY:
chatStyle.setStyleFromSettings(ChatStyle::TYPE_PUBLIC);
break;
}
currentColor.setNamedColor(PeerSettings->getPrivateChatColor(peerId));
@ -194,7 +216,30 @@ void ChatWidget::init(const std::string &peerId, const QString &title)
// load style
PeerSettings->getStyle(peerId, "ChatWidget", style);
if (!isChatLobby) {
/* Add plugin functions */
int pluginCount = rsPlugins->nbPlugins();
for (int i = 0; i < pluginCount; ++i) {
RsPlugin *plugin = rsPlugins->plugin(i);
if (plugin) {
ChatWidgetHolder *chatWidgetHolder = plugin->qt_get_chat_widget_holder(this);
if (chatWidgetHolder) {
mChatWidgetHolder.push_back(chatWidgetHolder);
}
}
}
uint32_t hist_chat_type;
int messageCount;
if (chatType() == CHATTYPE_LOBBY) {
hist_chat_type = RS_HISTORY_TYPE_LOBBY;
messageCount = Settings->getLobbyChatHistoryCount();
updateTitle();
} else {
hist_chat_type = RS_HISTORY_TYPE_PRIVATE ;
messageCount = Settings->getPrivateChatHistoryCount();
// initialize first status
StatusInfo peerStatusInfo;
// No check of return value. Non existing status info is handled as offline.
@ -204,12 +249,8 @@ void ChatWidget::init(const std::string &peerId, const QString &title)
// initialize first custom state string
QString customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(peerId).c_str());
updatePeersCustomStateString(QString::fromStdString(peerId), customStateString);
} else {
updateTitle();
}
uint32_t hist_chat_type = isChatLobby?RS_HISTORY_TYPE_LOBBY:RS_HISTORY_TYPE_PRIVATE ;
int messageCount = isChatLobby?(Settings->getLobbyChatHistoryCount()):(Settings->getPrivateChatHistoryCount());
if (rsHistory->getEnable(hist_chat_type))
{
@ -222,7 +263,7 @@ void ChatWidget::init(const std::string &peerId, const QString &title)
std::list<HistoryMsg>::iterator historyIt;
for (historyIt = historyMsgs.begin(); historyIt != historyMsgs.end(); historyIt++)
addChatMsg(historyIt->incoming, QString::fromUtf8(historyIt->peerName.c_str()), QDateTime::fromTime_t(historyIt->sendTime), QDateTime::fromTime_t(historyIt->recvTime), QString::fromUtf8(historyIt->message.c_str()), TYPE_HISTORY);
addChatMsg(historyIt->incoming, QString::fromUtf8(historyIt->peerName.c_str()), QDateTime::fromTime_t(historyIt->sendTime), QDateTime::fromTime_t(historyIt->recvTime), QString::fromUtf8(historyIt->message.c_str()), MSGTYPE_HISTORY);
}
}
@ -272,7 +313,7 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
updateStatusTyping();
}
if (isChatLobby) {
if (chatType() == CHATTYPE_LOBBY) {
if (keyEvent->key() == Qt::Key_Tab) {
completeNickname((bool)(keyEvent->modifiers() & Qt::ShiftModifier));
return true; // eat event
@ -524,7 +565,7 @@ void ChatWidget::setWelcomeMessage(QString &text)
ui->textBrowser->setText(text);
}
void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType)
void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, MsgType chatType)
{
#ifdef CHAT_DEBUG
std::cout << "ChatWidget::addChatMsg message : " << message.toStdString() << std::endl;
@ -564,18 +605,18 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime
}
ChatStyle::enumFormatMessage type;
if (chatType == TYPE_OFFLINE) {
if (chatType == MSGTYPE_OFFLINE) {
type = ChatStyle::FORMATMSG_OOUTGOING;
} else if (chatType == TYPE_SYSTEM) {
} else if (chatType == MSGTYPE_SYSTEM) {
type = ChatStyle::FORMATMSG_SYSTEM;
} else if (chatType == TYPE_HISTORY || addDate) {
} else if (chatType == MSGTYPE_HISTORY || addDate) {
lastMsgDate=QDate::currentDate();
type = incoming ? ChatStyle::FORMATMSG_HINCOMING : ChatStyle::FORMATMSG_HOUTGOING;
} else {
type = incoming ? ChatStyle::FORMATMSG_INCOMING : ChatStyle::FORMATMSG_OUTGOING;
}
if (chatType == TYPE_SYSTEM) {
if (chatType == MSGTYPE_SYSTEM) {
formatFlag |= CHAT_FORMATMSG_SYSTEM;
}
@ -587,7 +628,7 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime
resetStatusBar();
if (incoming && chatType == TYPE_NORMAL) {
if (incoming && chatType == MSGTYPE_NORMAL) {
emit newMessage(this);
if (!isActive()) {
@ -697,7 +738,7 @@ void ChatWidget::sendChat()
if (rsMsgs->sendPrivateChat(peerId, msg)) {
QDateTime currentTime = QDateTime::currentDateTime();
addChatMsg(false, name, currentTime, currentTime, QString::fromStdWString(msg), TYPE_NORMAL);
addChatMsg(false, name, currentTime, currentTime, QString::fromStdWString(msg), MSGTYPE_NORMAL);
}
chatWidget->clear();
@ -900,7 +941,7 @@ void ChatWidget::setCurrentFileName(const QString &fileName)
void ChatWidget::updateStatus(const QString &peer_id, int status)
{
if (isChatLobby) {
if (chatType() == CHATTYPE_LOBBY) {
// updateTitle is used
return;
}
@ -961,6 +1002,11 @@ void ChatWidget::updateStatus(const QString &peer_id, int status)
emit infoChanged(this);
emit statusChanged(status);
// Notify all ChatWidgetHolder
foreach (ChatWidgetHolder *chatWidgetHolder, mChatWidgetHolder) {
chatWidgetHolder->updateStatus(status);
}
return;
}
@ -969,7 +1015,7 @@ void ChatWidget::updateStatus(const QString &peer_id, int status)
void ChatWidget::updateTitle()
{
if (!isChatLobby) {
if (!chatType() != CHATTYPE_LOBBY) {
// updateStatus is used
return;
}

View file

@ -35,22 +35,41 @@
class QAction;
class QTextEdit;
class QPushButton;
class ChatWidget;
namespace Ui {
class ChatWidget;
}
// a Container for the logic behind buttons in a PopupChatDialog
// Plugins can implement this interface to provide their own buttons
class ChatWidgetHolder
{
public:
ChatWidgetHolder(ChatWidget *chatWidget) : mChatWidget(chatWidget) {}
virtual ~ChatWidgetHolder() {}
// status comes from notifyPeerStatusChanged
// see rststaus.h for possible values
virtual void updateStatus(int /*status*/) {}
protected:
ChatWidget *mChatWidget;
};
class ChatWidget : public QWidget
{
Q_OBJECT
public:
enum enumChatType { TYPE_NORMAL, TYPE_HISTORY, TYPE_OFFLINE, TYPE_SYSTEM };
enum MsgType { MSGTYPE_NORMAL, MSGTYPE_HISTORY, MSGTYPE_OFFLINE, MSGTYPE_SYSTEM };
enum ChatType { CHATTYPE_UNKNOWN, CHATTYPE_PRIVATE, CHATTYPE_LOBBY, CHATTYPE_DISTANT };
explicit ChatWidget(QWidget *parent = 0);
~ChatWidget();
void init(const std::string &peerId, const QString &title);
ChatType chatType() { return mChatType; }
bool hasNewMessages() { return newMessages; }
bool isTyping() { return typing; }
@ -60,7 +79,7 @@ public:
void removeFromParent(QWidget *oldParent);
void setWelcomeMessage(QString &text);
void addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType);
void addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, MsgType chatType);
void updateStatusString(const QString &statusMask, const QString &statusString);
void addToolsAction(QAction *action);
@ -79,6 +98,8 @@ public:
void setDefaultExtraFileFlags(TransferRequestFlags f) ;
void pasteText(const QString&);
const QList<ChatWidgetHolder*> &chatWidgetHolderList() { return mChatWidgetHolder; }
public slots:
void updateStatus(const QString &peer_id, int status);
@ -151,7 +172,7 @@ private:
bool newMessages;
bool typing;
int peerStatus;
bool isChatLobby;
ChatType mChatType;
time_t lastStatusSendTime;
@ -166,6 +187,8 @@ private:
QCompleter *completer;
QList<ChatWidgetHolder*> mChatWidgetHolder;
Ui::ChatWidget *ui;
};

View file

@ -51,18 +51,8 @@ PopupChatDialog::PopupChatDialog(QWidget *parent, Qt::WindowFlags flags)
connect(NotifyQt::getInstance(), SIGNAL(chatStatusChanged(const QString&, const QString&, bool)), this, SLOT(chatStatusChanged(const QString&, const QString&, bool)));
}
void PopupChatDialog::addWidgets(PopupChatDialog_WidgetsHolder *wh){
widgetsHolders.push_back(wh);
}
std::vector<PopupChatDialog_WidgetsHolder*> PopupChatDialog::getWidgets(){
return widgetsHolders;
}
void PopupChatDialog::init(const std::string &peerId, const QString &title)
{
connect(ui.chatWidget, SIGNAL(statusChanged(int)), this, SLOT(statusChanged(int)));
ChatDialog::init(peerId, title);
/* Hide or show the avatar frames */
@ -85,20 +75,8 @@ void PopupChatDialog::init(const std::string &peerId, const QString &title)
window->addDialog(this);
}
// load settings
processSettings(true);
// Add ChatBarWidgets from Plugins
std::vector<PopupChatDialog_WidgetsHolder*>::iterator it;
for(it = widgetsHolders.begin(); it != widgetsHolders.end(); ++it){
PopupChatDialog_WidgetsHolder *wh = *it;
wh->init(peerId, title, ui.chatWidget);
std::vector<QWidget*> widgetsVector = wh->getWidgets();
std::vector<QWidget*>::iterator it2;
for(it2 = widgetsVector.begin(); it2 != widgetsVector.end(); ++it2){
addChatBarWidget(*it2);
}
}
// load settings
processSettings(true);
}
/** Destructor. */
@ -106,12 +84,6 @@ PopupChatDialog::~PopupChatDialog()
{
// save settings
processSettings(false);
std::vector<PopupChatDialog_WidgetsHolder*>::iterator it;
for(it = widgetsHolders.begin(); it != widgetsHolders.end(); ++it){
PopupChatDialog_WidgetsHolder *wh = *it;
delete wh;
}
}
ChatWidget *PopupChatDialog::getChatWidget()
@ -163,15 +135,10 @@ void PopupChatDialog::addIncomingChatMsg(const ChatInfo& info)
QString message = QString::fromStdWString(info.msg);
QString name = getPeerName(info.rsid) ;
cw->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
cw->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::MSGTYPE_NORMAL);
}
}
void PopupChatDialog::addChatBarWidget(QWidget *w)
{
getChatWidget()->addChatBarWidget(w) ;
}
void PopupChatDialog::onChatChanged(int list, int type)
{
if (list == NOTIFY_LIST_PRIVATE_OUTGOING_CHAT) {
@ -204,7 +171,7 @@ void PopupChatDialog::onChatChanged(int list, int type)
QDateTime recvTime = QDateTime::fromTime_t(it->recvTime);
QString message = QString::fromStdWString(it->msg);
ui.chatWidget->addChatMsg(false, name, sendTime, recvTime, message, ChatWidget::TYPE_OFFLINE);
ui.chatWidget->addChatMsg(false, name, sendTime, recvTime, message, ChatWidget::MSGTYPE_OFFLINE);
}
}
@ -223,7 +190,7 @@ void PopupChatDialog::onChatChanged(int list, int type)
QDateTime recvTime = QDateTime::fromTime_t(it->recvTime);
QString message = QString::fromStdWString(it->msg);
ui.chatWidget->addChatMsg(false, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
ui.chatWidget->addChatMsg(false, name, sendTime, recvTime, message, ChatWidget::MSGTYPE_NORMAL);
}
}
@ -261,15 +228,3 @@ void PopupChatDialog::clearOfflineMessages()
rsMsgs->clearPrivateChatQueue(false, peerId);
manualDelete = false;
}
void PopupChatDialog::statusChanged(int status)
{
updateStatus(status);
// Notify Plugins
std::vector<PopupChatDialog_WidgetsHolder*>::iterator it;
for(it = widgetsHolders.begin(); it != widgetsHolders.end(); ++it){
PopupChatDialog_WidgetsHolder *wh = *it;
wh->updateStatus(status);
}
}

View file

@ -28,34 +28,16 @@
#include <retroshare/rsmsgs.h>
// a Container for the logic behind buttons in a PopupChatDialog
// Plugins can implement this interface to provide their own buttons
class PopupChatDialog_WidgetsHolder{
public:
virtual ~PopupChatDialog_WidgetsHolder(){}
virtual void init(const std::string &peerId, const QString &title, ChatWidget* chatWidget) = 0;
virtual std::vector<QWidget*> getWidgets() = 0;
// status comes from notifyPeerStatusChanged
// see rststaus.h for possible values
virtual void updateStatus(int status) = 0;
};
class PopupChatDialog : public ChatDialog
{
Q_OBJECT
friend class ChatDialog;
public:
virtual void addWidgets(PopupChatDialog_WidgetsHolder *wh);
virtual std::vector<PopupChatDialog_WidgetsHolder*> getWidgets();
private slots:
void showAvatarFrame(bool show);
void clearOfflineMessages();
void chatStatusChanged(const QString &peerId, const QString &statusString, bool isPrivateChat);
void statusChanged(int);
protected:
/** Default constructor */
@ -73,9 +55,6 @@ protected:
void processSettings(bool load);
// used by plugins
void addChatBarWidget(QWidget *w) ;
protected:
virtual void addIncomingChatMsg(const ChatInfo& info);
virtual void onChatChanged(int list, int type);
@ -83,7 +62,6 @@ protected:
private:
bool manualDelete;
std::list<ChatInfo> savedOfflineChat;
std::vector<PopupChatDialog_WidgetsHolder*> widgetsHolders;
/** Qt Designer generated object */
Ui::PopupChatDialog ui;

View file

@ -50,7 +50,7 @@ PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WindowFlags
_update_timer->start() ;
addChatBarWidget(_status_label) ;
getChatWidget()->addChatBarWidget(_status_label) ;
updateDisplay() ;
}
@ -146,11 +146,3 @@ QString PopupDistantChatDialog::getPeerName(const std::string& id) const
else
return ChatDialog::getPeerName(id) ;
}