static gboolean deserialize_cache (MuContacts *self) { gchar **groups; gsize i, len; groups = g_key_file_get_groups (self->_ccache, &len); for (i = 0; i != len; ++i) { ContactInfo *cinfo; char *name, *email; size_t tstamp; if (!get_values (self->_ccache, groups[i], &email, &name, &tstamp)) continue; /* ignore this one... */ cinfo = contact_info_new (email, name, tstamp); /* note, we're using the groups[i], so don't free with g_strfreev */ g_hash_table_insert (self->_hash, groups[i], cinfo); } g_free (groups); return TRUE; }
gboolean mu_contacts_add (MuContacts *self, const char *email, const char* name, time_t tstamp) { ContactInfo *cinfo; const char* group; g_return_val_if_fail (self, FALSE); g_return_val_if_fail (email, FALSE); /* add the info, if either there is no info for this email * yet, *OR* the new one is more recent and does not have an * empty name */ group = encode_email_address (email); cinfo = (ContactInfo*) g_hash_table_lookup (self->_hash, group); if (!cinfo || (cinfo->_tstamp < tstamp && !mu_str_is_empty(name))) { ContactInfo *ci; ci = contact_info_new (g_strdup(email), name ? g_strdup(name) : NULL, tstamp); g_hash_table_insert (self->_hash, g_strdup(group), ci); return self->_dirty = TRUE; } return FALSE; }
gboolean mu_contacts_add (MuContacts *self, const char *addr, const char *name, gboolean personal, time_t tstamp) { ContactInfo *cinfo; const char *group; g_return_val_if_fail (self, FALSE); g_return_val_if_fail (addr, FALSE); group = encode_email_address (addr); cinfo = (ContactInfo*) g_hash_table_lookup (self->_hash, group); if (!cinfo) { char *addr_dc; if (!(addr_dc = downcase_domain_maybe (addr))) return FALSE; cinfo = contact_info_new (addr_dc, name ? g_strdup(name) : NULL, personal, tstamp, 1); g_hash_table_insert (self->_hash, g_strdup(group), cinfo); } else { if (cinfo->_tstamp < tstamp) { if (!mu_str_is_empty(name)) { /* update the name to the last one used, unless it's * empty*/ g_free (cinfo->_name); cinfo->_name = g_strdup (name); if (cinfo->_name) mu_str_remove_ctrl_in_place (cinfo->_name); } cinfo->_tstamp = tstamp; } ++cinfo->_freq; } self->_dirty = TRUE; return TRUE; }