622582582a60edb1872fb8b33b1b252048ace8fb
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 (mode_fn_prev == &screen_song)
100 screen_song_switch(c, song);
101 else if (mode_fn_prev == &screen_lyrics)
102 screen_lyrics_switch(c, song);
103 else
104 screen_switch(mode_fn_prev, c);
105 }
106 else
107 screen_switch(mode_fn_prev, c);
108 }
110 static int
111 find_configured_screen(const char *name)
112 {
113 unsigned i;
115 for (i = 0; options.screen_list[i] != NULL; ++i)
116 if (strcmp(options.screen_list[i], name) == 0)
117 return i;
119 return -1;
120 }
122 static void
123 screen_next_mode(mpdclient_t *c, int offset)
124 {
125 int max = g_strv_length(options.screen_list);
126 int current, next;
127 const struct screen_functions *sf;
129 /* find current screen */
130 current = find_configured_screen(screen_get_name(mode_fn));
131 next = current + offset;
132 if (next<0)
133 next = max-1;
134 else if (next>=max)
135 next = 0;
137 sf = screen_lookup_name(options.screen_list[next]);
138 if (sf != NULL)
139 screen_switch(sf, c);
140 }
142 #ifndef NCMPC_MINI
143 static void
144 print_hotkey(WINDOW *w, command_t cmd, const char *label)
145 {
146 colors_use(w, COLOR_TITLE_BOLD);
147 waddstr(w, get_key_names(cmd, FALSE));
148 colors_use(w, COLOR_TITLE);
149 waddch(w, ':');
150 waddstr(w, label);
151 waddch(w, ' ');
152 waddch(w, ' ');
153 }
154 #endif
156 static void
157 paint_top_window2(const char *header, mpdclient_t *c)
158 {
159 char flags[5];
160 WINDOW *w = screen.top_window.w;
161 char buf[32];
163 if (header[0]) {
164 colors_use(w, COLOR_TITLE_BOLD);
165 mvwaddstr(w, 0, 0, header);
166 #ifndef NCMPC_MINI
167 } else {
168 #ifdef ENABLE_HELP_SCREEN
169 print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
170 #endif
171 print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
172 print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
173 #ifdef ENABLE_ARTIST_SCREEN
174 print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
175 #endif
176 #ifdef ENABLE_SEARCH_SCREEN
177 print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
178 #endif
179 #ifdef ENABLE_LYRICS_SCREEN
180 print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
181 #endif
182 #ifdef ENABLE_OUTPUTS_SCREEN
183 print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
184 #endif
185 #endif
186 }
188 if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
189 g_snprintf(buf, 32, _("Volume n/a "));
190 } else {
191 g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
192 }
193 colors_use(w, COLOR_TITLE);
194 mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
196 flags[0] = 0;
197 if (c->status != NULL) {
198 if (c->status->repeat)
199 g_strlcat(flags, "r", sizeof(flags));
200 if (c->status->random)
201 g_strlcat(flags, "z", sizeof(flags));;
202 if (c->status->crossfade)
203 g_strlcat(flags, "x", sizeof(flags));
204 if (c->status->updatingDb)
205 g_strlcat(flags, "U", sizeof(flags));
206 }
208 colors_use(w, COLOR_LINE);
209 mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
210 if (flags[0]) {
211 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
212 waddch(w, '[');
213 colors_use(w, COLOR_LINE_BOLD);
214 waddstr(w, flags);
215 colors_use(w, COLOR_LINE);
216 waddch(w, ']');
217 }
218 wnoutrefresh(w);
219 }
221 static void
222 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
223 {
224 static int prev_volume = -1;
225 static unsigned prev_header_len = -1;
226 WINDOW *w = screen.top_window.w;
228 if (prev_header_len != utf8_width(header)) {
229 prev_header_len = utf8_width(header);
230 full_repaint = 1;
231 }
233 if (full_repaint) {
234 wmove(w, 0, 0);
235 wclrtoeol(w);
236 }
238 if ((c->status != NULL && prev_volume != c->status->volume) ||
239 full_repaint)
240 paint_top_window2(header, c);
241 }
243 static void
244 paint_progress_window(mpdclient_t *c)
245 {
246 double p;
247 int width;
248 int elapsedTime;
250 if (c->status==NULL || IS_STOPPED(c->status->state)) {
251 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
252 screen.progress_window.cols);
253 wnoutrefresh(screen.progress_window.w);
254 return;
255 }
257 if (c->song && seek_id == c->song->id)
258 elapsedTime = seek_target_time;
259 else
260 elapsedTime = c->status->elapsedTime;
262 p = ((double) elapsedTime) / ((double) c->status->totalTime);
264 width = (int) (p * (double) screen.progress_window.cols);
265 mvwhline(screen.progress_window.w,
266 0, 0,
267 ACS_HLINE,
268 screen.progress_window.cols);
269 whline(screen.progress_window.w, '=', width-1);
270 mvwaddch(screen.progress_window.w, 0, width-1, 'O');
271 wnoutrefresh(screen.progress_window.w);
272 }
274 static void
275 paint_status_window(mpdclient_t *c)
276 {
277 WINDOW *w = screen.status_window.w;
278 mpd_Status *status = c->status;
279 mpd_Song *song = c->song;
280 int elapsedTime = 0;
281 #ifdef NCMPC_MINI
282 static char bitrate[1];
283 #else
284 char bitrate[16];
285 #endif
286 const char *str = NULL;
287 int x = 0;
289 if( time(NULL) - screen.status_timestamp <= options.status_message_time )
290 return;
292 wmove(w, 0, 0);
293 wclrtoeol(w);
294 colors_use(w, COLOR_STATUS_BOLD);
296 switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
297 case MPD_STATUS_STATE_PLAY:
298 str = _("Playing:");
299 break;
300 case MPD_STATUS_STATE_PAUSE:
301 str = _("[Paused]");
302 break;
303 case MPD_STATUS_STATE_STOP:
304 default:
305 break;
306 }
308 if (str) {
309 waddstr(w, str);
310 x += utf8_width(str) + 1;
311 }
313 /* create time string */
314 memset(screen.buf, 0, screen.buf_size);
315 if (status != NULL && (IS_PLAYING(status->state) ||
316 IS_PAUSED(status->state))) {
317 if (status->totalTime > 0) {
318 /*checks the conf to see whether to display elapsed or remaining time */
319 if(!strcmp(options.timedisplay_type,"elapsed"))
320 elapsedTime = c->status->elapsedTime;
321 else if(!strcmp(options.timedisplay_type,"remaining"))
322 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
324 if( c->song && seek_id == c->song->id )
325 elapsedTime = seek_target_time;
327 /* display bitrate if visible-bitrate is true */
328 #ifndef NCMPC_MINI
329 if (options.visible_bitrate) {
330 g_snprintf(bitrate, 16,
331 " [%d kbps]", status->bitRate);
332 } else {
333 bitrate[0] = '\0';
334 }
335 #endif
337 /*write out the time, using hours if time over 60 minutes*/
338 if (c->status->totalTime > 3600) {
339 g_snprintf(screen.buf, screen.buf_size,
340 "%s [%i:%02i:%02i/%i:%02i:%02i]",
341 bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
342 status->totalTime/3600, (status->totalTime%3600)/60, status->totalTime%60);
343 } else {
344 g_snprintf(screen.buf, screen.buf_size,
345 "%s [%i:%02i/%i:%02i]",
346 bitrate, elapsedTime/60, elapsedTime%60,
347 status->totalTime/60, status->totalTime%60 );
348 }
349 #ifndef NCMPC_MINI
350 } else {
351 g_snprintf(screen.buf, screen.buf_size,
352 " [%d kbps]", status->bitRate );
353 #endif
354 }
355 #ifndef NCMPC_MINI
356 } else {
357 if (options.display_time) {
358 time_t timep;
360 time(&timep);
361 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
362 }
363 #endif
364 }
366 /* display song */
367 if (status != NULL && (IS_PLAYING(status->state) ||
368 IS_PAUSED(status->state))) {
369 char songname[MAX_SONGNAME_LENGTH];
370 #ifndef NCMPC_MINI
371 int width = COLS - x - utf8_width(screen.buf);
372 #endif
374 if (song)
375 strfsong(songname, MAX_SONGNAME_LENGTH,
376 options.status_format, song);
377 else
378 songname[0] = '\0';
380 colors_use(w, COLOR_STATUS);
381 /* scroll if the song name is to long */
382 #ifndef NCMPC_MINI
383 if (options.scroll && utf8_width(songname) > (unsigned)width) {
384 static scroll_state_t st = { 0, 0 };
385 char *tmp = strscroll(songname, options.scroll_sep, width, &st);
387 g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
388 g_free(tmp);
389 }
390 #endif
391 //mvwaddnstr(w, 0, x, songname, width);
392 mvwaddstr(w, 0, x, songname);
393 }
395 /* display time string */
396 if (screen.buf[0]) {
397 x = screen.status_window.cols - strlen(screen.buf);
398 colors_use(w, COLOR_STATUS_TIME);
399 mvwaddstr(w, 0, x, screen.buf);
400 }
402 wnoutrefresh(w);
403 }
405 void
406 screen_exit(void)
407 {
408 if (mode_fn->close != NULL)
409 mode_fn->close();
411 screen_list_exit();
413 string_list_free(screen.find_history);
414 g_free(screen.buf);
415 g_free(screen.findbuf);
416 }
418 void
419 screen_resize(struct mpdclient *c)
420 {
421 if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
422 screen_exit();
423 fprintf(stderr, "%s", _("Error: Screen too small"));
424 exit(EXIT_FAILURE);
425 }
427 resizeterm(LINES, COLS);
429 screen.cols = COLS;
430 screen.rows = LINES;
432 /* top window */
433 screen.top_window.cols = screen.cols;
434 wresize(screen.top_window.w, 2, screen.cols);
436 /* main window */
437 screen.main_window.cols = screen.cols;
438 screen.main_window.rows = screen.rows-4;
439 wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
440 wclear(screen.main_window.w);
442 /* progress window */
443 screen.progress_window.cols = screen.cols;
444 wresize(screen.progress_window.w, 1, screen.cols);
445 mvwin(screen.progress_window.w, screen.rows-2, 0);
447 /* status window */
448 screen.status_window.cols = screen.cols;
449 wresize(screen.status_window.w, 1, screen.cols);
450 mvwin(screen.status_window.w, screen.rows-1, 0);
452 screen.buf_size = screen.cols;
453 g_free(screen.buf);
454 screen.buf = g_malloc(screen.cols);
456 /* resize all screens */
457 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
459 /* ? - without this the cursor becomes visible with aterm & Eterm */
460 curs_set(1);
461 curs_set(0);
463 screen_paint(c);
464 }
466 void
467 screen_status_message(const char *msg)
468 {
469 WINDOW *w = screen.status_window.w;
471 wmove(w, 0, 0);
472 wclrtoeol(w);
473 colors_use(w, COLOR_STATUS_ALERT);
474 waddstr(w, msg);
475 wnoutrefresh(w);
476 screen.status_timestamp = time(NULL);
477 }
479 void
480 screen_status_printf(const char *format, ...)
481 {
482 char *msg;
483 va_list ap;
485 va_start(ap,format);
486 msg = g_strdup_vprintf(format,ap);
487 va_end(ap);
488 screen_status_message(msg);
489 g_free(msg);
490 }
492 void
493 screen_init(mpdclient_t *c)
494 {
495 if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
496 fprintf(stderr, "%s\n", _("Error: Screen too small"));
497 exit(EXIT_FAILURE);
498 }
500 screen.cols = COLS;
501 screen.rows = LINES;
503 screen.buf = g_malloc(screen.cols);
504 screen.buf_size = screen.cols;
505 screen.findbuf = NULL;
506 screen.start_timestamp = time(NULL);
507 screen.last_cmd = CMD_NONE;
509 /* create top window */
510 screen.top_window.rows = 2;
511 screen.top_window.cols = screen.cols;
512 screen.top_window.w = newwin(screen.top_window.rows,
513 screen.top_window.cols,
514 0, 0);
515 leaveok(screen.top_window.w, TRUE);
516 keypad(screen.top_window.w, TRUE);
518 /* create main window */
519 screen.main_window.rows = screen.rows-4;
520 screen.main_window.cols = screen.cols;
521 screen.main_window.w = newwin(screen.main_window.rows,
522 screen.main_window.cols,
523 2,
524 0);
526 // leaveok(screen.main_window.w, TRUE); temporary disabled
527 keypad(screen.main_window.w, TRUE);
529 /* create progress window */
530 screen.progress_window.rows = 1;
531 screen.progress_window.cols = screen.cols;
532 screen.progress_window.w = newwin(screen.progress_window.rows,
533 screen.progress_window.cols,
534 screen.rows-2,
535 0);
536 leaveok(screen.progress_window.w, TRUE);
538 /* create status window */
539 screen.status_window.rows = 1;
540 screen.status_window.cols = screen.cols;
541 screen.status_window.w = newwin(screen.status_window.rows,
542 screen.status_window.cols,
543 screen.rows-1,
544 0);
546 leaveok(screen.status_window.w, FALSE);
547 keypad(screen.status_window.w, TRUE);
549 #ifdef ENABLE_COLORS
550 if (options.enable_colors) {
551 /* set background attributes */
552 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
553 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
554 wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
555 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
556 wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
557 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
558 }
559 #endif
561 refresh();
563 /* initialize screens */
564 screen_list_init(screen.main_window.w,
565 screen.main_window.cols, screen.main_window.rows);
567 if (mode_fn->open != NULL)
568 mode_fn->open(c);
569 }
571 void
572 screen_paint(mpdclient_t *c)
573 {
574 const char *title = NULL;
576 if (mode_fn->get_title != NULL)
577 title = mode_fn->get_title(screen.buf, screen.buf_size);
579 /* paint the title/header window */
580 if( title )
581 paint_top_window(title, c, 1);
582 else
583 paint_top_window("", c, 1);
585 /* paint the main window */
586 wclear(screen.main_window.w);
587 if (mode_fn->paint != NULL)
588 mode_fn->paint();
590 paint_progress_window(c);
591 paint_status_window(c);
592 wmove(screen.main_window.w, 0, 0);
593 wnoutrefresh(screen.main_window.w);
595 /* tell curses to update */
596 doupdate();
597 }
599 void
600 screen_update(mpdclient_t *c)
601 {
602 #ifndef NCMPC_MINI
603 static int repeat = -1;
604 static int random_enabled = -1;
605 static int crossfade = -1;
606 static int dbupdate = -1;
608 /* print a message if mpd status has changed */
609 if (c->status != NULL) {
610 if (repeat < 0) {
611 repeat = c->status->repeat;
612 random_enabled = c->status->random;
613 crossfade = c->status->crossfade;
614 dbupdate = c->status->updatingDb;
615 }
617 if (repeat != c->status->repeat)
618 screen_status_printf(c->status->repeat ?
619 _("Repeat is on") :
620 _("Repeat is off"));
622 if (random_enabled != c->status->random)
623 screen_status_printf(c->status->random ?
624 _("Random is on") :
625 _("Random is off"));
627 if (crossfade != c->status->crossfade)
628 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
630 if (dbupdate && dbupdate != c->status->updatingDb) {
631 screen_status_printf(_("Database updated"));
632 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
633 }
635 repeat = c->status->repeat;
636 random_enabled = c->status->random;
637 crossfade = c->status->crossfade;
638 dbupdate = c->status->updatingDb;
639 }
641 /* update title/header window */
642 if (welcome && options.welcome_screen_list &&
643 screen.last_cmd==CMD_NONE &&
644 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
645 paint_top_window("", c, 0);
646 else
647 #endif
648 if (mode_fn->get_title != NULL) {
649 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
650 #ifndef NCMPC_MINI
651 welcome = FALSE;
652 #endif
653 } else
654 paint_top_window("", c, 0);
656 /* update the main window */
657 if (mode_fn->update != NULL)
658 mode_fn->update(c);
660 /* update progress window */
661 paint_progress_window(c);
663 /* update status window */
664 paint_status_window(c);
666 /* move the cursor to the origin */
667 wmove(screen.main_window.w, 0, 0);
668 wnoutrefresh(screen.main_window.w);
670 /* tell curses to update */
671 doupdate();
672 }
674 void
675 screen_idle(mpdclient_t *c)
676 {
677 if (c->song && seek_id == c->song->id &&
678 (screen.last_cmd == CMD_SEEK_FORWARD ||
679 screen.last_cmd == CMD_SEEK_BACKWARD))
680 mpdclient_cmd_seek(c, seek_id, seek_target_time);
682 screen.last_cmd = CMD_NONE;
683 seek_id = -1;
684 }
686 #ifdef HAVE_GETMOUSE
687 int
688 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
689 {
690 MEVENT event;
692 /* retrieve the mouse event from ncurses */
693 getmouse(&event);
694 /* calculate the selected row in the list window */
695 *row = event.y - screen.top_window.rows;
696 /* copy button state bits */
697 *bstate = event.bstate;
698 /* if button 2 was pressed switch screen */
699 if (event.bstate & BUTTON2_CLICKED) {
700 screen_cmd(c, CMD_SCREEN_NEXT);
701 return 1;
702 }
704 return 0;
705 }
706 #endif
708 static int
709 screen_client_cmd(mpdclient_t *c, command_t cmd)
710 {
711 if (c->connection == NULL || c->status == NULL)
712 return 0;
714 switch(cmd) {
715 /*
716 case CMD_PLAY:
717 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
718 break;
719 */
720 case CMD_PAUSE:
721 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
722 break;
723 case CMD_STOP:
724 mpdclient_cmd_stop(c);
725 break;
726 case CMD_CROP:
727 mpdclient_cmd_crop(c);
728 break;
729 case CMD_SEEK_FORWARD:
730 if (!IS_STOPPED(c->status->state)) {
731 if (c->song && seek_id != c->song->id) {
732 seek_id = c->song->id;
733 seek_target_time = c->status->elapsedTime;
734 }
735 seek_target_time+=options.seek_time;
736 if (seek_target_time < c->status->totalTime)
737 break;
738 seek_target_time = c->status->totalTime;
739 /* seek_target_time=0; */
740 }
741 break;
742 /* fall through... */
743 case CMD_TRACK_NEXT:
744 if (!IS_STOPPED(c->status->state))
745 mpdclient_cmd_next(c);
746 break;
747 case CMD_SEEK_BACKWARD:
748 if (!IS_STOPPED(c->status->state)) {
749 if (seek_id != c->song->id) {
750 seek_id = c->song->id;
751 seek_target_time = c->status->elapsedTime;
752 }
753 seek_target_time-=options.seek_time;
754 if (seek_target_time < 0)
755 seek_target_time=0;
756 }
757 break;
758 case CMD_TRACK_PREVIOUS:
759 if (!IS_STOPPED(c->status->state))
760 mpdclient_cmd_prev(c);
761 break;
762 case CMD_SHUFFLE:
763 if (mpdclient_cmd_shuffle(c) == 0)
764 screen_status_message(_("Shuffled playlist"));
765 break;
766 case CMD_CLEAR:
767 if (mpdclient_cmd_clear(c) == 0)
768 screen_status_message(_("Cleared playlist"));
769 break;
770 case CMD_REPEAT:
771 mpdclient_cmd_repeat(c, !c->status->repeat);
772 break;
773 case CMD_RANDOM:
774 mpdclient_cmd_random(c, !c->status->random);
775 break;
776 case CMD_CROSSFADE:
777 if (c->status->crossfade)
778 mpdclient_cmd_crossfade(c, 0);
779 else
780 mpdclient_cmd_crossfade(c, options.crossfade_time);
781 break;
782 case CMD_DB_UPDATE:
783 if (!c->status->updatingDb) {
784 if( mpdclient_cmd_db_update(c,NULL)==0 )
785 screen_status_printf(_("Database update started"));
786 } else
787 screen_status_printf(_("Database update running..."));
788 break;
789 case CMD_VOLUME_UP:
790 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
791 mpdclient_cmd_volume(c, ++c->status->volume);
792 break;
793 case CMD_VOLUME_DOWN:
794 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
795 mpdclient_cmd_volume(c, --c->status->volume);
796 break;
798 default:
799 return 0;
800 }
802 return 1;
803 }
805 void
806 screen_cmd(mpdclient_t *c, command_t cmd)
807 {
808 screen.last_cmd = cmd;
809 #ifndef NCMPC_MINI
810 welcome = FALSE;
811 #endif
813 if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
814 return;
816 if (screen_client_cmd(c, cmd))
817 return;
819 switch(cmd) {
820 case CMD_TOGGLE_FIND_WRAP:
821 options.find_wrap = !options.find_wrap;
822 screen_status_printf(options.find_wrap ?
823 _("Find mode: Wrapped") :
824 _("Find mode: Normal"));
825 break;
826 case CMD_TOGGLE_AUTOCENTER:
827 options.auto_center = !options.auto_center;
828 screen_status_printf(options.auto_center ?
829 _("Auto center mode: On") :
830 _("Auto center mode: Off"));
831 break;
832 case CMD_SCREEN_UPDATE:
833 screen_paint(c);
834 break;
835 case CMD_SCREEN_PREVIOUS:
836 screen_next_mode(c, -1);
837 break;
838 case CMD_SCREEN_NEXT:
839 screen_next_mode(c, 1);
840 break;
841 case CMD_SCREEN_PLAY:
842 screen_switch(&screen_playlist, c);
843 break;
844 case CMD_SCREEN_FILE:
845 screen_switch(&screen_browse, c);
846 break;
847 #ifdef ENABLE_HELP_SCREEN
848 case CMD_SCREEN_HELP:
849 screen_switch(&screen_help, c);
850 break;
851 #endif
852 #ifdef ENABLE_SEARCH_SCREEN
853 case CMD_SCREEN_SEARCH:
854 screen_switch(&screen_search, c);
855 break;
856 #endif
857 #ifdef ENABLE_ARTIST_SCREEN
858 case CMD_SCREEN_ARTIST:
859 screen_switch(&screen_artist, c);
860 break;
861 #endif
862 #ifdef ENABLE_SONG_SCREEN
863 case CMD_SCREEN_SONG:
864 screen_switch(&screen_song, c);
865 break;
866 #endif
867 #ifdef ENABLE_KEYDEF_SCREEN
868 case CMD_SCREEN_KEYDEF:
869 screen_switch(&screen_keydef, c);
870 break;
871 #endif
872 #ifdef ENABLE_LYRICS_SCREEN
873 case CMD_SCREEN_LYRICS:
874 screen_switch(&screen_lyrics, c);
875 break;
876 #endif
877 #ifdef ENABLE_OUTPUTS_SCREEN
878 case CMD_SCREEN_OUTPUTS:
879 screen_switch(&screen_outputs, c);
880 break;
881 case CMD_SCREEN_SWAP:
882 screen_swap(c, NULL);
883 break;
884 #endif
886 default:
887 break;
888 }
889 }