コード例 #1
0
ファイル: contacts.c プロジェクト: shr-project/shr
static void
moko_contacts_init (MokoContacts *contacts)
{
  MokoContactsPrivate *priv;
  EBook *book;
  EBookView *view;
  EBookQuery *query;
  GList *contact, *c;

  priv = contacts->priv = MOKO_CONTACTS_GET_PRIVATE (contacts);

  priv->contacts = NULL;
  priv->entries = NULL;
  priv->start = NULL;
  priv->prefixes = g_hash_table_new ((GHashFunc)g_str_hash,
                                     (GEqualFunc)g_str_equal);
  priv->uids = g_hash_table_new ((GHashFunc)g_str_hash,
                                     (GEqualFunc)g_str_equal);
  query = e_book_query_any_field_contains ("");

  /* Open the system book and check that it is valid */
  book = priv->book = e_book_new_system_addressbook (NULL);
  if (!book)
  {
    g_warning ("Failed to create system book\n");
    return;
  }
  
  if (!e_book_open (book, FALSE, NULL))
  {
    g_warning ("Failed to open system book\n");
    return;
  }  
  
  if (!e_book_get_contacts (book, query, &contact, NULL)) 	 
  { 	 
     g_warning ("Failed to get contacts from system book\n"); 	 
     return; 	 
  } 	 
  	 
  /* Go through the contacts, creating the contact structs, and entry structs*/ 	 
  for (c = contact; c != NULL; c = c->next) 	 
  { 	 
     moko_contacts_add_contact (contacts, E_CONTACT (c->data)); 	 
  }

  /* Connect to the ebookviews signals */
  if (e_book_get_book_view (book, query, NULL, 0, &view, NULL))
  {
    g_signal_connect (G_OBJECT (view), "contacts-added",
                      G_CALLBACK (on_ebook_contacts_added), (gpointer)contacts);
    g_signal_connect (G_OBJECT (view), "contacts-changed",
                    G_CALLBACK (on_ebook_contacts_changed), (gpointer)contacts);
    g_signal_connect (G_OBJECT (view), "contacts-removed",
                    G_CALLBACK (on_ebook_contacts_removed), (gpointer)contacts);

    e_book_view_start (view);
  }
  e_book_query_unref(query);
}
コード例 #2
0
gint
main (gint argc,
      gchar **argv)
{
#if 0  /* ACCOUNT_MGMT */
	EBook *book;
	gboolean status;
	EBookQuery *query;
	EBookView *view = NULL;
	EBookView *new_view;
	gint i;

	g_type_init ();

	/*
	** the actual ebook foo
	*/

	printf ("loading addressbook\n");
	book = e_book_new_system_addressbook (NULL);
	if (!book) {
		printf ("failed to create ebook\n");
		exit (0);
	}

	status = e_book_open (book, FALSE, NULL);
	if (status == FALSE) {
		printf ("failed to open local addressbook\n");
		exit (0);
	}

	query = e_book_query_any_field_contains ("");

	for (i = 0; i < 500; i++) {
		status = e_book_get_book_view (book, query, NULL, -1, &new_view, NULL);

		g_signal_connect (new_view, "contacts_added", G_CALLBACK (contacts_added), NULL);
		g_signal_connect (new_view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
		g_signal_connect (new_view, "view_complete", G_CALLBACK (view_complete), NULL);

		e_book_view_start (new_view);

		if (view) {
			e_book_view_stop (view);
			g_object_unref (view);
		}

		view = new_view;
	}

	e_book_view_stop (view);
	g_object_unref (view);

	e_book_query_unref (query);
	g_object_unref (book);
#endif /* ACCOUNT_MGMT */

	return 0;
}
コード例 #3
0
static void
setup_and_start_view (EBookView *view)
{
	g_signal_connect (view, "contacts_added", G_CALLBACK (contacts_added), NULL);
	g_signal_connect (view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
	g_signal_connect (view, "view_complete", G_CALLBACK (view_complete), NULL);

	e_book_view_start (view);
}
コード例 #4
0
ファイル: history.c プロジェクト: shr-project/shr
static void
add_number_to_contact (gchar *number)
{
    EBook *book;
    EBookQuery *query;
    EBookView *view;
    GtkWidget *window, *contacts_treeview, *scroll, *groups_combo;
    GtkTreeModel *store, *group_store, *contact_filter;
    GError *err = NULL;

    window = gtk_dialog_new_with_buttons ("Add to Contact", NULL, 0,
					  "Cancel", GTK_RESPONSE_CANCEL,
					  "Add", GTK_RESPONSE_OK,
					  NULL);
    gtk_dialog_set_has_separator (GTK_DIALOG (window), FALSE);

    book = e_book_new_system_addressbook (&err);
    if (err)
      return;
    e_book_open (book, FALSE, &err);
    if (err)
     return;
    query = e_book_query_any_field_contains (NULL);
    e_book_get_book_view (book, query, NULL, 0, &view, &err);
    if (err)
      return;

    e_book_query_unref (query);
    e_book_view_start (view);


    store = hito_contact_store_new (view);

    group_store = hito_group_store_new ();
    hito_group_store_set_view (HITO_GROUP_STORE (group_store), view);
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_all_group_new ());
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_separator_group_new (-99));
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_separator_group_new (99));
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_no_category_group_new ());

    contact_filter = hito_contact_model_filter_new (HITO_CONTACT_STORE (store));

    groups_combo = hito_group_combo_new (HITO_GROUP_STORE (group_store));
    hito_group_combo_connect_filter (HITO_GROUP_COMBO (groups_combo),
                                   HITO_CONTACT_MODEL_FILTER (contact_filter));
    gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (window)->vbox), groups_combo);
    gtk_combo_box_set_active (GTK_COMBO_BOX (groups_combo), 0);



    contacts_treeview = hito_contact_view_new (HITO_CONTACT_STORE (store), HITO_CONTACT_MODEL_FILTER (contact_filter));

    scroll = moko_finger_scroll_new ();
    gtk_widget_set_size_request (scroll, -1, 300);
    gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (window)->vbox), scroll);

    gtk_container_add (GTK_CONTAINER (scroll), contacts_treeview);

    gtk_widget_show_all (scroll);
    gtk_widget_show_all (groups_combo);

    if (gtk_dialog_run (GTK_DIALOG (window)) == GTK_RESPONSE_OK)
    {
      GtkTreeIter iter;
      EContact *contact;
      EVCardAttribute *attr;
      GtkTreeModel *model;
      GtkTreeSelection *selection;

      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (contacts_treeview));

      if (gtk_tree_selection_get_selected (selection, &model, &iter))
      {
        gtk_tree_model_get (model, &iter, COLUMN_CONTACT, &contact, -1);
        if (contact)
        {
          attr = e_vcard_attribute_new ("", EVC_TEL);
          e_vcard_add_attribute_with_value (E_VCARD (contact), attr, number);
          hito_vcard_attribute_set_type (attr, "Other");
          e_book_async_commit_contact (book, contact, NULL, NULL);
          g_object_unref (contact);
        }
      }
    }

    gtk_widget_destroy (window);
    g_object_unref (book);
}
コード例 #5
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);
  }

}
コード例 #6
0
ファイル: main.c プロジェクト: rossburton/eds-tools
int
main (int argc, char **argv) {
    GError *error = NULL;
    GtkWidget *window;
    GtkWidget *tabs, *hbox, *vbox, *query_entry, *query_button;
    EBook *book;
    EBookView *view = NULL;
    EBookQuery *query;

    gtk_init (&argc, &argv);

    book = e_book_new_system_addressbook (&error);
    if (!book) {
        g_warning ("Cannot get book: %s", error->message);
        g_error_free (error);
        return 1;
    }

    if (!e_book_open (book, FALSE, &error)) {
        g_warning ("Cannot get book: %s", error->message);
        g_error_free (error);
        return 1;
    }

    query = e_book_query_any_field_contains ("");
    if (!e_book_get_book_view (book, query, NULL, 0, &view, &error)) {
        g_warning ("Cannot get book view: %s", error->message);
        g_error_free (error);
        return 1;
    }
    e_book_query_unref (query);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Contact Trace");
    gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
    g_signal_connect (window, "delete-event", gtk_main_quit, NULL);
    gtk_widget_show (window);

    tabs = gtk_notebook_new ();
    gtk_container_add (GTK_CONTAINER (window), tabs);

    /* The Contacts tab */
    contacts_view = eds_contact_view_new ();
    eds_contact_view_set_book (EDS_CONTACT_VIEW (contacts_view), book);
    eds_contact_view_set_book_view (EDS_CONTACT_VIEW (contacts_view), view);
    gtk_notebook_append_page (GTK_NOTEBOOK (tabs),
                              contacts_view,
                              gtk_label_new_with_mnemonic ("_Contacts"));

    /* Events Tab */
    event_view = eds_event_view_new ();
    eds_event_view_set_book_view (EDS_EVENT_VIEW (event_view), view);
    gtk_notebook_append_page (GTK_NOTEBOOK (tabs),
                              event_view,
                              gtk_label_new_with_mnemonic ("_Events"));

    /* The Query tab */
    vbox = gtk_vbox_new (FALSE, 8);

    query_view = eds_contact_view_new ();
    eds_contact_view_set_book (EDS_CONTACT_VIEW (query_view), book);

    hbox = gtk_hbox_new (FALSE, 8);
    query_entry = gtk_entry_new ();
    gtk_box_pack_start (GTK_BOX (hbox), query_entry, TRUE, TRUE, 0);
    query_button = gtk_button_new_with_label ("Run");
    g_signal_connect (query_button, "clicked", G_CALLBACK (on_query_button_clicked), query_entry);
    gtk_box_pack_start (GTK_BOX (hbox), query_button, FALSE, FALSE, 0);

    gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), query_view, TRUE, TRUE, 0);
    gtk_notebook_append_page (GTK_NOTEBOOK (tabs),
                              vbox,
                              gtk_label_new_with_mnemonic ("_Queries"));

    e_book_view_start (view);

    gtk_widget_show_all (window);
    gtk_main ();

    return 0;
}