configure.ac: require GLib 2.14
[ncmpc.git] / src / title_bar.c
blobe83156519a4890ef2a10c13248638ecdcba00b04
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2010 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
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.
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)
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, ' ');
47 #endif
49 static inline int
50 get_volume(const struct mpd_status *status)
52 return status != NULL
53 ? mpd_status_get_volume(status)
54 : -1;
57 void
58 title_bar_paint(const struct title_bar *p, const char *title,
59 const struct mpd_status *status)
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 #ifdef ENABLE_CHAT_SCREEN
94 print_hotkey(w, CMD_SCREEN_CHAT, _("Chat"));
95 #endif
96 #endif
99 volume = get_volume(status);
100 if (volume < 0)
101 g_snprintf(buf, 32, _("Volume n/a"));
102 else
103 g_snprintf(buf, 32, _("Volume %d%%"), volume);
105 colors_use(w, COLOR_TITLE);
106 mvwaddstr(w, 0, p->window.cols - utf8_width(buf), buf);
108 flags[0] = 0;
109 if (status != NULL) {
110 if (mpd_status_get_repeat(status))
111 g_strlcat(flags, "r", sizeof(flags));
112 if (mpd_status_get_random(status))
113 g_strlcat(flags, "z", sizeof(flags));
114 if (mpd_status_get_single(status))
115 g_strlcat(flags, "s", sizeof(flags));
116 if (mpd_status_get_consume(status))
117 g_strlcat(flags, "c", sizeof(flags));
118 if (mpd_status_get_crossfade(status))
119 g_strlcat(flags, "x", sizeof(flags));
120 if (mpd_status_get_update_id(status) != 0)
121 g_strlcat(flags, "U", sizeof(flags));
124 colors_use(w, COLOR_LINE);
125 mvwhline(w, 1, 0, ACS_HLINE, p->window.cols);
126 if (flags[0]) {
127 wmove(w, 1, p->window.cols - strlen(flags) - 3);
128 waddch(w, '[');
129 colors_use(w, COLOR_LINE_BOLD);
130 waddstr(w, flags);
131 colors_use(w, COLOR_LINE);
132 waddch(w, ']');
135 wnoutrefresh(w);
138 void
139 title_bar_resize(struct title_bar *p, unsigned width)
141 assert(p != NULL);
143 p->window.cols = width;
144 wresize(p->window.w, 2, width);