Code

Update copyright notices
[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 /** status message time [s] */
49 static const GTime SCREEN_STATUS_MESSAGE_TIME = 3;
51 /* minumum window size */
52 static const int SCREEN_MIN_COLS = 14;
53 static const int SCREEN_MIN_ROWS = 5;
55 /* screens */
57 #ifndef NCMPC_MINI
58 static gboolean welcome = TRUE;
59 #endif
61 struct screen screen;
62 static const struct screen_functions *mode_fn = &screen_playlist;
63 static int seek_id = -1;
64 static int seek_target_time = 0;
66 gboolean
67 screen_is_visible(const struct screen_functions *sf)
68 {
69         return sf == mode_fn;
70 }
72 void
73 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
74 {
75         assert(sf != NULL);
77         if (sf == mode_fn)
78                 return;
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 <= SCREEN_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                 time_t timep;
343                 time(&timep);
344                 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
345 #endif
346         }
348         /* display song */
349         if (status != NULL && (IS_PLAYING(status->state) ||
350                                IS_PAUSED(status->state))) {
351                 char songname[MAX_SONGNAME_LENGTH];
352 #ifndef NCMPC_MINI
353                 int width = COLS - x - utf8_width(screen.buf);
354 #endif
356                 if (song)
357                         strfsong(songname, MAX_SONGNAME_LENGTH,
358                                  options.status_format, song);
359                 else
360                         songname[0] = '\0';
362                 colors_use(w, COLOR_STATUS);
363                 /* scroll if the song name is to long */
364 #ifndef NCMPC_MINI
365                 if (options.scroll && utf8_width(songname) > (unsigned)width) {
366                         static  scroll_state_t st = { 0, 0 };
367                         char *tmp = strscroll(songname, options.scroll_sep, width, &st);
369                         g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
370                         g_free(tmp);
371                 }
372 #endif
373                 //mvwaddnstr(w, 0, x, songname, width);
374                 mvwaddstr(w, 0, x, songname);
375         }
377         /* display time string */
378         if (screen.buf[0]) {
379                 x = screen.status_window.cols - strlen(screen.buf);
380                 colors_use(w, COLOR_STATUS_TIME);
381                 mvwaddstr(w, 0, x, screen.buf);
382         }
384         wnoutrefresh(w);
387 void
388 screen_exit(void)
390         if (mode_fn->close != NULL)
391                 mode_fn->close();
393         screen_list_exit();
395         string_list_free(screen.find_history);
396         g_free(screen.buf);
397         g_free(screen.findbuf);
400 void
401 screen_resize(struct mpdclient *c)
403         if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
404                 screen_exit();
405                 fprintf(stderr, "%s", _("Error: Screen too small"));
406                 exit(EXIT_FAILURE);
407         }
409         resizeterm(LINES, COLS);
411         screen.cols = COLS;
412         screen.rows = LINES;
414         /* top window */
415         screen.top_window.cols = screen.cols;
416         wresize(screen.top_window.w, 2, screen.cols);
418         /* main window */
419         screen.main_window.cols = screen.cols;
420         screen.main_window.rows = screen.rows-4;
421         wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
422         wclear(screen.main_window.w);
424         /* progress window */
425         screen.progress_window.cols = screen.cols;
426         wresize(screen.progress_window.w, 1, screen.cols);
427         mvwin(screen.progress_window.w, screen.rows-2, 0);
429         /* status window */
430         screen.status_window.cols = screen.cols;
431         wresize(screen.status_window.w, 1, screen.cols);
432         mvwin(screen.status_window.w, screen.rows-1, 0);
434         screen.buf_size = screen.cols;
435         g_free(screen.buf);
436         screen.buf = g_malloc(screen.cols);
438         /* resize all screens */
439         screen_list_resize(screen.main_window.cols, screen.main_window.rows);
441         /* ? - without this the cursor becomes visible with aterm & Eterm */
442         curs_set(1);
443         curs_set(0);
445         screen_paint(c);
448 void
449 screen_status_message(const char *msg)
451         WINDOW *w = screen.status_window.w;
453         wmove(w, 0, 0);
454         wclrtoeol(w);
455         colors_use(w, COLOR_STATUS_ALERT);
456         waddstr(w, msg);
457         wnoutrefresh(w);
458         screen.status_timestamp = time(NULL);
461 void
462 screen_status_printf(const char *format, ...)
464         char *msg;
465         va_list ap;
467         va_start(ap,format);
468         msg = g_strdup_vprintf(format,ap);
469         va_end(ap);
470         screen_status_message(msg);
471         g_free(msg);
474 void
475 screen_init(mpdclient_t *c)
477         if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
478                 fprintf(stderr, "%s\n", _("Error: Screen too small"));
479                 exit(EXIT_FAILURE);
480         }
482         screen.cols = COLS;
483         screen.rows = LINES;
485         screen.buf  = g_malloc(screen.cols);
486         screen.buf_size = screen.cols;
487         screen.findbuf = NULL;
488         screen.start_timestamp = time(NULL);
489         screen.last_cmd = CMD_NONE;
491         /* create top window */
492         screen.top_window.rows = 2;
493         screen.top_window.cols = screen.cols;
494         screen.top_window.w = newwin(screen.top_window.rows,
495                                       screen.top_window.cols,
496                                       0, 0);
497         leaveok(screen.top_window.w, TRUE);
498         keypad(screen.top_window.w, TRUE);
500         /* create main window */
501         screen.main_window.rows = screen.rows-4;
502         screen.main_window.cols = screen.cols;
503         screen.main_window.w = newwin(screen.main_window.rows,
504                                        screen.main_window.cols,
505                                        2,
506                                        0);
508         //  leaveok(screen.main_window.w, TRUE); temporary disabled
509         keypad(screen.main_window.w, TRUE);
511         /* create progress window */
512         screen.progress_window.rows = 1;
513         screen.progress_window.cols = screen.cols;
514         screen.progress_window.w = newwin(screen.progress_window.rows,
515                                            screen.progress_window.cols,
516                                            screen.rows-2,
517                                            0);
518         leaveok(screen.progress_window.w, TRUE);
520         /* create status window */
521         screen.status_window.rows = 1;
522         screen.status_window.cols = screen.cols;
523         screen.status_window.w = newwin(screen.status_window.rows,
524                                          screen.status_window.cols,
525                                          screen.rows-1,
526                                          0);
528         leaveok(screen.status_window.w, FALSE);
529         keypad(screen.status_window.w, TRUE);
531 #ifdef ENABLE_COLORS
532         if (options.enable_colors) {
533                 /* set background attributes */
534                 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
535                 wbkgd(screen.main_window.w,     COLOR_PAIR(COLOR_LIST));
536                 wbkgd(screen.top_window.w,      COLOR_PAIR(COLOR_TITLE));
537                 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
538                 wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
539                 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
540         }
541 #endif
543         refresh();
545         /* initialize screens */
546         screen_list_init(screen.main_window.w,
547                          screen.main_window.cols, screen.main_window.rows);
549         if (mode_fn->open != NULL)
550                 mode_fn->open(c);
553 void
554 screen_paint(mpdclient_t *c)
556         const char *title = NULL;
558         if (mode_fn->get_title != NULL)
559                 title = mode_fn->get_title(screen.buf, screen.buf_size);
561         /* paint the title/header window */
562         if( title )
563                 paint_top_window(title, c, 1);
564         else
565                 paint_top_window("", c, 1);
567         /* paint the main window */
568         wclear(screen.main_window.w);
569         if (mode_fn->paint != NULL)
570                 mode_fn->paint();
572         paint_progress_window(c);
573         paint_status_window(c);
574         wmove(screen.main_window.w, 0, 0);
575         wnoutrefresh(screen.main_window.w);
577         /* tell curses to update */
578         doupdate();
581 void
582 screen_update(mpdclient_t *c)
584 #ifndef NCMPC_MINI
585         static int repeat = -1;
586         static int random_enabled = -1;
587         static int crossfade = -1;
588         static int dbupdate = -1;
590         /* print a message if mpd status has changed */
591         if (c->status != NULL) {
592                 if (repeat < 0) {
593                         repeat = c->status->repeat;
594                         random_enabled = c->status->random;
595                         crossfade = c->status->crossfade;
596                         dbupdate = c->status->updatingDb;
597                 }
599                 if (repeat != c->status->repeat)
600                         screen_status_printf(c->status->repeat ?
601                                              _("Repeat is on") :
602                                              _("Repeat is off"));
604                 if (random_enabled != c->status->random)
605                         screen_status_printf(c->status->random ?
606                                              _("Random is on") :
607                                              _("Random is off"));
609                 if (crossfade != c->status->crossfade)
610                         screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
612                 if (dbupdate && dbupdate != c->status->updatingDb) {
613                         screen_status_printf(_("Database updated"));
614                         mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
615                 }
617                 repeat = c->status->repeat;
618                 random_enabled = c->status->random;
619                 crossfade = c->status->crossfade;
620                 dbupdate = c->status->updatingDb;
621         }
623         /* update title/header window */
624         if (welcome && options.welcome_screen_list &&
625             screen.last_cmd==CMD_NONE &&
626             time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
627                 paint_top_window("", c, 0);
628         else
629 #endif
630         if (mode_fn->get_title != NULL) {
631                 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
632 #ifndef NCMPC_MINI
633                 welcome = FALSE;
634 #endif
635         } else
636                 paint_top_window("", c, 0);
638         /* update the main window */
639         if (mode_fn->update != NULL)
640                 mode_fn->update(c);
642         /* update progress window */
643         paint_progress_window(c);
645         /* update status window */
646         paint_status_window(c);
648         /* move the cursor to the origin */
649         wmove(screen.main_window.w, 0, 0);
650         wnoutrefresh(screen.main_window.w);
652         /* tell curses to update */
653         doupdate();
656 void
657 screen_idle(mpdclient_t *c)
659         if (c->song && seek_id == c->song->id &&
660             (screen.last_cmd == CMD_SEEK_FORWARD ||
661              screen.last_cmd == CMD_SEEK_BACKWARD))
662                 mpdclient_cmd_seek(c, seek_id, seek_target_time);
664         screen.last_cmd = CMD_NONE;
665         seek_id = -1;
668 #ifdef HAVE_GETMOUSE
669 int
670 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
672         MEVENT event;
674         /* retreive the mouse event from ncurses */
675         getmouse(&event);
676         /* calculate the selected row in the list window */
677         *row = event.y - screen.top_window.rows;
678         /* copy button state bits */
679         *bstate = event.bstate;
680         /* if button 2 was pressed switch screen */
681         if (event.bstate & BUTTON2_CLICKED) {
682                 screen_cmd(c, CMD_SCREEN_NEXT);
683                 return 1;
684         }
686         return 0;
688 #endif
690 static int
691 screen_client_cmd(mpdclient_t *c, command_t cmd)
693         if (c->connection == NULL || c->status == NULL)
694                 return 0;
696         switch(cmd) {
697                 /*
698         case CMD_PLAY:
699                 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
700                 break;
701                 */
702         case CMD_PAUSE:
703                 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
704                 break;
705         case CMD_STOP:
706                 mpdclient_cmd_stop(c);
707                 break;
708         case CMD_CROP:
709                 mpdclient_cmd_crop(c);
710                 break;
711         case CMD_SEEK_FORWARD:
712                 if (!IS_STOPPED(c->status->state)) {
713                         if (c->song && seek_id != c->song->id) {
714                                 seek_id = c->song->id;
715                                 seek_target_time = c->status->elapsedTime;
716                         }
717                         seek_target_time+=options.seek_time;
718                         if (seek_target_time < c->status->totalTime)
719                                 break;
720                         seek_target_time = c->status->totalTime;
721                         /* seek_target_time=0; */
722                 }
723                 break;
724                 /* fall through... */
725         case CMD_TRACK_NEXT:
726                 if (!IS_STOPPED(c->status->state))
727                         mpdclient_cmd_next(c);
728                 break;
729         case CMD_SEEK_BACKWARD:
730                 if (!IS_STOPPED(c->status->state)) {
731                         if (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 < 0)
737                                 seek_target_time=0;
738                 }
739                 break;
740         case CMD_TRACK_PREVIOUS:
741                 if (!IS_STOPPED(c->status->state))
742                         mpdclient_cmd_prev(c);
743                 break;
744         case CMD_SHUFFLE:
745                 if (mpdclient_cmd_shuffle(c) == 0)
746                         screen_status_message(_("Shuffled playlist"));
747                 break;
748         case CMD_CLEAR:
749                 if (mpdclient_cmd_clear(c) == 0)
750                         screen_status_message(_("Cleared playlist"));
751                 break;
752         case CMD_REPEAT:
753                 mpdclient_cmd_repeat(c, !c->status->repeat);
754                 break;
755         case CMD_RANDOM:
756                 mpdclient_cmd_random(c, !c->status->random);
757                 break;
758         case CMD_CROSSFADE:
759                 if (c->status->crossfade)
760                         mpdclient_cmd_crossfade(c, 0);
761                 else
762                         mpdclient_cmd_crossfade(c, options.crossfade_time);
763                 break;
764         case CMD_DB_UPDATE:
765                 if (!c->status->updatingDb) {
766                         if( mpdclient_cmd_db_update(c,NULL)==0 )
767                                 screen_status_printf(_("Database update started"));
768                 } else
769                         screen_status_printf(_("Database update running..."));
770                 break;
771         case CMD_VOLUME_UP:
772                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
773                         mpdclient_cmd_volume(c, ++c->status->volume);
774                 break;
775         case CMD_VOLUME_DOWN:
776                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
777                         mpdclient_cmd_volume(c, --c->status->volume);
778                 break;
780         default:
781                 return 0;
782         }
784         return 1;
787 void
788 screen_cmd(mpdclient_t *c, command_t cmd)
790         screen.last_cmd = cmd;
791 #ifndef NCMPC_MINI
792         welcome = FALSE;
793 #endif
795         if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
796                 return;
798         if (screen_client_cmd(c, cmd))
799                 return;
801         switch(cmd) {
802         case CMD_TOGGLE_FIND_WRAP:
803                 options.find_wrap = !options.find_wrap;
804                 screen_status_printf(options.find_wrap ?
805                                      _("Find mode: Wrapped") :
806                                      _("Find mode: Normal"));
807                 break;
808         case CMD_TOGGLE_AUTOCENTER:
809                 options.auto_center = !options.auto_center;
810                 screen_status_printf(options.auto_center ?
811                                      _("Auto center mode: On") :
812                                      _("Auto center mode: Off"));
813                 break;
814         case CMD_SCREEN_UPDATE:
815                 screen_paint(c);
816                 break;
817         case CMD_SCREEN_PREVIOUS:
818                 screen_next_mode(c, -1);
819                 break;
820         case CMD_SCREEN_NEXT:
821                 screen_next_mode(c, 1);
822                 break;
823         case CMD_SCREEN_PLAY:
824                 screen_switch(&screen_playlist, c);
825                 break;
826         case CMD_SCREEN_FILE:
827                 screen_switch(&screen_browse, c);
828                 break;
829 #ifdef ENABLE_HELP_SCREEN
830         case CMD_SCREEN_HELP:
831                 screen_switch(&screen_help, c);
832                 break;
833 #endif
834 #ifdef ENABLE_SEARCH_SCREEN
835         case CMD_SCREEN_SEARCH:
836                 screen_switch(&screen_search, c);
837                 break;
838 #endif
839 #ifdef ENABLE_ARTIST_SCREEN
840         case CMD_SCREEN_ARTIST:
841                 screen_switch(&screen_artist, c);
842                 break;
843 #endif
844 #ifdef ENABLE_KEYDEF_SCREEN
845         case CMD_SCREEN_KEYDEF:
846                 screen_switch(&screen_keydef, c);
847                 break;
848 #endif
849 #ifdef ENABLE_LYRICS_SCREEN
850         case CMD_SCREEN_LYRICS:
851                 screen_switch(&screen_lyrics, c);
852                 break;
853 #endif
854 #ifdef ENABLE_OUTPUTS_SCREEN
855         case CMD_SCREEN_OUTPUTS:
856                 screen_switch(&screen_outputs, c);
857                 break;
858 #endif
859         default:
860                 break;
861         }