soylent r54 - trunk/src



Author: treitter
Date: Thu Jan 24 07:30:59 2008
New Revision: 54
URL: http://svn.gnome.org/viewvc/soylent?rev=54&view=rev

Log:
cleaned up more functions (recursively), moved some to more-appropriate files

Modified:
   trunk/src/soylent-browser-person-view.c
   trunk/src/soylent-browser-person-view.h
   trunk/src/soylent-browser.c
   trunk/src/soylent-person.c
   trunk/src/soylent-person.h

Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c	(original)
+++ trunk/src/soylent-browser-person-view.c	Thu Jan 24 07:30:59 2008
@@ -41,16 +41,18 @@
                                     (EBookView *book_view,
                                      const GList *e_contacts,
                                      cb_data_pre_person *pre_person_to_match);
-static void soylent_browser_person_action_chat_menu_item_cb (GtkMenuItem *item,
-                                                gpointer user_data);
+static gboolean soylent_browser_person_action_chat_menu_item_cb
+                                                          (GtkMenuItem *item,
+                                                           gpointer user_data);
 static void soylent_browser_person_selected_chat_menu_update_cb
                                                       (GtkMenuToolButton *btntb,
                                                        gpointer user_data);
-static void soylent_browser_person_action_email_menu_shell_cb
+static gboolean soylent_browser_person_action_email_menu_shell_cb
                                                       (GtkMenuShell *menu_email,
                                                        gpointer user_data);
-static void soylent_browser_person_action_email_menu_item_cb (GtkMenuItem *item,
-                                                            gpointer user_data);
+static gboolean soylent_browser_person_action_email_menu_item_cb
+                                                          (GtkMenuItem *item,
+                                                           gpointer user_data);
 static void soylent_browser_person_selected_email_menu_update_cb
                                                 (GtkMenuToolButton *btntb_email,
                                                  gpointer user_data);
@@ -81,24 +83,24 @@
                                               const gchar *param_val);
 
 /* Setup/update sections of the person view UI with latest data from e-d-s */
-static void soylent_browser_person_view_update        (SoylentBrowser *browser,
-                                                       SoylentPerson *person);
-static void soylent_browser_person_view_email_update  (SoylentBrowser *browser,
-                                                       SoylentPerson *person);
-static void soylent_browser_person_view_im_update     (SoylentBrowser *browser,
-                                                       SoylentPerson *person);
+static void soylent_browser_person_view_update (SoylentBrowser *browser,
+                                                SoylentPerson *person);
+static void soylent_browser_person_view_email_update (SoylentBrowser *browser,
+                                                      SoylentPerson *person);
+static void soylent_browser_person_view_im_update (SoylentBrowser *browser,
+                                                   SoylentPerson *person);
 static void soylent_browser_person_view_avatar_update (SoylentBrowser *browser,
                                                        SoylentPerson *person);
-static void soylent_browser_person_view_mail_update   (SoylentBrowser *browser,
-                                                       SoylentPerson *person);
-static void soylent_browser_person_view_name_update   (SoylentBrowser *browser,
-                                                       SoylentPerson *person);
+static void soylent_browser_person_view_mail_update (SoylentBrowser *browser,
+                                                     SoylentPerson *person);
+static void soylent_browser_person_view_name_update (SoylentBrowser *browser,
+                                                     SoylentPerson *person);
 static void soylent_browser_person_view_detail_add_update
                                                       (SoylentBrowser *browser);
-static void soylent_browser_person_view_phone_update  (SoylentBrowser *browser,
-                                                       SoylentPerson *person);
-static void soylent_browser_person_view_web_update    (SoylentBrowser *browser,
-                                                       SoylentPerson *person);
+static void soylent_browser_person_view_phone_update (SoylentBrowser *browser,
+                                                      SoylentPerson *person);
+static void soylent_browser_person_view_web_update (SoylentBrowser *browser,
+                                                    SoylentPerson *person);
 
 /* FIXME: call soylent_browser_view_save_changes instead of duplicating code */
 /* Save unsaved changes to the person's details and return to Browse Mode */
@@ -387,76 +389,144 @@
 }
 
 /* FIXME: collapse these three following functions if possible */
