diff --git a/src/screen_play.c b/src/screen_play.c
index 8bbe60b8b691ffe5b511eba580ee7577388168f3..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;
static guint timer_hide_cursor_id;
}
static void
-playlist_changed_callback(struct mpdclient *c, int event, gpointer data)
+playlist_save_selection(void)
{
- switch (event) {
- case PLAYLIST_EVENT_DELETE:
- break;
- case PLAYLIST_EVENT_MOVE:
- if (!lw->range_selection) {
- lw->selected = *((int *) data);
- if (lw->selected < lw->start)
- lw->start--;
- }
- break;
- default:
- break;
- }
+ selected_song_id = playlist_selected_song() != NULL
+ ? (int)mpd_song_get_id(playlist_selected_song())
+ : -1;
+}
+
+static void
+playlist_restore_selection(void)
+{
+ const struct mpd_song *song;
+ int pos;
+
+ if (selected_song_id < 0)
+ /* there was no selection */
+ return;
+
+ song = playlist_selected_song();
+ if (song != NULL &&
+ mpd_song_get_id(song) == (unsigned)selected_song_id)
+ /* selection is still valid */
+ return;
+
+ pos = playlist_get_index_from_id(playlist, selected_song_id);
+ if (pos >= 0)
+ lw->selected = pos;
- list_window_check_selected(lw, c->playlist.list->len);
+ list_window_check_selected(lw, playlist_length(playlist));
+ playlist_save_selection();
}
#ifndef NCMPC_MINI
@@ -169,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();
lw->selected = selected;
list_window_check_selected(lw, playlist_length(playlist));
+ playlist_save_selection();
playlist_repaint();
return true;
}
if (list_window_cmd(lw, playlist_length(&c->playlist), cmd)) {
+ playlist_save_selection();
playlist_repaint();
return true;
}
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);
+ }
+ 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;
case CMD_SELECT_PLAYING:
list_window_set_selected(lw, playlist_get_index(&c->playlist,
c->song));
+ playlist_save_selection();
return true;
case CMD_SHUFFLE:
{
lw->selected_start--;
lw->selected_end--;
}
+
+ playlist_save_selection();
return true;
case CMD_LIST_MOVE_DOWN:
if(lw->selected_end+1 >= playlist_length(&c->playlist))
lw->selected_start++;
lw->selected_end++;
}
+
+ playlist_save_selection();
return true;
case CMD_LIST_FIND:
case CMD_LIST_RFIND:
case CMD_LIST_RFIND_NEXT:
screen_find(lw, playlist_length(&c->playlist),
cmd, list_callback, NULL);
+ playlist_save_selection();
playlist_repaint();
return true;
case CMD_LIST_JUMP:
screen_jump(lw, list_callback, NULL);
+ playlist_save_selection();
playlist_repaint();
return true;