1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into plugins

Conflicts:
	Makefile.am
	src/ui/console.c
	src/ui/core.c
	src/ui/window.c
This commit is contained in:
James Booth 2014-07-29 16:23:01 +01:00
commit b831eb026e
11 changed files with 524 additions and 621 deletions

View File

@ -17,6 +17,7 @@ core_sources = \
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/ui/buffer.c \
src/command/command.h src/command/command.c src/command/history.c \
src/command/commands.h src/command/commands.c \
src/command/history.h src/tools/parser.c \
@ -65,6 +66,7 @@ tests_sources = \
tests/xmpp/mock_xmpp.h tests/xmpp/mock_xmpp.c \
tests/otr/mock_otr.h tests/otr/mock_otr.c \
tests/ui/mock_ui.h tests/ui/mock_ui.c \
src/ui/buffer.c \
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \
tests/config/mock_accounts.h tests/config/mock_accounts.c \

View File

@ -1,4 +1,4 @@
#!/bin/sh
./configure --enable-python-plugins --enable-ruby-plugins --enable-c-plugins --disable-lua-plugins CFLAGS='-g -O0' CXXFLAGS='-g -O0'
./configure --enable-python-plugins --disable-ruby-plugins --enable-c-plugins --disable-lua-plugins CFLAGS='-g -O0' CXXFLAGS='-g -O0'

View File

