Sun, 22 Jul 2007 08:14:16 +0000
revert 'no visible tabs when only one conversation' as it proved unpopular. Made tabs only fill the entire width of the notebook when there's only one tab to avoid http://pidgin.im/~deryni/that_just_looks_dumb.png
| 15412 | 1 | /* |
| 15884 | 2 | * Purple - XMPP debugging tool |
| 15412 | 3 | * |
| 4 | * Copyright (C) 2002-2003, Sean Egan | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | * | |
| 20 | */ | |
| 21 | ||
| 22 | #include "internal.h" | |
| 23 | #include "gtkplugin.h" | |
| 24 | #include "version.h" | |
| 25 | #include "prpl.h" | |
| 26 | #include "xmlnode.h" | |
| 27 | ||
| 28 | #include "gtkimhtml.h" | |
| 15427 | 29 | #if !GTK_CHECK_VERSION(2,4,0) |
| 16290 | 30 | #include "pidgincombobox.h" |
| 15427 | 31 | #endif |
| 17242 | 32 | #include "gtkutils.h" |
| 15412 | 33 | |
| 34 | typedef struct { | |
| 15884 | 35 | PurpleConnection *gc; |
| 15412 | 36 | GtkWidget *window; |
| 37 | GtkWidget *hbox; | |
| 38 | GtkWidget *dropdown; | |
| 39 | GtkWidget *imhtml; | |
| 40 | GtkWidget *entry; | |
| 41 | GtkWidget *sw; | |
| 42 | int count; | |
| 43 | GList *accounts; | |
| 44 | } XmppConsole; | |
| 45 | ||
| 46 | XmppConsole *console = NULL; | |
| 47 | static void *xmpp_console_handle = NULL; | |
| 48 | ||
| 49 | #define BRACKET_COLOR "#940f8c" | |
| 50 | #define TAG_COLOR "#8b1dab" | |
| 51 | #define ATTR_NAME_COLOR "#a02961" | |
| 52 | #define ATTR_VALUE_COLOR "#324aa4" | |
| 53 | #define XMLNS_COLOR "#2cb12f" | |
| 54 | ||
| 55 | static char * | |
| 56 | xmlnode_to_pretty_str(xmlnode *node, int *len, int depth) | |
| 57 | { | |
| 58 | GString *text = g_string_new(""); | |
| 59 | xmlnode *c; | |
| 60 | char *node_name, *esc, *esc2, *tab = NULL; | |
| 61 | gboolean need_end = FALSE, pretty = TRUE; | |
| 62 | ||
| 63 | g_return_val_if_fail(node != NULL, NULL); | |
| 64 | ||
| 65 | if(pretty && depth) { | |
| 66 | tab = g_strnfill(depth, '\t'); | |
| 67 | text = g_string_append(text, tab); | |
| 68 | } | |
| 69 | ||
| 70 | node_name = g_markup_escape_text(node->name, -1); | |
| 71 | g_string_append_printf(text, "<font color='" | |
| 72 | BRACKET_COLOR "'><</font><font color='" | |
| 73 | TAG_COLOR "'><b>%s</b></font>", node_name); | |
| 74 | ||
| 75 | if (node->xmlns) { | |
| 76 | if((!node->parent || | |
| 77 | !node->parent->xmlns || | |
| 78 | strcmp(node->xmlns, node->parent->xmlns)) && | |
| 79 | strcmp(node->xmlns, "jabber:client")) | |
| 80 | { | |
| 81 | char *xmlns = g_markup_escape_text(node->xmlns, -1); | |
| 82 | g_string_append_printf(text, " <font color='" | |
| 83 | ATTR_NAME_COLOR "'><b>xmlns</b></font>='<font color='" | |
| 84 | XMLNS_COLOR "'><b>%s</b></font>'", xmlns); | |
| 85 | g_free(xmlns); | |
| 86 | } | |
| 87 | } | |
| 88 | for(c = node->child; c; c = c->next) | |
| 89 | { | |
| 90 | if(c->type == XMLNODE_TYPE_ATTRIB) { | |
| 91 | esc = g_markup_escape_text(c->name, -1); | |
| 92 | esc2 = g_markup_escape_text(c->data, -1); | |
| 93 | g_string_append_printf(text, " <font color='" | |
| 94 | ATTR_NAME_COLOR "'><b>%s</b></font>='<font color='" | |
| 95 | ATTR_VALUE_COLOR "'>%s</font>'", esc, esc2); | |
| 96 | g_free(esc); | |
| 97 | g_free(esc2); | |
| 98 | } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) { | |
| 99 | if(c->type == XMLNODE_TYPE_DATA) | |
| 100 | pretty = FALSE; | |
| 101 | need_end = TRUE; | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| 105 | if(need_end) { | |
| 106 | g_string_append_printf(text, | |
| 107 | "<font color='"BRACKET_COLOR"'>></font>%s", pretty ? "<br>" : ""); | |
| 108 | ||
| 109 | for(c = node->child; c; c = c->next) | |
| 110 | { | |
| 111 | if(c->type == XMLNODE_TYPE_TAG) { | |
| 112 | int esc_len; | |
| 113 | esc = xmlnode_to_pretty_str(c, &esc_len, depth+1); | |
| 114 | text = g_string_append_len(text, esc, esc_len); | |
| 115 | g_free(esc); | |
| 116 | } else if(c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) { | |
| 117 | esc = g_markup_escape_text(c->data, c->data_sz); | |
| 118 | text = g_string_append(text, esc); | |
| 119 | g_free(esc); | |
| 120 | } | |
| 121 | } | |
| 122 | ||
| 123 | if(tab && pretty) | |
| 124 | text = g_string_append(text, tab); | |
| 125 | g_string_append_printf(text, "<font color='"BRACKET_COLOR"'><</font>/<font color='" | |
| 126 | TAG_COLOR"'><b>%s</b></font><font color='"BRACKET_COLOR | |
| 127 | "'>></font><br>", node_name); | |
| 128 | } else { | |
| 129 | g_string_append_printf(text, "/<font color='"BRACKET_COLOR"'>></font><br>"); | |
| 130 | } | |
| 131 | ||
| 132 | g_free(node_name); | |
| 133 | ||
| 134 | g_free(tab); | |
| 135 | ||
| 136 | if(len) | |
| 137 | *len = text->len; | |
| 138 | ||
| 139 | return g_string_free(text, FALSE); | |
| 140 | } | |
| 141 | ||
| 142 | static void | |
| 15884 | 143 | xmlnode_received_cb(PurpleConnection *gc, xmlnode **packet, gpointer null) |
| 15412 | 144 | { |
| 145 | char *str, *formatted; | |
| 146 | ||
| 147 | if (!console || console->gc != gc) | |
| 148 | return; | |
| 149 | str = xmlnode_to_pretty_str(*packet, NULL, 0); | |
| 150 | formatted = g_strdup_printf("<body bgcolor='#ffcece'><pre>%s</pre></body>", str); | |
| 151 | gtk_imhtml_append_text(GTK_IMHTML(console->imhtml), formatted, 0); | |
| 152 | g_free(formatted); | |
| 153 | g_free(str); | |
| 154 | } | |
| 155 | ||
| 156 | static void | |
| 15884 | 157 | xmlnode_sent_cb(PurpleConnection *gc, char **packet, gpointer null) |
| 15412 | 158 | { |
| 159 | char *str; | |
| 160 | char *formatted; | |
| 161 | xmlnode *node; | |
| 162 | ||
| 163 | if (!console || console->gc != gc) | |
| 164 | return; | |
| 165 | node = xmlnode_from_str(*packet, -1); | |
| 166 | ||
| 167 | if (!node) | |
| 168 | return; | |
| 169 | ||
| 170 | str = xmlnode_to_pretty_str(node, NULL, 0); | |
| 171 | formatted = g_strdup_printf("<body bgcolor='#dcecc4'><pre>%s</pre></body>", str); | |
| 172 | gtk_imhtml_append_text(GTK_IMHTML(console->imhtml), formatted, 0); | |
| 173 | g_free(formatted); | |
| 174 | g_free(str); | |
| 175 | xmlnode_free(node); | |
| 176 | } | |
| 177 | ||
| 178 | static void message_send_cb(GtkWidget *widget, gpointer p) | |
| 179 | { | |
| 180 | GtkTextIter start, end; | |
| 15884 | 181 | PurplePluginProtocolInfo *prpl_info = NULL; |
| 182 | PurpleConnection *gc = console->gc; | |
| 15412 | 183 | GtkTextBuffer *buffer; |
| 184 | char *text; | |
| 185 | ||
| 186 | gc = console->gc; | |
|
17529
5fd44f61d007
Fix a crash when trying to use XMPP console with no XMPP accounts connected
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16749
diff
changeset
|
187 | |
|
5fd44f61d007
Fix a crash when trying to use XMPP console with no XMPP accounts connected
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16749
diff
changeset
|
188 | if (gc) |
|
5fd44f61d007
Fix a crash when trying to use XMPP console with no XMPP accounts connected
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16749
diff
changeset
|
189 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
|
5fd44f61d007
Fix a crash when trying to use XMPP console with no XMPP accounts connected
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16749
diff
changeset
|
190 | |
| 15412 | 191 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console->entry)); |
| 192 | gtk_text_buffer_get_start_iter(buffer, &start); | |
| 193 | gtk_text_buffer_get_end_iter(buffer, &end); | |
|
17529
5fd44f61d007
Fix a crash when trying to use XMPP console with no XMPP accounts connected
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16749
diff
changeset
|
194 | |
| 15412 | 195 | text = gtk_imhtml_get_text(GTK_IMHTML(console->entry), &start, &end); |
|
17529
5fd44f61d007
Fix a crash when trying to use XMPP console with no XMPP accounts connected
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16749
diff
changeset
|
196 | |
|
5fd44f61d007
Fix a crash when trying to use XMPP console with no XMPP accounts connected
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16749
diff
changeset
|
197 | if (prpl_info && prpl_info->send_raw != NULL) |
| 15412 | 198 | prpl_info->send_raw(gc, text, strlen(text)); |
| 199 | ||
| 200 | g_free(text); | |
| 201 | gtk_imhtml_clear(GTK_IMHTML(console->entry)); | |
| 202 | } | |
| 203 | ||
| 204 | static void entry_changed_cb(GtkTextBuffer *buffer, void *data) | |
| 205 | { | |
| 206 | char *xmlstr, *str; | |
| 207 | GtkTextIter iter; | |
| 208 | int wrapped_lines; | |
| 209 | int lines; | |
| 210 | GdkRectangle oneline; | |
| 211 | int height; | |
| 212 | int pad_top, pad_inside, pad_bottom; | |
| 213 | GtkTextIter start, end; | |
| 214 | xmlnode *node; | |
| 215 | ||
| 216 | wrapped_lines = 1; | |
| 217 | gtk_text_buffer_get_start_iter(buffer, &iter); | |
| 218 | gtk_text_view_get_iter_location(GTK_TEXT_VIEW(console->entry), &iter, &oneline); | |
| 219 | while (gtk_text_view_forward_display_line(GTK_TEXT_VIEW(console->entry), &iter)) | |
| 220 | wrapped_lines++; | |
| 221 | ||
| 222 | lines = gtk_text_buffer_get_line_count(buffer); | |
| 223 | ||
| 224 | /* Show a maximum of 64 lines */ | |
| 225 | lines = MIN(lines, 6); | |
| 226 | wrapped_lines = MIN(wrapped_lines, 6); | |
| 227 | ||
| 228 | pad_top = gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(console->entry)); | |
| 229 | pad_bottom = gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(console->entry)); | |
| 230 | pad_inside = gtk_text_view_get_pixels_inside_wrap(GTK_TEXT_VIEW(console->entry)); | |
| 231 | ||
| 232 | height = (oneline.height + pad_top + pad_bottom) * lines; | |
| 233 | height += (oneline.height + pad_inside) * (wrapped_lines - lines); | |
| 234 | ||
| 235 | gtk_widget_set_size_request(console->sw, -1, height+6); | |
| 236 | ||
| 237 | ||
| 238 | ||
| 239 | gtk_text_buffer_get_start_iter(buffer, &start); | |
| 240 | gtk_text_buffer_get_end_iter(buffer, &end); | |
| 241 | str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); | |
| 242 | if (!str) | |
| 243 | return; | |
| 244 | xmlstr = g_strdup_printf("<xml>%s</xml>", str); | |
| 245 | node = xmlnode_from_str(xmlstr, -1); | |
| 246 | if (node) { | |
| 247 | gtk_imhtml_clear_formatting(GTK_IMHTML(console->entry)); | |
| 248 | } else { | |
| 249 | gtk_imhtml_toggle_background(GTK_IMHTML(console->entry), "#ffcece"); | |
| 250 | } | |
| 251 | g_free(str); | |
| 252 | g_free(xmlstr); | |
| 253 | if (node) | |
| 254 | xmlnode_free(node); | |
| 255 | } | |
| 256 | ||
| 257 | static void iq_clicked_cb(GtkWidget *w, gpointer nul) | |
| 258 | { | |
| 259 | GtkWidget *hbox, *to_entry, *label, *type_combo; | |
| 260 | GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
| 261 | GtkTextIter iter; | |
| 262 | GtkTextBuffer *buffer; | |
| 263 | const char *to; | |
| 264 | int result; | |
| 265 | char *stanza; | |
| 266 | ||
| 267 | GtkWidget *dialog = gtk_dialog_new_with_buttons("<iq/>", | |
| 268 | GTK_WINDOW(console->window), | |
| 269 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 270 | GTK_STOCK_CANCEL, | |
| 271 | GTK_RESPONSE_REJECT, | |
| 272 | GTK_STOCK_OK, | |
| 273 | GTK_RESPONSE_ACCEPT, | |
| 274 | NULL); | |
| 275 | gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | |
| 276 | gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); | |
| 277 | gtk_container_set_border_width(GTK_CONTAINER(dialog), 12); | |
| 278 | ||
| 279 | hbox = gtk_hbox_new(FALSE, 3); | |
| 280 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 281 | ||
| 282 | label = gtk_label_new("To:"); | |
| 283 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 284 | gtk_size_group_add_widget(sg, label); | |
| 285 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 286 | ||
| 287 | to_entry = gtk_entry_new(); | |
| 288 | gtk_entry_set_activates_default (GTK_ENTRY (to_entry), TRUE); | |
| 289 | gtk_box_pack_start(GTK_BOX(hbox), to_entry, FALSE, FALSE, 0); | |
| 290 | ||
| 291 | hbox = gtk_hbox_new(FALSE, 3); | |
| 292 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 293 | label = gtk_label_new("Type:"); | |
| 294 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 295 | ||
| 296 | gtk_size_group_add_widget(sg, label); | |
| 297 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 298 | type_combo = gtk_combo_box_new_text(); | |
| 299 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "get"); | |
| 300 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "set"); | |
| 301 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "result"); | |
| 302 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "error"); | |
| 303 | gtk_combo_box_set_active(GTK_COMBO_BOX(type_combo), 0); | |
| 304 | gtk_box_pack_start(GTK_BOX(hbox), type_combo, FALSE, FALSE, 0); | |
| 305 | ||
| 306 | gtk_widget_show_all(GTK_DIALOG(dialog)->vbox); | |
| 307 | ||
| 308 | result = gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 309 | if (result != GTK_RESPONSE_ACCEPT) { | |
| 310 | gtk_widget_destroy(dialog); | |
| 311 | return; | |
| 312 | } | |
| 313 | ||
| 314 | to = gtk_entry_get_text(GTK_ENTRY(to_entry)); | |
| 315 | ||
| 316 | stanza = g_strdup_printf("<iq %s%s%s id='console%x' type='%s'></iq>", | |
| 317 | to && *to ? "to='" : "", | |
| 318 | to && *to ? to : "", | |
| 319 | to && *to ? "'" : "", | |
| 320 | g_random_int(), | |
| 321 | gtk_combo_box_get_active_text(GTK_COMBO_BOX(type_combo))); | |
| 322 | ||
| 323 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console->entry)); | |
| 324 | gtk_text_buffer_set_text(buffer, stanza, -1); | |
| 325 | gtk_text_buffer_get_iter_at_offset(buffer, &iter, strstr(stanza, "</iq>") - stanza); | |
| 326 | gtk_text_buffer_place_cursor(buffer, &iter); | |
| 327 | g_free(stanza); | |
| 328 | ||
| 329 | gtk_widget_destroy(dialog); | |
| 330 | ||
| 331 | } | |
| 332 | ||
| 333 | static void presence_clicked_cb(GtkWidget *w, gpointer nul) | |
| 334 | { | |
| 335 | GtkWidget *hbox, | |
| 336 | *to_entry, | |
| 337 | *status_entry, | |
| 338 | *priority_entry, | |
| 339 | *label, | |
| 340 | *show_combo, | |
| 341 | *type_combo; | |
| 342 | GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
| 343 | GtkTextIter iter; | |
| 344 | GtkTextBuffer *buffer; | |
| 345 | const char *to, *type, *status, *show, *priority; | |
| 346 | int result; | |
| 347 | char *stanza; | |
| 348 | ||
| 349 | GtkWidget *dialog = gtk_dialog_new_with_buttons("<presence/>", | |
| 350 | GTK_WINDOW(console->window), | |
| 351 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 352 | GTK_STOCK_CANCEL, | |
| 353 | GTK_RESPONSE_REJECT, | |
| 354 | GTK_STOCK_OK, | |
| 355 | GTK_RESPONSE_ACCEPT, | |
| 356 | NULL); | |
| 357 | gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | |
| 358 | gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); | |
| 359 | gtk_container_set_border_width(GTK_CONTAINER(dialog), 12); | |
| 360 | ||
| 361 | hbox = gtk_hbox_new(FALSE, 3); | |
| 362 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 363 | ||
| 364 | label = gtk_label_new("To:"); | |
| 365 | gtk_size_group_add_widget(sg, label); | |
| 366 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 367 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 368 | ||
| 369 | to_entry = gtk_entry_new(); | |
| 370 | gtk_entry_set_activates_default (GTK_ENTRY (to_entry), TRUE); | |
| 371 | gtk_box_pack_start(GTK_BOX(hbox), to_entry, FALSE, FALSE, 0); | |
| 372 | ||
| 373 | hbox = gtk_hbox_new(FALSE, 3); | |
| 374 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 375 | label = gtk_label_new("Type:"); | |
| 376 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 377 | gtk_size_group_add_widget(sg, label); | |
| 378 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 379 | type_combo = gtk_combo_box_new_text(); | |
| 380 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "default"); | |
| 381 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "unavailable"); | |
| 382 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "subscribe"); | |
| 383 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "unsubscribe"); | |
| 384 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "subscribed"); | |
| 385 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "unsubscribed"); | |
| 386 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "probe"); | |
| 387 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "error"); | |
| 388 | gtk_combo_box_set_active(GTK_COMBO_BOX(type_combo), 0); | |
| 389 | gtk_box_pack_start(GTK_BOX(hbox), type_combo, FALSE, FALSE, 0); | |
| 390 | ||
| 391 | hbox = gtk_hbox_new(FALSE, 3); | |
| 392 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 393 | label = gtk_label_new("Show:"); | |
| 394 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 395 | gtk_size_group_add_widget(sg, label); | |
| 396 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 397 | show_combo = gtk_combo_box_new_text(); | |
| 398 | gtk_combo_box_append_text(GTK_COMBO_BOX(show_combo), "default"); | |
| 399 | gtk_combo_box_append_text(GTK_COMBO_BOX(show_combo), "away"); | |
| 400 | gtk_combo_box_append_text(GTK_COMBO_BOX(show_combo), "dnd"); | |
| 401 | gtk_combo_box_append_text(GTK_COMBO_BOX(show_combo), "xa"); | |
| 402 | gtk_combo_box_append_text(GTK_COMBO_BOX(show_combo), "chat"); | |
| 403 | ||
| 404 | gtk_combo_box_set_active(GTK_COMBO_BOX(show_combo), 0); | |
| 405 | gtk_box_pack_start(GTK_BOX(hbox), show_combo, FALSE, FALSE, 0); | |
| 406 | ||
| 407 | hbox = gtk_hbox_new(FALSE, 3); | |
| 408 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 409 | ||
| 410 | label = gtk_label_new("Status:"); | |
| 411 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 412 | gtk_size_group_add_widget(sg, label); | |
| 413 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 414 | ||
| 415 | status_entry = gtk_entry_new(); | |
| 416 | gtk_entry_set_activates_default (GTK_ENTRY (status_entry), TRUE); | |
| 417 | gtk_box_pack_start(GTK_BOX(hbox), status_entry, FALSE, FALSE, 0); | |
| 418 | ||
| 419 | ||
| 420 | hbox = gtk_hbox_new(FALSE, 3); | |
| 421 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 422 | ||
| 423 | label = gtk_label_new("Priority:"); | |
| 424 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 425 | gtk_size_group_add_widget(sg, label); | |
| 426 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 427 | ||
| 428 | priority_entry = gtk_spin_button_new_with_range(-128, 127, 1); | |
| 429 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(priority_entry), 0); | |
| 430 | gtk_box_pack_start(GTK_BOX(hbox), priority_entry, FALSE, FALSE, 0); | |
| 431 | ||
| 432 | ||
| 433 | gtk_widget_show_all(GTK_DIALOG(dialog)->vbox); | |
| 434 | ||
| 435 | result = gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 436 | if (result != GTK_RESPONSE_ACCEPT) { | |
| 437 | gtk_widget_destroy(dialog); | |
| 438 | return; | |
| 439 | } | |
| 440 | ||
| 441 | to = gtk_entry_get_text(GTK_ENTRY(to_entry)); | |
| 442 | type = gtk_combo_box_get_active_text(GTK_COMBO_BOX(type_combo)); | |
| 443 | if (!strcmp(type, "default")) | |
| 444 | type = ""; | |
| 445 | show = gtk_combo_box_get_active_text(GTK_COMBO_BOX(show_combo)); | |
| 446 | if (!strcmp(show, "default")) | |
| 447 | show = ""; | |
| 448 | status = gtk_entry_get_text(GTK_ENTRY(status_entry)); | |
| 449 | priority = gtk_entry_get_text(GTK_ENTRY(priority_entry)); | |
| 450 | if (!strcmp(priority, "0")) | |
| 451 | priority = ""; | |
| 452 | ||
| 453 | ||
| 454 | ||
| 455 | stanza = g_strdup_printf("<presence %s%s%s id='console%x' %s%s%s>" | |
| 456 | "%s%s%s%s%s%s%s%s%s" | |
| 457 | "</presence>", | |
| 458 | *to ? "to='" : "", | |
| 459 | *to ? to : "", | |
| 460 | *to ? "'" : "", | |
| 461 | g_random_int(), | |
| 462 | ||
| 463 | *type ? "type='" : "", | |
| 464 | *type ? type : "", | |
| 465 | *type ? "'" : "", | |
| 466 | ||
| 467 | *show ? "<show>" : "", | |
| 468 | *show ? show : "", | |
| 469 | *show ? "</show>" : "", | |
| 470 | ||
| 471 | *status ? "<status>" : "", | |
| 472 | *status ? status : "", | |
| 473 | *status ? "</status>" : "", | |
| 474 | ||
| 475 | *priority ? "<priority>" : "", | |
| 476 | *priority ? priority : "", | |
| 477 | *priority ? "</priority>" : ""); | |
| 478 | ||
| 479 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console->entry)); | |
| 480 | gtk_text_buffer_set_text(buffer, stanza, -1); | |
| 481 | gtk_text_buffer_get_iter_at_offset(buffer, &iter, strstr(stanza, "</presence>") - stanza); | |
| 482 | gtk_text_buffer_place_cursor(buffer, &iter); | |
| 483 | g_free(stanza); | |
| 484 | ||
| 485 | gtk_widget_destroy(dialog); | |
| 486 | } | |
| 487 | ||
| 488 | static void message_clicked_cb(GtkWidget *w, gpointer nul) | |
| 489 | { | |
| 490 | GtkWidget *hbox, | |
| 491 | *to_entry, | |
| 492 | *body_entry, | |
| 493 | *thread_entry, | |
| 494 | *subject_entry, | |
| 495 | *label, | |
| 496 | *type_combo; | |
| 497 | GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
| 498 | GtkTextIter iter; | |
| 499 | GtkTextBuffer *buffer; | |
| 500 | const char *to, *body, *thread, *subject; | |
| 501 | char *stanza; | |
| 502 | int result; | |
| 503 | ||
| 504 | GtkWidget *dialog = gtk_dialog_new_with_buttons("<message/>", | |
| 505 | GTK_WINDOW(console->window), | |
| 506 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 507 | GTK_STOCK_CANCEL, | |
| 508 | GTK_RESPONSE_REJECT, | |
| 509 | GTK_STOCK_OK, | |
| 510 | GTK_RESPONSE_ACCEPT, | |
| 511 | NULL); | |
| 512 | gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | |
| 513 | gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); | |
| 514 | gtk_container_set_border_width(GTK_CONTAINER(dialog), 12); | |
| 515 | ||
| 516 | hbox = gtk_hbox_new(FALSE, 3); | |
| 517 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 518 | ||
| 519 | label = gtk_label_new("To:"); | |
| 520 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 521 | gtk_size_group_add_widget(sg, label); | |
| 522 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 523 | ||
| 524 | to_entry = gtk_entry_new(); | |
| 525 | gtk_entry_set_activates_default (GTK_ENTRY (to_entry), TRUE); | |
| 526 | gtk_box_pack_start(GTK_BOX(hbox), to_entry, FALSE, FALSE, 0); | |
| 527 | ||
| 528 | hbox = gtk_hbox_new(FALSE, 3); | |
| 529 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 530 | label = gtk_label_new("Type:"); | |
| 531 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 532 | gtk_size_group_add_widget(sg, label); | |
| 533 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 534 | type_combo = gtk_combo_box_new_text(); | |
| 535 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "chat"); | |
| 536 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "headline"); | |
| 537 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "groupchat"); | |
| 538 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "normal"); | |
| 539 | gtk_combo_box_append_text(GTK_COMBO_BOX(type_combo), "error"); | |
| 540 | gtk_combo_box_set_active(GTK_COMBO_BOX(type_combo), 0); | |
| 541 | gtk_box_pack_start(GTK_BOX(hbox), type_combo, FALSE, FALSE, 0); | |
| 542 | ||
| 543 | hbox = gtk_hbox_new(FALSE, 3); | |
| 544 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 545 | ||
| 546 | label = gtk_label_new("Body:"); | |
| 547 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 548 | gtk_size_group_add_widget(sg, label); | |
| 549 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 550 | ||
| 551 | body_entry = gtk_entry_new(); | |
| 552 | gtk_entry_set_activates_default (GTK_ENTRY (body_entry), TRUE); | |
| 553 | gtk_box_pack_start(GTK_BOX(hbox), body_entry, FALSE, FALSE, 0); | |
| 554 | ||
| 555 | ||
| 556 | hbox = gtk_hbox_new(FALSE, 3); | |
| 557 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 558 | ||
| 559 | label = gtk_label_new("Subject:"); | |
| 560 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 561 | gtk_size_group_add_widget(sg, label); | |
| 562 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 563 | ||
| 564 | subject_entry = gtk_entry_new(); | |
| 565 | gtk_entry_set_activates_default (GTK_ENTRY (subject_entry), TRUE); | |
| 566 | gtk_box_pack_start(GTK_BOX(hbox), subject_entry, FALSE, FALSE, 0); | |
| 567 | ||
| 568 | hbox = gtk_hbox_new(FALSE, 3); | |
| 569 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); | |
| 570 | ||
| 571 | label = gtk_label_new("Thread:"); | |
| 572 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 573 | gtk_size_group_add_widget(sg, label); | |
| 574 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 575 | ||
| 576 | thread_entry = gtk_entry_new(); | |
| 577 | gtk_entry_set_activates_default (GTK_ENTRY (thread_entry), TRUE); | |
| 578 | gtk_box_pack_start(GTK_BOX(hbox), thread_entry, FALSE, FALSE, 0); | |
| 579 | ||
| 580 | gtk_widget_show_all(GTK_DIALOG(dialog)->vbox); | |
| 581 | ||
| 582 | result = gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 583 | if (result != GTK_RESPONSE_ACCEPT) { | |
| 584 | gtk_widget_destroy(dialog); | |
| 585 | return; | |
| 586 | } | |
| 587 | ||
| 588 | to = gtk_entry_get_text(GTK_ENTRY(to_entry)); | |
| 589 | body = gtk_entry_get_text(GTK_ENTRY(body_entry)); | |
| 590 | thread = gtk_entry_get_text(GTK_ENTRY(thread_entry)); | |
| 591 | subject = gtk_entry_get_text(GTK_ENTRY(subject_entry)); | |
| 592 | ||
| 593 | stanza = g_strdup_printf("<message %s%s%s id='console%x' type='%s'>" | |
| 594 | "%s%s%s%s%s%s%s%s%s" | |
| 595 | "</message>", | |
| 596 | ||
| 597 | *to ? "to='" : "", | |
| 598 | *to ? to : "", | |
| 599 | *to ? "'" : "", | |
| 600 | g_random_int(), | |
| 601 | gtk_combo_box_get_active_text(GTK_COMBO_BOX(type_combo)), | |
| 602 | ||
| 603 | *body ? "<body>" : "", | |
| 604 | *body ? body : "", | |
| 605 | *body ? "</body>" : "", | |
| 606 | ||
| 607 | *subject ? "<subject>" : "", | |
| 608 | *subject ? subject : "", | |
| 609 | *subject ? "</subject>" : "", | |
| 610 | ||
| 611 | *thread ? "<thread>" : "", | |
| 612 | *thread ? thread : "", | |
| 613 | *thread ? "</thread>" : ""); | |
| 614 | ||
| 615 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console->entry)); | |
| 616 | gtk_text_buffer_set_text(buffer, stanza, -1); | |
| 617 | gtk_text_buffer_get_iter_at_offset(buffer, &iter, strstr(stanza, "</message>") - stanza); | |
| 618 | gtk_text_buffer_place_cursor(buffer, &iter); | |
| 619 | g_free(stanza); | |
| 620 | ||
| 621 | gtk_widget_destroy(dialog); | |
| 622 | } | |
| 623 | ||
| 624 | static void | |
| 15884 | 625 | signed_on_cb(PurpleConnection *gc) |
| 15412 | 626 | { |
| 627 | if (!console) | |
| 628 | return; | |
| 629 | ||
| 15884 | 630 | gtk_combo_box_append_text(GTK_COMBO_BOX(console->dropdown), purple_account_get_username(gc->account)); |
| 15412 | 631 | console->accounts = g_list_append(console->accounts, gc); |
| 632 | console->count++; | |
| 633 | ||
| 634 | if (console->count > 1) | |
| 635 | gtk_widget_show_all(console->hbox); | |
| 636 | } | |
| 637 | ||
| 638 | static void | |
| 15884 | 639 | signed_off_cb(PurpleConnection *gc) |
| 15412 | 640 | { |
| 641 | int i = 0; | |
| 642 | GList *l; | |
| 643 | ||
| 644 | if (!console) | |
| 645 | return; | |
| 646 | ||
| 647 | l = console->accounts; | |
| 648 | while (l) { | |
| 15884 | 649 | PurpleConnection *g = l->data; |
| 15412 | 650 | if (gc == g) |
| 651 | break; | |
| 652 | i++; | |
| 653 | l = l->next; | |
| 654 | } | |
| 655 | ||
| 656 | if (l == NULL) | |
| 657 | return; | |
| 658 | ||
| 659 | gtk_combo_box_remove_text(GTK_COMBO_BOX(console->dropdown), i); | |
| 660 | console->accounts = g_list_remove(console->accounts, gc); | |
| 15884 | 661 | printf("%s\n", purple_account_get_username(gc->account)); |
| 15412 | 662 | console->count--; |
| 663 | ||
| 664 | if (gc == console->gc) { | |
| 665 | console->gc = NULL; | |
| 666 | gtk_imhtml_append_text(GTK_IMHTML(console->imhtml), | |
| 667 | _("<font color='#777777'>Logged out.</font>"), 0); | |
| 668 | } | |
| 669 | } | |
| 670 | ||
| 671 | static gboolean | |
| 15884 | 672 | plugin_load(PurplePlugin *plugin) |
| 15412 | 673 | { |
| 15884 | 674 | PurplePlugin *jabber; |
| 15412 | 675 | |
| 15884 | 676 | jabber = purple_find_prpl("prpl-jabber"); |
| 15412 | 677 | if (!jabber) |
| 678 | return FALSE; | |
| 679 | ||
| 680 | xmpp_console_handle = plugin; | |
| 15884 | 681 | purple_signal_connect(jabber, "jabber-receiving-xmlnode", xmpp_console_handle, |
| 682 | PURPLE_CALLBACK(xmlnode_received_cb), NULL); | |
| 683 | purple_signal_connect(jabber, "jabber-sending-text", xmpp_console_handle, | |
| 684 | PURPLE_CALLBACK(xmlnode_sent_cb), NULL); | |
| 685 | purple_signal_connect(purple_connections_get_handle(), "signed-on", | |
| 686 | plugin, PURPLE_CALLBACK(signed_on_cb), NULL); | |
| 687 | purple_signal_connect(purple_connections_get_handle(), "signed-off", | |
| 688 | plugin, PURPLE_CALLBACK(signed_off_cb), NULL); | |
| 15412 | 689 | |
| 690 | return TRUE; | |
| 691 | } | |
| 692 | ||
| 693 | static gboolean | |
| 15884 | 694 | plugin_unload(PurplePlugin *plugin) |
| 15412 | 695 | { |
| 15414 | 696 | if (console) |
| 697 | gtk_widget_destroy(console->window); | |
| 15412 | 698 | return TRUE; |
| 699 | } | |
| 700 | ||
| 701 | static void | |
| 702 | console_destroy(GtkObject *window, gpointer nul) | |
| 703 | { | |
| 704 | g_list_free(console->accounts); | |
| 705 | g_free(console); | |
| 706 | console = NULL; | |
| 707 | } | |
| 708 | ||
| 709 | static void | |
| 710 | dropdown_changed_cb(GtkComboBox *widget, gpointer nul) | |
| 711 | { | |
| 15884 | 712 | PurpleAccount *account; |
| 15412 | 713 | |
| 714 | if (!console) | |
| 715 | return; | |
| 716 | ||
| 15884 | 717 | account = purple_accounts_find(gtk_combo_box_get_active_text(GTK_COMBO_BOX(console->dropdown)), |
| 15412 | 718 | "prpl-jabber"); |
| 719 | if (!account || !account->gc) | |
| 720 | return; | |
| 721 | ||
| 722 | console->gc = account->gc; | |
| 723 | gtk_imhtml_clear(GTK_IMHTML(console->imhtml)); | |
| 724 | } | |
| 725 | ||
| 726 | static void | |
| 727 | create_console() | |
| 728 | { | |
| 729 | GtkWidget *vbox = gtk_vbox_new(FALSE, 6); | |
| 730 | GtkWidget *sw = gtk_scrolled_window_new(NULL, NULL); | |
| 731 | GtkWidget *label; | |
| 732 | GtkTextBuffer *buffer; | |
| 733 | GtkWidget *toolbar; | |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
734 | GList *connections; |
| 15427 | 735 | #if GTK_CHECK_VERSION(2,4,0) |
| 15412 | 736 | GtkToolItem *button; |
| 15427 | 737 | #endif |
| 15412 | 738 | |
| 739 | if (console) { | |
| 740 | gtk_window_present(GTK_WINDOW(console->window)); | |
| 741 | return; | |
| 742 | } | |
| 743 | ||
| 744 | console = g_new0(XmppConsole, 1); | |
| 745 | ||
| 17213 | 746 | console->window = pidgin_create_window(_("XMPP Console"), PIDGIN_HIG_BORDER, NULL, TRUE); |
| 15412 | 747 | g_signal_connect(G_OBJECT(console->window), "destroy", G_CALLBACK(console_destroy), NULL); |
| 748 | gtk_window_set_default_size(GTK_WINDOW(console->window), 580, 400); | |
| 749 | gtk_container_add(GTK_CONTAINER(console->window), vbox); | |
| 750 | ||
| 751 | console->hbox = gtk_hbox_new(FALSE, 3); | |
| 752 | gtk_box_pack_start(GTK_BOX(vbox), console->hbox, FALSE, FALSE, 0); | |
| 753 | label = gtk_label_new(_("Account: ")); | |
| 754 | gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
| 755 | gtk_box_pack_start(GTK_BOX(console->hbox), label, FALSE, FALSE, 0); | |
| 756 | console->dropdown = gtk_combo_box_new_text(); | |
| 15884 | 757 | for (connections = purple_connections_get_all(); connections; connections = connections->next) { |
| 758 | PurpleConnection *gc = connections->data; | |
| 759 | if (!strcmp(purple_account_get_protocol_id(purple_connection_get_account(gc)), "prpl-jabber")) { | |
| 15412 | 760 | console->count++; |
| 761 | console->accounts = g_list_append(console->accounts, gc); | |
| 762 | gtk_combo_box_append_text(GTK_COMBO_BOX(console->dropdown), | |
| 15884 | 763 | purple_account_get_username(purple_connection_get_account(gc))); |
| 15412 | 764 | if (!console->gc) |
| 765 | console->gc = gc; | |
| 766 | } | |
| 767 | } | |
| 768 | gtk_combo_box_set_active(GTK_COMBO_BOX(console->dropdown),0); | |
| 769 | gtk_box_pack_start(GTK_BOX(console->hbox), console->dropdown, TRUE, TRUE, 0); | |
| 770 | g_signal_connect(G_OBJECT(console->dropdown), "changed", G_CALLBACK(dropdown_changed_cb), NULL); | |
| 771 | ||
| 772 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); | |
| 773 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
| 774 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
| 775 | ||
| 776 | console->imhtml = gtk_imhtml_new(NULL, NULL); | |
| 777 | gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
| 778 | if (console->count == 0) | |
| 779 | gtk_imhtml_append_text(GTK_IMHTML(console->imhtml), | |
| 780 | _("<font color='#777777'>Not connected to XMPP</font>"), 0); | |
| 781 | gtk_container_add(GTK_CONTAINER(sw), console->imhtml); | |
| 782 | ||
| 783 | toolbar = gtk_toolbar_new(); | |
| 15427 | 784 | #if GTK_CHECK_VERSION(2,4,0) |
| 15412 | 785 | button = gtk_tool_button_new(NULL, "<iq/>"); |
| 786 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(iq_clicked_cb), NULL); | |
| 787 | gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(button)); | |
| 15427 | 788 | #else |
| 789 | gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "<iq/>", | |
| 790 | _("Insert an <iq/> stanza."), "foo", NULL, GTK_SIGNAL_FUNC(iq_clicked_cb), NULL); | |
| 791 | #endif | |
| 15412 | 792 | |
| 15427 | 793 | #if GTK_CHECK_VERSION(2,4,0) |
| 15412 | 794 | button = gtk_tool_button_new(NULL, "<presence/>"); |
| 795 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(presence_clicked_cb), NULL); | |
| 796 | gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(button)); | |
| 15427 | 797 | #else |
| 798 | gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "<presence/>", | |
| 799 | _("Insert a <presence/> stanza."), NULL, gtk_label_new(NULL), GTK_SIGNAL_FUNC(presence_clicked_cb), NULL); | |
| 800 | #endif | |
| 15412 | 801 | |
| 15427 | 802 | #if GTK_CHECK_VERSION(2,4,0) |
| 15412 | 803 | button = gtk_tool_button_new(NULL, "<message/>"); |
| 804 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(message_clicked_cb), NULL); | |
| 805 | gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(button)); | |
| 15427 | 806 | #else |
| 807 | gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "<message/>", | |
| 808 | _("Insert a <message/> stanza."), "foo", gtk_label_new(NULL), GTK_SIGNAL_FUNC(message_clicked_cb), NULL); | |
| 809 | #endif | |
| 810 | ||
| 15412 | 811 | gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); |
| 812 | ||
| 813 | sw = gtk_scrolled_window_new(NULL, NULL); | |
| 814 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); | |
| 815 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
| 816 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
| 817 | ||
| 818 | console->entry = gtk_imhtml_new(NULL, NULL); | |
| 819 | gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(console->entry), TRUE); | |
| 820 | g_signal_connect(G_OBJECT(console->entry),"message_send", G_CALLBACK(message_send_cb), console); | |
| 821 | ||
| 822 | gtk_box_pack_start(GTK_BOX(vbox), sw, FALSE, FALSE, 0); | |
| 823 | gtk_container_add(GTK_CONTAINER(sw), console->entry); | |
| 824 | gtk_imhtml_set_editable(GTK_IMHTML(console->entry), TRUE); | |
| 825 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console->entry)); | |
| 826 | g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(entry_changed_cb), NULL); | |
| 827 | console->sw = sw; | |
| 828 | entry_changed_cb(buffer, NULL); | |
| 829 | ||
| 830 | gtk_widget_show_all(console->window); | |
| 831 | if (console->count < 2) | |
| 832 | gtk_widget_hide(console->hbox); | |
| 833 | } | |
| 834 | ||
| 835 | static GList * | |
| 15884 | 836 | actions(PurplePlugin *plugin, gpointer context) |
| 15412 | 837 | { |
| 838 | GList *l = NULL; | |
| 15884 | 839 | PurplePluginAction *act = NULL; |
| 15412 | 840 | |
| 15884 | 841 | act = purple_plugin_action_new(_("XMPP Console"), create_console); |
| 15412 | 842 | l = g_list_append(l, act); |
| 843 | ||
| 844 | return l; | |
| 845 | } | |
| 846 | ||
| 847 | ||
| 15884 | 848 | static PurplePluginInfo info = |
| 15412 | 849 | { |
| 15884 | 850 | PURPLE_PLUGIN_MAGIC, |
| 851 | PURPLE_MAJOR_VERSION, | |
| 852 | PURPLE_MINOR_VERSION, | |
| 853 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
854 | PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ |
| 15412 | 855 | 0, /**< flags */ |
| 856 | NULL, /**< dependencies */ | |
| 15884 | 857 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 15412 | 858 | |
| 859 | "gtk-xmpp", /**< id */ | |
| 860 | N_("XMPP Console"), /**< name */ | |
| 861 | VERSION, /**< version */ | |
| 862 | /** summary */ | |
| 863 | N_("Send and receive raw XMPP stanzas."), | |
| 864 | /** description */ | |
| 865 | N_("This plugin is useful for debbuging XMPP servers or clients."), | |
| 866 | "Sean Egan <seanegan@gmail.com>", /**< author */ | |
| 15884 | 867 | PURPLE_WEBSITE, /**< homepage */ |
| 15412 | 868 | |
| 869 | plugin_load, /**< load */ | |
| 870 | plugin_unload, /**< unload */ | |
| 871 | NULL, /**< destroy */ | |
| 872 | ||
| 873 | NULL, /**< ui_info */ | |
| 874 | NULL, /**< extra_info */ | |
| 875 | NULL, | |
|
16749
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16290
diff
changeset
|
876 | actions, |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16290
diff
changeset
|
877 | |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16290
diff
changeset
|
878 | /* padding */ |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16290
diff
changeset
|
879 | NULL, |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16290
diff
changeset
|
880 | NULL, |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16290
diff
changeset
|
881 | NULL, |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16290
diff
changeset
|
882 | NULL |
| 15412 | 883 | }; |
| 884 | ||
| 885 | static void | |
| 15884 | 886 | init_plugin(PurplePlugin *plugin) |
| 15412 | 887 | { |
| 888 | } | |
| 889 | ||
| 15884 | 890 | PURPLE_INIT_PLUGIN(interval, init_plugin, info) |