| 85 static PidginXmppConsole *console = NULL; |
81 static PidginXmppConsole *console = NULL; |
| 86 |
82 |
| 87 /****************************************************************************** |
83 /****************************************************************************** |
| 88 * Helpers |
84 * Helpers |
| 89 *****************************************************************************/ |
85 *****************************************************************************/ |
| 90 static gboolean |
|
| 91 xmppconsole_is_xmpp_account(PurpleAccount *account) |
|
| 92 { |
|
| 93 const gchar *prpl_name; |
|
| 94 |
|
| 95 prpl_name = purple_account_get_protocol_id(account); |
|
| 96 |
|
| 97 return purple_strequal("prpl-jabber", prpl_name); |
|
| 98 } |
|
| 99 |
|
| 100 static void |
86 static void |
| 101 xmppconsole_append_xmlnode(PidginXmppConsole *console, PurpleXmlNode *node, |
87 xmppconsole_append_xmlnode(PidginXmppConsole *console, PurpleXmlNode *node, |
| 102 gint indent_level, GtkTextIter *iter, |
88 gint indent_level, GtkTextIter *iter, |
| 103 GtkTextTag *tag) |
89 GtkTextTag *tag) |
| 104 { |
90 { |
| 483 gtk_entry_set_text(console->message.thread, "0"); |
469 gtk_entry_set_text(console->message.thread, "0"); |
| 484 gtk_popover_popdown(console->message.popover); |
470 gtk_popover_popdown(console->message.popover); |
| 485 } |
471 } |
| 486 |
472 |
| 487 static void |
473 static void |
| 488 signing_on_cb(PurpleConnection *gc) |
|
| 489 { |
|
| 490 PurpleAccount *account; |
|
| 491 |
|
| 492 if (console == NULL) { |
|
| 493 return; |
|
| 494 } |
|
| 495 |
|
| 496 account = purple_connection_get_account(gc); |
|
| 497 if (!xmppconsole_is_xmpp_account(account)) |
|
| 498 return; |
|
| 499 |
|
| 500 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(console->dropdown), |
|
| 501 purple_account_get_username(account)); |
|
| 502 console->accounts = g_list_append(console->accounts, gc); |
|
| 503 console->count++; |
|
| 504 |
|
| 505 if (console->count == 1) { |
|
| 506 console->gc = gc; |
|
| 507 gtk_text_buffer_set_text(console->buffer, "", 0); |
|
| 508 gtk_combo_box_set_active(GTK_COMBO_BOX(console->dropdown), 0); |
|
| 509 } else |
|
| 510 gtk_widget_show_all(console->hbox); |
|
| 511 } |
|
| 512 |
|
| 513 static void |
|
| 514 signed_off_cb(PurpleConnection *gc) |
|
| 515 { |
|
| 516 int i; |
|
| 517 |
|
| 518 if (console == NULL) { |
|
| 519 return; |
|
| 520 } |
|
| 521 |
|
| 522 i = g_list_index(console->accounts, gc); |
|
| 523 if (i == -1) |
|
| 524 return; |
|
| 525 |
|
| 526 gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(console->dropdown), i); |
|
| 527 console->accounts = g_list_remove(console->accounts, gc); |
|
| 528 console->count--; |
|
| 529 |
|
| 530 if (gc == console->gc) { |
|
| 531 GtkTextIter end; |
|
| 532 gtk_text_buffer_get_end_iter(console->buffer, &end); |
|
| 533 gtk_text_buffer_insert_with_tags(console->buffer, &end, _("Logged out."), -1, |
|
| 534 console->tags.info, NULL); |
|
| 535 console->gc = NULL; |
|
| 536 } |
|
| 537 } |
|
| 538 |
|
| 539 static void |
|
| 540 dropdown_changed_cb(GtkComboBox *widget, gpointer data) { |
474 dropdown_changed_cb(GtkComboBox *widget, gpointer data) { |
| 541 PidginXmppConsole *console = data; |
475 PidginXmppConsole *console = data; |
| 542 |
476 PidginAccountChooser *chooser = PIDGIN_ACCOUNT_CHOOSER(widget); |
| 543 console->gc = g_list_nth_data(console->accounts, |
477 PurpleAccount *account = NULL; |
| 544 gtk_combo_box_get_active(widget)); |
478 |
| 545 gtk_text_buffer_set_text(console->buffer, "", 0); |
479 account = pidgin_account_chooser_get_selected(chooser); |
| |
480 if(PURPLE_IS_ACCOUNT(account)) { |
| |
481 console->gc = purple_account_get_connection(account); |
| |
482 gtk_text_buffer_set_text(console->buffer, "", 0); |
| |
483 } else { |
| |
484 GtkTextIter start, end; |
| |
485 console->gc = NULL; |
| |
486 gtk_text_buffer_set_text(console->buffer, _("Not connected to XMPP"), -1); |
| |
487 gtk_text_buffer_get_bounds(console->buffer, &start, &end); |
| |
488 gtk_text_buffer_apply_tag(console->buffer, console->tags.info, &start, &end); |
| |
489 } |
| 546 } |
490 } |
| 547 |
491 |
| 548 /****************************************************************************** |
492 /****************************************************************************** |
| 549 * GObject Implementation |
493 * GObject Implementation |
| 550 *****************************************************************************/ |
494 *****************************************************************************/ |
| 551 static void |
495 static void |
| 552 pidgin_xmpp_console_finalize(GObject *obj) { |
|
| 553 PidginXmppConsole *console = PIDGIN_XMPP_CONSOLE(obj); |
|
| 554 |
|
| 555 g_clear_pointer(&console->accounts, g_list_free); |
|
| 556 |
|
| 557 G_OBJECT_CLASS(pidgin_xmpp_console_parent_class)->finalize(obj); |
|
| 558 } |
|
| 559 |
|
| 560 static void |
|
| 561 pidgin_xmpp_console_class_finalize(PidginXmppConsoleClass *klass) { |
496 pidgin_xmpp_console_class_finalize(PidginXmppConsoleClass *klass) { |
| 562 } |
497 } |
| 563 |
498 |
| 564 static void |
499 static void |
| 565 pidgin_xmpp_console_class_init(PidginXmppConsoleClass *klass) { |
500 pidgin_xmpp_console_class_init(PidginXmppConsoleClass *klass) { |
| 566 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
| 567 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
501 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
| 568 |
|
| 569 obj_class->finalize = pidgin_xmpp_console_finalize; |
|
| 570 |
502 |
| 571 gtk_widget_class_set_template_from_resource( |
503 gtk_widget_class_set_template_from_resource( |
| 572 widget_class, |
504 widget_class, |
| 573 "/im/pidgin/Pidgin3/Plugin/XMPPConsole/console.ui" |
505 "/im/pidgin/Pidgin3/Plugin/XMPPConsole/console.ui" |
| 574 ); |
506 ); |
| 575 |
507 |
| 576 gtk_widget_class_bind_template_child(widget_class, PidginXmppConsole, |
|
| 577 hbox); |
|
| 578 gtk_widget_class_bind_template_child(widget_class, PidginXmppConsole, |
|
| 579 dropdown); |
|
| 580 gtk_widget_class_bind_template_callback(widget_class, dropdown_changed_cb); |
508 gtk_widget_class_bind_template_callback(widget_class, dropdown_changed_cb); |
| 581 |
509 |
| 582 gtk_widget_class_bind_template_child(widget_class, PidginXmppConsole, |
510 gtk_widget_class_bind_template_child(widget_class, PidginXmppConsole, |
| 583 buffer); |
511 buffer); |
| 584 gtk_widget_class_bind_template_child(widget_class, PidginXmppConsole, |
512 gtk_widget_class_bind_template_child(widget_class, PidginXmppConsole, |
| 651 gtk_widget_class_bind_template_callback(widget_class, entry_changed_cb); |
579 gtk_widget_class_bind_template_callback(widget_class, entry_changed_cb); |
| 652 } |
580 } |
| 653 |
581 |
| 654 static void |
582 static void |
| 655 pidgin_xmpp_console_init(PidginXmppConsole *console) { |
583 pidgin_xmpp_console_init(PidginXmppConsole *console) { |
| 656 GList *connections; |
|
| 657 GtkCssProvider *entry_css; |
584 GtkCssProvider *entry_css; |
| 658 GtkStyleContext *context; |
585 GtkStyleContext *context; |
| 659 |
586 |
| 660 gtk_widget_init_template(GTK_WIDGET(console)); |
587 gtk_widget_init_template(GTK_WIDGET(console)); |
| 661 |
|
| 662 for (connections = purple_connections_get_all(); connections; connections = connections->next) { |
|
| 663 PurpleConnection *gc = connections->data; |
|
| 664 if (xmppconsole_is_xmpp_account(purple_connection_get_account(gc))) { |
|
| 665 console->count++; |
|
| 666 console->accounts = g_list_append(console->accounts, gc); |
|
| 667 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(console->dropdown), |
|
| 668 purple_account_get_username(purple_connection_get_account(gc))); |
|
| 669 if (!console->gc) |
|
| 670 console->gc = gc; |
|
| 671 } |
|
| 672 } |
|
| 673 gtk_combo_box_set_active(GTK_COMBO_BOX(console->dropdown), 0); |
|
| 674 |
|
| 675 if (console->count == 0) { |
|
| 676 GtkTextIter start, end; |
|
| 677 gtk_text_buffer_set_text(console->buffer, _("Not connected to XMPP"), -1); |
|
| 678 gtk_text_buffer_get_bounds(console->buffer, &start, &end); |
|
| 679 gtk_text_buffer_apply_tag(console->buffer, console->tags.info, &start, &end); |
|
| 680 } |
|
| 681 |
588 |
| 682 entry_css = gtk_css_provider_new(); |
589 entry_css = gtk_css_provider_new(); |
| 683 gtk_css_provider_load_from_data(entry_css, |
590 gtk_css_provider_load_from_data(entry_css, |
| 684 "textview." GTK_STYLE_CLASS_ERROR " text {background-color:#ffcece;}", |
591 "textview." GTK_STYLE_CLASS_ERROR " text {background-color:#ffcece;}", |
| 685 -1, NULL); |
592 -1, NULL); |
| 686 context = gtk_widget_get_style_context(console->entry); |
593 context = gtk_widget_get_style_context(console->entry); |
| 687 gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(entry_css), |
594 gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(entry_css), |
| 688 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
595 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
| 689 |
596 |
| 690 entry_changed_cb(console->entry_buffer, console); |
597 entry_changed_cb(console->entry_buffer, console); |
| 691 |
|
| 692 if (console->count < 2) { |
|
| 693 gtk_widget_hide(console->hbox); |
|
| 694 } |
|
| 695 |
598 |
| 696 gtk_widget_show(GTK_WIDGET(console)); |
599 gtk_widget_show(GTK_WIDGET(console)); |
| 697 } |
600 } |
| 698 |
601 |
| 699 /****************************************************************************** |
602 /****************************************************************************** |
| 765 purple_signal_connect(xmpp, "jabber-receiving-xmlnode", plugin, |
668 purple_signal_connect(xmpp, "jabber-receiving-xmlnode", plugin, |
| 766 G_CALLBACK(purple_xmlnode_received_cb), NULL); |
669 G_CALLBACK(purple_xmlnode_received_cb), NULL); |
| 767 purple_signal_connect(xmpp, "jabber-sending-text", plugin, |
670 purple_signal_connect(xmpp, "jabber-sending-text", plugin, |
| 768 G_CALLBACK(purple_xmlnode_sent_cb), NULL); |
671 G_CALLBACK(purple_xmlnode_sent_cb), NULL); |
| 769 |
672 |
| 770 purple_signal_connect(purple_connections_get_handle(), "signing-on", |
|
| 771 plugin, G_CALLBACK(signing_on_cb), NULL); |
|
| 772 purple_signal_connect(purple_connections_get_handle(), "signed-off", |
|
| 773 plugin, G_CALLBACK(signed_off_cb), NULL); |
|
| 774 |
|
| 775 return TRUE; |
673 return TRUE; |
| 776 } |
674 } |
| 777 |
675 |
| 778 static gboolean |
676 static gboolean |
| 779 xmpp_console_unload(GPluginPlugin *plugin, gboolean shutdown, GError **error) |
677 xmpp_console_unload(GPluginPlugin *plugin, gboolean shutdown, GError **error) |