Mercurial > pidgin
comparison src/gtkft.c @ 9509:aecabbe495db
[gaim-migrate @ 10336]
FT --> gtk 2.4 file chooser via request API.
I'm going to try to move some of this from gtkft.c to ft.c
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 11 Jul 2004 19:57:31 +0000 |
parents | 72c88ac84afa |
children | 3ed6001d5de8 |
comparison
equal
deleted
inserted
replaced
9508:0123d883616c | 9509:aecabbe495db |
---|---|
77 GtkWidget *close_button; | 77 GtkWidget *close_button; |
78 }; | 78 }; |
79 | 79 |
80 typedef struct | 80 typedef struct |
81 { | 81 { |
82 GtkWidget *filesel; | |
83 GtkTreeIter iter; | 82 GtkTreeIter iter; |
84 time_t start_time; | 83 time_t start_time; |
85 time_t end_time; | 84 time_t end_time; |
86 gboolean in_list; | 85 gboolean in_list; |
87 | 86 |
1013 g_free(data); | 1012 g_free(data); |
1014 xfer->ui_data = NULL; | 1013 xfer->ui_data = NULL; |
1015 } | 1014 } |
1016 } | 1015 } |
1017 | 1016 |
1018 static gboolean | 1017 static void |
1019 choose_file_close_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | 1018 choose_file_ok_cb(void *user_data, const char *filename) |
1020 { | |
1021 GaimXfer *xfer = (GaimXfer *)user_data; | |
1022 GaimGtkXferUiData *data; | |
1023 | |
1024 data = GAIM_GTKXFER(xfer); | |
1025 data->filesel = NULL; | |
1026 gaim_xfer_request_denied(xfer); | |
1027 | |
1028 return FALSE; | |
1029 } | |
1030 | |
1031 static void | |
1032 choose_file_cancel_cb(GtkButton *button, gpointer user_data) | |
1033 { | |
1034 GaimXfer *xfer = (GaimXfer *)user_data; | |
1035 GaimGtkXferUiData *data; | |
1036 | |
1037 data = GAIM_GTKXFER(xfer); | |
1038 gtk_widget_destroy(data->filesel); | |
1039 data->filesel = NULL; | |
1040 gaim_xfer_request_denied(xfer); | |
1041 } | |
1042 | |
1043 static int | |
1044 do_overwrite_cb(GaimXfer *xfer) | |
1045 { | |
1046 GaimGtkXferUiData *data; | |
1047 | |
1048 data = GAIM_GTKXFER(xfer); | |
1049 | |
1050 gaim_xfer_request_accepted(xfer, data->name); | |
1051 | |
1052 g_free(data->name); | |
1053 data->name = NULL; | |
1054 | |
1055 gaim_xfer_unref(xfer); | |
1056 return 0; | |
1057 } | |
1058 | |
1059 static int | |
1060 dont_overwrite_cb(GaimXfer *xfer) | |
1061 { | |
1062 GaimGtkXferUiData *data; | |
1063 | |
1064 data = GAIM_GTKXFER(xfer); | |
1065 | |
1066 g_free(data->name); | |
1067 data->name = NULL; | |
1068 | |
1069 choose_file(xfer); | |
1070 | |
1071 return 0; | |
1072 } | |
1073 | |
1074 static void | |
1075 choose_file_ok_cb(GtkButton *button, gpointer user_data) | |
1076 { | 1019 { |
1077 GaimXfer *xfer; | 1020 GaimXfer *xfer; |
1078 GaimGtkXferUiData *data; | |
1079 struct stat st; | 1021 struct stat st; |
1080 const char *name; | |
1081 | 1022 |
1082 xfer = (GaimXfer *)user_data; | 1023 xfer = (GaimXfer *)user_data; |
1083 data = GAIM_GTKXFER(xfer); | 1024 |
1084 | 1025 if (stat(filename, &st) != 0) { |
1085 name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data->filesel)); | |
1086 | |
1087 if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(data->filesel))) { | |
1088 return; | |
1089 } | |
1090 | |
1091 if (stat(name, &st) != 0) { | |
1092 /* File not found. */ | 1026 /* File not found. */ |
1093 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | 1027 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { |
1094 gaim_xfer_request_accepted(xfer, g_strdup(name)); | 1028 gaim_xfer_request_accepted(xfer, filename); |
1095 } | 1029 } |
1096 else { | 1030 else { |
1097 gaim_notify_error(NULL, NULL, | 1031 gaim_notify_error(NULL, NULL, |
1098 _("That file does not exist."), NULL); | 1032 _("That file does not exist."), NULL); |
1099 | 1033 |
1112 if (S_ISDIR(st.st_mode)) { | 1046 if (S_ISDIR(st.st_mode)) { |
1113 /* XXX */ | 1047 /* XXX */ |
1114 gaim_xfer_request_denied(xfer); | 1048 gaim_xfer_request_denied(xfer); |
1115 } | 1049 } |
1116 else if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | 1050 else if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { |
1117 data->name = g_strdup(name); | 1051 gaim_xfer_request_accepted(xfer, filename); |
1118 gaim_xfer_ref(xfer); | |
1119 | |
1120 gaim_request_yes_no(NULL, NULL, | |
1121 _("That file already exists."), | |
1122 _("Would you like to overwrite it?"), | |
1123 1, xfer, | |
1124 G_CALLBACK(do_overwrite_cb), | |
1125 G_CALLBACK(dont_overwrite_cb)); | |
1126 } | 1052 } |
1127 else { | 1053 else { |
1128 gaim_xfer_request_accepted(xfer, name); | 1054 gaim_xfer_request_accepted(xfer, filename); |
1129 } | 1055 } |
1130 } | 1056 } |
1131 | 1057 |
1132 gtk_widget_destroy(data->filesel); | |
1133 data->filesel = NULL; | |
1134 gaim_xfer_unref(xfer); | 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); | |
1135 } | 1067 } |
1136 | 1068 |
1137 static int | 1069 static int |
1138 choose_file(GaimXfer *xfer) | 1070 choose_file(GaimXfer *xfer) |
1139 { | 1071 { |
1140 char *cur_dir, *init_str; | 1072 gaim_request_file(xfer, NULL, gaim_xfer_get_filename(xfer), |
1141 GaimGtkXferUiData *data; | 1073 (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE), |
1142 | 1074 G_CALLBACK(choose_file_ok_cb), |
1143 data = GAIM_GTKXFER(xfer); | 1075 G_CALLBACK(choose_file_cancel_cb), xfer); |
1144 cur_dir = g_get_current_dir(); | |
1145 | |
1146 if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) | |
1147 data->filesel = gtk_file_selection_new(_("Open...")); | |
1148 else | |
1149 data->filesel = gtk_file_selection_new(_("Save As...")); | |
1150 | |
1151 if (gaim_xfer_get_filename(xfer) == NULL) | |
1152 init_str = g_strdup_printf("%s" G_DIR_SEPARATOR_S, cur_dir); | |
1153 else | |
1154 init_str = g_build_filename(cur_dir, gaim_xfer_get_filename(xfer), | |
1155 NULL); | |
1156 | |
1157 g_free(cur_dir); | |
1158 | |
1159 gtk_file_selection_set_filename(GTK_FILE_SELECTION(data->filesel), | |
1160 init_str); | |
1161 | |
1162 g_free(init_str); | |
1163 | |
1164 g_signal_connect(G_OBJECT(data->filesel), "delete_event", | |
1165 G_CALLBACK(choose_file_close_cb), xfer); | |
1166 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(data->filesel)->cancel_button), | |
1167 "clicked", | |
1168 G_CALLBACK(choose_file_cancel_cb), xfer); | |
1169 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(data->filesel)->ok_button), | |
1170 "clicked", | |
1171 G_CALLBACK(choose_file_ok_cb), xfer); | |
1172 | |
1173 gtk_widget_show(data->filesel); | |
1174 | 1076 |
1175 return 0; | 1077 return 0; |
1176 } | 1078 } |
1177 | 1079 |
1178 static int | 1080 static int |
1211 | 1113 |
1212 static int | 1114 static int |
1213 ask_accept_ok(GaimXfer *xfer) | 1115 ask_accept_ok(GaimXfer *xfer) |
1214 { | 1116 { |
1215 gaim_xfer_request_accepted(xfer, NULL); | 1117 gaim_xfer_request_accepted(xfer, NULL); |
1118 gaim_xfer_unref(xfer); | |
1216 return 0; | 1119 return 0; |
1217 } | 1120 } |
1218 | 1121 |
1219 static int | 1122 static int |
1220 ask_accept_cancel(GaimXfer *xfer) | 1123 ask_accept_cancel(GaimXfer *xfer) |