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:
thunder2 2012-10-21 21:38:55 +00:00
parent 56635e4ce4
commit 232af8e71e
11 changed files with 109 additions and 41 deletions

View File

@ -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.
//

View File

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

View File

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

View File

@ -3,6 +3,7 @@
#include <QIcon>
#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;
}

View File

@ -6,6 +6,8 @@
class QPushButton;
#define VOIP_SOUND_INCOMING_CALL "VOIP_incoming_call"
class AudioPopupChatDialog: public PopupChatDialog
{
Q_OBJECT

View File

@ -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()) {

View File

@ -24,16 +24,36 @@
#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
{
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();

View File

@ -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<std::string> ids;
if (rsMsgs->getPrivateChatQueueIds(true, ids)) {

View File

@ -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)
{

View File

@ -23,6 +23,8 @@
#include "rsharesettings.h"
#include "util/misc.h"
#include <retroshare/rsplugin.h>
#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<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);

View File

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