totem r5990 - in trunk: . src/plugins/screenshot



Author: hadess
Date: Tue Feb 17 11:08:06 2009
New Revision: 5990
URL: http://svn.gnome.org/viewvc/totem?rev=5990&view=rev

Log:
2009-02-17  Bastien Nocera  <hadess hadess net>

	* src/plugins/screenshot/totem-gallery-progress.c
	(totem_gallery_progress_finalize), (totem_gallery_progress_new),
	(dialog_response_callback), (stdout_watch_cb),
	(totem_gallery_progress_run):
	* src/plugins/screenshot/totem-gallery.c
	(dialog_response_callback):
	* src/plugins/screenshot/totem-screenshot-plugin.c
	(take_gallery_response_cb), (take_gallery_action_cb): Avoid
	using gtk_dialog_run() inside a gtk_dialog_run() call, fixes
	the gallery plugin (Closes: #561088)



Modified:
   trunk/ChangeLog
   trunk/src/plugins/screenshot/totem-gallery-progress.c
   trunk/src/plugins/screenshot/totem-gallery.c
   trunk/src/plugins/screenshot/totem-screenshot-plugin.c

Modified: trunk/src/plugins/screenshot/totem-gallery-progress.c
==============================================================================
--- trunk/src/plugins/screenshot/totem-gallery-progress.c	(original)
+++ trunk/src/plugins/screenshot/totem-gallery-progress.c	Tue Feb 17 11:08:06 2009
@@ -29,6 +29,7 @@
 
 #include <signal.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
@@ -43,7 +44,6 @@
 	GPid child_pid;
 	GString *line;
 	gchar *output_filename;
-	GMainLoop *loop;
 
 	GtkProgressBar *progress_bar;
 };
@@ -77,8 +77,6 @@
 
 	if (priv->line != NULL)
 		g_string_free (priv->line, TRUE);
-	if (priv->loop != NULL)
-		g_main_loop_unref (priv->loop);
 
 	/* Chain up to the parent class */
 	G_OBJECT_CLASS (totem_gallery_progress_parent_class)->finalize (object);
@@ -118,21 +116,21 @@
 	container = gtk_dialog_get_content_area (GTK_DIALOG (self));
 	gtk_box_pack_start (GTK_BOX (container), GTK_WIDGET (self->priv->progress_bar), TRUE, TRUE, 5);
 
+	gtk_widget_show_all (container);
+
 	return self;
 }
 
 static void
 dialog_response_callback (GtkDialog *dialog, gint response_id, TotemGalleryProgress *self)
 {
-	/* Cancel the operation by killing the process */
-	kill (self->priv->child_pid, SIGINT);
-
-	/* Unlink the output file, just in case (race condition) it's already been created */
-	g_unlink (self->priv->output_filename);
+	if (response_id != GTK_RESPONSE_OK) {
+		/* Cancel the operation by killing the process */
+		kill (self->priv->child_pid, SIGINT);
 
-	/* Quit the main loop */
-	if (self->priv->loop != NULL && g_main_loop_is_running (self->priv->loop))
-		g_main_loop_quit (self->priv->loop);
+		/* Unlink the output file, just in case (race condition) it's already been created */
+		g_unlink (self->priv->output_filename);
+	}
 }
 
 static gboolean
@@ -157,7 +155,7 @@
 	TotemGalleryProgressPrivate *priv = self->priv;
 	gboolean retval = TRUE;
 
