From: Max Kellermann Date: Sun, 4 Oct 2009 16:59:00 +0000 (+0200) Subject: options: convert timedisplay_type into a bool variable X-Git-Tag: release-0.16~163 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a4389ab4cec21c4f767e5d1eaa6bfa8591ce7165;p=ncmpc.git options: convert timedisplay_type into a bool variable Save some CPU and memory by using bool instead of a string. This patch also removes the compile-time option --with-default-timedisplay_type. --- diff --git a/configure.ac b/configure.ac index 5bc8531..92b46c3 100644 --- a/configure.ac +++ b/configure.ac @@ -367,16 +367,6 @@ fi AM_CONDITIONAL(ENABLE_OUTPUTS_SCREEN, test x$outputs_screen = xyes) -dnl Default timedisplay type -AC_MSG_CHECKING([for default timedisplay type]) -AC_ARG_WITH([default-timedisplay_type], - AC_HELP_STRING([--with-default-timedisplay_type=ARG], - [default_timedisplay]), - [DEFAULT_TIMEDISPLAY_TYPE="$withval"], - [DEFAULT_TIMEDISPLAY_TYPE="elapsed"]) -AC_MSG_RESULT([$DEFAULT_TIMEDISPLAY_TYPE]) -AC_DEFINE_UNQUOTED([DEFAULT_TIMEDISPLAY_TYPE], ["$DEFAULT_TIMEDISPLAY_TYPE"], [Default way to display time, either 'elapsed' or 'remaining']) - dnl dnl build options diff --git a/src/conf.c b/src/conf.c index a7d6ff0..3ec37b8 100644 --- a/src/conf.c +++ b/src/conf.c @@ -169,18 +169,20 @@ parse_key_definition(char *str) return assign_keys(cmd, keys); } -static const char * +static bool parse_timedisplay_type(const char *str) { - if (!strcmp(str,"elapsed") || !strcmp(str,"remaining")) - return str; + if (strcmp(str, "elapsed") == 0) + return false; + else if (strcmp(str, "remaining") == 0) + return true; else { /* translators: ncmpc supports displaying the "elapsed" or "remaining" time of a song being played; in this case, the configuration file contained an invalid setting */ print_error(_("Bad time display type"), str); - return DEFAULT_TIMEDISPLAY_TYPE; + return false; } } @@ -430,11 +432,10 @@ parse_line(char *line) else if (!strcasecmp(CONF_VISIBLE_BITRATE, name)) options.visible_bitrate = str2bool(value); /* timer display type */ - else if (!strcasecmp(CONF_TIMEDISPLAY_TYPE, name)) { - g_free(options.timedisplay_type); - options.timedisplay_type=g_strdup(parse_timedisplay_type(value)); + else if (!strcasecmp(CONF_TIMEDISPLAY_TYPE, name)) + options.display_remaining_time = parse_timedisplay_type(value); /* color definition */ - } else if (!strcasecmp(CONF_COLOR_DEFINITION, name)) + else if (!strcasecmp(CONF_COLOR_DEFINITION, name)) #ifdef ENABLE_COLORS parse_color_definition(value); #else diff --git a/src/options.c b/src/options.c index 9cf0fa9..c9eb5e8 100644 --- a/src/options.c +++ b/src/options.c @@ -381,7 +381,6 @@ options_init(void) options.list_format = g_strdup(DEFAULT_LIST_FORMAT); options.status_format = g_strdup(DEFAULT_STATUS_FORMAT); options.screen_list = g_strsplit_set(DEFAULT_SCREEN_LIST, " ", 0); - options.timedisplay_type = g_strdup(DEFAULT_TIMEDISPLAY_TYPE); #ifndef NCMPC_MINI options.scroll_sep = g_strdup(DEFAULT_SCROLL_SEP); #endif @@ -402,5 +401,4 @@ options_deinit(void) g_free(options.xterm_title_format); g_free(options.scroll_sep); #endif - g_free(options.timedisplay_type); } diff --git a/src/options.h b/src/options.h index b57ecba..8a0a9d3 100644 --- a/src/options.h +++ b/src/options.h @@ -38,7 +38,7 @@ typedef struct { char *scroll_sep; #endif char **screen_list; - char *timedisplay_type; + bool display_remaining_time; int port; int crossfade_time; int search_mode; diff --git a/src/status_bar.c b/src/status_bar.c index 4e03206..16012f4 100644 --- a/src/status_bar.c +++ b/src/status_bar.c @@ -119,15 +119,14 @@ status_bar_paint(struct status_bar *p, const struct mpd_status *status, char elapsed_string[32], duration_string[32]; /*checks the conf to see whether to display elapsed or remaining time */ - if(!strcmp(options.timedisplay_type,"elapsed")) - elapsedTime = mpd_status_get_elapsed_time(status); - else if(!strcmp(options.timedisplay_type,"remaining")) - elapsedTime = total_time - - mpd_status_get_elapsed_time(status); - if (song != NULL && seek_id == (int)mpd_song_get_id(song)) elapsedTime = seek_target_time; + else if (options.display_remaining_time) + elapsedTime = total_time - + mpd_status_get_elapsed_time(status); + else + elapsedTime = mpd_status_get_elapsed_time(status); /* display bitrate if visible-bitrate is true */ #ifndef NCMPC_MINI