changeset 24529:c31be282935d

When adding custom smiley without a previous filename (which is the case when adding a received smiley using the context menu, at which point there is only a pixbuf) create the storing dir if doesn't yet exists, since we need to dump the generated image there before calling purpl_smiley_create_from_file Closes #6623
author Marcus Lundblad <ml@update.uu.se>
date Tue, 02 Dec 2008 18:46:21 +0000
parents f59b9bfba784
children 2b705f7b3cbf
files pidgin/gtksmiley.c
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtksmiley.c	Tue Dec 02 15:58:39 2008 +0000
+++ b/pidgin/gtksmiley.c	Tue Dec 02 18:46:21 2008 +0000
@@ -272,11 +272,25 @@
 			gchar *buffer = NULL;
 			gsize size = 0;
 			gchar *filename;
+			const gchar *dirname = purple_smileys_get_storing_dir();
+			
+			/* since this may be called before purple_smiley_new_* has ever been
+			 called, we create the storing dir, if it doesn't exist yet, to be
+			 able to save the pixbuf before adding the smiley */
+			if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
+				purple_debug_info("gtksmiley", "Creating smileys directory.\n");
 
+				if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) {
+					purple_debug_error("gtksmiley",
+			                   "Unable to create directory %s: %s\n",
+			                   dirname, g_strerror(errno));
+				}
+			}
+			
 			gdk_pixbuf_save_to_buffer(s->custom_pixbuf, &buffer, &size,
 				"png", NULL, "compression", "9", NULL, NULL);
 			filename = purple_util_get_image_filename(buffer, size);
-			s->filename = g_build_filename(purple_smileys_get_storing_dir(), filename, NULL);
+			s->filename = g_build_filename(dirname, filename, NULL);
 			purple_util_write_data_to_file_absolute(s->filename, buffer, size);
 			g_free(filename);
 			g_free(buffer);