From 6a14b6d36bb4b4edecb8c5844a062e4c48270cce Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 14 Nov 2009 02:38:26 +0100 Subject: [PATCH] status_bar: moved code to format_bitrate() --- src/status_bar.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) 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 -- 2.30.2