summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2a4b3d1)
raw | patch | inline | side by side (parent: 2a4b3d1)
author | Max Kellermann <max@duempel.org> | |
Sun, 4 Oct 2009 16:59:00 +0000 (18:59 +0200) | ||
committer | Max 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.
patch also removes the compile-time option
--with-default-timedisplay_type.
configure.ac | patch | blob | history | |
src/conf.c | patch | blob | history | |
src/options.c | patch | blob | history | |
src/options.h | patch | blob | history | |
src/status_bar.c | patch | blob | history |
diff --git a/configure.ac b/configure.ac
index 5bc8531c31a0a2de6511f84a4e1979143bb207ab..92b46c3e972cf58c23193cf62466080e43344383 100644 (file)
--- a/configure.ac
+++ b/configure.ac
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 a7d6ff0cf7609dfab786fdc71e943a627e03195e..3ec37b855776cde142e8eae35e854daa45bb835a 100644 (file)
--- a/src/conf.c
+++ b/src/conf.c
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;
}
}
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 9cf0fa99fc37b6951a594a84ed39ad5dd11ef84b..c9eb5e8a954c3fcbb812caa4651e36b1f5888548 100644 (file)
--- a/src/options.c
+++ b/src/options.c
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
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 b57ecbaeea555b13d8d05c34645b30e7022d946e..8a0a9d353d0b4a56ba3170d9603907c6e72fff19 100644 (file)
--- a/src/options.h
+++ b/src/options.h
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 4e0320639c733f368d5862890e1af331dc9ce314..16012f4deb4d5807a9895a595b3910f1f69fb48e 100644 (file)
--- a/src/status_bar.c
+++ b/src/status_bar.c
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