void contact_list_editor_source_menu_changed_cb (GtkWidget *widget) { EContactListEditor *editor; ESource *source; editor = contact_list_editor_extract (widget); source = e_source_combo_box_get_active (E_SOURCE_COMBO_BOX (widget)); if (e_source_equal (e_book_get_source (editor->priv->book), source)) return; editor->priv->load_book = e_book_new (source, NULL); editor->priv->load_source_id = addressbook_load ( editor->priv->load_book, (EBookCallback) contact_list_editor_book_loaded, editor); }
static GSList *traverse_sources(GSList *ebooks, GSList *sources, char **default_src) { GError *gerr = NULL; for (; sources != NULL; sources = g_slist_next(sources)) { char *uri; ESource *source = E_SOURCE(sources->data); EBook *ebook = e_book_new(source, &gerr); if (ebook == NULL) { error("Can't create user's address book: %s", gerr->message); g_clear_error(&gerr); continue; } uri = e_source_get_uri(source); if (g_strcmp0(*default_src, uri) == 0) { g_free(uri); continue; } g_free(uri); if (e_book_open(ebook, FALSE, &gerr) == FALSE) { error("Can't open e-book address book: %s", gerr->message); g_object_unref(ebook); g_clear_error(&gerr); continue; } if (*default_src == NULL) *default_src = e_source_get_uri(source); DBG("%s address book opened", e_source_peek_name(source)); ebooks = g_slist_append(ebooks, ebook); } return ebooks; }
/* For now we show all the sources from a group in a List. Later we will us a Tree to show them usings groups. */ static void eds_load_resources (ESourceGroup *group, PlannerPlugin *plugin, const gchar *search) { GtkListStore *model; GSList *sources, *sl; PlannerPluginPriv *priv; g_return_if_fail (E_IS_SOURCE_GROUP (group)); sources = e_source_group_peek_sources (group); priv = plugin->priv; model = GTK_LIST_STORE (priv->resources_model); if (sources == NULL) { if (model) { gtk_list_store_clear (model); } gtk_widget_set_sensitive (glade_xml_get_widget (priv->glade, "search_box"), FALSE); return; } if (model) { gtk_list_store_clear (model); } else { GtkCellRenderer *toggle; guint column_pos; GtkTreeViewColumn *column; model = gtk_list_store_new (NUM_RESOURCE_COLS, G_TYPE_STRING, /* name */ G_TYPE_STRING, /* email */ G_TYPE_BOOLEAN, /* import */ GDK_TYPE_PIXBUF, /* photo */ G_TYPE_OBJECT); /* full contact */ priv->resources_model = GTK_TREE_MODEL (model); gtk_tree_view_set_model (priv->resources_tree_view, priv->resources_model); /* Name Column with sorting features */ column_pos = gtk_tree_view_insert_column_with_attributes (priv->resources_tree_view, -1, _("Name"), gtk_cell_renderer_text_new (), "text", COL_RESOURCE_NAME, NULL); column = gtk_tree_view_get_column (priv->resources_tree_view, column_pos-1); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->resources_model), column_pos-1, eds_compare_field, GINT_TO_POINTER (column_pos-1), NULL); gtk_tree_view_column_set_sort_column_id (column, column_pos-1); g_signal_connect (gtk_tree_view_get_column (priv->resources_tree_view, column_pos-1), "clicked", G_CALLBACK (eds_column_clicked), plugin); /* Email column with sorting features */ column_pos = gtk_tree_view_insert_column_with_attributes (priv->resources_tree_view, -1, _("Email"), gtk_cell_renderer_text_new (), "text", COL_RESOURCE_EMAIL, NULL); column = gtk_tree_view_get_column (priv->resources_tree_view, column_pos-1); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->resources_model), column_pos-1, eds_compare_field, GINT_TO_POINTER (column_pos-1), NULL); gtk_tree_view_column_set_sort_column_id (column, column_pos-1); g_signal_connect (gtk_tree_view_get_column (priv->resources_tree_view, column_pos-1), "clicked", G_CALLBACK (eds_column_clicked), plugin); /* Import */ toggle = gtk_cell_renderer_toggle_new (); gtk_tree_view_insert_column_with_attributes (priv->resources_tree_view, -1, _("Import"), toggle, "active", COL_RESOURCE_SELECTED, NULL); g_signal_connect (toggle, "toggled", G_CALLBACK (eds_resource_selected), plugin); /* Photo */ gtk_tree_view_insert_column_with_attributes (priv->resources_tree_view, -1, _("Photo"), gtk_cell_renderer_pixbuf_new (), "pixbuf", COL_RESOURCE_PHOTO, NULL); gtk_tree_view_set_headers_clickable (priv->resources_tree_view, TRUE); } for (sl = sources; sl; sl = sl->next) { EBook *client; AsyncQuery *async_query = g_new0 (AsyncQuery, 1); g_free (plugin->priv->current_query_id); plugin->priv->current_query_id = e_uid_new (); async_query->plugin = plugin; async_query->uid = plugin->priv->current_query_id; async_query->search = search; client = e_book_new (sl->data, NULL); g_message ("Open book async query: %s", async_query->uid); e_book_async_open (client, TRUE, eds_receive_book_cb, async_query); eds_plugin_busy (plugin, TRUE); } }
/* Pilot syncing callbacks */ static gint pre_sync (GnomePilotConduit *conduit, GnomePilotDBInfo *dbi, EAddrConduitContext *ctxt) { GnomePilotConduitSyncAbs *abs_conduit; EBookQuery *query; GList *l; int len; char *filename; char *change_id; char *auth; gint num_records, add_records = 0, mod_records = 0, del_records = 0; #ifdef PILOT_LINK_0_12 pi_buffer_t *buffer; #else unsigned char *buf; #endif abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit); LOG (g_message ( "---------------------------------------------------------\n" )); LOG (g_message ( "pre_sync: Addressbook Conduit v.%s", CONDUIT_VERSION )); /* g_message ("Addressbook Conduit v.%s", CONDUIT_VERSION); */ ctxt->dbi = dbi; if (ctxt->cfg->source) { ctxt->ebook = e_book_new (ctxt->cfg->source, NULL); } else { ctxt->ebook = e_book_new_default_addressbook (NULL); } auth = (gchar *)e_source_get_property (ctxt->cfg->source, "auth"); if (auth) { LOG (g_message ("contacts needs authentication\n")); g_signal_connect (ctxt->ebook, "auth_required", G_CALLBACK (addressbook_authenticate), ctxt->cfg->source); } if (!ctxt->ebook || !e_book_open (ctxt->ebook, TRUE, NULL)) { WARN(_("Could not load addressbook")); gnome_pilot_conduit_error (conduit, _("Could not load addressbook")); return -1; } /* Load the uid <--> pilot id mappings */ filename = map_name (ctxt); e_pilot_map_read (filename, &ctxt->map); g_free (filename); /* Get a list of all contacts */ if (!(query = e_book_query_any_field_contains (""))) { LOG (g_warning ("Failed to get EBookQuery")); return -1; } if (!e_book_get_contacts (ctxt->ebook, query, &ctxt->cards, NULL)) { LOG (g_warning ("Failed to get Contacts")); e_book_query_unref (query); return -1; } e_book_query_unref (query); /* Count and hash the changes */ change_id = g_strdup_printf ("pilot-sync-evolution-addressbook-%d", ctxt->cfg->pilot_id); if (!e_book_get_changes (ctxt->ebook, change_id, &ctxt->changed, NULL)) return -1; ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal); g_free (change_id); for (l = ctxt->changed; l != NULL; l = l->next) { EBookChange *ebc = l->data; const char *uid; uid = e_contact_get_const (ebc->contact, E_CONTACT_UID); if (!e_pilot_map_uid_is_archived (ctxt->map, uid)) { g_hash_table_insert (ctxt->changed_hash, g_strdup (uid), ebc); switch (ebc->change_type) { case E_BOOK_CHANGE_CARD_ADDED: add_records++; break; case E_BOOK_CHANGE_CARD_MODIFIED: mod_records++; break; case E_BOOK_CHANGE_CARD_DELETED: del_records++; break; } } else if (ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) { e_pilot_map_remove_by_uid (ctxt->map, uid); } } /* Set the count information */ num_records = g_list_length (ctxt->cards); gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records); gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records); gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records); gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records); #ifdef PILOT_LINK_0_12 buffer = pi_buffer_new(DLP_BUF_SIZE); if(buffer == NULL){ return pi_set_error(dbi->pilot_socket, PI_ERR_GENERIC_MEMORY); } len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, DLP_BUF_SIZE, buffer); #else buf = (unsigned char*)g_malloc (0xffff); len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, (unsigned char *)buf, 0xffff); #endif if (len < 0) { WARN (_("Could not read pilot's Address application block")); WARN ("dlp_ReadAppBlock(...) = %d", len); gnome_pilot_conduit_error (conduit, _("Could not read pilot's Address application block")); return -1; } #ifdef PILOT_LINK_0_12 unpack_AddressAppInfo (&(ctxt->ai), buffer->data, len); pi_buffer_free (buffer); #else unpack_AddressAppInfo (&(ctxt->ai), buf, len); g_free (buf); #endif check_for_slow_setting (conduit, ctxt); if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot || ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyFromPilot) ctxt->map->write_touched_only = TRUE; return 0; }
static void add_gnome_addressbook(GList **address_list) { ESourceRegistry * registry = NULL; GError *error = NULL; GList *a; registry = e_source_registry_new_sync (NULL, &error); if (!registry || error) { debug_print("Error: Failed to get access to source registry: %s\n", error->message); g_error_free(error); return; } // create book accessor if necessary if(!eds_books) { GList *list_sources = e_source_registry_list_sources (registry, E_SOURCE_EXTENSION_ADDRESS_BOOK); for (a = list_sources; a; a = a->next) { ESource *source = E_SOURCE (a->data); if (e_source_get_enabled(source)) { EBook *eds_book = e_book_new(source, &error); if(!eds_book) { g_list_free_full(list_sources, g_object_unref); debug_print("Error: Could not get eds addressbook: %s\n", error->message); g_error_free(error); return; } eds_books = g_list_append (eds_books, eds_book); } } g_list_free_full(list_sources, g_object_unref); } for (a = eds_books; a; a = a->next) { EBook *eds_book = a->data; EBookQuery *query; EBookView *view; // open book if necessary if(!e_book_is_opened(eds_book) && !e_book_open(eds_book, TRUE, &error)) { debug_print("Error: Could not open eds addressbook: %s\n", error->message); g_error_free(error); return; } // query book query = e_book_query_field_exists(E_CONTACT_EMAIL); if(!e_book_get_book_view(eds_book, query, NULL, 0, &view, &error)) { debug_print("Error: Could not get eds addressbook view: %s\n", error->message); g_error_free(error); } e_book_query_unref(query); g_signal_connect(G_OBJECT(view), "contacts-added", G_CALLBACK(eds_contacts_added_cb), address_list); g_signal_connect(G_OBJECT(view), "sequence-complete", G_CALLBACK(eds_sequence_complete_cb), NULL); eds_waiting = TRUE; e_book_view_start(view); while(eds_waiting) gtk_main_iteration(); e_book_view_stop(view); g_object_unref(view); } }