* Per-Henrik Lundblom <p...@whatever.nu> [111219 13:42]:
 
> Suggestions? If not, I will just email a patch. How are patches handled,
> emailed to list or pushed into some repo?

Didn't get any feedback on this so I attach the patche to the list. I'm
not sure if it is the cleanest solution. Moved color scheme string
conversion to Utils class. This piece of code is only used by
BuddyListBuddy and BuddyListContact and doesn't really fit into the top
BuddyListNode class.

/PH

--
Per-Henrik Lundblom           epost: p...@whatever.nu
telefon: 0733-20 71 26        hemsida: www.whatever.nu

>From 10911322186540871b069f4a8e64ca1c03a5b98e Mon Sep 17 00:00:00 2001
From: Per-Henrik Lundblom <p...@whatever.nu>
Date: Tue, 20 Dec 2011 11:56:01 +0100
Subject: [PATCH] Contact color scheme depending on contact status

---
 src/BuddyListNode.cpp |   21 ++++++++++++++++++
 src/BuddyListNode.h   |    2 +
 src/CenterIM.cpp      |   22 +++++++++++++++++++
 src/Utils.cpp         |   55 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/Utils.h           |    1 +
 5 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/src/BuddyListNode.cpp b/src/BuddyListNode.cpp
index 51b2a00..f74418f 100644
--- a/src/BuddyListNode.cpp
+++ b/src/BuddyListNode.cpp
@@ -228,6 +228,8 @@ void BuddyListBuddy::Update()
 
   SortIn();
 
+  UpdateColorScheme();
+
   if (!purple_account_is_connected(purple_buddy_get_account(buddy))) {
     // hide if account is offline
     SetVisibility(false);
@@ -341,6 +343,14 @@ BuddyListBuddy::BuddyListBuddy(PurpleBlistNode *node)
   buddy = reinterpret_cast<PurpleBuddy*>(node);
 }
 
+void BuddyListBuddy::UpdateColorScheme(void)
+{
+  char *new_scheme = Utils::GetColorSchemeString("buddylistbuddy", buddy);
+
+  SetColorScheme(new_scheme);
+  g_free(new_scheme);
+}
+
 bool BuddyListChat::LessThan(const BuddyListNode& other) const
 {
   const BuddyListChat *o = dynamic_cast<const BuddyListChat*>(&other);
@@ -513,6 +523,8 @@ void BuddyListContact::Update()
 
   SortIn();
 
+  UpdateColorScheme();
+
   if (!purple_account_is_connected(purple_buddy_get_account(buddy))) {
     // hide if account is offline
     SetVisibility(false);
@@ -645,6 +657,15 @@ BuddyListContact::BuddyListContact(PurpleBlistNode *node)
   contact = reinterpret_cast<PurpleContact*>(node);
 }
 
+void BuddyListContact::UpdateColorScheme(void)
+{
+  PurpleBuddy *buddy = purple_contact_get_priority_buddy(contact);
+  char *new_scheme = Utils::GetColorSchemeString("buddylistcontact", buddy);
+
+  SetColorScheme(new_scheme);
+  g_free(new_scheme);
+}
+
 bool BuddyListGroup::LessThan(const BuddyListNode& other) const
 {
   const BuddyListGroup *o = dynamic_cast<const BuddyListGroup*>(&other);
diff --git a/src/BuddyListNode.h b/src/BuddyListNode.h
index 41f5126..badcc1e 100644
--- a/src/BuddyListNode.h
+++ b/src/BuddyListNode.h
@@ -148,6 +148,7 @@ private:
   BuddyListBuddy(const BuddyListBuddy&);
   BuddyListBuddy& operator=(const BuddyListBuddy&);
   virtual ~BuddyListBuddy() {}
+  void UpdateColorScheme(void);
 };
 
 class BuddyListChat
@@ -248,6 +249,7 @@ private:
   BuddyListContact(const BuddyListContact&);
   BuddyListContact& operator=(const BuddyListContact&);
   virtual ~BuddyListContact() {}
+  void UpdateColorScheme(void);
 };
 
 class BuddyListGroup
diff --git a/src/CenterIM.cpp b/src/CenterIM.cpp
index c8d3c4c..4f65d88 100644
--- a/src/CenterIM.cpp
+++ b/src/CenterIM.cpp
@@ -259,6 +259,28 @@ void CenterIM::ColorSchemeInit()
       CppConsUI::Curses::Color::YELLOW, CppConsUI::Curses::Color::BLACK,
       CppConsUI::Curses::Attr::BOLD);
 
