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

Changed type to enum for presence colour attributes

This commit is contained in:
James Booth 2014-11-16 23:37:07 +00:00
parent b60a5b08c0
commit 74d9937573
6 changed files with 39 additions and 39 deletions

View File

@ -558,6 +558,24 @@ _theme_find(const char * const theme_name)
return path;
}
theme_item_t
theme_main_presence_attrs(const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ONLINE;
} else if (g_strcmp0(presence, "away") == 0) {
return THEME_AWAY;
} else if (g_strcmp0(presence, "chat") == 0) {
return THEME_CHAT;
} else if (g_strcmp0(presence, "dnd") == 0) {
return THEME_DND;
} else if (g_strcmp0(presence, "xa") == 0) {
return THEME_XA;
} else {
return THEME_OFFLINE;
}
}
int
theme_attrs(theme_item_t attrs)
{

View File

@ -99,5 +99,6 @@ gboolean theme_load(const char * const theme_name);
GSList* theme_list(void);
void theme_close(void);
int theme_attrs(theme_item_t attrs);
theme_item_t theme_main_presence_attrs(const char * const presence);
#endif

View File

@ -230,7 +230,7 @@ _cons_show_login_success(ProfAccount *account)
resource_presence_t presence = accounts_get_login_presence(account->name);
const char *presence_str = string_from_resource_presence(presence);
int presence_colour = win_presence_colour(presence_str);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str);
win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
@ -292,7 +292,7 @@ _cons_show_caps(const char * const fulljid, resource_presence_t presence)
if (caps) {
const char *resource_presence = string_from_resource_presence(presence);
int presence_colour = win_presence_colour(resource_presence);
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid);
win_save_print(console, '-', NULL, NO_DATE, 0, "", ":");
@ -359,7 +359,7 @@ _cons_show_software_version(const char * const jid, const char * const presence
ProfWin *console = wins_get_console();
if ((name != NULL) || (version != NULL) || (os != NULL)) {
cons_show("");
int presence_colour = win_presence_colour(presence);
theme_item_t presence_colour = theme_main_presence_attrs(presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid);
win_save_print(console, '-', NULL, NO_DATE, 0, "", ":");
}
@ -611,7 +611,7 @@ _cons_show_account_list(gchar **accounts)
if ((jabber_get_connection_status() == JABBER_CONNECTED) &&
(g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) {
resource_presence_t presence = accounts_get_last_presence(accounts[i]);
int presence_colour = win_presence_colour(string_from_resource_presence(presence));
theme_item_t presence_colour = theme_main_presence_attrs(string_from_resource_presence(presence));
win_save_vprint(console, '-', NULL, 0, presence_colour, "", "%s", accounts[i]);
} else {
cons_show(accounts[i]);
@ -730,7 +730,7 @@ _cons_show_account(ProfAccount *account)
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
int presence_colour = win_presence_colour(resource_presence);
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
@ -1524,9 +1524,9 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
const char *presence = p_contact_presence(contact);
theme_item_t presence_colour = THEME_TEXT;
if (p_contact_subscribed(contact)) {
presence_colour = win_presence_colour(presence);
presence_colour = theme_main_presence_attrs(presence);
} else {
presence_colour = win_presence_colour("offline");
presence_colour = theme_main_presence_attrs("offline");
}
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", title->str);

View File

@ -1576,7 +1576,7 @@ _ui_room_roster(const char * const room, GList *roster, const char * const prese
Occupant *occupant = roster->data;
const char *presence_str = string_from_resource_presence(occupant->presence);
int presence_colour = win_presence_colour(presence_str);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick);
if (roster->next != NULL) {
@ -2830,7 +2830,7 @@ _ui_roster_contact(PContact contact)
if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) &&
(prefs_get_boolean(PREF_ROSTER_OFFLINE)))) {
theme_item_t presence_colour = win_presence_colour(presence);
theme_item_t presence_colour = theme_main_presence_attrs(presence);
wattron(window->subwin, theme_attrs(presence_colour));
@ -2847,7 +2847,7 @@ _ui_roster_contact(PContact contact)
while (curr_resource) {
Resource *resource = curr_resource->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
theme_item_t resource_presence_colour = win_presence_colour(resource_presence);
theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence);
wattron(window->subwin, theme_attrs(resource_presence_colour));
GString *msg = g_string_new(" ");
@ -2989,7 +2989,7 @@ _ui_muc_roster(const char * const room)
Occupant *occupant = roster_curr->data;
if (occupant->role == MUC_ROLE_MODERATOR) {
const char *presence_str = string_from_resource_presence(occupant->presence);
theme_item_t presence_colour = win_presence_colour(presence_str);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
wattron(window->subwin, theme_attrs(presence_colour));
GString *msg = g_string_new(" ");
@ -3010,7 +3010,7 @@ _ui_muc_roster(const char * const room)
Occupant *occupant = roster_curr->data;
if (occupant->role == MUC_ROLE_PARTICIPANT) {
const char *presence_str = string_from_resource_presence(occupant->presence);
theme_item_t presence_colour = win_presence_colour(presence_str);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
wattron(window->subwin, theme_attrs(presence_colour));
GString *msg = g_string_new(" ");
@ -3031,7 +3031,7 @@ _ui_muc_roster(const char * const room)
Occupant *occupant = roster_curr->data;
if (occupant->role == MUC_ROLE_VISITOR) {
const char *presence_str = string_from_resource_presence(occupant->presence);
theme_item_t presence_colour = win_presence_colour(presence_str);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
wattron(window->subwin, theme_attrs(presence_colour));
GString *msg = g_string_new(" ");
@ -3051,7 +3051,7 @@ _ui_muc_roster(const char * const room)
while (roster_curr) {
Occupant *occupant = roster_curr->data;
const char *presence_str = string_from_resource_presence(occupant->presence);
theme_item_t presence_colour = win_presence_colour(presence_str);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
wattron(window->subwin, theme_attrs(presence_colour));
GString *msg = g_string_new(" ");

View File

@ -191,30 +191,12 @@ win_move_to_end(ProfWin *window)
}
}
theme_item_t
win_presence_colour(const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
return THEME_ONLINE;
} else if (g_strcmp0(presence, "away") == 0) {
return THEME_AWAY;
} else if (g_strcmp0(presence, "chat") == 0) {
return THEME_CHAT;
} else if (g_strcmp0(presence, "dnd") == 0) {
return THEME_DND;
} else if (g_strcmp0(presence, "xa") == 0) {
return THEME_XA;
} else {
return THEME_OFFLINE;
}
}
void
win_show_occupant(ProfWin *window, Occupant *occupant)
{
const char *presence_str = string_from_resource_presence(occupant->presence);
theme_item_t presence_colour = win_presence_colour(presence_str);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick);
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
@ -235,7 +217,7 @@ win_show_contact(ProfWin *window, PContact contact)
const char *status = p_contact_status(contact);
GDateTime *last_activity = p_contact_last_activity(contact);
theme_item_t presence_colour = win_presence_colour(presence);
theme_item_t presence_colour = theme_main_presence_attrs(presence);
if (name != NULL) {
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", name);
@ -277,7 +259,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
const char *occupant_affiliation = muc_occupant_affiliation_str(occupant);
const char *occupant_role = muc_occupant_role_str(occupant);
theme_item_t presence_colour = win_presence_colour(presence_str);
theme_item_t presence_colour = theme_main_presence_attrs(presence_str);
win_save_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick);
win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str);
@ -355,7 +337,7 @@ win_show_info(ProfWin *window, PContact contact)
GList *ordered_resources = NULL;
GDateTime *last_activity = p_contact_last_activity(contact);
theme_item_t presence_colour = win_presence_colour(presence);
theme_item_t presence_colour = theme_main_presence_attrs(presence);
win_save_print(window, '-', NULL, 0, 0, "", "");
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
@ -403,7 +385,7 @@ win_show_info(ProfWin *window, PContact contact)
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
int presence_colour = win_presence_colour(resource_presence);
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
@ -469,7 +451,7 @@ win_show_status_string(ProfWin *window, const char * const from,
theme_item_t presence_colour;
if (show != NULL) {
presence_colour = win_presence_colour(show);
presence_colour = theme_main_presence_attrs(show);
} else if (strcmp(default_show, "online") == 0) {
presence_colour = THEME_ONLINE;
} else {

View File

@ -86,7 +86,6 @@ ProfWin* win_create(const char * const title, win_type_t type);
void win_free(ProfWin *window);
void win_update_virtual(ProfWin *window);
void win_move_to_end(ProfWin *window);
theme_item_t win_presence_colour(const char * const presence);
void win_show_contact(ProfWin *window, PContact contact);
void win_show_occupant(ProfWin *window, Occupant *occupant);
void win_show_status_string(ProfWin *window, const char * const from,