Code

Added list-format and status-format conf options
authorKalle Wallin <kaw@linux.se>
Tue, 15 Jun 2004 13:10:54 +0000 (13:10 +0000)
committerKalle Wallin <kaw@linux.se>
Tue, 15 Jun 2004 13:10:54 +0000 (13:10 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1496 09075e82-0dd4-0310-85a5-a0d7c8717e4f

doc/config.sample
src/conf.c
src/ncmpc.h
src/options.c
src/options.h

index f8d2ad4d3a62b68a4d404d60ff35f169b0fcc7c9..ecbc8cc41b2d415a01c7ab330e43b4cf338086f4 100644 (file)
@@ -3,10 +3,17 @@
 ## 
 
 ## auto center (center the playing track in the playlist)
-#auto_center = no
+#auto-center = no
 
 ## wide_cursor - make the cursor as wide as the screen
-#wide_cursor = yes
+#wide-cursor = yes
+
+## list-format
+#list-format = "%name%|[%artist% - ]%title%|%file%"
+
+## status-format
+#status-format = "[%artist% - ]%title%|%basename%"
+
 
 ##
 ## Color configuration
@@ -15,7 +22,7 @@
 ##
 
 ## enable/disable colors
-#enable_colors = no
+#enable-colors = no
 
 ## background colors: black,red,green,yellow,blue,magenta,cyan,white, none 
 #color background = black
index 0d6d96834d517743783798a1ce87e653b8eca560..a40c90ad7a4354b5a4ad46dc4d4d4e1a45a804ee 100644 (file)
 #include "colors.h"
 #include "conf.h"
 
-#define ENABLE_OLD_COLOR_SYNTAX
+#define ENABLE_OLD_SYNTAX
 
 #define MAX_LINE_LENGTH 1024
 #define COMMENT_TOKEN   '#'
 
 /* configuration field names */
-#define CONF_ENABLE_COLORS           "enable_colors"
-#define CONF_AUTO_CENTER             "auto_center"
-#define CONF_WIDE_CURSOR             "wide_cursor"
+#define CONF_ENABLE_COLORS           "enable-colors"
+#define CONF_AUTO_CENTER             "auto-center"
+#define CONF_WIDE_CURSOR             "wide-cursor"
+#define CONF_ENABLE_BELL             "enable-bell"
 #define CONF_KEY_DEFINITION          "key"
 #define CONF_COLOR                   "color"
 #define CONF_COLOR_DEFINITION        "colordef"
+#define CONF_LIST_FORMAT             "list-format"
+#define CONF_STATUS_FORMAT           "status-format"
 
 /* Deprecated - configuration field names */
+#define OLD_CONF_ENABLE_COLORS       "enable_colors"
+#define OLD_CONF_AUTO_CENTER         "auto_center"
+#define OLD_CONF_WIDE_CURSOR         "wide_cursor"
 #define CONF_COLOR_BACKGROUND        "background_color"
 #define CONF_COLOR_TITLE             "title_color"
 #define CONF_COLOR_LINE              "line_color"
@@ -299,6 +305,19 @@ parse_color_definition(char *str)
   return value;
 }
 
+static char *
+get_format(char *str)
+{
+  gsize len = strlen(str);
+
+  if( str && str[0]=='\"' && str[len-1] == '\"' )
+    {
+      str[len-1] = '\0';
+      str++;
+    }
+  return g_strdup(str);
+}
+
 
 static int
 read_rc_file(char *filename, options_t *options)
@@ -404,52 +423,70 @@ read_rc_file(char *filename, options_t *options)
                {
                  parse_color(value);
                }
-#ifdef ENABLE_OLD_COLOR_SYNTAX
+#ifdef ENABLE_OLD_SYNTAX
              /* background color */
              else if( !strcasecmp(CONF_COLOR_BACKGROUND, name) )
                {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
+                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
                  colors_assign("background", value);
                }
              /* color - top (title) window */
              else if( !strcasecmp(CONF_COLOR_TITLE, name) )
                {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
+                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
                  colors_assign("title", value);
                  colors_assign("title2", value);
                }
              /* color - line (title) window */
              else if( !strcasecmp(CONF_COLOR_LINE, name) )
                {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
+                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
                  colors_assign("line", value);
                  colors_assign("line2", value);
                }
              /* color - list window */
              else if( !strcasecmp(CONF_COLOR_LIST, name) )
                {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
+                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
                  colors_assign("list", value);
                }
              /* color - progress bar */
              else if( !strcasecmp(CONF_COLOR_PROGRESS, name) )
                {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
+                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
                  colors_assign("progressbar", value);
                }
              /* color - status window */
              else if( !strcasecmp(CONF_COLOR_STATUS, name) )
                {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
+                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
                  colors_assign("status", value);
                  colors_assign("status2", value);
                }
              /* color - alerts */
              else if( !strcasecmp(CONF_COLOR_ALERT, name) )
                {
-                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
+                 fprintf(stderr,"%s: %s deprecated!\n", filename,name);
                  colors_assign("alert", value);
                }
