comparison src/gtkconv.c @ 9213:99abaef7ed34

[gaim-migrate @ 10008] Here's a first stab at /help Still some things that need work. Notice that help is listed twice, etc. I think I'll change it to make it automaticly tell you the args, instead of putting them in the help string. Also there's the question of if help strings should be considered html or plain text. (If plain text, we need to run gaim_escape_html on it in /help.) committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Sun, 06 Jun 2004 06:15:27 +0000
parents a10359a27789
children 933c7418fd03
comparison
equal deleted inserted replaced
9212:a10359a27789 9213:99abaef7ed34
380 GAIM_MESSAGE_NO_LOG|GAIM_MESSAGE_ERROR, time(NULL)); 380 GAIM_MESSAGE_NO_LOG|GAIM_MESSAGE_ERROR, time(NULL));
381 return GAIM_CMD_STATUS_OK; 381 return GAIM_CMD_STATUS_OK;
382 } 382 }
383 } 383 }
384 384
385 static GaimCmdRet
386 help_command_cb(GaimConversation *conv,
387 const char *cmd, char **args, char **error)
388 {
389 GString *s;
390 GList *cmds, *l;
391
392 s = g_string_new(_("Use \"/help &lt;command&gt;\" for help on a specific command.\n"
393 "The following commands are available in this context:\n"));
394
395 cmds = gaim_cmd_list(conv);
396 for (l = cmds; l; l = l->next)
397 if (l->next)
398 g_string_append_printf(s, "%s, ", (char *)l->data);
399 else
400 g_string_append_printf(s, "%s.", (char *)l->data);
401
402 gaim_conversation_write(conv, NULL, s->str, GAIM_MESSAGE_NO_LOG, time(NULL));
403 g_string_free(s, TRUE);
404 g_list_free(cmds);
405
406 return GAIM_CMD_STATUS_OK;
407 }
408
409 static GaimCmdRet
410 help_arg_command_cb(GaimConversation *conv,
411 const char *cmd, char **args, char **error)
412 {
413 GList *help, *l;
414 GString *s;
415
416 s = g_string_new("");
417 help = gaim_cmd_help(conv, args[0]);
418
419 if (help) {
420 for (l = help; l; l = l->next)
421 if (l->next)
422 g_string_append_printf(s, "%s\n", (char *)l->data);
423 else
424 g_string_append_printf(s, "%s", (char *)l->data);
425 } else {
426 g_string_append(s, _("No such command (in this context)."));
427 }
428
429 gaim_conversation_write(conv, NULL, s->str, GAIM_MESSAGE_NO_LOG, time(NULL));
430 g_string_free(s, TRUE);
431 g_list_free(help);
432
433 return GAIM_CMD_STATUS_OK;
434 }
435
385 static void 436 static void
386 send_cb(GtkWidget *widget, GaimConversation *conv) 437 send_cb(GtkWidget *widget, GaimConversation *conv)
387 { 438 {
388 GaimGtkConversation *gtkconv; 439 GaimGtkConversation *gtkconv;
389 char *cmd; 440 char *cmd;
422 gaim_conversation_write(conv, "", _("No such command. If you didn't mean " 473 gaim_conversation_write(conv, "", _("No such command. If you didn't mean "
423 "to type a command, you can turn " 474 "to type a command, you can turn "
424 "commands off from Tools->" 475 "commands off from Tools->"
425 "Preferences->Interface->Conversation" 476 "Preferences->Interface->Conversation"
426 "->Enable \"slash\" commands."), 477 "->Enable \"slash\" commands."),
427 GAIM_MESSAGE_SYSTEM, time(NULL)); 478 GAIM_MESSAGE_NO_LOG, time(NULL));
428 return; 479 return;
429 case GAIM_CMD_STATUS_WRONG_ARGS: 480 case GAIM_CMD_STATUS_WRONG_ARGS:
430 gaim_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " 481 gaim_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments "
431 "to that command. If you didn't mean to type a command, " 482 "to that command. If you didn't mean to type a command, "
432 "you can turn commands off from Tools->Preferences->" 483 "you can turn commands off from Tools->Preferences->"
433 "Interface->Conversation->Enable \"slash\" commands."), 484 "Interface->Conversation->Enable \"slash\" commands."),
434 GAIM_MESSAGE_SYSTEM, time(NULL)); 485 GAIM_MESSAGE_NO_LOG, time(NULL));
435 return; 486 return;
436 case GAIM_CMD_STATUS_FAILED: 487 case GAIM_CMD_STATUS_FAILED:
437 gaim_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."), 488 gaim_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."),
438 GAIM_MESSAGE_SYSTEM, time(NULL)); 489 GAIM_MESSAGE_NO_LOG, time(NULL));
439 if(error) 490 if(error)
440 g_free(error); 491 g_free(error);
441 return; 492 return;
442 case GAIM_CMD_STATUS_WRONG_TYPE: 493 case GAIM_CMD_STATUS_WRONG_TYPE:
443 if(gaim_conversation_get_type(conv) == GAIM_CONV_IM) 494 if(gaim_conversation_get_type(conv) == GAIM_CONV_IM)
444 gaim_conversation_write(conv, "", _("That command only works in Chats, not IMs."), 495 gaim_conversation_write(conv, "", _("That command only works in Chats, not IMs."),
445 GAIM_MESSAGE_SYSTEM, time(NULL)); 496 GAIM_MESSAGE_NO_LOG, time(NULL));
446 else 497 else
447 gaim_conversation_write(conv, "", _("That command only works in IMs, not Chats."), 498 gaim_conversation_write(conv, "", _("That command only works in IMs, not Chats."),
448 GAIM_MESSAGE_SYSTEM, time(NULL)); 499 GAIM_MESSAGE_NO_LOG, time(NULL));
449 return; 500 return;
450 case GAIM_CMD_STATUS_WRONG_PRPL: 501 case GAIM_CMD_STATUS_WRONG_PRPL:
451 gaim_conversation_write(conv, "", _("That command doesn't work on this protocol."), 502 gaim_conversation_write(conv, "", _("That command doesn't work on this protocol."),
452 GAIM_MESSAGE_SYSTEM, time(NULL)); 503 GAIM_MESSAGE_NO_LOG, time(NULL));
453 return; 504 return;
454 } 505 }
455 } 506 }
456 507
457 g_free(cmd); 508 g_free(cmd);
6020 GAIM_SUBTYPE_CONV_WINDOW)); 6071 GAIM_SUBTYPE_CONV_WINDOW));
6021 6072
6022 /********************************************************************** 6073 /**********************************************************************
6023 * Register commands 6074 * Register commands
6024 **********************************************************************/ 6075 **********************************************************************/
6025 gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT, 6076 gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT,
6026 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, 6077 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
6027 me_command_cb, _("Send an IRC style action to a buddy or chat.")); 6078 me_command_cb, _("Send an IRC style action to a buddy or chat."));
6028 gaim_cmd_register("debug", "w", GAIM_CMD_P_DEFAULT, 6079 gaim_cmd_register("debug", "w", GAIM_CMD_P_DEFAULT,
6029 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, 6080 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
6030 debug_command_cb, _("Send various debug information to the current conversation.")); 6081 debug_command_cb, _("Send various debug information to the current conversation."));
6082
6083 gaim_cmd_register("help", "", GAIM_CMD_P_DEFAULT,
6084 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
6085 help_command_cb, _("/help: List available commands."));
6086
6087 gaim_cmd_register("help", "w", GAIM_CMD_P_DEFAULT,
6088 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
6089 help_arg_command_cb, _("/help &lt;command&gt;: Help on a specific command."));
6031 } 6090 }
6032 6091
6033 void 6092 void
6034 gaim_gtk_conversations_uninit(void) 6093 gaim_gtk_conversations_uninit(void)
6035 { 6094 {