gnumeric r17186 - in trunk: . src



Author: mortenw
Date: Wed Mar 11 15:33:58 2009
New Revision: 17186
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17186&view=rev

Log:
2009-03-11  Morten Welinder  <terra gnome org>

	* src/wbc-gtk-actions.c (cb_file_sendto): Import from
	wb_view_sendto and use go_gtk_url_show.  Plug leak.

	* src/workbook-view.c (wb_view_save_to_uri): Rename from
	wbv_save_to_uri and make public.
	(wb_view_sendto): Remove.




Modified:
   trunk/ChangeLog
   trunk/README
   trunk/configure.in
   trunk/src/wbc-gtk-actions.c
   trunk/src/workbook-view.c
   trunk/src/workbook-view.h

Modified: trunk/README
==============================================================================
--- trunk/README	(original)
+++ trunk/README	Wed Mar 11 15:33:58 2009
@@ -17,7 +17,7 @@
 	glib		>= 2.10.0	libglib2.0-dev
 	gtk+		>= 2.12.0	libgtk2.0-dev
 	libgsf		>= 1.14.6	libgsf-1-dev
-	libgoffice	>= 0.7.3	libgoffice-0-5-dev
+	libgoffice	>= 0.7.4	libgoffice-0-5-dev
 	libglade	>= 2.3.6	libglade2-dev
 	gnome-xml   	>= 2.4.12	libxml2-dev
 	pango		>= 1.12.0	libpango1.0-dev

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Wed Mar 11 15:33:58 2009
@@ -141,7 +141,7 @@
 
 dnl *****************************
 libspreadsheet_reqs="
-	libgoffice-${GOFFICE_API_VER}	>= 0.7.3
+	libgoffice-${GOFFICE_API_VER}	>= 0.7.4
 	libgsf-1		>= 1.14.9
 	libxml-2.0		>= 2.4.12
 "

Modified: trunk/src/wbc-gtk-actions.c
==============================================================================
--- trunk/src/wbc-gtk-actions.c	(original)
+++ trunk/src/wbc-gtk-actions.c	Wed Mar 11 15:33:58 2009
@@ -75,6 +75,22 @@
 #include <glib/gi18n-lib.h>
 #include <gsf/gsf-input.h>
 #include <string.h>
