~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to addressbook/libebook/e-contact.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
#define d(x)
43
43
 
 
44
G_DEFINE_TYPE (EContact, e_contact, E_TYPE_VCARD)
 
45
 
44
46
struct _EContactPrivate {
45
47
        gchar *cached_strings [E_CONTACT_FIELD_LAST];
46
48
};
374
376
        ec->priv = g_new0 (EContactPrivate, 1);
375
377
}
376
378
 
377
 
GType
378
 
e_contact_get_type (void)
379
 
{
380
 
        static GType contact_type = 0;
381
 
 
382
 
        if (!contact_type) {
383
 
                static const GTypeInfo contact_info =  {
384
 
                        sizeof (EContactClass),
385
 
                        NULL,           /* base_init */
386
 
                        NULL,           /* base_finalize */
387
 
                        (GClassInitFunc) e_contact_class_init,
388
 
                        NULL,           /* class_finalize */
389
 
                        NULL,           /* class_data */
390
 
                        sizeof (EContact),
391
 
                        0,             /* n_preallocs */
392
 
                        (GInstanceInitFunc) e_contact_init,
393
 
                };
394
 
 
395
 
                contact_type = g_type_register_static (E_TYPE_VCARD, "EContact", &contact_info, 0);
396
 
        }
397
 
 
398
 
        return contact_type;
399
 
}
400
 
 
401
379
static EVCardAttribute*
402
380
e_contact_get_first_attr (EContact *contact, const gchar *attr_name)
403
381
{
1217
1195
 *
1218
1196
 * Creates a new, blank #EContact.
1219
1197
 *
1220
 
 * Return value: A new #EContact.
 
1198
 * Returns: A new #EContact.
1221
1199
 **/
1222
1200
EContact*
1223
1201
e_contact_new (void)
1231
1209
 *
1232
1210
 * Creates a new #EContact based on a vcard.
1233
1211
 *
1234
 
 * Return value: A new #EContact.
 
1212
 * Returns: A new #EContact.
1235
1213
 **/
1236
1214
EContact*
1237
1215
e_contact_new_from_vcard  (const gchar *vcard)
1289
1267
 *
1290
1268
 * Creates a copy of @contact.
1291
1269
 *
1292
 
 * Return value: A new #EContact identical to @contact.
 
1270
 * Returns: A new #EContact identical to @contact.
1293
1271
 **/
1294
1272
EContact*
1295
1273
e_contact_duplicate (EContact *contact)
1312
1290
 *
1313
1291
 * Gets the string representation of @field_id.
1314
1292
 *
1315
 
 * Return value: The string representation of @field_id, or %NULL if it doesn't exist.
 
1293
 * Returns: The string representation of @field_id, or %NULL if it doesn't exist.
1316
1294
 **/
1317
1295
const gchar *
1318
1296
e_contact_field_name (EContactField field_id)
1329
1307
 * Gets a human-readable, translated string representation
1330
1308
 * of @field_id.
1331
1309
 *
1332
 
 * Return value: The human-readable representation of @field_id, or %NULL if it doesn't exist.
 
1310
 * Returns: The human-readable representation of @field_id, or %NULL if it doesn't exist.
1333
1311
 **/
1334
1312
const gchar *
1335
1313
e_contact_pretty_name (EContactField field_id)
1350
1328
 *
1351
1329
 * Gets the vcard attribute corresponding to @field_id, as a string.
1352
1330
 *
1353
 
 * Return value: The vcard attribute corresponding to @field_id, or %NULL if it doesn't exist.
 
1331
 * Returns: The vcard attribute corresponding to @field_id, or %NULL if it doesn't exist.
1354
1332
 **/
1355
1333
const gchar *
1356
1334
e_contact_vcard_attribute  (EContactField field_id)
1366
1344
 *
1367
1345
 * Gets the #EContactField corresponding to the @field_name.
1368
1346
 *
1369
 
 * Return value: An #EContactField corresponding to @field_name, or %0 if it doesn't exist.
 
1347
 * Returns: An #EContactField corresponding to @field_name, or %0 if it doesn't exist.
1370
1348
 **/
1371
1349
EContactField
1372
1350
e_contact_field_id (const gchar *field_name)
1387
1365
 *
1388
1366
 * Gets the #EContactField corresponding to the @vcard_field.
1389
1367
 *
1390
 
 * Return value: An #EContactField corresponding to @vcard_field, or %0 if it doesn't exist.
 
1368
 * Returns: An #EContactField corresponding to @vcard_field, or %0 if it doesn't exist.
 
1369
 *
 
1370
 * Since: 2.26
1391
1371
 **/
1392
1372
EContactField
1393
1373
e_contact_field_id_from_vcard (const gchar *vcard_field)
1414
1394
 *
1415
1395
 * Gets the value of @contact's field specified by @field_id.
1416
1396
 *
1417
 
 * Return value: Depends on the field's type, owned by the caller.
 
1397
 * Returns: Depends on the field's type, owned by the caller.
1418
1398
 **/
1419
1399
gpointer
1420
1400
e_contact_get (EContact *contact, EContactField field_id)
1443
1423
                        GList *list = g_list_copy (e_vcard_attribute_get_values (attr));
1444
1424
                        GList *l;
1445
1425
                        for (l = list; l; l = l->next)
1446
 
                                l->data = g_strdup (l->data);
 
1426
                                l->data = g_strstrip (g_strdup (l->data));
1447
1427
                        return list;
1448
1428
                }
