diff --git a/src/screen_play.c b/src/screen_play.c
index 5bdfbe3f60b3551f4d97f76e7d486bce5b11ef95..ceb13616662197b076a0316e9fdfbb3dc735a971 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "screen_play.h"
+#include "screen_interface.h"
+#include "screen_file.h"
#include "config.h"
#include "i18n.h"
#include "charset.h"
#include "utils.h"
#include "strfsong.h"
#include "wreadln.h"
-#include "command.h"
#include "colors.h"
#include "screen.h"
#include "screen_utils.h"
-#include "screen_play.h"
+#include "screen_song.h"
+#include "screen_lyrics.h"
#ifndef NCMPC_MINI
#include "hscroll.h"
#include <mpd/client.h>
#include <ctype.h>
-#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include <glib.h>
#define MAX_SONG_LENGTH 512
#endif
static struct mpdclient_playlist *playlist;
-static unsigned visible_version = -1;
static int current_song_id = -1;
static int selected_song_id = -1;
static list_window_t *lw = NULL;
playlist_save_selection();
}
-static void
-playlist_changed_callback(G_GNUC_UNUSED struct mpdclient *c,
- G_GNUC_UNUSED int event, G_GNUC_UNUSED gpointer data)
-{
- playlist_restore_selection();
-}
-
#ifndef NCMPC_MINI
static char *
format_duration(unsigned duration)
@@ -189,11 +182,12 @@ list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED
static void
center_playing_item(struct mpdclient *c, bool center_cursor)
{
+ const struct mpd_song *song;
unsigned length = c->playlist.list->len;
int idx;
- if (!c->song || c->status == NULL ||
- IS_STOPPED(mpd_status_get_state(c->status)))
+ song = mpdclient_get_current_song(c);
+ if (song == NULL)
return;
/* try to center the song that are playing */
static void
play_open(struct mpdclient *c)
{
- static gboolean install_cb = TRUE;
-
playlist = &c->playlist;
assert(timer_hide_cursor_id == 0);
timer_hide_cursor, c);
}
- if (install_cb) {
- mpdclient_install_playlist_callback(c, playlist_changed_callback);
- install_cb = FALSE;
- }
+ playlist_restore_selection();
}
static void
#endif
list_window_paint(lw, list_callback, NULL);
-
- visible_version = playlist->id;
}
static void
{
static int prev_song_id = -1;
- current_song_id = c->song != NULL && c->status != NULL &&
+ if (c->events & MPD_IDLE_PLAYLIST)
+ playlist_restore_selection();
+
+ current_song_id = c->status != NULL &&
!IS_STOPPED(mpd_status_get_state(c->status))
- ? (int)mpd_song_get_id(c->song) : -1;
+ ? (int)mpd_status_get_song_id(c->status) : -1;
if (current_song_id != prev_song_id) {
prev_song_id = current_song_id;
enabled */
playlist_repaint();
#endif
- } else if (visible_version != playlist->id) {
+ } else if (c->events & MPD_IDLE_PLAYLIST) {
/* the playlist has changed, we must paint the new
version */
playlist_repaint();
mpdclient_cmd_play(c, lw->selected);
return true;
case CMD_DELETE:
- {
- int i = lw->selected_end, start = lw->selected_start;
- for(; i >= start; --i)
- mpdclient_cmd_delete(c, i);
-
- i++;
- if(i >= (int)playlist_length(&c->playlist))
- i--;
- lw->selected = i;
- lw->selected_start = i;
- lw->selected_end = i;
- lw->range_selection = false;
+ if (lw->range_selection) {
+ mpdclient_cmd_delete_range(c, lw->selected_start,
+ lw->selected_end + 1);
+ } else {
+ mpdclient_cmd_delete(c, lw->selected);
+ }
- playlist_save_selection();
+ lw->selected = lw->selected_end = lw->selected_start;
+ lw->range_selection = false;
return true;
- }
+
case CMD_SAVE_PLAYLIST:
playlist_save(c, NULL, NULL);
return true;