2 * @file pounce.h Buddy Pounce API
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #ifndef _PURPLE_POUNCE_H_
27 #define _PURPLE_POUNCE_H_
29 typedef struct _PurplePounce PurplePounce
;
35 * Events that trigger buddy pounces.
39 PURPLE_POUNCE_NONE
= 0x000, /**< No events. */
40 PURPLE_POUNCE_SIGNON
= 0x001, /**< The buddy signed on. */
41 PURPLE_POUNCE_SIGNOFF
= 0x002, /**< The buddy signed off. */
42 PURPLE_POUNCE_AWAY
= 0x004, /**< The buddy went away. */
43 PURPLE_POUNCE_AWAY_RETURN
= 0x008, /**< The buddy returned from away. */
44 PURPLE_POUNCE_IDLE
= 0x010, /**< The buddy became idle. */
45 PURPLE_POUNCE_IDLE_RETURN
= 0x020, /**< The buddy is no longer idle. */
46 PURPLE_POUNCE_TYPING
= 0x040, /**< The buddy started typing. */
47 PURPLE_POUNCE_TYPED
= 0x080, /**< The buddy has entered text. */
48 PURPLE_POUNCE_TYPING_STOPPED
= 0x100, /**< The buddy stopped typing. */
49 PURPLE_POUNCE_MESSAGE_RECEIVED
= 0x200 /**< The buddy sent a message */
55 PURPLE_POUNCE_OPTION_NONE
= 0x00, /**< No Option */
56 PURPLE_POUNCE_OPTION_AWAY
= 0x01 /**< Pounce only when away */
59 /** A pounce callback. */
60 typedef void (*PurplePounceCb
)(PurplePounce
*, PurplePounceEvent
, void *);
63 * A buddy pounce structure.
65 * Buddy pounces are actions triggered by a buddy-related event. For
66 * example, a sound can be played or an IM window opened when a buddy
67 * signs on or returns from away. Such responses are handled in the
68 * UI. The events themselves are done in the core.
72 char *ui_type
; /**< The type of UI. */
74 PurplePounceEvent events
; /**< The event(s) to pounce on. */
75 PurplePounceOption options
; /**< The pounce options */
76 PurpleAccount
*pouncer
; /**< The user who is pouncing. */
78 char *pouncee
; /**< The buddy to pounce on. */
80 GHashTable
*actions
; /**< The registered actions. */
82 gboolean save
; /**< Whether or not the pounce should
83 be saved after activation. */
84 void *data
; /**< Pounce-specific data. */
91 /**************************************************************************/
92 /** @name Buddy Pounce API */
93 /**************************************************************************/
97 * Creates a new buddy pounce.
99 * @param ui_type The type of UI the pounce is for.
100 * @param pouncer The account that will pounce.
101 * @param pouncee The buddy to pounce on.
102 * @param event The event(s) to pounce on.
103 * @param option Pounce options.
105 * @return The new buddy pounce structure.
107 PurplePounce
*purple_pounce_new(const char *ui_type
, PurpleAccount
*pouncer
,
108 const char *pouncee
, PurplePounceEvent event
,
109 PurplePounceOption option
);
112 * Destroys a buddy pounce.
114 * @param pounce The buddy pounce.
116 void purple_pounce_destroy(PurplePounce
*pounce
);
119 * Destroys all buddy pounces for the account
121 * @param account The account to remove all pounces from.
123 void purple_pounce_destroy_all_by_account(PurpleAccount
*account
);
126 * Destroys all buddy pounces for a buddy
128 * @param buddy The buddy whose pounces are to be removed
132 void purple_pounce_destroy_all_by_buddy(PurpleBuddy
*buddy
);
135 * Sets the events a pounce should watch for.
137 * @param pounce The buddy pounce.
138 * @param events The events to watch for.
140 void purple_pounce_set_events(PurplePounce
*pounce
, PurplePounceEvent events
);
143 * Sets the options for a pounce.
145 * @param pounce The buddy pounce.
146 * @param options The options for the pounce.
148 void purple_pounce_set_options(PurplePounce
*pounce
, PurplePounceOption options
);
151 * Sets the account that will do the pouncing.
153 * @param pounce The buddy pounce.
154 * @param pouncer The account that will pounce.
156 void purple_pounce_set_pouncer(PurplePounce
*pounce
, PurpleAccount
*pouncer
);
159 * Sets the buddy a pounce should pounce on.
161 * @param pounce The buddy pounce.
162 * @param pouncee The buddy to pounce on.
164 void purple_pounce_set_pouncee(PurplePounce
*pounce
, const char *pouncee
);
167 * Sets whether or not the pounce should be saved after execution.
169 * @param pounce The buddy pounce.
170 * @param save @c TRUE if the pounce should be saved, or @c FALSE otherwise.
172 void purple_pounce_set_save(PurplePounce
*pounce
, gboolean save
);
175 * Registers an action type for the pounce.
177 * @param pounce The buddy pounce.
178 * @param name The action name.
180 void purple_pounce_action_register(PurplePounce
*pounce
, const char *name
);
183 * Enables or disables an action for a pounce.
185 * @param pounce The buddy pounce.
186 * @param action The name of the action.
187 * @param enabled The enabled state.
189 void purple_pounce_action_set_enabled(PurplePounce
*pounce
, const char *action
,
193 * Sets a value for an attribute in an action.
195 * If @a value is @c NULL, the value will be unset.
197 * @param pounce The buddy pounce.
198 * @param action The action name.
199 * @param attr The attribute name.
200 * @param value The value.
202 void purple_pounce_action_set_attribute(PurplePounce
*pounce
, const char *action
,
203 const char *attr
, const char *value
);
206 * Sets the pounce-specific data.
208 * @param pounce The buddy pounce.
209 * @param data Data specific to the pounce.
211 void purple_pounce_set_data(PurplePounce
*pounce
, void *data
);
214 * Returns the events a pounce should watch for.
216 * @param pounce The buddy pounce.
218 * @return The events the pounce is watching for.
220 PurplePounceEvent
purple_pounce_get_events(const PurplePounce
*pounce
);
223 * Returns the options for a pounce.
225 * @param pounce The buddy pounce.
227 * @return The options for the pounce.
229 PurplePounceOption
purple_pounce_get_options(const PurplePounce
*pounce
);
232 * Returns the account that will do the pouncing.
234 * @param pounce The buddy pounce.
236 * @return The account that will pounce.
238 PurpleAccount
*purple_pounce_get_pouncer(const PurplePounce
*pounce
);
241 * Returns the buddy a pounce should pounce on.
243 * @param pounce The buddy pounce.
245 * @return The buddy to pounce on.
247 const char *purple_pounce_get_pouncee(const PurplePounce
*pounce
);
250 * Returns whether or not the pounce should save after execution.
252 * @param pounce The buddy pounce.
254 * @return @c TRUE if the pounce should be saved after execution, or
255 * @c FALSE otherwise.
257 gboolean
purple_pounce_get_save(const PurplePounce
*pounce
);
260 * Returns whether or not an action is enabled.
262 * @param pounce The buddy pounce.
263 * @param action The action name.
265 * @return @c TRUE if the action is enabled, or @c FALSE otherwise.
267 gboolean
purple_pounce_action_is_enabled(const PurplePounce
*pounce
,
271 * Returns the value for an attribute in an action.
273 * @param pounce The buddy pounce.
274 * @param action The action name.
275 * @param attr The attribute name.
277 * @return The attribute value, if it exists, or @c NULL.
279 const char *purple_pounce_action_get_attribute(const PurplePounce
*pounce
,
284 * Returns the pounce-specific data.
286 * @param pounce The buddy pounce.
288 * @return The data specific to a buddy pounce.
290 void *purple_pounce_get_data(const PurplePounce
*pounce
);
293 * Executes a pounce with the specified pouncer, pouncee, and event type.
295 * @param pouncer The account that will do the pouncing.
296 * @param pouncee The buddy that is being pounced.
297 * @param events The events that triggered the pounce.
299 void purple_pounce_execute(const PurpleAccount
*pouncer
, const char *pouncee
,
300 PurplePounceEvent events
);
304 /**************************************************************************/
305 /** @name Buddy Pounce Subsystem API */
306 /**************************************************************************/
310 * Finds a pounce with the specified event(s) and buddy.
312 * @param pouncer The account to match against.
313 * @param pouncee The buddy to match against.
314 * @param events The event(s) to match against.
316 * @return The pounce if found, or @c NULL otherwise.
318 PurplePounce
*purple_find_pounce(const PurpleAccount
*pouncer
,
319 const char *pouncee
, PurplePounceEvent events
);
325 * @return @c TRUE if the pounces could be loaded.
327 gboolean
purple_pounces_load(void);
330 * Registers a pounce handler for a UI.
332 * @param ui The UI name.
333 * @param cb The callback function.
334 * @param new_pounce The function called when a pounce is created.
335 * @param free_pounce The function called when a pounce is freed.
337 void purple_pounces_register_handler(const char *ui
, PurplePounceCb cb
,
338 void (*new_pounce
)(PurplePounce
*pounce
),
339 void (*free_pounce
)(PurplePounce
*pounce
));
342 * Unregisters a pounce handle for a UI.
344 * @param ui The UI name.
346 void purple_pounces_unregister_handler(const char *ui
);
349 * Returns a list of all registered buddy pounces.
351 * @constreturn The list of buddy pounces.
353 GList
*purple_pounces_get_all(void);
356 * Returns a list of registered buddy pounces for the ui-type.
358 * @param ui The ID of the UI using the core.
360 * @return The list of buddy pounces. The list should be freed by
361 * the caller when it's no longer used.
364 GList
*purple_pounces_get_all_for_ui(const char *ui
);
367 * Returns the buddy pounce subsystem handle.
369 * @return The subsystem handle.
371 void *purple_pounces_get_handle(void);
374 * Initializes the pounces subsystem.
376 void purple_pounces_init(void);
379 * Uninitializes the pounces subsystem.
381 void purple_pounces_uninit(void);
389 #endif /* _PURPLE_POUNCE_H_ */