1449
1429
        }
1457
1437
                                v = e_vcard_attribute_get_values (attr);
1458
1438
                                v = g_list_nth (v, info->list_elem);
1459
1439
 
1460
 
                                return v ? g_strdup (v->data) : NULL;
 
1440
                                return v ? g_strstrip (g_strdup (v->data)) : NULL;
1461
1441
                        }
1462
1442
                }
1463
1443
        }
1478
1458
                                        if (num_left-- == 0) {
1479
1459
                                                GList *v = e_vcard_attribute_get_values (attr);
1480
1460
 
1481
 
                                                return v ? g_strdup (v->data) : NULL;
 
1461
                                                return v ? g_strstrip (g_strdup (v->data)) : NULL;
1482
1462
                                        }
1483
1463
                                }
1484
1464
                        }
1490
1470
                if (info->t & E_CONTACT_FIELD_TYPE_STRING) {
1491
1471
                        if (attr) {
1492
1472
                                GList *p = e_vcard_attribute_get_values (attr);
1493
 
                                return g_strdup (p->data);
 
1473
                                return g_strstrip (g_strdup (p->data));
1494
1474
                        }
1495
1475
                        else {
1496
1476
                                return NULL;
1516
1496
                if (info->t & E_CONTACT_FIELD_TYPE_STRUCT)
1517
1497
                        return (gpointer)info->boxed_type_getter();
1518
1498
                else
1519
 
                        return g_strdup (rv);
 
1499
                        return g_strstrip (g_strdup (rv));
1520
1500
        }
1521
1501
        else if (info->t & E_CONTACT_FIELD_TYPE_SYNTHETIC) {
1522
1502
                switch (info->field_id) {
1537
1517
                                        str = e_contact_get_const (contact, E_CONTACT_EMAIL_1);
1538
1518
                        }
1539
1519
 
1540
 
                        return g_strdup (str);
 
1520
                        return g_strstrip (g_strdup (str));
1541
1521
                }
1542
1522
                case E_CONTACT_CATEGORIES: {
1543
1523
                        EVCardAttribute *attr = e_contact_get_first_attr (contact, EVC_CATEGORIES);
1580
1560
                                v = e_vcard_attribute_get_values (attr);
1581
1561
 
1582
1562
                                if (info->t & E_CONTACT_FIELD_TYPE_STRING) {
1583
 
                                        return v ? g_strdup (v->data) : NULL;
 
1563
                                        return v ? g_strstrip (g_strdup (v->data)) : NULL;
1584
1564
                                }
1585
1565
                                else {
1586
 
                                        rv = g_list_append (rv, v ? g_strdup (v->data) : NULL);
 
1566
                                        rv = g_list_append (rv, v ? g_strstrip (g_strdup (v->data)) : NULL);
1587
1567
                                }
1588
1568
                        }
1589
1569
                }
1600
1580
 * Gets the value of @contact's field specified by @field_id, caching
1601
1581
 * the result so it can be freed later.
1602
1582
 *
1603
 
 * Return value: Depends on the field's type, owned by the #EContact.
 
1583
 * Returns: Depends on the field's type, owned by the #EContact.
1604
1584
 **/
1605
1585
gconstpointer
1606
1586
e_contact_get_const (EContact *contact, EContactField field_id)
1653
1633
 *
1654
1634
 * Gets a list of the vcard attributes for @contact's @field_id.
1655
1635
 *
1656
 
 * Return value: A #GList of pointers to #EVCardAttribute, owned by the caller.
 
1636
 * Returns: A #GList of pointers to #EVCardAttribute, owned by the caller.
1657
1637
 **/
1658
1638
GList*
1659
1639
e_contact_get_attributes (EContact *contact, EContactField field_id)
1714
1694
 *
1715
1695
 * Creates a new #EContactName struct.
1716
1696
 *
1717
 
 * Return value: A new #EContactName struct.
 
1697
 * Returns: A new #EContactName struct.
1718
1698
 **/
1719
1699
EContactName*
1720
1700
e_contact_name_new (void)
1728
1708
 *
1729
1709
 * Generates a string representation of @name.
1730
1710
 *
