Code

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