From: Roman Moravcik Date: Mon, 18 Oct 2010 07:21:06 +0000 (+0200) Subject: Rewritten handling contacts using OssoAbookContact instead of EContact. X-Git-Tag: v0.3-1~1 X-Git-Url: http://vcs.maemo.org/git/?p=birthday;a=commitdiff_plain;h=36684dd6b5d824257ec09feca0cc5da955eff391 Rewritten handling contacts using OssoAbookContact instead of EContact. --- diff --git a/src/birthday.c b/src/birthday.c index b5f9fd7..b81d176 100644 --- a/src/birthday.c +++ b/src/birthday.c @@ -539,67 +539,26 @@ create_bday_liststore (BirthdayData *priv, GList *contacts) G_TYPE_POINTER); /* COLUMN_ABOOK_CONTACT */ for (contact = contacts; contact != NULL; contact = contact->next) { + EContactDate *bdate = NULL; bdate = e_contact_get (E_CONTACT (contact->data), E_CONTACT_BIRTH_DATE); if (bdate) { - EContactPhoto *photo = NULL; GError *error = NULL; GdkPixbuf *avatar = NULL; - gchar *fullname = NULL; + const gchar *fullname = NULL; guint age = 0, next_birthday = 0; gchar *display_column = NULL; gchar *next_birthday_text = NULL; struct tm birthday_tm; gchar birthday_text[11]; - OssoABookContact *abook_contact; - - photo = e_contact_get (E_CONTACT (contact->data), E_CONTACT_PHOTO); - if (photo) { - if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) { - GdkPixbufLoader *loader; - - loader = gdk_pixbuf_loader_new (); - if (gdk_pixbuf_loader_write (loader, (guchar *) photo->data.inlined.data, photo->data.inlined.length, NULL)) - avatar = gdk_pixbuf_loader_get_pixbuf (loader); - - } else { - gchar *avatar_filename = NULL; - - avatar_filename = g_filename_from_uri (photo->data.uri, NULL, NULL); - if (avatar_filename) { - avatar = gdk_pixbuf_new_from_file (avatar_filename, &error); - g_free (avatar_filename); - } - } - - if (avatar) { - gint height = gdk_pixbuf_get_height (avatar); - if (height != 48) { - gint new_height = 48; - gint new_width = new_height * gdk_pixbuf_get_width (avatar) / height; - avatar = gdk_pixbuf_scale_simple (avatar, new_width, new_height, GDK_INTERP_BILINEAR); - } - } - e_contact_photo_free (photo); - photo = NULL; - } else { + + avatar = osso_abook_avatar_get_image_rounded (OSSO_ABOOK_AVATAR (contact->data), 48, 48, TRUE, 4, NULL); + if (!avatar) { avatar = gdk_pixbuf_new_from_file ("/usr/share/icons/hicolor/48x48/hildon/general_default_avatar.png", &error); } - fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_FULL_NAME); - if (!fullname) { - fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_GIVEN_NAME); - if (!fullname) { - fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_FAMILY_NAME); - if (!fullname) { - fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_NICKNAME); - if (!fullname) { - fullname = e_contact_get (E_CONTACT (contact->data), E_CONTACT_ORG); - } - } - } - } + fullname = osso_abook_contact_get_display_name (OSSO_ABOOK_CONTACT (contact->data)); birthday_tm.tm_sec = 0; birthday_tm.tm_min = 0; @@ -622,15 +581,13 @@ create_bday_liststore (BirthdayData *priv, GList *contacts) display_column = g_strdup_printf ("%s (%d)\n%s, %s", fullname, text_font, text_color, age, birthday_text, next_birthday_text); - abook_contact = osso_abook_contact_new_from_template (E_CONTACT (contact->data)); - gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COLUMN_AVATAR, avatar, COLUMN_DISPLAY, display_column, COLUMN_FULLNAME, fullname, COLUMN_NEXT_BIRTHDAY, next_birthday, - COLUMN_ABOOK_CONTACT, abook_contact, + COLUMN_ABOOK_CONTACT, contact->data, -1); n_contacts++; @@ -638,10 +595,6 @@ create_bday_liststore (BirthdayData *priv, GList *contacts) g_free (display_column); display_column = NULL; - if (fullname) - g_free (fullname); - fullname = NULL; - if (next_birthday_text) g_free (next_birthday_text); next_birthday_text = NULL; @@ -731,7 +684,7 @@ static void create_main_window (BirthdayData *priv, GtkListStore *store) { HildonProgram *program = NULL; - GtkWidget *main_vbox, *alignment, *pannable, *tree_view; + GtkWidget *main_vbox, *alignment, *pannable; GtkTreeModel *filter; GtkTreeViewColumn *column; GtkCellRenderer *renderer; @@ -849,32 +802,27 @@ create_main_window (BirthdayData *priv, GtkListStore *store) } static GList * -get_all_contacts (EBook *ebook) +get_all_contacts (void) { GError *error = NULL; - EBookQuery *query; + OssoABookAggregator *aggregator; GList *contacts; - ebook = e_book_new_system_addressbook (&error); - if (!ebook) { - g_warning ("Error opening system address book: %s", error->message); + aggregator = OSSO_ABOOK_AGGREGATOR (osso_abook_aggregator_get_default (&error)); + if (!aggregator) { + g_warning ("Error creating default abook aggregator: %s", error->message); g_error_free (error); return NULL; } - if (!e_book_open (ebook, TRUE, &error)) { - g_warning ("Error opening system address book: %s", error->message); + osso_abook_waitable_run (OSSO_ABOOK_WAITABLE (aggregator), g_main_context_default(), &error); + if (error) { + g_warning ("Error wating for abook: %s", error->message); g_error_free (error); return NULL; } - query = e_book_query_any_field_contains (""); - - if (!e_book_get_contacts (ebook, query, &contacts, &error)) { - g_warning ("Error getting contacts: %s", error->message); - g_error_free (error); - return NULL; - } + contacts = osso_abook_aggregator_list_master_contacts (aggregator); return contacts; } @@ -883,8 +831,6 @@ int main (int argc, char **argv) { BirthdayData *data; osso_context_t *osso_context; - EBook *ebook; - GtkWidget *window; GtkListStore *store; GList *contacts; @@ -915,7 +861,7 @@ int main (int argc, char **argv) goto exit; } - contacts = get_all_contacts (ebook); + contacts = get_all_contacts (); store = create_bday_liststore (data, contacts); /* create main widow */