-/* Handle clicks on the button part of the Email action MenuToolButton */
-void
+/* Handle clicks on the button part of the Email action MenuToolButton
+ *
+ * Return TRUE for success, FALSE for any failure */
+gboolean
 soylent_browser_person_action_email_menu_tool_button_cb
                                                       (GtkMenuToolButton *btntb,
                                                        gpointer user_data)
 {
-  soylent_browser_person_action_email_menu_shell_cb
+  gboolean retval = FALSE;
+
+  retval = soylent_browser_person_action_email_menu_shell_cb
                         (GTK_MENU_SHELL (gtk_menu_tool_button_get_menu (btntb)),
-                         (gpointer) NULL);
+                         user_data);
+
+  return retval;
 }
 
 /* FIXME: use this to replace the few functions before it */
-void
+/* FIXME: should this just be in soylent-browser.c ? */
+gboolean
 soylent_browser_person_action_communicate_email (SoylentBrowser *browser,
                                                  SoylentPerson *person)
 {
+  gboolean retval = FALSE;
   GladeXML *wtree = NULL;
   GtkMenuToolButton *btntb = NULL;
 
+  g_return_val_if_fail (browser != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+   */
+
   wtree = soylent_browser_get_widget_tree (browser);
-  btntb = GTK_MENU_TOOL_BUTTON (glade_xml_get_widget (wtree, "btntb_email"));
+  if (wtree && GLADE_IS_XML (wtree))
+    {
+      btntb = GTK_MENU_TOOL_BUTTON (glade_xml_get_widget (wtree, "btntb_email"));
+      if (btntb && GTK_IS_MENU_TOOL_BUTTON (btntb))
+        {
+          retval = soylent_browser_person_action_chat_menu_tool_button_cb
+                                                                    (btntb,
+                                                                     browser);
+        }
+      else
+        {
+          g_critical ("failed to get the Email button widget");
+        }
+    }
+  else
+    {
+      g_critical ("SoylentBrowser's widget tree is invalid");
+    }
 
-  soylent_browser_person_action_email_menu_tool_button_cb (btntb, browser);
+  return retval;
 }
 
 /* FIXME: collapse these three following functions if possible */
-/* Handle clicks on the button part of the Chat action MenuToolButton */
-void
+/* Handle clicks on the button part of the Chat action MenuToolButton
+ *
+ * Return TRUE for success, FALSE for any failure */
+gboolean
 soylent_browser_person_action_chat_menu_tool_button_cb
                                                       (GtkMenuToolButton *btntb,
                                                        gpointer user_data)
 {
-  soylent_browser_person_action_chat_menu_shell_cb
+  gboolean retval = FALSE;
+
+  retval = soylent_browser_person_action_chat_menu_shell_cb
                         (GTK_MENU_SHELL (gtk_menu_tool_button_get_menu (btntb)),
                          user_data);
+
+  return retval;
 }
 
-/* Handle activation of an item in the Chat action MenuToolButton */
-void
+/* Handle activation of an item in the Chat action MenuToolButton
+ *
+ * Return TRUE for success, FALSE for any failure */
+gboolean
 soylent_browser_person_action_chat_menu_shell_cb (GtkMenuShell *menu_chat,
                                                   gpointer user_data)
 {
+  gboolean retval = FALSE;
   GtkMenu *menu = NULL;
   GtkMenuItem *selected_item = NULL;
 
+  g_return_val_if_fail (menu_chat, retval);
+  g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_chat), retval);
+
   menu = GTK_MENU (menu_chat);
-  if (!menu)
+  selected_item = GTK_MENU_ITEM (gtk_menu_get_active (menu));
+  if (selected_item)
     {
-      return;
+      retval = soylent_browser_person_action_chat_menu_item_cb (selected_item,
+                                                                user_data);
     }
-  if (!(selected_item = GTK_MENU_ITEM (gtk_menu_get_active (menu))))
+  else
     {
-      return;
+      g_warning ("failed to get the selected Chat menu item");
     }
 
-  soylent_browser_person_action_chat_menu_item_cb (selected_item, user_data);
+  return retval;
 }
 
 /* FIXME: use this to replace the few functions before it */
