From fc40637789136a1fecbb7ec18fa60238b77abe13 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Apr 2014 20:41:06 +0100 Subject: Removed titlebar functions from ui.h --- src/command/commands.c | 12 +------- src/main.c | 1 - src/profanity.c | 30 +++----------------- src/server_events.c | 12 +++----- src/ui/core.c | 69 ++++++++++++++++++++++++++++++++++++++++++++ src/ui/titlebar.c | 77 ++++++++++++++++++++++---------------------------- src/ui/titlebar.h | 8 +++++- src/ui/ui.h | 16 +++++------ 8 files changed, 125 insertions(+), 100 deletions(-) (limited to 'src') diff --git a/src/command/commands.c b/src/command/commands.c index f179fcb8..65537f7b 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2790,18 +2790,8 @@ _update_presence(const resource_presence_t resource_presence, cons_show("You are not currently connected."); } else { presence_update(resource_presence, msg, 0); - - contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); - title_bar_set_presence(contact_presence); - - gint priority = accounts_get_priority_for_presence_type(jabber_get_account_name(), resource_presence); - if (msg != NULL) { - cons_show("Status set to %s (priority %d), \"%s\".", show, priority, msg); - } else { - cons_show("Status set to %s (priority %d).", show, priority); - } + ui_update_presence(resource_presence, msg, show); } - } // helper function for boolean preference commands diff --git a/src/main.c b/src/main.c index d26b737c..5c18b924 100644 --- a/src/main.c +++ b/src/main.c @@ -57,7 +57,6 @@ _init_modules(void) inputwin_init_module(); notifier_init_module(); statusbar_init_module(); - titlebar_init_module(); accounts_init_module(); #ifdef HAVE_LIBOTR diff --git a/src/profanity.c b/src/profanity.c index 43eee835..fb33cffa 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -224,28 +224,11 @@ _handle_idle_time() // 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(); - } + ui_auto_away(); // 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); + presence_update(RESOURCE_ONLINE, prefs_get_string(PREF_AUTOAWAY_MESSAGE), idle_ms / 1000); } } } @@ -258,15 +241,10 @@ _handle_idle_time() 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(); + ui_end_auto_away(); } else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) { presence_update(RESOURCE_ONLINE, NULL, 0); - title_bar_set_presence(CONTACT_ONLINE); + ui_titlebar_presence(CONTACT_ONLINE); } } } diff --git a/src/server_events.c b/src/server_events.c index ac1fb2f5..566d460b 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -87,18 +87,14 @@ void handle_login_account_success(char *account_name) { ProfAccount *account = accounts_get_account(account_name); + #ifdef HAVE_LIBOTR otr_on_connect(account); #endif - resource_presence_t resource_presence = accounts_get_login_presence(account->name); - contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); - cons_show_login_success(account); - title_bar_set_presence(contact_presence); - log_info("%s logged in successfully", account->jid); - ui_current_page_off(); - status_bar_print_message(account->jid); - status_bar_update_virtual(); + ui_handle_login_account_success(account); + + log_info("%s logged in successfully", account->jid); account_free(account); } diff --git a/src/ui/core.c b/src/ui/core.c index 07e5bc11..bafd1987 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -351,6 +351,70 @@ _ui_group_removed(const char * const contact, const char * const group) cons_show("%s removed from group %s", contact, group); } +static void +_ui_auto_away(void) +{ + 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(); + } +} + +static void +_ui_end_auto_away(void) +{ + 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(); +} + +static void +_ui_titlebar_presence(contact_presence_t presence) +{ + title_bar_set_presence(presence); +} + +static void +_ui_handle_login_account_success(ProfAccount *account) +{ + resource_presence_t resource_presence = accounts_get_login_presence(account->name); + contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); + cons_show_login_success(account); + title_bar_set_presence(contact_presence); + ui_current_page_off(); + status_bar_print_message(account->jid); + status_bar_update_virtual(); +} + +static void +_ui_update_presence(const resource_presence_t resource_presence, + const char * const message, const char * const show) +{ + contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); + title_bar_set_presence(contact_presence); + gint priority = accounts_get_priority_for_presence_type(jabber_get_account_name(), resource_presence); + if (message != NULL) { + cons_show("Status set to %s (priority %d), \"%s\".", show, priority, message); + } else { + cons_show("Status set to %s (priority %d).", show, priority); + } +} + static void _ui_handle_recipient_not_found(const char * const recipient, const char * const err_msg) { @@ -1775,4 +1839,9 @@ ui_init_module(void) ui_handle_error = _ui_handle_error; ui_current_update_virtual = _ui_current_update_virtual; ui_clear_win_title = _ui_clear_win_title; + ui_auto_away = _ui_auto_away; + ui_end_auto_away = _ui_end_auto_away; + ui_titlebar_presence = _ui_titlebar_presence; + ui_handle_login_account_success = _ui_handle_login_account_success; + ui_update_presence =_ui_update_presence; } diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index e9e2e457..bc8fc947 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -57,22 +57,28 @@ create_title_bar(void) inp_put_back(); } -static void -_title_bar_console(void) +void +title_bar_update_virtual(void) { - werase(win); - current_recipient = NULL; - typing = FALSE; - typing_elapsed = NULL; + if (current_recipient != NULL) { - free(current_title); - current_title = strdup(CONSOLE_TITLE); + if (typing_elapsed != NULL) { + gdouble seconds = g_timer_elapsed(typing_elapsed, NULL); - _title_bar_draw(); + if (seconds >= 10) { + typing = FALSE; + + g_timer_destroy(typing_elapsed); + typing_elapsed = NULL; + + _title_bar_draw(); + } + } + } } -static void -_title_bar_resize(void) +void +title_bar_resize(void) { int cols = getmaxx(stdscr); @@ -82,35 +88,29 @@ _title_bar_resize(void) _title_bar_draw(); } -static void -_title_bar_update_virtual(void) +void +title_bar_console(void) { - if (current_recipient != NULL) { - - if (typing_elapsed != NULL) { - gdouble seconds = g_timer_elapsed(typing_elapsed, NULL); - - if (seconds >= 10) { - typing = FALSE; + werase(win); + current_recipient = NULL; + typing = FALSE; + typing_elapsed = NULL; - g_timer_destroy(typing_elapsed); - typing_elapsed = NULL; + free(current_title); + current_title = strdup(CONSOLE_TITLE); - _title_bar_draw(); - } - } - } + _title_bar_draw(); } -static void -_title_bar_set_presence(contact_presence_t presence) +void +title_bar_set_presence(contact_presence_t presence) { current_presence = presence; _title_bar_draw(); } -static void -_title_bar_set_recipient(const char * const recipient) +void +title_bar_set_recipient(const char * const recipient) { if (typing_elapsed != NULL) { g_timer_destroy(typing_elapsed); @@ -127,8 +127,8 @@ _title_bar_set_recipient(const char * const recipient) _title_bar_draw(); } -static void -_title_bar_set_typing(gboolean is_typing) +void +title_bar_set_typing(gboolean is_typing) { if (is_typing) { if (typing_elapsed != NULL) { @@ -257,15 +257,4 @@ _title_bar_draw(void) wnoutrefresh(win); inp_put_back(); -} - -void -titlebar_init_module(void) -{ - title_bar_console = _title_bar_console; - title_bar_resize = _title_bar_resize; - title_bar_update_virtual = _title_bar_update_virtual; - title_bar_set_presence = _title_bar_set_presence; - title_bar_set_recipient = _title_bar_set_recipient; - title_bar_set_typing = _title_bar_set_typing; -} +} \ No newline at end of file diff --git a/src/ui/titlebar.h b/src/ui/titlebar.h index 11b015c6..3980964d 100644 --- a/src/ui/titlebar.h +++ b/src/ui/titlebar.h @@ -20,4 +20,10 @@ * */ -void create_title_bar(void); \ No newline at end of file +void create_title_bar(void); +void title_bar_update_virtual(void); +void title_bar_resize(void); +void title_bar_console(void); +void title_bar_set_presence(contact_presence_t presence); +void title_bar_set_recipient(const char * const from); +void title_bar_set_typing(gboolean is_typing); \ No newline at end of file diff --git a/src/ui/ui.h b/src/ui/ui.h index 5d737b6a..737cbc8c 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -46,7 +46,6 @@ void console_init_module(void); void inputwin_init_module(void); void notifier_init_module(void); void statusbar_init_module(void); -void titlebar_init_module(void); // ui startup and control void (*ui_init)(void); @@ -148,18 +147,17 @@ gboolean (*ui_duck_exists)(void); void (*ui_tidy_wins)(void); void (*ui_prune_wins)(void); +void (*ui_auto_away)(void); +void (*ui_end_auto_away)(void); +void (*ui_titlebar_presence)(contact_presence_t presence); +void (*ui_handle_login_account_success)(ProfAccount *account); +void (*ui_update_presence)(const resource_presence_t resource_presence, + const char * const message, const char * const show); + // create windows void (*create_status_bar)(void); void (*create_input_window)(void); -// title bar actions -void (*title_bar_update_virtual)(void); -void (*title_bar_resize)(void); -void (*title_bar_console)(void); -void (*title_bar_set_presence)(contact_presence_t presence); -void (*title_bar_set_recipient)(const char * const from); -void (*title_bar_set_typing)(gboolean is_typing); - // console window actions void (*cons_show)(const char * const msg, ...); void (*cons_about)(void); -- cgit 1.4.1-2-gfad0