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

@ -55,9 +55,10 @@ class ftServer ;
class ConfigPage ;
class RsPQIService ;
class RsAutoUpdatePage ;
class PopupChatDialog_WidgetsHolder ;
class SoundEvents;
class FeedNotify;
class ChatWidget;
class ChatWidgetHolder;
// Plugin API version. Not used yet, but will be in the future the
// main value that decides for compatibility.
@ -143,8 +144,8 @@ class RsPlugin
virtual std::string qt_transfers_tab_name()const { return "Tab" ; } // Tab name
virtual void qt_sound_events(SoundEvents &/*events*/) const { } // Sound events
// provide buttons for the PopupChatDialog
virtual PopupChatDialog_WidgetsHolder *qt_allocate_new_popup_chat_dialog_widgets() const { return NULL ; }
// Provide buttons for the ChatWidget
virtual ChatWidgetHolder *qt_get_chat_widget_holder(ChatWidget */*chatWidget*/) const { return NULL ; }
virtual QTranslator *qt_translator(QApplication * /* app */, const QString& /* languageCode */, const QString& /* externalDir */ ) const { return NULL ; }

View File

@ -32,7 +32,7 @@ SOURCES = services/p3vors.cc \
gui/SpeexProcessor.cpp \
gui/audiodevicehelper.cpp \
gui/VoipStatistics.cpp \
gui/AudioPopupChatDialog.cpp \
gui/AudioChatWidgetHolder.cpp \
gui/PluginGUIHandler.cpp \
gui/PluginNotifier.cpp \
VOIPPlugin.cpp
@ -45,7 +45,7 @@ HEADERS = services/p3vors.h \
gui/SpeexProcessor.h \
gui/audiodevicehelper.h \
gui/VoipStatistics.h \
gui/AudioPopupChatDialog.h \
gui/AudioChatWidgetHolder.h \
gui/PluginGUIHandler.h \
gui/PluginNotifier.h \
interface/rsvoip.h \

View File

