2
/* Ekiga -- A VoIP and Video-Conferencing application
3
* Copyright (C) 2000-2006 Damien Sandras
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20
* Ekiga is licensed under the GPL license and as a special exception,
21
* you have permission to link or otherwise combine this program with the
22
* programs OPAL, OpenH323 and PWLIB, and distribute the combination,
23
* without applying the requirements of the GNU GPL to the OPAL, OpenH323
24
* and PWLIB programs, as long as you do follow the requirements of the
25
* GNU GPL for all the rest of the software thus combined.
30
* gmcontacts-dnd.c - description
31
* ------------------------------------------
33
* copyright : (C) 2004 by Julien Puydt
34
* description : Drag'n drop of contacts made easy (implementation)
40
#include "gmcontacts.h"
41
#ifndef _GM_CONTACTS_H_INSIDE__
42
#define _GM_CONTACTS_H_INSIDE__
43
#include "gmcontacts-convert.h"
44
#undef _GM_CONTACTS_H_INSIDE__
49
gmcontact_to_vcard (GmContact *contact)
54
g_return_val_if_fail (contact != NULL, NULL);
56
/* do the conversion the brute way, since a GmContact is a rather crude
59
str = g_string_new ("BEGIN:VCARD\r\n");
60
if (contact->fullname)
61
g_string_sprintfa (str, "FN:%s\r\n", contact->fullname);
63
g_string_sprintfa (str, "EMAIL;INTERNET:%s\r\n", contact->email);
65
g_string_sprintfa (str, "X-EVOLUTION-VIDEO-URL:%s\r\n", contact->url);
66
if (contact->categories)
67
g_string_sprintfa (str, "CATEGORIES:%s\r\n", contact->categories);
68
if (contact->speeddial)
69
g_string_sprintfa (str, "X-GNOMEMEETING-SPEEDDIAL:%s\r\n",
71
str = g_string_append (str, "END:VCARD\r\n\r\n");
74
g_string_free (str, FALSE); /* keep the gchar* ! */
79
vcard_to_gmcontact (const gchar *vcard)
81
GmContact *contact = NULL;
83
GList *attr_iter = NULL;
84
EVCardAttribute *attr = NULL;
85
const char *attr_name = NULL;
86
GList *attr_values = NULL;
89
g_return_val_if_fail (vcard != NULL, NULL);
91
/* parsing a vcard may not be really simple, as it can have all fields
92
* a GmContact uses, and much, much more: use the evolution-data-server
93
* code to make the hard work, then loop over the attributes and see what
97
e_vcard_construct (evc, vcard);
98
contact = gmcontact_new ();
99
attr_iter = e_vcard_get_attributes (evc);
100
while (attr_iter != NULL) {
101
attr = (EVCardAttribute *)attr_iter->data;
102
attr_name = e_vcard_attribute_get_name (attr);
103
if (!strcmp (attr_name, EVC_FN)) {
104
attr_values = e_vcard_attribute_get_values (attr);
106
contact->fullname = g_strdup ((char *)attr_values->data);
108
if (!strcmp (attr_name, EVC_EMAIL)) {
109
attr_values = e_vcard_attribute_get_values (attr);
111
contact->email = g_strdup ((char *)attr_values->data);
113
if (!strcmp (attr_name, EVC_X_VIDEO_URL)) {
114
attr_values = e_vcard_attribute_get_values (attr);
116
contact->url = g_strdup ((char *)attr_values->data);
118
if (!strcmp (attr_name, EVC_CATEGORIES)) {
119
attr_values = e_vcard_attribute_get_values (attr);
121
contact->categories = g_strdup ((char *)attr_values->data);
123
if (!strcmp (attr_name, "X-GNOMEMEETING-SPEEDDIAL")) {
124
attr_values = e_vcard_attribute_get_values (attr);
126
contact->speeddial = g_strdup ((char *)attr_values->data);
128
attr_iter = g_list_next (attr_iter);
130
g_object_unref (evc);