-void
+/* FIXME: should this just be in soylent-browser.c ? */
+gboolean
 soylent_browser_person_action_communicate_chat (SoylentBrowser *browser,
                                                 SoylentPerson *person)
 {
+  gboolean retval = FALSE;
   GladeXML *wtree = NULL;
   GtkMenuToolButton *btntb = NULL;
 
+  g_return_val_if_fail (browser != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+   */
+
   wtree = soylent_browser_get_widget_tree (browser);
-  btntb = GTK_MENU_TOOL_BUTTON (glade_xml_get_widget (wtree, "btntb_chat"));
+  if (wtree && GLADE_IS_XML (wtree))
+    {
+      btntb = GTK_MENU_TOOL_BUTTON (glade_xml_get_widget (wtree, "btntb_chat"));
+      if (btntb && GTK_IS_MENU_TOOL_BUTTON (btntb))
+        {
+          retval = soylent_browser_person_action_chat_menu_tool_button_cb
+                                                                    (btntb,
+                                                                     browser);
+        }
+      else
+        {
+          g_critical ("failed to get the Chat button widget");
+        }
+    }
+  else
+    {
+      g_critical ("SoylentBrowser's widget tree is invalid");
+    }
 
-  soylent_browser_person_action_chat_menu_tool_button_cb (btntb, browser);
+  return retval;
 }
 
 /* Handle a change of who is selected */
@@ -1008,125 +1078,231 @@
   return retval;
 }
 
-/* Handle activation of an item in the Email action MenuToolButton */
-static void
-soylent_browser_person_action_email_menu_shell_cb (GtkMenuShell *menu_email,
+/* Handle activation of an item in the Email action MenuToolButton
+ *
+ * Return TRUE for success, FALSE for any failure */
+gboolean
+soylent_browser_person_action_email_menu_shell_cb (GtkMenuShell *menu_chat,
                                                    gpointer user_data)
 {
+  gboolean retval = FALSE;
   GtkMenu *menu = NULL;
   GtkMenuItem *selected_item = NULL;
 
-  menu = GTK_MENU (menu_email);
+  g_return_val_if_fail (menu_chat, retval);
+  g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_chat), retval);
 
-  if (!menu)
+  menu = GTK_MENU (menu_chat);
+  selected_item = GTK_MENU_ITEM (gtk_menu_get_active (menu));
+  if (selected_item)
     {
-      return;
+      retval = soylent_browser_person_action_email_menu_item_cb (selected_item,
+                                                                 user_data);
     }
-  if (!(selected_item = GTK_MENU_ITEM (gtk_menu_get_active (menu))))
+  else
     {
-      return;
+      g_warning ("failed to get the selected Email menu item");
     }
 
-  soylent_browser_person_action_email_menu_item_cb (selected_item, NULL);
+  return retval;
 }
 
-/* Perform the actual action for an Email action MenuToolButton item */
-static void
+/* Perform the actual action for an Email action MenuToolButton item
+ *
+ * Return TRUE for success, FALSE for any failure */
+static gboolean
 soylent_browser_person_action_email_menu_item_cb (GtkMenuItem *item,
                                                   gpointer user_data)
 {
+  gboolean retval = FALSE;
   GList *selection_children = NULL;
-  GtkLabel *email_addr_label = NULL;
-  const gchar *email_addr = NULL;
-  gchar *mailto = NULL;
-  GError *error = NULL;
 
   selection_children = gtk_container_get_children (GTK_CONTAINER (item));
-  if (!selection_children
-      || !(email_addr_label = GTK_LABEL (selection_children->data))
-      || !(email_addr = gtk_label_get_text (email_addr_label)))
+  if (selection_children)
     {
-      return;
-    }
+      GtkLabel *email_addr_label = NULL;
+
+      email_addr_label = GTK_LABEL (selection_children->data);
+      if (email_addr_label)
+        {
+          const gchar *email_addr = NULL;
+
+          email_addr = gtk_label_get_text (email_addr_label);
+          if (email_addr)
+            {
+              gchar *mailto = NULL;
+
+              mailto = g_strdup_printf ("mailto:%s";, email_addr);
+              if (mailto)
+                {
+                  gboolean url_show_retval = FALSE;
+                  GError *error = NULL;
 
-  mailto = g_strdup_printf ("mailto:%s";, email_addr);
-  if (!gnome_url_show (mailto, &error))
+                  url_show_retval = gnome_url_show (mailto, &error);
+                  if (url_show_retval)
+                    {
+                      retval = TRUE;
+                    }
+                  else
+                    {
+                      g_warning ("Failed to open email window to %s: %s",
+                                email_addr, error->message);
+                      g_error_free (error);
+                    }
+
+                  g_free (mailto);
+                }
+              else
+                {
+                  g_critical ("failed to allocate memory for mailto string");
+                }
+            }
+          else
+            {
+              g_warning ("failed to get Email menu's current email address");
+            }
+        }
+      else
+        {
+          g_warning ("failed to get Email menu's current email address label");
+        }
+    }
+  else
     {
-      g_warning ("Failed to open email window to %s: %s", email_addr,
-                 error->message);
-      g_error_free (error);
+      g_warning ("failed to get selected Email menu item");
     }
