1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 10:35:10 +00:00

enable max length argument for mpd_smart

* 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
This commit is contained in:
Phil 2008-09-01 22:30:54 +00:00
parent e873442ec5
commit 36e34a3c8d
5 changed files with 30 additions and 15 deletions

2
README
View File

@ -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

View 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

View File

@ -1406,6 +1406,7 @@
<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

View 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;
}

View File

@ -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;
};