+#include <glib/gstdio.h>
+
+static gboolean
+cb_cleanup_sendto (gpointer path)
+{
+	char *dir = g_path_get_dirname (path);
+
+	g_unlink (path);
+	g_free (path);	/* the attachment */
+
+	g_rmdir (dir);
+	g_free (dir);	/* the tempdir */
+
+	return FALSE;
+}
+
 
 static GNM_ACTION_DEF (cb_file_new)
 {
@@ -88,8 +104,118 @@
 static GNM_ACTION_DEF (cb_file_open)	{ gui_file_open (wbcg, NULL); }
 static GNM_ACTION_DEF (cb_file_save)	{ gui_file_save (wbcg, wb_control_view (WORKBOOK_CONTROL (wbcg))); }
 static GNM_ACTION_DEF (cb_file_save_as)	{ gui_file_save_as (wbcg, wb_control_view (WORKBOOK_CONTROL (wbcg))); }
-static GNM_ACTION_DEF (cb_file_sendto)	{
-	wb_view_sendto (wb_control_view (WORKBOOK_CONTROL (wbcg)), GO_CMD_CONTEXT (wbcg)); }
+
+static GNM_ACTION_DEF (cb_file_sendto) {
+	WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
+	WorkbookView *wbv = wb_control_view (wbc);
+	GOCmdContext *gcc = GO_CMD_CONTEXT (wbcg);
+	gboolean problem = FALSE;
+	IOContext *io_context;
+	Workbook *wb;
+	GOFileSaver *fs;
+
+	wb = wb_control_get_workbook (wbc);
+	g_object_ref (wb);
+	fs = workbook_get_file_saver (wb);
+	if (fs == NULL)
+		fs = go_file_saver_get_default ();
+
+	io_context = gnumeric_io_context_new (gcc);
+	if (fs != NULL) {
+		char *template, *full_name, *uri;
+		char *basename = g_path_get_basename (go_doc_get_uri (GO_DOC (wb)));
+
+#define GNM_SEND_DIR	".gnm-sendto-"
+#ifdef HAVE_MKDTEMP
+		template = g_build_filename (g_get_tmp_dir (),
+			GNM_SEND_DIR "XXXXXX", NULL);
+		problem = (mkdtemp (template) == NULL);
+#else
+		while (1) {
+			char *dirname = g_strdup_printf
+				("%s%ld-%08d",
+				 GNM_SEND_DIR,
+				 (long)getpid (),
+				 (int)(1e8 * random_01 ()));
+			template = g_build_filename (g_get_tmp_dir (), dirname, NULL);
+			g_free (dirname);
+
+			if (g_mkdir (template, 0700) == 0) {
+				problem = FALSE;
+				break;
+			}
+
+			if (errno != EEXIST) {
+				go_cmd_context_error_export (gcc,
+					_("Failed to create temporary file for sending."));
+				gnumeric_io_error_display (io_context);
+				problem = TRUE;
+				break;
+			}
+		}
+#endif
+
+		if (problem) {
+			g_free (template);
+			goto out;
+		}
+
+		full_name = g_build_filename (template, basename, NULL);
+		g_free (basename);
+		uri = go_filename_to_uri (full_name);
+
+		wb_view_save_to_uri (wbv, fs, uri, io_context);
+
+		if (gnumeric_io_error_occurred (io_context) ||
+		    gnumeric_io_warning_occurred (io_context))
+			gnumeric_io_error_display (io_context);
+
+		if (gnumeric_io_error_occurred (io_context)) {
+			problem = TRUE;
+		} else {
+			/* mutt does not handle urls with no destination
+			 * so pick something to arbitrary */
+			GError *err;
+			GdkScreen *screen = gtk_window_get_screen (wbcg_toplevel (wbcg));
+			char *url, *tmp = go_url_encode (full_name, 0);
+			url = g_strdup_printf ("mailto:someone?attach=%s";, tmp);
+			g_free (tmp);
+
+			err = go_gtk_url_show (url, screen);
+
+			if (err != NULL) {
+				go_cmd_context_error (GO_CMD_CONTEXT (io_context), err);
+				g_error_free (err);
+				gnumeric_io_error_display (io_context);
+				problem = TRUE;
+			}
+		}
+		g_free (template);
+		g_free (uri);
+
+		if (problem) {
+			cb_cleanup_sendto (full_name);
+		} else {
+			/*
+			 * We wait a while before we clean up to ensure the file is
+			 * loaded by the mailer.
+			 */
+			g_timeout_add (1000 * 10, cb_cleanup_sendto, full_name);
+		}
+	} else {
+		go_cmd_context_error_export (GO_CMD_CONTEXT (io_context),
+			_("Default file saver is not available."));
+		gnumeric_io_error_display (io_context);
+		problem = TRUE;
+	}
+
+ out:
+	g_object_unref (io_context);
+	g_object_unref (wb);
+
+	/* What do we do with "problem"? */
+}
+
 static GNM_ACTION_DEF (cb_file_page_setup)
 {
 	dialog_printer_setup (wbcg, wbcg_cur_sheet (wbcg));

Modified: trunk/src/workbook-view.c
==============================================================================
--- trunk/src/workbook-view.c	(original)
+++ trunk/src/workbook-view.c	Wed Mar 11 15:33:58 2009
@@ -862,9 +862,9 @@
 		go_cmd_context_error_export (GO_CMD_CONTEXT (io_context), msg);
 }
 
-static void
-wbv_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
-		 char const *uri, IOContext *io_context)
+void
+wb_view_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
+		     char const *uri, IOContext *io_context)
 {
 	char   *msg = NULL;
 	GError *err = NULL;
@@ -920,7 +920,7 @@
 	io_context = gnumeric_io_context_new (context);
 
 	go_cmd_context_set_sensitive (context, FALSE);
-	wbv_save_to_uri (wbv, fs, uri, io_context);
+	wb_view_save_to_uri (wbv, fs, uri, io_context);
 	go_cmd_context_set_sensitive (context, TRUE);
 
 	has_error   = gnumeric_io_error_occurred (io_context);
@@ -974,7 +974,7 @@
 			_("Default file saver is not available."));
 	else {
 		char const *uri = go_doc_get_uri (GO_DOC (wb));
-		wbv_save_to_uri (wbv, fs, uri, io_context);
+		wb_view_save_to_uri (wbv, fs, uri, io_context);
 	}
 
 	has_error   = gnumeric_io_error_occurred (io_context);