1731
 
 * Return value: The string representation of @name.
 
1711
 * Returns: The string representation of @name.
1732
1712
 **/
1733
1713
gchar *
1734
1714
e_contact_name_to_string(const EContactName *name)
1757
1737
 *
1758
1738
 * Creates a new #EContactName based on the parsed @name_str.
1759
1739
 *
1760
 
 * Return value: A new #EContactName struct.
 
1740
 * Returns: A new #EContactName struct.
1761
1741
 **/
1762
1742
EContactName*
1763
1743
e_contact_name_from_string (const gchar *name_str)
1786
1766
 *
1787
1767
 * Creates a copy of @n.
1788
1768
 *
1789
 
 * Return value: A new #EContactName identical to @n.
 
1769
 * Returns: A new #EContactName identical to @n.
1790
1770
 **/
1791
1771
EContactName*
1792
1772
e_contact_name_copy (EContactName *n)
1827
1807
        g_free (name);
1828
1808
}
1829
1809
 
1830
 
GType
1831
 
e_contact_name_get_type (void)
1832
 
{
1833
 
        static GType type_id = 0;
1834
 
 
1835
 
        if (!type_id)
1836
 
                type_id = g_boxed_type_register_static ("EContactName",
1837
 
                                                        (GBoxedCopyFunc) e_contact_name_copy,
1838
 
                                                        (GBoxedFreeFunc) e_contact_name_free);
1839
 
        return type_id;
 
1810
#define E_CONTACT_DEFINE_BOXED_TYPE(_tp,_nm)                            \
 
1811
        GType                                                           \
 
1812
        _tp ## _get_type (void)                                         \
 
1813
        {                                                               \
 
1814
                static volatile gsize type_id__volatile = 0;            \
 
1815
                                                                        \
 
1816
                if (g_once_init_enter (&type_id__volatile)) {           \
 
1817
                        GType type_id;                                  \
 
1818
                                                                        \
 
1819
                        type_id = g_boxed_type_register_static (_nm,    \
 
1820
                                (GBoxedCopyFunc) _tp ## _copy,          \
 
1821
                                (GBoxedFreeFunc) _tp ## _free);         \
 
1822
                                                                        \
 
1823
                        g_once_init_leave (&type_id__volatile, type_id);\
 
1824
        }                                                               \
 
1825
                                                                        \
 
1826
        return type_id__volatile;                                       \
1840
1827
}
1841
1828
 
 
1829
E_CONTACT_DEFINE_BOXED_TYPE (e_contact_name, "EContactName")
 
1830
 
1842
1831
/**
1843
1832
 * e_contact_date_from_string:
1844
1833
 * @str: a date string in the format YYYY-MM-DD or YYYYMMDD
1845
1834
 *
1846
1835
 * Creates a new #EContactDate based on @str.
1847
1836
 *
1848
 
 * Return value: A new #EContactDate struct.
 
1837
 * Returns: A new #EContactDate struct.
1849
1838
 **/
1850
1839
EContactDate*
1851
1840
e_contact_date_from_string (const gchar *str)
1867
1856
                date->year = str[0] * 1000 + str[1] * 100 + str[2] * 10 + str[3] - '0' * 1111;
1868
1857
                date->month = str[5] * 10 + str[6] - '0' * 11;
1869
1858
                date->day = str[8] * 10 + str[9] - '0' * 11;
1870
 
        } else if ( length == 8 ) {
 
1859
        } else if (length == 8) {
1871
1860
                date->year = str[0] * 1000 + str[1] * 100 + str[2] * 10 + str[3] - '0' * 1111;
1872
1861
                date->month = str[4] * 10 + str[5] - '0' * 11;
1873
1862
                date->day = str[6] * 10 + str[7] - '0' * 11;
1883
1872
 * Generates a date string in the format YYYY-MM-DD based
1884
1873
 * on the values of @dt.
1885
1874
 *
1886
 
 * Return value: A date string, owned by the caller.
 
1875
 * Returns: A date string, owned by the caller.
1887
1876
 **/
1888
1877
gchar *
1889
1878
e_contact_date_to_string (EContactDate *dt)
1904
1893
 *
1905
1894
 * Checks if @dt1 and @dt2 are the same date.
1906
1895
 *
1907
 
 * Return value: %TRUE if @dt1 and @dt2 are equal, %FALSE otherwise.
 
1896
 * Returns: %TRUE if @dt1 and @dt2 are equal, %FALSE otherwise.
1908
1897
 **/
1909
1898
gboolean
1910
1899
e_contact_date_equal (EContactDate *dt1, EContactDate *dt2)
1923
1912
 *
1924
1913
 * Creates a copy of @dt.
1925
1914
 *
1926
 
 * Return value: A new #EContactDate struct identical to @dt.
 
1915
 * Returns: A new #EContactDate struct identical to @dt.
1927
1916
 **/
1928
1917
static EContactDate *
1929
1918
e_contact_date_copy (EContactDate *dt)
1948
1937
        g_free (date);
1949
1938
}
1950
1939
 
1951
 
GType
1952
 
e_contact_date_get_type (void)
1953
 
{
1954
 
        static GType type_id = 0;
1955
 
 
1956
 
        if (!type_id)
1957
 
                type_id = g_boxed_type_register_static ("EContactDate",
1958
 
                                                        (GBoxedCopyFunc) e_contact_date_copy,
1959
 
                                                        (GBoxedFreeFunc) e_contact_date_free);
1960
 
        return type_id;
1961
 
}
 
1940
E_CONTACT_DEFINE_BOXED_TYPE (e_contact_date, "EContactDate")
1962
1941
 
1963
1942
/**
1964
1943
 * e_contact_date_new:
1965
1944
 *
1966
1945
 * Creates a new #EContactDate struct.
1967
1946
 *
1968
 
 * Return value: A new #EContactDate struct.
 
1947
 * Returns: A new #EContactDate struct.
1969
1948
 **/
1970
1949
EContactDate*
1971
1950
e_contact_date_new (void)
2007
1986
 *
2008
1987
 * Creates a copy of @photo.
2009
1988
 *
2010
 
 * Return value: A new #EContactPhoto struct identical to @photo.
 
1989
 * Returns: A new #EContactPhoto struct identical to @photo.
2011
1990
 **/
2012
1991
static EContactPhoto *
2013
1992
e_contact_photo_copy (EContactPhoto *photo)
2032
2011
        return photo2;
2033
2012
}
2034
2013
 
