chiark / gitweb /
merge disorder.unicode branch
[disorder] / disobedience / queue.c
index 80ca4a6e5534eed01d9246d8b227a557b3898345..7565935dce915c2e21bbe6faaf84baa68da253c4 100644 (file)
@@ -55,6 +55,7 @@
  */
 
 #include "disobedience.h"
  */
 
 #include "disobedience.h"
+#include "charset.h"
 
 /** @brief Horizontal padding for queue cells */
 #define HCELLPADDING 4
 
 /** @brief Horizontal padding for queue cells */
 #define HCELLPADDING 4
@@ -174,13 +175,10 @@ struct queue_menuitem {
  * ql_added.
  */
 struct queuelike {
  * ql_added.
  */
 struct queuelike {
-  /** @brief Name of this queue */
-  const char *name;
-
   /** @brief Called when an update completes */
   void (*notify)(void);
 
   /** @brief Called when an update completes */
   void (*notify)(void);
 
-  /** @brief Called to  fix up the queue after update
+  /** @brief Called to fix up the queue after update
    * @param q The list passed back from the server
    * @return Assigned to @c ql->q
    */
    * @param q The list passed back from the server
    * @return Assigned to @c ql->q
    */
@@ -261,7 +259,7 @@ static void dump_layout(const struct queuelike *ql) {
 static void namepart_completed_or_failed(void) {
   D(("namepart_completed_or_failed"));
   --namepart_lookups_outstanding;
 static void namepart_completed_or_failed(void) {
   D(("namepart_completed_or_failed"));
   --namepart_lookups_outstanding;
-  if(!namepart_lookups_outstanding || namepart_completions_deferred > 24) {
+  if(!namepart_lookups_outstanding) {
     redisplay_queue(&ql_queue);
     redisplay_queue(&ql_recent);
     redisplay_queue(&ql_added);
     redisplay_queue(&ql_queue);
     redisplay_queue(&ql_recent);
     redisplay_queue(&ql_added);
@@ -433,7 +431,8 @@ static GtkWidget *column_namepart(const struct queuelike
                                   const char *data) {
   D(("column_namepart"));
   NW(label);
                                   const char *data) {
   D(("column_namepart"));
   NW(label);
-  return gtk_label_new(namepart(q->track, "display", data));
+  return gtk_label_new(truncate_for_display(namepart(q->track, "display", data),
+                                            config->short_display));
 }
 
 /** @brief Compute the length field */
 }
 
 /** @brief Compute the length field */
@@ -509,9 +508,14 @@ static void update_queue(struct queuelike *ql, struct queue_entry *newq) {
   selection_cleanup(ql->selection);
 }
 
   selection_cleanup(ql->selection);
 }
 
-/** @brief Wrap up a widget for putting into the queue or title */
+/** @brief Wrap up a widget for putting into the queue or title
+ * @param label Label to contain
+ * @param style Pointer to style to use
+ * @param wp Updated with maximum width (or NULL)
+ * @return New widget
+ */
 static GtkWidget *wrap_queue_cell(GtkWidget *label,
 static GtkWidget *wrap_queue_cell(GtkWidget *label,
-                                  const char *name,
+                                  GtkStyle *style,
                                   int *wp) {
   GtkRequisition req;
   GtkWidget *bg;
                                   int *wp) {
   GtkRequisition req;
   GtkWidget *bg;
@@ -529,9 +533,9 @@ static GtkWidget *wrap_queue_cell(GtkWidget *label,
     gtk_widget_size_request(label, &req);
     if(req.width > *wp) *wp = req.width;
   }
     gtk_widget_size_request(label, &req);
     if(req.width > *wp) *wp = req.width;
   }
-  /* Set widget names */
-  gtk_widget_set_name(bg, name);
-  gtk_widget_set_name(label, name);
+  /* Set colors */
+  gtk_widget_set_style(bg, style);
+  gtk_widget_set_style(label, style);
   return bg;
 }
 
   return bg;
 }
 
@@ -540,20 +544,20 @@ static GtkWidget *get_queue_cell(struct queuelike *ql,
                                  const struct queue_entry *q,
                                  int row,
                                  int col,
                                  const struct queue_entry *q,
                                  int row,
                                  int col,
-                                 const char *name,
+                                 GtkStyle *style,
                                  int *wp) {
   GtkWidget *label;
   D(("get_queue_cell %d %d", row, col));
   label = ql->columns[col].widget(ql, q, ql->columns[col].data);
   gtk_misc_set_alignment(GTK_MISC(label), ql->columns[col].xalign, 0);
                                  int *wp) {
   GtkWidget *label;
   D(("get_queue_cell %d %d", row, col));
   label = ql->columns[col].widget(ql, q, ql->columns[col].data);
   gtk_misc_set_alignment(GTK_MISC(label), ql->columns[col].xalign, 0);
-  return wrap_queue_cell(label, name, wp);
+  return wrap_queue_cell(label, style, wp);
 }
 
 /** @brief Add a padding cell to the end of a row */
 }
 
 /** @brief Add a padding cell to the end of a row */
-static GtkWidget *get_padding_cell(const char *name) {
+static GtkWidget *get_padding_cell(GtkStyle *style) {
   D(("get_padding_cell"));
   NW(label);
   D(("get_padding_cell"));
   NW(label);
-  return wrap_queue_cell(gtk_label_new(""), name, 0);
+  return wrap_queue_cell(gtk_label_new(""), style, 0);
 }
 
 /* User button press and menu ---------------------------------------------- */
 }
 
 /* User button press and menu ---------------------------------------------- */
@@ -804,7 +808,7 @@ static gboolean queue_drag_motion(GtkWidget attribute((unused)) *widget,
       g_signal_connect(ql->dragmark, "destroy",
                        G_CALLBACK(gtk_widget_destroyed), &ql->dragmark);
       gtk_widget_set_size_request(ql->dragmark, 10240, row ? 4 : 2);
       g_signal_connect(ql->dragmark, "destroy",
                        G_CALLBACK(gtk_widget_destroyed), &ql->dragmark);
       gtk_widget_set_size_request(ql->dragmark, 10240, row ? 4 : 2);
-      gtk_widget_set_name(ql->dragmark, "queue-drag");
+      gtk_widget_set_style(ql->dragmark, drag_style);
       gtk_layout_put(GTK_LAYOUT(ql->mainlayout), ql->dragmark, 0, 
                      (row + 1) * ql->mainrowheight - !!row);
     } else
       gtk_layout_put(GTK_LAYOUT(ql->mainlayout), ql->dragmark, 0, 
                      (row + 1) * ql->mainrowheight - !!row);
     } else
@@ -906,7 +910,7 @@ static void redisplay_queue(struct queuelike *ql) {
   struct queue_entry *q;
   int row, col;
   GList *c, *children;
   struct queue_entry *q;
   int row, col;
   GList *c, *children;
-  const char *name;
+  GtkStyle *style;
   GtkRequisition req;  
   GtkWidget *w;
   int maxwidths[MAXCOLUMNS], x, y, titlerowheight;
   GtkRequisition req;  
   GtkWidget *w;
   int maxwidths[MAXCOLUMNS], x, y, titlerowheight;
@@ -946,15 +950,15 @@ static void redisplay_queue(struct queuelike *ql) {
     /* Construct the widgets */
     for(q = ql->q, row = 0; q; q = q->next, ++row) {
       /* Figure out the widget name for this row */
     /* Construct the widgets */
     for(q = ql->q, row = 0; q; q = q->next, ++row) {
       /* Figure out the widget name for this row */
-      if(q == playing_track) name = "row-playing";
-      else name = row % 2 ? "row-even" : "row-odd";
+      if(q == playing_track) style = active_style;
+      else style = row % 2 ? even_style : odd_style;
       /* Make the widget for each column */
       for(col = 0; col <= ql->ncolumns; ++col) {
         /* Create and store the widget */
         if(col < ql->ncolumns)
       /* Make the widget for each column */
       for(col = 0; col <= ql->ncolumns; ++col) {
         /* Create and store the widget */
         if(col < ql->ncolumns)
-          w = get_queue_cell(ql, q, row, col, name, &maxwidths[col]);
+          w = get_queue_cell(ql, q, row, col, style, &maxwidths[col]);
         else
         else
-          w = get_padding_cell(name);
+          w = get_padding_cell(style);
         ql->cells[row * (ql->ncolumns + 1) + col] = w;
         /* Maybe mark it draggable */
         if(draggable_row(q)) {
         ql->cells[row * (ql->ncolumns + 1) + col] = w;
         /* Maybe mark it draggable */
         if(draggable_row(q)) {
@@ -1059,7 +1063,6 @@ static GtkWidget *queuelike(struct queuelike *ql,
                             struct queue_entry *(*fixup)(struct queue_entry *),
                             void (*notify)(void),
                             struct queue_menuitem *menuitems,
                             struct queue_entry *(*fixup)(struct queue_entry *),
                             void (*notify)(void),
                             struct queue_menuitem *menuitems,
-                            const char *name,
                             const struct column *columns,
                             int ncolumns) {
   GtkWidget *vbox, *mainscroll, *titlescroll, *label;
                             const struct column *columns,
                             int ncolumns) {
   GtkWidget *vbox, *mainscroll, *titlescroll, *label;
@@ -1070,7 +1073,6 @@ static GtkWidget *queuelike(struct queuelike *ql,
   ql->fixup = fixup;
   ql->notify = notify;
   ql->menuitems = menuitems;
   ql->fixup = fixup;
   ql->notify = notify;
   ql->menuitems = menuitems;
-  ql->name = name;
   ql->mainrowheight = !0;                /* else division by 0 */
   ql->selection = selection_new();
   ql->columns = columns;
   ql->mainrowheight = !0;                /* else division by 0 */
   ql->selection = selection_new();
   ql->columns = columns;
@@ -1078,11 +1080,13 @@ static GtkWidget *queuelike(struct queuelike *ql,
   /* Create the layouts */
   NW(layout);
   ql->mainlayout = gtk_layout_new(0, 0);
   /* Create the layouts */
   NW(layout);
   ql->mainlayout = gtk_layout_new(0, 0);
+  gtk_widget_set_style(ql->mainlayout, layout_style);
   NW(layout);
   ql->titlelayout = gtk_layout_new(0, 0);
   NW(layout);
   ql->titlelayout = gtk_layout_new(0, 0);
+  gtk_widget_set_style(ql->titlelayout, title_style);
   /* Scroll the layouts */
   /* Scroll the layouts */
-  ql->mainscroll = mainscroll = scroll_widget(ql->mainlayout, name);
-  titlescroll = scroll_widget(ql->titlelayout, name);
+  ql->mainscroll = mainscroll = scroll_widget(ql->mainlayout);
+  titlescroll = scroll_widget(ql->titlelayout);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(titlescroll),
                                  GTK_POLICY_NEVER, GTK_POLICY_NEVER);
   mainadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(mainscroll));
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(titlescroll),
                                  GTK_POLICY_NEVER, GTK_POLICY_NEVER);
   mainadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(mainscroll));
@@ -1094,10 +1098,10 @@ static GtkWidget *queuelike(struct queuelike *ql,
     NW(label);
     label = gtk_label_new(ql->columns[col].name);
     gtk_misc_set_alignment(GTK_MISC(label), ql->columns[col].xalign, 0);
     NW(label);
     label = gtk_label_new(ql->columns[col].name);
     gtk_misc_set_alignment(GTK_MISC(label), ql->columns[col].xalign, 0);
-    ql->titlecells[col] = wrap_queue_cell(label, "row-title", 0);
+    ql->titlecells[col] = wrap_queue_cell(label, title_style, 0);
     gtk_layout_put(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], 0, 0);
   }
     gtk_layout_put(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], 0, 0);
   }
-  ql->titlecells[col] = get_padding_cell("row-title");
+  ql->titlecells[col] = get_padding_cell(title_style);
   gtk_layout_put(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], 0, 0);
   /* Pack the lot together in a vbox */
   NW(vbox);
   gtk_layout_put(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], 0, 0);
   /* Pack the lot together in a vbox */
   NW(vbox);
@@ -1123,6 +1127,7 @@ static GtkWidget *queuelike(struct queuelike *ql,
   g_signal_connect(ql->mainlayout, "button-press-event",
                    G_CALLBACK(mainlayout_button), ql);
 #endif
   g_signal_connect(ql->mainlayout, "button-press-event",
                    G_CALLBACK(mainlayout_button), ql);
 #endif
+  set_tool_colors(ql->menu);
   return vbox;
 }
 
   return vbox;
 }
 
@@ -1312,11 +1317,12 @@ GtkWidget *queue_widget(void) {
   /* Arrange periodic update of the so-far played field */
   g_timeout_add(1000/*ms*/, adjust_sofar, 0);
   /* Arrange a callback whenever the playing state changes */ 
   /* Arrange periodic update of the so-far played field */
   g_timeout_add(1000/*ms*/, adjust_sofar, 0);
   /* Arrange a callback whenever the playing state changes */ 
-  register_monitor(playing_update, 0,  DISORDER_PLAYING|DISORDER_TRACK_PAUSED);
+  register_monitor(playing_update, 0, DISORDER_PLAYING|DISORDER_TRACK_PAUSED);
+  register_reset(queue_update);
   /* We pass choose_update() as our notify function since the choose screen
    * marks tracks that are playing/in the queue. */
   return queuelike(&ql_queue, fixup_queue, choose_update, queue_menu,
   /* We pass choose_update() as our notify function since the choose screen
    * marks tracks that are playing/in the queue. */
   return queuelike(&ql_queue, fixup_queue, choose_update, queue_menu,
-                   "queue", maincolumns, NMAINCOLUMNS);
+                   maincolumns, NMAINCOLUMNS);
 }
 
 /** @brief Arrange an update of the queue widget
 }
 
 /** @brief Arrange an update of the queue widget
@@ -1367,7 +1373,8 @@ static struct queue_menuitem recent_menu[] = {
 /** @brief Create the recently-played list */
 GtkWidget *recent_widget(void) {
   D(("recent_widget"));
 /** @brief Create the recently-played list */
 GtkWidget *recent_widget(void) {
   D(("recent_widget"));
-  return queuelike(&ql_recent, fixup_recent, 0, recent_menu, "recent",
+  register_reset(recent_update);
+  return queuelike(&ql_recent, fixup_recent, 0, recent_menu,
                    maincolumns, NMAINCOLUMNS);
 }
 
                    maincolumns, NMAINCOLUMNS);
 }
 
@@ -1399,7 +1406,8 @@ static struct queue_menuitem added_menu[] = {
 /** @brief Create the newly-added list */
 GtkWidget *added_widget(void) {
   D(("added_widget"));
 /** @brief Create the newly-added list */
 GtkWidget *added_widget(void) {
   D(("added_widget"));
-  return queuelike(&ql_added, 0/*fixup*/, 0/*notify*/, added_menu, "added",
+  register_reset(added_update);
+  return queuelike(&ql_added, 0/*fixup*/, 0/*notify*/, added_menu,
                    addedcolumns, NADDEDCOLUMNS);
 }
 
                    addedcolumns, NADDEDCOLUMNS);
 }