Code

options: convert timedisplay_type into a bool variable
authorMax Kellermann <max@duempel.org>
Sun, 4 Oct 2009 16:59:00 +0000 (18:59 +0200)
committerMax Kellermann <max@duempel.org>
Sun, 4 Oct 2009 16:59:00 +0000 (18:59 +0200)
Save some CPU and memory by using bool instead of a string.  This
patch also removes the compile-time option
--with-default-timedisplay_type.

configure.ac
src/conf.c
src/options.c
src/options.h
src/status_bar.c

index 5bc8531c31a0a2de6511f84a4e1979143bb207ab..92b46c3e972cf58c23193cf62466080e43344383 100644 (file)
@@ -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
index a7d6ff0cf7609dfab786fdc71e943a627e03195e..3ec37b855776cde142e8eae35e854daa45bb835a 100644 (file)
@@ -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
index 9cf0fa99fc37b6951a594a84ed39ad5dd11ef84b..c9eb5e8a954c3fcbb812caa4651e36b1f5888548 100644 (file)
@@ -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);
 }
index b57ecbaeea555b13d8d05c34645b30e7022d946e..8a0a9d353d0b4a56ba3170d9603907c6e72fff19 100644 (file)
@@ -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;
index 4e0320639c733f368d5862890e1af331dc9ce314..16012f4deb4d5807a9895a595b3910f1f69fb48e 100644 (file)
@@ -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