4 * Finch is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #include NCURSES_HEADER
34 #include "gntaccount.h"
39 #include "gntplugin.h"
40 #include "gntpounce.h"
42 #include "gntrequest.h"
44 #include "gntstatus.h"
51 #include "gntmenuitem.h"
52 #include "gntmenuitemcheck.h"
53 #include "gntmenuutil.h"
55 #include "gnttextview.h"
58 #include "gntwindow.h"
60 #define PREF_ROOT "/finch/conversations"
61 #define PREF_CHAT PREF_ROOT "/chats"
62 #define PREF_USERLIST PREF_CHAT "/userlist"
66 static void generate_send_to_menu(FinchConv
*ggc
);
67 static void generate_e2ee_menu(FinchConv
*ggc
);
69 static int color_message_receive
;
70 static int color_message_send
;
71 static int color_message_highlight
;
72 static int color_message_action
;
73 static int color_timestamp
;
76 find_buddy_for_conversation(PurpleConversation
*conv
)
78 return purple_blist_find_buddy(purple_conversation_get_account(conv
),
79 purple_conversation_get_name(conv
));
83 find_chat_for_conversation(PurpleConversation
*conv
)
85 return purple_blist_find_chat(purple_conversation_get_account(conv
),
86 purple_conversation_get_name(conv
));
89 static PurpleBlistNode
*
90 get_conversation_blist_node(PurpleConversation
*conv
)
92 PurpleBlistNode
*node
= NULL
;
94 if (PURPLE_IS_IM_CONVERSATION(conv
)) {
95 node
= (PurpleBlistNode
*)find_buddy_for_conversation(conv
);
96 node
= node
? purple_blist_node_get_parent(node
) : NULL
;
97 } else if (PURPLE_IS_CHAT_CONVERSATION(conv
)) {
98 node
= (PurpleBlistNode
*)find_chat_for_conversation(conv
);
105 send_typing_notification(GntWidget
*w
, FinchConv
*ggconv
)
107 const char *text
= gnt_entry_get_text(GNT_ENTRY(ggconv
->entry
));
108 gboolean empty
= (!text
|| !*text
|| (*text
== '/'));
109 if (purple_prefs_get_bool("/finch/conversations/notify_typing")) {
110 PurpleConversation
*conv
= ggconv
->active_conv
;
111 PurpleIMConversation
*im
= PURPLE_IM_CONVERSATION(conv
);
113 gboolean send
= (purple_im_conversation_get_send_typed_timeout(im
) == 0);
115 purple_im_conversation_stop_send_typed_timeout(im
);
116 purple_im_conversation_start_send_typed_timeout(im
);
117 if (send
|| (purple_im_conversation_get_type_again(im
) != 0 &&
118 time(NULL
) > purple_im_conversation_get_type_again(im
))) {
119 unsigned int timeout
;
120 timeout
= purple_serv_send_typing(purple_conversation_get_connection(conv
),
121 purple_conversation_get_name(conv
),
123 purple_im_conversation_set_type_again(im
, timeout
);
126 purple_im_conversation_stop_send_typed_timeout(im
);
128 purple_serv_send_typing(purple_conversation_get_connection(conv
),
129 purple_conversation_get_name(conv
),
130 PURPLE_IM_NOT_TYPING
);
136 entry_key_pressed(GntWidget
*w
, FinchConv
*ggconv
)
138 const char *text
= gnt_entry_get_text(GNT_ENTRY(ggconv
->entry
));
139 if (*text
== '/' && *(text
+ 1) != '/')
141 PurpleConversation
*conv
= ggconv
->active_conv
;
142 PurpleCmdStatus status
;
143 const char *cmdline
= text
+ 1;
144 char *error
= NULL
, *escape
;
146 escape
= g_markup_escape_text(cmdline
, -1);
147 status
= purple_cmd_do_command(conv
, cmdline
, escape
, &error
);
152 case PURPLE_CMD_STATUS_OK
:
154 case PURPLE_CMD_STATUS_NOT_FOUND
:
155 purple_conversation_write_system_message(conv
,
156 _("No such command."), PURPLE_MESSAGE_NO_LOG
);
158 case PURPLE_CMD_STATUS_WRONG_ARGS
:
159 purple_conversation_write_system_message(conv
,
160 _("Syntax Error: You typed the wrong "
161 "number of arguments to that command."),
162 PURPLE_MESSAGE_NO_LOG
);
164 case PURPLE_CMD_STATUS_FAILED
:
165 purple_conversation_write_system_message(conv
,
166 error
? error
: _("Your command failed for an unknown reason."),
167 PURPLE_MESSAGE_NO_LOG
);
169 case PURPLE_CMD_STATUS_WRONG_TYPE
:
170 if(PURPLE_IS_IM_CONVERSATION(conv
))
171 purple_conversation_write_system_message(conv
,
172 _("That command only works in chats, not IMs."),
173 PURPLE_MESSAGE_NO_LOG
);
175 purple_conversation_write_system_message(conv
,
176 _("That command only works in IMs, not chats."),
177 PURPLE_MESSAGE_NO_LOG
);
179 case PURPLE_CMD_STATUS_WRONG_PROTOCOL
:
180 purple_conversation_write_system_message(conv
,
181 _("That command doesn't work on this protocol."),
182 PURPLE_MESSAGE_NO_LOG
);
187 else if (!purple_account_is_connected(purple_conversation_get_account(ggconv
->active_conv
)))
189 purple_conversation_write_system_message(ggconv
->active_conv
,
190 _("Message was not sent, because you are not signed on."),
191 PURPLE_MESSAGE_ERROR
| PURPLE_MESSAGE_NO_LOG
);
195 char *escape
= purple_markup_escape_text((*text
== '/' ? text
+ 1 : text
), -1);
196 purple_conversation_send(ggconv
->active_conv
, escape
);
200 gnt_entry_add_to_history(GNT_ENTRY(ggconv
->entry
), text
);
201 gnt_entry_clear(GNT_ENTRY(ggconv
->entry
));
205 closing_window(GntWidget
*window
, FinchConv
*ggconv
)
207 GList
*list
= ggconv
->list
;
208 ggconv
->window
= NULL
;
210 PurpleConversation
*conv
= list
->data
;
212 g_object_unref(conv
);
217 size_changed_cb(GntWidget
*widget
, int width
, int height
)
220 gnt_widget_get_size(widget
, &w
, &h
);
221 purple_prefs_set_int(PREF_ROOT
"/size/width", w
);
222 purple_prefs_set_int(PREF_ROOT
"/size/height", h
);
226 save_position_cb(GntWidget
*w
, int x
, int y
)
228 purple_prefs_set_int(PREF_ROOT
"/position/x", x
);
229 purple_prefs_set_int(PREF_ROOT
"/position/y", y
);
232 static PurpleIMConversation
*
233 find_im_with_contact(PurpleAccount
*account
, const char *name
)
235 PurpleBlistNode
*node
;
236 PurpleBuddy
*buddy
= purple_blist_find_buddy(account
, name
);
237 PurpleIMConversation
*im
= NULL
;
242 for (node
= purple_blist_node_get_first_child(purple_blist_node_get_parent((PurpleBlistNode
*)buddy
));
243 node
; node
= purple_blist_node_get_sibling_next(node
)) {
244 if (node
== (PurpleBlistNode
*)buddy
)
246 if ((im
= purple_conversations_find_im_with_account(
247 purple_buddy_get_name((PurpleBuddy
*)node
), purple_buddy_get_account((PurpleBuddy
*)node
))) != NULL
)
254 get_conversation_title(PurpleConversation
*conv
, PurpleAccount
*account
)
256 PurpleE2eeState
*e2ee
;
258 e2ee
= purple_conversation_get_e2ee_state(conv
);
260 return g_strdup_printf(_("%s (%s -- %s)%s%s%s%s"),
261 purple_conversation_get_title(conv
),
262 purple_account_get_username(account
),
263 purple_account_get_protocol_name(account
),
265 e2ee
? purple_e2ee_provider_get_name(purple_e2ee_state_get_provider(e2ee
)) : "",
267 e2ee
? purple_e2ee_state_get_name(e2ee
) : "");
271 update_buddy_typing(PurpleAccount
*account
, const char *who
, gpointer null
)
274 PurpleIMConversation
*im
;
275 PurpleConversation
*conv
;
278 im
= purple_conversations_find_im_with_account(who
, account
);
283 conv
= PURPLE_CONVERSATION(im
);
284 ggc
= FINCH_CONV(conv
);
286 if (purple_im_conversation_get_typing_state(im
) == PURPLE_IM_TYPING
) {
288 str
= get_conversation_title(conv
, account
);
289 title
= g_strdup_printf(_("%s [%s]"), str
,
290 gnt_ascii_only() ? "T" : "\342\243\277");
293 scroll
= gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggc
->tv
));
294 str
= g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_title(conv
));
295 /* Updating is a little buggy. So just remove and add a new one */
296 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc
->tv
), "typing", NULL
, TRUE
);
297 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggc
->tv
),
298 str
, GNT_TEXT_FLAG_DIM
, "typing");
301 gnt_text_view_scroll(GNT_TEXT_VIEW(ggc
->tv
), 0);
303 title
= get_conversation_title(conv
, account
);
304 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc
->tv
), "typing", " ", TRUE
);
306 gnt_screen_rename_widget(ggc
->window
, title
);
311 chat_left_cb(PurpleConversation
*conv
, gpointer null
)
313 purple_conversation_write_system_message(conv
,
314 _("You have left this chat."), 0);
318 buddy_signed_on_off(PurpleBuddy
*buddy
, gpointer null
)
320 PurpleIMConversation
*im
= find_im_with_contact(purple_buddy_get_account(buddy
), purple_buddy_get_name(buddy
));
323 generate_send_to_menu(FINCH_CONV(PURPLE_CONVERSATION(im
)));
327 account_signed_on_off(PurpleConnection
*gc
, gpointer null
)
329 GList
*list
= purple_conversations_get_ims();
331 PurpleConversation
*conv
= list
->data
;
332 PurpleIMConversation
*cc
= find_im_with_contact(
333 purple_conversation_get_account(conv
), purple_conversation_get_name(conv
));
335 generate_send_to_menu(FINCH_CONV(PURPLE_CONVERSATION(cc
)));
339 if (PURPLE_CONNECTION_IS_CONNECTED(gc
)) {
340 /* We just signed on. Let's see if there's any chat that we have open,
341 * and hadn't left before the disconnect. */
342 list
= purple_conversations_get_chats();
344 PurpleConversation
*conv
= list
->data
;
346 GHashTable
*comps
= NULL
;
349 if (purple_conversation_get_account(conv
) != purple_connection_get_account(gc
) ||
350 !g_object_get_data(G_OBJECT(conv
), "want-to-rejoin"))
353 chat
= find_chat_for_conversation(conv
);
355 PurpleProtocol
*protocol
= purple_connection_get_protocol(gc
);
356 comps
= purple_protocol_chat_iface_info_defaults(protocol
, gc
,
357 purple_conversation_get_name(conv
));
359 comps
= purple_chat_get_components(chat
);
361 purple_serv_join_chat(gc
, comps
);
362 if (chat
== NULL
&& comps
!= NULL
)
363 g_hash_table_destroy(comps
);
369 account_signing_off(PurpleConnection
*gc
)
371 GList
*list
= purple_conversations_get_chats();
372 PurpleAccount
*account
= purple_connection_get_account(gc
);
374 /* We are about to sign off. See which chats we are currently in, and mark
375 * them for rejoin on reconnect. */
377 PurpleConversation
*conv
= list
->data
;
378 if (!purple_chat_conversation_has_left(PURPLE_CHAT_CONVERSATION(conv
)) &&
379 purple_conversation_get_account(conv
) == account
) {
380 g_object_set_data(G_OBJECT(conv
), "want-to-rejoin", GINT_TO_POINTER(TRUE
));
381 purple_conversation_write_system_message(conv
,
382 _("The account has disconnected and you are no "
383 "longer in this chat. You will be automatically rejoined in the chat when "
384 "the account reconnects."),
385 PURPLE_MESSAGE_NO_LOG
);
392 finch_conv_get_handle(void)
399 cleared_message_history_cb(PurpleConversation
*conv
, gpointer data
)
401 FinchConv
*ggc
= FINCH_CONV(conv
);
403 gnt_text_view_clear(GNT_TEXT_VIEW(ggc
->tv
));
407 gg_extended_menu(FinchConv
*ggc
)
411 gboolean is_empty
= TRUE
;
413 g_return_if_fail(ggc
!= NULL
);
415 sub
= GNT_MENU(gnt_menu_new(GNT_MENU_POPUP
));
416 gnt_menuitem_set_submenu(ggc
->plugins
, sub
);
418 for (list
= purple_conversation_get_extended_menu(ggc
->active_conv
);
419 list
; list
= g_list_delete_link(list
, list
))
421 finch_append_menu_action(sub
, list
->data
, ggc
->active_conv
);
424 gnt_menuitem_set_visible(ggc
->plugins
, !is_empty
);
428 conv_updated(PurpleConversation
*conv
, PurpleConversationUpdateType type
)
430 if (purple_conversation_get_ui_data(conv
) == NULL
)
433 if (type
== PURPLE_CONVERSATION_UPDATE_FEATURES
) {
434 gg_extended_menu(purple_conversation_get_ui_data(conv
));
437 if (type
== PURPLE_CONVERSATION_UPDATE_E2EE
) {
438 FinchConv
*ggconv
= FINCH_CONV(conv
);
441 title
= get_conversation_title(conv
,
442 purple_conversation_get_account(conv
));
443 gnt_screen_rename_widget(ggconv
->window
, title
);
446 generate_e2ee_menu(ggconv
);
453 clear_scrollback_cb(GntMenuItem
*item
, gpointer ggconv
)
455 FinchConv
*ggc
= ggconv
;
456 purple_conversation_clear_message_history(ggc
->active_conv
);
460 send_file_cb(GntMenuItem
*item
, gpointer ggconv
)
462 FinchConv
*ggc
= ggconv
;
463 purple_serv_send_file(purple_conversation_get_connection(ggc
->active_conv
),
464 purple_conversation_get_name(ggc
->active_conv
), NULL
);
468 add_pounce_cb(GntMenuItem
*item
, gpointer ggconv
)
470 FinchConv
*ggc
= ggconv
;
471 finch_pounce_editor_show(
472 purple_conversation_get_account(ggc
->active_conv
),
473 purple_conversation_get_name(ggc
->active_conv
), NULL
);
477 get_info_cb(GntMenuItem
*item
, gpointer ggconv
)
479 FinchConv
*ggc
= ggconv
;
480 finch_retrieve_user_info(purple_conversation_get_connection(ggc
->active_conv
),
481 purple_conversation_get_name(ggc
->active_conv
));
485 toggle_timestamps_cb(GntMenuItem
*item
, gpointer ggconv
)
487 purple_prefs_set_bool(PREF_ROOT
"/timestamps",
488 !purple_prefs_get_bool(PREF_ROOT
"/timestamps"));
492 toggle_logging_cb(GntMenuItem
*item
, gpointer ggconv
)
494 FinchConv
*fc
= ggconv
;
495 PurpleConversation
*conv
= fc
->active_conv
;
496 gboolean logging
= gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item
));
499 if (logging
== purple_conversation_is_logging(conv
))
504 /* Enable logging first so the message below can be logged. */
505 purple_conversation_set_logging(conv
, TRUE
);
507 purple_conversation_write_system_message(conv
,
508 _("Logging started. Future messages in this "
509 "conversation will be logged."), 0);
511 purple_conversation_write_system_message(conv
,
512 _("Logging stopped. Future messages in this "
513 "conversation will not be logged."), 0);
515 /* Disable the logging second, so that the above message can be logged. */
516 purple_conversation_set_logging(conv
, FALSE
);
519 /* Each conversation with the same person will have the same logging setting */
520 for (iter
= fc
->list
; iter
; iter
= iter
->next
) {
521 if (iter
->data
== conv
)
523 purple_conversation_set_logging(iter
->data
, logging
);
528 toggle_sound_cb(GntMenuItem
*item
, gpointer ggconv
)
530 FinchConv
*fc
= ggconv
;
531 PurpleBlistNode
*node
= get_conversation_blist_node(fc
->active_conv
);
532 fc
->flags
^= FINCH_CONV_NO_SOUND
;
534 purple_blist_node_set_bool(node
, "gnt-mute-sound", !!(fc
->flags
& FINCH_CONV_NO_SOUND
));
538 send_to_cb(GntMenuItem
*m
, gpointer n
)
540 PurpleAccount
*account
= g_object_get_data(G_OBJECT(m
), "purple_account");
541 gchar
*buddy
= g_object_get_data(G_OBJECT(m
), "purple_buddy_name");
542 PurpleIMConversation
*im
= purple_im_conversation_new(account
, buddy
);
543 finch_conversation_set_active(PURPLE_CONVERSATION(im
));
547 view_log_cb(GntMenuItem
*n
, gpointer ggc
)
550 PurpleConversation
*conv
;
553 PurpleAccount
*account
;
558 conv
= fc
->active_conv
;
560 if (PURPLE_IS_IM_CONVERSATION(conv
))
561 type
= PURPLE_LOG_IM
;
562 else if (PURPLE_IS_CHAT_CONVERSATION(conv
))
563 type
= PURPLE_LOG_CHAT
;
567 name
= purple_conversation_get_name(conv
);
568 account
= purple_conversation_get_account(conv
);
570 buddies
= purple_blist_find_buddies(account
, name
);
571 for (cur
= buddies
; cur
!= NULL
; cur
= cur
->next
) {
572 PurpleBlistNode
*node
= cur
->data
;
573 if ((node
!= NULL
) &&
574 (purple_blist_node_get_sibling_prev(node
) || purple_blist_node_get_sibling_next(node
))) {
575 finch_log_show_contact((PurpleContact
*)purple_blist_node_get_parent(node
));
576 g_slist_free(buddies
);
580 g_slist_free(buddies
);
582 finch_log_show(type
, name
, account
);
586 generate_send_to_menu(FinchConv
*ggc
)
588 GntWidget
*sub
, *menu
= ggc
->menu
;
593 buds
= purple_blist_find_buddies(purple_conversation_get_account(ggc
->active_conv
),
594 purple_conversation_get_name(ggc
->active_conv
));
598 if ((item
= ggc
->u
.im
->sendto
) == NULL
) {
599 item
= gnt_menuitem_new(_("Send To"));
600 gnt_menu_add_item(GNT_MENU(menu
), item
);
601 ggc
->u
.im
->sendto
= item
;
603 sub
= gnt_menu_new(GNT_MENU_POPUP
);
604 gnt_menuitem_set_submenu(item
, GNT_MENU(sub
));
606 for (; buds
; buds
= g_slist_delete_link(buds
, buds
)) {
607 PurpleBlistNode
*node
= PURPLE_BLIST_NODE(purple_buddy_get_contact(PURPLE_BUDDY(buds
->data
)));
608 for (node
= purple_blist_node_get_first_child(node
); node
!= NULL
;
609 node
= purple_blist_node_get_sibling_next(node
)) {
610 PurpleBuddy
*buddy
= (PurpleBuddy
*)node
;
611 PurpleAccount
*account
= purple_buddy_get_account(buddy
);
612 if (purple_account_is_connected(account
)) {
613 /* Use the PurplePresence to get unique buddies. */
614 PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
615 if (!g_list_find(list
, presence
))
616 list
= g_list_prepend(list
, presence
);
620 for (list
= g_list_reverse(list
); list
!= NULL
; list
= g_list_delete_link(list
, list
)) {
621 PurplePresence
*pre
= list
->data
;
622 PurpleBuddy
*buddy
= purple_buddy_presence_get_buddy(PURPLE_BUDDY_PRESENCE(pre
));
623 PurpleAccount
*account
= purple_buddy_get_account(buddy
);
624 gchar
*name
= g_strdup(purple_buddy_get_name(buddy
));
625 gchar
*text
= g_strdup_printf("%s (%s)", purple_buddy_get_name(buddy
), purple_account_get_username(account
));
626 item
= gnt_menuitem_new(text
);
628 gnt_menu_add_item(GNT_MENU(sub
), item
);
629 gnt_menuitem_set_callback(item
, send_to_cb
, NULL
);
630 g_object_set_data(G_OBJECT(item
), "purple_account", account
);
631 g_object_set_data_full(G_OBJECT(item
), "purple_buddy_name", name
, g_free
);
636 generate_e2ee_menu(FinchConv
*ggc
)
639 GntWidget
*menu
= ggc
->menu
;
640 PurpleConversation
*conv
= ggc
->active_conv
;
642 PurpleE2eeProvider
*eprov
;
643 GList
*menu_actions
, *it
;
645 eprov
= purple_e2ee_provider_get_main();
647 item
= ggc
->u
.im
->e2ee_menu
;
649 item
= gnt_menuitem_new(NULL
);
650 gnt_menu_add_item(GNT_MENU(menu
), item
);
651 ggc
->u
.im
->e2ee_menu
= item
;
653 sub
= GNT_MENU(gnt_menu_new(GNT_MENU_POPUP
));
654 gnt_menuitem_set_submenu(item
, GNT_MENU(sub
));
656 gnt_menuitem_set_visible(item
, (eprov
!= NULL
));
659 gnt_menuitem_set_text(item
, purple_e2ee_provider_get_name(eprov
));
661 menu_actions
= purple_e2ee_provider_get_conv_menu_actions(eprov
, conv
);
662 for (it
= menu_actions
; it
; it
= g_list_next(it
)) {
663 PurpleActionMenu
*action
= it
->data
;
665 finch_append_menu_action(sub
, action
, conv
);
667 g_list_free(menu_actions
);
671 invite_cb(GntMenuItem
*item
, gpointer ggconv
)
673 FinchConv
*fc
= ggconv
;
674 PurpleChatConversation
*chat
= PURPLE_CHAT_CONVERSATION(fc
->active_conv
);
675 purple_chat_conversation_invite_user(chat
, NULL
, NULL
, TRUE
);
679 plugin_changed_cb(PurplePlugin
*p
, gpointer data
)
681 gg_extended_menu(data
);
685 gg_create_menu(FinchConv
*ggc
)
687 GntWidget
*menu
, *sub
;
690 ggc
->menu
= menu
= gnt_menu_new(GNT_MENU_TOPLEVEL
);
691 gnt_window_set_menu(GNT_WINDOW(ggc
->window
), GNT_MENU(menu
));
693 item
= gnt_menuitem_new(_("Conversation"));
694 gnt_menu_add_item(GNT_MENU(menu
), item
);
696 sub
= gnt_menu_new(GNT_MENU_POPUP
);
697 gnt_menuitem_set_submenu(item
, GNT_MENU(sub
));
699 item
= gnt_menuitem_new(_("Clear Scrollback"));
700 gnt_menu_add_item(GNT_MENU(sub
), item
);
701 gnt_menuitem_set_callback(item
, clear_scrollback_cb
, ggc
);
703 item
= gnt_menuitem_check_new(_("Show Timestamps"));
704 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item
),
705 purple_prefs_get_bool(PREF_ROOT
"/timestamps"));
706 gnt_menu_add_item(GNT_MENU(sub
), item
);
707 gnt_menuitem_set_callback(item
, toggle_timestamps_cb
, ggc
);
709 if (PURPLE_IS_IM_CONVERSATION(ggc
->active_conv
)) {
710 PurpleAccount
*account
= purple_conversation_get_account(ggc
->active_conv
);
711 PurpleConnection
*gc
= purple_account_get_connection(account
);
712 PurpleProtocol
*protocol
=
713 gc
? purple_connection_get_protocol(gc
) : NULL
;
715 if (protocol
&& PURPLE_PROTOCOL_IMPLEMENTS(protocol
, SERVER
, get_info
)) {
716 item
= gnt_menuitem_new(_("Get Info"));
717 gnt_menu_add_item(GNT_MENU(sub
), item
);
718 gnt_menuitem_set_callback(item
, get_info_cb
, ggc
);
721 item
= gnt_menuitem_new(_("Add Buddy Pounce..."));
722 gnt_menu_add_item(GNT_MENU(sub
), item
);
723 gnt_menuitem_set_callback(item
, add_pounce_cb
, ggc
);
725 if (PURPLE_IS_PROTOCOL_XFER(protocol
) &&
726 purple_protocol_xfer_can_receive(
727 PURPLE_PROTOCOL_XFER(protocol
),
729 purple_conversation_get_name(ggc
->active_conv
)
732 item
= gnt_menuitem_new(_("Send File"));
733 gnt_menu_add_item(GNT_MENU(sub
), item
);
734 gnt_menuitem_set_callback(item
, send_file_cb
, ggc
);
737 generate_send_to_menu(ggc
);
738 } else if (PURPLE_IS_CHAT_CONVERSATION(ggc
->active_conv
)) {
739 item
= gnt_menuitem_new(_("Invite..."));
740 gnt_menu_add_item(GNT_MENU(sub
), item
);
741 gnt_menuitem_set_callback(item
, invite_cb
, ggc
);
744 generate_e2ee_menu(ggc
);
746 item
= gnt_menuitem_new(_("View Log..."));
747 gnt_menu_add_item(GNT_MENU(sub
), item
);
748 gnt_menuitem_set_callback(item
, view_log_cb
, ggc
);
750 item
= gnt_menuitem_check_new(_("Enable Logging"));
751 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item
),
752 purple_conversation_is_logging(ggc
->active_conv
));
753 gnt_menu_add_item(GNT_MENU(sub
), item
);
754 gnt_menuitem_set_callback(item
, toggle_logging_cb
, ggc
);
756 item
= gnt_menuitem_check_new(_("Enable Sounds"));
757 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item
),
758 !(ggc
->flags
& FINCH_CONV_NO_SOUND
));
759 gnt_menu_add_item(GNT_MENU(sub
), item
);
760 gnt_menuitem_set_callback(item
, toggle_sound_cb
, ggc
);
762 item
= gnt_menuitem_new(_("Plugins"));
763 gnt_menu_add_item(GNT_MENU(menu
), item
);
766 gg_extended_menu(ggc
);
770 create_conv_from_userlist(GntWidget
*widget
, FinchConv
*fc
)
772 PurpleAccount
*account
= purple_conversation_get_account(fc
->active_conv
);
773 PurpleConnection
*gc
= purple_account_get_connection(account
);
774 PurpleProtocol
*protocol
= NULL
;
775 char *name
, *realname
= NULL
;
778 purple_conversation_write_system_message(fc
->active_conv
,
779 _("You are not connected."), 0);
783 name
= gnt_tree_get_selection_data(GNT_TREE(widget
));
785 protocol
= purple_connection_get_protocol(gc
);
787 realname
= purple_protocol_chat_iface_get_user_real_name(protocol
, gc
,
788 purple_chat_conversation_get_id(
789 PURPLE_CHAT_CONVERSATION(fc
->active_conv
)), name
);
791 purple_im_conversation_new(account
, realname
? realname
: name
);
796 gained_focus_cb(GntWindow
*window
, FinchConv
*fc
)
799 for (iter
= fc
->list
; iter
; iter
= iter
->next
) {
800 g_object_set_data(G_OBJECT(iter
->data
), "unseen-count", 0);
801 purple_conversation_update(iter
->data
, PURPLE_CONVERSATION_UPDATE_UNSEEN
);
806 completion_cb(GntEntry
*entry
, const char *start
, G_GNUC_UNUSED
const char *end
)
808 if (start
== gnt_entry_get_text(entry
) && *start
!= '/')
809 gnt_widget_key_pressed(GNT_WIDGET(entry
), ": ");
813 gg_setup_commands(FinchConv
*fconv
, gboolean remove_first
)
816 char command
[256] = "/";
819 commands
= purple_cmd_list(NULL
);
820 for (; commands
; commands
= g_list_delete_link(commands
, commands
)) {
821 g_strlcpy(command
+ 1, commands
->data
, sizeof(command
) - 1);
822 gnt_entry_remove_suggest(GNT_ENTRY(fconv
->entry
), command
);
826 commands
= purple_cmd_list(fconv
->active_conv
);
827 for (; commands
; commands
= g_list_delete_link(commands
, commands
)) {
828 g_strlcpy(command
+ 1, commands
->data
, sizeof(command
) - 1);
829 gnt_entry_add_suggest(GNT_ENTRY(fconv
->entry
), command
);
834 cmd_added_cb(const char *cmd
, PurpleCmdPriority prior
, PurpleCmdFlag flags
,
837 gg_setup_commands(fconv
, TRUE
);
841 cmd_removed_cb(const char *cmd
, FinchConv
*fconv
)
843 char command
[256] = "/";
844 g_strlcpy(command
+ 1, cmd
, sizeof(command
) - 1);
845 gnt_entry_remove_suggest(GNT_ENTRY(fconv
->entry
), command
);
846 gg_setup_commands(fconv
, TRUE
);
850 finch_create_conversation(PurpleConversation
*conv
)
852 FinchConv
*ggc
= FINCH_CONV(conv
);
854 PurpleConversation
*cc
;
855 PurpleAccount
*account
;
856 PurpleBlistNode
*convnode
= NULL
;
859 gnt_window_present(ggc
->window
);
863 account
= purple_conversation_get_account(conv
);
864 cc
= PURPLE_CONVERSATION(find_im_with_contact(account
, purple_conversation_get_name(conv
)));
865 if (cc
&& FINCH_CONV(cc
))
866 ggc
= FINCH_CONV(cc
);
868 ggc
= g_new0(FinchConv
, 1);
870 /* Each conversation with the same person will have the same logging setting */
872 purple_conversation_set_logging(conv
,
873 purple_conversation_is_logging(ggc
->list
->data
));
876 ggc
->list
= g_list_prepend(ggc
->list
, conv
);
877 ggc
->active_conv
= conv
;
878 purple_conversation_set_ui_data(conv
, ggc
);
880 if (cc
&& FINCH_CONV(cc
) && cc
!= conv
) {
881 finch_conversation_set_active(conv
);
885 title
= get_conversation_title(conv
, account
);
887 ggc
->window
= gnt_vwindow_new(FALSE
);
888 gnt_box_set_title(GNT_BOX(ggc
->window
), title
);
889 gnt_box_set_toplevel(GNT_BOX(ggc
->window
), TRUE
);
890 gnt_box_set_pad(GNT_BOX(ggc
->window
), 0);
892 if (PURPLE_IS_IM_CONVERSATION(conv
))
893 gnt_widget_set_name(ggc
->window
, "conversation-window-im");
894 else if (PURPLE_IS_CHAT_CONVERSATION(conv
))
895 gnt_widget_set_name(ggc
->window
, "conversation-window-chat");
897 gnt_widget_set_name(ggc
->window
, "conversation-window-other");
899 ggc
->tv
= gnt_text_view_new();
900 gnt_widget_set_name(ggc
->tv
, "conversation-window-textview");
901 gnt_widget_set_size(ggc
->tv
, purple_prefs_get_int(PREF_ROOT
"/size/width"),
902 purple_prefs_get_int(PREF_ROOT
"/size/height"));
904 if (PURPLE_IS_CHAT_CONVERSATION(conv
)) {
905 GntWidget
*hbox
, *tree
;
906 FinchConvChat
*fc
= ggc
->u
.chat
= g_new0(FinchConvChat
, 1);
907 hbox
= gnt_hbox_new(FALSE
);
908 gnt_box_set_pad(GNT_BOX(hbox
), 0);
909 tree
= fc
->userlist
= gnt_tree_new_with_columns(2);
910 gnt_tree_set_col_width(GNT_TREE(tree
), 0, 1); /* The flag column */
911 gnt_tree_set_compare_func(GNT_TREE(tree
), (GCompareFunc
)g_utf8_collate
);
912 gnt_tree_set_hash_fns(GNT_TREE(tree
), g_str_hash
, g_str_equal
, g_free
);
913 gnt_tree_set_search_column(GNT_TREE(tree
), 1);
914 gnt_widget_set_has_border(tree
, FALSE
);
915 gnt_box_add_widget(GNT_BOX(hbox
), ggc
->tv
);
916 gnt_box_add_widget(GNT_BOX(hbox
), tree
);
917 gnt_box_add_widget(GNT_BOX(ggc
->window
), hbox
);
918 g_signal_connect(G_OBJECT(tree
), "activate", G_CALLBACK(create_conv_from_userlist
), ggc
);
919 gnt_widget_set_visible(tree
, purple_prefs_get_bool(PREF_USERLIST
));
921 ggc
->u
.im
= g_new0(FinchConvIm
, 1);
922 gnt_box_add_widget(GNT_BOX(ggc
->window
), ggc
->tv
);
925 ggc
->info
= gnt_vbox_new(FALSE
);
926 gnt_box_add_widget(GNT_BOX(ggc
->window
), ggc
->info
);
928 ggc
->entry
= gnt_entry_new(NULL
);
929 gnt_box_add_widget(GNT_BOX(ggc
->window
), ggc
->entry
);
930 gnt_widget_set_name(ggc
->entry
, "conversation-window-entry");
931 gnt_entry_set_history_length(GNT_ENTRY(ggc
->entry
), -1);
932 gnt_entry_set_word_suggest(GNT_ENTRY(ggc
->entry
), TRUE
);
933 gnt_entry_set_always_suggest(GNT_ENTRY(ggc
->entry
), FALSE
);
935 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(ggc
->tv
), ggc
->entry
);
936 gnt_text_view_attach_pager_widget(GNT_TEXT_VIEW(ggc
->tv
), ggc
->entry
);
938 g_signal_connect_after(G_OBJECT(ggc
->entry
), "activate", G_CALLBACK(entry_key_pressed
), ggc
);
939 g_signal_connect(G_OBJECT(ggc
->entry
), "completion", G_CALLBACK(completion_cb
), NULL
);
940 g_signal_connect(G_OBJECT(ggc
->window
), "destroy", G_CALLBACK(closing_window
), ggc
);
942 gnt_widget_set_position(ggc
->window
, purple_prefs_get_int(PREF_ROOT
"/position/x"),
943 purple_prefs_get_int(PREF_ROOT
"/position/y"));
944 gnt_widget_show(ggc
->window
);
946 g_signal_connect(G_OBJECT(ggc
->tv
), "size_changed", G_CALLBACK(size_changed_cb
), NULL
);
947 g_signal_connect(G_OBJECT(ggc
->window
), "position_set", G_CALLBACK(save_position_cb
), NULL
);
949 if (PURPLE_IS_IM_CONVERSATION(conv
))
950 g_signal_connect(G_OBJECT(ggc
->entry
), "text_changed", G_CALLBACK(send_typing_notification
), ggc
);
952 convnode
= get_conversation_blist_node(conv
);
953 if ((convnode
&& purple_blist_node_get_bool(convnode
, "gnt-mute-sound")) ||
954 !finch_sound_is_enabled())
955 ggc
->flags
|= FINCH_CONV_NO_SOUND
;
958 gg_setup_commands(ggc
, FALSE
);
960 purple_signal_connect(purple_cmds_get_handle(), "cmd-added", ggc
,
961 G_CALLBACK(cmd_added_cb
), ggc
);
962 purple_signal_connect(purple_cmds_get_handle(), "cmd-removed", ggc
,
963 G_CALLBACK(cmd_removed_cb
), ggc
);
965 purple_signal_connect(purple_plugins_get_handle(), "plugin-load", ggc
,
966 PURPLE_CALLBACK(plugin_changed_cb
), ggc
);
967 purple_signal_connect(purple_plugins_get_handle(), "plugin-unload", ggc
,
968 PURPLE_CALLBACK(plugin_changed_cb
), ggc
);
971 gnt_box_give_focus_to_child(GNT_BOX(ggc
->window
), ggc
->entry
);
972 g_signal_connect(G_OBJECT(ggc
->window
), "gained-focus", G_CALLBACK(gained_focus_cb
), ggc
);
976 finch_destroy_conversation(PurpleConversation
*conv
)
979 FinchConv
*ggc
= FINCH_CONV(conv
);
980 ggc
->list
= g_list_remove(ggc
->list
, conv
);
981 if (ggc
->list
&& conv
== ggc
->active_conv
)
982 finch_conversation_set_active(ggc
->list
->data
);
984 if (ggc
->list
== NULL
) {
986 purple_signals_disconnect_by_handle(ggc
);
988 gnt_widget_destroy(ggc
->window
);
994 finch_write_conv(PurpleConversation
*conv
, PurpleMessage
*msg
)
996 FinchConv
*ggconv
= FINCH_CONV(conv
);
997 char *strip
, *newline
;
998 GntTextFormatFlags fl
= 0;
1000 PurpleMessageFlags flags
= purple_message_get_flags(msg
);
1002 g_return_if_fail(ggconv
!= NULL
);
1004 if ((flags
& PURPLE_MESSAGE_SYSTEM
) && !(flags
& PURPLE_MESSAGE_NOTIFY
)) {
1005 flags
&= ~(PURPLE_MESSAGE_SEND
| PURPLE_MESSAGE_RECV
);
1008 if (ggconv
->active_conv
!= conv
) {
1009 if (flags
& (PURPLE_MESSAGE_SEND
| PURPLE_MESSAGE_RECV
))
1010 finch_conversation_set_active(conv
);
1015 pos
= gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggconv
->tv
));
1017 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggconv
->tv
), "typing", NULL
, TRUE
);
1018 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv
->tv
), "\n", GNT_TEXT_FLAG_NORMAL
);
1020 /* Unnecessary to print the timestamp for delayed message */
1021 if (purple_prefs_get_bool("/finch/conversations/timestamps")) {
1022 time_t mtime
= purple_message_get_time(msg
);
1025 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv
->tv
),
1026 purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime
)), gnt_color_pair(color_timestamp
));
1029 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv
->tv
), " ", GNT_TEXT_FLAG_NORMAL
);
1031 if (flags
& PURPLE_MESSAGE_AUTO_RESP
)
1032 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv
->tv
),
1033 _("<AUTO-REPLY> "), GNT_TEXT_FLAG_BOLD
);
1035 if (purple_message_get_author(msg
) && (flags
& (PURPLE_MESSAGE_SEND
| PURPLE_MESSAGE_RECV
)) &&
1036 !(flags
& PURPLE_MESSAGE_NOTIFY
))
1039 GntTextFormatFlags msgflags
= GNT_TEXT_FLAG_NORMAL
;
1040 gboolean me
= FALSE
;
1041 gchar
*msg_text
= g_strdup(purple_message_get_contents(msg
));
1043 if (purple_message_meify(msg_text
, -1)) {
1044 name
= g_strdup_printf("*** %s", purple_message_get_author_alias(msg
));
1045 if (!(flags
& PURPLE_MESSAGE_SEND
) &&
1046 (flags
& PURPLE_MESSAGE_NICK
))
1047 msgflags
= gnt_color_pair(color_message_highlight
);
1049 msgflags
= gnt_color_pair(color_message_action
);
1052 name
= g_strdup_printf("%s", purple_message_get_author_alias(msg
));
1053 if (flags
& PURPLE_MESSAGE_SEND
)
1054 msgflags
= gnt_color_pair(color_message_send
);
1055 else if (flags
& PURPLE_MESSAGE_NICK
)
1056 msgflags
= gnt_color_pair(color_message_highlight
);
1058 msgflags
= gnt_color_pair(color_message_receive
);
1060 purple_message_set_contents(msg
, msg_text
); /* might be "meified" */
1061 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv
->tv
),
1063 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv
->tv
), me
? " " : ": ", GNT_TEXT_FLAG_NORMAL
);
1067 fl
= GNT_TEXT_FLAG_DIM
;
1069 if (flags
& PURPLE_MESSAGE_ERROR
)
1070 fl
|= GNT_TEXT_FLAG_BOLD
;
1072 /* XXX: Remove this workaround when textview can parse messages. */
1073 newline
= purple_strdup_withhtml(purple_message_get_contents(msg
));
1074 strip
= purple_markup_strip_html(newline
);
1075 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv
->tv
),
1081 if (PURPLE_IS_IM_CONVERSATION(conv
) && purple_im_conversation_get_typing_state(
1082 PURPLE_IM_CONVERSATION(conv
)) == PURPLE_IM_TYPING
) {
1083 strip
= g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_title(conv
));
1084 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggconv
->tv
),
1085 strip
, GNT_TEXT_FLAG_DIM
, "typing");
1090 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv
->tv
), 0);
1092 if (flags
& (PURPLE_MESSAGE_RECV
| PURPLE_MESSAGE_NICK
| PURPLE_MESSAGE_ERROR
))
1093 gnt_widget_set_urgent(ggconv
->tv
);
1094 if (flags
& PURPLE_MESSAGE_RECV
&& !gnt_widget_has_focus(ggconv
->window
)) {
1095 int count
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv
), "unseen-count"));
1096 g_object_set_data(G_OBJECT(conv
), "unseen-count", GINT_TO_POINTER(count
+ 1));
1097 purple_conversation_update(conv
, PURPLE_CONVERSATION_UPDATE_UNSEEN
);
1102 chat_flag_text(PurpleChatUserFlags flags
)
1104 if (flags
& PURPLE_CHAT_USER_FOUNDER
)
1106 if (flags
& PURPLE_CHAT_USER_OP
)
1108 if (flags
& PURPLE_CHAT_USER_HALFOP
)
1110 if (flags
& PURPLE_CHAT_USER_VOICE
)
1116 finch_chat_add_users(PurpleChatConversation
*chat
, GList
*users
, gboolean new_arrivals
)
1118 PurpleConversation
*conv
= PURPLE_CONVERSATION(chat
);
1119 FinchConv
*ggc
= FINCH_CONV(conv
);
1120 GntEntry
*entry
= GNT_ENTRY(ggc
->entry
);
1124 /* Print the list of users in the room */
1125 GString
*string
= g_string_new(NULL
);
1127 int count
= g_list_length(users
);
1129 g_string_printf(string
,
1130 ngettext("List of %d user:\n", "List of %d users:\n", count
), count
);
1131 for (iter
= users
; iter
; iter
= iter
->next
)
1133 PurpleChatUser
*chatuser
= iter
->data
;
1136 if ((str
= purple_chat_user_get_alias(chatuser
)) == NULL
)
1137 str
= purple_chat_user_get_name(chatuser
);
1138 g_string_append_printf(string
, "[ %s ]", str
);
1141 purple_conversation_write_system_message(
1142 conv
, string
->str
, 0);
1143 g_string_free(string
, TRUE
);
1146 for (; users
; users
= users
->next
)
1148 PurpleChatUser
*chatuser
= users
->data
;
1149 GntTree
*tree
= GNT_TREE(ggc
->u
.chat
->userlist
);
1150 gnt_entry_add_suggest(entry
, purple_chat_user_get_name(chatuser
));
1151 gnt_entry_add_suggest(entry
, purple_chat_user_get_alias(chatuser
));
1152 gnt_tree_add_row_after(tree
, g_strdup(purple_chat_user_get_name(chatuser
)),
1153 gnt_tree_create_row(tree
, chat_flag_text(purple_chat_user_get_flags(chatuser
)), purple_chat_user_get_alias(chatuser
)), NULL
, NULL
);
1158 finch_chat_rename_user(PurpleChatConversation
*chat
, const char *old
, const char *new_n
, const char *new_a
)
1160 /* Update the name for string completion */
1161 FinchConv
*ggc
= FINCH_CONV(PURPLE_CONVERSATION(chat
));
1162 GntEntry
*entry
= GNT_ENTRY(ggc
->entry
);
1163 GntTree
*tree
= GNT_TREE(ggc
->u
.chat
->userlist
);
1164 PurpleChatUser
*cb
= purple_chat_conversation_find_user(chat
, new_n
);
1166 gnt_entry_remove_suggest(entry
, old
);
1167 gnt_tree_remove(tree
, (gpointer
)old
);
1169 gnt_entry_add_suggest(entry
, new_n
);
1170 gnt_entry_add_suggest(entry
, new_a
);
1171 gnt_tree_add_row_after(tree
, g_strdup(new_n
),
1172 gnt_tree_create_row(tree
, chat_flag_text(purple_chat_user_get_flags(cb
)), new_a
), NULL
, NULL
);
1176 finch_chat_remove_users(PurpleChatConversation
*chat
, GList
*list
)
1178 /* Remove the name from string completion */
1179 FinchConv
*ggc
= FINCH_CONV(PURPLE_CONVERSATION(chat
));
1180 GntEntry
*entry
= GNT_ENTRY(ggc
->entry
);
1181 for (; list
; list
= list
->next
) {
1182 GntTree
*tree
= GNT_TREE(ggc
->u
.chat
->userlist
);
1183 gnt_entry_remove_suggest(entry
, list
->data
);
1184 gnt_tree_remove(tree
, list
->data
);
1189 finch_chat_update_user(PurpleChatUser
*cb
)
1191 PurpleChatConversation
*chat
;
1196 chat
= purple_chat_user_get_chat(cb
);
1197 ggc
= FINCH_CONV(PURPLE_CONVERSATION(chat
));
1198 gnt_tree_change_text(GNT_TREE(ggc
->u
.chat
->userlist
),
1199 (gpointer
)purple_chat_user_get_name(cb
), 0,
1200 chat_flag_text(purple_chat_user_get_flags(cb
)));
1204 finch_conv_present(PurpleConversation
*conv
)
1206 FinchConv
*fc
= FINCH_CONV(conv
);
1207 if (fc
&& fc
->window
)
1208 gnt_window_present(fc
->window
);
1212 finch_conv_has_focus(PurpleConversation
*conv
)
1214 FinchConv
*fc
= FINCH_CONV(conv
);
1215 if (fc
&& fc
->window
)
1216 return gnt_widget_has_focus(fc
->window
);
1220 static PurpleConversationUiOps conv_ui_ops
=
1222 finch_create_conversation
,
1223 finch_destroy_conversation
,
1224 NULL
, /* write_chat */
1225 NULL
, /* write_im */
1227 finch_chat_add_users
,
1228 finch_chat_rename_user
,
1229 finch_chat_remove_users
,
1230 finch_chat_update_user
,
1231 finch_conv_present
, /* present */
1232 finch_conv_has_focus
, /* has_focus */
1233 NULL
, /* send_confirm */
1240 PurpleConversationUiOps
*finch_conv_get_ui_ops()
1242 return &conv_ui_ops
;
1247 say_command_cb(PurpleConversation
*conv
,
1248 const char *cmd
, char **args
, char **error
, void *data
)
1250 purple_conversation_send(conv
, args
[0]);
1252 return PURPLE_CMD_RET_OK
;
1257 me_command_cb(PurpleConversation
*conv
,
1258 const char *cmd
, char **args
, char **error
, void *data
)
1262 tmp
= g_strdup_printf("/me %s", args
[0]);
1263 purple_conversation_send(conv
, tmp
);
1266 return PURPLE_CMD_RET_OK
;
1271 debug_command_cb(PurpleConversation
*conv
,
1272 const char *cmd
, char **args
, char **error
, void *data
)
1276 if (!g_ascii_strcasecmp(args
[0], "version")) {
1277 tmp
= g_strdup_printf("Using Finch v%s with libpurple v%s.",
1278 DISPLAY_VERSION
, purple_core_get_version());
1279 } else if (!g_ascii_strcasecmp(args
[0], "plugins")) {
1280 /* Show all the loaded plugins, including plugins marked internal.
1281 * This is intentional, since third party protocols are often sources of bugs, and some
1282 * loaders can also be buggy.
1284 GString
*str
= g_string_new("Loaded Plugins: ");
1285 const GList
*plugins
= purple_plugins_get_loaded();
1287 for (; plugins
; plugins
= plugins
->next
) {
1288 GPluginPluginInfo
*plugin_info
=
1289 GPLUGIN_PLUGIN_INFO(
1290 purple_plugin_get_info(
1292 str
= g_string_append(
1293 str
, gplugin_plugin_info_get_name(
1297 str
= g_string_append(str
, ", ");
1300 str
= g_string_append(str
, "(none)");
1303 tmp
= g_string_free(str
, FALSE
);
1305 purple_conversation_write_system_message(conv
,
1306 _("Supported debug options are: plugins version"),
1307 PURPLE_MESSAGE_NO_LOG
| PURPLE_MESSAGE_ERROR
);
1308 return PURPLE_CMD_RET_OK
;
1311 markup
= g_markup_escape_text(tmp
, -1);
1312 purple_conversation_send(conv
, markup
);
1316 return PURPLE_CMD_RET_OK
;
1321 clear_command_cb(PurpleConversation
*conv
,
1322 const char *cmd
, char **args
, char **error
, void *data
)
1324 purple_conversation_clear_message_history(conv
);
1325 return PURPLE_CMD_RET_OK
;
1330 help_command_cb(PurpleConversation
*conv
,
1331 const char *cmd
, char **args
, char **error
, void *data
)
1336 if (args
[0] != NULL
) {
1337 s
= g_string_new("");
1338 text
= purple_cmd_help(conv
, args
[0]);
1341 for (l
= text
; l
; l
= l
->next
)
1343 g_string_append_printf(s
, "%s\n", (char *)l
->data
);
1345 g_string_append_printf(s
, "%s", (char *)l
->data
);
1347 g_string_append(s
, _("No such command (in this context)."));
1350 s
= g_string_new(_("Use \"/help <command>\" for help with a "
1351 "specific command.\nThe following commands are available in "
1352 "this context:\n"));
1354 text
= purple_cmd_list(conv
);
1355 for (l
= text
; l
; l
= l
->next
)
1357 g_string_append_printf(s
, "%s, ", (char *)l
->data
);
1359 g_string_append_printf(s
, "%s.", (char *)l
->data
);
1363 purple_conversation_write_system_message(conv
, s
->str
, PURPLE_MESSAGE_NO_LOG
);
1364 g_string_free(s
, TRUE
);
1366 return PURPLE_CMD_RET_OK
;
1370 cmd_show_window(PurpleConversation
*conv
, const char *cmd
, char **args
, char **error
, gpointer data
)
1372 void (*callback
)(void) = data
;
1374 return PURPLE_CMD_RET_OK
;
1378 cmd_message_color(PurpleConversation
*conv
, const char *cmd
, char **args
, char **error
, gpointer data
)
1380 int *msgclass
= NULL
;
1383 if (purple_strequal(args
[0], "receive"))
1384 msgclass
= &color_message_receive
;
1385 else if (purple_strequal(args
[0], "send"))
1386 msgclass
= &color_message_send
;
1387 else if (purple_strequal(args
[0], "highlight"))
1388 msgclass
= &color_message_highlight
;
1389 else if (purple_strequal(args
[0], "action"))
1390 msgclass
= &color_message_action
;
1391 else if (purple_strequal(args
[0], "timestamp"))
1392 msgclass
= &color_timestamp
;
1395 *error
= g_strdup_printf(_("%s is not a valid message class. See '/help msgcolor' for valid message classes."), args
[0]);
1396 return PURPLE_CMD_RET_FAILED
;
1399 fg
= gnt_colors_get_color(args
[1]);
1400 if (fg
== -EINVAL
) {
1402 *error
= g_strdup_printf(_("%s is not a valid color. See '/help msgcolor' for valid colors."), args
[1]);
1403 return PURPLE_CMD_RET_FAILED
;
1406 bg
= gnt_colors_get_color(args
[2]);
1407 if (bg
== -EINVAL
) {
1409 *error
= g_strdup_printf(_("%s is not a valid color. See '/help msgcolor' for valid colors."), args
[2]);
1410 return PURPLE_CMD_RET_FAILED
;
1413 init_pair(*msgclass
, fg
, bg
);
1415 return PURPLE_CMD_RET_OK
;
1419 users_command_cb(PurpleConversation
*conv
, const char *cmd
, char **args
, char **error
, gpointer data
)
1421 FinchConv
*fc
= FINCH_CONV(conv
);
1424 return PURPLE_CMD_RET_FAILED
;
1427 gnt_widget_set_visible(ch
->userlist
,
1428 !gnt_widget_get_visible(ch
->userlist
));
1429 gnt_box_readjust(GNT_BOX(fc
->window
));
1430 gnt_box_give_focus_to_child(GNT_BOX(fc
->window
), fc
->entry
);
1431 purple_prefs_set_bool(PREF_USERLIST
, gnt_widget_get_visible(ch
->userlist
));
1432 return PURPLE_CMD_RET_OK
;
1435 void finch_conversation_init()
1437 color_message_send
= gnt_style_get_color(NULL
, "color-message-sent");
1438 if (!color_message_send
)
1439 color_message_send
= gnt_color_add_pair(COLOR_CYAN
, -1);
1440 color_message_receive
= gnt_style_get_color(NULL
, "color-message-received");
1441 if (!color_message_receive
)
1442 color_message_receive
= gnt_color_add_pair(COLOR_RED
, -1);
1443 color_message_highlight
= gnt_style_get_color(NULL
, "color-message-highlight");
1444 if (!color_message_highlight
)
1445 color_message_highlight
= gnt_color_add_pair(COLOR_GREEN
, -1);
1446 color_timestamp
= gnt_style_get_color(NULL
, "color-timestamp");
1447 if (!color_timestamp
)
1448 color_timestamp
= gnt_color_add_pair(COLOR_BLUE
, -1);
1449 color_message_action
= gnt_style_get_color(NULL
, "color-message-action");
1450 if (!color_message_action
)
1451 color_message_action
= gnt_color_add_pair(COLOR_YELLOW
, -1);
1452 purple_prefs_add_none(PREF_ROOT
);
1453 purple_prefs_add_none(PREF_ROOT
"/size");
1454 purple_prefs_add_int(PREF_ROOT
"/size/width", 70);
1455 purple_prefs_add_int(PREF_ROOT
"/size/height", 20);
1456 purple_prefs_add_none(PREF_ROOT
"/position");
1457 purple_prefs_add_int(PREF_ROOT
"/position/x", 0);
1458 purple_prefs_add_int(PREF_ROOT
"/position/y", 0);
1459 purple_prefs_add_none(PREF_CHAT
);
1460 purple_prefs_add_bool(PREF_USERLIST
, FALSE
);
1462 /* Xerox the commands */
1463 purple_cmd_register("say", "S", PURPLE_CMD_P_DEFAULT
,
1464 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1465 say_command_cb
, _("say <message>: Send a message normally as if you weren't using a command."), NULL
);
1466 purple_cmd_register("me", "S", PURPLE_CMD_P_DEFAULT
,
1467 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1468 me_command_cb
, _("me <action>: Send an IRC style action to a buddy or chat."), NULL
);
1469 purple_cmd_register("debug", "w", PURPLE_CMD_P_DEFAULT
,
1470 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1471 debug_command_cb
, _("debug <option>: Send various debug information to the current conversation."), NULL
);
1472 purple_cmd_register("clear", "", PURPLE_CMD_P_DEFAULT
,
1473 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1474 clear_command_cb
, _("clear: Clears the conversation scrollback."), NULL
);
1475 purple_cmd_register("help", "w", PURPLE_CMD_P_DEFAULT
,
1476 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
| PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS
, NULL
,
1477 help_command_cb
, _("help <command>: Help on a specific command."), NULL
);
1478 purple_cmd_register("users", "", PURPLE_CMD_P_DEFAULT
,
1479 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS
, NULL
,
1480 users_command_cb
, _("users: Show the list of users in the chat."), NULL
);
1482 /* Now some commands to bring up some other windows */
1483 purple_cmd_register("plugins", "", PURPLE_CMD_P_DEFAULT
,
1484 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1485 cmd_show_window
, _("plugins: Show the plugins window."), finch_plugins_show_all
);
1486 purple_cmd_register("buddylist", "", PURPLE_CMD_P_DEFAULT
,
1487 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1488 cmd_show_window
, _("buddylist: Show the buddylist."), finch_blist_show
);
1489 purple_cmd_register("accounts", "", PURPLE_CMD_P_DEFAULT
,
1490 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1491 cmd_show_window
, _("accounts: Show the accounts window."), finch_accounts_show_all
);
1492 purple_cmd_register("debugwin", "", PURPLE_CMD_P_DEFAULT
,
1493 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1494 cmd_show_window
, _("debugwin: Show the debug window."), finch_debug_window_show
);
1495 purple_cmd_register("prefs", "", PURPLE_CMD_P_DEFAULT
,
1496 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1497 cmd_show_window
, _("prefs: Show the preference window."), finch_prefs_show_all
);
1498 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT
,
1499 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1500 cmd_show_window
, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all
);
1502 /* Allow customizing the message colors using a command during run-time */
1503 purple_cmd_register("msgcolor", "www", PURPLE_CMD_P_DEFAULT
,
1504 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1505 cmd_message_color
, _("msgcolor <class> <foreground> <background>: "
1506 "Set the color for different classes of messages in the conversation window.<br>"
1507 " <class>: receive, send, highlight, action, timestamp<br>"
1508 " <foreground/background>: black, red, green, blue, white, gray, darkgray, magenta, cyan, default<br><br>"
1509 "EXAMPLE:<br> msgcolor send cyan default"),
1511 purple_cmd_register("msgcolour", "www", PURPLE_CMD_P_DEFAULT
,
1512 PURPLE_CMD_FLAG_CHAT
| PURPLE_CMD_FLAG_IM
, NULL
,
1513 cmd_message_color
, _("msgcolor <class> <foreground> <background>: "
1514 "Set the color for different classes of messages in the conversation window.<br>"
1515 " <class>: receive, send, highlight, action, timestamp<br>"
1516 " <foreground/background>: black, red, green, blue, white, gray, darkgray, magenta, cyan, default<br><br>"
1517 "EXAMPLE:<br> msgcolor send cyan default"),
1520 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(),
1521 PURPLE_CALLBACK(update_buddy_typing
), NULL
);
1522 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(),
1523 PURPLE_CALLBACK(update_buddy_typing
), NULL
);
1524 purple_signal_connect(purple_conversations_get_handle(), "chat-left", finch_conv_get_handle(),
1525 PURPLE_CALLBACK(chat_left_cb
), NULL
);
1526 purple_signal_connect(purple_conversations_get_handle(), "cleared-message-history", finch_conv_get_handle(),
1527 PURPLE_CALLBACK(cleared_message_history_cb
), NULL
);
1528 purple_signal_connect(purple_conversations_get_handle(), "conversation-updated", finch_conv_get_handle(),
1529 PURPLE_CALLBACK(conv_updated
), NULL
);
1530 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", finch_conv_get_handle(),
1531 PURPLE_CALLBACK(buddy_signed_on_off
), NULL
);
1532 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off", finch_conv_get_handle(),
1533 PURPLE_CALLBACK(buddy_signed_on_off
), NULL
);
1534 purple_signal_connect(purple_connections_get_handle(), "signed-on", finch_conv_get_handle(),
1535 PURPLE_CALLBACK(account_signed_on_off
), NULL
);
1536 purple_signal_connect(purple_connections_get_handle(), "signed-off", finch_conv_get_handle(),
1537 PURPLE_CALLBACK(account_signed_on_off
), NULL
);
1538 purple_signal_connect(purple_connections_get_handle(), "signing-off", finch_conv_get_handle(),
1539 PURPLE_CALLBACK(account_signing_off
), NULL
);
1542 void finch_conversation_uninit()
1544 purple_signals_disconnect_by_handle(finch_conv_get_handle());
1547 void finch_conversation_set_active(PurpleConversation
*conv
)
1549 FinchConv
*ggconv
= FINCH_CONV(conv
);
1550 PurpleAccount
*account
;
1553 g_return_if_fail(ggconv
);
1554 g_return_if_fail(g_list_find(ggconv
->list
, conv
));
1555 if (ggconv
->active_conv
== conv
)
1558 ggconv
->active_conv
= conv
;
1559 gg_setup_commands(ggconv
, TRUE
);
1560 account
= purple_conversation_get_account(conv
);
1561 title
= get_conversation_title(conv
, account
);
1562 gnt_screen_rename_widget(ggconv
->window
, title
);
1565 generate_e2ee_menu(ggconv
);
1568 void finch_conversation_set_info_widget(PurpleConversation
*conv
, GntWidget
*widget
)
1570 FinchConv
*fc
= FINCH_CONV(conv
);
1573 gnt_box_remove_all(GNT_BOX(fc
->info
));
1576 gnt_box_add_widget(GNT_BOX(fc
->info
), widget
);
1577 gnt_box_readjust(GNT_BOX(fc
->info
));
1580 gnt_widget_get_size(fc
->window
, &width
, &height
);
1581 gnt_box_readjust(GNT_BOX(fc
->window
));
1582 gnt_screen_resize_widget(fc
->window
, width
, height
);
1583 gnt_box_give_focus_to_child(GNT_BOX(fc
->window
), fc
->entry
);