diff --git a/libretroshare/src/retroshare/rsplugin.h b/libretroshare/src/retroshare/rsplugin.h index 5beff72fd..87ee520a7 100644 --- a/libretroshare/src/retroshare/rsplugin.h +++ b/libretroshare/src/retroshare/rsplugin.h @@ -51,6 +51,7 @@ class ConfigPage ; class RsPQIService ; class RsAutoUpdatePage ; class PopupChatDialog ; +class SoundEvents; // Plugin API version. Not used yet, but will be in the future the // main value that decides for compatibility. @@ -125,6 +126,7 @@ class RsPlugin virtual ConfigPage *qt_config_page() const { return NULL ; } // Config tab to add in config panel. virtual RsAutoUpdatePage *qt_transfers_tab() const { return NULL ; } // Tab to add in transfers, after turtle statistics. 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. // diff --git a/plugins/VOIP/VOIPPlugin.cpp b/plugins/VOIP/VOIPPlugin.cpp index 353ce3824..78236b377 100644 --- a/plugins/VOIP/VOIPPlugin.cpp +++ b/plugins/VOIP/VOIPPlugin.cpp @@ -14,6 +14,7 @@ #include "gui/AudioPopupChatDialog.h" #include "gui/PluginGUIHandler.h" #include "gui/PluginNotifier.h" +#include "gui/SoundManager.h" #define IMAGE_VOIP ":/images/talking_on.svg" @@ -175,4 +176,7 @@ QTranslator* VOIPPlugin::qt_translator(QApplication */*app*/, const QString& lan return NULL; } - +void VOIPPlugin::qt_sound_events(SoundEvents &/*events*/) const +{ +// events.addEvent(QApplication::translate("VOIP", "VOIP"), QApplication::translate("VOIP", "Incoming call"), VOIP_SOUND_INCOMING_CALL); +} diff --git a/plugins/VOIP/VOIPPlugin.h b/plugins/VOIP/VOIPPlugin.h index c237c23b6..bb85c07e1 100644 --- a/plugins/VOIP/VOIPPlugin.h +++ b/plugins/VOIP/VOIPPlugin.h @@ -22,6 +22,7 @@ class VOIPPlugin: public RsPlugin virtual QIcon *qt_icon() const; virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const; + virtual void qt_sound_events(SoundEvents &events) const; virtual void getPluginVersion(int& major,int& minor,int& svn_rev) const ; virtual void setPlugInHandler(RsPluginHandler *pgHandler); diff --git a/plugins/VOIP/gui/AudioPopupChatDialog.cpp b/plugins/VOIP/gui/AudioPopupChatDialog.cpp index 0dfe1dcbe..71135ccf6 100644 --- a/plugins/VOIP/gui/AudioPopupChatDialog.cpp +++ b/plugins/VOIP/gui/AudioPopupChatDialog.cpp @@ -3,6 +3,7 @@ #include #include "AudioPopupChatDialog.h" #include "interface/rsvoip.h" +#include "gui/SoundManager.h" AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent) : PopupChatDialog(parent) @@ -10,7 +11,7 @@ AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent) audioListenToggleButton = new QPushButton ; audioListenToggleButton->setMinimumSize(QSize(28,28)) ; audioListenToggleButton->setMaximumSize(QSize(28,28)) ; - audioListenToggleButton->setText(QString()) ; + audioListenToggleButton->setText(QString()) ; audioListenToggleButton->setToolTip(tr("Mute yourself")); std::cerr << "****** VOIPLugin: Creating new AudioPopupChatDialog !!" << std::endl; @@ -30,7 +31,7 @@ AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent) audioMuteCaptureToggleButton = new QPushButton ; audioMuteCaptureToggleButton->setMinimumSize(QSize(28,28)) ; audioMuteCaptureToggleButton->setMaximumSize(QSize(28,28)) ; - audioMuteCaptureToggleButton->setText(QString()) ; + audioMuteCaptureToggleButton->setText(QString()) ; audioMuteCaptureToggleButton->setToolTip(tr("Deafen yourself")); QIcon icon2 ; @@ -62,7 +63,7 @@ AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent) void AudioPopupChatDialog::toggleAudioListen() { std::cerr << "******** VOIPLugin: Toggling audio listen!" << std::endl; - if (audioListenToggleButton->isChecked()) { + if (audioListenToggleButton->isChecked()) { } else { //audioListenToggleButton->setChecked(false); /*if (outputDevice) { @@ -118,6 +119,8 @@ void AudioPopupChatDialog::addAudioData(const QString name, QByteArray* array) anim->start(); } +// soundManager->play(VOIP_SOUND_INCOMING_CALL); + //TODO make a toaster and a sound for the incoming call return; } diff --git a/plugins/VOIP/gui/AudioPopupChatDialog.h b/plugins/VOIP/gui/AudioPopupChatDialog.h index 06bc38ee1..5410bf6c0 100644 --- a/plugins/VOIP/gui/AudioPopupChatDialog.h +++ b/plugins/VOIP/gui/AudioPopupChatDialog.h @@ -6,6 +6,8 @@ class QPushButton; +#define VOIP_SOUND_INCOMING_CALL "VOIP_incoming_call" + class AudioPopupChatDialog: public PopupChatDialog { Q_OBJECT diff --git a/retroshare-gui/src/gui/SoundManager.cpp b/retroshare-gui/src/gui/SoundManager.cpp index f753b27a6..6c1e102ab 100644 --- a/retroshare-gui/src/gui/SoundManager.cpp +++ b/retroshare-gui/src/gui/SoundManager.cpp @@ -30,16 +30,18 @@ SoundManager *soundManager = NULL; -static QString settingName(SoundManager::Events event) +SoundEvents::SoundEvents() { - switch (event) { - case SoundManager::NEW_CHAT_MESSAGE: - return "NewChatMessage"; - case SoundManager::USER_ONLINE: - return "User_go_Online"; - } +} - return ""; +void SoundEvents::addEvent(const QString &groupName, const QString &eventName, const QString &event) +{ + SoundEventInfo info; + info.mGroupName = groupName; + info.mEventName = eventName; + info.mEvent = event; + + mEventInfos.push_back(info); } void SoundManager::create() @@ -71,47 +73,47 @@ bool SoundManager::isMute() return mute; } -bool SoundManager::eventEnabled(Events event) +bool SoundManager::eventEnabled(const QString &event) { Settings->beginGroup(GROUP_MAIN); Settings->beginGroup(GROUP_ENABLE); - bool enabled = Settings->value(settingName(event), false).toBool(); + bool enabled = Settings->value(event, false).toBool(); Settings->endGroup(); Settings->endGroup(); return enabled; } -void SoundManager::setEventEnabled(Events event, bool enabled) +void SoundManager::setEventEnabled(const QString &event, bool enabled) { Settings->beginGroup(GROUP_MAIN); Settings->beginGroup(GROUP_ENABLE); - Settings->setValue(settingName(event), enabled); + Settings->setValue(event, enabled); Settings->endGroup(); Settings->endGroup(); } -QString SoundManager::eventFilename(Events event) +QString SoundManager::eventFilename(const QString &event) { Settings->beginGroup(GROUP_MAIN); Settings->beginGroup(GROUP_SOUNDFILE); - QString filename = Settings->value(settingName(event)).toString(); + QString filename = Settings->value(event).toString(); Settings->endGroup(); Settings->endGroup(); return filename; } -void SoundManager::setEventFilename(Events event, const QString &filename) +void SoundManager::setEventFilename(const QString &event, const QString &filename) { Settings->beginGroup(GROUP_MAIN); Settings->beginGroup(GROUP_SOUNDFILE); - Settings->setValue(settingName(event), filename); + Settings->setValue(event, filename); Settings->endGroup(); Settings->endGroup(); } -void SoundManager::play(Events event) +void SoundManager::play(const QString &event) { if (isMute() || !QSound::isAvailable() || !eventEnabled(event)) { return; @@ -121,7 +123,6 @@ void SoundManager::play(Events event) playFile(filename); } - void SoundManager::playFile(const QString &filename) { if (filename.isEmpty()) { diff --git a/retroshare-gui/src/gui/SoundManager.h b/retroshare-gui/src/gui/SoundManager.h index b2eba3dec..f02ebe74d 100644 --- a/retroshare-gui/src/gui/SoundManager.h +++ b/retroshare-gui/src/gui/SoundManager.h @@ -24,16 +24,36 @@ #include +#define SOUND_NEW_CHAT_MESSAGE "NewChatMessage" +#define SOUND_USER_ONLINE "User_go_Online" + +class SoundEvents +{ +public: + class SoundEventInfo + { + public: + SoundEventInfo() {} + + public: + QString mGroupName; + QString mEventName; + QString mEvent; + }; + +public: + SoundEvents(); + + void addEvent(const QString &groupName, const QString &eventName, const QString &event); + +public: + QList mEventInfos; +}; + class SoundManager : public QObject { Q_OBJECT -public: - enum Events { - NEW_CHAT_MESSAGE, - USER_ONLINE - }; - public slots: void setMute(bool mute); @@ -45,14 +65,14 @@ public: bool isMute(); - void play(Events event); + void play(const QString &event); void playFile(const QString &filename); - bool eventEnabled(Events event); - void setEventEnabled(Events event, bool enabled); + bool eventEnabled(const QString &event); + void setEventEnabled(const QString &event, bool enabled); - QString eventFilename(Events event); - void setEventFilename(Events event, const QString &filename); + QString eventFilename(const QString &event); + void setEventFilename(const QString &event, const QString &filename); private: SoundManager(); diff --git a/retroshare-gui/src/gui/chat/ChatDialog.cpp b/retroshare-gui/src/gui/chat/ChatDialog.cpp index 336edee0c..45738b92d 100644 --- a/retroshare-gui/src/gui/chat/ChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatDialog.cpp @@ -162,7 +162,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title) { if (list == NOTIFY_LIST_PRIVATE_INCOMING_CHAT && type == NOTIFY_TYPE_ADD) { // play sound when recv a message - soundManager->play(SoundManager::NEW_CHAT_MESSAGE); + soundManager->play(SOUND_NEW_CHAT_MESSAGE); std::list ids; if (rsMsgs->getPrivateChatQueueIds(true, ids)) { diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index 3d0d623b4..555ced86e 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -646,7 +646,7 @@ void NotifyQt::UpdateGUI() } break; case RS_POPUP_CONNECT: - soundManager->play(SoundManager::USER_ONLINE); + soundManager->play(SOUND_USER_ONLINE); if (popupflags & RS_POPUP_CONNECT) { diff --git a/retroshare-gui/src/gui/settings/SoundPage.cpp b/retroshare-gui/src/gui/settings/SoundPage.cpp index 5ab77367f..74e1d702a 100644 --- a/retroshare-gui/src/gui/settings/SoundPage.cpp +++ b/retroshare-gui/src/gui/settings/SoundPage.cpp @@ -23,6 +23,8 @@ #include "rsharesettings.h" #include "util/misc.h" +#include + #define COLUMN_NAME 0 #define COLUMN_FILENAME 1 #define COLUMN_COUNT 2 @@ -66,7 +68,17 @@ SoundPage::~SoundPage() QTreeWidgetItem *SoundPage::addGroup(const QString &name) { - QTreeWidgetItem *item = new QTreeWidgetItem(TYPE_GROUP); + QTreeWidgetItem *item = NULL; + + int count = ui.eventTreeWidget->topLevelItemCount(); + for (int i = 0; i < count; ++i) { + item = ui.eventTreeWidget->topLevelItem(i); + if (item->text(COLUMN_NAME) == name) { + return item; + } + } + + item = new QTreeWidgetItem(TYPE_GROUP); item->setText(COLUMN_NAME, name); ui.eventTreeWidget->insertTopLevelItem(ui.eventTreeWidget->topLevelItemCount(), item); ui.eventTreeWidget->expandItem(item); @@ -74,7 +86,7 @@ QTreeWidgetItem *SoundPage::addGroup(const QString &name) return item; } -QTreeWidgetItem *SoundPage::addItem(QTreeWidgetItem *groupItem, const QString &name, SoundManager::Events event) +QTreeWidgetItem *SoundPage::addItem(QTreeWidgetItem *groupItem, const QString &name, const QString &event) { QTreeWidgetItem *item = new QTreeWidgetItem(TYPE_ITEM); item->setData(COLUMN_DATA, ROLE_EVENT, event); @@ -96,7 +108,7 @@ bool SoundPage::save(QString &/*errmsg*/) itemIterator++; if (item->type() == TYPE_ITEM) { - SoundManager::Events event = (SoundManager::Events) item->data(COLUMN_DATA, ROLE_EVENT).toInt(); + const QString event = item->data(COLUMN_DATA, ROLE_EVENT).toString(); soundManager->setEventEnabled(event, item->checkState(COLUMN_NAME) == Qt::Checked); soundManager->setEventFilename(event, item->text(COLUMN_FILENAME)); } @@ -110,11 +122,34 @@ void SoundPage::load() { ui.eventTreeWidget->clear(); + /* add standard events */ + QTreeWidgetItem *groupItem = addGroup(tr("Friend")); - addItem(groupItem, tr("go Online"), SoundManager::USER_ONLINE); + addItem(groupItem, tr("go Online"), SOUND_USER_ONLINE); groupItem = addGroup(tr("Chatmessage")); - addItem(groupItem, tr("New Msg"), SoundManager::NEW_CHAT_MESSAGE); + addItem(groupItem, tr("New Msg"), SOUND_NEW_CHAT_MESSAGE); + + /* add plugin events */ + int pluginCount = rsPlugins->nbPlugins(); + for (int i = 0; i < pluginCount; ++i) { + RsPlugin *plugin = rsPlugins->plugin(i); + + if (plugin) { + SoundEvents events; + plugin->qt_sound_events(events); + + if (events.mEventInfos.empty()) { + continue; + } + + QList::iterator it; + for (it = events.mEventInfos.begin(); it != events.mEventInfos.end(); ++it) { + groupItem = addGroup(it->mGroupName); + addItem(groupItem, it->mEventName, it->mEvent); + } + } + } ui.eventTreeWidget->resizeColumnToContents(COLUMN_NAME); diff --git a/retroshare-gui/src/gui/settings/SoundPage.h b/retroshare-gui/src/gui/settings/SoundPage.h index ae4fd313f..6a31fcbdd 100644 --- a/retroshare-gui/src/gui/settings/SoundPage.h +++ b/retroshare-gui/src/gui/settings/SoundPage.h @@ -54,7 +54,7 @@ private slots: private: QTreeWidgetItem *addGroup(const QString &name); - QTreeWidgetItem *addItem(QTreeWidgetItem *groupItem, const QString &name, SoundManager::Events event); + QTreeWidgetItem *addItem(QTreeWidgetItem *groupItem, const QString &name, const QString &event); /** Qt Designer generated object */ Ui::SoundPage ui;