Tue, 18 Sep 2007 16:32:46 +0000
merge of 'bc4b48f6fbaaf411c3e9245a9d0e3f22d763aacf'
and 'f7a11b4aef9753768661d36921787fad7693ad43'
| 9130 | 1 | /** |
| 2 | * @file cmds.h Commands API | |
| 3 | * @ingroup core | |
|
20330
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* Copyright (C) 2003 Timothy Ringenbach <omarvo@hotmail.com> |
| 9130 | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 9130 | 21 | * |
| 22 | */ | |
| 15884 | 23 | #ifndef _PURPLE_CMDS_H_ |
| 24 | #define _PURPLE_CMDS_H_ | |
| 9130 | 25 | |
| 26 | #include "conversation.h" | |
| 27 | ||
|
10231
047177cee39f
[gaim-migrate @ 11366]
Andrew Hart <arhart@users.sourceforge.net>
parents:
10052
diff
changeset
|
28 | /**************************************************************************/ |
|
047177cee39f
[gaim-migrate @ 11366]
Andrew Hart <arhart@users.sourceforge.net>
parents:
10052
diff
changeset
|
29 | /** @name Structures */ |
|
047177cee39f
[gaim-migrate @ 11366]
Andrew Hart <arhart@users.sourceforge.net>
parents:
10052
diff
changeset
|
30 | /**************************************************************************/ |
| 9130 | 31 | /*@{*/ |
| 32 | ||
| 15884 | 33 | typedef enum _PurpleCmdPriority PurpleCmdPriority; |
| 34 | typedef enum _PurpleCmdFlag PurpleCmdFlag; | |
| 35 | typedef enum _PurpleCmdStatus PurpleCmdStatus; | |
| 36 | typedef enum _PurpleCmdRet PurpleCmdRet; | |
| 9130 | 37 | |
| 15884 | 38 | enum _PurpleCmdStatus { |
| 39 | PURPLE_CMD_STATUS_OK, | |
| 40 | PURPLE_CMD_STATUS_FAILED, | |
| 41 | PURPLE_CMD_STATUS_NOT_FOUND, | |
| 42 | PURPLE_CMD_STATUS_WRONG_ARGS, | |
| 43 | PURPLE_CMD_STATUS_WRONG_PRPL, | |
| 44 | PURPLE_CMD_STATUS_WRONG_TYPE, | |
| 9130 | 45 | }; |
| 46 | ||
| 15884 | 47 | enum _PurpleCmdRet { |
| 48 | PURPLE_CMD_RET_OK, /**< Everything's okay. Don't look for another command to call. */ | |
| 49 | PURPLE_CMD_RET_FAILED, /**< The command failed, but stop looking.*/ | |
| 50 | PURPLE_CMD_RET_CONTINUE, /**< Continue, looking for other commands with the same name to call. */ | |
| 9130 | 51 | }; |
| 52 | ||
| 15884 | 53 | #define PURPLE_CMD_FUNC(func) ((PurpleCmdFunc)func) |
| 9597 | 54 | |
| 15884 | 55 | typedef PurpleCmdRet (*PurpleCmdFunc)(PurpleConversation *, const gchar *cmd, |
| 9597 | 56 | gchar **args, gchar **error, void *data); |
| 15884 | 57 | typedef guint PurpleCmdId; |
| 9130 | 58 | |
| 15884 | 59 | enum _PurpleCmdPriority { |
| 60 | PURPLE_CMD_P_VERY_LOW = -1000, | |
| 61 | PURPLE_CMD_P_LOW = 0, | |
| 62 | PURPLE_CMD_P_DEFAULT = 1000, | |
| 63 | PURPLE_CMD_P_PRPL = 2000, | |
| 64 | PURPLE_CMD_P_PLUGIN = 3000, | |
| 65 | PURPLE_CMD_P_ALIAS = 4000, | |
| 66 | PURPLE_CMD_P_HIGH = 5000, | |
| 67 | PURPLE_CMD_P_VERY_HIGH = 6000, | |
| 9130 | 68 | }; |
| 69 | ||
| 15884 | 70 | enum _PurpleCmdFlag { |
| 71 | PURPLE_CMD_FLAG_IM = 0x01, | |
| 72 | PURPLE_CMD_FLAG_CHAT = 0x02, | |
| 73 | PURPLE_CMD_FLAG_PRPL_ONLY = 0x04, | |
| 74 | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS = 0x08, | |
| 9130 | 75 | }; |
| 76 | ||
| 77 | ||
| 78 | /*@}*/ | |
| 79 | ||
| 80 | #ifdef __cplusplus | |
| 81 | extern "C" { | |
| 82 | #endif | |
| 83 | ||
|
10231
047177cee39f
[gaim-migrate @ 11366]
Andrew Hart <arhart@users.sourceforge.net>
parents:
10052
diff
changeset
|
84 | /**************************************************************************/ |
|
047177cee39f
[gaim-migrate @ 11366]
Andrew Hart <arhart@users.sourceforge.net>
parents:
10052
diff
changeset
|
85 | /** @name Commands API */ |
|
047177cee39f
[gaim-migrate @ 11366]
Andrew Hart <arhart@users.sourceforge.net>
parents:
10052
diff
changeset
|
86 | /**************************************************************************/ |
| 9130 | 87 | /*@{*/ |
| 88 | ||
| 89 | /** | |
| 90 | * Register a new command with the core. | |
| 91 | * | |
| 92 | * The command will only happen if commands are enabled, | |
| 93 | * which is a UI pref. UIs don't have to support commands at all. | |
| 94 | * | |
| 95 | * @param cmd The command. This should be a UTF8 (or ASCII) string, with no spaces | |
| 96 | * or other white space. | |
| 15884 | 97 | * @param args This tells Purple how to parse the arguments to the command for you. |
| 98 | * If what the user types doesn't match, Purple will keep looking for another | |
| 99 | * command, unless the flag @c PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS is passed in f. | |
| 9130 | 100 | * This string contains no whitespace, and uses a single character for each argument. |
| 101 | * The recognized characters are: | |
| 102 | * 'w' Matches a single word. | |
| 9175 | 103 | * 'W' Matches a single word, with formatting. |
| 9130 | 104 | * 's' Matches the rest of the arguments after this point, as a single string. |
| 9175 | 105 | * 'S' Same as 's' but with formatting. |
| 9130 | 106 | * If args is the empty string, then the command accepts no arguments. |
| 107 | * The args passed to callback func will be a @c NULL terminated array of null | |
| 108 | * terminated strings, and will always match the number of arguments asked for, | |
| 15884 | 109 | * unless PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS is passed. |
| 9130 | 110 | * @param p This is the priority. Higher priority commands will be run first, and usually the |
| 111 | * first command will stop any others from being called. | |
| 15884 | 112 | * @param f These are the flags. You need to at least pass one of PURPLE_CMD_FLAG_IM or |
| 113 | * PURPLE_CMD_FLAG_CHAT (can may pass both) in order for the command to ever actually | |
| 9130 | 114 | * be called. |
| 13841 | 115 | * @param prpl_id This is the prpl's id string. This is only meaningful if the proper flag is set. |
| 9130 | 116 | * @param func This is the function to call when someone enters this command. |
| 9247 | 117 | * @param helpstr This is a whitespace sensitive, UTF-8, HTML string describing how to use the command. |
| 9256 | 118 | * The preferred format of this string shall be the commands name, followed by a space |
| 13841 | 119 | * and any arguments it accepts (if it takes any arguments, otherwise no space), followed |
| 9256 | 120 | * by a colon, two spaces, and a description of the command in sentence form. No slash |
| 9247 | 121 | * before the command name. |
| 15884 | 122 | * @param data User defined data to pass to the PurpleCmdFunc |
| 123 | * @return A PurpleCmdId. This is only used for calling purple_cmd_unregister. | |
|
10052
329dad7e2da3
[gaim-migrate @ 11013]
Dave West <kat@users.sourceforge.net>
parents:
9939
diff
changeset
|
124 | * Returns 0 on failure. |
| 9130 | 125 | */ |
| 15884 | 126 | PurpleCmdId purple_cmd_register(const gchar *cmd, const gchar *args, PurpleCmdPriority p, PurpleCmdFlag f, |
| 127 | const gchar *prpl_id, PurpleCmdFunc func, const gchar *helpstr, void *data); | |
| 9130 | 128 | |
| 129 | /** | |
| 130 | * Unregister a command with the core. | |
| 131 | * | |
| 132 | * All registered commands must be unregistered, if they're registered by a plugin | |
| 133 | * or something else that might go away. Normally this is called when the plugin | |
| 134 | * unloads itself. | |
| 135 | * | |
| 15884 | 136 | * @param id The PurpleCmdId to unregister. |
| 9130 | 137 | */ |
| 15884 | 138 | void purple_cmd_unregister(PurpleCmdId id); |
| 9130 | 139 | |
| 140 | /** | |
| 141 | * Do a command. | |
| 142 | * | |
| 143 | * Normally the UI calls this to perform a command. This might also be useful | |
| 144 | * if aliases are ever implemented. | |
| 145 | * | |
| 146 | * @param conv The conversation the command was typed in. | |
| 9175 | 147 | * @param cmdline The command the user typed (including all arguments) as a single string. |
| 9130 | 148 | * The caller doesn't have to do any parsing, except removing the command |
| 9597 | 149 | * prefix, which the core has no knowledge of. cmd should not contain any |
| 150 | * formatting, and should be in plain text (no html entities). | |
| 9175 | 151 | * @param markup This is the same as cmd, but is the formatted version. It should be in |
| 152 | * HTML, with < > and &, at least, escaped to html entities, and should | |
| 153 | * include both the default formatting and any extra manual formatting. | |
|
10788
79d6a09303e7
[gaim-migrate @ 12429]
Richard Laager <rlaager@pidgin.im>
parents:
10231
diff
changeset
|
154 | * @param errormsg If the command failed errormsg is filled in with the appropriate error |
|
79d6a09303e7
[gaim-migrate @ 12429]
Richard Laager <rlaager@pidgin.im>
parents:
10231
diff
changeset
|
155 | * message. It must be freed by the caller with g_free(). |
| 15884 | 156 | * @return A PurpleCmdStatus indicated if the command succeeded or failed. |
| 9130 | 157 | */ |
| 15884 | 158 | PurpleCmdStatus purple_cmd_do_command(PurpleConversation *conv, const gchar *cmdline, |
| 9175 | 159 | const gchar *markup, gchar **errormsg); |
| 9130 | 160 | |
| 161 | /** | |
| 162 | * List registered commands. | |
| 163 | * | |
| 164 | * Returns a GList (which must be freed by the caller) of all commands | |
| 165 | * that are valid in the context of conv, or all commands, if conv is | |
| 166 | * @c NULL. Don't keep this list around past the main loop, or anything else | |
| 167 | * that might unregister a command, as the char*'s used get freed then. | |
| 168 | * | |
| 169 | * @param conv The conversation, or @c NULL. | |
| 170 | * @return A GList of const char*, which must be freed with g_list_free(). | |
| 171 | */ | |
| 15884 | 172 | GList *purple_cmd_list(PurpleConversation *conv); |
| 9130 | 173 | |
| 174 | /** | |
| 175 | * Get the help string for a command. | |
| 176 | * | |
| 177 | * Returns the help strings for a given command in the form of a GList, | |
| 178 | * one node for each matching command. | |
| 179 | * | |
| 180 | * @param conv The conversation, or @c NULL for no context. | |
| 181 | * @param cmd The command. No wildcards accepted, but returns help for all | |
| 182 | * commands if @c NULL. | |
| 183 | * @return A GList of const char*s, which is the help string | |
| 184 | * for that command. | |
| 185 | */ | |
| 15884 | 186 | GList *purple_cmd_help(PurpleConversation *conv, const gchar *cmd); |
| 9130 | 187 | |
| 188 | /*@}*/ | |
| 189 | ||
| 190 | #ifdef __cplusplus | |
| 191 | } | |
| 192 | #endif | |
| 193 | ||
| 15884 | 194 | #endif /* _PURPLE_CMDS_H_ */ |