2035
 
GType
2036
 
e_contact_photo_get_type (void)
2037
 
{
2038
 
        static GType type_id = 0;
2039
 
 
2040
 
        if (!type_id)
2041
 
                type_id = g_boxed_type_register_static ("EContactPhoto",
2042
 
                                                        (GBoxedCopyFunc) e_contact_photo_copy,
2043
 
                                                        (GBoxedFreeFunc) e_contact_photo_free);
2044
 
        return type_id;
2045
 
}
 
2014
E_CONTACT_DEFINE_BOXED_TYPE (e_contact_photo, "EContactPhoto")
2046
2015
 
2047
2016
/**
2048
2017
 * e_contact_geo_free:
2049
2018
 * @geo: an #EContactGeo
2050
2019
 *
2051
2020
 * Frees the @geo struct and its contents.
 
2021
 *
 
2022
 * Since: 1.12
2052
2023
 **/
2053
2024
void
2054
2025
e_contact_geo_free (EContactGeo *geo)
2066
2037
        return geo2;
2067
2038
}
2068
2039
 
2069
 
GType
2070
 
e_contact_geo_get_type (void)
2071
 
{
2072
 
        static GType type_id = 0;
2073
 
 
2074
 
        if (!type_id)
2075
 
                type_id = g_boxed_type_register_static ("EContactGeo",
2076
 
                                                        (GBoxedCopyFunc) e_contact_geo_copy,
2077
 
                                                        (GBoxedFreeFunc) e_contact_geo_free);
2078
 
        return type_id;
2079
 
}
 
2040
E_CONTACT_DEFINE_BOXED_TYPE (e_contact_geo, "EContactGeo")
2080
2041
 
2081
2042
/**
2082
2043
 * e_contact_address_free:
2119
2080
        return address2;
2120
2081
}
2121
2082
 
2122
 
GType
2123
 
e_contact_address_get_type (void)
2124
 
{
2125
 
        static GType type_id = 0;
2126
 
 
2127
 
        if (!type_id)
2128
 
                type_id = g_boxed_type_register_static ("EContactAddress",
2129
 
                                                        (GBoxedCopyFunc) e_contact_address_copy,
2130
 
                                                        (GBoxedFreeFunc) e_contact_address_free);
2131
 
        return type_id;
2132
 
}
 
2083
E_CONTACT_DEFINE_BOXED_TYPE (e_contact_address, "EContactAddress")
2133
2084
 
2134
2085
/**
2135
2086
 * e_contact_cert_free:
2158
2109
        return cert2;
2159
2110
}
2160
2111
 
2161
 
GType
2162
 
e_contact_cert_get_type (void)
2163
 
{
2164
 
        static GType type_id = 0;
2165
 
 
2166
 
        if (!type_id)
2167
 
                type_id = g_boxed_type_register_static ("EContactCert",
2168
 
                                                        (GBoxedCopyFunc) e_contact_cert_copy,
2169
 
                                                        (GBoxedFreeFunc) e_contact_cert_free);
2170
 
        return type_id;
2171
 
}
 
2112
E_CONTACT_DEFINE_BOXED_TYPE (e_contact_cert, "EContactCert")