-  g_free (mailto);
+
+  return retval;
 }
 
-/* Perform the actual action for an Chat action MenuToolButton item */
-static void
+/* FIXME: this function has way too many levels of logic; split it up */
+/* Perform the actual action for an Chat action MenuToolButton item
+ *
+ * Return TRUE for success, FALSE for any failure */
+static gboolean
 soylent_browser_person_action_chat_menu_item_cb (GtkMenuItem *item,
                                                  gpointer user_data)
 {
+  gboolean retval = FALSE;
   SoylentBrowser *browser = NULL;
-  GList *selection_children = NULL;
-  GtkLabel *im_handle_label = NULL;
-  const gchar *im_handle = NULL;
   McAccount *account = NULL;
   SoylentPerson *person = NULL;
-  GList *live_contacts = NULL;
   EmpathyContactManager *live_manager = NULL;
-  EmpathyContact *live_contact = NULL;
-  MissionControl *mc = NULL;
 
   browser = (SoylentBrowser*) user_data;
-  g_return_if_fail (browser != NULL);
+  g_return_val_if_fail (browser != NULL, retval);
 
   live_manager = soylent_browser_get_live_manager (browser);
-  g_return_if_fail (live_manager != NULL);
-
-  mc = empathy_mission_control_new ();
-  if (!mc)
+  if (live_manager)
     {
-      g_warning ("unable to create new MissionControl");
-      return;
-    }
+      /* FIXME: pick a better name */
+      MissionControl *mission_control = NULL;
 
-  selection_children = gtk_container_get_children (GTK_CONTAINER (item));
-  if (!selection_children
-      || !(im_handle_label = GTK_LABEL (selection_children->data))
-      || !(im_handle = gtk_label_get_text (im_handle_label)))
-    {
-      return;
-    }
+      mission_control = empathy_mission_control_new ();
+      if (mission_control)
+        {
+          GList *selection_children = NULL;
 
-  person = soylent_browser_get_selected_person (browser);
-  if (!person)
-    {
-      return;
-    }
+          selection_children = gtk_container_get_children
+                                                        (GTK_CONTAINER (item));
+          if (selection_children)
+            {
+              GtkLabel *im_handle_label = NULL;
 
-  live_contacts = soylent_person_get_live_contacts (person);
-  for (; live_contacts; live_contacts = g_list_next (live_contacts))
-    {
-      live_contact = EMPATHY_CONTACT (live_contacts->data);
-      if (live_contact
-          && g_str_equal (empathy_contact_get_id (live_contact), im_handle))
+              im_handle_label = GTK_LABEL (selection_children->data);
+              if (im_handle_label && GTK_IS_LABEL (im_handle_label))
+                {
+                  const gchar *im_handle = NULL;
+
+                  im_handle = gtk_label_get_text (im_handle_label);
+                  if (im_handle)
+                    {
+                      person = soylent_browser_get_selected_person (browser);
+                      if (person)
+                        {
+                          GList *live_contacts = NULL;
+                          EmpathyContact *live_contact = NULL;
+
+                          live_contacts = soylent_person_get_live_contacts
+                                                                      (person);
+                          for (; live_contacts;
+                               live_contacts = g_list_next (live_contacts))
+                            {
+                              live_contact = EMPATHY_CONTACT
+                                                          (live_contacts->data);
+                              if (live_contact
+                                  && g_str_equal (empathy_contact_get_id
+                                                                (live_contact),
+                                                  im_handle))
+                                {
+                                  break;
+                                }
+                            }
+
+                          if (live_contact)
+                            {
+                              account = empathy_contact_get_account
+                                                                (live_contact);
+                              if (account)
+                                {
+                                  /* FIXME: fill in the callback and user_data;
+                                   * this will let us know whether this
+                                   * succeeded or not */
+                              mission_control_request_channel_with_string_handle
+                                                  (mission_control, account,
+                                                   TP_IFACE_CHANNEL_TYPE_TEXT,
+                                                   im_handle,
+                                                   TP_HANDLE_TYPE_CONTACT, NULL,
+                                                   NULL);
+                                  /* FIXME: qualify this based on the callback
+                                   * function set above */
+                                  retval = TRUE;
+                                }
+                              else
+                                {
+                                  g_warning ("Chat account is invalid");
+                                }
+                            }
+                          else
+                            {
+                              g_warning ("selected person doesn't have the "
+                                         "selected IM name");
+                            }
+                        }
+                      else
+                        {
+                          g_warning ("failed to get the currently-selected"
+                                     "person");
+                        }
+                    }
+                  else
+                    {
+                      g_warning ("failed to get the current Chat handle");
+                    }
+                }
+              else
+                {
+                  g_warning ("failed to get the current Chat handle label");
+                }
+            }
+          else
+            {
+              g_warning ("failed to get the current Chat menu selection");
+            }
+
+          g_object_unref (mission_control);
+        }
+      else
         {
-          break;
+          g_warning ("unable to create new MissionControl");
         }
     }
-
-  if (!live_contact || !(account = empathy_contact_get_account (live_contact)))
+  else
     {
-      g_warning ("selected person doesn't have the selected IM name");
-      return;
+      g_warning ("failed to get the EmpathyContactList");
     }
 
-  /* FIXME: fill in the callback and user_data */
-  mission_control_request_channel_with_string_handle(mc, account,
-                                                     TP_IFACE_CHANNEL_TYPE_TEXT,
-                                                     im_handle,
-                                                     TP_HANDLE_TYPE_CONTACT,
-                                                     NULL, NULL);
-
-  g_object_unref (mc);
+  return retval;
 }
 
 /* Fill the Email action MenuToolButton's menu based on the selected person */

