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.
9 *
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.
14 *
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 "title_bar.h"
21 #include "colors.h"
22 #include "command.h"
23 #include "i18n.h"
24 #include "charset.h"
26 #include <mpd/client.h>
28 #include <glib.h>
30 #include <assert.h>
31 #include <string.h>
33 #ifndef NCMPC_MINI
34 static void
35 print_hotkey(WINDOW *w, command_t cmd, const char *label)
36 {
37 colors_use(w, COLOR_TITLE_BOLD);
38 waddstr(w, get_key_names(cmd, FALSE));
39 colors_use(w, COLOR_TITLE);
40 waddch(w, ':');
41 waddstr(w, label);
42 waddch(w, ' ');
43 waddch(w, ' ');
44 }
45 #endif
47 static inline int
48 get_volume(const struct mpd_status *status)
49 {
50 return status != NULL
51 ? mpd_status_get_volume(status)
52 : -1;
53 }
55 void
56 title_bar_paint(const struct title_bar *p, const char *title,
57 const struct mpd_status *status)
58 {
59 WINDOW *w = p->window.w;
60 int volume;
61 char flags[5];
62 char buf[32];
64 assert(p != NULL);
66 wmove(w, 0, 0);
67 wclrtoeol(w);
69 if (title[0]) {
70 colors_use(w, COLOR_TITLE_BOLD);
71 mvwaddstr(w, 0, 0, title);
72 #ifndef NCMPC_MINI
73 } else {
74 #ifdef ENABLE_HELP_SCREEN
75 print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
76 #endif
77 print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
78 print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
79 #ifdef ENABLE_ARTIST_SCREEN
80 print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
81 #endif
82 #ifdef ENABLE_SEARCH_SCREEN
83 print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
84 #endif
85 #ifdef ENABLE_LYRICS_SCREEN
86 print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
87 #endif
88 #ifdef ENABLE_OUTPUTS_SCREEN
89 print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
90 #endif
91 #endif
92 }
94 volume = get_volume(status);
95 if (volume < 0)
96 g_snprintf(buf, 32, _("Volume n/a"));
97 else
98 g_snprintf(buf, 32, _("Volume %d%%"), volume);
100 colors_use(w, COLOR_TITLE);
101 mvwaddstr(w, 0, p->window.cols - utf8_width(buf), buf);
103 flags[0] = 0;
104 if (status != NULL) {
105 if (mpd_status_get_repeat(status))
106 g_strlcat(flags, "r", sizeof(flags));
107 if (mpd_status_get_random(status))
108 g_strlcat(flags, "z", sizeof(flags));
109 if (mpd_status_get_single(status))
110 g_strlcat(flags, "s", sizeof(flags));
111 if (mpd_status_get_consume(status))
112 g_strlcat(flags, "c", sizeof(flags));
113 if (mpd_status_get_crossfade(status))
114 g_strlcat(flags, "x", sizeof(flags));
115 if (mpd_status_get_update_id(status) != 0)
116 g_strlcat(flags, "U", sizeof(flags));
117 }
119 colors_use(w, COLOR_LINE);
120 mvwhline(w, 1, 0, ACS_HLINE, p->window.cols);
121 if (flags[0]) {
122 wmove(w, 1, p->window.cols - strlen(flags) - 3);
123 waddch(w, '[');
124 colors_use(w, COLOR_LINE_BOLD);
125 waddstr(w, flags);
126 colors_use(w, COLOR_LINE);
127 waddch(w, ']');
128 }
130 wnoutrefresh(w);
131 }
133 void
134 title_bar_resize(struct title_bar *p, unsigned width)
135 {
136 assert(p != NULL);
138 p->window.cols = width;
139 wresize(p->window.w, 2, width);
140 }