aboutsummaryrefslogtreecommitdiffstats
path: root/composer
diff options
context:
space:
mode:
authorRadek Doulik <rodo@src.gnome.org>2002-03-07 08:21:59 +0800
committerRadek Doulik <rodo@src.gnome.org>2002-03-07 08:21:59 +0800
commita1bb1ba0fe60989c4e1ebf2798db8c2f5973d8c0 (patch)
tree2b0704091ffc986a0bcfdc4af18ad8c08ea3a136 /composer
parentfb1819e374f6d663e7b1044e5beb280f56ddb6e6 (diff)
downloadgsoc2013-evolution-a1bb1ba0fe60989c4e1ebf2798db8c2f5973d8c0.tar
gsoc2013-evolution-a1bb1ba0fe60989c4e1ebf2798db8c2f5973d8c0.tar.gz
gsoc2013-evolution-a1bb1ba0fe60989c4e1ebf2798db8c2f5973d8c0.tar.bz2
gsoc2013-evolution-a1bb1ba0fe60989c4e1ebf2798db8c2f5973d8c0.tar.lz
gsoc2013-evolution-a1bb1ba0fe60989c4e1ebf2798db8c2f5973d8c0.tar.xz
gsoc2013-evolution-a1bb1ba0fe60989c4e1ebf2798db8c2f5973d8c0.tar.zst
gsoc2013-evolution-a1bb1ba0fe60989c4e1ebf2798db8c2f5973d8c0.zip
merge new signature handling
svn path=/trunk/; revision=15960
Diffstat (limited to 'composer')
-rw-r--r--composer/e-msg-composer.c279
-rw-r--r--composer/e-msg-composer.h3
2 files changed, 252 insertions, 30 deletions
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index d939a7592e..c6437b6d93 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -22,6 +22,7 @@
* Ettore Perazzoli (ettore@ximian.com)
* Jeffrey Stedfast (fejj@ximian.com)
* Miguel de Icaza (miguel@ximian.com)
+ * Radek Doulik (rodo@ximian.com)
*
*/
@@ -47,9 +48,11 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <gal/unicode/gunicode.h>
#include <libgnome/gnome-defs.h>
+#include <libgnome/gnome-exec.h>
#include <libgnomeui/gnome-app.h>
#include <libgnomeui/gnome-uidefs.h>
#include <libgnomeui/gnome-dialog.h>
@@ -143,6 +146,7 @@ static void handle_multipart_alternative (EMsgComposer *composer, CamelMultipart
static void handle_multipart (EMsgComposer *composer, CamelMultipart *multipart, int depth);
+static void set_editor_signature (EMsgComposer *composer);
@@ -692,7 +696,7 @@ build_message (EMsgComposer *composer)
static char *
-get_file_content (EMsgComposer *composer, const char *file_name, gboolean want_html, guint flags)
+get_file_content (EMsgComposer *composer, const char *file_name, gboolean want_html, guint flags, gboolean warn)
{
CamelStreamFilter *filtered_stream;
CamelStreamMem *memstream;
@@ -706,11 +710,13 @@ get_file_content (EMsgComposer *composer, const char *file_name, gboolean want_h
fd = open (file_name, O_RDONLY | O_CREAT, 0644);
if (fd == -1) {
char *msg;
-
- msg = g_strdup_printf (_("Error while reading file %s:\n%s"),
- file_name, g_strerror (errno));
- gnome_error_dialog (msg);
- g_free (msg);
+
+ if (warn) {
+ msg = g_strdup_printf (_("Error while reading file %s:\n%s"),
+ file_name, g_strerror (errno));
+ gnome_error_dialog (msg);
+ g_free (msg);
+ }
return g_strdup ("");
}
@@ -751,7 +757,7 @@ e_msg_composer_get_sig_file_content (const char *sigfile, gboolean in_html)
return NULL;
}
- return get_file_content (NULL, sigfile, !in_html, 0);
+ return get_file_content (NULL, sigfile, !in_html, 0, FALSE);
}
static void
@@ -773,10 +779,11 @@ prepare_engine (EMsgComposer *composer)
composer->editor_listener = BONOBO_OBJECT (listener_new (composer));
if (composer->editor_listener != NULL)
GNOME_GtkHTML_Editor_Engine__set_listener (composer->editor_engine,
- (GNOME_GtkHTML_Editor_Listener)
- bonobo_object_dup_ref
- (bonobo_object_corba_objref (composer->editor_listener), &ev),
- &ev);
+ (GNOME_GtkHTML_Editor_Listener)
+ bonobo_object_dup_ref
+ (bonobo_object_corba_objref (composer->editor_listener),
+ &ev),
+ &ev);
if ((ev._major != CORBA_NO_EXCEPTION) || (composer->editor_listener == NULL)) {
CORBA_Environment err_ev;
@@ -803,26 +810,47 @@ static gchar *
get_signature_html (EMsgComposer *composer)
{
gboolean format_html = FALSE;
- char *text, *html = NULL, *sig_file = NULL;
-
- if (E_MSG_COMPOSER_HDRS (composer->hdrs)->account->id) {
- MailConfigIdentity *id;
-
- id = E_MSG_COMPOSER_HDRS (composer->hdrs)->account->id;
- if (composer->send_html) {
- if (id->has_html_signature) {
- sig_file = id->html_signature;
- format_html = TRUE;
- } else
- sig_file = id->signature;
- } else
- sig_file = id->signature;
+ char *text, *html = NULL, *sig_file = NULL, *script = NULL;
+ static gboolean random_initialized = FALSE;
+
+ if (composer->signature) {
+ sig_file = composer->signature->filename;
+ format_html = composer->signature->html;
+ script = composer->signature->script;
+ } else if (composer->random_signature) {
+ GList *l;
+ gint pos;
+
+ if (!random_initialized) {
+ printf ("initialize random generator\n");
+ srand (time (NULL));
+ random_initialized = TRUE;
+ }
+ pos = (int) (((gdouble) mail_config_get_signatures_random ())*rand()/(RAND_MAX+1.0));
+ printf ("using %d sig\n", pos);
+
+ for (l = mail_config_get_signature_list (); l; l = l->next) {
+ MailConfigSignature *sig = (MailConfigSignature *) l->data;
+
+ if (sig->random) {
+ if (pos == 0) {
+ printf ("using %s\n", sig->name);
+ sig_file = sig->filename;
+ script = sig->script;
+ format_html = sig->html;
+ break;
+ }
+ pos --;
+ }
+ }
}
-
if (!sig_file)
return NULL;
-
+ printf ("sig file: %s\n", sig_file);
+
+ mail_config_signature_run_script (script);
text = e_msg_composer_get_sig_file_content (sig_file, format_html);
+ /* printf ("text: %s\n", text); */
if (text) {
/* The signature dash convention ("-- \n") is specified in the
* "Son of RFC 1036": http://www.chemie.fu-berlin.de/outerspace/netnews/son-of-1036.html,
@@ -1483,7 +1511,7 @@ menu_file_insert_file_cb (BonoboUIComponent *uic,
if (file_name == NULL)
return;
- html = get_file_content (composer, file_name, TRUE, E_TEXT_TO_HTML_PRE);
+ html = get_file_content (composer, file_name, TRUE, E_TEXT_TO_HTML_PRE, TRUE);
if (html == NULL)
return;
@@ -1676,6 +1704,151 @@ static EPixmap pixcache [] = {
};
static void
+signature_regenerate_cb (BonoboUIComponent *uic, gpointer user_data, const char *path)
+{
+ printf ("signature_regenerate_cb: %s\n", path);
+
+ e_msg_composer_show_sig_file (E_MSG_COMPOSER (user_data));
+}
+
+static void
+signature_cb (BonoboUIComponent *uic, const char *path, Bonobo_UIComponent_EventType type,
+ const char *state, gpointer user_data)
+{
+ EMsgComposer *composer = (EMsgComposer *) user_data;
+
+ printf ("signature_cb: %s (%s)\n", path, state);
+
+ if (state && *state == '1') {
+ if (path && !strncmp (path, "Signature", 9)) {
+ MailConfigSignature *old_sig;
+ gboolean old_random;
+
+ old_sig = composer->signature;
+ old_random = composer->random_signature;
+
+ printf ("I'm going to set signature (%d)\n", atoi (path + 9));
+ if (path [9] == 'N') {
+ composer->signature = NULL;
+ composer->random_signature = FALSE;
+ } else if (path [9] == 'R') {
+ composer->signature = NULL;
+ composer->random_signature = TRUE;
+ } else {
+ composer->signature = g_list_nth_data (mail_config_get_signature_list (), atoi (path + 9));
+ composer->random_signature = FALSE;
+ }
+ if (old_sig != composer->signature || old_random != composer->random_signature)
+ e_msg_composer_show_sig_file (composer);
+ }
+ }
+
+ printf ("signature_cb end\n");
+}
+
+static void setup_signatures_menu (EMsgComposer *composer);
+
+static void
+remove_signature_list (EMsgComposer *composer)
+{
+ gchar path [64];
+ gint len = g_list_length (mail_config_get_signature_list ());
+
+ bonobo_ui_component_rm (composer->uic, "/menu/Edit/EditMisc/EditSignaturesSubmenu/SeparatorList", NULL);
+ bonobo_ui_component_rm (composer->uic, "/menu/Edit/EditMisc/EditSignaturesSubmenu/SeparatorRegenerate", NULL);
+ bonobo_ui_component_rm (composer->uic, "/menu/Edit/EditMisc/EditSignaturesSubmenu/SignatureRegenerate", NULL);
+ for (; len; len --) {
+ g_snprintf (path, 64, "/menu/Edit/EditMisc/EditSignaturesSubmenu/Signature%d", len - 1);
+ bonobo_ui_component_rm (composer->uic, path, NULL);
+ }
+}
+
+static void
+sig_event_client (MailConfigSigEvent event, MailConfigSignature *sig, EMsgComposer *composer)
+{
+ gchar *path;
+
+ bonobo_ui_component_freeze (composer->uic, NULL);
+ switch (event) {
+ case MAIL_CONFIG_SIG_EVENT_DELETED:
+ if (sig == composer->signature)
+ composer->signature = NULL;
+ path = g_strdup_printf ("/menu/Edit/EditMisc/EditSignaturesSubmenu/Signature%d",
+ g_list_length (mail_config_get_signature_list ()));
+ bonobo_ui_component_rm (composer->uic, path, NULL);
+ g_free (path);
+ setup_signatures_menu (composer);
+ break;
+ case MAIL_CONFIG_SIG_EVENT_RANDOM_OFF:
+ composer->random_signature = FALSE;
+ bonobo_ui_component_rm (composer->uic, "/menu/Edit/EditMisc/EditSignaturesSubmenu/SignatureRandom", NULL);
+ bonobo_ui_component_rm (composer->uic, "/menu/Edit/EditMisc/EditSignaturesSubmenu/SeparatorRandom", NULL);
+ setup_signatures_menu (composer);
+ break;
+ case MAIL_CONFIG_SIG_EVENT_RANDOM_ON:
+ remove_signature_list (composer);
+ setup_signatures_menu (composer);
+ break;
+ case MAIL_CONFIG_SIG_EVENT_ADDED:
+ case MAIL_CONFIG_SIG_EVENT_NAME_CHANGED:
+ setup_signatures_menu (composer);
+ }
+ bonobo_ui_component_thaw (composer->uic, NULL);
+}
+
+static void
+setup_signatures_menu (EMsgComposer *composer)
+{
+ GList *l, *list;
+ GString *str;
+ gchar *line;
+ gint i, len = 0;
+
+ str = g_string_new ("<submenu name=\"EditSignaturesSubmenu\" _label=\"Signatures\">\n"
+ "<menuitem name=\"SignatureNone\" _label=\"None\" verb=\"SignatureNone\""
+ " type=\"radio\" group=\"signatures_group\"/>\n");
+ if (mail_config_get_signatures_random ()) {
+ g_string_append (str,
+ "<separator name=\"SeparatorRandom\"/>\n"
+ "<menuitem name=\"SignatureRandom\" _label=\"Random\" verb=\"SignatureRandom\""
+ " type=\"radio\" group=\"signatures_group\"/>\n");
+ }
+
+ list = mail_config_get_signature_list ();
+ if (list) {
+
+ g_string_append (str, "<separator name=\"SeparatorList\"/>");
+
+ for (l = list; l; len ++, l = l->next) {
+ line = g_strdup_printf ("<menuitem name=\"Signature%d\" _label=\"%s\""
+ " verb=\"Signature%d\" type=\"radio\" group=\"signatures_group\"/>\n",
+ len, ((MailConfigSignature *)l->data)->name, len);
+ g_string_append (str, line);
+ g_free (line);
+ }
+ }
+
+ g_string_append (str,
+ "<separator name=\"SeparatorRegenerate\"/>\n"
+ "<menuitem name=\"SignatureRegenerate\" _label=\"_Regenerate\""
+ " verb=\"SignatureRegenerate\" accel=\"*Ctrl**Shift*G\"/>");
+ g_string_append (str, "</submenu>\n");
+
+ bonobo_ui_component_set_translate (composer->uic, "/menu/Edit/EditMisc/", str->str, NULL);
+ bonobo_ui_component_set (composer->uic, "/menu/Edit/EditMisc/", "<separator/>", NULL);
+
+ bonobo_ui_component_add_listener (composer->uic, "SignatureNone", signature_cb, composer);
+ bonobo_ui_component_add_listener (composer->uic, "SignatureRandom", signature_cb, composer);
+ bonobo_ui_component_add_verb (composer->uic, "SignatureRegenerate", signature_regenerate_cb, composer);
+
+ for (i = 0; i < len; i ++) {
+ g_string_sprintf (str, "Signature%d", i + 1);
+ bonobo_ui_component_add_listener (composer->uic, str->str, signature_cb, composer);
+ }
+ g_string_free (str, TRUE);
+}
+
+static void
setup_ui (EMsgComposer *composer)
{
BonoboUIContainer *container;
@@ -1826,6 +1999,9 @@ setup_ui (EMsgComposer *composer)
bonobo_ui_component_add_listener (
composer->uic, "ViewAttach",
menu_view_attachments_activate_cb, composer);
+
+ setup_signatures_menu (composer);
+ mail_config_signature_register_client ((MailConfigSignatureClient) sig_event_client, composer);
bonobo_ui_component_thaw (composer->uic, NULL);
}
@@ -2003,7 +2179,8 @@ from_changed_cb (EMsgComposerHdrs *hdrs, void *data)
update_auto_recipients (hdrs, UPDATE_AUTO_CC, NULL);
update_auto_recipients (hdrs, UPDATE_AUTO_BCC, NULL);
}
-
+
+ set_editor_signature (composer);
e_msg_composer_show_sig_file (composer);
}
@@ -2030,6 +2207,8 @@ destroy (GtkObject *object)
composer = E_MSG_COMPOSER (object);
+ mail_config_signature_register_client ((MailConfigSignatureClient) sig_event_client, composer);
+
CORBA_exception_init (&ev);
if (composer->config_db) {
@@ -2572,6 +2751,38 @@ create_composer (void)
return composer;
}
+static void
+set_editor_signature (EMsgComposer *composer)
+{
+ printf ("set_editor_signature\n");
+ if (E_MSG_COMPOSER_HDRS (composer->hdrs)->account->id) {
+ MailConfigIdentity *id;
+ gchar *verb, *name;
+
+ id = E_MSG_COMPOSER_HDRS (composer->hdrs)->account->id;
+
+ composer->random_signature = composer->send_html ? id->html_random : id->text_random;
+ if (composer->random_signature)
+ composer->signature = NULL;
+ else
+ composer->signature = composer->send_html ? id->html_signature : id->text_signature;
+
+ if (composer->random_signature) {
+ verb = g_strdup ("/commands/SignatureRandom");
+ name = g_strdup ("SignatureRandom");
+ } else if (composer->signature == NULL) {
+ verb = g_strdup ("/commands/SignatureNone");
+ name = g_strdup ("SignatureNone");
+ } else {
+ verb = g_strdup_printf ("/commands/Signature%d", composer->signature->id);
+ name = g_strdup_printf ("Signature%d", composer->signature->id);
+ }
+ bonobo_ui_component_set_prop (composer->uic, verb, "state", "1", NULL);
+ g_free (verb);
+ }
+ printf ("set_editor_signature end\n");
+}
+
/**
* e_msg_composer_new:
*
@@ -2588,6 +2799,7 @@ e_msg_composer_new (void)
if (new) {
e_msg_composer_set_send_html (new, mail_config_get_send_html ());
set_editor_text (new, "");
+ set_editor_signature (new);
}
return new;
@@ -2969,8 +3181,10 @@ e_msg_composer_new_with_message (CamelMimeMessage *message)
/* We wait until now to set the body text because we need to ensure that
* the attachment bar has all the attachments, before we request them.
- */
+ */
e_msg_composer_flush_pending_body (new, TRUE);
+
+ set_editor_signature (new);
return new;
}
@@ -3474,6 +3688,7 @@ e_msg_composer_show_sig_file (EMsgComposer *composer)
g_return_if_fail (composer != NULL);
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
+ printf ("e_msg_composer_show_sig_file\n");
/* printf ("set sig '%s' '%s'\n", sig_file, composer->sig_file); */
composer->in_signature_insert = TRUE;
@@ -3497,11 +3712,14 @@ e_msg_composer_show_sig_file (EMsgComposer *composer)
GNOME_GtkHTML_Editor_Engine_insertHTML (composer->editor_engine, html, &ev);
g_free (html);
}
+
GNOME_GtkHTML_Editor_Engine_undoEnd (composer->editor_engine, &ev);
GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "cursor-position-restore", &ev);
GNOME_GtkHTML_Editor_Engine_thaw (composer->editor_engine, &ev);
CORBA_exception_free (&ev);
composer->in_signature_insert = FALSE;
+
+ printf ("e_msg_composer_show_sig_file end\n");
}
/**
@@ -3538,6 +3756,7 @@ e_msg_composer_set_send_html (EMsgComposer *composer,
composer->send_html, NULL);
set_config (composer, "FormatHTML", composer->send_html);
+ set_editor_signature (composer);
e_msg_composer_show_sig_file (composer);
GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "unblock-redraw", &ev);
CORBA_exception_free (&ev);
diff --git a/composer/e-msg-composer.h b/composer/e-msg-composer.h
index 100760f87e..921dfc2ee1 100644
--- a/composer/e-msg-composer.h
+++ b/composer/e-msg-composer.h
@@ -99,6 +99,9 @@ struct _EMsgComposer {
gboolean enable_autosave : 1;
CamelMimeMessage *redirect;
+
+ MailConfigSignature *signature;
+ gboolean random_signature;
};
struct _EMsgComposerClass {