]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
channel: make channel number like name
authorAdam Sutton <dev@adamsutton.me.uk>
Fri, 11 Oct 2013 15:20:05 +0000 (16:20 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Fri, 11 Oct 2013 15:20:05 +0000 (16:20 +0100)
This allows user configuration which in the event of no setting will fallback
to information automatically determined from the services.

I have also updated the name stuff and simplified it a bit (with one minor
change to idnode to support).

src/channels.c
src/channels.h
src/htsp_server.c
src/idnode.c
src/service.c
src/service.h
src/webui/statedump.c

index 5d801dc0ae990f6868c7b818458c00c527046c15..e9b76cb202542b75f5487668bd8538b8da563cbe 100644 (file)
@@ -197,10 +197,12 @@ channel_class_get_name ( void *p )
   return &s;
 }
 
-static int
-channel_class_set_name ( void *o, const void *p )
+static const void *
+channel_class_get_number ( void *p )
 {
-  return channel_set_name(o, p);
+  static int i;
+  i = channel_get_number(p);
+  return &i;
 }
 
 const idclass_t channel_class = {
@@ -224,13 +226,13 @@ const idclass_t channel_class = {
       .name     = "Name",
       .off      = offsetof(channel_t, ch_name),
       .get      = channel_class_get_name,
-      .set      = channel_class_set_name,
     },
     {
       .type     = PT_INT,
       .id       = "number",
       .name     = "Number",
       .off      = offsetof(channel_t, ch_number),
+      .get      = channel_class_get_number,
     },
     {
       .type     = PT_STR,
@@ -380,8 +382,7 @@ channel_get_name ( channel_t *ch )
   static const char *blank = "";
   const char *s;
   channel_service_mapping_t *csm;
-
-  if (ch->ch_name) return ch->ch_name;
+  if (ch->ch_name && *ch->ch_name) return ch->ch_name;
   LIST_FOREACH(csm, &ch->ch_services, csm_chn_link)
     if ((s = service_get_channel_name(csm->csm_svc)))
       return s;
@@ -389,24 +390,14 @@ channel_get_name ( channel_t *ch )
 }
 
 int
-channel_set_name ( channel_t *ch, const char *s )
+channel_get_number ( channel_t *ch )
 {
-  if (!s || !*s) {
-    if (ch->ch_name) {
-      free(ch->ch_name);
-      ch->ch_name = NULL;
-    }
-    return 1; // NOTE: we always return this, else UI gets confused
-              // if user see's generated name clears to "" and tries to set
-              // and nosave is returned (so UI doesn't update)
-  }
-
-  if (!ch->ch_name || strcmp(ch->ch_name, s)) {
-    free(ch->ch_name);
-    ch->ch_name = strdup(s);
-    return 1;
-  }
-
+  int n;
+  channel_service_mapping_t *csm;
+  if (ch->ch_number) return ch->ch_number;
+  LIST_FOREACH(csm, &ch->ch_services, csm_chn_link)
+    if ((n = service_get_channel_number(csm->csm_svc)))
+      return n;
   return 0;
 }
 
index f4426ee058656dcad86079f272824526c1c3f0e1..f22053d90a5e5f41cb6278a64f0788a49f1e95de 100644 (file)
@@ -149,6 +149,10 @@ void channel_save(channel_t *ch);
 const char *channel_get_name ( channel_t *ch );
 int channel_set_name ( channel_t *ch, const char *s );
 
+int channel_get_number ( channel_t *ch );
+
+const char *channel_get_icon ( channel_t *ch );
+
 #define channel_get_uuid(ch) idnode_uuid_as_str(&ch->ch_id)
 
 #define channel_get_id(ch)   idnode_get_short_uuid((&ch->ch_id))
index c4192fa88151198f3278b020e0c3d8b5cbe84ce1..ea074e5d2528080c34930d94079a1969c8f2d1b9 100644 (file)
@@ -514,7 +514,7 @@ htsp_build_channel(channel_t *ch, const char *method, htsp_connection_t *htsp)
   htsmsg_t *services = htsmsg_create_list();
 
   htsmsg_add_u32(out, "channelId", channel_get_id(ch));
-  htsmsg_add_u32(out, "channelNumber", ch->ch_number);
+  htsmsg_add_u32(out, "channelNumber", channel_get_number(ch));
 
   htsmsg_add_str(out, "channelName", channel_get_name(ch));
   if(ch->ch_icon != NULL) {
index f96e4da8b1167056a915bf5c8290b7edf75b70a3..abe39042f283c19b27c7a0099bffb7a22abec6cf 100644 (file)
@@ -711,10 +711,15 @@ idnode_write0 ( idnode_t *self, htsmsg_t *c, int optmask, int dosave )
   int save = 0;
   const idclass_t *idc = self->in_class;
   save = idnode_class_write_values(self, idc, c, optmask);
-  if (save && dosave) {
+  if (save && dosave)
     idnode_savefn(self);
+  if (dosave)
     idnode_notify(self, NULL, 0, 0);
-  }
+  // Note: always output event if "dosave", reason is that UI updates on
+  //       these, but there are some subtle cases where it will expect
+  //       an update and not get one. This include fields being set for
+  //       which there is user-configurable value and auto fallback so
+  //       the UI state might not atually reflect the user config
   return save;
 }
 
index d513ceb06e55e6c96478df00737e18df9d8a2034..c10933afd75558de55c5c651d6ab43519015077d 100644 (file)
@@ -1194,6 +1194,16 @@ service_get_channel_name ( service_t *s )
   return r;
 }
 
+/*
+ * Get number for service
+ */
+int
+service_get_channel_number ( service_t *s )
+{
+  if (s->s_channel_number) return s->s_channel_number(s);
+  return 0;
+}
+
 /**
  * Get the encryption CAID from a service
  * only the first CA stream in a service is returned
index e353f564ae7c04325c6bf7959b09067ccf4a3111..7afc3ca1c7cc65ec4045cb35add3765b3d887a57 100644 (file)
@@ -526,5 +526,6 @@ void service_save ( service_t *s, htsmsg_t *c );
 void sort_elementary_streams(service_t *t);
 
 const char *service_get_channel_name (service_t *s);
+int         service_get_channel_number (service_t *s);
 
 #endif // SERVICE_H__
index 4ecdf70caf2f76538ae652271b725951026ae3bc..79dfc0fdc0ff7a39455a49a8471831fbfc7c3534 100644 (file)
@@ -65,7 +65,7 @@ dumpchannels(htsbuf_queue_t *hq)
                   "  icon = %s\n\n",
                   ch->ch_refcount,
                   ch->ch_zombie,
-                  ch->ch_number,
+                  channel_get_number(ch),
                   ch->ch_icon ?: "<none set>");
   }
 }