mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
generic: simplify notification by sound
in the future the volume will be configurable via a custom widget that is specifically for KMediaPlayer and friends so the KCM will have to be reworked to make use of it for volume control but until that happens the only options are sound and no sound for notifications Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
8bf18129e8
commit
a41da6cd32
4 changed files with 32 additions and 424 deletions
|
@ -219,30 +219,16 @@ PlayerSettingsDialog::PlayerSettingsDialog( QWidget *parent )
|
|||
|
||||
load();
|
||||
|
||||
connect( m_ui->cbExternal, SIGNAL( toggled( bool ) ), this, SLOT( externalToggled( bool ) ) );
|
||||
connect( m_ui->cbSoundSystem, SIGNAL(clicked(bool)), this, SLOT(slotChanged()));
|
||||
connect( m_ui->cbExternal, SIGNAL(clicked(bool)), this, SLOT(slotChanged()));
|
||||
connect( m_ui->cbNone, SIGNAL(clicked(bool)), this, SLOT(slotChanged()));
|
||||
connect( m_ui->cbVolume, SIGNAL(clicked(bool)), this, SLOT(slotChanged()));
|
||||
connect( m_ui->volumeSlider, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
|
||||
connect( m_ui->reqExternal, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotChanged() ) );
|
||||
m_ui->reqExternal->setMode(KFile::File|KFile::ExistingOnly|KFile::LocalOnly);
|
||||
}
|
||||
|
||||
void PlayerSettingsDialog::load()
|
||||
{
|
||||
KConfig _config( "knotifyrc", KConfig::NoGlobals );
|
||||
KConfigGroup config(&_config, "Sounds" );
|
||||
bool useExternal = config.readEntry( "Use external player", false );
|
||||
m_ui->cbExternal->setChecked( useExternal );
|
||||
m_ui->reqExternal->setUrl( config.readPathEntry( "External player", QString() ) );
|
||||
m_ui->cbVolume->setChecked( config.readEntry( "ChangeVolume", false ) );
|
||||
m_ui->volumeSlider->setValue( config.readEntry( "Volume", 100 ) );
|
||||
|
||||
if ( !m_ui->cbExternal->isChecked() )
|
||||
{
|
||||
m_ui->cbNone->setChecked( config.readEntry( "No sound", false ) );
|
||||
}
|
||||
m_ui->cbNone->setChecked( config.readEntry( "No sound", false ) );
|
||||
emit changed( false );
|
||||
m_change=false;
|
||||
}
|
||||
|
@ -256,10 +242,6 @@ void PlayerSettingsDialog::save()
|
|||
KConfig _config("knotifyrc", KConfig::NoGlobals);
|
||||
KConfigGroup config(&_config, "Sounds" );
|
||||
|
||||
config.writePathEntry( "External player", m_ui->reqExternal->url().path() );
|
||||
config.writeEntry( "Use external player", m_ui->cbExternal->isChecked() );
|
||||
config.writeEntry( "Volume", m_ui->volumeSlider->value() );
|
||||
config.writeEntry( "ChangeVolume", m_ui->cbVolume->isChecked() );
|
||||
config.writeEntry( "No sound", m_ui->cbNone->isChecked() );
|
||||
|
||||
config.sync();
|
||||
|
@ -283,14 +265,6 @@ void PlayerSettingsDialog::defaults()
|
|||
emit changed(true);
|
||||
}
|
||||
|
||||
void PlayerSettingsDialog::externalToggled( bool on )
|
||||
{
|
||||
if ( on )
|
||||
m_ui->reqExternal->setFocus();
|
||||
else
|
||||
m_ui->reqExternal->clearFocus();
|
||||
}
|
||||
|
||||
PlayerSettingsDialog::~ PlayerSettingsDialog( )
|
||||
{
|
||||
delete m_ui;
|
||||
|
|
|
@ -72,7 +72,6 @@ public:
|
|||
void defaults();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void externalToggled( bool on );
|
||||
void slotChanged();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>407</width>
|
||||
<height>178</height>
|
||||
<height>83</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
|
@ -21,149 +21,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="volumeHolder" native="true">
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item row="1" column="4">
|
||||
<widget class="QLabel" name="textLabel3">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>100%</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>261</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="textLabel2">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0%</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="cbVolume">
|
||||
<property name="text">
|
||||
<string>Force &Volume:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" colspan="3">
|
||||
<widget class="QSlider" name="volumeSlider">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>41</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="cbExternal">
|
||||
<property name="text">
|
||||
<string>&Use an external player</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="textLabel5">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Player:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>reqExternal</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="KUrlRequester" name="reqExternal" native="true">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>10</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="cbNone">
|
||||
<property name="text">
|
||||
|
@ -186,111 +43,6 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KUrlRequester</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>kurlrequester.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>cbExternal</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>textLabel5</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>91</x>
|
||||
<y>98</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>67</x>
|
||||
<y>128</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>cbExternal</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>reqExternal</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>240</x>
|
||||
<y>98</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>312</x>
|
||||
<y>128</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>cbSoundSystem</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>volumeHolder</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>71</x>
|
||||
<y>13</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>11</x>
|
||||
<y>35</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>cbVolume</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>textLabel2</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>72</x>
|
||||
<y>40</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>149</x>
|
||||
<y>60</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>cbVolume</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>volumeSlider</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>124</x>
|
||||
<y>39</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>178</x>
|
||||
<y>50</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>cbVolume</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>textLabel3</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>38</x>
|
||||
<y>39</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>380</x>
|
||||
<y>64</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -28,9 +28,8 @@
|
|||
|
||||
// QT headers
|
||||
#include <QHash>
|
||||
#include <QtCore/QBasicTimer>
|
||||
#include <QtCore/QQueue>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QQueue>
|
||||
#include <QtCore/qcoreevent.h>
|
||||
#include <QtCore/QStack>
|
||||
#include <QSignalMapper>
|
||||
|
@ -38,7 +37,6 @@
|
|||
// KDE headers
|
||||
#include <kdebug.h>
|
||||
#include <klocale.h>
|
||||
#include <kprocess.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kconfiggroup.h>
|
||||
#include <kurl.h>
|
||||
|
@ -47,88 +45,14 @@
|
|||
#include <knotifyconfig.h>
|
||||
#include <kmediaplayer.h>
|
||||
|
||||
class PlayerPool
|
||||
{
|
||||
public:
|
||||
PlayerPool() : m_idlePlayer(0), m_changeVolume(false), m_volume(1.0) {}
|
||||
|
||||
KAudioPlayer *getPlayer();
|
||||
void returnPlayer(KAudioPlayer *);
|
||||
void clear();
|
||||
|
||||
void setChangeVolume(bool b);
|
||||
void setVolume(float volume);
|
||||
|
||||
private:
|
||||
KAudioPlayer *m_idlePlayer;
|
||||
QList<KAudioPlayer *> m_playersInUse;
|
||||
bool m_changeVolume;
|
||||
float m_volume;
|
||||
};
|
||||
|
||||
KAudioPlayer *PlayerPool::getPlayer()
|
||||
{
|
||||
KAudioPlayer *p = 0;
|
||||
if (!m_idlePlayer) {
|
||||
p = new KAudioPlayer();
|
||||
} else {
|
||||
p = m_idlePlayer;
|
||||
m_idlePlayer = 0;
|
||||
}
|
||||
if (m_changeVolume) {
|
||||
p->setVolume(m_volume);
|
||||
}
|
||||
m_playersInUse << p;
|
||||
return p;
|
||||
}
|
||||
|
||||
void PlayerPool::returnPlayer(KAudioPlayer *p)
|
||||
{
|
||||
m_playersInUse.removeAll(p);
|
||||
if (m_idlePlayer) {
|
||||
delete p;
|
||||
} else {
|
||||
m_idlePlayer = p;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerPool::clear()
|
||||
{
|
||||
delete m_idlePlayer;
|
||||
m_idlePlayer = 0;
|
||||
}
|
||||
|
||||
void PlayerPool::setChangeVolume(bool b)
|
||||
{
|
||||
m_changeVolume = b;
|
||||
if (m_changeVolume) {
|
||||
foreach (KAudioPlayer *p, m_playersInUse) {
|
||||
p->setVolume(m_volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerPool::setVolume(float v)
|
||||
{
|
||||
m_volume = v;
|
||||
if (m_changeVolume) {
|
||||
foreach (KAudioPlayer *p, m_playersInUse) {
|
||||
p->setVolume(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NotifyBySound::Private
|
||||
{
|
||||
public:
|
||||
enum { NoSound, UsePhonon, ExternalPlayer } playerMode;
|
||||
QString externalPlayer;
|
||||
enum { NoSound, UseMediaPlayer } playerMode;
|
||||
|
||||
QHash<int, KProcess *> processes;
|
||||
QHash<int, KAudioPlayer*> playerObjects;
|
||||
QSignalMapper *signalmapper;
|
||||
PlayerPool playerPool;
|
||||
QBasicTimer poolTimer;
|
||||
KAudioPlayer *currentPlayer;
|
||||
QQueue<int> closeQueue;
|
||||
};
|
||||
|
||||
|
@ -137,6 +61,8 @@ NotifyBySound::NotifyBySound(QObject *parent) : KNotifyPlugin(parent),d(new Priv
|
|||
d->signalmapper = new QSignalMapper(this);
|
||||
connect(d->signalmapper, SIGNAL(mapped(int)), this, SLOT(slotSoundFinished(int)));
|
||||
|
||||
d->currentPlayer = new KAudioPlayer(this);
|
||||
startTimer(1000);
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
|
@ -149,32 +75,15 @@ NotifyBySound::~NotifyBySound()
|
|||
|
||||
void NotifyBySound::loadConfig()
|
||||
{
|
||||
// load external player settings
|
||||
// load player settings
|
||||
KSharedConfig::Ptr kc = KGlobal::config();
|
||||
KConfigGroup cg(kc, "Sounds");
|
||||
|
||||
d->playerMode = Private::UsePhonon;
|
||||
if(cg.readEntry( "Use external player", false ))
|
||||
{
|
||||
d->playerMode = Private::ExternalPlayer;
|
||||
d->externalPlayer = cg.readPathEntry("External player", QString());
|
||||
// try to locate a suitable player if none is configured
|
||||
if ( d->externalPlayer.isEmpty() ) {
|
||||
const QStringList players = QStringList() << "wavplay" << "aplay" << "auplay" << "artsplay" << "akodeplay";
|
||||
QStringList::const_iterator it = players.constBegin();
|
||||
while ( d->externalPlayer.isEmpty() && it != players.constEnd() ) {
|
||||
d->externalPlayer = KStandardDirs::findExe( *it );
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(cg.readEntry( "No sound" , false ))
|
||||
d->playerMode = Private::UseMediaPlayer;
|
||||
if(cg.readEntry( "No sound" , false ))
|
||||
{
|
||||
d->playerMode = Private::NoSound;
|
||||
}
|
||||
// load default volume
|
||||
d->playerPool.setChangeVolume( cg.readEntry( "ChangeVolume", false ) );
|
||||
setVolume( cg.readEntry( "Volume", 100 ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -188,7 +97,7 @@ void NotifyBySound::notify( int eventId, KNotifyConfig * config )
|
|||
return;
|
||||
}
|
||||
|
||||
if(d->playerObjects.contains(eventId) || d->processes.contains(eventId) )
|
||||
if(d->playerObjects.contains(eventId))
|
||||
{
|
||||
//a sound is already playing for this notification, we don't support playing two sounds.
|
||||
finish( eventId );
|
||||
|
@ -221,46 +130,35 @@ void NotifyBySound::notify( int eventId, KNotifyConfig * config )
|
|||
}
|
||||
|
||||
kDebug() << " going to play " << soundFile;
|
||||
d->poolTimer.stop();
|
||||
|
||||
if(d->playerMode == Private::UsePhonon)
|
||||
if(d->playerMode == Private::UseMediaPlayer)
|
||||
{
|
||||
KAudioPlayer *player = d->playerPool.getPlayer();
|
||||
KAudioPlayer *player = d->currentPlayer;
|
||||
if (d->currentPlayer && d->currentPlayer->isPlaying()) {
|
||||
kDebug() << "creating new player";
|
||||
player = new KAudioPlayer(this);
|
||||
}
|
||||
connect(player, SIGNAL(finished()), d->signalmapper, SLOT(map()));
|
||||
d->signalmapper->setMapping(player, eventId);
|
||||
player->load(soundFile);
|
||||
d->playerObjects.insert(eventId, player);
|
||||
}
|
||||
else if (d->playerMode == Private::ExternalPlayer && !d->externalPlayer.isEmpty())
|
||||
{
|
||||
// use an external player to play the sound
|
||||
KProcess *proc = new KProcess( this );
|
||||
connect( proc, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
d->signalmapper, SLOT(map()) );
|
||||
d->signalmapper->setMapping( proc , eventId );
|
||||
|
||||
(*proc) << d->externalPlayer << soundFile;
|
||||
proc->start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NotifyBySound::setVolume( int volume )
|
||||
{
|
||||
if ( volume<0 ) volume=0;
|
||||
if ( volume>=100 ) volume=100;
|
||||
d->playerPool.setVolume(volume / 100.0);
|
||||
}
|
||||
|
||||
|
||||
void NotifyBySound::timerEvent(QTimerEvent *e)
|
||||
{
|
||||
if (e->timerId() == d->poolTimer.timerId()) {
|
||||
d->poolTimer.stop();
|
||||
d->playerPool.clear();
|
||||
return;
|
||||
}
|
||||
KNotifyPlugin::timerEvent(e);
|
||||
QMutableHashIterator<int,KAudioPlayer*> iter(d->playerObjects);
|
||||
while(iter.hasNext()) {
|
||||
iter.next();
|
||||
KAudioPlayer *player = iter.value();
|
||||
if (player != d->currentPlayer && !player->isPlaying()) {
|
||||
kDebug() << "destroying idle player";
|
||||
d->playerObjects.remove(iter.key());
|
||||
delete player;
|
||||
}
|
||||
}
|
||||
KNotifyPlugin::timerEvent(e);
|
||||
}
|
||||
|
||||
void NotifyBySound::slotSoundFinished(int id)
|
||||
|
@ -268,15 +166,8 @@ void NotifyBySound::slotSoundFinished(int id)
|
|||
kDebug() << id;
|
||||
if(d->playerObjects.contains(id))
|
||||
{
|
||||
KAudioPlayer *player=d->playerObjects.take(id);
|
||||
KAudioPlayer *player=d->playerObjects.value(id);
|
||||
disconnect(player, SIGNAL(finished()), d->signalmapper, SLOT(map()));
|
||||
d->playerPool.returnPlayer(player);
|
||||
//d->poolTimer.start(1000, this);
|
||||
}
|
||||
if(d->processes.contains(id))
|
||||
{
|
||||
d->processes[id]->deleteLater();
|
||||
d->processes.remove(id);
|
||||
}
|
||||
finish(id);
|
||||
}
|
||||
|
@ -294,16 +185,8 @@ void NotifyBySound::closeNow()
|
|||
const int id = d->closeQueue.dequeue();
|
||||
if(d->playerObjects.contains(id))
|
||||
{
|
||||
KAudioPlayer *p = d->playerObjects.take(id);
|
||||
p->stop();
|
||||
d->playerPool.returnPlayer(p);
|
||||
//d->poolTimer.start(1000, this);
|
||||
}
|
||||
if(d->processes.contains(id))
|
||||
{
|
||||
d->processes[id]->kill();
|
||||
d->processes[id]->deleteLater();
|
||||
d->processes.remove(id);
|
||||
KAudioPlayer *player = d->playerObjects.value(id);
|
||||
player->stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue