From: Max Kellermann Date: Sat, 14 Nov 2009 01:38:26 +0000 (+0100) Subject: status_bar: moved code to format_bitrate() X-Git-Tag: release-0.16~27 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6a14b6d36bb4b4edecb8c5844a062e4c48270cce;p=ncmpc.git status_bar: moved code to format_bitrate() --- diff --git a/src/status_bar.c b/src/status_bar.c index 2e94499..4ccb6e3 100644 --- a/src/status_bar.c +++ b/src/status_bar.c @@ -79,6 +79,21 @@ status_bar_clear_message(gpointer data) return false; } +#ifndef NCMPC_MINI + +static void +format_bitrate(char *p, size_t max_length, const struct mpd_status *status) +{ + if (options.visible_bitrate && mpd_status_get_kbit_rate(status) > 0) + g_snprintf(p, max_length, + " [%d kbps]", + mpd_status_get_kbit_rate(status)); + else + p[0] = '\0'; +} + +#endif /* !NCMPC_MINI */ + void status_bar_paint(struct status_bar *p, const struct mpd_status *status, const struct mpd_song *song) @@ -145,13 +160,7 @@ status_bar_paint(struct status_bar *p, const struct mpd_status *status, /* display bitrate if visible-bitrate is true */ #ifndef NCMPC_MINI - if (options.visible_bitrate) { - g_snprintf(bitrate, 16, - " [%d kbps]", - mpd_status_get_kbit_rate(status)); - } else { - bitrate[0] = '\0'; - } + format_bitrate(bitrate, sizeof(bitrate), status); #endif /* write out the time */ @@ -165,13 +174,11 @@ status_bar_paint(struct status_bar *p, const struct mpd_status *status, g_snprintf(buffer, sizeof(buffer), "%s [%s/%s]", bitrate, elapsed_string, duration_string); #ifndef NCMPC_MINI - } else if (options.visible_bitrate) { - g_snprintf(buffer, sizeof(buffer), - " [%d kbps]", - mpd_status_get_kbit_rate(status)); -#endif } else { + format_bitrate(buffer, sizeof(buffer), status); +#else buffer[0] = 0; +#endif } } else { #ifndef NCMPC_MINI