Modified: trunk/src/soylent-browser-person-view.h
==============================================================================
--- trunk/src/soylent-browser-person-view.h	(original)
+++ trunk/src/soylent-browser-person-view.h	Thu Jan 24 07:30:59 2008
@@ -49,21 +49,21 @@
                                                             gpointer user_data);
 int      soylent_browser_person_action_edit_selected_cb (GtkButton *btn,
                                                          gpointer user_data);
-void     soylent_browser_person_action_chat_menu_tool_button_cb
+gboolean soylent_browser_person_action_chat_menu_tool_button_cb
                                                       (GtkMenuToolButton *btntb,
                                                        gpointer user_data);
-void     soylent_browser_person_action_chat_menu_shell_cb
+gboolean soylent_browser_person_action_chat_menu_shell_cb
                                                       (GtkMenuShell *menu_email,
                                                        gpointer user_data);
-void     soylent_browser_person_action_email_menu_tool_button_cb
+gboolean soylent_browser_person_action_email_menu_tool_button_cb
                                                       (GtkMenuToolButton *btntb,
                                                        gpointer user_data);
 void     soylent_browser_person_selection_changed_cb (GtkIconView *iv,
                                                       gpointer user_data);
-void     soylent_browser_person_action_communicate_email
+gboolean soylent_browser_person_action_communicate_email
                                                       (SoylentBrowser *browser,
                                                        SoylentPerson *person);
-void     soylent_browser_person_action_communicate_chat
+gboolean soylent_browser_person_action_communicate_chat
                                                       (SoylentBrowser *browser,
                                                        SoylentPerson *person);
 

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Thu Jan 24 07:30:59 2008
@@ -54,14 +54,13 @@
   GdkPixbuf *icon_stock_person;
 };
 
-static gchar* soylent_browser_person_get_display_name_with_presence
-                                                        (SoylentPerson *person);
 static int soylent_browser_compare_people_by_icon_iter (GtkTreeModel *model,
                                                         GtkTreeIter *a,
                                                         GtkTreeIter *b,
                                                         gpointer ptr);