-	if (condition & G_IO_IN || condition & G_IO_PRI) {
+	if (condition & G_IO_IN) {
 		gchar *line;
 		gchar buf[1];
 		GIOStatus status;
@@ -210,9 +208,8 @@
 	}
 
 	if (retval == FALSE) {
-		/* Exit the main loop; we're done processing input */
-		if (self->priv->loop != NULL && g_main_loop_is_running (self->priv->loop))
-			g_main_loop_quit (self->priv->loop);
+		/* We're done processing input, we now have an answer */
+		gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
 	}
 
 	return retval;
@@ -221,25 +218,16 @@
 void
 totem_gallery_progress_run (TotemGalleryProgress *self, gint stdout_fd)
 {
-	TotemGalleryProgressPrivate *priv = self->priv;
 	GIOChannel *channel;
-	guint stdout_watch_id;
+
+	fcntl (stdout_fd, F_SETFL, O_NONBLOCK);
 
 	/* Watch the output from totem-video-thumbnailer */
 	channel = g_io_channel_unix_new (stdout_fd);
 	g_io_channel_set_flags (channel, g_io_channel_get_flags (channel) | G_IO_FLAG_NONBLOCK, NULL);
-	g_io_channel_set_encoding (channel, NULL, NULL);
-	g_io_channel_set_buffered (channel, FALSE);
 
-	stdout_watch_id = g_io_add_watch (channel, G_IO_IN | G_IO_PRI | G_IO_HUP | G_IO_ERR | G_IO_NVAL, (GIOFunc) stdout_watch_cb, self);
+	g_io_add_watch (channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, (GIOFunc) stdout_watch_cb, self);
 
 	g_io_channel_unref (channel);
-
-	/* Listen in a recursive main loop so this function is synchronous */
-	priv->loop = g_main_loop_new (NULL, FALSE);
-	g_main_loop_run (priv->loop);
-
-	g_source_remove (stdout_watch_id);
-	g_main_loop_unref (priv->loop);
-	priv->loop = NULL;
 }
+

Modified: trunk/src/plugins/screenshot/totem-gallery.c
==============================================================================
--- trunk/src/plugins/screenshot/totem-gallery.c	(original)
+++ trunk/src/plugins/screenshot/totem-gallery.c	Tue Feb 17 11:08:06 2009
@@ -127,12 +127,16 @@
 	gint stdout_fd;
 	GPid child_pid;
 	GtkWidget *progress_dialog;
+	gboolean ret;
 	GError *error = NULL;
 
 	if (response_id != GTK_RESPONSE_OK)
 		return;
 	gtk_widget_hide (GTK_WIDGET (dialog));
 
+	/* Don't call in here again */
+	g_signal_handlers_disconnect_by_func (G_OBJECT (self), dialog_response_callback, self);
+
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->default_screenshot_count)) == TRUE)
 		screenshot_count = 0;
 	else
@@ -154,21 +158,26 @@
 	argv[8] = NULL;
 
 	/* Run the command */
-	if (g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
-				      &child_pid, NULL, &stdout_fd, NULL, &error) == FALSE) {
+	ret = g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
+					&child_pid, NULL, &stdout_fd, NULL, &error);
+
+	/* Free argv, minus the filename */
+	for (i = 4; i < G_N_ELEMENTS (argv) - 2; i++)
+		g_free (argv[i]);
+
+	if (ret == FALSE) {
 		g_warning ("Error spawning totem-video-thumbnailer: %s", error->message);
 		g_error_free (error);
-		goto error;
+		return;
 	}
 
 	/* Create the progress dialogue */
 	progress_dialog = GTK_WIDGET (totem_gallery_progress_new (child_pid, filename));
-	gtk_widget_show_all (progress_dialog);
+	g_free (filename);
 	totem_gallery_progress_run (TOTEM_GALLERY_PROGRESS (progress_dialog), stdout_fd);
+	gtk_dialog_run (GTK_DIALOG (progress_dialog));
 	gtk_widget_destroy (progress_dialog);
 
-error:
-	/* Free argv */
-	for (i = 4; i < G_N_ELEMENTS (argv); i++)
-		g_free (argv[i]);
+	gtk_dialog_response (GTK_DIALOG (self), 0);
 }
+

Modified: trunk/src/plugins/screenshot/totem-screenshot-plugin.c
==============================================================================
--- trunk/src/plugins/screenshot/totem-screenshot-plugin.c	(original)
+++ trunk/src/plugins/screenshot/totem-screenshot-plugin.c	Tue Feb 17 11:08:06 2009
@@ -114,6 +114,15 @@
 }
 
 static void
+take_gallery_response_cb (GtkDialog *dialog,
+			  int response_id,
+			  TotemScreenshotPlugin *self)
+{
+	if (response_id != GTK_RESPONSE_OK)
+		gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static void
 take_gallery_action_cb (GtkAction *action, TotemScreenshotPlugin *self)
 {
 	Totem *totem = self->priv->totem;
@@ -124,9 +133,9 @@
 
 	dialog = GTK_DIALOG (totem_gallery_new (totem, TOTEM_PLUGIN (self)));
 
+	g_signal_connect (dialog, "response",
+			  G_CALLBACK (take_gallery_response_cb), self);
 	gtk_widget_show (GTK_WIDGET (dialog));
-	gtk_dialog_run (dialog);
-	gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
 static gboolean



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