im.pidgin.pidgin: 2996670bdeb36ac63658ea4760a8a1f2e362e703
sadrul at pidgin.im
sadrul at pidgin.im
Fri Nov 30 14:00:39 EST 2007
-----------------------------------------------------------------
Revision: 2996670bdeb36ac63658ea4760a8a1f2e362e703
Ancestor: 076a7bfc9283437acb17a9e8d87235539b662227
Author: sadrul at pidgin.im
Date: 2007-11-30T18:58:56
Branch: im.pidgin.pidgin
Modified files:
finch/gntblist.c
ChangeLog:
Refactor the code a little bit.
-------------- next part --------------
============================================================
--- finch/gntblist.c cac01acd755fc8dfe697d9fc6871e218a81cbc3d
+++ finch/gntblist.c ff210da5db9b1629954713a9f045de56eb272731
@@ -131,6 +131,32 @@ static int color_idle;
static int color_offline;
static int color_idle;
+static int
+get_display_color(PurpleBlistNode *node)
+{
+ PurpleBuddy *buddy;
+ int color = 0;
+
+ if (PURPLE_BLIST_NODE_IS_CONTACT(node))
+ node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node);
+ if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
+ return 0;
+
+ buddy = (PurpleBuddy*)node;
+ if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) {
+ color = color_idle;
+ } else if (purple_presence_is_available(purple_buddy_get_presence(buddy))) {
+ color = color_available;
+ } else if (purple_presence_is_online(purple_buddy_get_presence(buddy)) &&
+ !purple_presence_is_available(purple_buddy_get_presence(buddy))) {
+ color = color_away;
+ } else if (!purple_presence_is_online(purple_buddy_get_presence(buddy))) {
+ color = color_offline;
+ }
+
+ return color;
+}
+
static gboolean
is_contact_online(PurpleContact *contact)
{
@@ -235,6 +261,7 @@ node_update(PurpleBuddyList *list, Purpl
gnt_tree_change_text(GNT_TREE(ggblist->tree), node,
0, get_display_name(node));
gnt_tree_sort_row(GNT_TREE(ggblist->tree), node);
+ gnt_tree_set_row_color(GNT_TREE(ggblist->tree), node, get_display_color(node));
}
if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
@@ -588,11 +615,11 @@ add_contact(PurpleContact *contact, Finc
if (node->ui_data)
return;
-
+
name = get_display_name(node);
if (name == NULL)
return;
-
+
group = (PurpleGroup*)node->parent;
add_node((PurpleBlistNode*)group, ggblist);
@@ -608,6 +635,7 @@ add_buddy(PurpleBuddy *buddy, FinchBlist
{
PurpleContact *contact;
PurpleBlistNode *node = (PurpleBlistNode *)buddy;
+ int color = 0;
if (node->ui_data)
return;
@@ -623,20 +651,10 @@ add_buddy(PurpleBuddy *buddy, FinchBlist
gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)),
contact, NULL);
- if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) {
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_idle);
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_idle);
- } else if (purple_presence_is_available(purple_buddy_get_presence(buddy)) && color_available) {
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_available);
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_available);
- } else if (purple_presence_is_online(purple_buddy_get_presence(buddy)) &&
- !purple_presence_is_available(purple_buddy_get_presence(buddy)) && color_away) {
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_away);
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_away);
- } else if (!purple_presence_is_online(purple_buddy_get_presence(buddy)) && color_offline) {
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_offline);
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_offline);
- }
+ color = get_display_color((PurpleBlistNode*)buddy);
+ gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color);
+ if (buddy == purple_contact_get_priority_buddy(contact))
+ gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color);
}
#if 0
@@ -1557,7 +1575,8 @@ update_buddy_display(PurpleBuddy *buddy,
{
PurpleContact *contact;
GntTextFormatFlags bflag = 0, cflag = 0;
-
+ int color = 0;
+
contact = purple_buddy_get_contact(buddy);
gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, 0, get_display_name((PurpleBlistNode*)buddy));
@@ -1571,28 +1590,11 @@ update_buddy_display(PurpleBuddy *buddy,
if (ggblist->tnode == (PurpleBlistNode*)buddy)
draw_tooltip(ggblist);
- if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) {
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_idle);
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_idle);
- if (buddy == purple_contact_get_priority_buddy(contact))
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_idle);
- } else if (purple_presence_is_available(purple_buddy_get_presence(buddy)) && color_available) {
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_available);
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_available);
- if (buddy == purple_contact_get_priority_buddy(contact))
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_available);
- } else if (purple_presence_is_online(purple_buddy_get_presence(buddy)) &&
- !purple_presence_is_available(purple_buddy_get_presence(buddy)) && color_away) {
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_away);
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_away);
- if (buddy == purple_contact_get_priority_buddy(contact))
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_away);
- } else if (!purple_presence_is_online(purple_buddy_get_presence(buddy)) && color_offline) {
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_offline);
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_offline);
- if (buddy == purple_contact_get_priority_buddy(contact))
- gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_offline);
- }
+ color = get_display_color((PurpleBlistNode*)buddy);
+ gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color);
+ if (buddy == purple_contact_get_priority_buddy(contact))
+ gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color);
+
gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag);
if (buddy == purple_contact_get_priority_buddy(contact))
gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, cflag);
More information about the Commits
mailing list