knotify: simplify idle players cleanup

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2016-04-18 19:29:18 +00:00
parent 513dbc7b53
commit f7f25c5f7c
2 changed files with 5 additions and 20 deletions

View file

@ -60,7 +60,6 @@ NotifyBySound::NotifyBySound(QObject *parent) : KNotifyPlugin(parent),d(new Priv
connect(d->signalmapper, SIGNAL(mapped(int)), this, SLOT(slotSoundFinished(int)));
d->currentPlayer = new KAudioPlayer(this);
startTimer(1000);
loadConfig();
}
@ -133,28 +132,17 @@ void NotifyBySound::notify( int eventId, KNotifyConfig * config )
}
}
void NotifyBySound::timerEvent(QTimerEvent *e)
{
QMutableMapIterator<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(d->playerObjects.key(player));
player->deleteLater();
}
}
KNotifyPlugin::timerEvent(e);
}
void NotifyBySound::slotSoundFinished(int id)
{
kDebug() << id;
if (d->playerObjects.contains(id)) {
KAudioPlayer *player=d->playerObjects.value(id);
disconnect(player, SIGNAL(finished()), d->signalmapper, SLOT(map()));
if (player != d->currentPlayer) {
kDebug() << "destroying idle player";
d->playerObjects.remove(id);
player->deleteLater();
}
}
finish(id);
}

View file

@ -44,9 +44,6 @@ class NotifyBySound : public KNotifyPlugin
public:
void setVolume( int v );
protected:
void timerEvent(QTimerEvent *);
private Q_SLOTS:
void slotSoundFinished(int id);
void closeNow();