Commit 8aaaa21d authored by Philip Withnall's avatar Philip Withnall Committed by Philip Withnall

Added support for cancelling queries to the YouTube plugin and tidied up

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.


svn path=/trunk/; revision=6245
parent 6d4f32c8
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.
2009-04-05 Philip Withnall <philip@tecnocode.co.uk>
* src/totem-video-list.c (query_tooltip_cb), (show_popup_menu),
......
......@@ -78,6 +78,7 @@ typedef struct {
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 @@ static void impl_deactivate (TotemPlugin *plugin, TotemObject *totem);
/* 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 @@ set_up_tree_view (TotemYouTubePlugin *self, GtkBuilder *builder, guint key)
/* 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 @@ increment_progress_bar_fraction (TotemYouTubePlugin *self, guint tree_view)
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 @@ resolve_t_param_cb (GObject *source_object, GAsyncResult *result, TParamData *da
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 @@ thumbnail_loaded_cb (GObject *source_object, GAsyncResult *result, ThumbnailData
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 @@ query_finished_cb (GObject *source_object, GAsyncResult *result, QueryData *data
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 @@ execute_query (TotemYouTubePlugin *self, guint tree_view, gboolean clear_tree_vi
(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
......@@ -807,6 +845,15 @@ search_button_clicked_cb (GtkButton *button, TotemYouTubePlugin *self)
execute_query (self, SEARCH_TREE_VIEW, TRUE);
}
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)
{
......@@ -833,6 +880,9 @@ notebook_switch_page_cb (GtkNotebook *notebook, GtkNotebookPage *page, guint pag
/* 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 &&
......
......@@ -23,12 +23,24 @@
<property name="border-width">5</property>
<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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment