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

Tidy wins_create_summary()

This commit is contained in:
James Booth 2015-11-29 23:58:52 +00:00
parent 6e304bb867
commit d9435d3b65
9 changed files with 158 additions and 94 deletions

View File

@ -355,6 +355,32 @@ chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status)
free(display_str); free(display_str);
} }
char*
chatwin_get_string(ProfChatWin *chatwin)
{
assert(chatwin != NULL);
GString *res = g_string_new("Chat ");
PContact contact = roster_get_contact(chatwin->barejid);
if (contact == NULL) {
g_string_append(res, chatwin->barejid);
} else {
const char *display_name = p_contact_name_or_jid(contact);
g_string_append(res, display_name);
g_string_append_printf(res, " - %s", p_contact_presence(contact));
}
if (chatwin->unread > 0) {
g_string_append_printf(res, ", %d unread", chatwin->unread);
}
char *resstr = res->str;
g_string_free(res, FALSE);
return resstr;
}
static void static void
_chatwin_history(ProfChatWin *chatwin, const char *const contact) _chatwin_history(ProfChatWin *chatwin, const char *const contact)
{ {

View File

@ -35,6 +35,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#ifdef HAVE_NCURSESW_NCURSES_H #ifdef HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h> #include <ncursesw/ncurses.h>
@ -1901,6 +1902,14 @@ cons_alert(void)
} }
} }
char*
cons_get_string(ProfConsoleWin *conswin)
{
assert(conswin != NULL);
return strdup("Console");
}
void void
cons_theme_colours(void) cons_theme_colours(void)
{ {

View File

@ -328,3 +328,20 @@ _mucconfwin_form_field(ProfWin *window, char *tag, FormField *field)
break; break;
} }
} }
char*
mucconfwin_get_string(ProfMucConfWin *confwin)
{
assert(confwin != NULL);
GString *res = g_string_new("");
char *title = win_get_title((ProfWin*)confwin);
g_string_append(res, title);
free(title);
char *resstr = res->str;
g_string_free(res, FALSE);
return resstr;
}

View File

@ -773,3 +773,20 @@ mucwin_hide_occupants(ProfMucWin *mucwin)
} }
} }
char*
mucwin_get_string(ProfMucWin *mucwin)
{
assert(mucwin != NULL);
GString *res = g_string_new("Room ");
g_string_append(res, mucwin->roomjid);
if (mucwin->unread > 0) {
g_string_append_printf(res, ", %d unread", mucwin->unread);
}
char *resstr = res->str;
g_string_free(res, FALSE);
return resstr;
}

View File

@ -107,3 +107,21 @@ privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message)
win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message);
} }
char*
privwin_get_string(ProfPrivateWin *privwin)
{
assert(privwin != NULL);
GString *res = g_string_new("Private ");
g_string_append(res, privwin->fulljid);
if (privwin->unread > 0) {
g_string_append_printf(res, ", %d unread", privwin->unread);
}
char *resstr = res->str;
g_string_free(res, FALSE);
return resstr;
}

View File

