chiark / gitweb /
Display track length and playing state in Disobedience choose tab. We
[disorder] / disobedience / queue-generic.c
index e6971ab60d487b77c3f05d69e618b0d7af6a4691..cc6bf53679bc03db7a47fb9e4e203f8a184d59ca 100644 (file)
@@ -50,124 +50,11 @@ static struct queuelike *const queuelikes[] = {
 
 /* Track detail lookup ----------------------------------------------------- */
 
-static int namepart_lookups_outstanding;
-static const struct cache_type cachetype_string = { 3600 };
-static const struct cache_type cachetype_integer = { 3600 };
-
-/** @brief Called when a namepart lookup has completed or failed
- *
- * When there are no lookups in flight a redraw is provoked.  This might well
- * provoke further lookups.
- */
-static void namepart_completed_or_failed(void) {
-  --namepart_lookups_outstanding;
-  if(!namepart_lookups_outstanding) {
-    /* There are no more lookups outstanding, so we update the display */
-    for(unsigned n = 0; n < NQUEUELIKES; ++n)
-      ql_update_list_store(queuelikes[n]);
-  }
-}
-
-/** @brief Called when a namepart lookup has completed */
-static void namepart_completed(void *v, const char *error, const char *value) {
-  D(("namepart_completed"));
-  if(error) {
-    gtk_label_set_text(GTK_LABEL(report_label), error);
-    value = "?";
-  }
-  const char *key = v;
-  
-  cache_put(&cachetype_string, key, value);
-  namepart_completed_or_failed();
-}
-
-/** @brief Called when a length lookup has completed */
-static void length_completed(void *v, const char *error, long l) {
-  D(("length_completed"));
-  if(error) {
-    gtk_label_set_text(GTK_LABEL(report_label), error);
-    l = -1;
-  }
-  const char *key = v;
-  long *value;
-  
-  D(("namepart_completed"));
-  value = xmalloc(sizeof *value);
-  *value = l;
-  cache_put(&cachetype_integer, key, value);
-  namepart_completed_or_failed();
-}
-
-/** @brief Arrange to fill in a namepart cache entry */
-static void namepart_fill(const char *track,
-                          const char *context,
-                          const char *part,
-                          const char *key) {
-  D(("namepart_fill %s %s %s %s", track, context, part, key));
-  /* We limit the total number of lookups in flight */
-  ++namepart_lookups_outstanding;
-  D(("namepart_lookups_outstanding -> %d\n", namepart_lookups_outstanding));
-  disorder_eclient_namepart(client, namepart_completed,
-                            track, context, part, (void *)key);
-}
-
-/** @brief Look up a namepart
- * @param track Track name
- * @param context Context
- * @param part Name part
- * @param lookup If nonzero, will schedule a lookup for unknown values
- *
- * If it is in the cache then just return its value.  If not then look it up
- * and arrange for the queues to be updated when its value is available. */
-static const char *namepart(const char *track,
-                            const char *context,
-                            const char *part) {
-  char *key;
-  const char *value;
-
-  D(("namepart %s %s %s", track, context, part));
-  byte_xasprintf(&key, "namepart context=%s part=%s track=%s",
-                 context, part, track);
-  value = cache_get(&cachetype_string, key);
-  if(!value) {
-    D(("deferring..."));
-    namepart_fill(track, context, part, key);
-    value = "?";
-  }
-  return value;
-}
-
-/** @brief Called from @ref disobedience/properties.c when we know a name part has changed */
-void namepart_update(const char *track,
-                     const char *context,
-                     const char *part) {
-  char *key;
-
-  byte_xasprintf(&key, "namepart context=%s part=%s track=%s",
-                 context, part, track);
-  /* Only refetch if it's actually in the cache. */
-  if(cache_get(&cachetype_string, key))
-    namepart_fill(track, context, part, key);
-}
-
-/** @brief Look up a track length
- *
- * If it is in the cache then just return its value.  If not then look it up
- * and arrange for the queues to be updated when its value is available. */
-static long getlength(const char *track) {
-  char *key;
-  const long *value;
-
-  D(("getlength %s", track));
-  byte_xasprintf(&key, "length track=%s", track);
-  value = cache_get(&cachetype_integer, key);
-  if(value)
-    return *value;
-  D(("deferring..."));;
-  ++namepart_lookups_outstanding;
-  D(("namepart_lookups_outstanding -> %d\n", namepart_lookups_outstanding));
-  disorder_eclient_length(client, length_completed, track, key);
-  return -1;
+static void queue_lookups_completed(const char attribute((unused)) *event,
+                                   void attribute((unused)) *eventdata,
+                                   void *callbackdata) {
+  struct queuelike *ql = callbackdata;
+  ql_update_list_store(ql);
 }
 
 /* Column formatting -------------------------------------------------------- */
@@ -229,7 +116,7 @@ const char *column_length(const struct queue_entry *q,
   char *played = 0, *length = 0;
 
   /* Work out what to say for the length */
-  l = getlength(q->track);
+  l = namepart_length(q->track);
   if(l > 0)
     byte_xasprintf(&length, "%ld:%02ld", l / 60, l % 60);
   else
@@ -495,8 +382,6 @@ void ql_new_queue(struct queuelike *ql,
   ql->q = newq;
   /* Set the rest of the columns in new rows */
   ql_update_list_store(ql);
-  /* Update menu sensitivity */
-  menu_update(-1);
   --suppress_actions;
 }
 
@@ -546,6 +431,9 @@ GtkWidget *init_queuelike(struct queuelike *ql) {
 
   ql->init();
 
+  /* Update display text when lookups complete */
+  event_register("lookups-completed", queue_lookups_completed, ql);
+  
   GtkWidget *scrolled = scroll_widget(ql->view);
   g_object_set_data(G_OBJECT(scrolled), "type", (void *)ql_tabtype(ql));
   return scrolled;