Merge branch 'master' into otr

Conflicts:
	src/command/command.c
This commit is contained in:
James Booth
2013-12-15 17:19:01 +00:00
52 changed files with 5127 additions and 4102 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -25,15 +25,10 @@
#include <glib.h>
// Command help strings
typedef struct cmd_help_t {
const gchar *usage;
const gchar *short_help;
const gchar *long_help[50];
} CommandHelp;
GHashTable *commands;
void cmd_init(void);
void cmd_close(void);
void cmd_uninit(void);
void cmd_autocomplete(char *input, int *size);
void cmd_reset_autocomplete(void);

2409
src/command/commands.c Normal file

File diff suppressed because it is too large Load Diff

113
src/command/commands.h Normal file
View File

@@ -0,0 +1,113 @@
/*
* commands.h
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COMMANDS_H
#define COMMANDS_H
// Command help strings
typedef struct cmd_help_t {
const gchar *usage;
const gchar *short_help;
const gchar *long_help[50];
} CommandHelp;
/*
* Command structure
*
* cmd - The command string including leading '/'
* func - The function to execute for the command
* parser - The function used to parse arguments
* min_args - Minimum number of arguments
* max_args - Maximum number of arguments
* help - A help struct containing usage info etc
*/
typedef struct cmd_t {
gchar *cmd;
gboolean (*func)(gchar **args, struct cmd_help_t help);
gchar** (*parser)(const char * const inp, int min, int max);
int min_args;
int max_args;
void (*setting_func)(void);
CommandHelp help;
} Command;
gboolean cmd_about(gchar **args, struct cmd_help_t help);
gboolean cmd_account(gchar **args, struct cmd_help_t help);
gboolean cmd_autoaway(gchar **args, struct cmd_help_t help);
gboolean cmd_autoconnect(gchar **args, struct cmd_help_t help);
gboolean cmd_autoping(gchar **args, struct cmd_help_t help);
gboolean cmd_away(gchar **args, struct cmd_help_t help);
gboolean cmd_beep(gchar **args, struct cmd_help_t help);
gboolean cmd_caps(gchar **args, struct cmd_help_t help);
gboolean cmd_chat(gchar **args, struct cmd_help_t help);
gboolean cmd_chlog(gchar **args, struct cmd_help_t help);
gboolean cmd_clear(gchar **args, struct cmd_help_t help);
gboolean cmd_close(gchar **args, struct cmd_help_t help);
gboolean cmd_connect(gchar **args, struct cmd_help_t help);
gboolean cmd_decline(gchar **args, struct cmd_help_t help);
gboolean cmd_disco(gchar **args, struct cmd_help_t help);
gboolean cmd_disconnect(gchar **args, struct cmd_help_t help);
gboolean cmd_dnd(gchar **args, struct cmd_help_t help);
gboolean cmd_duck(gchar **args, struct cmd_help_t help);
gboolean cmd_flash(gchar **args, struct cmd_help_t help);
gboolean cmd_gone(gchar **args, struct cmd_help_t help);
gboolean cmd_grlog(gchar **args, struct cmd_help_t help);
gboolean cmd_group(gchar **args, struct cmd_help_t help);
gboolean cmd_help(gchar **args, struct cmd_help_t help);
gboolean cmd_history(gchar **args, struct cmd_help_t help);
gboolean cmd_info(gchar **args, struct cmd_help_t help);
gboolean cmd_intype(gchar **args, struct cmd_help_t help);
gboolean cmd_invite(gchar **args, struct cmd_help_t help);
gboolean cmd_invites(gchar **args, struct cmd_help_t help);
gboolean cmd_join(gchar **args, struct cmd_help_t help);
gboolean cmd_leave(gchar **args, struct cmd_help_t help);
gboolean cmd_log(gchar **args, struct cmd_help_t help);
gboolean cmd_mouse(gchar **args, struct cmd_help_t help);
gboolean cmd_msg(gchar **args, struct cmd_help_t help);
gboolean cmd_nick(gchar **args, struct cmd_help_t help);
gboolean cmd_notify(gchar **args, struct cmd_help_t help);
gboolean cmd_online(gchar **args, struct cmd_help_t help);
gboolean cmd_otr(gchar **args, struct cmd_help_t help);
gboolean cmd_outtype(gchar **args, struct cmd_help_t help);
gboolean cmd_prefs(gchar **args, struct cmd_help_t help);
gboolean cmd_priority(gchar **args, struct cmd_help_t help);
gboolean cmd_quit(gchar **args, struct cmd_help_t help);
gboolean cmd_reconnect(gchar **args, struct cmd_help_t help);
gboolean cmd_rooms(gchar **args, struct cmd_help_t help);
gboolean cmd_bookmark(gchar **args, struct cmd_help_t help);
gboolean cmd_roster(gchar **args, struct cmd_help_t help);
gboolean cmd_software(gchar **args, struct cmd_help_t help);
gboolean cmd_splash(gchar **args, struct cmd_help_t help);
gboolean cmd_states(gchar **args, struct cmd_help_t help);
gboolean cmd_status(gchar **args, struct cmd_help_t help);
gboolean cmd_statuses(gchar **args, struct cmd_help_t help);
gboolean cmd_sub(gchar **args, struct cmd_help_t help);
gboolean cmd_theme(gchar **args, struct cmd_help_t help);
gboolean cmd_tiny(gchar **args, struct cmd_help_t help);
gboolean cmd_titlebar(gchar **args, struct cmd_help_t help);
gboolean cmd_vercheck(gchar **args, struct cmd_help_t help);
gboolean cmd_who(gchar **args, struct cmd_help_t help);
gboolean cmd_win(gchar **args, struct cmd_help_t help);
gboolean cmd_wins(gchar **args, struct cmd_help_t help);
gboolean cmd_xa(gchar **args, struct cmd_help_t help);
#endif

View File