@ -134,6 +134,8 @@ void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message); void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message);
void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity); void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity);
void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status); void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status);
char* chatwin_get_string(ProfChatWin *chatwin);
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted); void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted);
void chatwin_otr_unsecured(ProfChatWin *chatwin); void chatwin_otr_unsecured(ProfChatWin *chatwin);
@ -187,10 +189,12 @@ void mucwin_role_set_error(ProfMucWin *mucwin, const char *const nick, const cha
void mucwin_role_list_error(ProfMucWin *mucwin, const char *const role, const char *const error); void mucwin_role_list_error(ProfMucWin *mucwin, const char *const role, const char *const error);
void mucwin_handle_role_list(ProfMucWin *mucwin, const char *const role, GSList *nicks); void mucwin_handle_role_list(ProfMucWin *mucwin, const char *const role, GSList *nicks);
void mucwin_kick_error(ProfMucWin *mucwin, const char *const nick, const char *const error); void mucwin_kick_error(ProfMucWin *mucwin, const char *const nick, const char *const error);
char* mucwin_get_string(ProfMucWin *mucwin);
// MUC private chat window // MUC private chat window
void privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDateTime *timestamp); void privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDateTime *timestamp);
void privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message); void privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message);
char* privwin_get_string(ProfPrivateWin *privwin);
// MUC room config window // MUC room config window
void mucconfwin_handle_configuration(ProfMucConfWin *confwin, DataForm *form); void mucconfwin_handle_configuration(ProfMucConfWin *confwin, DataForm *form);
@ -198,9 +202,11 @@ void mucconfwin_show_form(ProfMucConfWin *confwin);
void mucconfwin_show_form_field(ProfMucConfWin *confwin, DataForm *form, char *tag); void mucconfwin_show_form_field(ProfMucConfWin *confwin, DataForm *form, char *tag);
void mucconfwin_form_help(ProfMucConfWin *confwin); void mucconfwin_form_help(ProfMucConfWin *confwin);
void mucconfwin_field_help(ProfMucConfWin *confwin, char *tag); void mucconfwin_field_help(ProfMucConfWin *confwin, char *tag);
char* mucconfwin_get_string(ProfMucConfWin *confwin);
// xml console // xml console
void xmlwin_show(ProfXMLWin *xmlwin, const char *const msg); void xmlwin_show(ProfXMLWin *xmlwin, const char *const msg);
char* xmlwin_get_string(ProfXMLWin *xmlwin);
// Input window // Input window
char* inp_readline(void); char* inp_readline(void);
@ -232,6 +238,7 @@ void cons_show_contacts(GSList *list);
void cons_show_roster(GSList *list); void cons_show_roster(GSList *list);
void cons_show_roster_group(const char *const group, GSList *list); void cons_show_roster_group(const char *const group, GSList *list);
void cons_show_wins(void); void cons_show_wins(void);
char* cons_get_string(ProfConsoleWin *conswin);
void cons_show_status(const char *const barejid); void cons_show_status(const char *const barejid);
void cons_show_info(PContact pcontact); void cons_show_info(PContact pcontact);
void cons_show_caps(const char *const fulljid, resource_presence_t presence); void cons_show_caps(const char *const fulljid, resource_presence_t presence);
@ -336,6 +343,7 @@ void win_show_info(ProfWin *window, PContact contact);
void win_println(ProfWin *window, int pad, const char *const message); void win_println(ProfWin *window, int pad, const char *const message);
void win_vprintln_ch(ProfWin *window, char ch, const char *const message, ...); void win_vprintln_ch(ProfWin *window, char ch, const char *const message, ...);
void win_clear(ProfWin *window); void win_clear(ProfWin *window);
char* win_get_string(ProfWin *window);
// desktop notifications // desktop notifications
void notifier_initialise(void); void notifier_initialise(void);

View File

@ -285,6 +285,47 @@ win_get_title(ProfWin *window)
return NULL; return NULL;
} }
char*
win_get_string(ProfWin *window)
{
assert(window != NULL);
switch (window->type) {
case WIN_CONSOLE:
{
ProfConsoleWin *conswin = (ProfConsoleWin*)window;
return cons_get_string(conswin);
}
case WIN_CHAT:
{
ProfChatWin *chatwin = (ProfChatWin*)window;
return chatwin_get_string(chatwin);
}
case WIN_MUC:
{
ProfMucWin *mucwin = (ProfMucWin*)window;
return mucwin_get_string(mucwin);
}
case WIN_MUC_CONFIG:
{
ProfMucConfWin *mucconfwin = (ProfMucConfWin*)window;
return mucconfwin_get_string(mucconfwin);
}
case WIN_PRIVATE:
{
ProfPrivateWin *privwin = (ProfPrivateWin*)window;
return privwin_get_string(privwin);
}
case WIN_XML:
{
ProfXMLWin *xmlwin = (ProfXMLWin*)window;
return xmlwin_get_string(xmlwin);
}
default:
return NULL;
}
}
void void
win_hide_subwin(ProfWin *window) win_hide_subwin(ProfWin *window)
{ {

View File

@ -53,3 +53,11 @@ xmlwin_show(ProfXMLWin *xmlwin, const char *const msg)
win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", ""); win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", "");
} }
} }
char*
xmlwin_get_string(ProfXMLWin *xmlwin)
{
assert(xmlwin != NULL);
return strdup("XML console");
}