@@ -990,179 +990,6 @@
 	return !has_error;
 }
 
-#ifndef GNM_WITH_GNOME
-static void
-gnm_mailto_url_show (char const *url, char const *working_dir, GError **err)
-{
-#ifdef G_OS_WIN32
-	ShellExecute (NULL, "open", url, NULL, working_dir, SW_SHOWNORMAL);
-	return;
-#else
-	static struct {
-		char const *app;
-		char const *arg;
-	} const fallback_mailers[] = {
-		{ "evolution",			NULL },
-		{ "evolution-1.6",		NULL },
-		{ "evolution-1.5",		NULL },
-		{ "evolution-1.4",		NULL },
-		{ "balsa",			"-m" },
-		{ "kmail",			NULL },
-		{ "mozilla",			"-mail" }
-	};
-	unsigned i;
-
-	for (i = 0 ; i < G_N_ELEMENTS (fallback_mailers); i++) {
-		char const *app = fallback_mailers[i].app;
-		if (g_find_program_in_path (app)) {
-			char *argv[4];
-			argv[0] = (char *)app;
-			if (fallback_mailers [i].arg == NULL) {
-				argv[1] = (char *)url;
-				argv[2] = NULL;
-			} else {
-				argv[1] = (char *)fallback_mailers[i].arg;
-				argv[2] = (char *)url;
-				argv[3] = NULL;
-			}
-			g_spawn_async (working_dir,
-				       argv, NULL, G_SPAWN_SEARCH_PATH,
-				       NULL, NULL, NULL, err);
-			return;
-		}
-	}
-
-	if (err)
-		*err = g_error_new (go_error_invalid (), 0,
-				    "Missing handler for mailto URLs.");
-#endif
-}
-#endif
-
-static gboolean
-cb_cleanup_sendto (gpointer path)
-{
-	char *dir = g_path_get_dirname (path);
-	g_unlink (path); g_free (path);	/* the attachment */
-	g_rmdir (dir); g_free (dir);	/* the tempdir */
-	return FALSE;
-}
-
-gboolean
-wb_view_sendto (WorkbookView *wbv, GOCmdContext *context)
-{
-	gboolean problem = FALSE;
-	IOContext	*io_context;
-	Workbook	*wb;
-	GOFileSaver	*fs;
-
-	g_return_val_if_fail (IS_WORKBOOK_VIEW (wbv), FALSE);
-	g_return_val_if_fail (IS_GO_CMD_CONTEXT (context), FALSE);
-
-	wb = wb_view_get_workbook (wbv);
-	g_object_ref (wb);
-	fs = workbook_get_file_saver (wb);
-	if (fs == NULL)
-		fs = go_file_saver_get_default ();
-
-	io_context = gnumeric_io_context_new (context);
-	if (fs != NULL) {
-		char *template, *full_name, *uri;
-		char *basename = g_path_get_basename (go_doc_get_uri (GO_DOC (wb)));
-
-#define GNM_SEND_DIR	".gnm-sendto-"
-#ifdef HAVE_MKDTEMP
-		template = g_build_filename (g_get_tmp_dir (),
-			GNM_SEND_DIR "XXXXXX", NULL);
-		problem = (mkdtemp (template) == NULL);
-#else
-		while (1) {
-			char *dirname = g_strdup_printf
-				("%s%ld-%08d",
-				 GNM_SEND_DIR,
-				 (long)getpid (),
-				 (int)(1e8 * random_01 ()));
-			template = g_build_filename (g_get_tmp_dir (), dirname, NULL);
-			g_free (dirname);
-
-			if (g_mkdir (template, 0700) == 0) {
-				problem = FALSE;
-				break;
-			}
-
-			if (errno != EEXIST) {
-				go_cmd_context_error_export (GO_CMD_CONTEXT (io_context),
-					_("Failed to create temporary file for sending."));
-				gnumeric_io_error_display (io_context);
-				problem = TRUE;
-				break;
-			}
-		}
-#endif
-
-		if (problem) {
-			g_free (template);
-			goto out;
-		}
-
-		full_name = g_build_filename (template, basename, NULL);
-		g_free (basename);
-		uri = go_filename_to_uri (full_name);
-
-		wbv_save_to_uri (wbv, fs, uri, io_context);
-
-		if (gnumeric_io_error_occurred (io_context) ||
-		    gnumeric_io_warning_occurred (io_context))
-			gnumeric_io_error_display (io_context);
-
-		if (gnumeric_io_error_occurred (io_context)) {
-			problem = TRUE;
-		} else {
-/****************************************************************
- * This code does not belong here
- * move to goffice
- **/
-			/* mutt does not handle urls with no destination
-			 * so pick something to arbitrary */
-			GError *err = NULL;
-			char *url, *tmp = go_url_encode (full_name, 0);
-			url = g_strdup_printf ("mailto:someone?attach=%s";, tmp);
-			g_free (tmp);
-#ifdef GNM_WITH_GNOME
-			go_url_show (url);
-#else
-			gnm_mailto_url_show (url, template, &err);
-#endif
-			if (err != NULL) {
-				go_cmd_context_error (GO_CMD_CONTEXT (io_context), err);
-				g_error_free (err);
-				gnumeric_io_error_display (io_context);
-				problem = TRUE;
-			}
-			g_free (url);
-		}
-		g_free (template);
-
-		/*
-		 * We wait a while before we clean up to ensure the file is
-		 * loaded by the mailer.
-		 */
-		g_timeout_add (1000 * 10, cb_cleanup_sendto, full_name);
-		g_free (uri);
-	} else {
-		go_cmd_context_error_export (GO_CMD_CONTEXT (io_context),
-			_("Default file saver is not available."));
-		gnumeric_io_error_display (io_context);
-		problem = TRUE;
-	}
-
- out:
-	g_object_unref (G_OBJECT (io_context));
-	g_object_unref (wb);
-
-	return !problem;
-}
-
 WorkbookView *
 wb_view_new_from_input  (GsfInput *input,
 			 GOFileOpener const *optional_fmt,

Modified: trunk/src/workbook-view.h
==============================================================================
--- trunk/src/workbook-view.h	(original)
+++ trunk/src/workbook-view.h	Wed Mar 11 15:33:58 2009
@@ -87,7 +87,8 @@
 gboolean wb_view_save	 (WorkbookView *wbv, GOCmdContext *cc);
 void	 wbv_save_to_output (WorkbookView *wbv, GOFileSaver const *fs,
 			     GsfOutput *output, IOContext *io_context);
-gboolean wb_view_sendto	 (WorkbookView *wbv, GOCmdContext *cc);
+void     wb_view_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
+			      char const *uri, IOContext *io_context);
 
 WorkbookView *wb_view_new_from_input  (GsfInput *input,
 				       GOFileOpener const *optional_format,



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