From c7e214860cf97b0dfd3687b09d1a9a7ff3b891c9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Apr 2014 20:00:11 +0100 Subject: [PATCH 1/5] Removed create_title_bar from ui.h --- src/ui/core.c | 1 + src/ui/titlebar.c | 6 +++--- src/ui/titlebar.h | 23 +++++++++++++++++++++++ src/ui/ui.h | 1 - 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/ui/titlebar.h diff --git a/src/ui/core.c b/src/ui/core.c index 41cdfe0c..07e5bc11 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -50,6 +50,7 @@ #include "muc.h" #include "otr/otr.h" #include "ui/ui.h" +#include "ui/titlebar.h" #include "ui/window.h" #include "ui/windows.h" #include "xmpp/xmpp.h" diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 5c346137..e9e2e457 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -27,6 +27,7 @@ #include "config/theme.h" #include "config/preferences.h" #include "ui/ui.h" +#include "ui/titlebar.h" #include "ui/windows.h" #include "ui/window.h" #include "roster_list.h" @@ -43,8 +44,8 @@ static GTimer *typing_elapsed; static void _title_bar_draw(void); -static void -_create_title_bar(void) +void +create_title_bar(void) { int cols = getmaxx(stdscr); @@ -261,7 +262,6 @@ _title_bar_draw(void) void titlebar_init_module(void) { - create_title_bar = _create_title_bar; title_bar_console = _title_bar_console; title_bar_resize = _title_bar_resize; title_bar_update_virtual = _title_bar_update_virtual; diff --git a/src/ui/titlebar.h b/src/ui/titlebar.h new file mode 100644 index 00000000..11b015c6 --- /dev/null +++ b/src/ui/titlebar.h @@ -0,0 +1,23 @@ +/* + * titlebar.h + * + * Copyright (C) 2012 - 2014 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + +void create_title_bar(void); \ No newline at end of file diff --git a/src/ui/ui.h b/src/ui/ui.h index 1dd6b160..5d737b6a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -149,7 +149,6 @@ void (*ui_tidy_wins)(void); void (*ui_prune_wins)(void); // create windows -void (*create_title_bar)(void); void (*create_status_bar)(void); void (*create_input_window)(void); From fc40637789136a1fecbb7ec18fa60238b77abe13 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Apr 2014 20:41:06 +0100 Subject: [PATCH 2/5] 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 | 79 ++++++++++++++++++------------------------ src/ui/titlebar.h | 8 ++++- src/ui/ui.h | 16 ++++----- 8 files changed, 126 insertions(+), 101 deletions(-) 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,33 +57,8 @@ create_title_bar(void) inp_put_back(); } -static void -_title_bar_console(void) -{ - werase(win); - current_recipient = NULL; - typing = FALSE; - typing_elapsed = NULL; - - free(current_title); - current_title = strdup(CONSOLE_TITLE); - - _title_bar_draw(); -} - -static void -_title_bar_resize(void) -{ - int cols = getmaxx(stdscr); - - wresize(win, 1, cols); - wbkgd(win, COLOUR_TITLE_TEXT); - - _title_bar_draw(); -} - -static void -_title_bar_update_virtual(void) +void +title_bar_update_virtual(void) { if (current_recipient != NULL) { @@ -102,15 +77,40 @@ _title_bar_update_virtual(void) } } -static void -_title_bar_set_presence(contact_presence_t presence) +void +title_bar_resize(void) +{ + int cols = getmaxx(stdscr); + + wresize(win, 1, cols); + wbkgd(win, COLOUR_TITLE_TEXT); + + _title_bar_draw(); +} + +void +title_bar_console(void) +{ + werase(win); + current_recipient = NULL; + typing = FALSE; + typing_elapsed = NULL; + + free(current_title); + current_title = strdup(CONSOLE_TITLE); + + _title_bar_draw(); +} + +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); From f0f0dbfdac75aaaac04f0b86f996b962e8464785 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Apr 2014 21:12:30 +0100 Subject: [PATCH 3/5] Removed statusbar functions from ui.h --- Makefile.am | 3 ++ src/command/commands.c | 8 ++--- src/main.c | 1 - src/ui/console.c | 1 + src/ui/core.c | 19 ++++++++++++ src/ui/inputwin.c | 1 + src/ui/statusbar.c | 68 ++++++++++++++++-------------------------- src/ui/statusbar.h | 33 ++++++++++++++++++++ src/ui/ui.h | 17 ++--------- src/ui/windows.c | 1 + 10 files changed, 88 insertions(+), 64 deletions(-) create mode 100644 src/ui/statusbar.h diff --git a/Makefile.am b/Makefile.am index 13f2d591..92ff7537 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,6 +14,7 @@ core_sources = \ src/server_events.c src/server_events.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ + src/ui/titlebar.h src/ui/statusbar.h \ src/ui/console.c src/ui/notifier.c \ src/ui/windows.c src/ui/windows.h \ src/command/command.h src/command/command.c src/command/history.c \ @@ -50,6 +51,8 @@ tests_sources = \ src/config/theme.c src/config/theme.h \ src/ui/windows.c src/ui/windows.h \ src/ui/window.c src/ui/window.h \ + src/ui/titlebar.c src/ui/statusbar.c \ + src/ui/titlebar.h src/ui/statusbar.h \ src/server_events.c src/server_events.h \ tests/xmpp/mock_xmpp.h tests/xmpp/mock_xmpp.c \ tests/otr/mock_otr.h tests/otr/mock_otr.c \ diff --git a/src/command/commands.c b/src/command/commands.c index 65537f7b..a7deb17a 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -647,11 +647,7 @@ cmd_help(gchar **args, struct cmd_help_t help) gboolean cmd_about(gchar **args, struct cmd_help_t help) { - cons_show(""); - cons_about(); - if (ui_current_win_type() != WIN_CONSOLE) { - status_bar_new(1); - } + ui_about(); return TRUE; } @@ -952,7 +948,7 @@ cmd_who(gchar **args, struct cmd_help_t help) } if (win_type != WIN_CONSOLE && win_type != WIN_MUC) { - status_bar_new(1); + ui_statusbar_new(1); } return TRUE; diff --git a/src/main.c b/src/main.c index 5c18b924..8a455da7 100644 --- a/src/main.c +++ b/src/main.c @@ -56,7 +56,6 @@ _init_modules(void) console_init_module(); inputwin_init_module(); notifier_init_module(); - statusbar_init_module(); accounts_init_module(); #ifdef HAVE_LIBOTR diff --git a/src/ui/console.c b/src/ui/console.c index 7732a177..9d65df10 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -37,6 +37,7 @@ #include "ui/window.h" #include "ui/windows.h" #include "ui/ui.h" +#include "ui/statusbar.h" #include "xmpp/xmpp.h" #include "xmpp/bookmark.h" diff --git a/src/ui/core.c b/src/ui/core.c index bafd1987..c17b5394 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -51,6 +51,7 @@ #include "otr/otr.h" #include "ui/ui.h" #include "ui/titlebar.h" +#include "ui/statusbar.h" #include "ui/window.h" #include "ui/windows.h" #include "xmpp/xmpp.h" @@ -111,6 +112,16 @@ _ui_update_screen(void) doupdate(); } +static void +_ui_about(void) +{ + cons_show(""); + cons_about(); + if (ui_current_win_type() != WIN_CONSOLE) { + status_bar_new(1); + } +} + static unsigned long _ui_get_idle_time(void) { @@ -1578,6 +1589,12 @@ _ui_clear_win_title(void) printf("%c]0;%c", '\033', '\007'); } +static void +_ui_statusbar_new(const int win) +{ + status_bar_new(win); +} + static void _ui_draw_term_title(void) { @@ -1844,4 +1861,6 @@ ui_init_module(void) ui_titlebar_presence = _ui_titlebar_presence; ui_handle_login_account_success = _ui_handle_login_account_success; ui_update_presence =_ui_update_presence; + ui_about = _ui_about; + ui_statusbar_new = _ui_statusbar_new; } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 365eed02..e9f377b1 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -42,6 +42,7 @@ #include "profanity.h" #include "roster_list.h" #include "ui/ui.h" +#include "ui/statusbar.h" #include "ui/windows.h" #include "xmpp/xmpp.h" diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 738242e0..673997bb 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -34,6 +34,7 @@ #include "config/theme.h" #include "ui/ui.h" +#include "ui/statusbar.h" #define TIME_CHECK 60000000 @@ -55,8 +56,8 @@ static void _mark_active(int num); static void _mark_inactive(int num); static void _status_bar_draw(void); -static void -_create_status_bar(void) +void +create_status_bar(void) { int rows, cols, i; getmaxyx(stdscr, rows, cols); @@ -86,8 +87,8 @@ _create_status_bar(void) _status_bar_draw(); } -static void -_status_bar_update_virtual(void) +void +status_bar_update_virtual(void) { GDateTime *now_time = g_date_time_new_now_local(); GTimeSpan elapsed = g_date_time_difference(now_time, last_time); @@ -99,8 +100,8 @@ _status_bar_update_virtual(void) g_date_time_unref(now_time); } -static void -_status_bar_resize(void) +void +status_bar_resize(void) { int rows, cols; getmaxyx(stdscr, rows, cols); @@ -125,8 +126,8 @@ _status_bar_resize(void) _status_bar_draw(); } -static void -_status_bar_set_all_inactive(void) +void +status_bar_set_all_inactive(void) { int i = 0; for (i = 0; i < 12; i++) { @@ -141,8 +142,8 @@ _status_bar_set_all_inactive(void) _status_bar_draw(); } -static void -_status_bar_current(int i) +void +status_bar_current(int i) { if (i == 0) { current = 10; @@ -160,8 +161,8 @@ _status_bar_current(int i) _status_bar_draw(); } -static void -_status_bar_inactive(const int win) +void +status_bar_inactive(const int win) { int true_win = win; if (true_win == 0) { @@ -202,8 +203,8 @@ _status_bar_inactive(const int win) _status_bar_draw(); } -static void -_status_bar_active(const int win) +void +status_bar_active(const int win) { int true_win = win; if (true_win == 0) { @@ -238,8 +239,8 @@ _status_bar_active(const int win) _status_bar_draw(); } -static void -_status_bar_new(const int win) +void +status_bar_new(const int win) { int true_win = win; if (true_win == 0) { @@ -263,16 +264,16 @@ _status_bar_new(const int win) _status_bar_draw(); } -static void -_status_bar_get_password(void) +void +status_bar_get_password(void) { status_bar_print_message("Enter password:"); _status_bar_draw(); } -static void -_status_bar_print_message(const char * const msg) +void +status_bar_print_message(const char * const msg) { werase(status_bar); @@ -292,8 +293,8 @@ _status_bar_print_message(const char * const msg) _status_bar_draw(); } -static void -_status_bar_clear(void) +void +status_bar_clear(void) { if (message != NULL) { free(message); @@ -320,8 +321,8 @@ _status_bar_clear(void) _status_bar_draw(); } -static void -_status_bar_clear_message(void) +void +status_bar_clear_message(void) { if (message != NULL) { free(message); @@ -421,21 +422,4 @@ _status_bar_draw(void) _update_win_statuses(); wnoutrefresh(status_bar); inp_put_back(); -} - -void -statusbar_init_module(void) -{ - create_status_bar = _create_status_bar; - status_bar_update_virtual = _status_bar_update_virtual; - status_bar_resize = _status_bar_resize; - status_bar_set_all_inactive = _status_bar_set_all_inactive; - status_bar_current = _status_bar_current; - status_bar_inactive = _status_bar_inactive; - status_bar_active = _status_bar_active; - status_bar_new = _status_bar_new; - status_bar_get_password = _status_bar_get_password; - status_bar_print_message = _status_bar_print_message; - status_bar_clear = _status_bar_clear; - status_bar_clear_message = _status_bar_clear_message; -} +} \ No newline at end of file diff --git a/src/ui/statusbar.h b/src/ui/statusbar.h new file mode 100644 index 00000000..74af3a68 --- /dev/null +++ b/src/ui/statusbar.h @@ -0,0 +1,33 @@ +/* + * statusbar.h + * + * Copyright (C) 2012 - 2014 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + void create_status_bar(void); + void status_bar_update_virtual(void); + void status_bar_resize(void); + void status_bar_clear(void); + void status_bar_clear_message(void); + void status_bar_get_password(void); + void status_bar_print_message(const char * const msg); + void status_bar_inactive(const int win); + void status_bar_active(const int win); + void status_bar_new(const int win); + void status_bar_set_all_inactive(void); + void status_bar_current(int i); \ No newline at end of file diff --git a/src/ui/ui.h b/src/ui/ui.h index 737cbc8c..1bc71546 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -45,7 +45,6 @@ void ui_init_module(void); void console_init_module(void); void inputwin_init_module(void); void notifier_init_module(void); -void statusbar_init_module(void); // ui startup and control void (*ui_init)(void); @@ -153,9 +152,10 @@ 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); +void (*ui_about)(void); +void (*ui_statusbar_new)(const int win); // create windows -void (*create_status_bar)(void); void (*create_input_window)(void); // console window actions @@ -230,19 +230,6 @@ void (*cons_autoconnect_setting)(void); void (*cons_show_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity); void (*cons_show_contact_offline)(PContact contact, char *resource, char *status); -// status bar actions -void (*status_bar_update_virtual)(void); -void (*status_bar_resize)(void); -void (*status_bar_clear)(void); -void (*status_bar_clear_message)(void); -void (*status_bar_get_password)(void); -void (*status_bar_print_message)(const char * const msg); -void (*status_bar_inactive)(const int win); -void (*status_bar_active)(const int win); -void (*status_bar_new)(const int win); -void (*status_bar_set_all_inactive)(void); -void (*status_bar_current)(int i); - // input window actions wint_t (*inp_get_char)(char *input, int *size); void (*inp_win_reset)(void); diff --git a/src/ui/windows.c b/src/ui/windows.c index 83841837..75691f0d 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -36,6 +36,7 @@ #include "roster_list.h" #include "config/theme.h" #include "ui/ui.h" +#include "ui/statusbar.h" #include "ui/window.h" #include "ui/windows.h" From e2443511b6aab32b6ab3264fe0a044b81a86cc81 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Apr 2014 21:19:35 +0100 Subject: [PATCH 4/5] Tidied new headers, added defines --- src/ui/statusbar.h | 30 ++++++++++++++++++------------ src/ui/titlebar.h | 7 ++++++- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/ui/statusbar.h b/src/ui/statusbar.h index 74af3a68..1d457d9f 100644 --- a/src/ui/statusbar.h +++ b/src/ui/statusbar.h @@ -19,15 +19,21 @@ * along with Profanity. If not, see . * */ - void create_status_bar(void); - void status_bar_update_virtual(void); - void status_bar_resize(void); - void status_bar_clear(void); - void status_bar_clear_message(void); - void status_bar_get_password(void); - void status_bar_print_message(const char * const msg); - void status_bar_inactive(const int win); - void status_bar_active(const int win); - void status_bar_new(const int win); - void status_bar_set_all_inactive(void); - void status_bar_current(int i); \ No newline at end of file + +#ifndef UI_STATUSBAR_H +#define UI_STATUSBAR_H + +void create_status_bar(void); +void status_bar_update_virtual(void); +void status_bar_resize(void); +void status_bar_clear(void); +void status_bar_clear_message(void); +void status_bar_get_password(void); +void status_bar_print_message(const char * const msg); +void status_bar_inactive(const int win); +void status_bar_active(const int win); +void status_bar_new(const int win); +void status_bar_set_all_inactive(void); +void status_bar_current(int i); + +#endif \ No newline at end of file diff --git a/src/ui/titlebar.h b/src/ui/titlebar.h index 3980964d..bc4e6a57 100644 --- a/src/ui/titlebar.h +++ b/src/ui/titlebar.h @@ -20,10 +20,15 @@ * */ +#ifndef UI_TITLEBAR_H +#define UI_TITLEBAR_H + 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 +void title_bar_set_typing(gboolean is_typing); + +#endif \ No newline at end of file From 9aa282f6dea09b706957d6a16bde5b74fd9a55fc Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Apr 2014 21:50:28 +0100 Subject: [PATCH 5/5] Removed inputwin functions from ui.h --- Makefile.am | 6 ++--- src/command/command.c | 18 +++++++-------- src/main.c | 1 - src/profanity.c | 9 +++----- src/ui/core.c | 33 +++++++++++++++++++++++++++ src/ui/inputwin.c | 53 ++++++++++++++++--------------------------- src/ui/inputwin.h | 36 +++++++++++++++++++++++++++++ src/ui/statusbar.c | 1 + src/ui/titlebar.c | 1 + src/ui/ui.h | 16 ++++--------- 10 files changed, 110 insertions(+), 64 deletions(-) create mode 100644 src/ui/inputwin.h diff --git a/Makefile.am b/Makefile.am index 92ff7537..8e71f369 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,7 +14,7 @@ core_sources = \ src/server_events.c src/server_events.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ - src/ui/titlebar.h src/ui/statusbar.h \ + src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ src/ui/console.c src/ui/notifier.c \ src/ui/windows.c src/ui/windows.h \ src/command/command.h src/command/command.c src/command/history.c \ @@ -51,8 +51,8 @@ tests_sources = \ src/config/theme.c src/config/theme.h \ src/ui/windows.c src/ui/windows.h \ src/ui/window.c src/ui/window.h \ - src/ui/titlebar.c src/ui/statusbar.c \ - src/ui/titlebar.h src/ui/statusbar.h \ + src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ + src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ src/server_events.c src/server_events.h \ tests/xmpp/mock_xmpp.h tests/xmpp/mock_xmpp.c \ tests/otr/mock_otr.h tests/otr/mock_otr.c \ diff --git a/src/command/command.c b/src/command/command.c index d4ad2d1a..5e833ace 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1178,7 +1178,7 @@ cmd_autocomplete(char *input, int *size) found = autocomplete_complete(commands_ac, inp_cpy); if (found != NULL) { char *auto_msg = strdup(found); - inp_replace_input(input, auto_msg, size); + ui_replace_input(input, auto_msg, size); free(auto_msg); free(found); } @@ -1411,7 +1411,7 @@ _cmd_complete_parameters(char *input, int *size) result = autocomplete_param_with_func(input, size, boolean_choices[i], prefs_autocomplete_boolean_choice); if (result != NULL) { - inp_replace_input(input, result, size); + ui_replace_input(input, result, size); g_free(result); return; } @@ -1428,7 +1428,7 @@ _cmd_complete_parameters(char *input, int *size) result = autocomplete_param_with_ac(input, size, nick_choices[i], nick_ac); if (result != NULL) { - inp_replace_input(input, result, size); + ui_replace_input(input, result, size); g_free(result); return; } @@ -1442,7 +1442,7 @@ _cmd_complete_parameters(char *input, int *size) result = autocomplete_param_with_func(input, size, contact_choices[i], roster_find_contact); if (result != NULL) { - inp_replace_input(input, result, size); + ui_replace_input(input, result, size); g_free(result); return; } @@ -1453,7 +1453,7 @@ _cmd_complete_parameters(char *input, int *size) result = autocomplete_param_with_func(input, size, resource_choices[i], roster_find_resource); if (result != NULL) { - inp_replace_input(input, result, size); + ui_replace_input(input, result, size); g_free(result); return; } @@ -1462,7 +1462,7 @@ _cmd_complete_parameters(char *input, int *size) result = autocomplete_param_with_func(input, size, "/invite", roster_find_contact); if (result != NULL) { - inp_replace_input(input, result, size); + ui_replace_input(input, result, size); g_free(result); return; } @@ -1472,7 +1472,7 @@ _cmd_complete_parameters(char *input, int *size) result = autocomplete_param_with_func(input, size, invite_choices[i], muc_find_invite); if (result != NULL) { - inp_replace_input(input, result, size); + ui_replace_input(input, result, size); g_free(result); return; } @@ -1484,7 +1484,7 @@ _cmd_complete_parameters(char *input, int *size) for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, size, cmds[i], completers[i]); if (result != NULL) { - inp_replace_input(input, result, size); + ui_replace_input(input, result, size); g_free(result); return; } @@ -1500,7 +1500,7 @@ _cmd_complete_parameters(char *input, int *size) for (i = 0; i < ARRAY_SIZE(acs); i++) { result = acs[i](input, size); if (result != NULL) { - inp_replace_input(input, result, size); + ui_replace_input(input, result, size); g_free(result); return; } diff --git a/src/main.c b/src/main.c index 8a455da7..25eef65e 100644 --- a/src/main.c +++ b/src/main.c @@ -54,7 +54,6 @@ _init_modules(void) ui_init_module(); console_init_module(); - inputwin_init_module(); notifier_init_module(); accounts_init_module(); diff --git a/src/profanity.c b/src/profanity.c index fb33cffa..ce7dd35b 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -62,7 +62,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name) { _init(disable_tls, log_level); log_info("Starting main event loop"); - inp_non_block(); + ui_input_nonblocking(); GTimer *timer = g_timer_new(); gboolean cmd_result = TRUE; jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -104,10 +104,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name) ui_update_screen(); jabber_process_events(); - ch = inp_get_char(inp, &size); - if (ch != ERR) { - ui_reset_idle_time(); - } + ch = ui_get_char(inp, &size); } inp[size++] = '\0'; @@ -202,7 +199,7 @@ process_input(char *inp) result = cmd_execute_default(inp); } - inp_win_reset(); + ui_input_clear(); roster_reset_search_attempts(); ui_current_page_off(); diff --git a/src/ui/core.c b/src/ui/core.c index c17b5394..eaa0af48 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -52,6 +52,7 @@ #include "ui/ui.h" #include "ui/titlebar.h" #include "ui/statusbar.h" +#include "ui/inputwin.h" #include "ui/window.h" #include "ui/windows.h" #include "xmpp/xmpp.h" @@ -155,6 +156,34 @@ _ui_close(void) endwin(); } +static wint_t +_ui_get_char(char *input, int *size) +{ + wint_t ch = inp_get_char(input, size); + if (ch != ERR) { + ui_reset_idle_time(); + } + return ch; +} + +static void +_ui_input_clear(void) +{ + inp_win_reset(); +} + +static void +_ui_replace_input(char *input, const char * const new_input, int *size) +{ + inp_replace_input(input, new_input, size); +} + +static void +_ui_input_nonblocking(void) +{ + inp_non_block(); +} + static void _ui_resize(const int ch, const char * const input, const int size) { @@ -1863,4 +1892,8 @@ ui_init_module(void) ui_update_presence =_ui_update_presence; ui_about = _ui_about; ui_statusbar_new = _ui_statusbar_new; + ui_get_char = _ui_get_char; + ui_input_clear = _ui_input_clear; + ui_input_nonblocking = _ui_input_nonblocking; + ui_replace_input = _ui_replace_input; } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index e9f377b1..d528fd49 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -43,6 +43,7 @@ #include "roster_list.h" #include "ui/ui.h" #include "ui/statusbar.h" +#include "ui/inputwin.h" #include "ui/windows.h" #include "xmpp/xmpp.h" @@ -59,8 +60,8 @@ static int _printable(const wint_t ch); static void _clear_input(void); static void _go_to_end(int display_size); -static void -_create_input_window(void) +void +create_input_window(void) { #ifdef NCURSES_REENTRANT set_escdelay(25); @@ -75,8 +76,8 @@ _create_input_window(void) _inp_win_update_virtual(); } -static void -_inp_win_resize(const char * const input, const int size) +void +inp_win_resize(const char * const input, const int size) { int inp_x; getmaxyx(stdscr, rows, cols); @@ -93,20 +94,20 @@ _inp_win_resize(const char * const input, const int size) _inp_win_update_virtual(); } -static void -_inp_non_block(void) +void +inp_non_block(void) { wtimeout(inp_win, 20); } -static void -_inp_block(void) +void +inp_block(void) { wtimeout(inp_win, -1); } -static wint_t -_inp_get_char(char *input, int *size) +wint_t +inp_get_char(char *input, int *size) { int inp_x = 0; int i; @@ -208,8 +209,8 @@ _inp_get_char(char *input, int *size) return ch; } -static void -_inp_get_password(char *passwd) +void +inp_get_password(char *passwd) { _clear_input(); _inp_win_update_virtual(); @@ -221,14 +222,14 @@ _inp_get_password(char *passwd) status_bar_clear(); } -static void -_inp_put_back(void) +void +inp_put_back(void) { _inp_win_update_virtual(); } -static void -_inp_replace_input(char *input, const char * const new_input, int *size) +void +inp_replace_input(char *input, const char * const new_input, int *size) { int display_size; strncpy(input, new_input, INP_WIN_MAX); @@ -240,8 +241,8 @@ _inp_replace_input(char *input, const char * const new_input, int *size) _go_to_end(display_size); } -static void -_inp_win_reset(void) +void +inp_win_reset(void) { _clear_input(); pad_start = 0; @@ -708,18 +709,4 @@ _printable(const wint_t ch) bytes[utf_len] = '\0'; gunichar unichar = g_utf8_get_char(bytes); return g_unichar_isprint(unichar) && (ch != KEY_MOUSE); -} - -void -inputwin_init_module(void) -{ - create_input_window = _create_input_window; - inp_win_resize = _inp_win_resize; - inp_non_block = _inp_non_block; - inp_block = _inp_block; - inp_get_char = _inp_get_char; - inp_get_password = _inp_get_password; - inp_put_back = _inp_put_back; - inp_replace_input = _inp_replace_input; - inp_win_reset = _inp_win_reset; -} +} \ No newline at end of file diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h new file mode 100644 index 00000000..f208cbc3 --- /dev/null +++ b/src/ui/inputwin.h @@ -0,0 +1,36 @@ +/* + * inputwin.c + * + * Copyright (C) 2012 - 2014 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + +#ifndef UI_INPUTWIN_H +#define UI_INPUTWIN_H + +void create_input_window(void); +wint_t inp_get_char(char *input, int *size); +void inp_win_reset(void); +void inp_win_resize(const char * input, const int size); +void inp_put_back(void); +void inp_non_block(void); +void inp_block(void); +void inp_get_password(char *passwd); +void inp_replace_input(char *input, const char * const new_input, int *size); + +#endif \ No newline at end of file diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 673997bb..9ab0b69d 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -35,6 +35,7 @@ #include "config/theme.h" #include "ui/ui.h" #include "ui/statusbar.h" +#include "ui/inputwin.h" #define TIME_CHECK 60000000 diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index bc8fc947..395b2c6f 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -28,6 +28,7 @@ #include "config/preferences.h" #include "ui/ui.h" #include "ui/titlebar.h" +#include "ui/inputwin.h" #include "ui/windows.h" #include "ui/window.h" #include "roster_list.h" diff --git a/src/ui/ui.h b/src/ui/ui.h index 1bc71546..b76ab610 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -155,8 +155,10 @@ void (*ui_update_presence)(const resource_presence_t resource_presence, void (*ui_about)(void); void (*ui_statusbar_new)(const int win); -// create windows -void (*create_input_window)(void); +wint_t (*ui_get_char)(char *input, int *size); +void (*ui_input_clear)(void); +void (*ui_input_nonblocking)(void); +void (*ui_replace_input)(char *input, const char * const new_input, int *size); // console window actions void (*cons_show)(const char * const msg, ...); @@ -230,16 +232,6 @@ void (*cons_autoconnect_setting)(void); void (*cons_show_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity); void (*cons_show_contact_offline)(PContact contact, char *resource, char *status); -// input window actions -wint_t (*inp_get_char)(char *input, int *size); -void (*inp_win_reset)(void); -void (*inp_win_resize)(const char * input, const int size); -void (*inp_put_back)(void); -void (*inp_non_block)(void); -void (*inp_block)(void); -void (*inp_get_password)(char *passwd); -void (*inp_replace_input)(char *input, const char * const new_input, int *size); - // desktop notifier actions void (*notifier_init)(void); void (*notifier_uninit)(void);