pidgin/gtkprefs.c

changeset 34225
3bba206f27f6
parent 34208
0b0ac1d83cce
child 34241
8b905ef8081d
equal deleted inserted replaced
34224:b9db365c4894 34225:3bba206f27f6
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 * 25 *
26 */ 26 */
27 #include "internal.h" 27 #include "internal.h"
28 #include "pidgin.h" 28 #include "pidgin.h"
29 #include "obsolete.h"
30 29
31 #include "debug.h" 30 #include "debug.h"
31 #include "http.h"
32 #include "nat-pmp.h" 32 #include "nat-pmp.h"
33 #include "notify.h" 33 #include "notify.h"
34 #include "prefs.h" 34 #include "prefs.h"
35 #include "proxy.h" 35 #include "proxy.h"
36 #include "prpl.h" 36 #include "prpl.h"
85 #define PROXYUSER 2 85 #define PROXYUSER 2
86 #define PROXYPASS 3 86 #define PROXYPASS 3
87 87
88 #define PREFS_OPTIMAL_ICON_SIZE 32 88 #define PREFS_OPTIMAL_ICON_SIZE 32
89 89
90 /* 25MB */
91 #define PREFS_MAX_DOWNLOADED_THEME_SIZE 26214400
92
90 struct theme_info { 93 struct theme_info {
91 gchar *type; 94 gchar *type;
92 gchar *extension; 95 gchar *extension;
93 gchar *original_name; 96 gchar *original_name;
94 }; 97 };
108 static GtkWidget *prefs_blist_themes_combo_box; 111 static GtkWidget *prefs_blist_themes_combo_box;
109 static GtkWidget *prefs_conv_themes_combo_box; 112 static GtkWidget *prefs_conv_themes_combo_box;
110 static GtkWidget *prefs_conv_variants_combo_box; 113 static GtkWidget *prefs_conv_variants_combo_box;
111 static GtkWidget *prefs_status_themes_combo_box; 114 static GtkWidget *prefs_status_themes_combo_box;
112 static GtkWidget *prefs_smiley_themes_combo_box; 115 static GtkWidget *prefs_smiley_themes_combo_box;
116 static PurpleHttpConnection *prefs_conv_themes_running_request = NULL;
113 117
114 /* Keyrings page */ 118 /* Keyrings page */
115 static GtkWidget *keyring_page_instance = NULL; 119 static GtkWidget *keyring_page_instance = NULL;
116 static GtkComboBox *keyring_combo = NULL; 120 static GtkComboBox *keyring_combo = NULL;
117 static GtkBox *keyring_vbox = NULL; 121 static GtkBox *keyring_vbox = NULL;
533 static void keyring_page_cleanup(void); 537 static void keyring_page_cleanup(void);
534 538
535 static void 539 static void
536 delete_prefs(GtkWidget *asdf, void *gdsa) 540 delete_prefs(GtkWidget *asdf, void *gdsa)
537 { 541 {
542 /* Cancel HTTP requests */
543 purple_http_conn_cancel(prefs_conv_themes_running_request);
544 prefs_conv_themes_running_request = NULL;
545
538 /* Close any "select sound" request dialogs */ 546 /* Close any "select sound" request dialogs */
539 purple_request_close_with_handle(prefs); 547 purple_request_close_with_handle(prefs);
540 548
541 purple_notify_close_with_handle(prefs); 549 purple_notify_close_with_handle(prefs);
542 550
1058 g_free(destdir); 1066 g_free(destdir);
1059 free_theme_info(info); 1067 free_theme_info(info);
1060 } 1068 }
1061 1069
1062 static void 1070 static void
1063 theme_got_url(PurpleUtilFetchUrlData *url_data, gpointer user_data, 1071 theme_got_url(PurpleHttpConnection *http_conn, PurpleHttpResponse *response,
1064 const gchar *themedata, size_t len, const gchar *error_message) 1072 gpointer _info)
1065 { 1073 {
1074 struct theme_info *info = _info;
1075 const gchar *themedata;
1076 size_t len;
1066 FILE *f; 1077 FILE *f;
1067 gchar *path; 1078 gchar *path;
1068 size_t wc; 1079 size_t wc;
1069 1080
1070 if ((error_message != NULL) || (len == 0)) { 1081 g_assert(http_conn == prefs_conv_themes_running_request);
1071 free_theme_info(user_data); 1082 prefs_conv_themes_running_request = NULL;
1083
1084 if (!purple_http_response_is_successfull(response)) {
1085 free_theme_info(info);
1072 return; 1086 return;
1073 } 1087 }
1088
1089 themedata = purple_http_response_get_data(response, &len);
1074 1090
1075 f = purple_mkstemp(&path, TRUE); 1091 f = purple_mkstemp(&path, TRUE);
1076 wc = fwrite(themedata, len, 1, f); 1092 wc = fwrite(themedata, len, 1, f);
1077 if (wc != 1) { 1093 if (wc != 1) {
1078 purple_debug_warning("theme_got_url", "Unable to write theme data.\n"); 1094 purple_debug_warning("theme_got_url", "Unable to write theme data.\n");
1079 fclose(f); 1095 fclose(f);
1080 g_unlink(path); 1096 g_unlink(path);
1081 g_free(path); 1097 g_free(path);
1082 free_theme_info(user_data); 1098 free_theme_info(info);
1083 return; 1099 return;
1084 } 1100 }
1085 fclose(f); 1101 fclose(f);
1086 1102
1087 theme_install_theme(path, user_data); 1103 theme_install_theme(path, info);
1088 1104
1089 g_unlink(path); 1105 g_unlink(path);
1090 g_free(path); 1106 g_free(path);
1091 } 1107 }
1092 1108
1119 free_theme_info(info); 1135 free_theme_info(info);
1120 return; 1136 return;
1121 } 1137 }
1122 theme_install_theme(tmp, info); 1138 theme_install_theme(tmp, info);
1123 g_free(tmp); 1139 g_free(tmp);
1124 } else if (!g_ascii_strncasecmp(name, "http://", 7)) { 1140 } else if (!g_ascii_strncasecmp(name, "http://", 7) ||
1141 !g_ascii_strncasecmp(name, "https://", 8)) {
1125 /* Oo, a web drag and drop. This is where things 1142 /* Oo, a web drag and drop. This is where things
1126 * will start to get interesting */ 1143 * will start to get interesting */
1127 purple_util_fetch_url(name, TRUE, NULL, FALSE, -1, theme_got_url, info); 1144 PurpleHttpRequest *hr;
1128 } else if (!g_ascii_strncasecmp(name, "https://", 8)) { 1145 purple_http_conn_cancel(prefs_conv_themes_running_request);
1129 /* purple_util_fetch_url() doesn't support HTTPS, but we want users 1146
1130 * to be able to drag and drop links from the SF trackers, so 1147 hr = purple_http_request_new(name);
1131 * we'll try it as an HTTP URL. */ 1148 purple_http_request_set_max_len(hr,
1132 char *tmp = g_strdup(name + 1); 1149 PREFS_MAX_DOWNLOADED_THEME_SIZE);
1133 tmp[0] = 'h'; 1150 prefs_conv_themes_running_request = purple_http_request(
1134 tmp[1] = 't'; 1151 NULL, hr, theme_got_url, info);
1135 tmp[2] = 't'; 1152 purple_http_request_unref(hr);
1136 tmp[3] = 'p';
1137
1138 purple_util_fetch_url(tmp, TRUE, NULL, FALSE, -1, theme_got_url, info);
1139 g_free(tmp);
1140 } else 1153 } else
1141 free_theme_info(info); 1154 free_theme_info(info);
1142 1155
1143 gtk_drag_finish(dc, TRUE, FALSE, t); 1156 gtk_drag_finish(dc, TRUE, FALSE, t);
1144 } 1157 }

mercurial