Options: convert display_remaining_time to enum
authorMax Kellermann <max@musicpd.org>
Wed, 29 Apr 2020 20:45:21 +0000 (22:45 +0200)
committerMax Kellermann <max@musicpd.org>
Wed, 29 Apr 2020 21:33:26 +0000 (23:33 +0200)
Prepare to add more options.

src/ConfigParser.cxx
src/Options.hxx
src/StatusBar.cxx

index 4d7d366..0d81743 100644 (file)
@@ -188,13 +188,13 @@ parse_key_definition(char *str)
 /**
  * Throws on error.
  */
-static bool
-parse_timedisplay_type(const char *str)
+static CurrentTimeDisplay
+ParseCurrentTimeDisplay(const char *str)
 {
        if (strcmp(str, "elapsed") == 0)
-               return false;
+               return CurrentTimeDisplay::ELAPSED;
        else if (strcmp(str, "remaining") == 0)
-               return true;
+               return CurrentTimeDisplay::REMAINING;
        else
                throw FormatRuntimeError("%s: %s",
                                         /* translators: ncmpc
@@ -492,7 +492,7 @@ parse_line(char *line)
                options.visible_bitrate = str2bool(value);
        /* timer display type */
        else if (!strcasecmp(CONF_TIMEDISPLAY_TYPE, name))
-               options.display_remaining_time = parse_timedisplay_type(value);
+               options.current_time_display = ParseCurrentTimeDisplay(value);
                /* color definition */
        else if (!strcasecmp(CONF_COLOR_DEFINITION, name))
 #ifdef ENABLE_COLORS
index 6d59d92..d83d737 100644 (file)
 
 #include <mpd/tag.h>
 
+#include <cstdint>
 #include <vector>
 #include <string>
 #include <chrono>
 
+enum class CurrentTimeDisplay : uint8_t {
+       ELAPSED,
+       REMAINING,
+};
+
 struct Options {
        std::string host;
        std::string password;
@@ -99,7 +105,7 @@ struct Options {
        bool second_column = true;
 #endif
 
-       bool display_remaining_time;
+       CurrentTimeDisplay current_time_display = CurrentTimeDisplay::ELAPSED;
 };
 
 extern Options options;
index ca5b7d1..b9a2620 100644 (file)
@@ -107,10 +107,16 @@ FormatCurrentSongTime(char *buffer, size_t size,
 
        /* checks the conf to see whether to display elapsed or
           remaining time */
-       if (options.display_remaining_time)
+       switch (options.current_time_display) {
+       case CurrentTimeDisplay::ELAPSED:
+               break;
+
+       case CurrentTimeDisplay::REMAINING:
                elapsed_time = elapsed_time < total_time
                        ? total_time - elapsed_time
                        : 0;
+               break;
+       }
 
        /* write out the time */
        format_duration_short(elapsed_string,