patch "chatdialog_allow_buttons_from_different_plugins_3" from electron. ChatDialog allows now Buttons from different Plugins.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6979 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2014-01-01 22:25:49 +00:00
parent 0e134d0a92
commit 7b0a6afa56
9 changed files with 122 additions and 50 deletions

View File

@ -55,7 +55,7 @@ class ftServer ;
class ConfigPage ; class ConfigPage ;
class RsPQIService ; class RsPQIService ;
class RsAutoUpdatePage ; class RsAutoUpdatePage ;
class PopupChatDialog ; class PopupChatDialog_WidgetsHolder ;
class SoundEvents; class SoundEvents;
class FeedNotify; class FeedNotify;
@ -143,9 +143,8 @@ class RsPlugin
virtual std::string qt_transfers_tab_name()const { return "Tab" ; } // Tab name virtual std::string qt_transfers_tab_name()const { return "Tab" ; } // Tab name
virtual void qt_sound_events(SoundEvents &/*events*/) const { } // Sound events virtual void qt_sound_events(SoundEvents &/*events*/) const { } // Sound events
// Any derived class of PopupChatDialog to be used for chat. // provide buttons for the PopupChatDialog
// virtual PopupChatDialog_WidgetsHolder *qt_allocate_new_popup_chat_dialog_widgets() const { return NULL ; }
virtual PopupChatDialog *qt_allocate_new_popup_chat_dialog() const { return NULL ; }
virtual QTranslator *qt_translator(QApplication * /* app */, const QString& /* languageCode */, const QString& /* externalDir */ ) const { return NULL ; } virtual QTranslator *qt_translator(QApplication * /* app */, const QString& /* languageCode */, const QString& /* externalDir */ ) const { return NULL ; }

View File

@ -106,9 +106,9 @@ QDialog *VOIPPlugin::qt_about_page() const
return about_dialog ; return about_dialog ;
} }
PopupChatDialog *VOIPPlugin::qt_allocate_new_popup_chat_dialog() const PopupChatDialog_WidgetsHolder *VOIPPlugin::qt_allocate_new_popup_chat_dialog_widgets() const
{ {
AudioPopupChatDialog *ap = new AudioPopupChatDialog() ; AudioPopupChatDialogWidgetsHolder *ap = new AudioPopupChatDialogWidgetsHolder() ;
return ap ; return ap ;
} }

View File

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

View File