View File

@ -657,106 +657,26 @@ wins_create_summary(void)
while (curr) { while (curr) {
ProfWin *window = g_hash_table_lookup(windows, curr->data); ProfWin *window = g_hash_table_lookup(windows, curr->data);
GString *line = g_string_new("");
int ui_index = GPOINTER_TO_INT(curr->data); int ui_index = GPOINTER_TO_INT(curr->data);
char *winstring = win_get_string(window);
GString *chat_string; if (!winstring) {
GString *priv_string; g_string_free(line, TRUE);
GString *muc_string; continue;
GString *muc_config_string;
GString *xml_string;
switch (window->type)
{
case WIN_CONSOLE:
result = g_slist_append(result, strdup("1: Console"));
break;
case WIN_CHAT:
chat_string = g_string_new("");
ProfChatWin *chatwin = (ProfChatWin*)window;
PContact contact = roster_get_contact(chatwin->barejid);
if (contact == NULL) {
g_string_printf(chat_string, "%d: Chat %s", ui_index, chatwin->barejid);
} else {
const char *display_name = p_contact_name_or_jid(contact);
g_string_printf(chat_string, "%d: Chat %s", ui_index, display_name);
GString *chat_presence = g_string_new("");
g_string_printf(chat_presence, " - %s", p_contact_presence(contact));
g_string_append(chat_string, chat_presence->str);
g_string_free(chat_presence, TRUE);
}
if (chatwin->unread > 0) {
GString *chat_unread = g_string_new("");
g_string_printf(chat_unread, ", %d unread", chatwin->unread);
g_string_append(chat_string, chat_unread->str);
g_string_free(chat_unread, TRUE);
}
result = g_slist_append(result, strdup(chat_string->str));
g_string_free(chat_string, TRUE);
break;
case WIN_PRIVATE:
priv_string = g_string_new("");
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
g_string_printf(priv_string, "%d: Private %s", ui_index, privatewin->fulljid);
if (privatewin->unread > 0) {
GString *priv_unread = g_string_new("");
g_string_printf(priv_unread, ", %d unread", privatewin->unread);
g_string_append(priv_string, priv_unread->str);
g_string_free(priv_unread, TRUE);
}
result = g_slist_append(result, strdup(priv_string->str));
g_string_free(priv_string, TRUE);
break;
case WIN_MUC:
muc_string = g_string_new("");
ProfMucWin *mucwin = (ProfMucWin*)window;
g_string_printf(muc_string, "%d: Room %s", ui_index, mucwin->roomjid);
if (mucwin->unread > 0) {
GString *muc_unread = g_string_new("");
g_string_printf(muc_unread, ", %d unread", mucwin->unread);
g_string_append(muc_string, muc_unread->str);
g_string_free(muc_unread, TRUE);
}
result = g_slist_append(result, strdup(muc_string->str));
g_string_free(muc_string, TRUE);
break;
case WIN_MUC_CONFIG:
muc_config_string = g_string_new("");
char *title = win_get_title(window);
g_string_printf(muc_config_string, "%d: %s", ui_index, title);
result = g_slist_append(result, strdup(muc_config_string->str));
g_string_free(muc_config_string, TRUE);
free(title);
break;
case WIN_XML:
xml_string = g_string_new("");
g_string_printf(xml_string, "%d: XML console", ui_index);
result = g_slist_append(result, strdup(xml_string->str));
g_string_free(xml_string, TRUE);
break;
default:
break;
} }
g_string_append_printf(line, "%d: %s", ui_index, winstring);
free(winstring);
result = g_slist_append(result, strdup(line->str));
g_string_free(line, TRUE);
curr = g_list_next(curr); curr = g_list_next(curr);
} }
g_list_free(keys); g_list_free(keys);
return result; return result;
} }