+  COLORSCHEME->SetColorPair("buddylistbuddy", "button", "normal",
+      CppConsUI::Curses::Color::RED, CppConsUI::Curses::Color::BLACK);
+  COLORSCHEME->SetColorPair("buddylistbuddy_offline", "button", "normal",
+      CppConsUI::Curses::Color::RED, CppConsUI::Curses::Color::BLACK);
+  COLORSCHEME->SetColorPair("buddylistbuddy_online", "button", "normal",
+      CppConsUI::Curses::Color::GREEN, CppConsUI::Curses::Color::BLACK);
+  COLORSCHEME->SetColorPair("buddylistbuddy_na", "button", "normal",
+      CppConsUI::Curses::Color::YELLOW, CppConsUI::Curses::Color::BLACK);
+  COLORSCHEME->SetColorPair("buddylistbuddy_away", "button", "normal",
+      CppConsUI::Curses::Color::BLUE, CppConsUI::Curses::Color::BLACK);
+
+  COLORSCHEME->SetColorPair("buddylistcontact", "button", "normal",
+      CppConsUI::Curses::Color::RED, CppConsUI::Curses::Color::BLACK);
+  COLORSCHEME->SetColorPair("buddylistcontact_offline", "button", "normal",
+      CppConsUI::Curses::Color::RED, CppConsUI::Curses::Color::BLACK);
+  COLORSCHEME->SetColorPair("buddylistcontact_online", "button", "normal",
+      CppConsUI::Curses::Color::GREEN, CppConsUI::Curses::Color::BLACK);
+  COLORSCHEME->SetColorPair("buddylistcontact_na", "button", "normal",
+      CppConsUI::Curses::Color::YELLOW, CppConsUI::Curses::Color::BLACK);
+  COLORSCHEME->SetColorPair("buddylistcontact_away", "button", "normal",
+      CppConsUI::Curses::Color::BLUE, CppConsUI::Curses::Color::BLACK);
+
   COLORSCHEME->SetColorPair("conversation", "textview", "text",
       CppConsUI::Curses::Color::MAGENTA, CppConsUI::Curses::Color::BLACK);
   COLORSCHEME->SetColorPair("conversation", "textview", "color1",
diff --git a/src/Utils.cpp b/src/Utils.cpp
index ddf6c04..11336f8 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -56,4 +56,59 @@ const char *GetStatusIndicator(PurpleStatus *status)
   }
 }
 
+char *GetColorSchemeString(const char *base_color_scheme, PurpleBuddy *buddy)
+{
+  char *text;
+
+  if (!purple_account_is_connected(purple_buddy_get_account(buddy))) {
+    text = g_strdup_printf("%s_offline", base_color_scheme);
+    return text;
+  }
+
+  PurplePresence *presence = purple_buddy_get_presence(buddy);
+  PurpleStatus *status = purple_presence_get_active_status(presence);
+  PurpleStatusType *status_type = purple_status_get_type(status);
+  PurpleStatusPrimitive prim = purple_status_type_get_primitive(status_type);
+
+  switch (prim) {
+    case PURPLE_STATUS_UNSET:
+      text = g_strdup_printf("%s_offline", base_color_scheme);
+      break;
+    case PURPLE_STATUS_OFFLINE:
+      text = g_strdup_printf("%s_offline", base_color_scheme);
+      break;
+    case PURPLE_STATUS_AVAILABLE:
+      text = g_strdup_printf("%s_online", base_color_scheme);
+      break;
+    case PURPLE_STATUS_UNAVAILABLE:
+      text = g_strdup_printf("%s_na", base_color_scheme);
+      break;
+    case PURPLE_STATUS_INVISIBLE:
+      text = g_strdup_printf("%s_na", base_color_scheme);
+      break;
+    case PURPLE_STATUS_AWAY:
+      text = g_strdup_printf("%s_away", base_color_scheme);
+      break;
+    case PURPLE_STATUS_EXTENDED_AWAY:
+      text = g_strdup_printf("%s_away", base_color_scheme);
+      break;
+    case PURPLE_STATUS_MOBILE:
+      text = g_strdup_printf("%s_online", base_color_scheme);
+      break;
+    case PURPLE_STATUS_TUNE:
+      text = g_strdup_printf("%s_online", base_color_scheme);
+      break;
+#if PURPLE_VERSION_CHECK(2, 7, 0)
+    case PURPLE_STATUS_MOOD:
+      text = g_strdup_printf("%s_online", base_color_scheme);
+      break;
+#endif
+    default:
+      text = g_strdup_printf("%s_offline", base_color_scheme);
+      break;
+  }
+  
+  return text;
+}
+
 } // namespace utils
diff --git a/src/Utils.h b/src/Utils.h
index 5a71cf1..76ab79b 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -27,6 +27,7 @@ namespace Utils
 {
 
 const char *GetStatusIndicator(PurpleStatus *status);
+char *GetColorSchemeString(const char *base_color_scheme, PurpleBuddy *buddy);
 
 } // namespace Utils
 
-- 
1.7.0.4

-- 
_______________________________________________
Centerim-devel mailing list
Centerim-devel@centerim.org
http://centerim.org/mailman/listinfo/centerim-devel
http://www.centerim.org/

Reply via email to