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 * Sets the events a pounce should watch for.
128 * @param pounce The buddy pounce.
129 * @param events The events to watch for.
131 void purple_pounce_set_events(PurplePounce *pounce, PurplePounceEvent events);
134 * Sets the options for a pounce.
136 * @param pounce The buddy pounce.
137 * @param options The options for the pounce.
139 void purple_pounce_set_options(PurplePounce *pounce, PurplePounceOption options);
142 * Sets the account that will do the pouncing.
144 * @param pounce The buddy pounce.
145 * @param pouncer The account that will pounce.
147 void purple_pounce_set_pouncer(PurplePounce *pounce, PurpleAccount *pouncer);
150 * Sets the buddy a pounce should pounce on.
152 * @param pounce The buddy pounce.
153 * @param pouncee The buddy to pounce on.
155 void purple_pounce_set_pouncee(PurplePounce *pounce, const char *pouncee);
158 * Sets whether or not the pounce should be saved after execution.
160 * @param pounce The buddy pounce.
161 * @param save @c TRUE if the pounce should be saved, or @c FALSE otherwise.
163 void purple_pounce_set_save(PurplePounce *pounce, gboolean save);
166 * Registers an action type for the pounce.
168 * @param pounce The buddy pounce.
169 * @param name The action name.
171 void purple_pounce_action_register(PurplePounce *pounce, const char *name);
174 * Enables or disables an action for a pounce.
176 * @param pounce The buddy pounce.
177 * @param action The name of the action.
178 * @param enabled The enabled state.
180 void purple_pounce_action_set_enabled(PurplePounce *pounce, const char *action,
184 * Sets a value for an attribute in an action.
186 * If @a value is @c NULL, the value will be unset.
188 * @param pounce The buddy pounce.
189 * @param action The action name.
190 * @param attr The attribute name.
191 * @param value The value.
193 void purple_pounce_action_set_attribute(PurplePounce *pounce, const char *action,
194 const char *attr, const char *value);
197 * Sets the pounce-specific data.
199 * @param pounce The buddy pounce.
200 * @param data Data specific to the pounce.
202 void purple_pounce_set_data(PurplePounce *pounce, void *data);
205 * Returns the events a pounce should watch for.
207 * @param pounce The buddy pounce.
209 * @return The events the pounce is watching for.
211 PurplePounceEvent purple_pounce_get_events(const PurplePounce *pounce);
214 * Returns the options for a pounce.
216 * @param pounce The buddy pounce.
218 * @return The options for the pounce.
220 PurplePounceOption purple_pounce_get_options(const PurplePounce *pounce);
223 * Returns the account that will do the pouncing.
225 * @param pounce The buddy pounce.
227 * @return The account that will pounce.
229 PurpleAccount *purple_pounce_get_pouncer(const PurplePounce *pounce);
232 * Returns the buddy a pounce should pounce on.
234 * @param pounce The buddy pounce.
236 * @return The buddy to pounce on.
238 const char *purple_pounce_get_pouncee(const PurplePounce *pounce);
241 * Returns whether or not the pounce should save after execution.
243 * @param pounce The buddy pounce.
245 * @return @c TRUE if the pounce should be saved after execution, or
246 * @c FALSE otherwise.
248 gboolean purple_pounce_get_save(const PurplePounce *pounce);
251 * Returns whether or not an action is enabled.
253 * @param pounce The buddy pounce.
254 * @param action The action name.
256 * @return @c TRUE if the action is enabled, or @c FALSE otherwise.
258 gboolean purple_pounce_action_is_enabled(const PurplePounce *pounce,
262 * Returns the value for an attribute in an action.
264 * @param pounce The buddy pounce.
265 * @param action The action name.
266 * @param attr The attribute name.
268 * @return The attribute value, if it exists, or @c NULL.
270 const char *purple_pounce_action_get_attribute(const PurplePounce *pounce,
275 * Returns the pounce-specific data.
277 * @param pounce The buddy pounce.
279 * @return The data specific to a buddy pounce.
281 void *purple_pounce_get_data(const PurplePounce *pounce);
284 * Executes a pounce with the specified pouncer, pouncee, and event type.
286 * @param pouncer The account that will do the pouncing.
287 * @param pouncee The buddy that is being pounced.
288 * @param events The events that triggered the pounce.
290 void purple_pounce_execute(const PurpleAccount *pouncer, const char *pouncee,
291 PurplePounceEvent events);
295 /**************************************************************************/
296 /** @name Buddy Pounce Subsystem API */
297 /**************************************************************************/
301 * Finds a pounce with the specified event(s) and buddy.
303 * @param pouncer The account to match against.
304 * @param pouncee The buddy to match against.
305 * @param events The event(s) to match against.
307 * @return The pounce if found, or @c NULL otherwise.
309 PurplePounce *purple_find_pounce(const PurpleAccount *pouncer,
310 const char *pouncee, PurplePounceEvent events);
316 * @return @c TRUE if the pounces could be loaded.
318 gboolean purple_pounces_load(void);
321 * Registers a pounce handler for a UI.
323 * @param ui The UI name.
324 * @param cb The callback function.
325 * @param new_pounce The function called when a pounce is created.
326 * @param free_pounce The function called when a pounce is freed.
328 void purple_pounces_register_handler(const char *ui, PurplePounceCb cb,
329 void (*new_pounce)(PurplePounce *pounce),
330 void (*free_pounce)(PurplePounce *pounce));
333 * Unregisters a pounce handle for a UI.
335 * @param ui The UI name.
337 void purple_pounces_unregister_handler(const char *ui);
340 * Returns a list of all registered buddy pounces.
342 * @constreturn The list of buddy pounces.
344 GList *purple_pounces_get_all(void);
347 * Returns a list of registered buddy pounces for the ui-type.
349 * @param ui The ID of the UI using the core.
351 * @return The list of buddy pounces. The list should be freed by
352 * the caller when it's no longer used.
355 GList *purple_pounces_get_all_for_ui(const char *ui);
358 * Returns the buddy pounce subsystem handle.
360 * @return The subsystem handle.
362 void *purple_pounces_get_handle(void);
365 * Initializes the pounces subsystem.
367 void purple_pounces_init(void);
370 * Uninitializes the pounces subsystem.
372 void purple_pounces_uninit(void);
380 #endif /* _PURPLE_POUNCE_H_ */