Mercurial > pidgin
comparison src/gtkaccount.c @ 10519:bec9130b24d2
[gaim-migrate @ 11833]
Leak fixes, round #2. And some minor MSN tweaks suggested by Felipe.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Mon, 17 Jan 2005 00:33:30 +0000 |
parents | dc4475bf718f |
children | f5c9438982f8 |
comparison
equal
deleted
inserted
replaced
10518:8ae540ad42e7 | 10519:bec9130b24d2 |
---|---|
242 | 242 |
243 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | 243 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
244 static void | 244 static void |
245 icon_filesel_choose_cb(GtkWidget *widget, gint response, AccountPrefsDialog *dialog) | 245 icon_filesel_choose_cb(GtkWidget *widget, gint response, AccountPrefsDialog *dialog) |
246 { | 246 { |
247 const char *filename; | 247 char *filename; |
248 | 248 |
249 if (response != GTK_RESPONSE_ACCEPT) { | 249 if (response != GTK_RESPONSE_ACCEPT) { |
250 if (response == GTK_RESPONSE_CANCEL) | 250 if (response == GTK_RESPONSE_CANCEL) |
251 gtk_widget_destroy(dialog->icon_filesel); | 251 gtk_widget_destroy(dialog->icon_filesel); |
252 dialog->icon_filesel = NULL; | 252 dialog->icon_filesel = NULL; |
256 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->icon_filesel)); | 256 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->icon_filesel)); |
257 #else /* FILECHOOSER */ | 257 #else /* FILECHOOSER */ |
258 static void | 258 static void |
259 icon_filesel_choose_cb(GtkWidget *w, AccountPrefsDialog *dialog) | 259 icon_filesel_choose_cb(GtkWidget *w, AccountPrefsDialog *dialog) |
260 { | 260 { |
261 const char *filename; | 261 char *filename; |
262 | 262 |
263 filename = gtk_file_selection_get_filename( | 263 filename = g_strdup(gtk_file_selection_get_filename( |
264 GTK_FILE_SELECTION(dialog->icon_filesel)); | 264 GTK_FILE_SELECTION(dialog->icon_filesel))); |
265 | 265 |
266 /* If they typed in a directory, change there */ | 266 /* If they typed in a directory, change there */ |
267 if (gaim_gtk_check_if_dir(filename, | 267 if (gaim_gtk_check_if_dir(filename, |
268 GTK_FILE_SELECTION(dialog->icon_filesel))) | 268 GTK_FILE_SELECTION(dialog->icon_filesel))) |
269 { | 269 { |
270 g_free(filename); | |
270 return; | 271 return; |
271 } | 272 } |
272 #endif /* FILECHOOSER */ | 273 #endif /* FILECHOOSER */ |
273 | 274 |
274 if (dialog->icon_path) | 275 if (dialog->icon_path) |
277 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), dialog->icon_path); | 278 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), dialog->icon_path); |
278 gtk_widget_show(dialog->icon_entry); | 279 gtk_widget_show(dialog->icon_entry); |
279 | 280 |
280 gtk_widget_destroy(dialog->icon_filesel); | 281 gtk_widget_destroy(dialog->icon_filesel); |
281 dialog->icon_filesel = NULL; | 282 dialog->icon_filesel = NULL; |
283 g_free(filename); | |
282 } | 284 } |
283 | 285 |
284 static void | 286 static void |
285 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | 287 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
286 icon_preview_change_cb(GtkFileChooser *widget, AccountPrefsDialog *dialog) | 288 icon_preview_change_cb(GtkFileChooser *widget, AccountPrefsDialog *dialog) |
290 { | 292 { |
291 GdkPixbuf *pixbuf, *scale; | 293 GdkPixbuf *pixbuf, *scale; |
292 int height, width; | 294 int height, width; |
293 char *basename, *markup, *size; | 295 char *basename, *markup, *size; |
294 struct stat st; | 296 struct stat st; |
295 const char *filename; | 297 char *filename; |
296 | 298 |
297 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | 299 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
298 filename = gtk_file_chooser_get_preview_filename( | 300 filename = gtk_file_chooser_get_preview_filename( |
299 GTK_FILE_CHOOSER(dialog->icon_filesel)); | 301 GTK_FILE_CHOOSER(dialog->icon_filesel)); |
300 #else /* FILECHOOSER */ | 302 #else /* FILECHOOSER */ |
301 filename = gtk_file_selection_get_filename( | 303 filename = g_strdup(gtk_file_selection_get_filename( |
302 GTK_FILE_SELECTION(dialog->icon_filesel)); | 304 GTK_FILE_SELECTION(dialog->icon_filesel))); |
303 #endif /* FILECHOOSER */ | 305 #endif /* FILECHOOSER */ |
304 | 306 |
305 if (!filename || stat(filename, &st)) | 307 if (!filename || stat(filename, &st)) |
308 { | |
309 g_free(filename); | |
306 return; | 310 return; |
311 } | |
307 | 312 |
308 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | 313 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); |
309 if (!pixbuf) { | 314 if (!pixbuf) { |
310 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->icon_preview), NULL); | 315 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->icon_preview), NULL); |
311 gtk_label_set_markup(GTK_LABEL(dialog->icon_text), ""); | 316 gtk_label_set_markup(GTK_LABEL(dialog->icon_text), ""); |
312 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | 317 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
313 gtk_file_chooser_set_preview_widget_active( | 318 gtk_file_chooser_set_preview_widget_active( |
314 GTK_FILE_CHOOSER(dialog->icon_filesel), FALSE); | 319 GTK_FILE_CHOOSER(dialog->icon_filesel), FALSE); |
315 #endif /* FILECHOOSER */ | 320 #endif /* FILECHOOSER */ |
321 g_free(filename); | |
316 return; | 322 return; |
317 } | 323 } |
318 | 324 |
319 width = gdk_pixbuf_get_width(pixbuf); | 325 width = gdk_pixbuf_get_width(pixbuf); |
320 height = gdk_pixbuf_get_height(pixbuf); | 326 height = gdk_pixbuf_get_height(pixbuf); |
334 #endif /* FILECHOOSER */ | 340 #endif /* FILECHOOSER */ |
335 gtk_label_set_markup(GTK_LABEL(dialog->icon_text), markup); | 341 gtk_label_set_markup(GTK_LABEL(dialog->icon_text), markup); |
336 | 342 |
337 g_object_unref(G_OBJECT(pixbuf)); | 343 g_object_unref(G_OBJECT(pixbuf)); |
338 g_object_unref(G_OBJECT(scale)); | 344 g_object_unref(G_OBJECT(scale)); |
345 g_free(filename); | |
339 g_free(basename); | 346 g_free(basename); |
340 g_free(size); | 347 g_free(size); |
341 g_free(markup); | 348 g_free(markup); |
342 } | 349 } |
343 | 350 |
533 (!(prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_SEND) || /* The prpl doesn't scale before it sends OR */ | 540 (!(prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_SEND) || /* The prpl doesn't scale before it sends OR */ |
534 (prpl_info->icon_spec.min_width <= width && | 541 (prpl_info->icon_spec.min_width <= width && |
535 prpl_info->icon_spec.max_width >= width && | 542 prpl_info->icon_spec.max_width >= width && |
536 prpl_info->icon_spec.min_height <= height && | 543 prpl_info->icon_spec.min_height <= height && |
537 prpl_info->icon_spec.max_height >= height))) { /* The icon is the correct size */ | 544 prpl_info->icon_spec.max_height >= height))) { /* The icon is the correct size */ |
545 g_strfreev(prpl_formats); | |
546 g_strfreev(pixbuf_formats); | |
538 #endif | 547 #endif |
539 return g_strdup(path); | 548 return g_strdup(path); |
540 #if GTK_CHECK_VERSION(2,2,0) | 549 #if GTK_CHECK_VERSION(2,2,0) |
541 } else { | 550 } else { |
542 int i; | 551 int i; |
544 GdkPixbuf *scale; | 553 GdkPixbuf *scale; |
545 char *random = g_strdup_printf("%x", g_random_int()); | 554 char *random = g_strdup_printf("%x", g_random_int()); |
546 const char *dirname = gaim_buddy_icons_get_cache_dir(); | 555 const char *dirname = gaim_buddy_icons_get_cache_dir(); |
547 char *filename = g_build_filename(dirname, random, NULL); | 556 char *filename = g_build_filename(dirname, random, NULL); |
548 pixbuf = gdk_pixbuf_new_from_file(path, &error); | 557 pixbuf = gdk_pixbuf_new_from_file(path, &error); |
558 g_strfreev(pixbuf_formats); | |
549 if (!error && (prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_SEND) && | 559 if (!error && (prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_SEND) && |
550 (width < prpl_info->icon_spec.min_width || | 560 (width < prpl_info->icon_spec.min_width || |
551 width > prpl_info->icon_spec.max_width || | 561 width > prpl_info->icon_spec.max_width || |
552 height < prpl_info->icon_spec.min_height || | 562 height < prpl_info->icon_spec.min_height || |
553 height > prpl_info->icon_spec.max_height)) | 563 height > prpl_info->icon_spec.max_height)) |
572 if (error) { | 582 if (error) { |
573 g_free(filename); | 583 g_free(filename); |
574 g_free(random); | 584 g_free(random); |
575 gaim_debug_error("buddyicon", "Could not open icon for conversion: %s\n", error->message); | 585 gaim_debug_error("buddyicon", "Could not open icon for conversion: %s\n", error->message); |
576 g_error_free(error); | 586 g_error_free(error); |
587 g_strfreev(prpl_formats); | |
577 return NULL; | 588 return NULL; |
578 } | 589 } |
579 | 590 |
580 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { | 591 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { |
581 gaim_debug_info("buddyicon", "Creating icon cache directory.\n"); | 592 gaim_debug_info("buddyicon", "Creating icon cache directory.\n"); |
582 | 593 |
583 if (mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) { | 594 if (mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) { |
584 gaim_debug_error("buddyicon", | 595 gaim_debug_error("buddyicon", |
585 "Unable to create directory %s: %s\n", | 596 "Unable to create directory %s: %s\n", |
586 dirname, strerror(errno)); | 597 dirname, strerror(errno)); |
598 g_strfreev(prpl_formats); | |
587 return NULL; | 599 return NULL; |
588 } | 600 } |
589 } | 601 } |
590 | 602 |
591 for (i = 0; prpl_formats[i]; i++) { | 603 for (i = 0; prpl_formats[i]; i++) { |
593 /* The gdk-pixbuf documentation is wrong. gdk_pixbuf_save returns TRUE if it was successful, | 605 /* The gdk-pixbuf documentation is wrong. gdk_pixbuf_save returns TRUE if it was successful, |
594 * FALSE if an error was set. */ | 606 * FALSE if an error was set. */ |
595 if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == TRUE) | 607 if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == TRUE) |
596 break; | 608 break; |
597 } | 609 } |
610 g_strfreev(prpl_formats); | |
598 if (!error) { | 611 if (!error) { |
599 g_free(random); | 612 g_free(random); |
600 g_object_unref(G_OBJECT(pixbuf)); | 613 g_object_unref(G_OBJECT(pixbuf)); |
601 return filename; | 614 return filename; |
602 } else { | 615 } else { |
1283 g_list_free(dialog->protocol_opt_entries); | 1296 g_list_free(dialog->protocol_opt_entries); |
1284 | 1297 |
1285 if (dialog->protocol_id != NULL) | 1298 if (dialog->protocol_id != NULL) |
1286 g_free(dialog->protocol_id); | 1299 g_free(dialog->protocol_id); |
1287 | 1300 |
1301 if (dialog->icon_path != NULL) | |
1302 g_free(dialog->icon_path); | |
1303 | |
1288 if (dialog->icon_filesel) | 1304 if (dialog->icon_filesel) |
1289 gtk_widget_destroy(dialog->icon_filesel); | 1305 gtk_widget_destroy(dialog->icon_filesel); |
1290 | 1306 |
1291 g_free(dialog); | 1307 g_free(dialog); |
1292 } | 1308 } |