Merged in rw_grim/pidgin (pull request #308)
Clean up the PurpleProtocolAttention interface and add unit tests around it and PurpleAttentionType
Approved-by: Elliott Sales de Andrade
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/attention.c Fri Feb 02 06:28:13 2018 +0000
@@ -0,0 +1,179 @@
+ * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA +/****************************************************************************** + * PurpleAttentionType API + *****************************************************************************/ +struct _PurpleAttentionType { + const gchar *incoming_description; + const gchar *outgoing_description; + const gchar *icon_name; + const gchar *unlocalized_name; + purple_attention_type_copy, +purple_attention_type_new(const gchar *unlocalized_name, + const gchar *incoming_description, + const gchar *outgoing_description) + PurpleAttentionType *attn = g_new0(PurpleAttentionType, 1); + attn->unlocalized_name = unlocalized_name; + attn->incoming_description = incoming_description; + attn->outgoing_description = outgoing_description; +purple_attention_type_copy(PurpleAttentionType *attn) { + PurpleAttentionType *attn_copy = NULL; + g_return_val_if_fail(attn != NULL, NULL); + attn_copy = g_new(PurpleAttentionType, 1); +purple_attention_type_get_name(const PurpleAttentionType *type) { + g_return_val_if_fail(type, NULL); +purple_attention_type_set_name(PurpleAttentionType *type, const gchar *name) { + g_return_if_fail(type); +purple_attention_type_get_incoming_desc(const PurpleAttentionType *type) { + g_return_val_if_fail(type, NULL); + return type->incoming_description; +purple_attention_type_set_incoming_desc(PurpleAttentionType *type, const gchar *desc) { + g_return_if_fail(type); + type->incoming_description = desc; +purple_attention_type_get_outgoing_desc(const PurpleAttentionType *type) { + g_return_val_if_fail(type, NULL); + return type->outgoing_description; +purple_attention_type_set_outgoing_desc(PurpleAttentionType *type, const gchar *desc) { + g_return_if_fail(type != NULL); + type->outgoing_description = desc; +purple_attention_type_get_icon_name(const PurpleAttentionType *type) { + g_return_val_if_fail(type, NULL); + if(type->icon_name == NULL || *(type->icon_name) == '\0') + return type->icon_name; +purple_attention_type_set_icon_name(PurpleAttentionType *type, const gchar *name) { + g_return_if_fail(type); + type->icon_name = name; +purple_attention_type_get_unlocalized_name(const PurpleAttentionType *type) { + g_return_val_if_fail(type, NULL); + return type->unlocalized_name; +purple_attention_type_set_unlocalized_name(PurpleAttentionType *type, const gchar *ulname) { + g_return_if_fail(type); + type->unlocalized_name = ulname; +/****************************************************************************** + * PurpleAttentionType API + *****************************************************************************/ +G_DEFINE_INTERFACE(PurpleProtocolAttention, purple_protocol_attention, G_TYPE_INVALID); +purple_protocol_attention_default_init(PurpleProtocolAttentionInterface *iface) { +purple_protocol_attention_send(PurpleProtocolAttention *attn, PurpleConnection *gc, const gchar *username, guint type) { + PurpleProtocolAttentionInterface *iface = NULL; + g_return_val_if_fail(PURPLE_IS_PROTOCOL_ATTENTION(attn), FALSE); + iface = PURPLE_PROTOCOL_ATTENTION_GET_IFACE(attn); + if(iface && iface->send) { + return iface->send(attn, gc, username, type); +purple_protocol_attention_get_types(PurpleProtocolAttention *attn, PurpleAccount *account) { + PurpleProtocolAttentionInterface *iface = NULL; + g_return_val_if_fail(PURPLE_IS_PROTOCOL_ATTENTION(attn), NULL); + iface = PURPLE_PROTOCOL_ATTENTION_GET_IFACE(attn); + if(iface && iface->get_types) { + return iface->get_types(attn, account); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/attention.h Fri Feb 02 06:28:13 2018 +0000
@@ -0,0 +1,254 @@
+ * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA +#ifndef PURPLE_ATTENTION_H +#define PURPLE_ATTENTION_H +#include <glib-object.h> + * @section_id: libpurple-attention + * @short_description: <filename>attention.h</filename> + * @title: Attention Object and Interfaces +#define PURPLE_TYPE_ATTENTION_TYPE (purple_attention_type_get_type()) + * @name: The name to show in GUI elements. + * @incoming_description: Shown when received. + * @outgoing_description: Shown when sent. + * @icon_name: Optional name of the icon to display. + * @unlocalized_name: An unlocalized name for UIs that would rather use that. + * Represents "nudges" and "buzzes" that you may send to a buddy to attract + * their attention (or vice-versa). +typedef struct _PurpleAttentionType PurpleAttentionType; +#define PURPLE_TYPE_PROTOCOL_ATTENTION (purple_protocol_attention_get_type()) +#define PURPLE_PROTOCOL_ATTENTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_PROTOCOL_ATTENTION, PurpleProtocolAttention)) +#define PURPLE_IS_PROTOCOL_ATTENTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_PROTOCOL_ATTENTION)) +#define PURPLE_PROTOCOL_ATTENTION_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), PURPLE_TYPE_PROTOCOL_ATTENTION, PurpleProtocolAttentionInterface)) +typedef struct _PurpleProtocolAttention PurpleProtocolAttention; +typedef struct _PurpleProtocolAttentionInterface PurpleProtocolAttentionInterface; + * PurpleProtocolAttentionInterface: + * The protocol attention interface. + * This interface provides attention API for sending and receiving + * zaps/nudges/buzzes etc. +struct _PurpleProtocolAttentionInterface + gboolean (*send)(PurpleProtocolAttention *attn, PurpleConnection *gc, const gchar *username, guint type); + GList *(*get_types)(PurpleProtocolAttention *attn, PurpleAccount *acct); +/****************************************************************************** + *****************************************************************************/ + * purple_attention_type_get_type: + * Returns: The #GType for the #PurpleAttentionType boxed structure. +GType purple_attention_type_get_type(void); +PurpleAttentionType *purple_attention_type_copy(PurpleAttentionType *attn); + * purple_attention_type_new: + * @unlocalized_name: A non-localized string that can be used by UIs in need of such + * non-localized strings. This should be the same as @name, + * without localization. + * @name: A localized string that the UI may display for the event. This + * should be the same string as @unlocalized_name, with localization. + * @incoming_description: A localized description shown when the event is received. + * @outgoing_description: A localized description shown when the event is sent. + * Creates a new #PurpleAttentionType object and sets its mandatory parameters. + * Returns: A pointer to the new object. +PurpleAttentionType *purple_attention_type_new(const gchar *unlocalized_name, const gchar *name, + const gchar *incoming_description, const gchar *outgoing_description); + * purple_attention_type_get_name: + * @type: The attention type. + * Get the attention type's name as displayed by the UI. +const gchar *purple_attention_type_get_name(const PurpleAttentionType *type); + * purple_attention_type_set_name: + * @type: The attention type. + * @name: The localized name that will be displayed by UIs. This should be + * the same string given as the unlocalized name, but with + * Sets the displayed name of the attention-demanding event. +void purple_attention_type_set_name(PurpleAttentionType *type, const gchar *name); + * purple_attention_type_get_incoming_desc: + * @type: The attention type. + * Get the attention type's description shown when the event is received. + * Returns: The description. +const gchar *purple_attention_type_get_incoming_desc(const PurpleAttentionType *type); + * purple_attention_type_set_incoming_desc: + * @type: The attention type. + * @desc: The localized description for incoming events. + * Sets the description of the attention-demanding event shown in conversations + * when the event is received. +void purple_attention_type_set_incoming_desc(PurpleAttentionType *type, const gchar *desc); + * purple_attention_type_get_outgoing_desc: + * @type: The attention type. + * Get the attention type's description shown when the event is sent. + * Returns: The description. +const gchar *purple_attention_type_get_outgoing_desc(const PurpleAttentionType *type); + * purple_attention_type_set_outgoing_desc: + * @type: The attention type. + * @desc: The localized description for outgoing events. + * Sets the description of the attention-demanding event shown in conversations + * when the event is sent. +void purple_attention_type_set_outgoing_desc(PurpleAttentionType *type, const gchar *desc); + * purple_attention_type_get_icon_name: + * @type: The attention type. + * Get the attention type's icon name. + * Note: Icons are optional for attention events. + * Returns: The icon name or %NULL if unset/empty. +const gchar *purple_attention_type_get_icon_name(const PurpleAttentionType *type); + * purple_attention_type_set_icon_name: + * @type: The attention type. + * @name: The icon's name. + * Sets the name of the icon to display for the attention event; this is optional. + * Note: Icons are optional for attention events. +void purple_attention_type_set_icon_name(PurpleAttentionType *type, const gchar *name); + * purple_attention_type_get_unlocalized_name: + * @type: The attention type + * Get the attention type's unlocalized name; this is useful for some UIs. + * Returns: The unlocalized name. +const gchar *purple_attention_type_get_unlocalized_name(const PurpleAttentionType *type); + * purple_attention_type_set_unlocalized_name: + * @type: The attention type. + * @ulname: The unlocalized name. This should be the same string given as + * the localized name, but without localization. + * Sets the unlocalized name of the attention event; some UIs may need this, +void purple_attention_type_set_unlocalized_name(PurpleAttentionType *type, const gchar *ulname); +/****************************************************************************** + *****************************************************************************/ + * purple_protocol_attention_get_type: + * Returns: The #GType for the protocol attention interface. +GType purple_protocol_attention_get_type(void); + * purple_protocol_attention_get_types: + * @protocol: The #PurpleProtocol. + * @account: The #PurpleAccount whose attention types to get. + * Returns a list of #PurpleAttentionType's for @attn. + * Returns: (transfer container) (element-type PurpleAttentionType): The list of #PurpleAttentionType's. +GList *purple_protocol_attention_get_types(PurpleProtocolAttention *attn, PurpleAccount *acct); + * purple_protocol_attention_send: + * @attn: The #PurpleProtocolAttention instance. + * @gc: The #PurpleConnection to send on + * @username: The name of the user to send the attention to. + * @type: The type of attention to send. + * Sends an attention message of @type to @username. + * Returns: TRUE on success, FALSE otherwise. +gboolean purple_protocol_attention_send(PurpleProtocolAttention *attn, PurpleConnection *gc, const gchar *username, guint type); +#endif /* PURPLE_ATTENTION_H */ --- a/libpurple/meson.build Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/meson.build Fri Feb 02 06:28:13 2018 +0000
@@ -2,6 +2,7 @@
@@ -86,6 +87,7 @@
--- a/libpurple/protocol.c Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/protocol.c Fri Feb 02 06:28:13 2018 +0000
@@ -864,56 +864,6 @@
#undef DEFINE_PROTOCOL_FUNC
/**************************************************************************
- * Protocol Attention Interface API
- **************************************************************************/
-#define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
- PurpleProtocolAttentionIface *attention_iface = \
- PURPLE_PROTOCOL_GET_ATTENTION_IFACE(protocol); \
- if (attention_iface && attention_iface->funcname) \
- attention_iface->funcname(__VA_ARGS__);
-#define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
- PurpleProtocolAttentionIface *attention_iface = \
- PURPLE_PROTOCOL_GET_ATTENTION_IFACE(protocol); \
- if (attention_iface && attention_iface->funcname) \
- return attention_iface->funcname(__VA_ARGS__); \
-purple_protocol_attention_iface_get_type(void)
- if (G_UNLIKELY(type == 0)) {
- static const GTypeInfo info = {
- .class_size = sizeof(PurpleProtocolAttentionIface),
- type = g_type_register_static(G_TYPE_INTERFACE,
- "PurpleProtocolAttentionIface", &info, 0);
-purple_protocol_attention_iface_send(PurpleProtocol *protocol,
- PurpleConnection *gc, const char *username, guint type)
- DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, FALSE, send, gc, username, type);
-purple_protocol_attention_iface_get_types(PurpleProtocol *protocol,
- PurpleAccount *account)
- DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_types, account);
-#undef DEFINE_PROTOCOL_FUNC_WITH_RETURN
-#undef DEFINE_PROTOCOL_FUNC
-/**************************************************************************
* Protocol Media Interface API
**************************************************************************/
#define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
--- a/libpurple/protocol.h Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/protocol.h Fri Feb 02 06:28:13 2018 +0000
@@ -588,34 +588,6 @@
#define PURPLE_PROTOCOL_GET_ROOMLIST_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), PURPLE_TYPE_PROTOCOL_ROOMLIST_IFACE, \
PurpleProtocolRoomlistIface))
-#define PURPLE_TYPE_PROTOCOL_ATTENTION_IFACE (purple_protocol_attention_iface_get_type())
-typedef struct _PurpleProtocolAttentionIface PurpleProtocolAttentionIface;
- * PurpleProtocolAttentionIface:
- * The protocol attention interface.
- * This interface provides attention API for sending and receiving
- * zaps/nudges/buzzes etc.
-struct _PurpleProtocolAttentionIface
- GTypeInterface parent_iface;
- gboolean (*send)(PurpleConnection *gc, const char *username,
- GList *(*get_types)(PurpleAccount *acct);
-#define PURPLE_PROTOCOL_HAS_ATTENTION_IFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_PROTOCOL_ATTENTION_IFACE))
-#define PURPLE_PROTOCOL_GET_ATTENTION_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), PURPLE_TYPE_PROTOCOL_ATTENTION_IFACE, \
- PurpleProtocolAttentionIface))
#define PURPLE_TYPE_PROTOCOL_MEDIA_IFACE (purple_protocol_media_iface_get_type())
typedef struct _PurpleProtocolMediaIface PurpleProtocolMediaIface;
@@ -1078,23 +1050,6 @@
PurpleRoomlistRoom *room);
/**************************************************************************/
-/* Protocol Attention Interface API */
-/**************************************************************************/
- * purple_protocol_attention_iface_get_type:
- * Returns: The #GType for the protocol attention interface.
-GType purple_protocol_attention_iface_get_type(void);
-gboolean purple_protocol_attention_iface_send(PurpleProtocol *protocol,
- PurpleConnection *gc, const char *username, guint type);
-GList *purple_protocol_attention_iface_get_types(PurpleProtocol *protocol,
-/**************************************************************************/
/* Protocol Media Interface API */
/**************************************************************************/
--- a/libpurple/protocols.c Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/protocols.c Fri Feb 02 06:28:13 2018 +0000
@@ -32,149 +32,6 @@
static GHashTable *protocols = NULL;
-/**************************************************************************/
-/* Attention Type API */
-/**************************************************************************/
-struct _PurpleAttentionType
- const char *name; /* Shown in GUI elements */
- const char *incoming_description; /* Shown when sent */
- const char *outgoing_description; /* Shown when receied */
- const char *icon_name; /* Icon to display (optional) */
- const char *unlocalized_name; /* Unlocalized name for UIs needing it */
-purple_attention_type_new(const char *ulname, const char *name,
- const char *inc_desc, const char *out_desc)
- PurpleAttentionType *attn = g_new0(PurpleAttentionType, 1);
- purple_attention_type_set_name(attn, name);
- purple_attention_type_set_incoming_desc(attn, inc_desc);
- purple_attention_type_set_outgoing_desc(attn, out_desc);
- purple_attention_type_set_unlocalized_name(attn, ulname);
-purple_attention_type_set_name(PurpleAttentionType *type, const char *name)
- g_return_if_fail(type != NULL);
-purple_attention_type_set_incoming_desc(PurpleAttentionType *type, const char *desc)
- g_return_if_fail(type != NULL);
- type->incoming_description = desc;
-purple_attention_type_set_outgoing_desc(PurpleAttentionType *type, const char *desc)
- g_return_if_fail(type != NULL);
- type->outgoing_description = desc;
-purple_attention_type_set_icon_name(PurpleAttentionType *type, const char *name)
- g_return_if_fail(type != NULL);
- type->icon_name = name;
-purple_attention_type_set_unlocalized_name(PurpleAttentionType *type, const char *ulname)
- g_return_if_fail(type != NULL);
- type->unlocalized_name = ulname;
-purple_attention_type_get_name(const PurpleAttentionType *type)
- g_return_val_if_fail(type != NULL, NULL);
-purple_attention_type_get_incoming_desc(const PurpleAttentionType *type)
- g_return_val_if_fail(type != NULL, NULL);
- return type->incoming_description;
-purple_attention_type_get_outgoing_desc(const PurpleAttentionType *type)
- g_return_val_if_fail(type != NULL, NULL);
- return type->outgoing_description;
-purple_attention_type_get_icon_name(const PurpleAttentionType *type)
- g_return_val_if_fail(type != NULL, NULL);
- if(type->icon_name == NULL || *(type->icon_name) == '\0')
- return type->icon_name;
-purple_attention_type_get_unlocalized_name(const PurpleAttentionType *type)
- g_return_val_if_fail(type != NULL, NULL);
- return type->unlocalized_name;
-/**************************************************************************
- * GBoxed code for PurpleAttentionType
- **************************************************************************/
-static PurpleAttentionType *
-purple_attention_type_copy(PurpleAttentionType *attn)
- PurpleAttentionType *attn_copy;
- g_return_val_if_fail(attn != NULL, NULL);
- attn_copy = g_new(PurpleAttentionType, 1);
-purple_attention_type_get_type(void)
- type = g_boxed_type_register_static("PurpleAttentionType",
- (GBoxedCopyFunc)purple_attention_type_copy,
- (GBoxedFreeFunc)g_free);
/**************************************************************************
* GBoxed code for PurpleProtocolChatEntry
**************************************************************************/
@@ -508,7 +365,7 @@
g_return_if_fail(who != NULL);
protocol = purple_protocols_find(purple_account_get_protocol_id(purple_connection_get_account(gc)));
- g_return_if_fail(PURPLE_PROTOCOL_IMPLEMENTS(protocol, ATTENTION_IFACE, send));
+ g_return_if_fail(PURPLE_IS_PROTOCOL_ATTENTION(protocol)); attn = purple_get_attention_type_from_code(purple_connection_get_account(gc), type_code);
@@ -526,7 +383,7 @@
purple_debug_info("server", "serv_send_attention: sending '%s' to %s\n",
- if (!purple_protocol_attention_iface_send(protocol, gc, who, type_code))
+ if (!purple_protocol_attention_send(PURPLE_PROTOCOL_ATTENTION(protocol), gc, who, type_code)) im = purple_im_conversation_new(purple_connection_get_account(gc), who);
--- a/libpurple/protocols.h Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/protocols.h Fri Feb 02 06:28:13 2018 +0000
@@ -36,16 +36,6 @@
typedef struct _PurpleProtocolAction PurpleProtocolAction;
typedef void (*PurpleProtocolActionCallback)(PurpleProtocolAction *action);
-#define PURPLE_TYPE_ATTENTION_TYPE (purple_attention_type_get_type())
- * Represents "nudges" and "buzzes" that you may send to a buddy to attract
- * their attention (or vice-versa).
-typedef struct _PurpleAttentionType PurpleAttentionType;
/**************************************************************************/
/* Basic Protocol Information */
/**************************************************************************/
@@ -157,135 +147,6 @@
/**************************************************************************/
- * purple_attention_type_get_type:
- * Returns: The #GType for the #PurpleAttentionType boxed structure.
-GType purple_attention_type_get_type(void);
- * purple_attention_type_new:
- * @ulname: A non-localized string that can be used by UIs in need of such
- * non-localized strings. This should be the same as @name,
- * without localization.
- * @name: A localized string that the UI may display for the event. This
- * should be the same string as @ulname, with localization.
- * @inc_desc: A localized description shown when the event is received.
- * @out_desc: A localized description shown when the event is sent.
- * Creates a new #PurpleAttentionType object and sets its mandatory parameters.
- * Returns: A pointer to the new object.
-PurpleAttentionType *purple_attention_type_new(const char *ulname, const char *name,
- const char *inc_desc, const char *out_desc);
- * purple_attention_type_set_name:
- * @type: The attention type.
- * @name: The localized name that will be displayed by UIs. This should be
- * the same string given as the unlocalized name, but with
- * Sets the displayed name of the attention-demanding event.
-void purple_attention_type_set_name(PurpleAttentionType *type, const char *name);
- * purple_attention_type_set_incoming_desc:
- * @type: The attention type.
- * @desc: The localized description for incoming events.
- * Sets the description of the attention-demanding event shown in conversations
- * when the event is received.
-void purple_attention_type_set_incoming_desc(PurpleAttentionType *type, const char *desc);
- * purple_attention_type_set_outgoing_desc:
- * @type: The attention type.
- * @desc: The localized description for outgoing events.
- * Sets the description of the attention-demanding event shown in conversations
- * when the event is sent.
-void purple_attention_type_set_outgoing_desc(PurpleAttentionType *type, const char *desc);
- * purple_attention_type_set_icon_name:
- * @type: The attention type.
- * @name: The icon's name.
- * Sets the name of the icon to display for the attention event; this is optional.
- * Note: Icons are optional for attention events.
-void purple_attention_type_set_icon_name(PurpleAttentionType *type, const char *name);
- * purple_attention_type_set_unlocalized_name:
- * @type: The attention type.
- * @ulname: The unlocalized name. This should be the same string given as
- * the localized name, but without localization.
- * Sets the unlocalized name of the attention event; some UIs may need this,
-void purple_attention_type_set_unlocalized_name(PurpleAttentionType *type, const char *ulname);
- * purple_attention_type_get_name:
- * @type: The attention type.
- * Get the attention type's name as displayed by the UI.
-const char *purple_attention_type_get_name(const PurpleAttentionType *type);
- * purple_attention_type_get_incoming_desc:
- * @type: The attention type.
- * Get the attention type's description shown when the event is received.
- * Returns: The description.
-const char *purple_attention_type_get_incoming_desc(const PurpleAttentionType *type);
- * purple_attention_type_get_outgoing_desc:
- * @type: The attention type.
- * Get the attention type's description shown when the event is sent.
- * Returns: The description.
-const char *purple_attention_type_get_outgoing_desc(const PurpleAttentionType *type);
- * purple_attention_type_get_icon_name:
- * @type: The attention type.
- * Get the attention type's icon name.
- * Note: Icons are optional for attention events.
- * Returns: The icon name or %NULL if unset/empty.
-const char *purple_attention_type_get_icon_name(const PurpleAttentionType *type);
- * purple_attention_type_get_unlocalized_name:
- * @type: The attention type
- * Get the attention type's unlocalized name; this is useful for some UIs.
- * Returns: The unlocalized name.
-const char *purple_attention_type_get_unlocalized_name(const PurpleAttentionType *type);
/**************************************************************************/
/* Protocol Action API */
/**************************************************************************/
--- a/libpurple/protocols/jabber/jabber.c Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/protocols/jabber/jabber.c Fri Feb 02 06:28:13 2018 +0000
@@ -3168,7 +3168,7 @@
return _jabber_send_buzz(js, who, error) ? PURPLE_CMD_RET_OK : PURPLE_CMD_RET_FAILED;
-GList *jabber_attention_types(PurpleAccount *account)
+GList *jabber_attention_types(PurpleProtocolAttention *attn, PurpleAccount *account) static GList *types = NULL;
@@ -3180,7 +3180,7 @@
-gboolean jabber_send_attention(PurpleConnection *gc, const char *username, guint code)
+gboolean jabber_send_attention(PurpleProtocolAttention *attn, PurpleConnection *gc, const char *username, guint code) JabberStream *js = purple_connection_get_protocol_data(gc);
@@ -4127,10 +4127,10 @@
-jabber_protocol_attention_iface_init(PurpleProtocolAttentionIface *attention_iface)
+jabber_protocol_attention_iface_init(PurpleProtocolAttentionInterface *iface) - attention_iface->send = jabber_send_attention;
- attention_iface->get_types = jabber_attention_types;
+ iface->send = jabber_send_attention; + iface->get_types = jabber_attention_types; @@ -4169,7 +4169,7 @@
PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_ROOMLIST_IFACE,
jabber_protocol_roomlist_iface_init)
- PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_ATTENTION_IFACE,
+ PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_ATTENTION, jabber_protocol_attention_iface_init)
PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_MEDIA_IFACE,
--- a/libpurple/protocols/jabber/jabber.h Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/protocols/jabber/jabber.h Fri Feb 02 06:28:13 2018 +0000
@@ -59,6 +59,7 @@
#include "circularbuffer.h"
@@ -418,8 +419,8 @@
void jabber_register_gateway(JabberStream *js, const char *gateway);
void jabber_register_account(PurpleAccount *account);
void jabber_unregister_account(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data);
-gboolean jabber_send_attention(PurpleConnection *gc, const char *username, guint code);
-GList *jabber_attention_types(PurpleAccount *account);
+gboolean jabber_send_attention(PurpleProtocolAttention *attn, PurpleConnection *gc, const char *username, guint code); +GList *jabber_attention_types(PurpleProtocolAttention *attn, PurpleAccount *account); void jabber_convo_closed(PurpleConnection *gc, const char *who);
PurpleChat *jabber_find_blist_chat(PurpleAccount *account, const char *name);
gboolean jabber_offline_message(const PurpleBuddy *buddy);
--- a/libpurple/server.c Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/server.c Fri Feb 02 06:28:13 2018 +0000
@@ -295,10 +295,10 @@
protocol = purple_protocols_find(purple_account_get_protocol_id(account));
/* Lookup the attention type in the protocol's attention_types list, if any. */
- if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, ATTENTION_IFACE, get_types)) {
+ if (PURPLE_IS_PROTOCOL_ATTENTION(protocol)) { - attention_types = purple_protocol_attention_iface_get_types(protocol, account);
+ attention_types = purple_protocol_attention_get_types(protocol, account); attn = (PurpleAttentionType *)g_list_nth_data(attention_types, type_code);
--- a/libpurple/server.h Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/server.h Fri Feb 02 06:28:13 2018 +0000
@@ -29,6 +29,7 @@
#include "conversations.h"
--- a/libpurple/tests/meson.build Fri Jan 26 05:03:09 2018 +0000
+++ b/libpurple/tests/meson.build Fri Feb 02 06:28:13 2018 +0000
@@ -1,5 +1,7 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_attention_type.c Fri Feb 02 06:28:13 2018 +0000
@@ -0,0 +1,181 @@
+ * Purple 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA +#include "dbus-server.h" +/****************************************************************************** + *****************************************************************************/ +test_purple_attention_type_new(void) { + PurpleAttentionType *type = NULL; + type = purple_attention_type_new("id", "name", "incoming", "outgoing"); + /* check the values new sets */ + g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type), ==, "id"); + g_assert_cmpstr(purple_attention_type_get_name(type), ==, "name"); + g_assert_cmpstr(purple_attention_type_get_incoming_desc(type), ==, "incoming"); + g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type), ==, "outgoing"); + /* check that default values are correct */ + g_assert_cmpstr(purple_attention_type_get_icon_name(type), ==, NULL); +test_purple_attention_type_copy(void) { + PurpleAttentionType *type1 = NULL, *type2 = NULL; + type1 = purple_attention_type_new("id", "name", "incoming", "outgoing"); + type2 = purple_attention_type_copy(type1); + /* check the values new sets */ + g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type2), ==, "id"); + g_assert_cmpstr(purple_attention_type_get_name(type2), ==, "name"); + g_assert_cmpstr(purple_attention_type_get_incoming_desc(type2), ==, "incoming"); + g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type2), ==, "outgoing"); + /* check that default values are correct */ + g_assert_cmpstr(purple_attention_type_get_icon_name(type2), ==, NULL); +test_purple_attention_type_set_unlocalized_name(void) { + PurpleAttentionType *type = NULL; + type = purple_attention_type_new("id", "name", "incoming", "outgoing"); + purple_attention_type_set_unlocalized_name(type, "this-is-my-id"); + g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type), ==, "this-is-my-id"); +test_purple_attention_type_set_name(void) { + PurpleAttentionType *type = NULL; + type = purple_attention_type_new("id", "name", "incoming", "outgoing"); + purple_attention_type_set_name(type, "this-is-my-name"); + g_assert_cmpstr(purple_attention_type_get_name(type), ==, "this-is-my-name"); +test_purple_attention_type_set_incoming_desc(void) { + PurpleAttentionType *type = NULL; + type = purple_attention_type_new("id", "name", "incoming", "outgoing"); + purple_attention_type_set_incoming_desc(type, "this-is-my-incoming-desc"); + g_assert_cmpstr(purple_attention_type_get_incoming_desc(type), ==, "this-is-my-incoming-desc"); +test_purple_attention_type_set_outgoing_desc(void) { + PurpleAttentionType *type = NULL; + type = purple_attention_type_new("id", "name", "incoming", "outgoing"); + purple_attention_type_set_outgoing_desc(type, "this-is-my-outgoing-desc"); + g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type), ==, "this-is-my-outgoing-desc"); +test_purple_attention_type_set_icon_name(void) { + PurpleAttentionType *type = NULL; + type = purple_attention_type_new("id", "name", "incoming", "outgoing"); + purple_attention_type_set_icon_name(type, "this-is-my-icon-name"); + g_assert_cmpstr(purple_attention_type_get_icon_name(type), ==, "this-is-my-icon-name"); +/****************************************************************************** + *****************************************************************************/ +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + g_test_set_nonfatal_assertions(); + test_purple_attention_type_new + "/attention-type/copy", + test_purple_attention_type_copy + "/attention-type/set-unlocalized-name", + test_purple_attention_type_set_unlocalized_name + "/attention-type/set-name", + test_purple_attention_type_set_name + "/attention-type/set-incoming-desc", + test_purple_attention_type_set_incoming_desc + "/attention-type/set-outgoing-desc", + test_purple_attention_type_set_outgoing_desc + "/attention-type/set-icon-name", + test_purple_attention_type_set_icon_name --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_protocol_attention.c Fri Feb 02 06:28:13 2018 +0000
@@ -0,0 +1,156 @@
+ * Purple 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA +#include "dbus-server.h" +/****************************************************************************** + * PurpleProtcolAttention Implementations + *****************************************************************************/ +static GType test_purple_protocol_attention_get_type(void); +} TestPurpleProtocolAttention; + PurpleProtocolClass parent; +} TestPurpleProtocolAttentionClass; +test_purple_protocol_attention_send(PurpleProtocolAttention *attn, PurpleConnection *c, const gchar *username, guint type) { + TestPurpleProtocolAttention *test_attn = (TestPurpleProtocolAttention *)attn; + test_attn->send_called = TRUE; +test_purple_protocol_attention_get_types(PurpleProtocolAttention *attn, PurpleAccount *acct) { + types = g_list_append(types, purple_attention_type_new("id", "name", "incoming", "outgoing")); +test_purple_protocol_attention_iface_init(PurpleProtocolAttentionInterface *iface) { + iface->send = test_purple_protocol_attention_send; + iface->get_types = test_purple_protocol_attention_get_types; +G_DEFINE_TYPE_WITH_CODE( + TestPurpleProtocolAttention, + test_purple_protocol_attention, + PURPLE_TYPE_PROTOCOL_ATTENTION, + test_purple_protocol_attention_iface_init +test_purple_protocol_attention_init(TestPurpleProtocolAttention *prplattn) { + PurpleProtocol *prpl = PURPLE_PROTOCOL(prplattn); + prpl->id = "prpl-attention"; +test_purple_protocol_attention_class_init(TestPurpleProtocolAttentionClass *klass) { +/****************************************************************************** + *****************************************************************************/ +test_purple_protocol_attention_can_send(void) { + TestPurpleProtocolAttention *attn = g_object_new(test_purple_protocol_attention_get_type(), NULL); + PurpleAccount *a = purple_account_new("prpl-attn-can-send", "prpl-attn"); + PurpleConnection *c = g_object_new(PURPLE_TYPE_CONNECTION, "account", a, NULL); + gboolean actual = FALSE; + attn->send_called = FALSE; + actual = purple_protocol_attention_send(PURPLE_PROTOCOL_ATTENTION(attn), c, "someguy", 0); + g_assert_true(attn->send_called); +test_purple_protocol_attention_can_get_types(void) { + TestPurpleProtocolAttention *attn = g_object_new(test_purple_protocol_attention_get_type(), NULL); + PurpleAccount *a = purple_account_new("prpl-attn-can-get-types", "prpl-attn"); + PurpleAttentionType *type = NULL; + types = purple_protocol_attention_get_types(PURPLE_PROTOCOL_ATTENTION(attn), a); + g_assert_true(g_list_length(types) == 1); + /* take the first item and cast it into type */ + type = (PurpleAttentionType *)(types->data); + g_assert_cmpstr(purple_attention_type_get_unlocalized_name(type), ==, "id"); + g_assert_cmpstr(purple_attention_type_get_name(type), ==, "name"); + g_assert_cmpstr(purple_attention_type_get_incoming_desc(type), ==, "incoming"); + g_assert_cmpstr(purple_attention_type_get_outgoing_desc(type), ==, "outgoing"); +/****************************************************************************** + *****************************************************************************/ +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + g_test_set_nonfatal_assertions(); + "/protocol-attention/send", + test_purple_protocol_attention_can_send + "/protocol-attention/get-types", + test_purple_protocol_attention_can_get_types --- a/pidgin/gtkconv.c Fri Jan 26 05:03:09 2018 +0000
+++ b/pidgin/gtkconv.c Fri Feb 02 06:28:13 2018 +0000
@@ -31,6 +31,7 @@
#include <gdk/gdkkeysyms.h>
@@ -3444,8 +3445,8 @@
protocol = purple_connection_get_protocol(pc);
- if (protocol && PURPLE_PROTOCOL_IMPLEMENTS(protocol, ATTENTION_IFACE, get_types)) {
- list = purple_protocol_attention_iface_get_types(protocol, purple_connection_get_account(pc));
+ if (protocol && PURPLE_IS_PROTOCOL_ATTENTION(protocol)) { + list = purple_protocol_attention_get_types(PURPLE_PROTOCOL_ATTENTION(protocol), purple_connection_get_account(pc)); /* Multiple attention types */
if (list && list->next) {
@@ -7432,7 +7433,7 @@
gtk_action_set_sensitive(win->menu->add, (PURPLE_PROTOCOL_IMPLEMENTS(protocol, SERVER_IFACE, add_buddy)));
gtk_action_set_sensitive(win->menu->remove, (PURPLE_PROTOCOL_IMPLEMENTS(protocol, SERVER_IFACE, remove_buddy)));
gtk_action_set_sensitive(win->menu->send_file, can_send_file);
- gtk_action_set_sensitive(win->menu->get_attention, (PURPLE_PROTOCOL_IMPLEMENTS(protocol, ATTENTION_IFACE, send)));
+ gtk_action_set_sensitive(win->menu->get_attention, (PURPLE_IS_PROTOCOL_ATTENTION(protocol))); gtk_action_set_sensitive(win->menu->alias,
(purple_blist_find_buddy(account, purple_conversation_get_name(conv)) != NULL));
--- a/pidgin/gtkwebviewtoolbar.c Fri Jan 26 05:03:09 2018 +0000
+++ b/pidgin/gtkwebviewtoolbar.c Fri Feb 02 06:28:13 2018 +0000
@@ -1682,7 +1682,7 @@
for the time being it is always disabled for chats */
gtk_action_set_sensitive(priv->attention,
conv && protocol && PURPLE_IS_IM_CONVERSATION(conv) &&
- PURPLE_PROTOCOL_IMPLEMENTS(protocol, ATTENTION_IFACE, send));
+ PURPLE_IS_PROTOCOL_ATTENTION(protocol)); update_smiley_button(toolbar);