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

Moved cons_show_info() to console module

This commit is contained in:
James Booth 2013-04-21 00:39:42 +01:00
parent 867774ce57
commit a3c241b3a8
2 changed files with 134 additions and 141 deletions

View File

@ -250,6 +250,140 @@ cons_show_wins(void)
}
}
void
cons_show_info(PContact pcontact)
{
const char *barejid = p_contact_barejid(pcontact);
const char *name = p_contact_name(pcontact);
const char *presence = p_contact_presence(pcontact);
const char *sub = p_contact_subscription(pcontact);
GList *resources = p_contact_get_available_resources(pcontact);
GList *ordered_resources = NULL;
GDateTime *last_activity = p_contact_last_activity(pcontact);
WINDOW *win = console->win;
window_show_time(console, '-');
wprintw(win, "\n");
window_show_time(console, '-');
window_presence_colour_on(console, presence);
wprintw(win, "%s", barejid);
if (name != NULL) {
wprintw(win, " (%s)", name);
}
window_presence_colour_off(console, presence);
wprintw(win, ":\n");
if (sub != NULL) {
window_show_time(console, '-');
wprintw(win, "Subscription: %s\n", sub);
}
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
window_show_time(console, '-');
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 (resources != NULL) {
window_show_time(console, '-');
wprintw(win, "Resources:\n");
// sort in order of availabiltiy
while (resources != NULL) {
Resource *resource = resources->data;
ordered_resources = g_list_insert_sorted(ordered_resources,
resource, (GCompareFunc)resource_compare_availability);
resources = g_list_next(resources);
}
}
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
window_show_time(console, '-');
window_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");
window_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)) {
window_show_time(console, '-');
wprintw(win, " Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
wprintw(win, " ");
}
}
if (caps->type != NULL) {
wprintw(win, "%s", caps->type);
if (caps->category != NULL) {
wprintw(win, " ");
}
}
if (caps->category != NULL) {
wprintw(win, "%s", caps->category);
}
wprintw(win, "\n");
}
if (caps->software != NULL) {
window_show_time(console, '-');
wprintw(win, " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
wprintw(win, ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
wprintw(win, "\n");
}
if (caps->os != NULL) {
window_show_time(console, '-');
wprintw(win, " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
wprintw(win, ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
wprintw(win, "\n");
}
}
}
ordered_resources = g_list_next(ordered_resources);
}
dirty = TRUE;
if (!win_current_is_console()) {
status_bar_new(0);
}
}
static void
_cons_splash_logo(void)
{

View File

@ -94,7 +94,6 @@ static void _win_resize_all(void);
static gint _win_get_unread(void);
static void _win_show_history(WINDOW *win, int win_index,
const char * const contact);
static void _win_show_info(ProfWin *window, PContact pcontact);
static void _ui_draw_win_title(void);
static void _notify(const char * const message, int timeout,
@ -1107,17 +1106,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message)
}
}
void
cons_show_info(PContact pcontact)
{
_win_show_info(console, pcontact);
if (current_index != 0) {
status_bar_new(0);
}
}
void
cons_show_caps(const char * const contact, Resource *resource)
{
@ -2411,135 +2399,6 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact)
}
}
static void
_win_show_info(ProfWin *window, PContact pcontact)
{
const char *barejid = p_contact_barejid(pcontact);
const char *name = p_contact_name(pcontact);
const char *presence = p_contact_presence(pcontact);
const char *sub = p_contact_subscription(pcontact);
GList *resources = p_contact_get_available_resources(pcontact);
GList *ordered_resources = NULL;
GDateTime *last_activity = p_contact_last_activity(pcontact);
WINDOW *win = window->win;
window_show_time(window, '-');
wprintw(win, "\n");
window_show_time(window, '-');
window_presence_colour_on(window, presence);
wprintw(win, "%s", barejid);
if (name != NULL) {
wprintw(win, " (%s)", name);
}
window_presence_colour_off(window, presence);
wprintw(win, ":\n");
if (sub != NULL) {
window_show_time(window, '-');
wprintw(win, "Subscription: %s\n", sub);
}
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
window_show_time(window, '-');
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 (resources != NULL) {
window_show_time(window, '-');
wprintw(win, "Resources:\n");
// sort in order of availabiltiy
while (resources != NULL) {
Resource *resource = resources->data;
ordered_resources = g_list_insert_sorted(ordered_resources,
resource, (GCompareFunc)resource_compare_availability);
resources = g_list_next(resources);
}
}
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
window_show_time(window, '-');
window_presence_colour_on(window, 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");
window_presence_colour_off(window, 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)) {
window_show_time(window, '-');
wprintw(win, " Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
wprintw(win, " ");
}
}
if (caps->type != NULL) {
wprintw(win, "%s", caps->type);
if (caps->category != NULL) {
wprintw(win, " ");
}
}
if (caps->category != NULL) {
wprintw(win, "%s", caps->category);
}
wprintw(win, "\n");
}
if (caps->software != NULL) {
window_show_time(window, '-');
wprintw(win, " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
wprintw(win, ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
wprintw(win, "\n");
}
if (caps->os != NULL) {
window_show_time(window, '-');
wprintw(win, " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
wprintw(win, ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
wprintw(win, "\n");
}
}
}
ordered_resources = g_list_next(ordered_resources);
}
}
void
_set_current(int index)
{