diff options
author | Sankar P <psankar@novell.com> | 2008-04-17 17:16:25 +0800 |
---|---|---|
committer | Sankarasivasubramanian Pasupathilingam <psankar@src.gnome.org> | 2008-04-17 17:16:25 +0800 |
commit | 298f58a3e72346247152137dec52dbb899eec162 (patch) | |
tree | a0036375fc0ec66c0959c044364429269e44333c /plugins | |
parent | e7adc5aefafb18e5149a5fdb07756febf17b5684 (diff) | |
download | gsoc2013-evolution-298f58a3e72346247152137dec52dbb899eec162.tar gsoc2013-evolution-298f58a3e72346247152137dec52dbb899eec162.tar.gz gsoc2013-evolution-298f58a3e72346247152137dec52dbb899eec162.tar.bz2 gsoc2013-evolution-298f58a3e72346247152137dec52dbb899eec162.tar.lz gsoc2013-evolution-298f58a3e72346247152137dec52dbb899eec162.tar.xz gsoc2013-evolution-298f58a3e72346247152137dec52dbb899eec162.tar.zst gsoc2013-evolution-298f58a3e72346247152137dec52dbb899eec162.zip |
Added new files deleted files not needed.
2008-04-17 Sankar P <psankar@novell.com>
* Makefile.am:
Added new files deleted files not needed.
* external-editor.c: (convert_to_camel_internet_address),
(ee_editor_command_changed), (e_plugin_lib_get_configure_widget),
(async_external_editor), (show_composer_dialog),
(org_gnome_external_editor):
Leak fixes, Temporary files, Bug fixes and so on.
* org-gnome-external-editor-errors.xml:
Modified error file for staying aligned with other plugins
* apps-evolution-external-editor.schemas.in:
Added new file for default schema
* org-gnome-external-editor.error.xml:
Removed in favor of the other errors file.
** Fix for bug #517168
svn path=/trunk/; revision=35373
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/external-editor/ChangeLog | 22 | ||||
-rw-r--r-- | plugins/external-editor/Makefile.am | 24 | ||||
-rw-r--r-- | plugins/external-editor/apps-evolution-external-editor.schemas.in | 16 | ||||
-rw-r--r-- | plugins/external-editor/external-editor.c | 190 | ||||
-rw-r--r-- | plugins/external-editor/org-gnome-external-editor-errors.xml | 14 | ||||
-rw-r--r-- | plugins/external-editor/org-gnome-external-editor.error.xml | 4 |
6 files changed, 215 insertions, 55 deletions
diff --git a/plugins/external-editor/ChangeLog b/plugins/external-editor/ChangeLog index 4f8996ea79..d49ecb97a4 100644 --- a/plugins/external-editor/ChangeLog +++ b/plugins/external-editor/ChangeLog @@ -1,3 +1,25 @@ +2008-04-17 Sankar P <psankar@novell.com> + + * Makefile.am: + Added new files deleted files not needed. + + * external-editor.c: (convert_to_camel_internet_address), + (ee_editor_command_changed), (e_plugin_lib_get_configure_widget), + (async_external_editor), (show_composer_dialog), + (org_gnome_external_editor): + Leak fixes, Temporary files, Bug fixes and so on. + + * org-gnome-external-editor-errors.xml: + Modified error file for staying aligned with other plugins + + * apps-evolution-external-editor.schemas.in: + Added new file for default schema + + * org-gnome-external-editor.error.xml: + Removed in favor of the other errors file. + + ** Fix for bug #517168 + 2008-02-18 Milan Crha <mcrha@redhat.com> ** Part of fix for bug #515744 diff --git a/plugins/external-editor/Makefile.am b/plugins/external-editor/Makefile.am index beec48dc29..0c7c22ab8b 100644 --- a/plugins/external-editor/Makefile.am +++ b/plugins/external-editor/Makefile.am @@ -13,7 +13,7 @@ INCLUDES = \ @EVO_PLUGIN_RULE@ -error_DATA = org-gnome-external-editor.error +error_DATA = org-gnome-external-editor-errors.xml errordir = $(privdatadir)/errors plugin_DATA = \ @@ -27,12 +27,28 @@ liborg_gnome_external_editor_la_SOURCES = \ liborg_gnome_external_editor_la_LDFLAGS = -module -avoid-version +schemadir = $(GCONF_SCHEMA_FILE_DIR) +schema_in_files = apps-evolution-external-editor.schemas.in +schema_DATA = $(schema_in_files:.schemas.in=.schemas) + +@INTLTOOL_SCHEMAS_RULE@ + +install-data-local: + if test -z "$(DESTDIR)" ; then \ + for p in $(schema_DATA) ; do \ + GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $$p; \ + done \ + fi + EXTRA_DIST = \ org-gnome-external-editor.eplug.xml \ - org-gnome-external-editor.error.xml \ - org-gnome-external-editor.xml + org-gnome-external-editor-errors.xml \ + org-gnome-external-editor.xml \ + $(schema_in_files) BUILT_SOURCES = org-gnome-external-editor.eplug \ - org-gnome-external-editor.error + $(error_i18n) CLEANFILES = $(BUILT_SOURCES) + +DISTCLEANFILES = $(schema_DATA) diff --git a/plugins/external-editor/apps-evolution-external-editor.schemas.in b/plugins/external-editor/apps-evolution-external-editor.schemas.in new file mode 100644 index 0000000000..0f6d264b90 --- /dev/null +++ b/plugins/external-editor/apps-evolution-external-editor.schemas.in @@ -0,0 +1,16 @@ +<gconfschemafile> + <schemalist> + <schema> + <key>/schemas/apps/evolution/eplugin/external-editor/editor-command</key> + <applyto>/apps/evolution/eplugin/external-editor/editor-command</applyto> + <owner>evolution-mail</owner> + <type>string</type> + <default>gedit</default> + <locale name="C"> + <short>Default External Editor</short> + <long>The default command that must be used as the editor.</long> + </locale> + </schema> + </schemalist> +</gconfschemafile> + diff --git a/plugins/external-editor/external-editor.c b/plugins/external-editor/external-editor.c index b34cb0717d..aaa06d3c73 100644 --- a/plugins/external-editor/external-editor.c +++ b/plugins/external-editor/external-editor.c @@ -9,97 +9,138 @@ #include <mail/em-composer-utils.h> #include <mail/mail-config.h> #include <e-util/e-error.h> - #include <e-msg-composer.h> +#include <glib/gi18n-lib.h> +#include <glib-object.h> +#include <glib.h> +#include <glib/gstdio.h> + #include <sys/stat.h> #include <sys/wait.h> #include <stdlib.h> #include <string.h> -#define d(x) x +#include <gconf/gconf-client.h> -#define TEMPORARY_FILE "/tmp/evolution-composer" +#define d(x) + +#define EDITOR_GCONF_KEY "/apps/evolution/eplugin/external-editor/editor-command" void org_gnome_external_editor (EPlugin *ep, EMMenuTargetSelect *select); +void ee_editor_command_changed (GtkWidget *textbox); +GtkWidget * e_plugin_lib_get_configure_widget (EPlugin *epl); +void async_external_editor (GArray *array); +static gboolean show_composer_dialog (EMsgComposer *composer); /* Utility function to convert an email address to CamelInternetAddress. -May be this should belong to CamelInternetAddress file itself. */ - +May be this should belong to CamelInternetAddress.h file itself. */ static CamelInternetAddress * convert_to_camel_internet_address (char * emails) { CamelInternetAddress *cia = camel_internet_address_new(); gchar **address_tokens = NULL; int i; + d(printf ("\n\aconvert called with : [%s] \n\a", emails)); + + emails = g_strstrip (emails); + if (emails && strlen (emails) > 1) { address_tokens = g_strsplit (emails, ",", 0); if (address_tokens) { - for (i = 1; address_tokens[i]; ++i) { + for (i = 0; address_tokens[i]; ++i) { camel_internet_address_add (cia, " ", address_tokens [i]); d(printf ("\nAdding camel_internet_address[%s] \n", address_tokens [i])); } g_strfreev (address_tokens); + g_free (emails); return cia; } } camel_object_unref (cia); + g_free (emails); return NULL; } -void org_gnome_external_editor (EPlugin *ep, EMMenuTargetSelect *select) +void ee_editor_command_changed (GtkWidget *textbox) { - d(printf ("\n\nexternal_editor plugin is launched \n\n")); + const char *editor; + GConfClient *gconf; + + editor = gtk_entry_get_text (GTK_ENTRY(textbox)); + d(printf ("\n\aeditor is : [%s] \n\a", editor)); + + /* gconf access for every key-press. Sucky ? */ + gconf = gconf_client_get_default (); + gconf_client_set_string (gconf, EDITOR_GCONF_KEY, editor, NULL); + g_object_unref (gconf); +} - /* The template to be used in the external editor */ - char template[] = "###|||Insert , seperated TO addresses below this line. Do not delete this line. Optional field\n\n###||| Insert , seperated CC addresses below this line. Do not delete this line. Optional field\n\n###|||Insert , seperated BCC addresses below this line. Do not delete this line. Optional field\n\n###|||Insert SUBJECT below this line. Do not delete this line. Optional field\n\n###|||Insert BODY of mail below this line. Do not delete this line.\n\n"; +GtkWidget * +e_plugin_lib_get_configure_widget (EPlugin *epl) +{ + GtkWidget *vbox, *textbox, *label, *help; + GConfClient *gconf; + char *editor; + vbox = gtk_vbox_new (FALSE, 10); + textbox = gtk_entry_new (); + label = gtk_label_new (_("Command to be executed to launch the editor: ")); + help = gtk_label_new (_("For Emacs use \"xemacs\"\nFor VI use \"gvim\"")); + gconf = gconf_client_get_default (); - /* Push the template contents to the intermediate file */ - g_file_set_contents (TEMPORARY_FILE, template, strlen (template), NULL); + editor = gconf_client_get_string (gconf, EDITOR_GCONF_KEY, NULL); + if (editor) { + gtk_entry_set_text (GTK_ENTRY(textbox), editor); + g_free (editor); + } + g_object_unref (gconf); - char *editor; + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), textbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), help, FALSE, FALSE, 0); - editor = (char *) g_getenv ("EDITOR"); - if (!editor) - editor = "gvim"; + g_signal_connect (textbox, "changed", G_CALLBACK(ee_editor_command_changed), textbox); + + gtk_widget_show_all (vbox); + return vbox; +} -#if 1 +void +async_external_editor (GArray *array) +{ + char *filename = NULL; + gchar *argv[5]; int status = 0; - gchar *argv[4]; - - argv[0] = editor; - /* README: The -- params should come via the "Configure" option */ - argv[1] = "--nofork"; + argv[0] = g_array_index (array, gpointer, 0); + argv[1] = g_array_index (array, gpointer, 1); + argv[2] = NULL; - argv[2] = TEMPORARY_FILE; - argv[3] = NULL; + filename = g_strdup (argv[1]); - /* FIXME: I guess NULL should do fine instead of /usr/bin */ - if (!g_spawn_sync ("/usr/bin", argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &status, NULL)) + if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &status, NULL)) { g_warning ("Unable to launch %s: ", argv[0]); + e_error_run (NULL, "org.gnome.evolution.plugins.external-editor:editor-not-launchable", NULL); + g_free (filename); return ; } - + if (WEXITSTATUS (status) != 0) { d(printf ("\n\nsome problem here with external editor\n\n")); return ; } else { - gchar *buf; CamelMimeMessage *message; EMsgComposer *composer; message = camel_mime_message_new (); - d(printf ("\n\nexternal editor works like a charm \n\n")); - - if (g_file_get_contents (TEMPORARY_FILE, &buf, NULL, NULL)) { + if (g_file_get_contents (filename, &buf, NULL, NULL)) { gchar **tokens; int i, j; @@ -114,42 +155,97 @@ void org_gnome_external_editor (EPlugin *ep, EMMenuTargetSelect *select) if (tokens[i][j] == '\n') tokens[i][j] = ' '; - g_strchug(tokens[i]); - d(printf ("\nstripped off token[%d] is : %s \n", i, tokens[i])); } - camel_mime_message_set_recipients (message, "To", convert_to_camel_internet_address(tokens[1])); - camel_mime_message_set_recipients (message, "Cc", convert_to_camel_internet_address(tokens[2])); - camel_mime_message_set_recipients (message, "Bcc", convert_to_camel_internet_address(tokens[3])); - + camel_mime_message_set_recipients (message, "To", convert_to_camel_internet_address(g_strchug(g_strdup(tokens[1])))); + camel_mime_message_set_recipients (message, "Cc", convert_to_camel_internet_address(g_strchug(g_strdup(tokens[2])))); + camel_mime_message_set_recipients (message, "Bcc", convert_to_camel_internet_address(g_strchug(g_strdup(tokens[3])))); camel_mime_message_set_subject (message, tokens[4]); - camel_mime_part_set_content ((CamelMimePart *)message, tokens [5], strlen (tokens [5]), "text/plain"); /* FIXME: We need to make mail-remote working properly. So that we neednot invoke composer widget at all. + May be we can do it now itself by invoking local CamelTransport. But all that is not needed for the first release. + + People might want to format mails using their editor (80 cols width etc.) + But might want to use evolution addressbook for auto-completion etc. + So starting the composer window anyway. */ composer = e_msg_composer_new_with_message (message); g_signal_connect (GTK_OBJECT (composer), "send", G_CALLBACK (em_utils_composer_send_cb), NULL); - g_signal_connect (GTK_OBJECT (composer), "save-draft", G_CALLBACK (em_utils_composer_save_draft_cb), NULL); - - gtk_widget_show (GTK_WIDGET (composer)); + + /* Composer cannot be shown in any random thread. Should happen in main thread */ + g_idle_add ((GSourceFunc) show_composer_dialog, composer); g_strfreev (tokens); + + /* We no longer need that temporary file */ + g_remove (filename); + g_free (filename); } } -#else - char *query; +} - query = g_strdup_printf ("%s /tmp/evolution-composer", editor); - system (query); - g_free (query); +static gboolean +show_composer_dialog (EMsgComposer *composer) +{ + gtk_widget_show (GTK_WIDGET(composer)); + return FALSE; +} -#endif +void org_gnome_external_editor (EPlugin *ep, EMMenuTargetSelect *select) +{ + d(printf ("\n\nexternal_editor plugin is launched \n\n")); + + /* The template to be used in the external editor */ + + /* README: I have not marked this for translation. + As I might change this string to make it more meaningful and friendlier based on feedback. */ + + char template[] = "###|||Insert , seperated TO addresses below this line. Do not edit or delete this line. Optional field\n\n###||| Insert , seperated CC addresses below this line. Do not edit or delete this line. Optional field\n\n###|||Insert , seperated BCC addresses below this line. Do not edit or delete this line. Optional field\n\n###|||Insert SUBJECT below this line. Do not edit or delete this line. Optional field\n\n###|||Insert BODY of mail below this line. Do not edit or delete this line.\n\n"; + + gint fd; + char *filename = NULL; + + fd = g_file_open_tmp (NULL, &filename, NULL); + if (fd > 0) { + close (fd); + /* Push the template contents to the intermediate file */ + g_file_set_contents (filename, template, strlen (template), NULL); + d(printf ("\n\aTemporary-file Name is : [%s] \n\a", filename)); + } else { + g_warning ("Temporary file fd is null"); + e_error_run (NULL, "org.gnome.evolution.plugins.external-editor:no-temp-file", NULL); + return ; + } + + char *editor = NULL; + GConfClient *gconf; + + gconf = gconf_client_get_default (); + editor = gconf_client_get_string (gconf, EDITOR_GCONF_KEY, NULL); + if (!editor) { + + if (! (editor = g_strdup(g_getenv ("EDITOR"))) ) + /* Make gedit the default external editor, + if the default schemas are not installed + and no $EDITOR is set. */ + editor = g_strdup("gedit"); + } + g_object_unref (gconf); + + GArray *array; + array = g_array_sized_new (TRUE, TRUE, sizeof (gpointer), 2 * sizeof(gpointer)); + array = g_array_append_val (array, editor); + array = g_array_append_val (array, filename); + + g_thread_create ( (GThreadFunc) async_external_editor, array, FALSE, NULL); + + return ; } diff --git a/plugins/external-editor/org-gnome-external-editor-errors.xml b/plugins/external-editor/org-gnome-external-editor-errors.xml new file mode 100644 index 0000000000..c6f0bebfa3 --- /dev/null +++ b/plugins/external-editor/org-gnome-external-editor-errors.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<error-list domain="org.gnome.evolution.plugins.external-editor"> + + <error id="editor-not-launchable" type="error"> + <_primary>Editor not launchable</_primary> + <_secondary>The external editor set in your plugin preferences cannot be launched. Try setting a different editor.</_secondary> + </error> + + <error id="no-temp-file" type="error"> + <_primary>Cannot create Temporary File</_primary> + <_secondary>Evolution is unable to create a temporary file to save your mail. Retry later.</_secondary> + </error> + +</error-list> diff --git a/plugins/external-editor/org-gnome-external-editor.error.xml b/plugins/external-editor/org-gnome-external-editor.error.xml deleted file mode 100644 index 05fbca60e9..0000000000 --- a/plugins/external-editor/org-gnome-external-editor.error.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<error-list domain="org.gnome.external-editor"> - -</error-list> |