@ -167,7 +167,7 @@ void
api_win_show(const char *tag, const char *line)
{
ProfWin *window = wins_get_by_recipient(tag);
win_print_line(window, '-', 0, line);
win_save_print(window, '!', NULL, 0, 0, "", line);
// refresh if current
if (wins_is_current(window)) {
@ -180,7 +180,7 @@ void
api_win_show_green(const char *tag, const char *line)
{
ProfWin *window = wins_get_by_recipient(tag);
win_print_line(window, '-', COLOUR_ONLINE, line);
win_save_print(window, '!', NULL, 0, COLOUR_ONLINE, "", line);
// refresh if current
if (wins_is_current(window)) {
@ -193,7 +193,7 @@ void
api_win_show_red(const char *tag, const char *line)
{
ProfWin *window = wins_get_by_recipient(tag);
win_print_line(window, '-', COLOUR_OFFLINE, line);
win_save_print(window, '!', NULL, 0, COLOUR_OFFLINE, "", line);
// refresh if current
if (wins_is_current(window)) {
@ -206,7 +206,7 @@ void
api_win_show_cyan(const char *tag, const char *line)
{
ProfWin *window = wins_get_by_recipient(tag);
win_print_line(window, '-', COLOUR_AWAY, line);
win_save_print(window, '!', NULL, 0, COLOUR_AWAY, "", line);
// refresh if current
if (wins_is_current(window)) {
@ -219,11 +219,11 @@ void
api_win_show_yellow(const char *tag, const char *line)
{
ProfWin *window = wins_get_by_recipient(tag);
win_print_line(window, '-', COLOUR_INCOMING, line);
win_save_print(window, '!', NULL, 0, COLOUR_INCOMING, "", line);
// refresh if current
if (wins_is_current(window)) {
int num = wins_get_num(window);
ui_switch_win(num);
}
}
}

88
src/ui/buffer.c Normal file
View File

@ -0,0 +1,88 @@
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <glib.h>
#ifdef HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h>
#elif HAVE_NCURSES_H
#include <ncurses.h>
#endif
#include "ui/window.h"
#include "ui/buffer.h"
#define BUFF_SIZE 1200
struct prof_buff_t {
GSList *entries;
};
static void _free_entry(ProfBuffEntry *entry);
ProfBuff
buffer_create()
{
ProfBuff new_buff = malloc(sizeof(struct prof_buff_t));
new_buff->entries = NULL;
return new_buff;
}
int
buffer_size(ProfBuff buffer)
{
return g_slist_length(buffer->entries);
}
void
buffer_free(ProfBuff buffer)
{
g_slist_free_full(buffer->entries, (GDestroyNotify)_free_entry);
free(buffer);
buffer = NULL;
}
void
buffer_push(ProfBuff buffer, const char show_char, const char * const date_fmt,
int flags, int attrs, const char * const from, const char * const message)
{
ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t));
e->show_char = show_char;
e->flags = flags;
e->attrs = attrs;
e->date_fmt = malloc(strlen(date_fmt)+1);
strcpy(e->date_fmt, date_fmt);
e->from = malloc(strlen(from)+1);
strcpy(e->from, from);
e->message = malloc(strlen(message)+1);
strcpy(e->message, message);
if (g_slist_length(buffer->entries) == BUFF_SIZE) {
_free_entry(buffer->entries->data);
buffer->entries = g_slist_delete_link(buffer->entries, buffer->entries);
}
buffer->entries = g_slist_append(buffer->entries, e);
}
ProfBuffEntry*
buffer_yield_entry(ProfBuff buffer, int entry)
{
GSList *node = g_slist_nth(buffer->entries, entry);
return node->data;
}
static void
_free_entry(ProfBuffEntry *entry)
{
free(entry->message);
free(entry->from);
free(entry->date_fmt);
}

22
src/ui/buffer.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef UI_BUFFER_H
#define UI_BUFFER_H
#include "config.h"
typedef struct prof_buff_entry_t {
char show_char;
char *date_fmt;
int flags;
int attrs;
char *from;
char *message;
} ProfBuffEntry;
typedef struct prof_buff_t *ProfBuff;
ProfBuff buffer_create();
void buffer_free(ProfBuff buffer);
void buffer_push(ProfBuff buffer, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message);
int buffer_size(ProfBuff buffer);
ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry);
#endif

View File

@ -54,7 +54,7 @@ static void
_cons_show_time(void)
{
ProfWin *console = wins_get_console();
win_print_time(console, '-');
win_save_print(console, '-', NULL, NO_EOL, 0, "", "");
if (wins_is_current(console)) {
win_update_virtual(console);
@ -65,7 +65,7 @@ static void
_cons_show_word(const char * const word)
{
ProfWin *console = wins_get_console();
wprintw(console->win, "%s", word);
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", word);
if (wins_is_current(console)) {
win_update_virtual(console);
@ -81,8 +81,7 @@ _cons_debug(const char * const msg, ...)
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);
win_save_println(console, fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@ -104,8 +103,7 @@ _cons_show(const char * const msg, ...)
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);
win_save_println(console, fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@ -122,10 +120,7 @@ _cons_show_error(const char * const msg, ...)
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_time(console, '-');
wattron(console->win, COLOUR_ERROR);
wprintw(console->win, "%s\n", fmt_msg->str);
wattroff(console->win, COLOUR_ERROR);
win_save_print(console, '-', NULL, 0, COLOUR_ERROR, "", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@ -148,7 +143,7 @@ _cons_show_typing(const char * const barejid)
display_usr = barejid;
}
win_vprint_line(console, '-', COLOUR_TYPING, "!! %s is typing a message...", display_usr);
win_save_vprint(console, '-', NULL, 0, COLOUR_TYPING, "", "!! %s is typing a message...", display_usr);
if (wins_is_current(console)) {
win_update_virtual(console);
@ -166,10 +161,7 @@ _cons_show_incoming_message(const char * const short_from, const int win_index)
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);
win_save_vprint(console, '-', NULL, 0, COLOUR_INCOMING, "", "<< incoming from %s (%d)", short_from, ui_index);
if (wins_is_current(console)) {
win_update_virtual(console);
@ -188,37 +180,26 @@ _cons_about(void)
if (prefs_get_boolean(PREF_SPLASH)) {
_cons_splash_logo();
} else {
win_print_time(console, '-');
if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) {
#ifdef PROF_HAVE_GIT_VERSION
wprintw(console->win, "Welcome to Profanity, version %sdev.%s.%s\n", PROF_PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev.%s.%s", PROF_PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
wprintw(console->win, "Welcome to Profanity, version %sdev\n", PROF_PACKAGE_VERSION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev", PROF_PACKAGE_VERSION);
#endif
} else {
wprintw(console->win, "Welcome to Profanity, version %s\n", PROF_PACKAGE_VERSION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %s", PROF_PACKAGE_VERSION);
}
}
win_print_time(console, '-');
wprintw(console->win, "Copyright (C) 2012 - 2014 James Booth <%s>.\n", PROF_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");
win_save_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2014 James Booth <%s>.", PROF_PACKAGE_BUGREPORT);
win_save_println(console, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>");
win_save_println(console, "");
win_save_println(console, "This is free software; you are free to change and redistribute it.");
win_save_println(console, "There is NO WARRANTY, to the extent permitted by law.");
win_save_println(console, "");
win_save_println(console, "Type '/help' to show complete help.");
win_save_println(console, "");
if (prefs_get_boolean(PREF_VERCHECK)) {
cons_check_version(FALSE);
@ -244,17 +225,14 @@ _cons_check_version(gboolean not_available_msg)
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");
win_save_vprint(console, '-', NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release);
win_save_println(console, "Check <http://www.profanity.im> for details.");
free(latest_release);
win_print_time(console, '-');
wprintw(console->win, "\n");
win_save_println(console, "");
} else {
if (not_available_msg) {
cons_show("No new version available.");
cons_show("");
win_save_println(console, "No new version available.");
win_save_println(console, "");
}
}
@ -271,18 +249,16 @@ static void
_cons_show_login_success(ProfAccount *account)
{
ProfWin *console = wins_get_console();
win_print_time(console, '-');
wprintw(console->win, "%s logged in successfully, ", account->jid);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "%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)",
int presence_colour = win_presence_colour(presence_str);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
wprintw(console->win, ".\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", ".");
if (wins_is_current(console)) {
win_update_virtual(console);
}
@ -299,9 +275,7 @@ _cons_show_wins(void)
GSList *curr = window_strings;
while (curr != NULL) {
win_print_time(console, '-');
wprintw(console->win, curr->data);
wprintw(console->win, "\n");
win_save_println(console, curr->data);
curr = g_slist_next(curr);
}
@ -349,67 +323,61 @@ static void
_cons_show_caps(const char * const contact, Resource *resource)
{
ProfWin *console = wins_get_console();
WINDOW *win = console->win;
cons_show("");
const char *resource_presence = string_from_resource_presence(resource->presence);
win_print_time(console, '-');
win_presence_colour_on(console, resource_presence);
wprintw(console->win, "%s", contact);
win_presence_colour_off(console, resource_presence);
wprintw(win, ":\n");
int presence_colour = win_presence_colour(resource_presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", contact);
win_save_print(console, '-', NULL, NO_DATE, 0, "", ":");
if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str);
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_print_time(console, '-');
wprintw(win, "Identity: ");
win_save_print(console, '-', NULL, NO_EOL, 0, "", "Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
wprintw(win, " ");
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->type != NULL) {
wprintw(win, "%s", caps->type);
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) {
wprintw(win, " ");
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->category != NULL) {
wprintw(win, "%s", caps->category);
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
}
wprintw(win, "\n");
win_save_newline(console);
}
if (caps->software != NULL) {
win_print_time(console, '-');
wprintw(win, "Software: %s", caps->software);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software);
}
if (caps->software_version != NULL) {
wprintw(win, ", %s", caps->software_version);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
wprintw(win, "\n");
win_save_newline(console);
}
if (caps->os != NULL) {
win_print_time(console, '-');
wprintw(win, "OS: %s", caps->os);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os);
}
if (caps->os_version != NULL) {
wprintw(win, ", %s", caps->os_version);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
wprintw(win, "\n");
win_save_newline(console);
}
if (caps->features != NULL) {
win_print_time(console, '-');
wprintw(win, "Features:\n");
win_save_println(console, "Features:");
GSList *feature = caps->features;
while (feature != NULL) {
win_print_time(console, '-');
wprintw(win, " %s\n", feature->data);
win_save_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data);
feature = g_slist_next(feature);
}
}
@ -429,11 +397,9 @@ _cons_show_software_version(const char * const jid, const char * const presence
ProfWin *console = wins_get_console();
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");
int presence_colour = win_presence_colour(presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid);
win_save_print(console, '-', NULL, NO_DATE, 0, "", ":");
}
if (name != NULL) {
cons_show("Name : %s", name);
@ -499,12 +465,11 @@ _cons_show_room_list(GSList *rooms, const char * const conference_node)
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);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid);
if (room->name != NULL) {
wprintw(console->win, ", (%s)", room->name);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name);
}
wprintw(console->win, "\n");
win_save_newline(console);
rooms = g_slist_next(rooms);
}
} else {
@ -532,32 +497,29 @@ _cons_show_bookmarks(const GList *list)
while (list != NULL) {
Bookmark *item = list->data;
win_print_time(console, '-');
int presence_colour = 0;
if (muc_room_is_active(item->jid)) {
wattron(console->win, COLOUR_ONLINE);
presence_colour = COLOUR_ONLINE;
}
wprintw(console->win, " %s", item->jid);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid);
if (item->nick != NULL) {
wprintw(console->win, "/%s", item->nick);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick);
}
if (item->autojoin) {
wprintw(console->win, " (autojoin)");
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)");
}
if (item->password != NULL) {
wprintw(console->win, " (private)");
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)");
}
if (muc_room_is_active(item->jid)) {
ProfWin *roomwin = wins_get_by_recipient(item->jid);
if (roomwin != NULL) {
int num = wins_get_num(roomwin);
wprintw(console->win, " (");
wprintw(console->win, "%d", num);
wprintw(console->win, ")");
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num);
}
wattroff(console->win, COLOUR_ONLINE);
}
wprintw(console->win, "\n");
win_save_newline(console);
list = g_list_next(list);
}
@ -623,12 +585,11 @@ _cons_show_disco_items(GSList *items, const char * const jid)
cons_show("Service discovery items for %s:", jid);
while (items != NULL) {
DiscoItem *item = items->data;
win_print_time(console, '-');
wprintw(console->win, " %s", item->jid);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid);
if (item->name != NULL) {
wprintw(console->win, ", (%s)", item->name);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name);
}
wprintw(console->win, "\n");
win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "");
items = g_slist_next(items);
}
} else {
@ -712,10 +673,8 @@ _cons_show_account_list(gchar **accounts)
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));
int presence_colour = win_presence_colour(string_from_resource_presence(presence));
win_save_vprint(console, '-', NULL, 0, presence_colour, "", "%s", accounts[i]);
} else {
cons_show(accounts[i]);
}
@ -821,10 +780,8 @@ _cons_show_account(ProfAccount *account)
GList *resources = jabber_get_available_resources();
GList *ordered_resources = NULL;
WINDOW *win = console->win;
if (resources != NULL) {
win_print_time(console, '-');
wprintw(win, "Resources:\n");
win_save_println(console, "Resources:");
// sort in order of availabiltiy
while (resources != NULL) {
@ -838,58 +795,54 @@ _cons_show_account(ProfAccount *account)
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
win_print_time(console, '-');
win_presence_colour_on(console, resource_presence);
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
int presence_colour = win_presence_colour(resource_presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
wprintw(win, ", \"%s\"", resource->status);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
}
wprintw(win, "\n");
win_presence_colour_off(console, resource_presence);
win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "");
if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str);
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_print_time(console, '-');
wprintw(win, " Identity: ");
win_save_print(console, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
wprintw(win, " ");
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->type != NULL) {
wprintw(win, "%s", caps->type);
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) {
wprintw(win, " ");
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->category != NULL) {
wprintw(win, "%s", caps->category);
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
}
wprintw(win, "\n");
win_save_newline(console);
}
if (caps->software != NULL) {
win_print_time(console, '-');
wprintw(win, " Software: %s", caps->software);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
wprintw(win, ", %s", caps->software_version);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
wprintw(win, "\n");
win_save_newline(console);
}
if (caps->os != NULL) {
win_print_time(console, '-');
wprintw(win, " OS: %s", caps->os);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
wprintw(win, ", %s", caps->os_version);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
wprintw(win, "\n");
win_save_newline(console);
}
}
}
@ -1568,55 +1521,25 @@ static void
_cons_splash_logo(void)
{
ProfWin *console = wins_get_console();
win_print_time(console, '-');
wprintw(console->win, "Welcome to\n");
win_save_println(console, "Welcome to");
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " ___ _ \n");
wattroff(console->win, COLOUR_SPLASH);
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", " ___ _ ");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", " / __) (_)_ ");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", " ____ ____ ___ | |__ ____ ____ _| |_ _ _ ");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "| | | | | | |_| | | ( ( | | | | | | |_| |_| |");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "|_| (____/ ");
win_save_print(console, '-', NULL, 0, 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(PROF_PACKAGE_STATUS, "development") == 0) {
#ifdef PROF_HAVE_GIT_VERSION
wprintw(console->win, "Version %sdev.%s.%s\n", PROF_PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %sdev.%s.%s", PROF_PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
wprintw(console->win, "Version %sdev\n", PROF_PACKAGE_VERSION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %sdev", PROF_PACKAGE_VERSION);
#endif
} else {
wprintw(console->win, "Version %s\n", PROF_PACKAGE_VERSION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %s", PROF_PACKAGE_VERSION);
}
}
@ -1637,21 +1560,17 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
}
const char *presence = p_contact_presence(contact);
win_print_time(console, '-');
int presence_colour;
if (p_contact_subscribed(contact)) {
win_presence_colour_on(console, presence);
wprintw(console->win, "%s\n", title->str);
win_presence_colour_off(console, presence);
presence_colour = win_presence_colour(presence);
} else {
win_presence_colour_on(console, "offline");
wprintw(console->win, "%s\n", title->str);
win_presence_colour_off(console, "offline");
presence_colour = win_presence_colour("offline");
}
win_save_vprint(console, '-', NULL, 0, presence_colour, "", title->str);
g_string_free(title, TRUE);
win_print_time(console, '-');
wprintw(console->win, " Subscription : ");
win_save_print(console, '-', NULL, NO_EOL, 0, "", " Subscription : ");
GString *sub = g_string_new("");
sub = g_string_append(sub, p_contact_subscription(contact));
if (p_contact_pending_out(contact)) {
@ -1661,16 +1580,11 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
sub = g_string_append(sub, ", request received");
}
if (p_contact_subscribed(contact)) {
wattron(console->win, COLOUR_SUBSCRIBED);
presence_colour = COLOUR_SUBSCRIBED;
} else {
wattron(console->win, COLOUR_UNSUBSCRIBED);
}
wprintw(console->win, "%s\n", sub->str);
if (p_contact_subscribed(contact)) {
wattroff(console->win, COLOUR_SUBSCRIBED);
} else {
wattroff(console->win, COLOUR_UNSUBSCRIBED);
presence_colour = COLOUR_UNSUBSCRIBED;
}
win_save_vprint(console, '-', NULL, NO_DATE, presence_colour, "", "%s", sub->str);
g_string_free(sub, TRUE);

View File

@ -68,8 +68,6 @@ static Display *display;
static GTimer *ui_idle_time;
static void _win_show_user(WINDOW *win, const char * const user, const int colour);
static void _win_show_message(WINDOW *win, const char * const message);
static void _win_handle_switch(const wint_t * const ch);
static void _win_handle_page(const wint_t * const ch);
static void _win_show_history(WINDOW *win, int win_index,
@ -193,9 +191,11 @@ static void
_ui_resize(const int ch, const char * const input, const int size)
{
log_info("Resizing UI");
erase();
refresh();
title_bar_resize();
status_bar_resize();
wins_resize_all();
status_bar_resize();
inp_win_resize(input, size);
ProfWin *window = wins_get_current();
win_update_virtual(window);
@ -237,13 +237,13 @@ _ui_handle_stanza(const char * const msg)
ProfWin *xmlconsole = wins_get_xmlconsole();
if (g_str_has_prefix(msg, "SENT:")) {
win_print_line_no_time(xmlconsole, 0, "SENT:");
win_print_line_no_time(xmlconsole, COLOUR_ONLINE, &msg[6]);
win_print_line_no_time(xmlconsole, COLOUR_ONLINE, "");
win_save_print(xmlconsole, '-', NULL, NO_DATE, 0, "", "SENT:");
win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_ONLINE, "", &msg[6]);
win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_ONLINE, "", "");
} else if (g_str_has_prefix(msg, "RECV:")) {
win_print_line_no_time(xmlconsole, 0, "RECV:");
win_print_line_no_time(xmlconsole, COLOUR_AWAY, &msg[6]);
win_print_line_no_time(xmlconsole, COLOUR_ONLINE, "");
win_save_print(xmlconsole, '-', NULL, NO_DATE, 0, "", "RECV:");
win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_AWAY, "", &msg[6]);
win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_AWAY, "", "");
}
if (wins_is_current(xmlconsole)) {
@ -519,13 +519,13 @@ _ui_handle_recipient_not_found(const char * const recipient, const char * const
} else if (win->type == WIN_MUC) {
g_string_printf(msg, "Room %s not found: %s", recipient, err_msg);
cons_show_error(msg->str);
win_print_line(win, '!', COLOUR_ERROR, msg->str);
win_save_print(win, '!', NULL, 0, COLOUR_ERROR, "", msg->str);
// unknown chat recipient
} else {
g_string_printf(msg, "Recipient %s not found: %s", recipient, err_msg);
cons_show_error(msg->str);
win_print_line(win, '!', COLOUR_ERROR, msg->str);
win_save_print(win, '!', NULL, 0, COLOUR_ERROR, "", msg->str);
}
ProfWin *current = wins_get_current();
@ -546,7 +546,7 @@ _ui_handle_recipient_error(const char * const recipient, const char * const err_
// show in window if exists for recipient
if (win != NULL) {
win_print_line(win, '!', COLOUR_ERROR, msg->str);
win_save_print(win, '!', NULL, 0, COLOUR_ERROR, "", msg->str);
}
ProfWin *current = wins_get_current();
@ -777,9 +777,9 @@ _ui_gone_secure(const char * const recipient, gboolean trusted)
window->is_otr = TRUE;
window->is_trusted = trusted;
if (trusted) {
win_vprint_line(window, '!', COLOUR_OTR_STARTED_TRUSTED, "OTR session started (trusted).");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_STARTED_TRUSTED, "", "OTR session started (trusted).");
} else {
win_vprint_line(window, '!', COLOUR_OTR_STARTED_UNTRUSTED, "OTR session started (untrusted).");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted).");
}
if (wins_is_current(window)) {
@ -812,7 +812,7 @@ _ui_smp_recipient_initiated(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "%s wants to authenticate your identity, use '/otr secret <secret>'.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret <secret>'.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -827,9 +827,9 @@ _ui_smp_recipient_initiated_q(const char * const recipient, const char *question
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "%s wants to authenticate your identity with the following question:", recipient);
win_vprint_line(window, '!', 0, " %s", question);
win_vprint_line(window, '!', 0, "use '/otr answer <answer>'.");
win_save_vprint(window, '!', NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", " %s", question);
win_save_print(window, '!', NULL, 0, 0, "", "use '/otr answer <answer>'.");
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -844,7 +844,7 @@ _ui_smp_unsuccessful_sender(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Authentication failed, the secret you entered does not match the secret entered by %s.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -859,7 +859,7 @@ _ui_smp_unsuccessful_receiver(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Authentication failed, the secret entered by %s does not match yours.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -874,7 +874,7 @@ _ui_smp_aborted(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "SMP session aborted.");
win_save_print(window, '!', NULL, 0, 0, "", "SMP session aborted.");
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -889,7 +889,7 @@ _ui_smp_successful(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Authentication successful.");
win_save_print(window, '!', NULL, 0, 0, "", "Authentication successful.");
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -904,7 +904,7 @@ _ui_smp_answer_success(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "%s successfully authenticated you.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "%s successfully authenticated you.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -919,7 +919,7 @@ _ui_smp_answer_failure(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "%s failed to authenticated you.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "%s failed to authenticate you.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -934,7 +934,7 @@ _ui_gone_insecure(const char * const recipient)
if (window != NULL) {
window->is_otr = FALSE;
window->is_trusted = FALSE;
win_vprint_line(window, '!', COLOUR_OTR_ENDED, "OTR session ended.");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_ENDED, "", "OTR session ended.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
@ -953,7 +953,7 @@ _ui_trust(const char * const recipient)
if (window != NULL) {
window->is_otr = TRUE;
window->is_trusted = TRUE;
win_vprint_line(window, '!', COLOUR_OTR_TRUSTED, "OTR session trusted.");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_TRUSTED, "", "OTR session trusted.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
@ -972,7 +972,7 @@ _ui_untrust(const char * const recipient)
if (window != NULL) {
window->is_otr = TRUE;
window->is_trusted = FALSE;
win_vprint_line(window, '!', COLOUR_OTR_UNTRUSTED, "OTR session untrusted.");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_UNTRUSTED, "", "OTR session untrusted.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
@ -1129,7 +1129,7 @@ _ui_otr_authenticating(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Authenticating %s...", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "Authenticating %s...", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -1144,7 +1144,7 @@ _ui_otr_authetication_waiting(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Awaiting authentication from %s...", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "Awaiting authentication from %s...", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -1182,15 +1182,15 @@ _ui_current_recipient(void)
static void
_ui_current_print_line(const char * const msg, ...)
{
ProfWin *current = wins_get_current();
ProfWin *window = 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_line(current, '-', 0, fmt_msg->str);
win_save_println(window, fmt_msg->str);
va_end(arg);
g_string_free(fmt_msg, TRUE);
win_update_virtual(current);
win_update_virtual(window);
}
static void
@ -1201,7 +1201,7 @@ _ui_current_print_formatted_line(const char show_char, int attrs, const char * c
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_line(current, show_char, attrs, fmt_msg->str);
win_save_print(current, show_char, NULL, 0, attrs, "", fmt_msg->str);
va_end(arg);
g_string_free(fmt_msg, TRUE);
win_update_virtual(current);
@ -1211,7 +1211,7 @@ static void
_ui_current_error_line(const char * const msg)
{
ProfWin *current = wins_get_current();
win_print_line(current, '-', COLOUR_ERROR, msg);
win_save_print(current, '-', NULL, 0, COLOUR_ERROR, "", msg);
win_update_virtual(current);
}
@ -1245,8 +1245,7 @@ _ui_print_system_msg_from_recipient(const char * const from, const char *message
}
}
win_print_time(window, '-');
wprintw(window->win, "*%s %s\n", jid->barejid, message);
win_save_vprint(window, '-', NULL, 0, 0, "", "*%s %s", jid->barejid, message);
// this is the current window
if (wins_is_current(window)) {
@ -1272,7 +1271,7 @@ _ui_recipient_gone(const char * const barejid)
ProfWin *window = wins_get_by_recipient(barejid);
if (window != NULL) {
win_vprint_line(window, '!', COLOUR_GONE, "<- %s has left the conversation.", display_usr);
win_save_vprint(window, '!', NULL, 0, COLOUR_GONE, "", "<- %s has left the conversation.", display_usr);
if (wins_is_current(window)) {
win_update_virtual(window);
}
@ -1324,7 +1323,7 @@ _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_line(window, '-', 0, "Type ':help' to find out more.");
win_save_println(window, "Type ':help' to find out more.");
}
static void
@ -1360,14 +1359,9 @@ _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");
win_save_println(window, "");
win_save_print(window, '-', NULL, NO_EOL, COLOUR_ME, "", "Query : ");
win_save_print(window, '-', NULL, NO_DATE, 0, "", query);
}
}
@ -1377,22 +1371,19 @@ _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);
win_save_print(window, '-', NULL, NO_EOL, COLOUR_THEM, "", "Result : ");
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, '-');
win_save_newline(window);
win_save_print(window, '-', NULL, NO_EOL, 0, "", "");
} else {
gchar *string = g_ucs4_to_utf8(&unichar, 1, NULL, NULL, NULL);
if (string != NULL) {
wprintw(window->win, string);
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", string);
g_free(string);
}
}
@ -1400,7 +1391,7 @@ _ui_duck_result(const char * const result)
offset++;
}
wprintw(window->win, "\n");
win_save_newline(window);
}
}
@ -1449,17 +1440,7 @@ _ui_outgoing_msg(const char * const from, const char * const to,
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, new_message);
}
win_save_print(window, '-', NULL, 0, 0, from, new_message);
ui_switch_win(num);
}
@ -1482,7 +1463,7 @@ _ui_room_join(const char * const room, gboolean focus)
status_bar_active(num);
ProfWin *console = wins_get_console();
char *nick = muc_get_room_nick(room);
win_vprint_line(console, '!', COLOUR_TYPING, "-> Autojoined %s as %s (%d).", room, nick, num);
win_save_vprint(console, '!', NULL, 0, COLOUR_TYPING, "", "-> Autojoined %s as %s (%d).", room, nick, num);
win_update_virtual(console);
}
}
@ -1492,29 +1473,21 @@ _ui_room_roster(const char * const room, GList *roster, const char * const prese
{
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");
win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room is empty.");
} else {
wprintw(window->win, "No participants %s.\n", presence);
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "No participants %s.", 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, ", ");
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "%d participants: ", length);
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", "%s", muc_get_room_nick(room));
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", ");
} else {
wprintw(window->win, "%d %s: ", length, presence);
wattroff(window->win, COLOUR_ROOMINFO);
wattron(window->win, COLOUR_ONLINE);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "%d %s: ", length, presence);
}
while (roster != NULL) {
@ -1522,19 +1495,17 @@ _ui_room_roster(const char * const room, GList *roster, const char * const prese
const char *nick = p_contact_barejid(member);
const char *show = p_contact_presence(member);
win_presence_colour_on(window, show);
wprintw(window->win, "%s", nick);
win_presence_colour_off(window, show);
int presence_colour = win_presence_colour(show);
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", nick);
if (roster->next != NULL) {
wprintw(window->win, ", ");
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", ");
}
roster = g_list_next(roster);
}
win_save_print(window, '!', NULL, NO_DATE, COLOUR_ONLINE, "", "");
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_ONLINE);
}
if (wins_is_current(window)) {
@ -1553,10 +1524,7 @@ _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);
win_save_vprint(window, '!', NULL, 0, COLOUR_OFFLINE, "", "<- %s has left the room.", nick);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1569,10 +1537,7 @@ _ui_room_member_online(const char * const room, const char * const nick,
{
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);
win_save_vprint(window, '!', NULL, 0, COLOUR_ONLINE, "", "-> %s has joined the room.", nick);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1600,10 +1565,7 @@ _ui_room_member_nick_change(const char * const room,
{
ProfWin *window = wins_get_by_recipient(room);
win_print_time(window, '!');
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "** %s is now known as %s\n", old_nick, nick);
wattroff(window->win, COLOUR_THEM);
win_save_vprint(window, '!', NULL, 0, COLOUR_THEM, "", "** %s is now known as %s", old_nick, nick);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1615,10 +1577,7 @@ _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);
win_save_vprint(window, '!', NULL, 0, COLOUR_ME, "", "** You are now known as %s", nick);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1631,21 +1590,28 @@ _ui_room_history(const char * const room_jid, const char * const nick,
{
ProfWin *window = wins_get_by_recipient(room_jid);
GString *line = g_string_new("");
GDateTime *time = g_date_time_new_from_timeval_utc(&tv_stamp);
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wprintw(window->win, "%s - ", date_fmt);
g_string_append(line, date_fmt);
g_string_append(line, " - ");
g_date_time_unref(time);
g_free(date_fmt);
if (strncmp(message, "/me ", 4) == 0) {
wprintw(window->win, "*%s ", nick);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
g_string_append(line, "*");
g_string_append(line, nick);
g_string_append(line, message + 4);
} else {
wprintw(window->win, "%s: ", nick);
_win_show_message(window->win, message);
g_string_append(line, nick);
g_string_append(line, ": ");
g_string_append(line, message);
}
win_save_print(window, '-', NULL, NO_DATE, 0, "", line->str);
g_string_free(line, TRUE);
if (wins_is_current(window)) {
win_update_virtual(window);
}
@ -1659,36 +1625,14 @@ _ui_room_message(const char * const room_jid, const char * const nick,
int num = wins_get_num(window);
char *my_nick = muc_get_room_nick(room_jid);
win_print_time(window, '-');
if (strcmp(nick, my_nick) != 0) {
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "*%s ", nick);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_THEM);
if (g_strrstr(message, my_nick) != NULL) {
win_save_print(window, '-', NULL, NO_ME, COLOUR_ROOMMENTION, nick, message);
} else {
_win_show_user(window->win, nick, 1);
if (g_strrstr(message, my_nick) != NULL) {
wattron(window->win, COLOUR_ROOMMENTION);
_win_show_message(window->win, message);
wattroff(window->win, COLOUR_ROOMMENTION);
} else {
_win_show_message(window->win, message);
}
win_save_print(window, '-', NULL, NO_ME, 0, nick, message);
}
} else {
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_ME);
wprintw(window->win, "*%s ", nick);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_ME);
} else {
_win_show_user(window->win, nick, 0);
_win_show_message(window->win, message);
}
win_save_print(window, '-', NULL, 0, 0, nick, message);
}
// currently in groupchat window
@ -1767,11 +1711,8 @@ _ui_room_subject(const char * const room_jid, const char * const subject)
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 subject: ");
wattroff(window->win, COLOUR_ROOMINFO);
wprintw(window->win, "%s\n", subject);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room subject: ");
win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject);
// currently in groupchat window
if (wins_is_current(window)) {
@ -1790,11 +1731,8 @@ _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);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room message: ");
win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", message);
// currently in groupchat window
if (wins_is_current(window)) {
@ -1812,12 +1750,12 @@ _ui_status(void)
{
char *recipient = ui_current_recipient();
PContact pcontact = roster_get_contact(recipient);
ProfWin *current = wins_get_current();
ProfWin *window = wins_get_current();
if (pcontact != NULL) {
win_show_contact(current, pcontact);
win_show_contact(window, pcontact);
} else {
win_print_line(current, '-', 0, "Error getting contact info.");
win_save_println(window, "Error getting contact info.");
}
}
@ -1826,12 +1764,12 @@ _ui_info(void)
{
char *recipient = ui_current_recipient();
PContact pcontact = roster_get_contact(recipient);
ProfWin *current = wins_get_current();
ProfWin *window = wins_get_current();
if (pcontact != NULL) {
win_show_info(current, pcontact);
win_show_info(window, pcontact);
} else {
win_print_line(current, '-', 0, "Error getting contact info.");
win_save_println(window, "Error getting contact info.");
}
}
@ -1840,12 +1778,12 @@ _ui_status_private(void)
{
Jid *jid = jid_create(ui_current_recipient());
PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
ProfWin *current = wins_get_current();
ProfWin *window = wins_get_current();
if (pcontact != NULL) {
win_show_contact(current, pcontact);
win_show_contact(window, pcontact);
} else {
win_print_line(current, '-', 0, "Error getting contact info.");
win_save_println(window, "Error getting contact info.");
}
jid_destroy(jid);
@ -1856,12 +1794,12 @@ _ui_info_private(void)
{
Jid *jid = jid_create(ui_current_recipient());
PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
ProfWin *current = wins_get_current();
ProfWin *window = wins_get_current();
if (pcontact != NULL) {
win_show_info(current, pcontact);
win_show_info(window, pcontact);
} else {
win_print_line(current, '-', 0, "Error getting contact info.");
win_save_println(window, "Error getting contact info.");
}
jid_destroy(jid);
@ -1876,7 +1814,7 @@ _ui_status_room(const char * const contact)
if (pcontact != NULL) {
win_show_contact(current, pcontact);
} else {
win_vprint_line(current, '-', 0, "No such participant \"%s\" in room.", contact);
win_save_vprint(current, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", contact);
}
}
@ -1889,7 +1827,7 @@ _ui_info_room(const char * const contact)
if (pcontact != NULL) {
win_show_info(current, pcontact);
} else {
win_vprint_line(current, '-', 0, "No such participant \"%s\" in room.", contact);
win_save_vprint(current, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", contact);
}
}
@ -2010,27 +1948,6 @@ _ui_draw_term_title(void)
}
}
static void
_win_show_user(WINDOW *win, const char * const user, const int colour)
{
if (colour)
wattron(win, COLOUR_THEM);
else
wattron(win, COLOUR_ME);
wprintw(win, "%s: ", user);
if (colour)
wattroff(win, COLOUR_THEM);
else
wattroff(win, COLOUR_ME);
}
static void
_win_show_message(WINDOW *win, const char * const message)
{
waddstr(win, message);
wprintw(win, "\n");
}
static void
_win_handle_switch(const wint_t * const ch)
{
@ -2147,7 +2064,7 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact)
jid_destroy(jid);
GSList *curr = history;
while (curr != NULL) {
wprintw(win, "%s\n", curr->data);
win_save_print(window, '-', NULL, NO_DATE, 0, "", curr->data);
curr = g_slist_next(curr);
}
window->history_shown = 1;

View File

@ -107,10 +107,11 @@ status_bar_resize(void)
int rows, cols;
getmaxyx(stdscr, rows, cols);
werase(status_bar);
mvwin(status_bar, rows-2, 0);
wresize(status_bar, 1, cols);
wbkgd(status_bar, COLOUR_STATUS_TEXT);
werase(status_bar);
wattron(status_bar, COLOUR_STATUS_BRACKET);
mvwprintw(status_bar, 0, cols - 34, _active);
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);