@ -12,10 +12,11 @@
#include "gui/VoipStatistics.h"
#include "gui/AudioInputConfig.h"
#include "gui/AudioPopupChatDialog.h"
#include "gui/AudioChatWidgetHolder.h"
#include "gui/PluginGUIHandler.h"
#include "gui/PluginNotifier.h"
#include "gui/SoundManager.h"
#include "gui/chat/ChatWidget.h"
#define IMAGE_VOIP ":/images/talking_on.svg"
@ -106,17 +107,25 @@ QDialog *VOIPPlugin::qt_about_page() const
return about_dialog ;
}
PopupChatDialog_WidgetsHolder *VOIPPlugin::qt_allocate_new_popup_chat_dialog_widgets() const
ChatWidgetHolder *VOIPPlugin::qt_get_chat_widget_holder(ChatWidget *chatWidget) const
{
AudioPopupChatDialogWidgetsHolder *ap = new AudioPopupChatDialogWidgetsHolder() ;
switch (chatWidget->chatType()) {
case ChatWidget::CHATTYPE_PRIVATE:
return new AudioChatWidgetHolder(chatWidget);
case ChatWidget::CHATTYPE_UNKNOWN:
case ChatWidget::CHATTYPE_LOBBY:
case ChatWidget::CHATTYPE_DISTANT:
break;
}
return ap ;
return NULL;
}
std::string VOIPPlugin::qt_transfers_tab_name() const
{
return QObject::tr("RTT Statistics").toUtf8().constData() ;
}
RsAutoUpdatePage *VOIPPlugin::qt_transfers_tab() const
{
return new VoipStatistics ;

View File

@ -18,7 +18,7 @@ class VOIPPlugin: public RsPlugin
virtual QDialog *qt_about_page() const ;
virtual RsAutoUpdatePage *qt_transfers_tab() const ;
virtual std::string qt_transfers_tab_name() const ;
virtual PopupChatDialog_WidgetsHolder *qt_allocate_new_popup_chat_dialog_widgets() const ;
virtual ChatWidgetHolder *qt_get_chat_widget_holder(ChatWidget *chatWidget) const ;
virtual QIcon *qt_icon() const;
virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const;

View File

@ -1,11 +1,15 @@
#include <QToolButton>
#include <QPropertyAnimation>
#include <QIcon>
#include "AudioPopupChatDialog.h"
#include "AudioChatWidgetHolder.h"
#include <gui/audiodevicehelper.h>
#include "interface/rsvoip.h"
#include "gui/SoundManager.h"
#include "util/HandleRichText.h"
#include "gui/common/StatusDefs.h"
#include "gui/chat/ChatWidget.h"
#include <retroshare/rsstatus.h>
#define CALL_START ":/images/call-start-22.png"
@ -13,7 +17,8 @@
#define CALL_HOLD ":/images/call-hold-22.png"
AudioPopupChatDialogWidgetsHolder::AudioPopupChatDialogWidgetsHolder()
AudioChatWidgetHolder::AudioChatWidgetHolder(ChatWidget *chatWidget)
: QObject(), ChatWidgetHolder(chatWidget)
{
audioListenToggleButton = new QToolButton ;
audioListenToggleButton->setMinimumSize(QSize(28,28)) ;
@ -21,7 +26,7 @@ AudioPopupChatDialogWidgetsHolder::AudioPopupChatDialogWidgetsHolder()
audioListenToggleButton->setText(QString()) ;
audioListenToggleButton->setToolTip(tr("Mute yourself"));
std::cerr << "****** VOIPLugin: Creating new AudioPopupChatDialog !!" << std::endl;
std::cerr << "****** VOIPLugin: Creating new AudioChatWidgetHolder !!" << std::endl;
QIcon icon ;
icon.addPixmap(QPixmap(":/images/audio-volume-muted-22.png")) ;
@ -67,28 +72,23 @@ AudioPopupChatDialogWidgetsHolder::AudioPopupChatDialogWidgetsHolder()
connect(audioMuteCaptureToggleButton, SIGNAL(clicked()), this , SLOT(toggleAudioMuteCapture()));
connect(hangupButton, SIGNAL(clicked()), this , SLOT(hangupCall()));
mChatWidget->addChatBarWidget(audioListenToggleButton) ;
mChatWidget->addChatBarWidget(audioMuteCaptureToggleButton) ;
mChatWidget->addChatBarWidget(hangupButton) ;
outputProcessor = NULL ;
outputDevice = NULL ;
inputProcessor = NULL ;
inputDevice = NULL ;
}
void AudioPopupChatDialogWidgetsHolder::init(const std::string &peerId, const QString &title, ChatWidget* chatWidget)
AudioChatWidgetHolder::~AudioChatWidgetHolder()
{
this->peerId = peerId;
this->chatWidget = chatWidget;
if(inputDevice != NULL)
inputDevice->stop() ;
}
std::vector<QWidget*> AudioPopupChatDialogWidgetsHolder::getWidgets()
{
std::vector<QWidget*> v;
v.push_back(audioListenToggleButton);
v.push_back(audioMuteCaptureToggleButton);
v.push_back(hangupButton);
return v;
}
void AudioPopupChatDialogWidgetsHolder::toggleAudioListen()
void AudioChatWidgetHolder::toggleAudioListen()
{
std::cerr << "******** VOIPLugin: Toggling audio listen!" << std::endl;
if (audioListenToggleButton->isChecked()) {
@ -102,7 +102,7 @@ void AudioPopupChatDialogWidgetsHolder::toggleAudioListen()
}
}
void AudioPopupChatDialogWidgetsHolder::hangupCall()
void AudioChatWidgetHolder::hangupCall()
{
std::cerr << "******** VOIPLugin: Hangup call!" << std::endl;
@ -117,7 +117,7 @@ void AudioPopupChatDialogWidgetsHolder::hangupCall()
audioMuteCaptureToggleButton->setChecked(false);
}
void AudioPopupChatDialogWidgetsHolder::toggleAudioMuteCapture()
void AudioChatWidgetHolder::toggleAudioMuteCapture()
{
std::cerr << "******** VOIPLugin: Toggling audio mute capture!" << std::endl;
if (audioMuteCaptureToggleButton->isChecked()) {
@ -139,8 +139,8 @@ void AudioPopupChatDialogWidgetsHolder::toggleAudioMuteCapture()
connect(inputProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData()));
inputDevice->start(inputProcessor);
if (chatWidget) {
chatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("Outgoing Call is started..."), ChatWidget::TYPE_SYSTEM);
if (mChatWidget) {
mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("Outgoing Call is started..."), ChatWidget::MSGTYPE_SYSTEM);
}
} else {
@ -149,13 +149,10 @@ void AudioPopupChatDialogWidgetsHolder::toggleAudioMuteCapture()
inputDevice->stop();
}
audioMuteCaptureToggleButton->setToolTip(tr("Resume Call"));
}
}
void AudioPopupChatDialogWidgetsHolder::addAudioData(const QString name, QByteArray* array)
void AudioChatWidgetHolder::addAudioData(const QString name, QByteArray* array)
{
if (!audioMuteCaptureToggleButton->isChecked()) {
//launch an animation. Don't launch it if already animating
@ -214,17 +211,18 @@ void AudioPopupChatDialogWidgetsHolder::addAudioData(const QString name, QByteAr
}
}
void AudioPopupChatDialogWidgetsHolder::sendAudioData() {
void AudioChatWidgetHolder::sendAudioData()
{
while(inputProcessor && inputProcessor->hasPendingPackets()) {
QByteArray qbarray = inputProcessor->getNetworkPacket();
RsVoipDataChunk chunk;
chunk.size = qbarray.size();
chunk.data = (void*)qbarray.constData();
rsVoip->sendVoipData(peerId,chunk);
rsVoip->sendVoipData(mChatWidget->getPeerId(),chunk);
}
}
void AudioPopupChatDialogWidgetsHolder::updateStatus(int status)
void AudioChatWidgetHolder::updateStatus(int status)
{
audioListenToggleButton->setEnabled(true);
audioMuteCaptureToggleButton->setEnabled(true);
@ -238,4 +236,3 @@ void AudioPopupChatDialogWidgetsHolder::updateStatus(int status)
break;
}
}

View File

@ -0,0 +1,41 @@
#include <QObject>
#include <QGraphicsEffect>
#include <gui/SpeexProcessor.h>
#include <gui/chat/ChatWidget.h>
class QToolButton;
class QAudioInput;
class QAudioOutput;
#define VOIP_SOUND_INCOMING_CALL "VOIP_incoming_call"
class AudioChatWidgetHolder : public QObject, public ChatWidgetHolder
{
Q_OBJECT
public:
AudioChatWidgetHolder(ChatWidget *chatWidget);
virtual ~AudioChatWidgetHolder();
virtual void updateStatus(int status);
void addAudioData(const QString name, QByteArray* array) ;
private slots:
void toggleAudioListen();
void toggleAudioMuteCapture();
void hangupCall() ;
public slots:
void sendAudioData();
protected:
QAudioInput* inputDevice;
QAudioOutput* outputDevice;
QtSpeex::SpeexInputProcessor* inputProcessor;
QtSpeex::SpeexOutputProcessor* outputProcessor;
QToolButton *audioListenToggleButton ;
QToolButton *audioMuteCaptureToggleButton ;
QToolButton *hangupButton ;
};

View File

@ -1,52 +0,0 @@
#include <QObject>
#include <QGraphicsEffect>
#include <gui/SpeexProcessor.h>
#include <gui/chat/PopupChatDialog.h>
#include <gui/audiodevicehelper.h>
class QToolButton;
#define VOIP_SOUND_INCOMING_CALL "VOIP_incoming_call"
class AudioPopupChatDialogWidgetsHolder: public QObject, public PopupChatDialog_WidgetsHolder
{
Q_OBJECT
public:
AudioPopupChatDialogWidgetsHolder();
virtual void init(const std::string &peerId, const QString &title, ChatWidget* chatWidget);
virtual std::vector<QWidget*> getWidgets();
virtual void updateStatus(int status);
virtual ~AudioPopupChatDialogWidgetsHolder()
{
if(inputDevice != NULL)
inputDevice->stop() ;
}
void addAudioData(const QString name, QByteArray* array) ;
private slots:
void toggleAudioListen();
void toggleAudioMuteCapture();
void hangupCall() ;
public slots:
void sendAudioData();
protected:
QAudioInput* inputDevice;
QAudioOutput* outputDevice;
QtSpeex::SpeexInputProcessor* inputProcessor;
QtSpeex::SpeexOutputProcessor* outputProcessor;
std::string peerId;
ChatWidget* chatWidget;
QToolButton *audioListenToggleButton ;
QToolButton *audioMuteCaptureToggleButton ;
QToolButton *hangupButton ;
};

View File

@ -4,7 +4,8 @@
#include <interface/rsvoip.h>
#include "PluginGUIHandler.h"
#include <gui/chat/ChatDialog.h>
#include <gui/AudioPopupChatDialog.h>
#include <gui/AudioChatWidgetHolder.h>
#include "gui/chat/ChatWidget.h"
void PluginGUIHandler::ReceivedInvitation(const QString& /*peer_id*/)
{
@ -33,29 +34,30 @@ void PluginGUIHandler::ReceivedVoipData(const QString& peer_id)
return ;
}
ChatDialog *cd = ChatDialog::getExistingChat(peer_id.toStdString()) ;
ChatDialog *di = ChatDialog::getExistingChat(peer_id.toStdString()) ;
if (di) {
ChatWidget *cw = di->getChatWidget();
if (cw) {
const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();
PopupChatDialog *pcd = dynamic_cast<PopupChatDialog*>(cd);
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) {
AudioChatWidgetHolder *acwh = dynamic_cast<AudioChatWidgetHolder*>(chatWidgetHolder) ;
if(pcd != NULL)
{
std::vector<PopupChatDialog_WidgetsHolder*> whs = pcd->getWidgets();
for(unsigned int whIndex=0; whIndex<whs.size(); whIndex++)
{
AudioPopupChatDialogWidgetsHolder* apcdwh;
if((apcdwh = dynamic_cast<AudioPopupChatDialogWidgetsHolder*>(whs[whIndex])))
{
for(unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++){
if (acwh) {
for (unsigned int i = 0; i < chunks.size(); ++i) {
for (unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++){
QByteArray qb(reinterpret_cast<const char *>(chunks[chunkIndex].data),chunks[chunkIndex].size);
apcdwh->addAudioData(peer_id,&qb);
acwh->addAudioData(peer_id,&qb);
}
}
break;
}
}
}
}
else
{
} else {
std::cerr << "Error: received audio data for a chat dialog that does not stand Audio (Peer id = " << peer_id.toStdString() << "!" << std::endl;
}
for(unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++){
free(chunks[chunkIndex].data);
}

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 */
@ -87,18 +77,6 @@ void PopupChatDialog::init(const std::string &peerId, const QString &title)
// 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);
}
}
}
/** 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) ;
}