Mercurial > pidgin.yaz
comparison pidgin/gtkft.c @ 30909:25e200cb3532
propagate from branch 'im.pidgin.pidgin' (head dca20e09164518b0f7a773edd7e9649f41d8873d)
to branch 'im.pidgin.cpw.malu.xmpp.google_refactor' (head 7823c556f2d1bbca43f5ef9f0fea30cabc5d313f)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Tue, 31 Aug 2010 18:28:10 +0000 |
parents | 1cdae196aac8 |
children | a8cc50c2279f |
comparison
equal
deleted
inserted
replaced
30908:c44ec533a48c | 30909:25e200cb3532 |
---|---|
38 #include "gtkutils.h" | 38 #include "gtkutils.h" |
39 | 39 |
40 #define PIDGINXFER(xfer) \ | 40 #define PIDGINXFER(xfer) \ |
41 (PidginXferUiData *)(xfer)->ui_data | 41 (PidginXferUiData *)(xfer)->ui_data |
42 | 42 |
43 /* the maximum size of files we will try to make a thumbnail for */ | |
44 #define PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL 10 * 1024 * 1024 | |
45 | |
43 struct _PidginXferDialog | 46 struct _PidginXferDialog |
44 { | 47 { |
45 gboolean keep_open; | 48 gboolean keep_open; |
46 gboolean auto_clear; | 49 gboolean auto_clear; |
47 | 50 |
107 **************************************************************************/ | 110 **************************************************************************/ |
108 static void | 111 static void |
109 get_xfer_info_strings(PurpleXfer *xfer, char **kbsec, char **time_elapsed, | 112 get_xfer_info_strings(PurpleXfer *xfer, char **kbsec, char **time_elapsed, |
110 char **time_remaining) | 113 char **time_remaining) |
111 { | 114 { |
112 PidginXferUiData *data; | |
113 double kb_sent, kb_rem; | 115 double kb_sent, kb_rem; |
114 double kbps = 0.0; | 116 double kbps = 0.0; |
115 time_t elapsed, now; | 117 time_t elapsed, now; |
116 | |
117 data = PIDGINXFER(xfer); | |
118 | 118 |
119 if (xfer->end_time != 0) | 119 if (xfer->end_time != 0) |
120 now = xfer->end_time; | 120 now = xfer->end_time; |
121 else | 121 else |
122 now = time(NULL); | 122 now = time(NULL); |
154 if (time_remaining != NULL) { | 154 if (time_remaining != NULL) { |
155 if (purple_xfer_is_completed(xfer)) { | 155 if (purple_xfer_is_completed(xfer)) { |
156 *time_remaining = g_strdup(_("Finished")); | 156 *time_remaining = g_strdup(_("Finished")); |
157 } | 157 } |
158 else if (purple_xfer_is_canceled(xfer)) { | 158 else if (purple_xfer_is_canceled(xfer)) { |
159 *time_remaining = g_strdup(_("Canceled")); | 159 *time_remaining = g_strdup(_("Cancelled")); |
160 } | 160 } |
161 else if (purple_xfer_get_size(xfer) == 0 || (kb_sent > 0 && kbps == 0)) { | 161 else if (purple_xfer_get_size(xfer) == 0 || (kb_sent > 0 && kbps == 0)) { |
162 *time_remaining = g_strdup(_("Unknown")); | 162 *time_remaining = g_strdup(_("Unknown")); |
163 } | 163 } |
164 else if (kb_sent <= 0) { | 164 else if (kb_sent <= 0) { |
990 pixbuf = gtk_widget_render_icon(dialog->window, | 990 pixbuf = gtk_widget_render_icon(dialog->window, |
991 PIDGIN_STOCK_FILE_CANCELED, | 991 PIDGIN_STOCK_FILE_CANCELED, |
992 GTK_ICON_SIZE_MENU, NULL); | 992 GTK_ICON_SIZE_MENU, NULL); |
993 | 993 |
994 if (purple_xfer_is_canceled(xfer)) | 994 if (purple_xfer_is_canceled(xfer)) |
995 status = _("Canceled"); | 995 status = _("Cancelled"); |
996 else | 996 else |
997 status = _("Failed"); | 997 status = _("Failed"); |
998 | 998 |
999 gtk_list_store_set(dialog->model, &data->iter, | 999 gtk_list_store_set(dialog->model, &data->iter, |
1000 COLUMN_STATUS, pixbuf, | 1000 COLUMN_STATUS, pixbuf, |
1010 pidgin_xfer_dialog_update_xfer(PidginXferDialog *dialog, | 1010 pidgin_xfer_dialog_update_xfer(PidginXferDialog *dialog, |
1011 PurpleXfer *xfer) | 1011 PurpleXfer *xfer) |
1012 { | 1012 { |
1013 PidginXferUiData *data; | 1013 PidginXferUiData *data; |
1014 char *size_str, *remaining_str; | 1014 char *size_str, *remaining_str; |
1015 GtkTreeSelection *selection; | |
1016 time_t current_time; | 1015 time_t current_time; |
1017 GtkTreeIter iter; | 1016 GtkTreeIter iter; |
1018 gboolean valid; | 1017 gboolean valid; |
1019 | 1018 |
1020 g_return_if_fail(dialog != NULL); | 1019 g_return_if_fail(dialog != NULL); |
1061 -1); | 1060 -1); |
1062 | 1061 |
1063 g_object_unref(pixbuf); | 1062 g_object_unref(pixbuf); |
1064 } | 1063 } |
1065 | 1064 |
1066 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(xfer_dialog->tree)); | |
1067 | |
1068 update_title_progress(dialog); | 1065 update_title_progress(dialog); |
1069 if (xfer == dialog->selected_xfer) | 1066 if (xfer == dialog->selected_xfer) |
1070 update_detailed_info(xfer_dialog, xfer); | 1067 update_detailed_info(xfer_dialog, xfer); |
1071 | 1068 |
1072 if (purple_xfer_is_completed(xfer) && dialog->auto_clear) | 1069 if (purple_xfer_is_completed(xfer) && dialog->auto_clear) |
1153 static void | 1150 static void |
1154 pidgin_xfer_cancel_remote(PurpleXfer *xfer) | 1151 pidgin_xfer_cancel_remote(PurpleXfer *xfer) |
1155 { | 1152 { |
1156 if (xfer_dialog) | 1153 if (xfer_dialog) |
1157 pidgin_xfer_dialog_cancel_xfer(xfer_dialog, xfer); | 1154 pidgin_xfer_dialog_cancel_xfer(xfer_dialog, xfer); |
1155 } | |
1156 | |
1157 static void | |
1158 pidgin_xfer_add_thumbnail(PurpleXfer *xfer, const gchar *formats) | |
1159 { | |
1160 purple_debug_info("ft", "creating thumbnail for transfer\n"); | |
1161 | |
1162 if (purple_xfer_get_size(xfer) <= PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL) { | |
1163 GdkPixbuf *thumbnail = | |
1164 gdk_pixbuf_new_from_file_at_size( | |
1165 purple_xfer_get_local_filename(xfer), 128, 128, NULL); | |
1166 | |
1167 if (thumbnail) { | |
1168 gchar **formats_split = g_strsplit(formats, ",", 0); | |
1169 gchar *buffer = NULL; | |
1170 gsize size; | |
1171 char *option_keys[2] = {NULL, NULL}; | |
1172 char *option_values[2] = {NULL, NULL}; | |
1173 int i; | |
1174 gchar *format = NULL; | |
1175 | |
1176 for (i = 0; formats_split[i]; i++) { | |
1177 if (purple_strequal(formats_split[i], "jpeg")) { | |
1178 purple_debug_info("ft", "creating JPEG thumbnail\n"); | |
1179 option_keys[0] = "quality"; | |
1180 option_values[0] = "90"; | |
1181 format = "jpeg"; | |
1182 break; | |
1183 } else if (purple_strequal(formats_split[i], "png")) { | |
1184 purple_debug_info("ft", "creating PNG thumbnail\n"); | |
1185 option_keys[0] = "compression"; | |
1186 option_values[0] = "9"; | |
1187 format = "png"; | |
1188 break; | |
1189 } | |
1190 } | |
1191 | |
1192 /* Try the first format given by the PRPL without options */ | |
1193 if (format == NULL) { | |
1194 purple_debug_info("ft", | |
1195 "creating thumbnail of format %s as demanded by PRPL\n", | |
1196 formats_split[0]); | |
1197 format = formats_split[0]; | |
1198 } | |
1199 | |
1200 gdk_pixbuf_save_to_bufferv(thumbnail, &buffer, &size, format, | |
1201 option_keys, option_values, NULL); | |
1202 | |
1203 if (buffer) { | |
1204 gchar *mimetype = g_strdup_printf("image/%s", format); | |
1205 purple_debug_info("ft", | |
1206 "created thumbnail of %" G_GSIZE_FORMAT " bytes\n", | |
1207 size); | |
1208 purple_xfer_set_thumbnail(xfer, buffer, size, mimetype); | |
1209 g_free(buffer); | |
1210 g_free(mimetype); | |
1211 } | |
1212 g_object_unref(thumbnail); | |
1213 g_strfreev(formats_split); | |
1214 } | |
1215 } | |
1158 } | 1216 } |
1159 | 1217 |
1160 static PurpleXferUiOps ops = | 1218 static PurpleXferUiOps ops = |
1161 { | 1219 { |
1162 pidgin_xfer_new_xfer, | 1220 pidgin_xfer_new_xfer, |
1166 pidgin_xfer_cancel_local, | 1224 pidgin_xfer_cancel_local, |
1167 pidgin_xfer_cancel_remote, | 1225 pidgin_xfer_cancel_remote, |
1168 NULL, | 1226 NULL, |
1169 NULL, | 1227 NULL, |
1170 NULL, | 1228 NULL, |
1171 NULL | 1229 pidgin_xfer_add_thumbnail |
1172 }; | 1230 }; |
1173 | 1231 |
1174 /************************************************************************** | 1232 /************************************************************************** |
1175 * GTK+ File Transfer API | 1233 * GTK+ File Transfer API |
1176 **************************************************************************/ | 1234 **************************************************************************/ |