View File

@ -37,8 +37,9 @@
#include "ui/window.h"
#include "xmpp/xmpp.h"
static void _win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message);
static void _win_print(ProfWin *window, const char show_char, const char * const date_fmt,
int flags, int attrs, const char * const from, const char * const message);
ProfWin*
win_create(const char * const title, int cols, win_type_t type)
@ -47,6 +48,7 @@ win_create(const char * const title, int cols, win_type_t type)
new_win->from = strdup(title);
new_win->win = newpad(PAD_SIZE, cols);
wbkgd(new_win->win, COLOUR_TEXT);
new_win->buffer = buffer_create();
new_win->y_pos = 0;
new_win->paged = 0;
new_win->unread = 0;
@ -62,60 +64,12 @@ win_create(const char * const title, int cols, win_type_t type)
void
win_free(ProfWin* window)
{
buffer_free(window->buffer);
delwin(window->win);
free(window->from);
free(window);
}
void
win_print_time(ProfWin* window, char show_char)
{
GDateTime *time = g_date_time_new_now_local();
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s %c ", date_fmt, show_char);
wattroff(window->win, COLOUR_TIME);
g_date_time_unref(time);
g_free(date_fmt);
}
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);
waddstr(window->win, msg);
wprintw(window->win, "\n");
wattroff(window->win, attrs);
}
void
win_print_line_no_time(ProfWin *window, int attrs, const char * const msg)
{
wattron(window->win, attrs);
waddstr(window->win, msg);
wprintw(window->win, "\n");
wattroff(window->win, attrs);
}
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);
waddstr(window->win, fmt_msg->str);
wprintw(window->win, "\n");
wattroff(window->win, attrs);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
void
win_update_virtual(ProfWin *window)
{
@ -139,39 +93,21 @@ win_move_to_end(ProfWin *window)
}
}
void
win_presence_colour_on(ProfWin *window, const char * const presence)
int
win_presence_colour(const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
wattron(window->win, COLOUR_ONLINE);
return COLOUR_ONLINE;
} else if (g_strcmp0(presence, "away") == 0) {
wattron(window->win, COLOUR_AWAY);
return COLOUR_AWAY;
} else if (g_strcmp0(presence, "chat") == 0) {
wattron(window->win, COLOUR_CHAT);
return COLOUR_CHAT;
} else if (g_strcmp0(presence, "dnd") == 0) {
wattron(window->win, COLOUR_DND);
return COLOUR_DND;
} else if (g_strcmp0(presence, "xa") == 0) {
wattron(window->win, COLOUR_XA);
return COLOUR_XA;
} else {
wattron(window->win, COLOUR_OFFLINE);
}
}
void
win_presence_colour_off(ProfWin *window, const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
wattroff(window->win, COLOUR_ONLINE);
} else if (g_strcmp0(presence, "away") == 0) {
wattroff(window->win, COLOUR_AWAY);
} else if (g_strcmp0(presence, "chat") == 0) {
wattroff(window->win, COLOUR_CHAT);
} else if (g_strcmp0(presence, "dnd") == 0) {
wattroff(window->win, COLOUR_DND);
} else if (g_strcmp0(presence, "xa") == 0) {
wattroff(window->win, COLOUR_XA);
} else {
wattroff(window->win, COLOUR_OFFLINE);
return COLOUR_OFFLINE;
}
}
@ -184,43 +120,39 @@ win_show_contact(ProfWin *window, PContact 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);
int presence_colour = win_presence_colour(presence);
if (name != NULL) {
wprintw(window->win, "%s", name);
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", name);
} else {
wprintw(window->win, "%s", barejid);
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
}
wprintw(window->win, " is %s", presence);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " 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 (hours > 0) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds);
}
else {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds);
}
}
if (status != NULL) {
wprintw(window->win, ", \"%s\"", p_contact_status(contact));
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact));
}
wprintw(window->win, "\n");
win_presence_colour_off(window, presence);
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
}
void
@ -233,52 +165,42 @@ win_show_info(ProfWin *window, PContact contact)
GList *resources = p_contact_get_available_resources(contact);
GList *ordered_resources = NULL;
GDateTime *last_activity = p_contact_last_activity(contact);
WINDOW *win = window->win;
win_print_time(window, '-');
wprintw(win, "\n");
win_print_time(window, '-');
win_presence_colour_on(window, presence);
wprintw(win, "%s", barejid);
int presence_colour = win_presence_colour(presence);
win_save_print(window, '-', NULL, 0, 0, "", "");
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
if (name != NULL) {
wprintw(win, " (%s)", name);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name);
}
win_presence_colour_off(window, presence);
wprintw(win, ":\n");
win_save_print(window, '-', NULL, NO_DATE, 0, "", ":");
if (sub != NULL) {
win_print_time(window, '-');
wprintw(win, "Subscription: %s\n", sub);
win_save_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub);
}
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
win_print_time(window, '-');
wprintw(win, "Last activity: ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(win, "%ds", seconds);
wprintw(win, "\n");
if (hours > 0) {
win_save_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dh%dm%ds", hours, minutes, seconds);
}
else {
win_save_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dm%ds", minutes, seconds);
}
g_date_time_unref(now);
}
if (resources != NULL) {
win_print_time(window, '-');
wprintw(win, "Resources:\n");
win_save_print(window, '-', NULL, 0, 0, "", "Resources:");
// sort in order of availabiltiy
while (resources != NULL) {
@ -292,58 +214,53 @@ win_show_info(ProfWin *window, PContact contact)
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
win_print_time(window, '-');
win_presence_colour_on(window, resource_presence);
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
int presence_colour = win_presence_colour(resource_presence);
win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
wprintw(win, ", \"%s\"", resource->status);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
}
wprintw(win, "\n");
win_presence_colour_off(window, resource_presence);
win_save_newline(window);
if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str);
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_print_time(window, '-');
wprintw(win, " Identity: ");
win_save_print(window, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
wprintw(win, " ");
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->type != NULL) {
wprintw(win, "%s", caps->type);
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) {
wprintw(win, " ");
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->category != NULL) {
wprintw(win, "%s", caps->category);
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
}
wprintw(win, "\n");
win_save_newline(window);
}
if (caps->software != NULL) {
win_print_time(window, '-');
wprintw(win, " Software: %s", caps->software);
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
wprintw(win, ", %s", caps->software_version);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
wprintw(win, "\n");
win_save_newline(window);
}
if (caps->os != NULL) {
win_print_time(window, '-');
wprintw(win, " OS: %s", caps->os);
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
wprintw(win, ", %s", caps->os_version);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
wprintw(win, "\n");
win_save_newline(window);
}
}
}
@ -358,81 +275,47 @@ win_show_status_string(ProfWin *window, const char * const from,
GDateTime *last_activity, const char * const pre,
const char * const default_show)
{
WINDOW *win = window->win;
win_print_time(window, '-');
int presence_colour;
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattron(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
wattron(win, COLOUR_CHAT);
} else if (strcmp(show, "dnd") == 0) {
wattron(win, COLOUR_DND);
} else if (strcmp(show, "xa") == 0) {
wattron(win, COLOUR_XA);
} else if (strcmp(show, "online") == 0) {
wattron(win, COLOUR_ONLINE);
} else {
wattron(win, COLOUR_OFFLINE);
}
presence_colour = win_presence_colour(show);
} else if (strcmp(default_show, "online") == 0) {
wattron(win, COLOUR_ONLINE);
presence_colour = COLOUR_ONLINE;
} else {
wattron(win, COLOUR_OFFLINE);
presence_colour = COLOUR_OFFLINE;
}
wprintw(win, "%s %s", pre, from);
win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from);
if (show != NULL)
wprintw(win, " is %s", show);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show);
else
wprintw(win, " is %s", default_show);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show);
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
wprintw(win, ", idle ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(win, "%ds", seconds);
if (hours > 0) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds);
}
else {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds);
}
}
if (status != NULL)
wprintw(win, ", \"%s\"", status);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status);
wprintw(win, "\n");
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattroff(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
wattroff(win, COLOUR_CHAT);
} else if (strcmp(show, "dnd") == 0) {
wattroff(win, COLOUR_DND);
} else if (strcmp(show, "xa") == 0) {
wattroff(win, COLOUR_XA);
} else if (strcmp(show, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else {
wattroff(win, COLOUR_OFFLINE);
}
} else if (strcmp(default_show, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else {
wattroff(win, COLOUR_OFFLINE);
}
}
void
@ -443,7 +326,7 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
{
case WIN_CHAT:
case WIN_PRIVATE:
_win_chat_print_incoming_message(window, tv_stamp, from, message);
win_save_print(window, '-', tv_stamp, NO_ME, 0, from, message);
break;
default:
assert(FALSE);
@ -451,33 +334,112 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
}
}
static void
_win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message)
void
win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp,
int flags, int attrs, const char * const from, const char * const message, ...)
{
if (tv_stamp == NULL) {
win_print_time(window, '-');
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
win_save_print(window, show_char, tstamp, flags, attrs, from, fmt_msg->str);
}
void
win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp,
int flags, int attrs, const char * const from, const char * const message)
{
gchar *date_fmt;
GDateTime *time;
if (tstamp == NULL) {
time = g_date_time_new_now_local();
date_fmt = g_date_time_format(time, "%H:%M:%S");
} 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);
time = g_date_time_new_from_timeval_utc(tstamp);
date_fmt = g_date_time_format(time, "%H:%M:%S");
}
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);
g_date_time_unref(time);
buffer_push(window->buffer, show_char, date_fmt, flags, attrs, from, message);
_win_print(window, show_char, date_fmt, flags, attrs, from, message);
g_free(date_fmt);
}
void
win_save_println(ProfWin *window, const char * const message)
{
win_save_print(window, '-', NULL, 0, 0, "", message);
}
void
win_save_newline(ProfWin *window)
{
win_save_print(window, '-', NULL, NO_DATE, 0, "", "");
}
static void
_win_print(ProfWin *window, const char show_char, const char * const date_fmt,
int flags, int attrs, const char * const from, const char * const message)
{
// flags : 1st bit = 0/1 - me/not me
// 2nd bit = 0/1 - date/no date
// 3rd bit = 0/1 - eol/no eol
// 4th bit = 0/1 - color from/no color from
int unattr_me = 0;
int offset = 0;
int colour = COLOUR_ME;
if ((flags & NO_DATE) == 0) {
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s %c ", date_fmt, show_char);
wattroff(window->win, COLOUR_TIME);
}
if (strlen(from) > 0) {
if (flags & NO_ME) {
colour = COLOUR_THEM;
}
if (flags & NO_COLOUR_FROM) {
colour = 0;
}
wattron(window->win, colour);
if (strncmp(message, "/me ", 4) == 0) {
wprintw(window->win, "*%s ", from);
offset = 4;
unattr_me = 1;
} else {
wprintw(window->win, "%s: ", from);
wattroff(window->win, colour);
}
}
wattron(window->win, attrs);
if (flags & NO_EOL) {
wprintw(window->win, "%s", message+offset);
} else {
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "%s: ", from);
wattroff(window->win, COLOUR_THEM);
waddstr(window->win, message);
wprintw(window->win, "\n");
wprintw(window->win, "%s\n", message+offset);
}
wattroff(window->win, attrs);
if (unattr_me) {
wattroff(window->win, colour);
}
}
void
win_redraw(ProfWin *window)
{
int i, size;
werase(window->win);
size = buffer_size(window->buffer);
for (i = 0; i < size; i++) {
ProfBuffEntry *e = buffer_yield_entry(window->buffer, i);
_win_print(window, e->show_char, e->date_fmt, e->flags, e->attrs, e->from, e->message);
}
}

