aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadek Doulik <rodo@ximian.com>2001-04-25 17:31:56 +0800
committerRadek Doulik <rodo@src.gnome.org>2001-04-25 17:31:56 +0800
commit0f25a9078109a26a08f909c6d2c34e1289c543d8 (patch)
tree40fd9a8a093861ed686fadb1666f49edfa3f6efe
parent65464a8165e62f342a8164a02024ce29f1b0bfe6 (diff)
downloadgsoc2013-evolution-0f25a9078109a26a08f909c6d2c34e1289c543d8.tar.gz
gsoc2013-evolution-0f25a9078109a26a08f909c6d2c34e1289c543d8.tar.zst
gsoc2013-evolution-0f25a9078109a26a08f909c6d2c34e1289c543d8.zip
signature changing
* signature changing 2001-04-25 Radek Doulik <rodo@ximian.com> * listener.c (impl_event): reflect object data type change * e-msg-composer.c (get_sig_file_content): renamed from get_signature (get_signature_html): new helper function, uses get_sig_file_content (set_editor_text): removed signature parameters (from_changed_cb): new signal handler, sets signature by identity change (delete_old_signature): new function, deletes old signature from the document (e_msg_composer_set_sig_file): new method, set's signature filename (e_msg_composer_mark_text_orig): removed (obsolete) * e-msg-composer-hdrs.c: added signal FROM_CHANGED svn path=/trunk/; revision=9557
-rw-r--r--composer/ChangeLog19
-rw-r--r--composer/e-msg-composer-hdrs.c11
-rw-r--r--composer/e-msg-composer-hdrs.h2
-rw-r--r--composer/e-msg-composer.c157
-rw-r--r--composer/e-msg-composer.h1
-rw-r--r--composer/listener.c17
6 files changed, 142 insertions, 65 deletions
diff --git a/composer/ChangeLog b/composer/ChangeLog
index a4c1fd9a7c..12ac7e54be 100644
--- a/composer/ChangeLog
+++ b/composer/ChangeLog
@@ -1,3 +1,22 @@
+2001-04-25 Radek Doulik <rodo@ximian.com>
+
+ * listener.c (impl_event): reflect object data type change
+
+ * e-msg-composer.c (get_sig_file_content): renamed from
+ get_signature
+ (get_signature_html): new helper function, uses
+ get_sig_file_content
+ (set_editor_text): removed signature parameters
+ (from_changed_cb): new signal handler, sets signature by identity
+ change
+ (delete_old_signature): new function, deletes old signature from
+ the document
+ (e_msg_composer_set_sig_file): new method, set's signature
+ filename
+ (e_msg_composer_mark_text_orig): removed (obsolete)
+
+ * e-msg-composer-hdrs.c: added signal FROM_CHANGED
+
2001-04-21 Duncan Mak <duncan@ximian.com>
* e-msg-composer.c (e_msg_composer_construct): Set window_icon to
diff --git a/composer/e-msg-composer-hdrs.c b/composer/e-msg-composer-hdrs.c
index ca618f5b35..d31ac118fc 100644
--- a/composer/e-msg-composer-hdrs.c
+++ b/composer/e-msg-composer-hdrs.c
@@ -83,6 +83,7 @@ enum {
SHOW_ADDRESS_DIALOG,
SUBJECT_CHANGED,
HDRS_CHANGED,
+ FROM_CHANGED,
LAST_SIGNAL
};
@@ -170,6 +171,7 @@ from_changed (GtkWidget *item, gpointer data)
EMsgComposerHdrs *hdrs = E_MSG_COMPOSER_HDRS (data);
hdrs->account = gtk_object_get_data (GTK_OBJECT (item), "account");
+ gtk_signal_emit (GTK_OBJECT (hdrs), signals [FROM_CHANGED]);
}
static GtkWidget *
@@ -557,6 +559,15 @@ class_init (EMsgComposerHdrsClass *class)
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
+ signals[FROM_CHANGED] =
+ gtk_signal_new ("from_changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (EMsgComposerHdrsClass,
+ from_changed),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+
gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
}
diff --git a/composer/e-msg-composer-hdrs.h b/composer/e-msg-composer-hdrs.h
index dcf2ac1d8e..5532289c37 100644
--- a/composer/e-msg-composer-hdrs.h
+++ b/composer/e-msg-composer-hdrs.h
@@ -62,6 +62,8 @@ struct _EMsgComposerHdrsClass {
void (* subject_changed) (EMsgComposerHdrs *hdrs, gchar *subject);
void (* hdrs_changed) (EMsgComposerHdrs *hdrs);
+
+ void (* from_changed) (EMsgComposerHdrs *hdrs);
};
typedef enum {
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 1e8d116c6c..b7af77d89a 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -182,7 +182,7 @@ best_content (gchar *plain)
} else {
result = g_strdup ("text/plain");
}
-
+
return result;
}
@@ -508,7 +508,7 @@ build_message (EMsgComposer *composer)
}
static char *
-get_signature (const char *sigfile, gboolean in_html)
+get_sig_file_content (const char *sigfile, gboolean in_html)
{
GString *rawsig;
gchar buf[1024];
@@ -578,67 +578,49 @@ prepare_engine (EMsgComposer *composer)
CORBA_exception_free (&ev);
}
-void
-e_msg_composer_mark_text_orig (EMsgComposer *composer)
+static gchar *
+get_signature_html (EMsgComposer *composer)
{
- g_assert (composer);
- g_assert (E_IS_MSG_COMPOSER (composer));
+ gboolean format_html = composer->send_html;
+ gchar *text, *html = NULL;
- if (composer->editor_engine != CORBA_OBJECT_NIL) {
- CORBA_Environment ev;
- CORBA_any *flag = bonobo_arg_new (TC_boolean);
- *((CORBA_boolean *) flag->_value) = CORBA_TRUE;
+ text = get_sig_file_content (composer->sig_file, format_html);
+ /* if we tried HTML sig and it's not available, try also non HTML signature */
+ if (format_html && !text) {
+ format_html = FALSE;
+ text = get_sig_file_content (composer->sig_file, format_html);
+ }
- CORBA_exception_init (&ev);
- GNOME_GtkHTML_Editor_Engine_setObjectDataByType (composer->editor_engine, "ClueFlow", "orig", flag, &ev);
- CORBA_free (flag);
- CORBA_exception_free (&ev);
+ if (text) {
+ html = g_strdup_printf ("<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature\" value=\"1\">-->%s%s%s%s",
+ format_html ? "" : "<PRE>\n",
+ format_html || !strncmp ("-- \n", text, 3) ? "" : "--\n",
+ text,
+ format_html ? "" : "</PRE>\n");
+ g_free (text);
+ text = html;
}
+
+ return text;
}
static void
-set_editor_text (EMsgComposer *composer, const char *sig_file, const char *text)
+set_editor_text (EMsgComposer *composer, const char *text)
{
Bonobo_PersistStream persist;
BonoboStream *stream;
BonoboWidget *editor;
CORBA_Environment ev;
- char *sig, *fulltext;
- gboolean html_sig = composer->send_html;
editor = BONOBO_WIDGET (composer->editor);
- sig = get_signature (sig_file, html_sig);
- /* if we tried HTML sig and it's not available, try also non HTML signature */
- if (html_sig && !sig) {
- html_sig = FALSE;
- sig = get_signature (sig_file, html_sig);
- }
-
- if (sig) {
- if (html_sig)
- fulltext = g_strdup_printf ("%s<br>%s",
- text, sig);
- else if (!strncmp ("-- \n", sig, 3))
- fulltext = g_strdup_printf ("%s<br>\n<pre>\n%s</pre>",
- text, sig);
- else
- fulltext = g_strdup_printf ("%s<br>\n<pre>\n-- \n%s</pre>",
- text, sig);
- } else {
- if (!*text)
- return;
- fulltext = (char*)text;
- }
CORBA_exception_init (&ev);
persist = (Bonobo_PersistStream) bonobo_object_client_query_interface (
bonobo_widget_get_server (editor), "IDL:Bonobo/PersistStream:1.0", &ev);
g_assert (persist != CORBA_OBJECT_NIL);
- stream = bonobo_stream_mem_create (fulltext, strlen (fulltext),
+ stream = bonobo_stream_mem_create (text, strlen (text),
TRUE, FALSE);
- if (sig)
- g_free (fulltext);
Bonobo_PersistStream_load (persist, (Bonobo_Stream)bonobo_object_corba_objref (BONOBO_OBJECT (stream)),
"text/html", &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
@@ -1422,6 +1404,17 @@ hdrs_changed_cb (EMsgComposerHdrs *hdrs,
e_msg_composer_set_changed (composer);
}
+static void
+from_changed_cb (EMsgComposerHdrs *hdrs,
+ void *data)
+{
+ EMsgComposer *composer;
+
+ composer = E_MSG_COMPOSER (data);
+
+ e_msg_composer_set_sig_file (composer, hdrs->account->id->signature);
+}
+
/* GtkObject methods. */
@@ -1759,6 +1752,8 @@ e_msg_composer_construct (EMsgComposer *composer)
GTK_SIGNAL_FUNC (subject_changed_cb), composer);
gtk_signal_connect (GTK_OBJECT (composer->hdrs), "hdrs_changed",
GTK_SIGNAL_FUNC (hdrs_changed_cb), composer);
+ gtk_signal_connect (GTK_OBJECT (composer->hdrs), "from_changed",
+ GTK_SIGNAL_FUNC (from_changed_cb), composer);
gtk_widget_show (composer->hdrs);
/* Editor component. */
@@ -1849,11 +1844,9 @@ e_msg_composer_new (void)
EMsgComposer *new;
new = create_composer ();
- if (new) {
- /* Load the signature, if any. */
- set_editor_text (new, NULL, "");
- }
-
+ if (new)
+ set_editor_text (new, "<BR>");
+
return new;
}
@@ -1868,15 +1861,15 @@ EMsgComposer *
e_msg_composer_new_with_sig_file (const char *sig_file, gboolean send_html)
{
EMsgComposer *new;
-
+
new = create_composer ();
if (new) {
e_msg_composer_set_send_html (new, send_html);
- /* Load the signature, if any. */
- set_editor_text (new, sig_file, "");
-
+ set_editor_text (new, "<BR>");
e_msg_composer_set_sig_file (new, sig_file);
}
+
+ /* printf ("e_msg_composer_new_with_sig_file %p\n", new); */
return new;
}
@@ -2240,7 +2233,7 @@ e_msg_composer_new_from_url (const char *url)
if (body) {
char *htmlbody = e_text_to_html (body, E_TEXT_TO_HTML_PRE);
- set_editor_text (composer, NULL, htmlbody);
+ set_editor_text (composer, htmlbody);
g_free (htmlbody);
}
@@ -2310,7 +2303,8 @@ e_msg_composer_set_body_text (EMsgComposer *composer, const char *text)
{
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
- set_editor_text (composer, composer->sig_file, text);
+ set_editor_text (composer, text);
+ e_msg_composer_set_sig_file (composer, composer->sig_file);
}
@@ -2378,6 +2372,28 @@ e_msg_composer_get_message (EMsgComposer *composer)
+static void
+delete_old_signature (EMsgComposer *composer)
+{
+ CORBA_Environment ev;
+ CORBA_boolean rv;
+
+ /* printf ("delete_old_signature\n"); */
+ CORBA_exception_init (&ev);
+ GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "cursor-bod", &ev);
+ while (GNOME_GtkHTML_Editor_Engine_searchByData (composer->editor_engine, 1, "ClueFlow", "signature", "1", &ev)) {
+ /* printf ("found\n"); */
+ GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "select-paragraph", &ev);
+ rv = GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "selection-move-right", &ev);
+ GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "delete", &ev);
+ /* selection-move-right doesn't succeed means that we are already on the end of document */
+ if (!rv)
+ break;
+ }
+ GNOME_GtkHTML_Editor_Engine_setParagraphData (composer->editor_engine, "signature", "0", &ev);
+ CORBA_exception_free (&ev);
+}
+
/**
* e_msg_composer_set_sig:
* @composer: A message composer widget
@@ -2388,10 +2404,39 @@ e_msg_composer_get_message (EMsgComposer *composer)
void
e_msg_composer_set_sig_file (EMsgComposer *composer, const char *sig_file)
{
+ CORBA_Environment ev;
+ gchar *html;
+
g_return_if_fail (composer != NULL);
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
-
- composer->sig_file = g_strdup (sig_file);
+
+ /* printf ("set sig '%s' '%s'\n", sig_file, composer->sig_file); */
+
+ CORBA_exception_init (&ev);
+ GNOME_GtkHTML_Editor_Engine_freeze (composer->editor_engine, &ev);
+ GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "cursor-position-save", &ev);
+ GNOME_GtkHTML_Editor_Engine_undo_begin (composer->editor_engine, "Set signature", "Reset signature", &ev);
+ if (composer->sig_file)
+ delete_old_signature (composer);
+
+ if (composer->sig_file != sig_file && (!sig_file || !composer->sig_file || strcmp (composer->sig_file, sig_file))) {
+ g_free (composer->sig_file);
+ composer->sig_file = g_strdup (sig_file);
+ }
+
+ html = get_signature_html (composer);
+ if (html) {
+ GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "cursor-eod", &ev);
+ if (!GNOME_GtkHTML_Editor_Engine_isParagraphEmpty (composer->editor_engine, &ev))
+ GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "insert-paragraph", &ev);
+ /* printf ("insert %s\n", html); */
+ GNOME_GtkHTML_Editor_Engine_insertHTML (composer->editor_engine, html, &ev);
+ g_free (html);
+ }
+ GNOME_GtkHTML_Editor_Engine_undo_end (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);
}
/**
@@ -2442,6 +2487,8 @@ e_msg_composer_set_send_html (EMsgComposer *composer,
composer->send_html, NULL);
set_config (composer, "FormatHTML", composer->send_html);
+ if (composer->sig_file)
+ e_msg_composer_set_sig_file (composer, composer->sig_file);
}
/**
diff --git a/composer/e-msg-composer.h b/composer/e-msg-composer.h
index 990be1edb4..461430fd90 100644
--- a/composer/e-msg-composer.h
+++ b/composer/e-msg-composer.h
@@ -112,7 +112,6 @@ void e_msg_composer_set_headers (EMsgComposer *compose
const char *subject);
void e_msg_composer_set_body_text (EMsgComposer *composer,
const char *text);
-void e_msg_composer_mark_text_orig (EMsgComposer *composer);
void e_msg_composer_add_header (EMsgComposer *composer,
const char *name,
const char *value);
diff --git a/composer/listener.c b/composer/listener.c
index 7b04aeef5d..8b13b0be64 100644
--- a/composer/listener.c
+++ b/composer/listener.c
@@ -96,23 +96,22 @@ reply_indent (EditorListener *l, CORBA_Environment * ev)
static CORBA_any *
impl_event (PortableServer_Servant _servant,
- const CORBA_char * name, const CORBA_any * arg,
- CORBA_Environment * ev)
+ const CORBA_char * name, const CORBA_any * arg,
+ CORBA_Environment * ev)
{
EditorListener *l = listener_from_servant (_servant);
- BonoboArg *data;
- CORBA_any *rv = NULL;
+ CORBA_any *rv = NULL;
+ CORBA_char *orig;
/* printf ("impl_event\n"); */
if (!strcmp (name, "command")) {
/* FIXME check for insert-paragraph command */
- data = GNOME_GtkHTML_Editor_Engine_getParagraphData (l->composer->editor_engine, "orig", ev);
- if (ev->_major == CORBA_NO_EXCEPTION && data) {
- if (CORBA_TypeCode_equal (data->_type, TC_boolean, ev) && BONOBO_ARG_GET_BOOLEAN (data))
+ orig = GNOME_GtkHTML_Editor_Engine_getParagraphData (l->composer->editor_engine, "orig", ev);
+ if (ev->_major == CORBA_NO_EXCEPTION) {
+ if (!strcmp (orig, "1"))
reply_indent (l, ev);
- BONOBO_ARG_SET_BOOLEAN (data, CORBA_FALSE);
- GNOME_GtkHTML_Editor_Engine_setParagraphData (l->composer->editor_engine, "orig", data, ev);
+ GNOME_GtkHTML_Editor_Engine_setParagraphData (l->composer->editor_engine, "orig", "0", ev);
}
} else if (!strcmp (name, "image_url")) {
gchar *url;