[evolution/wip/webkit-composer: 593/966] Initial attempt on signatures handling.
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit-composer: 593/966] Initial attempt on signatures handling.
- Date: Wed, 23 Apr 2014 10:43:16 +0000 (UTC)
commit eb4b2b978606312f680d7f36ae65848709d40176
Author: Dan Vrátil <dvratil redhat com>
Date: Thu Oct 11 01:07:27 2012 +0200
Initial attempt on signatures handling.
Still buggy, but we are on the right way
composer/e-composer-private.c | 179 +++++++++++++++-------------------------
composer/e-msg-composer.c | 28 ++++---
e-util/e-editor-selection.c | 97 ++++++++++++++++++++++
e-util/e-editor-selection.h | 3 +
mail/em-composer-utils.c | 26 ------
mail/em-utils.c | 2 +-
6 files changed, 184 insertions(+), 151 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index a3eaee5..408be29 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -970,8 +970,6 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
GAsyncResult *result,
EMsgComposer *composer)
{
- /* FIXME WEBKIT Uuuhm, yeah...we don't support signatures yet */
-#if 0
GString *html_buffer = NULL;
gchar *contents = NULL;
gsize length = 0;
@@ -981,24 +979,25 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
GError *error = NULL;
EEditor *editor;
EEditorWidget *editor_widget;
+ EEditorSelection *selection;
WebKitDOMDocument *document;
WebKitDOMNodeList *signatures;
+ WebKitDOMDOMWindow *window;
+ WebKitDOMDOMSelection *dom_selection;
gulong list_length, ii;
- GSettings *settings;
- gboolean start_bottom;
e_mail_signature_combo_box_load_selected_finish (
combo_box, result, &contents, &length, &is_html, &error);
- // FIXME Use an EAlert here.
+ /* FIXME Use an EAlert here.*/
if (error != NULL) {
g_warning ("%s: %s", G_STRFUNC, error->message);
g_error_free (error);
goto exit;
}
- // "Edit as New Message" sets "priv->is_from_message".
- //Always put the signature at the bottom for that case.
+ /* "Edit as New Message" sets "priv->is_from_message".
+ Always put the signature at the bottom for that case. */
top_signature =
use_top_signature (composer) &&
!composer->priv->is_from_message &&
@@ -1027,28 +1026,20 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
html_buffer = g_string_sized_new (1024);
- // The combo box active ID is the signature's ESource UID.
+ /* The combo box active ID is the signature's ESource UID. */
active_id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (combo_box));
g_string_append_printf (
html_buffer,
- "<!--+GtkHTML:<DATA class=\"ClueFlow\" "
- " key=\"signature\" value=\"1\">-->"
- "<!--+GtkHTML:<DATA class=\"ClueFlow\" "
- " key=\"signature_name\" value=\"uid:%s\"-->",
- (encoded_uid != NULL) ? encoded_uid : "");
-
- g_string_append (
- html_buffer,
- "<TABLE WIDTH=\"100%%\" CELLSPACING=\"0\""
- " CELLPADDING=\"0\"><TR><TD>");
+ "<SPAN class=\"-x-evolution-signature\" id=\"1\" name=\"%s\">",
+ (active_id != NULL) ? active_id : "");
if (!is_html)
g_string_append (html_buffer, "<PRE>\n");
- // 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
+ /* 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;
@@ -1061,7 +1052,7 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
delim_nl = "\n-- \n";
}
- // Skip the delimiter if the signature already has one.
+ /* 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)
@@ -1075,119 +1066,85 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
if (!is_html)
g_string_append (html_buffer, "</PRE>\n");
+ if (top_signature)
+ g_string_append (html_buffer, "<BR>");
+
g_string_append (html_buffer, "</SPAN>");
g_free (contents);
-insert:
- // Remove the old signature and insert the new one.
+ g_message ("Inserting signature: %s", html_buffer->str);
- editor = e_msg_composer_get_editor (composer);
+insert:
+ /* Remove the old signature and insert the new one. */
+ editor = e_editor_window_get_editor (E_EDITOR_WINDOW (composer));
editor_widget = e_editor_get_editor_widget (editor);
+ selection = e_editor_widget_get_selection (editor_widget);
+
+ e_editor_selection_save (selection);
+
+ /* This prevents our command before/after callbacks from
+ screwing around with the signature as we insert it. */
+ composer->priv->in_signature_insert = TRUE;
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (editor_widget));
+ window = webkit_dom_document_get_default_view (document);
+ dom_selection = webkit_dom_dom_window_get_selection (window);
- signatures = webkit_dom_document_get_elements_by_class_name (
- document, "-x-evolution-signature");
+ signatures = webkit_dom_document_get_elements_by_class_name (document, "-x-evolution-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;
- }
-
- // This prevents our command before/after callbacks from
- screwing around with the signature as we insert it.
- composer->priv->in_signature_insert = TRUE;
+ id = webkit_dom_html_element_get_id (WEBKIT_DOM_HTML_ELEMENT (node));
- 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;
+ if (id && (strlen (id) == 1) && (*id == '1')) {
+ webkit_dom_node_remove_child (
+ webkit_dom_node_get_parent_node (node), node, NULL);
+ g_free (id);
+ break;
}
g_free (id);
}
+ if (top_signature) {
+ WebKitDOMElement *citation;
+
+ citation = webkit_dom_document_get_element_by_id (
+ document, "-x-evolution-reply-citation");
+ if (!citation) {
+ webkit_dom_dom_selection_modify (
+ dom_selection, "move", "forward", "documentBoundary");
+ } else {
+ webkit_dom_dom_selection_set_base_and_extent (
+ dom_selection, WEBKIT_DOM_NODE (citation), 0,
+ WEBKIT_DOM_NODE (citation), 0, NULL);
+ }
+ } else {
+ webkit_dom_dom_selection_modify (
+ dom_selection, "move", "forward", "documentBoundary");
+ }
+
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_html_element_set_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (element), html_buffer->str, NULL);
-
- if (top_signature) {
- WebKitDOMNode *child =
- webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
-
- if (start_bottom) {
- 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 */
- 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);
- }
- } else {
- webkit_dom_node_append_child (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (element),
- NULL);
- }
+ webkit_dom_document_exec_command (
+ document, "insertParagraph", FALSE, "");
+ e_editor_selection_insert_html (selection, html_buffer->str);
+ webkit_dom_document_exec_command (
+ document, "insertParagraph", FALSE, "");
}
g_string_free (html_buffer, TRUE);
-
- } else if (top_signature) {
- // Insert paragraph after the signature ClueFlow stuff.
- if (gtkhtml_editor_run_command (editor, "cursor-forward"))
- gtkhtml_editor_run_command (editor, "insert-paragraph");
}
- composer_move_caret (composer);
+ e_editor_selection_restore (selection);
+
+ composer->priv->in_signature_insert = FALSE;
exit:
g_object_unref (composer);
-#endif
}
static void
@@ -1213,7 +1170,6 @@ composer_web_view_load_status_changed_cb (WebKitWebView *webkit_web_view,
void
e_composer_update_signature (EMsgComposer *composer)
{
- /* FIXME WEBKIT As said above...no signatures yet
EComposerHeaderTable *table;
EMailSignatureComboBox *combo_box;
EEditor *editor;
@@ -1222,7 +1178,7 @@ e_composer_update_signature (EMsgComposer *composer)
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
- // Do nothing if we're redirecting a message.
+ /* Do nothing if we're redirecting a message. */
if (composer->priv->redirect)
return;
@@ -1244,14 +1200,13 @@ e_composer_update_signature (EMsgComposer *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.
+ /*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));
- */
}
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 994d2e0..431c716 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -3089,8 +3089,10 @@ handle_multipart (EMsgComposer *composer,
static void
set_signature_gui (EMsgComposer *composer)
{
- /*FIXME WEBKIT We don't support signatures yet....
- GtkhtmlEditor *editor;
+ EEditor *editor;
+ EEditorWidget *widget;
+ WebKitDOMDocument *document;
+ WebKitDOMNodeList *nodes;
EComposerHeaderTable *table;
EMailSignatureComboBox *combo_box;
gchar *uid;
@@ -3099,34 +3101,36 @@ set_signature_gui (EMsgComposer *composer)
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);
+
+ editor = e_editor_window_get_editor (E_EDITOR_WINDOW (composer));
widget = e_editor_get_editor_widget (editor);
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (widget));
uid = NULL;
nodes = webkit_dom_document_get_elements_by_class_name (
- document, "-x-evolution-signature");
+ document, "-x-evolution-signature");
length = webkit_dom_node_list_get_length (nodes);
for (ii = 0; ii < length; ii++) {
WebKitDOMNode *node;
gchar *id;
node = webkit_dom_node_list_item (nodes, ii);
- id = webkit_dom_element_get_id (WEBKIT_DOM_ELEMENT (node));
+ id = webkit_dom_html_element_get_id (WEBKIT_DOM_HTML_ELEMENT (node));
if (id && (strlen (id) == 1) && (*id == '1')) {
- uid = webkit_dom_element_get_attribute (
- WEBKIT_DOM_ELEMENT (node), "name");
- g_free (id);
- break;
+ uid = webkit_dom_element_get_attribute (
+ WEBKIT_DOM_ELEMENT (node), "name");
+ g_free (id);
+ break;
}
g_free (id);
}
+ if (!uid) {
+ return;
+ }
// The combo box active ID is the signature's ESource UID.
- uid = e_composer_decode_clue_value (data + 4);
gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo_box), uid);
g_free (uid);
- */
}
static void
@@ -4988,7 +4992,7 @@ void
e_msg_composer_reply_indent (EMsgComposer *composer)
{
/* FIXME WEBKIT We already have indentation implementation. Why
- * is this done?
+ * is this done?
GtkhtmlEditor *editor;
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 0358a87..578f3f3 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -47,6 +47,8 @@ struct _EEditorSelectionPrivate {
gchar *background_color;
gchar *font_color;
gchar *font_family;
+
+ gulong selection_offset;
};
G_DEFINE_TYPE (
@@ -1632,3 +1634,98 @@ e_editor_selection_wrap_lines (EEditorSelection *selection)
g_free (html);
}
+
+void
+e_editor_selection_save (EEditorSelection* selection)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMRange *range;
+ WebKitDOMNode *container, *split;
+ WebKitDOMElement *marker;
+
+
+ g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
+
+ document = webkit_web_view_get_dom_document (selection->priv->webview);
+
+ /* First remove all markers (if present) */
+ marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evolution-selection-start-marker");
+ if (marker) {
+ webkit_dom_node_remove_child (
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (marker)),
+ WEBKIT_DOM_NODE (marker), NULL);
+ }
+
+ marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evolution-selection-end-marker");
+ if (marker) {
+ webkit_dom_node_remove_child (
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (marker)),
+ WEBKIT_DOM_NODE (marker), NULL);
+ }
+
+ range = editor_selection_get_current_range (selection);
+
+ marker = webkit_dom_document_create_element (document, "SPAN", NULL);
+ webkit_dom_html_element_set_id (
+ WEBKIT_DOM_HTML_ELEMENT (marker), "-x-evolution-selection-start-marker");
+ container = webkit_dom_range_get_start_container (range, NULL);
+ if (!WEBKIT_DOM_IS_TEXT (container)) {
+ split = container;
+ } else {
+ split = WEBKIT_DOM_NODE (webkit_dom_text_split_text (
+ (WebKitDOMText *) container,
+ webkit_dom_range_get_start_offset (range, NULL),
+ NULL));
+ }
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (container),
+ WEBKIT_DOM_NODE (marker), split, NULL);
+
+ marker = webkit_dom_document_create_element (document, "SPAN", NULL);
+ webkit_dom_html_element_set_id (
+ WEBKIT_DOM_HTML_ELEMENT (marker), "-x-evolution-selection-end-marker");
+ container = webkit_dom_range_get_end_container (range, NULL);
+ if (!WEBKIT_DOM_IS_TEXT (container)) {
+ split = container;
+ } else {
+ split = WEBKIT_DOM_NODE (webkit_dom_text_split_text (
+ (WebKitDOMText *) container,
+ webkit_dom_range_get_start_offset (range, NULL),
+ NULL));
+ }
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (container),
+ WEBKIT_DOM_NODE (marker), split, NULL);
+}
+
+
+void
+e_editor_selection_restore (EEditorSelection* selection)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMRange *range;
+ WebKitDOMElement *marker;
+
+ g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
+
+ document = webkit_web_view_get_dom_document (selection->priv->webview);
+ range = editor_selection_get_current_range (selection);
+
+ marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evolution-selection-start-marker");
+ g_return_if_fail (marker != NULL);
+ webkit_dom_range_set_start_after (range, WEBKIT_DOM_NODE (marker), NULL);
+ webkit_dom_node_remove_child (
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (marker)),
+ WEBKIT_DOM_NODE (marker), NULL);
+
+ marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evolution-selection-end-marker");
+ g_return_if_fail (marker != NULL);
+ webkit_dom_range_set_end_before (range, WEBKIT_DOM_NODE (marker), NULL);
+ webkit_dom_node_remove_child (
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (marker)),
+ WEBKIT_DOM_NODE (marker), NULL);
+}
diff --git a/e-util/e-editor-selection.h b/e-util/e-editor-selection.h
index f8e62ac..3914a59 100644
--- a/e-util/e-editor-selection.h
+++ b/e-util/e-editor-selection.h
@@ -205,6 +205,9 @@ void e_editor_selection_insert_text (EEditorSelection *selection,
const gchar *plain_text);
void e_editor_selection_wrap_lines (EEditorSelection *selection);
+void e_editor_selection_save (EEditorSelection *selection);
+void e_editor_selection_restore (EEditorSelection *selection);
+
G_END_DECLS
#endif /* E_EDITOR_SELECTION_H */
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index d396cf3..22426c3 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -2879,32 +2879,6 @@ composer_set_body (EMsgComposer *composer,
break;
}
- /* FIXME WEBKIT No signature yet...
- if (has_body_text && start_bottom) {
- GtkhtmlEditor *editor = GTKHTML_EDITOR (composer);
- gboolean move_cursor_to_end;
- gboolean top_signature;
-
- // If we are placing signature on top, then move cursor to the end,
- // otherwise try to find the signature place and place cursor just
- // before the signature. We added there an empty line already.
- gtkhtml_editor_run_command (editor, "block-selection");
- gtkhtml_editor_run_command (editor, "cursor-bod");
-
- top_signature = g_settings_get_boolean (settings, "composer-top-signature");
-
- move_cursor_to_end = top_signature ||
- !gtkhtml_editor_search_by_data (
- editor, 1, "ClueFlow", "signature", "1");
-
- if (move_cursor_to_end)
- gtkhtml_editor_run_command (editor, "cursor-eod");
- else
- gtkhtml_editor_run_command (editor, "selection-move-left");
- gtkhtml_editor_run_command (editor, "unblock-selection");
- }
- */
-
g_object_unref (settings);
g_object_unref (session);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 44556b9..a6aae98 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1191,7 +1191,7 @@ em_utils_message_to_html (CamelSession *session,
const gchar *credits,
guint32 flags,
EMailPartList *parts_list,
- const gchar *prepend,
+ const gchar *prepend,
const gchar *append,
EMailPartValidityFlags *validity_found)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]