Changeset 598

Show
Ignore:
Timestamp:
05/18/04 01:45:04
Author:
chipx86
Message:

Setup all accounts for all people in the Evolution address book.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/eds-feed/ChangeLog

    r498 r598  
     1Tue May 18 01:44:32 PDT 2004  Christian Hammond <chipx86@gnupdate.org> 
     2 
     3    * src/main.c: 
     4      - Setup all accounts for all people in the Evolution address book. 
  • trunk/eds-feed/src/main.c

    r498 r598  
     1/** 
     2 * @file main.c Main file 
     3 * 
     4 * Copyright (C) 2004 Christian Hammond. 
     5 * 
     6 * This program is free software; you can redistribute it and/or 
     7 * modify it under the terms of the GNU General Public License as 
     8 * published by the Free Software Foundation; either version 2 of 
     9 * the License, or (at your option) any later version. 
     10 * 
     11 * This program is distributed in the hope that it will be useful, 
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 * GNU General Public License for more details. 
     15 * 
     16 * You should have received a copy of the GNU General Public 
     17 * License along with this program; if not, write to the Free 
     18 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
     19 * MA  02111-1307  USA 
     20 */ 
     21#include <glib.h> 
     22#include <libgalago/galago.h> 
     23#include <libedata-book/Evolution-DataServer-Addressbook.h> 
     24 
     25#include <libebook/e-book-listener.h> 
     26#include <libebook/e-book-async.h> 
     27#include <libedata-book/e-data-book-factory.h> 
     28#include <bonobo/bonobo-main.h> 
     29 
     30#define E_DATA_BOOK_FACTORY_OAF_ID \ 
     31    "OAFIID:GNOME_Evolution_DataServer_BookFactory" 
     32 
     33static EBookView *book_view = NULL; 
     34static EBook *book = NULL; 
     35static gulong book_view_tag = 0; 
     36 
     37static void 
     38add_accounts(GalagoPerson *person, EContact *contact, 
     39             GalagoService *service, EContactField field) 
     40{ 
     41    GalagoAccount *account; 
     42    GList *im_attr_list, *l; 
     43 
     44    im_attr_list = e_contact_get_attributes(contact, field); 
     45 
     46    for (l = im_attr_list; l != NULL; l = l->next) 
     47    { 
     48        EVCardAttribute *attr = (EVCardAttribute *)l->data; 
     49        char *username; 
     50 
     51        username = e_vcard_attribute_get_value(attr); 
     52 
     53        account = galago_account_new(service, person, username); 
     54 
     55        galago_log(GALAGO_LOG_INFO, "Adding account %s on service %s\n", 
     56                   username, galago_service_get_id(service)); 
     57    } 
     58} 
     59 
     60static void 
     61contacts_changed_cb(EBookView *book_view, const GList *contacts) 
     62{ 
     63#if 0 
     64    const GList *l; 
     65 
     66    for (l = contacts; l != NULL; l = l->next) 
     67    { 
     68        EContact *contact = (EContact *)l->data; 
     69 
     70        printf("contacts_changed_cb: Got a contact!\n"); 
     71    } 
     72#endif 
     73} 
     74 
     75static void 
     76contacts_added_cb(EBookView *book_view, const GList *contacts) 
     77{ 
     78    const GList *l; 
     79    GalagoService *aim, *groupwise, *jabber, *yahoo, *msn, *icq; 
     80 
     81    aim       = galago_service_new("aim",       "AOL Instant Messenger", TRUE); 
     82    groupwise = galago_service_new("groupwise", "Novell Groupwise",      TRUE); 
     83    jabber    = galago_service_new("jabber",    "Jabber",                TRUE); 
     84    yahoo     = galago_service_new("yahoo",     "Yahoo! Messenger",      TRUE); 
     85    msn       = galago_service_new("msn",       "MSN Messenger",         TRUE); 
     86    icq       = galago_service_new("icq",       "ICQ",                   TRUE); 
     87 
     88    for (l = contacts; l != NULL; l = l->next) 
     89    { 
     90        EContact *contact = (EContact *)l->data; 
     91        GalagoPerson *person; 
     92        const char *name; 
     93        const char *uid; 
     94 
     95        uid  = e_contact_get_const(contact, E_CONTACT_UID); 
     96        name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); 
     97 
     98        person = galago_person_new(uid, TRUE); 
     99 
     100        add_accounts(person, contact, aim,    E_CONTACT_IM_AIM); 
     101        add_accounts(person, contact, jabber, E_CONTACT_IM_JABBER); 
     102        add_accounts(person, contact, yahoo,  E_CONTACT_IM_YAHOO); 
     103        add_accounts(person, contact, msn,    E_CONTACT_IM_MSN); 
     104        add_accounts(person, contact, icq,    E_CONTACT_IM_ICQ); 
     105    } 
     106} 
     107 
     108static void 
     109got_book_view_cb(EBook *book, EBookStatus status, EBookView *view, 
     110                 gpointer user_data) 
     111{ 
     112    book_view_tag = 0; 
     113 
     114    if (status != E_BOOK_ERROR_OK) 
     115    { 
     116        fprintf(stderr, "Unable to retrieve book view!\n"); 
     117        exit(1); 
     118    } 
     119 
     120    book_view = view; 
     121 
     122    g_object_ref(book_view); 
     123 
     124    g_signal_connect(G_OBJECT(book_view), "contacts_changed", 
     125                     G_CALLBACK(contacts_changed_cb), book); 
     126    g_signal_connect(G_OBJECT(book_view), "contacts_added", 
     127                     G_CALLBACK(contacts_added_cb), book); 
     128 
     129    e_book_view_start(view); 
     130} 
     131 
     132static void 
     133setup_book_view(void) 
     134{ 
     135    GError *error; 
     136    EBookQuery *query; 
     137 
     138    book = e_book_new(); 
     139 
     140    if (!e_book_load_local_addressbook(book, &error)) 
     141    { 
     142        fprintf(stderr, "Unable to load local address book\n"); 
     143 
     144        g_object_unref(book); 
     145 
     146        exit(1); 
     147    } 
     148 
     149    query = e_book_query_any_field_contains(""); 
     150 
     151    book_view_tag = e_book_async_get_book_view(book, query, NULL, -1, 
     152                                               got_book_view_cb, NULL); 
     153    e_book_query_unref(query); 
     154} 
     155 
     156int 
     157main(int argc, char **argv) 
     158{ 
     159    GMainLoop *loop; 
     160 
     161    loop = g_main_loop_new(NULL, FALSE); 
     162 
     163    if (!galago_glib_init("evolution-data-server", TRUE, NULL)) 
     164    { 
     165        fprintf(stderr, "Unable to initialize Galago.\n"); 
     166        exit(1); 
     167    } 
     168 
     169    if (!bonobo_init_full(NULL, NULL, bonobo_activation_orb_get(), 
     170                          CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) 
     171    { 
     172        fprintf(stderr, "Unable to initialize bonobo.\n"); 
     173        exit(1); 
     174    } 
     175 
     176    bonobo_activate(); 
     177 
     178    setup_book_view(); 
     179 
     180    g_main_loop_run(loop); 
     181 
     182    return 0; 
     183}