1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge branch 'master' into dev

This commit is contained in:
James Booth 2012-10-06 00:35:56 +01:00
commit 0139fb8b10
9 changed files with 146 additions and 59 deletions

View File

@ -27,6 +27,7 @@
#include "command.h"
#include "common.h"
#include "contact.h"
#include "contact_list.h"
#include "chat_log.h"
#include "history.h"
@ -63,7 +64,6 @@ static gboolean _cmd_quit(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_help(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_prefs(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_who(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_ros(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_connect(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_msg(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_tiny(const char * const inp, struct cmd_help_t help);
@ -153,21 +153,14 @@ static struct cmd_t main_commands[] =
"Example : /tiny http://www.google.com",
NULL } } },
{ "/ros",
_cmd_ros,
{ "/ros", "List all contacts.",
{ "/ros",
"----",
"List all contact currently on the chat hosts roster.",
"See /who for a more useful list of contacts who are currently online.",
NULL } } },
{ "/who",
_cmd_who,
{ "/who", "Find out who is online.",
{ "/who",
"----",
"Show the list of all online contacts with their current status message.",
{ "/who [status]", "Show contacts with chosen status.",
{ "/who [status]",
"-------------",
"Show contacts with the specified status, no status shows all contacts.",
"Possible statuses are: online, offline, away, dnd, xa, chat.",
"online includes: chat, dnd, away, xa.",
NULL } } },
{ "/close",
@ -560,19 +553,6 @@ _cmd_prefs(const char * const inp, struct cmd_help_t help)
return TRUE;
}
static gboolean
_cmd_ros(const char * const inp, struct cmd_help_t help)
{
jabber_conn_status_t conn_status = jabber_get_connection_status();
if (conn_status != JABBER_CONNECTED)
cons_show("You are not currently connected.");
else
jabber_roster_request();
return TRUE;
}
static gboolean
_cmd_who(const char * const inp, struct cmd_help_t help)
{
@ -580,9 +560,70 @@ _cmd_who(const char * const inp, struct cmd_help_t help)
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
} else {
// copy input
char inp_cpy[strlen(inp) + 1];
strcpy(inp_cpy, inp);
// get show
strtok(inp_cpy, " ");
char *show = strtok(NULL, " ");
// bad arg
if ((show != NULL)
&& (strcmp(show, "online") != 0)
&& (strcmp(show, "offline") != 0)
&& (strcmp(show, "away") != 0)
&& (strcmp(show, "chat") != 0)
&& (strcmp(show, "xa") != 0)
&& (strcmp(show, "dnd") != 0)) {
cons_show("Usage: %s", help.usage);
// valid arg
} else {
GSList *list = get_contact_list();
cons_show_online_contacts(list);
// no arg, show all contacts
if (show == NULL) {
cons_show("All contacts:");
cons_show_contacts(list);
// online, show all status that indicate online
} else if (strcmp("online", show) == 0) {
cons_show("Contacts (%s):", show);
GSList *filtered = NULL;
while (list != NULL) {
PContact contact = list->data;
const char * const contact_show = (p_contact_show(contact));
if ((strcmp(contact_show, "online") == 0)
|| (strcmp(contact_show, "away") == 0)
|| (strcmp(contact_show, "dnd") == 0)
|| (strcmp(contact_show, "xa") == 0)
|| (strcmp(contact_show, "chat") == 0)) {
filtered = g_slist_append(filtered, contact);
}
list = g_slist_next(list);
}
cons_show_contacts(filtered);
// show specific status
} else {
cons_show("Contacts (%s):", show);
GSList *filtered = NULL;
while (list != NULL) {
PContact contact = list->data;
if (strcmp(p_contact_show(contact), show) == 0) {
filtered = g_slist_append(filtered, contact);
}
list = g_slist_next(list);
}
cons_show_contacts(filtered);
}
}
}
return TRUE;

View File

@ -20,6 +20,8 @@
*
*/
#include <string.h>
#include "contact.h"
#include "prof_autocomplete.h"
@ -70,3 +72,19 @@ find_contact(char *search_str)
{
return p_autocomplete_complete(ac, search_str);
}
PContact
contact_list_get_contact(const char const *jid)
{
GSList *contacts = get_contact_list();
while (contacts != NULL) {
PContact contact = contacts->data;
if (strcmp(p_contact_name(contact), jid) == 0) {
return contact;
}
contacts = g_slist_next(contacts);
}
return NULL;
}

View File

@ -25,6 +25,8 @@
#include <glib.h>
#include "contact.h"
void contact_list_init(void);
void contact_list_clear(void);
void reset_search_attempts(void);
@ -33,5 +35,6 @@ gboolean contact_list_add(const char * const name, const char * const show,
gboolean contact_list_remove(const char * const name);
GSList * get_contact_list(void);
char * find_contact(char *search_str);
PContact contact_list_get_contact(const char const *jid);
#endif

View File

@ -110,7 +110,7 @@ inp_clear(void)
void
inp_non_block(void)
{
wtimeout(inp_win, 500);
wtimeout(inp_win, 20);
}
void

View File

@ -301,6 +301,7 @@ _connection_handler(xmpp_conn_t * const conn,
jabber_conn.conn_status = JABBER_CONNECTED;
jabber_conn.presence = PRESENCE_ONLINE;
jabber_roster_request();
} else {
// received close stream response from server after disconnect

View File

@ -55,11 +55,13 @@ prof_run(const int disable_tls, char *log_level)
GTimer *timer = g_timer_new();
gboolean cmd_result = TRUE;
while(cmd_result == TRUE) {
int ch = ERR;
char inp[INP_WIN_MAX];
int size = 0;
while(cmd_result == TRUE) {
int ch = ERR;
size = 0;
while(ch != '\n') {
gdouble elapsed = g_timer_elapsed(timer, NULL);
@ -159,7 +161,7 @@ prof_handle_contact_online(char *contact, char *show, char *status)
void
prof_handle_contact_offline(char *contact, char *show, char *status)
{
gboolean result = contact_list_remove(contact);
gboolean result = contact_list_add(contact, "offline", status);
if (result) {
win_contact_offline(contact, show, status);
}
@ -169,19 +171,15 @@ prof_handle_contact_offline(char *contact, char *show, char *status)
void
prof_handle_roster(GSList *roster)
{
cons_show("Roster:");
while (roster != NULL) {
jabber_roster_entry *entry = roster->data;
if (entry->name != NULL) {
cons_show("%s (%s)", entry->name, entry->jid);
} else {
cons_show("%s", entry->jid);
// if contact not in contact list add them as offline
if (find_contact(entry->jid) == NULL) {
contact_list_add(entry->jid, "offline", NULL);
}
roster = g_slist_next(roster);
win_page_off();
}
g_slist_free_full(roster, (GDestroyNotify)_free_roster_entry);

View File

@ -74,7 +74,6 @@ status_bar_refresh(void)
if (elapsed >= 60000000) {
dirty = TRUE;
g_date_time_unref(now_time);
last_time = g_date_time_new_now_local();
}
@ -84,6 +83,8 @@ status_bar_refresh(void)
inp_put_back();
dirty = FALSE;
}
g_date_time_unref(now_time);
}
void

View File

@ -107,7 +107,7 @@ void cons_bad_command(const char * const cmd);
void cons_show(const char * const cmd, ...);
void cons_bad_show(const char * const cmd);
void cons_highlight_show(const char * const cmd);
void cons_show_online_contacts(GSList * list);
void cons_show_contacts(GSList * list);
// status bar actions
void status_bar_refresh(void);

View File

@ -38,6 +38,7 @@
#include "command.h"
#include "contact.h"
#include "contact_list.h"
#include "log.h"
#include "preferences.h"
#include "ui.h"
@ -357,16 +358,34 @@ void
win_show_outgoing_msg(const char * const from, const char * const to,
const char * const message)
{
int win_index = _find_prof_win_index(to);
if (win_index == NUM_WINS)
win_index = _new_prof_win(to);
// if the contact is offline, show a message
PContact contact = contact_list_get_contact(to);
if (contact == NULL) {
cons_show("%s is not one of your contacts.");
} else {
int win_index = _find_prof_win_index(to);
WINDOW *win = NULL;
if (win_index == NUM_WINS) {
win_index = _new_prof_win(to);
win = _wins[win_index].win;
if (strcmp(p_contact_show(contact), "offline") == 0) {
const char const *show = p_contact_show(contact);
const char const *status = p_contact_status(contact);
_show_status_string(win, to, show, status, "--", "offline");
}
} else {
win = _wins[win_index].win;
}
WINDOW *win = _wins[win_index].win;
_win_show_time(win);
_win_show_user(win, from, 0);
_win_show_message(win, message);
_win_switch_if_active(win_index);
}
}
void
win_show(const char * const msg)
@ -554,18 +573,16 @@ cons_help(void)
}
void
cons_show_online_contacts(GSList *list)
cons_show_contacts(GSList *list)
{
_win_show_time(_cons_win);
wprintw(_cons_win, "Online contacts:\n");
GSList *curr = list;
while(curr) {
PContact contact = curr->data;
_win_show_time(_cons_win);
const char *show = p_contact_show(contact);
_win_show_time(_cons_win);
if (strcmp(show, "online") == 0) {
wattron(_cons_win, COLOUR_ONLINE);
} else if (strcmp(show, "away") == 0) {
@ -901,6 +918,10 @@ _show_status_string(WINDOW *win, const char * const from,
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);
@ -929,6 +950,10 @@ _show_status_string(WINDOW *win, const char * const from,
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);