comparison src/gtkpounce.c @ 5319:3adb20b869b4

[gaim-migrate @ 5691] Buddy pounce dialog enhancements from Benjamin Zeiss. Thanks! committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 07 May 2003 00:33:03 +0000
parents 1a53330dfd34
children ad445074d239
comparison
equal deleted inserted replaced
5318:bd98232872a3 5319:3adb20b869b4
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * 21 *
22 */ 22 */
23 #include <unistd.h> 23 #include <unistd.h>
24 #include <string.h>
24 #include "gaim.h" 25 #include "gaim.h"
25 #include "gtkpounce.h" 26 #include "gtkpounce.h"
26 #include "gtkblist.h" 27 #include "gtkblist.h"
27 #include "prpl.h" 28 #include "prpl.h"
28 #include "sound.h" 29 #include "sound.h"
55 GtkWidget *popup; 56 GtkWidget *popup;
56 GtkWidget *send_msg; 57 GtkWidget *send_msg;
57 GtkWidget *send_msg_entry; 58 GtkWidget *send_msg_entry;
58 GtkWidget *exec_cmd; 59 GtkWidget *exec_cmd;
59 GtkWidget *exec_cmd_entry; 60 GtkWidget *exec_cmd_entry;
61 GtkWidget *exec_cmd_browse;
60 GtkWidget *play_sound; 62 GtkWidget *play_sound;
61 GtkWidget *play_sound_entry; 63 GtkWidget *play_sound_entry;
62 64 GtkWidget *play_sound_browse;
65 GtkWidget *play_sound_test;
66
63 GtkWidget *save_pounce; 67 GtkWidget *save_pounce;
64 }; 68 };
65 69
66 /************************************************************************** 70 /**************************************************************************
67 * Callbacks 71 * Callbacks
88 cancel_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog) 92 cancel_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog)
89 { 93 {
90 delete_win_cb(NULL, NULL, dialog); 94 delete_win_cb(NULL, NULL, dialog);
91 } 95 }
92 96
97 static void
98 pounce_update_entryfields(GtkWidget *w, gpointer data)
99 {
100 const char *selected_filename;
101 GHashTable *args;
102
103 args = (GHashTable *) data;
104
105 selected_filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(g_hash_table_lookup(args, "pounce_file_selector")));
106 if (selected_filename != NULL)
107 gtk_entry_set_text(GTK_ENTRY(g_hash_table_lookup(args, "entry")),selected_filename);
108
109 g_free(args);
110 }
111
112 static void
113 pounce_file_selector(GtkWidget *w, gpointer data)
114 {
115 GtkWidget *pounce_file_selector;
116 GtkWidget *entry;
117 GHashTable *args;
118
119 entry = (GtkWidget *) data;
120
121 pounce_file_selector = gtk_file_selection_new(_("Select a file"));
122 gtk_file_selection_set_filename(GTK_FILE_SELECTION(pounce_file_selector), gtk_entry_get_text(GTK_ENTRY(entry)));
123 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(pounce_file_selector));
124 gtk_file_selection_set_select_multiple(GTK_FILE_SELECTION(pounce_file_selector), FALSE);
125
126 args = g_hash_table_new(g_str_hash,g_str_equal);
127 g_hash_table_insert(args, "pounce_file_selector", (gpointer) pounce_file_selector);
128 g_hash_table_insert(args, "entry", (gpointer) entry);
129
130 g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(pounce_file_selector)->ok_button),
131 "clicked", G_CALLBACK(pounce_update_entryfields), (gpointer) args);
132
133 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(pounce_file_selector)->ok_button),
134 "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer) pounce_file_selector);
135 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(pounce_file_selector)->cancel_button),
136 "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer) pounce_file_selector);
137
138 gtk_widget_show(pounce_file_selector);
139 }
140
141 static void
142 pounce_test_sound(GtkWidget *w, gpointer data)
143 {
144 const char *filename;
145 GtkWidget *entry;
146
147 entry = (GtkWidget *) data;
148
149 filename = gtk_entry_get_text(GTK_ENTRY(entry));
150 if ((filename != NULL) && (strlen(filename) > 0))
151 gaim_sound_play_file((char *) filename);
152 else
153 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT);
154 }
93 155
94 static void 156 static void
95 save_pounce_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog) 157 save_pounce_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog)
96 { 158 {
97 const char *name; 159 const char *name;
188 pounce_data->actions = actions; 250 pounce_data->actions = actions;
189 pounce_data->save = save; 251 pounce_data->save = save;
190 } 252 }
191 253
192 delete_win_cb(NULL, NULL, dialog); 254 delete_win_cb(NULL, NULL, dialog);
193
194 /* Rebuild the pounce menu */ 255 /* Rebuild the pounce menu */
195 blist = gaim_get_blist(); 256 blist = gaim_get_blist();
196 257
197 if (GAIM_IS_GTK_BLIST(blist)) 258 if (GAIM_IS_GTK_BLIST(blist))
198 { 259 {
400 GtkWidget *button; 461 GtkWidget *button;
401 GtkWidget *frame; 462 GtkWidget *frame;
402 GtkWidget *table; 463 GtkWidget *table;
403 GtkWidget *sep; 464 GtkWidget *sep;
404 GtkSizeGroup *sg; 465 GtkSizeGroup *sg;
405 466 GPtrArray *sound_widgets;
467 GPtrArray *exec_widgets;
468
406 dialog = g_new0(struct gaim_gtkpounce_dialog, 1); 469 dialog = g_new0(struct gaim_gtkpounce_dialog, 1);
407 470
408 if (cur_pounce != NULL) { 471 if (cur_pounce != NULL) {
409 dialog->pounce = cur_pounce; 472 dialog->pounce = cur_pounce;
410 dialog->account = gaim_pounce_get_pouncer(cur_pounce); 473 dialog->account = gaim_pounce_get_pouncer(cur_pounce);
522 GTK_FILL, 0, 0, 0); 585 GTK_FILL, 0, 0, 0);
523 gtk_table_attach(GTK_TABLE(table), dialog->idle_return, 1, 2, 2, 3, 586 gtk_table_attach(GTK_TABLE(table), dialog->idle_return, 1, 2, 2, 3,
524 GTK_FILL, 0, 0, 0); 587 GTK_FILL, 0, 0, 0);
525 gtk_table_attach(GTK_TABLE(table), dialog->typing, 0, 1, 3, 4, 588 gtk_table_attach(GTK_TABLE(table), dialog->typing, 0, 1, 3, 4,
526 GTK_FILL, 0, 0, 0); 589 GTK_FILL, 0, 0, 0);
527 gtk_table_attach(GTK_TABLE(table), dialog->stop_typing, 1, 2, 3, 4, 590 gtk_table_attach(GTK_TABLE(table), dialog->stop_typing, 1, 2, 3, 5,
528 GTK_FILL, 0, 0, 0); 591 GTK_FILL, 0, 0, 0);
529 592
530 gtk_widget_show(dialog->signon); 593 gtk_widget_show(dialog->signon);
531 gtk_widget_show(dialog->signoff); 594 gtk_widget_show(dialog->signoff);
532 gtk_widget_show(dialog->away); 595 gtk_widget_show(dialog->away);
537 gtk_widget_show(dialog->stop_typing); 600 gtk_widget_show(dialog->stop_typing);
538 601
539 /* Create the "Pounce Action" frame. */ 602 /* Create the "Pounce Action" frame. */
540 frame = make_frame(vbox2, _("Pounce Action")); 603 frame = make_frame(vbox2, _("Pounce Action"));
541 604
542 table = gtk_table_new(2, 5, FALSE); 605 table = gtk_table_new(3, 5, FALSE);
543 gtk_container_add(GTK_CONTAINER(frame), table); 606 gtk_container_add(GTK_CONTAINER(frame), table);
544 gtk_table_set_col_spacings(GTK_TABLE(table), 12); 607 gtk_table_set_col_spacings(GTK_TABLE(table), 12);
545 gtk_widget_show(table); 608 gtk_widget_show(table);
546 609
547 dialog->open_win = gtk_check_button_new_with_label(_("Open an IM window")); 610 dialog->open_win = gtk_check_button_new_with_label(_("Open an IM window"));
548 dialog->popup = gtk_check_button_new_with_label(_("Popup notification")); 611 dialog->popup = gtk_check_button_new_with_label(_("Popup notification"));
549 dialog->send_msg = gtk_check_button_new_with_label(_("Send a message")); 612 dialog->send_msg = gtk_check_button_new_with_label(_("Send a message"));
550 dialog->exec_cmd = gtk_check_button_new_with_label(_("Execute a command")); 613 dialog->exec_cmd = gtk_check_button_new_with_label(_("Execute a command"));
551 dialog->play_sound = gtk_check_button_new_with_label(_("Play a sound")); 614 dialog->play_sound = gtk_check_button_new_with_label(_("Play a sound"));
552 615
553 dialog->send_msg_entry = gtk_entry_new(); 616 dialog->send_msg_entry = gtk_entry_new();
554 dialog->exec_cmd_entry = gtk_entry_new(); 617 dialog->exec_cmd_entry = gtk_entry_new();
618 dialog->exec_cmd_browse = gtk_button_new_with_label(_("Browse"));
555 dialog->play_sound_entry = gtk_entry_new(); 619 dialog->play_sound_entry = gtk_entry_new();
556 620 dialog->play_sound_browse = gtk_button_new_with_label(_("Browse"));
621 dialog->play_sound_test = gtk_button_new_with_label(_("Test"));
622
557 gtk_widget_set_sensitive(dialog->send_msg_entry, FALSE); 623 gtk_widget_set_sensitive(dialog->send_msg_entry, FALSE);
558 gtk_widget_set_sensitive(dialog->exec_cmd_entry, FALSE); 624 gtk_widget_set_sensitive(dialog->exec_cmd_entry, FALSE);
625 gtk_widget_set_sensitive(dialog->exec_cmd_browse, FALSE);
559 gtk_widget_set_sensitive(dialog->play_sound_entry, FALSE); 626 gtk_widget_set_sensitive(dialog->play_sound_entry, FALSE);
627 gtk_widget_set_sensitive(dialog->play_sound_browse, FALSE);
628 gtk_widget_set_sensitive(dialog->play_sound_test, FALSE);
560 629
561 gtk_table_attach(GTK_TABLE(table), dialog->open_win, 0, 1, 0, 1, 630 gtk_table_attach(GTK_TABLE(table), dialog->open_win, 0, 1, 0, 1,
562 GTK_FILL, 0, 0, 0); 631 GTK_FILL, 0, 0, 0);
563 gtk_table_attach(GTK_TABLE(table), dialog->popup, 0, 1, 1, 2, 632 gtk_table_attach(GTK_TABLE(table), dialog->popup, 0, 1, 1, 2,
564 GTK_FILL, 0, 0, 0); 633 GTK_FILL, 0, 0, 0);
565 gtk_table_attach(GTK_TABLE(table), dialog->send_msg, 0, 1, 2, 3, 634 gtk_table_attach(GTK_TABLE(table), dialog->send_msg, 0, 1, 2, 3,
566 GTK_FILL, 0, 0, 0); 635 GTK_FILL, 0, 0, 0);
567 gtk_table_attach(GTK_TABLE(table), dialog->send_msg_entry, 1, 2, 2, 3, 636 gtk_table_attach(GTK_TABLE(table), dialog->send_msg_entry, 1, 4, 2, 3,
568 GTK_FILL, 0, 0, 0); 637 GTK_FILL, 0, 0, 0);
569 gtk_table_attach(GTK_TABLE(table), dialog->exec_cmd, 0, 1, 3, 4, 638 gtk_table_attach(GTK_TABLE(table), dialog->exec_cmd, 0, 1, 3, 4,
570 GTK_FILL, 0, 0, 0); 639 GTK_FILL, 0, 0, 0);
571 gtk_table_attach(GTK_TABLE(table), dialog->exec_cmd_entry, 1, 2, 3, 4, 640 gtk_table_attach(GTK_TABLE(table), dialog->exec_cmd_entry, 1, 2, 3, 4,
572 GTK_FILL, 0, 0, 0); 641 GTK_FILL, 0, 0, 0);
642 gtk_table_attach(GTK_TABLE(table), dialog->exec_cmd_browse, 2, 3, 3, 4,
643 GTK_FILL | GTK_EXPAND, 0, 0, 0);
573 gtk_table_attach(GTK_TABLE(table), dialog->play_sound, 0, 1, 4, 5, 644 gtk_table_attach(GTK_TABLE(table), dialog->play_sound, 0, 1, 4, 5,
574 GTK_FILL, 0, 0, 0); 645 GTK_FILL, 0, 0, 0);
575 gtk_table_attach(GTK_TABLE(table), dialog->play_sound_entry, 1, 2, 4, 5, 646 gtk_table_attach(GTK_TABLE(table), dialog->play_sound_entry, 1, 2, 4, 5,
576 GTK_FILL, 0, 0, 0); 647 GTK_FILL, 0, 0, 0);
648 gtk_table_attach(GTK_TABLE(table), dialog->play_sound_browse, 2, 3, 4, 5,
649 GTK_FILL | GTK_EXPAND, 0, 0, 0);
650 gtk_table_attach(GTK_TABLE(table), dialog->play_sound_test, 3, 4, 4, 5,
651 GTK_FILL | GTK_EXPAND, 0, 0, 0);
577 652
578 gtk_widget_show(dialog->open_win); 653 gtk_widget_show(dialog->open_win);
579 gtk_widget_show(dialog->popup); 654 gtk_widget_show(dialog->popup);
580 gtk_widget_show(dialog->send_msg); 655 gtk_widget_show(dialog->send_msg);
581 gtk_widget_show(dialog->send_msg_entry); 656 gtk_widget_show(dialog->send_msg_entry);
582 gtk_widget_show(dialog->exec_cmd); 657 gtk_widget_show(dialog->exec_cmd);
583 gtk_widget_show(dialog->exec_cmd_entry); 658 gtk_widget_show(dialog->exec_cmd_entry);
659 gtk_widget_show(dialog->exec_cmd_browse);
584 gtk_widget_show(dialog->play_sound); 660 gtk_widget_show(dialog->play_sound);
585 gtk_widget_show(dialog->play_sound_entry); 661 gtk_widget_show(dialog->play_sound_entry);
662 gtk_widget_show(dialog->play_sound_browse);
663 gtk_widget_show(dialog->play_sound_test);
586 664
587 g_signal_connect(G_OBJECT(dialog->send_msg), "clicked", 665 g_signal_connect(G_OBJECT(dialog->send_msg), "clicked",
588 G_CALLBACK(gaim_gtk_toggle_sensitive), 666 G_CALLBACK(gaim_gtk_toggle_sensitive),
589 dialog->send_msg_entry); 667 dialog->send_msg_entry);
668
669 exec_widgets = g_ptr_array_new();
670 g_ptr_array_add(exec_widgets,dialog->exec_cmd_entry);
671 g_ptr_array_add(exec_widgets,dialog->exec_cmd_browse);
672
590 g_signal_connect(G_OBJECT(dialog->exec_cmd), "clicked", 673 g_signal_connect(G_OBJECT(dialog->exec_cmd), "clicked",
591 G_CALLBACK(gaim_gtk_toggle_sensitive), 674 G_CALLBACK(gtk_toggle_sensitive_array),
675 exec_widgets);
676 g_signal_connect(G_OBJECT(dialog->exec_cmd_browse), "clicked",
677 G_CALLBACK(pounce_file_selector),
592 dialog->exec_cmd_entry); 678 dialog->exec_cmd_entry);
679
680 sound_widgets = g_ptr_array_new();
681 g_ptr_array_add(sound_widgets,dialog->play_sound_entry);
682 g_ptr_array_add(sound_widgets,dialog->play_sound_browse);
683 g_ptr_array_add(sound_widgets,dialog->play_sound_test);
684
593 g_signal_connect(G_OBJECT(dialog->play_sound), "clicked", 685 g_signal_connect(G_OBJECT(dialog->play_sound), "clicked",
594 G_CALLBACK(gaim_gtk_toggle_sensitive), 686 G_CALLBACK(gtk_toggle_sensitive_array),
687 sound_widgets);
688 g_signal_connect(G_OBJECT(dialog->play_sound_browse), "clicked",
689 G_CALLBACK(pounce_file_selector),
595 dialog->play_sound_entry); 690 dialog->play_sound_entry);
596 691 g_signal_connect(G_OBJECT(dialog->play_sound_test), "clicked",
692 G_CALLBACK(pounce_test_sound),
693 dialog->play_sound_entry);
694
597 g_signal_connect(G_OBJECT(dialog->send_msg_entry), "activate", 695 g_signal_connect(G_OBJECT(dialog->send_msg_entry), "activate",
598 G_CALLBACK(save_pounce_cb), dialog); 696 G_CALLBACK(save_pounce_cb), dialog);
599 g_signal_connect(G_OBJECT(dialog->exec_cmd_entry), "activate", 697 g_signal_connect(G_OBJECT(dialog->exec_cmd_entry), "activate",
600 G_CALLBACK(save_pounce_cb), dialog); 698 G_CALLBACK(save_pounce_cb), dialog);
601 g_signal_connect(G_OBJECT(dialog->play_sound_entry), "activate", 699 g_signal_connect(G_OBJECT(dialog->play_sound_entry), "activate",
602 G_CALLBACK(save_pounce_cb), dialog); 700 G_CALLBACK(save_pounce_cb), dialog);
603 701
604 /* Now the last part, where we have the Save checkbox */ 702 /* Now the last part, where we have the Save checkbox */
605 dialog->save_pounce = gtk_check_button_new_with_mnemonic( 703 dialog->save_pounce = gtk_check_button_new_with_mnemonic(
606 _("_Save this pounce after activation")); 704 _("_Save this pounce after activation"));
607 705
608 gtk_box_pack_start(GTK_BOX(vbox2), dialog->save_pounce, FALSE, FALSE, 0); 706 gtk_box_pack_start(GTK_BOX(vbox2), dialog->save_pounce, FALSE, FALSE, 0);
682 (actions & GAIM_GTKPOUNCE_PLAY_SOUND)); 780 (actions & GAIM_GTKPOUNCE_PLAY_SOUND));
683 781
684 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->save_pounce), 782 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->save_pounce),
685 pounce_data->save); 783 pounce_data->save);
686 784
687 gtk_entry_set_text(GTK_ENTRY(dialog->send_msg_entry), 785 if (pounce_data->message != NULL)
688 pounce_data->message); 786 gtk_entry_set_text(GTK_ENTRY(dialog->send_msg_entry),
689 gtk_entry_set_text(GTK_ENTRY(dialog->exec_cmd_entry), 787 pounce_data->message);
690 pounce_data->command); 788 if (pounce_data->command != NULL)
691 gtk_entry_set_text(GTK_ENTRY(dialog->play_sound_entry), 789 gtk_entry_set_text(GTK_ENTRY(dialog->exec_cmd_entry),
692 pounce_data->sound); 790 pounce_data->command);
791 if (pounce_data->sound != NULL)
792 gtk_entry_set_text(GTK_ENTRY(dialog->play_sound_entry),
793 pounce_data->sound);
693 } 794 }
694 else { 795 else {
695 /* Set some defaults */ 796 /* Set some defaults */
696 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->send_msg), TRUE); 797 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->send_msg), TRUE);
697 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->signon), TRUE); 798 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->signon), TRUE);