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