From: Jaroslav Kysela Date: Fri, 5 Jan 2018 16:44:50 +0000 (+0100) Subject: api: channel list - sort the channels by numbers by default, issue #4819 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=944121fb900f5b09c139247881ea3d71163ab2e7;p=thirdparty%2Ftvheadend.git api: channel list - sort the channels by numbers by default, issue #4819 --- diff --git a/src/api/api_channel.c b/src/api/api_channel.c index 347068473..a851331d9 100644 --- a/src/api/api_channel.c +++ b/src/api/api_channel.c @@ -37,7 +37,7 @@ static int api_channel_list ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { - channel_t *ch; + channel_t *ch, **chlist; htsmsg_t *l; const int cfg = api_channel_is_all(perm, args); const int numbers = htsmsg_get_s32_or_default(args, "numbers", 0); @@ -45,12 +45,17 @@ api_channel_list const int flags = (numbers ? CHANNEL_ENAME_NUMBERS : 0) | (sources ? CHANNEL_ENAME_SOURCES : 0); char buf[128], buf1[128], ubuf[UUID_HEX_SIZE]; - const char *name, *blank; + const char *name, *blank, *sort = htsmsg_get_str(args, "sort"); + int i, count; + sort = htsmsg_get_str(args, "sort"); + if (numbers && !sort) sort = "numname"; blank = tvh_gettext_lang(perm->aa_lang_ui, channel_blank_name); l = htsmsg_create_list(); pthread_mutex_lock(&global_lock); - CHANNEL_FOREACH(ch) { + chlist = channel_get_sorted_list(sort, cfg, &count); + for (i = 0; i < count; i++) { + ch = chlist[i]; if (!cfg && !channel_access(ch, perm, 0)) continue; if (!ch->ch_enabled) { snprintf(buf, sizeof(buf), "{%s}", @@ -62,6 +67,7 @@ api_channel_list htsmsg_add_msg(l, NULL, htsmsg_create_key_val(idnode_uuid_as_str(&ch->ch_id, ubuf), name)); } pthread_mutex_unlock(&global_lock); + free(chlist); *resp = htsmsg_create_map(); htsmsg_add_msg(*resp, "entries", l); diff --git a/src/channels.c b/src/channels.c index 831fc4d65..7ecba2051 100644 --- a/src/channels.c +++ b/src/channels.c @@ -1300,13 +1300,13 @@ static sortfcn_t *channel_sort_fcn(const char *sort_type) } channel_t ** -channel_get_sorted_list(const char *sort_type, int *_count) +channel_get_sorted_list(const char *sort_type, int all, int *_count) { int count = 0; channel_t *ch, **chlist = malloc(channels_count * sizeof(channel_t *)); CHANNEL_FOREACH(ch) - if (ch->ch_enabled) + if (all || ch->ch_enabled) chlist[count++] = ch; assert(count <= channels_count); diff --git a/src/channels.h b/src/channels.h index 00a750844..47781a75d 100644 --- a/src/channels.h +++ b/src/channels.h @@ -209,7 +209,7 @@ const char *channel_get_epgid ( channel_t *ch ); #define channel_get_id(ch) idnode_get_short_uuid((&(ch)->ch_id)) channel_t **channel_get_sorted_list - ( const char *sort_type, int *_count ) ; + ( const char *sort_type, int all, int *_count ) ; channel_t **channel_get_sorted_list_for_tag ( const char *sort_type, channel_tag_t *tag, int *_count ); channel_tag_t **channel_tag_get_sorted_list diff --git a/src/webui/static/app/chconf.js b/src/webui/static/app/chconf.js index 3f00b7f2f..6f8840eeb 100644 --- a/src/webui/static/app/chconf.js +++ b/src/webui/static/app/chconf.js @@ -24,6 +24,7 @@ tvheadend.getChannels = function() { 'sources': tvheadend.chname_src, }, event: 'channel', + stype: 'none', listeners: { 'load': function(scope, records, options) { var placeholder = Ext.data.Record.create(['key', 'val']); diff --git a/src/webui/webui.c b/src/webui/webui.c index c3fde79cb..a2f8f9c7e 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -686,7 +686,7 @@ http_tag_list_playlist(http_connection_t *hc, int pltype) ctlist = channel_tag_get_sorted_list(sort, &count); if (pltype == PLAYLIST_E2 || pltype == PLAYLIST_SATIP_M3U) { - chlist = channel_get_sorted_list(sort, &chcount); + chlist = channel_get_sorted_list(sort, 0, &chcount); } else { chlist = NULL; } @@ -754,7 +754,7 @@ http_channel_list_playlist(http_connection_t *hc, int pltype) profile = profile_validate_name(http_arg_get(&hc->hc_req_args, "profile")); hostpath = http_get_hostpath(hc); sort = http_arg_get(&hc->hc_req_args, "sort"); - chlist = channel_get_sorted_list(sort, &count); + chlist = channel_get_sorted_list(sort, 0, &count); blank = tvh_gettext_lang(lang, channel_blank_name); htsbuf_append_str(hq, pltype == PLAYLIST_E2 ? "#NAME Tvheadend Channels\n" : "#EXTM3U\n");