Code

use glib regex for list_window_jump.
[ncmpc.git] / src / player_command.c
index 54664e58e9bdb8c6a5ccc78a7ec0f4f0a505d5ff..2455c83e58cdb74b5645730c0a91590c5c0e073b 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
 
  * This program is free software; you can redistribute it and/or modify
@@ -82,11 +82,26 @@ cancel_seek_timer(void)
        }
 }
 
+static bool
+setup_seek(struct mpdclient *c)
+{
+       if (!mpdclient_is_playing(c))
+               return false;
+
+       if (seek_id != (int)mpd_status_get_song_id(c->status)) {
+               seek_id = mpd_status_get_song_id(c->status);
+               seek_target_time = mpd_status_get_elapsed_time(c->status);
+       }
+
+       schedule_seek_timer(c);
+
+       return true;
+}
+
 bool
 handle_player_command(struct mpdclient *c, command_t cmd)
 {
        struct mpd_connection *connection;
-       const struct mpd_song *song;
 
        if (!mpdclient_is_connected(c) || c->status == NULL)
                return false;
@@ -120,18 +135,14 @@ handle_player_command(struct mpdclient *c, command_t cmd)
                mpdclient_cmd_crop(c);
                break;
        case CMD_SEEK_FORWARD:
-               song = mpdclient_get_current_song(c);
-               if (song != NULL) {
-                       if (seek_id != (int)mpd_song_get_id(song)) {
-                               seek_id = mpd_song_get_id(song);
-                               seek_target_time = mpd_status_get_elapsed_time(c->status);
-                       }
-                       seek_target_time+=options.seek_time;
-                       if (seek_target_time > (int)mpd_status_get_total_time(c->status))
-                               seek_target_time = mpd_status_get_total_time(c->status);
-                       schedule_seek_timer(c);
-               }
+               if (!setup_seek(c))
+                       break;
+
+               seek_target_time += options.seek_time;
+               if (seek_target_time > (int)mpd_status_get_total_time(c->status))
+                       seek_target_time = mpd_status_get_total_time(c->status);
                break;
+
        case CMD_TRACK_NEXT:
                connection = mpdclient_get_connection(c);
                if (connection == NULL)
@@ -141,18 +152,14 @@ handle_player_command(struct mpdclient *c, command_t cmd)
                        mpdclient_handle_error(c);
                break;
        case CMD_SEEK_BACKWARD:
-               song = mpdclient_get_current_song(c);
-               if (song != NULL) {
-                       if (seek_id != (int)mpd_song_get_id(song)) {
-                               seek_id = mpd_song_get_id(c->song);
-                               seek_target_time = mpd_status_get_elapsed_time(c->status);
-                       }
-                       seek_target_time-=options.seek_time;
-                       if (seek_target_time < 0)
-                               seek_target_time=0;
-                       schedule_seek_timer(c);
-               }
+               if (!setup_seek(c))
+                       break;
+
+               seek_target_time -= options.seek_time;
+               if (seek_target_time < 0)
+                       seek_target_time = 0;
                break;
+
        case CMD_TRACK_PREVIOUS:
                connection = mpdclient_get_connection(c);
                if (connection == NULL)