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

Moved cons_show_status() to console module

This commit is contained in:
James Booth 2013-04-21 01:13:35 +01:00
parent d7cc54db63
commit 688eea083b
4 changed files with 65 additions and 64 deletions

View File

@ -584,6 +584,18 @@ cons_show_disco_items(GSList *items, const char * const jid)
} }
} }
void
cons_show_status(const char * const contact)
{
PContact pcontact = contact_list_get_contact(contact);
if (pcontact != NULL) {
window_show_contact(console, pcontact);
} else {
cons_show("No such contact \"%s\" in roster.", contact);
}
}
static void static void
_cons_splash_logo(void) _cons_splash_logo(void)
{ {

View File

@ -113,3 +113,49 @@ window_presence_colour_off(ProfWin *window, const char * const presence)
} }
} }
void
window_show_contact(ProfWin *window, PContact contact)
{
const char *barejid = p_contact_barejid(contact);
const char *name = p_contact_name(contact);
const char *presence = p_contact_presence(contact);
const char *status = p_contact_status(contact);
GDateTime *last_activity = p_contact_last_activity(contact);
window_show_time(window, '-');
window_presence_colour_on(window, presence);
wprintw(window->win, "%s", barejid);
if (name != NULL) {
wprintw(window->win, " (%s)", name);
}
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(window->win, ", idle ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(window->win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(window->win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(window->win, "%ds", seconds);
}
if (status != NULL) {
wprintw(window->win, ", \"%s\"", p_contact_status(contact));
}
wprintw(window->win, "\n");
window_presence_colour_off(window, presence);
}

View File

@ -23,6 +23,8 @@
#ifndef WINDOW_H #ifndef WINDOW_H
#define WINDOW_H #define WINDOW_H
#include "contact.h"
#define PAD_SIZE 1000 #define PAD_SIZE 1000
typedef enum { typedef enum {
@ -49,5 +51,6 @@ void window_free(ProfWin *window);
void window_show_time(ProfWin *window, char show_char); void window_show_time(ProfWin *window, char show_char);
void window_presence_colour_on(ProfWin *window, const char * const presence); void window_presence_colour_on(ProfWin *window, const char * const presence);
void window_presence_colour_off(ProfWin *window, const char * const presence); void window_presence_colour_off(ProfWin *window, const char * const presence);
void window_show_contact(ProfWin *window, PContact contact);
#endif #endif

View File

@ -74,7 +74,6 @@ static GTimer *ui_idle_time;
static void _set_current(int index); static void _set_current(int index);
static void _cons_show_basic_help(void); static void _cons_show_basic_help(void);
static void _win_show_contact(ProfWin *window, 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);
@ -1106,18 +1105,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message)
} }
} }
void
cons_show_status(const char * const contact)
{
PContact pcontact = contact_list_get_contact(contact);
if (pcontact != NULL) {
_win_show_contact(console, pcontact);
} else {
cons_show("No such contact \"%s\" in roster.", contact);
}
}
void void
cons_show_room_invite(const char * const invitor, const char * const room, cons_show_room_invite(const char * const invitor, const char * const room,
const char * const reason) const char * const reason)
@ -1292,7 +1279,7 @@ win_show_status(void)
PContact pcontact = contact_list_get_contact(recipient); PContact pcontact = contact_list_get_contact(recipient);
if (pcontact != NULL) { if (pcontact != NULL) {
_win_show_contact(current, pcontact); window_show_contact(current, pcontact);
} else { } else {
win_current_show("Error getting contact info."); win_current_show("Error getting contact info.");
} }
@ -1306,7 +1293,7 @@ win_private_show_status(void)
PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart); PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
if (pcontact != NULL) { if (pcontact != NULL) {
_win_show_contact(current, pcontact); window_show_contact(current, pcontact);
} else { } else {
win_current_show("Error getting contact info."); win_current_show("Error getting contact info.");
} }
@ -1320,7 +1307,7 @@ win_room_show_status(const char * const contact)
PContact pcontact = muc_get_participant(win_current_get_recipient(), contact); PContact pcontact = muc_get_participant(win_current_get_recipient(), contact);
if (pcontact != NULL) { if (pcontact != NULL) {
_win_show_contact(current, pcontact); window_show_contact(current, pcontact);
} else { } else {
win_current_show("No such participant \"%s\" in room.", contact); win_current_show("No such participant \"%s\" in room.", contact);
} }
@ -1667,7 +1654,7 @@ cons_show_contacts(GSList *list)
while(curr) { while(curr) {
PContact contact = curr->data; PContact contact = curr->data;
if (strcmp(p_contact_subscription(contact), "none") != 0) { if (strcmp(p_contact_subscription(contact), "none") != 0) {
_win_show_contact(console, contact); window_show_contact(console, contact);
} }
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
@ -2036,53 +2023,6 @@ _cons_show_incoming_message(const char * const short_from, const int win_index)
wattroff(console->win, COLOUR_INCOMING); wattroff(console->win, COLOUR_INCOMING);
} }
static void
_win_show_contact(ProfWin *window, PContact contact)
{
const char *barejid = p_contact_barejid(contact);
const char *name = p_contact_name(contact);
const char *presence = p_contact_presence(contact);
const char *status = p_contact_status(contact);
GDateTime *last_activity = p_contact_last_activity(contact);
window_show_time(window, '-');
window_presence_colour_on(window, presence);
wprintw(window->win, "%s", barejid);
if (name != NULL) {
wprintw(window->win, " (%s)", name);
}
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(window->win, ", idle ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(window->win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(window->win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(window->win, "%ds", seconds);
}
if (status != NULL) {
wprintw(window->win, ", \"%s\"", p_contact_status(contact));
}
wprintw(window->win, "\n");
window_presence_colour_off(window, presence);
}
static void static void
_win_handle_switch(const wint_t * const ch) _win_handle_switch(const wint_t * const ch)
{ {