~ubuntu-branches/ubuntu/jaunty/ekiga/jaunty-updates

« back to all changes in this revision

Viewing changes to lib/gmcontacts/gmcontacts-convert.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2008-12-07 10:30:45 UTC
  • mfrom: (1.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20081207103045-iaurrjo4p7d1nngo
Tags: 3.0.1-1ubuntu1
* Merge to Debian experimental, to get Ekiga 3. (LP: #274085) Remaining
  Ubuntu changes:
  - Launchpad Integration: (Ubuntu specific)
    + debian/control.in: Add liblaunchpad-integration-dev build dependency.
    + Add ubuntu_lpi.patch: Call launchpad_integration_add_items() in main() and
      check for the launchpad-integration pkg-config module.
    + Add autoconf.patch: autoconf changes from above patch.
  - Add ubuntu_desktop-file-onlyshowin.patch: Show ekiga in Mobile, too.
    (Ubuntu specific).
  - debian/control.in: Add missing fdupes build dependency for identical
    GNOME help file symlinking. (Debian #505536)
* Drop 42_change_pixmaps.dpatch: Many of the old icons do not exist any
  more, some have been replaced, and keeping the remaining three would make
  them look very inconsistent.
* Convert our dpatches to quilt patches and rewrite them for new upstream
  version.
* Add migrate_2.0_settings.patch: Properly migrate settings from
  2.0. Taken from upstream SVN, thanks to Damien Sandras!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/* Ekiga -- A VoIP and Video-Conferencing application
3
 
 * Copyright (C) 2000-2006 Damien Sandras
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 *
19
 
 *
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.
26
 
 */
27
 
 
28
 
 
29
 
/*
30
 
 *                         gmcontacts-dnd.c  -  description
31
 
 *                         ------------------------------------------
32
 
 *   begin                : July 2004
33
 
 *   copyright            : (C) 2004 by Julien Puydt
34
 
 *   description          : Drag'n drop of contacts made easy (implementation)
35
 
 *
36
 
 */
37
 
 
38
 
#include <string.h>
39
 
 
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__
45
 
#endif
46
 
#include "e-vcard.h"
47
 
 
48
 
gchar *
49
 
gmcontact_to_vcard (GmContact *contact)
50
 
{
51
 
    GString *str = NULL;
52
 
    gchar *result = NULL;
53
 
 
54
 
    g_return_val_if_fail (contact != NULL, NULL);
55
 
 
56
 
    /* do the conversion the brute way, since a GmContact is a rather crude
57
 
     * thing! 
58
 
     */
59
 
    str = g_string_new ("BEGIN:VCARD\r\n");
60
 
    if (contact->fullname)
61
 
      g_string_sprintfa (str, "FN:%s\r\n", contact->fullname);
62
 
    if (contact->email)
63
 
      g_string_sprintfa (str, "EMAIL;INTERNET:%s\r\n", contact->email);
64
 
    if (contact->url)
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",
70
 
                         contact->speeddial);   
71
 
    str = g_string_append (str, "END:VCARD\r\n\r\n");
72
 
 
73
 
    result = str->str;
74
 
    g_string_free (str, FALSE); /* keep the gchar* ! */
75
 
    return result;
76
 
}
77
 
 
78
 
GmContact *
79
 
vcard_to_gmcontact (const gchar *vcard)
80
 
{
81
 
  GmContact *contact = NULL;
82
 
 
83
 
  GList *attr_iter = NULL;
84
 
  EVCardAttribute *attr = NULL;
85
 
  const char *attr_name = NULL;
86
 
  GList *attr_values = NULL;
87
 
  EVCard *evc = NULL;
88
 
 
89
 
  g_return_val_if_fail (vcard != NULL, NULL);
90
 
 
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
94
 
   * we have
95
 
   */
96
 
  evc = e_vcard_new ();
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);
105
 
      if (attr_values)
106
 
        contact->fullname = g_strdup ((char *)attr_values->data);
107
 
    }
108
 
    if (!strcmp (attr_name, EVC_EMAIL)) {
109
 
      attr_values = e_vcard_attribute_get_values (attr);
110
 
      if (attr_values)
111
 
        contact->email = g_strdup ((char *)attr_values->data);
112
 
    }
113
 
    if (!strcmp (attr_name, EVC_X_VIDEO_URL)) {
114
 
      attr_values = e_vcard_attribute_get_values (attr);
115
 
      if (attr_values)
116
 
        contact->url = g_strdup ((char *)attr_values->data);
117
 
    }
118
 
    if (!strcmp (attr_name, EVC_CATEGORIES)) {
119
 
      attr_values = e_vcard_attribute_get_values (attr);
120
 
        if (attr_values)
121
 
          contact->categories = g_strdup ((char *)attr_values->data);
122
 
    }
123
 
    if (!strcmp (attr_name, "X-GNOMEMEETING-SPEEDDIAL")) {
124
 
      attr_values = e_vcard_attribute_get_values (attr);
125
 
      if (attr_values)
126
 
        contact->speeddial = g_strdup ((char *)attr_values->data);
127
 
    }
128
 
    attr_iter = g_list_next (attr_iter);
129
 
  }
130
 
  g_object_unref (evc);
131
 
  
132
 
  return contact;
133
 
}