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

@ -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));
}

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)));
}
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);
}
}

View file

@ -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;