OSDN Git Service

knotify: simplify idle players cleanup
authorIvailo Monev <xakepa10@gmail.com>
Mon, 18 Apr 2016 19:29:18 +0000 (19:29 +0000)
committerIvailo Monev <xakepa10@gmail.com>
Mon, 18 Apr 2016 19:29:18 +0000 (19:29 +0000)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
knotify/notifybysound.cpp
knotify/notifybysound.h

index 349412b..9a1a2cf 100644 (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);
 }
index 44f6463..34ed8e6 100644 (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();