View File

@ -32,6 +32,12 @@
#endif
#include "contact.h"
#include "ui/buffer.h"
#define NO_ME 1
#define NO_DATE 2
#define NO_EOL 4
#define NO_COLOUR_FROM 8
#define PAD_SIZE 1000
@ -49,6 +55,7 @@ typedef enum {
typedef struct prof_win_t {
char *from;
WINDOW *win;
ProfBuff buffer;
win_type_t type;
gboolean is_otr;
gboolean is_trusted;
@ -60,16 +67,9 @@ typedef struct prof_win_t {
ProfWin* win_create(const char * const title, int cols, win_type_t type);
void win_free(ProfWin *window);
void win_vprint_line(ProfWin *self, const char show_char, int attrs,
const char * const msg, ...);
void win_print_line(ProfWin *self, const char show_char, int attrs,
const char * const msg);
void win_print_line_no_time(ProfWin *window, int attrs, const char * const msg);
void win_update_virtual(ProfWin *window);
void win_move_to_end(ProfWin *window);
void win_print_time(ProfWin *window, char show_char);
void win_presence_colour_on(ProfWin *window, const char * const presence);
void win_presence_colour_off(ProfWin *window, const char * const presence);
int win_presence_colour(const char * const presence);
void win_show_contact(ProfWin *window, PContact contact);
void win_show_status_string(ProfWin *window, const char * const from,
const char * const show, const char * const status,
@ -78,5 +78,10 @@ void win_show_status_string(ProfWin *window, const char * const from,
void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message);
void win_show_info(ProfWin *window, PContact contact);
void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message, ...);
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message);
void win_save_println(ProfWin *window, const char * const message);
void win_save_newline(ProfWin *window);
void win_redraw(ProfWin *window);
#endif

View File

@ -274,20 +274,15 @@ wins_resize_all(void)
int rows, cols;
getmaxyx(stdscr, rows, cols);
// only make the pads bigger, to avoid data loss on cropping
if (cols > max_cols) {
max_cols = cols;
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
ProfWin *window = curr->data;
wresize(window->win, PAD_SIZE, cols);
curr = g_list_next(curr);
}
g_list_free(values);
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
ProfWin *window = curr->data;
wresize(window->win, PAD_SIZE, cols);
win_redraw(window);
curr = g_list_next(curr);
}
g_list_free(values);
ProfWin *current_win = wins_get_current();
@ -396,10 +391,7 @@ wins_lost_connection(void)
while (curr != NULL) {
ProfWin *window = curr->data;
if (window->type != WIN_CONSOLE) {
win_print_time(window, '-');
wattron(window->win, COLOUR_ERROR);
wprintw(window->win, "%s\n", "Lost connection.");
wattroff(window->win, COLOUR_ERROR);
win_save_print(window, '-', NULL, 0, COLOUR_ERROR, "", "Lost connection.");
// if current win, set current_win_dirty
if (wins_is_current(window)) {