Merged in default (pull request #594)
[pidgin-git.git] / libpurple / attention.c
blobcf967bd437c85c0af3bd6c802cdf6cde576e36c5
1 /* purple
3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #include "attention.h"
24 /******************************************************************************
25 * PurpleAttentionType API
26 *****************************************************************************/
27 struct _PurpleAttentionType {
28 const gchar *name;
29 const gchar *incoming_description;
30 const gchar *outgoing_description;
31 const gchar *icon_name;
32 const gchar *unlocalized_name;
35 G_DEFINE_BOXED_TYPE(
36 PurpleAttentionType,
37 purple_attention_type,
38 purple_attention_type_copy,
39 g_free
42 PurpleAttentionType *
43 purple_attention_type_new(const gchar *unlocalized_name,
44 const gchar *name,
45 const gchar *incoming_description,
46 const gchar *outgoing_description)
48 PurpleAttentionType *attn = g_new0(PurpleAttentionType, 1);
50 attn->unlocalized_name = unlocalized_name;
51 attn->name = name;
52 attn->incoming_description = incoming_description;
53 attn->outgoing_description = outgoing_description;
55 return attn;
58 PurpleAttentionType *
59 purple_attention_type_copy(PurpleAttentionType *attn) {
60 PurpleAttentionType *attn_copy = NULL;
62 g_return_val_if_fail(attn != NULL, NULL);
64 attn_copy = g_new(PurpleAttentionType, 1);
65 *attn_copy = *attn;
67 return attn_copy;
70 const gchar *
71 purple_attention_type_get_name(const PurpleAttentionType *type) {
72 g_return_val_if_fail(type, NULL);
74 return type->name;
77 void
78 purple_attention_type_set_name(PurpleAttentionType *type, const gchar *name) {
79 g_return_if_fail(type);
81 type->name = name;
84 const gchar *
85 purple_attention_type_get_incoming_desc(const PurpleAttentionType *type) {
86 g_return_val_if_fail(type, NULL);
88 return type->incoming_description;
91 void
92 purple_attention_type_set_incoming_desc(PurpleAttentionType *type, const gchar *desc) {
93 g_return_if_fail(type);
95 type->incoming_description = desc;
98 const gchar *
99 purple_attention_type_get_outgoing_desc(const PurpleAttentionType *type) {
100 g_return_val_if_fail(type, NULL);
102 return type->outgoing_description;
105 void
106 purple_attention_type_set_outgoing_desc(PurpleAttentionType *type, const gchar *desc) {
107 g_return_if_fail(type != NULL);
109 type->outgoing_description = desc;
112 const gchar *
113 purple_attention_type_get_icon_name(const PurpleAttentionType *type) {
114 g_return_val_if_fail(type, NULL);
116 if(type->icon_name == NULL || *(type->icon_name) == '\0')
117 return NULL;
119 return type->icon_name;
122 void
123 purple_attention_type_set_icon_name(PurpleAttentionType *type, const gchar *name) {
124 g_return_if_fail(type);
126 type->icon_name = name;
129 const gchar *
130 purple_attention_type_get_unlocalized_name(const PurpleAttentionType *type) {
131 g_return_val_if_fail(type, NULL);
133 return type->unlocalized_name;
136 void
137 purple_attention_type_set_unlocalized_name(PurpleAttentionType *type, const gchar *ulname) {
138 g_return_if_fail(type);
140 type->unlocalized_name = ulname;
143 /******************************************************************************
144 * PurpleAttentionType API
145 *****************************************************************************/
146 G_DEFINE_INTERFACE(PurpleProtocolAttention, purple_protocol_attention, G_TYPE_INVALID);
148 static void
149 purple_protocol_attention_default_init(PurpleProtocolAttentionInterface *iface) {
152 gboolean
153 purple_protocol_attention_send(PurpleProtocolAttention *attn, PurpleConnection *gc, const gchar *username, guint type) {
154 PurpleProtocolAttentionInterface *iface = NULL;
156 g_return_val_if_fail(PURPLE_IS_PROTOCOL_ATTENTION(attn), FALSE);
158 iface = PURPLE_PROTOCOL_ATTENTION_GET_IFACE(attn);
159 if(iface && iface->send) {
160 return iface->send(attn, gc, username, type);
163 return FALSE;
166 GList *
167 purple_protocol_attention_get_types(PurpleProtocolAttention *attn, PurpleAccount *account) {
168 PurpleProtocolAttentionInterface *iface = NULL;
170 g_return_val_if_fail(PURPLE_IS_PROTOCOL_ATTENTION(attn), NULL);
172 iface = PURPLE_PROTOCOL_ATTENTION_GET_IFACE(attn);
173 if(iface && iface->get_types) {
174 return iface->get_types(attn, account);
177 return NULL;