From 06abe13f196638e7e9ee0a0b293a82f2a4d6ad66 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 31 Jan 2013 00:40:27 +0000 Subject: [PATCH] Show current presence when logging in Also show correct presence in title bar upon login --- src/accounts.c | 2 +- src/accounts.h | 2 +- src/profanity.c | 9 ++++----- src/ui.h | 1 + src/ui_windows.c | 34 ++++++++++++++++++++++++++++++++++ src/xmpp_iq.c | 2 +- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/accounts.c b/src/accounts.c index 5cfbe299..d7149b77 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -365,7 +365,7 @@ accounts_get_last_presence(const char * const account_name) } jabber_presence_t -account_get_login_presence(const char * const account_name) +accounts_get_login_presence(const char * const account_name) { gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL); if (setting == NULL || (strcmp(setting, "online") == 0)) { diff --git a/src/accounts.h b/src/accounts.h index bf05ba93..f6e54358 100644 --- a/src/accounts.h +++ b/src/accounts.h @@ -56,7 +56,7 @@ void accounts_set_server(const char * const account_name, const char * const val void accounts_set_resource(const char * const account_name, const char * const value); void accounts_set_last_presence(const char * const account_name, const char * const value); void accounts_set_login_presence(const char * const account_name, const char * const value); -jabber_presence_t account_get_login_presence(const char * const account_name); +jabber_presence_t accounts_get_login_presence(const char * const account_name); jabber_presence_t accounts_get_last_presence(const char * const account_name); #endif diff --git a/src/profanity.c b/src/profanity.c index f46ffca5..f3fb2bfc 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -198,11 +198,10 @@ void prof_handle_login_account_success(char *account_name) { ProfAccount *account = accounts_get_account(account_name); - - const char *msg = "logged in successfully."; - cons_show("%s %s", account->jid, msg); - title_bar_set_status(PRESENCE_ONLINE); - log_info("%s %s", account->jid, msg); + jabber_presence_t presence = accounts_get_login_presence(account->name); + cons_show_login_success(account); + title_bar_set_status(presence); + log_info("%s logged in successfully", account->jid); win_current_page_off(); status_bar_print_message(account->jid); status_bar_refresh(); diff --git a/src/ui.h b/src/ui.h index d336af08..2d58f755 100644 --- a/src/ui.h +++ b/src/ui.h @@ -166,6 +166,7 @@ void cons_show_wins(void); void cons_show_status(const char * const contact); void cons_show_info(PContact pcontact); void cons_show_themes(GSList *themes); +void cons_show_login_success(ProfAccount *account); // status bar actions void status_bar_refresh(void); diff --git a/src/ui_windows.c b/src/ui_windows.c index 26e7a197..b17536e5 100644 --- a/src/ui_windows.c +++ b/src/ui_windows.c @@ -1083,6 +1083,40 @@ win_show_room_broadcast(const char * const room_jid, const char * const message) } } +void +cons_show_login_success(ProfAccount *account) +{ + _win_show_time(console->win, '-'); + wprintw(console->win, "%s logged in successfully, ", account->jid); + + jabber_presence_t presence = accounts_get_login_presence(account->name); + char *presence_str; + switch(presence) + { + case PRESENCE_CHAT: + presence_str = "chat"; + break; + case PRESENCE_AWAY: + presence_str = "away"; + break; + case PRESENCE_XA: + presence_str = "xa"; + break; + case PRESENCE_DND: + presence_str = "dnd"; + break; + default: + presence_str = "online"; + break; + } + + _presence_colour_on(console->win, presence_str); + wprintw(console->win, "%s", presence_str); + _presence_colour_off(console->win, presence_str); + wprintw(console->win, ".\n"); +} + + void cons_show_wins(void) { diff --git a/src/xmpp_iq.c b/src/xmpp_iq.c index 60722080..1b3a3f25 100644 --- a/src/xmpp_iq.c +++ b/src/xmpp_iq.c @@ -149,7 +149,7 @@ _iq_handle_roster_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, item = xmpp_stanza_get_next(item); } - jabber_presence_t connect_presence = account_get_login_presence(jabber_get_account_name()); + jabber_presence_t connect_presence = accounts_get_login_presence(jabber_get_account_name()); presence_update(connect_presence, NULL, 0); }