mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
0e134d0a92
commit
7b0a6afa56
@ -55,7 +55,7 @@ class ftServer ;
|
||||
class ConfigPage ;
|
||||
class RsPQIService ;
|
||||
class RsAutoUpdatePage ;
|
||||
class PopupChatDialog ;
|
||||
class PopupChatDialog_WidgetsHolder ;
|
||||
class SoundEvents;
|
||||
class FeedNotify;
|
||||
|
||||
@ -143,9 +143,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
|
||||
|
||||
// Any derived class of PopupChatDialog to be used for chat.
|
||||
//
|
||||
virtual PopupChatDialog *qt_allocate_new_popup_chat_dialog() const { return NULL ; }
|
||||
// provide buttons for the PopupChatDialog
|
||||
virtual PopupChatDialog_WidgetsHolder *qt_allocate_new_popup_chat_dialog_widgets() const { return NULL ; }
|
||||
|
||||
virtual QTranslator *qt_translator(QApplication * /* app */, const QString& /* languageCode */, const QString& /* externalDir */ ) const { return NULL ; }
|
||||
|
||||
|
@ -106,9 +106,9 @@ QDialog *VOIPPlugin::qt_about_page() const
|
||||
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 ;
|
||||
}
|
||||
|
@ -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 *qt_allocate_new_popup_chat_dialog() const ;
|
||||
virtual PopupChatDialog_WidgetsHolder *qt_allocate_new_popup_chat_dialog_widgets() const ;
|
||||
|
||||
virtual QIcon *qt_icon() const;
|
||||
virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const;
|
||||
|
@ -13,8 +13,7 @@
|
||||
#define CALL_HOLD ":/images/call-hold-22.png"
|
||||
|
||||
|
||||
AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent)
|
||||
: PopupChatDialog(parent)
|
||||
AudioPopupChatDialogWidgetsHolder::AudioPopupChatDialogWidgetsHolder()
|
||||
{
|
||||
audioListenToggleButton = new QToolButton ;
|
||||
audioListenToggleButton->setMinimumSize(QSize(28,28)) ;
|
||||
@ -68,19 +67,28 @@ AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent)
|
||||
connect(audioMuteCaptureToggleButton, SIGNAL(clicked()), this , SLOT(toggleAudioMuteCapture()));
|
||||
connect(hangupButton, SIGNAL(clicked()), this , SLOT(hangupCall()));
|
||||
|
||||
addChatBarWidget(audioListenToggleButton) ;
|
||||
addChatBarWidget(audioMuteCaptureToggleButton) ;
|
||||
addChatBarWidget(hangupButton) ;
|
||||
|
||||
//ui.chatWidget->resetStatusBar();
|
||||
|
||||
outputProcessor = NULL ;
|
||||
outputDevice = NULL ;
|
||||
inputProcessor = 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;
|
||||
if (audioListenToggleButton->isChecked()) {
|
||||
@ -94,7 +102,7 @@ void AudioPopupChatDialog::toggleAudioListen()
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPopupChatDialog::hangupCall()
|
||||
void AudioPopupChatDialogWidgetsHolder::hangupCall()
|
||||
{
|
||||
std::cerr << "******** VOIPLugin: Hangup call!" << std::endl;
|
||||
|
||||
@ -109,15 +117,13 @@ void AudioPopupChatDialog::hangupCall()
|
||||
audioMuteCaptureToggleButton->setChecked(false);
|
||||
}
|
||||
|
||||
void AudioPopupChatDialog::toggleAudioMuteCapture()
|
||||
void AudioPopupChatDialogWidgetsHolder::toggleAudioMuteCapture()
|
||||
{
|
||||
std::cerr << "******** VOIPLugin: Toggling audio mute capture!" << std::endl;
|
||||
if (audioMuteCaptureToggleButton->isChecked()) {
|
||||
//activate audio output
|
||||
audioListenToggleButton->setChecked(true);
|
||||
audioMuteCaptureToggleButton->setToolTip(tr("Hold Call"));
|
||||
|
||||
ChatWidget *cw = getChatWidget();
|
||||
|
||||
//activate audio input
|
||||
if (!inputProcessor) {
|
||||
@ -133,8 +139,8 @@ void AudioPopupChatDialog::toggleAudioMuteCapture()
|
||||
connect(inputProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData()));
|
||||
inputDevice->start(inputProcessor);
|
||||
|
||||
if (cw) {
|
||||
cw->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("Outgoing Call is started..."), ChatWidget::TYPE_SYSTEM);
|
||||
if (chatWidget) {
|
||||
chatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("Outgoing Call is started..."), ChatWidget::TYPE_SYSTEM);
|
||||
}
|
||||
|
||||
} 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()) {
|
||||
//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()) {
|
||||
QByteArray qbarray = inputProcessor->getNetworkPacket();
|
||||
RsVoipDataChunk chunk;
|
||||
@ -218,7 +224,7 @@ void AudioPopupChatDialog::sendAudioData() {
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPopupChatDialog::updateStatus(int status)
|
||||
void AudioPopupChatDialogWidgetsHolder::updateStatus(int status)
|
||||
{
|
||||
audioListenToggleButton->setEnabled(true);
|
||||
audioMuteCaptureToggleButton->setEnabled(true);
|
||||
@ -231,7 +237,5 @@ void AudioPopupChatDialog::updateStatus(int status)
|
||||
hangupButton->setEnabled(false);
|
||||
break;
|
||||
}
|
||||
|
||||
PopupChatDialog::updateStatus(status) ;
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,18 @@ class QToolButton;
|
||||
|
||||
#define VOIP_SOUND_INCOMING_CALL "VOIP_incoming_call"
|
||||
|
||||
class AudioPopupChatDialog: public PopupChatDialog
|
||||
class AudioPopupChatDialogWidgetsHolder: public QObject, public PopupChatDialog_WidgetsHolder
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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)
|
||||
inputDevice->stop() ;
|
||||
@ -37,7 +41,8 @@ class AudioPopupChatDialog: public PopupChatDialog
|
||||
QtSpeex::SpeexInputProcessor* inputProcessor;
|
||||
QtSpeex::SpeexOutputProcessor* outputProcessor;
|
||||
|
||||
virtual void updateStatus(int status) ;
|
||||
std::string peerId;
|
||||
ChatWidget* chatWidget;
|
||||
|
||||
QToolButton *audioListenToggleButton ;
|
||||
QToolButton *audioMuteCaptureToggleButton ;
|
||||
|
@ -33,18 +33,31 @@ void PluginGUIHandler::ReceivedVoipData(const QString& peer_id)
|
||||
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)
|
||||
for(unsigned int i=0;i<chunks.size();++i)
|
||||
{
|
||||
QByteArray qb(reinterpret_cast<const char *>(chunks[i].data),chunks[i].size) ;
|
||||
adi->addAudioData(peer_id,&qb) ;
|
||||
free(chunks[i].data) ;
|
||||
}
|
||||
else
|
||||
std::cerr << "Error: received audio data for a chat dialog that does not stand Audio (Peer id = " << peer_id.toStdString() << "!" << std::endl;
|
||||
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++){
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,14 +125,14 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
|
||||
} else {
|
||||
RsPeerDetails sslDetails;
|
||||
if (rsPeers->getPeerDetails(peerId, sslDetails)) {
|
||||
|
||||
for(int i=0;i<rsPlugins->nbPlugins();++i)
|
||||
if(rsPlugins->plugin(i) != NULL && (cd = rsPlugins->plugin(i)->qt_allocate_new_popup_chat_dialog()) != NULL)
|
||||
break ;
|
||||
|
||||
if(cd == NULL)
|
||||
cd = new PopupChatDialog();
|
||||
|
||||
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;
|
||||
chatDialogs[peerId] = cd;
|
||||
cd->init(peerId, PeerDefs::nameWithLocation(sslDetails));
|
||||
}
|
||||
|
@ -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)));
|
||||
}
|
||||
|
||||
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)));
|
||||
@ -79,6 +87,18 @@ 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. */
|
||||
@ -86,6 +106,12 @@ 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()
|
||||
@ -239,4 +265,11 @@ void PopupChatDialog::clearOfflineMessages()
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,29 @@
|
||||
|
||||
#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();
|
||||
@ -66,6 +83,7 @@ protected:
|
||||
private:
|
||||
bool manualDelete;
|
||||
std::list<ChatInfo> savedOfflineChat;
|
||||
std::vector<PopupChatDialog_WidgetsHolder*> widgetsHolders;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::PopupChatDialog ui;
|
||||
|
Loading…
Reference in New Issue
Block a user