static void _check_autoaway() { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { return; } gint prefs_time = prefs_get_autoaway_time() * 60000; unsigned long idle_ms = ui_get_idle_time(); char *pref_autoaway_mode = prefs_get_string(PREF_AUTOAWAY_MODE); if (!idle) { resource_presence_t current_presence = accounts_get_last_presence(jabber_get_account_name()); if ((current_presence == RESOURCE_ONLINE) || (current_presence == RESOURCE_CHAT)) { if (idle_ms >= prefs_time) { idle = TRUE; char *pref_autoaway_message = prefs_get_string(PREF_AUTOAWAY_MESSAGE); // handle away mode if (strcmp(pref_autoaway_mode, "away") == 0) { presence_update(RESOURCE_AWAY, pref_autoaway_message, 0); ui_auto_away(); // handle idle mode } else if (strcmp(pref_autoaway_mode, "idle") == 0) { presence_update(RESOURCE_ONLINE, pref_autoaway_message, idle_ms / 1000); } prefs_free_string(pref_autoaway_message); } } } else { if (idle_ms < prefs_time) { idle = FALSE; // handle check if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) { if (strcmp(pref_autoaway_mode, "away") == 0) { presence_update(RESOURCE_ONLINE, NULL, 0); ui_end_auto_away(); } else if (strcmp(pref_autoaway_mode, "idle") == 0) { presence_update(RESOURCE_ONLINE, NULL, 0); ui_titlebar_presence(CONTACT_ONLINE); } } } } prefs_free_string(pref_autoaway_mode); }
void cons_autoaway_setting(void) { if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "off") == 0) { cons_show("Autoaway (/autoaway mode) : OFF"); } else { cons_show("Autoaway (/autoaway mode) : %s", prefs_get_string(PREF_AUTOAWAY_MODE)); } cons_show("Autoaway minutes (/autoaway time) : %d minutes", prefs_get_autoaway_time()); if ((prefs_get_string(PREF_AUTOAWAY_MESSAGE) == NULL) || (strcmp(prefs_get_string(PREF_AUTOAWAY_MESSAGE), "") == 0)) { cons_show("Autoaway message (/autoaway message) : OFF"); } else { cons_show("Autoaway message (/autoaway message) : \"%s\"", prefs_get_string(PREF_AUTOAWAY_MESSAGE)); } if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) { cons_show("Autoaway check (/autoaway check) : ON"); } else { cons_show("Autoaway check (/autoaway check) : OFF"); } }
static void _check_autoaway() { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { return; } char *mode = prefs_get_string(PREF_AUTOAWAY_MODE); gboolean check = prefs_get_boolean(PREF_AUTOAWAY_CHECK); gint away_time = prefs_get_autoaway_time(); gint xa_time = prefs_get_autoxa_time(); int away_time_ms = away_time * 60000; int xa_time_ms = xa_time * 60000; char *account = jabber_get_account_name(); resource_presence_t curr_presence = accounts_get_last_presence(account); char *curr_status = accounts_get_last_status(account); unsigned long idle_ms = ui_get_idle_time(); switch (activity_state) { case ACTIVITY_ST_ACTIVE: if (idle_ms >= away_time_ms) { if (g_strcmp0(mode, "away") == 0) { if ((curr_presence == RESOURCE_ONLINE) || (curr_presence == RESOURCE_CHAT) || (curr_presence == RESOURCE_DND)) { activity_state = ACTIVITY_ST_AWAY; // save current presence saved_presence = curr_presence; if (saved_status) { free(saved_status); } saved_status = curr_status; // send away presence with last activity char *message = prefs_get_string(PREF_AUTOAWAY_MESSAGE); if (prefs_get_boolean(PREF_LASTACTIVITY)) { cl_ev_presence_send(RESOURCE_AWAY, message, idle_ms / 1000); } else { cl_ev_presence_send(RESOURCE_AWAY, message, 0); } int pri = accounts_get_priority_for_presence_type(account, RESOURCE_AWAY); if (message) { cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".", away_time, pri, message); } else { cons_show("Idle for %d minutes, status set to away (priority %d).", away_time, pri); } prefs_free_string(message); ui_titlebar_presence(CONTACT_AWAY); } } else if (g_strcmp0(mode, "idle") == 0) { activity_state = ACTIVITY_ST_IDLE; // send current presence with last activity cl_ev_presence_send(curr_presence, curr_status, idle_ms / 1000); } } break; case ACTIVITY_ST_IDLE: if (check && (idle_ms < away_time_ms)) { activity_state = ACTIVITY_ST_ACTIVE; cons_show("No longer idle."); // send current presence without last activity cl_ev_presence_send(curr_presence, curr_status, 0); } break; case ACTIVITY_ST_AWAY: if (xa_time_ms > 0 && (idle_ms >= xa_time_ms)) { activity_state = ACTIVITY_ST_XA; // send extended away presence with last activity char *message = prefs_get_string(PREF_AUTOXA_MESSAGE); if (prefs_get_boolean(PREF_LASTACTIVITY)) { cl_ev_presence_send(RESOURCE_XA, message, idle_ms / 1000); } else { cl_ev_presence_send(RESOURCE_XA, message, 0); } int pri = accounts_get_priority_for_presence_type(account, RESOURCE_XA); if (message) { cons_show("Idle for %d minutes, status set to xa (priority %d), \"%s\".", xa_time, pri, message); } else { cons_show("Idle for %d minutes, status set to xa (priority %d).", xa_time, pri); } prefs_free_string(message); ui_titlebar_presence(CONTACT_XA); } else if (check && (idle_ms < away_time_ms)) { activity_state = ACTIVITY_ST_ACTIVE; cons_show("No longer idle."); // send saved presence without last activity cl_ev_presence_send(saved_presence, saved_status, 0); contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence); ui_titlebar_presence(contact_pres); } break; case ACTIVITY_ST_XA: if (check && (idle_ms < away_time_ms)) { activity_state = ACTIVITY_ST_ACTIVE; cons_show("No longer idle."); // send saved presence without last activity cl_ev_presence_send(saved_presence, saved_status, 0); contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence); ui_titlebar_presence(contact_pres); } break; } prefs_free_string(mode); }
static void _handle_idle_time() { gint prefs_time = prefs_get_autoaway_time() * 60000; resource_presence_t current_presence = accounts_get_last_presence(jabber_get_account_name()); unsigned long idle_ms = ui_get_idle_time(); if (!idle) { if ((current_presence == RESOURCE_ONLINE) || (current_presence == RESOURCE_CHAT)) { if (idle_ms >= prefs_time) { idle = TRUE; // handle away mode if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) { presence_update(RESOURCE_AWAY, prefs_get_string(PREF_AUTOAWAY_MESSAGE), 0); if (prefs_get_string(PREF_AUTOAWAY_MESSAGE) != NULL) { int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), RESOURCE_AWAY); cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".", prefs_get_autoaway_time(), pri, prefs_get_string(PREF_AUTOAWAY_MESSAGE)); title_bar_set_presence(CONTACT_AWAY); ui_current_page_off(); } else { int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), RESOURCE_AWAY); cons_show("Idle for %d minutes, status set to away (priority %d).", prefs_get_autoaway_time(), pri); title_bar_set_presence(CONTACT_AWAY); ui_current_page_off(); } // handle idle mode } else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) { presence_update(RESOURCE_ONLINE, prefs_get_string(PREF_AUTOAWAY_MESSAGE), idle_ms / 1000); } } } } else { if (idle_ms < prefs_time) { idle = FALSE; // handle check if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) { if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) { presence_update(RESOURCE_ONLINE, NULL, 0); int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), RESOURCE_ONLINE); cons_show("No longer idle, status set to online (priority %d).", pri); title_bar_set_presence(CONTACT_ONLINE); ui_current_page_off(); } else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) { presence_update(RESOURCE_ONLINE, NULL, 0); title_bar_set_presence(CONTACT_ONLINE); } } } } }