From 3b03ca2a76e2300e2b02f98995766dee17cee76d Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Sun, 6 May 2007 12:17:13 +0000 Subject: [PATCH] Experimental RSS code. git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@864 7f574dfc-610e-0410-a909-a81674777703 --- configure.ac.in | 32 ++++++++++++++++++++++++---- src/Makefile.am | 5 +++++ src/conky.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ src/conky.h | 12 +++++++++++ 4 files changed, 100 insertions(+), 4 deletions(-) diff --git a/configure.ac.in b/configure.ac.in index af8bb324..8a14c4fd 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -179,6 +179,22 @@ if test x$want_xmms2 = xyes; then AC_DEFINE(XMMS2, 1, [Define if you want XMMS2 support]) fi +dnl +dnl RSS +dnl + +AC_ARG_ENABLE([rss], + AC_HELP_STRING([--enable-rss], [enable if you want rss support (requires libmrss) @<:@default=no@:>@]), + [want_rss="$enableval"], [want_rss=no]) +# +AM_CONDITIONAL(BUILD_RSS, test x$want_rss = xyes) +if test x$want_rss = xyes; then + WANT_GLIB=yes + PKG_CHECK_MODULES([MRSS], [mrss]) + CFLAGS="$CFLAGS $MRSS_CFLAGS" + LIBS="$LIBS $MRSS_LIBS" + AC_DEFINE(RSS, 1, [Define if you want rss support]) +fi dnl dnl IMLIB2 @@ -218,10 +234,8 @@ if test x$want_portmon = xyes; then if test "x$PORT_MONITORS_MISSING" = xyes; then AC_MSG_ERROR([missing a needed network header for port monitoring]) fi - PKG_CHECK_MODULES([GLIB], [glib-2.0]) - CFLAGS="$CFLAGS $GLIB_CFLAGS" - LIBS="$LIBS $GLIB_LIBS" - AC_DEFINE(TCP_PORT_MONITOR, 1, [Define if you want tcp port monitoring support]) + WANT_GLIB=yes + AC_DEFINE(TCP_PORT_MONITOR, 1, [Define if you want tcp port monitoring support]) fi fi @@ -356,6 +370,15 @@ if test x$want_xft = "xyes"; then fi fi +dnl +dnl GLIB +dnl + +if test x$WANT_GLIB = xyes; then + PKG_CHECK_MODULES([GLIB], [glib-2.0]) + CFLAGS="$CFLAGS $GLIB_CFLAGS" + LIBS="$LIBS $GLIB_LIBS" +fi dnl dnl KVM @@ -519,4 +542,5 @@ $PACKAGE $VERSION configured successfully: * general: hddtemp: $want_hddtemp portmon: $want_portmon + RSS: $want_rss EOF diff --git a/src/Makefile.am b/src/Makefile.am index 72b323a6..c13e4e53 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -51,6 +51,10 @@ if BUILD_HDDTEMP hddtemp = hddtemp.c endif +if BUILD_RSS +rss = rss.c +endif + conky_SOURCES = \ $(audacious) \ $(bmpx) \ @@ -67,6 +71,7 @@ conky_SOURCES = \ $(netbsd) \ $(openbsd) \ $(port_monitors) \ + $(rss) \ $(solaris) \ timed_thread.c \ timed_thread.h \ diff --git a/src/conky.c b/src/conky.c index c9073b56..0c0d200f 100644 --- a/src/conky.c +++ b/src/conky.c @@ -93,6 +93,9 @@ static void print_version() #ifdef TCP_PORT_MONITOR " * portmon\n" #endif /* TCP_PORT_MONITOR */ +#ifdef RSS + " * rss\n" +#endif "\n"); exit(0); @@ -1163,6 +1166,9 @@ enum text_object_type { OBJ_bmpx_uri, OBJ_bmpx_bitrate, #endif +#ifdef RSS + OBJ_rss, +#endif #ifdef TCP_PORT_MONITOR OBJ_tcp_portmon, #endif @@ -1276,6 +1282,12 @@ struct text_object { int port; char *dev; } hddtemp; /* 2 */ +#endif +#ifdef RSS + struct { + char *uri; + int count; + } rss; #endif } data; }; @@ -2030,6 +2042,10 @@ static void free_text_objects(unsigned int count, struct text_object *objs) case OBJ_bmpx_track: case OBJ_bmpx_uri: case OBJ_bmpx_bitrate: +#endif +#ifdef RSS + case OBJ_rss: + free(objs[i].data.rss.uri); #endif case OBJ_pre_exec: case OBJ_battery: @@ -3100,6 +3116,21 @@ static struct text_object *construct_text_object(const char *s, const char *arg, memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); END #endif +#ifdef RSS + OBJ(rss, 0) + if (arg) { + int argc, count; + char *uri = (char *)malloc(64 * sizeof(char *)); + + argc = sscanf(arg, "%63s %d", uri, &count); + printf("argc: %d, uri: %s, count: %d\n", argc, uri, count); + obj->data.rss.uri = uri; + obj->data.rss.count = count; + } else + CRIT_ERR("rss: needs arguments"); + + END +#endif #ifdef HDDTEMP OBJ(hddtemp, 0) if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev, @@ -4254,6 +4285,30 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object * OBJ(hr) { new_hr(p, obj->data.i); } +#ifdef RSS + OBJ(rss) { + GList *walk = NULL; + GList *list = NULL; + char *titles = malloc(1024*sizeof(char *)); + + memset(titles, 0, sizeof(titles)); + list = get_rss_info(obj->data.rss.uri, obj->data.rss.count); + + for (walk = g_list_first(list); walk != NULL; walk = g_list_next(walk)) { + snprintf(titles, 1023, "%s%s\n", titles, (char *)walk->data); + free(walk->data); + } + + /* we don't need last \n */ + titles[strlen(titles)-2] = '\0'; + + snprintf(p, p_max_size, "%s", titles); + + free(titles); + g_list_free(walk); + g_list_free(list); + } +#endif #ifdef HDDTEMP OBJ(hddtemp) { char *temp; diff --git a/src/conky.h b/src/conky.h index 32d32625..8512c4a3 100644 --- a/src/conky.h +++ b/src/conky.h @@ -46,6 +46,10 @@ #include #endif +#ifdef RSS +#include +#endif + #include "mboxscan.h" #include "timed_thread.h" @@ -243,6 +247,9 @@ enum { INFO_XMMS2 = 22, #endif INFO_ENTROPY = 23, +#ifdef RSS + INFO_RSS = 24, +#endif }; @@ -589,6 +596,11 @@ int scan_hddtemp(const char *arg, char **dev, char **addr, int *port); char *get_hddtemp_info(char *dev, char *addr, int port, char *unit); #endif /* HDDTEMP */ +/* in rss.c */ +#ifdef RSS +GList* get_rss_info(char *uri, int count); +#endif /* RSS */ + /* in linux.c */ #endif