-static void iv_people_item_activated (GtkIconView *iv, GtkTreePath *path,
-                                      gpointer user_data);
+static gboolean soylent_browser_person_icon_activated_cb (GtkIconView *iv,
+                                                          GtkTreePath *path,
+                                                          gpointer user_data);
 
 static SoylentPerson* soylent_browser_live_contact_find_owner_person 
                                              (SoylentBrowser *browser,
@@ -1150,8 +1149,7 @@
         {
           gchar *name_display = NULL;
 
-          name_display = soylent_browser_person_get_display_name_with_presence
-                                                                      (person);
+          name_display = soylent_person_get_display_name_with_presence (person);
           if (name_display)
             {
               EContact *e_contact = NULL;
@@ -1371,85 +1369,61 @@
 }
 
 /* Compare the display names of two people in the main icon view; used to sort
- * the main icon view */
+ * the main icon view
+ *
+ * Return
+ *    0   if the two people have the same name
+ *  < 0   if person a's name < person b's name
+ *  > 0   if person b's name > person a's name */
 static int
 soylent_browser_compare_people_by_icon_iter (GtkTreeModel *model,
                                              GtkTreeIter *a, GtkTreeIter *b,
                                              gpointer ptr)
 {
+  int retval = 0;
   const gchar *name_a = NULL;
   const gchar *name_b = NULL;
 
   gtk_tree_model_get (model, a, PEOPLE_COL_NAME, &name_a, -1);
   gtk_tree_model_get (model, b, PEOPLE_COL_NAME, &name_b, -1);
 
-  return g_ascii_strcasecmp (name_a, name_b);
-}
-
-/* XXX: should this be in another file? */
-static gchar*
-soylent_browser_person_get_display_name_with_presence (SoylentPerson *person)
-{
-  gchar *retval = NULL;
-  EContact *e_contact = NULL;
-
-  g_return_val_if_fail (person != NULL, retval);
-  /* FIXME: uncomment once SoylentPerson is a GObject:
-  g_return_val_if_fail (SOYLENT_IS_PERSON (person), NULL);
-   */
-
-  e_contact = soylent_person_get_e_contact (person);
-  /* FIXME: make sure e_contact is non-NULL, and IS_ECONTACT */
-  if (e_contact && E_IS_CONTACT (e_contact))
-    {
-      const gchar *e_uid = NULL;
-      const gchar *name_display_base = NULL;
-      SoylentPresence presence = SP_PRESENCE_UNSET;
-
-      e_uid = e_contact_get_const (e_contact, E_CONTACT_UID);
-      name_display_base = display_name_from_e_contact (e_contact);
-
-      presence = soylent_person_get_presence (person);
-      switch (presence)
-        {
-          case SP_PRESENCE_AVAILABLE:
-          /* TODO: indicate idleness eventually */
-          case SP_PRESENCE_IDLE:
-            retval = g_strdup_printf ("%s [*]", name_display_base);
-            break;
-          case SP_PRESENCE_BUSY:
-          /* TODO: indicate idleness eventually */
-          case SP_PRESENCE_IDLE_BUSY:
-            retval = g_strdup_printf ("%s [...]", name_display_base);
-            break;
-          case SP_PRESENCE_OFFLINE:
-            retval = g_strdup (name_display_base);
-            break;
-          default:
-            retval = g_strdup (name_display_base);
-            break;
-        }
-    }
-  else
-    {
-      g_warning ("person's EContact is invalid");
-    }
+  retval = g_ascii_strcasecmp (name_a, name_b);
 
   return retval;
 }
 
-/* Handle the person icon activation */
-static void
-iv_people_item_activated (GtkIconView *iv, GtkTreePath *path,
-                          gpointer user_data)
+/* Handle the person icon activation
+ *
+ * Return TRUE for success, FALSE for any failure */
+static gboolean
+soylent_browser_person_icon_activated_cb (GtkIconView *iv, GtkTreePath *path,
+                                          gpointer user_data)
 {
+  gboolean retval = FALSE;
   SoylentBrowser *browser = NULL;
   SoylentPerson *person = NULL;
 
+  /* FIXME: once SoylentBrowser is a GObject, also check SOYLENT_IS_BROWSER */
   browser = (SoylentBrowser*) user_data;
-  person = soylent_browser_get_selected_person (browser);
+  if (browser)
+    {
+      /* FIXME: once SoylentPerson is a GObject, also check SOYLENT_IS_PERSON */
+      person = soylent_browser_get_selected_person (browser);
+      if (person)
+        {
+          retval = soylent_person_action_communicate (person); 
+        }
+      else
+        {
+          g_warning ("no person is selected to communicate with");
+        }
+    }
+  else
+    {
+      g_critical ("failed to activate a person: browser is NULL");
+    }
   
-  soylent_person_action_communicate (person); 
+  return retval;
 }
 
 /* Set up the main EBookView's signal handlers and initiate it */
@@ -2058,7 +2032,8 @@
 
   widget = glade_xml_get_widget (wtree, "iv_people");
   g_signal_connect (G_OBJECT (widget), "item_activated",
-                    G_CALLBACK (iv_people_item_activated), browser);
+                    G_CALLBACK (soylent_browser_person_icon_activated_cb),
+                    browser);
 
   /* Have the delete event (window close) end the program */
   widget = glade_xml_get_widget (wtree, "window_main");

Modified: trunk/src/soylent-person.c
==============================================================================
--- trunk/src/soylent-person.c	(original)
+++ trunk/src/soylent-person.c	Thu Jan 24 07:30:59 2008
@@ -216,6 +216,58 @@
   return retval;
 }
 
