changeset 23183:013ec6fabd3f

Always store custom smileys with hashed filenames. Closes #5913. committer: Sadrul Habib Chowdhury <imadil@gmail.com>
author Marcus Lundblad <ml@update.uu.se>
date Sun, 25 May 2008 16:16:22 +0000
parents 89713caa9ade
children fc8cc6b58809
files libpurple/smiley.c libpurple/smiley.h pidgin/gtksmiley.c
diffstat 3 files changed, 15 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/smiley.c	Sun May 25 16:08:26 2008 +0000
+++ b/libpurple/smiley.c	Sun May 25 16:16:22 2008 +0000
@@ -119,7 +119,7 @@
 
 static void
 purple_smiley_set_data_impl(PurpleSmiley *smiley, guchar *smiley_data,
-		size_t smiley_data_len, const char *filename);
+		size_t smiley_data_len);
 
 static void
 purple_smiley_data_store(PurpleStoredImage *stored_img);
@@ -499,7 +499,7 @@
 
 	if (read_smiley_file(fullpath, &smiley_data, &smiley_data_len))
 		purple_smiley_set_data_impl(smiley, smiley_data,
-				smiley_data_len, filename);
+				smiley_data_len);
 	else
 		purple_smiley_delete(smiley);
 
@@ -617,7 +617,7 @@
 
 static void
 purple_smiley_set_data_impl(PurpleSmiley *smiley, guchar *smiley_data,
-				size_t smiley_data_len, const char *filename)
+				size_t smiley_data_len)
 {
 	PurpleStoredImage *old_img, *new_img;
 	const char *old_filename = NULL;
@@ -629,10 +629,7 @@
 
 	old_img = smiley->img;
 
-	if (filename)
-		new_img = purple_imgstore_add(smiley_data, smiley_data_len, filename);
-	else
-		new_img = purple_smiley_data_new(smiley_data, smiley_data_len);
+	new_img = purple_smiley_data_new(smiley_data, smiley_data_len);
 
 	g_object_set(G_OBJECT(smiley), PROP_IMGSTORE_S, new_img, NULL);
 
@@ -688,7 +685,7 @@
 
 static PurpleSmiley *
 purple_smiley_new_from_stream(const char *shortcut, guchar *smiley_data,
-			size_t smiley_data_len, const char *filename)
+			size_t smiley_data_len)
 {
 	PurpleSmiley *smiley;
 
@@ -705,7 +702,7 @@
 	if (!smiley)
 		return NULL;
 
-	purple_smiley_set_data_impl(smiley, smiley_data, smiley_data_len, filename);
+	purple_smiley_set_data_impl(smiley, smiley_data, smiley_data_len);
 
 	purple_smiley_data_store(smiley->img);
 
@@ -718,17 +715,15 @@
 	PurpleSmiley *smiley = NULL;
 	guchar *smiley_data;
 	size_t smiley_data_len;
-	char *filename;
 
 	g_return_val_if_fail(shortcut  != NULL,  NULL);
 	g_return_val_if_fail(filepath != NULL,  NULL);
 
-	filename = g_path_get_basename(filepath);
-	if (read_smiley_file(filepath, &smiley_data, &smiley_data_len))
+	if (read_smiley_file(filepath, &smiley_data, &smiley_data_len)) {
 		smiley = purple_smiley_new_from_stream(shortcut, smiley_data,
-				smiley_data_len, filename);
-	g_free(filename);
-
+				smiley_data_len);
+	}
+	
 	return smiley;
 }
 
@@ -769,7 +764,7 @@
 
 void
 purple_smiley_set_data(PurpleSmiley *smiley, guchar *smiley_data,
-			   size_t smiley_data_len, gboolean keepfilename)
+			   size_t smiley_data_len)
 {
 	g_return_if_fail(smiley     != NULL);
 	g_return_if_fail(smiley_data != NULL);
@@ -779,14 +774,7 @@
 	g_hash_table_remove(smiley_checksum_index, smiley->checksum);
 
 	/* Update the file data. This also updates the checksum. */
-	if ((keepfilename) && (smiley->img) &&
-			(purple_imgstore_get_filename(smiley->img)))
-		purple_smiley_set_data_impl(smiley, smiley_data,
-				smiley_data_len,
-				purple_imgstore_get_filename(smiley->img));
-	else
-		purple_smiley_set_data_impl(smiley, smiley_data,
-				smiley_data_len, NULL);
+	purple_smiley_set_data_impl(smiley, smiley_data, smiley_data_len);
 
 	/* Reinsert the index item. */
 	g_hash_table_insert(smiley_checksum_index, g_strdup(smiley->checksum), smiley);
--- a/libpurple/smiley.h	Sun May 25 16:08:26 2008 +0000
+++ b/libpurple/smiley.h	Sun May 25 16:16:22 2008 +0000
@@ -128,12 +128,10 @@
  * @param smiley             The custom smiley.
  * @param smiley_data        The custom smiley data.
  * @param smiley_data_len    The custom smiley data length.
- * @param keepfilename      The current custom smiley's filename must be
- *                           kept.
  */
 void
 purple_smiley_set_data(PurpleSmiley *smiley, guchar *smiley_data,
-                                           size_t smiley_data_len, gboolean keepfilename);
+                                           size_t smiley_data_len);
 
 /**
  * Returns the custom smiley's associated shortcut.
--- a/pidgin/gtksmiley.c	Sun May 25 16:08:26 2008 +0000
+++ b/pidgin/gtksmiley.c	Sun May 25 16:16:22 2008 +0000
@@ -229,7 +229,7 @@
 
 				return;
 			}
-			purple_smiley_set_data(s->smiley, (guchar*)data, len, FALSE);
+			purple_smiley_set_data(s->smiley, (guchar*)data, len);
 		}
 		purple_smiley_set_shortcut(s->smiley, entry);
 	} else {
@@ -329,8 +329,8 @@
 	window = gtk_dialog_new_with_buttons(smiley ? _("Edit Smiley") : _("Add Smiley"),
 			widget ? GTK_WINDOW(widget) : NULL,
 			GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
+			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,							 
 			smiley ? GTK_STOCK_SAVE : GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
-			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 			NULL);
 	s->parent = window;