[empathy: 12/12] Merge branch 'irc-command'
- From: Xavier Claessens <xclaesse src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [empathy: 12/12] Merge branch 'irc-command'
- Date: Tue, 3 Nov 2009 16:17:01 +0000 (UTC)
commit 22c06bcfd832f65fe2de6e44657e22decf2f523d
Merge: 2fdf428... e31c0e3...
Author: Xavier Claessens <xclaesse gmail com>
Date: Tue Nov 3 17:15:50 2009 +0100
Merge branch 'irc-command'
libempathy-gtk/empathy-chat.c | 378 +++++++++++++++++++++++++++++++++++++++--
libempathy/empathy-message.c | 56 ------
libempathy/empathy-message.h | 1 -
libempathy/empathy-tp-chat.c | 73 ++++++---
libempathy/empathy-tp-chat.h | 11 ++
5 files changed, 424 insertions(+), 95 deletions(-)
---
diff --cc libempathy-gtk/empathy-chat.c
index b2fefee,cfeb007..e96c02d
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@@ -591,22 -680,61 +882,61 @@@ chat_send (EmpathyChat *chat
priv = GET_PRIV (chat);
- chat_sent_message_add (chat, msg);
+ chat_input_history_add (chat, msg, FALSE);
- if (strcmp (msg, "/clear") == 0) {
- empathy_chat_view_clear (chat->view);
- return;
- }
+ if (msg[0] == '/') {
+ gboolean second_slash = FALSE;
+ const gchar *iter = msg + 1;
- message = empathy_message_new_from_entry (msg);
+ for (i = 0; i < G_N_ELEMENTS (commands); i++) {
+ GStrv strv;
+ guint strv_len;
- if (message == NULL) {
- empathy_chat_view_append_event (chat->view,
- _("Unsupported command"));
- } else {
- empathy_tp_chat_send (priv->tp_chat, message);
- g_object_unref (message);
+ if (!has_prefix_case (msg + 1, commands[i].prefix) ||
+ !g_ascii_isspace (msg + 1 + strlen (commands[i].prefix))) {
+ continue;
+ }
+
+ /* We can't use g_strsplit here because it does
+ * not deal correctly if we have more than one space
+ * between args */
+ strv = chat_command_parse (msg + 1, commands[i].max_parts);
+
+ strv_len = g_strv_length (strv);
+ if (strv_len < commands[i].min_parts ||
+ strv_len > commands[i].max_parts) {
+ chat_command_show_help (chat, &commands[i]);
+ g_strfreev (strv);
+ return;
+ }
+
+ commands[i].func (chat, strv);
+ g_strfreev (strv);
+ return;
+ }
+
+ /* Also allow messages with two slashes before the
+ * first space, so it is possible to send a /unix/path.
+ * This heuristic is kind of crap. */
+ while (*iter != '\0' && !g_ascii_isspace (*iter)) {
+ if (*iter == '/') {
+ second_slash = TRUE;
+ break;
+ }
+ iter++;
+ }
+
+ if (!second_slash) {
+ empathy_chat_view_append_event (chat->view,
+ _("Unknown command, see /help for the available"
+ " commands"));
+ return;
+ }
}
+
+ message = empathy_message_new (msg);
+ empathy_tp_chat_send (priv->tp_chat, message);
+ g_object_unref (message);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]