changeset 2790:c156102069ae

background fetching of streaming info is now indicated in gui
author Calin Crisan ccrisan@gmail.com
date Wed, 09 Jul 2008 22:07:55 +0300
parents b34c4e3d9488
children f9c6a9cb442e
files src/streambrowser/gui/streambrowser_win.c src/streambrowser/gui/streambrowser_win.h src/streambrowser/streambrowser.c
diffstat 3 files changed, 53 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/streambrowser/gui/streambrowser_win.c	Wed Jul 09 16:18:55 2008 +0200
+++ b/src/streambrowser/gui/streambrowser_win.c	Wed Jul 09 22:07:55 2008 +0300
@@ -32,6 +32,7 @@
 static streamdir_gui_t*		find_streamdir_gui_by_name(gchar *name);
 static streamdir_gui_t*		find_streamdir_gui_by_tree_view(GtkTreeView *tree_view);
 static streamdir_gui_t*		find_streamdir_gui_by_table(GtkTable *table);
+static streamdir_gui_t*		find_streamdir_gui_by_streamdir(streamdir_t *streamdir);
 static gboolean			tree_view_search_equal_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer data);
 
 
@@ -85,7 +86,6 @@
 
 	/* others */
 	cell_renderer_pixbuf = gtk_cell_renderer_pixbuf_new();
-	g_object_set(G_OBJECT(cell_renderer_pixbuf), "stock-id", "gtk-directory", NULL);
 	cell_renderer_text = gtk_cell_renderer_text_new();
 }
 
@@ -147,7 +147,7 @@
 		category = category_get_by_index(streamdir, i);
 
 		gtk_tree_store_append(store, &iter, NULL);
-		gtk_tree_store_set(store, &iter, 0, NULL, 1, category->name, 2, "", -1);
+		gtk_tree_store_set(store, &iter, 0, "gtk-directory", 1, category->name, 2, "", -1);
 	}
 }
 
@@ -183,7 +183,7 @@
 		streaminfo = streaminfo_get_by_index(category, i);
 
 		gtk_tree_store_append(store, &new_iter, &iter);
-		gtk_tree_store_set(store, &new_iter, 0, NULL, 1, streaminfo->name, 2, streaminfo->current_track, -1);
+		gtk_tree_store_set(store, &new_iter, 0, "gtk-directory", 1, streaminfo->name, 2, streaminfo->current_track, -1);
 	}
 }
 
@@ -192,6 +192,29 @@
 	update_function = function;
 }
 
+void streambrowser_win_set_category_state(streamdir_t *streamdir, category_t *category, gboolean fetching)
+{
+	streamdir_gui_t *streamdir_gui = find_streamdir_gui_by_streamdir(streamdir);
+	GtkTreeView *tree_view = GTK_TREE_VIEW(streamdir_gui->tree_view);
+	GtkTreeStore *store = GTK_TREE_STORE(gtk_tree_view_get_model(tree_view));
+	GtkTreePath *path;
+	GtkTreeIter iter;
+	
+	/* find the corresponding category tree iter */
+	path = gtk_tree_path_new_from_indices(category_get_index(streamdir, category), -1);
+	if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path))
+		return;
+	
+	if (fetching) {
+		gchar temp[DEF_STRING_LEN];
+		sprintf(temp, "<span style='italic' weight='heavy'>%s</span>", category->name);
+		gtk_tree_store_set(store, &iter, 0, "gtk-refresh", 1, temp, 2, "", -1);
+	}
+	else {
+		gtk_tree_store_set(store, &iter, 0, "gtk-directory", 1, category->name, 2, "", -1);
+	}
+}
+
 static GtkWidget* gtk_label_new_with_icon(gchar *icon_filename, gchar *label_text)
 {
 	GtkWidget *hbox = gtk_hbox_new(FALSE, 1);
@@ -208,7 +231,7 @@
 {
 	GtkWidget *tree_view = gtk_tree_view_new();
 
-	GtkTreeStore *store = gtk_tree_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
+	GtkTreeStore *store = gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 	gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), GTK_TREE_MODEL(store));
 
 	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), TRUE);
@@ -218,13 +241,13 @@
 
 	GtkTreeViewColumn *column = gtk_tree_view_column_new();
 	gtk_tree_view_column_pack_start(column, cell_renderer_pixbuf, TRUE);
