",
(active_id != NULL) ? active_id : "");
if (!is_html)
g_string_append (html_buffer, "");
/* The signature dash convention ("-- \n") is specified
* in the "Son of RFC 1036", section 4.3.2.
* http://www.chemie.fu-berlin.de/outerspace/netnews/son-of-1036.html
*/
if (add_signature_delimiter (composer)) {
const gchar *delim;
const gchar *delim_nl;
if (is_html) {
delim = "--
";
delim_nl = "\n--
";
} else {
delim = "-- \n";
delim_nl = "\n-- \n";
}
/* Skip the delimiter if the signature already has one. */
if (g_ascii_strncasecmp (contents, delim, strlen (delim)) == 0)
; /* skip */
else if (e_util_strstrcase (contents, delim_nl) != NULL)
; /* skip */
else
g_string_append (html_buffer, delim);
}
g_string_append_len (html_buffer, contents, length);
if (!is_html)
g_string_append (html_buffer, "
");
g_string_append (html_buffer, "");
g_free (contents);
insert:
/* Remove the old signature and insert the new one. */
editor = e_msg_composer_get_editor (composer);
view = e_html_editor_get_view (editor);
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
signatures = webkit_dom_document_get_elements_by_class_name (
document, "-x-evo-signature");
list_length = webkit_dom_node_list_get_length (signatures);
for (ii = 0; ii < list_length; ii++) {
WebKitDOMNode *node;
gchar *id;
node = webkit_dom_node_list_item (signatures, ii);
id = webkit_dom_element_get_id (WEBKIT_DOM_ELEMENT (node));
/* When we are editing a message with signature we need to set active
* signature id in signature combo box otherwise no signature will be
* added but we have to do it just once when the composer opens */
if (composer->priv->is_from_message && composer->priv->set_signature_from_message) {
gchar *name = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "name");
gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo_box), name);
g_free (name);
composer->priv->set_signature_from_message = FALSE;
}
if (id && (strlen (id) == 1) && (*id == '1')) {
/* We have to remove the div containing the span with signature */
WebKitDOMNode *next_sibling;
WebKitDOMNode *parent;
parent = webkit_dom_node_get_parent_node (node);
next_sibling = webkit_dom_node_get_next_sibling (parent);
if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (next_sibling))
webkit_dom_node_remove_child (
webkit_dom_node_get_parent_node (next_sibling),
next_sibling,
NULL);
webkit_dom_node_remove_child (
webkit_dom_node_get_parent_node (parent),
parent,
NULL);
g_free (id);
break;
}
g_free (id);
}
if (html_buffer != NULL) {
if (*html_buffer->str) {
WebKitDOMElement *element;
WebKitDOMHTMLElement *body;
body = webkit_dom_document_get_body (document);
element = webkit_dom_document_create_element (document, "DIV", NULL);
webkit_dom_element_set_class_name (element, "-x-evo-signature-wrapper");
webkit_dom_html_element_set_inner_html (
WEBKIT_DOM_HTML_ELEMENT (element), html_buffer->str, NULL);
if (top_signature) {
WebKitDOMNode *signature_inserted;
WebKitDOMNode *child =
webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
WebKitDOMElement *br =
webkit_dom_document_create_element (
document, "br", NULL);
if (start_bottom) {
signature_inserted = webkit_dom_node_insert_before (
WEBKIT_DOM_NODE (body),
WEBKIT_DOM_NODE (element),
child,
NULL);
} else {
WebKitDOMElement *input_start =
webkit_dom_document_get_element_by_id (
document, "-x-evo-input-start");
/* When we are using signature on top the caret
* should be before the signature */
signature_inserted = webkit_dom_node_insert_before (
WEBKIT_DOM_NODE (body),
WEBKIT_DOM_NODE (element),
input_start ?
webkit_dom_node_get_next_sibling (
WEBKIT_DOM_NODE (input_start)) :
child,
NULL);
}
webkit_dom_node_insert_before (
WEBKIT_DOM_NODE (body),
WEBKIT_DOM_NODE (br),
webkit_dom_node_get_next_sibling (signature_inserted),
NULL);
} else {
webkit_dom_node_append_child (
WEBKIT_DOM_NODE (body),
WEBKIT_DOM_NODE (element),
NULL);
}
}
g_string_free (html_buffer, TRUE);
}
composer_move_caret (composer);
exit:
g_object_unref (composer);
}
static void
composer_web_view_load_status_changed_cb (WebKitWebView *webkit_web_view,
GParamSpec *pspec,
EMsgComposer *composer)
{
WebKitLoadStatus status;
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
status = webkit_web_view_get_load_status (webkit_web_view);
if (status != WEBKIT_LOAD_FINISHED)
return;
g_signal_handlers_disconnect_by_func (
webkit_web_view,
G_CALLBACK (composer_web_view_load_status_changed_cb),
NULL);
e_composer_update_signature (composer);
}
void
e_composer_update_signature (EMsgComposer *composer)
{
EComposerHeaderTable *table;
EMailSignatureComboBox *combo_box;
EHTMLEditor *editor;
EHTMLEditorView *view;
WebKitLoadStatus status;
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
/* Do nothing if we're redirecting a message or we disabled the signature * on purpose */
if (composer->priv->redirect || composer->priv->disable_signature)
return;
table = e_msg_composer_get_header_table (composer);
combo_box = e_composer_header_table_get_signature_combo_box (table);
editor = e_msg_composer_get_editor (composer);
view = e_html_editor_get_view (editor);
status = webkit_web_view_get_load_status (WEBKIT_WEB_VIEW (view));
/* If document is not loaded, we will wait for him */
if (status != WEBKIT_LOAD_FINISHED) {
/* Disconnect previous handlers */
g_signal_handlers_disconnect_by_func (
WEBKIT_WEB_VIEW (view),
G_CALLBACK (composer_web_view_load_status_changed_cb),
composer);
g_signal_connect (
WEBKIT_WEB_VIEW(view), "notify::load-status",
G_CALLBACK (composer_web_view_load_status_changed_cb),
composer);
return;
}
/* XXX Signature files should be local and therefore load quickly,
* so while we do load them asynchronously we don't allow for
* user cancellation and we keep the composer alive until the
* asynchronous loading is complete. */
e_mail_signature_combo_box_load_selected (
combo_box, G_PRIORITY_DEFAULT, NULL,
(GAsyncReadyCallback) composer_load_signature_cb,
g_object_ref (composer));
}