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 is on") :
634 _("Repeat is off"));
636 if (random_enabled != c->status->random)
637 screen_status_printf(c->status->random ?
638 _("Random is on") :
639 _("Random is off"));
641 if (single != c->status->single)
642 screen_status_printf(c->status->single ?
643 _("Single is on") :
644 _("Single is off"));
646 if (consume != c->status->consume)
647 screen_status_printf(c->status->consume ?
648 _("Consume is on") :
649 _("Consume is off"));
651 if (crossfade != c->status->crossfade)
652 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
654 if (dbupdate && dbupdate != c->status->updatingDb) {
655 screen_status_printf(_("Database updated"));
656 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
657 }
659 repeat = c->status->repeat;
660 single = c->status->single;
661 consume = c->status->consume;
662 random_enabled = c->status->random;
663 crossfade = c->status->crossfade;
664 dbupdate = c->status->updatingDb;
665 }
667 /* update title/header window */
668 if (welcome && options.welcome_screen_list &&
669 screen.last_cmd==CMD_NONE &&
670 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
671 paint_top_window("", c, 0);
672 else
673 #endif
674 if (mode_fn->get_title != NULL) {
675 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
676 #ifndef NCMPC_MINI
677 welcome = FALSE;
678 #endif
679 } else
680 paint_top_window("", c, 0);
682 /* update the main window */
683 if (mode_fn->update != NULL)
684 mode_fn->update(c);
686 /* update progress window */
687 paint_progress_window(c);
689 /* update status window */
690 paint_status_window(c);
692 /* move the cursor to the origin */
693 wmove(screen.main_window.w, 0, 0);
694 wnoutrefresh(screen.main_window.w);
696 /* tell curses to update */
697 doupdate();
698 }
700 void
701 screen_idle(mpdclient_t *c)
702 {
703 if (c->song && seek_id == c->song->id &&
704 (screen.last_cmd == CMD_SEEK_FORWARD ||
705 screen.last_cmd == CMD_SEEK_BACKWARD))
706 mpdclient_cmd_seek(c, seek_id, seek_target_time);
708 screen.last_cmd = CMD_NONE;
709 seek_id = -1;
710 }
712 #ifdef HAVE_GETMOUSE
713 int
714 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
715 {
716 MEVENT event;
718 /* retrieve the mouse event from ncurses */
719 getmouse(&event);
720 /* calculate the selected row in the list window */
721 *row = event.y - screen.top_window.rows;
722 /* copy button state bits */
723 *bstate = event.bstate;
724 /* if button 2 was pressed switch screen */
725 if (event.bstate & BUTTON2_CLICKED) {
726 screen_cmd(c, CMD_SCREEN_NEXT);
727 return 1;
728 }
730 return 0;
731 }
732 #endif
734 static int
735 screen_client_cmd(mpdclient_t *c, command_t cmd)
736 {
737 if (c->connection == NULL || c->status == NULL)
738 return 0;
740 switch(cmd) {
741 /*
742 case CMD_PLAY:
743 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
744 break;
745 */
746 case CMD_PAUSE:
747 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
748 break;
749 case CMD_STOP:
750 mpdclient_cmd_stop(c);
751 break;
752 case CMD_CROP:
753 mpdclient_cmd_crop(c);
754 break;
755 case CMD_SEEK_FORWARD:
756 if (!IS_STOPPED(c->status->state)) {
757 if (c->song && seek_id != c->song->id) {
758 seek_id = c->song->id;
759 seek_target_time = c->status->elapsedTime;
760 }
761 seek_target_time+=options.seek_time;
762 if (seek_target_time < c->status->totalTime)
763 break;
764 seek_target_time = c->status->totalTime;
765 /* seek_target_time=0; */
766 }
767 break;
768 /* fall through... */
769 case CMD_TRACK_NEXT:
770 if (!IS_STOPPED(c->status->state))
771 mpdclient_cmd_next(c);
772 break;
773 case CMD_SEEK_BACKWARD:
774 if (!IS_STOPPED(c->status->state)) {
775 if (seek_id != c->song->id) {
776 seek_id = c->song->id;
777 seek_target_time = c->status->elapsedTime;
778 }
779 seek_target_time-=options.seek_time;
780 if (seek_target_time < 0)
781 seek_target_time=0;
782 }
783 break;
784 case CMD_TRACK_PREVIOUS:
785 if (!IS_STOPPED(c->status->state))
786 mpdclient_cmd_prev(c);
787 break;
788 case CMD_SHUFFLE:
789 if (mpdclient_cmd_shuffle(c) == 0)
790 screen_status_message(_("Shuffled playlist"));
791 break;
792 case CMD_CLEAR:
793 if (mpdclient_cmd_clear(c) == 0)
794 screen_status_message(_("Cleared playlist"));
795 break;
796 case CMD_REPEAT:
797 mpdclient_cmd_repeat(c, !c->status->repeat);
798 break;
799 case CMD_RANDOM:
800 mpdclient_cmd_random(c, !c->status->random);
801 break;
802 case CMD_SINGLE:
803 mpdclient_cmd_single(c, !c->status->single);
804 break;
805 case CMD_CONSUME:
806 mpdclient_cmd_consume(c, !c->status->consume);
807 break;
808 case CMD_CROSSFADE:
809 if (c->status->crossfade)
810 mpdclient_cmd_crossfade(c, 0);
811 else
812 mpdclient_cmd_crossfade(c, options.crossfade_time);
813 break;
814 case CMD_DB_UPDATE:
815 if (!c->status->updatingDb) {
816 if( mpdclient_cmd_db_update(c,NULL)==0 )
817 screen_status_printf(_("Database update started"));
818 } else
819 screen_status_printf(_("Database update running..."));
820 break;
821 case CMD_VOLUME_UP:
822 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
823 mpdclient_cmd_volume(c, ++c->status->volume);
824 break;
825 case CMD_VOLUME_DOWN:
826 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
827 mpdclient_cmd_volume(c, --c->status->volume);
828 break;
830 default:
831 return 0;
832 }
834 return 1;
835 }
837 void
838 screen_cmd(mpdclient_t *c, command_t cmd)
839 {
840 screen.last_cmd = cmd;
841 #ifndef NCMPC_MINI
842 welcome = FALSE;
843 #endif
845 if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
846 return;
848 if (screen_client_cmd(c, cmd))
849 return;
851 switch(cmd) {
852 case CMD_TOGGLE_FIND_WRAP:
853 options.find_wrap = !options.find_wrap;
854 screen_status_printf(options.find_wrap ?
855 _("Find mode: Wrapped") :
856 _("Find mode: Normal"));
857 break;
858 case CMD_TOGGLE_AUTOCENTER:
859 options.auto_center = !options.auto_center;
860 screen_status_printf(options.auto_center ?
861 _("Auto center mode: On") :
862 _("Auto center mode: Off"));
863 break;
864 case CMD_SCREEN_UPDATE:
865 screen_paint(c);
866 break;
867 case CMD_SCREEN_PREVIOUS:
868 screen_next_mode(c, -1);
869 break;
870 case CMD_SCREEN_NEXT:
871 screen_next_mode(c, 1);
872 break;
873 case CMD_SCREEN_PLAY:
874 screen_switch(&screen_playlist, c);
875 break;
876 case CMD_SCREEN_FILE:
877 screen_switch(&screen_browse, c);
878 break;
879 #ifdef ENABLE_HELP_SCREEN
880 case CMD_SCREEN_HELP:
881 screen_switch(&screen_help, c);
882 break;
883 #endif
884 #ifdef ENABLE_SEARCH_SCREEN
885 case CMD_SCREEN_SEARCH:
886 screen_switch(&screen_search, c);
887 break;
888 #endif
889 #ifdef ENABLE_ARTIST_SCREEN
890 case CMD_SCREEN_ARTIST:
891 screen_switch(&screen_artist, c);
892 break;
893 #endif
894 #ifdef ENABLE_SONG_SCREEN
895 case CMD_SCREEN_SONG:
896 screen_switch(&screen_song, c);
897 break;
898 #endif
899 #ifdef ENABLE_KEYDEF_SCREEN
900 case CMD_SCREEN_KEYDEF:
901 screen_switch(&screen_keydef, c);
902 break;
903 #endif
904 #ifdef ENABLE_LYRICS_SCREEN
905 case CMD_SCREEN_LYRICS:
906 screen_switch(&screen_lyrics, c);
907 break;
908 #endif
909 #ifdef ENABLE_OUTPUTS_SCREEN
910 case CMD_SCREEN_OUTPUTS:
911 screen_switch(&screen_outputs, c);
912 break;
913 case CMD_SCREEN_SWAP:
914 screen_swap(c, NULL);
915 break;
916 #endif
918 default:
919 break;
920 }
921 }