From 3d6ebf48ecd61d8bfe9293a16cce67c2065769ff Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 19 Dec 2012 23:31:25 +0000 Subject: [PATCH] Added /gone to allow configurable delay for state --- src/chat_session.c | 7 +++---- src/command.c | 31 +++++++++++++++++++++++++++++++ src/preferences.c | 13 +++++++++++++ src/preferences.h | 2 ++ src/windows.c | 9 +++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/chat_session.c b/src/chat_session.c index a2650b10..0b65c237 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -27,10 +27,10 @@ #include "chat_session.h" #include "log.h" +#include "preferences.h" #define PAUSED_TIMOUT 10.0 #define INACTIVE_TIMOUT 30.0 -#define GONE_TIMOUT 600.0 static void _chat_session_free(ChatSession session); @@ -113,7 +113,7 @@ chat_session_no_activity(const char * const recipient) if (session->active_timer != NULL) { gdouble elapsed = g_timer_elapsed(session->active_timer, NULL); - if (elapsed > GONE_TIMOUT) { + if ((prefs_get_gone() != 0) && (elapsed > (prefs_get_gone() * 60.0))) { if (session->state != CHAT_STATE_GONE) { session->sent = FALSE; } @@ -127,8 +127,7 @@ chat_session_no_activity(const char * const recipient) } else if (elapsed > PAUSED_TIMOUT) { - if ((session->state != CHAT_STATE_PAUSED) && - (session->state != CHAT_STATE_ACTIVE)) { + if (session->state == CHAT_STATE_COMPOSING) { session->sent = FALSE; } session->state = CHAT_STATE_PAUSED; diff --git a/src/command.c b/src/command.c index bd0ab01b..5e53e169 100644 --- a/src/command.c +++ b/src/command.c @@ -113,6 +113,7 @@ static gboolean _cmd_set_chlog(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_history(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_states(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_outtype(gchar **args, struct cmd_help_t help); +static gboolean _cmd_set_gone(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_autoping(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_titlebar(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_autoaway(gchar **args, struct cmd_help_t help); @@ -459,6 +460,17 @@ static struct cmd_t setting_commands[] = "Chat states must be enabled for this to work, see the /states command.", NULL } } }, + { "/gone", + _cmd_set_gone, parse_args, 1, 1, + { "/gone minutes", "Send 'gone' state to recipient.", + { "/gone minutes", + "--------------", + "Send a 'gone' state to the recipient after the specified number of minutes." + "This indicates to the recipient's client that you have left the conversation.", + "A value of 0 will disable sending this chat state automatically after a period.", + "Chat states must be enabled for this to work, see the /states command.", + NULL } } }, + { "/history", _cmd_set_history, parse_args, 1, 1, { "/history on|off", "Chat history in message windows.", @@ -1684,6 +1696,25 @@ _cmd_set_outtype(gchar **args, struct cmd_help_t help) "Sending typing notifications", prefs_set_outtype); } +static gboolean +_cmd_set_gone(gchar **args, struct cmd_help_t help) +{ + char *value = args[0]; + + gint period = atoi(value); + prefs_set_gone(period); + if (period == 0) { + cons_show("Automatic leaving conversations after period disabled."); + } else if (period == 1) { + cons_show("Leaving conversations after 1 minute of inactivity."); + } else { + cons_show("Leaving conversations after %d minutes of inactivity.", period); + } + + return TRUE; +} + + static gboolean _cmd_set_notify(gchar **args, struct cmd_help_t help) { diff --git a/src/preferences.c b/src/preferences.c index 5bf3e03a..cfad2787 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -140,6 +140,19 @@ prefs_set_outtype(gboolean value) _save_prefs(); } +gint +prefs_get_gone(void) +{ + return g_key_file_get_integer(prefs, "chatstates", "gone", NULL); +} + +void +prefs_set_gone(gint value) +{ + g_key_file_set_integer(prefs, "chatstates", "gone", value); + _save_prefs(); +} + gboolean prefs_get_notify_typing(void) { diff --git a/src/preferences.h b/src/preferences.h index 31550502..295f7e85 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -65,6 +65,8 @@ gboolean prefs_get_states(void); void prefs_set_states(gboolean value); gboolean prefs_get_outtype(void); void prefs_set_outtype(gboolean value); +gint prefs_get_gone(void); +void prefs_set_gone(gint value); gchar * prefs_get_theme(void); void prefs_set_theme(gchar *value); diff --git a/src/windows.c b/src/windows.c index 94698667..c71e4d41 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1259,6 +1259,15 @@ cons_show_chat_prefs(void) cons_show("Send composing (/outtype) : ON"); else cons_show("Send composing (/outtype) : OFF"); + + gint gone_time = prefs_get_gone(); + if (gone_time == 0) { + cons_show("Leave conversation (/gone) : OFF"); + } else if (gone_time == 1) { + cons_show("Leave conversation (/gone) : 1 minute"); + } else { + cons_show("Leave conversation (/gone) : %d minutes", gone_time); + } } void