Mercurial > pidgin
comparison src/gtkft.c @ 9511:3ed6001d5de8
[gaim-migrate @ 10338]
Move the file transfer file selector stuff from gtkft.c to ft.c
Having less code in the gtk* files makes it easier for people
to write UIs.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 11 Jul 2004 20:42:16 +0000 |
parents | aecabbe495db |
children | 03be9d653123 |
comparison
equal
deleted
inserted
replaced
9510:2aed8d5cda1b | 9511:3ed6001d5de8 |
---|---|
26 | 26 |
27 #include "debug.h" | 27 #include "debug.h" |
28 #include "notify.h" | 28 #include "notify.h" |
29 #include "ft.h" | 29 #include "ft.h" |
30 #include "prpl.h" | 30 #include "prpl.h" |
31 #include "request.h" | |
32 #include "util.h" | 31 #include "util.h" |
33 | 32 |
34 #include "gaim-disclosure.h" | 33 #include "gaim-disclosure.h" |
35 #include "gtkcellrendererprogress.h" | 34 #include "gtkcellrendererprogress.h" |
36 #include "gtkft.h" | 35 #include "gtkft.h" |
99 COLUMN_REMAINING, | 98 COLUMN_REMAINING, |
100 COLUMN_DATA, | 99 COLUMN_DATA, |
101 NUM_COLUMNS | 100 NUM_COLUMNS |
102 }; | 101 }; |
103 | 102 |
104 | |
105 /************************************************************************** | |
106 * Prototype(s) | |
107 **************************************************************************/ | |
108 static int choose_file(GaimXfer *xfer); | |
109 | 103 |
110 /************************************************************************** | 104 /************************************************************************** |
111 * Utility Functions | 105 * Utility Functions |
112 **************************************************************************/ | 106 **************************************************************************/ |
113 static void | 107 static void |
1013 xfer->ui_data = NULL; | 1007 xfer->ui_data = NULL; |
1014 } | 1008 } |
1015 } | 1009 } |
1016 | 1010 |
1017 static void | 1011 static void |
1018 choose_file_ok_cb(void *user_data, const char *filename) | |
1019 { | |
1020 GaimXfer *xfer; | |
1021 struct stat st; | |
1022 | |
1023 xfer = (GaimXfer *)user_data; | |
1024 | |
1025 if (stat(filename, &st) != 0) { | |
1026 /* File not found. */ | |
1027 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | |
1028 gaim_xfer_request_accepted(xfer, filename); | |
1029 } | |
1030 else { | |
1031 gaim_notify_error(NULL, NULL, | |
1032 _("That file does not exist."), NULL); | |
1033 | |
1034 gaim_xfer_request_denied(xfer); | |
1035 } | |
1036 } | |
1037 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) && | |
1038 (st.st_size == 0)) { | |
1039 | |
1040 gaim_notify_error(NULL, NULL, | |
1041 _("Cannot send a file of 0 bytes."), NULL); | |
1042 | |
1043 gaim_xfer_request_denied(xfer); | |
1044 } | |
1045 else { | |
1046 if (S_ISDIR(st.st_mode)) { | |
1047 /* XXX */ | |
1048 gaim_xfer_request_denied(xfer); | |
1049 } | |
1050 else if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | |
1051 gaim_xfer_request_accepted(xfer, filename); | |
1052 } | |
1053 else { | |
1054 gaim_xfer_request_accepted(xfer, filename); | |
1055 } | |
1056 } | |
1057 | |
1058 gaim_xfer_unref(xfer); | |
1059 } | |
1060 | |
1061 static void | |
1062 choose_file_cancel_cb(void *user_data, const char *filename) | |
1063 { | |
1064 GaimXfer *xfer = (GaimXfer *)user_data; | |
1065 | |
1066 gaim_xfer_request_denied(xfer); | |
1067 } | |
1068 | |
1069 static int | |
1070 choose_file(GaimXfer *xfer) | |
1071 { | |
1072 gaim_request_file(xfer, NULL, gaim_xfer_get_filename(xfer), | |
1073 (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE), | |
1074 G_CALLBACK(choose_file_ok_cb), | |
1075 G_CALLBACK(choose_file_cancel_cb), xfer); | |
1076 | |
1077 return 0; | |
1078 } | |
1079 | |
1080 static int | |
1081 cancel_recv_cb(GaimXfer *xfer) | |
1082 { | |
1083 gaim_xfer_request_denied(xfer); | |
1084 gaim_xfer_unref(xfer); | |
1085 | |
1086 return 0; | |
1087 } | |
1088 | |
1089 static void | |
1090 gaim_gtkxfer_ask_recv(GaimXfer *xfer) | |
1091 { | |
1092 char *buf, *size_buf; | |
1093 size_t size; | |
1094 | |
1095 /* If we have already accepted the request, ask the destination file | |
1096 name directly */ | |
1097 if (gaim_xfer_get_status(xfer) != GAIM_XFER_STATUS_ACCEPTED) { | |
1098 size = gaim_xfer_get_size(xfer); | |
1099 size_buf = gaim_str_size_to_units(size); | |
1100 | |
1101 buf = g_strdup_printf(_("%s wants to send you %s (%s)"), | |
1102 xfer->who, gaim_xfer_get_filename(xfer), | |
1103 size_buf); | |
1104 g_free(size_buf); | |
1105 | |
1106 gaim_request_accept_cancel(NULL, NULL, buf, NULL, 0, xfer, | |
1107 G_CALLBACK(choose_file), | |
1108 G_CALLBACK(cancel_recv_cb)); | |
1109 g_free(buf); | |
1110 } else | |
1111 choose_file(xfer); | |
1112 } | |
1113 | |
1114 static int | |
1115 ask_accept_ok(GaimXfer *xfer) | |
1116 { | |
1117 gaim_xfer_request_accepted(xfer, NULL); | |
1118 gaim_xfer_unref(xfer); | |
1119 return 0; | |
1120 } | |
1121 | |
1122 static int | |
1123 ask_accept_cancel(GaimXfer *xfer) | |
1124 { | |
1125 gaim_xfer_request_denied(xfer); | |
1126 gaim_xfer_unref(xfer); | |
1127 return 0; | |
1128 } | |
1129 | |
1130 static void | |
1131 gaim_gtkxfer_ask_accept(GaimXfer *xfer) | |
1132 { | |
1133 char *buf, *buf2 = NULL; | |
1134 | |
1135 buf = g_strdup_printf(_("Accept file transfer request from %s?"), | |
1136 xfer->who); | |
1137 if (gaim_xfer_get_remote_ip(xfer) && | |
1138 gaim_xfer_get_remote_port(xfer)) | |
1139 buf2 = g_strdup_printf(_("A file is available for download from:\n" | |
1140 "Remote host: %s\nRemote port: %d"), | |
1141 gaim_xfer_get_remote_ip(xfer), | |
1142 gaim_xfer_get_remote_port(xfer)); | |
1143 gaim_request_accept_cancel(NULL, NULL, buf, buf2, 0, xfer, | |
1144 G_CALLBACK(ask_accept_ok), | |
1145 G_CALLBACK(ask_accept_cancel)); | |
1146 g_free(buf); | |
1147 g_free(buf2); | |
1148 } | |
1149 | |
1150 static void | |
1151 gaim_gtkxfer_request_file(GaimXfer *xfer) | |
1152 { | |
1153 gaim_xfer_ref(xfer); | |
1154 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | |
1155 if (gaim_xfer_get_filename(xfer) || | |
1156 gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_ACCEPTED) | |
1157 gaim_gtkxfer_ask_recv(xfer); | |
1158 else | |
1159 gaim_gtkxfer_ask_accept(xfer); | |
1160 } else | |
1161 choose_file(xfer); | |
1162 } | |
1163 | |
1164 static void | |
1165 gaim_gtkxfer_ask_cancel(GaimXfer *xfer) | |
1166 { | |
1167 } | |
1168 | |
1169 static void | |
1170 gaim_gtkxfer_add_xfer(GaimXfer *xfer) | 1012 gaim_gtkxfer_add_xfer(GaimXfer *xfer) |
1171 { | 1013 { |
1172 if (xfer_dialog == NULL) | 1014 if (xfer_dialog == NULL) |
1173 xfer_dialog = gaim_gtkxfer_dialog_new(); | 1015 xfer_dialog = gaim_gtkxfer_dialog_new(); |
1174 | 1016 |
1197 | 1039 |
1198 static GaimXferUiOps ops = | 1040 static GaimXferUiOps ops = |
1199 { | 1041 { |
1200 gaim_gtkxfer_new_xfer, | 1042 gaim_gtkxfer_new_xfer, |
1201 gaim_gtkxfer_destroy, | 1043 gaim_gtkxfer_destroy, |
1202 gaim_gtkxfer_request_file, | |
1203 gaim_gtkxfer_ask_cancel, | |
1204 gaim_gtkxfer_add_xfer, | 1044 gaim_gtkxfer_add_xfer, |
1205 gaim_gtkxfer_update_progress, | 1045 gaim_gtkxfer_update_progress, |
1206 gaim_gtkxfer_cancel_local, | 1046 gaim_gtkxfer_cancel_local, |
1207 gaim_gtkxfer_cancel_remote | 1047 gaim_gtkxfer_cancel_remote |
1208 }; | 1048 }; |