]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
use common code for drawing tables, this also allows us to do some
authorAndreas Öman <andreas@lonelycoder.com>
Wed, 9 Apr 2008 15:31:07 +0000 (15:31 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Wed, 9 Apr 2008 15:31:07 +0000 (15:31 +0000)
simple scrollbar control

ajaxui/ajaxui.c
ajaxui/ajaxui.h
ajaxui/ajaxui_config_dvb.c

index 88d435bc30432faffa5021c1d38fd9b556d40bd7..f452694abaf3e187f59b2e5953960157d37deac9 100644 (file)
@@ -56,6 +56,63 @@ const char *ajax_tabnames[] = {
   [AJAX_TAB_ABOUT]         = "About",
 };
 
+/**
+ * AJAX table header
+ */
+void
+ajax_table_header(http_connection_t *hc, tcp_queue_t *tq,
+                 const char *names[], int weights[],
+                 int scrollbar, int columnsizes[])
+{
+  int n = 0, i, tw = 0;
+  while(names[n]) {
+    tw += weights[n];
+    n++;
+  }
+
+  for(i = 0; i < n; i++)
+    columnsizes[i] = 100 * weights[i] / tw;
+
+  if(scrollbar)
+    tcp_qprintf(tq, "<div style=\"padding-right: 20px\">");
+
+  tcp_qprintf(tq, "<div style=\"overflow: auto; width: 100%\">");
+
+  for(i = 0; i < n; i++)
+    tcp_qprintf(tq, "<div style=\"float: left; width: %d%%\">%s</div>",
+               columnsizes[i], names[i] ?: "&nbsp;");
+
+  tcp_qprintf(tq, "</div>");
+  if(scrollbar)
+    tcp_qprintf(tq, "</div>");
+}
+                 
+                 
+/**
+ * AJAX table row
+ */
+void
+ajax_table_row(tcp_queue_t *tq, const char *cells[], int columnsizes[],
+              int *bgptr)
+{
+  int i = 0;
+
+  tcp_qprintf(tq, "<div style=\"%soverflow: auto; width: 100%\">",
+             *bgptr ? "background: #fff; " : "");
+
+  *bgptr = !*bgptr;
+
+  while(cells[i]) {
+    tcp_qprintf(tq, "<div style=\"float: left; width: %d%%\">%s</div>",
+               columnsizes[i], cells[i]);
+    i++;
+  }
+  tcp_qprintf(tq, "</div>\r\n");
+}
+
+
+
+
 /**
  * AJAX box start
  */
index 0271bb39a9881b9ff8e2d16cb96086580103ef54..ac33df54edc4ae1109e2d75ce1651568e708bae0 100644 (file)
@@ -67,4 +67,12 @@ void ajax_config_transport_init(void);
 int ajax_transport_build_list(tcp_queue_t *tq,
                              struct th_transport_list *tlist);
 
+
+void ajax_table_header(http_connection_t *hc, tcp_queue_t *tq,
+                      const char *names[], int weights[],
+                      int scrollbar, int columnsizes[]);
+
+void ajax_table_row(tcp_queue_t *tq, const char *cells[], int columnsizes[],
+                   int *bgptr);
+
 #endif /* AJAXUI_H_ */
index 33f41b32106b122f4ad53e498ed5b9e21375644c..ef5cda2e47219c7441e803e1d600cff2789317b8 100644 (file)
@@ -219,30 +219,11 @@ ajax_adaptereditor(http_connection_t *hc, const char *remain, void *opaque)
   //  tcp_qprintf(&tq, "<div class=\"infoprefixwide\">Capabilities:</div>");
 
   tcp_qprintf(&tq, "<div style=\"float: left; width:45%\">");
-  ajax_box_begin(&tq, AJAX_BOX_SIDEBOX, NULL, NULL, "Multiplexes");
-
-  /* List of muxes */
-
-  tcp_qprintf(&tq, "<div style=\"overflow: auto; width: 100%\">");
-
-  tcp_qprintf(&tq, "<div style=\"float: left; width: 20%\">"
-             "Freq.</div>");
-  tcp_qprintf(&tq, "<div style=\"float: left; width: 25%\">%s</div>",
-             "Status");
-  tcp_qprintf(&tq, "<div style=\"float: left; width: 15%\">%s</div>",
-             "State");
-  tcp_qprintf(&tq, "<div style=\"float: left; width: 25%\">%s</div>",
-             "Name");
-  tcp_qprintf(&tq, "<div style=\"float: left; width: 15%\">%s</div>",
-             "Services");
-  tcp_qprintf(&tq, "</div><hr>");
 
+  ajax_box_begin(&tq, AJAX_BOX_SIDEBOX, NULL, NULL, "Multiplexes");
 
-  tcp_qprintf(&tq, "<div id=\"dvbmuxlist%s\" class=\"normallist\">",
+  tcp_qprintf(&tq, "<div id=\"dvbmuxlist%s\"></div>",
              tda->tda_identifier);
-  tcp_qprintf(&tq, "</div>");
-  
-  
 
   ajax_js(&tq, 
          "new Ajax.Updater('dvbmuxlist%s', "
@@ -557,11 +538,17 @@ ajax_adaptermuxlist(http_connection_t *hc, const char *remain, void *opaque)
   th_dvb_mux_instance_t *tdmi;
   tcp_queue_t tq;
   th_dvb_adapter_t *tda;
-  char buf[50];
+  char buf[50], buf2[500], buf3[20];
   const char *txt;
   int fetype, n;
   th_transport_t *t;
-  int o = 1;
+  int o = 1, v;
+  int csize[10];
+  int nmuxes = 0;
+
+  int displines = 21;
+
+  const char *cells[10];
 
   if(remain == NULL || (tda = dvb_adapter_find_by_identifier(remain)) == NULL)
     return HTTP_STATUS_NOT_FOUND;
@@ -570,27 +557,44 @@ ajax_adaptermuxlist(http_connection_t *hc, const char *remain, void *opaque)
 
   tcp_init_queue(&tq, -1);
 
-  if(LIST_FIRST(&tda->tda_muxes) == NULL) {
+  /* List of muxes */
+  
+  LIST_FOREACH(tdmi, &tda->tda_muxes, tdmi_adapter_link)
+    nmuxes++;
+  
+  ajax_table_header(hc, &tq,
+                   (const char *[])
+                   {"Freq", "Status", "State", "Name", "Services", NULL},
+                   (int[]){3,3,2,4,2},
+                   nmuxes > displines,
+                   csize);
+
+  tcp_qprintf(&tq, "<hr>");
+
+  v = displines;
+  if(nmuxes < displines)
+    v = nmuxes;
+
+  tcp_qprintf(&tq, "<div id=\"dvbmuxlist%s\" "
+             "style=\"height: %dpx; overflow: auto\" class=\"normallist\">",
+             tda->tda_identifier, v * 14);
+
+  if(nmuxes == 0) {
     tcp_qprintf(&tq, "<div style=\"text-align: center\">"
                "No muxes configured</div>");
   } else LIST_FOREACH(tdmi, &tda->tda_muxes, tdmi_adapter_link) {
 
-    tcp_qprintf(&tq, "<div%s>", o ? " style=\"background: #fff\"" : "");
-    o = !o;
-
     tdmi_displayname(tdmi, buf, sizeof(buf));
 
-    tcp_qprintf(&tq, "<div style=\"overflow: auto; width: 100%\">");
-    tcp_qprintf(&tq, "<div style=\"float: left; width: 20%\">"
-               "<a href=\"javascript:void(0);\" "
-               "onClick=\"new Ajax.Updater('servicepane', "
-               "'/ajax/dvbmuxeditor/%s', "
-               "{method: 'get', evalScripts: true})\""
-               ">%s</a></div>", tdmi->tdmi_identifier, buf);
-
-    tcp_qprintf(&tq, "<div style=\"float: left; width: 25%\">%s</div>",
-               dvb_mux_status(tdmi));
+    snprintf(buf2, sizeof(buf2), 
+            "<a href=\"javascript:void(0);\" "
+            "onClick=\"new Ajax.Updater('servicepane', "
+            "'/ajax/dvbmuxeditor/%s', {method: 'get', evalScripts: true})\""
+            ">%s</a>", tdmi->tdmi_identifier, buf);
 
+    cells[0] = buf2;
+    cells[1] = dvb_mux_status(tdmi);
     switch(tdmi->tdmi_state) {
     case TDMI_IDLE:      txt = "Idle";      break;
     case TDMI_IDLESCAN:  txt = "Scanning";  break;
@@ -598,24 +602,26 @@ ajax_adaptermuxlist(http_connection_t *hc, const char *remain, void *opaque)
     default:             txt = "???";       break;
     }
 
-    tcp_qprintf(&tq, "<div style=\"float: left; width: 15%\">%s</div>",
-               txt);
-
+    cells[2] = txt;
     txt = tdmi->tdmi_network;
     if(txt == NULL)
       txt = "Unknown";
 
-    tcp_qprintf(&tq, "<div style=\"float: left; width: 25%\">%s</div>",
-               txt);
+    cells[3] = txt;
 
     n = 0;
     LIST_FOREACH(t, &tdmi->tdmi_transports, tht_mux_link)
       n++;
 
-    tcp_qprintf(&tq, "<div style=\"float: left; width: 15%\">%d</div>", n);
+    snprintf(buf3, sizeof(buf3), "%d", n);
+    cells[4] = buf3;
+    cells[5] = NULL;
+
+    ajax_table_row(&tq, cells, csize, &o);
 
-    tcp_qprintf(&tq, "</div></div>");
   }
+  tcp_qprintf(&tq, "</div>");
 
   http_output_queue(hc, &tq, "text/html; charset=UTF-8", 0);
   return 0;