enable max length argument for mpd_smart
authorPhil <n0-1@users.sourceforge.net>
Mon, 1 Sep 2008 22:30:54 +0000 (22:30 +0000)
committerPhil <n0-1@users.sourceforge.net>
Mon, 1 Sep 2008 22:30:54 +0000 (22:30 +0000)
* this also fixes mpd_title for changing lengths, e.g.
  ${mpd_title 2} ${mpd_title 3} ${mpd_title 4}

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1241 7f574dfc-610e-0410-a909-a81674777703

README
doc/conky.1
doc/variables.xml
src/conky.c
src/mpd.h

diff --git a/README b/README
index d296ae3..112a8f1 100644 (file)
--- a/README
+++ b/README
@@ -1144,7 +1144,7 @@ conky(1)                                                        conky(1)
              Prints the file name of the current MPD song
 
 
-       1mmpd_smart0m
+       1mmpd_smart (max length)0m
              Prints the song name in either the form "artist - title" or file
              name, depending on whats available
 
index a4ec04f..b78db2b 100644 (file)
@@ -1,4 +1,4 @@
-.\" -*- coding: us-ascii -*-
+'\" -*- coding: us-ascii -*-
 .if \n(.g .ds T< \\FC
 .if \n(.g .ds T> \\F[\n[.fam]]
 .de URL
@@ -977,7 +977,7 @@ Prints the MPD name field
 Prints the file name of the current MPD song
 
 .TP 
-\fB\*(T<\fBmpd_smart\fR\*(T>\fR 
+\fB\*(T<\fBmpd_smart\fR\*(T>\fR \*(T<\fB(max length)\fR\*(T> 
 Prints the song name in either the form "artist - title" or file name, depending on whats available
 
 .TP 
index 147cb78..d8df26e 100644 (file)
        <varlistentry>
                <term>
                        <command><option>mpd_smart</option></command>
+                       <option>(max length)</option>
                </term>
                <listitem>
                        Prints the song name in either the form "artist - title" or file name, depending on whats available
index 7324acc..00a24d5 100644 (file)
@@ -3793,14 +3793,14 @@ static struct text_object *construct_text_object(const char *s,
        END OBJ_THREAD(mpd_artist, INFO_MPD)
        END OBJ_THREAD(mpd_title, INFO_MPD)
                if (arg) {
-                       sscanf(arg, "%d", &info.mpd.max_title_len);
-                       if (info.mpd.max_title_len > 0) {
-                               info.mpd.max_title_len++;
+                       sscanf(arg, "%d", &obj->data.i);
+                       if (obj->data.i > 0) {
+                               obj->data.i++;
                        } else {
                                CRIT_ERR("mpd_title: invalid length argument");
                        }
                } else {
-                       info.mpd.max_title_len = 0;
+                       obj->data.i = 0;
                }
        END OBJ_THREAD(mpd_random, INFO_MPD)
        END OBJ_THREAD(mpd_repeat, INFO_MPD)
@@ -3817,6 +3817,16 @@ static struct text_object *construct_text_object(const char *s,
        END OBJ_THREAD(mpd_bar, INFO_MPD)
                scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
        END OBJ_THREAD(mpd_smart, INFO_MPD)
+               if (arg) {
+                       sscanf(arg, "%d", &obj->data.i);
+                       if (obj->data.i > 0) {
+                               obj->data.i++;
+                       } else {
+                               CRIT_ERR("mpd_smart: invalid length argument");
+                       }
+               } else {
+                       obj->data.i = 0;
+               }
 #endif /* MPD */
 #ifdef XMMS2
        END OBJ(xmms2_artist, INFO_XMMS2)
@@ -5690,9 +5700,10 @@ static void generate_text_internal(char *p, int p_max_size,
 
 #ifdef MPD
                        OBJ(mpd_title) {
-                               snprintf(p, cur->mpd.max_title_len > 0
-                                       ? cur->mpd.max_title_len : p_max_size, "%s",
-                                       cur->mpd.title);
+                               int len = obj->data.i;
+                               if (len == 0 || len > p_max_size)
+                                       len = p_max_size;
+                               snprintf(p, len, "%s", cur->mpd.title);
                        }
                        OBJ(mpd_artist) {
                                snprintf(p, p_max_size, "%s", cur->mpd.artist);
@@ -5739,17 +5750,21 @@ static void generate_text_internal(char *p, int p_max_size,
                                        (int) (cur->mpd.progress * 255.0f));
                        }
                        OBJ(mpd_smart) {
+                               int len = obj->data.i;
+                               if (len == 0 || len > p_max_size)
+                                       len = p_max_size;
+
                                memset(p, 0, p_max_size);
                                if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
                                                && *cur->mpd.title) {
-                                       snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
+                                       snprintf(p, len, "%s - %s", cur->mpd.artist,
                                                cur->mpd.title);
                                } else if (cur->mpd.title && *cur->mpd.title) {
-                                       snprintf(p, p_max_size, "%s", cur->mpd.title);
+                                       snprintf(p, len, "%s", cur->mpd.title);
                                } else if (cur->mpd.artist && *cur->mpd.artist) {
-                                       snprintf(p, p_max_size, "%s", cur->mpd.artist);
+                                       snprintf(p, len, "%s", cur->mpd.artist);
                                } else if (cur->mpd.file && *cur->mpd.file) {
-                                       snprintf(p, p_max_size, "%s", cur->mpd.file);
+                                       snprintf(p, len, "%s", cur->mpd.file);
                                } else {
                                        *p = 0;
                                }
index e728775..7f8412f 100644 (file)
--- a/src/mpd.h
+++ b/src/mpd.h
@@ -26,7 +26,6 @@ struct mpd_s {
        int bitrate;
        int length;
        int elapsed;
-       int max_title_len;              /* e.g. ${mpd_title 50} */
        mpd_Connection *conn;
        timed_thread *timed_thread;
 };