3 * Finch is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
24 #include NCURSES_HEADER
28 #include <gntbutton.h>
29 #include <gntcheckbox.h>
30 #include <gntcombobox.h>
40 #include "conversation.h"
48 #include "gntpounce.h"
55 PurpleAccount
*account
;
61 GntWidget
*account_menu
;
62 GntWidget
*buddy_entry
;
67 /* Pounce When Buddy... */
71 GntWidget
*away_return
;
73 GntWidget
*idle_return
;
76 GntWidget
*stop_typing
;
77 GntWidget
*message_recv
;
82 GntWidget
*popup_entry
;
84 GntWidget
*send_msg_entry
;
86 GntWidget
*exec_cmd_entry
;
87 GntWidget
*play_sound
;
89 GntWidget
*save_pounce
;
92 GntWidget
*save_button
;
94 } PurpleGntPounceDialog
;
100 GntWidget
*modify_button
;
101 GntWidget
*delete_button
;
104 static PouncesManager
*pounces_manager
= NULL
;
106 /**************************************************************************
108 **************************************************************************/
110 delete_win_cb(GntWidget
*w
, PurpleGntPounceDialog
*dialog
)
112 gnt_widget_destroy(dialog
->window
);
119 cancel_cb(GntWidget
*w
, PurpleGntPounceDialog
*dialog
)
121 gnt_widget_destroy(dialog
->window
);
125 add_pounce_to_treeview(GntTree
*tree
, PurplePounce
*pounce
)
127 PurpleAccount
*account
;
131 account
= purple_pounce_get_pouncer(pounce
);
132 pouncer
= purple_account_get_username(account
);
133 pouncee
= purple_pounce_get_pouncee(pounce
);
134 gnt_tree_add_row_last(tree
, pounce
,
135 gnt_tree_create_row(tree
, pouncer
, pouncee
), NULL
);
139 populate_pounces_list(PouncesManager
*dialog
)
143 gnt_tree_remove_all(GNT_TREE(dialog
->tree
));
145 for (pounces
= purple_pounces_get_all_for_ui(FINCH_UI
); pounces
!= NULL
;
146 pounces
= g_list_delete_link(pounces
, pounces
))
148 add_pounce_to_treeview(GNT_TREE(dialog
->tree
), pounces
->data
);
155 /* Rebuild the pounces list if the pounces manager is open */
156 if (pounces_manager
!= NULL
)
158 populate_pounces_list(pounces_manager
);
163 signed_on_off_cb(PurpleConnection
*gc
, gpointer user_data
)
169 setup_buddy_list_suggestion(GntEntry
*entry
, gboolean offline
)
171 PurpleBlistNode
*node
= purple_blist_get_default_root();
172 for (; node
; node
= purple_blist_node_next(node
, offline
)) {
173 if (!PURPLE_IS_BUDDY(node
))
175 gnt_entry_add_suggest(entry
, purple_buddy_get_name((PurpleBuddy
*)node
));
180 save_pounce_cb(GntWidget
*w
, PurpleGntPounceDialog
*dialog
)
183 const char *message
, *command
, *reason
;
184 PurplePounceEvent events
= PURPLE_POUNCE_NONE
;
185 PurplePounceOption options
= PURPLE_POUNCE_OPTION_NONE
;
187 name
= gnt_entry_get_text(GNT_ENTRY(dialog
->buddy_entry
));
191 purple_notify_error(NULL
, NULL
,
192 _("Please enter a buddy to pounce."), NULL
, NULL
);
197 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->on_away
)))
198 options
|= PURPLE_POUNCE_OPTION_AWAY
;
201 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->signon
)))
202 events
|= PURPLE_POUNCE_SIGNON
;
204 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->signoff
)))
205 events
|= PURPLE_POUNCE_SIGNOFF
;
207 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->away
)))
208 events
|= PURPLE_POUNCE_AWAY
;
210 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->away_return
)))
211 events
|= PURPLE_POUNCE_AWAY_RETURN
;
213 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->idle
)))
214 events
|= PURPLE_POUNCE_IDLE
;
216 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->idle_return
)))
217 events
|= PURPLE_POUNCE_IDLE_RETURN
;
219 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->typing
)))
220 events
|= PURPLE_POUNCE_TYPING
;
222 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->typed
)))
223 events
|= PURPLE_POUNCE_TYPED
;
225 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->stop_typing
)))
226 events
|= PURPLE_POUNCE_TYPING_STOPPED
;
228 if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->message_recv
)))
229 events
|= PURPLE_POUNCE_MESSAGE_RECEIVED
;
232 message
= gnt_entry_get_text(GNT_ENTRY(dialog
->send_msg_entry
));
233 command
= gnt_entry_get_text(GNT_ENTRY(dialog
->exec_cmd_entry
));
234 reason
= gnt_entry_get_text(GNT_ENTRY(dialog
->popup_entry
));
236 if (*reason
== '\0') reason
= NULL
;
237 if (*message
== '\0') message
= NULL
;
238 if (*command
== '\0') command
= NULL
;
240 if (dialog
->pounce
== NULL
) {
241 dialog
->pounce
= purple_pounce_new(FINCH_UI
, dialog
->account
,
242 name
, events
, options
);
244 purple_pounce_set_events(dialog
->pounce
, events
);
245 purple_pounce_set_options(dialog
->pounce
, options
);
246 purple_pounce_set_pouncer(dialog
->pounce
, dialog
->account
);
247 purple_pounce_set_pouncee(dialog
->pounce
, name
);
251 purple_pounce_action_set_enabled(dialog
->pounce
, "open-window",
252 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->open_win
)));
253 purple_pounce_action_set_enabled(dialog
->pounce
, "popup-notify",
254 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->popup
)));
255 purple_pounce_action_set_enabled(dialog
->pounce
, "send-message",
256 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->send_msg
)));
257 purple_pounce_action_set_enabled(dialog
->pounce
, "execute-command",
258 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->exec_cmd
)));
259 purple_pounce_action_set_enabled(dialog
->pounce
, "play-beep",
260 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->play_sound
)));
262 purple_pounce_action_set_attribute(dialog
->pounce
, "send-message",
264 purple_pounce_action_set_attribute(dialog
->pounce
, "execute-command",
266 purple_pounce_action_set_attribute(dialog
->pounce
, "popup-notify",
269 /* Set the defaults for next time. */
270 purple_prefs_set_bool("/finch/pounces/default_actions/open-window",
271 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->open_win
)));
272 purple_prefs_set_bool("/finch/pounces/default_actions/popup-notify",
273 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->popup
)));
274 purple_prefs_set_bool("/finch/pounces/default_actions/send-message",
275 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->send_msg
)));
276 purple_prefs_set_bool("/finch/pounces/default_actions/execute-command",
277 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->exec_cmd
)));
278 purple_prefs_set_bool("/finch/pounces/default_actions/play-beep",
279 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->play_sound
)));
281 purple_pounce_set_save(dialog
->pounce
,
282 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog
->save_pounce
)));
284 purple_pounce_set_pouncer(dialog
->pounce
,
285 (PurpleAccount
*)gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog
->account_menu
)));
289 gnt_widget_destroy(dialog
->window
);
294 finch_pounce_editor_show(PurpleAccount
*account
, const char *name
,
295 PurplePounce
*cur_pounce
)
297 PurpleGntPounceDialog
*dialog
;
300 GntWidget
*hbox
, *vbox
;
305 g_return_if_fail((cur_pounce
!= NULL
) ||
307 (purple_accounts_get_all() != NULL
));
309 dialog
= g_new0(PurpleGntPounceDialog
, 1);
311 if (cur_pounce
!= NULL
) {
312 dialog
->pounce
= cur_pounce
;
313 dialog
->account
= purple_pounce_get_pouncer(cur_pounce
);
314 } else if (account
!= NULL
) {
315 dialog
->pounce
= NULL
;
316 dialog
->account
= account
;
318 GList
*connections
= purple_connections_get_all();
319 PurpleConnection
*gc
;
321 if (connections
!= NULL
) {
322 gc
= (PurpleConnection
*)connections
->data
;
323 dialog
->account
= purple_connection_get_account(gc
);
325 dialog
->account
= purple_accounts_get_all()->data
;
327 dialog
->pounce
= NULL
;
330 /* Create the window. */
331 dialog
->window
= window
= gnt_vbox_new(FALSE
);
332 gnt_box_set_pad(GNT_BOX(window
), 0);
333 gnt_box_set_toplevel(GNT_BOX(window
), TRUE
);
334 gnt_box_set_alignment(GNT_BOX(window
), GNT_ALIGN_LEFT
);
335 gnt_box_set_title(GNT_BOX(window
),
337 ? _("New Buddy Pounce") : _("Edit Buddy Pounce")));
339 g_signal_connect(G_OBJECT(window
), "destroy",
340 G_CALLBACK(delete_win_cb
), dialog
);
342 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new_with_format(_("Pounce on Whom"), GNT_TEXT_FLAG_BOLD
));
345 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new(_("Account:")));
346 dialog
->account_menu
= combo
= gnt_combo_box_new();
347 list
= purple_accounts_get_all();
348 for (; list
; list
= list
->next
)
350 PurpleAccount
*account
;
353 account
= list
->data
;
354 text
= g_strdup_printf("%s (%s)",
355 purple_account_get_username(account
),
356 purple_account_get_protocol_name(account
));
357 gnt_combo_box_add_data(GNT_COMBO_BOX(combo
), account
, text
);
361 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo
), dialog
->account
);
363 gnt_box_add_widget(GNT_BOX(window
), combo
);
366 hbox
= gnt_hbox_new(FALSE
);
367 gnt_box_add_widget(GNT_BOX(hbox
), gnt_label_new(_("Buddy name:")));
369 dialog
->buddy_entry
= gnt_entry_new(NULL
);
370 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->buddy_entry
);
372 setup_buddy_list_suggestion(GNT_ENTRY(dialog
->buddy_entry
), TRUE
);
374 gnt_box_add_widget(GNT_BOX(window
), hbox
);
376 if (cur_pounce
!= NULL
) {
377 gnt_entry_set_text(GNT_ENTRY(dialog
->buddy_entry
),
378 purple_pounce_get_pouncee(cur_pounce
));
379 } else if (name
!= NULL
) {
380 gnt_entry_set_text(GNT_ENTRY(dialog
->buddy_entry
), name
);
383 /* Create the event frame */
384 gnt_box_add_widget(GNT_BOX(window
), gnt_line_new(FALSE
));
385 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new_with_format(_("Pounce When Buddy..."), GNT_TEXT_FLAG_BOLD
));
387 dialog
->signon
= gnt_check_box_new(_("Signs on"));
388 dialog
->signoff
= gnt_check_box_new(_("Signs off"));
389 dialog
->away
= gnt_check_box_new(_("Goes away"));
390 dialog
->away_return
= gnt_check_box_new(_("Returns from away"));
391 dialog
->idle
= gnt_check_box_new(_("Becomes idle"));
392 dialog
->idle_return
= gnt_check_box_new(_("Is no longer idle"));
393 dialog
->typing
= gnt_check_box_new(_("Starts typing"));
394 dialog
->typed
= gnt_check_box_new(_("Pauses while typing"));
395 dialog
->stop_typing
= gnt_check_box_new(_("Stops typing"));
396 dialog
->message_recv
= gnt_check_box_new(_("Sends a message"));
398 hbox
= gnt_hbox_new(TRUE
);
399 gnt_box_set_pad(GNT_BOX(hbox
), 2);
401 vbox
= gnt_vbox_new(FALSE
);
402 gnt_box_set_pad(GNT_BOX(vbox
), 0);
403 gnt_box_add_widget(GNT_BOX(hbox
), vbox
);
405 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->signon
);
406 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->away
);
407 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->idle
);
408 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->typing
);
409 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->stop_typing
);
411 vbox
= gnt_vbox_new(FALSE
);
412 gnt_box_set_pad(GNT_BOX(vbox
), 0);
413 gnt_box_add_widget(GNT_BOX(hbox
), vbox
);
415 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->signoff
);
416 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->away_return
);
417 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->idle_return
);
418 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->typed
);
419 gnt_box_add_widget(GNT_BOX(vbox
), dialog
->message_recv
);
421 gnt_box_add_widget(GNT_BOX(window
), hbox
);
423 /* Create the "Action" frame. */
424 gnt_box_add_widget(GNT_BOX(window
), gnt_line_new(FALSE
));
425 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new_with_format(_("Action"), GNT_TEXT_FLAG_BOLD
));
427 dialog
->open_win
= gnt_check_box_new(_("Open an IM window"));
428 dialog
->popup
= gnt_check_box_new(_("Pop up a notification"));
429 dialog
->send_msg
= gnt_check_box_new(_("Send a message"));
430 dialog
->exec_cmd
= gnt_check_box_new(_("Execute a command"));
431 dialog
->play_sound
= gnt_check_box_new(_("Play a sound"));
433 dialog
->send_msg_entry
= gnt_entry_new(NULL
);
434 dialog
->exec_cmd_entry
= gnt_entry_new(NULL
);
435 dialog
->popup_entry
= gnt_entry_new(NULL
);
436 dialog
->exec_cmd_entry
= gnt_entry_new(NULL
);
438 hbox
= gnt_hbox_new(FALSE
);
439 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->open_win
);
440 gnt_box_add_widget(GNT_BOX(window
), hbox
);
441 hbox
= gnt_hbox_new(FALSE
);
442 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->popup
);
443 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->popup_entry
);
444 gnt_box_add_widget(GNT_BOX(window
), hbox
);
445 hbox
= gnt_hbox_new(FALSE
);
446 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->send_msg
);
447 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->send_msg_entry
);
448 gnt_box_add_widget(GNT_BOX(window
), hbox
);
449 hbox
= gnt_hbox_new(FALSE
);
450 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->exec_cmd
);
451 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->exec_cmd_entry
);
452 gnt_box_add_widget(GNT_BOX(window
), hbox
);
453 hbox
= gnt_hbox_new(FALSE
);
454 gnt_box_add_widget(GNT_BOX(hbox
), dialog
->play_sound
);
455 gnt_box_add_widget(GNT_BOX(window
), hbox
);
457 gnt_box_add_widget(GNT_BOX(window
), gnt_line_new(FALSE
));
458 gnt_box_add_widget(GNT_BOX(window
), gnt_label_new_with_format(_("Options"), GNT_TEXT_FLAG_BOLD
));
459 dialog
->on_away
= gnt_check_box_new(_("Pounce only when my status is not Available"));
460 gnt_box_add_widget(GNT_BOX(window
), dialog
->on_away
);
461 dialog
->save_pounce
= gnt_check_box_new(_("Recurring"));
462 gnt_box_add_widget(GNT_BOX(window
), dialog
->save_pounce
);
465 gnt_box_add_widget(GNT_BOX(window
), gnt_line_new(FALSE
));
466 /* Now the button box! */
467 bbox
= gnt_hbox_new(FALSE
);
470 button
= gnt_button_new(_("Cancel"));
471 gnt_box_add_widget(GNT_BOX(bbox
), button
);
472 g_signal_connect(G_OBJECT(button
), "activate",
473 G_CALLBACK(cancel_cb
), dialog
);
476 dialog
->save_button
= button
= gnt_button_new(_("Save"));
477 gnt_box_add_widget(GNT_BOX(bbox
), button
);
478 g_signal_connect(G_OBJECT(button
), "activate",
479 G_CALLBACK(save_pounce_cb
), dialog
);
481 gnt_box_add_widget(GNT_BOX(window
), bbox
);
484 /* Set the values of stuff. */
485 if (cur_pounce
!= NULL
)
487 PurplePounceEvent events
= purple_pounce_get_events(cur_pounce
);
488 PurplePounceOption options
= purple_pounce_get_options(cur_pounce
);
492 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->on_away
),
493 (options
& PURPLE_POUNCE_OPTION_AWAY
));
496 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->signon
),
497 (events
& PURPLE_POUNCE_SIGNON
));
498 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->signoff
),
499 (events
& PURPLE_POUNCE_SIGNOFF
));
500 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->away
),
501 (events
& PURPLE_POUNCE_AWAY
));
502 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->away_return
),
503 (events
& PURPLE_POUNCE_AWAY_RETURN
));
504 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->idle
),
505 (events
& PURPLE_POUNCE_IDLE
));
506 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->idle_return
),
507 (events
& PURPLE_POUNCE_IDLE_RETURN
));
508 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->typing
),
509 (events
& PURPLE_POUNCE_TYPING
));
510 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->typed
),
511 (events
& PURPLE_POUNCE_TYPED
));
512 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->stop_typing
),
513 (events
& PURPLE_POUNCE_TYPING_STOPPED
));
514 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->message_recv
),
515 (events
& PURPLE_POUNCE_MESSAGE_RECEIVED
));
518 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->open_win
),
519 purple_pounce_action_is_enabled(cur_pounce
, "open-window"));
520 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->popup
),
521 purple_pounce_action_is_enabled(cur_pounce
, "popup-notify"));
522 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->send_msg
),
523 purple_pounce_action_is_enabled(cur_pounce
, "send-message"));
524 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->exec_cmd
),
525 purple_pounce_action_is_enabled(cur_pounce
, "execute-command"));
526 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->play_sound
),
527 purple_pounce_action_is_enabled(cur_pounce
, "play-beep"));
529 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->save_pounce
),
530 purple_pounce_get_save(cur_pounce
));
532 if ((value
= purple_pounce_action_get_attribute(cur_pounce
,
536 gnt_entry_set_text(GNT_ENTRY(dialog
->send_msg_entry
), value
);
539 if ((value
= purple_pounce_action_get_attribute(cur_pounce
,
543 gnt_entry_set_text(GNT_ENTRY(dialog
->popup_entry
), value
);
546 if ((value
= purple_pounce_action_get_attribute(cur_pounce
,
550 gnt_entry_set_text(GNT_ENTRY(dialog
->exec_cmd_entry
), value
);
555 PurpleBuddy
*buddy
= NULL
;
558 buddy
= purple_blist_find_buddy(account
, name
);
560 /* Set some defaults */
562 gnt_check_box_set_checked(
563 GNT_CHECK_BOX(dialog
->signon
), TRUE
);
565 if (!PURPLE_BUDDY_IS_ONLINE(buddy
)) {
566 gnt_check_box_set_checked(
567 GNT_CHECK_BOX(dialog
->signon
), TRUE
);
569 gboolean default_set
= FALSE
;
570 PurplePresence
*presence
= purple_buddy_get_presence(buddy
);
572 if (purple_presence_is_idle(presence
))
574 gnt_check_box_set_checked(
575 GNT_CHECK_BOX(dialog
->idle_return
), TRUE
);
580 if (!purple_presence_is_available(presence
))
582 gnt_check_box_set_checked(
583 GNT_CHECK_BOX(dialog
->away_return
), TRUE
);
590 gnt_check_box_set_checked(
591 GNT_CHECK_BOX(dialog
->signon
), TRUE
);
596 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->open_win
),
597 purple_prefs_get_bool("/finch/pounces/default_actions/open-window"));
598 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->popup
),
599 purple_prefs_get_bool("/finch/pounces/default_actions/popup-notify"));
600 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->send_msg
),
601 purple_prefs_get_bool("/finch/pounces/default_actions/send-message"));
602 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->exec_cmd
),
603 purple_prefs_get_bool("/finch/pounces/default_actions/execute-command"));
604 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog
->play_sound
),
605 purple_prefs_get_bool("/finch/pounces/default_actions/play-beep"));
608 gnt_widget_show(window
);
614 pounces_manager_destroy_cb(GntWidget
*widget
, gpointer user_data
)
616 PouncesManager
*dialog
= user_data
;
618 dialog
->window
= NULL
;
619 finch_pounces_manager_hide();
626 pounces_manager_add_cb(GntButton
*button
, gpointer user_data
)
628 if (purple_accounts_get_all() == NULL
) {
629 purple_notify_error(NULL
, _("Cannot create pounce"),
630 _("You do not have any accounts."),
631 _("You must create an account first before you can create a pounce."), NULL
);
634 finch_pounce_editor_show(NULL
, NULL
, NULL
);
639 pounces_manager_modify_cb(GntButton
*button
, gpointer user_data
)
641 PouncesManager
*dialog
= user_data
;
642 PurplePounce
*pounce
= gnt_tree_get_selection_data(GNT_TREE(dialog
->tree
));
644 finch_pounce_editor_show(NULL
, NULL
, pounce
);
648 pounces_manager_delete_confirm_cb(PurplePounce
*pounce
)
650 gnt_tree_remove(GNT_TREE(pounces_manager
->tree
), pounce
);
652 purple_request_close_with_handle(pounce
);
653 purple_pounce_destroy(pounce
);
658 pounces_manager_delete_cb(GntButton
*button
, gpointer user_data
)
660 PouncesManager
*dialog
= user_data
;
661 PurplePounce
*pounce
;
662 PurpleAccount
*account
;
663 const char *pouncer
, *pouncee
;
666 pounce
= (PurplePounce
*)gnt_tree_get_selection_data(GNT_TREE(dialog
->tree
));
670 account
= purple_pounce_get_pouncer(pounce
);
671 pouncer
= purple_account_get_username(account
);
672 pouncee
= purple_pounce_get_pouncee(pounce
);
673 buf
= g_strdup_printf(_("Are you sure you want to delete the pounce on %s for %s?"), pouncee
, pouncer
);
674 purple_request_action(pounce
, NULL
, buf
, NULL
, 0,
675 purple_request_cpar_from_account(account
), pounce
, 2,
676 _("Delete"), pounces_manager_delete_confirm_cb
,
682 pounces_manager_close_cb(GntButton
*button
, gpointer user_data
)
684 finch_pounces_manager_hide();
689 finch_pounces_manager_show(void)
691 PouncesManager
*dialog
;
697 if (pounces_manager
!= NULL
) {
698 gnt_window_present(pounces_manager
->window
);
702 pounces_manager
= dialog
= g_new0(PouncesManager
, 1);
704 dialog
->window
= win
= gnt_vbox_new(FALSE
);
705 gnt_box_set_toplevel(GNT_BOX(win
), TRUE
);
706 gnt_box_set_title(GNT_BOX(win
), _("Buddy Pounces"));
707 gnt_box_set_pad(GNT_BOX(win
), 0);
709 g_signal_connect(G_OBJECT(win
), "destroy",
710 G_CALLBACK(pounces_manager_destroy_cb
), dialog
);
712 /* List of saved buddy pounces */
713 dialog
->tree
= tree
= GNT_WIDGET(gnt_tree_new_with_columns(2));
714 gnt_tree_set_column_titles(GNT_TREE(tree
), "Account", "Pouncee", NULL
);
715 gnt_tree_set_show_title(GNT_TREE(tree
), TRUE
);
717 gnt_box_add_widget(GNT_BOX(win
), tree
);
720 bbox
= gnt_hbox_new(FALSE
);
723 button
= gnt_button_new(_("Add"));
724 gnt_box_add_widget(GNT_BOX(bbox
), button
);
725 gnt_util_set_trigger_widget(tree
, GNT_KEY_INS
, button
);
727 g_signal_connect(G_OBJECT(button
), "activate",
728 G_CALLBACK(pounces_manager_add_cb
), dialog
);
731 button
= gnt_button_new(_("Modify"));
732 dialog
->modify_button
= button
;
733 gnt_box_add_widget(GNT_BOX(bbox
), button
);
735 g_signal_connect(G_OBJECT(button
), "activate",
736 G_CALLBACK(pounces_manager_modify_cb
), dialog
);
739 button
= gnt_button_new(_("Delete"));
740 dialog
->delete_button
= button
;
741 gnt_box_add_widget(GNT_BOX(bbox
), button
);
742 gnt_util_set_trigger_widget(tree
, GNT_KEY_DEL
, button
);
744 g_signal_connect(G_OBJECT(button
), "activate",
745 G_CALLBACK(pounces_manager_delete_cb
), dialog
);
748 button
= gnt_button_new(_("Close"));
749 gnt_box_add_widget(GNT_BOX(bbox
), button
);
750 gnt_widget_show(button
);
752 g_signal_connect(G_OBJECT(button
), "activate",
753 G_CALLBACK(pounces_manager_close_cb
), dialog
);
755 gnt_box_add_widget(GNT_BOX(win
), bbox
);
757 gnt_widget_show(win
);
758 populate_pounces_list(pounces_manager
);
762 finch_pounces_manager_hide(void)
764 if (pounces_manager
== NULL
)
767 if (pounces_manager
->window
!= NULL
)
768 gnt_widget_destroy(pounces_manager
->window
);
770 purple_signals_disconnect_by_handle(pounces_manager
);
772 g_free(pounces_manager
);
773 pounces_manager
= NULL
;
777 pounce_cb(PurplePounce
*pounce
, PurplePounceEvent events
, void *data
)
779 PurpleIMConversation
*im
;
780 PurpleAccount
*account
;
785 pouncee
= purple_pounce_get_pouncee(pounce
);
786 account
= purple_pounce_get_pouncer(pounce
);
788 buddy
= purple_blist_find_buddy(account
, pouncee
);
791 alias
= purple_buddy_get_alias(buddy
);
798 if (purple_pounce_action_is_enabled(pounce
, "open-window"))
800 if (!purple_conversations_find_im_with_account(pouncee
, account
))
801 purple_im_conversation_new(account
, pouncee
);
804 if (purple_pounce_action_is_enabled(pounce
, "popup-notify"))
807 const char *name_shown
;
810 PurplePounceEvent event
;
813 {PURPLE_POUNCE_TYPING
, _("%s has started typing to you (%s)")},
814 {PURPLE_POUNCE_TYPED
, _("%s has paused while typing to you (%s)")},
815 {PURPLE_POUNCE_SIGNON
, _("%s has signed on (%s)")},
816 {PURPLE_POUNCE_IDLE_RETURN
, _("%s has returned from being idle (%s)")},
817 {PURPLE_POUNCE_AWAY_RETURN
, _("%s has returned from being away (%s)")},
818 {PURPLE_POUNCE_TYPING_STOPPED
, _("%s has stopped typing to you (%s)")},
819 {PURPLE_POUNCE_SIGNOFF
, _("%s has signed off (%s)")},
820 {PURPLE_POUNCE_IDLE
, _("%s has become idle (%s)")},
821 {PURPLE_POUNCE_AWAY
, _("%s has gone away. (%s)")},
822 {PURPLE_POUNCE_MESSAGE_RECEIVED
, _("%s has sent you a message. (%s)")},
826 reason
= purple_pounce_action_get_attribute(pounce
, "popup-notify",
830 * Here we place the protocol name in the pounce dialog to lessen
831 * confusion about what protocol a pounce is for.
833 for (i
= 0; messages
[i
].format
!= NULL
; i
++) {
834 if (messages
[i
].event
& events
) {
835 tmp
= g_strdup_printf(messages
[i
].format
, alias
,
836 purple_account_get_protocol_name(account
));
841 tmp
= g_strdup(_("Unknown pounce event. Please report this!"));
844 * Ok here is where I change the second argument, title, from
845 * NULL to the account alias if we have it or the account
846 * name if that's all we have
848 if ((name_shown
= purple_account_get_private_alias(account
)) == NULL
)
849 name_shown
= purple_account_get_username(account
);
853 purple_notify_info(NULL
, name_shown
, tmp
, purple_date_format_full(NULL
), NULL
);
857 char *tmp2
= g_strdup_printf("%s\n\n%s", reason
, purple_date_format_full(NULL
));
858 purple_notify_info(NULL
, name_shown
, tmp
, tmp2
, NULL
);
864 if (purple_pounce_action_is_enabled(pounce
, "send-message"))
868 message
= purple_pounce_action_get_attribute(pounce
, "send-message",
875 im
= purple_conversations_find_im_with_account(pouncee
, account
);
878 im
= purple_im_conversation_new(account
, pouncee
);
880 pmsg
= purple_message_new_outgoing(pouncee
, message
, 0);
881 purple_serv_send_im(purple_account_get_connection(account
), pmsg
);
882 purple_conversation_write_message(PURPLE_CONVERSATION(im
), pmsg
);
886 if (purple_pounce_action_is_enabled(pounce
, "execute-command"))
889 purple_debug_error("gntpounce", "execute-command is not supported on this OS");
893 command
= purple_pounce_action_get_attribute(pounce
,
894 "execute-command", "command");
898 char *localecmd
= g_locale_from_utf8(command
, -1, NULL
,
901 if (localecmd
!= NULL
)
910 args
[2] = (char *)localecmd
;
913 execvp(args
[0], args
);
923 if (purple_pounce_action_is_enabled(pounce
, "play-beep"))
930 free_pounce(PurplePounce
*pounce
)
936 new_pounce(PurplePounce
*pounce
)
938 purple_pounce_action_register(pounce
, "open-window");
939 purple_pounce_action_register(pounce
, "popup-notify");
940 purple_pounce_action_register(pounce
, "send-message");
941 purple_pounce_action_register(pounce
, "execute-command");
942 purple_pounce_action_register(pounce
, "play-beep");
948 finch_pounces_get_handle()
956 finch_pounces_init(void)
958 purple_pounces_register_handler(FINCH_UI
, pounce_cb
, new_pounce
,
961 purple_prefs_add_none("/finch/pounces");
962 purple_prefs_add_none("/finch/pounces/default_actions");
963 purple_prefs_add_bool("/finch/pounces/default_actions/open-window",
965 purple_prefs_add_bool("/finch/pounces/default_actions/popup-notify",
967 purple_prefs_add_bool("/finch/pounces/default_actions/send-message",
969 purple_prefs_add_bool("/finch/pounces/default_actions/execute-command",
971 purple_prefs_add_bool("/finch/pounces/default_actions/play-beep",
973 purple_prefs_add_none("/finch/pounces/dialog");
975 purple_signal_connect(purple_connections_get_handle(), "signed-on",
976 finch_pounces_get_handle(),
977 PURPLE_CALLBACK(signed_on_off_cb
), NULL
);
978 purple_signal_connect(purple_connections_get_handle(), "signed-off",
979 finch_pounces_get_handle(),
980 PURPLE_CALLBACK(signed_on_off_cb
), NULL
);
983 /* XXX: There's no such thing in pidgin. Perhaps there should be?
984 * For sure, we don't need purple_pounces_unregister_handler -
985 * it's wiped in purple_pounces_uninit.
987 void finch_pounces_uninit()
989 purple_signals_disconnect_by_handle(finch_pounces_get_handle());