@ -13,8 +13,7 @@
#define CALL_HOLD ":/images/call-hold-22.png" #define CALL_HOLD ":/images/call-hold-22.png"
AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent) AudioPopupChatDialogWidgetsHolder::AudioPopupChatDialogWidgetsHolder()
: PopupChatDialog(parent)
{ {
audioListenToggleButton = new QToolButton ; audioListenToggleButton = new QToolButton ;
audioListenToggleButton->setMinimumSize(QSize(28,28)) ; audioListenToggleButton->setMinimumSize(QSize(28,28)) ;
@ -68,19 +67,28 @@ AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent)
connect(audioMuteCaptureToggleButton, SIGNAL(clicked()), this , SLOT(toggleAudioMuteCapture())); connect(audioMuteCaptureToggleButton, SIGNAL(clicked()), this , SLOT(toggleAudioMuteCapture()));
connect(hangupButton, SIGNAL(clicked()), this , SLOT(hangupCall())); connect(hangupButton, SIGNAL(clicked()), this , SLOT(hangupCall()));
addChatBarWidget(audioListenToggleButton) ;
addChatBarWidget(audioMuteCaptureToggleButton) ;
addChatBarWidget(hangupButton) ;
//ui.chatWidget->resetStatusBar();
outputProcessor = NULL ; outputProcessor = NULL ;
outputDevice = NULL ; outputDevice = NULL ;
inputProcessor = NULL ; inputProcessor = NULL ;
inputDevice = NULL ; inputDevice = NULL ;
} }
void AudioPopupChatDialog::toggleAudioListen() void AudioPopupChatDialogWidgetsHolder::init(const std::string &peerId, const QString &title, ChatWidget* chatWidget)
{
this->peerId = peerId;
this->chatWidget = chatWidget;
}
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()
{ {
std::cerr << "******** VOIPLugin: Toggling audio listen!" << std::endl; std::cerr << "******** VOIPLugin: Toggling audio listen!" << std::endl;
if (audioListenToggleButton->isChecked()) { if (audioListenToggleButton->isChecked()) {
@ -94,7 +102,7 @@ void AudioPopupChatDialog::toggleAudioListen()
} }
} }
void AudioPopupChatDialog::hangupCall() void AudioPopupChatDialogWidgetsHolder::hangupCall()
{ {
std::cerr << "******** VOIPLugin: Hangup call!" << std::endl; std::cerr << "******** VOIPLugin: Hangup call!" << std::endl;
@ -109,15 +117,13 @@ void AudioPopupChatDialog::hangupCall()
audioMuteCaptureToggleButton->setChecked(false); audioMuteCaptureToggleButton->setChecked(false);
} }
void AudioPopupChatDialog::toggleAudioMuteCapture() void AudioPopupChatDialogWidgetsHolder::toggleAudioMuteCapture()
{ {
std::cerr << "******** VOIPLugin: Toggling audio mute capture!" << std::endl; std::cerr << "******** VOIPLugin: Toggling audio mute capture!" << std::endl;
if (audioMuteCaptureToggleButton->isChecked()) { if (audioMuteCaptureToggleButton->isChecked()) {
//activate audio output //activate audio output
audioListenToggleButton->setChecked(true); audioListenToggleButton->setChecked(true);
audioMuteCaptureToggleButton->setToolTip(tr("Hold Call")); audioMuteCaptureToggleButton->setToolTip(tr("Hold Call"));
ChatWidget *cw = getChatWidget();
//activate audio input //activate audio input
if (!inputProcessor) { if (!inputProcessor) {
@ -133,8 +139,8 @@ void AudioPopupChatDialog::toggleAudioMuteCapture()
connect(inputProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData())); connect(inputProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData()));
inputDevice->start(inputProcessor); inputDevice->start(inputProcessor);
if (cw) { if (chatWidget) {
cw->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("Outgoing Call is started..."), ChatWidget::TYPE_SYSTEM); chatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("Outgoing Call is started..."), ChatWidget::TYPE_SYSTEM);
} }
} else { } else {
@ -149,7 +155,7 @@ void AudioPopupChatDialog::toggleAudioMuteCapture()
} }
void AudioPopupChatDialog::addAudioData(const QString name, QByteArray* array) void AudioPopupChatDialogWidgetsHolder::addAudioData(const QString name, QByteArray* array)
{ {
if (!audioMuteCaptureToggleButton->isChecked()) { if (!audioMuteCaptureToggleButton->isChecked()) {
//launch an animation. Don't launch it if already animating //launch an animation. Don't launch it if already animating
@ -208,7 +214,7 @@ void AudioPopupChatDialog::addAudioData(const QString name, QByteArray* array)
} }
} }
void AudioPopupChatDialog::sendAudioData() { void AudioPopupChatDialogWidgetsHolder::sendAudioData() {
while(inputProcessor && inputProcessor->hasPendingPackets()) { while(inputProcessor && inputProcessor->hasPendingPackets()) {
QByteArray qbarray = inputProcessor->getNetworkPacket(); QByteArray qbarray = inputProcessor->getNetworkPacket();
RsVoipDataChunk chunk; RsVoipDataChunk chunk;
@ -218,7 +224,7 @@ void AudioPopupChatDialog::sendAudioData() {
} }
} }
void AudioPopupChatDialog::updateStatus(int status) void AudioPopupChatDialogWidgetsHolder::updateStatus(int status)
{ {
audioListenToggleButton->setEnabled(true); audioListenToggleButton->setEnabled(true);
audioMuteCaptureToggleButton->setEnabled(true); audioMuteCaptureToggleButton->setEnabled(true);
@ -231,7 +237,5 @@ void AudioPopupChatDialog::updateStatus(int status)
hangupButton->setEnabled(false); hangupButton->setEnabled(false);
break; break;
} }
PopupChatDialog::updateStatus(status) ;
} }

View File

