comparison src/gtkpounce.c @ 9205:5b35a6b96726

[gaim-migrate @ 10000] Buddy pounce defaults are now more sane, and apply to the state the buddy is currently in. For example, if the buddy is idle, set "Return from idle" by default. The action is now set to "Popup notification" by default, as well. Also, cleaned up the code a little bit. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 06 Jun 2004 04:21:33 +0000
parents 06b28fb24300
children 13bfd59e164f
comparison
equal deleted inserted replaced
9204:6478190b36a9 9205:5b35a6b96726
149 149
150 args = g_hash_table_new(g_str_hash, g_str_equal); 150 args = g_hash_table_new(g_str_hash, g_str_equal);
151 g_hash_table_insert(args, "filesel", filesel); 151 g_hash_table_insert(args, "filesel", filesel);
152 g_hash_table_insert(args, "entry", entry); 152 g_hash_table_insert(args, "entry", entry);
153 153
154 g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), 154 g_signal_connect(
155 "clicked", 155 GTK_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), "clicked",
156 G_CALLBACK(pounce_update_entry_fields), args); 156 G_CALLBACK(pounce_update_entry_fields), args);
157 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), 157 g_signal_connect_swapped(
158 "clicked", 158 G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), "clicked",
159 G_CALLBACK(g_hash_table_destroy), args); 159 G_CALLBACK(g_hash_table_destroy), args);
160 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), 160 g_signal_connect_swapped(
161 "clicked", 161 G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), "clicked",
162 G_CALLBACK(gtk_widget_destroy), filesel); 162 G_CALLBACK(gtk_widget_destroy), filesel);
163 163
164 gtk_widget_show(filesel); 164 gtk_widget_show(filesel);
165 } 165 }
166 166
167 static void 167 static void
226 226
227 if (*message == '\0') message = NULL; 227 if (*message == '\0') message = NULL;
228 if (*command == '\0') command = NULL; 228 if (*command == '\0') command = NULL;
229 if (*sound == '\0') sound = NULL; 229 if (*sound == '\0') sound = NULL;
230 230
231 if (dialog->pounce == NULL) { 231 if (dialog->pounce == NULL)
232 {
232 dialog->pounce = gaim_pounce_new(GAIM_GTK_UI, dialog->account, 233 dialog->pounce = gaim_pounce_new(GAIM_GTK_UI, dialog->account,
233 name, events); 234 name, events);
234 } 235 }
235 else { 236 else {
236 gaim_pounce_set_events(dialog->pounce, events); 237 gaim_pounce_set_events(dialog->pounce, events);
287 { 288 {
288 if (dialog->save_button == NULL) 289 if (dialog->save_button == NULL)
289 return; 290 return;
290 291
291 gtk_widget_set_sensitive(dialog->save_button, 292 gtk_widget_set_sensitive(dialog->save_button,
292 *gtk_entry_get_text(entry) != '\0'); 293 *gtk_entry_get_text(entry) != '\0');
293 } 294 }
294 295
295 static void 296 static void
296 pounce_dnd_recv(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, 297 pounce_dnd_recv(GtkWidget *widget, GdkDragContext *dc, gint x, gint y,
297 GtkSelectionData *sd, guint info, guint t, gpointer data) 298 GtkSelectionData *sd, guint info, guint t, gpointer data)
528 table = gtk_table_new(3, 5, FALSE); 529 table = gtk_table_new(3, 5, FALSE);
529 gtk_container_add(GTK_CONTAINER(frame), table); 530 gtk_container_add(GTK_CONTAINER(frame), table);
530 gtk_table_set_col_spacings(GTK_TABLE(table), 12); 531 gtk_table_set_col_spacings(GTK_TABLE(table), 12);
531 gtk_widget_show(table); 532 gtk_widget_show(table);
532 533
533 dialog->open_win = gtk_check_button_new_with_mnemonic(_("Op_en an IM window")); 534 dialog->open_win
534 dialog->popup = gtk_check_button_new_with_mnemonic(_("_Popup notification")); 535 = gtk_check_button_new_with_mnemonic(_("Op_en an IM window"));
535 dialog->send_msg = gtk_check_button_new_with_mnemonic(_("Send a _message")); 536 dialog->popup
536 dialog->exec_cmd = gtk_check_button_new_with_mnemonic(_("E_xecute a command")); 537 = gtk_check_button_new_with_mnemonic(_("_Popup notification"));
537 dialog->play_sound = gtk_check_button_new_with_mnemonic(_("P_lay a sound")); 538 dialog->send_msg
538 539 = gtk_check_button_new_with_mnemonic(_("Send a _message"));
539 dialog->send_msg_entry = gtk_entry_new(); 540 dialog->exec_cmd
540 dialog->exec_cmd_entry = gtk_entry_new(); 541 = gtk_check_button_new_with_mnemonic(_("E_xecute a command"));
541 dialog->exec_cmd_browse = gtk_button_new_with_mnemonic(_("B_rowse...")); 542 dialog->play_sound
542 dialog->play_sound_entry = gtk_entry_new(); 543 = gtk_check_button_new_with_mnemonic(_("P_lay a sound"));
544
545 dialog->send_msg_entry = gtk_entry_new();
546 dialog->exec_cmd_entry = gtk_entry_new();
547 dialog->exec_cmd_browse = gtk_button_new_with_mnemonic(_("B_rowse..."));
548 dialog->play_sound_entry = gtk_entry_new();
543 dialog->play_sound_browse = gtk_button_new_with_mnemonic(_("Bro_wse...")); 549 dialog->play_sound_browse = gtk_button_new_with_mnemonic(_("Bro_wse..."));
544 dialog->play_sound_test = gtk_button_new_with_mnemonic(_("Pre_view")); 550 dialog->play_sound_test = gtk_button_new_with_mnemonic(_("Pre_view"));
545 551
546 gtk_widget_set_sensitive(dialog->send_msg_entry, FALSE); 552 gtk_widget_set_sensitive(dialog->send_msg_entry, FALSE);
547 gtk_widget_set_sensitive(dialog->exec_cmd_entry, FALSE); 553 gtk_widget_set_sensitive(dialog->exec_cmd_entry, FALSE);
548 gtk_widget_set_sensitive(dialog->exec_cmd_browse, FALSE); 554 gtk_widget_set_sensitive(dialog->exec_cmd_browse, FALSE);
549 gtk_widget_set_sensitive(dialog->play_sound_entry, FALSE); 555 gtk_widget_set_sensitive(dialog->play_sound_entry, FALSE);
685 G_CALLBACK(pounce_dnd_recv), dialog); 691 G_CALLBACK(pounce_dnd_recv), dialog);
686 g_signal_connect(G_OBJECT(dialog->buddy_entry), "drag_data_received", 692 g_signal_connect(G_OBJECT(dialog->buddy_entry), "drag_data_received",
687 G_CALLBACK(pounce_dnd_recv), dialog); 693 G_CALLBACK(pounce_dnd_recv), dialog);
688 694
689 /* Set the values of stuff. */ 695 /* Set the values of stuff. */
690 if (cur_pounce != NULL) { 696 if (cur_pounce != NULL)
697 {
691 GaimPounceEvent events = gaim_pounce_get_events(cur_pounce); 698 GaimPounceEvent events = gaim_pounce_get_events(cur_pounce);
692 const char *value; 699 const char *value;
693 700
694 /* Events */ 701 /* Events */
695 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->signon), 702 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->signon),
724 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->save_pounce), 731 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->save_pounce),
725 gaim_pounce_get_save(cur_pounce)); 732 gaim_pounce_get_save(cur_pounce));
726 733
727 if ((value = gaim_pounce_action_get_attribute(cur_pounce, 734 if ((value = gaim_pounce_action_get_attribute(cur_pounce,
728 "send-message", 735 "send-message",
729 "message")) != NULL) { 736 "message")) != NULL)
730 737 {
731 gtk_entry_set_text(GTK_ENTRY(dialog->send_msg_entry), value); 738 gtk_entry_set_text(GTK_ENTRY(dialog->send_msg_entry), value);
732 } 739 }
733 740
734 if ((value = gaim_pounce_action_get_attribute(cur_pounce, 741 if ((value = gaim_pounce_action_get_attribute(cur_pounce,
735 "execute-command", 742 "execute-command",
736 "command")) != NULL) { 743 "command")) != NULL)
737 744 {
738 gtk_entry_set_text(GTK_ENTRY(dialog->exec_cmd_entry), value); 745 gtk_entry_set_text(GTK_ENTRY(dialog->exec_cmd_entry), value);
739 } 746 }
740 747
741 if ((value = gaim_pounce_action_get_attribute(cur_pounce, 748 if ((value = gaim_pounce_action_get_attribute(cur_pounce,
742 "play-sound", 749 "play-sound",
743 "filename")) != NULL) { 750 "filename")) != NULL)
751 {
744 gtk_entry_set_text(GTK_ENTRY(dialog->play_sound_entry), value); 752 gtk_entry_set_text(GTK_ENTRY(dialog->play_sound_entry), value);
745 } 753 }
746 } 754 }
747 else { 755 else
756 {
757 GaimBuddy *buddy = NULL;
758
759 if (name != NULL)
760 buddy = gaim_find_buddy(account, name);
761
748 /* Set some defaults */ 762 /* Set some defaults */
749 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->send_msg), TRUE); 763 if (buddy == NULL)
750 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->signon), TRUE); 764 {
765 gtk_toggle_button_set_active(
766 GTK_TOGGLE_BUTTON(dialog->signon), TRUE);
767 }
768 else
769 {
770 if (!GAIM_BUDDY_IS_ONLINE(buddy))
771 {
772 gtk_toggle_button_set_active(
773 GTK_TOGGLE_BUTTON(dialog->signon), TRUE);
774 }
775 else
776 {
777 gboolean default_set = FALSE;
778
779 if (buddy->idle)
780 {
781 gtk_toggle_button_set_active(
782 GTK_TOGGLE_BUTTON(dialog->idle_return), TRUE);
783
784 default_set = TRUE;
785 }
786
787 if (buddy->uc & UC_UNAVAILABLE)
788 {
789 gtk_toggle_button_set_active(
790 GTK_TOGGLE_BUTTON(dialog->away_return), TRUE);
791
792 default_set = TRUE;
793 }
794
795 if (!default_set)
796 {
797 gtk_toggle_button_set_active(
798 GTK_TOGGLE_BUTTON(dialog->signon), TRUE);
799 }
800 }
801 }
802
803 gtk_toggle_button_set_active(
804 GTK_TOGGLE_BUTTON(dialog->popup), TRUE);
751 } 805 }
752 806
753 gtk_widget_show_all(vbox2); 807 gtk_widget_show_all(vbox2);
754 gtk_widget_show(window); 808 gtk_widget_show(window);
755 } 809 }
784 GaimPounce *pounce; 838 GaimPounce *pounce;
785 const char *buddy; 839 const char *buddy;
786 gboolean has_items = FALSE; 840 gboolean has_items = FALSE;
787 GList *bp; 841 GList *bp;
788 842
789 for (bp = gaim_pounces_get_all(); bp != NULL; bp = bp->next) { 843 for (bp = gaim_pounces_get_all(); bp != NULL; bp = bp->next)
844 {
790 pounce = (GaimPounce *)bp->data; 845 pounce = (GaimPounce *)bp->data;
791 buddy = gaim_pounce_get_pouncee(pounce); 846 buddy = gaim_pounce_get_pouncee(pounce);
792 847
793 /* Check if account is online, if not skip it */ 848 /* Check if account is online, if not skip it */
794 if (!gaim_account_is_connected(pounce->pouncer)) 849 if (!gaim_account_is_connected(pounce->pouncer))
799 /* Build the menu item */ 854 /* Build the menu item */
800 item = gtk_image_menu_item_new_with_label(buddy); 855 item = gtk_image_menu_item_new_with_label(buddy);
801 856
802 /* Create a pixmap for the protocol icon. */ 857 /* Create a pixmap for the protocol icon. */
803 pixbuf = create_prpl_icon(gaim_pounce_get_pouncer(pounce)); 858 pixbuf = create_prpl_icon(gaim_pounce_get_pouncer(pounce));
804 if(pixbuf) { 859 if (pixbuf != NULL)
860 {
805 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, 861 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
806 GDK_INTERP_BILINEAR); 862 GDK_INTERP_BILINEAR);
807 863
808 /* Now convert it to GtkImage */ 864 /* Now convert it to GtkImage */
809 image = gtk_image_new_from_pixbuf(scale); 865 image = gtk_image_new_from_pixbuf(scale);
810 g_object_unref(G_OBJECT(scale)); 866 g_object_unref(G_OBJECT(scale));
811 g_object_unref(G_OBJECT(pixbuf)); 867 g_object_unref(G_OBJECT(pixbuf));
881 GaimBuddy *buddy; 937 GaimBuddy *buddy;
882 GaimPlugin *proto; 938 GaimPlugin *proto;
883 const char *pouncee; 939 const char *pouncee;
884 const char *alias; 940 const char *alias;
885 const char *proto_id; 941 const char *proto_id;
886 942
887 pouncee = gaim_pounce_get_pouncee(pounce); 943 pouncee = gaim_pounce_get_pouncee(pounce);
888 account = gaim_pounce_get_pouncer(pounce); 944 account = gaim_pounce_get_pouncer(pounce);
889 945
890 buddy = gaim_find_buddy(account, pouncee); 946 buddy = gaim_find_buddy(account, pouncee);
891 947
892 alias = gaim_get_buddy_alias(buddy); 948 alias = gaim_get_buddy_alias(buddy);
893 949
894 /*find the protocol id for the window title and/or message*/ 950 /* Find the protocol id for the window title and/or message */
895 proto = gaim_find_prpl(gaim_account_get_protocol_id(account)); 951 proto = gaim_find_prpl(gaim_account_get_protocol_id(account));
896 proto_id = proto->info->name; 952 proto_id = proto->info->name;
897 953
898 if (gaim_pounce_action_is_enabled(pounce, "open-window")) { 954 if (gaim_pounce_action_is_enabled(pounce, "open-window"))
955 {
899 conv = gaim_find_conversation_with_account(pouncee, account); 956 conv = gaim_find_conversation_with_account(pouncee, account);
900 957
901 if (conv == NULL) 958 if (conv == NULL)
902 conv = gaim_conversation_new(GAIM_CONV_IM, account, pouncee); 959 conv = gaim_conversation_new(GAIM_CONV_IM, account, pouncee);
903 } 960 }
904 961
905 if (gaim_pounce_action_is_enabled(pounce, "popup-notify")) { 962 if (gaim_pounce_action_is_enabled(pounce, "popup-notify"))
963 {
906 char tmp[1024]; 964 char tmp[1024];
907 965 const char *name_shown;
908 /*Here we place the protocol name in the pounce dialog to lessen confusion about what 966
909 protocol a pounce is for*/ 967 /*
968 * Here we place the protocol name in the pounce dialog to lessen
969 * confusion about what protocol a pounce is for.
970 */
910 g_snprintf(tmp, sizeof(tmp), 971 g_snprintf(tmp, sizeof(tmp),
911 (events & GAIM_POUNCE_TYPING) ? _("%s has started typing to you (%s)") : 972 (events & GAIM_POUNCE_TYPING) ?
912 (events & GAIM_POUNCE_SIGNON) ? _("%s has signed on (%s)") : 973 _("%s has started typing to you (%s)") :
913 (events & GAIM_POUNCE_IDLE_RETURN) ? _("%s has returned from being idle (%s)") : 974 (events & GAIM_POUNCE_SIGNON) ?
914 (events & GAIM_POUNCE_AWAY_RETURN) ? _("%s has returned from being away (%s)") : 975 _("%s has signed on (%s)") :
915 (events & GAIM_POUNCE_TYPING_STOPPED) ? _("%s has stopped typing to you %s") : 976 (events & GAIM_POUNCE_IDLE_RETURN) ?
916 (events & GAIM_POUNCE_SIGNOFF) ? _("%s has signed off (%s)") : 977 _("%s has returned from being idle (%s)") :
917 (events & GAIM_POUNCE_IDLE) ? _("%s has become idle (%s)") : 978 (events & GAIM_POUNCE_AWAY_RETURN) ?
918 (events & GAIM_POUNCE_AWAY) ? _("%s has gone away. (%s)") : 979 _("%s has returned from being away (%s)") :
980 (events & GAIM_POUNCE_TYPING_STOPPED) ?
981 _("%s has stopped typing to you (%s)") :
982 (events & GAIM_POUNCE_SIGNOFF) ?
983 _("%s has signed off (%s)") :
984 (events & GAIM_POUNCE_IDLE) ?
985 _("%s has become idle (%s)") :
986 (events & GAIM_POUNCE_AWAY) ?
987 _("%s has gone away. (%s)") :
919 _("Unknown pounce event. Please report this!"), 988 _("Unknown pounce event. Please report this!"),
920 alias,proto_id); 989 alias,proto_id);
921 990
922 /*Ok here is where I change the second argument, title, 991 /*
923 from NULL to the account name if that's all we have 992 * Ok here is where I change the second argument, title, from
924 or the account alias if we have that*/ 993 * NULL to the account name if that's all we have or the account
925 if(gaim_account_get_alias(account)) { 994 * alias if we have that
926 gaim_notify_info(NULL, gaim_account_get_alias(account), tmp, (char*)gaim_date_full()); 995 */
927 } else { 996 if ((name_shown = gaim_account_get_alias(account)) == NULL)
928 gaim_notify_info(NULL, gaim_account_get_username(account), tmp, (char*)gaim_date_full()); 997 name_shown = gaim_account_get_username(account);
929 } 998
930 } 999 gaim_notify_info(NULL, name_shown, tmp, gaim_date_full());
931 1000 }
932 if (gaim_pounce_action_is_enabled(pounce, "send-message")) { 1001
1002 if (gaim_pounce_action_is_enabled(pounce, "send-message"))
1003 {
933 const char *message; 1004 const char *message;
934 1005
935 message = gaim_pounce_action_get_attribute(pounce, "send-message", 1006 message = gaim_pounce_action_get_attribute(pounce, "send-message",
936 "message"); 1007 "message");
937 1008
938 if (message != NULL) { 1009 if (message != NULL)
1010 {
939 conv = gaim_find_conversation_with_account(pouncee, account); 1011 conv = gaim_find_conversation_with_account(pouncee, account);
940 1012
941 if (conv == NULL) 1013 if (conv == NULL)
942 conv = gaim_conversation_new(GAIM_CONV_IM, account, pouncee); 1014 conv = gaim_conversation_new(GAIM_CONV_IM, account, pouncee);
943 1015
946 1018
947 serv_send_im(account->gc, (char *)pouncee, (char *)message, 0); 1019 serv_send_im(account->gc, (char *)pouncee, (char *)message, 0);
948 } 1020 }
949 } 1021 }
950 1022
951 if (gaim_pounce_action_is_enabled(pounce, "execute-command")) { 1023 if (gaim_pounce_action_is_enabled(pounce, "execute-command"))
1024 {
952 const char *command; 1025 const char *command;
953 1026
954 command = gaim_pounce_action_get_attribute(pounce, "execute-command", 1027 command = gaim_pounce_action_get_attribute(pounce, "execute-command",
955 "command"); 1028 "command");
956 1029
957 if (command != NULL) { 1030 if (command != NULL)
1031 {
958 #ifndef _WIN32 1032 #ifndef _WIN32
959 int pid = fork(); 1033 int pid = fork();
960 1034
961 if (pid == 0) { 1035 if (pid == 0) {
962 char *args[4]; 1036 char *args[4];
968 1042
969 execvp(args[0], args); 1043 execvp(args[0], args);
970 1044
971 _exit(0); 1045 _exit(0);
972 } 1046 }
973 #else 1047 #else /* !_WIN32 */
974 STARTUPINFO StartInfo; 1048 STARTUPINFO StartInfo;
975 PROCESS_INFORMATION ProcInfo; 1049 PROCESS_INFORMATION ProcInfo;
976 1050
977 memset(&ProcInfo, 0, sizeof(ProcInfo)); 1051 memset(&ProcInfo, 0, sizeof(ProcInfo));
978 memset(&StartInfo, 0 , sizeof(StartInfo)); 1052 memset(&StartInfo, 0 , sizeof(StartInfo));
979 StartInfo.cb = sizeof(StartInfo); 1053 StartInfo.cb = sizeof(StartInfo);
980 CreateProcess(NULL, (char *)command, NULL, NULL, 0, 0, NULL, NULL, &StartInfo, &ProcInfo); 1054 CreateProcess(NULL, (char *)command, NULL, NULL, 0, 0, NULL,
1055 NULL, &StartInfo, &ProcInfo);
981 gaim_debug_info("pounce", 1056 gaim_debug_info("pounce",
982 "Pounce execute command called for: %s\n", 1057 "Pounce execute command called for: %s\n",
983 command); 1058 command);
984 #endif 1059 #endif /* !_WIN32 */
985 } 1060 }
986 } 1061 }
987 1062
988 if (gaim_pounce_action_is_enabled(pounce, "play-sound")) { 1063 if (gaim_pounce_action_is_enabled(pounce, "play-sound"))
1064 {
989 const char *sound; 1065 const char *sound;
990 1066
991 sound = gaim_pounce_action_get_attribute(pounce, "play-sound", 1067 sound = gaim_pounce_action_get_attribute(pounce,
992 "filename"); 1068 "play-sound", "filename");
993 1069
994 if (sound != NULL) 1070 if (sound != NULL)
995 gaim_sound_play_file(sound); 1071 gaim_sound_play_file(sound);
996 else 1072 else
997 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); 1073 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT);