fix conflicts

This commit is contained in:
Will Song
2015-05-29 19:53:37 -05:00
138 changed files with 7452 additions and 6201 deletions

View File

@@ -1,7 +1,7 @@
/*
* buffer.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -81,7 +81,7 @@ buffer_free(ProfBuff buffer)
void
buffer_push(ProfBuff buffer, const char show_char, GDateTime *time,
int flags, theme_item_t theme_item, const char * const from, const char * const message)
int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt)
{
ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t));
e->show_char = show_char;
@@ -90,6 +90,7 @@ buffer_push(ProfBuff buffer, const char show_char, GDateTime *time,
e->time = time;
e->from = strdup(from);
e->message = strdup(message);
e->receipt = receipt;
if (g_slist_length(buffer->entries) == BUFF_SIZE) {
_free_entry(buffer->entries->data);
@@ -99,6 +100,24 @@ buffer_push(ProfBuff buffer, const char show_char, GDateTime *time,
buffer->entries = g_slist_append(buffer->entries, e);
}
gboolean
buffer_mark_received(ProfBuff buffer, const char * const id)
{
GSList *entries = buffer->entries;
while (entries) {
ProfBuffEntry *entry = entries->data;
if (entry->receipt && g_strcmp0(entry->receipt->id, id) == 0) {
if (!entry->receipt->received) {
entry->receipt->received = TRUE;
return TRUE;
}
}
entries = g_slist_next(entries);
}
return FALSE;
}
ProfBuffEntry*
buffer_yield_entry(ProfBuff buffer, int entry)
{
@@ -112,5 +131,9 @@ _free_entry(ProfBuffEntry *entry)
free(entry->message);
free(entry->from);
g_date_time_unref(entry->time);
if (entry->receipt) {
free(entry->receipt->id);
free(entry->receipt);
}
free(entry);
}

View File

@@ -1,7 +1,7 @@
/*
* buffer.h
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -40,6 +40,11 @@
#include <glib.h>
typedef struct delivery_receipt_t {
char *id;
gboolean received;
} DeliveryReceipt;
typedef struct prof_buff_entry_t {
char show_char;
GDateTime *time;
@@ -47,13 +52,18 @@ typedef struct prof_buff_entry_t {
theme_item_t theme_item;
char *from;
char *message;
DeliveryReceipt *receipt;
} ProfBuffEntry;
typedef struct prof_buff_t *ProfBuff;
ProfBuff buffer_create();
void buffer_free(ProfBuff buffer);
void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message);
void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, int flags, theme_item_t theme_item,
const char * const from, const char * const message, DeliveryReceipt *receipt);
int buffer_size(ProfBuff buffer);
ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry);
gboolean buffer_mark_received(ProfBuff buffer, const char * const id);
#endif

View File

@@ -1,7 +1,7 @@
/*
* console.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -67,14 +67,14 @@ void
cons_show_time(void)
{
ProfWin *console = wins_get_console();
win_save_print(console, '-', NULL, NO_EOL, 0, "", "");
win_print(console, '-', NULL, NO_EOL, 0, "", "");
}
void
cons_show_word(const char * const word)
{
ProfWin *console = wins_get_console();
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", word);
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", word);
}
void
@@ -86,7 +86,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_save_println(console, fmt_msg->str);
win_println(console, fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
@@ -100,7 +100,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_save_println(console, fmt_msg->str);
win_println(console, fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
@@ -113,7 +113,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_save_print(console, '-', NULL, 0, THEME_ERROR, "", fmt_msg->str);
win_print(console, '-', NULL, 0, THEME_ERROR, "", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@@ -126,8 +126,8 @@ cons_show_typing(const char * const barejid)
ProfWin *console = wins_get_console();
const char * display_usr = NULL;
PContact contact = roster_get_contact(barejid);
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
if (contact) {
if (p_contact_name(contact)) {
display_usr = p_contact_name(contact);
} else {
display_usr = barejid;
@@ -136,7 +136,7 @@ cons_show_typing(const char * const barejid)
display_usr = barejid;
}
win_save_vprint(console, '-', NULL, 0, THEME_TYPING, "", "!! %s is typing a message...", display_usr);
win_vprint(console, '-', NULL, 0, THEME_TYPING, "", "!! %s is typing a message...", display_usr);
cons_alert();
}
@@ -149,7 +149,7 @@ cons_show_incoming_message(const char * const short_from, const int win_index)
if (ui_index == 10) {
ui_index = 0;
}
win_save_vprint(console, '-', NULL, 0, THEME_INCOMING, "", "<< incoming from %s (%d)", short_from, ui_index);
win_vprint(console, '-', NULL, 0, THEME_INCOMING, "", "<< incoming from %s (%d)", short_from, ui_index);
cons_alert();
}
@@ -167,23 +167,23 @@ cons_about(void)
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev", PACKAGE_VERSION);
win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev", PACKAGE_VERSION);
#endif
} else {
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %s", PACKAGE_VERSION);
win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %s", PACKAGE_VERSION);
}
}
win_save_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2014 James Booth <%s>.", 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, "");
win_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT);
win_println(console, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>");
win_println(console, "");
win_println(console, "This is free software; you are free to change and redistribute it.");
win_println(console, "There is NO WARRANTY, to the extent permitted by law.");
win_println(console, "");
win_println(console, "Type '/help' to show complete help.");
win_println(console, "");
if (prefs_get_boolean(PREF_VERCHECK)) {
cons_check_version(FALSE);
@@ -200,18 +200,18 @@ cons_check_version(gboolean not_available_msg)
ProfWin *console = wins_get_console();
char *latest_release = release_get_latest();
if (latest_release != NULL) {
if (latest_release) {
gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0);
if (relase_valid) {
if (release_is_new(latest_release)) {
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.");
win_save_println(console, "");
win_vprint(console, '-', NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release);
win_println(console, "Check <http://www.profanity.im> for details.");
win_println(console, "");
} else {
if (not_available_msg) {
win_save_println(console, "No new version available.");
win_save_println(console, "");
win_println(console, "No new version available.");
win_println(console, "");
}
}
@@ -225,16 +225,16 @@ void
cons_show_login_success(ProfAccount *account)
{
ProfWin *console = wins_get_console();
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "%s logged in successfully, ", account->jid);
win_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);
theme_item_t presence_colour = theme_main_presence_attrs(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)",
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str);
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
win_save_print(console, '-', NULL, NO_DATE, 0, "", ".");
win_print(console, '-', NULL, NO_DATE, 0, "", ".");
cons_alert();
}
@@ -247,10 +247,11 @@ cons_show_wins(void)
GSList *window_strings = wins_create_summary();
GSList *curr = window_strings;
while (curr != NULL) {
win_save_println(console, curr->data);
while (curr) {
win_println(console, curr->data);
curr = g_slist_next(curr);
}
g_slist_free_full(window_strings, free);
cons_show("");
cons_alert();
@@ -264,7 +265,7 @@ cons_show_room_invites(GSList *invites)
cons_show("No outstanding chat room invites.");
} else {
cons_show("Chat room invites, use /join or /decline commands:");
while (invites != NULL) {
while (invites) {
cons_show(" %s", invites->data);
invites = g_slist_next(invites);
}
@@ -293,53 +294,53 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence)
const char *resource_presence = string_from_resource_presence(presence);
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid);
win_save_print(console, '-', NULL, NO_DATE, 0, "", ":");
win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid);
win_print(console, '-', NULL, NO_DATE, 0, "", ":");
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_save_print(console, '-', NULL, NO_EOL, 0, "", "Identity: ");
if (caps->name != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
if (caps->category || caps->type || caps->name) {
win_print(console, '-', NULL, NO_EOL, 0, "", "Identity: ");
if (caps->name) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if (caps->category || caps->type) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->type != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
if (caps->type) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->category != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
if (caps->category) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
}
win_save_newline(console);
win_newline(console);
}
if (caps->software != NULL) {
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software);
if (caps->software) {
win_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software);
}
if (caps->software_version != NULL) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
if (caps->software_version) {
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
win_save_newline(console);
if (caps->software || caps->software_version) {
win_newline(console);
}
if (caps->os != NULL) {
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os);
if (caps->os) {
win_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os);
}
if (caps->os_version != NULL) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
if (caps->os_version) {
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
win_save_newline(console);
if (caps->os || caps->os_version) {
win_newline(console);
}
if (caps->features != NULL) {
win_save_println(console, "Features:");
if (caps->features) {
win_println(console, "Features:");
GSList *feature = caps->features;
while (feature != NULL) {
win_save_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data);
while (feature) {
win_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data);
feature = g_slist_next(feature);
}
}
@@ -357,19 +358,19 @@ cons_show_software_version(const char * const jid, const char * const presence,
const char * const name, const char * const version, const char * const os)
{
ProfWin *console = wins_get_console();
if ((name != NULL) || (version != NULL) || (os != NULL)) {
if (name || version || os) {
cons_show("");
theme_item_t presence_colour = theme_main_presence_attrs(presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid);
win_save_print(console, '-', NULL, NO_DATE, 0, "", ":");
win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid);
win_print(console, '-', NULL, NO_DATE, 0, "", ":");
}
if (name != NULL) {
if (name) {
cons_show("Name : %s", name);
}
if (version != NULL) {
if (version) {
cons_show("Version : %s", version);
}
if (os != NULL) {
if (os) {
cons_show("OS : %s", os);
}
@@ -385,7 +386,7 @@ cons_show_received_subs(void)
} else {
cons_show("Outstanding subscription requests from:",
g_slist_length(received));
while (received != NULL) {
while (received) {
cons_show(" %s", received->data);
received = g_slist_next(received);
}
@@ -402,17 +403,18 @@ cons_show_sent_subs(void)
GSList *contacts = roster_get_contacts();
PContact contact = NULL;
cons_show("Awaiting subscription responses from:");
while (contacts != NULL) {
contact = (PContact) contacts->data;
GSList *curr = contacts;
while (curr) {
contact = (PContact) curr->data;
if (p_contact_pending_out(contact)) {
cons_show(" %s", p_contact_barejid(contact));
}
contacts = g_slist_next(contacts);
curr = g_slist_next(curr);
}
g_slist_free(contacts);
} else {
cons_show("No pending requests sent.");
}
cons_alert();
}
@@ -420,15 +422,15 @@ void
cons_show_room_list(GSList *rooms, const char * const conference_node)
{
ProfWin *console = wins_get_console();
if ((rooms != NULL) && (g_slist_length(rooms) > 0)) {
if (rooms && (g_slist_length(rooms) > 0)) {
cons_show("Chat rooms at %s:", conference_node);
while (rooms != NULL) {
while (rooms) {
DiscoItem *room = rooms->data;
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid);
if (room->name != NULL) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name);
win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid);
if (room->name) {
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name);
}
win_save_newline(console);
win_newline(console);
rooms = g_slist_next(rooms);
}
} else {
@@ -450,7 +452,7 @@ cons_show_bookmarks(const GList *list)
cons_show("");
cons_show("Bookmarks:");
while (list != NULL) {
while (list) {
Bookmark *item = list->data;
theme_item_t presence_colour = THEME_TEXT;
@@ -458,24 +460,24 @@ cons_show_bookmarks(const GList *list)
if (muc_active(item->jid)) {
presence_colour = THEME_ONLINE;
}
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid);
if (item->nick != NULL) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick);
win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid);
if (item->nick) {
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick);
}
if (item->autojoin) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)");
win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)");
}
if (item->password != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)");
if (item->password) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)");
}
if (muc_active(item->jid)) {
ProfWin *roomwin = (ProfWin*)wins_get_muc(item->jid);
if (roomwin != NULL) {
if (roomwin) {
int num = wins_get_num(roomwin);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num);
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num);
}
}
win_save_newline(console);
win_newline(console);
list = g_list_next(list);
}
}
@@ -485,26 +487,26 @@ cons_show_bookmarks(const GList *list)
void
cons_show_disco_info(const char *jid, GSList *identities, GSList *features)
{
if (((identities != NULL) && (g_slist_length(identities) > 0)) ||
((features != NULL) && (g_slist_length(features) > 0))) {
if ((identities && (g_slist_length(identities) > 0)) ||
(features && (g_slist_length(features) > 0))) {
cons_show("");
cons_show("Service disovery info for %s", jid);
if (identities != NULL) {
if (identities) {
cons_show(" Identities");
}
while (identities != NULL) {
while (identities) {
DiscoIdentity *identity = identities->data; // anme trpe, cat
GString *identity_str = g_string_new(" ");
if (identity->name != NULL) {
if (identity->name) {
identity_str = g_string_append(identity_str, identity->name);
identity_str = g_string_append(identity_str, " ");
}
if (identity->type != NULL) {
if (identity->type) {
identity_str = g_string_append(identity_str, identity->type);
identity_str = g_string_append(identity_str, " ");
}
if (identity->category != NULL) {
if (identity->category) {
identity_str = g_string_append(identity_str, identity->category);
}
cons_show(identity_str->str);
@@ -512,10 +514,10 @@ cons_show_disco_info(const char *jid, GSList *identities, GSList *features)
identities = g_slist_next(identities);
}
if (features != NULL) {
if (features) {
cons_show(" Features:");
}
while (features != NULL) {
while (features) {
cons_show(" %s", features->data);
features = g_slist_next(features);
}
@@ -528,16 +530,16 @@ void
cons_show_disco_items(GSList *items, const char * const jid)
{
ProfWin *console = wins_get_console();
if ((items != NULL) && (g_slist_length(items) > 0)) {
if (items && (g_slist_length(items) > 0)) {
cons_show("");
cons_show("Service discovery items for %s:", jid);
while (items != NULL) {
while (items) {
DiscoItem *item = items->data;
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid);
if (item->name != NULL) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name);
win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid);
if (item->name) {
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name);
}
win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "");
win_vprint(console, '-', NULL, NO_DATE, 0, "", "");
items = g_slist_next(items);
}
} else {
@@ -554,7 +556,7 @@ cons_show_status(const char * const barejid)
ProfWin *console = wins_get_console();
PContact pcontact = roster_get_contact(barejid);
if (pcontact != NULL) {
if (pcontact) {
win_show_contact(console, pcontact);
} else {
cons_show("No such contact \"%s\" in roster.", barejid);
@@ -569,8 +571,8 @@ cons_show_room_invite(const char * const invitor, const char * const room,
{
char *display_from = NULL;
PContact contact = roster_get_contact(invitor);
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
if (contact) {
if (p_contact_name(contact)) {
display_from = strdup(p_contact_name(contact));
} else {
display_from = strdup(invitor);
@@ -584,7 +586,7 @@ cons_show_room_invite(const char * const invitor, const char * const room,
cons_show(" From : %s", display_from);
cons_show(" Room : %s", room);
if (reason != NULL) {
if (reason) {
cons_show(" Message: %s", reason);
}
@@ -612,7 +614,7 @@ cons_show_account_list(gchar **accounts)
(g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) {
resource_presence_t presence = accounts_get_last_presence(accounts[i]);
theme_item_t presence_colour = theme_main_presence_attrs(string_from_resource_presence(presence));
win_save_vprint(console, '-', NULL, 0, presence_colour, "", "%s", accounts[i]);
win_vprint(console, '-', NULL, 0, presence_colour, "", "%s", accounts[i]);
} else {
cons_show(accounts[i]);
}
@@ -671,9 +673,9 @@ cons_show_account(ProfAccount *account)
if (g_list_length(account->otr_manual) > 0) {
GString *manual = g_string_new("OTR manual : ");
GList *curr = account->otr_manual;
while (curr != NULL) {
while (curr) {
g_string_append(manual, curr->data);
if (curr->next != NULL) {
if (curr->next) {
g_string_append(manual, ", ");
}
curr = curr->next;
@@ -684,9 +686,9 @@ cons_show_account(ProfAccount *account)
if (g_list_length(account->otr_opportunistic) > 0) {
GString *opportunistic = g_string_new("OTR opportunistic : ");
GList *curr = account->otr_opportunistic;
while (curr != NULL) {
while (curr) {
g_string_append(opportunistic, curr->data);
if (curr->next != NULL) {
if (curr->next) {
g_string_append(opportunistic, ", ");
}
curr = curr->next;
@@ -697,9 +699,9 @@ cons_show_account(ProfAccount *account)
if (g_list_length(account->otr_always) > 0) {
GString *always = g_string_new("OTR always : ");
GList *curr = account->otr_always;
while (curr != NULL) {
while (curr) {
g_string_append(always, curr->data);
if (curr->next != NULL) {
if (curr->next) {
g_string_append(always, ", ");
}
curr = curr->next;
@@ -717,76 +719,81 @@ cons_show_account(ProfAccount *account)
GList *resources = jabber_get_available_resources();
GList *ordered_resources = NULL;
if (resources != NULL) {
win_save_println(console, "Resources:");
GList *curr = resources;
if (curr) {
win_println(console, "Resources:");
// sort in order of availabiltiy
while (resources != NULL) {
Resource *resource = resources->data;
// sort in order of availability
while (curr) {
Resource *resource = curr->data;
ordered_resources = g_list_insert_sorted(ordered_resources,
resource, (GCompareFunc)resource_compare_availability);
resources = g_list_next(resources);
curr = g_list_next(curr);
}
}
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
g_list_free(resources);
curr = ordered_resources;
while (curr) {
Resource *resource = curr->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
if (resource->status) {
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
}
win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "");
win_vprint(console, '-', NULL, NO_DATE, 0, "", "");
Jid *jidp = jid_create_from_bare_and_resource(account->jid, resource->name);
Capabilities *caps = caps_lookup(jidp->fulljid);
jid_destroy(jidp);
if (caps != NULL) {
if (caps) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_save_print(console, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
if (caps->category || caps->type || caps->name) {
win_print(console, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if (caps->category || caps->type) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->type != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
if (caps->type) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->category != NULL) {
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
if (caps->category) {
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
}
win_save_newline(console);
win_newline(console);
}
if (caps->software != NULL) {
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
if (caps->software) {
win_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
if (caps->software_version) {
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
win_save_newline(console);
if (caps->software || caps->software_version) {
win_newline(console);
}
if (caps->os != NULL) {
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
if (caps->os) {
win_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
if (caps->os_version) {
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
win_save_newline(console);
if (caps->os || caps->os_version) {
win_newline(console);
}
caps_destroy(caps);
}
ordered_resources = g_list_next(ordered_resources);
curr = g_list_next(curr);
}
g_list_free(ordered_resources);
}
cons_alert();
@@ -801,10 +808,10 @@ cons_show_aliases(GList *aliases)
}
GList *curr = aliases;
if (curr != NULL) {
if (curr) {
cons_show("Command aliases:");
}
while (curr != NULL) {
while (curr) {
ProfAlias *alias = curr->data;
cons_show(" /%s -> %s", alias->name, alias->value);
curr = g_list_next(curr);
@@ -850,9 +857,9 @@ cons_resource_setting(void)
else
cons_show("Resource title (/resource) : OFF");
if (prefs_get_boolean(PREF_RESOURCE_MESSAGE))
cons_show("Message title (/resource) : ON");
cons_show("Resource message (/resource) : ON");
else
cons_show("Message title (/resource) : OFF");
cons_show("Resource message (/resource) : OFF");
}
void
@@ -899,6 +906,11 @@ cons_occupants_setting(void)
else
cons_show("Occupants (/occupants) : hide");
if (prefs_get_boolean(PREF_OCCUPANTS_JID))
cons_show("Occupant jids (/occupants) : show");
else
cons_show("Occupant jids (/occupants) : hide");
int size = prefs_get_occupants_size();
cons_show("Occupants size (/occupants) : %d", size);
}
@@ -907,7 +919,7 @@ void
cons_autoconnect_setting(void)
{
char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT);
if (pref_connect_account != NULL)
if (pref_connect_account)
cons_show("Autoconnect (/autoconnect) : %s", pref_connect_account);
else
cons_show("Autoconnect (/autoconnect) : OFF");
@@ -925,6 +937,16 @@ cons_time_setting(void)
cons_show("Time (/time) : %s", pref_time);
prefs_free_string(pref_time);
char *pref_time_statusbar = prefs_get_string(PREF_TIME_STATUSBAR);
if (g_strcmp0(pref_time_statusbar, "minutes") == 0)
cons_show("Time statusbar (/time) : minutes");
else if (g_strcmp0(pref_time_statusbar, "off") == 0)
cons_show("Time statusbar (/time) : OFF");
else
cons_show("Time statusbar (/time) : seconds");
prefs_free_string(pref_time_statusbar);
}
void
@@ -994,6 +1016,9 @@ cons_roster_setting(void)
else
cons_show("Roster resource (/roster) : hide");
char *by = prefs_get_string(PREF_ROSTER_BY);
cons_show("Roster by (/roster) : %s", by);
int size = prefs_get_roster_size();
cons_show("Roster size (/roster) : %d", size);
}
@@ -1120,27 +1145,27 @@ void
cons_states_setting(void)
{
if (prefs_get_boolean(PREF_STATES))
cons_show("Send chat states (/states) : ON");
cons_show("Send chat states (/states) : ON");
else
cons_show("Send chat states (/states) : OFF");
cons_show("Send chat states (/states) : OFF");
}
void
cons_outtype_setting(void)
{
if (prefs_get_boolean(PREF_OUTTYPE))
cons_show("Send composing (/outtype) : ON");
cons_show("Send composing (/outtype) : ON");
else
cons_show("Send composing (/outtype) : OFF");
cons_show("Send composing (/outtype) : OFF");
}
void
cons_intype_setting(void)
{
if (prefs_get_boolean(PREF_INTYPE))
cons_show("Show typing (/intype) : ON");
cons_show("Show typing (/intype) : ON");
else
cons_show("Show typing (/intype) : OFF");
cons_show("Show typing (/intype) : OFF");
}
void
@@ -1148,11 +1173,11 @@ cons_gone_setting(void)
{
gint gone_time = prefs_get_gone();
if (gone_time == 0) {
cons_show("Leave conversation (/gone) : OFF");
cons_show("Leave conversation (/gone) : OFF");
} else if (gone_time == 1) {
cons_show("Leave conversation (/gone) : 1 minute");
cons_show("Leave conversation (/gone) : 1 minute");
} else {
cons_show("Leave conversation (/gone) : %d minutes", gone_time);
cons_show("Leave conversation (/gone) : %d minutes", gone_time);
}
}
@@ -1160,9 +1185,33 @@ void
cons_history_setting(void)
{
if (prefs_get_boolean(PREF_HISTORY))
cons_show("Chat history (/history) : ON");
cons_show("Chat history (/history) : ON");
else
cons_show("Chat history (/history) : OFF");
cons_show("Chat history (/history) : OFF");
}
void
cons_carbons_setting(void)
{
if (prefs_get_boolean(PREF_CARBONS))
cons_show("Message carbons (/carbons) : ON");
else
cons_show("Message carbons (/carbons) : OFF");
}
void
cons_receipts_setting(void)
{
if (prefs_get_boolean(PREF_RECEIPTS_REQUEST))
cons_show("Request receipts (/receipts) : ON");
else
cons_show("Request receipts (/receipts) : OFF");
if (prefs_get_boolean(PREF_RECEIPTS_SEND))
cons_show("Send receipts (/receipts) : ON");
else
cons_show("Send receipts (/receipts) : OFF");
}
void
@@ -1175,6 +1224,8 @@ cons_show_chat_prefs(void)
cons_intype_setting();
cons_gone_setting();
cons_history_setting();
cons_carbons_setting();
cons_receipts_setting();
cons_alert();
}
@@ -1359,7 +1410,7 @@ cons_show_themes(GSList *themes)
cons_show("No available themes.");
} else {
cons_show("Available themes:");
while (themes != NULL) {
while (themes) {
cons_show(themes->data);
themes = g_slist_next(themes);
}
@@ -1400,7 +1451,7 @@ cons_help(void)
cons_show("/help basic - List basic commands for getting started.");
cons_show("/help chatting - List chat commands.");
cons_show("/help groupchat - List groupchat commands.");
cons_show("/help presence - List commands to change presence.");
cons_show("/help presences - List commands to change presence.");
cons_show("/help contacts - List commands for manipulating your roster.");
cons_show("/help service - List service discovery commands.");
cons_show("/help settings - List commands for changing settings.");
@@ -1417,27 +1468,10 @@ cons_navigation_help(void)
cons_show("");
cons_show("Navigation:");
cons_show("");
cons_show("Alt-1 : This console window.");
cons_show("F1 : This console window.");
cons_show("Alt-2..Alt-0 : Chat windows.");
cons_show("F2..F10 : Chat windows.");
cons_show("Alt-1..Alt-0, F1..F10 : Choose window.");
cons_show("Alt-LEFT, Alt-RIGHT : Previous/next chat window");
cons_show("UP, DOWN : Navigate input history.");
cons_show("Ctrl-n, Ctrl-p : Navigate input history.");
cons_show("LEFT, RIGHT, HOME, END : Move cursor.");
cons_show("Ctrl-b, Ctrl-f, Ctrl-a, Ctrl-e : Move cursor.");
cons_show("Ctrl-LEFT, Ctrl-RIGHT : Jump word.");
cons_show("Ctrl-w : Delete previous word.");
cons_show("Alt-Backspace : Delete previous word.");
cons_show("Backspace : Delete previous character.");
cons_show("DEL : Delete next character.");
cons_show("Ctrl-d : Delete next character.");
cons_show("ESC : Clear current input.");
cons_show("Ctrl-u : Delete all previous characters.");
cons_show("TAB : Autocomplete.");
cons_show("PAGE UP, PAGE DOWN : Page the main window.");
cons_show("Shift-UP, Shift-DOWN : Page occupants/roster panel.");
cons_show("Ctrl-UP, Ctrl-DOWN : Page occupants/roster panel.");
cons_show("PAGEUP, PAGEDOWN : Page the main window.");
cons_show("Alt-PAGEUP, Alt-PAGEDOWN : Page occupants/roster panel.");
cons_show("");
cons_alert();
@@ -1448,7 +1482,7 @@ cons_show_roster_group(const char * const group, GSList *list)
{
cons_show("");
if (list != NULL) {
if (list) {
cons_show("%s:", group);
} else {
cons_show("No group named %s exists.", group);
@@ -1537,22 +1571,22 @@ cons_theme_colours(void)
ProfWin *console = wins_get_console();
cons_show("Theme colours:");
win_save_print(console, '-', NULL, NO_EOL, THEME_WHITE, "", " white ");
win_save_print(console, '-', NULL, NO_DATE, THEME_WHITE_BOLD, "", " bold_white");
win_save_print(console, '-', NULL, NO_EOL, THEME_GREEN, "", " green ");
win_save_print(console, '-', NULL, NO_DATE, THEME_GREEN_BOLD, "", " bold_green");
win_save_print(console, '-', NULL, NO_EOL, THEME_RED, "", " red ");
win_save_print(console, '-', NULL, NO_DATE, THEME_RED_BOLD, "", " bold_red");
win_save_print(console, '-', NULL, NO_EOL, THEME_YELLOW, "", " yellow ");
win_save_print(console, '-', NULL, NO_DATE, THEME_YELLOW_BOLD, "", " bold_yellow");
win_save_print(console, '-', NULL, NO_EOL, THEME_BLUE, "", " blue ");
win_save_print(console, '-', NULL, NO_DATE, THEME_BLUE_BOLD, "", " bold_blue");
win_save_print(console, '-', NULL, NO_EOL, THEME_CYAN, "", " cyan ");
win_save_print(console, '-', NULL, NO_DATE, THEME_CYAN_BOLD, "", " bold_cyan");
win_save_print(console, '-', NULL, NO_EOL, THEME_MAGENTA, "", " magenta ");
win_save_print(console, '-', NULL, NO_DATE, THEME_MAGENTA_BOLD, "", " bold_magenta");
win_save_print(console, '-', NULL, NO_EOL, THEME_BLACK, "", " black ");
win_save_print(console, '-', NULL, NO_DATE, THEME_BLACK_BOLD, "", " bold_black");
win_print(console, '-', NULL, NO_EOL, THEME_WHITE, "", " white ");
win_print(console, '-', NULL, NO_DATE, THEME_WHITE_BOLD, "", " bold_white");
win_print(console, '-', NULL, NO_EOL, THEME_GREEN, "", " green ");
win_print(console, '-', NULL, NO_DATE, THEME_GREEN_BOLD, "", " bold_green");
win_print(console, '-', NULL, NO_EOL, THEME_RED, "", " red ");
win_print(console, '-', NULL, NO_DATE, THEME_RED_BOLD, "", " bold_red");
win_print(console, '-', NULL, NO_EOL, THEME_YELLOW, "", " yellow ");
win_print(console, '-', NULL, NO_DATE, THEME_YELLOW_BOLD, "", " bold_yellow");
win_print(console, '-', NULL, NO_EOL, THEME_BLUE, "", " blue ");
win_print(console, '-', NULL, NO_DATE, THEME_BLUE_BOLD, "", " bold_blue");
win_print(console, '-', NULL, NO_EOL, THEME_CYAN, "", " cyan ");
win_print(console, '-', NULL, NO_DATE, THEME_CYAN_BOLD, "", " bold_cyan");
win_print(console, '-', NULL, NO_EOL, THEME_MAGENTA, "", " magenta ");
win_print(console, '-', NULL, NO_DATE, THEME_MAGENTA_BOLD, "", " bold_magenta");
win_print(console, '-', NULL, NO_EOL, THEME_BLACK, "", " black ");
win_print(console, '-', NULL, NO_DATE, THEME_BLACK_BOLD, "", " bold_black");
cons_show("");
}
@@ -1560,25 +1594,25 @@ static void
_cons_splash_logo(void)
{
ProfWin *console = wins_get_console();
win_save_println(console, "Welcome to");
win_println(console, "Welcome to");
win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", " ___ _ ");
win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", " / __) (_)_ ");
win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", " ____ ____ ___ | |__ ____ ____ _| |_ _ _ ");
win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |");
win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "| | | | | | |_| | | ( ( | | | | | | |_| |_| |");
win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |");
win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "|_| (____/ ");
win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "");
win_print(console, '-', NULL, 0, THEME_SPLASH, "", " ___ _ ");
win_print(console, '-', NULL, 0, THEME_SPLASH, "", " / __) (_)_ ");
win_print(console, '-', NULL, 0, THEME_SPLASH, "", " ____ ____ ___ | |__ ____ ____ _| |_ _ _ ");
win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |");
win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| | | | | | |_| | | ( ( | | | | | | |_| |_| |");
win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |");
win_print(console, '-', NULL, 0, THEME_SPLASH, "", "|_| (____/ ");
win_print(console, '-', NULL, 0, THEME_SPLASH, "", "");
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
win_vprint(console, '-', NULL, 0, 0, "", "Version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %sdev", PACKAGE_VERSION);
win_vprint(console, '-', NULL, 0, 0, "", "Version %sdev", PACKAGE_VERSION);
#endif
} else {
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %s", PACKAGE_VERSION);
win_vprint(console, '-', NULL, 0, 0, "", "Version %s", PACKAGE_VERSION);
}
}
@@ -1592,7 +1626,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
PContact contact = curr->data;
GString *title = g_string_new(" ");
title = g_string_append(title, p_contact_barejid(contact));
if (p_contact_name(contact) != NULL) {
if (p_contact_name(contact)) {
title = g_string_append(title, " (");
title = g_string_append(title, p_contact_name(contact));
title = g_string_append(title, ")");
@@ -1605,11 +1639,11 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
} else {
presence_colour = theme_main_presence_attrs("offline");
}
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", title->str);
win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", title->str);
g_string_free(title, TRUE);
win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " - ");
win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " - ");
GString *sub = g_string_new("");
sub = g_string_append(sub, p_contact_subscription(contact));
if (p_contact_pending_out(contact)) {
@@ -1625,28 +1659,28 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
}
if (show_groups) {
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", sub->str);
win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", sub->str);
} else {
win_save_vprint(console, '-', NULL, NO_DATE, presence_colour, "", "%s", sub->str);
win_vprint(console, '-', NULL, NO_DATE, presence_colour, "", "%s", sub->str);
}
g_string_free(sub, TRUE);
if (show_groups) {
GSList *groups = p_contact_groups(contact);
if (groups != NULL) {
if (groups) {
GString *groups_str = g_string_new(" - ");
while (groups != NULL) {
while (groups) {
g_string_append(groups_str, groups->data);
if (g_slist_next(groups) != NULL) {
if (g_slist_next(groups)) {
g_string_append(groups_str, ", ");
}
groups = g_slist_next(groups);
}
win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "%s", groups_str->str);
win_vprint(console, '-', NULL, NO_DATE, 0, "", "%s", groups_str->str);
g_string_free(groups_str, TRUE);
} else {
win_save_print(console, '-', NULL, NO_DATE, 0, "", " ");
win_print(console, '-', NULL, NO_DATE, 0, "", " ");
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/*
* inputwin.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -35,15 +35,17 @@
#ifndef UI_INPUTWIN_H
#define UI_INPUTWIN_H
#include <glib.h>
#define INP_WIN_MAX 1000
void create_input_window(void);
char* inp_read(int *key_type, wint_t *ch);
void inp_win_reset(void);
char* inp_readline(void);
void inp_nonblocking(gboolean reset);
void inp_close(void);
void inp_win_clear(void);
void inp_win_resize(void);
void inp_put_back(void);
void inp_non_block(gint);
void inp_block(void);
void inp_get_password(char *passwd);
void inp_replace_input(const char * const new_input);
void inp_history_append(char *inp);
char* inp_get_password(void);
#endif

View File

@@ -1,7 +1,7 @@
/*
* notifier.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -48,10 +48,10 @@
#include "log.h"
#include "muc.h"
#include "ui/ui.h"
#include "ui/windows.h"
#include "config/preferences.h"
static void _notify(const char * const message, int timeout,
const char * const category);
static void _notify(const char * const message, int timeout, const char * const category);
static GTimer *remind_timer;
@@ -89,7 +89,7 @@ notify_invite(const char * const from, const char * const room,
g_string_append(message, from);
g_string_append(message, "\nto: ");
g_string_append(message, room);
if (reason != NULL) {
if (reason) {
g_string_append_printf(message, "\n\"%s\"", reason);
}
@@ -99,17 +99,25 @@ notify_invite(const char * const from, const char * const room,
}
void
notify_message(const char * const handle, int win, const char * const text)
notify_message(ProfWin *window, const char * const name, const char * const text)
{
GString *message = g_string_new("");
g_string_append_printf(message, "%s (win %d)", handle, win);
if (text != NULL) {
g_string_append_printf(message, "\n%s", text);
int num = wins_get_num(window);
if (num == 10) {
num = 0;
}
_notify(message->str, 10000, "incoming message");
gboolean is_current = wins_is_current(window);
if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) {
GString *message = g_string_new("");
g_string_append_printf(message, "%s (win %d)", name, num);
g_string_free(message, TRUE);
if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT) && text) {
g_string_append_printf(message, "\n%s", text);
}
_notify(message->str, 10000, "incoming message");
g_string_free(message, TRUE);
}
}
void
@@ -117,7 +125,7 @@ notify_room_message(const char * const handle, const char * const room, int win,
{
GString *message = g_string_new("");
g_string_append_printf(message, "%s in %s (win %d)", handle, room, win);
if (text != NULL) {
if (text) {
g_string_append_printf(message, "\n%s", text);
}
@@ -243,10 +251,9 @@ _notify(const char * const message, int timeout,
Shell_NotifyIcon(NIM_MODIFY, &nid);
#endif
#ifdef HAVE_OSXNOTIFY
GString *notify_command = g_string_new("terminal-notifier -title \"Profanity\" -message \"");
GString *notify_command = g_string_new("terminal-notifier -title \"Profanity\" -message '");
char *escaped_double = str_replace(message, "\"", "\\\"");
char *escaped_single = str_replace(escaped_double, "`", "\\`");
char *escaped_single = str_replace(message, "'", "'\\''");
if (escaped_single[0] == '<') {
g_string_append(notify_command, "\\<");
@@ -264,8 +271,7 @@ _notify(const char * const message, int timeout,
g_string_append(notify_command, escaped_single);
}
g_string_append(notify_command, "\"");
free(escaped_double);
g_string_append(notify_command, "'");
free(escaped_single);
char *term_name = getenv("TERM_PROGRAM");
@@ -276,7 +282,7 @@ _notify(const char * const message, int timeout,
app_id = "com.googlecode.iterm2";
}
if (app_id != NULL) {
if (app_id) {
g_string_append(notify_command, " -sender ");
g_string_append(notify_command, app_id);
}
@@ -288,4 +294,4 @@ _notify(const char * const message, int timeout,
g_string_free(notify_command, TRUE);
#endif
}
}

View File

@@ -1,7 +1,7 @@
/*
* occupantswin.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -40,7 +40,7 @@
#include "config/preferences.h"
static void
_occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant)
_occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean showjid)
{
const char *presence_str = string_from_resource_presence(occupant->presence);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
@@ -51,6 +51,13 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant)
win_printline_nowrap(layout->subwin, msg->str);
g_string_free(msg, TRUE);
if (showjid && occupant->jid) {
GString *msg = g_string_new(" ");
g_string_append(msg, occupant->jid);
win_printline_nowrap(layout->subwin, msg->str);
g_string_free(msg, TRUE);
}
wattroff(layout->subwin, theme_attrs(presence_colour));
}
@@ -74,7 +81,7 @@ occupantswin_occupants(const char * const roomjid)
while (roster_curr) {
Occupant *occupant = roster_curr->data;
if (occupant->role == MUC_ROLE_MODERATOR) {
_occuptantswin_occupant(layout, occupant);
_occuptantswin_occupant(layout, occupant, mucwin->showjid);
}
roster_curr = g_list_next(roster_curr);
}
@@ -86,7 +93,7 @@ occupantswin_occupants(const char * const roomjid)
while (roster_curr) {
Occupant *occupant = roster_curr->data;
if (occupant->role == MUC_ROLE_PARTICIPANT) {
_occuptantswin_occupant(layout, occupant);
_occuptantswin_occupant(layout, occupant, mucwin->showjid);
}
roster_curr = g_list_next(roster_curr);
}
@@ -98,7 +105,7 @@ occupantswin_occupants(const char * const roomjid)
while (roster_curr) {
Occupant *occupant = roster_curr->data;
if (occupant->role == MUC_ROLE_VISITOR) {
_occuptantswin_occupant(layout, occupant);
_occuptantswin_occupant(layout, occupant, mucwin->showjid);
}
roster_curr = g_list_next(roster_curr);
}
@@ -109,7 +116,7 @@ occupantswin_occupants(const char * const roomjid)
GList *roster_curr = occupants;
while (roster_curr) {
Occupant *occupant = roster_curr->data;
_occuptantswin_occupant(layout, occupant);
_occuptantswin_occupant(layout, occupant, mucwin->showjid);
roster_curr = g_list_next(roster_curr);
}
}

View File

@@ -1,7 +1,7 @@
/*
* rosterwin.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*

View File

@@ -1,7 +1,7 @@
/*
* statusbar.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -48,6 +48,7 @@
#include "ui/ui.h"
#include "ui/statusbar.h"
#include "ui/inputwin.h"
#include "config/preferences.h"
#define TIME_CHECK 60000000
@@ -94,7 +95,7 @@ create_status_bar(void)
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
wattroff(status_bar, bracket_attrs);
if (last_time != NULL) {
if (last_time) {
g_date_time_unref(last_time);
}
last_time = g_date_time_new_now_local();
@@ -126,10 +127,17 @@ status_bar_resize(void)
mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
wattroff(status_bar, bracket_attrs);
if (message != NULL) {
mvwprintw(status_bar, 0, 10, message);
if (message) {
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
if (g_strcmp0(time_pref, "minutes") == 0) {
mvwprintw(status_bar, 0, 10, message);
} else if (g_strcmp0(time_pref, "seconds") == 0) {
mvwprintw(status_bar, 0, 13, message);
} else {
mvwprintw(status_bar, 0, 1, message);
}
}
if (last_time != NULL) {
if (last_time) {
g_date_time_unref(last_time);
}
last_time = g_date_time_new_now_local();
@@ -192,7 +200,7 @@ status_bar_inactive(const int win)
is_new[11] = TRUE;
_mark_new(11);
// still have active winsows
// still have active windows
} else if (g_hash_table_size(remaining_active) != 0) {
is_active[11] = TRUE;
is_new[11] = FALSE;
@@ -241,7 +249,7 @@ status_bar_active(const int win)
_mark_active(11);
}
// visible winsow indicators
// visible window indicators
} else {
is_active[true_win] = TRUE;
is_new[true_win] = FALSE;
@@ -289,11 +297,19 @@ status_bar_print_message(const char * const msg)
{
werase(status_bar);
if (message != NULL) {
if (message) {
free(message);
}
message = strdup(msg);
mvwprintw(status_bar, 0, 10, message);
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
if (g_strcmp0(time_pref, "minutes") == 0) {
mvwprintw(status_bar, 0, 10, message);
} else if (g_strcmp0(time_pref, "seconds") == 0) {
mvwprintw(status_bar, 0, 13, message);
} else {
mvwprintw(status_bar, 0, 1, message);
}
int cols = getmaxx(stdscr);
int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
@@ -309,7 +325,7 @@ status_bar_print_message(const char * const msg)
void
status_bar_clear(void)
{
if (message != NULL) {
if (message) {
free(message);
message = NULL;
}
@@ -330,7 +346,7 @@ status_bar_clear(void)
void
status_bar_clear_message(void)
{
if (message != NULL) {
if (message) {
free(message);
message = NULL;
}
@@ -412,23 +428,37 @@ _mark_inactive(int num)
static void
_status_bar_draw(void)
{
if (last_time != NULL) {
if (last_time) {
g_date_time_unref(last_time);
}
last_time = g_date_time_new_now_local();
gchar *date_fmt = g_date_time_format(last_time, "%H:%M");
assert(date_fmt != NULL);
int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
wattron(status_bar, bracket_attrs);
mvwaddch(status_bar, 0, 1, '[');
wattroff(status_bar, bracket_attrs);
mvwprintw(status_bar, 0, 2, date_fmt);
wattron(status_bar, bracket_attrs);
mvwaddch(status_bar, 0, 7, ']');
wattroff(status_bar, bracket_attrs);
g_free(date_fmt);
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
if (g_strcmp0(time_pref, "minutes") == 0) {
gchar *date_fmt = g_date_time_format(last_time, "%H:%M");
assert(date_fmt != NULL);
wattron(status_bar, bracket_attrs);
mvwaddch(status_bar, 0, 1, '[');
wattroff(status_bar, bracket_attrs);
mvwprintw(status_bar, 0, 2, date_fmt);
wattron(status_bar, bracket_attrs);
mvwaddch(status_bar, 0, 7, ']');
wattroff(status_bar, bracket_attrs);
g_free(date_fmt);
} else if (g_strcmp0(time_pref, "seconds") == 0) {
gchar *date_fmt = g_date_time_format(last_time, "%H:%M:%S");
assert(date_fmt != NULL);
wattron(status_bar, bracket_attrs);
mvwaddch(status_bar, 0, 1, '[');
wattroff(status_bar, bracket_attrs);
mvwprintw(status_bar, 0, 2, date_fmt);
wattron(status_bar, bracket_attrs);
mvwaddch(status_bar, 0, 10, ']');
wattroff(status_bar, bracket_attrs);
g_free(date_fmt);
}
_update_win_statuses();
wnoutrefresh(status_bar);

View File

@@ -1,7 +1,7 @@
/*
* statusbar.h
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*

View File

@@ -1,7 +1,7 @@
/*
* titlebar.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -80,7 +80,7 @@ title_bar_update_virtual(void)
{
ProfWin *window = wins_get_current();
if (window->type != WIN_CONSOLE) {
if (typing_elapsed != NULL) {
if (typing_elapsed) {
gdouble seconds = g_timer_elapsed(typing_elapsed, NULL);
if (seconds >= 10) {
@@ -109,8 +109,11 @@ void
title_bar_console(void)
{
werase(win);
typing = FALSE;
if (typing_elapsed) {
g_timer_destroy(typing_elapsed);
}
typing_elapsed = NULL;
typing = FALSE;
_title_bar_draw();
}
@@ -125,7 +128,7 @@ title_bar_set_presence(contact_presence_t presence)
void
title_bar_switch(void)
{
if (typing_elapsed != NULL) {
if (typing_elapsed) {
g_timer_destroy(typing_elapsed);
typing_elapsed = NULL;
typing = FALSE;
@@ -138,7 +141,7 @@ void
title_bar_set_typing(gboolean is_typing)
{
if (is_typing) {
if (typing_elapsed != NULL) {
if (typing_elapsed) {
g_timer_start(typing_elapsed);
} else {
typing_elapsed = g_timer_new();
@@ -249,7 +252,7 @@ _show_privacy(ProfChatWin *chatwin)
{
int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
if (!chatwin->is_otr) {
if (chatwin->enc_mode == PROF_ENC_NONE) {
if (prefs_get_boolean(PREF_OTR_WARN)) {
int unencrypted_attrs = theme_attrs(THEME_TITLE_UNENCRYPTED);
wprintw(win, " ");

View File

@@ -1,7 +1,7 @@
/*
* titlebar.h
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*

View File

@@ -1,7 +1,7 @@
/*
* ui.h
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -59,9 +59,8 @@ void ui_close(void);
void ui_redraw(void);
void ui_resize(void);
GSList* ui_get_chat_recipients(void);
gboolean ui_switch_win(const int i);
void ui_next_win(void);
void ui_previous_win(void);
void ui_switch_win(ProfWin *window);
void ui_sigwinch_handler(int sig);
void ui_gone_secure(const char * const barejid, gboolean trusted);
void ui_gone_insecure(const char * const barejid);
@@ -81,10 +80,12 @@ void ui_smp_answer_failure(const char * const barejid);
void ui_otr_authenticating(const char * const barejid);
void ui_otr_authetication_waiting(const char * const recipient);
void ui_handle_otr_error(const char * const barejid, const char * const message);
unsigned long ui_get_idle_time(void);
void ui_reset_idle_time(void);
void ui_new_chat_win(const char * const barejid);
void ui_new_private_win(const char * const fulljid);
ProfPrivateWin* ui_new_private_win(const char * const fulljid);
ProfChatWin* ui_new_chat_win(const char * const barejid);
void ui_print_system_msg_from_recipient(const char * const barejid, const char *message);
gint ui_unread(void);
void ui_close_connected_win(int index);
@@ -94,7 +95,6 @@ int ui_close_read_wins(void);
// current window actions
void ui_clear_current(void);
win_type_t ui_current_win_type(void);
int ui_current_win_index(void);
gboolean ui_current_win_is_otr(void);
ProfChatWin *ui_get_current_chat(void);
@@ -102,27 +102,28 @@ ProfChatWin *ui_get_current_chat(void);
void ui_current_print_line(const char * const msg, ...);
void ui_current_print_formatted_line(const char show_char, int attrs, const char * const msg, ...);
void ui_current_error_line(const char * const msg);
void ui_win_error_line(ProfWin *window, const char * const msg);
win_type_t ui_win_type(int index);
void ui_close_win(int index);
gboolean ui_win_exists(int index);
int ui_win_unread(int index);
char * ui_ask_password(void);
void ui_handle_stanza(const char * const msg);
// ui events
void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity);
void ui_contact_typing(const char * const barejid, const char * const resource);
void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp);
void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp);
void ui_message_receipt(const char * const barejid, const char * const id);
void ui_disconnected(void);
void ui_recipient_gone(const char * const barejid, const char * const resource);
void ui_outgoing_chat_msg(const char * const from, const char * const barejid,
const char * const message);
void ui_outgoing_private_msg(const char * const from, const char * const fulljid,
const char * const message);
void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id);
void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message);
void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message);
void ui_room_join(const char * const roomjid, gboolean focus);
void ui_switch_to_room(const char * const roomjid);
@@ -171,6 +172,7 @@ void ui_room_member_nick_change(const char * const roomjid,
void ui_room_nick_change(const char * const roomjid, const char * const nick);
void ui_room_member_presence(const char * const roomjid,
const char * const nick, const char * const show, const char * const status);
void ui_room_update_occupants(const char * const roomjid);
void ui_room_show_occupants(const char * const roomjid);
void ui_room_hide_occupants(const char * const roomjid);
void ui_show_roster(void);
@@ -218,6 +220,11 @@ void ui_tidy_wins(void);
void ui_prune_wins(void);
gboolean ui_swap_wins(int source_win, int target_win);
void ui_page_up(void);
void ui_page_down(void);
void ui_subwin_page_up(void);
void ui_subwin_page_down(void);
void ui_auto_away(void);
void ui_end_auto_away(void);
void ui_titlebar_presence(contact_presence_t presence);
@@ -227,9 +234,10 @@ void ui_update_presence(const resource_presence_t resource_presence,
void ui_about(void);
void ui_statusbar_new(const int win);
char * ui_readline(void);
char* ui_readline(void);
void ui_input_clear(void);
void ui_input_nonblocking(gboolean);
void ui_write(char *line, int offset);
void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void));
@@ -308,6 +316,8 @@ void cons_outtype_setting(void);
void cons_intype_setting(void);
void cons_gone_setting(void);
void cons_history_setting(void);
void cons_carbons_setting(void);
void cons_receipts_setting(void);
void cons_log_setting(void);
void cons_chlog_setting(void);
void cons_grlog_setting(void);
@@ -332,7 +342,7 @@ void notifier_initialise(void);
void notifier_uninit(void);
void notify_typing(const char * const handle);
void notify_message(const char * const handle, int win, const char * const text);
void notify_message(ProfWin *window, const char * const name, const char * const text);
void notify_room_message(const char * const handle, const char * const room,
int win, const char * const text);
void notify_remind(void);

View File

@@ -1,7 +1,7 @@
/*
* window.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -38,6 +38,7 @@
#include <string.h>
#include <time.h>
#include <assert.h>
#include <wchar.h>
#include <glib.h>
#ifdef HAVE_NCURSESW_NCURSES_H
@@ -59,7 +60,7 @@
#define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
static void _win_print(ProfWin *window, const char show_char, GDateTime *time,
int flags, theme_item_t theme_item, const char * const from, const char * const message);
int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt);
static void _win_print_wrapped(WINDOW *win, const char * const message);
int
@@ -134,7 +135,7 @@ win_create_chat(const char * const barejid)
new_win->barejid = strdup(barejid);
new_win->resource_override = NULL;
new_win->is_otr = FALSE;
new_win->enc_mode = PROF_ENC_NONE;
new_win->is_trusted = FALSE;
new_win->history_shown = FALSE;
new_win->unread = 0;
@@ -177,6 +178,11 @@ win_create_muc(const char * const roomjid)
new_win->roomjid = strdup(roomjid);
new_win->unread = 0;
if (prefs_get_boolean(PREF_OCCUPANTS_JID)) {
new_win->showjid = TRUE;
} else {
new_win->showjid = FALSE;
}
new_win->memcheck = PROFMUCWIN_MEMCHECK;
@@ -331,12 +337,13 @@ win_free(ProfWin* window)
buffer_free(window->layout->buffer);
delwin(window->layout->win);
}
free(window->layout);
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)window;
free(chatwin->barejid);
free(chatwin->resource_override);
free(chatwin->state);
chat_state_free(chatwin->state);
}
if (window->type == WIN_MUC) {
@@ -359,7 +366,101 @@ win_free(ProfWin* window)
}
void
win_handle_page(ProfWin *window, const wint_t ch, const int result)
win_page_up(ProfWin *window)
{
int rows = getmaxy(stdscr);
int y = getcury(window->layout->win);
int page_space = rows - 4;
int *page_start = &(window->layout->y_pos);
*page_start -= page_space;
// went past beginning, show first page
if (*page_start < 0)
*page_start = 0;
window->layout->paged = 1;
win_update_virtual(window);
// switch off page if last line and space line visible
if ((y) - *page_start == page_space) {
window->layout->paged = 0;
}
}
void
win_page_down(ProfWin *window)
{
int rows = getmaxy(stdscr);
int y = getcury(window->layout->win);
int page_space = rows - 4;
int *page_start = &(window->layout->y_pos);
*page_start += page_space;
// only got half a screen, show full screen
if ((y - (*page_start)) < page_space)
*page_start = y - page_space;
// went past end, show full screen
else if (*page_start >= y)
*page_start = y - page_space - 1;
window->layout->paged = 1;
win_update_virtual(window);
// switch off page if last line and space line visible
if ((y) - *page_start == page_space) {
window->layout->paged = 0;
}
}
void
win_sub_page_down(ProfWin *window)
{
if (window->layout->type == LAYOUT_SPLIT) {
int rows = getmaxy(stdscr);
int page_space = rows - 4;
ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
int sub_y = getcury(split_layout->subwin);
int *sub_y_pos = &(split_layout->sub_y_pos);
*sub_y_pos += page_space;
// only got half a screen, show full screen
if ((sub_y- (*sub_y_pos)) < page_space)
*sub_y_pos = sub_y - page_space;
// went past end, show full screen
else if (*sub_y_pos >= sub_y)
*sub_y_pos = sub_y - page_space - 1;
win_update_virtual(window);
}
}
void
win_sub_page_up(ProfWin *window)
{
if (window->layout->type == LAYOUT_SPLIT) {
int rows = getmaxy(stdscr);
int page_space = rows - 4;
ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
int *sub_y_pos = &(split_layout->sub_y_pos);
*sub_y_pos -= page_space;
// went past beginning, show first page
if (*sub_y_pos < 0)
*sub_y_pos = 0;
win_update_virtual(window);
}
}
void
win_mouse(ProfWin *window, const wint_t ch, const int result)
{
int rows = getmaxy(stdscr);
int y = getcury(window->layout->win);
@@ -403,69 +504,6 @@ win_handle_page(ProfWin *window, const wint_t ch, const int result)
}
}
}
// page up
if (ch == KEY_PPAGE) {
*page_start -= page_space;
// went past beginning, show first page
if (*page_start < 0)
*page_start = 0;
window->layout->paged = 1;
win_update_virtual(window);
// page down
} else if (ch == KEY_NPAGE) {
*page_start += page_space;
// only got half a screen, show full screen
if ((y - (*page_start)) < page_space)
*page_start = y - page_space;
// went past end, show full screen
else if (*page_start >= y)
*page_start = y - page_space - 1;
window->layout->paged = 1;
win_update_virtual(window);
}
// switch off page if last line and space line visible
if ((y) - *page_start == page_space) {
window->layout->paged = 0;
}
if (window->layout->type == LAYOUT_SPLIT) {
ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
int sub_y = getcury(split_layout->subwin);
int *sub_y_pos = &(split_layout->sub_y_pos);
// alt up arrow
if ((result == KEY_CODE_YES) && ((ch == 565) || (ch == 337))) {
*sub_y_pos -= page_space;
// went past beginning, show first page
if (*sub_y_pos < 0)
*sub_y_pos = 0;
win_update_virtual(window);
// alt down arrow
} else if ((result == KEY_CODE_YES) && ((ch == 524) || (ch == 336))) {
*sub_y_pos += page_space;
// only got half a screen, show full screen
if ((sub_y- (*sub_y_pos)) < page_space)
*sub_y_pos = sub_y - page_space;
// went past end, show full screen
else if (*sub_y_pos >= sub_y)
*sub_y_pos = sub_y - page_space - 1;
win_update_virtual(window);
}
}
}
void
@@ -515,14 +553,14 @@ win_show_occupant(ProfWin *window, Occupant *occupant)
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
win_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick);
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
if (occupant->status) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status);
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status);
}
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
win_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
}
void
@@ -536,15 +574,15 @@ win_show_contact(ProfWin *window, PContact contact)
theme_item_t presence_colour = theme_main_presence_attrs(presence);
if (name != NULL) {
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", name);
if (name) {
win_print(window, '-', NULL, NO_EOL, presence_colour, "", name);
} else {
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
}
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence);
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence);
if (last_activity != NULL) {
if (last_activity) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
@@ -555,18 +593,18 @@ win_show_contact(ProfWin *window, PContact contact)
int seconds = span / G_TIME_SPAN_SECOND;
if (hours > 0) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds);
win_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);
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds);
}
}
if (status != NULL) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact));
if (status) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact));
}
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
win_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
}
void
@@ -578,21 +616,21 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
win_save_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick);
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
win_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick);
win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
if (occupant->status) {
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status);
win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status);
}
win_save_newline(window);
win_newline(window);
if (occupant->jid) {
win_save_vprint(window, '!', NULL, 0, 0, "", " Jid: %s", occupant->jid);
win_vprint(window, '!', NULL, 0, 0, "", " Jid: %s", occupant->jid);
}
win_save_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", occupant_affiliation);
win_save_vprint(window, '!', NULL, 0, 0, "", " Role: %s", occupant_role);
win_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", occupant_affiliation);
win_vprint(window, '!', NULL, 0, 0, "", " Role: %s", occupant_role);
Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick);
Capabilities *caps = caps_lookup(jidp->fulljid);
@@ -600,47 +638,47 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
if (caps) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_save_print(window, '!', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) {
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
if (caps->category || caps->type || caps->name) {
win_print(window, '!', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name) {
win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if (caps->category || caps->type) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->type != NULL) {
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) {
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " ");
if (caps->type) {
win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category) {
win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->category != NULL) {
win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
if (caps->category) {
win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
}
win_save_newline(window);
win_newline(window);
}
if (caps->software != NULL) {
win_save_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
if (caps->software) {
win_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
if (caps->software_version) {
win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
win_save_newline(window);
if (caps->software || caps->software_version) {
win_newline(window);
}
if (caps->os != NULL) {
win_save_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
if (caps->os) {
win_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
if (caps->os_version) {
win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
win_save_newline(window);
if (caps->os || caps->os_version) {
win_newline(window);
}
caps_destroy(caps);
}
win_save_print(window, '-', NULL, 0, 0, "", "");
win_print(window, '-', NULL, 0, 0, "", "");
}
void
@@ -650,24 +688,22 @@ win_show_info(ProfWin *window, PContact contact)
const char *name = p_contact_name(contact);
const char *presence = p_contact_presence(contact);
const char *sub = p_contact_subscription(contact);
GList *resources = p_contact_get_available_resources(contact);
GList *ordered_resources = NULL;
GDateTime *last_activity = p_contact_last_activity(contact);
theme_item_t presence_colour = theme_main_presence_attrs(presence);
win_save_print(window, '-', NULL, 0, 0, "", "");
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
if (name != NULL) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name);
win_print(window, '-', NULL, 0, 0, "", "");
win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
if (name) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name);
}
win_save_print(window, '-', NULL, NO_DATE, 0, "", ":");
win_print(window, '-', NULL, NO_DATE, 0, "", ":");
if (sub != NULL) {
win_save_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub);
if (sub) {
win_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub);
}
if (last_activity != NULL) {
if (last_activity) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
@@ -678,36 +714,41 @@ win_show_info(ProfWin *window, PContact contact)
int seconds = span / G_TIME_SPAN_SECOND;
if (hours > 0) {
win_save_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dh%dm%ds", hours, minutes, seconds);
win_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);
win_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dm%ds", minutes, seconds);
}
g_date_time_unref(now);
}
if (resources != NULL) {
win_save_print(window, '-', NULL, 0, 0, "", "Resources:");
GList *resources = p_contact_get_available_resources(contact);
GList *ordered_resources = NULL;
if (resources) {
win_print(window, '-', NULL, 0, 0, "", "Resources:");
// sort in order of availabiltiy
while (resources != NULL) {
Resource *resource = resources->data;
// sort in order of availability
GList *curr = resources;
while (curr) {
Resource *resource = curr->data;
ordered_resources = g_list_insert_sorted(ordered_resources,
resource, (GCompareFunc)resource_compare_availability);
resources = g_list_next(resources);
curr = g_list_next(curr);
}
}
g_list_free(resources);
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
GList *curr = ordered_resources;
while (curr) {
Resource *resource = curr->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
}
win_save_newline(window);
win_newline(window);
Jid *jidp = jid_create_from_bare_and_resource(barejid, resource->name);
Capabilities *caps = caps_lookup(jidp->fulljid);
@@ -715,48 +756,49 @@ win_show_info(ProfWin *window, PContact contact)
if (caps) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_save_print(window, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) {
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
if (caps->category || caps->type || caps->name) {
win_print(window, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name);
if (caps->category || caps->type) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->type != NULL) {
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category != NULL) {
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
if (caps->type) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type);
if (caps->category) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " ");
}
}
if (caps->category != NULL) {
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
if (caps->category) {
win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category);
}
win_save_newline(window);
win_newline(window);
}
if (caps->software != NULL) {
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
if (caps->software) {
win_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
if (caps->software_version) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
win_save_newline(window);
if (caps->software || caps->software_version) {
win_newline(window);
}
if (caps->os != NULL) {
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
if (caps->os) {
win_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
if (caps->os_version) {
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
win_save_newline(window);
if (caps->os || caps->os_version) {
win_newline(window);
}
caps_destroy(caps);
}
ordered_resources = g_list_next(ordered_resources);
curr = g_list_next(curr);
}
g_list_free(ordered_resources);
}
void
@@ -767,7 +809,7 @@ win_show_status_string(ProfWin *window, const char * const from,
{
theme_item_t presence_colour;
if (show != NULL) {
if (show) {
presence_colour = theme_main_presence_attrs(show);
} else if (strcmp(default_show, "online") == 0) {
presence_colour = THEME_ONLINE;
@@ -776,14 +818,14 @@ win_show_status_string(ProfWin *window, const char * const from,
}
win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from);
win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from);
if (show != NULL)
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show);
if (show)
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show);
else
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show);
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show);
if (last_activity != NULL) {
if (last_activity) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
g_date_time_unref(now);
@@ -795,17 +837,17 @@ win_show_status_string(ProfWin *window, const char * const from,
int seconds = span / G_TIME_SPAN_SECOND;
if (hours > 0) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds);
win_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);
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds);
}
}
if (status != NULL)
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status);
if (status)
win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status);
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
win_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
}
@@ -817,7 +859,7 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
{
case WIN_CHAT:
case WIN_PRIVATE:
win_save_print(window, '-', tv_stamp, NO_ME, THEME_TEXT_THEM, from, message);
win_print(window, '-', tv_stamp, NO_ME, THEME_TEXT_THEM, from, message);
break;
default:
assert(FALSE);
@@ -826,19 +868,19 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
}
void
win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp,
win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp,
int flags, theme_item_t theme_item, const char * const from, const char * const message, ...)
{
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, theme_item, from, fmt_msg->str);
win_print(window, show_char, tstamp, flags, theme_item, from, fmt_msg->str);
g_string_free(fmt_msg, TRUE);
}
void
win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp,
win_print(ProfWin *window, const char show_char, GTimeVal *tstamp,
int flags, theme_item_t theme_item, const char * const from, const char * const message)
{
GDateTime *time;
@@ -849,27 +891,58 @@ win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp,
time = g_date_time_new_from_timeval_utc(tstamp);
}
buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message);
_win_print(window, show_char, time, flags, theme_item, from, message);
buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, NULL);
_win_print(window, show_char, time, flags, theme_item, from, message, NULL);
// TODO: cross-reference.. this should be replaced by a real event-based system
ui_input_nonblocking(TRUE);
}
void
win_save_println(ProfWin *window, const char * const message)
win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp,
int flags, theme_item_t theme_item, const char * const from, const char * const message, char *id)
{
win_save_print(window, '-', NULL, 0, 0, "", message);
GDateTime *time;
if (tstamp == NULL) {
time = g_date_time_new_now_local();
} else {
time = g_date_time_new_from_timeval_utc(tstamp);
}
DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t));
receipt->id = strdup(id);
receipt->received = FALSE;
buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, receipt);
_win_print(window, show_char, time, flags, theme_item, from, message, receipt);
// TODO: cross-reference.. this should be replaced by a real event-based system
ui_input_nonblocking(TRUE);
}
void
win_save_newline(ProfWin *window)
win_mark_received(ProfWin *window, const char * const id)
{
win_save_print(window, '-', NULL, NO_DATE, 0, "", "");
gboolean received = buffer_mark_received(window->layout->buffer, id);
if (received) {
win_redraw(window);
}
}
void
win_println(ProfWin *window, const char * const message)
{
win_print(window, '-', NULL, 0, 0, "", message);
}
void
win_newline(ProfWin *window)
{
win_print(window, '-', NULL, NO_DATE, 0, "", "");
}
static void
_win_print(ProfWin *window, const char show_char, GDateTime *time,
int flags, theme_item_t theme_item, const char * const from, const char * const message)
int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt)
{
// flags : 1st bit = 0/1 - me/not me
// 2nd bit = 0/1 - date/no date
@@ -907,6 +980,10 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time,
colour = 0;
}
if (receipt && !receipt->received) {
colour = theme_attrs(THEME_RECEIPT_SENT);
}
wattron(window->layout->win, colour);
if (strncmp(message, "/me ", 4) == 0) {
wprintw(window->layout->win, "*%s ", from);
@@ -919,7 +996,11 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time,
}
if (!me_message) {
wattron(window->layout->win, theme_attrs(theme_item));
if (receipt && !receipt->received) {
wattron(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
} else {
wattron(window->layout->win, theme_attrs(theme_item));
}
}
if (prefs_get_boolean(PREF_WRAP)) {
@@ -935,7 +1016,11 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time,
if (me_message) {
wattroff(window->layout->win, colour);
} else {
wattroff(window->layout->win, theme_attrs(theme_item));
if (receipt && !receipt->received) {
wattroff(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));
} else {
wattroff(window->layout->win, theme_attrs(theme_item));
}
}
}
@@ -951,7 +1036,6 @@ _win_indent(WINDOW *win, int size)
static void
_win_print_wrapped(WINDOW *win, const char * const message)
{
int linei = 0;
int wordi = 0;
char *word = malloc(strlen(message) + 1);
@@ -964,18 +1048,26 @@ _win_print_wrapped(WINDOW *win, const char * const message)
}
free(time_pref);
while (message[linei] != '\0') {
if (message[linei] == ' ') {
gchar *curr_ch = g_utf8_offset_to_pointer(message, 0);
while (*curr_ch != '\0') {
if (*curr_ch == ' ') {
waddch(win, ' ');
linei++;
} else if (message[linei] == '\n') {
curr_ch = g_utf8_next_char(curr_ch);
} else if (*curr_ch == '\n') {
waddch(win, '\n');
_win_indent(win, indent);
linei++;
curr_ch = g_utf8_next_char(curr_ch);
} else {
// get word
wordi = 0;
while (message[linei] != ' ' && message[linei] != '\n' && message[linei] != '\0') {
word[wordi++] = message[linei++];
while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') {
size_t ch_len = mbrlen(curr_ch, 4, NULL);
int offset = 0;
while (offset < ch_len) {
word[wordi++] = curr_ch[offset++];
}
curr_ch = g_utf8_next_char(curr_ch);
}
word[wordi] = '\0';
@@ -983,17 +1075,27 @@ _win_print_wrapped(WINDOW *win, const char * const message)
int maxx = getmaxx(win);
// word larger than line
if (strlen(word) > (maxx - indent)) {
int i;
for (i = 0; i < wordi; i++) {
if (utf8_display_len(word) > (maxx - indent)) {
gchar *word_ch = g_utf8_offset_to_pointer(word, 0);
while(*word_ch != '\0') {
curx = getcurx(win);
if (curx < indent) {
_win_indent(win, indent);
}
waddch(win, word[i]);
gchar copy[wordi++];
g_utf8_strncpy(copy, word_ch, 1);
if (curx + utf8_display_len(copy) > maxx) {
waddch(win, '\n');
_win_indent(win, indent);
}
waddstr(win, copy);
word_ch = g_utf8_next_char(word_ch);
}
} else {
if (curx + strlen(word) > maxx) {
if (curx + utf8_display_len(word) > maxx) {
waddch(win, '\n');
_win_indent(win, indent);
}
@@ -1017,7 +1119,7 @@ win_redraw(ProfWin *window)
for (i = 0; i < size; i++) {
ProfBuffEntry *e = buffer_yield_entry(window->layout->buffer, i);
_win_print(window, e->show_char, e->time, e->flags, e->theme_item, e->from, e->message);
_win_print(window, e->show_char, e->time, e->flags, e->theme_item, e->from, e->message, e->receipt);
}
}

View File

@@ -1,7 +1,7 @@
/*
* window.h
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -99,6 +99,11 @@ typedef enum {
WIN_XML
} win_type_t;
typedef enum {
PROF_ENC_NONE,
PROF_ENC_OTR
} prof_enc_t;
typedef struct prof_win_t {
win_type_t type;
ProfLayout *layout;
@@ -113,7 +118,7 @@ typedef struct prof_chat_win_t {
char *barejid;
int unread;
ChatState *state;
gboolean is_otr;
prof_enc_t enc_mode;
gboolean is_trusted;
char *resource_override;
gboolean history_shown;
@@ -124,6 +129,7 @@ typedef struct prof_muc_win_t {
ProfWin window;
char *roomjid;
int unread;
gboolean showjid;
unsigned long memcheck;
} ProfMucWin;
@@ -168,19 +174,27 @@ 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_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant);
void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...);
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, 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_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...);
void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message);
void win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags,
theme_item_t theme_item, const char * const from, const char * const message, char *id);
void win_println(ProfWin *window, const char * const message);
void win_newline(ProfWin *window);
void win_redraw(ProfWin *window);
void win_hide_subwin(ProfWin *window);
void win_show_subwin(ProfWin *window);
int win_roster_cols(void);
int win_occpuants_cols(void);
void win_printline_nowrap(WINDOW *win, char *msg);
void win_handle_page(ProfWin *current, const wint_t ch, const int result);
void win_mouse(ProfWin *current, const wint_t ch, const int result);
void win_mark_received(ProfWin *window, const char * const id);
int win_unread(ProfWin *window);
gboolean win_has_active_subwin(ProfWin *window);
void win_page_up(ProfWin *window);
void win_page_down(ProfWin *window);
void win_sub_page_down(ProfWin *window);
void win_sub_page_up(ProfWin *window);
#endif

View File

@@ -1,7 +1,7 @@
/*
* windows.c
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
@@ -53,6 +53,7 @@
#include "ui/statusbar.h"
#include "ui/window.h"
#include "ui/windows.h"
#include "event/ui_events.h"
static GHashTable *windows;
static int current;
@@ -83,7 +84,7 @@ wins_get_chat(const char * const barejid)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)window;
@@ -105,7 +106,7 @@ wins_get_muc_conf(const char * const roomjid)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
if (window->type == WIN_MUC_CONFIG) {
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
@@ -127,11 +128,12 @@ wins_get_muc(const char * const roomjid)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = (ProfMucWin*)window;
if (g_strcmp0(mucwin->roomjid, roomjid) == 0) {
g_list_free(values);
return mucwin;
}
}
@@ -148,11 +150,12 @@ wins_get_private(const char * const fulljid)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
if (window->type == WIN_PRIVATE) {
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
if (g_strcmp0(privatewin->fulljid, fulljid) == 0) {
g_list_free(values);
return privatewin;
}
}
@@ -166,7 +169,7 @@ wins_get_private(const char * const fulljid)
ProfWin *
wins_get_current(void)
{
if (windows != NULL) {
if (windows) {
return g_hash_table_lookup(windows, GINT_TO_POINTER(current));
} else {
return NULL;
@@ -283,7 +286,7 @@ wins_get_next(void)
GList *curr = keys;
// find our place in the list
while (curr != NULL) {
while (curr) {
if (current == GPOINTER_TO_INT(curr->data)) {
break;
}
@@ -292,7 +295,7 @@ wins_get_next(void)
// if there is a next window return it
curr = g_list_next(curr);
if (curr != NULL) {
if (curr) {
int next = GPOINTER_TO_INT(curr->data);
g_list_free(keys);
return wins_get_by_num(next);
@@ -312,7 +315,7 @@ wins_get_previous(void)
GList *curr = keys;
// find our place in the list
while (curr != NULL) {
while (curr) {
if (current == GPOINTER_TO_INT(curr->data)) {
break;
}
@@ -321,7 +324,7 @@ wins_get_previous(void)
// if there is a previous window return it
curr = g_list_previous(curr);
if (curr != NULL) {
if (curr) {
int previous = GPOINTER_TO_INT(curr->data);
g_list_free(keys);
return wins_get_by_num(previous);
@@ -339,7 +342,7 @@ wins_get_num(ProfWin *window)
GList *keys = g_hash_table_get_keys(windows);
GList *curr = keys;
while (curr != NULL) {
while (curr) {
gconstpointer num_p = curr->data;
ProfWin *curr_win = g_hash_table_lookup(windows, num_p);
if (curr_win == window) {
@@ -408,9 +411,9 @@ wins_new_xmlconsole(void)
{
GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys);
g_list_free(keys);
ProfWin *newwin = win_create_xmlconsole();
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
g_list_free(keys);
return newwin;
}
@@ -419,9 +422,9 @@ wins_new_chat(const char * const barejid)
{
GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys);
g_list_free(keys);
ProfWin *newwin = win_create_chat(barejid);
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
g_list_free(keys);
return newwin;
}
@@ -430,9 +433,9 @@ wins_new_muc(const char * const roomjid)
{
GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys);
g_list_free(keys);
ProfWin *newwin = win_create_muc(roomjid);
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
g_list_free(keys);
return newwin;
}
@@ -441,9 +444,9 @@ wins_new_muc_config(const char * const roomjid, DataForm *form)
{
GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys);
g_list_free(keys);
ProfWin *newwin = win_create_muc_config(roomjid, form);
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
g_list_free(keys);
return newwin;
}
@@ -452,9 +455,9 @@ wins_new_private(const char * const fulljid)
{
GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys);
g_list_free(keys);
ProfWin *newwin = win_create_private(fulljid);
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
g_list_free(keys);
return newwin;
}
@@ -465,7 +468,7 @@ wins_get_total_unread(void)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
result += win_unread(window);
curr = g_list_next(curr);
@@ -481,7 +484,7 @@ wins_resize_all(void)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
int subwin_cols = 0;
@@ -495,7 +498,13 @@ wins_resize_all(void)
}
wresize(layout->base.win, PAD_SIZE, cols - subwin_cols);
wresize(layout->subwin, PAD_SIZE, subwin_cols);
rosterwin_roster();
if (window->type == WIN_CONSOLE) {
rosterwin_roster();
} else if (window->type == WIN_MUC) {
ProfMucWin *mucwin = (ProfMucWin *)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
occupantswin_occupants(mucwin->roomjid);
}
} else {
wresize(layout->base.win, PAD_SIZE, cols);
}
@@ -555,7 +564,7 @@ wins_get_xmlconsole(void)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
if (window->type == WIN_XML) {
ProfXMLWin *xmlwin = (ProfXMLWin*)window;
@@ -577,7 +586,7 @@ wins_get_chat_recipients(void)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)window;
@@ -596,7 +605,7 @@ wins_get_prune_wins(void)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
if (win_unread(window) == 0 &&
window->type != WIN_MUC &&
@@ -617,10 +626,10 @@ wins_lost_connection(void)
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
while (curr) {
ProfWin *window = curr->data;
if (window->type != WIN_CONSOLE) {
win_save_print(window, '-', NULL, 0, THEME_ERROR, "", "Lost connection.");
win_print(window, '-', NULL, 0, THEME_ERROR, "", "Lost connection.");
// if current win, set current_win_dirty
if (wins_is_current(window)) {
@@ -636,22 +645,24 @@ gboolean
wins_swap(int source_win, int target_win)
{
ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win));
ProfWin *console = wins_get_console();
if (source != NULL) {
if (source) {
ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win));
// target window empty
if (target == NULL) {
if (!target) {
g_hash_table_steal(windows, GINT_TO_POINTER(source_win));
status_bar_inactive(source_win);
g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source);
status_bar_inactive(source_win);
if (win_unread(source) > 0) {
status_bar_new(target_win);
} else {
status_bar_active(target_win);
}
if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) {
ui_switch_win(1);
if (wins_get_current_num() == source_win) {
wins_set_current_by_num(target_win);
ui_ev_focus_win(console);
}
return TRUE;
@@ -672,7 +683,7 @@ wins_swap(int source_win, int target_win)
status_bar_active(source_win);
}
if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) {
ui_switch_win(1);
ui_ev_focus_win(console);
}
return TRUE;
}
@@ -708,7 +719,7 @@ wins_tidy(void)
int num = 1;
GList *curr = keys;
while (curr != NULL) {
while (curr) {
ProfWin *window = g_hash_table_lookup(windows, curr->data);
if (num == 10) {
g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window);
@@ -731,7 +742,8 @@ wins_tidy(void)
windows = new_windows;
current = 1;
ui_switch_win(1);
ProfWin *console = wins_get_console();
ui_ev_focus_win(console);
g_list_free(keys);
return TRUE;
} else {
@@ -749,7 +761,7 @@ wins_create_summary(void)
keys = g_list_sort(keys, cmp_win_num);
GList *curr = keys;
while (curr != NULL) {
while (curr) {
ProfWin *window = g_hash_table_lookup(windows, curr->data);
int ui_index = GPOINTER_TO_INT(curr->data);

View File

@@ -1,7 +1,7 @@
/*
* windows.h
*
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*