gaim/gaim

Patch #1227578 from Richard Laager*
oldstatus
2005-06-30, Richard Laager
15f0a3d50f43
Parents 6e1e3509c1d5
Children 4c3d11607e6d
Patch #1227578 from Richard Laager*

"This is a completed backport of two of my buddy icon patches."

* grim: Because it's funny to credit myself and I'm only going to get to do it today. ;-)
--- a/ChangeLog Thu Jun 30 00:33:22 2005 -0400
+++ b/ChangeLog Thu Jun 30 00:52:16 2005 -0400
@@ -5,6 +5,7 @@
* SILC compiles with newer SILC toolkit versions (Pekka Riikonen)
* Fixed a bug where buddy icon cache files were left in the icon
cache directory after they were no longer in use.
+ * Attempt to detect the file type of a buddy icon when saving.
version 1.3.1 (6/9/2005):
* The file transfer details section now also displays the full path to
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/buddyicon-signals.dox Thu Jun 30 00:52:16 2005 -0400
@@ -0,0 +1,24 @@
+/** @page buddyicon-signals Buddy Icon Signals
+
+ @signals
+ @signal buddy-icon-cached
+ @endsignals
+
+ <hr>
+
+ @signaldef buddy-icon-cached
+ @signalproto
+void (*buddy-icon-cached)(GaimBuddyIcon *icon, GaimBuddy *buddy, const char *filename, const char *old_icon);
+ @endsignalproto
+ @signaldesc
+ Emitted when a buddy icon is cached.
+ @param icon The icon that was just cached.
+ @param buddy The buddy the icon belongs to.
+ @param filename The full filename for the newly created icon cache file.
+ @param old_icon The filename of the icon cache file for the buddy's previous icon, or @c NULL if the buddy
+ had no icon when this new icon was set. This filename is generally the full filename of the
+ previous icon cache file, but if the previous buddy icon was set in an old version of Gaim,
+ this may just be the basename of the icon cache file. The directory can be obtained with
+ gaim_buddy_icons_get_cache_dir().
+ @endsignaldef
+*/
--- a/plugins/ChangeLog.API Thu Jun 30 00:33:22 2005 -0400
+++ b/plugins/ChangeLog.API Thu Jun 30 00:52:16 2005 -0400
@@ -3,6 +3,10 @@
version 1.4.0:
* Added: gaim_buddy_icon_uncache()
Deletes a cached buddy icon for a specified buddy
+ * Added: gaim_buddy_icon_get_type
+ Attempts to determine the type of a given buddy icon.
+ * Added: buddy-icon-cached signal
+ Emitted when a new buddy icon is cached.
version 1.3.1 (6/9/2005):
* No changes
--- a/plugins/signals-test.c Thu Jun 30 00:33:22 2005 -0400
+++ b/plugins/signals-test.c Thu Jun 30 00:52:16 2005 -0400
@@ -71,6 +71,17 @@
}
/**************************************************************************
+ * Buddy Icons signal callbacks
+ **************************************************************************/
+static void
+buddy_icon_cached_cb(GaimBuddyIcon *icon, GaimBuddy *buddy,
+ const char *filename, const char *old_icon)
+{
+ gaim_debug_misc("signals test", "buddy icon cached (%s, %s, %s)\n",
+ buddy->name, filename, old_icon);
+}
+
+/**************************************************************************
* Buddy List subsystem signal callbacks
**************************************************************************/
static void
@@ -458,6 +469,7 @@
void *conn_handle = gaim_connections_get_handle();
void *conv_handle = gaim_conversations_get_handle();
void *accounts_handle = gaim_accounts_get_handle();
+ void *buddy_icons_handle = gaim_buddy_icons_get_handle();
/* Accounts subsystem signals */
gaim_signal_connect(accounts_handle, "account-connecting",
@@ -471,6 +483,10 @@
gaim_signal_connect(accounts_handle, "account-warned",
plugin, GAIM_CALLBACK(account_warned_cb), NULL);
+ /* Buddy Icon subsystem signals */
+ gaim_signal_connect(buddy_icons_handle, "buddy-icon-cached",
+ plugin, GAIM_CALLBACK(buddy_icon_cached_cb), NULL);
+
/* Buddy List subsystem signals */
gaim_signal_connect(blist_handle, "buddy-away",
plugin, GAIM_CALLBACK(buddy_away_cb), NULL);
--- a/src/buddyicon.c Thu Jun 30 00:33:22 2005 -0400
+++ b/src/buddyicon.c Thu Jun 30 00:52:16 2005 -0400
@@ -257,6 +257,9 @@
fclose(file);
}
+ gaim_signal_emit(gaim_buddy_icons_get_handle(), "buddy-icon-cached",
+ icon, buddy, filename, old_icon);
+
g_free(filename);
if (old_icon != NULL)
@@ -360,6 +363,32 @@
return icon->data;
}
+const char *
+gaim_buddy_icon_get_type(const GaimBuddyIcon *icon)
+{
+ const void *data;
+ size_t len;
+
+ g_return_val_if_fail(icon != NULL, NULL);
+
+ data = gaim_buddy_icon_get_data(icon, &len);
+
+ /* TODO: Find a way to do this with GDK */
+ if (len >= 4)
+ {
+ if (!strncmp(data, "BM", 2))
+ return "bmp";
+ else if (!strncmp(data, "GIF8", 4))
+ return "gif";
+ else if (!strncmp(data, "\xff\xd8\xff\xe0", 4))
+ return "jpg";
+ else if (!strncmp(data, "\x89PNG", 4))
+ return "png";
+ }
+
+ return NULL;
+}
+
void
gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username,
void *icon_data, size_t icon_len)
@@ -476,6 +505,15 @@
NULL, (GFreeFunc)g_hash_table_destroy);
cache_dir = g_build_filename(gaim_user_dir(), "icons", NULL);
+
+ gaim_signal_register(gaim_buddy_icons_get_handle(), "buddy-icon-cached",
+ gaim_marshal_VOID__POINTER_POINTER_POINTER_POINTER, NULL, 4,
+ gaim_value_new(GAIM_TYPE_SUBTYPE,
+ GAIM_SUBTYPE_BUDDY_ICON),
+ gaim_value_new(GAIM_TYPE_SUBTYPE,
+ GAIM_SUBTYPE_BLIST_BUDDY),
+ gaim_value_new(GAIM_TYPE_STRING),
+ gaim_value_new(GAIM_TYPE_STRING));
}
void
--- a/src/buddyicon.h Thu Jun 30 00:33:22 2005 -0400
+++ b/src/buddyicon.h Thu Jun 30 00:52:16 2005 -0400
@@ -164,6 +164,15 @@
*/
const void *gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len);
+/**
+ * Returns an extension corresponding to the buddy icon's file type.
+ *
+ * @param icon The buddy icon.
+ *
+ * @return The icon's extension.
+ */
+const char *gaim_buddy_icon_get_type(const GaimBuddyIcon *icon);
+
/*@}*/
/**************************************************************************/
--- a/src/gtkconv.c Thu Jun 30 00:33:22 2005 -0400
+++ b/src/gtkconv.c Thu Jun 30 00:52:16 2005 -0400
@@ -2662,14 +2662,15 @@
icon_menu_save_cb(GtkWidget *widget, GaimConversation *conv)
{
gchar *buf;
+ const gchar *ext;
g_return_if_fail(conv != NULL);
- /*
- * XXX - The file extension needs to be set to something that doesn't suck...
- * Maybe do what gtkimhtml.c does when saving an image?
- */
- buf = g_strdup_printf("%s.icon", gaim_normalize(conv->account, conv->name));
+ ext = gaim_buddy_icon_get_type(gaim_conv_im_get_icon(GAIM_CONV_IM(conv)));
+ if (ext == NULL)
+ ext = "icon";
+
+ buf = g_strdup_printf("%s.%s", gaim_normalize(conv->account, conv->name), ext);
gaim_request_file(conv, _("Save Icon"), buf, TRUE,
G_CALLBACK(saveicon_writefile_cb), NULL, conv);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/value.h Thu Jun 30 00:52:16 2005 -0400
@@ -0,0 +1,487 @@
+/**
+ * @file value.h Value wrapper API
+ * @ingroup core
+ *
+ * gaim
+ *
+ * Gaim is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _GAIM_VALUE_H_
+#define _GAIM_VALUE_H_
+
+#include <glib.h>
+
+/**
+ * Specific value types.
+ */
+typedef enum
+{
+ GAIM_TYPE_UNKNOWN = 0, /**< Unknown type. */
+ GAIM_TYPE_SUBTYPE, /**< Subtype. */
+ GAIM_TYPE_CHAR, /**< Character. */
+ GAIM_TYPE_UCHAR, /**< Unsigned character. */
+ GAIM_TYPE_BOOLEAN, /**< Boolean. */
+ GAIM_TYPE_SHORT, /**< Short integer. */
+ GAIM_TYPE_USHORT, /**< Unsigned short integer. */
+ GAIM_TYPE_INT, /**< Integer. */
+ GAIM_TYPE_UINT, /**< Unsigned integer. */
+ GAIM_TYPE_LONG, /**< Long integer. */
+ GAIM_TYPE_ULONG, /**< Unsigned long integer. */
+ GAIM_TYPE_INT64, /**< 64-bit integer. */
+ GAIM_TYPE_UINT64, /**< 64-bit unsigned integer. */
+ GAIM_TYPE_STRING, /**< String. */
+ GAIM_TYPE_OBJECT, /**< Object pointer. */
+ GAIM_TYPE_POINTER, /**< Generic pointer. */
+ GAIM_TYPE_ENUM, /**< Enum. */
+ GAIM_TYPE_BOXED /**< Boxed pointer with specific type. */
+
+} GaimType;
+
+/**
+ * Gaim-specific subtype values.
+ */
+typedef enum
+{
+ GAIM_SUBTYPE_UNKNOWN = 0,
+ GAIM_SUBTYPE_ACCOUNT,
+ GAIM_SUBTYPE_BLIST,
+ GAIM_SUBTYPE_BLIST_BUDDY,
+ GAIM_SUBTYPE_BLIST_GROUP,
+ GAIM_SUBTYPE_BLIST_CHAT,
+ GAIM_SUBTYPE_CONNECTION,
+ GAIM_SUBTYPE_CONVERSATION,
+ GAIM_SUBTYPE_CONV_WINDOW,
+ GAIM_SUBTYPE_PLUGIN,
+ GAIM_SUBTYPE_BLIST_NODE,
+ GAIM_SUBTYPE_BUDDY_ICON
+
+} GaimSubType;
+
+/**
+ * A wrapper for a type, subtype, and specific type of value.
+ */
+typedef struct
+{
+ GaimType type;
+ unsigned short flags;
+
+ union
+ {
+ char char_data;
+ unsigned char uchar_data;
+ gboolean boolean_data;
+ short short_data;
+ unsigned short ushort_data;
+ int int_data;
+ unsigned int uint_data;
+ long long_data;
+ unsigned long ulong_data;
+ gint64 int64_data;
+ guint64 uint64_data;
+ char *string_data;
+ void *object_data;
+ void *pointer_data;
+ int enum_data;
+ void *boxed_data;
+
+ } data;
+
+ union
+ {
+ unsigned int subtype;
+ char *specific_type;
+
+ } u;
+
+} GaimValue;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Creates a new GaimValue.
+ *
+ * This function takes a type and, depending on that type, a sub-type
+ * or specific type.
+ *
+ * If @a type is GAIM_TYPE_POINTER, the next parameter must be a
+ * string representing the specific type.
+ *
+ * If @a type is GAIM_TYPE_SUBTYPE, the next parameter must be a
+ * integer or enum representing the sub-type.
+ *
+ * If the subtype or specific type is not set when required, random
+ * errors may occur. You have been warned.
+ *
+ * @param type The type.
+ *
+ * @return The new value.
+ */
+GaimValue *gaim_value_new(GaimType type, ...);
+
+/**
+ * Creates a new outgoing GaimValue.
+ *
+ * This function takes a type and, depending on that type, a sub-type
+ * or specific type.
+ *
+ * If @a type is GAIM_TYPE_POINTER, the next parameter must be a
+ * string representing the specific type.
+ *
+ * If @a type is GAIM_TYPE_SUBTYPE, the next parameter must be a
+ * integer or enum representing the sub-type.
+ *
+ * If the sub-type or specific type is not set when required, random
+ * errors may occur. You have been warned.
+ *
+ * @param type The type.
+ *
+ * @return The new value.
+ */
+GaimValue *gaim_value_new_outgoing(GaimType type, ...);
+
+/**
+ * Destroys a GaimValue.
+ *
+ * @param value The value to destroy.
+ */
+void gaim_value_destroy(GaimValue *value);
+
+/**
+ * Duplicated a GaimValue.
+ *
+ * @param value The value to duplicate.
+ *
+ * @return The duplicate value.
+ */
+GaimValue *gaim_value_dup(const GaimValue *value);
+
+/**
+ * Returns a value's type.
+ *
+ * @return The value's type.
+ */
+GaimType gaim_value_get_type(const GaimValue *value);
+
+/**
+ * Returns a value's subtype.
+ *
+ * If the value's type is not GAIM_TYPE_SUBTYPE, this will return 0.
+ * Subtypes should never have a subtype of 0.
+ *
+ * @return The value's subtype, or 0 if @a type is not GAIM_TYPE_SUBTYPE.
+ */
+unsigned int gaim_value_get_subtype(const GaimValue *value);
+
+/**
+ * Returns a value's specific type.
+ *
+ * If the value's type is not GAIM_TYPE_BOXED, this will return @c NULL.
+ *
+ * @return The value's specific type, or @a NULL if not GAIM_TYPE_BOXED.
+ */
+const char *gaim_value_get_specific_type(const GaimValue *value);
+
+/**
+ * Returns whether or not the value is an outgoing value.
+ *
+ * @param value The value.
+ *
+ * @return TRUE if the value is outgoing, or FALSE otherwise.
+ */
+gboolean gaim_value_is_outgoing(const GaimValue *value);
+
+/**
+ * Sets the value's character data.
+ *
+ * @param value The value.
+ * @param data The character data.
+ */
+void gaim_value_set_char(GaimValue *value, char data);
+
+/**
+ * Sets the value's unsigned character data.
+ *
+ * @param value The value.
+ * @param data The unsigned character data.
+ */
+void gaim_value_set_uchar(GaimValue *value, unsigned char data);
+
+/**
+ * Sets the value's boolean data.
+ *
+ * @param value The value.
+ * @param data The boolean data.
+ */
+void gaim_value_set_boolean(GaimValue *value, gboolean data);
+
+/**
+ * Sets the value's short integer data.
+ *
+ * @param value The value.
+ * @param data The short integer data.
+ */
+void gaim_value_set_short(GaimValue *value, short data);
+
+/**
+ * Sets the value's unsigned short integer data.
+ *
+ * @param value The value.
+ * @param data The unsigned short integer data.
+ */
+void gaim_value_set_ushort(GaimValue *value, unsigned short data);
+
+/**
+ * Sets the value's integer data.
+ *
+ * @param value The value.
+ * @param data The integer data.
+ */
+void gaim_value_set_int(GaimValue *value, int data);
+
+/**
+ * Sets the value's unsigned integer data.
+ *
+ * @param value The value.
+ * @param data The unsigned integer data.
+ */
+void gaim_value_set_uint(GaimValue *value, unsigned int data);
+
+/**
+ * Sets the value's long integer data.
+ *
+ * @param value The value.
+ * @param data The long integer data.
+ */
+void gaim_value_set_long(GaimValue *value, long data);
+
+/**
+ * Sets the value's unsigned long integer data.
+ *
+ * @param value The value.
+ * @param data The unsigned long integer data.
+ */
+void gaim_value_set_ulong(GaimValue *value, unsigned long data);
+
+/**
+ * Sets the value's 64-bit integer data.
+ *
+ * @param value The value.
+ * @param data The 64-bit integer data.
+ */
+void gaim_value_set_int64(GaimValue *value, gint64 data);
+
+/**
+ * Sets the value's unsigned 64-bit integer data.
+ *
+ * @param value The value.
+ * @param data The unsigned 64-bit integer data.
+ */
+void gaim_value_set_uint64(GaimValue *value, guint64 data);
+
+/**
+ * Sets the value's string data.
+ *
+ * @param value The value.
+ * @param data The string data.
+ */
+void gaim_value_set_string(GaimValue *value, const char *data);
+
+/**
+ * Sets the value's object data.
+ *
+ * @param value The value.
+ * @param data The object data.
+ */
+void gaim_value_set_object(GaimValue *value, void *data);
+
+/**
+ * Sets the value's pointer data.
+ *
+ * @param value The value.
+ * @param data The pointer data.
+ */
+void gaim_value_set_pointer(GaimValue *value, void *data);
+
+/**
+ * Sets the value's enum data.
+ *
+ * @param value The value.
+ * @param data The enum data.
+ */
+void gaim_value_set_enum(GaimValue *value, int data);
+
+/**
+ * Sets the value's boxed data.
+ *
+ * @param value The value.
+ * @param data The boxed data.
+ */
+void gaim_value_set_boxed(GaimValue *value, void *data);
+
+/**
+ * Returns the value's character data.
+ *
+ * @param value The value.
+ *
+ * @return The character data.
+ */
+char gaim_value_get_char(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned character data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned character data.
+ */
+unsigned char gaim_value_get_uchar(const GaimValue *value);
+
+/**
+ * Returns the value's boolean data.
+ *
+ * @param value The value.
+ *
+ * @return The boolean data.
+ */
+gboolean gaim_value_get_boolean(const GaimValue *value);
+
+/**
+ * Returns the value's short integer data.
+ *
+ * @param value The value.
+ *
+ * @return The short integer data.
+ */
+short gaim_value_get_short(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned short integer data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned short integer data.
+ */
+unsigned short gaim_value_get_ushort(const GaimValue *value);
+
+/**
+ * Returns the value's integer data.
+ *
+ * @param value The value.
+ *
+ * @return The integer data.
+ */
+int gaim_value_get_int(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned integer data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned integer data.
+ */
+unsigned int gaim_value_get_uint(const GaimValue *value);
+
+/**
+ * Returns the value's long integer data.
+ *
+ * @param value The value.
+ *
+ * @return The long integer data.
+ */
+long gaim_value_get_long(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned long integer data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned long integer data.
+ */
+unsigned long gaim_value_get_ulong(const GaimValue *value);
+
+/**
+ * Returns the value's 64-bit integer data.
+ *
+ * @param value The value.
+ *
+ * @return The 64-bit integer data.
+ */
+gint64 gaim_value_get_int64(const GaimValue *value);
+
+/**
+ * Returns the value's unsigned 64-bit integer data.
+ *
+ * @param value The value.
+ *
+ * @return The unsigned 64-bit integer data.
+ */
+guint64 gaim_value_get_uint64(const GaimValue *value);
+
+/**
+ * Returns the value's string data.
+ *
+ * @param value The value.
+ *
+ * @return The string data.
+ */
+const char *gaim_value_get_string(const GaimValue *value);
+
+/**
+ * Returns the value's object data.
+ *
+ * @param value The value.
+ *
+ * @return The object data.
+ */
+void *gaim_value_get_object(const GaimValue *value);
+
+/**
+ * Returns the value's pointer data.
+ *
+ * @param value The value.
+ *
+ * @return The pointer data.
+ */
+void *gaim_value_get_pointer(const GaimValue *value);
+
+/**
+ * Returns the value's enum data.
+ *
+ * @param value The value.
+ *
+ * @return The enum data.
+ */
+int gaim_value_get_enum(const GaimValue *value);
+
+/**
+ * Returns the value's boxed data.
+ *
+ * @param value The value.
+ *
+ * @return The boxed data.
+ */
+void *gaim_value_get_boxed(const GaimValue *value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GAIM_VALUE_H_ */