mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-07 00:25:16 -04:00
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:
parent
7b0a6afa56
commit
92fabf4c56
15 changed files with 222 additions and 237 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue