X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fplayer_command.c;h=d4ff4ae280830e749adee8f1ce6ae01aaffc093f;hb=d4007f2eef7bf32498ad4233d8115c9e2c48b2c1;hp=226d18ca91d4b78092e88e18cc50bba9bdb350a6;hpb=d14a5d89609fbbbdf1dec6248f8afa9470824996;p=ncmpc.git diff --git a/src/player_command.c b/src/player_command.c index 226d18c..d4ff4ae 100644 --- a/src/player_command.c +++ b/src/player_command.c @@ -1,17 +1,17 @@ /* 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 * 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. @@ -22,7 +22,7 @@ #include "options.h" #include "i18n.h" #include "screen_client.h" -#include "screen_message.h" +#include "screen_status.h" int seek_id = -1; int seek_target_time; @@ -32,12 +32,10 @@ static guint seek_source_id; static void commit_seek(struct mpdclient *c) { - struct mpd_connection *connection; - if (seek_id < 0) return; - connection = mpdclient_get_connection(c); + struct mpd_connection *connection = mpdclient_get_connection(c); if (connection == NULL) { seek_id = -1; return; @@ -82,18 +80,33 @@ 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; cancel_seek_timer(); switch(cmd) { + struct mpd_connection *connection; + /* case CMD_PLAY: mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING); @@ -120,20 +133,12 @@ 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 (!setup_seek(c)) break; - 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); break; case CMD_TRACK_NEXT: @@ -145,20 +150,12 @@ 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 (!setup_seek(c)) break; - 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); break; case CMD_TRACK_PREVIOUS: @@ -175,7 +172,7 @@ handle_player_command(struct mpdclient *c, command_t cmd) break; if (mpd_run_shuffle(connection)) - screen_status_message(_("Shuffled playlist")); + screen_status_message(_("Shuffled queue")); else mpdclient_handle_error(c); break; @@ -185,7 +182,7 @@ handle_player_command(struct mpdclient *c, command_t cmd) break; if (mpdclient_cmd_clear(c)) - screen_status_message(_("Cleared playlist")); + screen_status_message(_("Cleared queue")); break; case CMD_REPEAT: connection = mpdclient_get_connection(c);