/pidgin/main: 6ba80150e4c3: Fix the buttons in the XMPP Console ...
Elliott Sales de Andrade
qulogic at pidgin.im
Fri Jun 15 03:12:27 EDT 2012
Changeset: 6ba80150e4c38739b53f00a11576878739adc380
Author: Elliott Sales de Andrade <qulogic at pidgin.im>
Date: 2012-06-15 02:55 -0400
Branch: default
URL: http://hg.pidgin.im/pidgin/main/rev/6ba80150e4c3
Description:
Fix the buttons in the XMPP Console plugin.
They were still using the old GtkTextBuffer stuff that doesn't work
with WebKit.
diffstat:
pidgin/plugins/xmppconsole.c | 106 +++++++++++++++++++++++-------------------
1 files changed, 59 insertions(+), 47 deletions(-)
diffs (204 lines):
diff --git a/pidgin/plugins/xmppconsole.c b/pidgin/plugins/xmppconsole.c
--- a/pidgin/plugins/xmppconsole.c
+++ b/pidgin/plugins/xmppconsole.c
@@ -59,6 +59,14 @@
"span.value { color: #324aa4; }" \
"span.xmlns { color: #2cb12f; font-weight: bold;}" \
"</style></head></html>"
+#define SET_CURSOR \
+ "var s = window.getSelection();" \
+ "var r = document.createRange();" \
+ "var n = document.getElementById('caret');" \
+ "r.setStartBefore(n);" \
+ "r.setEndBefore(n);" \
+ "s.removeAllRanges();" \
+ "s.addRange(r);"
static char *
xmlnode_to_pretty_str(xmlnode *node, int *len)
@@ -272,9 +280,7 @@
{
GtkWidget *vbox, *hbox, *to_entry, *label, *type_combo;
GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
- GtkTextIter iter;
- GtkTextBuffer *buffer;
- const char *to;
+ char *to;
int result;
char *stanza;
@@ -332,19 +338,21 @@
return;
}
- to = gtk_entry_get_text(GTK_ENTRY(to_entry));
+ to = g_markup_escape_text(gtk_entry_get_text(GTK_ENTRY(to_entry)), -1);
- stanza = g_strdup_printf("<iq %s%s%s id='console%x' type='%s'></iq>",
+ stanza = g_strdup_printf("<iq %s%s%s id='console%x' type='%s'>"
+ "<a id=caret></a>"
+ "</iq>",
to && *to ? "to='" : "",
to && *to ? to : "",
to && *to ? "'" : "",
g_random_int(),
gtk_combo_box_get_active_text(GTK_COMBO_BOX(type_combo)));
- buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console->entry));
- gtk_text_buffer_set_text(buffer, stanza, -1);
- gtk_text_buffer_get_iter_at_offset(buffer, &iter, strstr(stanza, "</iq>") - stanza);
- gtk_text_buffer_place_cursor(buffer, &iter);
+ gtk_webview_load_html_string(GTK_WEBVIEW(console->entry), stanza);
+ gtk_widget_grab_focus(console->entry);
+ gtk_webview_safe_execute_script(GTK_WEBVIEW(console->entry), SET_CURSOR);
+ g_free(to);
g_free(stanza);
gtk_widget_destroy(dialog);
@@ -362,9 +370,8 @@
GtkWidget *show_combo;
GtkWidget *type_combo;
GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
- GtkTextIter iter;
- GtkTextBuffer *buffer;
- const char *to, *type, *status, *show, *priority;
+ char *to, *status, *priority;
+ const char *type, *show;
int result;
char *stanza;
@@ -465,21 +472,22 @@
return;
}
- to = gtk_entry_get_text(GTK_ENTRY(to_entry));
+ to = g_markup_escape_text(gtk_entry_get_text(GTK_ENTRY(to_entry)), -1);
type = gtk_combo_box_get_active_text(GTK_COMBO_BOX(type_combo));
if (!strcmp(type, "default"))
type = "";
show = gtk_combo_box_get_active_text(GTK_COMBO_BOX(show_combo));
if (!strcmp(show, "default"))
show = "";
- status = gtk_entry_get_text(GTK_ENTRY(status_entry));
- priority = gtk_entry_get_text(GTK_ENTRY(priority_entry));
+ status = g_markup_escape_text(gtk_entry_get_text(GTK_ENTRY(status_entry)), -1);
+ priority = g_markup_escape_text(gtk_entry_get_text(GTK_ENTRY(priority_entry)), -1);
if (!strcmp(priority, "0"))
- priority = "";
+ *priority = '\0';
- stanza = g_strdup_printf("<presence %s%s%s id='console%x' %s%s%s>"
+ stanza = g_strdup_printf("<presence %s%s%s id='console%x' %s%s%s>"
"%s%s%s%s%s%s%s%s%s"
- "</presence>",
+ "<a id=caret></a>"
+ "</presence>",
*to ? "to='" : "",
*to ? to : "",
*to ? "'" : "",
@@ -489,23 +497,25 @@
*type ? type : "",
*type ? "'" : "",
- *show ? "<show>" : "",
+ *show ? "<show>" : "",
*show ? show : "",
- *show ? "</show>" : "",
+ *show ? "</show>" : "",
- *status ? "<status>" : "",
+ *status ? "<status>" : "",
*status ? status : "",
- *status ? "</status>" : "",
+ *status ? "</status>" : "",
- *priority ? "<priority>" : "",
+ *priority ? "<priority>" : "",
*priority ? priority : "",
- *priority ? "</priority>" : "");
+ *priority ? "</priority>" : "");
- buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console->entry));
- gtk_text_buffer_set_text(buffer, stanza, -1);
- gtk_text_buffer_get_iter_at_offset(buffer, &iter, strstr(stanza, "</presence>") - stanza);
- gtk_text_buffer_place_cursor(buffer, &iter);
+ gtk_webview_load_html_string(GTK_WEBVIEW(console->entry), stanza);
+ gtk_widget_grab_focus(console->entry);
+ gtk_webview_safe_execute_script(GTK_WEBVIEW(console->entry), SET_CURSOR);
g_free(stanza);
+ g_free(to);
+ g_free(status);
+ g_free(priority);
gtk_widget_destroy(dialog);
g_object_unref(sg);
@@ -522,9 +532,7 @@
GtkWidget *label;
GtkWidget *type_combo;
GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
- GtkTextIter iter;
- GtkTextBuffer *buffer;
- const char *to, *body, *thread, *subject;
+ char *to, *body, *thread, *subject;
char *stanza;
int result;
@@ -618,14 +626,15 @@
return;
}
- to = gtk_entry_get_text(GTK_ENTRY(to_entry));
- body = gtk_entry_get_text(GTK_ENTRY(body_entry));
- thread = gtk_entry_get_text(GTK_ENTRY(thread_entry));
- subject = gtk_entry_get_text(GTK_ENTRY(subject_entry));
+ to = g_markup_escape_text(gtk_entry_get_text(GTK_ENTRY(to_entry)), -1);
+ body = g_markup_escape_text(gtk_entry_get_text(GTK_ENTRY(body_entry)), -1);
+ thread = g_markup_escape_text(gtk_entry_get_text(GTK_ENTRY(thread_entry)), -1);
+ subject = g_markup_escape_text(gtk_entry_get_text(GTK_ENTRY(subject_entry)), -1);
- stanza = g_strdup_printf("<message %s%s%s id='console%x' type='%s'>"
+ stanza = g_strdup_printf("<message %s%s%s id='console%x' type='%s'>"
"%s%s%s%s%s%s%s%s%s"
- "</message>",
+ "<a id=caret></a>"
+ "</message>",
*to ? "to='" : "",
*to ? to : "",
@@ -633,23 +642,26 @@
g_random_int(),
gtk_combo_box_get_active_text(GTK_COMBO_BOX(type_combo)),
- *body ? "<body>" : "",
+ *body ? "<body>" : "",
*body ? body : "",
- *body ? "</body>" : "",
+ *body ? "</body>" : "",
- *subject ? "<subject>" : "",
+ *subject ? "<subject>" : "",
*subject ? subject : "",
- *subject ? "</subject>" : "",
+ *subject ? "</subject>" : "",
- *thread ? "<thread>" : "",
+ *thread ? "<thread>" : "",
*thread ? thread : "",
- *thread ? "</thread>" : "");
+ *thread ? "</thread>" : "");
- buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console->entry));
- gtk_text_buffer_set_text(buffer, stanza, -1);
- gtk_text_buffer_get_iter_at_offset(buffer, &iter, strstr(stanza, "</message>") - stanza);
- gtk_text_buffer_place_cursor(buffer, &iter);
+ gtk_webview_load_html_string(GTK_WEBVIEW(console->entry), stanza);
+ gtk_widget_grab_focus(console->entry);
+ gtk_webview_safe_execute_script(GTK_WEBVIEW(console->entry), SET_CURSOR);
g_free(stanza);
+ g_free(to);
+ g_free(body);
+ g_free(thread);
+ g_free(subject);
gtk_widget_destroy(dialog);
g_object_unref(sg);
More information about the Commits
mailing list