[Cxplorer-cvs 01257] CVS update: cxplorer/src

Back to archive index

Yasumichi Akahoshi yasum****@users*****
2005年 9月 6日 (火) 23:17:49 JST


Index: cxplorer/src/cxp-right-pane.c
diff -u cxplorer/src/cxp-right-pane.c:1.62 cxplorer/src/cxp-right-pane.c:1.63
--- cxplorer/src/cxp-right-pane.c:1.62	Tue Sep  6 21:45:10 2005
+++ cxplorer/src/cxp-right-pane.c	Tue Sep  6 23:17:49 2005
@@ -109,6 +109,9 @@
 static void cxp_right_pane_show_preview (CxpRightPane * self,
 					 GtkTextBuffer * text_buffer,
 					 const gchar * filename);
+static void cxp_right_pane_preview_by_command (CxpRightPane * self,
+					 GtkTextBuffer * text_buffer,
+					 const gchar *command);
 static gint cxp_right_pane_popup_handler (GtkWidget * widget, GdkEvent * event);
 static void cxp_right_pane_preview_expanded (GObject * object,
 					     GParamSpec * param_spec,
@@ -723,9 +726,7 @@
 					       CxpFileListStore * store,
 					       const gchar * fullpath)
 {
-	CxpRightPanePrivate *priv = CXP_RIGHT_PANE_GET_PRIVATE (self);
 	GtkTreeIter iter;
-	struct stat status;
 
 	cxp_file_list_store_append_file (store, fullpath, &iter);
 
@@ -748,11 +749,9 @@
 	gchar *cmd = NULL;
 	gchar *filetype;
 	gchar *key;
-	gchar *standard_output;
-	gchar *stdout_utf8;
-	gint exit_status;
 	struct stat status;
 
+	gtk_text_buffer_set_text (text_buffer, "", -1);	/* clear text buffer */
 	stat (filename, &status);
 	switch (status.st_mode & S_IFMT)
 	{
@@ -760,10 +759,8 @@
 			filetype = cxp_get_mime_type_for_file (filename);
 			if (strstr (filetype, "image") != NULL)
 			{
-				if ((pixbuf =
-							gdk_pixbuf_new_from_file (filename, NULL)) != NULL)
+				if ((pixbuf = gdk_pixbuf_new_from_file (filename, NULL)) != NULL)
 				{
-					gtk_text_buffer_set_text (text_buffer, "", -1);
 					gtk_text_buffer_get_iter_at_line (text_buffer,
 							&iter, 0);
 					gtk_text_buffer_insert_pixbuf (text_buffer,
@@ -810,23 +807,51 @@
 	}
 
 	cmd = g_strdup_printf ("%s '%s'", preview_cmd, filename);
-	g_spawn_command_line_sync (cmd, &standard_output, NULL,
-				   &exit_status, NULL);
+	cxp_right_pane_preview_by_command (self, text_buffer, cmd);
 	g_free (preview_cmd);
 	g_free (cmd);
+}
+
+
+static void cxp_right_pane_preview_by_command (CxpRightPane * self,
+					 GtkTextBuffer * text_buffer,
+					 const gchar *command)
+{
+	const gchar *encoding;
+	gchar **args;
+	gint sout;
+	gint loop;
+	gint max = 100;	/* FIXME: get from gconf */
+	GPid pid;
+	GIOChannel *channel;
+	GString *str;
+	GError *error;
+
+	g_shell_parse_argv (command, NULL, &args, NULL);
 
-	if (exit_status == 0)
+	if(g_spawn_async_with_pipes (NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, NULL, &sout, NULL, &error))
 	{
-		stdout_utf8 =
-			g_locale_to_utf8 (standard_output, -1, NULL,
-					  NULL, NULL);
-		g_free (standard_output);
-		if (stdout_utf8 != NULL)
+		channel = g_io_channel_unix_new (sout);
+		if(g_get_charset(&encoding) == FALSE)
+		{
+			g_io_channel_set_encoding (channel, encoding, NULL);
+		}
+		str = g_string_new ("");
+		for (loop=0; (loop<max) && (g_io_channel_read_line_string (channel, str, NULL, NULL) == G_IO_STATUS_NORMAL); loop++)
 		{
-			gtk_text_buffer_set_text (text_buffer, stdout_utf8, -1);
+			gtk_text_buffer_insert_at_cursor (text_buffer, str->str, str->len);
 		}
-		g_free (stdout_utf8);
+		g_io_channel_shutdown (channel, FALSE, NULL);
+		g_io_channel_unref (channel);
+		g_string_free (str, TRUE);
+		g_spawn_close_pid (pid);
 	}
+	else
+	{
+		gtk_text_buffer_set_text (text_buffer, error->message, -1);
+	}
+
+	g_strfreev (args);
 }
 
 static gint cxp_right_pane_popup_handler (GtkWidget * widget, GdkEvent * event)


Cxplorer-cvs メーリングリストの案内
Back to archive index