Mercurial > pidgin.yaz
comparison src/gtkpounce.c @ 5857:2fa4aa9c1885
[gaim-migrate @ 6288]
Renamed the pounce structures and typedefs to be in sync with the rest of
the API. Also added some g_return_*_if_fail() checks in place of the if
statements we had. I'll try to get pounces working again.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Fri, 13 Jun 2003 23:04:26 +0000 |
parents | dae79aefac8d |
children | 417b1001d2b1 |
comparison
equal
deleted
inserted
replaced
5856:a479e218c54b | 5857:2fa4aa9c1885 |
---|---|
27 #include "gtkblist.h" | 27 #include "gtkblist.h" |
28 #include "prpl.h" | 28 #include "prpl.h" |
29 #include "sound.h" | 29 #include "sound.h" |
30 #include "notify.h" | 30 #include "notify.h" |
31 | 31 |
32 struct gaim_gtkpounce_dialog | 32 typedef struct |
33 { | 33 { |
34 /* Pounce data */ | 34 /* Pounce data */ |
35 struct gaim_pounce *pounce; | 35 GaimPounce *pounce; |
36 GaimAccount *account; | 36 GaimAccount *account; |
37 | 37 |
38 /* The window */ | 38 /* The window */ |
39 GtkWidget *window; | 39 GtkWidget *window; |
40 | 40 |
64 GtkWidget *play_sound_entry; | 64 GtkWidget *play_sound_entry; |
65 GtkWidget *play_sound_browse; | 65 GtkWidget *play_sound_browse; |
66 GtkWidget *play_sound_test; | 66 GtkWidget *play_sound_test; |
67 | 67 |
68 GtkWidget *save_pounce; | 68 GtkWidget *save_pounce; |
69 }; | 69 |
70 } GaimGtkPounceDialog; | |
70 | 71 |
71 /************************************************************************** | 72 /************************************************************************** |
72 * Callbacks | 73 * Callbacks |
73 **************************************************************************/ | 74 **************************************************************************/ |
74 static gint | 75 static gint |
75 delete_win_cb(GtkWidget *w, GdkEventAny *e, | 76 delete_win_cb(GtkWidget *w, GdkEventAny *e, GaimGtkPounceDialog *dialog) |
76 struct gaim_gtkpounce_dialog *dialog) | |
77 { | 77 { |
78 gtk_widget_destroy(dialog->window); | 78 gtk_widget_destroy(dialog->window); |
79 g_free(dialog); | 79 g_free(dialog); |
80 | 80 |
81 return TRUE; | 81 return TRUE; |
82 } | 82 } |
83 | 83 |
84 static void | 84 static void |
85 delete_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog) | 85 delete_cb(GtkWidget *w, GaimGtkPounceDialog *dialog) |
86 { | 86 { |
87 gaim_pounce_destroy(dialog->pounce); | 87 gaim_pounce_destroy(dialog->pounce); |
88 | 88 |
89 delete_win_cb(NULL, NULL, dialog); | 89 delete_win_cb(NULL, NULL, dialog); |
90 } | 90 } |
91 | 91 |
92 static void | 92 static void |
93 cancel_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog) | 93 cancel_cb(GtkWidget *w, GaimGtkPounceDialog *dialog) |
94 { | 94 { |
95 delete_win_cb(NULL, NULL, dialog); | 95 delete_win_cb(NULL, NULL, dialog); |
96 } | 96 } |
97 | 97 |
98 static void | 98 static void |
99 pounce_update_entryfields(GtkWidget *w, gpointer data) | 99 pounce_update_entryfields(GtkWidget *w, gpointer data) |
100 { | 100 { |
101 const char *selected_filename; | 101 const char *filename; |
102 GHashTable *args; | 102 GHashTable *args; |
103 | 103 |
104 args = (GHashTable *) data; | 104 args = (GHashTable *)data; |
105 | 105 |
106 selected_filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(g_hash_table_lookup(args, "pounce_file_selector"))); | 106 filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION( |
107 if (selected_filename != NULL) | 107 g_hash_table_lookup(args, "filesel"))); |
108 gtk_entry_set_text(GTK_ENTRY(g_hash_table_lookup(args, "entry")),selected_filename); | 108 |
109 if (filename != NULL) | |
110 gtk_entry_set_text(GTK_ENTRY(g_hash_table_lookup(args, "entry")), | |
111 filename); | |
109 | 112 |
110 g_free(args); | 113 g_free(args); |
111 } | 114 } |
112 | 115 |
113 static void | 116 static void |
114 pounce_file_selector(GtkWidget *w, gpointer data) | 117 filesel(GtkWidget *w, gpointer data) |
115 { | 118 { |
116 GtkWidget *pounce_file_selector; | 119 GtkWidget *filesel; |
117 GtkWidget *entry; | 120 GtkWidget *entry; |
118 GHashTable *args; | 121 GHashTable *args; |
119 | 122 |
120 entry = (GtkWidget *) data; | 123 entry = (GtkWidget *)data; |
121 | 124 |
122 pounce_file_selector = gtk_file_selection_new(_("Select a file")); | 125 filesel = gtk_file_selection_new(_("Select a file")); |
123 gtk_file_selection_set_filename(GTK_FILE_SELECTION(pounce_file_selector), gtk_entry_get_text(GTK_ENTRY(entry))); | 126 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), |
124 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(pounce_file_selector)); | 127 gtk_entry_get_text(GTK_ENTRY(entry))); |
125 gtk_file_selection_set_select_multiple(GTK_FILE_SELECTION(pounce_file_selector), FALSE); | 128 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(filesel)); |
129 gtk_file_selection_set_select_multiple(GTK_FILE_SELECTION(filesel), FALSE); | |
126 | 130 |
127 args = g_hash_table_new(g_str_hash,g_str_equal); | 131 args = g_hash_table_new(g_str_hash,g_str_equal); |
128 g_hash_table_insert(args, "pounce_file_selector", (gpointer) pounce_file_selector); | 132 g_hash_table_insert(args, "filesel", filesel); |
129 g_hash_table_insert(args, "entry", (gpointer) entry); | 133 g_hash_table_insert(args, "entry", entry); |
130 | 134 |
131 g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(pounce_file_selector)->ok_button), | 135 g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), |
132 "clicked", G_CALLBACK(pounce_update_entryfields), (gpointer) args); | 136 "clicked", |
133 | 137 G_CALLBACK(pounce_update_entryfields), args); |
134 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(pounce_file_selector)->ok_button), | 138 |
135 "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer) pounce_file_selector); | 139 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), |
136 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(pounce_file_selector)->cancel_button), | 140 "clicked", |
137 "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer) pounce_file_selector); | 141 G_CALLBACK(gtk_widget_destroy), filesel); |
138 | 142 |
139 gtk_widget_show(pounce_file_selector); | 143 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), |
140 } | 144 "clicked", |
141 | 145 G_CALLBACK(gtk_widget_destroy), filesel); |
142 static void | 146 |
143 pounce_test_sound(GtkWidget *w, gpointer data) | 147 gtk_widget_show(filesel); |
148 } | |
149 | |
150 static void | |
151 pounce_test_sound(GtkWidget *w, GtkWidget *entry) | |
144 { | 152 { |
145 const char *filename; | 153 const char *filename; |
146 GtkWidget *entry; | 154 |
147 | |
148 entry = (GtkWidget *) data; | |
149 | |
150 filename = gtk_entry_get_text(GTK_ENTRY(entry)); | 155 filename = gtk_entry_get_text(GTK_ENTRY(entry)); |
151 if ((filename != NULL) && (strlen(filename) > 0)) | 156 |
157 if (filename != NULL && *filename != '\0') | |
152 gaim_sound_play_file((char *) filename); | 158 gaim_sound_play_file((char *) filename); |
153 else | 159 else |
154 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); | 160 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); |
155 } | 161 } |
156 | 162 |
157 static void | 163 static void |
158 save_pounce_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog) | 164 save_pounce_cb(GtkWidget *w, GaimGtkPounceDialog *dialog) |
159 { | 165 { |
160 const char *name; | 166 const char *name; |
161 const char *message, *command, *sound; | 167 const char *message, *command, *sound; |
162 struct gaim_buddy_list *blist; | 168 struct gaim_buddy_list *blist; |
163 struct gaim_gtk_buddy_list *gtkblist; | 169 struct gaim_gtk_buddy_list *gtkblist; |
231 gaim_gtkpounce_new(dialog->account, name, events, actions, | 237 gaim_gtkpounce_new(dialog->account, name, events, actions, |
232 message, command, sound, save); | 238 message, command, sound, save); |
233 } | 239 } |
234 else | 240 else |
235 { | 241 { |
236 struct gaim_gtkpounce_data *pounce_data; | 242 GaimGtkPounceData *pounce_data; |
237 | 243 |
238 gaim_pounce_set_events(dialog->pounce, events); | 244 gaim_pounce_set_events(dialog->pounce, events); |
239 gaim_pounce_set_pouncer(dialog->pounce, dialog->account); | 245 gaim_pounce_set_pouncer(dialog->pounce, dialog->account); |
240 gaim_pounce_set_pouncee(dialog->pounce, name); | 246 gaim_pounce_set_pouncee(dialog->pounce, name); |
241 | 247 |
264 gaim_gtkpounce_menu_build(gtkblist->bpmenu); | 270 gaim_gtkpounce_menu_build(gtkblist->bpmenu); |
265 } | 271 } |
266 } | 272 } |
267 | 273 |
268 static void | 274 static void |
269 pounce_choose_cb(GtkWidget *item, struct gaim_gtkpounce_dialog *dialog) | 275 pounce_choose_cb(GtkWidget *item, GaimGtkPounceDialog *dialog) |
270 { | 276 { |
271 dialog->account = g_object_get_data(G_OBJECT(item), "user_data"); | 277 dialog->account = g_object_get_data(G_OBJECT(item), "user_data"); |
272 } | 278 } |
273 | 279 |
274 static GtkWidget * | 280 static GtkWidget * |
275 pounce_user_menu(struct gaim_gtkpounce_dialog *dialog) | 281 pounce_user_menu(GaimGtkPounceDialog *dialog) |
276 { | 282 { |
277 GaimAccount *account; | 283 GaimAccount *account; |
278 GaimPlugin *prpl; | 284 GaimPlugin *prpl; |
279 GtkWidget *opt_menu; | 285 GtkWidget *opt_menu; |
280 GtkWidget *menu; | 286 GtkWidget *menu; |
318 | 324 |
319 return opt_menu; | 325 return opt_menu; |
320 } | 326 } |
321 | 327 |
322 static void | 328 static void |
323 pounce_cb(struct gaim_pounce *pounce, GaimPounceEvent events, void *data) | 329 pounce_cb(GaimPounce *pounce, GaimPounceEvent events, void *data) |
324 { | 330 { |
325 GaimConversation *conv; | 331 GaimConversation *conv; |
326 GaimAccount *account; | 332 GaimAccount *account; |
327 struct gaim_gtkpounce_data *pounce_data; | 333 GaimGtkPounceData *pounce_data; |
328 const char *pouncee; | 334 const char *pouncee; |
329 | 335 |
330 pounce_data = (struct gaim_gtkpounce_data *)data; | 336 pounce_data = (GaimGtkPounceData *)data; |
331 pouncee = gaim_pounce_get_pouncee(pounce); | 337 pouncee = gaim_pounce_get_pouncee(pounce); |
332 account = gaim_pounce_get_pouncer(pounce); | 338 account = gaim_pounce_get_pouncer(pounce); |
333 | 339 |
334 if (pounce_data->actions & GAIM_GTKPOUNCE_OPEN_WIN) { | 340 if (pounce_data->actions & GAIM_GTKPOUNCE_OPEN_WIN) { |
335 conv = gaim_find_conversation(pouncee); | 341 conv = gaim_find_conversation(pouncee); |
402 } | 408 } |
403 | 409 |
404 static void | 410 static void |
405 free_pounce(void *data) | 411 free_pounce(void *data) |
406 { | 412 { |
407 struct gaim_gtkpounce_data *pounce_data; | 413 GaimGtkPounceData *pounce_data; |
408 struct gaim_buddy_list *blist; | 414 struct gaim_buddy_list *blist; |
409 struct gaim_gtk_buddy_list *gtkblist; | 415 struct gaim_gtk_buddy_list *gtkblist; |
410 | 416 |
411 pounce_data = (struct gaim_gtkpounce_data *)data; | 417 pounce_data = (GaimGtkPounceData *)data; |
412 | 418 |
413 if (pounce_data->message != NULL) g_free(pounce_data->message); | 419 if (pounce_data->message != NULL) g_free(pounce_data->message); |
414 if (pounce_data->command != NULL) g_free(pounce_data->command); | 420 if (pounce_data->command != NULL) g_free(pounce_data->command); |
415 if (pounce_data->sound != NULL) g_free(pounce_data->sound); | 421 if (pounce_data->sound != NULL) g_free(pounce_data->sound); |
416 | 422 |
425 | 431 |
426 gaim_gtkpounce_menu_build(gtkblist->bpmenu); | 432 gaim_gtkpounce_menu_build(gtkblist->bpmenu); |
427 } | 433 } |
428 } | 434 } |
429 | 435 |
430 struct gaim_pounce * | 436 GaimPounce * |
431 gaim_gtkpounce_new(GaimAccount *pouncer, const char *pouncee, | 437 gaim_gtkpounce_new(GaimAccount *pouncer, const char *pouncee, |
432 GaimPounceEvent events, GaimGtkPounceAction actions, | 438 GaimPounceEvent events, GaimGtkPounceAction actions, |
433 const char *message, const char *command, | 439 const char *message, const char *command, |
434 const char *sound, gboolean save) | 440 const char *sound, gboolean save) |
435 { | 441 { |
436 struct gaim_gtkpounce_data *data; | 442 GaimGtkPounceData *data; |
437 | 443 |
438 data = g_new0(struct gaim_gtkpounce_data, 1); | 444 data = g_new0(GaimGtkPounceData, 1); |
439 | 445 |
440 data->actions = actions; | 446 data->actions = actions; |
441 | 447 |
442 if (message != NULL) data->message = g_strdup(message); | 448 if (message != NULL) data->message = g_strdup(message); |
443 if (command != NULL) data->command = g_strdup(command); | 449 if (command != NULL) data->command = g_strdup(command); |
449 free_pounce); | 455 free_pounce); |
450 } | 456 } |
451 | 457 |
452 void | 458 void |
453 gaim_gtkpounce_dialog_show(struct buddy *buddy, | 459 gaim_gtkpounce_dialog_show(struct buddy *buddy, |
454 struct gaim_pounce *cur_pounce) | 460 GaimPounce *cur_pounce) |
455 { | 461 { |
456 struct gaim_gtkpounce_dialog *dialog; | 462 GaimGtkPounceDialog *dialog; |
457 GtkWidget *window; | 463 GtkWidget *window; |
458 GtkWidget *label; | 464 GtkWidget *label; |
459 GtkWidget *bbox; | 465 GtkWidget *bbox; |
460 GtkWidget *vbox1, *vbox2; | 466 GtkWidget *vbox1, *vbox2; |
461 GtkWidget *hbox; | 467 GtkWidget *hbox; |
464 GtkWidget *table; | 470 GtkWidget *table; |
465 GtkWidget *sep; | 471 GtkWidget *sep; |
466 GtkSizeGroup *sg; | 472 GtkSizeGroup *sg; |
467 GPtrArray *sound_widgets; | 473 GPtrArray *sound_widgets; |
468 GPtrArray *exec_widgets; | 474 GPtrArray *exec_widgets; |
469 | 475 |
470 dialog = g_new0(struct gaim_gtkpounce_dialog, 1); | 476 dialog = g_new0(GaimGtkPounceDialog, 1); |
471 | 477 |
472 if (cur_pounce != NULL) { | 478 if (cur_pounce != NULL) { |
473 dialog->pounce = cur_pounce; | 479 dialog->pounce = cur_pounce; |
474 dialog->account = gaim_pounce_get_pouncer(cur_pounce); | 480 dialog->account = gaim_pounce_get_pouncer(cur_pounce); |
475 } | 481 } |
673 | 679 |
674 g_signal_connect(G_OBJECT(dialog->exec_cmd), "clicked", | 680 g_signal_connect(G_OBJECT(dialog->exec_cmd), "clicked", |
675 G_CALLBACK(gtk_toggle_sensitive_array), | 681 G_CALLBACK(gtk_toggle_sensitive_array), |
676 exec_widgets); | 682 exec_widgets); |
677 g_signal_connect(G_OBJECT(dialog->exec_cmd_browse), "clicked", | 683 g_signal_connect(G_OBJECT(dialog->exec_cmd_browse), "clicked", |
678 G_CALLBACK(pounce_file_selector), | 684 G_CALLBACK(filesel), |
679 dialog->exec_cmd_entry); | 685 dialog->exec_cmd_entry); |
680 | 686 |
681 sound_widgets = g_ptr_array_new(); | 687 sound_widgets = g_ptr_array_new(); |
682 g_ptr_array_add(sound_widgets,dialog->play_sound_entry); | 688 g_ptr_array_add(sound_widgets,dialog->play_sound_entry); |
683 g_ptr_array_add(sound_widgets,dialog->play_sound_browse); | 689 g_ptr_array_add(sound_widgets,dialog->play_sound_browse); |
685 | 691 |
686 g_signal_connect(G_OBJECT(dialog->play_sound), "clicked", | 692 g_signal_connect(G_OBJECT(dialog->play_sound), "clicked", |
687 G_CALLBACK(gtk_toggle_sensitive_array), | 693 G_CALLBACK(gtk_toggle_sensitive_array), |
688 sound_widgets); | 694 sound_widgets); |
689 g_signal_connect(G_OBJECT(dialog->play_sound_browse), "clicked", | 695 g_signal_connect(G_OBJECT(dialog->play_sound_browse), "clicked", |
690 G_CALLBACK(pounce_file_selector), | 696 G_CALLBACK(filesel), |
691 dialog->play_sound_entry); | 697 dialog->play_sound_entry); |
692 g_signal_connect(G_OBJECT(dialog->play_sound_test), "clicked", | 698 g_signal_connect(G_OBJECT(dialog->play_sound_test), "clicked", |
693 G_CALLBACK(pounce_test_sound), | 699 G_CALLBACK(pounce_test_sound), |
694 dialog->play_sound_entry); | 700 dialog->play_sound_entry); |
695 | 701 |
744 | 750 |
745 /* Set the values of stuff. */ | 751 /* Set the values of stuff. */ |
746 if (cur_pounce != NULL) { | 752 if (cur_pounce != NULL) { |
747 GaimPounceEvent events; | 753 GaimPounceEvent events; |
748 GaimGtkPounceAction actions; | 754 GaimGtkPounceAction actions; |
749 struct gaim_gtkpounce_data *pounce_data; | 755 GaimGtkPounceData *pounce_data; |
750 | 756 |
751 pounce_data = GAIM_GTKPOUNCE(cur_pounce); | 757 pounce_data = GAIM_GTKPOUNCE(cur_pounce); |
752 events = gaim_pounce_get_events(cur_pounce); | 758 events = gaim_pounce_get_events(cur_pounce); |
753 actions = pounce_data->actions; | 759 actions = pounce_data->actions; |
754 | 760 |
808 { | 814 { |
809 gaim_gtkpounce_dialog_show(b, NULL); | 815 gaim_gtkpounce_dialog_show(b, NULL); |
810 } | 816 } |
811 | 817 |
812 static void | 818 static void |
813 delete_pounce_cb(GtkWidget *w, struct gaim_pounce *pounce) | 819 delete_pounce_cb(GtkWidget *w, GaimPounce *pounce) |
814 { | 820 { |
815 gaim_pounce_destroy(pounce); | 821 gaim_pounce_destroy(pounce); |
816 } | 822 } |
817 | 823 |
818 static void | 824 static void |
819 edit_pounce_cb(GtkWidget *w, struct gaim_pounce *pounce) | 825 edit_pounce_cb(GtkWidget *w, GaimPounce *pounce) |
820 { | 826 { |
821 struct buddy *buddy; | 827 struct buddy *buddy; |
822 | 828 |
823 buddy = gaim_find_buddy(gaim_pounce_get_pouncer(pounce), | 829 buddy = gaim_find_buddy(gaim_pounce_get_pouncer(pounce), |
824 gaim_pounce_get_pouncee(pounce)); | 830 gaim_pounce_get_pouncee(pounce)); |
830 fill_menu(GtkWidget *menu, GCallback cb) | 836 fill_menu(GtkWidget *menu, GCallback cb) |
831 { | 837 { |
832 GtkWidget *image; | 838 GtkWidget *image; |
833 GtkWidget *item; | 839 GtkWidget *item; |
834 GdkPixbuf *pixbuf, *scale; | 840 GdkPixbuf *pixbuf, *scale; |
835 struct gaim_pounce *pounce; | 841 GaimPounce *pounce; |
836 const char *buddy; | 842 const char *buddy; |
837 GList *bp; | 843 GList *bp; |
838 | 844 |
839 for (bp = gaim_get_pounces(); bp != NULL; bp = bp->next) { | 845 for (bp = gaim_get_pounces(); bp != NULL; bp = bp->next) { |
840 pounce = (struct gaim_pounce *)bp->data; | 846 pounce = (GaimPounce *)bp->data; |
841 buddy = gaim_pounce_get_pouncee(pounce); | 847 buddy = gaim_pounce_get_pouncee(pounce); |
842 | 848 |
843 /* Build the menu item */ | 849 /* Build the menu item */ |
844 item = gtk_image_menu_item_new_with_label(buddy); | 850 item = gtk_image_menu_item_new_with_label(buddy); |
845 | 851 |