Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
channel tag: export public URL for icons
  • Loading branch information
perexg committed Oct 15, 2014
1 parent ec231ac commit 8d1eb5b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
43 changes: 41 additions & 2 deletions src/channels.c
Expand Up @@ -535,7 +535,7 @@ channel_get_number ( channel_t *ch )
const char *
channel_get_icon ( channel_t *ch )
{
static __thread char buf[512], buf2[512];
static char buf[512], buf2[512];
channel_service_mapping_t *csm;
const char *picon = config_get_picon_path(),
*icon = ch->ch_icon;
Expand Down Expand Up @@ -570,7 +570,6 @@ channel_get_icon ( channel_t *ch )
/* Lookup imagecache ID */
if ((id = imagecache_get_id(icon))) {
snprintf(buf, sizeof(buf), "imagecache/%d", id);

} else {
strncpy(buf, icon, sizeof(buf));
buf[sizeof(buf)-1] = '\0';
Expand Down Expand Up @@ -877,6 +876,24 @@ channel_tag_save(channel_tag_t *ct)
}


/**
*
*/
const char *
channel_tag_get_icon(channel_tag_t *ct)
{
static char buf[64];
const char *icon = ct->ct_icon;
uint32_t id;

/* Lookup imagecache ID */
if ((id = imagecache_get_id(icon))) {
snprintf(buf, sizeof(buf), "imagecache/%d", id);
return buf;
}
return icon;
}

/* **************************************************************************
* Channel Tag Class definition
* **************************************************************************/
Expand All @@ -900,6 +917,20 @@ channel_tag_class_get_title (idnode_t *self)
return ct->ct_name ?: "";
}

static void
channel_tag_class_icon_notify ( void *obj )
{
(void)channel_tag_get_icon(obj);
}

static const void *
channel_tag_class_get_icon ( void *obj )
{
static const char *s;
s = channel_tag_get_icon(obj);
return &s;
}

/* exported for others */
htsmsg_t *
channel_tag_class_get_list(void *o)
Expand Down Expand Up @@ -942,6 +973,14 @@ const idclass_t channel_tag_class = {
.id = "icon",
.name = "Icon (full URL)",
.off = offsetof(channel_tag_t, ct_icon),
.notify = channel_tag_class_icon_notify,
},
{
.type = PT_STR,
.id = "icon_public_url",
.name = "Icon URL",
.get = channel_tag_class_get_icon,
.opts = PO_RDONLY | PO_NOSAVE | PO_HIDDEN,
},
{
.type = PT_BOOL,
Expand Down
2 changes: 2 additions & 0 deletions src/channels.h
Expand Up @@ -171,6 +171,8 @@ void channel_tag_save(channel_tag_t *ct);

htsmsg_t * channel_tag_class_get_list(void *o);

const char * channel_tag_get_icon(channel_tag_t *ct);

int channel_access(channel_t *ch, struct access *a, const char *username);

int channel_tag_map(channel_t *ch, channel_tag_t *ct);
Expand Down
2 changes: 1 addition & 1 deletion src/htsp_server.c
Expand Up @@ -651,7 +651,7 @@ htsp_build_tag(channel_tag_t *ct, const char *method, int include_channels)
htsmsg_add_u32(out, "tagId", htsp_channel_tag_get_identifier(ct));

htsmsg_add_str(out, "tagName", ct->ct_name);
htsmsg_add_str(out, "tagIcon", ct->ct_icon);
htsmsg_add_str(out, "tagIcon", channel_tag_get_icon(ct));
htsmsg_add_u32(out, "tagTitledIcon", ct->ct_titled_icon);

if(members != NULL) {
Expand Down
8 changes: 5 additions & 3 deletions src/imagecache.c
Expand Up @@ -451,9 +451,11 @@ imagecache_get_id ( const char *url )
if (!i) {
i = imagecache_skel;
i->url = strdup(url);
i->id = ++imagecache_id;
j = RB_INSERT_SORTED(&imagecache_by_id, i, id_link, id_cmp);
assert(!j);
do {
i->id = ++imagecache_id % INT_MAX;
if (!i->id) i->id = ++imagecache_id % INT_MAX;
j = RB_INSERT_SORTED(&imagecache_by_id, i, id_link, id_cmp);
} while (j);
SKEL_USED(imagecache_skel);
#if ENABLE_IMAGECACHE
imagecache_image_add(i);
Expand Down

0 comments on commit 8d1eb5b

Please sign in to comment.