2 * @file gntpounce.c GNT Buddy Pounce API
7 * Finch is the legal property of its developers, whose names are too numerous
8 * to list here. Please refer to the COPYRIGHT file distributed with this
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <gntbutton.h>
29 #include <gntcheckbox.h>
30 #include <gntcombobox.h>
39 #include "conversation.h"
47 #include "gntpounce.h"
54 PurpleAccount
*account
;
60 GntWidget
*account_menu
;
61 GntWidget
*buddy_entry
;
66 /* Pounce When Buddy... */
70 GntWidget
*away_return
;
72 GntWidget
*idle_return
;
75 GntWidget
*stop_typing
;
76 GntWidget
*message_recv
;
81 GntWidget
*popup_entry
;
83 GntWidget
*send_msg_entry
;
85 GntWidget
*exec_cmd_entry
;
86 GntWidget
*play_sound
;
88 GntWidget
*save_pounce
;
91 GntWidget
*save_button
;
93 } PurpleGntPounceDialog
;
99 GntWidget
*modify_button
;
100 GntWidget
*delete_button
;
103 static PouncesManager
*pounces_manager
= NULL
;
105 /**************************************************************************
107 **************************************************************************/
109 delete_win_cb(GntWidget
*w
, PurpleGntPounceDialog
*dialog
)
111 gnt_widget_destroy(dialog
->window
);
118 cancel_cb(GntWidget
*w
, PurpleGntPounceDialog
*dialog
)
120 gnt_widget_destroy(dialog
->window
);
124 add_pounce_to_treeview(GntTree
*tree
, PurplePounce
*pounce
)
126 PurpleAccount
*account
;
130 account
= purple_pounce_get_pouncer(pounce
);
131 pouncer
= purple_account_get_username(account
);
132 pouncee
= purple_pounce_get_pouncee(pounce
);
133 gnt_tree_add_row_last(tree
, pounce
,
134 gnt_tree_create_row(tree
, pouncer
, pouncee
), NULL
);
138 populate_pounces_list(PouncesManager
*dialog
)
140 const GList
*pounces
;
142 gnt_tree_remove_all(GNT_TREE(dialog
->tree
));
144 for (pounces
= purple_pounces_get_all(); pounces
!= NULL
;
145 pounces
= g_list_next(pounces
))
147 add_pounce_to_treeview(GNT_TREE(dialog
->tree
), pounces
->data
);
154 /* Rebuild the pounces list if the pounces manager is open */
155 if (pounces_manager
!= NULL
)
157 populate_pounces_list(pounces_manager
);
162 signed_on_off_cb(PurpleConnection
*gc
, gpointer user_data
)
168 save_pounce_cb(GntWidget
*w
, PurpleGntPounceDialog
*dialog
)
171 const char *message
, *command
, *reason
;
172 PurplePounceEvent events
= PURPLE_POUNCE_NONE
;
173 PurplePounceOption options
= PURPLE_POUNCE_OPTION_NONE
;
175 name
= gnt_entry_get_text(GNT_ENTRY(dialog
->buddy_entry
));
179 purple_notify_error(NULL
, NULL
,
180 _("Please enter a buddy to pounce."), NULL
);
185 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->on_away
)))
186 options
|= PURPLE_POUNCE_OPTION_AWAY
;
189 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->signon
)))
190 events
|= PURPLE_POUNCE_SIGNON
;
192 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->signoff
)))
193 events
|= PURPLE_POUNCE_SIGNOFF
;
195 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->away
)))
196 events
|= PURPLE_POUNCE_AWAY
;
198 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->away_return
)))
199 events
|= PURPLE_POUNCE_AWAY_RETURN
;
201 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->idle
)))
202 events
|= PURPLE_POUNCE_IDLE
;
204 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->idle_return
)))
205 events
|= PURPLE_POUNCE_IDLE_RETURN
;
207 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->typing
)))
208 events
|= PURPLE_POUNCE_TYPING
;
210 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->typed
)))
211 events
|= PURPLE_POUNCE_TYPED
;
213 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->stop_typing
)))
214 events
|= PURPLE_POUNCE_TYPING_STOPPED
;
216 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->message_recv
)))
217 events
|= PURPLE_POUNCE_MESSAGE_RECEIVED
;
220 message
= gnt_entry_get_text(GNT_ENTRY(dialog
->send_msg_entry
));
221 command
= gnt_entry_get_text(GNT_ENTRY(dialog
->exec_cmd_entry
));
222 reason
= gnt_entry_get_text(GNT_ENTRY(dialog
->popup_entry
));
224 if (*reason
== '\0') reason
= NULL
;
225 if (*message
== '\0') message
= NULL
;
226 if (*command
== '\0') command
= NULL
;
228 if (dialog
->pounce
== NULL
) {
229 dialog
->pounce
= purple_pounce_new(FINCH_UI
, dialog
->account
,
230 name
, events
, options
);
232 purple_pounce_set_events(dialog
->pounce
, events
);
233 purple_pounce_set_options(dialog
->pounce
, options
);
234 purple_pounce_set_pouncer(dialog
->pounce
, dialog
->account
);
235 purple_pounce_set_pouncee(dialog
->pounce
, name
);
239 purple_pounce_action_set_enabled(dialog
->pounce
, "open-window",
240 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->open_win
)));
241 purple_pounce_action_set_enabled(dialog
->pounce
, "popup-notify",
242 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->popup
)));
243 purple_pounce_action_set_enabled(dialog
->pounce
, "send-message",
244 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->send_msg
)));
245 purple_pounce_action_set_enabled(dialog
->pounce
, "execute-command",
246 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->exec_cmd
)));
247 purple_pounce_action_set_enabled(dialog
->pounce
, "play-beep",
248 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->play_sound
)));
250 purple_pounce_action_set_attribute(dialog
->pounce
, "send-message",
252 purple_pounce_action_set_attribute(dialog
->pounce
, "execute-command",
254 purple_pounce_action_set_attribute(dialog
->pounce
, "popup-notify",
257 /* Set the defaults for next time. */
258 purple_prefs_set_bool("/finch/pounces/default_actions/open-window",
259 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->open_win
)));
260 purple_prefs_set_bool("/finch/pounces/default_actions/popup-notify",
261 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->popup
)));
262 purple_prefs_set_bool("/finch/pounces/default_actions/send-message",
263 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->send_msg
)));
264 purple_prefs_set_bool("/finch/pounces/default_actions/execute-command",
265 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->exec_cmd
)));
266 purple_prefs_set_bool("/finch/pounces/default_actions/play-beep",
267 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->play_sound
)));
269 purple_pounce_set_save(dialog
->pounce
,
270 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->save_pounce
)));
272 purple_pounce_set_pouncer(dialog
->pounce
,
273 (PurpleAccount
*)gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog
->account_menu
)));
277 gnt_widget_destroy(dialog
->window
);
282 finch_pounce_editor_show(PurpleAccount
*account
, const char *name
,
283 PurplePounce
*cur_pounce
)
285 PurpleGntPounceDialog
*dialog
;
288 GntWidget
*hbox
, *vbox
;
293 g_return_if_fail((cur_pounce
!= NULL
) ||
295 (purple_accounts_get_all() != NULL
));
297 dialog
= g_new0(PurpleGntPounceDialog
, 1);
299 if (cur_pounce
!= NULL
) {
300 dialog
->pounce
= cur_pounce
;
301 dialog
->account
= purple_pounce_get_pouncer(cur_pounce
);
302 } else if (account
!= NULL
) {
303 dialog
->pounce
= NULL
;
304 dialog
->account
= account
;
306 GList
*connections
= purple_connections_get_all();
307 PurpleConnection
*gc
;
309 if (connections
!= NULL
) {
310 gc
= (PurpleConnection
*)connections
->data
;
311 dialog
->account
= purple_connection_get_account(gc
);
313 dialog
->account
= purple_accounts_get_all()->data
;
315 dialog
->pounce
= NULL
;
318 /* Create the window. */
319 dialog
->window
= window
= gnt_vbox_new(FALSE
);
320 gnt_box_set_pad(GNT_BOX(window
), 0);
321 gnt_box_set_toplevel(GNT_BOX(window
), TRUE
);
322 gnt_box_set_alignment(GNT_BOX(window
), GNT_ALIGN_LEFT
);
323 gnt_box_set_title(GNT_BOX(window
),
325 ? _("New Buddy Pounce") : _("Edit Buddy Pounce")));
327 g_signal_connect(G_OBJECT(window
), "destroy",
328 G_CALLBACK(delete_win_cb
), dialog
);
330 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new_with_format(_("Pounce Who"), GNT_TEXT_FLAG_BOLD
));
333 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new(_("Account:")));
334 dialog
->account_menu
= combo
= gnt_combo_box_new();
335 list
= purple_accounts_get_all();
336 for (; list
; list
= list
->next
)
338 PurpleAccount
*account
;
341 account
= list
->data
;
342 text
= g_strdup_printf("%s (%s)",
343 purple_account_get_username(account
),
344 purple_account_get_protocol_name(account
));
345 gnt_combo_box_add_data(GNT_COMBO_BOX(combo
), account
, text
);
349 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo
), dialog
->account
);
351 gnt_box_add_widget(GNT_BOX(window
), combo
);
354 hbox
= gnt_hbox_new(FALSE
);
355 gnt_box_add_widget(GNT_BOX(hbox
), gnt_label_new(_("Buddy name:")));
357 dialog
->buddy_entry
= gnt_entry_new(NULL
);
358 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->buddy_entry
);
360 gnt_box_add_widget(GNT_BOX(window
), hbox
);
362 if (cur_pounce
!= NULL
) {
363 gnt_entry_set_text(GNT_ENTRY(dialog
->buddy_entry
),
364 purple_pounce_get_pouncee(cur_pounce
));
365 } else if (name
!= NULL
) {
366 gnt_entry_set_text(GNT_ENTRY(dialog
->buddy_entry
), name
);
369 /* Create the event frame */
370 gnt_box_add_widget(GNT_BOX(window
), gnt_line_new(FALSE
));
371 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new_with_format(_("Pounce When Buddy..."), GNT_TEXT_FLAG_BOLD
));
373 dialog
->signon
= gnt_check_box_new(_("Signs on"));
374 dialog
->signoff
= gnt_check_box_new(_("Signs off"));
375 dialog
->away
= gnt_check_box_new(_("Goes away"));
376 dialog
->away_return
= gnt_check_box_new(_("Returns from away"));
377 dialog
->idle
= gnt_check_box_new(_("Becomes idle"));
378 dialog
->idle_return
= gnt_check_box_new(_("Is no longer idle"));
379 dialog
->typing
= gnt_check_box_new(_("Starts typing"));
380 dialog
->typed
= gnt_check_box_new(_("Pauses while typing"));
381 dialog
->stop_typing
= gnt_check_box_new(_("Stops typing"));
382 dialog
->message_recv
= gnt_check_box_new(_("Sends a message"));
384 hbox
= gnt_hbox_new(TRUE
);
385 gnt_box_set_pad(GNT_BOX(hbox
), 2);
387 vbox
= gnt_vbox_new(FALSE
);
388 gnt_box_set_pad(GNT_BOX(vbox
), 0);
389 gnt_box_add_widget(GNT_BOX(hbox
), vbox
);
391 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->signon
);
392 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->away
);
393 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->idle
);
394 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->typing
);
395 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->stop_typing
);
397 vbox
= gnt_vbox_new(FALSE
);
398 gnt_box_set_pad(GNT_BOX(vbox
), 0);
399 gnt_box_add_widget(GNT_BOX(hbox
), vbox
);
401 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->signoff
);
402 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->away_return
);
403 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->idle_return
);
404 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->typed
);
405 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->message_recv
);
407 gnt_box_add_widget(GNT_BOX(window
), hbox
);
409 /* Create the "Action" frame. */
410 gnt_box_add_widget(GNT_BOX(window
), gnt_line_new(FALSE
));
411 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new_with_format(_("Action"), GNT_TEXT_FLAG_BOLD
));
413 dialog
->open_win
= gnt_check_box_new(_("Open an IM window"));
414 dialog
->popup
= gnt_check_box_new(_("Pop up a notification"));
415 dialog
->send_msg
= gnt_check_box_new(_("Send a message"));
416 dialog
->exec_cmd
= gnt_check_box_new(_("Execute a command"));
417 dialog
->play_sound
= gnt_check_box_new(_("Play a sound"));
419 dialog
->send_msg_entry
= gnt_entry_new(NULL
);
420 dialog
->exec_cmd_entry
= gnt_entry_new(NULL
);
421 dialog
->popup_entry
= gnt_entry_new(NULL
);
422 dialog
->exec_cmd_entry
= gnt_entry_new(NULL
);
424 hbox
= gnt_hbox_new(FALSE
);
425 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->open_win
);
426 gnt_box_add_widget(GNT_BOX(window
), hbox
);
427 hbox
= gnt_hbox_new(FALSE
);
428 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->popup
);
429 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->popup_entry
);
430 gnt_box_add_widget(GNT_BOX(window
), hbox
);
431 hbox
= gnt_hbox_new(FALSE
);
432 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->send_msg
);
433 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->send_msg_entry
);
434 gnt_box_add_widget(GNT_BOX(window
), hbox
);
435 hbox
= gnt_hbox_new(FALSE
);
436 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->exec_cmd
);
437 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->exec_cmd_entry
);
438 gnt_box_add_widget(GNT_BOX(window
), hbox
);
439 hbox
= gnt_hbox_new(FALSE
);
440 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->play_sound
);
441 gnt_box_add_widget(GNT_BOX(window
), hbox
);
443 gnt_box_add_widget(GNT_BOX(window
), gnt_line_new(FALSE
));
444 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new_with_format(_("Options"), GNT_TEXT_FLAG_BOLD
));
445 dialog
->on_away
= gnt_check_box_new(_("Pounce only when my status is not available"));
446 gnt_box_add_widget(GNT_BOX(window
), dialog
->on_away
);
447 dialog
->save_pounce
= gnt_check_box_new(_("Recurring"));
448 gnt_box_add_widget(GNT_BOX(window
), dialog
->save_pounce
);
451 gnt_box_add_widget(GNT_BOX(window
), gnt_line_new(FALSE
));
452 /* Now the button box! */
453 bbox
= gnt_hbox_new(TRUE
);
456 button
= gnt_button_new(_("Cancel"));
457 gnt_box_add_widget(GNT_BOX(bbox
), button
);
458 g_signal_connect(G_OBJECT(button
), "activate",
459 G_CALLBACK(cancel_cb
), dialog
);
462 dialog
->save_button
= button
= gnt_button_new(_("Save"));
463 gnt_box_add_widget(GNT_BOX(bbox
), button
);
464 g_signal_connect(G_OBJECT(button
), "activate",
465 G_CALLBACK(save_pounce_cb
), dialog
);
467 gnt_box_add_widget(GNT_BOX(window
), bbox
);
470 /* Set the values of stuff. */
471 if (cur_pounce
!= NULL
)
473 PurplePounceEvent events
= purple_pounce_get_events(cur_pounce
);
474 PurplePounceOption options
= purple_pounce_get_options(cur_pounce
);
478 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->on_away
),
479 (options
& PURPLE_POUNCE_OPTION_AWAY
));
482 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->signon
),
483 (events
& PURPLE_POUNCE_SIGNON
));
484 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->signoff
),
485 (events
& PURPLE_POUNCE_SIGNOFF
));
486 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->away
),
487 (events
& PURPLE_POUNCE_AWAY
));
488 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->away_return
),
489 (events
& PURPLE_POUNCE_AWAY_RETURN
));
490 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->idle
),
491 (events
& PURPLE_POUNCE_IDLE
));
492 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->idle_return
),
493 (events
& PURPLE_POUNCE_IDLE_RETURN
));
494 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->typing
),
495 (events
& PURPLE_POUNCE_TYPING
));
496 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->typed
),
497 (events
& PURPLE_POUNCE_TYPED
));
498 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->stop_typing
),
499 (events
& PURPLE_POUNCE_TYPING_STOPPED
));
500 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->message_recv
),
501 (events
& PURPLE_POUNCE_MESSAGE_RECEIVED
));
504 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->open_win
),
505 purple_pounce_action_is_enabled(cur_pounce
, "open-window"));
506 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->popup
),
507 purple_pounce_action_is_enabled(cur_pounce
, "popup-notify"));
508 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->send_msg
),
509 purple_pounce_action_is_enabled(cur_pounce
, "send-message"));
510 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->exec_cmd
),
511 purple_pounce_action_is_enabled(cur_pounce
, "execute-command"));
512 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->play_sound
),
513 purple_pounce_action_is_enabled(cur_pounce
, "play-beep"));
515 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->save_pounce
),
516 purple_pounce_get_save(cur_pounce
));
518 if ((value
= purple_pounce_action_get_attribute(cur_pounce
,
522 gnt_entry_set_text(GNT_ENTRY(dialog
->send_msg_entry
), value
);
525 if ((value
= purple_pounce_action_get_attribute(cur_pounce
,
529 gnt_entry_set_text(GNT_ENTRY(dialog
->popup_entry
), value
);
532 if ((value
= purple_pounce_action_get_attribute(cur_pounce
,
536 gnt_entry_set_text(GNT_ENTRY(dialog
->exec_cmd_entry
), value
);
541 PurpleBuddy
*buddy
= NULL
;
544 buddy
= purple_find_buddy(account
, name
);
546 /* Set some defaults */
548 gnt_check_box_set_checked(
549 GNT_CHECK_BOX(dialog
->signon
), TRUE
);
551 if (!PURPLE_BUDDY_IS_ONLINE(buddy
)) {
552 gnt_check_box_set_checked(
553 GNT_CHECK_BOX(dialog
->signon
), TRUE
);
555 gboolean default_set
= FALSE
;
556 PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
558 if (purple_presence_is_idle(presence
))
560 gnt_check_box_set_checked(
561 GNT_CHECK_BOX(dialog
->idle_return
), TRUE
);
566 if (!purple_presence_is_available(presence
))
568 gnt_check_box_set_checked(
569 GNT_CHECK_BOX(dialog
->away_return
), TRUE
);
576 gnt_check_box_set_checked(
577 GNT_CHECK_BOX(dialog
->signon
), TRUE
);
582 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->open_win
),
583 purple_prefs_get_bool("/finch/pounces/default_actions/open-window"));
584 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->popup
),
585 purple_prefs_get_bool("/finch/pounces/default_actions/popup-notify"));
586 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->send_msg
),
587 purple_prefs_get_bool("/finch/pounces/default_actions/send-message"));
588 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->exec_cmd
),
589 purple_prefs_get_bool("/finch/pounces/default_actions/execute-command"));
590 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->play_sound
),
591 purple_prefs_get_bool("/finch/pounces/default_actions/play-beep"));
594 gnt_widget_show(window
);
600 pounces_manager_destroy_cb(GntWidget
*widget
, gpointer user_data
)
602 PouncesManager
*dialog
= user_data
;
604 dialog
->window
= NULL
;
605 finch_pounces_manager_hide();
612 pounces_manager_add_cb(GntButton
*button
, gpointer user_data
)
614 finch_pounce_editor_show(NULL
, NULL
, NULL
);
619 pounces_manager_modify_cb(GntButton
*button
, gpointer user_data
)
621 PouncesManager
*dialog
= user_data
;
622 PurplePounce
*pounce
= gnt_tree_get_selection_data(GNT_TREE(dialog
->tree
));
623 finch_pounce_editor_show(NULL
, NULL
, pounce
);
627 pounces_manager_delete_confirm_cb(PurplePounce
*pounce
)
629 gnt_tree_remove(GNT_TREE(pounces_manager
->tree
), pounce
);
631 purple_request_close_with_handle(pounce
);
632 purple_pounce_destroy(pounce
);
637 pounces_manager_delete_cb(GntButton
*button
, gpointer user_data
)
639 PouncesManager
*dialog
= user_data
;
640 PurplePounce
*pounce
;
641 PurpleAccount
*account
;
642 const char *pouncer
, *pouncee
;
645 pounce
= (PurplePounce
*)gnt_tree_get_selection_data(GNT_TREE(dialog
->tree
));
646 account
= purple_pounce_get_pouncer(pounce
);
647 pouncer
= purple_account_get_username(account
);
648 pouncee
= purple_pounce_get_pouncee(pounce
);
649 buf
= g_strdup_printf(_("Are you sure you want to delete the pounce on %s for %s?"), pouncee
, pouncer
);
650 purple_request_action(pounce
, NULL
, buf
, NULL
, 0,
651 account
, pouncee
, NULL
,
653 _("Delete"), pounces_manager_delete_confirm_cb
,
659 pounces_manager_close_cb(GntButton
*button
, gpointer user_data
)
661 finch_pounces_manager_hide();
666 finch_pounces_manager_show(void)
668 PouncesManager
*dialog
;
674 if (pounces_manager
!= NULL
) {
678 pounces_manager
= dialog
= g_new0(PouncesManager
, 1);
680 dialog
->window
= win
= gnt_vbox_new(FALSE
);
681 gnt_box_set_toplevel(GNT_BOX(win
), TRUE
);
682 gnt_box_set_title(GNT_BOX(win
), _("Buddy Pounces"));
683 gnt_box_set_pad(GNT_BOX(win
), 0);
685 g_signal_connect(G_OBJECT(win
), "destroy",
686 G_CALLBACK(pounces_manager_destroy_cb
), dialog
);
688 /* List of saved buddy pounces */
689 dialog
->tree
= tree
= GNT_WIDGET(gnt_tree_new_with_columns(2));
690 gnt_tree_set_column_titles(GNT_TREE(tree
), "Account", "Pouncee", NULL
);
691 gnt_tree_set_show_title(GNT_TREE(tree
), TRUE
);
693 gnt_box_add_widget(GNT_BOX(win
), tree
);
696 bbox
= gnt_hbox_new(TRUE
);
699 button
= gnt_button_new(_("Add"));
700 gnt_box_add_widget(GNT_BOX(bbox
), button
);
702 g_signal_connect(G_OBJECT(button
), "activate",
703 G_CALLBACK(pounces_manager_add_cb
), dialog
);
706 button
= gnt_button_new(_("Modify"));
707 dialog
->modify_button
= button
;
708 gnt_box_add_widget(GNT_BOX(bbox
), button
);
710 g_signal_connect(G_OBJECT(button
), "activate",
711 G_CALLBACK(pounces_manager_modify_cb
), dialog
);
714 button
= gnt_button_new(_("Delete"));
715 dialog
->delete_button
= button
;
716 gnt_box_add_widget(GNT_BOX(bbox
), button
);
718 g_signal_connect(G_OBJECT(button
), "activate",
719 G_CALLBACK(pounces_manager_delete_cb
), dialog
);
722 button
= gnt_button_new(_("Close"));
723 gnt_box_add_widget(GNT_BOX(bbox
), button
);
724 gnt_widget_show(button
);
726 g_signal_connect(G_OBJECT(button
), "activate",
727 G_CALLBACK(pounces_manager_close_cb
), dialog
);
729 gnt_box_add_widget(GNT_BOX(win
), bbox
);
731 gnt_widget_show(win
);
732 populate_pounces_list(pounces_manager
);
736 finch_pounces_manager_hide(void)
738 if (pounces_manager
== NULL
)
741 if (pounces_manager
->window
!= NULL
)
742 gnt_widget_destroy(pounces_manager
->window
);
744 purple_signals_disconnect_by_handle(pounces_manager
);
746 g_free(pounces_manager
);
747 pounces_manager
= NULL
;
751 pounce_cb(PurplePounce
*pounce
, PurplePounceEvent events
, void *data
)
753 PurpleConversation
*conv
;
754 PurpleAccount
*account
;
759 pouncee
= purple_pounce_get_pouncee(pounce
);
760 account
= purple_pounce_get_pouncer(pounce
);
762 buddy
= purple_find_buddy(account
, pouncee
);
765 alias
= purple_buddy_get_alias(buddy
);
772 if (purple_pounce_action_is_enabled(pounce
, "open-window"))
774 conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
, pouncee
, account
);
777 conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, account
, pouncee
);
780 if (purple_pounce_action_is_enabled(pounce
, "popup-notify"))
783 const char *name_shown
;
785 reason
= purple_pounce_action_get_attribute(pounce
, "popup-notify",
789 * Here we place the protocol name in the pounce dialog to lessen
790 * confusion about what protocol a pounce is for.
792 tmp
= g_strdup_printf(
793 (events
& PURPLE_POUNCE_TYPING
) ?
794 _("%s has started typing to you (%s)") :
795 (events
& PURPLE_POUNCE_TYPED
) ?
796 _("%s has paused while typing to you (%s)") :
797 (events
& PURPLE_POUNCE_SIGNON
) ?
798 _("%s has signed on (%s)") :
799 (events
& PURPLE_POUNCE_IDLE_RETURN
) ?
800 _("%s has returned from being idle (%s)") :
801 (events
& PURPLE_POUNCE_AWAY_RETURN
) ?
802 _("%s has returned from being away (%s)") :
803 (events
& PURPLE_POUNCE_TYPING_STOPPED
) ?
804 _("%s has stopped typing to you (%s)") :
805 (events
& PURPLE_POUNCE_SIGNOFF
) ?
806 _("%s has signed off (%s)") :
807 (events
& PURPLE_POUNCE_IDLE
) ?
808 _("%s has become idle (%s)") :
809 (events
& PURPLE_POUNCE_AWAY
) ?
810 _("%s has gone away. (%s)") :
811 (events
& PURPLE_POUNCE_MESSAGE_RECEIVED
) ?
812 _("%s has sent you a message. (%s)") :
813 _("Unknown pounce event. Please report this!"),
814 alias
, purple_account_get_protocol_name(account
));
817 * Ok here is where I change the second argument, title, from
818 * NULL to the account alias if we have it or the account
819 * name if that's all we have
821 if ((name_shown
= purple_account_get_alias(account
)) == NULL
)
822 name_shown
= purple_account_get_username(account
);
826 purple_notify_info(NULL
, name_shown
, tmp
, purple_date_format_full(NULL
));
830 char *tmp2
= g_strdup_printf("%s\n\n%s", reason
, purple_date_format_full(NULL
));
831 purple_notify_info(NULL
, name_shown
, tmp
, tmp2
);
837 if (purple_pounce_action_is_enabled(pounce
, "send-message"))
841 message
= purple_pounce_action_get_attribute(pounce
, "send-message",
846 conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
, pouncee
, account
);
849 conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, account
, pouncee
);
851 purple_conversation_write(conv
, NULL
, message
,
852 PURPLE_MESSAGE_SEND
, time(NULL
));
854 serv_send_im(account
->gc
, (char *)pouncee
, (char *)message
, 0);
858 if (purple_pounce_action_is_enabled(pounce
, "execute-command"))
862 command
= purple_pounce_action_get_attribute(pounce
,
863 "execute-command", "command");
867 char *localecmd
= g_locale_from_utf8(command
, -1, NULL
,
870 if (localecmd
!= NULL
)
879 args
[2] = (char *)localecmd
;
882 execvp(args
[0], args
);
891 if (purple_pounce_action_is_enabled(pounce
, "play-beep"))
898 free_pounce(PurplePounce
*pounce
)
904 new_pounce(PurplePounce
*pounce
)
906 purple_pounce_action_register(pounce
, "open-window");
907 purple_pounce_action_register(pounce
, "popup-notify");
908 purple_pounce_action_register(pounce
, "send-message");
909 purple_pounce_action_register(pounce
, "execute-command");
910 purple_pounce_action_register(pounce
, "play-beep");
916 finch_pounces_get_handle()
924 finch_pounces_init(void)
926 purple_pounces_register_handler(FINCH_UI
, pounce_cb
, new_pounce
,
929 purple_prefs_add_none("/finch/pounces");
930 purple_prefs_add_none("/finch/pounces/default_actions");
931 purple_prefs_add_bool("/finch/pounces/default_actions/open-window",
933 purple_prefs_add_bool("/finch/pounces/default_actions/popup-notify",
935 purple_prefs_add_bool("/finch/pounces/default_actions/send-message",
937 purple_prefs_add_bool("/finch/pounces/default_actions/execute-command",
939 purple_prefs_add_bool("/finch/pounces/default_actions/play-beep",
941 purple_prefs_add_none("/finch/pounces/dialog");
943 purple_signal_connect(purple_connections_get_handle(), "signed-on",
944 finch_pounces_get_handle(),
945 PURPLE_CALLBACK(signed_on_off_cb
), NULL
);
946 purple_signal_connect(purple_connections_get_handle(), "signed-off",
947 finch_pounces_get_handle(),
948 PURPLE_CALLBACK(signed_on_off_cb
), NULL
);
951 /* XXX: There's no such thing in pidgin. Perhaps there should be? */
952 void finch_pounces_uninit()
954 purple_pounces_register_handler(FINCH_UI
, NULL
, NULL
, NULL
);
956 purple_signals_disconnect_by_handle(finch_pounces_get_handle());