+             /* enable colors */
+             else if( !strcasecmp(OLD_CONF_ENABLE_COLORS, name) )
+               {
+                 fprintf(stderr,"%s: %s deprecated - use %s!\n", filename, name, CONF_ENABLE_COLORS);
+                 options->enable_colors = str2bool(value);
+               }
+             /* auto center */
+             else if( !strcasecmp(OLD_CONF_AUTO_CENTER, name) )
+               {
+                 fprintf(stderr,"%s: %s deprecated - use %s!\n", filename, name, CONF_AUTO_CENTER);
+                 options->auto_center = str2bool(value);
+               }
+             /* wide cursor */
+             else if( !strcasecmp(OLD_CONF_WIDE_CURSOR, name) )
+               {
+                 fprintf(stderr,"%s: %s deprecated - use %s!\n", filename, name, CONF_WIDE_CURSOR);
+                 options->wide_cursor = str2bool(value);
+               }
 #endif
              /* wide cursor */
              else if( !strcasecmp(CONF_WIDE_CURSOR, name) )
@@ -461,6 +498,20 @@ read_rc_file(char *filename, options_t *options)
                {
                  parse_color_definition(value);
                }
+             /* list format string */
+             else if( !strcasecmp(CONF_LIST_FORMAT, name) )
+               {
+                 g_free(options->list_format);
+                 options->list_format = get_format(value);
+                 fprintf(stderr, "list-format = \'%s\'\n", options->list_format);
+               }
+             /* status format string */
+             else if( !strcasecmp(CONF_STATUS_FORMAT, name) )
+               {
+                 g_free(options->status_format);
+                 options->status_format = get_format(value);
+                 fprintf(stderr, "status-format = \'%s\'\n", options->status_format);
+               }
              else
                {
                  match_found = 0;
index 6bbb745fbbcee19bb081d67a8c3a6dca464b3b20..64160531f2f310aa9f75c7448162d52476ea2ca9 100644 (file)
@@ -23,6 +23,9 @@
 #define N_(x) x
 #endif
 
+#define YES   _("y")
+#define NO    _("n")
+
 /* welcome message time [s] */
 #define SCREEN_WELCOME_TIME 10
 
 #define MPD_UPDATE_TIME        0.5
 
 /* time in milliseconds before trying to reconnect (int) */
-#define MPD_RECONNECT_TIME  1000
+#define MPD_RECONNECT_TIME  1500
 
 /* song format - list window */
-#define LIST_FORMAT "%name%|[%artist% - ]%title%|%file%"
+#define DEFAULT_LIST_FORMAT "%name%|[%artist% - ]%title%|%file%"
+#define LIST_FORMAT (options.list_format ? options.list_format : DEFAULT_LIST_FORMAT)
 
 /* song format - status window */
-#define STATUS_FORMAT "[%artist% - ]%title%|%basename%"
+#define DEFAULT_STATUS_FORMAT "[%artist% - ]%title%|%basename%"
+#define STATUS_FORMAT (options.status_format ? options.status_format : DEFAULT_STATUS_FORMAT)
 
 #endif /* NCMPC_H */
index 416727ad3e8b51bfd23621cddcc7ef1545a66078..952f436d541c07d5d5a6befd39207ae3cba9ae89 100644 (file)
@@ -1,5 +1,7 @@
 /* 
- * (c) 2004 by Kalle Wallin (kaw@linux.se)
+ * $Id$
+ *
+ * (c) 2004 by Kalle Wallin <kaw@linux.se>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,6 +27,7 @@
 #include <popt.h>
 
 #include "config.h"
+#include "ncmpc.h"
 #include "options.h"
 #include "command.h"
 #include "support.h"
@@ -170,9 +173,14 @@ options_init( void )
   else
     options.port = DEFAULT_PORT;
 
+  options.list_format = NULL;
+  options.status_format = NULL;
+
   options.reconnect = 1;
   options.find_wrap = 1;
   options.wide_cursor = 1;
+  options.enable_beep = 1;
+
 
   return &options;
 }
index 2a6681e2a3ac9f437e71caed7f842285845ac0ee..4ca1a4561bbb37b06575bc38f63bf6b9df4ba492 100644 (file)
@@ -9,6 +9,8 @@ typedef struct
   char *password;
   char *config_file;
   char *key_file;
+  char *list_format;
+  char *status_format;
   int   port;
   int   reconnect;
   int   debug;
@@ -16,6 +18,7 @@ typedef struct
   int   auto_center;
   int   wide_cursor;  
   int   enable_colors;
+  int   enable_beep;
 
 } options_t;