+/* Return a "pretty" version of a SoylentPerson's name, including a symbol to
+ * indicate presence */
+gchar*
+soylent_person_get_display_name_with_presence (SoylentPerson *person)
+{
+  gchar *retval = NULL;
+  EContact *e_contact = NULL;
+
+  g_return_val_if_fail (person != NULL, retval);
+  /* FIXME: uncomment once SoylentPerson is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_PERSON (person), NULL);
+   */
+
+  e_contact = soylent_person_get_e_contact (person);
+  if (e_contact && E_IS_CONTACT (e_contact))
+    {
+      const gchar *e_uid = NULL;
+      const gchar *name_display_base = NULL;
+      SoylentPresence presence = SP_PRESENCE_UNSET;
+
+      e_uid = e_contact_get_const (e_contact, E_CONTACT_UID);
+      name_display_base = display_name_from_e_contact (e_contact);
+
+      presence = soylent_person_get_presence (person);
+      switch (presence)
+        {
+          case SP_PRESENCE_AVAILABLE:
+          /* TODO: indicate idleness eventually */
+          case SP_PRESENCE_IDLE:
+            retval = g_strdup_printf ("%s [*]", name_display_base);
+            break;
+          case SP_PRESENCE_BUSY:
+          /* TODO: indicate idleness eventually */
+          case SP_PRESENCE_IDLE_BUSY:
+            retval = g_strdup_printf ("%s [...]", name_display_base);
+            break;
+          case SP_PRESENCE_OFFLINE:
+            retval = g_strdup (name_display_base);
+            break;
+          default:
+            retval = g_strdup (name_display_base);
+            break;
+        }
+    }
+  else
+    {
+      g_warning ("person's EContact is invalid");
+    }
+
+  return retval;
+}
+
 /* Returns TRUE upon success, FALSE otherwise */
 gboolean
 soylent_person_set_e_contact (SoylentPerson *person, EContact *e_contact)
@@ -645,19 +697,24 @@
   return retval;
 }
 
-int
+/* Initiate communication with the SoylentPerson, using the
+ * generally-lowest-latency method possible
+ *
+ * Return TRUE for success, FALSE for any failure */
+gboolean
 soylent_person_action_communicate (SoylentPerson *person)
 {
-  int retval = 0;
+  gboolean retval = FALSE;
 
-  /* FIXME: we never do anything with retval */
   if (soylent_person_is_online (person))
     {
-      soylent_browser_person_action_communicate_chat (person->browser, person);
+      retval = soylent_browser_person_action_communicate_chat (person->browser,
+                                                               person);
     }
   else
     {
-      soylent_browser_person_action_communicate_email (person->browser, person);
+      retval = soylent_browser_person_action_communicate_email (person->browser,
+                                                                person);
     }
 
   return retval;

Modified: trunk/src/soylent-person.h
==============================================================================
--- trunk/src/soylent-person.h	(original)
+++ trunk/src/soylent-person.h	Thu Jan 24 07:30:59 2008
@@ -62,6 +62,7 @@
 GdkPixbuf* soylent_person_get_avatar (SoylentPerson *person,
                                       guint icon_width_max,
                                       guint icon_height_max);
+gchar* soylent_person_get_display_name_with_presence (SoylentPerson *person);
 gboolean soylent_person_set_e_contact (SoylentPerson *person,
                                        EContact *e_contact);
 gboolean soylent_person_set_live_contacts (SoylentPerson *person,
@@ -100,7 +101,7 @@
 SoylentPresence soylent_person_presence_from_empathy_presence
                                                     (EmpathyPresence *presence);
 
-int soylent_person_action_communicate (SoylentPerson *person);
+gboolean soylent_person_action_communicate (SoylentPerson *person);
 
 void soylent_person_free (SoylentPerson *person);
 



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