changeset 3920:c2b2828186ba

- serial number has been added to playlist structure so that changes of the current playlist can be notified. - now jumptotrack always synchronizes to the current plalylist. - jumptotrack remembers the filter string while the current playlist is identical. - refresh button in jumptotrack deletes filter string.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Fri, 09 Nov 2007 19:39:27 +0900
parents 11145cc182f1
children 35a26116f6bd
files src/audacious/playlist.c src/audacious/playlist.h src/audacious/ui_jumptotrack.c
diffstat 3 files changed, 73 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playlist.c	Thu Nov 08 18:33:14 2007 +0100
+++ b/src/audacious/playlist.c	Fri Nov 09 19:39:27 2007 +0900
@@ -451,6 +451,7 @@
     playlist->entries = NULL;
     playlist->tail = NULL;
     playlist->attribute = PLAYLIST_PLAIN;
+    playlist->serial = 0;
 
     PLAYLIST_UNLOCK(playlist);
 }
@@ -985,7 +986,6 @@
 {
     guint entries;
     entries = playlist_ins_url(playlist, url, -1);
-//    printf("playlist_add_url: entries = %d\n", entries);
     return entries;
 }
 
@@ -1038,8 +1038,6 @@
     g_return_val_if_fail(playlist != NULL, 0);
     g_return_val_if_fail(string != NULL, 0);
 
-//    playlistwin_update_list(playlist); // is this necessary? --yaz
-
     while (*string) {
         GList *node;
         guint i = 0;
@@ -1115,7 +1113,7 @@
         }
     }
 
-    playlist_recalc_total_time(playlist);
+//    playlist_recalc_total_time(playlist); //annoying --yaz
 
     /* broadcast a PlaylistEventInfoChange message. */
     msg = g_new0(PlaylistEventInfoChange, 1);
@@ -1714,7 +1712,6 @@
 		pr = input_check_file(filename, FALSE);
 
             __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL);
-
             g_free(pr);
             return;
         }
@@ -1741,7 +1738,6 @@
 	    pr = input_check_file(filename, FALSE);
 
         __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL);
-
         g_free(pr);
     }
 
@@ -1782,7 +1778,6 @@
 	        pr = input_check_file(filename, FALSE);
 
             __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL);
-
             g_free(pr);
             return;
         }
@@ -1849,7 +1844,6 @@
     playlist_generate_shuffle_list(playlist);
     playlistwin_update_list(playlist);
     playlist_manager_update();
-
     return new_len - old_len;
 }
 
@@ -2960,6 +2954,7 @@
                 playlist->pl_selection_more = TRUE;
         }
     }
+    playlist->serial++;
 }
 
 static void
@@ -3157,7 +3152,7 @@
     }
 
     PLAYLIST_UNLOCK(playlist);
-    playlist_recalc_total_time(playlist);
+//    playlist_recalc_total_time(playlist); //annoying --yaz
 }
 
 void
@@ -3191,7 +3186,7 @@
     }
 
     PLAYLIST_UNLOCK(playlist);
-    playlist_recalc_total_time(playlist);
+//    playlist_recalc_total_time(playlist); //annoying --yaz
 
     return invert_ok;
 }
@@ -3315,6 +3310,9 @@
     playlist->title = NULL;
     playlist->filename = NULL;
     playlist_clear(playlist);
+    playlist->tail = NULL;
+    playlist->attribute = PLAYLIST_PLAIN;
+    playlist->serial = 0;
 
     return playlist;
 }
@@ -3327,6 +3325,7 @@
     
     g_mutex_free( playlist->mutex );
     g_free( playlist );
+    playlist = NULL; //XXX lead to crash? --yaz
 }
 
 Playlist *
--- a/src/audacious/playlist.h	Thu Nov 08 18:33:14 2007 +0100
+++ b/src/audacious/playlist.h	Fri Nov 09 19:39:27 2007 +0900
@@ -94,8 +94,9 @@
     gboolean       pl_selection_more;
     gboolean       loading_playlist;
     GMutex        *mutex;       /* this is required for multiple playlist */
-    GList *tail; /* marker for the last element in playlist->entries */
+    GList         *tail; /* marker for the last element in playlist->entries */
     gint           attribute; /* PlaylistAttribute */
+    gulong         serial;     /* serial number */
 };
 
 typedef enum {
--- a/src/audacious/ui_jumptotrack.c	Thu Nov 08 18:33:14 2007 +0100
+++ b/src/audacious/ui_jumptotrack.c	Fri Nov 09 19:39:27 2007 +0900
@@ -80,6 +80,7 @@
 #include "ui_skinned_window.h"
 
 static GtkWidget *jump_to_track_win = NULL;
+static gulong serial = 0;
 
 static void
 change_song(guint pos)
@@ -91,6 +92,13 @@
     playback_initiate();
 }
 
+void
+ui_jump_to_track_hide(void)
+{
+    g_return_if_fail(jump_to_track_win);
+    gtk_widget_hide(jump_to_track_win);
+}
+
 static void
 ui_jump_to_track_jump(GtkTreeView * treeview)
 {
@@ -109,18 +117,8 @@
 
     change_song(pos - 1);
 
-    /* FIXME: should only hide window */
-    if(cfg.close_jtf_dialog){
-        gtk_widget_destroy(jump_to_track_win);
-        jump_to_track_win = NULL;
-    }
-}
-
-void
-ui_jump_to_track_hide(void)
-{
-    g_return_if_fail(jump_to_track_win);
-    gtk_widget_hide(jump_to_track_win);
+    if(cfg.close_jtf_dialog)
+        ui_jump_to_track_hide();
 }
 
 static void
