Code

Added support for (auto) center/focus playlists.
[ncmpc.git] / conf.c
diff --git a/conf.c b/conf.c
index 1ea1fd971e44dac34c92f28d3f0916d339c623c0..6def7b638388863bed664b181a87227706ad3c2a 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -6,6 +6,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+
+#include <glib.h>
 #include <ncurses.h>
 
 #include "config.h"
@@ -26,6 +28,9 @@
 
 /* configuration field names */
 #define CONF_ENABLE_COLORS           "enable_colors"
+#define CONF_AUTO_CENTER             "auto_center"
+
+/* configuration field names - colors */
 #define CONF_COLOR_BACKGROUND        "background_color"
 #define CONF_COLOR_TITLE             "title_color"
 #define CONF_COLOR_LINE              "line_color"
@@ -35,9 +40,6 @@
 #define CONF_COLOR_ALERT             "alert_color"
 
 
-#define IS_WHITESPACE(c) (c==' ' || c=='\t' || c=='\r' || c=='\n')
-
-
 static int
 str2bool(char *str)
 {
@@ -66,24 +68,6 @@ str2color(char *str)
     return COLOR_CYAN;
   else if( !strcasecmp(str,"white") )
     return COLOR_WHITE;
-#if 0
-   else if( !strcasecmp(str,"grey") ) 
-     return COLOR_BLACK | A_BOLD;
-  else if( !strcasecmp(str,"brightred") )
-    return COLOR_RED | A_BOLD;
-  else if( !strcasecmp(str,"brightgreen") )
-    return COLOR_GREEN | A_BOLD;
-  else if( !strcasecmp(str,"brightyellow") )
-    return COLOR_YELLOW | A_BOLD;
-  else if( !strcasecmp(str,"brightblue") )
-    return COLOR_BLUE | A_BOLD;
-  else if( !strcasecmp(str,"brightmagenta") )
-    return COLOR_MAGENTA | A_BOLD;
-  else if( !strcasecmp(str,"brightcyan") )
-    return COLOR_CYAN | A_BOLD;
-  else if( !strcasecmp(str,"brightwhite") )
-    return COLOR_WHITE | A_BOLD;
-#endif
   fprintf(stderr,"Warning: unknown color %s\n", str);
   return -1;
 }
@@ -98,7 +82,7 @@ read_rc_file(char *filename, options_t *options)
 
   if( filename==NULL )
     {
-      filename = concat_path(getenv("HOME"), RCFILE);
+      filename = g_build_filename(g_get_home_dir(), RCFILE, NULL);
       free_filename = 1;
     }
 
@@ -107,7 +91,7 @@ read_rc_file(char *filename, options_t *options)
     {
       D(perror(filename));
       if( free_filename )
-       free(filename);
+       g_free(filename);
       return -1;
     }
 
@@ -182,6 +166,12 @@ read_rc_file(char *filename, options_t *options)
                  options->enable_colors = str2bool(value);
                  match_found = 1;
                }
+             /* auto center */
+             else if( !strcasecmp(CONF_AUTO_CENTER, name) )
+               {
+                 options->auto_center = str2bool(value);
+                 match_found = 1;
+               }
              /* background color */
              else if( !strcasecmp(CONF_COLOR_BACKGROUND, name) )
                {
@@ -251,7 +241,7 @@ read_rc_file(char *filename, options_t *options)
   D(printf( "--\n\n" ));
 
   if( free_filename )
-    free(filename);
+    g_free(filename);
  
   return 0;
 }