Changeset 2493
- Timestamp:
- 07/10/07 13:57:34 (6 years ago)
- Location:
- trunk/applications/openmoko-dialer
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
src/moko-contacts.c (modified) (5 diffs)
-
src/moko-contacts.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/applications/openmoko-dialer/ChangeLog
r2490 r2493 1 2007-07-10 Neil J. Patel <njp@o-hand.com> 2 3 * src/moko-contacts.c: (moko_contacts_add_contact), 4 (on_ebook_contact_added), (moko_contacts_init), 5 (moko_contacts_get_default): 6 * src/moko-contacts.h: 7 Create the EBook and populate the contacts and entries list. 8 Connect to the 'contacts-added' signal and add new contacts to the list. 9 1 10 2007-07-09 Neil J. Patel <njp@o-hand.com> 2 11 -
trunk/applications/openmoko-dialer/src/moko-contacts.c
r2490 r2493 1 1 /* 2 * moko-contacts; The contactss contacts 2 * moko-contacts; A rework of the dialers contact list, some e-book code taken 3 * from the orignal dialer contacts.c (written by tonyguan@fic-sh.com.cn) 3 4 * 4 5 * Authored by OpenedHand Ltd <info@openedhand.com> … … 18 19 */ 19 20 20 #include <gtk/gtk.h> 21 #include <gtk/gtk.h> 21 #include <glib.h> 22 23 #include <libebook/e-book.h> 22 24 23 25 #include "moko-contacts.h" … … 30 32 struct _MokoContactsPrivate 31 33 { 32 gint null; 34 GList *contacts; 35 GList *entries; 33 36 }; 37 38 static void 39 moko_contacts_add_contact (MokoContacts *contacts, EContact *e_contact) 40 { 41 MokoContactsPrivate *priv; 42 MokoContact *m_contact = NULL; 43 const gchar *name; 44 gint i; 45 46 g_return_if_fail (MOKO_IS_CONTACTS (contacts)); 47 g_return_if_fail (E_IS_CONTACT (e_contact)); 48 priv = contacts->priv; 49 50 name = e_contact_get_const (e_contact, E_CONTACT_NAME_OR_ORG); 51 if (!name || (g_utf8_strlen (name, -1) <= 0)) 52 name = "Unnamed"; 53 54 /* Create the contact & append to the list */ 55 m_contact = g_new0 (MokoContact, 1); 56 m_contact->name = g_strdup (name); 57 m_contact->uid = e_contact_get (e_contact, E_CONTACT_UID); 58 m_contact->photo = NULL; 59 60 priv->contacts = g_list_append (priv->contacts, m_contact); 61 62 /* Now go through the numbers,creating MokoNumber for them */ 63 for (i = E_CONTACT_FIRST_PHONE_ID; i < E_CONTACT_LAST_PHONE_ID; i++) 64 { 65 MokoContactEntry *entry; 66 const gchar *phone; 67 68 phone = e_contact_get_const (e_contact, i); 69 if (phone) 70 { 71 entry = g_new0 (MokoContactEntry, 1); 72 entry->desc = g_strdup (e_contact_field_name (i)); 73 entry->number = g_strdup (phone); 74 entry->contact = m_contact; 75 76 priv->entries = g_list_append (priv->entries, (gpointer)entry); 77 } 78 } 79 } 80 81 static void 82 on_ebook_contact_added (EBookView *view, 83 GList *c_list, 84 MokoContacts *contacts) 85 { 86 MokoContactsPrivate *priv; 87 GList *c; 88 89 g_return_if_fail (MOKO_IS_CONTACTS (contacts)); 90 priv = contacts->priv; 91 92 for (c = c_list; c != NULL; c = c->next) 93 moko_contacts_add_contact (contacts, E_CONTACT (c->data)); 94 } 34 95 35 96 /* GObject functions */ … … 58 119 } 59 120 121 60 122 static void 61 123 moko_contacts_init (MokoContacts *contacts) 62 124 { 63 125 MokoContactsPrivate *priv; 126 EBook *book; 127 EBookView *view; 128 EBookQuery *query; 129 GList *contact, *c; 64 130 65 131 priv = contacts->priv = MOKO_CONTACTS_GET_PRIVATE (contacts); 132 133 priv->contacts = priv->entries = NULL; 134 135 query = e_book_query_any_field_contains (""); 136 137 /* Open the system book and check that it is valid */ 138 book = e_book_new_system_addressbook (NULL); 139 if (!book) 140 { 141 g_warning ("Failed to create system book\n"); 142 return; 143 } 144 if (!e_book_open (book, TRUE, NULL)) 145 { 146 g_warning ("Failed to open system book\n"); 147 return; 148 } 149 if (!e_book_get_contacts (book, query, &contact, NULL)) 150 { 151 g_warning ("Failed to get contacts from system book\n"); 152 return; 153 } 154 155 /* Go through the contacts, creating the contact structs, and entry structs*/ 156 for (c = contact; c != NULL; c = c->next) 157 { 158 moko_contacts_add_contact (contacts, E_CONTACT (c->data)); 159 } 160 161 /* Connect to contact added signals */ 162 if (e_book_get_book_view (book, query, NULL, 0, &view, NULL)) 163 { 164 g_signal_connect (G_OBJECT (view), "contacts-added", 165 G_CALLBACK (on_ebook_contact_added), (gpointer)contacts); 166 } 66 167 } 67 168 … … 71 172 static MokoContacts *contacts = NULL; 72 173 73 if (contacts = NULL)174 if (contacts == NULL) 74 175 contacts = g_object_new (MOKO_TYPE_CONTACTS, 75 176 NULL); -
trunk/applications/openmoko-dialer/src/moko-contacts.h
r2490 r2493 1 1 /* 2 * moko-contacts; The contactss contacts. 2 * moko-contacts; A rework of the dialers contact list, some e-book code taken 3 * from the orignal dialer contacts.c (written by tonyguan@fic-sh.com.cn) 3 4 * 4 5 * Authored by OpenedHand Ltd <info@openedhand.com> … … 22 23 23 24 #include <glib.h> 25 #include <gtk/gtk.h> 24 26 25 27 G_BEGIN_DECLS … … 45 47 typedef struct _MokoContactsClass MokoContactsClass; 46 48 typedef struct _MokoContactsPrivate MokoContactsPrivate; 49 typedef struct _MokoContact MokoContact; 50 typedef struct _MokoContactEntry MokoContactEntry; 47 51 48 52 struct _MokoContacts … … 64 68 void (*_moko_contacts_3) (void); 65 69 void (*_moko_contacts_4) (void); 66 }; 70 }; 71 72 struct _MokoContact 73 { 74 gchar *uid; 75 gchar *name; 76 GdkPixbuf *photo; 77 }; 78 79 struct _MokoContactEntry 80 { 81 gchar *desc; 82 gchar *number; 83 MokoContact *contact; 84 }; 67 85 68 86 GType moko_contacts_get_type (void) G_GNUC_CONST; … … 71 89 moko_contacts_get_default (void); 72 90 91 MokoContactEntry* 92 moko_contacts_lookup (MokoContacts *contacts, const gchar *number); 93 73 94 G_END_DECLS 74 95
Note: See TracChangeset
for help on using the changeset viewer.