@ -8,14 +8,18 @@ class QToolButton;
#define VOIP_SOUND_INCOMING_CALL "VOIP_incoming_call" #define VOIP_SOUND_INCOMING_CALL "VOIP_incoming_call"
class AudioPopupChatDialog: public PopupChatDialog class AudioPopupChatDialogWidgetsHolder: public QObject, public PopupChatDialog_WidgetsHolder
{ {
Q_OBJECT Q_OBJECT
public: public:
AudioPopupChatDialog(QWidget *parent = NULL); AudioPopupChatDialogWidgetsHolder();
virtual ~AudioPopupChatDialog() 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) if(inputDevice != NULL)
inputDevice->stop() ; inputDevice->stop() ;
@ -37,7 +41,8 @@ class AudioPopupChatDialog: public PopupChatDialog
QtSpeex::SpeexInputProcessor* inputProcessor; QtSpeex::SpeexInputProcessor* inputProcessor;
QtSpeex::SpeexOutputProcessor* outputProcessor; QtSpeex::SpeexOutputProcessor* outputProcessor;
virtual void updateStatus(int status) ; std::string peerId;
ChatWidget* chatWidget;
QToolButton *audioListenToggleButton ; QToolButton *audioListenToggleButton ;
QToolButton *audioMuteCaptureToggleButton ; QToolButton *audioMuteCaptureToggleButton ;

View File

@ -33,18 +33,31 @@ void PluginGUIHandler::ReceivedVoipData(const QString& peer_id)
return ; return ;
} }
ChatDialog *di = ChatDialog::getExistingChat(peer_id.toStdString()) ; ChatDialog *cd = ChatDialog::getExistingChat(peer_id.toStdString()) ;
AudioPopupChatDialog *adi = dynamic_cast<AudioPopupChatDialog*>(di) ; PopupChatDialog *pcd = dynamic_cast<PopupChatDialog*>(cd);
if(adi != NULL) if(pcd != NULL)
for(unsigned int i=0;i<chunks.size();++i) {
{ std::vector<PopupChatDialog_WidgetsHolder*> whs = pcd->getWidgets();
QByteArray qb(reinterpret_cast<const char *>(chunks[i].data),chunks[i].size) ; for(unsigned int whIndex=0; whIndex<whs.size(); whIndex++)
adi->addAudioData(peer_id,&qb) ; {
free(chunks[i].data) ; AudioPopupChatDialogWidgetsHolder* apcdwh;
} if((apcdwh = dynamic_cast<AudioPopupChatDialogWidgetsHolder*>(whs[whIndex])))
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++){
QByteArray qb(reinterpret_cast<const char *>(chunks[chunkIndex].data),chunks[chunkIndex].size);
apcdwh->addAudioData(peer_id,&qb);
}
}
}
}
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

@ -125,14 +125,14 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
} else { } else {
RsPeerDetails sslDetails; RsPeerDetails sslDetails;
if (rsPeers->getPeerDetails(peerId, sslDetails)) { if (rsPeers->getPeerDetails(peerId, sslDetails)) {
PopupChatDialog* pcd = new PopupChatDialog();
for(int i=0;i<rsPlugins->nbPlugins();++i) PopupChatDialog_WidgetsHolder *wh = NULL;
if(rsPlugins->plugin(i) != NULL && (cd = rsPlugins->plugin(i)->qt_allocate_new_popup_chat_dialog()) != NULL) for(int i=0;i<rsPlugins->nbPlugins();++i){
break ; if(rsPlugins->plugin(i) != NULL && (wh = rsPlugins->plugin(i)->qt_allocate_new_popup_chat_dialog_widgets()) != NULL){
pcd->addWidgets(wh);
if(cd == NULL) }
cd = new PopupChatDialog(); }
cd = pcd;
chatDialogs[peerId] = cd; chatDialogs[peerId] = cd;
cd->init(peerId, PeerDefs::nameWithLocation(sslDetails)); cd->init(peerId, PeerDefs::nameWithLocation(sslDetails));
} }

View File

@ -51,6 +51,14 @@ 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))); 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) void PopupChatDialog::init(const std::string &peerId, const QString &title)
{ {
connect(ui.chatWidget, SIGNAL(statusChanged(int)), this, SLOT(statusChanged(int))); connect(ui.chatWidget, SIGNAL(statusChanged(int)), this, SLOT(statusChanged(int)));
@ -79,6 +87,18 @@ void PopupChatDialog::init(const std::string &peerId, const QString &title)
// load settings // load settings
processSettings(true); 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. */ /** Destructor. */
@ -86,6 +106,12 @@ PopupChatDialog::~PopupChatDialog()
{ {
// save settings // save settings
processSettings(false); 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() ChatWidget *PopupChatDialog::getChatWidget()
@ -239,4 +265,11 @@ void PopupChatDialog::clearOfflineMessages()
void PopupChatDialog::statusChanged(int status) void PopupChatDialog::statusChanged(int status)
{ {
updateStatus(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,12 +28,29 @@
#include <retroshare/rsmsgs.h> #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 class PopupChatDialog : public ChatDialog
{ {
Q_OBJECT Q_OBJECT
friend class ChatDialog; friend class ChatDialog;
public:
virtual void addWidgets(PopupChatDialog_WidgetsHolder *wh);
virtual std::vector<PopupChatDialog_WidgetsHolder*> getWidgets();
private slots: private slots:
void showAvatarFrame(bool show); void showAvatarFrame(bool show);
void clearOfflineMessages(); void clearOfflineMessages();
@ -66,6 +83,7 @@ protected:
private: private:
bool manualDelete; bool manualDelete;
std::list<ChatInfo> savedOfflineChat; std::list<ChatInfo> savedOfflineChat;
std::vector<PopupChatDialog_WidgetsHolder*> widgetsHolders;
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::PopupChatDialog ui; Ui::PopupChatDialog ui;