diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2009-02-16 08:44:40 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2009-02-16 08:44:40 +0800 |
commit | 03d8740213e324efaf7b774b0c7497ced2fa626b (patch) | |
tree | 590073927ce64831efba1b4039404e7f5a5a49df /mail | |
parent | f7e298665b02f72890c6681e6d21ef5601beccbb (diff) | |
download | gsoc2013-evolution-03d8740213e324efaf7b774b0c7497ced2fa626b.tar.gz gsoc2013-evolution-03d8740213e324efaf7b774b0c7497ced2fa626b.tar.zst gsoc2013-evolution-03d8740213e324efaf7b774b0c7497ced2fa626b.zip |
Move signature script execution to e-util/e-signature-utils.s so the
composer can invoke it. Composer no longer needs mail-config.h.
Split signature preview into a new widget: ESignaturePreview.
svn path=/branches/kill-bonobo/; revision=37272
Diffstat (limited to 'mail')
-rw-r--r-- | mail/em-composer-prefs.c | 126 | ||||
-rw-r--r-- | mail/mail-config.c | 126 | ||||
-rw-r--r-- | mail/mail-config.h | 4 |
3 files changed, 13 insertions, 243 deletions
diff --git a/mail/em-composer-prefs.c b/mail/em-composer-prefs.c index ef73c23355..9b81935e90 100644 --- a/mail/em-composer-prefs.c +++ b/mail/em-composer-prefs.c @@ -49,6 +49,7 @@ #include "misc/e-charset-picker.h" #include "misc/e-signature-manager.h" +#include "misc/e-signature-preview.h" #include "e-util/e-error.h" #include "e-util/e-util-private.h" @@ -213,49 +214,6 @@ em_composer_prefs_get_type (void) return type; } -static void -sig_load_preview (EMComposerPrefs *prefs, - ESignature *signature) -{ - GtkHTML *html; - gchar *str; - - html = prefs->sig_preview; - - if (signature == NULL) { - gtk_html_load_from_string (html, " ", 1); - return; - } - - if (signature->script) - str = mail_config_signature_run_script (signature->filename); - else - /* FIXME Show an error in the preview area. */ - str = e_read_signature_file (signature, FALSE, NULL); - if (!str || !*str) { - /* make html stream happy and write at least one character */ - g_free (str); - str = g_strdup (" "); - } - - if (signature->html) { - gtk_html_load_from_string (html, str, strlen (str)); - } else { - GtkHTMLStream *stream; - int len; - - len = strlen (str); - stream = gtk_html_begin_content (html, "text/html; charset=utf-8"); - gtk_html_write (html, stream, "<PRE>", 5); - if (len) - gtk_html_write (html, stream, str, len); - gtk_html_write (html, stream, "</PRE>", 6); - gtk_html_end (html, stream, GTK_HTML_STREAM_OK); - } - - g_free (str); -} - void em_composer_prefs_new_signature (GtkWindow *parent, gboolean html_mode) @@ -269,59 +227,6 @@ em_composer_prefs_new_signature (GtkWindow *parent, } static void -sig_selection_changed (GtkTreeSelection *selection, - EMComposerPrefs *prefs) -{ - ESignature *signature; - GtkTreeView *tree_view; - - tree_view = gtk_tree_selection_get_tree_view (selection); - - signature = e_signature_tree_view_get_selected ( - E_SIGNATURE_TREE_VIEW (tree_view)); - - sig_load_preview (prefs, signature); - - if (signature != NULL) - g_object_unref (signature); -} - -static void -url_requested (GtkHTML *html, - const gchar *url, - GtkHTMLStream *handle) -{ - GtkHTMLStreamStatus status; - gchar buf[128]; - gssize size; - gint fd; - gchar *filename; - - if (strncmp (url, "file:", 5) == 0) - filename = g_filename_from_uri (url, NULL, NULL); - else - filename = g_strdup (url); - fd = g_open (filename, O_RDONLY | O_BINARY, 0); - g_free (filename); - - status = GTK_HTML_STREAM_OK; - if (fd != -1) { - while ((size = read (fd, buf, sizeof (buf)))) { - if (size == -1) { - status = GTK_HTML_STREAM_ERROR; - break; - } else - gtk_html_write (html, handle, buf, size); - } - } else - status = GTK_HTML_STREAM_ERROR; - - gtk_html_end (html, handle, status); - if (fd > 0) - close (fd); -} - -static void spell_language_toggled_cb (GtkCellRendererToggle *renderer, const gchar *path_string, EMComposerPrefs *prefs) @@ -383,10 +288,8 @@ spell_setup (EMComposerPrefs *prefs) { const GList *available_languages; GList *active_languages; - GConfClient *client; GtkListStore *store; - client = mail_config_get_gconf_client (); store = GTK_LIST_STORE (prefs->language_model); available_languages = gtkhtml_spell_language_get_available (); @@ -681,22 +584,19 @@ em_composer_prefs_construct (EMComposerPrefs *prefs, signature_tree_view = e_signature_manager_get_tree_view ( E_SIGNATURE_MANAGER (widget)); - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (signature_tree_view)); - g_signal_connect ( - selection, "changed", - G_CALLBACK (sig_selection_changed), prefs); - /* preview GtkHTML widget */ - widget = glade_xml_get_widget (gui, "scrolled-sig"); - prefs->sig_preview = (GtkHTML *) gtk_html_new (); - g_signal_connect ( - prefs->sig_preview, "url_requested", - G_CALLBACK (url_requested), NULL); - gtk_widget_show (GTK_WIDGET (prefs->sig_preview)); - gtk_container_add ( - GTK_CONTAINER (widget), - GTK_WIDGET (prefs->sig_preview)); + container = glade_xml_get_widget (gui, "scrolled-sig"); + widget = e_signature_preview_new (); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + e_binding_new_with_negation ( + G_OBJECT (shell_settings), "disable-command-line", + G_OBJECT (widget), "allow-scripts"); + + e_binding_new ( + G_OBJECT (signature_tree_view), "selected", + G_OBJECT (widget), "signature"); /* get our toplevel widget */ target = em_config_target_new_prefs (ec, client); diff --git a/mail/mail-config.c b/mail/mail-config.c index a7e8bb908c..3c39791dfa 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -39,10 +39,6 @@ #include <glib/gstdio.h> #include <glib/gi18n-lib.h> -#ifndef G_OS_WIN32 -#include <sys/wait.h> -#endif - #include <gtkhtml/gtkhtml.h> #include <glade/glade.h> @@ -983,125 +979,3 @@ mail_config_get_lookup_book_local_only (void) return config->book_lookup_local_only; } - -char * -mail_config_signature_run_script (const char *script) -{ -#ifndef G_OS_WIN32 - int result, status; - int in_fds[2]; - pid_t pid; - - if (config == NULL) - mail_config_init (); - - if (config->scripts_disabled) - return NULL; - - if (pipe (in_fds) == -1) { - g_warning ("Failed to create pipe to '%s': %s", script, g_strerror (errno)); - return NULL; - } - - if (!(pid = fork ())) { - /* child process */ - int maxfd, i; - - close (in_fds [0]); - if (dup2 (in_fds[1], STDOUT_FILENO) < 0) - _exit (255); - close (in_fds [1]); - - setsid (); - - maxfd = sysconf (_SC_OPEN_MAX); - for (i = 3; i < maxfd; i++) { - if (i != STDIN_FILENO && i != STDOUT_FILENO && i != STDERR_FILENO) - fcntl (i, F_SETFD, FD_CLOEXEC); - } - - execlp("/bin/sh", "/bin/sh", "-c", script, NULL); - g_warning ("Could not execute %s: %s\n", script, g_strerror (errno)); - _exit (255); - } else if (pid < 0) { - g_warning ("Failed to create create child process '%s': %s", script, g_strerror (errno)); - close (in_fds [0]); - close (in_fds [1]); - return NULL; - } else { - CamelStreamFilter *filtered_stream; - CamelStreamMem *memstream; - CamelMimeFilter *charenc; - CamelStream *stream; - GByteArray *buffer; - char *charset; - char *content; - - /* parent process */ - close (in_fds[1]); - - stream = camel_stream_fs_new_with_fd (in_fds[0]); - - memstream = (CamelStreamMem *) camel_stream_mem_new (); - buffer = g_byte_array_new (); - camel_stream_mem_set_byte_array (memstream, buffer); - - camel_stream_write_to_stream (stream, (CamelStream *) memstream); - camel_object_unref (stream); - - /* signature scripts are supposed to generate UTF-8 content, but because users - are known to not ever read the manual... we try to do our best if the - content isn't valid UTF-8 by assuming that the content is in the user's - preferred charset. */ - if (!g_utf8_validate ((char *)buffer->data, buffer->len, NULL)) { - stream = (CamelStream *) memstream; - memstream = (CamelStreamMem *) camel_stream_mem_new (); - camel_stream_mem_set_byte_array (memstream, g_byte_array_new ()); - - filtered_stream = camel_stream_filter_new_with_stream (stream); - camel_object_unref (stream); - - charset = gconf_client_get_string (config->gconf, "/apps/evolution/mail/composer/charset", NULL); - if (charset && *charset) { - if ((charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "utf-8"))) { - camel_stream_filter_add (filtered_stream, charenc); - camel_object_unref (charenc); - } - } - g_free (charset); - - camel_stream_write_to_stream ((CamelStream *) filtered_stream, (CamelStream *) memstream); - camel_object_unref (filtered_stream); - g_byte_array_free (buffer, TRUE); - - buffer = memstream->buffer; - } - - camel_object_unref (memstream); - - g_byte_array_append (buffer, (const unsigned char *)"", 1); - content = (char *)buffer->data; - g_byte_array_free (buffer, FALSE); - - /* wait for the script process to terminate */ - result = waitpid (pid, &status, 0); - - if (result == -1 && errno == EINTR) { - /* child process is hanging... */ - kill (pid, SIGTERM); - sleep (1); - result = waitpid (pid, &status, WNOHANG); - if (result == 0) { - /* ...still hanging, set phasers to KILL */ - kill (pid, SIGKILL); - sleep (1); - result = waitpid (pid, &status, WNOHANG); - } - } - - return content; - } -#else - return NULL; -#endif -} diff --git a/mail/mail-config.h b/mail/mail-config.h index ecbdb198ea..6c4683113f 100644 --- a/mail/mail-config.h +++ b/mail/mail-config.h @@ -110,10 +110,6 @@ gboolean mail_config_get_enable_magic_spacebar (void); struct _EAccountService *mail_config_get_default_transport (void); -/* signatures */ -char *mail_config_signature_run_script (const char *script); - - /* uri's got changed by the store, etc */ void mail_config_uri_renamed (GCompareFunc uri_cmp, const char *old, const char *new); void mail_config_uri_deleted (GCompareFunc uri_cmp, const char *uri); |