Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
channels: icons - implement 'service name picons' scheme, fixes #3525
  • Loading branch information
perexg committed Jan 25, 2016
1 parent b883383 commit afa1a3c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 22 deletions.
84 changes: 68 additions & 16 deletions src/channels.c
Expand Up @@ -657,6 +657,41 @@ channel_set_number ( channel_t *ch, uint32_t major, uint32_t minor )
return save;
}

static char *
svcnamepicons(const char *svcname)
{
const char *s;
char *r, *d;
int count;
char c;

for (s = svcname, count = 0; *s; s++) {
c = *s;
if (c == '&' || c == '+' || c == '*')
count++;
}
r = d = malloc(count * 4 + (s - svcname) + 1);
for (s = svcname; *s; s++) {
c = *s;
if (c == '&') {
d[0] = 'a'; d[1] = 'n'; d[2] = 'd'; d += 3;
} else if (c == '*') {
d[0] = 'p'; d[1] = 'l'; d[2] = 'u'; d[3] = 's'; d += 4;
} else if (c == '*') {
d[0] = 's'; d[1] = 't'; d[2] = 'a'; d[3] = 'r'; d += 4;
} else {
if (c >= 'a' && c <= 'z')
*d++ = c;
else if (c >= 'A' && c <= 'Z')
*d++ = c - 'A' + 'a';
else if (c >= '0' && c <= '9')
*d++ = c;
}
}
*d = '\0';
return r;
}

static int
check_file( const char *url )
{
Expand All @@ -675,6 +710,7 @@ channel_get_icon ( channel_t *ch )
*icon = ch->ch_icon,
*chname, *icn;
uint32_t id, i, pick, prefer = config.prefer_picon ? 1 : 0;
char c;

if (icon && *icon == '\0')
icon = NULL;
Expand Down Expand Up @@ -713,38 +749,54 @@ channel_get_icon ( channel_t *ch )

/* Check for and replace placeholders */
if ((send = strstr(chi, "%C"))) {

sname = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
chname, strlen(chname) * 2);
if (sname == NULL)
sname = strdup(chname);

/* Remove problematic characters */
s = sname;
while (s && *s) {
if (*s <= ' ' || *s > 122 ||
strchr("/:\\<>|*?'\"", *s) != NULL)
*(char *)s = '_';
else if (config.chicon_lowercase && *s >= 'A' && *s <= 'Z')
*(char *)s = *s - 'A' + 'a';
s++;
if (config.chicon_scheme == CHICON_SVCNAME) {
s = svcnamepicons(sname);
free((char *)sname);
sname = s;
} else {
s = sname;
while (s && *s) {
c = *s;
if (c <= ' ' || c > 122 ||
strchr("/:\\<>|*?'\"", c) != NULL)
*(char *)s = '_';
else if (config.chicon_scheme == CHICON_LOWERCASE && c >= 'A' && c <= 'Z')
*(char *)s = c - 'A' + 'a';
s++;
}
}
}
else if((send = strstr(chi, "%c"))) {

} else if((send = strstr(chi, "%c"))) {

char *aname = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
chname, strlen(chname) * 2);

if (aname == NULL)
aname = strdup(chname);

if (config.chicon_lowercase)
for (s = aname; *s; s++)
if (*s >= 'A' && *s <= 'Z')
*(char *)s = *s - 'A' + 'a';
if (config.chicon_scheme == CHICON_LOWERCASE) {
for (s = aname; *s; s++) {
c = *s;
if (c >= 'A' && c <= 'Z')
*(char *)s = c - 'A' + 'a';
}
} else if (config.chicon_scheme == CHICON_SVCNAME) {
s = svcnamepicons(aname);
free((char *)aname);
aname = (char *)s;
}

sname = url_encode(aname);
free((char *)aname);
}
else {

} else {
buf[0] = '\0';
sname = "";
}
Expand Down
23 changes: 18 additions & 5 deletions src/config.c
Expand Up @@ -1911,6 +1911,17 @@ config_class_uilevel ( void *o, const char *lang )
return strtab2htsmsg(tab, 1, lang);
}

static htsmsg_t *
config_class_chiconscheme_list ( void *o, const char *lang )
{
static const struct strtab tab[] = {
{ N_("No scheme"), CHICON_NONE },
{ N_("All lower-case"), CHICON_LOWERCASE },
{ N_("Service name picons"), CHICON_SVCNAME },
};
return strtab2htsmsg(tab, 1, lang);
}

const idclass_t config_class = {
.ic_snode = &config.idnode,
.ic_class = "config",
Expand Down Expand Up @@ -2163,11 +2174,13 @@ const idclass_t config_class = {
.group = 6,
},
{
.type = PT_BOOL,
.id = "chiconlowercase",
.name = N_("Channel icon name lower-case"),
.desc = N_("Use icons with lower-case filenames only."),
.off = offsetof(config_t, chicon_lowercase),
.type = PT_INT,
.id = "chiconscheme",
.name = N_("Channel icon name scheme"),
.desc = N_("Select scheme to generathe the channel icon names "
"(all lower-case, service name picons etc.)."),
.list = config_class_chiconscheme_list,
.off = offsetof(config_t, chicon_scheme),
.opts = PO_ADVANCED,
.group = 6,
},
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Expand Up @@ -42,7 +42,7 @@ typedef struct config {
char *muxconf_path;
int prefer_picon;
char *chicon_path;
int chicon_lowercase;
int chicon_scheme;
char *picon_path;
int tvhtime_update_enabled;
int tvhtime_ntp_enabled;
Expand Down
7 changes: 7 additions & 0 deletions src/tvheadend.h
Expand Up @@ -131,6 +131,13 @@ typedef enum {
#define UILEVEL_ADVANCED 1
#define UILEVEL_EXPERT 2

/*
*
*/
#define CHICON_NONE 0
#define CHICON_LOWERCASE 1
#define CHICON_SVCNAME 2

/*
* global timer
*/
Expand Down

0 comments on commit afa1a3c

Please sign in to comment.