1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Added basic /status command to find out about a specific contact

This commit is contained in:
James Booth 2012-11-13 22:08:46 +00:00
parent 2afe7b83ab
commit e506986ef5
3 changed files with 112 additions and 52 deletions

View File

@ -108,6 +108,7 @@ static gboolean _cmd_online(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help); static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_chat(const char * const inp, struct cmd_help_t help); static gboolean _cmd_chat(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_xa(const char * const inp, struct cmd_help_t help); static gboolean _cmd_xa(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_status(const char * const inp, struct cmd_help_t help);
/* /*
* The commands are broken down into three groups: * The commands are broken down into three groups:
@ -190,6 +191,15 @@ static struct cmd_t main_commands[] =
"Example : /msg boothj5@gmail.com Hey, here's a message!", "Example : /msg boothj5@gmail.com Hey, here's a message!",
NULL } } }, NULL } } },
{ "/status",
_cmd_status,
{ "/msg user@host", "Find out a contacts status.",
{ "/msg user@host",
"--------------",
"Find out someones presence information.",
"Use tab completion to autocomplete the contact.",
NULL } } },
{ "/join", { "/join",
_cmd_join, _cmd_join,
{ "/join room@server [nick]", "Join a chat room.", { "/join room@server [nick]", "Join a chat room.",
@ -777,6 +787,8 @@ _cmd_complete_parameters(char *input, int *size)
_parameter_autocomplete(input, size, "/msg", _parameter_autocomplete(input, size, "/msg",
contact_list_find_contact); contact_list_find_contact);
_parameter_autocomplete(input, size, "/status",
contact_list_find_contact);
_parameter_autocomplete(input, size, "/connect", _parameter_autocomplete(input, size, "/connect",
prefs_find_login); prefs_find_login);
_parameter_autocomplete(input, size, "/sub", _parameter_autocomplete(input, size, "/sub",
@ -1162,6 +1174,33 @@ _cmd_msg(const char * const inp, struct cmd_help_t help)
return TRUE; return TRUE;
} }
static gboolean
_cmd_status(const char * const inp, struct cmd_help_t help)
{
char *usr = NULL;
jabber_conn_status_t conn_status = jabber_get_connection_status();
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 user
strtok(inp_cpy, " ");
usr = strtok(NULL, " ");
if (usr != NULL) {
win_show_status(usr);
} else {
cons_show("Usage: %s", help.usage);
}
}
return TRUE;
}
static gboolean static gboolean
_cmd_join(const char * const inp, struct cmd_help_t help) _cmd_join(const char * const inp, struct cmd_help_t help)
{ {

View File

@ -127,6 +127,7 @@ void win_show_room_subject(const char * const room_jid,
const char * const subject); const char * const subject);
void win_show_room_member_offline(const char * const room, const char * const nick); void win_show_room_member_offline(const char * const room, const char * const nick);
void win_show_room_member_online(const char * const room, const char * const nick); void win_show_room_member_online(const char * const room, const char * const nick);
void win_show_status(const char * const contact);
// console window actions // console window actions
void cons_about(void); void cons_about(void);

View File

@ -69,6 +69,7 @@ static int max_cols = 0;
static void _create_windows(void); static void _create_windows(void);
static void _cons_splash_logo(void); static void _cons_splash_logo(void);
static void _cons_show_basic_help(void); static void _cons_show_basic_help(void);
static void _cons_show_contact(PContact contact);
static int _find_prof_win_index(const char * const contact); static int _find_prof_win_index(const char * const contact);
static int _new_prof_win(const char * const contact, win_type_t type); static int _new_prof_win(const char * const contact, win_type_t type);
static void _current_window_refresh(void); static void _current_window_refresh(void);
@ -807,6 +808,20 @@ win_contact_offline(const char * const from, const char * const show,
dirty = TRUE; dirty = TRUE;
} }
void
win_show_status(const char * const contact)
{
PContact pcontact = contact_list_get_contact(contact);
cons_show("");
if (pcontact != NULL) {
_cons_show_contact(pcontact);
} else {
cons_show("No such contact %s in roster.", contact);
}
cons_show("");
}
void void
win_disconnected(void) win_disconnected(void)
{ {
@ -1017,58 +1032,7 @@ cons_show_contacts(GSList *list)
while(curr) { while(curr) {
PContact contact = curr->data; PContact contact = curr->data;
const char *jid = p_contact_jid(contact); _cons_show_contact(contact);
const char *name = p_contact_name(contact);
const char *presence = p_contact_presence(contact);
const char *status = p_contact_status(contact);
const char *sub = p_contact_subscription(contact);
if (strcmp(sub, "none") != 0) {
_win_show_time(_cons_win);
if (strcmp(presence, "online") == 0) {
wattron(_cons_win, COLOUR_ONLINE);
} else if (strcmp(presence, "away") == 0) {
wattron(_cons_win, COLOUR_AWAY);
} else if (strcmp(presence, "chat") == 0) {
wattron(_cons_win, COLOUR_CHAT);
} else if (strcmp(presence, "dnd") == 0) {
wattron(_cons_win, COLOUR_DND);
} else if (strcmp(presence, "xa") == 0) {
wattron(_cons_win, COLOUR_XA);
} else {
wattron(_cons_win, COLOUR_OFFLINE);
}
wprintw(_cons_win, "%s", jid);
if (name != NULL) {
wprintw(_cons_win, " (%s)", name);
}
wprintw(_cons_win, " is %s", presence);
if (status != NULL) {
wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
}
wprintw(_cons_win, "\n");
if (strcmp(presence, "online") == 0) {
wattroff(_cons_win, COLOUR_ONLINE);
} else if (strcmp(presence, "away") == 0) {
wattroff(_cons_win, COLOUR_AWAY);
} else if (strcmp(presence, "chat") == 0) {
wattroff(_cons_win, COLOUR_CHAT);
} else if (strcmp(presence, "dnd") == 0) {
wattroff(_cons_win, COLOUR_DND);
} else if (strcmp(presence, "xa") == 0) {
wattroff(_cons_win, COLOUR_XA);
} else {
wattroff(_cons_win, COLOUR_OFFLINE);
}
}
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
} }
@ -1546,6 +1510,62 @@ _cons_show_incoming_message(const char * const short_from, const int win_index)
wattroff(_cons_win, COLOUR_INC); wattroff(_cons_win, COLOUR_INC);
} }
static void
_cons_show_contact(PContact contact)
{
const char *jid = p_contact_jid(contact);
const char *name = p_contact_name(contact);
const char *presence = p_contact_presence(contact);
const char *status = p_contact_status(contact);
const char *sub = p_contact_subscription(contact);
if (strcmp(sub, "none") != 0) {
_win_show_time(_cons_win);
if (strcmp(presence, "online") == 0) {
wattron(_cons_win, COLOUR_ONLINE);
} else if (strcmp(presence, "away") == 0) {
wattron(_cons_win, COLOUR_AWAY);
} else if (strcmp(presence, "chat") == 0) {
wattron(_cons_win, COLOUR_CHAT);
} else if (strcmp(presence, "dnd") == 0) {
wattron(_cons_win, COLOUR_DND);
} else if (strcmp(presence, "xa") == 0) {
wattron(_cons_win, COLOUR_XA);
} else {
wattron(_cons_win, COLOUR_OFFLINE);
}
wprintw(_cons_win, "%s", jid);
if (name != NULL) {
wprintw(_cons_win, " (%s)", name);
}
wprintw(_cons_win, " is %s", presence);
if (status != NULL) {
wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
}
wprintw(_cons_win, "\n");
if (strcmp(presence, "online") == 0) {
wattroff(_cons_win, COLOUR_ONLINE);
} else if (strcmp(presence, "away") == 0) {
wattroff(_cons_win, COLOUR_AWAY);
} else if (strcmp(presence, "chat") == 0) {
wattroff(_cons_win, COLOUR_CHAT);
} else if (strcmp(presence, "dnd") == 0) {
wattroff(_cons_win, COLOUR_DND);
} else if (strcmp(presence, "xa") == 0) {
wattroff(_cons_win, COLOUR_XA);
} else {
wattroff(_cons_win, COLOUR_OFFLINE);
}
}
}
static void static void
_win_handle_switch(const int * const ch) _win_handle_switch(const int * const ch)
{ {