@@ -166,6 +166,31 @@ p_contact_name_or_jid(const PContact contact)
}
}
char *
p_contact_create_display_string(const PContact contact, const char * const resource)
{
GString *result_str = g_string_new("");
// use nickname if exists
if (contact->name != NULL) {
g_string_append(result_str, contact->name);
} else {
g_string_append(result_str, contact->barejid);
}
// add resource if not default provided by profanity
if (strcmp(resource, "__prof_default") != 0) {
g_string_append(result_str, " (");
g_string_append(result_str, resource);
g_string_append(result_str, ")");
}
char *result = result_str->str;
g_string_free(result_str, FALSE);
return result;
}
static Resource *
_highest_presence(Resource *first, Resource *second)
{

View File

@@ -55,5 +55,6 @@ void p_contact_set_groups(const PContact contact, GSList *groups);
GSList * p_contact_groups(const PContact contact);
gboolean p_contact_in_group(const PContact contact, const char * const group);
gboolean p_contact_subscribed(const PContact contact);
char * p_contact_create_display_string(const PContact contact, const char * const resource);
#endif

View File

@@ -41,11 +41,11 @@
#include "command/command.h"
#include "common.h"
#include "contact.h"
#include "roster_list.h"
#include "log.h"
#include "muc.h"
#include "otr.h"
#include "resource.h"
#include "ui/notifier.h"
#include "ui/ui.h"
#include "xmpp/xmpp.h"
@@ -414,7 +414,7 @@ prof_handle_contact_online(char *contact, Resource *resource,
{
gboolean updated = roster_update_presence(contact, resource, last_activity);
if (updated) {
if (updated && prefs_get_boolean(PREF_STATUSES)) {
PContact result = roster_get_contact(contact);
if (p_contact_subscription(result) != NULL) {
if (strcmp(p_contact_subscription(result), "none") != 0) {
@@ -431,7 +431,7 @@ prof_handle_contact_offline(char *contact, char *resource, char *status)
{
gboolean updated = roster_contact_offline(contact, resource, status);
if (resource != NULL && updated) {
if (resource != NULL && updated && prefs_get_boolean(PREF_STATUSES)) {
Jid *jid = jid_create_from_bare_and_resource(contact, resource);
PContact result = roster_get_contact(contact);
if (p_contact_subscription(result) != NULL) {
@@ -465,7 +465,31 @@ prof_handle_idle(void)
{
jabber_conn_status_t status = jabber_get_connection_status();
if (status == JABBER_CONNECTED) {
ui_idle();
GSList *recipients = ui_get_recipients();
GSList *curr = recipients;
while (curr != NULL) {
char *recipient = curr->data;
chat_session_no_activity(recipient);
if (chat_session_is_gone(recipient) &&
!chat_session_get_sent(recipient)) {
message_send_gone(recipient);
} else if (chat_session_is_inactive(recipient) &&
!chat_session_get_sent(recipient)) {
message_send_inactive(recipient);
} else if (prefs_get_boolean(PREF_OUTTYPE) &&
chat_session_is_paused(recipient) &&
!chat_session_get_sent(recipient)) {
message_send_paused(recipient);
}
curr = g_slist_next(curr);
}
if (recipients != NULL) {
g_slist_free(recipients);
}
}
}
@@ -666,7 +690,7 @@ _shutdown(void)
prefs_close();
theme_close();
accounts_close();
cmd_close();
cmd_uninit();
log_close();
}

475
src/roster_list.c Normal file
View File

@@ -0,0 +1,475 @@
/*
* roster_list.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <string.h>
#include <glib.h>
#include <assert.h>
#include "roster_list.h"
#include "resource.h"
#include "contact.h"
#include "jid.h"
#include "tools/autocomplete.h"
#include "xmpp/xmpp.h"
#include "profanity.h"
// nicknames
static Autocomplete name_ac;
// barejids
static Autocomplete barejid_ac;
// fulljids
static Autocomplete fulljid_ac;
// groups
static Autocomplete groups_ac;
// contacts, indexed on barejid
static GHashTable *contacts;
// nickname to jid map
static GHashTable *name_to_barejid;
static gboolean _key_equals(void *key1, void *key2);
static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2);
static void _replace_name(const char * const current_name,
const char * const new_name, const char * const barejid);
static void _add_name_and_barejid(const char * const name,
const char * const barejid);
static gint _compare_contacts(PContact a, PContact b);
void
roster_clear(void)
{
autocomplete_clear(name_ac);
autocomplete_clear(barejid_ac);
autocomplete_clear(fulljid_ac);
autocomplete_clear(groups_ac);
g_hash_table_destroy(contacts);
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
(GDestroyNotify)p_contact_free);
g_hash_table_destroy(name_to_barejid);
name_to_barejid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
g_free);
}
gboolean
roster_update_presence(const char * const barejid, Resource *resource,
GDateTime *last_activity)
{
assert(barejid != NULL);
assert(resource != NULL);
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) {
return FALSE;
}
if (!_datetimes_equal(p_contact_last_activity(contact), last_activity)) {
p_contact_set_last_activity(contact, last_activity);
}
p_contact_set_presence(contact, resource);
Jid *jid = jid_create_from_bare_and_resource(barejid, resource->name);
autocomplete_add(fulljid_ac, jid->fulljid);
jid_destroy(jid);
return TRUE;
}
PContact
roster_get_contact(const char * const barejid)
{
return g_hash_table_lookup(contacts, barejid);
}
gboolean
roster_contact_offline(const char * const barejid,
const char * const resource, const char * const status)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) {
return FALSE;
}
if (resource == NULL) {
return TRUE;
} else {
gboolean result = p_contact_remove_resource(contact, resource);
if (result == TRUE) {
Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
autocomplete_remove(fulljid_ac, jid->fulljid);
jid_destroy(jid);
}
return result;
}
}
void
roster_reset_search_attempts(void)
{
autocomplete_reset(name_ac);
autocomplete_reset(barejid_ac);
autocomplete_reset(fulljid_ac);
autocomplete_reset(groups_ac);
}
void
roster_init(void)
{
name_ac = autocomplete_new();
barejid_ac = autocomplete_new();
fulljid_ac = autocomplete_new();
groups_ac = autocomplete_new();
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
(GDestroyNotify)p_contact_free);
name_to_barejid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
g_free);
}
void
roster_free(void)
{
autocomplete_free(name_ac);
autocomplete_free(barejid_ac);
autocomplete_free(fulljid_ac);
autocomplete_free(groups_ac);
}
void
roster_change_name(const char * const barejid, const char * const new_name)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
const char * current_name = NULL;
if (p_contact_name(contact) != NULL) {
current_name = strdup(p_contact_name(contact));
}
if (contact != NULL) {
p_contact_set_name(contact, new_name);
_replace_name(current_name, new_name, barejid);
GSList *groups = p_contact_groups(contact);
roster_send_name_change(barejid, new_name, groups);
}
}
void
roster_remove(const char * const name, const char * const barejid)
{
autocomplete_remove(barejid_ac, barejid);
autocomplete_remove(name_ac, name);
g_hash_table_remove(name_to_barejid, name);
// remove each fulljid
PContact contact = roster_get_contact(barejid);
if (contact != NULL) {
GList *resources = p_contact_get_available_resources(contact);
while (resources != NULL) {
GString *fulljid = g_string_new(strdup(barejid));
g_string_append(fulljid, "/");
g_string_append(fulljid, resources->data);
autocomplete_remove(fulljid_ac, fulljid->str);
g_string_free(fulljid, TRUE);
resources = g_list_next(resources);
}
}
// remove the contact
g_hash_table_remove(contacts, barejid);
}
void
roster_update(const char * const barejid, const char * const name,
GSList *groups, const char * const subscription, gboolean pending_out)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) {
roster_add(barejid, name, groups, subscription, pending_out, FALSE);
} else {
p_contact_set_subscription(contact, subscription);
p_contact_set_pending_out(contact, pending_out);
const char * const new_name = name;
const char * current_name = NULL;
if (p_contact_name(contact) != NULL) {
current_name = strdup(p_contact_name(contact));
}
p_contact_set_name(contact, new_name);
p_contact_set_groups(contact, groups);
_replace_name(current_name, new_name, barejid);
// add groups
while (groups != NULL) {
autocomplete_add(groups_ac, groups->data);
groups = g_slist_next(groups);
}
}
}
gboolean
roster_add(const char * const barejid, const char * const name, GSList *groups,
const char * const subscription, gboolean pending_out, gboolean from_initial)
{
gboolean added = FALSE;
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) {
contact = p_contact_new(barejid, name, groups, subscription, NULL,
pending_out);
// add groups
while (groups != NULL) {
autocomplete_add(groups_ac, groups->data);
groups = g_slist_next(groups);
}
g_hash_table_insert(contacts, strdup(barejid), contact);
autocomplete_add(barejid_ac, barejid);
_add_name_and_barejid(name, barejid);
if (!from_initial) {
prof_handle_roster_add(barejid, name);
}
added = TRUE;
}
return added;
}
char *
roster_barejid_from_name(const char * const name)
{
return g_hash_table_lookup(name_to_barejid, name);
}
GSList *
roster_get_contacts(void)
{
GSList *result = NULL;
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, contacts);
while (g_hash_table_iter_next(&iter, &key, &value)) {
result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts);
}
// resturn all contact structs
return result;
}
gboolean
roster_has_pending_subscriptions(void)
{
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, contacts);
while (g_hash_table_iter_next(&iter, &key, &value)) {
PContact contact = (PContact) value;
if (p_contact_pending_out(contact)) {
return TRUE;
}
}
return FALSE;
}
char *
roster_find_contact(char *search_str)
{
return autocomplete_complete(name_ac, search_str);
}
char *
roster_find_resource(char *search_str)
{
return autocomplete_complete(fulljid_ac, search_str);
}
GSList *
roster_get_group(const char * const group)
{
GSList *result = NULL;
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, contacts);
while (g_hash_table_iter_next(&iter, &key, &value)) {
GSList *groups = p_contact_groups(value);
while (groups != NULL) {
if (strcmp(groups->data, group) == 0) {
result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts);
break;
}
groups = g_slist_next(groups);
}
}
// resturn all contact structs
return result;
}
void
roster_add_to_group(const char * const group, const char * const barejid)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact != NULL) {
if (p_contact_in_group(contact, group)) {
if (p_contact_name(contact) != NULL) {
prof_handle_already_in_group(p_contact_name(contact), group);
} else {
prof_handle_already_in_group(p_contact_barejid(contact), group);
}
return;
}
roster_send_add_to_group(group, contact);
}
}
void
roster_remove_from_group(const char * const group, const char * const barejid)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact != NULL) {
if (!p_contact_in_group(contact, group)) {
if (p_contact_name(contact) != NULL) {
prof_handle_not_in_group(p_contact_name(contact), group);
} else {
prof_handle_not_in_group(p_contact_barejid(contact), group);
}
return;
}
roster_send_remove_from_group(group, contact);
}
}
GSList *
roster_get_groups(void)
{
return autocomplete_get_list(groups_ac);
}
char *
roster_find_group(char *search_str)
{
return autocomplete_complete(groups_ac, search_str);
}
char *
roster_find_jid(char *search_str)
{
return autocomplete_complete(barejid_ac, search_str);
}
static
gboolean _key_equals(void *key1, void *key2)
{
gchar *str1 = (gchar *) key1;
gchar *str2 = (gchar *) key2;
return (g_strcmp0(str1, str2) == 0);
}
static gboolean
_datetimes_equal(GDateTime *dt1, GDateTime *dt2)
{
if ((dt1 == NULL) && (dt2 == NULL)) {
return TRUE;
} else if ((dt1 == NULL) && (dt2 != NULL)) {
return FALSE;
} else if ((dt1 != NULL) && (dt2 == NULL)) {
return FALSE;
} else {
return g_date_time_equal(dt1, dt2);
}
}
static void
_replace_name(const char * const current_name, const char * const new_name,
const char * const barejid)
{
// current handle exists already
if (current_name != NULL) {
autocomplete_remove(name_ac, current_name);
g_hash_table_remove(name_to_barejid, current_name);
_add_name_and_barejid(new_name, barejid);
// no current handle
} else if (new_name != NULL) {
autocomplete_remove(name_ac, barejid);
g_hash_table_remove(name_to_barejid, barejid);
_add_name_and_barejid(new_name, barejid);
}
}
static void
_add_name_and_barejid(const char * const name, const char * const barejid)
{
if (name != NULL) {
autocomplete_add(name_ac, name);
g_hash_table_insert(name_to_barejid, strdup(name), strdup(barejid));
} else {
autocomplete_add(name_ac, barejid);
g_hash_table_insert(name_to_barejid, strdup(barejid), strdup(barejid));
}
}
static
gint _compare_contacts(PContact a, PContact b)
{
const char * utf8_str_a = NULL;
const char * utf8_str_b = NULL;
if (p_contact_name(a) != NULL) {
utf8_str_a = p_contact_name(a);
} else {
utf8_str_a = p_contact_barejid(a);
}
if (p_contact_name(b) != NULL) {
utf8_str_b = p_contact_name(b);
} else {
utf8_str_b = p_contact_barejid(b);
}
gchar *key_a = g_utf8_collate_key(utf8_str_a, -1);
gchar *key_b = g_utf8_collate_key(utf8_str_b, -1);
gint result = g_strcmp0(key_a, key_b);
g_free(key_a);
g_free(key_b);
return result;
}

58
src/roster_list.h Normal file
View File

@@ -0,0 +1,58 @@
/*
* roster_list.h
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ROSTER_LIST_H
#define ROSTER_LIST_H
#include <glib.h>
#include "resource.h"
#include "contact.h"
void roster_clear(void);
gboolean roster_update_presence(const char * const barejid, Resource *resource,
GDateTime *last_activity);
PContact roster_get_contact(const char * const barejid);
gboolean roster_contact_offline(const char * const barejid,
const char * const resource, const char * const status);
void roster_reset_search_attempts(void);
void roster_init(void);
void roster_free(void);
void roster_change_name(const char * const barejid, const char * const new_name);
void roster_remove(const char * const name, const char * const barejid);
void roster_update(const char * const barejid, const char * const name,
GSList *groups, const char * const subscription, gboolean pending_out);
gboolean roster_add(const char * const barejid, const char * const name, GSList *groups,
const char * const subscription, gboolean pending_out, gboolean from_initial);
char * roster_barejid_from_name(const char * const name);
GSList * roster_get_contacts(void);
gboolean roster_has_pending_subscriptions(void);
char * roster_find_contact(char *search_str);
char * roster_find_resource(char *search_str);
GSList * roster_get_group(const char * const group);
GSList * roster_get_groups(void);
void roster_add_to_group(const char * const group, const char * const barejid);
void roster_remove_from_group(const char * const group, const char * const barejid);
char * roster_find_group(char *search_str);
char * roster_find_jid(char *search_str);
#endif

View File

@@ -31,9 +31,9 @@
#include "command/command.h"
#include "common.h"
#include "roster_list.h"
#include "config/preferences.h"
#include "config/theme.h"
#include "ui/notifier.h"
#include "ui/window.h"
#include "ui/windows.h"
#include "ui/ui.h"
@@ -51,7 +51,7 @@ void
cons_show_time(void)
{
ProfWin *console = wins_get_console();
console->print_time(console, '-');
win_print_time(console, '-');
wins_refresh_console();
}
@@ -72,7 +72,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);
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "%s\n", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@@ -93,7 +93,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);
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "%s\n", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@@ -108,7 +108,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);
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_ERROR);
wprintw(console->win, "%s\n", fmt_msg->str);
wattroff(console->win, COLOUR_ERROR);
@@ -131,10 +131,7 @@ cons_show_typing(const char * const barejid)
display_usr = barejid;
}
console->print_time(console, '-');
wattron(console->win, COLOUR_TYPING);
wprintw(console->win, "!! %s is typing a message...\n", display_usr);
wattroff(console->win, COLOUR_TYPING);
win_print_line(console, '-', COLOUR_TYPING, "!! %s is typing a message...", display_usr);
wins_refresh_console();
cons_alert();
@@ -149,7 +146,7 @@ cons_show_incoming_message(const char * const short_from, const int win_index)
if (ui_index == 10) {
ui_index = 0;
}
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_INCOMING);
wprintw(console->win, "<< incoming from %s (%d)\n", short_from, ui_index);
wattroff(console->win, COLOUR_INCOMING);
@@ -168,7 +165,7 @@ cons_about(void)
if (prefs_get_boolean(PREF_SPLASH)) {
_cons_splash_logo();
} else {
console->print_time(console, '-');
win_print_time(console, '-');
if (strcmp(PACKAGE_STATUS, "development") == 0) {
@@ -182,22 +179,22 @@ cons_about(void)
}
}
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT);
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "\n");
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "This is free software; you are free to change and redistribute it.\n");
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n");
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "\n");
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "Type '/help' to show complete help.\n");
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "\n");
if (prefs_get_boolean(PREF_VERCHECK)) {
@@ -221,12 +218,12 @@ cons_check_version(gboolean not_available_msg)
if (relase_valid) {
if (release_is_new(latest_release)) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "A new version of Profanity is available: %s", latest_release);
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "Check <http://www.profanity.im> for details.\n");
free(latest_release);
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "\n");
} else {
if (not_available_msg) {
@@ -245,15 +242,15 @@ void
cons_show_login_success(ProfAccount *account)
{
ProfWin *console = wins_get_console();
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "%s logged in successfully, ", account->jid);
resource_presence_t presence = accounts_get_login_presence(account->name);
const char *presence_str = string_from_resource_presence(presence);
console->presence_colour_on(console, presence_str);
win_presence_colour_on(console, presence_str);
wprintw(console->win, "%s", presence_str);
console->presence_colour_off(console, presence_str);
win_presence_colour_off(console, presence_str);
wprintw(console->win, " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
wprintw(console->win, ".\n");
@@ -271,7 +268,7 @@ cons_show_wins(void)
GSList *curr = window_strings;
while (curr != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, curr->data);
wprintw(console->win, "\n");
curr = g_slist_next(curr);
@@ -313,19 +310,19 @@ cons_show_info(PContact pcontact)
GDateTime *last_activity = p_contact_last_activity(pcontact);
WINDOW *win = console->win;
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "\n");
console->print_time(console, '-');
console->presence_colour_on(console, presence);
win_print_time(console, '-');
win_presence_colour_on(console, presence);
wprintw(win, "%s", barejid);
if (name != NULL) {
wprintw(win, " (%s)", name);
}
console->presence_colour_off(console, presence);
win_presence_colour_off(console, presence);
wprintw(win, ":\n");
if (sub != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "Subscription: %s\n", sub);
}
@@ -333,7 +330,7 @@ cons_show_info(PContact pcontact)
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "Last activity: ");
int hours = span / G_TIME_SPAN_HOUR;
@@ -355,7 +352,7 @@ cons_show_info(PContact pcontact)
}
if (resources != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "Resources:\n");
// sort in order of availabiltiy
@@ -370,21 +367,21 @@ cons_show_info(PContact pcontact)
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
console->print_time(console, '-');
console->presence_colour_on(console, resource_presence);
win_print_time(console, '-');
win_presence_colour_on(console, resource_presence);
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
wprintw(win, ", \"%s\"", resource->status);
}
wprintw(win, "\n");
console->presence_colour_off(console, resource_presence);
win_presence_colour_off(console, resource_presence);
if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str);
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, " Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
@@ -404,7 +401,7 @@ cons_show_info(PContact pcontact)
wprintw(win, "\n");
}
if (caps->software != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
@@ -414,7 +411,7 @@ cons_show_info(PContact pcontact)
wprintw(win, "\n");
}
if (caps->os != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
@@ -440,10 +437,10 @@ cons_show_caps(const char * const contact, Resource *resource)
WINDOW *win = console->win;
cons_show("");
const char *resource_presence = string_from_resource_presence(resource->presence);
console->print_time(console, '-');
console->presence_colour_on(console, resource_presence);
win_print_time(console, '-');
win_presence_colour_on(console, resource_presence);
wprintw(console->win, "%s", contact);
console->presence_colour_off(console, resource_presence);
win_presence_colour_off(console, resource_presence);
wprintw(win, ":\n");
if (resource->caps_str != NULL) {
@@ -451,7 +448,7 @@ cons_show_caps(const char * const contact, Resource *resource)
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
@@ -471,7 +468,7 @@ cons_show_caps(const char * const contact, Resource *resource)
wprintw(win, "\n");
}
if (caps->software != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "Software: %s", caps->software);
}
if (caps->software_version != NULL) {
@@ -481,7 +478,7 @@ cons_show_caps(const char * const contact, Resource *resource)
wprintw(win, "\n");
}
if (caps->os != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "OS: %s", caps->os);
}
if (caps->os_version != NULL) {
@@ -492,11 +489,11 @@ cons_show_caps(const char * const contact, Resource *resource)
}
if (caps->features != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "Features:\n");
GSList *feature = caps->features;
while (feature != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, " %s\n", feature->data);
feature = g_slist_next(feature);
}
@@ -515,10 +512,10 @@ cons_show_software_version(const char * const jid, const char * const presence,
ProfWin *console = wins_get_console();
if ((name != NULL) || (version != NULL) || (os != NULL)) {
cons_show("");
console->print_time(console, '-');
console->presence_colour_on(console, presence);
win_print_time(console, '-');
win_presence_colour_on(console, presence);
wprintw(console->win, "%s", jid);
console->presence_colour_off(console, presence);
win_presence_colour_off(console, presence);
wprintw(console->win, ":\n");
}
if (name != NULL) {
@@ -585,7 +582,7 @@ cons_show_room_list(GSList *rooms, const char * const conference_node)
cons_show("Chat rooms at %s:", conference_node);
while (rooms != NULL) {
DiscoItem *room = rooms->data;
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, " %s", room->jid);
if (room->name != NULL) {
wprintw(console->win, ", (%s)", room->name);
@@ -615,7 +612,7 @@ cons_show_bookmarks(const GList *list)
ProfWin *console = wins_get_console();
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, " %s", item->jid);
if (item->nick != NULL) {
wprintw(console->win, "/%s", item->nick);
@@ -683,7 +680,7 @@ cons_show_disco_items(GSList *items, const char * const jid)
cons_show("Service discovery items for %s:", jid);
while (items != NULL) {
DiscoItem *item = items->data;
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, " %s", item->jid);
if (item->name != NULL) {
wprintw(console->win, ", (%s)", item->name);
@@ -706,7 +703,7 @@ cons_show_status(const char * const barejid)
PContact pcontact = roster_get_contact(barejid);
if (pcontact != NULL) {
console->show_contact(console, pcontact);
win_show_contact(console, pcontact);
} else {
cons_show("No such contact \"%s\" in roster.", barejid);
}
@@ -763,10 +760,10 @@ cons_show_account_list(gchar **accounts)
if ((jabber_get_connection_status() == JABBER_CONNECTED) &&
(g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) {
resource_presence_t presence = accounts_get_last_presence(accounts[i]);
console->print_time(console, '-');
console->presence_colour_on(console, string_from_resource_presence(presence));
win_print_time(console, '-');
win_presence_colour_on(console, string_from_resource_presence(presence));
wprintw(console->win, "%s\n", accounts[i]);
console->presence_colour_off(console, string_from_resource_presence(presence));
win_presence_colour_off(console, string_from_resource_presence(presence));
} else {
cons_show(accounts[i]);
}
@@ -825,7 +822,7 @@ cons_show_account(ProfAccount *account)
WINDOW *win = console->win;
if (resources != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, "Resources:\n");
// sort in order of availabiltiy
@@ -840,21 +837,21 @@ cons_show_account(ProfAccount *account)
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
console->print_time(console, '-');
console->presence_colour_on(console, resource_presence);
win_print_time(console, '-');
win_presence_colour_on(console, resource_presence);
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
wprintw(win, ", \"%s\"", resource->status);
}
wprintw(win, "\n");
console->presence_colour_off(console, resource_presence);
win_presence_colour_off(console, resource_presence);
if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str);
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, " Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
@@ -874,7 +871,7 @@ cons_show_account(ProfAccount *account)
wprintw(win, "\n");
}
if (caps->software != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
@@ -884,7 +881,7 @@ cons_show_account(ProfAccount *account)
wprintw(win, "\n");
}
if (caps->os != NULL) {
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(win, " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
@@ -1357,7 +1354,7 @@ cons_show_contacts(GSList *list)
PContact contact = curr->data;
if ((strcmp(p_contact_subscription(contact), "to") == 0) ||
(strcmp(p_contact_subscription(contact), "both") == 0)) {
console->show_contact(console, contact);
win_show_contact(console, contact);
}
curr = g_slist_next(curr);
}
@@ -1378,47 +1375,47 @@ static void
_cons_splash_logo(void)
{
ProfWin *console = wins_get_console();
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "Welcome to\n");
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " ___ _ \n");
wattroff(console->win, COLOUR_SPLASH);
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " / __) (_)_ \n");
wattroff(console->win, COLOUR_SPLASH);
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n");
wattroff(console->win, COLOUR_SPLASH);
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n");
wattroff(console->win, COLOUR_SPLASH);
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n");
wattroff(console->win, COLOUR_SPLASH);
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n");
wattroff(console->win, COLOUR_SPLASH);
console->print_time(console, '-');
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "|_| (____/ \n");
wattroff(console->win, COLOUR_SPLASH);
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, "\n");
console->print_time(console, '-');
win_print_time(console, '-');
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
wprintw(console->win, "Version %sdev.%s.%s\n", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
@@ -1447,20 +1444,20 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
}
const char *presence = p_contact_presence(contact);
console->print_time(console, '-');
win_print_time(console, '-');
if (p_contact_subscribed(contact)) {
console->presence_colour_on(console, presence);
win_presence_colour_on(console, presence);
wprintw(console->win, "%s\n", title->str);
console->presence_colour_off(console, presence);
win_presence_colour_off(console, presence);
} else {
console->presence_colour_on(console, "offline");
win_presence_colour_on(console, "offline");
wprintw(console->win, "%s\n", title->str);
console->presence_colour_off(console, "offline");
win_presence_colour_off(console, "offline");
}
g_string_free(title, TRUE);
console->print_time(console, '-');
win_print_time(console, '-');
wprintw(console->win, " Subscription : ");
GString *sub = g_string_new("");
sub = g_string_append(sub, p_contact_subscription(contact));

View File

@@ -44,10 +44,10 @@
#include "config/preferences.h"
#include "config/theme.h"
#include "contact.h"
#include "roster_list.h"
#include "jid.h"
#include "log.h"
#include "muc.h"
#include "ui/notifier.h"
#include "ui/ui.h"
#include "ui/window.h"
#include "ui/windows.h"
@@ -63,11 +63,6 @@ static GTimer *ui_idle_time;
static void _win_show_user(WINDOW *win, const char * const user, const int colour);
static void _win_show_message(WINDOW *win, const char * const message);
static void _win_show_error_msg(WINDOW *win, const char * const message);
static void _show_status_string(ProfWin *window, const char * const from,
const char * const show, const char * const status,
GDateTime *last_activity, const char * const pre,
const char * const default_show);
static void _win_handle_switch(const wint_t * const ch);
static void _win_handle_page(const wint_t * const ch);
static void _win_show_history(WINDOW *win, int win_index,
@@ -215,33 +210,11 @@ ui_contact_typing(const char * const barejid)
}
}
void
ui_idle(void)
GSList *
ui_get_recipients(void)
{
GSList *recipients = wins_get_chat_recipients();
GSList *curr = recipients;
while (curr != NULL) {
char *recipient = curr->data;
chat_session_no_activity(recipient);
if (chat_session_is_gone(recipient) &&
!chat_session_get_sent(recipient)) {
message_send_gone(recipient);
} else if (chat_session_is_inactive(recipient) &&
!chat_session_get_sent(recipient)) {
message_send_inactive(recipient);
} else if (prefs_get_boolean(PREF_OUTTYPE) &&
chat_session_is_paused(recipient) &&
!chat_session_get_sent(recipient)) {
message_send_paused(recipient);
}
curr = g_slist_next(curr);
}
if (recipients != NULL) {
g_slist_free(recipients);
}
return recipients;
}
void
@@ -279,28 +252,7 @@ ui_incoming_msg(const char * const from, const char * const message,
// currently viewing chat window with sender
if (wins_is_current(window)) {
if (tv_stamp == NULL) {
window->print_time(window, '-');
} else {
GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s - ", date_fmt);
wattroff(window->win, COLOUR_TIME);
g_date_time_unref(time);
g_free(date_fmt);
}
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "*%s ", display_from);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_THEM);
} else {
_win_show_user(window->win, display_from, 1);
_win_show_message(window->win, message);
}
window->print_incoming_message(window, tv_stamp, display_from, message);
title_bar_set_typing(FALSE);
title_bar_draw();
status_bar_active(num);
@@ -318,35 +270,15 @@ ui_incoming_msg(const char * const from, const char * const message,
_win_show_history(window->win, num, from);
}
if (tv_stamp == NULL) {
window->print_time(window, '-');
} else {
// show users status first, when receiving message via delayed delivery
if (win_created) {
PContact pcontact = roster_get_contact(from);
if (pcontact != NULL) {
window->show_contact(window, pcontact);
}
// show users status first, when receiving message via delayed delivery
if ((tv_stamp != NULL) && (win_created)) {
PContact pcontact = roster_get_contact(from);
if (pcontact != NULL) {
win_show_contact(window, pcontact);
}
GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s - ", date_fmt);
wattroff(window->win, COLOUR_TIME);
g_date_time_unref(time);
g_free(date_fmt);
}
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "*%s ", display_from);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_THEM);
} else {
_win_show_user(window->win, display_from, 1);
_win_show_message(window->win, message);
}
window->print_incoming_message(window, tv_stamp, display_from, message);
}
int ui_index = num;
@@ -408,8 +340,8 @@ ui_handle_error_message(const char * const from, const char * const err_msg)
if (err_msg == NULL) {
cons_show_error("Unknown error received from service.");
} else {
ProfWin *win = wins_get_current();
gboolean handled = win->handle_error_message(win, from, err_msg);
ProfWin *current = wins_get_current();
gboolean handled = current->handle_error_message(current, from, err_msg);
if (handled != TRUE) {
cons_show_error("Error received from server: %s", err_msg);
}
@@ -422,36 +354,20 @@ void
ui_contact_online(const char * const barejid, const char * const resource,
const char * const show, const char * const status, GDateTime *last_activity)
{
Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
PContact contact = roster_get_contact(barejid);
GString *display_str = g_string_new("");
// use nickname if exists
if (p_contact_name(contact) != NULL) {
g_string_append(display_str, p_contact_name(contact));
} else {
g_string_append(display_str, barejid);
}
// add resource if not default provided by profanity
if (strcmp(jid->resourcepart, "__prof_default") != 0) {
g_string_append(display_str, " (");
g_string_append(display_str, jid->resourcepart);
g_string_append(display_str, ")");
}
char *display_str = p_contact_create_display_string(contact, resource);
ProfWin *console = wins_get_console();
_show_status_string(console, display_str->str, show, status, last_activity,
win_show_status_string(console, display_str, show, status, last_activity,
"++", "online");
ProfWin *window = wins_get_by_recipient(barejid);
if (window != NULL) {
_show_status_string(window, display_str->str, show, status,
win_show_status_string(window, display_str, show, status,
last_activity, "++", "online");
}
jid_destroy(jid);
g_string_free(display_str, TRUE);
free(display_str);
if (wins_is_current(console)) {
wins_refresh_current();
@@ -466,34 +382,20 @@ ui_contact_offline(const char * const from, const char * const show,
{
Jid *jidp = jid_create(from);
PContact contact = roster_get_contact(jidp->barejid);
GString *display_str = g_string_new("");
// use nickname if exists
if (p_contact_name(contact) != NULL) {
g_string_append(display_str, p_contact_name(contact));
} else {
g_string_append(display_str, jidp->barejid);
}
// add resource if not default provided by profanity
if (strcmp(jidp->resourcepart, "__prof_default") != 0) {
g_string_append(display_str, " (");
g_string_append(display_str, jidp->resourcepart);
g_string_append(display_str, ")");
}
char *display_str = p_contact_create_display_string(contact, jidp->resourcepart);
ProfWin *console = wins_get_console();
_show_status_string(console, display_str->str, show, status, NULL, "--",
win_show_status_string(console, display_str, show, status, NULL, "--",
"offline");
ProfWin *window = wins_get_by_recipient(jidp->barejid);
if (window != NULL) {
_show_status_string(window, display_str->str, show, status, NULL, "--",
win_show_status_string(window, display_str, show, status, NULL, "--",
"offline");
}
jid_destroy(jidp);
g_string_free(display_str, TRUE);
free(display_str);
if (wins_is_current(console)) {
wins_refresh_current();
@@ -824,39 +726,25 @@ ui_current_print_line(const char * const msg, ...)
ProfWin *current = wins_get_current();
va_list arg;
va_start(arg, msg);
current->print_line(current, msg, arg);
win_print_line(current, '-', 0, msg, arg);
va_end(arg);
current->refresh_win(current);
win_refresh(current);
}
void
ui_current_error_line(const char * const msg)
{
ProfWin *current = wins_get_current();
current->print_time(current, '-');
wattron(current->win, COLOUR_ERROR);
wprintw(current->win, "%s\n", msg);
wattroff(current->win, COLOUR_ERROR);
wins_refresh_current();
win_print_line(current, '-', COLOUR_ERROR, msg);
win_refresh(current);
}
void
ui_current_page_off(void)
{
ProfWin *current = wins_get_current();
current->paged = 0;
int rows = getmaxy(stdscr);
int y = getcury(current->win);
int size = rows - 3;
current->y_pos = y - (size - 1);
if (current->y_pos < 0) {
current->y_pos = 0;
}
wins_refresh_current();
win_page_off(current);
win_refresh(current);
}
void
@@ -867,8 +755,7 @@ ui_print_error_from_recipient(const char * const from, const char *err_msg)
ProfWin *window = wins_get_by_recipient(from);
if (window != NULL) {
window->print_time(window, '-');
_win_show_error_msg(window->win, err_msg);
win_print_line(window, '-', COLOUR_ERROR, "%s", err_msg);
if (wins_is_current(window)) {
wins_refresh_current();
}
@@ -901,7 +788,7 @@ ui_print_system_msg_from_recipient(const char * const from, const char *message)
}
}
window->print_time(window, '-');
win_print_time(window, '-');
wprintw(window->win, "*%s %s\n", bare_jid, message);
// this is the current window
@@ -926,12 +813,7 @@ ui_recipient_gone(const char * const barejid)
ProfWin *window = wins_get_by_recipient(barejid);
if (window != NULL) {
window->print_time(window, '!');
wattron(window->win, COLOUR_GONE);
wprintw(window->win, "<- %s ", display_usr);
wprintw(window->win, "has left the conversation.");
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_GONE);
win_print_line(window, '!', COLOUR_GONE, "<- %s has left the conversation.", display_usr);
if (wins_is_current(window)) {
wins_refresh_current();
}
@@ -967,7 +849,7 @@ ui_new_chat_win(const char * const to)
if (strcmp(p_contact_presence(contact), "offline") == 0) {
const char * const show = p_contact_presence(contact);
const char * const status = p_contact_status(contact);
_show_status_string(window, to, show, status, NULL, "--", "offline");
win_show_status_string(window, to, show, status, NULL, "--", "offline");
}
}
} else {
@@ -983,8 +865,7 @@ ui_create_duck_win(void)
ProfWin *window = wins_new("DuckDuckGo search", WIN_DUCK);
int num = wins_get_num(window);
ui_switch_win(num);
window->print_time(window, '-');
wprintw(window->win, "Type ':help' to find out more.\n");
win_print_line(window, '-', 0, "Type ':help' to find out more.");
}
void
@@ -1002,9 +883,9 @@ ui_duck(const char * const query)
{
ProfWin *window = wins_get_by_recipient("DuckDuckGo search");
if (window != NULL) {
window->print_time(window, '-');
win_print_time(window, '-');
wprintw(window->win, "\n");
window->print_time(window, '-');
win_print_time(window, '-');
wattron(window->win, COLOUR_ME);
wprintw(window->win, "Query : ");
wattroff(window->win, COLOUR_ME);
@@ -1019,7 +900,7 @@ ui_duck_result(const char * const result)
ProfWin *window = wins_get_by_recipient("DuckDuckGo search");
if (window != NULL) {
window->print_time(window, '-');
win_print_time(window, '-');
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "Result : ");
wattroff(window->win, COLOUR_THEM);
@@ -1030,7 +911,7 @@ ui_duck_result(const char * const result)
gunichar unichar = g_utf8_get_char(ptr);
if (unichar == '\n') {
wprintw(window->win, "\n");
window->print_time(window, '-');
win_print_time(window, '-');
} else {
gchar *string = g_ucs4_to_utf8(&unichar, 1, NULL, NULL, NULL);
if (string != NULL) {
@@ -1075,7 +956,7 @@ ui_outgoing_msg(const char * const from, const char * const to,
if (strcmp(p_contact_presence(contact), "offline") == 0) {
const char const *show = p_contact_presence(contact);
const char const *status = p_contact_status(contact);
_show_status_string(window, to, show, status, NULL, "--", "offline");
win_show_status_string(window, to, show, status, NULL, "--", "offline");
}
}
@@ -1084,7 +965,7 @@ ui_outgoing_msg(const char * const from, const char * const to,
num = wins_get_num(window);
}
window->print_time(window, '-');
win_print_time(window, '-');
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_ME);
wprintw(window->win, "*%s ", from);
@@ -1118,7 +999,7 @@ ui_room_roster(const char * const room, GList *roster, const char * const presen
{
ProfWin *window = wins_get_by_recipient(room);
window->print_time(window, '!');
win_print_time(window, '!');
if ((roster == NULL) || (g_list_length(roster) == 0)) {
wattron(window->win, COLOUR_ROOMINFO);
if (presence == NULL) {
@@ -1148,9 +1029,9 @@ ui_room_roster(const char * const room, GList *roster, const char * const presen
const char const *nick = p_contact_barejid(member);
const char const *show = p_contact_presence(member);
window->presence_colour_on(window, show);
win_presence_colour_on(window, show);
wprintw(window->win, "%s", nick);
window->presence_colour_off(window, show);
win_presence_colour_off(window, show);
if (roster->next != NULL) {
wprintw(window->win, ", ");
@@ -1173,7 +1054,7 @@ ui_room_member_offline(const char * const room, const char * const nick)
{
ProfWin *window = wins_get_by_recipient(room);
window->print_time(window, '!');
win_print_time(window, '!');
wattron(window->win, COLOUR_OFFLINE);
wprintw(window->win, "<- %s has left the room.\n", nick);
wattroff(window->win, COLOUR_OFFLINE);
@@ -1189,7 +1070,7 @@ ui_room_member_online(const char * const room, const char * const nick,
{
ProfWin *window = wins_get_by_recipient(room);
window->print_time(window, '!');
win_print_time(window, '!');
wattron(window->win, COLOUR_ONLINE);
wprintw(window->win, "-> %s has joined the room.\n", nick);
wattroff(window->win, COLOUR_ONLINE);
@@ -1206,7 +1087,7 @@ ui_room_member_presence(const char * const room, const char * const nick,
ProfWin *window = wins_get_by_recipient(room);
if (window != NULL) {
_show_status_string(window, nick, show, status, NULL, "++", "online");
win_show_status_string(window, nick, show, status, NULL, "++", "online");
}
if (wins_is_current(window)) {
@@ -1220,7 +1101,7 @@ ui_room_member_nick_change(const char * const room,
{
ProfWin *window = wins_get_by_recipient(room);
window->print_time(window, '!');
win_print_time(window, '!');
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "** %s is now known as %s\n", old_nick, nick);
wattroff(window->win, COLOUR_THEM);
@@ -1235,7 +1116,7 @@ ui_room_nick_change(const char * const room, const char * const nick)
{
ProfWin *window = wins_get_by_recipient(room);
window->print_time(window, '!');
win_print_time(window, '!');
wattron(window->win, COLOUR_ME);
wprintw(window->win, "** You are now known as %s\n", nick);
wattroff(window->win, COLOUR_ME);
@@ -1278,7 +1159,7 @@ ui_room_message(const char * const room_jid, const char * const nick,
ProfWin *window = wins_get_by_recipient(room_jid);
int num = wins_get_num(window);
window->print_time(window, '-');
win_print_time(window, '-');
if (strcmp(nick, muc_get_room_nick(room_jid)) != 0) {
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_THEM);
@@ -1349,7 +1230,7 @@ ui_room_subject(const char * const room_jid, const char * const subject)
ProfWin *window = wins_get_by_recipient(room_jid);
int num = wins_get_num(window);
window->print_time(window, '!');
win_print_time(window, '!');
wattron(window->win, COLOUR_ROOMINFO);
wprintw(window->win, "Room subject: ");
wattroff(window->win, COLOUR_ROOMINFO);
@@ -1372,7 +1253,7 @@ ui_room_broadcast(const char * const room_jid, const char * const message)
ProfWin *window = wins_get_by_recipient(room_jid);
int num = wins_get_num(window);
window->print_time(window, '!');
win_print_time(window, '!');
wattron(window->win, COLOUR_ROOMINFO);
wprintw(window->win, "Room message: ");
wattroff(window->win, COLOUR_ROOMINFO);
@@ -1397,9 +1278,9 @@ ui_status(void)
ProfWin *current = wins_get_current();
if (pcontact != NULL) {
current->show_contact(current, pcontact);
win_show_contact(current, pcontact);
} else {
ui_current_print_line("Error getting contact info.");
win_print_line(current, '-', 0, "Error getting contact info.");
}
}
@@ -1411,9 +1292,9 @@ ui_status_private(void)
ProfWin *current = wins_get_current();
if (pcontact != NULL) {
current->show_contact(current, pcontact);
win_show_contact(current, pcontact);
} else {
ui_current_print_line("Error getting contact info.");
win_print_line(current, '-', 0, "Error getting contact info.");
}
jid_destroy(jid);
@@ -1426,9 +1307,9 @@ ui_status_room(const char * const contact)
ProfWin *current = wins_get_current();
if (pcontact != NULL) {
current->show_contact(current, pcontact);
win_show_contact(current, pcontact);
} else {
ui_current_print_line("No such participant \"%s\" in room.", contact);
win_print_line(current, '-', 0, "No such participant \"%s\" in room.", contact);
}
}
@@ -1478,12 +1359,17 @@ _ui_draw_win_title(void)
gint unread = ui_unread();
if (unread != 0) {
snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s (%d) - %s%c", '\033', "Profanity", version_str->str, unread, jid, '\007');
snprintf(new_win_title, sizeof(new_win_title),
"%c]0;%s%s (%d) - %s%c", '\033', "Profanity", version_str->str,
unread, jid, '\007');
} else {
snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s - %s%c", '\033', "Profanity", version_str->str, jid, '\007');
snprintf(new_win_title, sizeof(new_win_title),
"%c]0;%s%s - %s%c", '\033', "Profanity", version_str->str, jid,
'\007');
}
} else {
snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s%c", '\033', "Profanity", version_str->str, '\007');
snprintf(new_win_title, sizeof(new_win_title), "%c]0;%s%s%c", '\033',
"Profanity", version_str->str, '\007');
}
g_string_free(version_str, TRUE);
@@ -1519,100 +1405,6 @@ _win_show_message(WINDOW *win, const char * const message)
wprintw(win, "\n");
}
static void
_win_show_error_msg(WINDOW *win, const char * const message)
{
wattron(win, COLOUR_ERROR);
wprintw(win, "%s\n", message);
wattroff(win, COLOUR_ERROR);
}
static void
_show_status_string(ProfWin *window, const char * const from,
const char * const show, const char * const status,
GDateTime *last_activity, const char * const pre,
const char * const default_show)
{
WINDOW *win = window->win;
if (!prefs_get_boolean(PREF_STATUSES))
return;
window->print_time(window, '-');
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattron(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
wattron(win, COLOUR_CHAT);
} else if (strcmp(show, "dnd") == 0) {
wattron(win, COLOUR_DND);
} else if (strcmp(show, "xa") == 0) {
wattron(win, COLOUR_XA);
} else if (strcmp(show, "online") == 0) {
wattron(win, COLOUR_ONLINE);
} else {
wattron(win, COLOUR_OFFLINE);
}
} else if (strcmp(default_show, "online") == 0) {
wattron(win, COLOUR_ONLINE);
} else {
wattron(win, COLOUR_OFFLINE);
}
wprintw(win, "%s %s", pre, from);
if (show != NULL)
wprintw(win, " is %s", show);
else
wprintw(win, " is %s", default_show);
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
wprintw(win, ", idle ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(win, "%ds", seconds);
}
if (status != NULL)
wprintw(win, ", \"%s\"", status);
wprintw(win, "\n");
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattroff(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
wattroff(win, COLOUR_CHAT);
} else if (strcmp(show, "dnd") == 0) {
wattroff(win, COLOUR_DND);
} else if (strcmp(show, "xa") == 0) {
wattroff(win, COLOUR_XA);
} else if (strcmp(show, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else {
wattroff(win, COLOUR_OFFLINE);
}
} else if (strcmp(default_show, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else {
wattroff(win, COLOUR_OFFLINE);
}
}
static void
_win_handle_switch(const wint_t * const ch)
{

View File

@@ -40,6 +40,7 @@
#include "config/theme.h"
#include "log.h"
#include "profanity.h"
#include "roster_list.h"
#include "ui/ui.h"
#include "ui/windows.h"
#include "xmpp/xmpp.h"

View File

@@ -1,5 +1,5 @@
/*
* notifier.h
* muc_window.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
@@ -20,14 +20,20 @@
*
*/
void notifier_init(void);
void notifier_uninit(void);
#include <glib.h>
void notify_typing(const char * const handle);
void notify_message(const char * const handle, int win);
void notify_room_message(const char * const handle, const char * const room,
int win);
void notify_remind(void);
void notify_invite(const char * const from, const char * const room,
const char * const reason);
void notify_subscription(const char * const from);
#include "ui/window.h"
gboolean
muc_handle_error_message(ProfWin *self, const char * const from,
const char * const err_msg)
{
gboolean handled = FALSE;
if (g_strcmp0(err_msg, "conflict") == 0) {
win_print_line(self, '-', 0, "Nickname already in use.");
win_refresh(self);
handled = TRUE;
}
return handled;
}

33
src/ui/muc_window.h Normal file
View File

@@ -0,0 +1,33 @@
/*
* muc_window.h
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef UI_MUC_WINDOW_H
#define UI_MUC_WINDOW_H
#include <glib.h>
#include "ui/window.h"
gboolean muc_handle_error_message(ProfWin *self, const char * const from,
const char * const err_msg);
#endif

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef UI_H
#define UI_H
#ifndef UI_UI_H
#define UI_UI_H
#include "config.h"
@@ -48,7 +48,7 @@ void ui_refresh(void);
void ui_close(void);
void ui_resize(const int ch, const char * const input,
const int size);
void ui_idle(void);
GSList* ui_get_recipients(void);
void ui_handle_special_keys(const wint_t * const ch, const char * const inp,
const int size);
void ui_switch_win(const int i);
@@ -242,4 +242,17 @@ void inp_block(void);
void inp_get_password(char *passwd);
void inp_replace_input(char *input, const char * const new_input, int *size);
// desktop notifier actions
void notifier_init(void);
void notifier_uninit(void);
void notify_typing(const char * const handle);
void notify_message(const char * const handle, int win);
void notify_room_message(const char * const handle, const char * const room,
int win);
void notify_remind(void);
void notify_invite(const char * const from, const char * const room,
const char * const reason);
void notify_subscription(const char * const from);
#endif

View File

@@ -34,17 +34,12 @@
#include "config/theme.h"
#include "ui/window.h"
#include "ui/muc_window.h"
static gboolean _muc_handle_error_message(ProfWin *self, const char * const from,
const char * const err_msg);
static gboolean _default_handle_error_message(ProfWin *self, const char * const from,
const char * const err_msg);
static void _win_print_time(ProfWin *self, char show_char);
static void _win_print_line(ProfWin *self, const char * const msg, ...);
static void _win_refresh(ProfWin *self);
static void _win_presence_colour_on(ProfWin *self, const char * const presence);
static void _win_presence_colour_off(ProfWin *self, const char * const presence);
static void _win_show_contact(ProfWin *self, PContact contact);
static void _print_incoming_message(ProfWin *self, GTimeVal *tv_stamp,
const char * const from, const char * const message);
ProfWin*
win_create(const char * const title, int cols, win_type_t type)
@@ -59,20 +54,31 @@ win_create(const char * const title, int cols, win_type_t type)
new_win->history_shown = 0;
new_win->type = type;
new_win->print_time = _win_print_time;
new_win->print_line = _win_print_line;
new_win->refresh_win = _win_refresh;
new_win->presence_colour_on = _win_presence_colour_on;
new_win->presence_colour_off = _win_presence_colour_off;
new_win->show_contact = _win_show_contact;
switch (new_win->type)
{
case WIN_CONSOLE:
new_win->handle_error_message = _default_handle_error_message;
new_win->print_incoming_message = NULL;
break;
case WIN_CHAT:
new_win->handle_error_message = _default_handle_error_message;
new_win->print_incoming_message = _print_incoming_message;
break;
case WIN_MUC:
new_win->handle_error_message = _muc_handle_error_message;
new_win->handle_error_message = muc_handle_error_message;
new_win->print_incoming_message = NULL;
break;
case WIN_PRIVATE:
new_win->handle_error_message = _default_handle_error_message;
new_win->print_incoming_message = _print_incoming_message;
break;
case WIN_DUCK:
new_win->handle_error_message = _default_handle_error_message;
new_win->print_incoming_message = NULL;
break;
default:
new_win->handle_error_message = _default_handle_error_message;
new_win->print_incoming_message = NULL;
break;
}
@@ -90,77 +96,95 @@ win_free(ProfWin* window)
window = NULL;
}
static void
_win_print_time(ProfWin* self, char show_char)
void
win_print_time(ProfWin* window, char show_char)
{
GDateTime *time = g_date_time_new_now_local();
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wattron(self->win, COLOUR_TIME);
wprintw(self->win, "%s %c ", date_fmt, show_char);
wattroff(self->win, COLOUR_TIME);
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s %c ", date_fmt, show_char);
wattroff(window->win, COLOUR_TIME);
g_date_time_unref(time);
g_free(date_fmt);
}
static void
_win_print_line(ProfWin *self, const char * const msg, ...)
void
win_print_line(ProfWin *window, const char show_char, int attrs,
const char * const msg, ...)
{
va_list arg;
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
_win_print_time(self, '-');
wprintw(self->win, "%s\n", fmt_msg->str);
win_print_time(window, show_char);
wattron(window->win, attrs);
wprintw(window->win, "%s\n", fmt_msg->str);
wattroff(window->win, attrs);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
static void
_win_refresh(ProfWin *self)
void
win_refresh(ProfWin *window)
{
int rows, cols;
getmaxyx(stdscr, rows, cols);
prefresh(self->win, self->y_pos, 0, 1, 0, rows-3, cols-1);
prefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1);
}
static void
_win_presence_colour_on(ProfWin *self, const char * const presence)
void
win_page_off(ProfWin *window)
{
if (g_strcmp0(presence, "online") == 0) {
wattron(self->win, COLOUR_ONLINE);
} else if (g_strcmp0(presence, "away") == 0) {
wattron(self->win, COLOUR_AWAY);
} else if (g_strcmp0(presence, "chat") == 0) {
wattron(self->win, COLOUR_CHAT);
} else if (g_strcmp0(presence, "dnd") == 0) {
wattron(self->win, COLOUR_DND);
} else if (g_strcmp0(presence, "xa") == 0) {
wattron(self->win, COLOUR_XA);
} else {
wattron(self->win, COLOUR_OFFLINE);
window->paged = 0;
int rows = getmaxy(stdscr);
int y = getcury(window->win);
int size = rows - 3;
window->y_pos = y - (size - 1);
if (window->y_pos < 0) {
window->y_pos = 0;
}
}
static void
_win_presence_colour_off(ProfWin *self, const char * const presence)
void
win_presence_colour_on(ProfWin *window, const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
wattroff(self->win, COLOUR_ONLINE);
wattron(window->win, COLOUR_ONLINE);
} else if (g_strcmp0(presence, "away") == 0) {
wattroff(self->win, COLOUR_AWAY);
wattron(window->win, COLOUR_AWAY);
} else if (g_strcmp0(presence, "chat") == 0) {
wattroff(self->win, COLOUR_CHAT);
wattron(window->win, COLOUR_CHAT);
} else if (g_strcmp0(presence, "dnd") == 0) {
wattroff(self->win, COLOUR_DND);
wattron(window->win, COLOUR_DND);
} else if (g_strcmp0(presence, "xa") == 0) {
wattroff(self->win, COLOUR_XA);
wattron(window->win, COLOUR_XA);
} else {
wattroff(self->win, COLOUR_OFFLINE);
wattron(window->win, COLOUR_OFFLINE);
}
}
static void
_win_show_contact(ProfWin *self, PContact contact)
void
win_presence_colour_off(ProfWin *window, const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
wattroff(window->win, COLOUR_ONLINE);
} else if (g_strcmp0(presence, "away") == 0) {
wattroff(window->win, COLOUR_AWAY);
} else if (g_strcmp0(presence, "chat") == 0) {
wattroff(window->win, COLOUR_CHAT);
} else if (g_strcmp0(presence, "dnd") == 0) {
wattroff(window->win, COLOUR_DND);
} else if (g_strcmp0(presence, "xa") == 0) {
wattroff(window->win, COLOUR_XA);
} else {
wattroff(window->win, COLOUR_OFFLINE);
}
}
void
win_show_contact(ProfWin *window, PContact contact)
{
const char *barejid = p_contact_barejid(contact);
const char *name = p_contact_name(contact);
@@ -168,57 +192,126 @@ _win_show_contact(ProfWin *self, PContact contact)
const char *status = p_contact_status(contact);
GDateTime *last_activity = p_contact_last_activity(contact);
_win_print_time(self, '-');
_win_presence_colour_on(self, presence);
win_print_time(window, '-');
win_presence_colour_on(window, presence);
if (name != NULL) {
wprintw(self->win, "%s", name);
wprintw(window->win, "%s", name);
} else {
wprintw(self->win, "%s", barejid);
wprintw(window->win, "%s", barejid);
}
wprintw(self->win, " is %s", presence);
wprintw(window->win, " is %s", presence);
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
wprintw(self->win, ", idle ");
wprintw(window->win, ", idle ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(self->win, "%dh", hours);
wprintw(window->win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(self->win, "%dm", minutes);
wprintw(window->win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(self->win, "%ds", seconds);
wprintw(window->win, "%ds", seconds);
}
if (status != NULL) {
wprintw(self->win, ", \"%s\"", p_contact_status(contact));
wprintw(window->win, ", \"%s\"", p_contact_status(contact));
}
wprintw(self->win, "\n");
_win_presence_colour_off(self, presence);
wprintw(window->win, "\n");
win_presence_colour_off(window, presence);
}
static gboolean
_muc_handle_error_message(ProfWin *self, const char * const from,
const char * const err_msg)
void
win_show_status_string(ProfWin *window, const char * const from,
const char * const show, const char * const status,
GDateTime *last_activity, const char * const pre,
const char * const default_show)
{
gboolean handled = FALSE;
if (g_strcmp0(err_msg, "conflict") == 0) {
_win_print_line(self, "Nickname already in use.");
_win_refresh(self);
handled = TRUE;
WINDOW *win = window->win;
win_print_time(window, '-');
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattron(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
wattron(win, COLOUR_CHAT);
} else if (strcmp(show, "dnd") == 0) {
wattron(win, COLOUR_DND);
} else if (strcmp(show, "xa") == 0) {
wattron(win, COLOUR_XA);
} else if (strcmp(show, "online") == 0) {
wattron(win, COLOUR_ONLINE);
} else {
wattron(win, COLOUR_OFFLINE);
}
} else if (strcmp(default_show, "online") == 0) {
wattron(win, COLOUR_ONLINE);
} else {
wattron(win, COLOUR_OFFLINE);
}
return handled;
wprintw(win, "%s %s", pre, from);
if (show != NULL)
wprintw(win, " is %s", show);
else
wprintw(win, " is %s", default_show);
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
wprintw(win, ", idle ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(win, "%ds", seconds);
}
if (status != NULL)
wprintw(win, ", \"%s\"", status);
wprintw(win, "\n");
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattroff(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
wattroff(win, COLOUR_CHAT);
} else if (strcmp(show, "dnd") == 0) {
wattroff(win, COLOUR_DND);
} else if (strcmp(show, "xa") == 0) {
wattroff(win, COLOUR_XA);
} else if (strcmp(show, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else {
wattroff(win, COLOUR_OFFLINE);
}
} else if (strcmp(default_show, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else {
wattroff(win, COLOUR_OFFLINE);
}
}
static gboolean
@@ -227,3 +320,34 @@ _default_handle_error_message(ProfWin *self, const char * const from,
{
return FALSE;
}
static void
_print_incoming_message(ProfWin *self, GTimeVal *tv_stamp,
const char * const from, const char * const message)
{
if (tv_stamp == NULL) {
win_print_time(self, '-');
} else {
GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wattron(self->win, COLOUR_TIME);
wprintw(self->win, "%s - ", date_fmt);
wattroff(self->win, COLOUR_TIME);
g_date_time_unref(time);
g_free(date_fmt);
}
if (strncmp(message, "/me ", 4) == 0) {
wattron(self->win, COLOUR_THEM);
wprintw(self->win, "*%s ", from);
waddstr(self->win, message + 4);
wprintw(self->win, "\n");
wattroff(self->win, COLOUR_THEM);
} else {
wattron(self->win, COLOUR_THEM);
wprintw(self->win, "%s: ", from);
wattroff(self->win, COLOUR_THEM);
waddstr(self->win, message);
wprintw(self->win, "\n");
}
}

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef WINDOW_H
#define WINDOW_H
#ifndef UI_WINDOW_H
#define UI_WINDOW_H
#include "config.h"
@@ -52,17 +52,25 @@ typedef struct prof_win_t {
int paged;
int unread;
int history_shown;
void (*print_time)(struct prof_win_t *self, char show_char);
void (*print_line)(struct prof_win_t *self, const char * const msg, ...);
void (*refresh_win)(struct prof_win_t *self);
void (*presence_colour_on)(struct prof_win_t *self, const char * const presence);
void (*presence_colour_off)(struct prof_win_t *self, const char * const presence);
void (*show_contact)(struct prof_win_t *self, PContact contact);
gboolean (*handle_error_message)(struct prof_win_t *self,
const char * const from, const char * const err_msg);
void (*print_incoming_message)(struct prof_win_t *self, GTimeVal *tv_stamp,
const char * const from, const char * const message);
} ProfWin;
ProfWin* win_create(const char * const title, int cols, win_type_t type);
void win_free(ProfWin *window);
void win_print_line(ProfWin *self, const char show_char, int attrs,
const char * const msg, ...);
void win_refresh(ProfWin *window);
void win_page_off(ProfWin *window);
void win_print_time(ProfWin *window, char show_char);
void win_presence_colour_on(ProfWin *window, const char * const presence);
void win_presence_colour_off(ProfWin *window, const char * const presence);
void win_show_contact(ProfWin *window, PContact contact);
void win_show_status_string(ProfWin *window, const char * const from,
const char * const show, const char * const status,
GDateTime *last_activity, const char * const pre,
const char * const default_show);
#endif

View File

@@ -33,6 +33,7 @@
#endif
#include "common.h"
#include "roster_list.h"
#include "config/theme.h"
#include "ui/ui.h"
#include "ui/window.h"
@@ -207,9 +208,7 @@ void
wins_refresh_current(void)
{
ProfWin *window = wins_get_current();
int rows, cols;
getmaxyx(stdscr, rows, cols);
prefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1);
win_refresh(window);
}
void
@@ -350,7 +349,7 @@ wins_lost_connection(void)
while (curr != NULL) {
ProfWin *window = curr->data;
if (window->type != WIN_CONSOLE) {
window->print_time(window, '-');
win_print_time(window, '-');
wattron(window->win, COLOUR_ERROR);
wprintw(window->win, "%s\n", "Lost connection.");
wattroff(window->win, COLOUR_ERROR);

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef WINDOWS_H
#define WINDOWS_H
#ifndef UI_WINDOWS_H
#define UI_WINDOWS_H
void wins_init(void);
ProfWin * wins_get_console(void);

View File

@@ -1,6 +1,6 @@
#ifndef BOOKMARK_H
#define BOOKMARK_H
#ifndef XMPP_BOOKMARK_H
#define XMPP_BOOKMARK_H
#include <glib.h>
@@ -13,10 +13,5 @@ struct bookmark_t {
typedef struct bookmark_t Bookmark;
void bookmark_request(void);
void bookmark_add(const char *jid, const char *nick, gboolean autojoin);
void bookmark_remove(const char *jid, gboolean autojoin);
const GList *bookmark_get_list(void);
char *bookmark_find(char *search_str);
void bookmark_autocomplete_reset(void);
#endif

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef CAPABILITIES_H
#define CAPABILITIES_H
#ifndef XMPP_CAPABILITIES_H
#define XMPP_CAPABILITIES_H
#include <strophe.h>

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef CONNECTION_H
#define CONNECTION_H
#ifndef XMPP_CONNECTION_H
#define XMPP_CONNECTION_H
#include <strophe.h>

View File

@@ -38,6 +38,7 @@
#include "xmpp/capabilities.h"
#include "xmpp/connection.h"
#include "xmpp/stanza.h"
#include "roster_list.h"
#include "xmpp/xmpp.h"
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_IQ, type, ctx)

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef IQ_H
#define IQ_H
#ifndef XMPP_IQ_H
#define XMPP_IQ_H
void iq_add_handlers(void);
void iq_roster_request(void);

View File

@@ -33,6 +33,7 @@
#include "xmpp/connection.h"
#include "xmpp/message.h"
#include "xmpp/roster.h"
#include "roster_list.h"
#include "xmpp/stanza.h"
#include "xmpp/xmpp.h"

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef MESSAGE_H
#define MESSAGE_H
#ifndef XMPP_MESSAGE_H
#define XMPP_MESSAGE_H
void message_add_handlers(void);

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef PRESENCE_H
#define PRESENCE_H
#ifndef XMPP_PRESENCE_H
#define XMPP_PRESENCE_H
void presence_sub_requests_init(void);
void presence_add_handlers(void);

View File

@@ -32,30 +32,13 @@
#include "tools/autocomplete.h"
#include "xmpp/connection.h"
#include "xmpp/roster.h"
#include "roster_list.h"
#include "xmpp/stanza.h"
#include "xmpp/xmpp.h"
#define HANDLE(type, func) xmpp_handler_add(conn, func, XMPP_NS_ROSTER, \
STANZA_NAME_IQ, type, ctx)
// nicknames
static Autocomplete name_ac;
// barejids
static Autocomplete barejid_ac;
// fulljids
static Autocomplete fulljid_ac;
// groups
static Autocomplete groups_ac;
// contacts, indexed on barejid
static GHashTable *contacts;
// nickname to jid map
static GHashTable *name_to_barejid;
// callback data for group commands
typedef struct _group_data {
char *name;
@@ -77,14 +60,7 @@ _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata);
// helper functions
static void _add_name_and_barejid(const char * const name,
const char * const barejid);
static void _replace_name(const char * const current_name,
const char * const new_name, const char * const barejid);
GSList * _get_groups_from_item(xmpp_stanza_t *item);
static gboolean _key_equals(void *key1, void *key2);
static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2);
static gint _compare_contacts(PContact a, PContact b);
void
roster_add_handlers(void)
@@ -105,52 +81,6 @@ roster_request(void)
xmpp_stanza_release(iq);
}
void
roster_init(void)
{
name_ac = autocomplete_new();
barejid_ac = autocomplete_new();
fulljid_ac = autocomplete_new();
groups_ac = autocomplete_new();
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
(GDestroyNotify)p_contact_free);
name_to_barejid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
g_free);
}
void
roster_clear(void)
{
autocomplete_clear(name_ac);
autocomplete_clear(barejid_ac);
autocomplete_clear(fulljid_ac);
autocomplete_clear(groups_ac);
g_hash_table_destroy(contacts);
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
(GDestroyNotify)p_contact_free);
g_hash_table_destroy(name_to_barejid);
name_to_barejid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
g_free);
}
void
roster_free()
{
autocomplete_free(name_ac);
autocomplete_free(barejid_ac);
autocomplete_free(fulljid_ac);
autocomplete_free(groups_ac);
}
void
roster_reset_search_attempts(void)
{
autocomplete_reset(name_ac);
autocomplete_reset(barejid_ac);
autocomplete_reset(fulljid_ac);
autocomplete_reset(groups_ac);
}
void
roster_add_new(const char * const barejid, const char * const name)
{
@@ -162,7 +92,7 @@ roster_add_new(const char * const barejid, const char * const name)
}
void
roster_remove(const char * const barejid)
roster_send_remove(const char * const barejid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
@@ -171,180 +101,46 @@ roster_remove(const char * const barejid)
xmpp_stanza_release(iq);
}
gboolean
roster_add(const char * const barejid, const char * const name, GSList *groups,
const char * const subscription, gboolean pending_out, gboolean from_initial)
void
roster_send_name_change(const char * const barejid, const char * const new_name, GSList *groups)
{
gboolean added = FALSE;
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) {
contact = p_contact_new(barejid, name, groups, subscription, NULL,
pending_out);
// add groups
while (groups != NULL) {
autocomplete_add(groups_ac, groups->data);
groups = g_slist_next(groups);
}
g_hash_table_insert(contacts, strdup(barejid), contact);
autocomplete_add(barejid_ac, barejid);
_add_name_and_barejid(name, barejid);
if (!from_initial) {
prof_handle_roster_add(barejid, name);
}
added = TRUE;
}
return added;
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, NULL, barejid, new_name,
groups);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
void
roster_update(const char * const barejid, const char * const name,
GSList *groups, const char * const subscription, gboolean pending_out)
roster_send_add_to_group(const char * const group, PContact contact)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) {
roster_add(barejid, name, groups, subscription, pending_out, FALSE);
} else {
p_contact_set_subscription(contact, subscription);
p_contact_set_pending_out(contact, pending_out);
const char * const new_name = name;
const char * current_name = NULL;
if (p_contact_name(contact) != NULL) {
current_name = strdup(p_contact_name(contact));
}
p_contact_set_name(contact, new_name);
p_contact_set_groups(contact, groups);
_replace_name(current_name, new_name, barejid);
// add groups
while (groups != NULL) {
autocomplete_add(groups_ac, groups->data);
groups = g_slist_next(groups);
}
GSList *groups = p_contact_groups(contact);
GSList *new_groups = NULL;
while (groups != NULL) {
new_groups = g_slist_append(new_groups, strdup(groups->data));
groups = g_slist_next(groups);
}
}
gboolean
roster_update_presence(const char * const barejid, Resource *resource,
GDateTime *last_activity)
{
assert(barejid != NULL);
assert(resource != NULL);
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) {
return FALSE;
}
if (!_datetimes_equal(p_contact_last_activity(contact), last_activity)) {
p_contact_set_last_activity(contact, last_activity);
}
p_contact_set_presence(contact, resource);
Jid *jid = jid_create_from_bare_and_resource(barejid, resource->name);
autocomplete_add(fulljid_ac, jid->fulljid);
jid_destroy(jid);
return TRUE;
}
gboolean
roster_contact_offline(const char * const barejid,
const char * const resource, const char * const status)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) {
return FALSE;
}
if (resource == NULL) {
return TRUE;
} else {
gboolean result = p_contact_remove_resource(contact, resource);
if (result == TRUE) {
Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
autocomplete_remove(fulljid_ac, jid->fulljid);
jid_destroy(jid);
}
return result;
}
}
void
roster_change_name(const char * const barejid, const char * const new_name)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
const char * current_name = NULL;
new_groups = g_slist_append(new_groups, strdup(group));
// add an id handler to handle the response
char *unique_id = get_unique_id();
GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group);
if (p_contact_name(contact) != NULL) {
current_name = strdup(p_contact_name(contact));
data->name = strdup(p_contact_name(contact));
} else {
data->name = strdup(p_contact_barejid(contact));
}
if (contact != NULL) {
p_contact_set_name(contact, new_name);
_replace_name(current_name, new_name, barejid);
GSList *groups = p_contact_groups(contact);
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, NULL, barejid, new_name,
groups);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
}
void
roster_add_to_group(const char * const group, const char * const barejid)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact != NULL) {
if (p_contact_in_group(contact, group)) {
if (p_contact_name(contact) != NULL) {
prof_handle_already_in_group(p_contact_name(contact), group);
} else {
prof_handle_already_in_group(p_contact_barejid(contact), group);
}
return;
}
GSList *groups = p_contact_groups(contact);
GSList *new_groups = NULL;
while (groups != NULL) {
new_groups = g_slist_append(new_groups, strdup(groups->data));
groups = g_slist_next(groups);
}
new_groups = g_slist_append(new_groups, strdup(group));
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
// add an id handler to handle the response
char *unique_id = get_unique_id();
GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group);
if (p_contact_name(contact) != NULL) {
data->name = strdup(p_contact_name(contact));
} else {
data->name = strdup(p_contact_barejid(contact));
}
xmpp_id_handler_add(conn, _group_add_handler, unique_id, data);
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, barejid,
p_contact_name(contact), new_groups);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
free(unique_id);
}
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_id_handler_add(conn, _group_add_handler, unique_id, data);
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, p_contact_barejid(contact),
p_contact_name(contact), new_groups);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
free(unique_id);
}
static int
@@ -362,50 +158,36 @@ _group_add_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
}
void
roster_remove_from_group(const char * const group, const char * const barejid)
roster_send_remove_from_group(const char * const group, PContact contact)
{
PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact != NULL) {
if (!p_contact_in_group(contact, group)) {
if (p_contact_name(contact) != NULL) {
prof_handle_not_in_group(p_contact_name(contact), group);
} else {
prof_handle_not_in_group(p_contact_barejid(contact), group);
}
return;
GSList *groups = p_contact_groups(contact);
GSList *new_groups = NULL;
while (groups != NULL) {
if (strcmp(groups->data, group) != 0) {
new_groups = g_slist_append(new_groups, strdup(groups->data));
}
GSList *groups = p_contact_groups(contact);
GSList *new_groups = NULL;
while (groups != NULL) {
if (strcmp(groups->data, group) != 0) {
new_groups = g_slist_append(new_groups, strdup(groups->data));
}
groups = g_slist_next(groups);
}
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
// add an id handler to handle the response
char *unique_id = get_unique_id();
GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group);
if (p_contact_name(contact) != NULL) {
data->name = strdup(p_contact_name(contact));
} else {
data->name = strdup(p_contact_barejid(contact));
}
xmpp_id_handler_add(conn, _group_remove_handler, unique_id, data);
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, barejid,
p_contact_name(contact), new_groups);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
free(unique_id);
groups = g_slist_next(groups);
}
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
// add an id handler to handle the response
char *unique_id = get_unique_id();
GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group);
if (p_contact_name(contact) != NULL) {
data->name = strdup(p_contact_name(contact));
} else {
data->name = strdup(p_contact_barejid(contact));
}
xmpp_id_handler_add(conn, _group_remove_handler, unique_id, data);
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, p_contact_barejid(contact),
p_contact_name(contact), new_groups);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
free(unique_id);
}
static int
@@ -422,107 +204,6 @@ _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 0;
}
gboolean
roster_has_pending_subscriptions(void)
{
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, contacts);
while (g_hash_table_iter_next(&iter, &key, &value)) {
PContact contact = (PContact) value;
if (p_contact_pending_out(contact)) {
return TRUE;
}
}
return FALSE;
}
GSList *
roster_get_contacts(void)
{
GSList *result = NULL;
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, contacts);
while (g_hash_table_iter_next(&iter, &key, &value)) {
result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts);
}
// resturn all contact structs
return result;
}
GSList *
roster_get_groups(void)
{
return autocomplete_get_list(groups_ac);
}
GSList *
roster_get_group(const char * const group)
{
GSList *result = NULL;
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, contacts);
while (g_hash_table_iter_next(&iter, &key, &value)) {
GSList *groups = p_contact_groups(value);
while (groups != NULL) {
if (strcmp(groups->data, group) == 0) {
result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts);
break;
}
groups = g_slist_next(groups);
}
}
// resturn all contact structs
return result;
}
char *
roster_find_contact(char *search_str)
{
return autocomplete_complete(name_ac, search_str);
}
char *
roster_find_jid(char *search_str)
{
return autocomplete_complete(barejid_ac, search_str);
}
char *
roster_find_resource(char *search_str)
{
return autocomplete_complete(fulljid_ac, search_str);
}
char *
roster_find_group(char *search_str)
{
return autocomplete_complete(groups_ac, search_str);
}
char *
roster_barejid_from_name(const char * const name)
{
return g_hash_table_lookup(name_to_barejid, name);
}
PContact
roster_get_contact(const char * const barejid)
{
return g_hash_table_lookup(contacts, barejid);
}
static int
_roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
@@ -556,26 +237,8 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
if (name == NULL) {
name = barejid;
}
autocomplete_remove(barejid_ac, barejid);
autocomplete_remove(name_ac, name);
g_hash_table_remove(name_to_barejid, name);
// remove each fulljid
PContact contact = roster_get_contact(barejid);
if (contact != NULL) {
GList *resources = p_contact_get_available_resources(contact);
while (resources != NULL) {
GString *fulljid = g_string_new(strdup(barejid));
g_string_append(fulljid, "/");
g_string_append(fulljid, resources->data);
autocomplete_remove(fulljid_ac, fulljid->str);
g_string_free(fulljid, TRUE);
resources = g_list_next(resources);
}
}
// remove the contact
g_hash_table_remove(contacts, barejid);
roster_remove(name, barejid);
prof_handle_roster_remove(barejid);
@@ -642,35 +305,6 @@ _roster_handle_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1;
}
static void
_add_name_and_barejid(const char * const name, const char * const barejid)
{
if (name != NULL) {
autocomplete_add(name_ac, name);
g_hash_table_insert(name_to_barejid, strdup(name), strdup(barejid));
} else {
autocomplete_add(name_ac, barejid);
g_hash_table_insert(name_to_barejid, strdup(barejid), strdup(barejid));
}
}
static void
_replace_name(const char * const current_name, const char * const new_name,
const char * const barejid)
{
// current handle exists already
if (current_name != NULL) {
autocomplete_remove(name_ac, current_name);
g_hash_table_remove(name_to_barejid, current_name);
_add_name_and_barejid(new_name, barejid);
// no current handle
} else if (new_name != NULL) {
autocomplete_remove(name_ac, barejid);
g_hash_table_remove(name_to_barejid, barejid);
_add_name_and_barejid(new_name, barejid);
}
}
GSList *
_get_groups_from_item(xmpp_stanza_t *item)
{
@@ -689,54 +323,3 @@ _get_groups_from_item(xmpp_stanza_t *item)
return groups;
}
static
gboolean _key_equals(void *key1, void *key2)
{
gchar *str1 = (gchar *) key1;
gchar *str2 = (gchar *) key2;
return (g_strcmp0(str1, str2) == 0);
}
static
gint _compare_contacts(PContact a, PContact b)
{
const char * utf8_str_a = NULL;
const char * utf8_str_b = NULL;
if (p_contact_name(a) != NULL) {
utf8_str_a = p_contact_name(a);
} else {
utf8_str_a = p_contact_barejid(a);
}
if (p_contact_name(b) != NULL) {
utf8_str_b = p_contact_name(b);
} else {
utf8_str_b = p_contact_barejid(b);
}
gchar *key_a = g_utf8_collate_key(utf8_str_a, -1);
gchar *key_b = g_utf8_collate_key(utf8_str_b, -1);
gint result = g_strcmp0(key_a, key_b);
g_free(key_a);
g_free(key_b);
return result;
}
static gboolean
_datetimes_equal(GDateTime *dt1, GDateTime *dt2)
{
if ((dt1 == NULL) && (dt2 == NULL)) {
return TRUE;
} else if ((dt1 == NULL) && (dt2 != NULL)) {
return FALSE;
} else if ((dt1 != NULL) && (dt2 == NULL)) {
return FALSE;
} else {
return g_date_time_equal(dt1, dt2);
}
}

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef ROSTER_H
#define ROSTER_H
#ifndef XMPP_ROSTER_H
#define XMPP_ROSTER_H
void roster_add_handlers(void);
void roster_request(void);

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef STANZA_H
#define STANZA_H
#ifndef XMPP_STANZA_H
#define XMPP_STANZA_H
#include <strophe.h>

View File

@@ -20,8 +20,8 @@
*
*/
#ifndef XMPP_H
#define XMPP_H
#ifndef XMPP_XMPP_H
#define XMPP_XMPP_H
#include <strophe.h>
@@ -124,32 +124,16 @@ void iq_disco_items_request(gchar *jid);
Capabilities* caps_get(const char * const caps_str);
void caps_close(void);
void roster_clear(void);
gboolean roster_update_presence(const char * const barejid,
Resource *resource, GDateTime *last_activity);
PContact roster_get_contact(const char * const barejid);
gboolean roster_contact_offline(const char * const barejid,
const char * const resource, const char * const status);
void roster_reset_search_attempts(void);
void roster_init(void);
void roster_free(void);
gboolean roster_has_pending_subscriptions(void);
GSList * roster_get_contacts(void);
char * roster_find_contact(char *search_str);
char * roster_find_jid(char *search_str);
char * roster_find_resource(char *search_str);
char * roster_find_group(char *search_str);
gboolean roster_add(const char * const barejid, const char * const name,
GSList *groups, const char * const subscription, gboolean pending_out,
gboolean from_initial);
void roster_change_name(const char * const barejid, const char * const new_name);
char * roster_barejid_from_name(const char * const name);
void bookmark_add(const char *jid, const char *nick, gboolean autojoin);
void bookmark_remove(const char *jid, gboolean autojoin);
const GList *bookmark_get_list(void);
char *bookmark_find(char *search_str);
void bookmark_autocomplete_reset(void);
void roster_send_name_change(const char * const barejid, const char * const new_name, GSList *groups);
void roster_send_add_to_group(const char * const group, PContact contact);
void roster_send_remove_from_group(const char * const group, PContact contact);
void roster_add_new(const char * const barejid, const char * const name);
void roster_remove(const char * const barejid);
GSList * roster_get_group(const char * const group);
void roster_add_to_group(const char * const group, const char * const barejid);
void roster_remove_from_group(const char * const group,
const char * const barejid);
GSList * roster_get_groups(void);
void roster_send_remove(const char * const barejid);
#endif