enum EDSContactsStorageItemIterator::eCursorInit EDSContactsStorageItemIterator::cursorInit(EBookClient* c)
{
  LOG_FUNC();

  GError *gerror = NULL;

  EContactField sort_fields[]      = { E_CONTACT_FULL_NAME };
  EBookCursorSortType sort_types[] = { E_BOOK_CURSOR_SORT_ASCENDING };

  e_book_client_get_cursor_sync(c, NULL, sort_fields, sort_types, 1, &cursor, NULL, &gerror);

  if (NULL != gerror)
  {
    LOG_ERROR() << "Error e_book_client_get_cursor_sync results: " << GERROR_MESSAGE(gerror)<<std::endl ;
    GERROR_FREE(gerror);
    return eCursorInitFail;
  }

  total = e_book_client_cursor_get_total(cursor);
  LOG_VERBOSE() << "Number of contacts: " << total <<std::endl;

  GERROR_FREE(gerror);

  return eCursorInitOK;
}
static void
cursor_example_update_status (CursorExample *example)
{
	CursorExamplePrivate *priv = example->priv;
	gint                  total, position;
	gchar                *txt;
	gboolean              up_sensitive;
	gboolean              down_sensitive;
	gdouble               fraction;

	total = e_book_client_cursor_get_total (priv->cursor);
	position = e_book_client_cursor_get_position (priv->cursor);

	/* Set the label showing the cursor position and total contacts */
	txt = g_strdup_printf ("Position %d / Total %d", position, total);
	gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progressbar), txt);
	g_free (txt);

	/* Give visual feedback on how far we are into the contact list */
	fraction = position * 1.0F / (total - N_SLOTS);
	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progressbar), fraction);

	/* Update sensitivity of buttons */
	if (total <= N_SLOTS) {
		/* If the amount of contacts is less than the amount of visual slots,
		 * then we cannot browse up and down
		 */
		up_sensitive = FALSE;
		down_sensitive = FALSE;
	} else {
		/* The cursor is always pointing directly before
		 * the first contact visible in the view, so if the
		 * cursor is passed the first contact we can rewind.
		 */
		up_sensitive = position > 0;

		/* If more than N_SLOTS contacts remain, then
		 * we can still scroll down */
		down_sensitive = position < total - N_SLOTS;
	}

	gtk_widget_set_sensitive (priv->browse_up_button, up_sensitive);
	gtk_widget_set_sensitive (priv->browse_down_button, down_sensitive);
}
static gboolean
cursor_example_timeout (CursorExample *example)
{
	CursorExamplePrivate *priv = example->priv;
	gboolean can_move;

	switch (priv->activity) {
	case TIMEOUT_NONE:
		break;

	case TIMEOUT_UP_INITIAL:
	case TIMEOUT_UP_TICK:

		/* Move the cursor backwards by 1 and then refresh the page */
		if (cursor_example_move_cursor (example, E_BOOK_CURSOR_ORIGIN_CURRENT, 0 - 1)) {
			cursor_example_load_page (example, NULL);
			cursor_example_ensure_timeout (example, TIMEOUT_UP_TICK);
		} else
			cursor_example_cancel_timeout (example);

		break;

	case TIMEOUT_DOWN_INITIAL:
	case TIMEOUT_DOWN_TICK:

		/* Avoid scrolling past the end of the list - N_SLOTS */
		can_move = (e_book_client_cursor_get_position (priv->cursor) <
			    e_book_client_cursor_get_total (priv->cursor) - N_SLOTS);

		/* Move the cursor forwards by 1 and then refresh the page */
		if (can_move &&
		    cursor_example_move_cursor (example, E_BOOK_CURSOR_ORIGIN_CURRENT, 1)) {
			cursor_example_load_page (example, NULL);
			cursor_example_ensure_timeout (example, TIMEOUT_DOWN_TICK);
		} else
			cursor_example_cancel_timeout (example);

		break;
	}

	return FALSE;
}