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

« back to all changes in this revision

Viewing changes to calendar/backends/file/e-cal-backend-file.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:
45
45
#define O_BINARY 0
46
46
#endif
47
47
 
 
48
G_DEFINE_TYPE (ECalBackendFile, e_cal_backend_file, E_TYPE_CAL_BACKEND_SYNC)
 
49
 
48
50
/* Placeholder for each component and its recurrences */
49
51
typedef struct {
50
52
        ECalComponent *full_object;
296
298
{
297
299
        ECalBackendFile *cbfile;
298
300
        ECalBackendFilePrivate *priv;
 
301
        ESource *source;
299
302
 
300
303
        cbfile = E_CAL_BACKEND_FILE (object);
301
304
        priv = cbfile->priv;
306
309
 
307
310
        free_calendar_data (cbfile);
308
311
 
 
312
        source = e_cal_backend_get_source (E_CAL_BACKEND (cbfile));
 
313
        if (source)
 
314
                g_signal_handlers_disconnect_matched (source, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, cbfile);
 
315
 
309
316
        if (G_OBJECT_CLASS (parent_class)->dispose)
310
317
                (* G_OBJECT_CLASS (parent_class)->dispose) (object);
311
318
}
1233
1240
        return add || to_remove != NULL;
1234
1241
}
1235
1242
 
 
1243
static void
 
1244
source_changed_cb (ESource *source, ECalBackend *backend)
 
1245
{
 
1246
        const gchar *value;
 
1247
 
 
1248
        g_return_if_fail (source != NULL);
 
1249
        g_return_if_fail (backend != NULL);
 
1250
        g_return_if_fail (E_IS_CAL_BACKEND (backend));
 
1251
 
 
1252
        value = e_source_get_property (source, "custom-file");
 
1253
        if (value && *value) {
 
1254
                ECalBackendFile *cbfile;
 
1255
                gboolean forced_readonly;
 
1256
 
 
1257
                cbfile = E_CAL_BACKEND_FILE (backend);
 
1258
                g_return_if_fail (cbfile != NULL);
 
1259
 
 
1260
                value = e_source_get_property (source, "custom-file-readonly");
 
1261
                forced_readonly = value && g_str_equal (value, "1");
 
1262
 
 
1263
                if ((forced_readonly != FALSE) != (cbfile->priv->read_only != FALSE)) {
 
1264
                        cbfile->priv->read_only = forced_readonly;
 
1265
                        if (!forced_readonly) {
 
1266
                                gchar *str_uri = get_uri_string (backend);
 
1267
 
 
1268
                                g_return_if_fail (str_uri != NULL);
 
1269
 
 
1270
                                cbfile->priv->read_only = g_access (str_uri, W_OK) != 0;
 
1271
 
 
1272
                                g_free (str_uri);
 
1273
                        }
 
1274
 
 
1275
                        e_cal_backend_notify_readonly (backend, cbfile->priv->read_only);
 
1276
                }
 
1277
        }
 
1278
}
 
1279
 
1236
1280
/* Open handler for the file backend */
1237
1281
static ECalBackendSyncStatus
1238
1282
e_cal_backend_file_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists,
1275
1319
                if (!priv->read_only) {
1276
1320
                        ESource *source = e_cal_backend_get_source (E_CAL_BACKEND (backend));
1277
1321
 
1278
 
                        if (source && e_source_get_property (source, "custom-file-readonly") && g_str_equal (e_source_get_property (source, "custom-file-readonly"), "1"))
1279
 
                                priv->read_only = TRUE;
 
1322
                        if (source) {
 
1323
                                g_signal_connect (source, "changed", G_CALLBACK (source_changed_cb), backend);
 
1324
 
 
1325
                                if (e_source_get_property (source, "custom-file-readonly") && g_str_equal (e_source_get_property (source, "custom-file-readonly"), "1"))
 
1326
                                        priv->read_only = TRUE;
 
1327
                        }
1280
1328
                }
1281
1329
 
1282
1330
                if (priv->default_zone && add_timezone (priv->icalcomp, priv->default_zone)) {
1512
1560
        return GNOME_Evolution_Calendar_Success;
1513
1561
}
1514
1562
 
1515
 
/* Get_timezone_object handler for the file backend */
1516
 
static ECalBackendSyncStatus
1517
 
e_cal_backend_file_get_timezone (ECalBackendSync *backend, EDataCal *cal, const gchar *tzid, gchar **object)
1518
 
