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

Added basic room /info command

This commit is contained in:
James Booth 2013-01-20 03:32:51 +00:00
parent e9695c83aa
commit cae7717e73
3 changed files with 91 additions and 65 deletions

View File

@ -1424,7 +1424,6 @@ _cmd_who(gchar **args, struct cmd_help_t help)
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected."); cons_show("You are not currently connected.");
} else { } else {
cons_show("");
char *presence = args[0]; char *presence = args[0];
// bad arg // bad arg
@ -1519,6 +1518,7 @@ _cmd_who(gchar **args, struct cmd_help_t help)
// not in groupchat window // not in groupchat window
} else { } else {
cons_show("");
GSList *list = get_contact_list(); GSList *list = get_contact_list();
// no arg, show all contacts // no arg, show all contacts
@ -1674,7 +1674,7 @@ _cmd_info(gchar **args, struct cmd_help_t help)
} else { } else {
if (win_current_is_groupchat()) { if (win_current_is_groupchat()) {
if (usr != NULL) { if (usr != NULL) {
win_room_show_status(usr); win_room_show_info(usr);
} else { } else {
win_current_show("You must specify a nickname."); win_current_show("You must specify a nickname.");
} }

View File

@ -133,6 +133,7 @@ void win_show_room_nick_change(const char * const room, const char * const nick)
void win_show_room_member_presence(const char * const room, void win_show_room_member_presence(const char * const room,
const char * const nick, const char * const show, const char * const status); const char * const nick, const char * const show, const char * const status);
void win_room_show_status(const char * const contact); void win_room_show_status(const char * const contact);
void win_room_show_info(const char * const contact);
void win_show_status(void); void win_show_status(void);
void win_private_show_status(void); void win_private_show_status(void);

View File

@ -110,6 +110,7 @@ static void _win_resize_all(void);
static gint _win_get_unread(void); static gint _win_get_unread(void);
static void _win_show_history(WINDOW *win, int win_index, static void _win_show_history(WINDOW *win, int win_index,
const char * const contact); const char * const contact);
static void _win_show_info(WINDOW *win, PContact pcontact);
static gboolean _new_release(char *found_version); static gboolean _new_release(char *found_version);
static void _ui_draw_win_title(void); static void _ui_draw_win_title(void);
static void _presence_colour_on(WINDOW *win, const char * const presence); static void _presence_colour_on(WINDOW *win, const char * const presence);
@ -1148,75 +1149,26 @@ cons_show_wins(void)
cons_show(""); cons_show("");
} }
void
win_room_show_info(const char * const contact)
{
PContact pcontact = muc_get_participant(win_current_get_recipient(), contact);
if (pcontact != NULL) {
_win_show_info(current->win, pcontact);
} else {
win_current_show("No such participant \"%s\" in room.", contact);
}
}
void void
cons_show_info(const char * const contact) cons_show_info(const char * const contact)
{ {
PContact pcontact = contact_list_get_contact(contact); PContact pcontact = contact_list_get_contact(contact);
if (pcontact != NULL) { if (pcontact != NULL) {
const char *jid = p_contact_jid(pcontact); _win_show_info(console->win, pcontact);
const char *name = p_contact_name(pcontact);
const char *presence = p_contact_presence(pcontact);
const char *status = p_contact_status(pcontact);
const char *sub = p_contact_subscription(pcontact);
const char *caps_str = p_contact_caps_str(pcontact);
GDateTime *last_activity = p_contact_last_activity(pcontact);
cons_show("");
_win_show_time(console->win, '-');
_presence_colour_on(console->win, presence);
wprintw(console->win, "%s:\n", jid);
_presence_colour_off(console->win, presence);
if (name != NULL) {
cons_show("Name : %s", name);
}
if (sub != NULL) {
cons_show("Subscription : %s", sub);
}
_win_show_time(console->win, '-');
wprintw(console->win, "Presence : ");
_presence_colour_on(console->win, presence);
wprintw(console->win, "%s\n", presence);
_presence_colour_off(console->win, presence);
if (status != NULL) {
cons_show("Message : %s", status);
}
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
_win_show_time(console->win, '-');
wprintw(console->win, "Last activity : ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(console->win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(console->win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(console->win, "%ds", seconds);
wprintw(console->win, "\n");
g_date_time_unref(now);
}
if (caps_str != NULL) {
Capabilities *caps = caps_get(caps_str);
if ((caps != NULL) && (caps->client != NULL)) {
cons_show("Client : %s", caps->client);
}
}
} else { } else {
cons_show("No such contact \"%s\" in roster.", contact); cons_show("No such contact \"%s\" in roster.", contact);
} }
@ -2382,6 +2334,79 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact)
} }
} }
static void
_win_show_info(WINDOW *win, PContact pcontact)
{
const char *jid = p_contact_jid(pcontact);
const char *name = p_contact_name(pcontact);
const char *presence = p_contact_presence(pcontact);
const char *status = p_contact_status(pcontact);
const char *sub = p_contact_subscription(pcontact);
const char *caps_str = p_contact_caps_str(pcontact);
GDateTime *last_activity = p_contact_last_activity(pcontact);
_win_show_time(win, '-');
wprintw(win, "\n");
_win_show_time(win, '-');
_presence_colour_on(win, presence);
wprintw(win, "%s:\n", jid);
_presence_colour_off(win, presence);
if (name != NULL) {
_win_show_time(win, '-');
wprintw(win, "Name : %s\n", name);
}
if (sub != NULL) {
_win_show_time(win, '-');
wprintw(win, "Subscription : %s\n", sub);
}
_win_show_time(win, '-');
wprintw(win, "Presence : ");
_presence_colour_on(win, presence);
wprintw(win, "%s\n", presence);
_presence_colour_off(win, presence);
if (status != NULL) {
_win_show_time(win, '-');
wprintw(win, "Message : %s\n", status);
}
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
_win_show_time(win, '-');
wprintw(win, "Last activity : ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(win, "%ds", seconds);
wprintw(win, "\n");
g_date_time_unref(now);
}
if (caps_str != NULL) {
Capabilities *caps = caps_get(caps_str);
if ((caps != NULL) && (caps->client != NULL)) {
_win_show_time(win, '-');
wprintw(win, "Client : %s\n", caps->client);
}
}
}
void void
_set_current(int index) _set_current(int index)
{ {