]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
channel tag: export public URL for icons
authorJaroslav Kysela <perex@perex.cz>
Wed, 15 Oct 2014 09:50:52 +0000 (11:50 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 15 Oct 2014 09:50:52 +0000 (11:50 +0200)
src/channels.c
src/channels.h
src/htsp_server.c
src/imagecache.c

index 3f60a6584882d61f998857a62611d4729561c4c2..1d7e33411c26c6d777103e96a4ec459171bcb1e8 100644 (file)
@@ -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;
@@ -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';
@@ -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
  * **************************************************************************/
@@ -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)
@@ -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,
index 3993c43660686c8f3b147f27ee528220e401b61c..7b1e4ff9c0792158515376fc8fed7ac9eb6f9189 100644 (file)
@@ -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);
index 33a27a1e33208f854c0c9597cc9e0e3091b8cc28..4c08ddac045bf674fae5f672858b0e925ed42dd9 100644 (file)
@@ -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) {
index aa0f460c779359812acb4a202aeeea9cb63bc800..f1589c77fbfaedc59ac8c79263f4e901718dfcbc 100644 (file)
@@ -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);