chiark / gitweb /
Don't playlist_list_update when playlist-modified
authorRichard Kettlewell <rjk@greenend.org.uk>
Mon, 23 Nov 2009 14:56:19 +0000 (14:56 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Mon, 23 Nov 2009 14:56:19 +0000 (14:56 +0000)
disobedience/disobedience.h
disobedience/menu.c
disobedience/playlists.c

index 95ab02f..e8b2d02 100644 (file)
@@ -257,9 +257,9 @@ void popup_settings(void);
 
 #if PLAYLISTS
 void playlists_init(void);
-void edit_playlists(gpointer callback_data,
-                    guint callback_action,
-                    GtkWidget  *menu_item);
+void playlist_window_create(gpointer callback_data,
+                            guint callback_action,
+                            GtkWidget  *menu_item);
 extern char **playlists;
 extern int nplaylists;
 extern GtkWidget *menu_playlists_widget;
index f0db1c2..6a265ba 100644 (file)
@@ -302,7 +302,7 @@ GtkWidget *menubar(GtkWidget *w) {
     {
       (char *)"/Edit/Edit playlists",   /* path */
       0,                                /* accelerator */
-      edit_playlists,                   /* callback */
+      playlist_window_create,           /* callback */
       0,                                /* callback_action */
       0,                                /* item_type */
       0                                 /* extra_data */
index 05de973..f6659db 100644 (file)
@@ -638,13 +638,21 @@ static GtkWidget *playlist_picker_create(void) {
 /* Playlist editor ---------------------------------------------------------- */
 
 /** @brief Called with new tracks for the playlist */
-static void playlists_editor_received_tracks(void attribute((unused)) *v,
+static void playlists_editor_received_tracks(void *v,
                                              const char *err,
                                              int nvec, char **vec) {
+  const char *playlist = v;
   if(err) {
     popup_protocol_error(0, err);
     return;
   }
+  if(!playlist_picker_selected
+     || strcmp(playlist, playlist_picker_selected)) {
+    /* The tracks are for the wrong playlist - something must have changed
+     * while the fetch command was in flight.  We just ignore this callback,
+     * the right answer will be requested and arrive in due course. */
+    return;
+  }
   if(nvec == -1)
     /* No such playlist, presumably we'll get a deleted event shortly */
     return;
@@ -660,7 +668,6 @@ static void playlists_editor_received_tracks(void attribute((unused)) *v,
     /* TODO but this doesn't work for some reason */
     int *serialp = hash_find(h, vec[n]), serial = serialp ? *serialp : 0;
     byte_xasprintf((char **)&q->id, "%d-%s", serial++, vec[n]);
-    fprintf(stderr, "%s\n", q->id);
     hash_add(h, vec[0], &serial, HASH_INSERT_OR_REPLACE);
     *qq = q;
     qq = &q->next;
@@ -680,7 +687,8 @@ static void playlist_editor_fill(const char attribute((unused)) *event,
     return;
   if(!strcmp(playlist_picker_selected, modified_playlist))
     disorder_eclient_playlist_get(client, playlists_editor_received_tracks,
-                                  playlist_picker_selected, NULL);
+                                  playlist_picker_selected,
+                                  (void *)playlist_picker_selected);
 }
 
 static GtkWidget *playlists_editor_create(void) {
@@ -718,9 +726,9 @@ static void playlist_window_destroyed(GtkWidget attribute((unused)) *widget,
  *
  * Called when the playlists menu item is selected
  */
-void edit_playlists(gpointer attribute((unused)) callback_data,
-                    guint attribute((unused)) callback_action,
-                    GtkWidget attribute((unused)) *menu_item) {
+void playlist_window_create(gpointer attribute((unused)) callback_data,
+                            guint attribute((unused)) callback_action,
+                            GtkWidget attribute((unused)) *menu_item) {
   /* If the window already exists, raise it */
   if(playlist_window) {
     gtk_window_present(GTK_WINDOW(playlist_window));
@@ -756,7 +764,6 @@ void edit_playlists(gpointer attribute((unused)) callback_data,
 void playlists_init(void) {
   /* We re-get all playlists upon any change... */
   event_register("playlist-created", playlist_list_update, 0);
-  event_register("playlist-modified", playlist_list_update, 0); /* TODO why? */
   event_register("playlist-deleted", playlist_list_update, 0);
   /* ...and on reconnection */
   event_register("log-connected", playlist_list_update, 0);