@@ -219,9 +217,7 @@
 {
     switch (event->keyval) {
     case GDK_Escape:
-        /* FIXME: show only hide window */
-        gtk_widget_destroy(jump_to_track_win);
-        jump_to_track_win = NULL;
+        ui_jump_to_track_hide();
         return TRUE;
     case GDK_KP_Enter:
         ui_jump_to_track_queue_cb(NULL, data);
@@ -254,12 +250,9 @@
     return rv;
 }
 
-/* FIXME: Clear the entry when the list gets updated */
 void
 ui_jump_to_track_update(GtkWidget * widget, gpointer user_data)
 {
-    /* FIXME: Is not in sync with playlist due to delayed extinfo
-     * reading */
     guint row;
     GList *playlist_glist;
     gchar *desc_buf = NULL;
@@ -269,10 +262,18 @@
 
     GtkTreeModel *store;
 
+    GtkTreeView *tree = GTK_TREE_VIEW(g_object_get_data(user_data, "treeview"));
+    GtkEntry *edit = g_object_get_data(user_data, "edit");
+
     if (!jump_to_track_win)
         return;
 
-    store = gtk_tree_view_get_model(GTK_TREE_VIEW(user_data));
+    /* clear edit widget */
+    if(edit){
+        gtk_entry_set_text(edit, "\0");
+    }
+
+    store = gtk_tree_view_get_model(tree);
     gtk_list_store_clear(GTK_LIST_STORE(store));
 
     row = 1;
@@ -303,8 +304,9 @@
     }
 
     gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
-    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(user_data));
+    selection = gtk_tree_view_get_selection(tree);
     gtk_tree_selection_select_iter(selection, &iter);
+    serial = playlist->serial; // important. --yaz
 }
 
 static void
@@ -450,11 +452,9 @@
     gtk_list_store_clear(jtf_store);
 
     row = 1;
-
     playlist = playlist_get_active();
 
     PLAYLIST_LOCK(playlist);
-
     for (playlist_glist = playlist->entries; playlist_glist;
          playlist_glist = g_list_next(playlist_glist)) {
 
@@ -477,36 +477,50 @@
                            0, row, 1, desc_buf, -1);
         row++;
 
-        if (desc_buf) {
-            g_free(desc_buf);
-            desc_buf = NULL;
-        }
+        g_free(desc_buf);
+        desc_buf = NULL;
     }
-
     PLAYLIST_UNLOCK(playlist);
 
     /* attach liststore to treeview */
     gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(jtf_store));
     g_object_unref(jtf_store);
+    serial = playlist->serial;
     return FALSE;
 }
 
+static gboolean
+watchdog(gpointer storage)
+{
+    GtkWidget *widget;
+    Playlist *playlist = playlist_get_active();
+
+    if(serial == playlist->serial)
+        return TRUE;
+
+    widget = g_object_get_data(storage, "widget");
+    ui_jump_to_track_update(widget, storage);
+    return TRUE;
+}
+
 void
 ui_jump_to_track(void)
 {
     GtkWidget *scrollwin;
     GtkWidget *vbox, *bbox, *sep;
     GtkWidget *toggle;
-    GtkWidget *jump, *queue, *cancel;
+    GtkWidget *jump, *queue, *close;
     GtkWidget *rescan, *edit;
     GtkWidget *search_label, *hbox;
 
-    GtkWidget *treeview;
+    GtkWidget *treeview = NULL;
     GtkListStore *jtf_store;
 
     GtkCellRenderer *renderer;
     GtkTreeViewColumn *column;
 
+    gpointer storage;
+
     if (jump_to_track_win) {
         gtk_window_present(GTK_WINDOW(jump_to_track_win));
         return;
@@ -619,8 +633,16 @@
 
     rescan = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
     gtk_box_pack_start(GTK_BOX(bbox), rescan, FALSE, FALSE, 0);
+
+    /* pack to container */
+    storage = g_object_new(G_TYPE_OBJECT, NULL);
+    g_object_set_data(storage, "widget", rescan);
+    g_object_set_data(storage, "treeview", treeview);
+    g_object_set_data(storage, "edit", edit);
+
     g_signal_connect(rescan, "clicked",
-                     G_CALLBACK(ui_jump_to_track_update), treeview);
+                     G_CALLBACK(ui_jump_to_track_update), storage);
+
     GTK_WIDGET_SET_FLAGS(rescan, GTK_CAN_DEFAULT);
     gtk_widget_grab_default(rescan);
 
@@ -634,14 +656,18 @@
     GTK_WIDGET_SET_FLAGS(jump, GTK_CAN_DEFAULT);
     gtk_widget_grab_default(jump);
 
-    cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
-    gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0);
-    g_signal_connect_swapped(cancel, "clicked",
-                             G_CALLBACK(gtk_widget_destroy),
-                             jump_to_track_win);
-    GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT);
+    close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
+    gtk_box_pack_start(GTK_BOX(bbox), close, FALSE, FALSE, 0);
+/*     g_signal_connect_swapped(close, "clicked", */
+/*                              G_CALLBACK(gtk_widget_destroy), */
+/*                              jump_to_track_win); */
+    g_signal_connect_swapped(close, "clicked",
+                             G_CALLBACK(gtk_widget_hide),
+                             jump_to_track_win); // just hide --yaz
+    GTK_WIDGET_SET_FLAGS(close, GTK_CAN_DEFAULT);
 
     g_timeout_add(100, (GSourceFunc)ui_jump_to_track_fill, treeview);
+    g_timeout_add(500, (GSourceFunc)watchdog, storage);
 
     gtk_widget_show_all(jump_to_track_win);
     gtk_widget_grab_focus(edit);