Changeset 2493


Ignore:
Timestamp:
07/10/07 13:57:34 (6 years ago)
Author:
njp
Message:

2007-07-10 Neil J. Patel <njp@…>

  • src/moko-contacts.c: (moko_contacts_add_contact), (on_ebook_contact_added), (moko_contacts_init), (moko_contacts_get_default):
  • src/moko-contacts.h: Create the EBook and populate the contacts and entries list. Connect to the 'contacts-added' signal and add new contacts to the list.
Location:
trunk/applications/openmoko-dialer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/applications/openmoko-dialer/ChangeLog

    r2490 r2493  
     12007-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 
    1102007-07-09  Neil J. Patel  <njp@o-hand.com> 
    211 
  • trunk/applications/openmoko-dialer/src/moko-contacts.c

    r2490 r2493  
    11/* 
    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) 
    34 * 
    45 *  Authored by OpenedHand Ltd <info@openedhand.com> 
     
    1819 */ 
    1920 
    20 #include <gtk/gtk.h> 
    21 #include <gtk/gtk.h> 
     21#include <glib.h> 
     22 
     23#include <libebook/e-book.h> 
    2224 
    2325#include "moko-contacts.h" 
     
    3032struct _MokoContactsPrivate 
    3133{ 
    32   gint null; 
     34  GList *contacts; 
     35  GList *entries; 
    3336}; 
     37 
     38static void 
     39moko_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 
     81static void 
     82on_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} 
    3495 
    3596/* GObject functions */ 
     
    58119} 
    59120 
     121 
    60122static void 
    61123moko_contacts_init (MokoContacts *contacts) 
    62124{ 
    63125  MokoContactsPrivate *priv; 
     126  EBook *book; 
     127  EBookView *view; 
     128  EBookQuery *query; 
     129  GList *contact, *c; 
    64130 
    65131  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  } 
    66167} 
    67168 
     
    71172  static MokoContacts *contacts = NULL; 
    72173   
    73   if (contacts = NULL) 
     174  if (contacts == NULL) 
    74175    contacts = g_object_new (MOKO_TYPE_CONTACTS,  
    75176                             NULL); 
  • trunk/applications/openmoko-dialer/src/moko-contacts.h

    r2490 r2493  
    11/* 
    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) 
    34 * 
    45 *  Authored by OpenedHand Ltd <info@openedhand.com> 
     
    2223 
    2324#include <glib.h> 
     25#include <gtk/gtk.h> 
    2426 
    2527G_BEGIN_DECLS 
     
    4547typedef struct _MokoContactsClass MokoContactsClass; 
    4648typedef struct _MokoContactsPrivate MokoContactsPrivate; 
     49typedef struct _MokoContact MokoContact; 
     50typedef struct _MokoContactEntry MokoContactEntry; 
    4751 
    4852struct _MokoContacts 
     
    6468  void (*_moko_contacts_3) (void); 
    6569  void (*_moko_contacts_4) (void); 
    66 };  
     70}; 
     71 
     72struct _MokoContact 
     73{ 
     74  gchar       *uid; 
     75  gchar       *name; 
     76  GdkPixbuf   *photo; 
     77}; 
     78 
     79struct _MokoContactEntry 
     80{ 
     81  gchar       *desc; 
     82  gchar       *number; 
     83  MokoContact *contact; 
     84}; 
    6785 
    6886GType moko_contacts_get_type (void) G_GNUC_CONST; 
     
    7189moko_contacts_get_default (void); 
    7290 
     91MokoContactEntry* 
     92moko_contacts_lookup (MokoContacts *contacts, const gchar *number); 
     93 
    7394G_END_DECLS 
    7495 
Note: See TracChangeset for help on using the changeset viewer.