{
1519
 
        ECalBackendFile *cbfile;
1520
 
        ECalBackendFilePrivate *priv;
1521
 
        icaltimezone *zone;
1522
 
        icalcomponent *icalcomp;
1523
 
 
1524
 
        cbfile = E_CAL_BACKEND_FILE (backend);
1525
 
        priv = cbfile->priv;
1526
 
 
1527
 
        g_return_val_if_fail (priv->icalcomp != NULL, GNOME_Evolution_Calendar_NoSuchCal);
1528
 
        g_return_val_if_fail (tzid != NULL, GNOME_Evolution_Calendar_ObjectNotFound);
1529
 
 
1530
 
        g_static_rec_mutex_lock (&priv->idle_save_rmutex);
1531
 
 
1532
 
        if (!strcmp (tzid, "UTC")) {
1533
 
                zone = icaltimezone_get_utc_timezone ();
1534
 
        } else {
1535
 
                zone = icalcomponent_get_timezone (priv->icalcomp, tzid);
1536
 
                if (!zone) {
1537
 
                        zone = icaltimezone_get_builtin_timezone_from_tzid (tzid);
1538
 
                        if (!zone) {
1539
 
                                g_static_rec_mutex_unlock (&priv->idle_save_rmutex);
1540
 
                                return GNOME_Evolution_Calendar_ObjectNotFound;
1541
 
                        }
1542
 
                }
1543
 
        }
1544
 
 
1545
 
        icalcomp = icaltimezone_get_component (zone);
1546
 
        if (!icalcomp) {
1547
 
                g_static_rec_mutex_unlock (&priv->idle_save_rmutex);
1548
 
                return GNOME_Evolution_Calendar_InvalidObject;
1549
 
        }
1550
 
 
1551
 
        *object = icalcomponent_as_ical_string_r (icalcomp);
1552
 
 
1553
 
        g_static_rec_mutex_unlock (&priv->idle_save_rmutex);
1554
 
        return GNOME_Evolution_Calendar_Success;
1555
 
}
1556
 
 
1557
1563
/* Add_timezone handler for the file backend */
1558
1564
static ECalBackendSyncStatus
1559
1565
e_cal_backend_file_add_timezone (ECalBackendSync *backend, EDataCal *cal, const gchar *tzobj)
2077
2083
                zone = icaltimezone_get_utc_timezone ();
2078
2084
        else {
2079
2085
                zone = icalcomponent_get_timezone (priv->icalcomp, tzid);
2080
 
                if (!zone)
2081
 
                        zone = icaltimezone_get_builtin_timezone_from_tzid (tzid);
2082
2086
 
2083
2087
                if (!zone && E_CAL_BACKEND_CLASS (parent_class)->internal_get_timezone)
2084
2088
                        zone = E_CAL_BACKEND_CLASS (parent_class)->internal_get_timezone (backend, tzid);
2483
2487
{
2484
2488
        gchar *hash_rid;
2485
2489
        ECalComponent *comp;
 
2490
        struct icaltimetype current;
2486
2491
 
2487
2492
        if (!rid || !*rid)
2488
2493
                return;
2508
2513
                                     icaltime_from_string (rid), CALOBJ_MOD_THIS);
2509
2514
 
2510
2515
        /* Since we are only removing one instance of recurrence
2511
 
       event, update the last modified time on the component */
2512
 
        struct icaltimetype current = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
 
2516
           event, update the last modified time on the component */
 
2517
        current = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
2513
2518
        e_cal_component_set_last_modified (obj_data->full_object, &current);
2514
2519
 
2515
2520
        /* add the modified object to the beginning of the list,
3103
3108
        sync_class->get_object_sync = e_cal_backend_file_get_object;
3104
3109
        sync_class->get_object_list_sync = e_cal_backend_file_get_object_list;
3105
3110
        sync_class->get_attachment_list_sync = e_cal_backend_file_get_attachment_list;
3106
 
        sync_class->get_timezone_sync = e_cal_backend_file_get_timezone;
3107
3111
        sync_class->add_timezone_sync = e_cal_backend_file_add_timezone;
3108
3112
        sync_class->set_default_zone_sync = e_cal_backend_file_set_default_zone;
3109
3113
        sync_class->get_freebusy_sync = e_cal_backend_file_get_free_busy;
3118
3122
        backend_class->internal_get_timezone = e_cal_backend_file_internal_get_timezone;
3119
3123
}
3120
3124
 
3121
 
/**
3122
 
 * e_cal_backend_file_get_type:
3123
 
 * @void:
3124
 
 *
3125
 
 * Registers the #ECalBackendFile class if necessary, and returns the type ID
3126
 
 * associated to it.
3127
 
 *
3128
 
 * Return value: The type ID of the #ECalBackendFile class.
3129
 
 **/
3130
 
GType
3131
 
e_cal_backend_file_get_type (void)
3132
 
{
3133
 
        static GType e_cal_backend_file_type = 0;
3134
 
 
3135
 
        if (!e_cal_backend_file_type) {
3136
 
                static GTypeInfo info = {
3137
 
                        sizeof (ECalBackendFileClass),
3138
 
                        (GBaseInitFunc) NULL,
3139
 
                        (GBaseFinalizeFunc) NULL,
3140
 
                        (GClassInitFunc) e_cal_backend_file_class_init,
3141
 
                        NULL, NULL,
3142
 
                        sizeof (ECalBackendFile),
3143
 
                        0,
3144
 
                        (GInstanceInitFunc) e_cal_backend_file_init
3145
 
                };
3146
 
                e_cal_backend_file_type = g_type_register_static (E_TYPE_CAL_BACKEND_SYNC,
3147
 
                                                                "ECalBackendFile", &info, 0);
3148
 
        }
3149
 
 
3150
 
        return e_cal_backend_file_type;
3151
 
}
3152
 
 
3153
3125
void
3154
3126
e_cal_backend_file_set_file_name (ECalBackendFile *cbfile, const gchar *file_name)
3155
3127
{