Code

increment version number to 0.28
[ncmpc.git] / src / title_bar.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2017 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;
63         assert(p != NULL);
65         wmove(w, 0, 0);
66         wclrtoeol(w);
68         if (title[0]) {
69                 colors_use(w, COLOR_TITLE_BOLD);
70                 mvwaddstr(w, 0, 0, title);
71 #ifndef NCMPC_MINI
72         } else {
73 #ifdef ENABLE_HELP_SCREEN
74                 print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
75 #endif
76                 print_hotkey(w, CMD_SCREEN_PLAY, _("Queue"));
77                 print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
78 #ifdef ENABLE_ARTIST_SCREEN
79                 print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
80 #endif
81 #ifdef ENABLE_SEARCH_SCREEN
82                 print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
83 #endif
84 #ifdef ENABLE_LYRICS_SCREEN
85                 print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
86 #endif
87 #ifdef ENABLE_OUTPUTS_SCREEN
88                 print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
89 #endif
90 #ifdef ENABLE_CHAT_SCREEN
91                 print_hotkey(w, CMD_SCREEN_CHAT, _("Chat"));
92 #endif
93 #endif
94         }
96         int volume = get_volume(status);
97         char buf[32];
98         if (volume < 0)
99                 g_snprintf(buf, 32, _("Volume n/a"));
100         else
101                 g_snprintf(buf, 32, _("Volume %d%%"), volume);
103         colors_use(w, COLOR_TITLE);
104         mvwaddstr(w, 0, p->window.cols - utf8_width(buf), buf);
106         char flags[5];
107         flags[0] = 0;
108         if (status != NULL) {
109                 if (mpd_status_get_repeat(status))
110                         g_strlcat(flags, "r", sizeof(flags));
111                 if (mpd_status_get_random(status))
112                         g_strlcat(flags, "z", sizeof(flags));
113                 if (mpd_status_get_single(status))
114                         g_strlcat(flags, "s", sizeof(flags));
115                 if (mpd_status_get_consume(status))
116                         g_strlcat(flags, "c", sizeof(flags));
117                 if (mpd_status_get_crossfade(status))
118                         g_strlcat(flags, "x", sizeof(flags));
119                 if (mpd_status_get_update_id(status) != 0)
120                         g_strlcat(flags, "U", sizeof(flags));
121         }
123         colors_use(w, COLOR_LINE);
124         mvwhline(w, 1, 0, ACS_HLINE, p->window.cols);
125         if (flags[0]) {
126                 wmove(w, 1, p->window.cols - strlen(flags) - 3);
127                 waddch(w, '[');
128                 colors_use(w, COLOR_LINE_FLAGS);
129                 waddstr(w, flags);
130                 colors_use(w, COLOR_LINE);
131                 waddch(w, ']');
132         }
134         wnoutrefresh(w);
137 void
138 title_bar_resize(struct title_bar *p, unsigned width)
140         assert(p != NULL);
142         p->window.cols = width;
143         wresize(p->window.w, 2, width);