Mercurial > pidgin.yaz
comparison src/gtkft.c @ 7805:5f0bb52c0609
[gaim-migrate @ 8452]
File transfer changes from marv.
This fixes various ft related bugs, including:
* Sometimes clicking cancel on a send would crash.
* We seemed to leak the GaimXfer most of the time.
* Choosing to not overwrite the file would cancel the
receive altogether.
This should fix all these issues. It would be nice if
someone (SimGuy?) could test this for me, especially on
windows, to make sure i didn't break anything. Jabber
ft is untested, althoughi didn't make any changes in
the jabber source. So, it should still work, i just
can't comfirm it. Yahoo and OSCAR do still work.
Amoung other things, this patch impliments some
reference counting on the GaimXfer, so the ui can keep
it around a while if it wants, without leaking it
because we're afraid to destroy it.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 08 Dec 2003 04:58:07 +0000 |
parents | b14442b31a9b |
children | 8e60ddc28a22 |
comparison
equal
deleted
inserted
replaced
7804:622c9149609c | 7805:5f0bb52c0609 |
---|---|
78 typedef struct | 78 typedef struct |
79 { | 79 { |
80 GtkWidget *filesel; | 80 GtkWidget *filesel; |
81 GtkTreeIter iter; | 81 GtkTreeIter iter; |
82 time_t start_time; | 82 time_t start_time; |
83 gboolean in_list; | |
83 | 84 |
84 char *name; | 85 char *name; |
85 | 86 |
86 } GaimGtkXferUiData; | 87 } GaimGtkXferUiData; |
87 | 88 |
95 COLUMN_SIZE, | 96 COLUMN_SIZE, |
96 COLUMN_REMAINING, | 97 COLUMN_REMAINING, |
97 COLUMN_DATA, | 98 COLUMN_DATA, |
98 NUM_COLUMNS | 99 NUM_COLUMNS |
99 }; | 100 }; |
101 | |
102 | |
103 /************************************************************************** | |
104 * Prototype(s) | |
105 **************************************************************************/ | |
106 static int choose_file(GaimXfer *xfer); | |
100 | 107 |
101 /************************************************************************** | 108 /************************************************************************** |
102 * Utility Functions | 109 * Utility Functions |
103 **************************************************************************/ | 110 **************************************************************************/ |
104 static void | 111 static void |
764 char *lfilename; | 771 char *lfilename; |
765 | 772 |
766 g_return_if_fail(dialog != NULL); | 773 g_return_if_fail(dialog != NULL); |
767 g_return_if_fail(xfer != NULL); | 774 g_return_if_fail(xfer != NULL); |
768 | 775 |
776 gaim_xfer_ref(xfer); | |
777 | |
769 data = GAIM_GTKXFER(xfer); | 778 data = GAIM_GTKXFER(xfer); |
779 data->in_list = TRUE; | |
770 | 780 |
771 gaim_gtkxfer_dialog_show(dialog); | 781 gaim_gtkxfer_dialog_show(dialog); |
772 | 782 |
773 data->start_time = time(NULL); | 783 data->start_time = time(NULL); |
774 | 784 |
821 data = GAIM_GTKXFER(xfer); | 831 data = GAIM_GTKXFER(xfer); |
822 | 832 |
823 if (data == NULL) | 833 if (data == NULL) |
824 return; | 834 return; |
825 | 835 |
836 if (!data->in_list) | |
837 return; | |
838 | |
839 data->in_list = FALSE; | |
840 | |
826 gtk_list_store_remove(GTK_LIST_STORE(dialog->model), &data->iter); | 841 gtk_list_store_remove(GTK_LIST_STORE(dialog->model), &data->iter); |
827 | |
828 g_free(data->name); | |
829 g_free(data); | |
830 | |
831 xfer->ui_data = NULL; | |
832 | 842 |
833 dialog->num_transfers--; | 843 dialog->num_transfers--; |
834 | 844 |
835 if (dialog->num_transfers == 0 && !dialog->keep_open) | 845 if (dialog->num_transfers == 0 && !dialog->keep_open) |
836 gaim_gtkxfer_dialog_hide(dialog); | 846 gaim_gtkxfer_dialog_hide(dialog); |
837 else | 847 else |
838 ensure_row_selected(dialog); | 848 ensure_row_selected(dialog); |
849 | |
850 gaim_xfer_unref(xfer); | |
839 } | 851 } |
840 | 852 |
841 void | 853 void |
842 gaim_gtkxfer_dialog_cancel_xfer(GaimGtkXferDialog *dialog, | 854 gaim_gtkxfer_dialog_cancel_xfer(GaimGtkXferDialog *dialog, |
843 GaimXfer *xfer) | 855 GaimXfer *xfer) |
844 { | 856 { |
845 GaimGtkXferUiData *data; | 857 GaimGtkXferUiData *data; |
846 GdkPixbuf *pixbuf; | 858 GdkPixbuf *pixbuf; |
847 gchar *status; | 859 gchar *status; |
848 | 860 |
849 | |
850 g_return_if_fail(dialog != NULL); | 861 g_return_if_fail(dialog != NULL); |
851 g_return_if_fail(xfer != NULL); | 862 g_return_if_fail(xfer != NULL); |
852 | 863 |
853 data = GAIM_GTKXFER(xfer); | 864 data = GAIM_GTKXFER(xfer); |
854 | 865 |
855 if (data == NULL) | 866 if (data == NULL) |
856 return; | 867 return; |
857 | 868 |
858 | 869 |
859 if ((gaim_xfer_is_canceled(xfer) == GAIM_XFER_CANCEL_LOCAL) && (dialog->auto_clear)) { | 870 if ((gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) && (dialog->auto_clear)) { |
860 gtk_list_store_remove(GTK_LIST_STORE(dialog->model), &data->iter); | 871 gaim_gtkxfer_dialog_remove_xfer(dialog, xfer); |
861 | |
862 g_free(data->name); | |
863 g_free(data); | |
864 | |
865 xfer->ui_data = NULL; | |
866 | |
867 dialog->num_transfers--; | |
868 | |
869 if (dialog->num_transfers == 0 && !dialog->keep_open) | |
870 gaim_gtkxfer_dialog_hide(dialog); | |
871 | |
872 return; | 872 return; |
873 } | 873 } |
874 | 874 |
875 data = GAIM_GTKXFER(xfer); | 875 data = GAIM_GTKXFER(xfer); |
876 | 876 |
877 pixbuf = gtk_widget_render_icon(dialog->window, | 877 pixbuf = gtk_widget_render_icon(dialog->window, |
878 GAIM_STOCK_FILE_CANCELED, | 878 GAIM_STOCK_FILE_CANCELED, |
879 GTK_ICON_SIZE_MENU, NULL); | 879 GTK_ICON_SIZE_MENU, NULL); |
880 | 880 |
881 if (gaim_xfer_is_canceled(xfer) == GAIM_XFER_CANCEL_LOCAL) | 881 if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) |
882 status = _("Canceled"); | 882 status = _("Canceled"); |
883 else | 883 else |
884 status = _("Failed"); | 884 status = _("Failed"); |
885 | 885 |
886 gtk_list_store_set(dialog->model, &data->iter, | 886 gtk_list_store_set(dialog->model, &data->iter, |
903 | 903 |
904 g_return_if_fail(dialog != NULL); | 904 g_return_if_fail(dialog != NULL); |
905 g_return_if_fail(xfer != NULL); | 905 g_return_if_fail(xfer != NULL); |
906 | 906 |
907 if ((data = GAIM_GTKXFER(xfer)) == NULL) | 907 if ((data = GAIM_GTKXFER(xfer)) == NULL) |
908 return; | |
909 | |
910 if (data->in_list == FALSE) | |
908 return; | 911 return; |
909 | 912 |
910 size_str = gaim_str_size_to_units(gaim_xfer_get_size(xfer)); | 913 size_str = gaim_str_size_to_units(gaim_xfer_get_size(xfer)); |
911 remaining_str = gaim_str_size_to_units(gaim_xfer_get_bytes_remaining(xfer)); | 914 remaining_str = gaim_str_size_to_units(gaim_xfer_get_bytes_remaining(xfer)); |
912 | 915 |
956 } | 959 } |
957 | 960 |
958 static void | 961 static void |
959 gaim_gtkxfer_destroy(GaimXfer *xfer) | 962 gaim_gtkxfer_destroy(GaimXfer *xfer) |
960 { | 963 { |
961 gaim_gtkxfer_dialog_remove_xfer(xfer_dialog, xfer); | 964 GaimGtkXferUiData *data; |
965 | |
966 data = GAIM_GTKXFER(xfer); | |
967 if (data) { | |
968 if (data->name) | |
969 g_free(data->name); | |
970 g_free(data); | |
971 xfer->ui_data = NULL; | |
972 } | |
962 } | 973 } |
963 | 974 |
964 static gboolean | 975 static gboolean |
965 choose_file_close_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | 976 choose_file_close_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) |
966 { | 977 { |
967 gaim_xfer_request_denied((GaimXfer *)user_data); | 978 GaimXfer *xfer = (GaimXfer *)user_data; |
979 GaimGtkXferUiData *data; | |
980 | |
981 data = GAIM_GTKXFER(xfer); | |
982 data->filesel = NULL; | |
983 gaim_xfer_request_denied(xfer); | |
968 | 984 |
969 return FALSE; | 985 return FALSE; |
970 } | 986 } |
971 | 987 |
972 static void | 988 static void |
974 { | 990 { |
975 GaimXfer *xfer = (GaimXfer *)user_data; | 991 GaimXfer *xfer = (GaimXfer *)user_data; |
976 GaimGtkXferUiData *data; | 992 GaimGtkXferUiData *data; |
977 | 993 |
978 data = GAIM_GTKXFER(xfer); | 994 data = GAIM_GTKXFER(xfer); |
979 | |
980 gaim_xfer_request_denied(xfer); | |
981 | |
982 gtk_widget_destroy(data->filesel); | 995 gtk_widget_destroy(data->filesel); |
983 data->filesel = NULL; | 996 data->filesel = NULL; |
997 gaim_xfer_request_denied(xfer); | |
984 } | 998 } |
985 | 999 |
986 static int | 1000 static int |
987 do_overwrite_cb(GaimXfer *xfer) | 1001 do_overwrite_cb(GaimXfer *xfer) |
988 { | 1002 { |
990 | 1004 |
991 data = GAIM_GTKXFER(xfer); | 1005 data = GAIM_GTKXFER(xfer); |
992 | 1006 |
993 gaim_xfer_request_accepted(xfer, data->name); | 1007 gaim_xfer_request_accepted(xfer, data->name); |
994 | 1008 |
995 /* | 1009 g_free(data->name); |
996 * No, we don't want to free data->name. gaim_xfer_request_accepted | |
997 * will deal with it. | |
998 */ | |
999 data->name = NULL; | 1010 data->name = NULL; |
1000 | 1011 |
1001 return 0; | 1012 return 0; |
1002 } | 1013 } |
1003 | 1014 |
1009 data = GAIM_GTKXFER(xfer); | 1020 data = GAIM_GTKXFER(xfer); |
1010 | 1021 |
1011 g_free(data->name); | 1022 g_free(data->name); |
1012 data->name = NULL; | 1023 data->name = NULL; |
1013 | 1024 |
1014 gaim_xfer_request_denied(xfer); | 1025 choose_file(xfer); |
1015 | 1026 |
1016 return 0; | 1027 return 0; |
1017 } | 1028 } |
1018 | 1029 |
1019 static void | 1030 static void |
1066 1, xfer, | 1077 1, xfer, |
1067 G_CALLBACK(do_overwrite_cb), | 1078 G_CALLBACK(do_overwrite_cb), |
1068 G_CALLBACK(dont_overwrite_cb)); | 1079 G_CALLBACK(dont_overwrite_cb)); |
1069 } | 1080 } |
1070 else { | 1081 else { |
1071 gaim_xfer_request_accepted(xfer, g_strdup(name)); | 1082 gaim_xfer_request_accepted(xfer, name); |
1072 } | 1083 } |
1073 } | 1084 } |
1074 | 1085 |
1075 gtk_widget_destroy(data->filesel); | 1086 gtk_widget_destroy(data->filesel); |
1076 data->filesel = NULL; | 1087 data->filesel = NULL; |
1172 | 1183 |
1173 static void | 1184 static void |
1174 gaim_gtkxfer_update_progress(GaimXfer *xfer, double percent) | 1185 gaim_gtkxfer_update_progress(GaimXfer *xfer, double percent) |
1175 { | 1186 { |
1176 gaim_gtkxfer_dialog_update_xfer(xfer_dialog, xfer); | 1187 gaim_gtkxfer_dialog_update_xfer(xfer_dialog, xfer); |
1177 | |
1178 /* See if it's removed. */ | |
1179 /* XXX - This caused some bad stuff, and I don't see a point to it */ | |
1180 #if 0 | |
1181 if (xfer->ui_data == NULL) | |
1182 gaim_xfer_destroy(xfer); | |
1183 #endif | |
1184 } | 1188 } |
1185 | 1189 |
1186 static void | 1190 static void |
1187 gaim_gtkxfer_cancel_local(GaimXfer *xfer) | 1191 gaim_gtkxfer_cancel_local(GaimXfer *xfer) |
1188 { | 1192 { |
1189 gaim_gtkxfer_dialog_cancel_xfer(xfer_dialog, xfer); | 1193 if (xfer_dialog) |
1194 gaim_gtkxfer_dialog_cancel_xfer(xfer_dialog, xfer); | |
1190 } | 1195 } |
1191 | 1196 |
1192 static void | 1197 static void |
1193 gaim_gtkxfer_cancel_remote(GaimXfer *xfer) | 1198 gaim_gtkxfer_cancel_remote(GaimXfer *xfer) |
1194 { | 1199 { |
1195 gaim_gtkxfer_dialog_cancel_xfer(xfer_dialog, xfer); | 1200 if (xfer_dialog) |
1201 gaim_gtkxfer_dialog_cancel_xfer(xfer_dialog, xfer); | |
1196 } | 1202 } |
1197 | 1203 |
1198 static GaimXferUiOps ops = | 1204 static GaimXferUiOps ops = |
1199 { | 1205 { |
1200 gaim_gtkxfer_new_xfer, | 1206 gaim_gtkxfer_new_xfer, |