Fri, 12 Aug 2022 03:44:34 -0500
A bunch of random fixes for the the gtk4 branch
Testing Done:
Compiled
Reviewed at https://reviews.imfreedom.org/r/1581/
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
1 | /* Copyright (C) 2003-2004 Timothy Ringenbach <omarvo@hotmail.com |
| 9130 | 2 | * |
| 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. | |
| 7 | * | |
| 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. | |
| 12 | * | |
| 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18265
diff
changeset
|
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 9130 | 16 | * |
| 17 | */ | |
| 18 | ||
|
18265
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
19 | #include "internal.h" |
|
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
20 | |
| 9130 | 21 | #include "account.h" |
|
40564
2c5b4dc2e86a
Pull the purple_markup_* api out of util.[ch] to purplemarkup.[ch]. No code was changed just moved it from one file to the other.
Gary Kramlich <grim@reaperworld.com>
parents:
40079
diff
changeset
|
22 | #include "purplemarkup.h" |
| 9130 | 23 | #include "cmds.h" |
| 24 | ||
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
25 | static PurpleCommandsUiOps *cmds_ui_ops = NULL; |
| 9130 | 26 | static GList *cmds = NULL; |
| 27 | static guint next_id = 1; | |
| 28 | ||
|
39556
622bf98df0ac
Remove unnecessary struct tags.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37903
diff
changeset
|
29 | typedef struct { |
| 15884 | 30 | PurpleCmdId id; |
| 9130 | 31 | gchar *cmd; |
| 32 | gchar *args; | |
| 15884 | 33 | PurpleCmdPriority priority; |
| 34 | PurpleCmdFlag flags; | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
35 | gchar *protocol_id; |
| 15884 | 36 | PurpleCmdFunc func; |
| 9130 | 37 | gchar *help; |
| 9597 | 38 | void *data; |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
39 | } PurpleCmd; |
| 9130 | 40 | |
| 41 | ||
| 15884 | 42 | static gint cmds_compare_func(const PurpleCmd *a, const PurpleCmd *b) |
| 9130 | 43 | { |
| 40884 | 44 | return b->priority - a->priority; |
| 9130 | 45 | } |
| 46 | ||
| 15884 | 47 | PurpleCmdId purple_cmd_register(const gchar *cmd, const gchar *args, |
| 48 | PurpleCmdPriority p, PurpleCmdFlag f, | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
49 | const gchar *protocol_id, PurpleCmdFunc func, |
| 9597 | 50 | const gchar *helpstr, void *data) |
| 9130 | 51 | { |
| 15884 | 52 | PurpleCmdId id; |
| 53 | PurpleCmd *c; | |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
54 | PurpleCommandsUiOps *ops; |
| 9130 | 55 | |
| 9343 | 56 | g_return_val_if_fail(cmd != NULL && *cmd != '\0', 0); |
| 57 | g_return_val_if_fail(args != NULL, 0); | |
| 58 | g_return_val_if_fail(func != NULL, 0); | |
| 9130 | 59 | |
| 9343 | 60 | id = next_id++; |
| 9130 | 61 | |
| 15884 | 62 | c = g_new0(PurpleCmd, 1); |
| 9343 | 63 | c->id = id; |
| 9130 | 64 | c->cmd = g_strdup(cmd); |
| 65 | c->args = g_strdup(args); | |
| 66 | c->priority = p; | |
| 67 | c->flags = f; | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
68 | c->protocol_id = g_strdup(protocol_id); |
| 9130 | 69 | c->func = func; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
70 | c->help = g_strdup(helpstr); |
| 9597 | 71 | c->data = data; |
| 9130 | 72 | |
| 73 | cmds = g_list_insert_sorted(cmds, c, (GCompareFunc)cmds_compare_func); | |
| 74 | ||
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
75 | ops = purple_cmds_get_ui_ops(); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
76 | if (ops && ops->register_command) |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
77 | ops->register_command(cmd, p, f, protocol_id, helpstr, c->id); |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
78 | |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
79 | purple_signal_emit(purple_cmds_get_handle(), "cmd-added", cmd, p, f); |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
80 | |
| 9130 | 81 | return id; |
| 82 | } | |
| 83 | ||
| 15884 | 84 | static void purple_cmd_free(PurpleCmd *c) |
| 9130 | 85 | { |
| 86 | g_free(c->cmd); | |
| 87 | g_free(c->args); | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
88 | g_free(c->protocol_id); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
89 | g_free(c->help); |
| 9130 | 90 | g_free(c); |
| 91 | } | |
| 92 | ||
| 40884 | 93 | static gint |
| 94 | purple_cmd_cmp_id(gconstpointer cmd, gconstpointer id) | |
| 95 | { | |
| 96 | return ((PurpleCmd *)cmd)->id - GPOINTER_TO_UINT(id); | |
| 97 | } | |
| 98 | ||
| 15884 | 99 | void purple_cmd_unregister(PurpleCmdId id) |
| 9130 | 100 | { |
| 15884 | 101 | PurpleCmd *c; |
| 9130 | 102 | GList *l; |
| 40884 | 103 | PurpleCommandsUiOps *ops; |
| 9130 | 104 | |
| 40884 | 105 | l = g_list_find_custom(cmds, GUINT_TO_POINTER(id), purple_cmd_cmp_id); |
| 106 | if (!l) { | |
| 107 | return; | |
| 108 | } | |
| 109 | ||
| 110 | c = l->data; | |
| 9130 | 111 | |
| 40884 | 112 | ops = purple_cmds_get_ui_ops(); |
| 113 | if (ops && ops->unregister_command) { | |
| 114 | ops->unregister_command(c->cmd, c->protocol_id); | |
| 115 | } | |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
116 | |
| 40884 | 117 | cmds = g_list_delete_link(cmds, l); |
| 118 | purple_signal_emit(purple_cmds_get_handle(), "cmd-removed", c->cmd); | |
| 119 | purple_cmd_free(c); | |
| 9130 | 120 | } |
| 121 | ||
|
35458
385156e1b493
Fix some gtk-doc warnings from account to connection
Ankit Vani <a@nevitus.org>
parents:
35454
diff
changeset
|
122 | /* |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
123 | * This sets args to a NULL-terminated array of strings. It should |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
124 | * be freed using g_strfreev(). |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
125 | */ |
| 15884 | 126 | static gboolean purple_cmd_parse_args(PurpleCmd *cmd, const gchar *s, const gchar *m, gchar ***args) |
| 9130 | 127 | { |
| 128 | int i; | |
| 129 | const char *end, *cur; | |
| 130 | ||
| 131 | *args = g_new0(char *, strlen(cmd->args) + 1); | |
| 132 | ||
| 133 | cur = s; | |
| 134 | ||
| 135 | for (i = 0; cmd->args[i]; i++) { | |
| 136 | if (!*cur) | |
| 15884 | 137 | return (cmd->flags & PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS); |
| 9130 | 138 | |
| 139 | switch (cmd->args[i]) { | |
| 140 | case 'w': | |
| 9428 | 141 | if (!(end = strchr(cur, ' '))) { |
| 142 | end = cur + strlen(cur); | |
| 143 | (*args)[i] = g_strndup(cur, end - cur); | |
| 144 | cur = end; | |
| 145 | } else { | |
| 146 | (*args)[i] = g_strndup(cur, end - cur); | |
| 147 | cur = end + 1; | |
| 148 | } | |
| 9130 | 149 | break; |
| 150 | case 'W': | |
| 9428 | 151 | if (!(end = strchr(cur, ' '))) { |
| 152 | end = cur + strlen(cur); | |
| 15884 | 153 | (*args)[i] = purple_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end)); |
| 9428 | 154 | cur = end; |
| 155 | } else { | |
| 15884 | 156 | (*args)[i] = purple_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end)); |
| 9428 | 157 | cur = end +1; |
| 158 | } | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
159 | break; |
| 9130 | 160 | case 's': |
| 161 | (*args)[i] = g_strdup(cur); | |
| 162 | cur = cur + strlen(cur); | |
| 163 | break; | |
| 164 | case 'S': | |
| 15884 | 165 | (*args)[i] = purple_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_strlen(cur, -1) + 1); |
| 9130 | 166 | cur = cur + strlen(cur); |
| 167 | break; | |
| 168 | } | |
| 169 | } | |
| 170 | ||
| 171 | if (*cur) | |
| 15884 | 172 | return (cmd->flags & PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS); |
| 9130 | 173 | |
| 174 | return TRUE; | |
| 175 | } | |
| 176 | ||
| 15884 | 177 | static void purple_cmd_strip_current_char(gunichar c, char *s, guint len) |
| 9175 | 178 | { |
| 179 | int bytes; | |
| 180 | ||
| 181 | bytes = g_unichar_to_utf8(c, NULL); | |
| 182 | memmove(s, s + bytes, len + 1 - bytes); | |
| 183 | } | |
| 184 | ||
| 15884 | 185 | static void purple_cmd_strip_cmd_from_markup(char *markup) |
| 9175 | 186 | { |
| 187 | guint len = strlen(markup); | |
| 188 | char *s = markup; | |
| 189 | ||
| 190 | while (*s) { | |
| 191 | gunichar c = g_utf8_get_char(s); | |
| 192 | ||
| 193 | if (c == '<') { | |
| 194 | s = strchr(s, '>'); | |
| 195 | if (!s) | |
| 196 | return; | |
| 197 | } else if (g_unichar_isspace(c)) { | |
| 15884 | 198 | purple_cmd_strip_current_char(c, s, len - (s - markup)); |
| 9175 | 199 | return; |
| 200 | } else { | |
| 15884 | 201 | purple_cmd_strip_current_char(c, s, len - (s - markup)); |
| 9175 | 202 | continue; |
| 203 | } | |
| 204 | s = g_utf8_next_char(s); | |
| 205 | } | |
| 206 | } | |
| 9597 | 207 | |
| 40884 | 208 | static gboolean |
| 209 | is_right_type(PurpleCmd *cmd, PurpleConversation *conv) | |
| 210 | { | |
| 211 | return (PURPLE_IS_IM_CONVERSATION(conv) && (cmd->flags & PURPLE_CMD_FLAG_IM)) | |
| 212 | || (PURPLE_IS_CHAT_CONVERSATION(conv) && (cmd->flags & PURPLE_CMD_FLAG_CHAT)); | |
| 213 | } | |
| 214 | ||
| 215 | static gboolean | |
| 216 | is_right_protocol(PurpleCmd *cmd, PurpleConversation *conv) | |
| 217 | { | |
| 218 | const gchar *protocol_id = purple_account_get_protocol_id(purple_conversation_get_account(conv)); | |
| 219 | ||
| 220 | return !(cmd->flags & PURPLE_CMD_FLAG_PROTOCOL_ONLY) | |
| 221 | || purple_strequal(cmd->protocol_id, protocol_id); | |
| 222 | } | |
| 223 | ||
| 15884 | 224 | PurpleCmdStatus purple_cmd_do_command(PurpleConversation *conv, const gchar *cmdline, |
| 9175 | 225 | const gchar *markup, gchar **error) |
| 9130 | 226 | { |
| 227 | gchar *err = NULL; | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
228 | gboolean found = FALSE, tried_cmd = FALSE, right_type = FALSE, right_protocol = FALSE; |
| 9175 | 229 | gchar *cmd, *rest, *mrest; |
| 15884 | 230 | PurpleCmdRet ret = PURPLE_CMD_RET_CONTINUE; |
| 9130 | 231 | |
| 9149 | 232 | *error = NULL; |
| 9130 | 233 | |
| 234 | rest = strchr(cmdline, ' '); | |
| 235 | if (rest) { | |
| 236 | cmd = g_strndup(cmdline, rest - cmdline); | |
| 237 | rest++; | |
| 238 | } else { | |
| 239 | cmd = g_strdup(cmdline); | |
| 240 | rest = ""; | |
| 241 | } | |
| 242 | ||
| 9175 | 243 | mrest = g_strdup(markup); |
| 15884 | 244 | purple_cmd_strip_cmd_from_markup(mrest); |
| 9175 | 245 | |
| 40884 | 246 | for (GList *l = cmds; l; l = l->next) { |
| 247 | PurpleCmd *c = l->data; | |
| 248 | gchar **args = NULL; | |
| 9130 | 249 | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
23555
diff
changeset
|
250 | if (!purple_strequal(c->cmd, cmd)) |
| 9130 | 251 | continue; |
| 252 | ||
| 253 | found = TRUE; | |
| 254 | ||
| 40884 | 255 | if (!is_right_type(c, conv)) { |
| 256 | continue; | |
| 257 | } | |
| 9130 | 258 | |
| 259 | right_type = TRUE; | |
| 260 | ||
| 40884 | 261 | if (!is_right_protocol(c, conv)) { |
| 9130 | 262 | continue; |
| 40884 | 263 | } |
| 9130 | 264 | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
265 | right_protocol = TRUE; |
| 9130 | 266 | |
| 267 | /* this checks the allow bad args flag for us */ | |
| 15884 | 268 | if (!purple_cmd_parse_args(c, rest, mrest, &args)) { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
269 | g_strfreev(args); |
| 9130 | 270 | continue; |
| 271 | } | |
| 272 | ||
| 273 | tried_cmd = TRUE; | |
| 9597 | 274 | ret = c->func(conv, cmd, args, &err, c->data); |
| 40884 | 275 | g_strfreev(args); |
| 15884 | 276 | if (ret == PURPLE_CMD_RET_CONTINUE) { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
277 | g_free(err); |
| 9149 | 278 | err = NULL; |
| 9130 | 279 | continue; |
| 280 | } | |
| 281 | ||
| 40884 | 282 | break; |
| 9130 | 283 | } |
| 284 | ||
| 285 | g_free(cmd); | |
| 9175 | 286 | g_free(mrest); |
| 9130 | 287 | |
| 288 | if (!found) | |
| 15884 | 289 | return PURPLE_CMD_STATUS_NOT_FOUND; |
| 9130 | 290 | |
| 291 | if (!right_type) | |
| 15884 | 292 | return PURPLE_CMD_STATUS_WRONG_TYPE; |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
293 | if (!right_protocol) |
|
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
294 | return PURPLE_CMD_STATUS_WRONG_PROTOCOL; |
| 9130 | 295 | if (!tried_cmd) |
| 15884 | 296 | return PURPLE_CMD_STATUS_WRONG_ARGS; |
| 9130 | 297 | |
| 40884 | 298 | if (ret != PURPLE_CMD_RET_OK) { |
| 9130 | 299 | *error = err; |
| 15884 | 300 | if (ret == PURPLE_CMD_RET_CONTINUE) |
| 301 | return PURPLE_CMD_STATUS_NOT_FOUND; | |
| 9130 | 302 | else |
| 15884 | 303 | return PURPLE_CMD_STATUS_FAILED; |
| 9130 | 304 | } |
| 305 | ||
| 40884 | 306 | return PURPLE_CMD_STATUS_OK; |
| 9130 | 307 | } |
| 308 | ||
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
309 | gboolean purple_cmd_execute(PurpleCmdId id, PurpleConversation *conv, |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
310 | const gchar *cmdline) |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
311 | { |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
312 | PurpleCmd *cmd = NULL; |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
313 | PurpleCmdRet ret = PURPLE_CMD_RET_CONTINUE; |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
314 | GList *l = NULL; |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
315 | gchar *err = NULL; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
316 | gchar **args = NULL; |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
317 | |
| 40884 | 318 | l = g_list_find_custom(cmds, GUINT_TO_POINTER(id), purple_cmd_cmp_id); |
| 319 | if (!l) { | |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
320 | return FALSE; |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
321 | } |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
322 | |
| 40884 | 323 | cmd = l->data; |
| 324 | ||
| 325 | if (!is_right_type(cmd, conv)) { | |
| 326 | return FALSE; | |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
327 | } |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
328 | |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
329 | /* XXX: Don't worry much about the markup version of the command |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
330 | line, there's not a single use case... */ |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
331 | /* this checks the allow bad args flag for us */ |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
332 | if (!purple_cmd_parse_args(cmd, cmdline, cmdline, &args)) { |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
333 | g_strfreev(args); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
334 | return FALSE; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
335 | } |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
336 | |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
337 | ret = cmd->func(conv, cmd->cmd, args, &err, cmd->data); |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
338 | |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
339 | g_free(err); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
340 | g_strfreev(args); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
341 | |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
342 | return ret == PURPLE_CMD_RET_OK; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
343 | } |
| 9130 | 344 | |
| 15884 | 345 | GList *purple_cmd_list(PurpleConversation *conv) |
| 9130 | 346 | { |
| 347 | GList *ret = NULL; | |
| 348 | ||
| 40884 | 349 | for (GList *l = cmds; l; l = l->next) { |
| 350 | PurpleCmd *c = l->data; | |
| 9130 | 351 | |
| 40884 | 352 | if (conv && (!is_right_type(c, conv) || !is_right_protocol(c, conv))) { |
| 9130 | 353 | continue; |
| 40884 | 354 | } |
| 9130 | 355 | |
| 356 | ret = g_list_append(ret, c->cmd); | |
| 357 | } | |
| 358 | ||
|
12014
8a45c4f43021
[gaim-migrate @ 14307]
Mark Doliner <markdoliner@pidgin.im>
parents:
11338
diff
changeset
|
359 | ret = g_list_sort(ret, (GCompareFunc)strcmp); |
|
8a45c4f43021
[gaim-migrate @ 14307]
Mark Doliner <markdoliner@pidgin.im>
parents:
11338
diff
changeset
|
360 | |
| 9130 | 361 | return ret; |
| 362 | } | |
| 363 | ||
| 364 | ||
| 15884 | 365 | GList *purple_cmd_help(PurpleConversation *conv, const gchar *cmd) |
| 9130 | 366 | { |
| 367 | GList *ret = NULL; | |
| 368 | ||
| 40884 | 369 | for (GList *l = cmds; l; l = l->next) { |
| 370 | PurpleCmd *c = l->data; | |
| 9130 | 371 | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
23555
diff
changeset
|
372 | if (cmd && !purple_strequal(cmd, c->cmd)) |
| 9130 | 373 | continue; |
| 374 | ||
| 40884 | 375 | if (conv && (!is_right_type(c, conv) || !is_right_protocol(c, conv))) { |
| 9130 | 376 | continue; |
| 40884 | 377 | } |
| 9130 | 378 | |
| 379 | ret = g_list_append(ret, c->help); | |
| 380 | } | |
| 381 | ||
|
12014
8a45c4f43021
[gaim-migrate @ 14307]
Mark Doliner <markdoliner@pidgin.im>
parents:
11338
diff
changeset
|
382 | ret = g_list_sort(ret, (GCompareFunc)strcmp); |
|
8a45c4f43021
[gaim-migrate @ 14307]
Mark Doliner <markdoliner@pidgin.im>
parents:
11338
diff
changeset
|
383 | |
| 9130 | 384 | return ret; |
| 385 | } | |
| 386 | ||
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
387 | gpointer purple_cmds_get_handle(void) |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
388 | { |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
389 | static int handle; |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
390 | return &handle; |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
391 | } |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
392 | |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
393 | void |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
394 | purple_cmds_set_ui_ops(PurpleCommandsUiOps *ops) |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
395 | { |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
396 | cmds_ui_ops = ops; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
397 | } |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
398 | |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
399 | PurpleCommandsUiOps * |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
400 | purple_cmds_get_ui_ops(void) |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
401 | { |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
402 | /* It is perfectly acceptable for cmds_ui_ops to be NULL; this just |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
403 | * means that the default libpurple implementation will be used. |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
404 | */ |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
405 | return cmds_ui_ops; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
406 | } |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
407 | |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
408 | void purple_cmds_init(void) |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
409 | { |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
410 | gpointer handle = purple_cmds_get_handle(); |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
411 | |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
412 | purple_signal_register(handle, "cmd-added", |
|
34814
759ea31715dd
Refactored cmds and connection to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34645
diff
changeset
|
413 | purple_marshal_VOID__POINTER_INT_INT, G_TYPE_NONE, 3, |
|
759ea31715dd
Refactored cmds and connection to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34645
diff
changeset
|
414 | G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
415 | purple_signal_register(handle, "cmd-removed", |
|
34814
759ea31715dd
Refactored cmds and connection to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34645
diff
changeset
|
416 | purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, |
|
759ea31715dd
Refactored cmds and connection to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34645
diff
changeset
|
417 | G_TYPE_STRING); |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
418 | } |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
419 | |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
420 | void purple_cmds_uninit(void) |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
421 | { |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
422 | purple_signals_unregister_by_instance(purple_cmds_get_handle()); |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
28981
diff
changeset
|
423 | |
|
40062
d25228fc7b8e
Use g_list_free_full instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39556
diff
changeset
|
424 | g_list_free_full(cmds, (GDestroyNotify)purple_cmd_free); |
| 40064 | 425 | cmds = NULL; |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
426 | } |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
427 |