mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
xmms2: outsource code and convert to callbacks.print
This commit is contained in:
parent
6bf79b7ebe
commit
ee40c63542
68
src/conky.c
68
src/conky.c
@ -1523,74 +1523,6 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
#endif
|
||||
|
||||
#ifdef XMMS2
|
||||
OBJ(xmms2_artist) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.artist);
|
||||
}
|
||||
OBJ(xmms2_album) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.album);
|
||||
}
|
||||
OBJ(xmms2_title) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.title);
|
||||
}
|
||||
OBJ(xmms2_genre) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.genre);
|
||||
}
|
||||
OBJ(xmms2_comment) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.comment);
|
||||
}
|
||||
OBJ(xmms2_url) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.url);
|
||||
}
|
||||
OBJ(xmms2_status) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.status);
|
||||
}
|
||||
OBJ(xmms2_date) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.date);
|
||||
}
|
||||
OBJ(xmms2_tracknr) {
|
||||
if (cur->xmms2.tracknr != -1) {
|
||||
snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
|
||||
}
|
||||
}
|
||||
OBJ(xmms2_bitrate) {
|
||||
snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
|
||||
}
|
||||
OBJ(xmms2_id) {
|
||||
snprintf(p, p_max_size, "%u", cur->xmms2.id);
|
||||
}
|
||||
OBJ(xmms2_size) {
|
||||
snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
|
||||
}
|
||||
OBJ(xmms2_elapsed) {
|
||||
snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
|
||||
(cur->xmms2.elapsed / 1000) % 60);
|
||||
}
|
||||
OBJ(xmms2_duration) {
|
||||
snprintf(p, p_max_size, "%02d:%02d",
|
||||
cur->xmms2.duration / 60000,
|
||||
(cur->xmms2.duration / 1000) % 60);
|
||||
}
|
||||
OBJ(xmms2_percent) {
|
||||
snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
|
||||
}
|
||||
OBJ(xmms2_bar) {
|
||||
new_bar(obj, p, p_max_size, (int) (cur->xmms2.progress * 255.0f));
|
||||
}
|
||||
OBJ(xmms2_playlist) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
|
||||
}
|
||||
OBJ(xmms2_timesplayed) {
|
||||
snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
|
||||
}
|
||||
OBJ(xmms2_smart) {
|
||||
if (strlen(cur->xmms2.title) < 2
|
||||
&& strlen(cur->xmms2.title) < 2) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.url);
|
||||
} else {
|
||||
snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
|
||||
cur->xmms2.title);
|
||||
}
|
||||
}
|
||||
OBJ(if_xmms2_connected) {
|
||||
if (cur->xmms2.conn_state != 1) {
|
||||
DO_JUMP;
|
||||
|
19
src/core.c
19
src/core.c
@ -1167,25 +1167,44 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
#endif /* MOC */
|
||||
#ifdef XMMS2
|
||||
END OBJ(xmms2_artist, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_artist;
|
||||
END OBJ(xmms2_album, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_album;
|
||||
END OBJ(xmms2_title, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_title;
|
||||
END OBJ(xmms2_genre, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_genre;
|
||||
END OBJ(xmms2_comment, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_comment;
|
||||
END OBJ(xmms2_url, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_url;
|
||||
END OBJ(xmms2_tracknr, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_tracknr;
|
||||
END OBJ(xmms2_bitrate, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_bitrate;
|
||||
END OBJ(xmms2_date, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_date;
|
||||
END OBJ(xmms2_id, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_id;
|
||||
END OBJ(xmms2_duration, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_duration;
|
||||
END OBJ(xmms2_elapsed, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_elapsed;
|
||||
END OBJ(xmms2_size, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_size;
|
||||
END OBJ(xmms2_status, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_status;
|
||||
END OBJ(xmms2_percent, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_percent;
|
||||
END OBJ(xmms2_bar, &update_xmms2)
|
||||
scan_bar(obj, arg);
|
||||
obj->callbacks.print = &print_xmms2_bar;
|
||||
END OBJ(xmms2_smart, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_smart;
|
||||
END OBJ(xmms2_playlist, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_playlist;
|
||||
END OBJ(xmms2_timesplayed, &update_xmms2)
|
||||
obj->callbacks.print = &print_xmms2_timesplayed;
|
||||
END OBJ_IF(if_xmms2_connected, &update_xmms2)
|
||||
#endif
|
||||
#ifdef AUDACIOUS
|
||||
|
65
src/xmms2.c
65
src/xmms2.c
@ -320,4 +320,69 @@ void update_xmms2(void)
|
||||
}
|
||||
}
|
||||
|
||||
void print_xmms2_tracknr(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
if (info.xmms2.tracknr != -1) {
|
||||
snprintf(p, p_max_size, "%i", info.xmms2.tracknr);
|
||||
}
|
||||
}
|
||||
|
||||
void print_xmms2_elapsed(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%02d:%02d", info.xmms2.elapsed / 60000,
|
||||
(info.xmms2.elapsed / 1000) % 60);
|
||||
}
|
||||
|
||||
void print_xmms2_duration(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%02d:%02d",
|
||||
info.xmms2.duration / 60000,
|
||||
(info.xmms2.duration / 1000) % 60);
|
||||
}
|
||||
|
||||
void print_xmms2_bar(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
if (!p_max_size)
|
||||
return;
|
||||
|
||||
new_bar(obj, p, p_max_size, (int) (info.xmms2.progress * 255.0f));
|
||||
}
|
||||
|
||||
void print_xmms2_smart(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
if (strlen(info.xmms2.title) < 2
|
||||
&& strlen(info.xmms2.title) < 2) {
|
||||
snprintf(p, p_max_size, "%s", info.xmms2.url);
|
||||
} else {
|
||||
snprintf(p, p_max_size, "%s - %s", info.xmms2.artist,
|
||||
info.xmms2.title);
|
||||
}
|
||||
}
|
||||
|
||||
#define XMMS2_PRINT_GENERATOR(name, fmt) \
|
||||
void print_xmms2_##name(struct text_object *obj, char *p, int p_max_size) \
|
||||
{ \
|
||||
(void)obj; \
|
||||
snprintf(p, p_max_size, fmt, info.xmms2.name); \
|
||||
}
|
||||
|
||||
XMMS2_PRINT_GENERATOR(artist, "%s")
|
||||
XMMS2_PRINT_GENERATOR(album, "%s")
|
||||
XMMS2_PRINT_GENERATOR(title, "%s")
|
||||
XMMS2_PRINT_GENERATOR(genre, "%s")
|
||||
XMMS2_PRINT_GENERATOR(comment, "%s")
|
||||
XMMS2_PRINT_GENERATOR(url, "%s")
|
||||
XMMS2_PRINT_GENERATOR(status, "%s")
|
||||
XMMS2_PRINT_GENERATOR(date, "%s")
|
||||
XMMS2_PRINT_GENERATOR(bitrate, "%i")
|
||||
XMMS2_PRINT_GENERATOR(id, "%u")
|
||||
XMMS2_PRINT_GENERATOR(size, "%2.1f")
|
||||
XMMS2_PRINT_GENERATOR(playlist, "%s")
|
||||
XMMS2_PRINT_GENERATOR(timesplayed, "%i")
|
||||
|
||||
#undef XMMS2_PRINT_GENERATOR
|
||||
|
21
src/xmms2.h
21
src/xmms2.h
@ -55,4 +55,25 @@ struct xmms2_s {
|
||||
|
||||
void update_xmms2(void);
|
||||
|
||||
void print_xmms2_tracknr(struct text_object *, char *, int);
|
||||
void print_xmms2_elapsed(struct text_object *, char *, int);
|
||||
void print_xmms2_duration(struct text_object *, char *, int);
|
||||
#ifdef X11
|
||||
void print_xmms2_bar(struct text_object *, char *, int);
|
||||
#endif /* X11 */
|
||||
void print_xmms2_smart(struct text_object *, char *, int);
|
||||
void print_xmms2_artist(struct text_object *, char *, int);
|
||||
void print_xmms2_album(struct text_object *, char *, int);
|
||||
void print_xmms2_title(struct text_object *, char *, int);
|
||||
void print_xmms2_genre(struct text_object *, char *, int);
|
||||
void print_xmms2_comment(struct text_object *, char *, int);
|
||||
void print_xmms2_url(struct text_object *, char *, int);
|
||||
void print_xmms2_status(struct text_object *, char *, int);
|
||||
void print_xmms2_date(struct text_object *, char *, int);
|
||||
void print_xmms2_bitrate(struct text_object *, char *, int);
|
||||
void print_xmms2_id(struct text_object *, char *, int);
|
||||
void print_xmms2_size(struct text_object *, char *, int);
|
||||
void print_xmms2_playlist(struct text_object *, char *, int);
|
||||
void print_xmms2_timesplayed(struct text_object *, char *, int);
|
||||
|
||||
#endif /*XMMS2_H_*/
|
||||
|
Loading…
Reference in New Issue
Block a user