]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
channels: icon - generate default channel icon using channel name and path in global...
authorJaroslav Kysela <perex@perex.cz>
Tue, 21 Oct 2014 09:20:52 +0000 (11:20 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 21 Oct 2014 09:20:52 +0000 (11:20 +0200)
src/channels.c
src/config.c
src/config.h
src/imagecache.c
src/webui/extjs.c
src/webui/static/app/config.js

index 1d7e33411c26c6d777103e96a4ec459171bcb1e8..dac123b83d3ae7504847e55e53cbea4b57841cd6 100644 (file)
@@ -42,6 +42,7 @@
 #include "imagecache.h"
 #include "service_mapper.h"
 #include "htsbuf.h"
+#include "intlconv.h"
 
 struct channel_tree channels;
 
@@ -292,6 +293,7 @@ const idclass_t channel_class = {
       .name     = "Name",
       .off      = offsetof(channel_t, ch_name),
       .get      = channel_class_get_name,
+      .notify   = channel_class_icon_notify, /* try to re-render default icon path */
     },
     {
       .type     = PT_S64,
@@ -537,10 +539,47 @@ channel_get_icon ( channel_t *ch )
 {
   static char buf[512], buf2[512];
   channel_service_mapping_t *csm;
-  const char *picon = config_get_picon_path(),
-             *icon  = ch->ch_icon;
+  const char *chicon = config_get_chicon_path(),
+             *picon  = config_get_picon_path(),
+             *icon   = ch->ch_icon,
+             *chname;
   uint32_t id;
 
+  if (icon && *icon == '\0')
+    icon = NULL;
+
+  /* No user icon - try to get the channel icon by name */
+  if (!icon && chicon && chicon[0] >= ' ' && chicon[0] <= 122 &&
+      (chname = channel_get_name(ch)) != NULL && chname[0]) {
+    const char *send, *sname, *s;
+    chicon = strdup(chicon);
+    send = strstr(chicon, "%C");
+    if (send == NULL) {
+      buf[0] = '\0';
+      sname = "";
+    } else {
+      *(char *)send = '\0';
+      send += 2;
+      sname = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
+                                   chname, strlen(chname) * 2);
+      /* Remove problematic characters */
+      s = sname;
+      while (*s) {
+        if (*s <= ' ' || *s > 122 ||
+            strchr("/:\\<>|*?'\"", *s) != NULL)
+          *(char *)s = '_';
+        s++;
+      }
+    }
+    snprintf(buf, sizeof(buf), "%s%s%s", chicon, sname, send);
+    if (send)
+      free((char *)sname);
+    free((char *)chicon);
+
+    icon = ch->ch_icon = strdup(buf);
+    channel_save(ch);
+  }
+
   /* No user icon - try access from services */
   if (!icon && picon) {
     LIST_FOREACH(csm, &ch->ch_services, csm_chn_link) {
index 735563ff9c6c5b77cfdd5ec7d2ceb3e48cbd0005..7f04a5457b40d936bc8c76482da037e382f29c86 100644 (file)
@@ -1400,6 +1400,16 @@ int config_set_muxconfpath ( const char *path )
   return _config_set_str("muxconfpath", path);
 }
 
+const char *config_get_chicon_path ( void )
+{
+  return htsmsg_get_str(config, "chiconpath");
+}
+
+int config_set_chicon_path ( const char *str )
+{
+  return _config_set_str("chiconpath", str);
+}
+
 const char *config_get_picon_path ( void )
 {
   return htsmsg_get_str(config, "piconpath");
index 76f054e4f3215af01542bf339461f3af03655ba9..303199aef1cc4823ebc1cee69a94a821d9d5bc70 100644 (file)
@@ -37,6 +37,10 @@ const char *config_get_language    ( void );
 int         config_set_language    ( const char *str )
   __attribute__((warn_unused_result));
 
+const char *config_get_chicon_path  ( void );
+int         config_set_chicon_path  ( const char *str )
+  __attribute__((warn_unused_result));
+
 const char *config_get_picon_path  ( void );
 int         config_set_picon_path  ( const char *str )
   __attribute__((warn_unused_result));
index f1589c77fbfaedc59ac8c79263f4e901718dfcbc..9713a317059a541eccc1f6aed6afeba55400c150 100644 (file)
@@ -433,7 +433,7 @@ imagecache_get_id ( const char *url )
   lock_assert(&global_lock);
 
   /* Invalid */
-  if (!url || url[0] == '\0')
+  if (!url || url[0] == '\0' || !strstr(url, "://"))
     return 0;
 
   /* Disabled */
index 9172368aebd43dc040314a5fa059c596d3cd9d3c..0a27493d4fd321f5cdc7554be8ed4937f8054e53 100755 (executable)
@@ -505,6 +505,8 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)
       save |= config_set_muxconfpath(str);
     if ((str = http_arg_get(&hc->hc_req_args, "language")))
       save |= config_set_language(str);
+    if ((str = http_arg_get(&hc->hc_req_args, "chiconpath")))
+      save |= config_set_chicon_path(str);
     if ((str = http_arg_get(&hc->hc_req_args, "piconpath")))
       save |= config_set_picon_path(str);
     if (save)
index 166dbd3f2bdf6bd32db823a3a7862ca755d51c12..aa780bcbc277f24d593e3e6f8b773cb60db9b625 100644 (file)
@@ -44,6 +44,7 @@ tvheadend.miscconf = function(panel, index) {
         'muxconfpath', 'language',
         'tvhtime_update_enabled', 'tvhtime_ntp_enabled',
         'tvhtime_tolerance',
+        'chiconpath',
         'piconpath'
     ]);
 
@@ -131,9 +132,15 @@ tvheadend.miscconf = function(panel, index) {
     * Picons
     */
 
+    var chiconPath = new Ext.form.TextField({
+        name: 'chiconpath',
+        fieldLabel: 'Channel icon path<br/>(e.g. file:///tmp/icons/%C.png or http://...)',
+        width: 400
+    });
+
     var piconPath = new Ext.form.TextField({
         name: 'piconpath',
-        fieldLabel: 'Picon path (e.g. file:///tmp/picons)',
+        fieldLabel: 'Picon path<br/>(e.g. file:///tmp/picons or http://...)',
         width: 400
     });
 
@@ -143,7 +150,7 @@ tvheadend.miscconf = function(panel, index) {
         autoHeight: true,
         collapsible: true,
         animCollapse: true,
-        items: [piconPath]
+        items: [chiconPath, piconPath]
     });
 
     /*