void ui_duck_result(const char * const result) { ProfWin *window = wins_get_by_recipient("DuckDuckGo search"); if (window != NULL) { win_print_time(window, '-'); wattron(window->win, COLOUR_THEM); wprintw(window->win, "Result : "); wattroff(window->win, COLOUR_THEM); glong offset = 0; while (offset < g_utf8_strlen(result, -1)) { gchar *ptr = g_utf8_offset_to_pointer(result, offset); gunichar unichar = g_utf8_get_char(ptr); if (unichar == '\n') { wprintw(window->win, "\n"); win_print_time(window, '-'); } else { gchar *string = g_ucs4_to_utf8(&unichar, 1, NULL, NULL, NULL); if (string != NULL) { wprintw(window->win, string); g_free(string); } } offset++; } wprintw(window->win, "\n"); } }
void cons_check_version(gboolean not_available_msg) { char *latest_release = release_get_latest(); if (latest_release != NULL) { gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); if (relase_valid) { if (release_is_new(latest_release)) { win_print_time(console, '-'); wprintw(console->win, "A new version of Profanity is available: %s", latest_release); win_print_time(console, '-'); wprintw(console->win, "Check <http://www.profanity.im> for details.\n"); free(latest_release); win_print_time(console, '-'); wprintw(console->win, "\n"); } else { if (not_available_msg) { cons_show("No new version available."); cons_show(""); } } ui_console_dirty(); cons_alert(); } } }
static void _cons_splash_logo(void) { win_print_time(console, '-'); wprintw(console->win, "Welcome to\n"); win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " ___ _ \n"); wattroff(console->win, COLOUR_SPLASH); win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " / __) (_)_ \n"); wattroff(console->win, COLOUR_SPLASH); win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n"); wattroff(console->win, COLOUR_SPLASH); win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n"); wattroff(console->win, COLOUR_SPLASH); win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n"); wattroff(console->win, COLOUR_SPLASH); win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n"); wattroff(console->win, COLOUR_SPLASH); win_print_time(console, '-'); wattron(console->win, COLOUR_SPLASH); wprintw(console->win, "|_| (____/ \n"); wattroff(console->win, COLOUR_SPLASH); win_print_time(console, '-'); wprintw(console->win, "\n"); win_print_time(console, '-'); if (strcmp(PACKAGE_STATUS, "development") == 0) { wprintw(console->win, "Version %sdev\n", PACKAGE_VERSION); } else { wprintw(console->win, "Version %s\n", PACKAGE_VERSION); } }
void ui_duck(const char * const query) { ProfWin *window = wins_get_by_recipient("DuckDuckGo search"); if (window != NULL) { win_print_time(window, '-'); wprintw(window->win, "\n"); win_print_time(window, '-'); wattron(window->win, COLOUR_ME); wprintw(window->win, "Query : "); wattroff(window->win, COLOUR_ME); wprintw(window->win, query); wprintw(window->win, "\n"); } }
void cons_show_account_list(gchar **accounts) { int size = g_strv_length(accounts); if (size > 0) { cons_show("Accounts:"); int i = 0; for (i = 0; i < size; i++) { if ((jabber_get_connection_status() == JABBER_CONNECTED) && (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); win_print_time(console, '-'); win_presence_colour_on(console, string_from_resource_presence(presence)); wprintw(console->win, "%s\n", accounts[i]); win_presence_colour_off(console, string_from_resource_presence(presence)); } else { cons_show(accounts[i]); } } cons_show(""); } else { cons_show("No accounts created yet."); cons_show(""); } ui_console_dirty(); cons_alert(); }
static void _win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, const char * const from, const char * const message) { if (tv_stamp == NULL) { win_print_time(window, '-'); } else { GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp); gchar *date_fmt = g_date_time_format(time, "%H:%M:%S"); wattron(window->win, COLOUR_TIME); wprintw(window->win, "%s - ", date_fmt); wattroff(window->win, COLOUR_TIME); g_date_time_unref(time); g_free(date_fmt); } if (strncmp(message, "/me ", 4) == 0) { wattron(window->win, COLOUR_THEM); wprintw(window->win, "*%s ", from); waddstr(window->win, message + 4); wprintw(window->win, "\n"); wattroff(window->win, COLOUR_THEM); } else { wattron(window->win, COLOUR_THEM); wprintw(window->win, "%s: ", from); wattroff(window->win, COLOUR_THEM); waddstr(window->win, message); wprintw(window->win, "\n"); } }
void ui_recipient_gone(const char * const barejid) { if (barejid == NULL) return; PContact contact = roster_get_contact(barejid); const char * display_usr = NULL; if (p_contact_name(contact) != NULL) { display_usr = p_contact_name(contact); } else { display_usr = barejid; } ProfWin *window = wins_get_by_recipient(barejid); if (window != NULL) { win_print_time(window, '!'); wattron(window->win, COLOUR_GONE); wprintw(window->win, "<- %s ", display_usr); wprintw(window->win, "has left the conversation."); wprintw(window->win, "\n"); wattroff(window->win, COLOUR_GONE); if (wins_is_current(window)) { wins_refresh_current(); } } }
void cons_show_bookmarks(const GList *list) { Bookmark *item; cons_show(""); cons_show("Bookmarks:"); /* TODO: show status (connected or not) and window number */ while (list != NULL) { item = list->data; win_print_time(console, '-'); wprintw(console->win, " %s", item->jid); if (item->nick != NULL) { wprintw(console->win, "/%s", item->nick); } if (item->autojoin) { wprintw(console->win, " (autojoin)"); } wprintw(console->win, "\n"); list = g_list_next(list); } ui_console_dirty(); cons_alert(); }
void ui_print_system_msg_from_recipient(const char * const from, const char *message) { int num = 0; char from_cpy[strlen(from) + 1]; char *bare_jid; if (from == NULL || message == NULL) return; strcpy(from_cpy, from); bare_jid = strtok(from_cpy, "/"); ProfWin *window = wins_get_by_recipient(bare_jid); if (window == NULL) { window = wins_new(bare_jid, WIN_CHAT); if (window != NULL) { num = wins_get_num(window); status_bar_active(num); } else { num = 0; window = wins_get_console(); status_bar_active(1); } } win_print_time(window, '-'); wprintw(window->win, "*%s %s\n", bare_jid, message); // this is the current window if (wins_is_current(window)) { wins_refresh_current(); } }
void cons_show_software_version(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os) { if ((name != NULL) || (version != NULL) || (os != NULL)) { cons_show(""); win_print_time(console, '-'); win_presence_colour_on(console, presence); wprintw(console->win, "%s", jid); win_presence_colour_off(console, presence); wprintw(console->win, ":\n"); } if (name != NULL) { cons_show("Name : %s", name); } if (version != NULL) { cons_show("Version : %s", version); } if (os != NULL) { cons_show("OS : %s", os); } ui_console_dirty(); cons_alert(); }
void win_print_line(ProfWin *window, const char show_char, int attrs, const char * const msg) { win_print_time(window, show_char); wattron(window->win, attrs); wprintw(window->win, "%s\n", msg); wattroff(window->win, attrs); }
void ui_create_duck_win(void) { ProfWin *window = wins_new("DuckDuckGo search", WIN_DUCK); int num = wins_get_num(window); ui_switch_win(num); win_print_time(window, '-'); wprintw(window->win, "Type ':help' to find out more.\n"); }
void ui_current_error_line(const char * const msg) { ProfWin *current = wins_get_current(); win_print_time(current, '-'); wattron(current->win, COLOUR_ERROR); wprintw(current->win, "%s\n", msg); wattroff(current->win, COLOUR_ERROR); wins_refresh_current(); }
void ui_room_roster(const char * const room, GList *roster, const char * const presence) { ProfWin *window = wins_get_by_recipient(room); win_print_time(window, '!'); if ((roster == NULL) || (g_list_length(roster) == 0)) { wattron(window->win, COLOUR_ROOMINFO); if (presence == NULL) { wprintw(window->win, "Room is empty.\n"); } else { wprintw(window->win, "No participants %s.\n", presence); } wattroff(window->win, COLOUR_ROOMINFO); } else { int length = g_list_length(roster); wattron(window->win, COLOUR_ROOMINFO); if (presence == NULL) { length++; wprintw(window->win, "%d participants: ", length); wattroff(window->win, COLOUR_ROOMINFO); wattron(window->win, COLOUR_ONLINE); wprintw(window->win, "%s", muc_get_room_nick(room)); wprintw(window->win, ", "); } else { wprintw(window->win, "%d %s: ", length, presence); wattroff(window->win, COLOUR_ROOMINFO); wattron(window->win, COLOUR_ONLINE); } while (roster != NULL) { PContact member = roster->data; const char const *nick = p_contact_barejid(member); const char const *show = p_contact_presence(member); win_presence_colour_on(window, show); wprintw(window->win, "%s", nick); win_presence_colour_off(window, show); if (roster->next != NULL) { wprintw(window->win, ", "); } roster = g_list_next(roster); } wprintw(window->win, "\n"); wattroff(window->win, COLOUR_ONLINE); } if (wins_is_current(window)) { wins_refresh_current(); } }
void cons_show(const char * const msg, ...) { va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_print_time(console, '-'); wprintw(console->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); ui_console_dirty(); }
void cons_about(void) { int rows, cols; getmaxyx(stdscr, rows, cols); if (prefs_get_boolean(PREF_SPLASH)) { _cons_splash_logo(); } else { win_print_time(console, '-'); if (strcmp(PACKAGE_STATUS, "development") == 0) { wprintw(console->win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION); } else { wprintw(console->win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION); } } win_print_time(console, '-'); wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT); win_print_time(console, '-'); wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"); win_print_time(console, '-'); wprintw(console->win, "\n"); win_print_time(console, '-'); wprintw(console->win, "This is free software; you are free to change and redistribute it.\n"); win_print_time(console, '-'); wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n"); win_print_time(console, '-'); wprintw(console->win, "\n"); win_print_time(console, '-'); wprintw(console->win, "Type '/help' to show complete help.\n"); win_print_time(console, '-'); wprintw(console->win, "\n"); if (prefs_get_boolean(PREF_VERCHECK)) { cons_check_version(FALSE); } prefresh(console->win, 0, 0, 1, 0, rows-3, cols-1); ui_console_dirty(); cons_alert(); }
void ui_outgoing_msg(const char * const from, const char * const to, const char * const message) { PContact contact = roster_get_contact(to); ProfWin *window = wins_get_by_recipient(to); int num = 0; // create new window if (window == NULL) { Jid *jid = jid_create(to); if (muc_room_is_active(jid)) { window = wins_new(to, WIN_PRIVATE); } else { window = wins_new(to, WIN_CHAT); } jid_destroy(jid); num = wins_get_num(window); if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { _win_show_history(window->win, num, to); } if (contact != NULL) { if (strcmp(p_contact_presence(contact), "offline") == 0) { const char const *show = p_contact_presence(contact); const char const *status = p_contact_status(contact); _show_status_string(window, to, show, status, NULL, "--", "offline"); } } // use existing window } else { num = wins_get_num(window); } win_print_time(window, '-'); if (strncmp(message, "/me ", 4) == 0) { wattron(window->win, COLOUR_ME); wprintw(window->win, "*%s ", from); wprintw(window->win, "%s", message + 4); wprintw(window->win, "\n"); wattroff(window->win, COLOUR_ME); } else { _win_show_user(window->win, from, 0); _win_show_message(window->win, message); } ui_switch_win(num); }
void ui_room_member_offline(const char * const room, const char * const nick) { ProfWin *window = wins_get_by_recipient(room); win_print_time(window, '!'); wattron(window->win, COLOUR_OFFLINE); wprintw(window->win, "<- %s has left the room.\n", nick); wattroff(window->win, COLOUR_OFFLINE); if (wins_is_current(window)) { wins_refresh_current(); } }
void ui_room_nick_change(const char * const room, const char * const nick) { ProfWin *window = wins_get_by_recipient(room); win_print_time(window, '!'); wattron(window->win, COLOUR_ME); wprintw(window->win, "** You are now known as %s\n", nick); wattroff(window->win, COLOUR_ME); if (wins_is_current(window)) { wins_refresh_current(); } }
void ui_current_print_line(const char * const msg, ...) { ProfWin *current = wins_get_current(); va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_print_time(current, '-'); wprintw(current->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); wins_refresh_current(); }
void ui_print_error_from_recipient(const char * const from, const char *err_msg) { if (from == NULL || err_msg == NULL) return; ProfWin *window = wins_get_by_recipient(from); if (window != NULL) { win_print_time(window, '-'); _win_show_error_msg(window->win, err_msg); if (wins_is_current(window)) { wins_refresh_current(); } } }
void ui_room_member_online(const char * const room, const char * const nick, const char * const show, const char * const status) { ProfWin *window = wins_get_by_recipient(room); win_print_time(window, '!'); wattron(window->win, COLOUR_ONLINE); wprintw(window->win, "-> %s has joined the room.\n", nick); wattroff(window->win, COLOUR_ONLINE); if (wins_is_current(window)) { wins_refresh_current(); } }
void win_vprint_line(ProfWin *window, const char show_char, int attrs, const char * const msg, ...) { va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_print_time(window, show_char); wattron(window->win, attrs); wprintw(window->win, "%s\n", fmt_msg->str); wattroff(window->win, attrs); g_string_free(fmt_msg, TRUE); va_end(arg); }
void cons_show_incoming_message(const char * const short_from, const int win_index) { int ui_index = win_index + 1; if (ui_index == 10) { ui_index = 0; } win_print_time(console, '-'); wattron(console->win, COLOUR_INCOMING); wprintw(console->win, "<< incoming from %s (%d)\n", short_from, ui_index); wattroff(console->win, COLOUR_INCOMING); ui_console_dirty(); cons_alert(); }
void win_show_contact(ProfWin *window, PContact contact) { const char *barejid = p_contact_barejid(contact); const char *name = p_contact_name(contact); const char *presence = p_contact_presence(contact); const char *status = p_contact_status(contact); GDateTime *last_activity = p_contact_last_activity(contact); win_print_time(window, '-'); win_presence_colour_on(window, presence); if (name != NULL) { wprintw(window->win, "%s", name); } else { wprintw(window->win, "%s", barejid); } wprintw(window->win, " is %s", presence); if (last_activity != NULL) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); wprintw(window->win, ", idle "); int hours = span / G_TIME_SPAN_HOUR; span = span - hours * G_TIME_SPAN_HOUR; if (hours > 0) { wprintw(window->win, "%dh", hours); } int minutes = span / G_TIME_SPAN_MINUTE; span = span - minutes * G_TIME_SPAN_MINUTE; wprintw(window->win, "%dm", minutes); int seconds = span / G_TIME_SPAN_SECOND; wprintw(window->win, "%ds", seconds); } if (status != NULL) { wprintw(window->win, ", \"%s\"", p_contact_status(contact)); } wprintw(window->win, "\n"); win_presence_colour_off(window, presence); }
void cons_show_login_success(ProfAccount *account) { win_print_time(console, '-'); wprintw(console->win, "%s logged in successfully, ", account->jid); resource_presence_t presence = accounts_get_login_presence(account->name); const char *presence_str = string_from_resource_presence(presence); win_presence_colour_on(console, presence_str); wprintw(console->win, "%s", presence_str); win_presence_colour_off(console, presence_str); wprintw(console->win, " (priority %d)", accounts_get_priority_for_presence_type(account->name, presence)); wprintw(console->win, ".\n"); ui_console_dirty(); cons_alert(); }
void cons_show_typing(const char * const barejid) { PContact contact = roster_get_contact(barejid); const char * display_usr = NULL; if (p_contact_name(contact) != NULL) { display_usr = p_contact_name(contact); } else { display_usr = barejid; } win_print_time(console, '-'); wattron(console->win, COLOUR_TYPING); wprintw(console->win, "!! %s is typing a message...\n", display_usr); wattroff(console->win, COLOUR_TYPING); ui_console_dirty(); cons_alert(); }
void cons_debug(const char * const msg, ...) { if (strcmp(PACKAGE_STATUS, "development") == 0) { va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_print_time(console, '-'); wprintw(console->win, "%s\n", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); ui_console_dirty(); cons_alert(); ui_current_page_off(); ui_refresh(); } }
void ui_room_broadcast(const char * const room_jid, const char * const message) { ProfWin *window = wins_get_by_recipient(room_jid); int num = wins_get_num(window); win_print_time(window, '!'); wattron(window->win, COLOUR_ROOMINFO); wprintw(window->win, "Room message: "); wattroff(window->win, COLOUR_ROOMINFO); wprintw(window->win, "%s\n", message); // currently in groupchat window if (wins_is_current(window)) { status_bar_active(num); wins_refresh_current(); // not currenlty on groupchat window } else { status_bar_new(num); } }
void cons_show_room_list(GSList *rooms, const char * const conference_node) { if ((rooms != NULL) && (g_slist_length(rooms) > 0)) { cons_show("Chat rooms at %s:", conference_node); while (rooms != NULL) { DiscoItem *room = rooms->data; win_print_time(console, '-'); wprintw(console->win, " %s", room->jid); if (room->name != NULL) { wprintw(console->win, ", (%s)", room->name); } wprintw(console->win, "\n"); rooms = g_slist_next(rooms); } } else { cons_show("No chat rooms at %s", conference_node); } ui_console_dirty(); cons_alert(); }