soylent r287 - trunk/libsoylent



Author: svenp
Date: Mon Aug 18 10:18:34 2008
New Revision: 287
URL: http://svn.gnome.org/viewvc/soylent?rev=287&view=rev

Log:
improved list-printing functions
added utility-functions for IM-contacts and accounts

Modified:
   trunk/libsoylent/sl-priv-util.c
   trunk/libsoylent/sl-priv-util.h

Modified: trunk/libsoylent/sl-priv-util.c
==============================================================================
--- trunk/libsoylent/sl-priv-util.c	(original)
+++ trunk/libsoylent/sl-priv-util.c	Mon Aug 18 10:18:34 2008
@@ -94,15 +94,35 @@
   return (g_list_find_custom (list, data, sl_priv_util_compare_by_equal) != NULL);
 }
 
+gchar *
+sl_priv_util_imcontact_to_string (EmpathyContact *imcontact)
+{
+  g_return_val_if_fail (imcontact != NULL && EMPATHY_IS_CONTACT (imcontact), NULL);
+  
+  GString *gstr = g_string_new ("");
+  g_string_printf (gstr, "EmpathyContact [%s, %s]",
+    empathy_contact_get_name (imcontact), empathy_contact_get_id (imcontact));
+  gchar *str = gstr->str;
+  g_string_free (gstr, FALSE);
+  return str;
+}
+
 void
-sl_priv_util_list_print (GList *list, const gchar *title)
+sl_priv_util_list_print (GList *list, const gchar *title, SlPrivUtilToStringFunc to_string)
 {
   g_return_if_fail (title != NULL);
   
   g_print ("%s (%d):\n", title, g_list_length (list));
   for (; list != NULL; list = list->next)
     {
-      g_print (" * %s\n", (gchar *) list->data);
+      if (to_string == NULL)
+        {
+          g_print (" * %s\n", (gchar *) list->data);
+        }
+      else
+        {
+          g_print (" * %s\n", to_string (list->data));
+        }
     }
 }
 
@@ -156,7 +176,7 @@
   g_return_if_fail (table != NULL && title != NULL);
   
   GList *keys = g_hash_table_get_keys (table);
-  sl_priv_util_list_print (keys, title);
+  sl_priv_util_list_print (keys, title, NULL);
   g_list_free (keys);
 }
 
@@ -423,3 +443,23 @@
   *strvp = NULL;
   return strv;
 }
+
+gchar *
+sl_priv_util_get_account_id_from_imcontact (EmpathyContact *imcontact)
+{
+  McAccount *account = empathy_contact_get_account (imcontact);
+  gchar *id = NULL;
+  if (mc_account_get_param_string (account, "account", &id) == MC_ACCOUNT_SETTING_ABSENT)
+    {
+      g_critical ("failed to get account-id");
+    }
+  return id;
+}
+
+const gchar *
+sl_priv_util_get_protocol_name_from_account (McAccount *account)
+{
+  McProfile *profile = mc_account_get_profile (account);
+  McProtocol *protocol = mc_profile_get_protocol (profile);
+  return mc_protocol_get_name (protocol);
+}

Modified: trunk/libsoylent/sl-priv-util.h
==============================================================================
--- trunk/libsoylent/sl-priv-util.h	(original)
+++ trunk/libsoylent/sl-priv-util.h	Mon Aug 18 10:18:34 2008
@@ -25,8 +25,10 @@
 #define SL_PRIV_UTIL_H
 
 #include <libebook/e-book.h>
+#include <libempathy/empathy-contact.h>
 
 /*#define SL_ENABLE_DEBUG_ALL*/
+#define SL_ENABLE_DEBUG_BOOK
 
 #define sl_debug(unit, format, ...) g_printerr ("dbg[%s]: ", unit); \
                                     g_printerr (format, __VA_ARGS__); \
@@ -60,6 +62,8 @@
   #define sl_debug_util(format, ...)
 #endif
 
+typedef gchar * (*SlPrivUtilToStringFunc)(gpointer data);
+
 ESource *sl_priv_util_get_source (ESourceList *source_tree, const gchar *name);
 ESourceGroup *sl_priv_util_source_tree_get_default_group
   (ESourceList *source_tree);
@@ -68,7 +72,8 @@
 gboolean sl_priv_util_list_contains (GList *list, gpointer data, GEqualFunc equal);
 void sl_priv_util_hash_table_print (GHashTable *table, const gchar *title);
 void sl_priv_util_hash_table_print_keys (GHashTable *table, const gchar *title);
-void sl_priv_util_list_print (GList *list, const gchar *title);
+gchar *sl_priv_util_imcontact_to_string (EmpathyContact *imcontact);
+void sl_priv_util_list_print (GList *list, const gchar *title, SlPrivUtilToStringFunc to_string);
 void sl_priv_util_eattribute_list_print (GList *eattributes, const gchar *title);
 void sl_priv_util_attribute_list_print (GList *attributes, const gchar *title);
 
@@ -89,4 +94,7 @@
 GList *sl_priv_util_strv_to_list (gchar **strv);
 gchar **sl_priv_util_list_to_strv (GList *strings);
 
+gchar *sl_priv_util_get_account_id_from_imcontact (EmpathyContact *imcontact);
+const gchar *sl_priv_util_get_protocol_name_from_account (McAccount *account);
+
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]