Disable installing plugins that aren't built.
[pidgin-git.git] / libpurple / cmds.h
blob8dbf34cbc134b8a1775ee811923bed2dce0309c4
1 /* Copyright (C) 2003 Timothy Ringenbach <omarvo@hotmail.com>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
19 #ifndef PURPLE_CMDS_H
20 #define PURPLE_CMDS_H
21 /**
22 * SECTION:cmds
23 * @section_id: libpurple-cmds
24 * @short_description: <filename>cmds.h</filename>
25 * @title: Commands API
26 * @see_also: <link linkend="chapter-signals-cmd">Command signals</link>
29 #include "conversation.h"
31 /**************************************************************************/
32 /* Structures */
33 /**************************************************************************/
35 /**
36 * PurpleCmdStatus:
38 * The possible results of running a command with purple_cmd_do_command().
40 typedef enum {
41 PURPLE_CMD_STATUS_OK,
42 PURPLE_CMD_STATUS_FAILED,
43 PURPLE_CMD_STATUS_NOT_FOUND,
44 PURPLE_CMD_STATUS_WRONG_ARGS,
45 PURPLE_CMD_STATUS_WRONG_PROTOCOL,
46 PURPLE_CMD_STATUS_WRONG_TYPE
47 } PurpleCmdStatus;
49 /**
50 * PurpleCmdRet:
51 * @PURPLE_CMD_RET_OK: Everything's okay; Don't look for another command
52 * to call.
53 * @PURPLE_CMD_RET_FAILED: The command failed, but stop looking.
54 * @PURPLE_CMD_RET_CONTINUE: Continue, looking for other commands with the same
55 * name to call.
57 * Commands registered with the core return one of these values when run.
58 * Normally, a command will want to return one of the first two; in some
59 * unusual cases, you might want to have several functions called for a
60 * particular command; in this case, they should return
61 * #PURPLE_CMD_RET_CONTINUE to cause the core to fall through to other
62 * commands with the same name.
64 typedef enum {
65 PURPLE_CMD_RET_OK,
66 PURPLE_CMD_RET_FAILED,
67 PURPLE_CMD_RET_CONTINUE
68 } PurpleCmdRet;
70 #define PURPLE_CMD_FUNC(func) ((PurpleCmdFunc)func)
72 /**
73 * PurpleCmdFunc:
75 * A function implementing a command, as passed to purple_cmd_register().
77 /* TODO document the arguments to these functions. */
78 typedef PurpleCmdRet (*PurpleCmdFunc)(PurpleConversation *conversation, const gchar *cmd,
79 gchar **args, gchar **error, void *data);
80 /**
81 * PurpleCmdId:
83 * A unique integer representing a command registered with
84 * purple_cmd_register(), which can subsequently be passed to
85 * purple_cmd_unregister() to unregister that command.
87 typedef guint PurpleCmdId;
89 typedef enum {
90 PURPLE_CMD_P_VERY_LOW = -1000,
91 PURPLE_CMD_P_LOW = 0,
92 PURPLE_CMD_P_DEFAULT = 1000,
93 PURPLE_CMD_P_PROTOCOL = 2000,
94 PURPLE_CMD_P_PLUGIN = 3000,
95 PURPLE_CMD_P_ALIAS = 4000,
96 PURPLE_CMD_P_HIGH = 5000,
97 PURPLE_CMD_P_VERY_HIGH = 6000
98 } PurpleCmdPriority;
101 * PurpleCmdFlag:
102 * @PURPLE_CMD_FLAG_IM: Command is usable in IMs.
103 * @PURPLE_CMD_FLAG_CHAT: Command is usable in multi-user chats.
104 * @PURPLE_CMD_FLAG_PROTOCOL_ONLY: Command is usable only for a particular
105 * protocol.
106 * @PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS: Incorrect arguments to this command
107 * should be accepted anyway.
109 * Flags used to set various properties of commands. Every command should
110 * have at least one of #PURPLE_CMD_FLAG_IM and #PURPLE_CMD_FLAG_CHAT set in
111 * order to be even slighly useful.
113 * See purple_cmd_register().
115 typedef enum {
116 PURPLE_CMD_FLAG_IM = 0x01,
117 PURPLE_CMD_FLAG_CHAT = 0x02,
118 PURPLE_CMD_FLAG_PROTOCOL_ONLY = 0x04,
119 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS = 0x08
120 } PurpleCmdFlag;
123 * PurpleCommandsUiOps:
124 * @register_command: If implemented, the UI is responsible for handling
125 * commands. See @purple_cmd_register for the argument values.
126 * @unregister_command: Should be implemented if register_command is
127 * implemented. @name and @prpl_id will have the same value
128 * that were used for the register_command call.
130 * Command UI operations; UIs should implement this if they want to handle
131 * commands themselves, rather than relying on the core.
133 * See <link linkend="chapter-ui-ops">List of <literal>UiOps</literal>
134 * Structures</link>
136 typedef struct {
137 void (*register_command)(const gchar *name, PurpleCmdPriority priority,
138 PurpleCmdFlag flags, const gchar *prpl_id,
139 const gchar *help, PurpleCmdId id);
141 void (*unregister_command)(const gchar *name, const gchar *prpl_id);
143 /*< private >*/
144 void (*_purple_reserved1)(void);
145 void (*_purple_reserved2)(void);
146 void (*_purple_reserved3)(void);
147 void (*_purple_reserved4)(void);
148 } PurpleCommandsUiOps;
150 G_BEGIN_DECLS
152 /**************************************************************************/
153 /* Commands API */
154 /**************************************************************************/
157 * purple_cmd_register:
158 * @cmd: The command. This should be a UTF-8 (or ASCII) string, with no spaces
159 * or other white space.
160 * @args: A string of characters describing to libpurple how to parse this
161 * command's arguments. If what the user types doesn't match this
162 * pattern, libpurple will keep looking for another command, unless
163 * the flag #PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS is passed in @f.
164 * This string should contain no whitespace, and use a single
165 * character for each argument. The recognized characters are:
166 * <itemizedlist>
167 * <listitem><literal>'w'</literal>: Matches a single word.</listitem>
168 * <listitem><literal>'W'</literal>: Matches a single word, with
169 * formatting.</listitem>
170 * <listitem><literal>'s'</literal>: Matches the rest of the
171 * arguments after this point,
172 * as a single string.</listitem>
173 * <listitem><literal>'S'</literal>: Same as <literal>'s'</literal>
174 * but with formatting.</listitem>
175 * </itemizedlist>
176 * If args is the empty string, then the command accepts no
177 * arguments. The args passed to the callback @func will be a %NULL
178 * terminated array of %NULL terminated strings, and will always
179 * match the number of arguments asked for, unless
180 * #PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS is passed.
181 * @p: This is the priority. Higher priority commands will be run first,
182 * and usually the first command will stop any others from being
183 * called.
184 * @f: Flags specifying various options about this command, combined with
185 * <literal>|</literal> (bitwise OR). You need to at least pass one of
186 * #PURPLE_CMD_FLAG_IM or #PURPLE_CMD_FLAG_CHAT (you may pass both) in
187 * order for the command to ever actually be called.
188 * @protocol_id: If the #PURPLE_CMD_FLAG_PROTOCOL_ONLY flag is set, this is the id
189 * of the protocol to which the command applies (such as
190 * <literal>"prpl-msn"</literal>). If the flag is not set, this
191 * parameter is ignored; pass %NULL (or a humourous string of
192 * your choice!).
193 * @func: (scope call): This is the function to call when someone enters this
194 * command.
195 * @helpstr: a whitespace sensitive, UTF-8, HTML string describing how to
196 * use the command. The preferred format of this string is the
197 * command's name, followed by a space and any arguments it
198 * accepts (if it takes any arguments, otherwise no space),
199 * followed by a colon, two spaces, and a description of the
200 * command in sentence form. Do not include a slash before the
201 * command name.
202 * @data: User defined data to pass to the #PurpleCmdFunc @f.
204 * Register a new command with the core.
206 * The command will only happen if commands are enabled,
207 * which is a UI pref. UIs don't have to support commands at all.
209 * Returns: A #PurpleCmdId, which is only used for calling
210 * #purple_cmd_unregister, or 0 on failure.
212 PurpleCmdId purple_cmd_register(const gchar *cmd, const gchar *args, PurpleCmdPriority p, PurpleCmdFlag f,
213 const gchar *protocol_id, PurpleCmdFunc func, const gchar *helpstr, void *data);
216 * purple_cmd_unregister:
217 * @id: The #PurpleCmdId to unregister, as returned by #purple_cmd_register.
219 * Unregister a command with the core.
221 * All registered commands must be unregistered, if they're registered by a plugin
222 * or something else that might go away. Normally this is called when the plugin
223 * unloads itself.
225 void purple_cmd_unregister(PurpleCmdId id);
228 * purple_cmd_do_command:
229 * @conv: The conversation the command was typed in.
230 * @cmdline: The command the user typed (including all arguments) as a single string.
231 * The caller doesn't have to do any parsing, except removing the command
232 * prefix, which the core has no knowledge of. cmd should not contain any
233 * formatting, and should be in plain text (no html entities).
234 * @markup: This is the same as cmd, but is the formatted version. It should be in
235 * HTML, with < > and &, at least, escaped to html entities, and should
236 * include both the default formatting and any extra manual formatting.
237 * @errormsg: If the command failed errormsg is filled in with the appropriate error
238 * message. It must be freed by the caller with g_free().
240 * Do a command.
242 * Normally the UI calls this to perform a command. This might also be useful
243 * if aliases are ever implemented.
245 * Returns: A #PurpleCmdStatus indicating if the command succeeded or failed.
247 PurpleCmdStatus purple_cmd_do_command(PurpleConversation *conv, const gchar *cmdline,
248 const gchar *markup, gchar **errormsg);
251 * purple_cmd_execute:
252 * @id: The command to execute.
253 * @conv: The conversation the command was typed in.
254 * @cmdline: The command the user typed (only the arguments).
255 * The caller should remove the prefix and the command name.
256 * It should not contain any formatting, and should be
257 * in plain text (no HTML entities).
259 * Execute a specific command.
261 * The UI calls this to execute a command, after parsing the
262 * command name.
264 * Returns: %TRUE if the command handled the @cmdline, %FALSE otherwise.
266 gboolean purple_cmd_execute(PurpleCmdId id, PurpleConversation *conv,
267 const gchar *cmdline);
270 * purple_cmd_list:
271 * @conv: The conversation, or %NULL.
273 * List registered commands.
275 * Returns: (element-type utf8) (transfer container): All commands
276 * that are valid in the context of @conv, or all commands, if @conv is
277 * %NULL. Don't keep this list around past the main loop, or anything else that
278 * might unregister a command, as the <type>const char *</type>'s used get freed
279 * then.
281 GList *purple_cmd_list(PurpleConversation *conv);
284 * purple_cmd_help:
285 * @conv: The conversation, or %NULL for no context.
286 * @cmd: The command. No wildcards accepted, but returns help for all
287 * commands if %NULL.
289 * Get the help string for a command.
291 * Returns: (element-type utf8) (transfer container): the help strings for a
292 * given command, one node for each matching command.
294 GList *purple_cmd_help(PurpleConversation *conv, const gchar *cmd);
297 * purple_cmds_get_handle:
299 * Get the handle for the commands API
301 * Returns: The handle
303 gpointer purple_cmds_get_handle(void);
306 * purple_cmds_set_ui_ops:
307 * @ops: The UI operations structure.
309 * Sets the UI operations structure to be used when registering and
310 * unregistering commands. The UI operations need only be set if the
311 * UI wants to handle the commands itself; otherwise, leave it as NULL.
313 void purple_cmds_set_ui_ops(PurpleCommandsUiOps *ops);
316 * purple_cmds_get_ui_ops:
318 * Returns the UI operations structure to be used when registering and
319 * unregistering commands.
321 * Returns: (transfer none): The UI operations structure.
323 PurpleCommandsUiOps *purple_cmds_get_ui_ops(void);
326 * purple_cmds_init:
328 * Initialize the commands subsystem.
330 void purple_cmds_init(void);
333 * purple_cmds_uninit:
335 * Uninitialize the commands subsystem.
337 void purple_cmds_uninit(void);
339 G_END_DECLS
341 #endif /* PURPLE_CMDS_H */