1 /*
2 * (c) 2004 by Kalle Wallin <kaw@linux.se>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
19 #include "screen.h"
20 #include "screen_list.h"
21 #include "screen_utils.h"
22 #include "config.h"
23 #include "i18n.h"
24 #include "support.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 #include <stdlib.h>
33 #include <unistd.h>
34 #include <stdarg.h>
35 #include <string.h>
36 #include <time.h>
37 #include <locale.h>
39 #ifndef NCMPC_MINI
40 /** welcome message time [s] */
41 static const GTime SCREEN_WELCOME_TIME = 10;
42 #endif
44 /** status message time [s] */
45 static const GTime SCREEN_STATUS_MESSAGE_TIME = 3;
47 /* minumum window size */
48 static const int SCREEN_MIN_COLS = 14;
49 static const int SCREEN_MIN_ROWS = 5;
51 /* screens */
53 #ifndef NCMPC_MINI
54 static gboolean welcome = TRUE;
55 #endif
57 struct screen screen;
58 static const struct screen_functions *mode_fn = &screen_playlist;
59 static int seek_id = -1;
60 static int seek_target_time = 0;
62 gboolean
63 screen_is_visible(const struct screen_functions *sf)
64 {
65 return sf == mode_fn;
66 }
68 void
69 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
70 {
71 assert(sf != NULL);
73 if (sf == mode_fn)
74 return;
76 /* close the old mode */
77 if (mode_fn->close != NULL)
78 mode_fn->close();
80 /* get functions for the new mode */
81 mode_fn = sf;
83 /* open the new mode */
84 if (mode_fn->open != NULL)
85 mode_fn->open(c);
87 screen_paint(c);
88 }
90 static int
91 find_configured_screen(const char *name)
92 {
93 unsigned i;
95 for (i = 0; options.screen_list[i] != NULL; ++i)
96 if (strcmp(options.screen_list[i], name) == 0)
97 return i;
99 return -1;
100 }
102 static void
103 screen_next_mode(mpdclient_t *c, int offset)
104 {
105 int max = g_strv_length(options.screen_list);
106 int current, next;
107 const struct screen_functions *sf;
109 /* find current screen */
110 current = find_configured_screen(screen_get_name(mode_fn));
111 next = current + offset;
112 if (next<0)
113 next = max-1;
114 else if (next>=max)
115 next = 0;
117 sf = screen_lookup_name(options.screen_list[next]);
118 if (sf != NULL)
119 screen_switch(sf, c);
120 }
122 static void
123 paint_top_window2(const char *header, mpdclient_t *c)
124 {
125 char flags[5];
126 WINDOW *w = screen.top_window.w;
127 char buf[32];
129 if (header[0]) {
130 colors_use(w, COLOR_TITLE_BOLD);
131 mvwaddstr(w, 0, 0, header);
132 #ifndef NCMPC_MINI
133 } else {
134 colors_use(w, COLOR_TITLE_BOLD);
135 waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
136 colors_use(w, COLOR_TITLE);
137 waddstr(w, _(":Help "));
138 colors_use(w, COLOR_TITLE_BOLD);
139 waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE));
140 colors_use(w, COLOR_TITLE);
141 waddstr(w, _(":Playlist "));
142 colors_use(w, COLOR_TITLE_BOLD);
143 waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE));
144 colors_use(w, COLOR_TITLE);
145 waddstr(w, _(":Browse "));
146 #ifdef ENABLE_ARTIST_SCREEN
147 colors_use(w, COLOR_TITLE_BOLD);
148 waddstr(w, get_key_names(CMD_SCREEN_ARTIST, FALSE));
149 colors_use(w, COLOR_TITLE);
150 waddstr(w, _(":Artist "));
151 #endif
152 #ifdef ENABLE_SEARCH_SCREEN
153 colors_use(w, COLOR_TITLE_BOLD);
154 waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE));
155 colors_use(w, COLOR_TITLE);
156 waddstr(w, _(":Search "));
157 #endif
158 #ifdef ENABLE_LYRICS_SCREEN
159 colors_use(w, COLOR_TITLE_BOLD);
160 waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE));
161 colors_use(w, COLOR_TITLE);
162 waddstr(w, _(":Lyrics "));
163 #endif
164 #endif
165 }
167 if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
168 g_snprintf(buf, 32, _("Volume n/a "));
169 } else {
170 g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
171 }
172 colors_use(w, COLOR_TITLE);
173 mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
175 flags[0] = 0;
176 if (c->status != NULL) {
177 if (c->status->repeat)
178 g_strlcat(flags, "r", sizeof(flags));
179 if (c->status->random)
180 g_strlcat(flags, "z", sizeof(flags));;
181 if (c->status->crossfade)
182 g_strlcat(flags, "x", sizeof(flags));
183 if (c->status->updatingDb)
184 g_strlcat(flags, "U", sizeof(flags));
185 }
187 colors_use(w, COLOR_LINE);
188 mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
189 if (flags[0]) {
190 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
191 waddch(w, '[');
192 colors_use(w, COLOR_LINE_BOLD);
193 waddstr(w, flags);
194 colors_use(w, COLOR_LINE);
195 waddch(w, ']');
196 }
197 wnoutrefresh(w);
198 }
200 static void
201 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
202 {
203 static int prev_volume = -1;
204 static unsigned prev_header_len = -1;
205 WINDOW *w = screen.top_window.w;
207 if (prev_header_len != utf8_width(header)) {
208 prev_header_len = utf8_width(header);
209 full_repaint = 1;
210 }
212 if (full_repaint) {
213 wmove(w, 0, 0);
214 wclrtoeol(w);
215 }
217 if ((c->status != NULL && prev_volume != c->status->volume) ||
218 full_repaint)
219 paint_top_window2(header, c);
220 }
222 static void
223 paint_progress_window(mpdclient_t *c)
224 {
225 double p;
226 int width;
227 int elapsedTime;
229 if (c->status==NULL || IS_STOPPED(c->status->state)) {
230 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
231 screen.progress_window.cols);
232 wnoutrefresh(screen.progress_window.w);
233 return;
234 }
236 if (c->song && seek_id == c->song->id)
237 elapsedTime = seek_target_time;
238 else
239 elapsedTime = c->status->elapsedTime;
241 p = ((double) elapsedTime) / ((double) c->status->totalTime);
243 width = (int) (p * (double) screen.progress_window.cols);
244 mvwhline(screen.progress_window.w,
245 0, 0,
246 ACS_HLINE,
247 screen.progress_window.cols);
248 whline(screen.progress_window.w, '=', width-1);
249 mvwaddch(screen.progress_window.w, 0, width-1, 'O');
250 wnoutrefresh(screen.progress_window.w);
251 }
253 static void
254 paint_status_window(mpdclient_t *c)
255 {
256 WINDOW *w = screen.status_window.w;
257 mpd_Status *status = c->status;
258 mpd_Song *song = c->song;
259 int elapsedTime = 0;
260 #ifdef NCMPC_MINI
261 static char bitrate[1];
262 #else
263 char bitrate[16];
264 #endif
265 const char *str = NULL;
266 int x = 0;
268 if( time(NULL) - screen.status_timestamp <= SCREEN_STATUS_MESSAGE_TIME )
269 return;
271 wmove(w, 0, 0);
272 wclrtoeol(w);
273 colors_use(w, COLOR_STATUS_BOLD);
275 switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
276 case MPD_STATUS_STATE_PLAY:
277 str = _("Playing:");
278 break;
279 case MPD_STATUS_STATE_PAUSE:
280 str = _("[Paused]");
281 break;
282 case MPD_STATUS_STATE_STOP:
283 default:
284 break;
285 }
287 if (str) {
288 waddstr(w, str);
289 x += utf8_width(str) + 1;
290 }
292 /* create time string */
293 memset(screen.buf, 0, screen.buf_size);
294 if (status != NULL && (IS_PLAYING(status->state) ||
295 IS_PAUSED(status->state))) {
296 if (status->totalTime > 0) {
297 /*checks the conf to see whether to display elapsed or remaining time */
298 if(!strcmp(options.timedisplay_type,"elapsed"))
299 elapsedTime = c->status->elapsedTime;
300 else if(!strcmp(options.timedisplay_type,"remaining"))
301 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
303 if( c->song && seek_id == c->song->id )
304 elapsedTime = seek_target_time;
306 /* display bitrate if visible-bitrate is true */
307 #ifndef NCMPC_MINI
308 if (options.visible_bitrate) {
309 g_snprintf(bitrate, 16,
310 " [%d kbps]", status->bitRate);
311 } else {
312 bitrate[0] = '\0';
313 }
314 #endif
316 /*write out the time, using hours if time over 60 minutes*/
317 if (c->status->totalTime > 3600) {
318 g_snprintf(screen.buf, screen.buf_size,
319 "%s [%i:%02i:%02i/%i:%02i:%02i]",
320 bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
321 status->totalTime/3600, (status->totalTime%3600)/60, status->totalTime%60);
322 } else {
323 g_snprintf(screen.buf, screen.buf_size,
324 "%s [%i:%02i/%i:%02i]",
325 bitrate, elapsedTime/60, elapsedTime%60,
326 status->totalTime/60, status->totalTime%60 );
327 }
328 #ifndef NCMPC_MINI
329 } else {
330 g_snprintf(screen.buf, screen.buf_size,
331 " [%d kbps]", status->bitRate );
332 #endif
333 }
334 #ifndef NCMPC_MINI
335 } else {
336 time_t timep;
338 time(&timep);
339 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
340 #endif
341 }
343 /* display song */
344 if (status != NULL && (IS_PLAYING(status->state) ||
345 IS_PAUSED(status->state))) {
346 char songname[MAX_SONGNAME_LENGTH];
347 #ifndef NCMPC_MINI
348 int width = COLS - x - utf8_width(screen.buf);
349 #endif
351 if (song)
352 strfsong(songname, MAX_SONGNAME_LENGTH,
353 options.status_format, song);
354 else
355 songname[0] = '\0';
357 colors_use(w, COLOR_STATUS);
358 /* scroll if the song name is to long */
359 #ifndef NCMPC_MINI
360 if (options.scroll && utf8_width(songname) > (unsigned)width) {
361 static scroll_state_t st = { 0, 0 };
362 char *tmp = strscroll(songname, options.scroll_sep, width, &st);
364 g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
365 g_free(tmp);
366 }
367 #endif
368 //mvwaddnstr(w, 0, x, songname, width);
369 mvwaddstr(w, 0, x, songname);
370 }
372 /* display time string */
373 if (screen.buf[0]) {
374 x = screen.status_window.cols - strlen(screen.buf);
375 colors_use(w, COLOR_STATUS_TIME);
376 mvwaddstr(w, 0, x, screen.buf);
377 }
379 wnoutrefresh(w);
380 }
382 void
383 screen_exit(void)
384 {
385 if (mode_fn->close != NULL)
386 mode_fn->close();
388 screen_list_exit();
390 string_list_free(screen.find_history);
391 g_free(screen.buf);
392 g_free(screen.findbuf);
393 }
395 void
396 screen_resize(struct mpdclient *c)
397 {
398 if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
399 screen_exit();
400 fprintf(stderr, _("Error: Screen to small!\n"));
401 exit(EXIT_FAILURE);
402 }
404 resizeterm(LINES, COLS);
406 screen.cols = COLS;
407 screen.rows = LINES;
409 /* top window */
410 screen.top_window.cols = screen.cols;
411 wresize(screen.top_window.w, 2, screen.cols);
413 /* main window */
414 screen.main_window.cols = screen.cols;
415 screen.main_window.rows = screen.rows-4;
416 wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
417 wclear(screen.main_window.w);
419 /* progress window */
420 screen.progress_window.cols = screen.cols;
421 wresize(screen.progress_window.w, 1, screen.cols);
422 mvwin(screen.progress_window.w, screen.rows-2, 0);
424 /* status window */
425 screen.status_window.cols = screen.cols;
426 wresize(screen.status_window.w, 1, screen.cols);
427 mvwin(screen.status_window.w, screen.rows-1, 0);
429 screen.buf_size = screen.cols;
430 g_free(screen.buf);
431 screen.buf = g_malloc(screen.cols);
433 /* resize all screens */
434 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
436 /* ? - without this the cursor becomes visible with aterm & Eterm */
437 curs_set(1);
438 curs_set(0);
440 screen_paint(c);
441 }
443 void
444 screen_status_message(const char *msg)
445 {
446 WINDOW *w = screen.status_window.w;
448 wmove(w, 0, 0);
449 wclrtoeol(w);
450 colors_use(w, COLOR_STATUS_ALERT);
451 waddstr(w, msg);
452 wnoutrefresh(w);
453 screen.status_timestamp = time(NULL);
454 }
456 void
457 screen_status_printf(const char *format, ...)
458 {
459 char *msg;
460 va_list ap;
462 va_start(ap,format);
463 msg = g_strdup_vprintf(format,ap);
464 va_end(ap);
465 screen_status_message(msg);
466 g_free(msg);
467 }
469 void
470 screen_init(mpdclient_t *c)
471 {
472 if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
473 fprintf(stderr, _("Error: Screen to small!\n"));
474 exit(EXIT_FAILURE);
475 }
477 screen.cols = COLS;
478 screen.rows = LINES;
480 screen.buf = g_malloc(screen.cols);
481 screen.buf_size = screen.cols;
482 screen.findbuf = NULL;
483 screen.start_timestamp = time(NULL);
484 screen.last_cmd = CMD_NONE;
486 /* create top window */
487 screen.top_window.rows = 2;
488 screen.top_window.cols = screen.cols;
489 screen.top_window.w = newwin(screen.top_window.rows,
490 screen.top_window.cols,
491 0, 0);
492 leaveok(screen.top_window.w, TRUE);
493 keypad(screen.top_window.w, TRUE);
495 /* create main window */
496 screen.main_window.rows = screen.rows-4;
497 screen.main_window.cols = screen.cols;
498 screen.main_window.w = newwin(screen.main_window.rows,
499 screen.main_window.cols,
500 2,
501 0);
503 // leaveok(screen.main_window.w, TRUE); temporary disabled
504 keypad(screen.main_window.w, TRUE);
506 /* create progress window */
507 screen.progress_window.rows = 1;
508 screen.progress_window.cols = screen.cols;
509 screen.progress_window.w = newwin(screen.progress_window.rows,
510 screen.progress_window.cols,
511 screen.rows-2,
512 0);
513 leaveok(screen.progress_window.w, TRUE);
515 /* create status window */
516 screen.status_window.rows = 1;
517 screen.status_window.cols = screen.cols;
518 screen.status_window.w = newwin(screen.status_window.rows,
519 screen.status_window.cols,
520 screen.rows-1,
521 0);
523 leaveok(screen.status_window.w, FALSE);
524 keypad(screen.status_window.w, TRUE);
526 #ifdef ENABLE_COLORS
527 if (options.enable_colors) {
528 /* set background attributes */
529 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
530 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
531 wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
532 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
533 wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
534 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
535 }
536 #endif
538 refresh();
540 /* initialize screens */
541 screen_list_init(screen.main_window.w,
542 screen.main_window.cols, screen.main_window.rows);
544 if (mode_fn->open != NULL)
545 mode_fn->open(c);
546 }
548 void
549 screen_paint(mpdclient_t *c)
550 {
551 const char *title = NULL;
553 if (mode_fn->get_title != NULL)
554 title = mode_fn->get_title(screen.buf, screen.buf_size);
556 /* paint the title/header window */
557 if( title )
558 paint_top_window(title, c, 1);
559 else
560 paint_top_window("", c, 1);
562 /* paint the main window */
563 wclear(screen.main_window.w);
564 if (mode_fn->paint != NULL)
565 mode_fn->paint();
567 paint_progress_window(c);
568 paint_status_window(c);
569 wmove(screen.main_window.w, 0, 0);
570 wnoutrefresh(screen.main_window.w);
572 /* tell curses to update */
573 doupdate();
574 }
576 void
577 screen_update(mpdclient_t *c)
578 {
579 #ifndef NCMPC_MINI
580 static int repeat = -1;
581 static int random_enabled = -1;
582 static int crossfade = -1;
583 static int dbupdate = -1;
585 /* print a message if mpd status has changed */
586 if (c->status != NULL) {
587 if (repeat < 0) {
588 repeat = c->status->repeat;
589 random_enabled = c->status->random;
590 crossfade = c->status->crossfade;
591 dbupdate = c->status->updatingDb;
592 }
594 if (repeat != c->status->repeat)
595 screen_status_printf(c->status->repeat ?
596 _("Repeat is on") :
597 _("Repeat is off"));
599 if (random_enabled != c->status->random)
600 screen_status_printf(c->status->random ?
601 _("Random is on") :
602 _("Random is off"));
604 if (crossfade != c->status->crossfade)
605 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
607 if (dbupdate && dbupdate != c->status->updatingDb) {
608 screen_status_printf(_("Database updated!"));
609 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
610 }
612 repeat = c->status->repeat;
613 random_enabled = c->status->random;
614 crossfade = c->status->crossfade;
615 dbupdate = c->status->updatingDb;
616 }
618 /* update title/header window */
619 if (welcome && options.welcome_screen_list &&
620 screen.last_cmd==CMD_NONE &&
621 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
622 paint_top_window("", c, 0);
623 else
624 #endif
625 if (mode_fn->get_title != NULL) {
626 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
627 #ifndef NCMPC_MINI
628 welcome = FALSE;
629 #endif
630 } else
631 paint_top_window("", c, 0);
633 /* update the main window */
634 if (mode_fn->update != NULL)
635 mode_fn->update(c);
637 /* update progress window */
638 paint_progress_window(c);
640 /* update status window */
641 paint_status_window(c);
643 /* move the cursor to the origin */
644 wmove(screen.main_window.w, 0, 0);
645 wnoutrefresh(screen.main_window.w);
647 /* tell curses to update */
648 doupdate();
649 }
651 void
652 screen_idle(mpdclient_t *c)
653 {
654 if (c->song && seek_id == c->song->id &&
655 (screen.last_cmd == CMD_SEEK_FORWARD ||
656 screen.last_cmd == CMD_SEEK_BACKWARD))
657 mpdclient_cmd_seek(c, seek_id, seek_target_time);
659 screen.last_cmd = CMD_NONE;
660 seek_id = -1;
661 }
663 #ifdef HAVE_GETMOUSE
664 int
665 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
666 {
667 MEVENT event;
669 /* retreive the mouse event from ncurses */
670 getmouse(&event);
671 /* calculate the selected row in the list window */
672 *row = event.y - screen.top_window.rows;
673 /* copy button state bits */
674 *bstate = event.bstate;
675 /* if button 2 was pressed switch screen */
676 if (event.bstate & BUTTON2_CLICKED) {
677 screen_cmd(c, CMD_SCREEN_NEXT);
678 return 1;
679 }
681 return 0;
682 }
683 #endif
685 static int
686 screen_client_cmd(mpdclient_t *c, command_t cmd)
687 {
688 if (c->connection == NULL || c->status == NULL)
689 return 0;
691 switch(cmd) {
692 /*
693 case CMD_PLAY:
694 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
695 break;
696 */
697 case CMD_PAUSE:
698 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
699 break;
700 case CMD_STOP:
701 mpdclient_cmd_stop(c);
702 break;
703 case CMD_CROP:
704 mpdclient_cmd_crop(c);
705 break;
706 case CMD_SEEK_FORWARD:
707 if (!IS_STOPPED(c->status->state)) {
708 if (c->song && seek_id != c->song->id) {
709 seek_id = c->song->id;
710 seek_target_time = c->status->elapsedTime;
711 }
712 seek_target_time+=options.seek_time;
713 if (seek_target_time < c->status->totalTime)
714 break;
715 seek_target_time = c->status->totalTime;
716 /* seek_target_time=0; */
717 }
718 break;
719 /* fall through... */
720 case CMD_TRACK_NEXT:
721 if (!IS_STOPPED(c->status->state))
722 mpdclient_cmd_next(c);
723 break;
724 case CMD_SEEK_BACKWARD:
725 if (!IS_STOPPED(c->status->state)) {
726 if (seek_id != c->song->id) {
727 seek_id = c->song->id;
728 seek_target_time = c->status->elapsedTime;
729 }
730 seek_target_time-=options.seek_time;
731 if (seek_target_time < 0)
732 seek_target_time=0;
733 }
734 break;
735 case CMD_TRACK_PREVIOUS:
736 if (!IS_STOPPED(c->status->state))
737 mpdclient_cmd_prev(c);
738 break;
739 case CMD_SHUFFLE:
740 if (mpdclient_cmd_shuffle(c) == 0)
741 screen_status_message(_("Shuffled playlist!"));
742 break;
743 case CMD_CLEAR:
744 if (mpdclient_cmd_clear(c) == 0)
745 screen_status_message(_("Cleared playlist!"));
746 break;
747 case CMD_REPEAT:
748 mpdclient_cmd_repeat(c, !c->status->repeat);
749 break;
750 case CMD_RANDOM:
751 mpdclient_cmd_random(c, !c->status->random);
752 break;
753 case CMD_CROSSFADE:
754 if (c->status->crossfade)
755 mpdclient_cmd_crossfade(c, 0);
756 else
757 mpdclient_cmd_crossfade(c, options.crossfade_time);
758 break;
759 case CMD_DB_UPDATE:
760 if (!c->status->updatingDb) {
761 if( mpdclient_cmd_db_update(c,NULL)==0 )
762 screen_status_printf(_("Database update started!"));
763 } else
764 screen_status_printf(_("Database update running..."));
765 break;
766 case CMD_VOLUME_UP:
767 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
768 mpdclient_cmd_volume(c, ++c->status->volume);
769 break;
770 case CMD_VOLUME_DOWN:
771 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
772 mpdclient_cmd_volume(c, --c->status->volume);
773 break;
775 default:
776 return 0;
777 }
779 return 1;
780 }
782 void
783 screen_cmd(mpdclient_t *c, command_t cmd)
784 {
785 screen.last_cmd = cmd;
786 #ifndef NCMPC_MINI
787 welcome = FALSE;
788 #endif
790 if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
791 return;
793 if (screen_client_cmd(c, cmd))
794 return;
796 switch(cmd) {
797 case CMD_TOGGLE_FIND_WRAP:
798 options.find_wrap = !options.find_wrap;
799 screen_status_printf(options.find_wrap ?
800 _("Find mode: Wrapped") :
801 _("Find mode: Normal"));
802 break;
803 case CMD_TOGGLE_AUTOCENTER:
804 options.auto_center = !options.auto_center;
805 screen_status_printf(options.auto_center ?
806 _("Auto center mode: On") :
807 _("Auto center mode: Off"));
808 break;
809 case CMD_SCREEN_UPDATE:
810 screen_paint(c);
811 break;
812 case CMD_SCREEN_PREVIOUS:
813 screen_next_mode(c, -1);
814 break;
815 case CMD_SCREEN_NEXT:
816 screen_next_mode(c, 1);
817 break;
818 case CMD_SCREEN_PLAY:
819 screen_switch(&screen_playlist, c);
820 break;
821 case CMD_SCREEN_FILE:
822 screen_switch(&screen_browse, c);
823 break;
824 #ifdef ENABLE_HELP_SCREEN
825 case CMD_SCREEN_HELP:
826 screen_switch(&screen_help, c);
827 break;
828 #endif
829 #ifdef ENABLE_SEARCH_SCREEN
830 case CMD_SCREEN_SEARCH:
831 screen_switch(&screen_search, c);
832 break;
833 #endif
834 #ifdef ENABLE_ARTIST_SCREEN
835 case CMD_SCREEN_ARTIST:
836 screen_switch(&screen_artist, c);
837 break;
838 #endif
839 #ifdef ENABLE_KEYDEF_SCREEN
840 case CMD_SCREEN_KEYDEF:
841 screen_switch(&screen_keydef, c);
842 break;
843 #endif
844 #ifdef ENABLE_LYRICS_SCREEN
845 case CMD_SCREEN_LYRICS:
846 screen_switch(&screen_lyrics, c);
847 break;
848 #endif
849 default:
850 break;
851 }
852 }