soylent r109 - trunk/src
- From: treitter svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r109 - trunk/src
- Date: Mon, 31 Mar 2008 06:59:58 +0100 (BST)
Author: treitter
Date: Mon Mar 31 06:59:58 2008
New Revision: 109
URL: http://svn.gnome.org/viewvc/soylent?rev=109&view=rev
Log:
Make the final close-scrutiny general code clean-ups before 0.1.4. *whew* -- that took a while\!
Modified:
trunk/src/eds-utils.c
trunk/src/eds-utils.h
trunk/src/soylent-browser-person-view.c
trunk/src/soylent-person.c
trunk/src/soylent-person.h
trunk/src/soylent-utils.c
trunk/src/soylent-utils.h
Modified: trunk/src/eds-utils.c
==============================================================================
--- trunk/src/eds-utils.c (original)
+++ trunk/src/eds-utils.c Mon Mar 31 06:59:58 2008
@@ -332,3 +332,64 @@
return retval;
}
+
+/* FIXME: doesn't handle titles properly */
+/* Return a copy of the X-EVOLUTION-FILE-AS-formatted version of a person's full
+ * name (must be freed by caller) if successful; otherwise, NULL */
+gchar*
+eds_get_name_file_as_from_full (const gchar *full_name)
+{
+ gchar *retval = NULL;
+ GString *name_file_as = NULL;
+ gchar **name_split = NULL;
+ guint names_num = 0;
+
+ g_return_val_if_fail (full_name != NULL, retval);
+ g_return_val_if_fail (!g_str_equal (full_name, ""), retval);
+
+ /* Construct the X-EVOLUTION-FILE-AS name in the format:
+ * "[<family_name>, ][<given_name>][ <middle name>][ <suffixes>]" */
+ name_file_as = g_string_new ("");
+ name_split = g_strsplit (full_name, " ", -1);
+ if (name_split)
+ {
+ for (names_num = 0; name_split && name_split[names_num]; names_num++)
+ {
+ }
+
+ if (names_num == 0)
+ {
+ /* do nothing; we'll use "" */
+ }
+ else if (names_num == 1)
+ {
+ g_string_append (name_file_as, name_split[0]);
+ }
+ else if (names_num == 2)
+ {
+ g_string_append (name_file_as, name_split[1]);
+ g_string_append (name_file_as, ", ");
+ g_string_append (name_file_as, name_split[0]);
+ }
+ else if (names_num >= 3)
+ {
+ g_string_append (name_file_as, name_split[2]);
+ g_string_append (name_file_as, ", ");
+ g_string_append (name_file_as, name_split[0]);
+
+ g_string_append_c (name_file_as, ' ');
+ g_string_append (name_file_as, name_split[1]);
+
+ if (names_num >= 4)
+ {
+ /* FIXME: handle titles */
+ }
+ }
+
+ g_strfreev (name_split);
+ }
+
+ retval = g_string_free (name_file_as, FALSE);
+
+ return retval;
+}
Modified: trunk/src/eds-utils.h
==============================================================================
--- trunk/src/eds-utils.h (original)
+++ trunk/src/eds-utils.h Mon Mar 31 06:59:58 2008
@@ -45,4 +45,6 @@
EContactField field_id, const gchar *type,
guint abs_num, const gchar *value);
+gchar* eds_get_name_file_as_from_full (const gchar *full_name);
+
#endif /* _EDS_UTILS_H_ */
Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c (original)
+++ trunk/src/soylent-browser-person-view.c Mon Mar 31 06:59:58 2008
@@ -2203,20 +2203,20 @@
if (e_contact_field == E_CONTACT_FULL_NAME)
{
gchar *name_file_as = NULL;
- gchar *name_first = NULL;
- gchar *name_last = NULL;
+ gchar *name_given = NULL;
+ gchar *name_family = NULL;
- name_file_as = get_file_as_name (contents_new);
- name_first = get_first_name (contents_new);
- name_last = get_last_name (contents_new);
+ name_file_as = eds_get_name_file_as_from_full (contents_new);
+ name_given = name_get_given_from_full (contents_new);
+ name_family = name_get_family_from_full (contents_new);
e_contact_set (e_contact, E_CONTACT_FILE_AS, name_file_as);
- e_contact_set (e_contact, E_CONTACT_GIVEN_NAME, name_first);
- e_contact_set (e_contact, E_CONTACT_FAMILY_NAME, name_last);
-
+ e_contact_set (e_contact, E_CONTACT_GIVEN_NAME, name_given);
+ e_contact_set (e_contact, E_CONTACT_FAMILY_NAME, name_family);
+
g_free (name_file_as);
- g_free (name_first);
- g_free (name_last);
+ g_free (name_given);
+ g_free (name_family);
}
retval = TRUE;
Modified: trunk/src/soylent-person.c
==============================================================================
--- trunk/src/soylent-person.c (original)
+++ trunk/src/soylent-person.c Mon Mar 31 06:59:58 2008
@@ -192,20 +192,21 @@
{
empathy_contact = EMPATHY_CONTACT (c->data);
retval = empathy_pixbuf_avatar_from_contact_scaled
- (empathy_contact,
- icon_width_max,
- icon_height_max);
+ (empathy_contact,
+ icon_width_max,
+ icon_height_max);
}
- /* FIXME: do something with this logic elsewhere */
- /*
- if (retval)
- {
- avatar_pixbuf_needs_unref = TRUE;
- }
- */
}
}
+
+ /* FIXME: do something with this logic elsewhere */
+ /*
+ if (retval)
+ {
+ avatar_pixbuf_needs_unref = TRUE;
+ }
+ */
}
else
{
@@ -404,109 +405,7 @@
g_warning ("presence2 is invalid");
}
- if (presence1 < presence2)
- {
- return -1;
- }
- if (presence1 > presence2)
- {
- return 1;
- }
-
- /* the presences are equal */
- return 0;
-}
-
-/* Derive the X-EVOLUTION-FILE-AS-formatted name from a full name */
-gchar*
-get_file_as_name (const gchar *full_name)
-{
- GString *name_file_as = NULL;
- gchar **name_split = NULL;
- guint i = 0;
- guint j = 0;
-
- if (!full_name || g_str_equal (full_name, ""))
- {
- return NULL;
- }
-
- name_file_as = g_string_new ("");
- name_split = g_strsplit (full_name, " ", -1);
- for (i = 0; name_split && name_split[i]; i++)
- {
- }
-
- if (name_split)
- {
- if (i > 1 && name_split[i-1])
- {
- g_string_append (name_file_as, name_split[i-1]);
- g_string_append (name_file_as, ",");
- for (j = 0; j < i-1 && name_split && name_split[j]; j++)
- {
- g_string_append_c (name_file_as, ' ');
- g_string_append (name_file_as, name_split[j]);
- }
- }
- else if (name_split[i])
- {
- g_string_append (name_file_as, name_split[i]);
- }
- }
-
- g_strfreev (name_split);
-
- return g_string_free (name_file_as, FALSE);
-}
-
-gchar*
-get_first_name (const gchar *full_name)
-{
- gchar *name_first = NULL;
- gchar **name_split = NULL;
-
- if (!full_name || g_str_equal (full_name, ""))
- {
- return NULL;
- }
-
- name_split = g_strsplit (full_name, " ", -1);
- name_first = g_strdup (name_split[0]);
-
- g_strfreev (name_split);
-
- return name_first;
-}
-
-gchar*
-get_last_name (const gchar *full_name)
-{
- gchar *name_last = NULL;
- gchar **name_split = NULL;
- guint i = 0;
-
- if (!full_name || g_str_equal (full_name, ""))
- {
- return NULL;
- }
-
- name_split = g_strsplit (full_name, " ", -1);
-
- for (i = 0; name_split && name_split[i]; i++)
- {
- }
-
- if (!name_split || i <= 1)
- {
- g_strfreev (name_split);
- return NULL;
- }
-
- name_last = g_strdup (name_split[i-1]);
- g_strfreev (name_split);
-
- return name_last;
+ return (presence1 - presence2);
}
/* Update a SoylentPerson's IM contacts' groups, based on their changes on the
@@ -519,47 +418,10 @@
"soylent_person_live_groups_updated_cb");
}
-#if 0
-/* Transform an EmpathyPresence into our internal representation */
-SoylentPresence
-soylent_person_presence_from_empathy_presence (EmpathyPresence *presence)
-{
- McPresence mc_state = MC_PRESENCE_UNSET;
-
- if (presence)
- {
- switch ((mc_state = empathy_presence_get_state (presence)))
- {
- case MC_PRESENCE_AVAILABLE:
- return SP_PRESENCE_AVAILABLE;
- break;
- case MC_PRESENCE_AWAY:
- case MC_PRESENCE_EXTENDED_AWAY:
- case MC_PRESENCE_DO_NOT_DISTURB:
- return SP_PRESENCE_BUSY;
- break;
- case MC_PRESENCE_OFFLINE:
- case MC_PRESENCE_HIDDEN:
- return SP_PRESENCE_OFFLINE;
- break;
- default:
- g_warning ("unknown Mission Control presence: %u", mc_state);
- break;
- }
- }
-
- return SP_PRESENCE_UNSET;
-}
-#endif
-
/* Transform an EmpathyPresence into our internal representation */
SoylentPresence
soylent_person_presence_from_mc_presence (McPresence presence)
{
- /*
- McPresence mc_state = MC_PRESENCE_UNSET;
- */
-
switch (presence)
{
case MC_PRESENCE_AVAILABLE:
@@ -583,62 +445,6 @@
return SP_PRESENCE_UNSET;
}
-#if 0
-/* Propagate IM contacts' presence changes to our internal state, updating
- * the SoylentPerson's representation and other widgets accordingly.
- *
- * Return TRUE for success, FALSE for any failure
- */
-gboolean
-soylent_person_live_presence_updated_cb (EmpathyContact *empathy_contact,
- GParamSpec *param,
- SoylentPerson *person)
-{
- gboolean retval = FALSE;
- SoylentPresence soylent_person_presence_effective = SP_PRESENCE_OFFLINE;
- GList *l = NULL;
-
- g_return_val_if_fail (empathy_contact != NULL, retval);
- g_return_val_if_fail (EMPATHY_IS_CONTACT (empathy_contact), retval);
- g_return_val_if_fail (person != NULL, retval);
- /* FIXME: uncomment once SoylentPerson is a GObject:
- g_return_val_if_fail (SOYLENT_IS_PERSON (person), retval);
- */
-
- for (l = person->live_contacts;
- l && l->data && EMPATHY_IS_CONTACT (l->data);
- l = g_list_next (l))
- {
- EmpathyContact *empathy_contact_cur = NULL;
- EmpathyPresence *empathy_presence_cur = NULL;
- SoylentPresence soylent_presence_cur = SP_PRESENCE_UNSET;
-
- empathy_contact_cur = EMPATHY_CONTACT (l->data);
- empathy_presence_cur = empathy_contact_get_presence
- (empathy_contact_cur);
- soylent_presence_cur = soylent_person_presence_from_empathy_presence
- (empathy_presence_cur);
-
- if (SP_PRESENCE_IS_VALID (soylent_presence_cur))
- {
- if ((soylent_person_live_presence_compare
- (soylent_presence_cur,
- soylent_person_presence_effective))
- > 0)
- {
- soylent_person_presence_effective = soylent_presence_cur;
- }
- }
- }
-
- person->presence = soylent_person_presence_effective;
-
- retval = soylent_browser_update_person_icon (person->browser, person);
-
- return retval;
-}
-#endif
-
/* Propagate IM contacts' presence changes to our internal state, updating
* the SoylentPerson's representation and other widgets accordingly.
*
@@ -719,36 +525,7 @@
g_return_val_if_fail (SOYLENT_IS_PERSON (person), retval);
* */
-#if 0
- GdkPixbuf *pixbuf = NULL;
-#endif
-
- /*
- soylent_debug ("updating the avatar\n");
- */
-
- /*
- if (!empathy_contact || !person)
- {
- soylent_debug ("!empathy_contact || !person\n");
- return;
- }
- */
-
browser = person->browser;
-#if 0
- pixbuf = empathy_pixbuf_avatar_from_contact_scaled (empathy_contact,
- icon_width_max,
- icon_height_max);
-
- if (!pixbuf || e_contact_get (person->e_contact, E_CONTACT_PHOTO))
- {
- soylent_debug ("!pixbuf || e_contact_get (person->e_contact, "
- "E_CONTACT_PHOTO)\n");
- return;
- }
-#endif
-
retval = soylent_browser_update_person_icon (browser, person);
return retval;
Modified: trunk/src/soylent-person.h
==============================================================================
--- trunk/src/soylent-person.h (original)
+++ trunk/src/soylent-person.h Mon Mar 31 06:59:58 2008
@@ -71,11 +71,6 @@
gboolean soylent_person_remove_live_contact (SoylentPerson *person,
EmpathyContact *live_contact);
-/* FIXME: these should (almost?) all be static */
-gchar* get_file_as_name (const gchar *full_name);
-gchar* get_last_name (const gchar *full_name);
-gchar* get_first_name (const gchar *full_name);
-
gint soylent_person_live_presence_compare (SoylentPresence presence1,
SoylentPresence presence2);
gboolean soylent_person_is_online (SoylentPerson *person);
Modified: trunk/src/soylent-utils.c
==============================================================================
--- trunk/src/soylent-utils.c (original)
+++ trunk/src/soylent-utils.c Mon Mar 31 06:59:58 2008
@@ -106,3 +106,50 @@
g_signal_handlers_unblock_matched (entry, G_SIGNAL_MATCH_FUNC, 0, (GQuark) 0,
NULL, handler, NULL);
}
+
+/* Return a copy of the given name portion of a person's full name if
+ * successful; otherwise, NULL */
+gchar*
+name_get_given_from_full (const gchar *full_name)
+{
+ gchar *retval = NULL;
+ gchar **name_split = NULL;
+
+ g_return_val_if_fail (full_name != NULL, retval);
+ g_return_val_if_fail (!g_str_equal (full_name, ""), retval);
+
+ name_split = g_strsplit (full_name, " ", -1);
+ retval = g_strdup (name_split[0]);
+
+ g_strfreev (name_split);
+
+ return retval;
+}
+
+/* Return a copy of the family name portion of a person's full name if
+ * successful; otherwise, NULL */
+gchar*
+name_get_family_from_full (const gchar *full_name)
+{
+ gchar *retval = NULL;
+ gchar **name_split = NULL;
+ guint names_num = 0;
+
+ g_return_val_if_fail (full_name != NULL, retval);
+ g_return_val_if_fail (!g_str_equal (full_name, ""), retval);
+
+ name_split = g_strsplit (full_name, " ", -1);
+
+ for (names_num = 0; name_split && name_split[names_num]; names_num++)
+ {
+ }
+
+ if (names_num > 1)
+ {
+ retval = g_strdup (name_split[names_num - 1]);
+ }
+
+ g_strfreev (name_split);
+
+ return retval;
+}
Modified: trunk/src/soylent-utils.h
==============================================================================
--- trunk/src/soylent-utils.h (original)
+++ trunk/src/soylent-utils.h Mon Mar 31 06:59:58 2008
@@ -66,4 +66,8 @@
gpointer handler);
void entry_set_text_block_handler (GtkEntry *entry, const gchar *text,
gpointer handler);
+
+gchar* name_get_given_from_full (const gchar *full_name);
+gchar* name_get_family_from_full (const gchar *full_name);
+
#endif /* _SOYLENT_UTILS_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]