static GtkWidget *
vcard_get_preview (EImport *ei,
                   EImportTarget *target,
                   EImportImporter *im)
{
	GtkWidget *preview;
	GSList *contacts;
	gchar *contents;
	VCardEncoding encoding;
	EImportTargetURI *s = (EImportTargetURI *) target;
	gchar *filename;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (filename == NULL) {
		g_message (G_STRLOC ": Couldn't get filename from URI '%s'", s->uri_src);
		return NULL;
	}

	encoding = guess_vcard_encoding (filename);
	if (encoding == VCARD_ENCODING_NONE) {
		g_free (filename);
		return NULL;
	}

	if (!g_file_get_contents (filename, &contents, NULL, NULL)) {
		g_message (G_STRLOC ": Couldn't read file.");
		g_free (filename);
		return NULL;
	}

	g_free (filename);

	if (encoding == VCARD_ENCODING_UTF16) {
		gchar *tmp;

		gunichar2 *contents_utf16 = (gunichar2 *) contents;
		tmp = utf16_to_utf8 (contents_utf16);
		g_free (contents);
		contents = tmp;
	} else if (encoding == VCARD_ENCODING_LOCALE) {
		gchar *tmp;
		tmp = g_locale_to_utf8 (contents, -1, NULL, NULL, NULL);
		g_free (contents);
		contents = tmp;
	}

	contacts = eab_contact_list_from_string (contents);
	g_free (contents);

	preview = evolution_contact_importer_get_preview_widget (contacts);

	e_client_util_free_object_slist (contacts);

	return preview;
}
示例#2
0
gboolean
eab_source_and_contact_list_from_string (ESourceRegistry *registry,
                                         const gchar *str,
                                         ESource **out_source,
                                         GSList **out_contacts)
{
	ESource *source;
	const gchar *s0, *s1;
	gchar *uid;
	gboolean success = FALSE;

	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
	g_return_val_if_fail (str != NULL, FALSE);

	if (out_source != NULL)
		*out_source = NULL;  /* in case we fail */

	if (out_contacts != NULL)
		*out_contacts = NULL;  /* in case we fail */

	if (!strncmp (str, "Book: ", 6)) {
		s0 = str + 6;
		s1 = strchr (str, '\r');

		if (!s1)
			s1 = strchr (str, '\n');
	} else {
		s0 = NULL;
		s1 = NULL;
	}

	if (!s0 || !s1)
		return FALSE;

	uid = g_strndup (s0, s1 - s0);
	source = e_source_registry_ref_source (registry, uid);
	if (source != NULL) {
		if (out_source != NULL)
			*out_source = g_object_ref (source);
		g_object_unref (source);
		success = TRUE;
	}
	g_free (uid);

	if (success && out_contacts != NULL)
		*out_contacts = eab_contact_list_from_string (str);

	return success;
}
示例#3
0
/*
 * This function implements the Bonobo::PersistStream:load method.
 */
static void
pstream_load (BonoboPersistStream *ps, const Bonobo_Stream stream,
              Bonobo_Persist_ContentType type, void *data,
              CORBA_Environment *ev)
{
    GList *list;
    char *vcard;
    EABVCardControl *vcard_control = data;

    if (type && g_ascii_strcasecmp (type, "text/vCard") != 0 &&
            g_ascii_strcasecmp (type, "text/x-vCard") != 0) {
        CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
                             ex_Bonobo_Persist_WrongDataType, NULL);
        return;
    }

    if ((vcard = stream_read (stream)) == NULL) {
        CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
                             ex_Bonobo_Persist_FileNotFound, NULL);
        return;
    }

    g_list_foreach (
        vcard_control->card_list,
        (GFunc) g_object_unref, NULL);
    g_list_free (vcard_control->card_list);

    list = eab_contact_list_from_string (vcard);
    g_free(vcard);
    vcard_control->card_list = list;
    if (list) {
        eab_contact_display_render (vcard_control->display, E_CONTACT (list->data),
                                    vcard_control->render_mode);
    }
    if (list && list->next) {
        char *message;
        int length = g_list_length (list) - 1;
        message = g_strdup_printf (ngettext("There is one other contact.",
                                            "There are %d other contacts.", length),
                                   length);
        gtk_label_set_text (GTK_LABEL (vcard_control->label), message);
        g_free (message);
        gtk_widget_show (vcard_control->label);
    } else {
        gtk_widget_hide (vcard_control->label);
    }
} /* pstream_load */
static void
book_loaded_cb (GObject *source_object,
                GAsyncResult *result,
                gpointer user_data)
{
	ESource *source = E_SOURCE (source_object);
	VCardImporter *gci = user_data;
	EClient *client = NULL;

	e_client_utils_open_new_finish (source, result, &client, NULL);

	if (client == NULL) {
		vcard_import_done (gci);
		return;
	}

	gci->book_client = E_BOOK_CLIENT (client);

	if (gci->encoding == VCARD_ENCODING_UTF16) {
		gchar *tmp;

		gunichar2 *contents_utf16 = (gunichar2 *) gci->contents;
		tmp = utf16_to_utf8 (contents_utf16);
		g_free (gci->contents);
		gci->contents = tmp;

	} else if (gci->encoding == VCARD_ENCODING_LOCALE) {
		gchar *tmp;
		tmp = g_locale_to_utf8 (gci->contents, -1, NULL, NULL, NULL);
		g_free (gci->contents);
		gci->contents = tmp;
	}

	gci->contactlist = eab_contact_list_from_string (gci->contents);
	g_free (gci->contents);
	gci->contents = NULL;
	gci->iterator = gci->contactlist;
	gci->total = g_slist_length (gci->contactlist);

	if (gci->iterator)
		gci->idle_id = g_idle_add (vcard_import_contacts, gci);
	else
		vcard_import_done (gci);
}
void
contact_list_editor_drag_data_received_cb (GtkWidget *widget,
                                           GdkDragContext *context,
                                             gint x, gint y,
                                             GtkSelectionData *selection_data,
                                             guint info,
                                             guint time)
{
	EContactListEditor *editor;
	EContactListModel *model;
	gchar *target_type;
	gboolean changed = FALSE;
	gboolean handled = FALSE;
	GList *list, *iter;

	editor = contact_list_editor_extract (widget);

	model = E_CONTACT_LIST_MODEL (editor->priv->model);
	target_type = gdk_atom_name (selection_data->target);

	if (strcmp (target_type, VCARD_TYPE) != 0)
		goto exit;

	list = eab_contact_list_from_string ((gchar *) selection_data->data);

	if (list != NULL)
		handled = TRUE;

	for (iter = list; iter != NULL; iter = iter->next) {
		EContact *contact = iter->data;
		const gchar *email;

		if (e_contact_get (contact, E_CONTACT_IS_LIST))
			continue;

		email = e_contact_get (contact, E_CONTACT_EMAIL_1);
		if (email == NULL) {
			g_warning (
				"Contact with no email-ids listed "
				"can't be added to a Contact-List");
			continue;
		}

		if (!contact_list_editor_contact_exists (model, email)) {
			/* Hard-wired for default e-mail */
			e_contact_list_model_add_contact (model, contact, 0);
			changed = TRUE;
		}
	}

	g_list_foreach (list, (GFunc) g_object_unref, NULL);
	g_list_free (list);

	contact_list_editor_scroll_to_end (editor);

	if (changed) {
		editor->priv->changed = TRUE;
		contact_list_editor_update (editor);
	}

exit:
	gtk_drag_finish (context, handled, FALSE, time);
}