mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-22 05:14:31 -04:00
Changed SoundManger to allow the plugins to play sounds.
Added example to VOIP (commented out). git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5709 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
56635e4ce4
commit
232af8e71e
11 changed files with 109 additions and 41 deletions
|
@ -51,6 +51,7 @@ class ConfigPage ;
|
||||||
class RsPQIService ;
|
class RsPQIService ;
|
||||||
class RsAutoUpdatePage ;
|
class RsAutoUpdatePage ;
|
||||||
class PopupChatDialog ;
|
class PopupChatDialog ;
|
||||||
|
class SoundEvents;
|
||||||
|
|
||||||
// Plugin API version. Not used yet, but will be in the future the
|
// Plugin API version. Not used yet, but will be in the future the
|
||||||
// main value that decides for compatibility.
|
// 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 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 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 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.
|
// Any derived class of PopupChatDialog to be used for chat.
|
||||||
//
|
//
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "gui/AudioPopupChatDialog.h"
|
#include "gui/AudioPopupChatDialog.h"
|
||||||
#include "gui/PluginGUIHandler.h"
|
#include "gui/PluginGUIHandler.h"
|
||||||
#include "gui/PluginNotifier.h"
|
#include "gui/PluginNotifier.h"
|
||||||
|
#include "gui/SoundManager.h"
|
||||||
|
|
||||||
#define IMAGE_VOIP ":/images/talking_on.svg"
|
#define IMAGE_VOIP ":/images/talking_on.svg"
|
||||||
|
|
||||||
|
@ -175,4 +176,7 @@ QTranslator* VOIPPlugin::qt_translator(QApplication */*app*/, const QString& lan
|
||||||
return NULL;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ class VOIPPlugin: public RsPlugin
|
||||||
|
|
||||||
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;
|
||||||
|
virtual void qt_sound_events(SoundEvents &events) const;
|
||||||
|
|
||||||
virtual void getPluginVersion(int& major,int& minor,int& svn_rev) const ;
|
virtual void getPluginVersion(int& major,int& minor,int& svn_rev) const ;
|
||||||
virtual void setPlugInHandler(RsPluginHandler *pgHandler);
|
virtual void setPlugInHandler(RsPluginHandler *pgHandler);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include "AudioPopupChatDialog.h"
|
#include "AudioPopupChatDialog.h"
|
||||||
#include "interface/rsvoip.h"
|
#include "interface/rsvoip.h"
|
||||||
|
#include "gui/SoundManager.h"
|
||||||
|
|
||||||
AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent)
|
AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent)
|
||||||
: PopupChatDialog(parent)
|
: PopupChatDialog(parent)
|
||||||
|
@ -118,6 +119,8 @@ void AudioPopupChatDialog::addAudioData(const QString name, QByteArray* array)
|
||||||
anim->start();
|
anim->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// soundManager->play(VOIP_SOUND_INCOMING_CALL);
|
||||||
|
|
||||||
//TODO make a toaster and a sound for the incoming call
|
//TODO make a toaster and a sound for the incoming call
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
||||||
|
#define VOIP_SOUND_INCOMING_CALL "VOIP_incoming_call"
|
||||||
|
|
||||||
class AudioPopupChatDialog: public PopupChatDialog
|
class AudioPopupChatDialog: public PopupChatDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -30,16 +30,18 @@
|
||||||
|
|
||||||
SoundManager *soundManager = NULL;
|
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()
|
void SoundManager::create()
|
||||||
|
@ -71,47 +73,47 @@ bool SoundManager::isMute()
|
||||||
return mute;
|
return mute;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundManager::eventEnabled(Events event)
|
bool SoundManager::eventEnabled(const QString &event)
|
||||||
{
|
{
|
||||||
Settings->beginGroup(GROUP_MAIN);
|
Settings->beginGroup(GROUP_MAIN);
|
||||||
Settings->beginGroup(GROUP_ENABLE);
|
Settings->beginGroup(GROUP_ENABLE);
|
||||||
bool enabled = Settings->value(settingName(event), false).toBool();
|
bool enabled = Settings->value(event, false).toBool();
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
|
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::setEventEnabled(Events event, bool enabled)
|
void SoundManager::setEventEnabled(const QString &event, bool enabled)
|
||||||
{
|
{
|
||||||
Settings->beginGroup(GROUP_MAIN);
|
Settings->beginGroup(GROUP_MAIN);
|
||||||
Settings->beginGroup(GROUP_ENABLE);
|
Settings->beginGroup(GROUP_ENABLE);
|
||||||
Settings->setValue(settingName(event), enabled);
|
Settings->setValue(event, enabled);
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SoundManager::eventFilename(Events event)
|
QString SoundManager::eventFilename(const QString &event)
|
||||||
{
|
{
|
||||||
Settings->beginGroup(GROUP_MAIN);
|
Settings->beginGroup(GROUP_MAIN);
|
||||||
Settings->beginGroup(GROUP_SOUNDFILE);
|
Settings->beginGroup(GROUP_SOUNDFILE);
|
||||||
QString filename = Settings->value(settingName(event)).toString();
|
QString filename = Settings->value(event).toString();
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
|
|
||||||
return filename;
|
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_MAIN);
|
||||||
Settings->beginGroup(GROUP_SOUNDFILE);
|
Settings->beginGroup(GROUP_SOUNDFILE);
|
||||||
Settings->setValue(settingName(event), filename);
|
Settings->setValue(event, filename);
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
Settings->endGroup();
|
Settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::play(Events event)
|
void SoundManager::play(const QString &event)
|
||||||
{
|
{
|
||||||
if (isMute() || !QSound::isAvailable() || !eventEnabled(event)) {
|
if (isMute() || !QSound::isAvailable() || !eventEnabled(event)) {
|
||||||
return;
|
return;
|
||||||
|
@ -121,7 +123,6 @@ void SoundManager::play(Events event)
|
||||||
playFile(filename);
|
playFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SoundManager::playFile(const QString &filename)
|
void SoundManager::playFile(const QString &filename)
|
||||||
{
|
{
|
||||||
if (filename.isEmpty()) {
|
if (filename.isEmpty()) {
|
||||||
|
|
|
@ -24,16 +24,36 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#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<SoundEventInfo> mEventInfos;
|
||||||
|
};
|
||||||
|
|
||||||
class SoundManager : public QObject
|
class SoundManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
|
||||||
enum Events {
|
|
||||||
NEW_CHAT_MESSAGE,
|
|
||||||
USER_ONLINE
|
|
||||||
};
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setMute(bool mute);
|
void setMute(bool mute);
|
||||||
|
|
||||||
|
@ -45,14 +65,14 @@ public:
|
||||||
|
|
||||||
bool isMute();
|
bool isMute();
|
||||||
|
|
||||||
void play(Events event);
|
void play(const QString &event);
|
||||||
void playFile(const QString &filename);
|
void playFile(const QString &filename);
|
||||||
|
|
||||||
bool eventEnabled(Events event);
|
bool eventEnabled(const QString &event);
|
||||||
void setEventEnabled(Events event, bool enabled);
|
void setEventEnabled(const QString &event, bool enabled);
|
||||||
|
|
||||||
QString eventFilename(Events event);
|
QString eventFilename(const QString &event);
|
||||||
void setEventFilename(Events event, const QString &filename);
|
void setEventFilename(const QString &event, const QString &filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SoundManager();
|
SoundManager();
|
||||||
|
|
|
@ -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) {
|
if (list == NOTIFY_LIST_PRIVATE_INCOMING_CHAT && type == NOTIFY_TYPE_ADD) {
|
||||||
// play sound when recv a message
|
// play sound when recv a message
|
||||||
soundManager->play(SoundManager::NEW_CHAT_MESSAGE);
|
soundManager->play(SOUND_NEW_CHAT_MESSAGE);
|
||||||
|
|
||||||
std::list<std::string> ids;
|
std::list<std::string> ids;
|
||||||
if (rsMsgs->getPrivateChatQueueIds(true, ids)) {
|
if (rsMsgs->getPrivateChatQueueIds(true, ids)) {
|
||||||
|
|
|
@ -646,7 +646,7 @@ void NotifyQt::UpdateGUI()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RS_POPUP_CONNECT:
|
case RS_POPUP_CONNECT:
|
||||||
soundManager->play(SoundManager::USER_ONLINE);
|
soundManager->play(SOUND_USER_ONLINE);
|
||||||
|
|
||||||
if (popupflags & RS_POPUP_CONNECT)
|
if (popupflags & RS_POPUP_CONNECT)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "rsharesettings.h"
|
#include "rsharesettings.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
|
|
||||||
|
#include <retroshare/rsplugin.h>
|
||||||
|
|
||||||
#define COLUMN_NAME 0
|
#define COLUMN_NAME 0
|
||||||
#define COLUMN_FILENAME 1
|
#define COLUMN_FILENAME 1
|
||||||
#define COLUMN_COUNT 2
|
#define COLUMN_COUNT 2
|
||||||
|
@ -66,7 +68,17 @@ SoundPage::~SoundPage()
|
||||||
|
|
||||||
QTreeWidgetItem *SoundPage::addGroup(const QString &name)
|
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);
|
item->setText(COLUMN_NAME, name);
|
||||||
ui.eventTreeWidget->insertTopLevelItem(ui.eventTreeWidget->topLevelItemCount(), item);
|
ui.eventTreeWidget->insertTopLevelItem(ui.eventTreeWidget->topLevelItemCount(), item);
|
||||||
ui.eventTreeWidget->expandItem(item);
|
ui.eventTreeWidget->expandItem(item);
|
||||||
|
@ -74,7 +86,7 @@ QTreeWidgetItem *SoundPage::addGroup(const QString &name)
|
||||||
return item;
|
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);
|
QTreeWidgetItem *item = new QTreeWidgetItem(TYPE_ITEM);
|
||||||
item->setData(COLUMN_DATA, ROLE_EVENT, event);
|
item->setData(COLUMN_DATA, ROLE_EVENT, event);
|
||||||
|
@ -96,7 +108,7 @@ bool SoundPage::save(QString &/*errmsg*/)
|
||||||
itemIterator++;
|
itemIterator++;
|
||||||
|
|
||||||
if (item->type() == TYPE_ITEM) {
|
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->setEventEnabled(event, item->checkState(COLUMN_NAME) == Qt::Checked);
|
||||||
soundManager->setEventFilename(event, item->text(COLUMN_FILENAME));
|
soundManager->setEventFilename(event, item->text(COLUMN_FILENAME));
|
||||||
}
|
}
|
||||||
|
@ -110,11 +122,34 @@ void SoundPage::load()
|
||||||
{
|
{
|
||||||
ui.eventTreeWidget->clear();
|
ui.eventTreeWidget->clear();
|
||||||
|
|
||||||
|
/* add standard events */
|
||||||
|
|
||||||
QTreeWidgetItem *groupItem = addGroup(tr("Friend"));
|
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"));
|
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<SoundEvents::SoundEventInfo>::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);
|
ui.eventTreeWidget->resizeColumnToContents(COLUMN_NAME);
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTreeWidgetItem *addGroup(const QString &name);
|
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 */
|
/** Qt Designer generated object */
|
||||||
Ui::SoundPage ui;
|
Ui::SoundPage ui;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue