totem r6245 - in trunk: . src/plugins/youtube



Author: pwithnall
Date: Sun Apr  5 12:28:36 2009
New Revision: 6245
URL: http://svn.gnome.org/viewvc/totem?rev=6245&view=rev

Log:
2009-04-05  Philip Withnall  <philip tecnocode co uk>

	* src/plugins/youtube/totem-youtube.c (set_up_tree_view),
	(increment_progress_bar_fraction), (resolve_t_param_cb),
	(thumbnail_loaded_cb), (query_finished_cb), (execute_query),
	(cancel_button_clicked_cb), (notebook_switch_page_cb):
	* src/plugins/youtube/youtube.ui: Added support for cancelling queries
	to the YouTube plugin and tidied up the UI a little.



Modified:
   trunk/ChangeLog
   trunk/src/plugins/youtube/totem-youtube.c
   trunk/src/plugins/youtube/youtube.ui

Modified: trunk/src/plugins/youtube/totem-youtube.c
==============================================================================
--- trunk/src/plugins/youtube/totem-youtube.c	(original)
+++ trunk/src/plugins/youtube/totem-youtube.c	Sun Apr  5 12:28:36 2009
@@ -78,6 +78,7 @@
 	GtkAdjustment *vadjust[NUM_TREE_VIEWS];
 	GtkListStore *list_store[NUM_TREE_VIEWS];
 	GtkTreeView *tree_view[NUM_TREE_VIEWS];
+	GtkWidget *cancel_button;
 } TotemYouTubePlugin;
 
 typedef struct {
@@ -93,6 +94,7 @@
 /* GtkBuilder callbacks */
 void notebook_switch_page_cb (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, TotemYouTubePlugin *self);
 void search_button_clicked_cb (GtkButton *button, TotemYouTubePlugin *self);
+void cancel_button_clicked_cb (GtkButton *button, TotemYouTubePlugin *self);
 void search_entry_activate_cb (GtkEntry *entry, TotemYouTubePlugin *self);
 gboolean button_press_event_cb (GtkWidget *widget, GdkEventButton *event, TotemYouTubePlugin *self);
 gboolean button_release_event_cb (GtkWidget *widget, GdkEventButton *event, TotemYouTubePlugin *self);
@@ -316,6 +318,8 @@
 	/* Connect to more scroll events */
 	self->vadjust[key] = gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (tree_view));
 	g_signal_connect (self->vadjust[key], "value-changed", G_CALLBACK (value_changed_cb), self);
+
+	self->cancel_button = GTK_WIDGET (gtk_builder_get_object (builder, "yt_cancel_button"));
 }
 
 static gboolean
@@ -437,12 +441,24 @@
 	g_debug ("Incrementing progress bar by %f (new value: %f)", self->progress_bar_increment[tree_view], new_value);
 	gtk_progress_bar_set_fraction (self->progress_bar[tree_view], new_value);
 
+	/* Change the text if the operation's been cancelled */
+	if (self->cancellable[tree_view] == NULL || g_cancellable_is_cancelled (self->cancellable[tree_view]) == TRUE)
+		gtk_progress_bar_set_text (self->progress_bar[tree_view], _("Cancelling queryâ"));
+
 	/* Update the UI */
 	if (gtk_progress_bar_get_fraction (self->progress_bar[tree_view]) == 1.0) {
 		/* The entire search process (including loading thumbnails and t params) is finished, so update the progress bar */
 		gdk_window_set_cursor (gtk_widget_get_window (self->vbox), NULL);
 		gtk_progress_bar_set_text (self->progress_bar[tree_view], "");
 		gtk_progress_bar_set_fraction (self->progress_bar[tree_view], 0.0);
+
+		/* Disable the "Cancel" button, if it applies to the current tree view */
+		if (self->current_tree_view == tree_view)
+			gtk_widget_set_sensitive (self->cancel_button, FALSE);
+
+		/* Unref cancellable */
+		g_object_unref (self->cancellable[tree_view]);
+		self->cancellable[tree_view] = NULL;
 	}
 }
 
@@ -467,6 +483,12 @@
 	if (g_file_load_contents_finish (G_FILE (source_object), result, &contents, &length, NULL, &error) == FALSE) {
 		GtkWindow *window;
 
+		/* Bail out if the operation was cancelled */
+		if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) == TRUE) {
+			g_error_free (error);
+			goto free_data;
+		}
+
 		/* Couldn't load the page contents; error */
 		window = totem_get_main_window (data->plugin->totem);
 		totem_interface_error (_("Error Looking Up Video URI"), error->message, window);
@@ -568,6 +590,12 @@
 	if (thumbnail == NULL) {
 		GtkWindow *window;
 
+		/* Bail out if the operation was cancelled */
+		if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) == TRUE) {
+			g_error_free (error);
+			goto free_data;
+		}
+
 		/* Display an error message */
 		window = totem_get_main_window (data->plugin->totem);
 		totem_interface_error (_("Error Loading Video Thumbnail"), error->message, window);
@@ -635,14 +663,20 @@
 
 	g_debug ("Search finished!");
 
-	/* Unref cancellable */
-	g_object_unref (self->cancellable[data->tree_view]);
-	self->cancellable[data->tree_view] = NULL;
-
 	feed = gdata_service_query_finish (GDATA_SERVICE (self->service), result, &error);
 	if (feed == NULL) {
 		GtkWindow *window;
 
+		/* Stop the progress bar; a little hacky, but it works */
+		self->progress_bar_increment[data->tree_view] = 1.0;
+		increment_progress_bar_fraction (self, data->tree_view);
+
+		/* Bail out if the operation was cancelled */
+		if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) == TRUE) {
+			g_error_free (error);
+			goto free_data;
+		}
+
 		/* Error! */
 		window = totem_get_main_window (data->plugin->totem);
 		totem_interface_error (_("Error Searching for Videos"), error->message, window);
@@ -764,6 +798,10 @@
 							   (GDataQueryProgressCallback) query_progress_cb, data,
 							   (GAsyncReadyCallback) query_finished_cb, data);
 	}
+
+	/* Enable the "Cancel" button if it applies to the current tree view */
+	if (self->current_tree_view == tree_view)
+		gtk_widget_set_sensitive (self->cancel_button, TRUE);
 }
 
 void
@@ -808,6 +846,15 @@
 }
 
 void
+cancel_button_clicked_cb (GtkButton *button, TotemYouTubePlugin *self)
+{
+	g_assert (self->cancellable[self->current_tree_view] != NULL);
+
+	g_debug ("Cancelling search");
+	g_cancellable_cancel (self->cancellable[self->current_tree_view]);
+}
+
+void
 search_entry_activate_cb (GtkEntry *entry, TotemYouTubePlugin *self)
 {
 	search_button_clicked_cb (self->search_button, self);
@@ -833,6 +880,9 @@
 	/* Change the tree view */
 	self->current_tree_view = page_num;
 
+	/* Sort out the "Cancel" button's sensitivity */
+	gtk_widget_set_sensitive (self->cancel_button, (self->cancellable[page_num] != NULL) ? TRUE : FALSE);
+
 	/* If we're changing to the "Related Videos" tree view and have played a video, load
 	 * the related videos for that video; but only if the related tree view's empty first */
 	if (page_num == RELATED_TREE_VIEW && self->playing_video != NULL &&

Modified: trunk/src/plugins/youtube/youtube.ui
==============================================================================
--- trunk/src/plugins/youtube/youtube.ui	(original)
+++ trunk/src/plugins/youtube/youtube.ui	Sun Apr  5 12:28:36 2009
@@ -24,11 +24,23 @@
 	<property name="homogeneous">False</property>
 	<property name="spacing">6</property>
 	<child>
+		<object class="GtkEntry" id="yt_search_entry">
+			<signal name="activate" handler="search_entry_activate_cb"/>
+		</object>
+		<packing>
+			<property name="padding">0</property>
+			<property name="expand">False</property>
+			<property name="fill">True</property>
+		</packing>
+	</child>
+	<child>
 		<object class="GtkHBox" id="yt_hbox">
 			<property name="spacing">4</property>
 			<child>
-				<object class="GtkEntry" id="yt_search_entry">
-					<signal name="activate" handler="search_entry_activate_cb"/>
+				<object class="GtkButton" id="yt_search_button">
+					<property name="use-stock">True</property>
+					<property name="label">gtk-find</property>
+					<signal name="clicked" handler="search_button_clicked_cb"/>
 				</object>
 				<packing>
 					<property name="padding">0</property>
@@ -37,14 +49,15 @@
 				</packing>
 			</child>
 			<child>
-				<object class="GtkButton" id="yt_search_button">
+				<object class="GtkButton" id="yt_cancel_button">
 					<property name="use-stock">True</property>
-					<property name="label">gtk-find</property>
-					<signal name="clicked" handler="search_button_clicked_cb"/>
+					<property name="label">gtk-cancel</property>
+					<property name="sensitive">False</property>
+					<signal name="clicked" handler="cancel_button_clicked_cb"/>
 				</object>
 				<packing>
 					<property name="padding">0</property>
-					<property name="expand">False</property>
+					<property name="expand">True</property>
 					<property name="fill">True</property>
 				</packing>
 			</child>
@@ -60,6 +73,7 @@
 			<signal name="switch-page" handler="notebook_switch_page_cb"/>
 			<child>
 				<object class="GtkVBox" id="yt_vbox_related">
+					<property name="spacing">4</property>
 					<child>
 						<object class="GtkScrolledWindow" id="yt_scrolled_window_search">
 							<property name="hscrollbar-policy">GTK_POLICY_AUTOMATIC</property>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]