1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2009 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #include "screen.h"
21 #include "screen_list.h"
22 #include "screen_utils.h"
23 #include "config.h"
24 #include "i18n.h"
25 #include "charset.h"
26 #include "mpdclient.h"
27 #include "utils.h"
28 #include "options.h"
29 #include "colors.h"
30 #include "strfsong.h"
32 #ifndef NCMPC_MINI
33 #include "hscroll.h"
34 #endif
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <stdarg.h>
39 #include <string.h>
40 #include <time.h>
41 #include <locale.h>
43 #ifndef NCMPC_MINI
44 /** welcome message time [s] */
45 static const GTime SCREEN_WELCOME_TIME = 10;
46 #endif
48 /* minimum window size */
49 static const int SCREEN_MIN_COLS = 14;
50 static const int SCREEN_MIN_ROWS = 5;
52 /* screens */
54 #ifndef NCMPC_MINI
55 static gboolean welcome = TRUE;
56 #endif
58 struct screen screen;
59 static const struct screen_functions *mode_fn = &screen_playlist;
60 static const struct screen_functions *mode_fn_prev = &screen_playlist;
61 static int seek_id = -1;
62 static int seek_target_time = 0;
64 gboolean
65 screen_is_visible(const struct screen_functions *sf)
66 {
67 return sf == mode_fn;
68 }
70 void
71 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
72 {
73 assert(sf != NULL);
75 if (sf == mode_fn)
76 return;
78 mode_fn_prev = mode_fn;
80 /* close the old mode */
81 if (mode_fn->close != NULL)
82 mode_fn->close();
84 /* get functions for the new mode */
85 mode_fn = sf;
87 /* open the new mode */
88 if (mode_fn->open != NULL)
89 mode_fn->open(c);
91 screen_paint(c);
92 }
94 void
95 screen_swap(struct mpdclient *c, const struct mpd_song *song)
96 {
97 if (song != NULL)
98 {
99 if (false)
100 { /* just a hack to make the ifdefs less ugly */ }
101 #ifdef ENABLE_SONG_SCREEN
102 if (mode_fn_prev == &screen_song)
103 screen_song_switch(c, song);
104 #endif
105 #ifdef ENABLE_LYRICS_SCREEN
106 else if (mode_fn_prev == &screen_lyrics)
107 screen_lyrics_switch(c, song);
108 #endif
109 else
110 screen_switch(mode_fn_prev, c);
111 }
112 else
113 screen_switch(mode_fn_prev, c);
114 }
116 static int
117 find_configured_screen(const char *name)
118 {
119 unsigned i;
121 for (i = 0; options.screen_list[i] != NULL; ++i)
122 if (strcmp(options.screen_list[i], name) == 0)
123 return i;
125 return -1;
126 }
128 static void
129 screen_next_mode(mpdclient_t *c, int offset)
130 {
131 int max = g_strv_length(options.screen_list);
132 int current, next;
133 const struct screen_functions *sf;
135 /* find current screen */
136 current = find_configured_screen(screen_get_name(mode_fn));
137 next = current + offset;
138 if (next<0)
139 next = max-1;
140 else if (next>=max)
141 next = 0;
143 sf = screen_lookup_name(options.screen_list[next]);
144 if (sf != NULL)
145 screen_switch(sf, c);
146 }
148 #ifndef NCMPC_MINI
149 static void
150 print_hotkey(WINDOW *w, command_t cmd, const char *label)
151 {
152 colors_use(w, COLOR_TITLE_BOLD);
153 waddstr(w, get_key_names(cmd, FALSE));
154 colors_use(w, COLOR_TITLE);
155 waddch(w, ':');
156 waddstr(w, label);
157 waddch(w, ' ');
158 waddch(w, ' ');
159 }
160 #endif
162 static void
163 paint_top_window2(const char *header, mpdclient_t *c)
164 {
165 char flags[5];
166 WINDOW *w = screen.top_window.w;
167 char buf[32];
169 if (header[0]) {
170 colors_use(w, COLOR_TITLE_BOLD);
171 mvwaddstr(w, 0, 0, header);
172 #ifndef NCMPC_MINI
173 } else {
174 #ifdef ENABLE_HELP_SCREEN
175 print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
176 #endif
177 print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
178 print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
179 #ifdef ENABLE_ARTIST_SCREEN
180 print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
181 #endif
182 #ifdef ENABLE_SEARCH_SCREEN
183 print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
184 #endif
185 #ifdef ENABLE_LYRICS_SCREEN
186 print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
187 #endif
188 #ifdef ENABLE_OUTPUTS_SCREEN
189 print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
190 #endif
191 #endif
192 }
194 if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
195 g_snprintf(buf, 32, _("Volume n/a"));
196 } else {
197 g_snprintf(buf, 32, _("Volume %d%%"), c->status->volume);
198 }
199 colors_use(w, COLOR_TITLE);
200 mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
202 flags[0] = 0;
203 if (c->status != NULL) {
204 if (c->status->repeat)
205 g_strlcat(flags, "r", sizeof(flags));
206 if (c->status->random)
207 g_strlcat(flags, "z", sizeof(flags));
208 if (c->status->single)
209 g_strlcat(flags, "s", sizeof(flags));
210 if (c->status->consume)
211 g_strlcat(flags, "c", sizeof(flags));
212 if (c->status->crossfade)
213 g_strlcat(flags, "x", sizeof(flags));
214 if (c->status->updatingDb)
215 g_strlcat(flags, "U", sizeof(flags));
216 }
218 colors_use(w, COLOR_LINE);
219 mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
220 if (flags[0]) {
221 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
222 waddch(w, '[');
223 colors_use(w, COLOR_LINE_BOLD);
224 waddstr(w, flags);
225 colors_use(w, COLOR_LINE);
226 waddch(w, ']');
227 }
228 wnoutrefresh(w);
229 }
231 static void
232 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
233 {
234 static int prev_volume = -1;
235 static unsigned prev_header_len = -1;
236 WINDOW *w = screen.top_window.w;
238 if (prev_header_len != utf8_width(header)) {
239 prev_header_len = utf8_width(header);
240 full_repaint = 1;
241 }
243 if (full_repaint) {
244 wmove(w, 0, 0);
245 wclrtoeol(w);
246 }
248 if ((c->status != NULL && prev_volume != c->status->volume) ||
249 full_repaint)
250 paint_top_window2(header, c);
251 }
253 static void
254 paint_progress_window(mpdclient_t *c)
255 {
256 double p;
257 int width;
258 int elapsedTime;
260 if (c->status==NULL || IS_STOPPED(c->status->state)) {
261 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
262 screen.progress_window.cols);
263 wnoutrefresh(screen.progress_window.w);
264 return;
265 }
267 if (c->song && seek_id == c->song->id)
268 elapsedTime = seek_target_time;
269 else
270 elapsedTime = c->status->elapsedTime;
272 p = ((double) elapsedTime) / ((double) c->status->totalTime);
274 width = (int) (p * (double) screen.progress_window.cols);
275 mvwhline(screen.progress_window.w,
276 0, 0,
277 ACS_HLINE,
278 screen.progress_window.cols);
279 whline(screen.progress_window.w, '=', width-1);
280 mvwaddch(screen.progress_window.w, 0, width-1, 'O');
281 wnoutrefresh(screen.progress_window.w);
282 }
284 static void
285 paint_status_window(mpdclient_t *c)
286 {
287 WINDOW *w = screen.status_window.w;
288 mpd_Status *status = c->status;
289 mpd_Song *song = c->song;
290 int elapsedTime = 0;
291 #ifdef NCMPC_MINI
292 static char bitrate[1];
293 #else
294 char bitrate[16];
295 #endif
296 const char *str = NULL;
297 int x = 0;
299 if( time(NULL) - screen.status_timestamp <= options.status_message_time )
300 return;
302 wmove(w, 0, 0);
303 wclrtoeol(w);
304 colors_use(w, COLOR_STATUS_BOLD);
306 switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
307 case MPD_STATUS_STATE_PLAY:
308 str = _("Playing:");
309 break;
310 case MPD_STATUS_STATE_PAUSE:
311 str = _("[Paused]");
312 break;
313 case MPD_STATUS_STATE_STOP:
314 default:
315 break;
316 }
318 if (str) {
319 waddstr(w, str);
320 x += utf8_width(str) + 1;
321 }
323 /* create time string */
324 memset(screen.buf, 0, screen.buf_size);
325 if (status != NULL && (IS_PLAYING(status->state) ||
326 IS_PAUSED(status->state))) {
327 if (status->totalTime > 0) {
328 /*checks the conf to see whether to display elapsed or remaining time */
329 if(!strcmp(options.timedisplay_type,"elapsed"))
330 elapsedTime = c->status->elapsedTime;
331 else if(!strcmp(options.timedisplay_type,"remaining"))
332 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
334 if( c->song && seek_id == c->song->id )
335 elapsedTime = seek_target_time;
337 /* display bitrate if visible-bitrate is true */
338 #ifndef NCMPC_MINI
339 if (options.visible_bitrate) {
340 g_snprintf(bitrate, 16,
341 " [%d kbps]", status->bitRate);
342 } else {
343 bitrate[0] = '\0';
344 }
345 #endif
347 /*write out the time, using hours if time over 60 minutes*/
348 if (c->status->totalTime > 3600) {
349 g_snprintf(screen.buf, screen.buf_size,
350 "%s [%i:%02i:%02i/%i:%02i:%02i]",
351 bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
352 status->totalTime/3600, (status->totalTime%3600)/60, status->totalTime%60);
353 } else {
354 g_snprintf(screen.buf, screen.buf_size,
355 "%s [%i:%02i/%i:%02i]",
356 bitrate, elapsedTime/60, elapsedTime%60,
357 status->totalTime/60, status->totalTime%60 );
358 }
359 #ifndef NCMPC_MINI
360 } else {
361 g_snprintf(screen.buf, screen.buf_size,
362 " [%d kbps]", status->bitRate );
363 #endif
364 }
365 #ifndef NCMPC_MINI
366 } else {
367 if (options.display_time) {
368 time_t timep;
370 time(&timep);
371 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
372 }
373 #endif
374 }
376 /* display song */
377 if (status != NULL && (IS_PLAYING(status->state) ||
378 IS_PAUSED(status->state))) {
379 char songname[MAX_SONGNAME_LENGTH];
380 #ifndef NCMPC_MINI
381 int width = COLS - x - utf8_width(screen.buf);
382 #endif
384 if (song)
385 strfsong(songname, MAX_SONGNAME_LENGTH,
386 options.status_format, song);
387 else
388 songname[0] = '\0';
390 colors_use(w, COLOR_STATUS);
391 /* scroll if the song name is to long */
392 #ifndef NCMPC_MINI
393 if (options.scroll && utf8_width(songname) > (unsigned)width) {
394 static scroll_state_t st = { 0, 0 };
395 char *tmp = strscroll(songname, options.scroll_sep, width, &st);
397 g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
398 g_free(tmp);
399 }
400 #endif
401 //mvwaddnstr(w, 0, x, songname, width);
402 mvwaddstr(w, 0, x, songname);
403 }
405 /* display time string */
406 if (screen.buf[0]) {
407 x = screen.status_window.cols - strlen(screen.buf);
408 colors_use(w, COLOR_STATUS_TIME);
409 mvwaddstr(w, 0, x, screen.buf);
410 }
412 wnoutrefresh(w);
413 }
415 void
416 screen_exit(void)
417 {
418 if (mode_fn->close != NULL)
419 mode_fn->close();
421 screen_list_exit();
423 string_list_free(screen.find_history);
424 g_free(screen.buf);
425 g_free(screen.findbuf);
426 }
428 void
429 screen_resize(struct mpdclient *c)
430 {
431 if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
432 screen_exit();
433 fprintf(stderr, "%s", _("Error: Screen too small"));
434 exit(EXIT_FAILURE);
435 }
437 resizeterm(LINES, COLS);
439 screen.cols = COLS;
440 screen.rows = LINES;
442 /* top window */
443 screen.top_window.cols = screen.cols;
444 wresize(screen.top_window.w, 2, screen.cols);
446 /* main window */
447 screen.main_window.cols = screen.cols;
448 screen.main_window.rows = screen.rows-4;
449 wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
450 wclear(screen.main_window.w);
452 /* progress window */
453 screen.progress_window.cols = screen.cols;
454 wresize(screen.progress_window.w, 1, screen.cols);
455 mvwin(screen.progress_window.w, screen.rows-2, 0);
457 /* status window */
458 screen.status_window.cols = screen.cols;
459 wresize(screen.status_window.w, 1, screen.cols);
460 mvwin(screen.status_window.w, screen.rows-1, 0);
462 screen.buf_size = screen.cols;
463 g_free(screen.buf);
464 screen.buf = g_malloc(screen.cols);
466 /* resize all screens */
467 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
469 /* ? - without this the cursor becomes visible with aterm & Eterm */
470 curs_set(1);
471 curs_set(0);
473 screen_paint(c);
474 }
476 void
477 screen_status_message(const char *msg)
478 {
479 WINDOW *w = screen.status_window.w;
481 wmove(w, 0, 0);
482 wclrtoeol(w);
483 colors_use(w, COLOR_STATUS_ALERT);
484 waddstr(w, msg);
485 wnoutrefresh(w);
486 screen.status_timestamp = time(NULL);
487 }
489 void
490 screen_status_printf(const char *format, ...)
491 {
492 char *msg;
493 va_list ap;
495 va_start(ap,format);
496 msg = g_strdup_vprintf(format,ap);
497 va_end(ap);
498 screen_status_message(msg);
499 g_free(msg);
500 }
502 void
503 screen_init(mpdclient_t *c)
504 {
505 if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
506 fprintf(stderr, "%s\n", _("Error: Screen too small"));
507 exit(EXIT_FAILURE);
508 }
510 screen.cols = COLS;
511 screen.rows = LINES;
513 screen.buf = g_malloc(screen.cols);
514 screen.buf_size = screen.cols;
515 screen.findbuf = NULL;
516 screen.start_timestamp = time(NULL);
517 screen.last_cmd = CMD_NONE;
519 /* create top window */
520 screen.top_window.rows = 2;
521 screen.top_window.cols = screen.cols;
522 screen.top_window.w = newwin(screen.top_window.rows,
523 screen.top_window.cols,
524 0, 0);
525 leaveok(screen.top_window.w, TRUE);
526 keypad(screen.top_window.w, TRUE);
528 /* create main window */
529 screen.main_window.rows = screen.rows-4;
530 screen.main_window.cols = screen.cols;
531 screen.main_window.w = newwin(screen.main_window.rows,
532 screen.main_window.cols,
533 2,
534 0);
536 // leaveok(screen.main_window.w, TRUE); temporary disabled
537 keypad(screen.main_window.w, TRUE);
539 /* create progress window */
540 screen.progress_window.rows = 1;
541 screen.progress_window.cols = screen.cols;
542 screen.progress_window.w = newwin(screen.progress_window.rows,
543 screen.progress_window.cols,
544 screen.rows-2,
545 0);
546 leaveok(screen.progress_window.w, TRUE);
548 /* create status window */
549 screen.status_window.rows = 1;
550 screen.status_window.cols = screen.cols;
551 screen.status_window.w = newwin(screen.status_window.rows,
552 screen.status_window.cols,
553 screen.rows-1,
554 0);
556 leaveok(screen.status_window.w, FALSE);
557 keypad(screen.status_window.w, TRUE);
559 #ifdef ENABLE_COLORS
560 if (options.enable_colors) {
561 /* set background attributes */
562 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
563 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
564 wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
565 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
566 wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
567 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
568 }
569 #endif
571 refresh();
573 /* initialize screens */
574 screen_list_init(screen.main_window.w,
575 screen.main_window.cols, screen.main_window.rows);
577 if (mode_fn->open != NULL)
578 mode_fn->open(c);
579 }
581 void
582 screen_paint(mpdclient_t *c)
583 {
584 const char *title = NULL;
586 if (mode_fn->get_title != NULL)
587 title = mode_fn->get_title(screen.buf, screen.buf_size);
589 /* paint the title/header window */
590 if( title )
591 paint_top_window(title, c, 1);
592 else
593 paint_top_window("", c, 1);
595 /* paint the main window */
596 wclear(screen.main_window.w);
597 if (mode_fn->paint != NULL)
598 mode_fn->paint();
600 paint_progress_window(c);
601 paint_status_window(c);
602 wmove(screen.main_window.w, 0, 0);
603 wnoutrefresh(screen.main_window.w);
605 /* tell curses to update */
606 doupdate();
607 }
609 void
610 screen_update(mpdclient_t *c)
611 {
612 #ifndef NCMPC_MINI
613 static int repeat = -1;
614 static int random_enabled = -1;
615 static int single = -1;
616 static int consume = -1;
617 static int crossfade = -1;
618 static int dbupdate = -1;
620 /* print a message if mpd status has changed */
621 if (c->status != NULL) {
622 if (repeat < 0) {
623 repeat = c->status->repeat;
624 random_enabled = c->status->random;
625 single = c->status->single;
626 consume = c->status->consume;
627 crossfade = c->status->crossfade;
628 dbupdate = c->status->updatingDb;
629 }
631 if (repeat != c->status->repeat)
632 screen_status_printf(c->status->repeat ?
633 _("Repeat mode is on") :
634 _("Repeat mode is off"));
636 if (random_enabled != c->status->random)
637 screen_status_printf(c->status->random ?
638 _("Random mode is on") :
639 _("Random mode is off"));
641 if (single != c->status->single)
642 screen_status_printf(c->status->single ?
643 /* "single" mode means
644 that MPD will
645 automatically stop
646 after playing one
647 single song */
648 _("Single mode is on") :
649 _("Single mode is off"));
651 if (consume != c->status->consume)
652 screen_status_printf(c->status->consume ?
653 /* "consume" mode means
654 that MPD removes each
655 song which has
656 finished playing */
657 _("Consume mode is on") :
658 _("Consume mode is off"));
660 if (crossfade != c->status->crossfade)
661 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
663 if (dbupdate && dbupdate != c->status->updatingDb) {
664 screen_status_printf(_("Database updated"));
665 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
666 }
668 repeat = c->status->repeat;
669 single = c->status->single;
670 consume = c->status->consume;
671 random_enabled = c->status->random;
672 crossfade = c->status->crossfade;
673 dbupdate = c->status->updatingDb;
674 }
676 /* update title/header window */
677 if (welcome && options.welcome_screen_list &&
678 screen.last_cmd==CMD_NONE &&
679 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
680 paint_top_window("", c, 0);
681 else
682 #endif
683 if (mode_fn->get_title != NULL) {
684 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
685 #ifndef NCMPC_MINI
686 welcome = FALSE;
687 #endif
688 } else
689 paint_top_window("", c, 0);
691 /* update the main window */
692 if (mode_fn->update != NULL)
693 mode_fn->update(c);
695 /* update progress window */
696 paint_progress_window(c);
698 /* update status window */
699 paint_status_window(c);
701 /* move the cursor to the origin */
702 wmove(screen.main_window.w, 0, 0);
703 wnoutrefresh(screen.main_window.w);
705 /* tell curses to update */
706 doupdate();
707 }
709 void
710 screen_idle(mpdclient_t *c)
711 {
712 if (c->song && seek_id == c->song->id &&
713 (screen.last_cmd == CMD_SEEK_FORWARD ||
714 screen.last_cmd == CMD_SEEK_BACKWARD))
715 mpdclient_cmd_seek(c, seek_id, seek_target_time);
717 screen.last_cmd = CMD_NONE;
718 seek_id = -1;
719 }
721 #ifdef HAVE_GETMOUSE
722 int
723 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
724 {
725 MEVENT event;
727 /* retrieve the mouse event from ncurses */
728 getmouse(&event);
729 /* calculate the selected row in the list window */
730 *row = event.y - screen.top_window.rows;
731 /* copy button state bits */
732 *bstate = event.bstate;
733 /* if button 2 was pressed switch screen */
734 if (event.bstate & BUTTON2_CLICKED) {
735 screen_cmd(c, CMD_SCREEN_NEXT);
736 return 1;
737 }
739 return 0;
740 }
741 #endif
743 static int
744 screen_client_cmd(mpdclient_t *c, command_t cmd)
745 {
746 if (c->connection == NULL || c->status == NULL)
747 return 0;
749 switch(cmd) {
750 /*
751 case CMD_PLAY:
752 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
753 break;
754 */
755 case CMD_PAUSE:
756 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
757 break;
758 case CMD_STOP:
759 mpdclient_cmd_stop(c);
760 break;
761 case CMD_CROP:
762 mpdclient_cmd_crop(c);
763 break;
764 case CMD_SEEK_FORWARD:
765 if (!IS_STOPPED(c->status->state)) {
766 if (c->song && seek_id != c->song->id) {
767 seek_id = c->song->id;
768 seek_target_time = c->status->elapsedTime;
769 }
770 seek_target_time+=options.seek_time;
771 if (seek_target_time < c->status->totalTime)
772 break;
773 seek_target_time = c->status->totalTime;
774 /* seek_target_time=0; */
775 }
776 break;
777 /* fall through... */
778 case CMD_TRACK_NEXT:
779 if (!IS_STOPPED(c->status->state))
780 mpdclient_cmd_next(c);
781 break;
782 case CMD_SEEK_BACKWARD:
783 if (!IS_STOPPED(c->status->state)) {
784 if (seek_id != c->song->id) {
785 seek_id = c->song->id;
786 seek_target_time = c->status->elapsedTime;
787 }
788 seek_target_time-=options.seek_time;
789 if (seek_target_time < 0)
790 seek_target_time=0;
791 }
792 break;
793 case CMD_TRACK_PREVIOUS:
794 if (!IS_STOPPED(c->status->state))
795 mpdclient_cmd_prev(c);
796 break;
797 case CMD_SHUFFLE:
798 if (mpdclient_cmd_shuffle(c) == 0)
799 screen_status_message(_("Shuffled playlist"));
800 break;
801 case CMD_CLEAR:
802 if (mpdclient_cmd_clear(c) == 0)
803 screen_status_message(_("Cleared playlist"));
804 break;
805 case CMD_REPEAT:
806 mpdclient_cmd_repeat(c, !c->status->repeat);
807 break;
808 case CMD_RANDOM:
809 mpdclient_cmd_random(c, !c->status->random);
810 break;
811 case CMD_SINGLE:
812 mpdclient_cmd_single(c, !c->status->single);
813 break;
814 case CMD_CONSUME:
815 mpdclient_cmd_consume(c, !c->status->consume);
816 break;
817 case CMD_CROSSFADE:
818 if (c->status->crossfade)
819 mpdclient_cmd_crossfade(c, 0);
820 else
821 mpdclient_cmd_crossfade(c, options.crossfade_time);
822 break;
823 case CMD_DB_UPDATE:
824 if (!c->status->updatingDb) {
825 if( mpdclient_cmd_db_update(c,NULL)==0 )
826 screen_status_printf(_("Database update started"));
827 } else
828 screen_status_printf(_("Database update running..."));
829 break;
830 case CMD_VOLUME_UP:
831 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
832 mpdclient_cmd_volume(c, ++c->status->volume);
833 break;
834 case CMD_VOLUME_DOWN:
835 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
836 mpdclient_cmd_volume(c, --c->status->volume);
837 break;
839 default:
840 return 0;
841 }
843 return 1;
844 }
846 void
847 screen_cmd(mpdclient_t *c, command_t cmd)
848 {
849 screen.last_cmd = cmd;
850 #ifndef NCMPC_MINI
851 welcome = FALSE;
852 #endif
854 if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
855 return;
857 if (screen_client_cmd(c, cmd))
858 return;
860 switch(cmd) {
861 case CMD_TOGGLE_FIND_WRAP:
862 options.find_wrap = !options.find_wrap;
863 screen_status_printf(options.find_wrap ?
864 _("Find mode: Wrapped") :
865 _("Find mode: Normal"));
866 break;
867 case CMD_TOGGLE_AUTOCENTER:
868 options.auto_center = !options.auto_center;
869 screen_status_printf(options.auto_center ?
870 _("Auto center mode: On") :
871 _("Auto center mode: Off"));
872 break;
873 case CMD_SCREEN_UPDATE:
874 screen_paint(c);
875 break;
876 case CMD_SCREEN_PREVIOUS:
877 screen_next_mode(c, -1);
878 break;
879 case CMD_SCREEN_NEXT:
880 screen_next_mode(c, 1);
881 break;
882 case CMD_SCREEN_PLAY:
883 screen_switch(&screen_playlist, c);
884 break;
885 case CMD_SCREEN_FILE:
886 screen_switch(&screen_browse, c);
887 break;
888 #ifdef ENABLE_HELP_SCREEN
889 case CMD_SCREEN_HELP:
890 screen_switch(&screen_help, c);
891 break;
892 #endif
893 #ifdef ENABLE_SEARCH_SCREEN
894 case CMD_SCREEN_SEARCH:
895 screen_switch(&screen_search, c);
896 break;
897 #endif
898 #ifdef ENABLE_ARTIST_SCREEN
899 case CMD_SCREEN_ARTIST:
900 screen_switch(&screen_artist, c);
901 break;
902 #endif
903 #ifdef ENABLE_SONG_SCREEN
904 case CMD_SCREEN_SONG:
905 screen_switch(&screen_song, c);
906 break;
907 #endif
908 #ifdef ENABLE_KEYDEF_SCREEN
909 case CMD_SCREEN_KEYDEF:
910 screen_switch(&screen_keydef, c);
911 break;
912 #endif
913 #ifdef ENABLE_LYRICS_SCREEN
914 case CMD_SCREEN_LYRICS:
915 screen_switch(&screen_lyrics, c);
916 break;
917 #endif
918 #ifdef ENABLE_OUTPUTS_SCREEN
919 case CMD_SCREEN_OUTPUTS:
920 screen_switch(&screen_outputs, c);
921 break;
922 case CMD_SCREEN_SWAP:
923 screen_swap(c, NULL);
924 break;
925 #endif
927 default:
928 break;
929 }
930 }