-	gtk_tree_view_column_add_attribute(column, cell_renderer_pixbuf, "pixbuf", 0);
+	gtk_tree_view_column_add_attribute(column, cell_renderer_pixbuf, "stock-id", 0);
 	gtk_tree_view_column_set_resizable(column, TRUE);
 	gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
 	
 	column = gtk_tree_view_column_new();
 	gtk_tree_view_column_pack_start(column, cell_renderer_text, TRUE);
-	gtk_tree_view_column_add_attribute(column, cell_renderer_text, "text", 1);
+	gtk_tree_view_column_add_attribute(column, cell_renderer_text, "markup", 1);
 	gtk_tree_view_column_set_resizable(column, TRUE);
 	gtk_tree_view_column_set_title(column, _("Stream name"));
 	gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
@@ -438,6 +461,21 @@
 	return NULL;
 }
 
+static streamdir_gui_t* find_streamdir_gui_by_streamdir(streamdir_t *streamdir)
+{
+	GList *iterator;
+	streamdir_gui_t *streamdir_gui;
+
+	for (iterator = g_list_first(streamdir_gui_list); iterator != NULL; iterator = g_list_next(iterator)) {
+		streamdir_gui = iterator->data;
+
+		if ((void *) streamdir_gui->streamdir == (void *) streamdir)
+			return streamdir_gui;
+	}
+	
+	return NULL;
+}
+
 static gboolean tree_view_search_equal_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer data)
 {
 	GValue value = {0, };
--- a/src/streambrowser/gui/streambrowser_win.h	Wed Jul 09 16:18:55 2008 +0200
+++ b/src/streambrowser/gui/streambrowser_win.h	Wed Jul 09 22:07:55 2008 +0300
@@ -13,6 +13,7 @@
 void			streambrowser_win_set_streamdir(streamdir_t *streamdir, gchar *icon_filename);
 void			streambrowser_win_set_category(streamdir_t *streamdir, category_t *category);
 void			streambrowser_win_set_update_function(void (* update_function) (streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo));
+void			streambrowser_win_set_category_state(streamdir_t *streamdir, category_t *category, gboolean fetching);
 
 
 #endif	// STREAMBROWSER_WIN_H
--- a/src/streambrowser/streambrowser.c	Wed Jul 09 16:18:55 2008 +0200
+++ b/src/streambrowser/streambrowser.c	Wed Jul 09 22:07:55 2008 +0300
@@ -154,13 +154,13 @@
 static void gui_init()
 {
     /* the plugin services menu */
-    playlist_menu_item = gtk_image_menu_item_new_with_label("Streambrowser");
+    playlist_menu_item = gtk_image_menu_item_new_with_label(_("Streambrowser"));
     gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(playlist_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU));
     gtk_widget_show(playlist_menu_item);
     g_signal_connect(G_OBJECT(playlist_menu_item), "activate", G_CALLBACK(on_plugin_services_menu_item_click), NULL);
     audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST_RCLICK, playlist_menu_item);
 
-    main_menu_item = gtk_image_menu_item_new_with_label("Streambrowser");
+    main_menu_item = gtk_image_menu_item_new_with_label(_("Streambrowser"));
     gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(main_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU));
     gtk_widget_show(main_menu_item);
     g_signal_connect(G_OBJECT(main_menu_item), "activate", G_CALLBACK(on_plugin_services_menu_item_click), NULL);
@@ -304,10 +304,15 @@
     else if (data->category != NULL) {
         /* shoutcast */
         if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) {
+        	gdk_threads_enter();
+			streambrowser_win_set_category_state(data->streamdir, data->category, TRUE);
+        	gdk_threads_leave();
+        	
             shoutcast_category_fetch(data->category);
 
             gdk_threads_enter();
             streambrowser_win_set_category(data->streamdir, data->category);
+			streambrowser_win_set_category_state(data->streamdir, data->category, FALSE);
             gdk_threads_leave();
         }
     }
@@ -336,7 +341,7 @@
 
     g_free(data);
 
-    /* check to see if there are pending update requests */
+    /* check to see if there are queued update requests */
 
     data = NULL;
     g_mutex_lock(update_thread_mutex);