summaryrefslogtreecommitdiff
path: root/src/queue
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2016-03-10 20:10:14 +0100
committerMax Kellermann <max@duempel.org>2016-03-10 20:10:14 +0100
commit9a9b6fa32613dae2ae306ce553470c4845eb4b47 (patch)
tree4962539d23b82a452615a57f763722517745f9a5 /src/queue
parentba43ec57598a96f98b216715ec8c7b691d5b1a2b (diff)
queue/Playlist: add interface QueueListener, replacing calls to idle_add()
Diffstat (limited to 'src/queue')
-rw-r--r--src/queue/Listener.hxx43
-rw-r--r--src/queue/Playlist.cxx12
-rw-r--r--src/queue/Playlist.hxx13
-rw-r--r--src/queue/PlaylistEdit.cxx4
-rw-r--r--src/queue/PlaylistUpdate.cxx1
5 files changed, 61 insertions, 12 deletions
diff --git a/src/queue/Listener.hxx b/src/queue/Listener.hxx
new file mode 100644
index 000000000..7407d89f6
--- /dev/null
+++ b/src/queue/Listener.hxx
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2003-2016 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_QUEUE_LISTENER_HXX
+#define MPD_QUEUE_LISTENER_HXX
+
+class QueueListener {
+public:
+ /**
+ * Called after the queue has been modified.
+ */
+ virtual void OnQueueModified() = 0;
+
+ /**
+ * Called after a playback options have been changed.
+ */
+ virtual void OnQueueOptionsChanged() = 0;
+
+ /**
+ * Called after the player has started playing a new song.
+ * This gets called by playlist::SyncWithPlayer() after it has
+ * been notified by the player thread.
+ */
+ virtual void OnQueueSongStarted() = 0;
+};
+
+#endif
diff --git a/src/queue/Playlist.cxx b/src/queue/Playlist.cxx
index 6909d36a4..136682b00 100644
--- a/src/queue/Playlist.cxx
+++ b/src/queue/Playlist.cxx
@@ -19,10 +19,10 @@
#include "config.h"
#include "Playlist.hxx"
+#include "Listener.hxx"
#include "PlaylistError.hxx"
#include "player/Control.hxx"
#include "DetachedSong.hxx"
-#include "Idle.hxx"
#include "Log.hxx"
#include <assert.h>
@@ -86,7 +86,7 @@ playlist::QueuedSongStarted(PlayerControl &pc)
if (queue.consume)
DeleteOrder(pc, old_current);
- idle_add(IDLE_PLAYER);
+ listener.OnQueueSongStarted();
SongStarted();
}
@@ -245,7 +245,7 @@ playlist::SetRepeat(PlayerControl &pc, bool status)
might change when repeat mode is toggled */
UpdateQueuedSong(pc, GetQueuedSong());
- idle_add(IDLE_OPTIONS);
+ listener.OnQueueOptionsChanged();
}
static void
@@ -272,7 +272,7 @@ playlist::SetSingle(PlayerControl &pc, bool status)
might change when single mode is toggled */
UpdateQueuedSong(pc, GetQueuedSong());
- idle_add(IDLE_OPTIONS);
+ listener.OnQueueOptionsChanged();
}
void
@@ -282,7 +282,7 @@ playlist::SetConsume(bool status)
return;
queue.consume = status;
- idle_add(IDLE_OPTIONS);
+ listener.OnQueueOptionsChanged();
}
void
@@ -319,7 +319,7 @@ playlist::SetRandom(PlayerControl &pc, bool status)
UpdateQueuedSong(pc, queued_song);
- idle_add(IDLE_OPTIONS);
+ listener.OnQueueOptionsChanged();
}
int
diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx
index 0446f3f17..46ed9ae36 100644
--- a/src/queue/Playlist.hxx
+++ b/src/queue/Playlist.hxx
@@ -30,6 +30,7 @@ class Error;
class SongLoader;
class SongTime;
class SignedSongTime;
+class QueueListener;
struct playlist {
/**
@@ -37,6 +38,8 @@ struct playlist {
*/
Queue queue;
+ QueueListener &listener;
+
/**
* This value is true if the player is currently playing (or
* should be playing).
@@ -85,8 +88,11 @@ struct playlist {
*/
int queued;
- playlist(unsigned max_length)
- :queue(max_length), playing(false),
+ playlist(unsigned max_length,
+ QueueListener &_listener)
+ :queue(max_length),
+ listener(_listener),
+ playing(false),
bulk_edit(false),
current(-1), queued(-1) {
}
@@ -129,7 +135,8 @@ struct playlist {
protected:
/**
* Called by all editing methods after a modification.
- * Updates the queue version and emits #IDLE_PLAYLIST.
+ * Updates the queue version and invokes
+ * QueueListener::OnQueueModified().
*/
void OnModified();
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index 7af1e110f..f50eec144 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -25,12 +25,12 @@
#include "config.h"
#include "Playlist.hxx"
+#include "Listener.hxx"
#include "PlaylistError.hxx"
#include "player/Control.hxx"
#include "util/Error.hxx"
#include "DetachedSong.hxx"
#include "SongLoader.hxx"
-#include "Idle.hxx"
#include <memory>
@@ -47,7 +47,7 @@ playlist::OnModified()
queue.IncrementVersion();
- idle_add(IDLE_PLAYLIST);
+ listener.OnQueueModified();
}
void
diff --git a/src/queue/PlaylistUpdate.cxx b/src/queue/PlaylistUpdate.cxx
index 264ecaa93..d09d66935 100644
--- a/src/queue/PlaylistUpdate.cxx
+++ b/src/queue/PlaylistUpdate.cxx
@@ -22,7 +22,6 @@
#include "db/Interface.hxx"
#include "db/LightSong.hxx"
#include "DetachedSong.hxx"
-#include "Idle.hxx"
#include "util/Error.hxx"
static bool